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