1 /* 2 * Copyright (C) 2014 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 * in compliance with the License. You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software distributed under the License 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 * or implied. See the License for the specific language governing permissions and limitations under 12 * the License. 13 */ 14 15 package android.telecom; 16 17 import static android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE; 18 19 import android.Manifest; 20 import android.annotation.IntDef; 21 import android.annotation.NonNull; 22 import android.annotation.Nullable; 23 import android.annotation.RequiresPermission; 24 import android.annotation.SuppressAutoDoc; 25 import android.annotation.SuppressLint; 26 import android.annotation.SystemApi; 27 import android.annotation.SystemService; 28 import android.annotation.TestApi; 29 import android.compat.annotation.UnsupportedAppUsage; 30 import android.content.ComponentName; 31 import android.content.Context; 32 import android.content.Intent; 33 import android.net.Uri; 34 import android.os.Build; 35 import android.os.Bundle; 36 import android.os.RemoteException; 37 import android.os.ServiceManager; 38 import android.os.UserHandle; 39 import android.telephony.Annotation.CallState; 40 import android.telephony.SubscriptionManager; 41 import android.telephony.TelephonyManager; 42 import android.text.TextUtils; 43 import android.util.Log; 44 45 import com.android.internal.telecom.ITelecomService; 46 47 import java.lang.annotation.Retention; 48 import java.lang.annotation.RetentionPolicy; 49 import java.util.ArrayList; 50 import java.util.Collections; 51 import java.util.List; 52 import java.util.concurrent.Executor; 53 54 /** 55 * Provides access to information about active calls and registration/call-management functionality. 56 * Apps can use methods in this class to determine the current call state. 57 * <p> 58 * Apps do not instantiate this class directly; instead, they retrieve a reference to an instance 59 * through {@link Context#getSystemService Context.getSystemService(Context.TELECOM_SERVICE)}. 60 * <p> 61 * Note that access to some telecom information is permission-protected. Your app cannot access the 62 * protected information or gain access to protected functionality unless it has the appropriate 63 * permissions declared in its manifest file. Where permissions apply, they are noted in the method 64 * descriptions. 65 */ 66 @SuppressAutoDoc 67 @SystemService(Context.TELECOM_SERVICE) 68 public class TelecomManager { 69 70 /** 71 * Activity action: Starts the UI for handing an incoming call. This intent starts the in-call 72 * UI by notifying the Telecom system that an incoming call exists for a specific call service 73 * (see {@link android.telecom.ConnectionService}). Telecom reads the Intent extras to find 74 * and bind to the appropriate {@link android.telecom.ConnectionService} which Telecom will 75 * ultimately use to control and get information about the call. 76 * <p> 77 * Input: get*Extra field {@link #EXTRA_PHONE_ACCOUNT_HANDLE} contains the component name of the 78 * {@link android.telecom.ConnectionService} that Telecom should bind to. Telecom will then 79 * ask the connection service for more information about the call prior to showing any UI. 80 * 81 * @deprecated Use {@link #addNewIncomingCall} instead. 82 */ 83 public static final String ACTION_INCOMING_CALL = "android.telecom.action.INCOMING_CALL"; 84 85 /** 86 * Similar to {@link #ACTION_INCOMING_CALL}, but is used only by Telephony to add a new 87 * sim-initiated MO call for carrier testing. 88 * @deprecated Use {@link #addNewUnknownCall} instead. 89 * @hide 90 */ 91 public static final String ACTION_NEW_UNKNOWN_CALL = "android.telecom.action.NEW_UNKNOWN_CALL"; 92 93 /** 94 * An {@link android.content.Intent} action sent by the telecom framework to start a 95 * configuration dialog for a registered {@link PhoneAccount}. There is no default dialog 96 * and each app that registers a {@link PhoneAccount} should provide one if desired. 97 * <p> 98 * A user can access the list of enabled {@link android.telecom.PhoneAccount}s through the Phone 99 * app's settings menu. For each entry, the settings app will add a click action. When 100 * triggered, the click-action will start this intent along with the extra 101 * {@link #EXTRA_PHONE_ACCOUNT_HANDLE} to indicate the {@link PhoneAccount} to configure. If the 102 * {@link PhoneAccount} package does not register an {@link android.app.Activity} for this 103 * intent, then it will not be sent. 104 */ 105 public static final String ACTION_CONFIGURE_PHONE_ACCOUNT = 106 "android.telecom.action.CONFIGURE_PHONE_ACCOUNT"; 107 108 /** 109 * The {@link android.content.Intent} action used to show the call accessibility settings page. 110 */ 111 public static final String ACTION_SHOW_CALL_ACCESSIBILITY_SETTINGS = 112 "android.telecom.action.SHOW_CALL_ACCESSIBILITY_SETTINGS"; 113 114 /** 115 * The {@link android.content.Intent} action used to show the call settings page. 116 */ 117 public static final String ACTION_SHOW_CALL_SETTINGS = 118 "android.telecom.action.SHOW_CALL_SETTINGS"; 119 120 /** 121 * The {@link android.content.Intent} action used to show the respond via SMS settings page. 122 */ 123 public static final String ACTION_SHOW_RESPOND_VIA_SMS_SETTINGS = 124 "android.telecom.action.SHOW_RESPOND_VIA_SMS_SETTINGS"; 125 126 /** 127 * The {@link android.content.Intent} action used to show the settings page used to configure 128 * {@link PhoneAccount} preferences. 129 */ 130 public static final String ACTION_CHANGE_PHONE_ACCOUNTS = 131 "android.telecom.action.CHANGE_PHONE_ACCOUNTS"; 132 133 /** 134 * {@link android.content.Intent} action used indicate that a new phone account was just 135 * registered. 136 * <p> 137 * The Intent {@link Intent#getExtras() extras} will contain {@link #EXTRA_PHONE_ACCOUNT_HANDLE} 138 * to indicate which {@link PhoneAccount} was registered. 139 * <p> 140 * Will only be sent to the default dialer app (see {@link #getDefaultDialerPackage()}). 141 */ 142 public static final String ACTION_PHONE_ACCOUNT_REGISTERED = 143 "android.telecom.action.PHONE_ACCOUNT_REGISTERED"; 144 145 /** 146 * {@link android.content.Intent} action used indicate that a phone account was just 147 * unregistered. 148 * <p> 149 * The Intent {@link Intent#getExtras() extras} will contain {@link #EXTRA_PHONE_ACCOUNT_HANDLE} 150 * to indicate which {@link PhoneAccount} was unregistered. 151 * <p> 152 * Will only be sent to the default dialer app (see {@link #getDefaultDialerPackage()}). 153 */ 154 public static final String ACTION_PHONE_ACCOUNT_UNREGISTERED = 155 "android.telecom.action.PHONE_ACCOUNT_UNREGISTERED"; 156 157 /** 158 * Activity action: Shows a dialog asking the user whether or not they want to replace the 159 * current default Dialer with the one specified in 160 * {@link #EXTRA_CHANGE_DEFAULT_DIALER_PACKAGE_NAME}. 161 * 162 * Usage example: 163 * <pre> 164 * Intent intent = new Intent(TelecomManager.ACTION_CHANGE_DEFAULT_DIALER); 165 * intent.putExtra(TelecomManager.EXTRA_CHANGE_DEFAULT_DIALER_PACKAGE_NAME, 166 * getActivity().getPackageName()); 167 * startActivity(intent); 168 * </pre> 169 * <p> 170 * This is no longer supported since Q, please use 171 * {@link android.app.role.RoleManager#createRequestRoleIntent(String)} with 172 * {@link android.app.role.RoleManager#ROLE_DIALER} instead. 173 */ 174 public static final String ACTION_CHANGE_DEFAULT_DIALER = 175 "android.telecom.action.CHANGE_DEFAULT_DIALER"; 176 177 /** 178 * Broadcast intent action indicating that the current default dialer has changed. 179 * The string extra {@link #EXTRA_CHANGE_DEFAULT_DIALER_PACKAGE_NAME} will contain the 180 * name of the package that the default dialer was changed to. 181 * 182 * @see #EXTRA_CHANGE_DEFAULT_DIALER_PACKAGE_NAME 183 */ 184 public static final String ACTION_DEFAULT_DIALER_CHANGED = 185 "android.telecom.action.DEFAULT_DIALER_CHANGED"; 186 187 /** 188 * Extra value used to provide the package name for {@link #ACTION_CHANGE_DEFAULT_DIALER}. 189 */ 190 public static final String EXTRA_CHANGE_DEFAULT_DIALER_PACKAGE_NAME = 191 "android.telecom.extra.CHANGE_DEFAULT_DIALER_PACKAGE_NAME"; 192 193 /** 194 * Broadcast intent action indicating that the current default call screening app has changed. 195 * <p> 196 * Note: This intent is NEVER actually broadcast and will be deprecated in the future. 197 * <p> 198 * An app that want to know if it holds the 199 * {@link android.app.role.RoleManager#ROLE_CALL_SCREENING} role can use 200 * {@link android.app.role.RoleManager#isRoleHeld(String)} to confirm if it holds the role or 201 * not. 202 */ 203 public static final String ACTION_DEFAULT_CALL_SCREENING_APP_CHANGED = 204 "android.telecom.action.DEFAULT_CALL_SCREENING_APP_CHANGED"; 205 206 /** 207 * Extra value used with {@link #ACTION_DEFAULT_CALL_SCREENING_APP_CHANGED} broadcast to 208 * indicate the ComponentName of the call screening app which has changed. 209 * <p> 210 * Note: This extra is NOT used and will be deprecated in the future. 211 */ 212 public static final String EXTRA_DEFAULT_CALL_SCREENING_APP_COMPONENT_NAME = 213 "android.telecom.extra.DEFAULT_CALL_SCREENING_APP_COMPONENT_NAME"; 214 215 /** 216 * Extra value used with {@link #ACTION_DEFAULT_CALL_SCREENING_APP_CHANGED} broadcast to 217 * indicate whether an app is the default call screening app. 218 * <p> 219 * Note: This extra is NOT used and will be deprecated in the future. 220 */ 221 public static final String EXTRA_IS_DEFAULT_CALL_SCREENING_APP = 222 "android.telecom.extra.IS_DEFAULT_CALL_SCREENING_APP"; 223 224 /** 225 * Optional extra for {@link android.content.Intent#ACTION_CALL} containing a boolean that 226 * determines whether the speakerphone should be automatically turned on for an outgoing call. 227 */ 228 public static final String EXTRA_START_CALL_WITH_SPEAKERPHONE = 229 "android.telecom.extra.START_CALL_WITH_SPEAKERPHONE"; 230 231 /** 232 * Optional extra for {@link android.content.Intent#ACTION_CALL} containing an integer that 233 * determines the desired video state for an outgoing call. 234 * Valid options: 235 * {@link VideoProfile#STATE_AUDIO_ONLY}, 236 * {@link VideoProfile#STATE_BIDIRECTIONAL}, 237 * {@link VideoProfile#STATE_RX_ENABLED}, 238 * {@link VideoProfile#STATE_TX_ENABLED}. 239 */ 240 public static final String EXTRA_START_CALL_WITH_VIDEO_STATE = 241 "android.telecom.extra.START_CALL_WITH_VIDEO_STATE"; 242 243 /** 244 * Optional extra for {@link #addNewIncomingCall(PhoneAccountHandle, Bundle)} containing an 245 * integer that determines the requested video state for an incoming call. 246 * Valid options: 247 * {@link VideoProfile#STATE_AUDIO_ONLY}, 248 * {@link VideoProfile#STATE_BIDIRECTIONAL}, 249 * {@link VideoProfile#STATE_RX_ENABLED}, 250 * {@link VideoProfile#STATE_TX_ENABLED}. 251 */ 252 public static final String EXTRA_INCOMING_VIDEO_STATE = 253 "android.telecom.extra.INCOMING_VIDEO_STATE"; 254 255 /** 256 * The extra used with an {@link android.content.Intent#ACTION_CALL} and 257 * {@link android.content.Intent#ACTION_DIAL} {@code Intent} to specify a 258 * {@link PhoneAccountHandle} to use when making the call. 259 * <p class="note"> 260 * Retrieve with {@link android.content.Intent#getParcelableExtra(String)}. 261 */ 262 public static final String EXTRA_PHONE_ACCOUNT_HANDLE = 263 "android.telecom.extra.PHONE_ACCOUNT_HANDLE"; 264 265 /** 266 * Optional extra for {@link android.content.Intent#ACTION_CALL} containing a string call 267 * subject which will be associated with an outgoing call. Should only be specified if the 268 * {@link PhoneAccount} supports the capability {@link PhoneAccount#CAPABILITY_CALL_SUBJECT}. 269 */ 270 public static final String EXTRA_CALL_SUBJECT = "android.telecom.extra.CALL_SUBJECT"; 271 272 /** 273 * The extra used by a {@link ConnectionService} to provide the handle of the caller that 274 * has initiated a new incoming call. 275 */ 276 public static final String EXTRA_INCOMING_CALL_ADDRESS = 277 "android.telecom.extra.INCOMING_CALL_ADDRESS"; 278 279 /** 280 * Optional extra for {@link #ACTION_INCOMING_CALL} containing a {@link Bundle} which contains 281 * metadata about the call. This {@link Bundle} will be returned to the 282 * {@link ConnectionService}. 283 */ 284 public static final String EXTRA_INCOMING_CALL_EXTRAS = 285 "android.telecom.extra.INCOMING_CALL_EXTRAS"; 286 287 /** 288 * Optional extra for {@link #ACTION_INCOMING_CALL} containing a boolean to indicate that the 289 * call has an externally generated ringer. Used by the HfpClientConnectionService when In Band 290 * Ringtone is enabled to prevent two ringers from being generated. 291 * @hide 292 */ 293 public static final String EXTRA_CALL_EXTERNAL_RINGER = 294 "android.telecom.extra.CALL_EXTERNAL_RINGER"; 295 296 /** 297 * Optional extra for {@link android.content.Intent#ACTION_CALL} and 298 * {@link android.content.Intent#ACTION_DIAL} {@code Intent} containing a {@link Bundle} 299 * which contains metadata about the call. This {@link Bundle} will be saved into 300 * {@code Call.Details} and passed to the {@link ConnectionService} when placing the call. 301 */ 302 public static final String EXTRA_OUTGOING_CALL_EXTRAS = 303 "android.telecom.extra.OUTGOING_CALL_EXTRAS"; 304 305 /** 306 * An optional boolean extra on {@link android.content.Intent#ACTION_CALL_EMERGENCY} to tell 307 * whether the user's dial intent is emergency; this is required to specify when the dialed 308 * number is ambiguous, identified as both emergency number and any other non-emergency number; 309 * e.g. in some situation, 611 could be both an emergency number in a country and a 310 * non-emergency number of a carrier's customer service hotline. 311 * 312 * @hide 313 */ 314 @SystemApi 315 public static final String EXTRA_IS_USER_INTENT_EMERGENCY_CALL = 316 "android.telecom.extra.IS_USER_INTENT_EMERGENCY_CALL"; 317 318 /** 319 * A mandatory extra containing a {@link Uri} to be passed in when calling 320 * {@link #addNewUnknownCall(PhoneAccountHandle, Bundle)}. The {@link Uri} value indicates 321 * the remote handle of the new call. 322 * @hide 323 */ 324 public static final String EXTRA_UNKNOWN_CALL_HANDLE = 325 "android.telecom.extra.UNKNOWN_CALL_HANDLE"; 326 327 /** 328 * Optional extra for incoming and outgoing calls containing a long which specifies the time the 329 * call was created. This value is in milliseconds since boot. 330 * @hide 331 */ 332 public static final String EXTRA_CALL_CREATED_TIME_MILLIS = 333 "android.telecom.extra.CALL_CREATED_TIME_MILLIS"; 334 335 /** 336 * Optional extra for incoming and outgoing calls containing a long which specifies the Epoch 337 * time the call was created. 338 * @hide 339 */ 340 public static final String EXTRA_CALL_CREATED_EPOCH_TIME_MILLIS = 341 "android.telecom.extra.CALL_CREATED_EPOCH_TIME_MILLIS"; 342 343 /** 344 * Optional extra for incoming and outgoing calls containing a long which specifies the time 345 * telecom began routing the call. This value is in milliseconds since boot. 346 * @hide 347 */ 348 public static final String EXTRA_CALL_TELECOM_ROUTING_START_TIME_MILLIS = 349 "android.telecom.extra.CALL_TELECOM_ROUTING_START_TIME_MILLIS"; 350 351 /** 352 * Optional extra for incoming and outgoing calls containing a long which specifies the time 353 * telecom finished routing the call. This value is in milliseconds since boot. 354 * @hide 355 */ 356 public static final String EXTRA_CALL_TELECOM_ROUTING_END_TIME_MILLIS = 357 "android.telecom.extra.CALL_TELECOM_ROUTING_END_TIME_MILLIS"; 358 359 /** 360 * Optional extra for {@link android.telephony.TelephonyManager#ACTION_PHONE_STATE_CHANGED} 361 * containing the disconnect code. 362 */ 363 public static final String EXTRA_CALL_DISCONNECT_CAUSE = 364 "android.telecom.extra.CALL_DISCONNECT_CAUSE"; 365 366 /** 367 * Optional extra for {@link android.telephony.TelephonyManager#ACTION_PHONE_STATE_CHANGED} 368 * containing the disconnect message. 369 */ 370 public static final String EXTRA_CALL_DISCONNECT_MESSAGE = 371 "android.telecom.extra.CALL_DISCONNECT_MESSAGE"; 372 373 /** 374 * Optional extra for {@link android.telephony.TelephonyManager#ACTION_PHONE_STATE_CHANGED} 375 * containing the component name of the associated connection service. 376 * @hide 377 */ 378 @SystemApi 379 public static final String EXTRA_CONNECTION_SERVICE = 380 "android.telecom.extra.CONNECTION_SERVICE"; 381 382 /** 383 * Optional extra for communicating the call technology used by a {@link ConnectionService} 384 * to Telecom. Valid values are: 385 * <ul> 386 * <li>{@link TelephonyManager#PHONE_TYPE_CDMA}</li> 387 * <li>{@link TelephonyManager#PHONE_TYPE_GSM}</li> 388 * <li>{@link TelephonyManager#PHONE_TYPE_IMS}</li> 389 * <li>{@link TelephonyManager#PHONE_TYPE_THIRD_PARTY}</li> 390 * <li>{@link TelephonyManager#PHONE_TYPE_SIP}</li> 391 * </ul> 392 * @hide 393 */ 394 public static final String EXTRA_CALL_TECHNOLOGY_TYPE = 395 "android.telecom.extra.CALL_TECHNOLOGY_TYPE"; 396 397 /** 398 * Optional extra for communicating the call network technology used by a 399 * {@link android.telecom.Connection} to Telecom and InCallUI. 400 * 401 * {@code NETWORK_TYPE_*} in {@link android.telephony.TelephonyManager}. 402 */ 403 public static final String EXTRA_CALL_NETWORK_TYPE = 404 "android.telecom.extra.CALL_NETWORK_TYPE"; 405 406 /** 407 * An optional {@link android.content.Intent#ACTION_CALL} intent extra denoting the 408 * package name of the app specifying an alternative gateway for the call. 409 * The value is a string. 410 * 411 * (The following comment corresponds to the all GATEWAY_* extras) 412 * An app which sends the {@link android.content.Intent#ACTION_CALL} intent can specify an 413 * alternative address to dial which is different from the one specified and displayed to 414 * the user. This alternative address is referred to as the gateway address. 415 */ 416 public static final String GATEWAY_PROVIDER_PACKAGE = 417 "android.telecom.extra.GATEWAY_PROVIDER_PACKAGE"; 418 419 /** 420 * An optional {@link android.content.Intent#ACTION_CALL} intent extra corresponding to the 421 * original address to dial for the call. This is used when an alternative gateway address is 422 * provided to recall the original address. 423 * The value is a {@link android.net.Uri}. 424 * 425 * (See {@link #GATEWAY_PROVIDER_PACKAGE} for details) 426 */ 427 public static final String GATEWAY_ORIGINAL_ADDRESS = 428 "android.telecom.extra.GATEWAY_ORIGINAL_ADDRESS"; 429 430 /** 431 * The number which the party on the other side of the line will see (and use to return the 432 * call). 433 * <p> 434 * {@link ConnectionService}s which interact with {@link RemoteConnection}s should only populate 435 * this if the {@link android.telephony.TelephonyManager#getLine1Number()} value, as that is the 436 * user's expected caller ID. 437 */ 438 public static final String EXTRA_CALL_BACK_NUMBER = "android.telecom.extra.CALL_BACK_NUMBER"; 439 440 /** 441 * The number of milliseconds that Telecom should wait after disconnecting a call via the 442 * ACTION_NEW_OUTGOING_CALL broadcast, in order to wait for the app which cancelled the call 443 * to make a new one. 444 * @hide 445 */ 446 public static final String EXTRA_NEW_OUTGOING_CALL_CANCEL_TIMEOUT = 447 "android.telecom.extra.NEW_OUTGOING_CALL_CANCEL_TIMEOUT"; 448 449 /** 450 * Boolean extra specified to indicate that the intention of adding a call is to handover an 451 * existing call from the user's device to a different {@link PhoneAccount}. 452 * <p> 453 * Used when calling {@link #addNewIncomingCall(PhoneAccountHandle, Bundle)} 454 * to indicate to Telecom that the purpose of adding a new incoming call is to handover an 455 * existing call from the user's device to a different {@link PhoneAccount}. This occurs on 456 * the receiving side of a handover. 457 * <p> 458 * Used when Telecom calls 459 * {@link ConnectionService#onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)} 460 * to indicate that the purpose of Telecom requesting a new outgoing connection it to request 461 * a handover to this {@link ConnectionService} from an ongoing call on the user's device. This 462 * occurs on the initiating side of a handover. 463 * <p> 464 * The phone number of the call used by Telecom to determine which call should be handed over. 465 * @hide 466 * @deprecated Use the public handover APIs. See 467 * {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} for more information. 468 */ 469 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 119305590) 470 public static final String EXTRA_IS_HANDOVER = "android.telecom.extra.IS_HANDOVER"; 471 472 /** 473 * When {@code true} indicates that a request to create a new connection is for the purpose of 474 * a handover. Note: This is used with the 475 * {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int, Bundle)} API as part of the 476 * internal communication mechanism with the {@link android.telecom.ConnectionService}. It is 477 * not the same as the legacy {@link #EXTRA_IS_HANDOVER} extra. 478 * @hide 479 */ 480 public static final String EXTRA_IS_HANDOVER_CONNECTION = 481 "android.telecom.extra.IS_HANDOVER_CONNECTION"; 482 483 /** 484 * Parcelable extra used with {@link #EXTRA_IS_HANDOVER} to indicate the source 485 * {@link PhoneAccountHandle} when initiating a handover which {@link ConnectionService} 486 * the handover is from. 487 * @hide 488 */ 489 public static final String EXTRA_HANDOVER_FROM_PHONE_ACCOUNT = 490 "android.telecom.extra.HANDOVER_FROM_PHONE_ACCOUNT"; 491 492 /** 493 * Extra key specified in the {@link ConnectionRequest#getExtras()} when Telecom calls 494 * {@link ConnectionService#onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)} 495 * to inform the {@link ConnectionService} what the initial {@link CallAudioState} of the 496 * {@link Connection} will be. 497 * @hide 498 */ 499 public static final String EXTRA_CALL_AUDIO_STATE = "android.telecom.extra.CALL_AUDIO_STATE"; 500 501 /** 502 * A boolean extra, which when set on the {@link Intent#ACTION_CALL} intent or on the bundle 503 * passed into {@link #placeCall(Uri, Bundle)}, indicates that the call should be initiated with 504 * an RTT session open. See {@link android.telecom.Call.RttCall} for more information on RTT. 505 */ 506 public static final String EXTRA_START_CALL_WITH_RTT = 507 "android.telecom.extra.START_CALL_WITH_RTT"; 508 509 /** 510 * Start an activity indicating that the completion of an outgoing call or an incoming call 511 * which was not blocked by the {@link CallScreeningService}, and which was NOT terminated 512 * while the call was in {@link Call#STATE_AUDIO_PROCESSING}. 513 * 514 * The {@link Uri} extra {@link #EXTRA_HANDLE} will contain the uri handle(phone number) for the 515 * call which completed. 516 * 517 * The integer extra {@link #EXTRA_DISCONNECT_CAUSE} will indicate the reason for the call 518 * disconnection. See {@link #EXTRA_DISCONNECT_CAUSE} for more information. 519 * 520 * The integer extra {@link #EXTRA_CALL_DURATION} will indicate the duration of the call. See 521 * {@link #EXTRA_CALL_DURATION} for more information. 522 */ 523 public static final String ACTION_POST_CALL = "android.telecom.action.POST_CALL"; 524 525 /** 526 * A {@link Uri} extra, which when set on the {@link #ACTION_POST_CALL} intent, indicates the 527 * uri handle(phone number) of the completed call. 528 */ 529 public static final String EXTRA_HANDLE = "android.telecom.extra.HANDLE"; 530 531 /** 532 * A integer value provided for completed calls to indicate the reason for the call 533 * disconnection. 534 * <p> 535 * Allowed values: 536 * <ul> 537 * <li>{@link DisconnectCause#UNKNOWN}</li> 538 * <li>{@link DisconnectCause#LOCAL}</li> 539 * <li>{@link DisconnectCause#REMOTE}</li> 540 * <li>{@link DisconnectCause#REJECTED}</li> 541 * <li>{@link DisconnectCause#MISSED}</li> 542 * </ul> 543 * </p> 544 */ 545 public static final String EXTRA_DISCONNECT_CAUSE = "android.telecom.extra.DISCONNECT_CAUSE"; 546 547 /** 548 * A integer value provided for completed calls to indicate the duration of the call. 549 * <p> 550 * Allowed values: 551 * <ul> 552 * <li>{@link #DURATION_VERY_SHORT}</li> 553 * <li>{@link #DURATION_SHORT}</li> 554 * <li>{@link #DURATION_MEDIUM}</li> 555 * <li>{@link #DURATION_LONG}</li> 556 * </ul> 557 * </p> 558 */ 559 public static final String EXTRA_CALL_DURATION = "android.telecom.extra.CALL_DURATION"; 560 561 /** 562 * A integer value for {@link #EXTRA_CALL_DURATION}, indicates the duration of the completed 563 * call was < 3 seconds. 564 */ 565 public static final int DURATION_VERY_SHORT = 0; 566 567 /** 568 * A integer value for {@link #EXTRA_CALL_DURATION}, indicates the duration of the completed 569 * call was >= 3 seconds and < 60 seconds. 570 */ 571 public static final int DURATION_SHORT = 1; 572 573 /** 574 * A integer value for {@link #EXTRA_CALL_DURATION}, indicates the duration of the completed 575 * call was >= 60 seconds and < 120 seconds. 576 */ 577 public static final int DURATION_MEDIUM = 2; 578 579 /** 580 * A integer value for {@link #EXTRA_CALL_DURATION}, indicates the duration of the completed 581 * call was >= 120 seconds. 582 */ 583 public static final int DURATION_LONG = 3; 584 585 /** 586 * The threshold between {@link #DURATION_VERY_SHORT} calls and {@link #DURATION_SHORT} calls in 587 * milliseconds. 588 * @hide 589 */ 590 public static final long VERY_SHORT_CALL_TIME_MS = 3000; 591 592 /** 593 * The threshold between {@link #DURATION_SHORT} calls and {@link #DURATION_MEDIUM} calls in 594 * milliseconds. 595 * @hide 596 */ 597 public static final long SHORT_CALL_TIME_MS = 60000; 598 599 /** 600 * The threshold between {@link #DURATION_MEDIUM} calls and {@link #DURATION_LONG} calls in 601 * milliseconds. 602 * @hide 603 */ 604 public static final long MEDIUM_CALL_TIME_MS = 120000; 605 606 /** 607 * A boolean meta-data value indicating whether an {@link InCallService} implements an 608 * in-call user interface. Dialer implementations (see {@link #getDefaultDialerPackage()}) which 609 * would also like to replace the in-call interface should set this meta-data to {@code true} in 610 * the manifest registration of their {@link InCallService}. 611 */ 612 public static final String METADATA_IN_CALL_SERVICE_UI = "android.telecom.IN_CALL_SERVICE_UI"; 613 614 /** 615 * A boolean meta-data value indicating whether an {@link InCallService} implements an 616 * in-call user interface to be used while the device is in car-mode (see 617 * {@link android.content.res.Configuration#UI_MODE_TYPE_CAR}). 618 */ 619 public static final String METADATA_IN_CALL_SERVICE_CAR_MODE_UI = 620 "android.telecom.IN_CALL_SERVICE_CAR_MODE_UI"; 621 622 /** 623 * A boolean meta-data value indicating whether an {@link InCallService} implements ringing. 624 * Dialer implementations (see {@link #getDefaultDialerPackage()}) which would also like to 625 * override the system provided ringing should set this meta-data to {@code true} in the 626 * manifest registration of their {@link InCallService}. 627 * <p> 628 * When {@code true}, it is the {@link InCallService}'s responsibility to play a ringtone for 629 * all incoming calls. 630 */ 631 public static final String METADATA_IN_CALL_SERVICE_RINGING = 632 "android.telecom.IN_CALL_SERVICE_RINGING"; 633 634 /** 635 * A boolean meta-data value indicating whether an {@link InCallService} wants to be informed of 636 * calls which have the {@link Call.Details#PROPERTY_IS_EXTERNAL_CALL} property. An external 637 * call is one which a {@link ConnectionService} knows about, but is not connected to directly. 638 * Dialer implementations (see {@link #getDefaultDialerPackage()}) which would like to be 639 * informed of external calls should set this meta-data to {@code true} in the manifest 640 * registration of their {@link InCallService}. By default, the {@link InCallService} will NOT 641 * be informed of external calls. 642 */ 643 public static final String METADATA_INCLUDE_EXTERNAL_CALLS = 644 "android.telecom.INCLUDE_EXTERNAL_CALLS"; 645 646 /** 647 * A boolean meta-data value indicating whether an {@link InCallService} wants to be informed of 648 * calls which have the {@link Call.Details#PROPERTY_SELF_MANAGED} property. A self-managed 649 * call is one which originates from a self-managed {@link ConnectionService} which has chosen 650 * to implement its own call user interface. An {@link InCallService} implementation which 651 * would like to be informed of external calls should set this meta-data to {@code true} in the 652 * manifest registration of their {@link InCallService}. By default, the {@link InCallService} 653 * will NOT be informed about self-managed calls. 654 * <p> 655 * An {@link InCallService} which receives self-managed calls is free to view and control the 656 * state of calls in the self-managed {@link ConnectionService}. An example use-case is 657 * exposing these calls to an automotive device via its companion app. 658 * <p> 659 * This meta-data can only be set for an {@link InCallService} which also sets 660 * {@link #METADATA_IN_CALL_SERVICE_UI}. Only the default phone/dialer app, or a car-mode 661 * {@link InCallService} can see self-managed calls. 662 * <p> 663 * See also {@link Connection#PROPERTY_SELF_MANAGED}. 664 */ 665 public static final String METADATA_INCLUDE_SELF_MANAGED_CALLS = 666 "android.telecom.INCLUDE_SELF_MANAGED_CALLS"; 667 668 /** 669 * The dual tone multi-frequency signaling character sent to indicate the dialing system should 670 * pause for a predefined period. 671 */ 672 public static final char DTMF_CHARACTER_PAUSE = ','; 673 674 /** 675 * The dual-tone multi-frequency signaling character sent to indicate the dialing system should 676 * wait for user confirmation before proceeding. 677 */ 678 public static final char DTMF_CHARACTER_WAIT = ';'; 679 680 /** 681 * @hide 682 */ 683 @IntDef(prefix = { "TTY_MODE_" }, 684 value = {TTY_MODE_OFF, TTY_MODE_FULL, TTY_MODE_HCO, TTY_MODE_VCO}) 685 @Retention(RetentionPolicy.SOURCE) 686 public @interface TtyMode {} 687 688 /** 689 * TTY (teletypewriter) mode is off. 690 * 691 * @hide 692 */ 693 @TestApi 694 @SystemApi 695 public static final int TTY_MODE_OFF = 0; 696 697 /** 698 * TTY (teletypewriter) mode is on. The speaker is off and the microphone is muted. The user 699 * will communicate with the remote party by sending and receiving text messages. 700 * 701 * @hide 702 */ 703 @TestApi 704 @SystemApi 705 public static final int TTY_MODE_FULL = 1; 706 707 /** 708 * TTY (teletypewriter) mode is in hearing carryover mode (HCO). The microphone is muted but the 709 * speaker is on. The user will communicate with the remote party by sending text messages and 710 * hearing an audible reply. 711 * 712 * @hide 713 */ 714 @TestApi 715 @SystemApi 716 public static final int TTY_MODE_HCO = 2; 717 718 /** 719 * TTY (teletypewriter) mode is in voice carryover mode (VCO). The speaker is off but the 720 * microphone is still on. User will communicate with the remote party by speaking and receiving 721 * text message replies. 722 * 723 * @hide 724 */ 725 @TestApi 726 @SystemApi 727 public static final int TTY_MODE_VCO = 3; 728 729 /** 730 * Broadcast intent action indicating that the current TTY mode has changed. An intent extra 731 * provides this state as an int. 732 * 733 * @see #EXTRA_CURRENT_TTY_MODE 734 * @hide 735 */ 736 public static final String ACTION_CURRENT_TTY_MODE_CHANGED = 737 "android.telecom.action.CURRENT_TTY_MODE_CHANGED"; 738 739 /** 740 * The lookup key for an int that indicates the current TTY mode. 741 * Valid modes are: 742 * <ul> 743 * <li>{@link #TTY_MODE_OFF}</li> 744 * <li>{@link #TTY_MODE_FULL}</li> 745 * <li>{@link #TTY_MODE_HCO}</li> 746 * <li>{@link #TTY_MODE_VCO}</li> 747 * </ul> 748 * @hide 749 */ 750 public static final String EXTRA_CURRENT_TTY_MODE = 751 "android.telecom.extra.CURRENT_TTY_MODE"; 752 753 /** 754 * Broadcast intent action indicating that the TTY preferred operating mode has changed. An 755 * intent extra provides the new mode as an int. 756 * 757 * @see #EXTRA_TTY_PREFERRED_MODE 758 * @hide 759 */ 760 public static final String ACTION_TTY_PREFERRED_MODE_CHANGED = 761 "android.telecom.action.TTY_PREFERRED_MODE_CHANGED"; 762 763 /** 764 * The lookup key for an int that indicates preferred TTY mode. Valid modes are: - 765 * {@link #TTY_MODE_OFF} - {@link #TTY_MODE_FULL} - {@link #TTY_MODE_HCO} - 766 * {@link #TTY_MODE_VCO} 767 * 768 * @hide 769 */ 770 public static final String EXTRA_TTY_PREFERRED_MODE = 771 "android.telecom.extra.TTY_PREFERRED_MODE"; 772 773 /** 774 * Broadcast intent action for letting custom component know to show the missed call 775 * notification. If no custom component exists then this is sent to the default dialer which 776 * should post a missed-call notification. 777 */ 778 public static final String ACTION_SHOW_MISSED_CALLS_NOTIFICATION = 779 "android.telecom.action.SHOW_MISSED_CALLS_NOTIFICATION"; 780 781 /** 782 * The number of calls associated with the notification. If the number is zero then the missed 783 * call notification should be dismissed. 784 */ 785 public static final String EXTRA_NOTIFICATION_COUNT = 786 "android.telecom.extra.NOTIFICATION_COUNT"; 787 788 /** 789 * The number associated with the missed calls. This number is only relevant 790 * when EXTRA_NOTIFICATION_COUNT is 1. 791 */ 792 public static final String EXTRA_NOTIFICATION_PHONE_NUMBER = 793 "android.telecom.extra.NOTIFICATION_PHONE_NUMBER"; 794 795 /** 796 * The intent to clear missed calls. 797 * @hide 798 */ 799 @SystemApi 800 public static final String EXTRA_CLEAR_MISSED_CALLS_INTENT = 801 "android.telecom.extra.CLEAR_MISSED_CALLS_INTENT"; 802 803 /** 804 * The intent to call back a missed call. 805 * @hide 806 */ 807 @SystemApi 808 public static final String EXTRA_CALL_BACK_INTENT = 809 "android.telecom.extra.CALL_BACK_INTENT"; 810 811 /** 812 * The dialer activity responsible for placing emergency calls from, for example, a locked 813 * keyguard. 814 * @hide 815 */ 816 public static final ComponentName EMERGENCY_DIALER_COMPONENT = 817 ComponentName.createRelative("com.android.phone", ".EmergencyDialer"); 818 819 /** 820 * The boolean indicated by this extra controls whether or not a call is eligible to undergo 821 * assisted dialing. This extra is stored under {@link #EXTRA_OUTGOING_CALL_EXTRAS}. 822 * <p> 823 * The call initiator can use this extra to indicate that a call used assisted dialing to help 824 * place the call. This is most commonly used by a Dialer app which provides the ability to 825 * automatically add dialing prefixes when placing international calls. 826 * <p> 827 * Setting this extra on the outgoing call extras will cause the 828 * {@link Connection#PROPERTY_ASSISTED_DIALING} property and 829 * {@link Call.Details#PROPERTY_ASSISTED_DIALING} property to be set on the 830 * {@link Connection}/{@link Call} in question. When the call is logged to the call log, the 831 * {@link android.provider.CallLog.Calls#FEATURES_ASSISTED_DIALING_USED} call feature is set to 832 * indicate that assisted dialing was used for the call. 833 */ 834 public static final String EXTRA_USE_ASSISTED_DIALING = 835 "android.telecom.extra.USE_ASSISTED_DIALING"; 836 837 /** 838 * Optional extra for {@link #placeCall(Uri, Bundle)} containing an integer that specifies 839 * the source where user initiated this call. This data is used in metrics. 840 * Valid sources are: 841 * {@link TelecomManager#CALL_SOURCE_UNSPECIFIED}, 842 * {@link TelecomManager#CALL_SOURCE_EMERGENCY_DIALPAD}, 843 * {@link TelecomManager#CALL_SOURCE_EMERGENCY_SHORTCUT}. 844 * 845 * @hide 846 */ 847 public static final String EXTRA_CALL_SOURCE = "android.telecom.extra.CALL_SOURCE"; 848 849 /** 850 * Indicating the call is initiated via emergency dialer's shortcut button. 851 * 852 * @hide 853 */ 854 public static final int CALL_SOURCE_EMERGENCY_SHORTCUT = 2; 855 856 /** 857 * Indicating the call is initiated via emergency dialer's dialpad. 858 * 859 * @hide 860 */ 861 public static final int CALL_SOURCE_EMERGENCY_DIALPAD = 1; 862 863 /** 864 * Indicating the call source is not specified. 865 * 866 * @hide 867 */ 868 public static final int CALL_SOURCE_UNSPECIFIED = 0; 869 870 /** 871 * The following 4 constants define how properties such as phone numbers and names are 872 * displayed to the user. 873 */ 874 875 /** 876 * Indicates that the address or number of a call is allowed to be displayed for caller ID. 877 */ 878 public static final int PRESENTATION_ALLOWED = 1; 879 880 /** 881 * Indicates that the address or number of a call is blocked by the other party. 882 */ 883 public static final int PRESENTATION_RESTRICTED = 2; 884 885 /** 886 * Indicates that the address or number of a call is not specified or known by the carrier. 887 */ 888 public static final int PRESENTATION_UNKNOWN = 3; 889 890 /** 891 * Indicates that the address or number of a call belongs to a pay phone. 892 */ 893 public static final int PRESENTATION_PAYPHONE = 4; 894 895 896 /* 897 * Values for the adb property "persist.radio.videocall.audio.output" 898 */ 899 /** @hide */ 900 public static final int AUDIO_OUTPUT_ENABLE_SPEAKER = 0; 901 /** @hide */ 902 public static final int AUDIO_OUTPUT_DISABLE_SPEAKER = 1; 903 /** @hide */ 904 public static final int AUDIO_OUTPUT_DEFAULT = AUDIO_OUTPUT_ENABLE_SPEAKER; 905 906 /** @hide */ 907 @Retention(RetentionPolicy.SOURCE) 908 @IntDef( 909 prefix = { "PRESENTATION_" }, 910 value = {PRESENTATION_ALLOWED, PRESENTATION_RESTRICTED, PRESENTATION_UNKNOWN, 911 PRESENTATION_PAYPHONE}) 912 public @interface Presentation {} 913 914 private static final String TAG = "TelecomManager"; 915 916 private final Context mContext; 917 918 private final ITelecomService mTelecomServiceOverride; 919 920 /** 921 * @hide 922 */ 923 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) from(Context context)924 public static TelecomManager from(Context context) { 925 return (TelecomManager) context.getSystemService(Context.TELECOM_SERVICE); 926 } 927 928 /** 929 * @hide 930 */ TelecomManager(Context context)931 public TelecomManager(Context context) { 932 this(context, null); 933 } 934 935 /** 936 * @hide 937 */ TelecomManager(Context context, ITelecomService telecomServiceImpl)938 public TelecomManager(Context context, ITelecomService telecomServiceImpl) { 939 Context appContext = context.getApplicationContext(); 940 if (appContext != null) { 941 mContext = appContext; 942 } else { 943 mContext = context; 944 } 945 mTelecomServiceOverride = telecomServiceImpl; 946 } 947 948 /** 949 * Return the {@link PhoneAccount} which will be used to place outgoing calls to addresses with 950 * the specified {@code uriScheme}. This {@link PhoneAccount} will always be a member of the 951 * list which is returned from invoking {@link #getCallCapablePhoneAccounts()}. The specific 952 * account returned depends on the following priorities: 953 * <ul> 954 * <li> If the user-selected default {@link PhoneAccount} supports the specified scheme, it will 955 * be returned. 956 * </li> 957 * <li> If there exists only one {@link PhoneAccount} that supports the specified scheme, it 958 * will be returned. 959 * </li> 960 * </ul> 961 * <p> 962 * If no {@link PhoneAccount} fits the criteria above, this method will return {@code null}. 963 * 964 * Requires permission: {@link android.Manifest.permission#READ_PHONE_STATE} 965 * 966 * @param uriScheme The URI scheme. 967 * @return The {@link PhoneAccountHandle} corresponding to the account to be used. 968 */ 969 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) getDefaultOutgoingPhoneAccount(String uriScheme)970 public PhoneAccountHandle getDefaultOutgoingPhoneAccount(String uriScheme) { 971 try { 972 if (isServiceConnected()) { 973 return getTelecomService().getDefaultOutgoingPhoneAccount(uriScheme, 974 mContext.getOpPackageName()); 975 } 976 } catch (RemoteException e) { 977 Log.e(TAG, "Error calling ITelecomService#getDefaultOutgoingPhoneAccount", e); 978 } 979 return null; 980 } 981 982 /** 983 * Return the {@link PhoneAccount} which is the user-chosen default for making outgoing phone 984 * calls. This {@code PhoneAccount} will always be a member of the list which is returned from 985 * calling {@link #getCallCapablePhoneAccounts()} 986 * <p> 987 * Apps must be prepared for this method to return {@code null}, indicating that there currently 988 * exists no user-chosen default {@code PhoneAccount}. 989 * <p> 990 * The default dialer has access to use this method. 991 * 992 * @return The user outgoing phone account selected by the user, or {@code null} if there is no 993 * user selected outgoing {@link PhoneAccountHandle}. 994 */ 995 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) getUserSelectedOutgoingPhoneAccount()996 public @Nullable PhoneAccountHandle getUserSelectedOutgoingPhoneAccount() { 997 try { 998 if (isServiceConnected()) { 999 return getTelecomService().getUserSelectedOutgoingPhoneAccount( 1000 mContext.getOpPackageName()); 1001 } 1002 } catch (RemoteException e) { 1003 Log.e(TAG, "Error calling ITelecomService#getUserSelectedOutgoingPhoneAccount", e); 1004 } 1005 return null; 1006 } 1007 1008 /** 1009 * Sets the user-chosen default {@link PhoneAccountHandle} for making outgoing phone calls. 1010 * 1011 * @param accountHandle The {@link PhoneAccountHandle} which will be used by default for making 1012 * outgoing voice calls, or {@code null} if no default is specified (the 1013 * user will be asked each time a call is placed in this case). 1014 * @hide 1015 */ 1016 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) 1017 @TestApi 1018 @SystemApi setUserSelectedOutgoingPhoneAccount(@ullable PhoneAccountHandle accountHandle)1019 public void setUserSelectedOutgoingPhoneAccount(@Nullable PhoneAccountHandle accountHandle) { 1020 try { 1021 if (isServiceConnected()) { 1022 getTelecomService().setUserSelectedOutgoingPhoneAccount(accountHandle); 1023 } 1024 } catch (RemoteException e) { 1025 Log.e(TAG, "Error calling ITelecomService#setUserSelectedOutgoingPhoneAccount"); 1026 } 1027 } 1028 1029 /** 1030 * Returns the current SIM call manager. Apps must be prepared for this method to return 1031 * {@code null}, indicating that there currently exists no SIM call manager {@link PhoneAccount} 1032 * for the default voice subscription. 1033 * 1034 * @return The phone account handle of the current sim call manager for the default voice 1035 * subscription. 1036 * @see SubscriptionManager#getDefaultVoiceSubscriptionId() 1037 */ getSimCallManager()1038 public PhoneAccountHandle getSimCallManager() { 1039 try { 1040 if (isServiceConnected()) { 1041 return getTelecomService().getSimCallManager( 1042 SubscriptionManager.getDefaultSubscriptionId()); 1043 } 1044 } catch (RemoteException e) { 1045 Log.e(TAG, "Error calling ITelecomService#getSimCallManager"); 1046 } 1047 return null; 1048 } 1049 1050 /** 1051 * Returns current SIM call manager for the Telephony Subscription ID specified. Apps must be 1052 * prepared for this method to return {@code null}, indicating that there currently exists no 1053 * SIM call manager {@link PhoneAccount} for the subscription specified. 1054 * 1055 * @param subscriptionId The Telephony Subscription ID that the SIM call manager should be 1056 * queried for. 1057 * @return The phone account handle of the current sim call manager. 1058 * @see SubscriptionManager#getActiveSubscriptionInfoList() 1059 */ getSimCallManagerForSubscription(int subscriptionId)1060 public @Nullable PhoneAccountHandle getSimCallManagerForSubscription(int subscriptionId) { 1061 try { 1062 if (isServiceConnected()) { 1063 return getTelecomService().getSimCallManager(subscriptionId); 1064 } 1065 } catch (RemoteException e) { 1066 Log.e(TAG, "Error calling ITelecomService#getSimCallManager"); 1067 } 1068 return null; 1069 } 1070 1071 /** 1072 * Returns the current SIM call manager for the user-chosen default Telephony Subscription ID 1073 * (see {@link SubscriptionManager#getDefaultSubscriptionId()}) and the specified user. Apps 1074 * must be prepared for this method to return {@code null}, indicating that there currently 1075 * exists no SIM call manager {@link PhoneAccount} for the default voice subscription. 1076 * 1077 * @return The phone account handle of the current sim call manager. 1078 * 1079 * @hide 1080 * @deprecated Use {@link #getSimCallManager()}. 1081 */ 1082 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 119305590) getSimCallManager(int userId)1083 public PhoneAccountHandle getSimCallManager(int userId) { 1084 try { 1085 if (isServiceConnected()) { 1086 return getTelecomService().getSimCallManagerForUser(userId); 1087 } 1088 } catch (RemoteException e) { 1089 Log.e(TAG, "Error calling ITelecomService#getSimCallManagerForUser"); 1090 } 1091 return null; 1092 } 1093 1094 /** 1095 * Returns the current connection manager. Apps must be prepared for this method to return 1096 * {@code null}, indicating that there currently exists no Connection Manager 1097 * {@link PhoneAccount} for the default voice subscription. 1098 * 1099 * @return The phone account handle of the current connection manager. 1100 * @hide 1101 */ 1102 @SystemApi getConnectionManager()1103 public PhoneAccountHandle getConnectionManager() { 1104 return getSimCallManager(); 1105 } 1106 1107 /** 1108 * Returns a list of the {@link PhoneAccountHandle}s which can be used to make and receive phone 1109 * calls which support the specified URI scheme. 1110 * <P> 1111 * For example, invoking with {@code "tel"} will find all {@link PhoneAccountHandle}s which 1112 * support telephone calls (e.g. URIs such as {@code tel:555-555-1212}). Invoking with 1113 * {@code "sip"} will find all {@link PhoneAccountHandle}s which support SIP calls (e.g. URIs 1114 * such as {@code sip:example@sipexample.com}). 1115 * 1116 * @param uriScheme The URI scheme. 1117 * @return A list of {@code PhoneAccountHandle} objects supporting the URI scheme. 1118 * @hide 1119 */ 1120 @SystemApi 1121 @RequiresPermission(anyOf = { 1122 READ_PRIVILEGED_PHONE_STATE, 1123 android.Manifest.permission.READ_PHONE_STATE 1124 }) getPhoneAccountsSupportingScheme(String uriScheme)1125 public List<PhoneAccountHandle> getPhoneAccountsSupportingScheme(String uriScheme) { 1126 try { 1127 if (isServiceConnected()) { 1128 return getTelecomService().getPhoneAccountsSupportingScheme(uriScheme, 1129 mContext.getOpPackageName()); 1130 } 1131 } catch (RemoteException e) { 1132 Log.e(TAG, "Error calling ITelecomService#getPhoneAccountsSupportingScheme", e); 1133 } 1134 return new ArrayList<>(); 1135 } 1136 1137 1138 /** 1139 * Returns a list of {@link PhoneAccountHandle}s which can be used to make and receive phone 1140 * calls. The returned list includes only those accounts which have been explicitly enabled 1141 * by the user. 1142 * 1143 * Requires permission: {@link android.Manifest.permission#READ_PHONE_STATE} 1144 * 1145 * @see #EXTRA_PHONE_ACCOUNT_HANDLE 1146 * @return A list of {@code PhoneAccountHandle} objects. 1147 */ 1148 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) getCallCapablePhoneAccounts()1149 public List<PhoneAccountHandle> getCallCapablePhoneAccounts() { 1150 return getCallCapablePhoneAccounts(false); 1151 } 1152 1153 /** 1154 * Returns a list of {@link PhoneAccountHandle}s for self-managed {@link ConnectionService}s. 1155 * <p> 1156 * Self-Managed {@link ConnectionService}s have a {@link PhoneAccount} with 1157 * {@link PhoneAccount#CAPABILITY_SELF_MANAGED}. 1158 * <p> 1159 * Requires permission {@link android.Manifest.permission#READ_PHONE_STATE}, or that the caller 1160 * is the default dialer app. 1161 * <p> 1162 * A {@link SecurityException} will be thrown if a called is not the default dialer, or lacks 1163 * the {@link android.Manifest.permission#READ_PHONE_STATE} permission. 1164 * 1165 * @return A list of {@code PhoneAccountHandle} objects. 1166 */ 1167 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) getSelfManagedPhoneAccounts()1168 public List<PhoneAccountHandle> getSelfManagedPhoneAccounts() { 1169 try { 1170 if (isServiceConnected()) { 1171 return getTelecomService().getSelfManagedPhoneAccounts(mContext.getOpPackageName()); 1172 } 1173 } catch (RemoteException e) { 1174 Log.e(TAG, "Error calling ITelecomService#getSelfManagedPhoneAccounts()", e); 1175 } 1176 return new ArrayList<>(); 1177 } 1178 1179 /** 1180 * Returns a list of {@link PhoneAccountHandle}s including those which have not been enabled 1181 * by the user. 1182 * 1183 * @param includeDisabledAccounts When {@code true}, disabled phone accounts will be included, 1184 * when {@code false}, only enabled phone accounts will be 1185 * included. 1186 * @return A list of {@code PhoneAccountHandle} objects. 1187 * @hide 1188 */ 1189 @SystemApi 1190 @TestApi 1191 @RequiresPermission(READ_PRIVILEGED_PHONE_STATE) getCallCapablePhoneAccounts( boolean includeDisabledAccounts)1192 public @NonNull List<PhoneAccountHandle> getCallCapablePhoneAccounts( 1193 boolean includeDisabledAccounts) { 1194 try { 1195 if (isServiceConnected()) { 1196 return getTelecomService().getCallCapablePhoneAccounts( 1197 includeDisabledAccounts, mContext.getOpPackageName()); 1198 } 1199 } catch (RemoteException e) { 1200 Log.e(TAG, "Error calling ITelecomService#getCallCapablePhoneAccounts(" + 1201 includeDisabledAccounts + ")", e); 1202 } 1203 return new ArrayList<>(); 1204 } 1205 1206 /** 1207 * Returns a list of all {@link PhoneAccount}s registered for the calling package. 1208 * 1209 * @return A list of {@code PhoneAccountHandle} objects. 1210 * @hide 1211 */ 1212 @SystemApi 1213 @SuppressLint("Doclava125") getPhoneAccountsForPackage()1214 public List<PhoneAccountHandle> getPhoneAccountsForPackage() { 1215 try { 1216 if (isServiceConnected()) { 1217 return getTelecomService().getPhoneAccountsForPackage(mContext.getPackageName()); 1218 } 1219 } catch (RemoteException e) { 1220 Log.e(TAG, "Error calling ITelecomService#getPhoneAccountsForPackage", e); 1221 } 1222 return null; 1223 } 1224 1225 /** 1226 * Return the {@link PhoneAccount} for a specified {@link PhoneAccountHandle}. Object includes 1227 * resources which can be used in a user interface. 1228 * 1229 * @param account The {@link PhoneAccountHandle}. 1230 * @return The {@link PhoneAccount} object. 1231 */ getPhoneAccount(PhoneAccountHandle account)1232 public PhoneAccount getPhoneAccount(PhoneAccountHandle account) { 1233 try { 1234 if (isServiceConnected()) { 1235 return getTelecomService().getPhoneAccount(account); 1236 } 1237 } catch (RemoteException e) { 1238 Log.e(TAG, "Error calling ITelecomService#getPhoneAccount", e); 1239 } 1240 return null; 1241 } 1242 1243 /** 1244 * Returns a count of all {@link PhoneAccount}s. 1245 * 1246 * @return The count of {@link PhoneAccount}s. 1247 * @hide 1248 */ 1249 @SystemApi getAllPhoneAccountsCount()1250 public int getAllPhoneAccountsCount() { 1251 try { 1252 if (isServiceConnected()) { 1253 return getTelecomService().getAllPhoneAccountsCount(); 1254 } 1255 } catch (RemoteException e) { 1256 Log.e(TAG, "Error calling ITelecomService#getAllPhoneAccountsCount", e); 1257 } 1258 return 0; 1259 } 1260 1261 /** 1262 * Returns a list of all {@link PhoneAccount}s. 1263 * 1264 * @return All {@link PhoneAccount}s. 1265 * @hide 1266 */ 1267 @SystemApi getAllPhoneAccounts()1268 public List<PhoneAccount> getAllPhoneAccounts() { 1269 try { 1270 if (isServiceConnected()) { 1271 return getTelecomService().getAllPhoneAccounts(); 1272 } 1273 } catch (RemoteException e) { 1274 Log.e(TAG, "Error calling ITelecomService#getAllPhoneAccounts", e); 1275 } 1276 return Collections.EMPTY_LIST; 1277 } 1278 1279 /** 1280 * Returns a list of all {@link PhoneAccountHandle}s. 1281 * 1282 * @return All {@link PhoneAccountHandle}s. 1283 * @hide 1284 */ 1285 @SystemApi getAllPhoneAccountHandles()1286 public List<PhoneAccountHandle> getAllPhoneAccountHandles() { 1287 try { 1288 if (isServiceConnected()) { 1289 return getTelecomService().getAllPhoneAccountHandles(); 1290 } 1291 } catch (RemoteException e) { 1292 Log.e(TAG, "Error calling ITelecomService#getAllPhoneAccountHandles", e); 1293 } 1294 return Collections.EMPTY_LIST; 1295 } 1296 1297 /** 1298 * Register a {@link PhoneAccount} for use by the system that will be stored in Device Encrypted 1299 * storage. When registering {@link PhoneAccount}s, existing registrations will be overwritten 1300 * if the {@link PhoneAccountHandle} matches that of a {@link PhoneAccount} which is already 1301 * registered. Once registered, the {@link PhoneAccount} is listed to the user as an option 1302 * when placing calls. The user may still need to enable the {@link PhoneAccount} within 1303 * the phone app settings before the account is usable. 1304 * <p> 1305 * A {@link SecurityException} will be thrown if an app tries to register a 1306 * {@link PhoneAccountHandle} where the package name specified within 1307 * {@link PhoneAccountHandle#getComponentName()} does not match the package name of the app. 1308 * 1309 * @param account The complete {@link PhoneAccount}. 1310 */ registerPhoneAccount(PhoneAccount account)1311 public void registerPhoneAccount(PhoneAccount account) { 1312 try { 1313 if (isServiceConnected()) { 1314 getTelecomService().registerPhoneAccount(account); 1315 } 1316 } catch (RemoteException e) { 1317 Log.e(TAG, "Error calling ITelecomService#registerPhoneAccount", e); 1318 } 1319 } 1320 1321 /** 1322 * Remove a {@link PhoneAccount} registration from the system. 1323 * 1324 * @param accountHandle A {@link PhoneAccountHandle} for the {@link PhoneAccount} to unregister. 1325 */ unregisterPhoneAccount(PhoneAccountHandle accountHandle)1326 public void unregisterPhoneAccount(PhoneAccountHandle accountHandle) { 1327 try { 1328 if (isServiceConnected()) { 1329 getTelecomService().unregisterPhoneAccount(accountHandle); 1330 } 1331 } catch (RemoteException e) { 1332 Log.e(TAG, "Error calling ITelecomService#unregisterPhoneAccount", e); 1333 } 1334 } 1335 1336 /** 1337 * Remove all Accounts that belong to the calling package from the system. 1338 * @hide 1339 */ 1340 @SystemApi 1341 @SuppressLint("Doclava125") clearPhoneAccounts()1342 public void clearPhoneAccounts() { 1343 clearAccounts(); 1344 } 1345 /** 1346 * Remove all Accounts that belong to the calling package from the system. 1347 * @deprecated Use {@link #clearPhoneAccounts()} instead. 1348 * @hide 1349 */ 1350 @SystemApi 1351 @SuppressLint("Doclava125") clearAccounts()1352 public void clearAccounts() { 1353 try { 1354 if (isServiceConnected()) { 1355 getTelecomService().clearAccounts(mContext.getPackageName()); 1356 } 1357 } catch (RemoteException e) { 1358 Log.e(TAG, "Error calling ITelecomService#clearAccounts", e); 1359 } 1360 } 1361 1362 /** 1363 * Remove all Accounts that belong to the specified package from the system. 1364 * @hide 1365 */ clearAccountsForPackage(String packageName)1366 public void clearAccountsForPackage(String packageName) { 1367 try { 1368 if (isServiceConnected() && !TextUtils.isEmpty(packageName)) { 1369 getTelecomService().clearAccounts(packageName); 1370 } 1371 } catch (RemoteException e) { 1372 Log.e(TAG, "Error calling ITelecomService#clearAccountsForPackage", e); 1373 } 1374 } 1375 1376 1377 /** 1378 * @deprecated - Use {@link TelecomManager#getDefaultDialerPackage} to directly access 1379 * the default dialer's package name instead. 1380 * @hide 1381 */ 1382 @SystemApi 1383 @SuppressLint("Doclava125") getDefaultPhoneApp()1384 public ComponentName getDefaultPhoneApp() { 1385 try { 1386 if (isServiceConnected()) { 1387 return getTelecomService().getDefaultPhoneApp(); 1388 } 1389 } catch (RemoteException e) { 1390 Log.e(TAG, "RemoteException attempting to get the default phone app.", e); 1391 } 1392 return null; 1393 } 1394 1395 /** 1396 * Used to determine the currently selected default dialer package. 1397 * 1398 * @return package name for the default dialer package or null if no package has been 1399 * selected as the default dialer. 1400 */ getDefaultDialerPackage()1401 public String getDefaultDialerPackage() { 1402 try { 1403 if (isServiceConnected()) { 1404 return getTelecomService().getDefaultDialerPackage(); 1405 } 1406 } catch (RemoteException e) { 1407 Log.e(TAG, "RemoteException attempting to get the default dialer package name.", e); 1408 } 1409 return null; 1410 } 1411 1412 /** 1413 * Used to determine the currently selected default dialer package for a specific user. 1414 * 1415 * @param userHandle the user id to query the default dialer package for. 1416 * @return package name for the default dialer package or null if no package has been 1417 * selected as the default dialer. 1418 * @hide 1419 */ 1420 @SystemApi 1421 @TestApi 1422 @RequiresPermission(READ_PRIVILEGED_PHONE_STATE) getDefaultDialerPackage(@onNull UserHandle userHandle)1423 public @Nullable String getDefaultDialerPackage(@NonNull UserHandle userHandle) { 1424 try { 1425 if (isServiceConnected()) { 1426 return getTelecomService().getDefaultDialerPackageForUser( 1427 userHandle.getIdentifier()); 1428 } 1429 } catch (RemoteException e) { 1430 Log.e(TAG, "RemoteException attempting to get the default dialer package name.", e); 1431 } 1432 return null; 1433 } 1434 1435 /** 1436 * Used to set the default dialer package. 1437 * 1438 * @param packageName to set the default dialer to, or {@code null} if the system provided 1439 * dialer should be used instead. 1440 * 1441 * @result {@code true} if the default dialer was successfully changed, {@code false} if 1442 * the specified package does not correspond to an installed dialer, or is already 1443 * the default dialer. 1444 * 1445 * Requires permission: {@link android.Manifest.permission#MODIFY_PHONE_STATE} 1446 * Requires permission: {@link android.Manifest.permission#WRITE_SECURE_SETTINGS} 1447 * 1448 * @hide 1449 * @deprecated Use 1450 * {@link android.app.role.RoleManager#addRoleHolderAsUser(String, String, int, UserHandle, 1451 * Executor, java.util.function.Consumer)} instead. 1452 * @removed 1453 */ 1454 @SystemApi 1455 @Deprecated 1456 @RequiresPermission(allOf = { 1457 android.Manifest.permission.MODIFY_PHONE_STATE, 1458 android.Manifest.permission.WRITE_SECURE_SETTINGS}) setDefaultDialer(@ullable String packageName)1459 public boolean setDefaultDialer(@Nullable String packageName) { 1460 try { 1461 if (isServiceConnected()) { 1462 return getTelecomService().setDefaultDialer(packageName); 1463 } 1464 } catch (RemoteException e) { 1465 Log.e(TAG, "RemoteException attempting to set the default dialer.", e); 1466 } 1467 return false; 1468 } 1469 1470 /** 1471 * Determines the package name of the system-provided default phone app. 1472 * 1473 * @return package name for the system dialer package or {@code null} if no system dialer is 1474 * preloaded. 1475 */ getSystemDialerPackage()1476 public @Nullable String getSystemDialerPackage() { 1477 try { 1478 if (isServiceConnected()) { 1479 return getTelecomService().getSystemDialerPackage(); 1480 } 1481 } catch (RemoteException e) { 1482 Log.e(TAG, "RemoteException attempting to get the system dialer package name.", e); 1483 } 1484 return null; 1485 } 1486 1487 /** 1488 * Return whether a given phone number is the configured voicemail number for a 1489 * particular phone account. 1490 * 1491 * Requires permission: {@link android.Manifest.permission#READ_PHONE_STATE} 1492 * 1493 * @param accountHandle The handle for the account to check the voicemail number against 1494 * @param number The number to look up. 1495 */ 1496 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) isVoiceMailNumber(PhoneAccountHandle accountHandle, String number)1497 public boolean isVoiceMailNumber(PhoneAccountHandle accountHandle, String number) { 1498 try { 1499 if (isServiceConnected()) { 1500 return getTelecomService().isVoiceMailNumber(accountHandle, number, 1501 mContext.getOpPackageName()); 1502 } 1503 } catch (RemoteException e) { 1504 Log.e(TAG, "RemoteException calling ITelecomService#isVoiceMailNumber.", e); 1505 } 1506 return false; 1507 } 1508 1509 /** 1510 * Return the voicemail number for a given phone account. 1511 * 1512 * Requires permission: {@link android.Manifest.permission#READ_PHONE_STATE} 1513 * 1514 * @param accountHandle The handle for the phone account. 1515 * @return The voicemail number for the phone account, and {@code null} if one has not been 1516 * configured. 1517 */ 1518 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) getVoiceMailNumber(PhoneAccountHandle accountHandle)1519 public String getVoiceMailNumber(PhoneAccountHandle accountHandle) { 1520 try { 1521 if (isServiceConnected()) { 1522 return getTelecomService().getVoiceMailNumber(accountHandle, 1523 mContext.getOpPackageName()); 1524 } 1525 } catch (RemoteException e) { 1526 Log.e(TAG, "RemoteException calling ITelecomService#hasVoiceMailNumber.", e); 1527 } 1528 return null; 1529 } 1530 1531 /** 1532 * Return the line 1 phone number for given phone account. 1533 * 1534 * Requires permission: {@link android.Manifest.permission#READ_PHONE_STATE} 1535 * 1536 * @param accountHandle The handle for the account retrieve a number for. 1537 * @return A string representation of the line 1 phone number. 1538 */ 1539 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) getLine1Number(PhoneAccountHandle accountHandle)1540 public String getLine1Number(PhoneAccountHandle accountHandle) { 1541 try { 1542 if (isServiceConnected()) { 1543 return getTelecomService().getLine1Number(accountHandle, 1544 mContext.getOpPackageName()); 1545 } 1546 } catch (RemoteException e) { 1547 Log.e(TAG, "RemoteException calling ITelecomService#getLine1Number.", e); 1548 } 1549 return null; 1550 } 1551 1552 /** 1553 * Returns whether there is an ongoing phone call (can be in dialing, ringing, active or holding 1554 * states) originating from either a manager or self-managed {@link ConnectionService}. 1555 * <p> 1556 * Requires permission: {@link android.Manifest.permission#READ_PHONE_STATE} 1557 * 1558 * @return {@code true} if there is an ongoing call in either a managed or self-managed 1559 * {@link ConnectionService}, {@code false} otherwise. 1560 */ 1561 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) isInCall()1562 public boolean isInCall() { 1563 try { 1564 if (isServiceConnected()) { 1565 return getTelecomService().isInCall(mContext.getOpPackageName()); 1566 } 1567 } catch (RemoteException e) { 1568 Log.e(TAG, "RemoteException calling isInCall().", e); 1569 } 1570 return false; 1571 } 1572 1573 /** 1574 * Returns whether there is an ongoing call originating from a managed 1575 * {@link ConnectionService}. An ongoing call can be in dialing, ringing, active or holding 1576 * states. 1577 * <p> 1578 * If you also need to know if there are ongoing self-managed calls, use {@link #isInCall()} 1579 * instead. 1580 * <p> 1581 * Requires permission: {@link android.Manifest.permission#READ_PHONE_STATE} 1582 * 1583 * @return {@code true} if there is an ongoing call in a managed {@link ConnectionService}, 1584 * {@code false} otherwise. 1585 */ 1586 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) isInManagedCall()1587 public boolean isInManagedCall() { 1588 try { 1589 if (isServiceConnected()) { 1590 return getTelecomService().isInManagedCall(mContext.getOpPackageName()); 1591 } 1592 } catch (RemoteException e) { 1593 Log.e(TAG, "RemoteException calling isInManagedCall().", e); 1594 } 1595 return false; 1596 } 1597 1598 /** 1599 * Returns one of the following constants that represents the current state of Telecom: 1600 * 1601 * {@link TelephonyManager#CALL_STATE_RINGING} 1602 * {@link TelephonyManager#CALL_STATE_OFFHOOK} 1603 * {@link TelephonyManager#CALL_STATE_IDLE} 1604 * 1605 * Note that this API does not require the 1606 * {@link android.Manifest.permission#READ_PHONE_STATE} permission. This is intentional, to 1607 * preserve the behavior of {@link TelephonyManager#getCallState()}, which also did not require 1608 * the permission. 1609 * 1610 * Takes into consideration both managed and self-managed calls. 1611 * 1612 * @hide 1613 */ 1614 @SystemApi getCallState()1615 public @CallState int getCallState() { 1616 try { 1617 if (isServiceConnected()) { 1618 return getTelecomService().getCallState(); 1619 } 1620 } catch (RemoteException e) { 1621 Log.d(TAG, "RemoteException calling getCallState().", e); 1622 } 1623 return TelephonyManager.CALL_STATE_IDLE; 1624 } 1625 1626 /** 1627 * Returns whether there currently exists is a ringing incoming-call. 1628 * 1629 * @return {@code true} if there is a managed or self-managed ringing call. 1630 * @hide 1631 */ 1632 @SystemApi 1633 @TestApi 1634 @RequiresPermission(anyOf = { 1635 READ_PRIVILEGED_PHONE_STATE, 1636 android.Manifest.permission.READ_PHONE_STATE 1637 }) isRinging()1638 public boolean isRinging() { 1639 try { 1640 if (isServiceConnected()) { 1641 return getTelecomService().isRinging(mContext.getOpPackageName()); 1642 } 1643 } catch (RemoteException e) { 1644 Log.e(TAG, "RemoteException attempting to get ringing state of phone app.", e); 1645 } 1646 return false; 1647 } 1648 1649 /** 1650 * Ends the foreground call on the device. 1651 * <p> 1652 * If there is a ringing call, calling this method rejects the ringing call. Otherwise the 1653 * foreground call is ended. 1654 * <p> 1655 * Requires permission {@link android.Manifest.permission#ANSWER_PHONE_CALLS}. 1656 * <p> 1657 * Note: this method CANNOT be used to end ongoing emergency calls and will return {@code false} 1658 * if an attempt is made to end an emergency call. 1659 * 1660 * @return {@code true} if there is a call which will be rejected or terminated, {@code false} 1661 * otherwise. 1662 * @deprecated Companion apps for wearable devices should use the {@link InCallService} API 1663 * instead. Apps performing call screening should use the {@link CallScreeningService} API 1664 * instead. 1665 */ 1666 @RequiresPermission(Manifest.permission.ANSWER_PHONE_CALLS) 1667 @Deprecated endCall()1668 public boolean endCall() { 1669 try { 1670 if (isServiceConnected()) { 1671 return getTelecomService().endCall(mContext.getPackageName()); 1672 } 1673 } catch (RemoteException e) { 1674 Log.e(TAG, "Error calling ITelecomService#endCall", e); 1675 } 1676 return false; 1677 } 1678 1679 /** 1680 * If there is a ringing incoming call, this method accepts the call on behalf of the user. 1681 * 1682 * If the incoming call is a video call, the call will be answered with the same video state as 1683 * the incoming call requests. This means, for example, that an incoming call requesting 1684 * {@link VideoProfile#STATE_BIDIRECTIONAL} will be answered, accepting that state. 1685 * 1686 * Requires permission: {@link android.Manifest.permission#MODIFY_PHONE_STATE} or 1687 * {@link android.Manifest.permission#ANSWER_PHONE_CALLS} 1688 * 1689 * @deprecated Companion apps for wearable devices should use the {@link InCallService} API 1690 * instead. 1691 */ 1692 //TODO: L-release - need to convert all invocation of ITelecmmService#answerRingingCall to use 1693 // this method (clockwork & gearhead). 1694 @RequiresPermission(anyOf = 1695 {Manifest.permission.ANSWER_PHONE_CALLS, Manifest.permission.MODIFY_PHONE_STATE}) 1696 @Deprecated acceptRingingCall()1697 public void acceptRingingCall() { 1698 try { 1699 if (isServiceConnected()) { 1700 getTelecomService().acceptRingingCall(mContext.getPackageName()); 1701 } 1702 } catch (RemoteException e) { 1703 Log.e(TAG, "Error calling ITelecomService#acceptRingingCall", e); 1704 } 1705 } 1706 1707 /** 1708 * If there is a ringing incoming call, this method accepts the call on behalf of the user, 1709 * with the specified video state. 1710 * 1711 * Requires permission: {@link android.Manifest.permission#MODIFY_PHONE_STATE} or 1712 * {@link android.Manifest.permission#ANSWER_PHONE_CALLS} 1713 * 1714 * @param videoState The desired video state to answer the call with. 1715 * @deprecated Companion apps for wearable devices should use the {@link InCallService} API 1716 * instead. 1717 */ 1718 @RequiresPermission(anyOf = 1719 {Manifest.permission.ANSWER_PHONE_CALLS, Manifest.permission.MODIFY_PHONE_STATE}) 1720 @Deprecated acceptRingingCall(int videoState)1721 public void acceptRingingCall(int videoState) { 1722 try { 1723 if (isServiceConnected()) { 1724 getTelecomService().acceptRingingCallWithVideoState( 1725 mContext.getPackageName(), videoState); 1726 } 1727 } catch (RemoteException e) { 1728 Log.e(TAG, "Error calling ITelecomService#acceptRingingCallWithVideoState", e); 1729 } 1730 } 1731 1732 /** 1733 * Silences the ringer if a ringing call exists. 1734 * <p> 1735 * This method can only be relied upon to stop the ringtone for a call if the ringtone has 1736 * already started playing. It is intended to handle use-cases such as silencing a ringing call 1737 * when the user presses the volume button during ringing. 1738 * <p> 1739 * If this method is called prior to when the ringtone begins playing, the ringtone will not be 1740 * silenced. As such it is not intended as a means to avoid playing of a ringtone. 1741 * <p> 1742 * A dialer app which wants to have more control over ringtone playing should declare 1743 * {@link TelecomManager#METADATA_IN_CALL_SERVICE_RINGING} in the manifest entry for their 1744 * {@link InCallService} implementation to indicate that the app wants to be responsible for 1745 * playing the ringtone for all incoming calls. 1746 * <p> 1747 * Requires permission: {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the 1748 * app fills the dialer role (see {@link #getDefaultDialerPackage()}). 1749 */ 1750 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) silenceRinger()1751 public void silenceRinger() { 1752 try { 1753 if (isServiceConnected()) { 1754 getTelecomService().silenceRinger(mContext.getOpPackageName()); 1755 } 1756 } catch (RemoteException e) { 1757 Log.e(TAG, "Error calling ITelecomService#silenceRinger", e); 1758 } 1759 } 1760 1761 /** 1762 * Returns whether TTY is supported on this device. 1763 */ 1764 @RequiresPermission(anyOf = { 1765 READ_PRIVILEGED_PHONE_STATE, 1766 android.Manifest.permission.READ_PHONE_STATE 1767 }) isTtySupported()1768 public boolean isTtySupported() { 1769 try { 1770 if (isServiceConnected()) { 1771 return getTelecomService().isTtySupported(mContext.getOpPackageName()); 1772 } 1773 } catch (RemoteException e) { 1774 Log.e(TAG, "RemoteException attempting to get TTY supported state.", e); 1775 } 1776 return false; 1777 } 1778 1779 /** 1780 * Returns the current TTY mode of the device. For TTY to be on the user must enable it in 1781 * settings and have a wired headset plugged in. 1782 * Valid modes are: 1783 * - {@link TelecomManager#TTY_MODE_OFF} 1784 * - {@link TelecomManager#TTY_MODE_FULL} 1785 * - {@link TelecomManager#TTY_MODE_HCO} 1786 * - {@link TelecomManager#TTY_MODE_VCO} 1787 * @hide 1788 */ 1789 @SystemApi 1790 @TestApi 1791 @RequiresPermission(READ_PRIVILEGED_PHONE_STATE) getCurrentTtyMode()1792 public @TtyMode int getCurrentTtyMode() { 1793 try { 1794 if (isServiceConnected()) { 1795 return getTelecomService().getCurrentTtyMode(mContext.getOpPackageName()); 1796 } 1797 } catch (RemoteException e) { 1798 Log.e(TAG, "RemoteException attempting to get the current TTY mode.", e); 1799 } 1800 return TTY_MODE_OFF; 1801 } 1802 1803 /** 1804 * Registers a new incoming call. A {@link ConnectionService} should invoke this method when it 1805 * has an incoming call. For managed {@link ConnectionService}s, the specified 1806 * {@link PhoneAccountHandle} must have been registered with {@link #registerPhoneAccount} and 1807 * the user must have enabled the corresponding {@link PhoneAccount}. This can be checked using 1808 * {@link #getPhoneAccount}. Self-managed {@link ConnectionService}s must have 1809 * {@link android.Manifest.permission#MANAGE_OWN_CALLS} to add a new incoming call. 1810 * <p> 1811 * The incoming call you are adding is assumed to have a video state of 1812 * {@link VideoProfile#STATE_AUDIO_ONLY}, unless the extra value 1813 * {@link #EXTRA_INCOMING_VIDEO_STATE} is specified. 1814 * <p> 1815 * Once invoked, this method will cause the system to bind to the {@link ConnectionService} 1816 * associated with the {@link PhoneAccountHandle} and request additional information about the 1817 * call (See {@link ConnectionService#onCreateIncomingConnection}) before starting the incoming 1818 * call UI. 1819 * <p> 1820 * For a managed {@link ConnectionService}, a {@link SecurityException} will be thrown if either 1821 * the {@link PhoneAccountHandle} does not correspond to a registered {@link PhoneAccount} or 1822 * the associated {@link PhoneAccount} is not currently enabled by the user. 1823 * <p> 1824 * For a self-managed {@link ConnectionService}, a {@link SecurityException} will be thrown if 1825 * the {@link PhoneAccount} has {@link PhoneAccount#CAPABILITY_SELF_MANAGED} and the calling app 1826 * does not have {@link android.Manifest.permission#MANAGE_OWN_CALLS}. 1827 * 1828 * @param phoneAccount A {@link PhoneAccountHandle} registered with 1829 * {@link #registerPhoneAccount}. 1830 * @param extras A bundle that will be passed through to 1831 * {@link ConnectionService#onCreateIncomingConnection}. 1832 */ addNewIncomingCall(PhoneAccountHandle phoneAccount, Bundle extras)1833 public void addNewIncomingCall(PhoneAccountHandle phoneAccount, Bundle extras) { 1834 try { 1835 if (isServiceConnected()) { 1836 if (extras != null && extras.getBoolean(EXTRA_IS_HANDOVER) && 1837 mContext.getApplicationContext().getApplicationInfo().targetSdkVersion > 1838 Build.VERSION_CODES.O_MR1) { 1839 Log.e("TAG", "addNewIncomingCall failed. Use public api " + 1840 "acceptHandover for API > O-MR1"); 1841 return; 1842 } 1843 getTelecomService().addNewIncomingCall( 1844 phoneAccount, extras == null ? new Bundle() : extras); 1845 } 1846 } catch (RemoteException e) { 1847 Log.e(TAG, "RemoteException adding a new incoming call: " + phoneAccount, e); 1848 } 1849 } 1850 1851 /** 1852 * Registers a new incoming conference. A {@link ConnectionService} should invoke this method 1853 * when it has an incoming conference. An incoming {@link Conference} is an adhoc conference 1854 * call initiated on another device which the user is being invited to join in. For managed 1855 * {@link ConnectionService}s, the specified {@link PhoneAccountHandle} must have been 1856 * registered with {@link #registerPhoneAccount} and the user must have enabled the 1857 * corresponding {@link PhoneAccount}. This can be checked using 1858 * {@link #getPhoneAccount(PhoneAccountHandle)}. Self-managed {@link ConnectionService}s must 1859 * have {@link android.Manifest.permission#MANAGE_OWN_CALLS} to add a new incoming call. 1860 * <p> 1861 * The incoming conference you are adding is assumed to have a video state of 1862 * {@link VideoProfile#STATE_AUDIO_ONLY}, unless the extra value 1863 * {@link #EXTRA_INCOMING_VIDEO_STATE} is specified. 1864 * <p> 1865 * Once invoked, this method will cause the system to bind to the {@link ConnectionService} 1866 * associated with the {@link PhoneAccountHandle} and request additional information about the 1867 * call (See 1868 * {@link ConnectionService#onCreateIncomingConference(PhoneAccountHandle, ConnectionRequest)}) 1869 * before starting the incoming call UI. 1870 * <p> 1871 * For a managed {@link ConnectionService}, a {@link SecurityException} will be thrown if either 1872 * the {@link PhoneAccountHandle} does not correspond to a registered {@link PhoneAccount} or 1873 * the associated {@link PhoneAccount} is not currently enabled by the user. 1874 * 1875 * @param phoneAccount A {@link PhoneAccountHandle} registered with 1876 * {@link #registerPhoneAccount}. 1877 * @param extras A bundle that will be passed through to 1878 * {@link ConnectionService#onCreateIncomingConference}. 1879 */ addNewIncomingConference(@onNull PhoneAccountHandle phoneAccount, @NonNull Bundle extras)1880 public void addNewIncomingConference(@NonNull PhoneAccountHandle phoneAccount, 1881 @NonNull Bundle extras) { 1882 try { 1883 if (isServiceConnected()) { 1884 getTelecomService().addNewIncomingConference( 1885 phoneAccount, extras == null ? new Bundle() : extras); 1886 } 1887 } catch (RemoteException e) { 1888 Log.e(TAG, "RemoteException adding a new incoming conference: " + phoneAccount, e); 1889 } 1890 } 1891 1892 /** 1893 * Registers a new unknown call with Telecom. This can only be called by the system Telephony 1894 * service. This is invoked when Telephony detects a new unknown connection that was neither 1895 * a new incoming call, nor an user-initiated outgoing call. 1896 * 1897 * @param phoneAccount A {@link PhoneAccountHandle} registered with 1898 * {@link #registerPhoneAccount}. 1899 * @param extras A bundle that will be passed through to 1900 * {@link ConnectionService#onCreateIncomingConnection}. 1901 * @hide 1902 */ 1903 @SystemApi addNewUnknownCall(PhoneAccountHandle phoneAccount, Bundle extras)1904 public void addNewUnknownCall(PhoneAccountHandle phoneAccount, Bundle extras) { 1905 try { 1906 if (isServiceConnected()) { 1907 getTelecomService().addNewUnknownCall( 1908 phoneAccount, extras == null ? new Bundle() : extras); 1909 } 1910 } catch (RemoteException e) { 1911 Log.e(TAG, "RemoteException adding a new unknown call: " + phoneAccount, e); 1912 } 1913 } 1914 1915 /** 1916 * Processes the specified dial string as an MMI code. 1917 * MMI codes are any sequence of characters entered into the dialpad that contain a "*" or "#". 1918 * Some of these sequences launch special behavior through handled by Telephony. 1919 * This method uses the default subscription. 1920 * <p> 1921 * Requires that the method-caller be set as the system dialer app. 1922 * </p> 1923 * 1924 * Requires permission: {@link android.Manifest.permission#MODIFY_PHONE_STATE} 1925 * 1926 * @param dialString The digits to dial. 1927 * @return True if the digits were processed as an MMI code, false otherwise. 1928 */ 1929 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) handleMmi(String dialString)1930 public boolean handleMmi(String dialString) { 1931 ITelecomService service = getTelecomService(); 1932 if (service != null) { 1933 try { 1934 return service.handlePinMmi(dialString, mContext.getOpPackageName()); 1935 } catch (RemoteException e) { 1936 Log.e(TAG, "Error calling ITelecomService#handlePinMmi", e); 1937 } 1938 } 1939 return false; 1940 } 1941 1942 /** 1943 * Processes the specified dial string as an MMI code. 1944 * MMI codes are any sequence of characters entered into the dialpad that contain a "*" or "#". 1945 * Some of these sequences launch special behavior through handled by Telephony. 1946 * <p> 1947 * Requires that the method-caller be set as the system dialer app. 1948 * </p> 1949 * 1950 * Requires permission: {@link android.Manifest.permission#MODIFY_PHONE_STATE} 1951 * 1952 * @param accountHandle The handle for the account the MMI code should apply to. 1953 * @param dialString The digits to dial. 1954 * @return True if the digits were processed as an MMI code, false otherwise. 1955 */ 1956 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) handleMmi(String dialString, PhoneAccountHandle accountHandle)1957 public boolean handleMmi(String dialString, PhoneAccountHandle accountHandle) { 1958 ITelecomService service = getTelecomService(); 1959 if (service != null) { 1960 try { 1961 return service.handlePinMmiForPhoneAccount(accountHandle, dialString, 1962 mContext.getOpPackageName()); 1963 } catch (RemoteException e) { 1964 Log.e(TAG, "Error calling ITelecomService#handlePinMmi", e); 1965 } 1966 } 1967 return false; 1968 } 1969 1970 /** 1971 * Requires permission: {@link android.Manifest.permission#MODIFY_PHONE_STATE} 1972 * 1973 * @param accountHandle The handle for the account to derive an adn query URI for or 1974 * {@code null} to return a URI which will use the default account. 1975 * @return The URI (with the content:// scheme) specific to the specified {@link PhoneAccount} 1976 * for the the content retrieve. 1977 */ 1978 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) getAdnUriForPhoneAccount(PhoneAccountHandle accountHandle)1979 public Uri getAdnUriForPhoneAccount(PhoneAccountHandle accountHandle) { 1980 ITelecomService service = getTelecomService(); 1981 if (service != null && accountHandle != null) { 1982 try { 1983 return service.getAdnUriForPhoneAccount(accountHandle, mContext.getOpPackageName()); 1984 } catch (RemoteException e) { 1985 Log.e(TAG, "Error calling ITelecomService#getAdnUriForPhoneAccount", e); 1986 } 1987 } 1988 return Uri.parse("content://icc/adn"); 1989 } 1990 1991 /** 1992 * Removes the missed-call notification if one is present. 1993 * <p> 1994 * Requires that the method-caller be set as the system dialer app. 1995 * </p> 1996 * 1997 * Requires permission: {@link android.Manifest.permission#MODIFY_PHONE_STATE} 1998 */ 1999 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) cancelMissedCallsNotification()2000 public void cancelMissedCallsNotification() { 2001 ITelecomService service = getTelecomService(); 2002 if (service != null) { 2003 try { 2004 service.cancelMissedCallsNotification(mContext.getOpPackageName()); 2005 } catch (RemoteException e) { 2006 Log.e(TAG, "Error calling ITelecomService#cancelMissedCallsNotification", e); 2007 } 2008 } 2009 } 2010 2011 /** 2012 * Brings the in-call screen to the foreground if there is an ongoing call. If there is 2013 * currently no ongoing call, then this method does nothing. 2014 * <p> 2015 * Requires that the method-caller be set as the system dialer app or have the 2016 * {@link android.Manifest.permission#READ_PHONE_STATE} permission. 2017 * </p> 2018 * 2019 * @param showDialpad Brings up the in-call dialpad as part of showing the in-call screen. 2020 */ 2021 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) showInCallScreen(boolean showDialpad)2022 public void showInCallScreen(boolean showDialpad) { 2023 ITelecomService service = getTelecomService(); 2024 if (service != null) { 2025 try { 2026 service.showInCallScreen(showDialpad, mContext.getOpPackageName()); 2027 } catch (RemoteException e) { 2028 Log.e(TAG, "Error calling ITelecomService#showCallScreen", e); 2029 } 2030 } 2031 } 2032 2033 /** 2034 * Places a new outgoing call to the provided address using the system telecom service with 2035 * the specified extras. 2036 * 2037 * This method is equivalent to placing an outgoing call using {@link Intent#ACTION_CALL}, 2038 * except that the outgoing call will always be sent via the system telecom service. If 2039 * method-caller is either the user selected default dialer app or preloaded system dialer 2040 * app, then emergency calls will also be allowed. 2041 * 2042 * Placing a call via a managed {@link ConnectionService} requires permission: 2043 * {@link android.Manifest.permission#CALL_PHONE} 2044 * 2045 * Usage example: 2046 * <pre> 2047 * Uri uri = Uri.fromParts("tel", "12345", null); 2048 * Bundle extras = new Bundle(); 2049 * extras.putBoolean(TelecomManager.EXTRA_START_CALL_WITH_SPEAKERPHONE, true); 2050 * telecomManager.placeCall(uri, extras); 2051 * </pre> 2052 * 2053 * The following keys are supported in the supplied extras. 2054 * <ul> 2055 * <li>{@link #EXTRA_OUTGOING_CALL_EXTRAS}</li> 2056 * <li>{@link #EXTRA_PHONE_ACCOUNT_HANDLE}</li> 2057 * <li>{@link #EXTRA_START_CALL_WITH_SPEAKERPHONE}</li> 2058 * <li>{@link #EXTRA_START_CALL_WITH_VIDEO_STATE}</li> 2059 * </ul> 2060 * <p> 2061 * An app which implements the self-managed {@link ConnectionService} API uses 2062 * {@link #placeCall(Uri, Bundle)} to inform Telecom of a new outgoing call. A self-managed 2063 * {@link ConnectionService} must include {@link #EXTRA_PHONE_ACCOUNT_HANDLE} to specify its 2064 * associated {@link android.telecom.PhoneAccountHandle}. 2065 * 2066 * Self-managed {@link ConnectionService}s require permission 2067 * {@link android.Manifest.permission#MANAGE_OWN_CALLS}. 2068 * 2069 * <p class="note"><strong>Note:</strong> If this method is used to place an emergency call, it 2070 * is not guaranteed that the call will be placed on the {@link PhoneAccount} provided in 2071 * the {@link #EXTRA_PHONE_ACCOUNT_HANDLE} extra (if specified) and may be placed on another 2072 * {@link PhoneAccount} with the {@link PhoneAccount#CAPABILITY_PLACE_EMERGENCY_CALLS} 2073 * capability, depending on external factors, such as network conditions and Modem/SIM status. 2074 * </p> 2075 * 2076 * @param address The address to make the call to. 2077 * @param extras Bundle of extras to use with the call. 2078 */ 2079 @RequiresPermission(anyOf = {android.Manifest.permission.CALL_PHONE, 2080 android.Manifest.permission.MANAGE_OWN_CALLS}) placeCall(Uri address, Bundle extras)2081 public void placeCall(Uri address, Bundle extras) { 2082 ITelecomService service = getTelecomService(); 2083 if (service != null) { 2084 if (address == null) { 2085 Log.w(TAG, "Cannot place call to empty address."); 2086 } 2087 try { 2088 service.placeCall(address, extras == null ? new Bundle() : extras, 2089 mContext.getOpPackageName()); 2090 } catch (RemoteException e) { 2091 Log.e(TAG, "Error calling ITelecomService#placeCall", e); 2092 } 2093 } 2094 } 2095 2096 2097 /** 2098 * Place a new adhoc conference call with the provided participants using the system telecom 2099 * service. This method doesn't support placing of emergency calls. 2100 * 2101 * An adhoc conference call is established by providing a list of addresses to 2102 * {@code TelecomManager#startConference(List<Uri>, int videoState)} where the 2103 * {@link ConnectionService} is responsible for connecting all indicated participants 2104 * to a conference simultaneously. 2105 * This is in contrast to conferences formed by merging calls together (e.g. using 2106 * {@link android.telecom.Call#mergeConference()}). 2107 * 2108 * The following keys are supported in the supplied extras. 2109 * <ul> 2110 * <li>{@link #EXTRA_PHONE_ACCOUNT_HANDLE}</li> 2111 * <li>{@link #EXTRA_START_CALL_WITH_SPEAKERPHONE}</li> 2112 * <li>{@link #EXTRA_START_CALL_WITH_VIDEO_STATE}</li> 2113 * </ul> 2114 * 2115 * @param participants List of participants to start conference with 2116 * @param extras Bundle of extras to use with the call 2117 */ 2118 @RequiresPermission(android.Manifest.permission.CALL_PHONE) startConference(@onNull List<Uri> participants, @NonNull Bundle extras)2119 public void startConference(@NonNull List<Uri> participants, 2120 @NonNull Bundle extras) { 2121 ITelecomService service = getTelecomService(); 2122 if (service != null) { 2123 try { 2124 service.startConference(participants, extras, 2125 mContext.getOpPackageName()); 2126 } catch (RemoteException e) { 2127 Log.e(TAG, "Error calling ITelecomService#placeCall", e); 2128 } 2129 } 2130 } 2131 2132 /** 2133 * Enables and disables specified phone account. 2134 * 2135 * @param handle Handle to the phone account. 2136 * @param isEnabled Enable state of the phone account. 2137 * @hide 2138 */ 2139 @SystemApi 2140 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) enablePhoneAccount(PhoneAccountHandle handle, boolean isEnabled)2141 public void enablePhoneAccount(PhoneAccountHandle handle, boolean isEnabled) { 2142 ITelecomService service = getTelecomService(); 2143 if (service != null) { 2144 try { 2145 service.enablePhoneAccount(handle, isEnabled); 2146 } catch (RemoteException e) { 2147 Log.e(TAG, "Error enablePhoneAbbount", e); 2148 } 2149 } 2150 } 2151 2152 /** 2153 * Dumps telecom analytics for uploading. 2154 * 2155 * @return 2156 * @hide 2157 */ 2158 @SystemApi 2159 @RequiresPermission(Manifest.permission.DUMP) dumpAnalytics()2160 public TelecomAnalytics dumpAnalytics() { 2161 ITelecomService service = getTelecomService(); 2162 TelecomAnalytics result = null; 2163 if (service != null) { 2164 try { 2165 result = service.dumpCallAnalytics(); 2166 } catch (RemoteException e) { 2167 Log.e(TAG, "Error dumping call analytics", e); 2168 } 2169 } 2170 return result; 2171 } 2172 2173 /** 2174 * Creates the {@link Intent} which can be used with {@link Context#startActivity(Intent)} to 2175 * launch the activity to manage blocked numbers. 2176 * <p> The activity will display the UI to manage blocked numbers only if 2177 * {@link android.provider.BlockedNumberContract#canCurrentUserBlockNumbers(Context)} returns 2178 * {@code true} for the current user. 2179 */ createManageBlockedNumbersIntent()2180 public Intent createManageBlockedNumbersIntent() { 2181 ITelecomService service = getTelecomService(); 2182 Intent result = null; 2183 if (service != null) { 2184 try { 2185 result = service.createManageBlockedNumbersIntent(); 2186 } catch (RemoteException e) { 2187 Log.e(TAG, "Error calling ITelecomService#createManageBlockedNumbersIntent", e); 2188 } 2189 } 2190 return result; 2191 } 2192 2193 2194 /** 2195 * Creates the {@link Intent} which can be used with {@link Context#startActivity(Intent)} to 2196 * launch the activity for emergency dialer. 2197 * 2198 * @param number Optional number to call in emergency dialer 2199 * @hide 2200 */ 2201 @SystemApi 2202 @NonNull createLaunchEmergencyDialerIntent(@ullable String number)2203 public Intent createLaunchEmergencyDialerIntent(@Nullable String number) { 2204 ITelecomService service = getTelecomService(); 2205 Intent result = null; 2206 if (service != null) { 2207 try { 2208 result = service.createLaunchEmergencyDialerIntent(number); 2209 } catch (RemoteException e) { 2210 Log.e(TAG, "Error createLaunchEmergencyDialerIntent", e); 2211 } 2212 } 2213 return result; 2214 } 2215 2216 /** 2217 * Determines whether Telecom would permit an incoming call to be added via the 2218 * {@link #addNewIncomingCall(PhoneAccountHandle, Bundle)} API for the specified 2219 * {@link PhoneAccountHandle}. 2220 * <p> 2221 * A {@link ConnectionService} may not add a call for the specified {@link PhoneAccountHandle} 2222 * in the following situations: 2223 * <ul> 2224 * <li>{@link PhoneAccount} does not have property 2225 * {@link PhoneAccount#CAPABILITY_SELF_MANAGED} set (i.e. it is a managed 2226 * {@link ConnectionService}), and the active or held call limit has 2227 * been reached.</li> 2228 * <li>There is an ongoing emergency call.</li> 2229 * </ul> 2230 * 2231 * @param phoneAccountHandle The {@link PhoneAccountHandle} the call will be added for. 2232 * @return {@code true} if telecom will permit an incoming call to be added, {@code false} 2233 * otherwise. 2234 */ isIncomingCallPermitted(PhoneAccountHandle phoneAccountHandle)2235 public boolean isIncomingCallPermitted(PhoneAccountHandle phoneAccountHandle) { 2236 if (phoneAccountHandle == null) { 2237 return false; 2238 } 2239 2240 ITelecomService service = getTelecomService(); 2241 if (service != null) { 2242 try { 2243 return service.isIncomingCallPermitted(phoneAccountHandle); 2244 } catch (RemoteException e) { 2245 Log.e(TAG, "Error isIncomingCallPermitted", e); 2246 } 2247 } 2248 return false; 2249 } 2250 2251 /** 2252 * Determines whether Telecom would permit an outgoing call to be placed via the 2253 * {@link #placeCall(Uri, Bundle)} API for the specified {@link PhoneAccountHandle}. 2254 * <p> 2255 * A {@link ConnectionService} may not place a call for the specified {@link PhoneAccountHandle} 2256 * in the following situations: 2257 * <ul> 2258 * <li>{@link PhoneAccount} does not have property 2259 * {@link PhoneAccount#CAPABILITY_SELF_MANAGED} set (i.e. it is a managed 2260 * {@link ConnectionService}), and the active, held or ringing call limit has 2261 * been reached.</li> 2262 * <li>{@link PhoneAccount} has property {@link PhoneAccount#CAPABILITY_SELF_MANAGED} set 2263 * (i.e. it is a self-managed {@link ConnectionService} and there is an ongoing call in 2264 * another {@link ConnectionService}.</li> 2265 * <li>There is an ongoing emergency call.</li> 2266 * </ul> 2267 * 2268 * @param phoneAccountHandle The {@link PhoneAccountHandle} the call will be added for. 2269 * @return {@code true} if telecom will permit an outgoing call to be placed, {@code false} 2270 * otherwise. 2271 */ isOutgoingCallPermitted(PhoneAccountHandle phoneAccountHandle)2272 public boolean isOutgoingCallPermitted(PhoneAccountHandle phoneAccountHandle) { 2273 ITelecomService service = getTelecomService(); 2274 if (service != null) { 2275 try { 2276 return service.isOutgoingCallPermitted(phoneAccountHandle); 2277 } catch (RemoteException e) { 2278 Log.e(TAG, "Error isOutgoingCallPermitted", e); 2279 } 2280 } 2281 return false; 2282 } 2283 2284 /** 2285 * Called by an app to indicate that it wishes to accept the handover of an ongoing call to a 2286 * {@link PhoneAccountHandle} it defines. 2287 * <p> 2288 * A call handover is the process where an ongoing call is transferred from one app (i.e. 2289 * {@link ConnectionService} to another app. The user could, for example, choose to continue a 2290 * mobile network call in a video calling app. The mobile network call via the Telephony stack 2291 * is referred to as the source of the handover, and the video calling app is referred to as the 2292 * destination. 2293 * <p> 2294 * When considering a handover scenario the <em>initiating</em> device is where a user initiated 2295 * the handover process (e.g. by calling {@link android.telecom.Call#handoverTo( 2296 * PhoneAccountHandle, int, Bundle)}, and the other device is considered the <em>receiving</em> 2297 * device. 2298 * <p> 2299 * For a full discussion of the handover process and the APIs involved, see 2300 * {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int, Bundle)}. 2301 * <p> 2302 * This method is called from the <em>receiving</em> side of a handover to indicate a desire to 2303 * accept the handover of an ongoing call to another {@link ConnectionService} identified by 2304 * {@link PhoneAccountHandle} destAcct. For managed {@link ConnectionService}s, the specified 2305 * {@link PhoneAccountHandle} must have been registered with {@link #registerPhoneAccount} and 2306 * the user must have enabled the corresponding {@link PhoneAccount}. This can be checked using 2307 * {@link #getPhoneAccount}. Self-managed {@link ConnectionService}s must have 2308 * {@link android.Manifest.permission#MANAGE_OWN_CALLS} to handover a call to it. 2309 * <p> 2310 * Once invoked, this method will cause the system to bind to the {@link ConnectionService} 2311 * associated with the {@link PhoneAccountHandle} destAcct and call 2312 * (See {@link ConnectionService#onCreateIncomingHandoverConnection}). 2313 * <p> 2314 * For a managed {@link ConnectionService}, a {@link SecurityException} will be thrown if either 2315 * the {@link PhoneAccountHandle} destAcct does not correspond to a registered 2316 * {@link PhoneAccount} or the associated {@link PhoneAccount} is not currently enabled by the 2317 * user. 2318 * <p> 2319 * For a self-managed {@link ConnectionService}, a {@link SecurityException} will be thrown if 2320 * the calling app does not have {@link android.Manifest.permission#MANAGE_OWN_CALLS}. 2321 * 2322 * @param srcAddr The {@link android.net.Uri} of the ongoing call to handover to the caller’s 2323 * {@link ConnectionService}. 2324 * @param videoState Video state after the handover. 2325 * @param destAcct The {@link PhoneAccountHandle} registered to the calling package. 2326 */ acceptHandover(Uri srcAddr, @VideoProfile.VideoState int videoState, PhoneAccountHandle destAcct)2327 public void acceptHandover(Uri srcAddr, @VideoProfile.VideoState int videoState, 2328 PhoneAccountHandle destAcct) { 2329 try { 2330 if (isServiceConnected()) { 2331 getTelecomService().acceptHandover(srcAddr, videoState, destAcct); 2332 } 2333 } catch (RemoteException e) { 2334 Log.e(TAG, "RemoteException acceptHandover: " + e); 2335 } 2336 } 2337 2338 /** 2339 * Determines if there is an ongoing emergency call. This can be either an outgoing emergency 2340 * call, as identified by the dialed number, or because a call was identified by the network 2341 * as an emergency call. 2342 * @return {@code true} if there is an ongoing emergency call, {@code false} otherwise. 2343 * @hide 2344 */ 2345 @SystemApi 2346 @TestApi 2347 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) isInEmergencyCall()2348 public boolean isInEmergencyCall() { 2349 try { 2350 if (isServiceConnected()) { 2351 return getTelecomService().isInEmergencyCall(); 2352 } 2353 } catch (RemoteException e) { 2354 Log.e(TAG, "RemoteException isInEmergencyCall: " + e); 2355 return false; 2356 } 2357 return false; 2358 } 2359 2360 /** 2361 * Handles {@link Intent#ACTION_CALL} intents trampolined from UserCallActivity. 2362 * @param intent The {@link Intent#ACTION_CALL} intent to handle. 2363 * @param callingPackageProxy The original package that called this before it was trampolined. 2364 * @hide 2365 */ handleCallIntent(Intent intent, String callingPackageProxy)2366 public void handleCallIntent(Intent intent, String callingPackageProxy) { 2367 try { 2368 if (isServiceConnected()) { 2369 getTelecomService().handleCallIntent(intent, callingPackageProxy); 2370 } 2371 } catch (RemoteException e) { 2372 Log.e(TAG, "RemoteException handleCallIntent: " + e); 2373 } 2374 } 2375 getTelecomService()2376 private ITelecomService getTelecomService() { 2377 if (mTelecomServiceOverride != null) { 2378 return mTelecomServiceOverride; 2379 } 2380 return ITelecomService.Stub.asInterface(ServiceManager.getService(Context.TELECOM_SERVICE)); 2381 } 2382 isServiceConnected()2383 private boolean isServiceConnected() { 2384 boolean isConnected = getTelecomService() != null; 2385 if (!isConnected) { 2386 Log.w(TAG, "Telecom Service not found."); 2387 } 2388 return isConnected; 2389 } 2390 } 2391