1 /* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.dialer.spam.stub; 18 19 import android.support.annotation.Nullable; 20 import com.android.dialer.DialerPhoneNumber; 21 import com.android.dialer.common.concurrent.Annotations.BackgroundExecutor; 22 import com.android.dialer.logging.ContactLookupResult; 23 import com.android.dialer.logging.ContactSource; 24 import com.android.dialer.logging.ReportingLocation; 25 import com.android.dialer.spam.Spam; 26 import com.android.dialer.spam.status.SimpleSpamStatus; 27 import com.android.dialer.spam.status.SpamStatus; 28 import com.google.common.collect.ImmutableMap; 29 import com.google.common.collect.ImmutableSet; 30 import com.google.common.util.concurrent.Futures; 31 import com.google.common.util.concurrent.ListenableFuture; 32 import com.google.common.util.concurrent.ListeningExecutorService; 33 import javax.inject.Inject; 34 35 /** Default implementation of Spam. */ 36 public class SpamStub implements Spam { 37 38 private final ListeningExecutorService backgroundExecutorService; 39 40 @Inject SpamStub(@ackgroundExecutor ListeningExecutorService backgroundExecutorService)41 public SpamStub(@BackgroundExecutor ListeningExecutorService backgroundExecutorService) { 42 this.backgroundExecutorService = backgroundExecutorService; 43 } 44 45 @Override batchCheckSpamStatus( ImmutableSet<DialerPhoneNumber> dialerPhoneNumbers)46 public ListenableFuture<ImmutableMap<DialerPhoneNumber, SpamStatus>> batchCheckSpamStatus( 47 ImmutableSet<DialerPhoneNumber> dialerPhoneNumbers) { 48 return backgroundExecutorService.submit( 49 () -> { 50 ImmutableMap.Builder<DialerPhoneNumber, SpamStatus> resultBuilder = 51 new ImmutableMap.Builder<>(); 52 for (DialerPhoneNumber dialerPhoneNumber : dialerPhoneNumbers) { 53 resultBuilder.put(dialerPhoneNumber, SimpleSpamStatus.notSpam()); 54 } 55 return resultBuilder.build(); 56 }); 57 } 58 59 @Override checkSpamStatus(DialerPhoneNumber dialerPhoneNumber)60 public ListenableFuture<SpamStatus> checkSpamStatus(DialerPhoneNumber dialerPhoneNumber) { 61 return Futures.immediateFuture(SimpleSpamStatus.notSpam()); 62 } 63 64 @Override checkSpamStatus( String number, @Nullable String defaultCountryIso)65 public ListenableFuture<SpamStatus> checkSpamStatus( 66 String number, @Nullable String defaultCountryIso) { 67 return Futures.immediateFuture(SimpleSpamStatus.notSpam()); 68 } 69 70 @Override updateSpamListDownload(boolean isEnabledByUser)71 public ListenableFuture<Void> updateSpamListDownload(boolean isEnabledByUser) { 72 // no-op 73 return Futures.immediateFuture(null); 74 } 75 76 @Override checkSpamStatusSynchronous(String number, String countryIso)77 public boolean checkSpamStatusSynchronous(String number, String countryIso) { 78 return false; 79 } 80 81 @Override dataUpdatedSince(long timestampMillis)82 public ListenableFuture<Boolean> dataUpdatedSince(long timestampMillis) { 83 return Futures.immediateFuture(false); 84 } 85 86 @Override reportSpamFromAfterCallNotification( String number, String countryIso, int callType, ReportingLocation.Type from, ContactLookupResult.Type contactLookupResultType)87 public void reportSpamFromAfterCallNotification( 88 String number, 89 String countryIso, 90 int callType, 91 ReportingLocation.Type from, 92 ContactLookupResult.Type contactLookupResultType) {} 93 94 @Override reportSpamFromCallHistory( String number, String countryIso, int callType, ReportingLocation.Type from, ContactSource.Type contactSourceType)95 public void reportSpamFromCallHistory( 96 String number, 97 String countryIso, 98 int callType, 99 ReportingLocation.Type from, 100 ContactSource.Type contactSourceType) {} 101 102 @Override reportNotSpamFromAfterCallNotification( String number, String countryIso, int callType, ReportingLocation.Type from, ContactLookupResult.Type contactLookupResultType)103 public void reportNotSpamFromAfterCallNotification( 104 String number, 105 String countryIso, 106 int callType, 107 ReportingLocation.Type from, 108 ContactLookupResult.Type contactLookupResultType) {} 109 110 @Override reportNotSpamFromCallHistory( String number, String countryIso, int callType, ReportingLocation.Type from, ContactSource.Type contactSourceType)111 public void reportNotSpamFromCallHistory( 112 String number, 113 String countryIso, 114 int callType, 115 ReportingLocation.Type from, 116 ContactSource.Type contactSourceType) {} 117 } 118