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 | 9e76fd19b | 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 | 9e76fd19b | 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 | 9e76fd19b | 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 | 9e76fd19b | 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; |
| 109 | onScreenCall( |
| 110 | Call.Details.createFromParcelableCall((ParcelableCall) args.arg2)); |
| 111 | } finally { |
| 112 | args.recycle(); |
| 113 | } |
| 114 | break; |
| 115 | } |
| 116 | } |
| 117 | }; |
| 118 | |
| 119 | private final class CallScreeningBinder extends ICallScreeningService.Stub { |
| 120 | @Override |
| 121 | public void screenCall(ICallScreeningAdapter adapter, ParcelableCall call) { |
| 122 | Log.v(this, "screenCall"); |
| 123 | SomeArgs args = SomeArgs.obtain(); |
| 124 | args.arg1 = adapter; |
| 125 | args.arg2 = call; |
| 126 | mHandler.obtainMessage(MSG_SCREEN_CALL, args).sendToTarget(); |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | private ICallScreeningAdapter mCallScreeningAdapter; |
| 131 | |
| 132 | /* |
| 133 | * Information about how to respond to an incoming call. |
| 134 | */ |
Sailesh Nepal | f446071 | 2016-01-27 16:45:51 -0800 | [diff] [blame] | 135 | public static class CallResponse { |
Sailesh Nepal | 1bef339 | 2016-01-24 18:21:53 -0800 | [diff] [blame] | 136 | private final boolean mShouldDisallowCall; |
| 137 | private final boolean mShouldRejectCall; |
Usman Abdullah | 47b392d | 2019-03-06 15:54:56 -0800 | [diff] [blame] | 138 | private final boolean mShouldSilenceCall; |
Sailesh Nepal | 1bef339 | 2016-01-24 18:21:53 -0800 | [diff] [blame] | 139 | private final boolean mShouldSkipCallLog; |
| 140 | private final boolean mShouldSkipNotification; |
Hall Liu | 6dfa249 | 2019-10-01 17:20:39 -0700 | [diff] [blame] | 141 | private final boolean mShouldScreenCallFurther; |
Sailesh Nepal | 1bef339 | 2016-01-24 18:21:53 -0800 | [diff] [blame] | 142 | |
| 143 | private CallResponse( |
| 144 | boolean shouldDisallowCall, |
| 145 | boolean shouldRejectCall, |
Usman Abdullah | 47b392d | 2019-03-06 15:54:56 -0800 | [diff] [blame] | 146 | boolean shouldSilenceCall, |
Sailesh Nepal | 1bef339 | 2016-01-24 18:21:53 -0800 | [diff] [blame] | 147 | boolean shouldSkipCallLog, |
Hall Liu | 6dfa249 | 2019-10-01 17:20:39 -0700 | [diff] [blame] | 148 | boolean shouldSkipNotification, |
| 149 | boolean shouldScreenCallFurther) { |
Sailesh Nepal | 1bef339 | 2016-01-24 18:21:53 -0800 | [diff] [blame] | 150 | if (!shouldDisallowCall |
| 151 | && (shouldRejectCall || shouldSkipCallLog || shouldSkipNotification)) { |
| 152 | throw new IllegalStateException("Invalid response state for allowed call."); |
| 153 | } |
| 154 | |
Hall Liu | 6dfa249 | 2019-10-01 17:20:39 -0700 | [diff] [blame] | 155 | if (shouldDisallowCall && shouldScreenCallFurther) { |
| 156 | throw new IllegalStateException("Invalid response state for allowed call."); |
| 157 | } |
| 158 | |
Sailesh Nepal | 1bef339 | 2016-01-24 18:21:53 -0800 | [diff] [blame] | 159 | mShouldDisallowCall = shouldDisallowCall; |
| 160 | mShouldRejectCall = shouldRejectCall; |
| 161 | mShouldSkipCallLog = shouldSkipCallLog; |
| 162 | mShouldSkipNotification = shouldSkipNotification; |
Usman Abdullah | 47b392d | 2019-03-06 15:54:56 -0800 | [diff] [blame] | 163 | mShouldSilenceCall = shouldSilenceCall; |
Hall Liu | 6dfa249 | 2019-10-01 17:20:39 -0700 | [diff] [blame] | 164 | mShouldScreenCallFurther = shouldScreenCallFurther; |
Sailesh Nepal | 1bef339 | 2016-01-24 18:21:53 -0800 | [diff] [blame] | 165 | } |
| 166 | |
| 167 | /* |
| 168 | * @return Whether the incoming call should be blocked. |
| 169 | */ |
| 170 | public boolean getDisallowCall() { |
| 171 | return mShouldDisallowCall; |
| 172 | } |
| 173 | |
| 174 | /* |
| 175 | * @return Whether the incoming call should be disconnected as if the user had manually |
| 176 | * rejected it. |
| 177 | */ |
| 178 | public boolean getRejectCall() { |
| 179 | return mShouldRejectCall; |
| 180 | } |
| 181 | |
| 182 | /* |
Usman Abdullah | 47b392d | 2019-03-06 15:54:56 -0800 | [diff] [blame] | 183 | * @return Whether the ringtone should be silenced for the incoming call. |
| 184 | */ |
| 185 | public boolean getSilenceCall() { |
| 186 | return mShouldSilenceCall; |
| 187 | } |
| 188 | |
| 189 | /* |
Sailesh Nepal | 1bef339 | 2016-01-24 18:21:53 -0800 | [diff] [blame] | 190 | * @return Whether the incoming call should not be displayed in the call log. |
| 191 | */ |
| 192 | public boolean getSkipCallLog() { |
| 193 | return mShouldSkipCallLog; |
| 194 | } |
| 195 | |
| 196 | /* |
| 197 | * @return Whether a missed call notification should not be shown for the incoming call. |
| 198 | */ |
| 199 | public boolean getSkipNotification() { |
| 200 | return mShouldSkipNotification; |
| 201 | } |
| 202 | |
Hall Liu | 6dfa249 | 2019-10-01 17:20:39 -0700 | [diff] [blame] | 203 | /** |
| 204 | * @return Whether we should enter the {@link Call#STATE_AUDIO_PROCESSING} state to allow |
| 205 | * for further screening of the call. |
| 206 | * @hide |
| 207 | */ |
| 208 | public boolean getShouldScreenCallFurther() { |
| 209 | return mShouldScreenCallFurther; |
| 210 | } |
| 211 | |
Sailesh Nepal | f446071 | 2016-01-27 16:45:51 -0800 | [diff] [blame] | 212 | public static class Builder { |
Sailesh Nepal | 1bef339 | 2016-01-24 18:21:53 -0800 | [diff] [blame] | 213 | private boolean mShouldDisallowCall; |
| 214 | private boolean mShouldRejectCall; |
Usman Abdullah | 47b392d | 2019-03-06 15:54:56 -0800 | [diff] [blame] | 215 | private boolean mShouldSilenceCall; |
Sailesh Nepal | 1bef339 | 2016-01-24 18:21:53 -0800 | [diff] [blame] | 216 | private boolean mShouldSkipCallLog; |
| 217 | private boolean mShouldSkipNotification; |
Hall Liu | 6dfa249 | 2019-10-01 17:20:39 -0700 | [diff] [blame] | 218 | private boolean mShouldScreenCallFurther; |
Sailesh Nepal | 1bef339 | 2016-01-24 18:21:53 -0800 | [diff] [blame] | 219 | |
Tyler Gunn | e0caec7 | 2018-11-30 14:21:18 -0800 | [diff] [blame] | 220 | /** |
Sailesh Nepal | 1bef339 | 2016-01-24 18:21:53 -0800 | [diff] [blame] | 221 | * Sets whether the incoming call should be blocked. |
| 222 | */ |
| 223 | public Builder setDisallowCall(boolean shouldDisallowCall) { |
| 224 | mShouldDisallowCall = shouldDisallowCall; |
| 225 | return this; |
| 226 | } |
| 227 | |
Tyler Gunn | e0caec7 | 2018-11-30 14:21:18 -0800 | [diff] [blame] | 228 | /** |
Sailesh Nepal | 1bef339 | 2016-01-24 18:21:53 -0800 | [diff] [blame] | 229 | * Sets whether the incoming call should be disconnected as if the user had manually |
| 230 | * rejected it. This property should only be set to true if the call is disallowed. |
| 231 | */ |
| 232 | public Builder setRejectCall(boolean shouldRejectCall) { |
| 233 | mShouldRejectCall = shouldRejectCall; |
| 234 | return this; |
| 235 | } |
| 236 | |
Tyler Gunn | e0caec7 | 2018-11-30 14:21:18 -0800 | [diff] [blame] | 237 | /** |
Usman Abdullah | 47b392d | 2019-03-06 15:54:56 -0800 | [diff] [blame] | 238 | * Sets whether ringing should be silenced for the incoming call. When set |
| 239 | * to {@code true}, the Telecom framework will not play a ringtone for the call. |
| 240 | * The call will, however, still be sent to the default dialer app if it is not blocked. |
| 241 | * A {@link CallScreeningService} can use this to ensure a potential nuisance call is |
| 242 | * still surfaced to the user, but in a less intrusive manner. |
| 243 | * |
| 244 | * Setting this to true only makes sense when the call has not been disallowed |
| 245 | * using {@link #setDisallowCall(boolean)}. |
| 246 | */ |
| 247 | public @NonNull Builder setSilenceCall(boolean shouldSilenceCall) { |
| 248 | mShouldSilenceCall = shouldSilenceCall; |
| 249 | return this; |
| 250 | } |
| 251 | |
| 252 | /** |
Sailesh Nepal | 1bef339 | 2016-01-24 18:21:53 -0800 | [diff] [blame] | 253 | * Sets whether the incoming call should not be displayed in the call log. This property |
| 254 | * should only be set to true if the call is disallowed. |
Tyler Gunn | e0caec7 | 2018-11-30 14:21:18 -0800 | [diff] [blame] | 255 | * <p> |
| 256 | * Note: Calls will still be logged with type |
| 257 | * {@link android.provider.CallLog.Calls#BLOCKED_TYPE}, regardless of how this property |
| 258 | * is set. |
Sailesh Nepal | 1bef339 | 2016-01-24 18:21:53 -0800 | [diff] [blame] | 259 | */ |
| 260 | public Builder setSkipCallLog(boolean shouldSkipCallLog) { |
| 261 | mShouldSkipCallLog = shouldSkipCallLog; |
| 262 | return this; |
| 263 | } |
| 264 | |
Tyler Gunn | e0caec7 | 2018-11-30 14:21:18 -0800 | [diff] [blame] | 265 | /** |
Sailesh Nepal | 1bef339 | 2016-01-24 18:21:53 -0800 | [diff] [blame] | 266 | * Sets whether a missed call notification should not be shown for the incoming call. |
| 267 | * This property should only be set to true if the call is disallowed. |
| 268 | */ |
| 269 | public Builder setSkipNotification(boolean shouldSkipNotification) { |
| 270 | mShouldSkipNotification = shouldSkipNotification; |
| 271 | return this; |
| 272 | } |
| 273 | |
Hall Liu | 6dfa249 | 2019-10-01 17:20:39 -0700 | [diff] [blame] | 274 | /** |
| 275 | * Sets whether to request background audio processing so that the in-call service can |
| 276 | * screen the call further. If set to {@code true}, {@link #setDisallowCall} should be |
| 277 | * called with {@code false}, and all other parameters in this builder will be ignored. |
| 278 | * |
| 279 | * This request will only be honored if the {@link CallScreeningService} shares the same |
| 280 | * uid as the default dialer app. Otherwise, the call will go through as usual. |
| 281 | * |
| 282 | * @param shouldScreenCallFurther Whether to request further call screening. |
| 283 | * @hide |
| 284 | */ |
| 285 | @SystemApi |
| 286 | @TestApi |
| 287 | public Builder setShouldScreenCallFurther(boolean shouldScreenCallFurther) { |
| 288 | mShouldScreenCallFurther = shouldScreenCallFurther; |
| 289 | return this; |
| 290 | } |
| 291 | |
Sailesh Nepal | 1bef339 | 2016-01-24 18:21:53 -0800 | [diff] [blame] | 292 | public CallResponse build() { |
| 293 | return new CallResponse( |
| 294 | mShouldDisallowCall, |
| 295 | mShouldRejectCall, |
Usman Abdullah | 47b392d | 2019-03-06 15:54:56 -0800 | [diff] [blame] | 296 | mShouldSilenceCall, |
Sailesh Nepal | 1bef339 | 2016-01-24 18:21:53 -0800 | [diff] [blame] | 297 | mShouldSkipCallLog, |
Hall Liu | 6dfa249 | 2019-10-01 17:20:39 -0700 | [diff] [blame] | 298 | mShouldSkipNotification, |
| 299 | mShouldScreenCallFurther); |
Sailesh Nepal | 1bef339 | 2016-01-24 18:21:53 -0800 | [diff] [blame] | 300 | } |
| 301 | } |
| 302 | } |
| 303 | |
| 304 | public CallScreeningService() { |
| 305 | } |
| 306 | |
| 307 | @Override |
| 308 | public IBinder onBind(Intent intent) { |
| 309 | Log.v(this, "onBind"); |
| 310 | return new CallScreeningBinder(); |
| 311 | } |
| 312 | |
| 313 | @Override |
| 314 | public boolean onUnbind(Intent intent) { |
| 315 | Log.v(this, "onUnbind"); |
| 316 | return false; |
| 317 | } |
| 318 | |
| 319 | /** |
Tyler Gunn | 9e76fd19b | 2018-12-17 09:56:11 -0800 | [diff] [blame] | 320 | * Called when a new incoming or outgoing call is added which is not in the user's contact list. |
| 321 | * <p> |
| 322 | * A {@link CallScreeningService} must indicate whether an incoming call is allowed or not by |
| 323 | * calling |
| 324 | * {@link CallScreeningService#respondToCall(Call.Details, CallScreeningService.CallResponse)}. |
| 325 | * Your app can tell if a call is an incoming call by checking to see if |
| 326 | * {@link Call.Details#getCallDirection()} is {@link Call.Details#DIRECTION_INCOMING}. |
| 327 | * <p> |
Tyler Gunn | e0caec7 | 2018-11-30 14:21:18 -0800 | [diff] [blame] | 328 | * Note: The {@link Call.Details} instance provided to a call screening service will only have |
| 329 | * the following properties set. The rest of the {@link Call.Details} properties will be set to |
| 330 | * their default value or {@code null}. |
| 331 | * <ul> |
Tyler Gunn | 9e76fd19b | 2018-12-17 09:56:11 -0800 | [diff] [blame] | 332 | * <li>{@link Call.Details#getCallDirection()}</li> |
Tyler Gunn | e0caec7 | 2018-11-30 14:21:18 -0800 | [diff] [blame] | 333 | * <li>{@link Call.Details#getConnectTimeMillis()}</li> |
| 334 | * <li>{@link Call.Details#getCreationTimeMillis()}</li> |
| 335 | * <li>{@link Call.Details#getHandle()}</li> |
| 336 | * <li>{@link Call.Details#getHandlePresentation()}</li> |
| 337 | * </ul> |
Tyler Gunn | 9e76fd19b | 2018-12-17 09:56:11 -0800 | [diff] [blame] | 338 | * <p> |
| 339 | * Only calls where the {@link Call.Details#getHandle() handle} {@link Uri#getScheme() scheme} |
| 340 | * is {@link PhoneAccount#SCHEME_TEL} are passed for call |
| 341 | * screening. Further, only calls which are not in the user's contacts are passed for |
| 342 | * screening. For outgoing calls, no post-dial digits are passed. |
Sailesh Nepal | 1bef339 | 2016-01-24 18:21:53 -0800 | [diff] [blame] | 343 | * |
Tyler Gunn | 9e76fd19b | 2018-12-17 09:56:11 -0800 | [diff] [blame] | 344 | * @param callDetails Information about a new call, see {@link Call.Details}. |
Sailesh Nepal | 1bef339 | 2016-01-24 18:21:53 -0800 | [diff] [blame] | 345 | */ |
Tyler Gunn | 7e45b72 | 2018-12-04 12:56:45 -0800 | [diff] [blame] | 346 | public abstract void onScreenCall(@NonNull Call.Details callDetails); |
Sailesh Nepal | 1bef339 | 2016-01-24 18:21:53 -0800 | [diff] [blame] | 347 | |
| 348 | /** |
Usman Abdullah | 47b392d | 2019-03-06 15:54:56 -0800 | [diff] [blame] | 349 | * 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] | 350 | * <p> |
| 351 | * 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] | 352 | * should be silently blocked or not. In the event that it should not be blocked, it may |
| 353 | * also be requested to ring silently. |
Tyler Gunn | 9e76fd19b | 2018-12-17 09:56:11 -0800 | [diff] [blame] | 354 | * <p> |
| 355 | * Calls to this method are ignored unless the {@link Call.Details#getCallDirection()} is |
| 356 | * {@link Call.Details#DIRECTION_INCOMING}. |
Sailesh Nepal | 1bef339 | 2016-01-24 18:21:53 -0800 | [diff] [blame] | 357 | * |
| 358 | * @param callDetails The call to allow. |
Tyler Gunn | 7e45b72 | 2018-12-04 12:56:45 -0800 | [diff] [blame] | 359 | * <p> |
| 360 | * Must be the same {@link Call.Details call} which was provided to the |
| 361 | * {@link CallScreeningService} via {@link #onScreenCall(Call.Details)}. |
Sailesh Nepal | 1bef339 | 2016-01-24 18:21:53 -0800 | [diff] [blame] | 362 | * @param response The {@link CallScreeningService.CallResponse} which contains information |
| 363 | * about how to respond to a call. |
| 364 | */ |
Tyler Gunn | 7e45b72 | 2018-12-04 12:56:45 -0800 | [diff] [blame] | 365 | public final void respondToCall(@NonNull Call.Details callDetails, |
| 366 | @NonNull CallResponse response) { |
Sailesh Nepal | 1bef339 | 2016-01-24 18:21:53 -0800 | [diff] [blame] | 367 | try { |
| 368 | if (response.getDisallowCall()) { |
| 369 | mCallScreeningAdapter.disallowCall( |
| 370 | callDetails.getTelecomCallId(), |
| 371 | response.getRejectCall(), |
| 372 | !response.getSkipCallLog(), |
tonyzhu | 9e1d4f8 | 2018-10-22 15:11:31 +0800 | [diff] [blame] | 373 | !response.getSkipNotification(), |
| 374 | new ComponentName(getPackageName(), getClass().getName())); |
Usman Abdullah | 47b392d | 2019-03-06 15:54:56 -0800 | [diff] [blame] | 375 | } else if (response.getSilenceCall()) { |
| 376 | mCallScreeningAdapter.silenceCall(callDetails.getTelecomCallId()); |
Sailesh Nepal | 1bef339 | 2016-01-24 18:21:53 -0800 | [diff] [blame] | 377 | } else { |
| 378 | mCallScreeningAdapter.allowCall(callDetails.getTelecomCallId()); |
| 379 | } |
| 380 | } catch (RemoteException e) { |
| 381 | } |
| 382 | } |
Sailesh Nepal | 1bef339 | 2016-01-24 18:21:53 -0800 | [diff] [blame] | 383 | } |