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; 18 19 import android.support.annotation.NonNull; 20 import android.support.annotation.Nullable; 21 import com.android.dialer.DialerPhoneNumber; 22 import com.android.dialer.logging.ContactLookupResult; 23 import com.android.dialer.logging.ContactSource; 24 import com.android.dialer.logging.ReportingLocation; 25 import com.google.common.collect.ImmutableMap; 26 import com.google.common.collect.ImmutableSet; 27 import com.google.common.util.concurrent.ListenableFuture; 28 29 /** Allows the container application to mark calls as spam. */ 30 public interface Spam { 31 isSpamEnabled()32 boolean isSpamEnabled(); 33 isSpamNotificationEnabled()34 boolean isSpamNotificationEnabled(); 35 isDialogEnabledForSpamNotification()36 boolean isDialogEnabledForSpamNotification(); 37 isDialogReportSpamCheckedByDefault()38 boolean isDialogReportSpamCheckedByDefault(); 39 40 /** @return what percentage of aftercall notifications to show to the user */ percentOfSpamNotificationsToShow()41 int percentOfSpamNotificationsToShow(); 42 percentOfNonSpamNotificationsToShow()43 int percentOfNonSpamNotificationsToShow(); 44 45 /** 46 * Checks if each of numbers in the given list is suspected of being a spam. 47 * 48 * @param dialerPhoneNumbers A set of {@link DialerPhoneNumber}. 49 * @return A {@link ListenableFuture} of a map that maps each number to its {@link SpamStatus}. 50 */ batchCheckSpamStatus( ImmutableSet<DialerPhoneNumber> dialerPhoneNumbers)51 ListenableFuture<ImmutableMap<DialerPhoneNumber, SpamStatus>> batchCheckSpamStatus( 52 ImmutableSet<DialerPhoneNumber> dialerPhoneNumbers); 53 54 /** 55 * Checks if the given number is suspected of being a spam. 56 * 57 * @param number The phone number of the call. 58 * @param countryIso The country ISO of the call. 59 * @param listener The callback to be invoked after {@code Info} is fetched. 60 */ checkSpamStatus(String number, String countryIso, Listener listener)61 void checkSpamStatus(String number, String countryIso, Listener listener); 62 63 /** 64 * @param number The number to check if the number is in the user's white list (non spam list) 65 * @param countryIso The country ISO of the call. 66 * @param listener The callback to be invoked after {@code Info} is fetched. 67 */ checkUserMarkedNonSpamStatus( String number, @Nullable String countryIso, @NonNull Listener listener)68 void checkUserMarkedNonSpamStatus( 69 String number, @Nullable String countryIso, @NonNull Listener listener); 70 71 /** 72 * @param number The number to check if it is in user's spam list 73 * @param countryIso The country ISO of the call. 74 * @param listener The callback to be invoked after {@code Info} is fetched. 75 */ checkUserMarkedSpamStatus( String number, @Nullable String countryIso, @NonNull Listener listener)76 void checkUserMarkedSpamStatus( 77 String number, @Nullable String countryIso, @NonNull Listener listener); 78 79 /** 80 * @param number The number to check if it is in the global spam list 81 * @param countryIso The country ISO of the call. 82 * @param listener The callback to be invoked after {@code Info} is fetched. 83 */ checkGlobalSpamListStatus( String number, @Nullable String countryIso, @NonNull Listener listener)84 void checkGlobalSpamListStatus( 85 String number, @Nullable String countryIso, @NonNull Listener listener); 86 87 /** 88 * Synchronously checks if the given number is suspected of being a spamer. 89 * 90 * @param number The phone number of the call. 91 * @param countryIso The country ISO of the call. 92 * @return True if the number is spam. 93 */ checkSpamStatusSynchronous(String number, String countryIso)94 boolean checkSpamStatusSynchronous(String number, String countryIso); 95 96 /** 97 * Returns a {@link ListenableFuture} indicating whether the spam data have been updated since 98 * {@code timestampMillis}. 99 * 100 * <p>It is the caller's responsibility to ensure the timestamp is in milliseconds. Failure to do 101 * so will result in undefined behavior. 102 */ dataUpdatedSince(long timestampMillis)103 ListenableFuture<Boolean> dataUpdatedSince(long timestampMillis); 104 105 /** 106 * Reports number as spam. 107 * 108 * @param number The number to be reported. 109 * @param countryIso The country ISO of the number. 110 * @param callType Whether the type of call is missed, voicemail, etc. Example of this is {@link 111 * android.provider.CallLog.Calls#VOICEMAIL_TYPE}. 112 * @param from Where in the dialer this was reported from. Must be one of {@link 113 * com.android.dialer.logging.ReportingLocation}. 114 * @param contactLookupResultType The result of the contact lookup for this phone number. Must be 115 * one of {@link com.android.dialer.logging.ContactLookupResult}. 116 */ reportSpamFromAfterCallNotification( String number, String countryIso, int callType, ReportingLocation.Type from, ContactLookupResult.Type contactLookupResultType)117 void reportSpamFromAfterCallNotification( 118 String number, 119 String countryIso, 120 int callType, 121 ReportingLocation.Type from, 122 ContactLookupResult.Type contactLookupResultType); 123 124 /** 125 * Reports number as spam. 126 * 127 * @param number The number to be reported. 128 * @param countryIso The country ISO of the number. 129 * @param callType Whether the type of call is missed, voicemail, etc. Example of this is {@link 130 * android.provider.CallLog.Calls#VOICEMAIL_TYPE}. 131 * @param from Where in the dialer this was reported from. Must be one of {@link 132 * com.android.dialer.logging.ReportingLocation}. 133 * @param contactSourceType If we have cached contact information for the phone number, this 134 * indicates its source. Must be one of {@link com.android.dialer.logging.ContactSource}. 135 */ reportSpamFromCallHistory( String number, String countryIso, int callType, ReportingLocation.Type from, ContactSource.Type contactSourceType)136 void reportSpamFromCallHistory( 137 String number, 138 String countryIso, 139 int callType, 140 ReportingLocation.Type from, 141 ContactSource.Type contactSourceType); 142 143 /** 144 * Reports number as not spam. 145 * 146 * @param number The number to be reported. 147 * @param countryIso The country ISO of the number. 148 * @param callType Whether the type of call is missed, voicemail, etc. Example of this is {@link 149 * android.provider.CallLog.Calls#VOICEMAIL_TYPE}. 150 * @param from Where in the dialer this was reported from. Must be one of {@link 151 * com.android.dialer.logging.ReportingLocation}. 152 * @param contactLookupResultType The result of the contact lookup for this phone number. Must be 153 * one of {@link com.android.dialer.logging.ContactLookupResult}. 154 */ reportNotSpamFromAfterCallNotification( String number, String countryIso, int callType, ReportingLocation.Type from, ContactLookupResult.Type contactLookupResultType)155 void reportNotSpamFromAfterCallNotification( 156 String number, 157 String countryIso, 158 int callType, 159 ReportingLocation.Type from, 160 ContactLookupResult.Type contactLookupResultType); 161 162 /** 163 * Reports number as not spam. 164 * 165 * @param number The number to be reported. 166 * @param countryIso The country ISO of the number. 167 * @param callType Whether the type of call is missed, voicemail, etc. Example of this is {@link 168 * android.provider.CallLog.Calls#VOICEMAIL_TYPE}. 169 * @param from Where in the dialer this was reported from. Must be one of {@link 170 * com.android.dialer.logging.ReportingLocation}. 171 * @param contactSourceType If we have cached contact information for the phone number, this 172 * indicates its source. Must be one of {@link com.android.dialer.logging.ContactSource}. 173 */ reportNotSpamFromCallHistory( String number, String countryIso, int callType, ReportingLocation.Type from, ContactSource.Type contactSourceType)174 void reportNotSpamFromCallHistory( 175 String number, 176 String countryIso, 177 int callType, 178 ReportingLocation.Type from, 179 ContactSource.Type contactSourceType); 180 181 /** Callback to be invoked when data is fetched. */ 182 interface Listener { 183 184 /** Called when data is fetched. */ onComplete(boolean isSpam)185 void onComplete(boolean isSpam); 186 } 187 } 188