Sailesh Nepal | 1bef339 | 2016-01-24 18:21:53 -0800 | [diff] [blame] | 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 android.telecom; |
| 18 | |
Tyler Gunn | 7e45b72 | 2018-12-04 12:56:45 -0800 | [diff] [blame] | 19 | import android.annotation.NonNull; |
Sailesh Nepal | 1bef339 | 2016-01-24 18:21:53 -0800 | [diff] [blame] | 20 | import android.annotation.SdkConstant; |
Hall Liu | 6dfa249 | 2019-10-01 17:20:39 -0700 | [diff] [blame] | 21 | import android.annotation.SystemApi; |
| 22 | import android.annotation.TestApi; |
Sailesh Nepal | 1bef339 | 2016-01-24 18:21:53 -0800 | [diff] [blame] | 23 | import android.app.Service; |
tonyzhu | 9e1d4f8 | 2018-10-22 15:11:31 +0800 | [diff] [blame] | 24 | import android.content.ComponentName; |
Sailesh Nepal | 1bef339 | 2016-01-24 18:21:53 -0800 | [diff] [blame] | 25 | import android.content.Intent; |
Tyler Gunn | 9e76fd1 | 2018-12-17 09:56:11 -0800 | [diff] [blame] | 26 | import android.net.Uri; |
Sailesh Nepal | 1bef339 | 2016-01-24 18:21:53 -0800 | [diff] [blame] | 27 | import android.os.Handler; |
| 28 | import android.os.IBinder; |
| 29 | import android.os.Looper; |
| 30 | import android.os.Message; |
| 31 | import android.os.RemoteException; |
| 32 | |
| 33 | import com.android.internal.os.SomeArgs; |
Sailesh Nepal | 1bef339 | 2016-01-24 18:21:53 -0800 | [diff] [blame] | 34 | import com.android.internal.telecom.ICallScreeningAdapter; |
Tyler Gunn | e0caec7 | 2018-11-30 14:21:18 -0800 | [diff] [blame] | 35 | import com.android.internal.telecom.ICallScreeningService; |
Sailesh Nepal | 1bef339 | 2016-01-24 18:21:53 -0800 | [diff] [blame] | 36 | |
| 37 | /** |
| 38 | * This service can be implemented by the default dialer (see |
Tyler Gunn | 9e76fd1 | 2018-12-17 09:56:11 -0800 | [diff] [blame] | 39 | * {@link TelecomManager#getDefaultDialerPackage()}) or a third party app to allow or disallow |
Tyler Gunn | a842e76 | 2019-03-29 11:32:08 -0700 | [diff] [blame] | 40 | * incoming calls before they are shown to a user. A {@link CallScreeningService} can also see |
| 41 | * outgoing calls for the purpose of providing caller ID services for those calls. |
Sailesh Nepal | 1bef339 | 2016-01-24 18:21:53 -0800 | [diff] [blame] | 42 | * <p> |
| 43 | * Below is an example manifest registration for a {@code CallScreeningService}. |
| 44 | * <pre> |
| 45 | * {@code |
| 46 | * <service android:name="your.package.YourCallScreeningServiceImplementation" |
| 47 | * android:permission="android.permission.BIND_SCREENING_SERVICE"> |
| 48 | * <intent-filter> |
| 49 | * <action android:name="android.telecom.CallScreeningService"/> |
| 50 | * </intent-filter> |
| 51 | * </service> |
| 52 | * } |
| 53 | * </pre> |
Tyler Gunn | 7e45b72 | 2018-12-04 12:56:45 -0800 | [diff] [blame] | 54 | * <p> |
| 55 | * A CallScreeningService performs two functions: |
| 56 | * <ol> |
| 57 | * <li>Call blocking/screening - the service can choose which calls will ring on the user's |
| 58 | * device, and which will be silently sent to voicemail.</li> |
Tyler Gunn | a842e76 | 2019-03-29 11:32:08 -0700 | [diff] [blame] | 59 | * <li>Call identification - services which provide call identification functionality can |
| 60 | * display a user-interface of their choosing which contains identifying information for a call. |
| 61 | * </li> |
Tyler Gunn | 7e45b72 | 2018-12-04 12:56:45 -0800 | [diff] [blame] | 62 | * </ol> |
Tyler Gunn | 9e76fd1 | 2018-12-17 09:56:11 -0800 | [diff] [blame] | 63 | * <p> |
| 64 | * <h2>Becoming the {@link CallScreeningService}</h2> |
| 65 | * Telecom will bind to a single app chosen by the user which implements the |
| 66 | * {@link CallScreeningService} API when there are new incoming and outgoing calls. |
| 67 | * <p> |
| 68 | * The code snippet below illustrates how your app can request that it fills the call screening |
| 69 | * role. |
| 70 | * <pre> |
| 71 | * {@code |
| 72 | * private static final int REQUEST_ID = 1; |
| 73 | * |
| 74 | * public void requestRole() { |
| 75 | * RoleManager roleManager = (RoleManager) getSystemService(ROLE_SERVICE); |
Grace Jia | 2d21e95 | 2019-09-20 14:57:00 -0700 | [diff] [blame] | 76 | * Intent intent = roleManager.createRequestRoleIntent(RoleManager.ROLE_CALL_SCREENING); |
Tyler Gunn | 9e76fd1 | 2018-12-17 09:56:11 -0800 | [diff] [blame] | 77 | * startActivityForResult(intent, REQUEST_ID); |
| 78 | * } |
| 79 | * |
| 80 | * @Override |
| 81 | * public void onActivityResult(int requestCode, int resultCode, Intent data) { |
| 82 | * if (requestCode == REQUEST_ID) { |
| 83 | * if (resultCode == android.app.Activity.RESULT_OK) { |
| 84 | * // Your app is now the call screening app |
| 85 | * } else { |
| 86 | * // Your app is not the call screening app |
| 87 | * } |
| 88 | * } |
| 89 | * } |
| 90 | * </pre> |
Sailesh Nepal | 1bef339 | 2016-01-24 18:21:53 -0800 | [diff] [blame] | 91 | */ |
| 92 | public abstract class CallScreeningService extends Service { |
| 93 | /** |
| 94 | * The {@link Intent} that must be declared as handled by the service. |
| 95 | */ |
| 96 | @SdkConstant(SdkConstant.SdkConstantType.SERVICE_ACTION) |
| 97 | public static final String SERVICE_INTERFACE = "android.telecom.CallScreeningService"; |
| 98 | |
| 99 | private static final int MSG_SCREEN_CALL = 1; |
| 100 | |
| 101 | private final Handler mHandler = new Handler(Looper.getMainLooper()) { |
| 102 | @Override |
| 103 | public void handleMessage(Message msg) { |
| 104 | switch (msg.what) { |
| 105 | case MSG_SCREEN_CALL: |
| 106 | SomeArgs args = (SomeArgs) msg.obj; |
| 107 | try { |
| 108 | mCallScreeningAdapter = (ICallScreeningAdapter) args.arg1; |
Grace Jia | 90b3804 | 2019-11-06 14:12:33 -0800 | [diff] [blame] | 109 | Call.Details callDetails = Call.Details |
| 110 | .createFromParcelableCall((ParcelableCall) args.arg2); |
| 111 | onScreenCall(callDetails); |
| 112 | if (callDetails.getCallDirection() == Call.Details.DIRECTION_OUTGOING) { |
| 113 | mCallScreeningAdapter.allowCall(callDetails.getTelecomCallId()); |
| 114 | } |
| 115 | } catch (RemoteException e) { |
| 116 | Log.w(this, "Exception when screening call: " + e); |
Sailesh Nepal | 1bef339 | 2016-01-24 18:21:53 -0800 | [diff] [blame] | 117 | } finally { |
| 118 | args.recycle(); |
| 119 | } |
| 120 | break; |
| 121 | } |
| 122 | } |
| 123 | }; |
| 124 | |
| 125 | private final class CallScreeningBinder extends ICallScreeningService.Stub { |
| 126 | @Override |
| 127 | public void screenCall(ICallScreeningAdapter adapter, ParcelableCall call) { |
| 128 | Log.v(this, "screenCall"); |
| 129 | SomeArgs args = SomeArgs.obtain(); |
| 130 | args.arg1 = adapter; |
| 131 | args.arg2 = call; |
| 132 | mHandler.obtainMessage(MSG_SCREEN_CALL, args).sendToTarget(); |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | private ICallScreeningAdapter mCallScreeningAdapter; |
| 137 | |
| 138 | /* |
| 139 | * Information about how to respond to an incoming call. |
| 140 | */ |
Sailesh Nepal | f446071 | 2016-01-27 16:45:51 -0800 | [diff] [blame] | 141 | public static class CallResponse { |
Sailesh Nepal | 1bef339 | 2016-01-24 18:21:53 -0800 | [diff] [blame] | 142 | private final boolean mShouldDisallowCall; |
| 143 | private final boolean mShouldRejectCall; |
Usman Abdullah | 47b392d | 2019-03-06 15:54:56 -0800 | [diff] [blame] | 144 | private final boolean mShouldSilenceCall; |
Sailesh Nepal | 1bef339 | 2016-01-24 18:21:53 -0800 | [diff] [blame] | 145 | private final boolean mShouldSkipCallLog; |
| 146 | private final boolean mShouldSkipNotification; |
Hall Liu | 69554cf | 2019-11-11 17:44:09 -0800 | [diff] [blame] | 147 | private final boolean mShouldScreenCallViaAudioProcessing; |
Sailesh Nepal | 1bef339 | 2016-01-24 18:21:53 -0800 | [diff] [blame] | 148 | |
| 149 | private CallResponse( |
| 150 | boolean shouldDisallowCall, |
| 151 | boolean shouldRejectCall, |
Usman Abdullah | 47b392d | 2019-03-06 15:54:56 -0800 | [diff] [blame] | 152 | boolean shouldSilenceCall, |
Sailesh Nepal | 1bef339 | 2016-01-24 18:21:53 -0800 | [diff] [blame] | 153 | boolean shouldSkipCallLog, |
Hall Liu | 6dfa249 | 2019-10-01 17:20:39 -0700 | [diff] [blame] | 154 | boolean shouldSkipNotification, |
Hall Liu | 69554cf | 2019-11-11 17:44:09 -0800 | [diff] [blame] | 155 | boolean shouldScreenCallViaAudioProcessing) { |
Sailesh Nepal | 1bef339 | 2016-01-24 18:21:53 -0800 | [diff] [blame] | 156 | if (!shouldDisallowCall |
| 157 | && (shouldRejectCall || shouldSkipCallLog || shouldSkipNotification)) { |
| 158 | throw new IllegalStateException("Invalid response state for allowed call."); |
| 159 | } |
| 160 | |
Hall Liu | 69554cf | 2019-11-11 17:44:09 -0800 | [diff] [blame] | 161 | if (shouldDisallowCall && shouldScreenCallViaAudioProcessing) { |
Hall Liu | 6dfa249 | 2019-10-01 17:20:39 -0700 | [diff] [blame] | 162 | throw new IllegalStateException("Invalid response state for allowed call."); |
| 163 | } |
| 164 | |
Sailesh Nepal | 1bef339 | 2016-01-24 18:21:53 -0800 | [diff] [blame] | 165 | mShouldDisallowCall = shouldDisallowCall; |
| 166 | mShouldRejectCall = shouldRejectCall; |
| 167 | mShouldSkipCallLog = shouldSkipCallLog; |
| 168 | mShouldSkipNotification = shouldSkipNotification; |
Usman Abdullah | 47b392d | 2019-03-06 15:54:56 -0800 | [diff] [blame] | 169 | mShouldSilenceCall = shouldSilenceCall; |
Hall Liu | 69554cf | 2019-11-11 17:44:09 -0800 | [diff] [blame] | 170 | mShouldScreenCallViaAudioProcessing = shouldScreenCallViaAudioProcessing; |
Sailesh Nepal | 1bef339 | 2016-01-24 18:21:53 -0800 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | /* |
| 174 | * @return Whether the incoming call should be blocked. |
| 175 | */ |
| 176 | public boolean getDisallowCall() { |
| 177 | return mShouldDisallowCall; |
| 178 | } |
| 179 | |
| 180 | /* |
| 181 | * @return Whether the incoming call should be disconnected as if the user had manually |
| 182 | * rejected it. |
| 183 | */ |
| 184 | public boolean getRejectCall() { |
| 185 | return mShouldRejectCall; |
| 186 | } |
| 187 | |
| 188 | /* |
Usman Abdullah | 47b392d | 2019-03-06 15:54:56 -0800 | [diff] [blame] | 189 | * @return Whether the ringtone should be silenced for the incoming call. |
| 190 | */ |
| 191 | public boolean getSilenceCall() { |
| 192 | return mShouldSilenceCall; |
| 193 | } |
| 194 | |
| 195 | /* |
Sailesh Nepal | 1bef339 | 2016-01-24 18:21:53 -0800 | [diff] [blame] | 196 | * @return Whether the incoming call should not be displayed in the call log. |
| 197 | */ |
| 198 | public boolean getSkipCallLog() { |
| 199 | return mShouldSkipCallLog; |
| 200 | } |
| 201 | |
| 202 | /* |
| 203 | * @return Whether a missed call notification should not be shown for the incoming call. |
| 204 | */ |
| 205 | public boolean getSkipNotification() { |
| 206 | return mShouldSkipNotification; |
| 207 | } |
| 208 | |
Hall Liu | 6dfa249 | 2019-10-01 17:20:39 -0700 | [diff] [blame] | 209 | /** |
| 210 | * @return Whether we should enter the {@link Call#STATE_AUDIO_PROCESSING} state to allow |
| 211 | * for further screening of the call. |
| 212 | * @hide |
| 213 | */ |
Hall Liu | 69554cf | 2019-11-11 17:44:09 -0800 | [diff] [blame] | 214 | public boolean getShouldScreenCallViaAudioProcessing() { |
| 215 | return mShouldScreenCallViaAudioProcessing; |
Hall Liu | 6dfa249 | 2019-10-01 17:20:39 -0700 | [diff] [blame] | 216 | } |
| 217 | |
Sailesh Nepal | f446071 | 2016-01-27 16:45:51 -0800 | [diff] [blame] | 218 | public static class Builder { |
Sailesh Nepal | 1bef339 | 2016-01-24 18:21:53 -0800 | [diff] [blame] | 219 | private boolean mShouldDisallowCall; |
| 220 | private boolean mShouldRejectCall; |
Usman Abdullah | 47b392d | 2019-03-06 15:54:56 -0800 | [diff] [blame] | 221 | private boolean mShouldSilenceCall; |
Sailesh Nepal | 1bef339 | 2016-01-24 18:21:53 -0800 | [diff] [blame] | 222 | private boolean mShouldSkipCallLog; |
| 223 | private boolean mShouldSkipNotification; |
Hall Liu | 69554cf | 2019-11-11 17:44:09 -0800 | [diff] [blame] | 224 | private boolean mShouldScreenCallViaAudioProcessing; |
Sailesh Nepal | 1bef339 | 2016-01-24 18:21:53 -0800 | [diff] [blame] | 225 | |
Tyler Gunn | e0caec7 | 2018-11-30 14:21:18 -0800 | [diff] [blame] | 226 | /** |
Sailesh Nepal | 1bef339 | 2016-01-24 18:21:53 -0800 | [diff] [blame] | 227 | * Sets whether the incoming call should be blocked. |
| 228 | */ |
| 229 | public Builder setDisallowCall(boolean shouldDisallowCall) { |
| 230 | mShouldDisallowCall = shouldDisallowCall; |
| 231 | return this; |
| 232 | } |
| 233 | |
Tyler Gunn | e0caec7 | 2018-11-30 14:21:18 -0800 | [diff] [blame] | 234 | /** |
Sailesh Nepal | 1bef339 | 2016-01-24 18:21:53 -0800 | [diff] [blame] | 235 | * Sets whether the incoming call should be disconnected as if the user had manually |
| 236 | * rejected it. This property should only be set to true if the call is disallowed. |
| 237 | */ |
| 238 | public Builder setRejectCall(boolean shouldRejectCall) { |
| 239 | mShouldRejectCall = shouldRejectCall; |
| 240 | return this; |
| 241 | } |
| 242 | |
Tyler Gunn | e0caec7 | 2018-11-30 14:21:18 -0800 | [diff] [blame] | 243 | /** |
Usman Abdullah | 47b392d | 2019-03-06 15:54:56 -0800 | [diff] [blame] | 244 | * Sets whether ringing should be silenced for the incoming call. When set |
| 245 | * to {@code true}, the Telecom framework will not play a ringtone for the call. |
| 246 | * The call will, however, still be sent to the default dialer app if it is not blocked. |
| 247 | * A {@link CallScreeningService} can use this to ensure a potential nuisance call is |
| 248 | * still surfaced to the user, but in a less intrusive manner. |
| 249 | * |
| 250 | * Setting this to true only makes sense when the call has not been disallowed |
| 251 | * using {@link #setDisallowCall(boolean)}. |
| 252 | */ |
| 253 | public @NonNull Builder setSilenceCall(boolean shouldSilenceCall) { |
| 254 | mShouldSilenceCall = shouldSilenceCall; |
| 255 | return this; |
| 256 | } |
| 257 | |
| 258 | /** |
Sailesh Nepal | 1bef339 | 2016-01-24 18:21:53 -0800 | [diff] [blame] | 259 | * Sets whether the incoming call should not be displayed in the call log. This property |
| 260 | * should only be set to true if the call is disallowed. |
Tyler Gunn | e0caec7 | 2018-11-30 14:21:18 -0800 | [diff] [blame] | 261 | * <p> |
| 262 | * Note: Calls will still be logged with type |
| 263 | * {@link android.provider.CallLog.Calls#BLOCKED_TYPE}, regardless of how this property |
| 264 | * is set. |
Sailesh Nepal | 1bef339 | 2016-01-24 18:21:53 -0800 | [diff] [blame] | 265 | */ |
| 266 | public Builder setSkipCallLog(boolean shouldSkipCallLog) { |
| 267 | mShouldSkipCallLog = shouldSkipCallLog; |
| 268 | return this; |
| 269 | } |
| 270 | |
Tyler Gunn | e0caec7 | 2018-11-30 14:21:18 -0800 | [diff] [blame] | 271 | /** |
Sailesh Nepal | 1bef339 | 2016-01-24 18:21:53 -0800 | [diff] [blame] | 272 | * Sets whether a missed call notification should not be shown for the incoming call. |
| 273 | * This property should only be set to true if the call is disallowed. |
| 274 | */ |
| 275 | public Builder setSkipNotification(boolean shouldSkipNotification) { |
| 276 | mShouldSkipNotification = shouldSkipNotification; |
| 277 | return this; |
| 278 | } |
| 279 | |
Hall Liu | 6dfa249 | 2019-10-01 17:20:39 -0700 | [diff] [blame] | 280 | /** |
| 281 | * Sets whether to request background audio processing so that the in-call service can |
| 282 | * screen the call further. If set to {@code true}, {@link #setDisallowCall} should be |
| 283 | * called with {@code false}, and all other parameters in this builder will be ignored. |
| 284 | * |
| 285 | * This request will only be honored if the {@link CallScreeningService} shares the same |
| 286 | * uid as the default dialer app. Otherwise, the call will go through as usual. |
| 287 | * |
Hall Liu | 69554cf | 2019-11-11 17:44:09 -0800 | [diff] [blame] | 288 | * @param shouldScreenCallViaAudioProcessing Whether to request further call screening. |
Hall Liu | 6dfa249 | 2019-10-01 17:20:39 -0700 | [diff] [blame] | 289 | * @hide |
| 290 | */ |
| 291 | @SystemApi |
| 292 | @TestApi |
Hall Liu | 69554cf | 2019-11-11 17:44:09 -0800 | [diff] [blame] | 293 | public @NonNull Builder setShouldScreenCallViaAudioProcessing( |
| 294 | boolean shouldScreenCallViaAudioProcessing) { |
| 295 | mShouldScreenCallViaAudioProcessing = shouldScreenCallViaAudioProcessing; |
Hall Liu | 6dfa249 | 2019-10-01 17:20:39 -0700 | [diff] [blame] | 296 | return this; |
| 297 | } |
| 298 | |
Sailesh Nepal | 1bef339 | 2016-01-24 18:21:53 -0800 | [diff] [blame] | 299 | public CallResponse build() { |
| 300 | return new CallResponse( |
| 301 | mShouldDisallowCall, |
| 302 | mShouldRejectCall, |
Usman Abdullah | 47b392d | 2019-03-06 15:54:56 -0800 | [diff] [blame] | 303 | mShouldSilenceCall, |
Sailesh Nepal | 1bef339 | 2016-01-24 18:21:53 -0800 | [diff] [blame] | 304 | mShouldSkipCallLog, |
Hall Liu | 6dfa249 | 2019-10-01 17:20:39 -0700 | [diff] [blame] | 305 | mShouldSkipNotification, |
Hall Liu | 69554cf | 2019-11-11 17:44:09 -0800 | [diff] [blame] | 306 | mShouldScreenCallViaAudioProcessing); |
Sailesh Nepal | 1bef339 | 2016-01-24 18:21:53 -0800 | [diff] [blame] | 307 | } |
| 308 | } |
| 309 | } |
| 310 | |
| 311 | public CallScreeningService() { |
| 312 | } |
| 313 | |
| 314 | @Override |
| 315 | public IBinder onBind(Intent intent) { |
| 316 | Log.v(this, "onBind"); |
| 317 | return new CallScreeningBinder(); |
| 318 | } |
| 319 | |
| 320 | @Override |
| 321 | public boolean onUnbind(Intent intent) { |
| 322 | Log.v(this, "onUnbind"); |
| 323 | return false; |
| 324 | } |
| 325 | |
| 326 | /** |
Tyler Gunn | 9e76fd1 | 2018-12-17 09:56:11 -0800 | [diff] [blame] | 327 | * Called when a new incoming or outgoing call is added which is not in the user's contact list. |
| 328 | * <p> |
| 329 | * A {@link CallScreeningService} must indicate whether an incoming call is allowed or not by |
| 330 | * calling |
| 331 | * {@link CallScreeningService#respondToCall(Call.Details, CallScreeningService.CallResponse)}. |
| 332 | * Your app can tell if a call is an incoming call by checking to see if |
| 333 | * {@link Call.Details#getCallDirection()} is {@link Call.Details#DIRECTION_INCOMING}. |
| 334 | * <p> |
Tyler Gunn | e0caec7 | 2018-11-30 14:21:18 -0800 | [diff] [blame] | 335 | * Note: The {@link Call.Details} instance provided to a call screening service will only have |
| 336 | * the following properties set. The rest of the {@link Call.Details} properties will be set to |
| 337 | * their default value or {@code null}. |
| 338 | * <ul> |
Tyler Gunn | 9e76fd1 | 2018-12-17 09:56:11 -0800 | [diff] [blame] | 339 | * <li>{@link Call.Details#getCallDirection()}</li> |
Tyler Gunn | e0caec7 | 2018-11-30 14:21:18 -0800 | [diff] [blame] | 340 | * <li>{@link Call.Details#getConnectTimeMillis()}</li> |
| 341 | * <li>{@link Call.Details#getCreationTimeMillis()}</li> |
| 342 | * <li>{@link Call.Details#getHandle()}</li> |
| 343 | * <li>{@link Call.Details#getHandlePresentation()}</li> |
| 344 | * </ul> |
Tyler Gunn | 9e76fd1 | 2018-12-17 09:56:11 -0800 | [diff] [blame] | 345 | * <p> |
| 346 | * Only calls where the {@link Call.Details#getHandle() handle} {@link Uri#getScheme() scheme} |
| 347 | * is {@link PhoneAccount#SCHEME_TEL} are passed for call |
| 348 | * screening. Further, only calls which are not in the user's contacts are passed for |
| 349 | * screening. For outgoing calls, no post-dial digits are passed. |
Sailesh Nepal | 1bef339 | 2016-01-24 18:21:53 -0800 | [diff] [blame] | 350 | * |
Tyler Gunn | 9e76fd1 | 2018-12-17 09:56:11 -0800 | [diff] [blame] | 351 | * @param callDetails Information about a new call, see {@link Call.Details}. |
Sailesh Nepal | 1bef339 | 2016-01-24 18:21:53 -0800 | [diff] [blame] | 352 | */ |
Tyler Gunn | 7e45b72 | 2018-12-04 12:56:45 -0800 | [diff] [blame] | 353 | public abstract void onScreenCall(@NonNull Call.Details callDetails); |
Sailesh Nepal | 1bef339 | 2016-01-24 18:21:53 -0800 | [diff] [blame] | 354 | |
| 355 | /** |
Usman Abdullah | 47b392d | 2019-03-06 15:54:56 -0800 | [diff] [blame] | 356 | * Responds to the given incoming call, either allowing it, silencing it or disallowing it. |
Tyler Gunn | 7e45b72 | 2018-12-04 12:56:45 -0800 | [diff] [blame] | 357 | * <p> |
| 358 | * The {@link CallScreeningService} calls this method to inform the system whether the call |
Usman Abdullah | 47b392d | 2019-03-06 15:54:56 -0800 | [diff] [blame] | 359 | * should be silently blocked or not. In the event that it should not be blocked, it may |
| 360 | * also be requested to ring silently. |
Tyler Gunn | 9e76fd1 | 2018-12-17 09:56:11 -0800 | [diff] [blame] | 361 | * <p> |
| 362 | * Calls to this method are ignored unless the {@link Call.Details#getCallDirection()} is |
| 363 | * {@link Call.Details#DIRECTION_INCOMING}. |
Sailesh Nepal | 1bef339 | 2016-01-24 18:21:53 -0800 | [diff] [blame] | 364 | * |
| 365 | * @param callDetails The call to allow. |
Tyler Gunn | 7e45b72 | 2018-12-04 12:56:45 -0800 | [diff] [blame] | 366 | * <p> |
| 367 | * Must be the same {@link Call.Details call} which was provided to the |
| 368 | * {@link CallScreeningService} via {@link #onScreenCall(Call.Details)}. |
Sailesh Nepal | 1bef339 | 2016-01-24 18:21:53 -0800 | [diff] [blame] | 369 | * @param response The {@link CallScreeningService.CallResponse} which contains information |
| 370 | * about how to respond to a call. |
| 371 | */ |
Tyler Gunn | 7e45b72 | 2018-12-04 12:56:45 -0800 | [diff] [blame] | 372 | public final void respondToCall(@NonNull Call.Details callDetails, |
| 373 | @NonNull CallResponse response) { |
Sailesh Nepal | 1bef339 | 2016-01-24 18:21:53 -0800 | [diff] [blame] | 374 | try { |
| 375 | if (response.getDisallowCall()) { |
| 376 | mCallScreeningAdapter.disallowCall( |
| 377 | callDetails.getTelecomCallId(), |
| 378 | response.getRejectCall(), |
| 379 | !response.getSkipCallLog(), |
tonyzhu | 9e1d4f8 | 2018-10-22 15:11:31 +0800 | [diff] [blame] | 380 | !response.getSkipNotification(), |
| 381 | new ComponentName(getPackageName(), getClass().getName())); |
Usman Abdullah | 47b392d | 2019-03-06 15:54:56 -0800 | [diff] [blame] | 382 | } else if (response.getSilenceCall()) { |
| 383 | mCallScreeningAdapter.silenceCall(callDetails.getTelecomCallId()); |
Hall Liu | 69554cf | 2019-11-11 17:44:09 -0800 | [diff] [blame] | 384 | } else if (response.getShouldScreenCallViaAudioProcessing()) { |
Hall Liu | 31de23d | 2019-10-11 15:38:29 -0700 | [diff] [blame] | 385 | mCallScreeningAdapter.screenCallFurther(callDetails.getTelecomCallId()); |
Sailesh Nepal | 1bef339 | 2016-01-24 18:21:53 -0800 | [diff] [blame] | 386 | } else { |
| 387 | mCallScreeningAdapter.allowCall(callDetails.getTelecomCallId()); |
| 388 | } |
| 389 | } catch (RemoteException e) { |
| 390 | } |
| 391 | } |
Sailesh Nepal | 1bef339 | 2016-01-24 18:21:53 -0800 | [diff] [blame] | 392 | } |