blob: af3c55abf00c877272ebfa1941dde7d87ab1dec7 [file] [log] [blame]
Yorke Leeb4ce1432014-06-09 13:53:23 -07001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
Santos Cordon9eb45932014-06-27 12:28:43 -07004 * 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
Yorke Leeb4ce1432014-06-09 13:53:23 -07006 *
Santos Cordon9eb45932014-06-27 12:28:43 -07007 * http://www.apache.org/licenses/LICENSE-2.0
Yorke Leeb4ce1432014-06-09 13:53:23 -07008 *
Santos Cordon9eb45932014-06-27 12:28:43 -07009 * 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.
Yorke Leeb4ce1432014-06-09 13:53:23 -070013 */
14
Tyler Gunnef9f6f92014-09-12 22:16:17 -070015package android.telecom;
Yorke Leeb4ce1432014-06-09 13:53:23 -070016
Tyler Gunn5567d742019-10-31 13:04:37 -070017import static android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE;
18
Hall Liu0464b9b2016-01-12 15:32:58 -080019import android.Manifest;
Tyler Gunn6e3ecc42018-11-12 11:30:56 -080020import android.annotation.IntDef;
Hall Liub2306242019-11-15 17:13:05 -080021import android.annotation.NonNull;
Slava Shklyaeve65e4012019-03-04 16:02:34 +000022import android.annotation.Nullable;
Yorke Leec61d1362015-09-21 17:25:25 -070023import android.annotation.RequiresPermission;
Jeff Sharkey910e0812017-04-21 16:29:27 -060024import android.annotation.SuppressAutoDoc;
Jeff Sharkeybfc4fcd2017-06-05 17:38:17 -060025import android.annotation.SuppressLint;
Santos Cordon6c7a3882014-06-25 15:30:08 -070026import android.annotation.SystemApi;
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -060027import android.annotation.SystemService;
Tyler Gunn6c14a6992019-02-04 15:12:06 -080028import android.annotation.TestApi;
Austin Wanga63a2c02019-12-19 06:38:19 +000029import android.annotation.UnsupportedAppUsage;
Santos Cordon6c7a3882014-06-25 15:30:08 -070030import android.content.ComponentName;
Yorke Leeb4ce1432014-06-09 13:53:23 -070031import android.content.Context;
Yorke Lee3e56ba12015-04-23 12:32:36 -070032import android.content.Intent;
Nancy Chenb2299c12014-10-29 18:22:11 -070033import android.net.Uri;
Sanket Padawef6a9e5b2018-01-05 14:26:16 -080034import android.os.Build;
Santos Cordon96efb482014-07-19 14:57:05 -070035import android.os.Bundle;
Santos Cordon6c7a3882014-06-25 15:30:08 -070036import android.os.RemoteException;
37import android.os.ServiceManager;
Tyler Gunn7e45b722018-12-04 12:56:45 -080038import android.os.UserHandle;
Chen Xu7631ff72019-09-26 16:11:59 -070039import android.telephony.Annotation.CallState;
Brad Ebingere7833312019-05-07 10:55:55 -070040import android.telephony.SubscriptionManager;
Yorke Lee2ae312e2014-09-12 17:58:48 -070041import android.telephony.TelephonyManager;
Anthony Lee67279262014-10-27 11:28:40 -070042import android.text.TextUtils;
Santos Cordon6c7a3882014-06-25 15:30:08 -070043import android.util.Log;
Yorke Leeb4ce1432014-06-09 13:53:23 -070044
Tyler Gunnef9f6f92014-09-12 22:16:17 -070045import com.android.internal.telecom.ITelecomService;
Yorke Leeb4ce1432014-06-09 13:53:23 -070046
Tyler Gunn6e3ecc42018-11-12 11:30:56 -080047import java.lang.annotation.Retention;
48import java.lang.annotation.RetentionPolicy;
Jay Shrauner7746a942014-08-26 12:15:15 -070049import java.util.ArrayList;
Tyler Gunna1ed7d12014-09-08 09:52:22 -070050import java.util.Collections;
Ihab Awad807fe0a2014-07-09 12:30:52 -070051import java.util.List;
Tyler Gunn7e45b722018-12-04 12:56:45 -080052import java.util.concurrent.Executor;
Ihab Awad807fe0a2014-07-09 12:30:52 -070053
Yorke Leeb4ce1432014-06-09 13:53:23 -070054/**
Santos Cordond9e614f2014-10-28 13:10:36 -070055 * Provides access to information about active calls and registration/call-management functionality.
Evan Charlton0e094d92014-11-08 15:49:16 -080056 * Apps can use methods in this class to determine the current call state.
Santos Cordond9e614f2014-10-28 13:10:36 -070057 * <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.
Yorke Leeb4ce1432014-06-09 13:53:23 -070065 */
Jeff Sharkey910e0812017-04-21 16:29:27 -060066@SuppressAutoDoc
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -060067@SystemService(Context.TELECOM_SERVICE)
Tyler Gunnef9f6f92014-09-12 22:16:17 -070068public class TelecomManager {
Ihab Awad807fe0a2014-07-09 12:30:52 -070069
Evan Charlton10197192014-07-19 15:00:29 -070070 /**
Santos Cordon96efb482014-07-19 14:57:05 -070071 * Activity action: Starts the UI for handing an incoming call. This intent starts the in-call
Tyler Gunnef9f6f92014-09-12 22:16:17 -070072 * 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
Santos Cordon96efb482014-07-19 14:57:05 -070075 * 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
Tyler Gunnef9f6f92014-09-12 22:16:17 -070078 * {@link android.telecom.ConnectionService} that Telecom should bind to. Telecom will then
Evan Charlton10197192014-07-19 15:00:29 -070079 * ask the connection service for more information about the call prior to showing any UI.
Brad Ebinger23b1c6d2017-01-12 13:10:40 -080080 *
81 * @deprecated Use {@link #addNewIncomingCall} instead.
Evan Charlton10197192014-07-19 15:00:29 -070082 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -070083 public static final String ACTION_INCOMING_CALL = "android.telecom.action.INCOMING_CALL";
Evan Charlton10197192014-07-19 15:00:29 -070084
85 /**
Yorke Leec3cf9822014-10-02 09:38:39 -070086 * Similar to {@link #ACTION_INCOMING_CALL}, but is used only by Telephony to add a new
87 * sim-initiated MO call for carrier testing.
Brad Ebinger23b1c6d2017-01-12 13:10:40 -080088 * @deprecated Use {@link #addNewUnknownCall} instead.
Yorke Leec3cf9822014-10-02 09:38:39 -070089 * @hide
90 */
91 public static final String ACTION_NEW_UNKNOWN_CALL = "android.telecom.action.NEW_UNKNOWN_CALL";
92
93 /**
Santos Cordon895d4b82015-06-25 16:41:48 -070094 * 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.
Evan Charlton10197192014-07-19 15:00:29 -0700104 */
Santos Cordon895d4b82015-06-25 16:41:48 -0700105 public static final String ACTION_CONFIGURE_PHONE_ACCOUNT =
106 "android.telecom.action.CONFIGURE_PHONE_ACCOUNT";
Evan Charlton10197192014-07-19 15:00:29 -0700107
108 /**
Andrew Lee873cfbf2015-02-26 15:22:00 -0800109 * 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 /**
Yorke Lee3818a892014-07-21 15:57:17 -0700115 * The {@link android.content.Intent} action used to show the call settings page.
116 */
117 public static final String ACTION_SHOW_CALL_SETTINGS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700118 "android.telecom.action.SHOW_CALL_SETTINGS";
Yorke Lee3818a892014-07-21 15:57:17 -0700119
120 /**
Andrew Lee866080f2015-02-19 12:05:33 -0800121 * 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 /**
Evan Charlton6d8604f2014-09-04 12:38:17 -0700127 * 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 =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700131 "android.telecom.action.CHANGE_PHONE_ACCOUNTS";
Evan Charlton6d8604f2014-09-04 12:38:17 -0700132
133 /**
Tyler Gunnd9da6ce2017-04-14 13:43:30 -0700134 * {@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()}).
Santos Cordonc66f3ba2015-02-27 15:22:07 -0800141 */
Santos Cordonc66f3ba2015-02-27 15:22:07 -0800142 public static final String ACTION_PHONE_ACCOUNT_REGISTERED =
143 "android.telecom.action.PHONE_ACCOUNT_REGISTERED";
144
145 /**
Tyler Gunnd9da6ce2017-04-14 13:43:30 -0700146 * {@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()}).
Bryce Lee30b0aa02015-09-23 21:53:53 -0700153 */
Bryce Lee30b0aa02015-09-23 21:53:53 -0700154 public static final String ACTION_PHONE_ACCOUNT_UNREGISTERED =
155 "android.telecom.action.PHONE_ACCOUNT_UNREGISTERED";
156
157 /**
Yorke Lee1011f482015-04-23 15:58:27 -0700158 * 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>
Hai Zhang929085f2019-05-03 15:31:43 +0800169 * <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.
Yorke Lee1011f482015-04-23 15:58:27 -0700173 */
174 public static final String ACTION_CHANGE_DEFAULT_DIALER =
175 "android.telecom.action.CHANGE_DEFAULT_DIALER";
176
177 /**
Yorke Lee107c4ce2015-06-15 12:08:24 -0700178 * 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 /**
Yorke Lee1011f482015-04-23 15:58:27 -0700188 * 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 /**
tonyzhuff60f5e2018-10-01 19:14:59 +0800194 * Broadcast intent action indicating that the current default call screening app has changed.
195 *
196 * The string extra {@link #EXTRA_DEFAULT_CALL_SCREENING_APP_COMPONENT_NAME} will contain the
197 * name of the Component of the previous or the new call screening app.
198 *
199 * The boolean extra {@link #EXTRA_IS_DEFAULT_CALL_SCREENING_APP} will indicate the component
200 * name in the String extra {@link #EXTRA_DEFAULT_CALL_SCREENING_APP_COMPONENT_NAME} is default
201 * call screening app or 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 */
210 public static final String EXTRA_DEFAULT_CALL_SCREENING_APP_COMPONENT_NAME =
211 "android.telecom.extra.DEFAULT_CALL_SCREENING_APP_COMPONENT_NAME";
212
213 /**
214 * Extra value used with {@link #ACTION_DEFAULT_CALL_SCREENING_APP_CHANGED} broadcast to
215 * indicate whether an app is the default call screening app.
216 */
217 public static final String EXTRA_IS_DEFAULT_CALL_SCREENING_APP =
218 "android.telecom.extra.IS_DEFAULT_CALL_SCREENING_APP";
219
220 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700221 * Optional extra for {@link android.content.Intent#ACTION_CALL} containing a boolean that
222 * determines whether the speakerphone should be automatically turned on for an outgoing call.
Evan Charlton10197192014-07-19 15:00:29 -0700223 */
224 public static final String EXTRA_START_CALL_WITH_SPEAKERPHONE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700225 "android.telecom.extra.START_CALL_WITH_SPEAKERPHONE";
Evan Charlton10197192014-07-19 15:00:29 -0700226
227 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700228 * Optional extra for {@link android.content.Intent#ACTION_CALL} containing an integer that
229 * determines the desired video state for an outgoing call.
Santos Cordon96efb482014-07-19 14:57:05 -0700230 * Valid options:
Yorke Lee32f24732015-05-12 16:18:03 -0700231 * {@link VideoProfile#STATE_AUDIO_ONLY},
232 * {@link VideoProfile#STATE_BIDIRECTIONAL},
233 * {@link VideoProfile#STATE_RX_ENABLED},
234 * {@link VideoProfile#STATE_TX_ENABLED}.
Evan Charlton10197192014-07-19 15:00:29 -0700235 */
236 public static final String EXTRA_START_CALL_WITH_VIDEO_STATE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700237 "android.telecom.extra.START_CALL_WITH_VIDEO_STATE";
Evan Charlton10197192014-07-19 15:00:29 -0700238
239 /**
Tyler Gunn37653562017-03-13 18:15:15 -0700240 * Optional extra for {@link #addNewIncomingCall(PhoneAccountHandle, Bundle)} containing an
241 * integer that determines the requested video state for an incoming call.
242 * Valid options:
243 * {@link VideoProfile#STATE_AUDIO_ONLY},
244 * {@link VideoProfile#STATE_BIDIRECTIONAL},
245 * {@link VideoProfile#STATE_RX_ENABLED},
246 * {@link VideoProfile#STATE_TX_ENABLED}.
247 */
248 public static final String EXTRA_INCOMING_VIDEO_STATE =
249 "android.telecom.extra.INCOMING_VIDEO_STATE";
250
251 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700252 * The extra used with an {@link android.content.Intent#ACTION_CALL} and
253 * {@link android.content.Intent#ACTION_DIAL} {@code Intent} to specify a
254 * {@link PhoneAccountHandle} to use when making the call.
Evan Charlton10197192014-07-19 15:00:29 -0700255 * <p class="note">
Santos Cordon96efb482014-07-19 14:57:05 -0700256 * Retrieve with {@link android.content.Intent#getParcelableExtra(String)}.
Evan Charlton10197192014-07-19 15:00:29 -0700257 */
Evan Charlton6eb262c2014-07-19 18:18:19 -0700258 public static final String EXTRA_PHONE_ACCOUNT_HANDLE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700259 "android.telecom.extra.PHONE_ACCOUNT_HANDLE";
Evan Charlton10197192014-07-19 15:00:29 -0700260
261 /**
Tyler Gunn335ff2e2015-07-30 14:18:33 -0700262 * Optional extra for {@link android.content.Intent#ACTION_CALL} containing a string call
263 * subject which will be associated with an outgoing call. Should only be specified if the
264 * {@link PhoneAccount} supports the capability {@link PhoneAccount#CAPABILITY_CALL_SUBJECT}.
265 */
266 public static final String EXTRA_CALL_SUBJECT = "android.telecom.extra.CALL_SUBJECT";
267
268 /**
Yorke Lee04ea7d32015-06-05 15:59:18 -0700269 * The extra used by a {@link ConnectionService} to provide the handle of the caller that
270 * has initiated a new incoming call.
271 */
Yorke Lee02fb5bc2015-06-09 12:27:36 -0700272 public static final String EXTRA_INCOMING_CALL_ADDRESS =
273 "android.telecom.extra.INCOMING_CALL_ADDRESS";
Yorke Lee04ea7d32015-06-05 15:59:18 -0700274
275 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700276 * Optional extra for {@link #ACTION_INCOMING_CALL} containing a {@link Bundle} which contains
277 * metadata about the call. This {@link Bundle} will be returned to the
278 * {@link ConnectionService}.
Evan Charlton10197192014-07-19 15:00:29 -0700279 */
280 public static final String EXTRA_INCOMING_CALL_EXTRAS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700281 "android.telecom.extra.INCOMING_CALL_EXTRAS";
Evan Charlton10197192014-07-19 15:00:29 -0700282
283 /**
Joseph Pirozzo40ea5ee2018-01-02 16:15:23 -0800284 * Optional extra for {@link #ACTION_INCOMING_CALL} containing a boolean to indicate that the
285 * call has an externally generated ringer. Used by the HfpClientConnectionService when In Band
286 * Ringtone is enabled to prevent two ringers from being generated.
287 * @hide
288 */
289 public static final String EXTRA_CALL_EXTERNAL_RINGER =
290 "android.telecom.extra.CALL_EXTERNAL_RINGER";
291
292 /**
Nancy Chen10798dc2014-08-08 14:00:25 -0700293 * Optional extra for {@link android.content.Intent#ACTION_CALL} and
294 * {@link android.content.Intent#ACTION_DIAL} {@code Intent} containing a {@link Bundle}
295 * which contains metadata about the call. This {@link Bundle} will be saved into
Santos Cordon7a060d52015-06-19 14:52:04 -0700296 * {@code Call.Details} and passed to the {@link ConnectionService} when placing the call.
Nancy Chen10798dc2014-08-08 14:00:25 -0700297 */
298 public static final String EXTRA_OUTGOING_CALL_EXTRAS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700299 "android.telecom.extra.OUTGOING_CALL_EXTRAS";
Nancy Chen10798dc2014-08-08 14:00:25 -0700300
301 /**
sqian6d9e7452019-02-08 21:42:15 -0800302 * An optional boolean extra on {@link android.content.Intent#ACTION_CALL_EMERGENCY} to tell
303 * whether the user's dial intent is emergency; this is required to specify when the dialed
304 * number is ambiguous, identified as both emergency number and any other non-emergency number;
305 * e.g. in some situation, 611 could be both an emergency number in a country and a
306 * non-emergency number of a carrier's customer service hotline.
307 *
308 * @hide
309 */
310 @SystemApi
311 public static final String EXTRA_IS_USER_INTENT_EMERGENCY_CALL =
312 "android.telecom.extra.IS_USER_INTENT_EMERGENCY_CALL";
313
314 /**
Yorke Leec3cf9822014-10-02 09:38:39 -0700315 * @hide
316 */
317 public static final String EXTRA_UNKNOWN_CALL_HANDLE =
318 "android.telecom.extra.UNKNOWN_CALL_HANDLE";
319
320 /**
Sailesh Nepalda6bb382016-04-14 19:51:46 -0700321 * Optional extra for incoming and outgoing calls containing a long which specifies the time the
322 * call was created. This value is in milliseconds since boot.
323 * @hide
324 */
325 public static final String EXTRA_CALL_CREATED_TIME_MILLIS =
326 "android.telecom.extra.CALL_CREATED_TIME_MILLIS";
327
328 /**
329 * Optional extra for incoming and outgoing calls containing a long which specifies the time
330 * telecom began routing the call. This value is in milliseconds since boot.
331 * @hide
332 */
333 public static final String EXTRA_CALL_TELECOM_ROUTING_START_TIME_MILLIS =
334 "android.telecom.extra.CALL_TELECOM_ROUTING_START_TIME_MILLIS";
335
336 /**
337 * Optional extra for incoming and outgoing calls containing a long which specifies the time
338 * telecom finished routing the call. This value is in milliseconds since boot.
339 * @hide
340 */
341 public static final String EXTRA_CALL_TELECOM_ROUTING_END_TIME_MILLIS =
342 "android.telecom.extra.CALL_TELECOM_ROUTING_END_TIME_MILLIS";
343
344 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700345 * Optional extra for {@link android.telephony.TelephonyManager#ACTION_PHONE_STATE_CHANGED}
346 * containing the disconnect code.
Evan Charlton10197192014-07-19 15:00:29 -0700347 */
348 public static final String EXTRA_CALL_DISCONNECT_CAUSE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700349 "android.telecom.extra.CALL_DISCONNECT_CAUSE";
Evan Charlton10197192014-07-19 15:00:29 -0700350
351 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700352 * Optional extra for {@link android.telephony.TelephonyManager#ACTION_PHONE_STATE_CHANGED}
353 * containing the disconnect message.
Evan Charlton10197192014-07-19 15:00:29 -0700354 */
355 public static final String EXTRA_CALL_DISCONNECT_MESSAGE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700356 "android.telecom.extra.CALL_DISCONNECT_MESSAGE";
Evan Charlton10197192014-07-19 15:00:29 -0700357
358 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700359 * Optional extra for {@link android.telephony.TelephonyManager#ACTION_PHONE_STATE_CHANGED}
360 * containing the component name of the associated connection service.
Evan Charlton0e094d92014-11-08 15:49:16 -0800361 * @hide
Evan Charlton10197192014-07-19 15:00:29 -0700362 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800363 @SystemApi
Evan Charlton10197192014-07-19 15:00:29 -0700364 public static final String EXTRA_CONNECTION_SERVICE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700365 "android.telecom.extra.CONNECTION_SERVICE";
Evan Charlton10197192014-07-19 15:00:29 -0700366
367 /**
Hall Liu90f62902015-11-19 16:19:24 -0800368 * Optional extra for communicating the call technology used by a
369 * {@link com.android.internal.telephony.Connection} to Telecom
370 * @hide
371 */
372 public static final String EXTRA_CALL_TECHNOLOGY_TYPE =
373 "android.telecom.extra.CALL_TECHNOLOGY_TYPE";
374
375 /**
Wei Huang7f7f72e2018-05-30 19:21:36 +0800376 * Optional extra for communicating the call network technology used by a
377 * {@link android.telecom.Connection} to Telecom and InCallUI.
378 *
379 * @see {@code NETWORK_TYPE_*} in {@link android.telephony.TelephonyManager}.
380 */
381 public static final String EXTRA_CALL_NETWORK_TYPE =
382 "android.telecom.extra.CALL_NETWORK_TYPE";
383
384 /**
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700385 * An optional {@link android.content.Intent#ACTION_CALL} intent extra denoting the
386 * package name of the app specifying an alternative gateway for the call.
387 * The value is a string.
388 *
389 * (The following comment corresponds to the all GATEWAY_* extras)
390 * An app which sends the {@link android.content.Intent#ACTION_CALL} intent can specify an
391 * alternative address to dial which is different from the one specified and displayed to
392 * the user. This alternative address is referred to as the gateway address.
393 */
394 public static final String GATEWAY_PROVIDER_PACKAGE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700395 "android.telecom.extra.GATEWAY_PROVIDER_PACKAGE";
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700396
397 /**
398 * An optional {@link android.content.Intent#ACTION_CALL} intent extra corresponding to the
399 * original address to dial for the call. This is used when an alternative gateway address is
400 * provided to recall the original address.
401 * The value is a {@link android.net.Uri}.
402 *
403 * (See {@link #GATEWAY_PROVIDER_PACKAGE} for details)
404 */
405 public static final String GATEWAY_ORIGINAL_ADDRESS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700406 "android.telecom.extra.GATEWAY_ORIGINAL_ADDRESS";
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700407
408 /**
Evan Charlton10197192014-07-19 15:00:29 -0700409 * The number which the party on the other side of the line will see (and use to return the
410 * call).
411 * <p>
Santos Cordon96efb482014-07-19 14:57:05 -0700412 * {@link ConnectionService}s which interact with {@link RemoteConnection}s should only populate
413 * this if the {@link android.telephony.TelephonyManager#getLine1Number()} value, as that is the
414 * user's expected caller ID.
Evan Charlton10197192014-07-19 15:00:29 -0700415 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700416 public static final String EXTRA_CALL_BACK_NUMBER = "android.telecom.extra.CALL_BACK_NUMBER";
Evan Charlton10197192014-07-19 15:00:29 -0700417
418 /**
Hall Liu8f613fb2017-02-14 18:11:11 -0800419 * The number of milliseconds that Telecom should wait after disconnecting a call via the
420 * ACTION_NEW_OUTGOING_CALL broadcast, in order to wait for the app which cancelled the call
421 * to make a new one.
422 * @hide
423 */
424 public static final String EXTRA_NEW_OUTGOING_CALL_CANCEL_TIMEOUT =
425 "android.telecom.extra.NEW_OUTGOING_CALL_CANCEL_TIMEOUT";
426
427 /**
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700428 * Boolean extra specified to indicate that the intention of adding a call is to handover an
Tyler Gunn8bf76572017-04-06 15:30:08 -0700429 * existing call from the user's device to a different {@link PhoneAccount}.
430 * <p>
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700431 * Used when calling {@link #addNewIncomingCall(PhoneAccountHandle, Bundle)}
432 * to indicate to Telecom that the purpose of adding a new incoming call is to handover an
433 * existing call from the user's device to a different {@link PhoneAccount}. This occurs on
434 * the receiving side of a handover.
435 * <p>
436 * Used when Telecom calls
437 * {@link ConnectionService#onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}
438 * to indicate that the purpose of Telecom requesting a new outgoing connection it to request
439 * a handover to this {@link ConnectionService} from an ongoing call on the user's device. This
440 * occurs on the initiating side of a handover.
441 * <p>
Tyler Gunn727c6bd2017-04-11 09:51:40 -0700442 * The phone number of the call used by Telecom to determine which call should be handed over.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700443 * @hide
Tyler Gunn6e3ecc42018-11-12 11:30:56 -0800444 * @deprecated Use the public handover APIs. See
445 * {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} for more information.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700446 */
Tyler Gunn6e3ecc42018-11-12 11:30:56 -0800447 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 119305590)
Tyler Gunn8bf76572017-04-06 15:30:08 -0700448 public static final String EXTRA_IS_HANDOVER = "android.telecom.extra.IS_HANDOVER";
449
450 /**
Tyler Gunn79bc1ec2018-01-22 15:17:54 -0800451 * When {@code true} indicates that a request to create a new connection is for the purpose of
452 * a handover. Note: This is used with the
453 * {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int, Bundle)} API as part of the
454 * internal communication mechanism with the {@link android.telecom.ConnectionService}. It is
455 * not the same as the legacy {@link #EXTRA_IS_HANDOVER} extra.
456 * @hide
457 */
458 public static final String EXTRA_IS_HANDOVER_CONNECTION =
459 "android.telecom.extra.IS_HANDOVER_CONNECTION";
460
461 /**
Tyler Gunn3af38692017-05-26 13:30:09 -0700462 * Parcelable extra used with {@link #EXTRA_IS_HANDOVER} to indicate the source
463 * {@link PhoneAccountHandle} when initiating a handover which {@link ConnectionService}
464 * the handover is from.
465 * @hide
466 */
467 public static final String EXTRA_HANDOVER_FROM_PHONE_ACCOUNT =
468 "android.telecom.extra.HANDOVER_FROM_PHONE_ACCOUNT";
469
470 /**
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700471 * Extra key specified in the {@link ConnectionRequest#getExtras()} when Telecom calls
472 * {@link ConnectionService#onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}
473 * to inform the {@link ConnectionService} what the initial {@link CallAudioState} of the
474 * {@link Connection} will be.
475 * @hide
476 */
477 public static final String EXTRA_CALL_AUDIO_STATE = "android.telecom.extra.CALL_AUDIO_STATE";
478
479 /**
Hall Liu95d55872017-01-25 17:12:49 -0800480 * A boolean extra, which when set on the {@link Intent#ACTION_CALL} intent or on the bundle
481 * passed into {@link #placeCall(Uri, Bundle)}, indicates that the call should be initiated with
482 * an RTT session open. See {@link android.telecom.Call.RttCall} for more information on RTT.
483 */
484 public static final String EXTRA_START_CALL_WITH_RTT =
485 "android.telecom.extra.START_CALL_WITH_RTT";
486
487 /**
Grace Jia91cec6e2019-12-16 14:23:05 -0800488 * Start an activity indicating that the completion of an outgoing call or an incoming call
489 * which was not blocked by the {@link CallScreeningService}, and which was NOT terminated
490 * while the call was in {@link Call#STATE_AUDIO_PROCESSING}.
491 *
492 * The {@link Uri} extra {@link #EXTRA_HANDLE} will contain the uri handle(phone number) for the
493 * call which completed.
494 *
495 * The integer extra {@link #EXTRA_DISCONNECT_CAUSE} will indicate the reason for the call
496 * disconnection. See {@link #EXTRA_DISCONNECT_CAUSE} for more information.
497 *
498 * The integer extra {@link #EXTRA_CALL_DURATION} will indicate the duration of the call. See
499 * {@link #EXTRA_CALL_DURATION} for more information.
500 */
501 public static final String ACTION_POST_CALL = "android.telecom.action.POST_CALL";
502
503 /**
504 * A {@link Uri} extra, which when set on the {@link #ACTION_POST_CALL} intent, indicates the
505 * uri handle(phone number) of the completed call.
506 */
507 public static final String EXTRA_HANDLE = "android.telecom.extra.HANDLE";
508
509 /**
510 * A integer value provided for completed calls to indicate the reason for the call
511 * disconnection.
512 * <p>
513 * Allowed values:
514 * <ul>
515 * <li>{@link DisconnectCause#UNKNOWN}</li>
516 * <li>{@link DisconnectCause#LOCAL}</li>
517 * <li>{@link DisconnectCause#REMOTE}</li>
518 * <li>{@link DisconnectCause#REJECTED}</li>
519 * <li>{@link DisconnectCause#MISSED}</li>
520 * </ul>
521 * </p>
522 */
523 public static final String EXTRA_DISCONNECT_CAUSE = "android.telecom.extra.DISCONNECT_CAUSE";
524
525 /**
526 * A integer value provided for completed calls to indicate the duration of the call.
527 * <p>
528 * Allowed values:
529 * <ul>
530 * <li>{@link #DURATION_VERY_SHORT}</li>
531 * <li>{@link #DURATION_SHORT}</li>
532 * <li>{@link #DURATION_MEDIUM}</li>
533 * <li>{@link #DURATION_LONG}</li>
534 * </ul>
535 * </p>
536 */
537 public static final String EXTRA_CALL_DURATION = "android.telecom.extra.CALL_DURATION";
538
539 /**
540 * A integer value for {@link #EXTRA_CALL_DURATION}, indicates the duration of the completed
541 * call was < 3 seconds.
542 */
543 public static final int DURATION_VERY_SHORT = 0;
544
545 /**
546 * A integer value for {@link #EXTRA_CALL_DURATION}, indicates the duration of the completed
547 * call was >= 3 seconds and < 60 seconds.
548 */
549 public static final int DURATION_SHORT = 1;
550
551 /**
552 * A integer value for {@link #EXTRA_CALL_DURATION}, indicates the duration of the completed
553 * call was >= 60 seconds and < 120 seconds.
554 */
555 public static final int DURATION_MEDIUM = 2;
556
557 /**
558 * A integer value for {@link #EXTRA_CALL_DURATION}, indicates the duration of the completed
559 * call was >= 120 seconds.
560 */
561 public static final int DURATION_LONG = 3;
562
563 /**
564 * The threshold between {@link #DURATION_VERY_SHORT} calls and {@link #DURATION_SHORT} calls in
565 * milliseconds.
566 * @hide
567 */
568 public static final long VERY_SHORT_CALL_TIME_MS = 3000;
569
570 /**
571 * The threshold between {@link #DURATION_SHORT} calls and {@link #DURATION_MEDIUM} calls in
572 * milliseconds.
573 * @hide
574 */
575 public static final long SHORT_CALL_TIME_MS = 60000;
576
577 /**
578 * The threshold between {@link #DURATION_MEDIUM} calls and {@link #DURATION_LONG} calls in
579 * milliseconds.
580 * @hide
581 */
582 public static final long MEDIUM_CALL_TIME_MS = 120000;
583
584 /**
Santos Cordonf2600eb2015-06-22 15:02:20 -0700585 * A boolean meta-data value indicating whether an {@link InCallService} implements an
586 * in-call user interface. Dialer implementations (see {@link #getDefaultDialerPackage()}) which
587 * would also like to replace the in-call interface should set this meta-data to {@code true} in
588 * the manifest registration of their {@link InCallService}.
589 */
590 public static final String METADATA_IN_CALL_SERVICE_UI = "android.telecom.IN_CALL_SERVICE_UI";
591
592 /**
Santos Cordon88881552015-12-10 17:29:54 -0800593 * A boolean meta-data value indicating whether an {@link InCallService} implements an
594 * in-call user interface to be used while the device is in car-mode (see
Hector Dearman923382c2018-12-13 16:42:33 +0000595 * {@link android.content.res.Configuration#UI_MODE_TYPE_CAR}).
Santos Cordon88881552015-12-10 17:29:54 -0800596 */
597 public static final String METADATA_IN_CALL_SERVICE_CAR_MODE_UI =
598 "android.telecom.IN_CALL_SERVICE_CAR_MODE_UI";
599
600 /**
Sailesh Nepal9c2618b2016-01-23 16:28:22 -0800601 * A boolean meta-data value indicating whether an {@link InCallService} implements ringing.
602 * Dialer implementations (see {@link #getDefaultDialerPackage()}) which would also like to
603 * override the system provided ringing should set this meta-data to {@code true} in the
604 * manifest registration of their {@link InCallService}.
Tyler Gunn556d2402019-04-10 08:59:43 -0700605 * <p>
606 * When {@code true}, it is the {@link InCallService}'s responsibility to play a ringtone for
607 * all incoming calls.
Sailesh Nepal9c2618b2016-01-23 16:28:22 -0800608 */
609 public static final String METADATA_IN_CALL_SERVICE_RINGING =
610 "android.telecom.IN_CALL_SERVICE_RINGING";
611
612 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700613 * A boolean meta-data value indicating whether an {@link InCallService} wants to be informed of
614 * calls which have the {@link Call.Details#PROPERTY_IS_EXTERNAL_CALL} property. An external
615 * call is one which a {@link ConnectionService} knows about, but is not connected to directly.
616 * Dialer implementations (see {@link #getDefaultDialerPackage()}) which would like to be
617 * informed of external calls should set this meta-data to {@code true} in the manifest
618 * registration of their {@link InCallService}. By default, the {@link InCallService} will NOT
619 * be informed of external calls.
620 */
621 public static final String METADATA_INCLUDE_EXTERNAL_CALLS =
622 "android.telecom.INCLUDE_EXTERNAL_CALLS";
623
624 /**
Tyler Gunn24e18332017-02-10 09:42:49 -0800625 * A boolean meta-data value indicating whether an {@link InCallService} wants to be informed of
626 * calls which have the {@link Call.Details#PROPERTY_SELF_MANAGED} property. A self-managed
627 * call is one which originates from a self-managed {@link ConnectionService} which has chosen
628 * to implement its own call user interface. An {@link InCallService} implementation which
629 * would like to be informed of external calls should set this meta-data to {@code true} in the
630 * manifest registration of their {@link InCallService}. By default, the {@link InCallService}
631 * will NOT be informed about self-managed calls.
632 * <p>
633 * An {@link InCallService} which receives self-managed calls is free to view and control the
634 * state of calls in the self-managed {@link ConnectionService}. An example use-case is
Tyler Gunn37653562017-03-13 18:15:15 -0700635 * exposing these calls to an automotive device via its companion app.
636 * <p>
637 * This meta-data can only be set for an {@link InCallService} which also sets
638 * {@link #METADATA_IN_CALL_SERVICE_UI}. Only the default phone/dialer app, or a car-mode
639 * {@link InCallService} can see self-managed calls.
Tyler Gunn24e18332017-02-10 09:42:49 -0800640 * <p>
641 * See also {@link Connection#PROPERTY_SELF_MANAGED}.
642 */
643 public static final String METADATA_INCLUDE_SELF_MANAGED_CALLS =
644 "android.telecom.INCLUDE_SELF_MANAGED_CALLS";
645
646 /**
Evan Charlton10197192014-07-19 15:00:29 -0700647 * The dual tone multi-frequency signaling character sent to indicate the dialing system should
648 * pause for a predefined period.
649 */
650 public static final char DTMF_CHARACTER_PAUSE = ',';
651
652 /**
653 * The dual-tone multi-frequency signaling character sent to indicate the dialing system should
654 * wait for user confirmation before proceeding.
655 */
656 public static final char DTMF_CHARACTER_WAIT = ';';
657
658 /**
Tyler Gunn6e3ecc42018-11-12 11:30:56 -0800659 * @hide
660 */
661 @IntDef(prefix = { "TTY_MODE_" },
662 value = {TTY_MODE_OFF, TTY_MODE_FULL, TTY_MODE_HCO, TTY_MODE_VCO})
663 @Retention(RetentionPolicy.SOURCE)
664 public @interface TtyMode {}
665
666 /**
Evan Charlton10197192014-07-19 15:00:29 -0700667 * TTY (teletypewriter) mode is off.
668 *
669 * @hide
670 */
Tyler Gunn6c14a6992019-02-04 15:12:06 -0800671 @TestApi
Tyler Gunn6e3ecc42018-11-12 11:30:56 -0800672 @SystemApi
Evan Charlton10197192014-07-19 15:00:29 -0700673 public static final int TTY_MODE_OFF = 0;
674
675 /**
676 * TTY (teletypewriter) mode is on. The speaker is off and the microphone is muted. The user
677 * will communicate with the remote party by sending and receiving text messages.
678 *
679 * @hide
680 */
Tyler Gunn6c14a6992019-02-04 15:12:06 -0800681 @TestApi
Tyler Gunn6e3ecc42018-11-12 11:30:56 -0800682 @SystemApi
Evan Charlton10197192014-07-19 15:00:29 -0700683 public static final int TTY_MODE_FULL = 1;
684
685 /**
686 * TTY (teletypewriter) mode is in hearing carryover mode (HCO). The microphone is muted but the
687 * speaker is on. The user will communicate with the remote party by sending text messages and
688 * hearing an audible reply.
689 *
690 * @hide
691 */
Tyler Gunn6c14a6992019-02-04 15:12:06 -0800692 @TestApi
Tyler Gunn6e3ecc42018-11-12 11:30:56 -0800693 @SystemApi
Evan Charlton10197192014-07-19 15:00:29 -0700694 public static final int TTY_MODE_HCO = 2;
695
696 /**
697 * TTY (teletypewriter) mode is in voice carryover mode (VCO). The speaker is off but the
698 * microphone is still on. User will communicate with the remote party by speaking and receiving
699 * text message replies.
700 *
701 * @hide
702 */
Tyler Gunn6c14a6992019-02-04 15:12:06 -0800703 @TestApi
Tyler Gunn6e3ecc42018-11-12 11:30:56 -0800704 @SystemApi
Evan Charlton10197192014-07-19 15:00:29 -0700705 public static final int TTY_MODE_VCO = 3;
706
707 /**
708 * Broadcast intent action indicating that the current TTY mode has changed. An intent extra
709 * provides this state as an int.
Evan Charlton10197192014-07-19 15:00:29 -0700710 *
Santos Cordon96efb482014-07-19 14:57:05 -0700711 * @see #EXTRA_CURRENT_TTY_MODE
Evan Charlton10197192014-07-19 15:00:29 -0700712 * @hide
713 */
714 public static final String ACTION_CURRENT_TTY_MODE_CHANGED =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700715 "android.telecom.action.CURRENT_TTY_MODE_CHANGED";
Evan Charlton10197192014-07-19 15:00:29 -0700716
717 /**
718 * The lookup key for an int that indicates the current TTY mode.
719 * Valid modes are:
720 * - {@link #TTY_MODE_OFF}
721 * - {@link #TTY_MODE_FULL}
722 * - {@link #TTY_MODE_HCO}
723 * - {@link #TTY_MODE_VCO}
724 *
725 * @hide
726 */
727 public static final String EXTRA_CURRENT_TTY_MODE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700728 "android.telecom.intent.extra.CURRENT_TTY_MODE";
Evan Charlton10197192014-07-19 15:00:29 -0700729
730 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700731 * Broadcast intent action indicating that the TTY preferred operating mode has changed. An
732 * intent extra provides the new mode as an int.
Evan Charlton10197192014-07-19 15:00:29 -0700733 *
Santos Cordon96efb482014-07-19 14:57:05 -0700734 * @see #EXTRA_TTY_PREFERRED_MODE
Evan Charlton10197192014-07-19 15:00:29 -0700735 * @hide
736 */
737 public static final String ACTION_TTY_PREFERRED_MODE_CHANGED =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700738 "android.telecom.action.TTY_PREFERRED_MODE_CHANGED";
Evan Charlton10197192014-07-19 15:00:29 -0700739
740 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700741 * The lookup key for an int that indicates preferred TTY mode. Valid modes are: -
742 * {@link #TTY_MODE_OFF} - {@link #TTY_MODE_FULL} - {@link #TTY_MODE_HCO} -
743 * {@link #TTY_MODE_VCO}
Evan Charlton10197192014-07-19 15:00:29 -0700744 *
745 * @hide
746 */
747 public static final String EXTRA_TTY_PREFERRED_MODE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700748 "android.telecom.intent.extra.TTY_PREFERRED";
Evan Charlton10197192014-07-19 15:00:29 -0700749
Nancy Chen9d568c02014-09-08 14:17:59 -0700750 /**
Bryce Lee5e4dd3e2015-08-03 16:59:10 -0700751 * Broadcast intent action for letting custom component know to show the missed call
Sailesh Nepalbe15ad92016-01-21 19:26:20 -0800752 * notification. If no custom component exists then this is sent to the default dialer which
753 * should post a missed-call notification.
Bryce Lee5e4dd3e2015-08-03 16:59:10 -0700754 */
Bryce Lee5e4dd3e2015-08-03 16:59:10 -0700755 public static final String ACTION_SHOW_MISSED_CALLS_NOTIFICATION =
756 "android.telecom.action.SHOW_MISSED_CALLS_NOTIFICATION";
757
758 /**
Sailesh Nepalbe15ad92016-01-21 19:26:20 -0800759 * The number of calls associated with the notification. If the number is zero then the missed
760 * call notification should be dismissed.
Bryce Lee5e4dd3e2015-08-03 16:59:10 -0700761 */
Bryce Lee5e4dd3e2015-08-03 16:59:10 -0700762 public static final String EXTRA_NOTIFICATION_COUNT =
763 "android.telecom.extra.NOTIFICATION_COUNT";
764
765 /**
766 * The number associated with the missed calls. This number is only relevant
767 * when EXTRA_NOTIFICATION_COUNT is 1.
Bryce Lee5e4dd3e2015-08-03 16:59:10 -0700768 */
Bryce Lee5e4dd3e2015-08-03 16:59:10 -0700769 public static final String EXTRA_NOTIFICATION_PHONE_NUMBER =
770 "android.telecom.extra.NOTIFICATION_PHONE_NUMBER";
771
772 /**
Bryce Lee8d41d1d2015-08-10 07:40:42 -0700773 * The intent to clear missed calls.
774 * @hide
775 */
776 @SystemApi
777 public static final String EXTRA_CLEAR_MISSED_CALLS_INTENT =
778 "android.telecom.extra.CLEAR_MISSED_CALLS_INTENT";
779
780 /**
781 * The intent to call back a missed call.
782 * @hide
783 */
784 @SystemApi
785 public static final String EXTRA_CALL_BACK_INTENT =
786 "android.telecom.extra.CALL_BACK_INTENT";
787
788 /**
Charles He858f1322017-11-27 17:11:04 -0800789 * The dialer activity responsible for placing emergency calls from, for example, a locked
790 * keyguard.
791 * @hide
792 */
793 public static final ComponentName EMERGENCY_DIALER_COMPONENT =
794 ComponentName.createRelative("com.android.phone", ".EmergencyDialer");
795
796 /**
Eric Erfanian62706c52017-12-06 16:27:53 -0800797 * The boolean indicated by this extra controls whether or not a call is eligible to undergo
798 * assisted dialing. This extra is stored under {@link #EXTRA_OUTGOING_CALL_EXTRAS}.
Tyler Gunn5567d742019-10-31 13:04:37 -0700799 * <p>
800 * The call initiator can use this extra to indicate that a call used assisted dialing to help
801 * place the call. This is most commonly used by a Dialer app which provides the ability to
802 * automatically add dialing prefixes when placing international calls.
803 * <p>
804 * Setting this extra on the outgoing call extras will cause the
805 * {@link Connection#PROPERTY_ASSISTED_DIALING_USED} property and
806 * {@link Call.Details#PROPERTY_ASSISTED_DIALING_USED} property to be set on the
807 * {@link Connection}/{@link Call} in question. When the call is logged to the call log, the
808 * {@link android.provider.CallLog.Calls#FEATURES_ASSISTED_DIALING_USED} call feature is set to
809 * indicate that assisted dialing was used for the call.
Eric Erfanian62706c52017-12-06 16:27:53 -0800810 */
811 public static final String EXTRA_USE_ASSISTED_DIALING =
812 "android.telecom.extra.USE_ASSISTED_DIALING";
813
814 /**
Shaotang Li8cec25c2018-07-19 17:29:39 +0800815 * Optional extra for {@link #placeCall(Uri, Bundle)} containing an integer that specifies
816 * the source where user initiated this call. This data is used in metrics.
817 * Valid source are:
818 * {@link ParcelableCallAnalytics#CALL_SOURCE_UNSPECIFIED},
819 * {@link ParcelableCallAnalytics#CALL_SOURCE_EMERGENCY_DIALPAD},
820 * {@link ParcelableCallAnalytics#CALL_SOURCE_EMERGENCY_SHORTCUT}.
821 *
822 * @hide
823 */
824 public static final String EXTRA_CALL_SOURCE = "android.telecom.extra.CALL_SOURCE";
825
826 /**
Nancy Chen9d568c02014-09-08 14:17:59 -0700827 * The following 4 constants define how properties such as phone numbers and names are
828 * displayed to the user.
829 */
830
Santos Cordoned769ae2015-05-13 18:47:38 -0700831 /**
832 * Indicates that the address or number of a call is allowed to be displayed for caller ID.
Charles He858f1322017-11-27 17:11:04 -0800833 */
Nancy Chen9d568c02014-09-08 14:17:59 -0700834 public static final int PRESENTATION_ALLOWED = 1;
835
Santos Cordoned769ae2015-05-13 18:47:38 -0700836 /**
837 * Indicates that the address or number of a call is blocked by the other party.
838 */
Nancy Chen9d568c02014-09-08 14:17:59 -0700839 public static final int PRESENTATION_RESTRICTED = 2;
840
Santos Cordoned769ae2015-05-13 18:47:38 -0700841 /**
842 * Indicates that the address or number of a call is not specified or known by the carrier.
843 */
Nancy Chen9d568c02014-09-08 14:17:59 -0700844 public static final int PRESENTATION_UNKNOWN = 3;
845
Santos Cordoned769ae2015-05-13 18:47:38 -0700846 /**
847 * Indicates that the address or number of a call belongs to a pay phone.
848 */
Nancy Chen9d568c02014-09-08 14:17:59 -0700849 public static final int PRESENTATION_PAYPHONE = 4;
850
Tyler Gunn5567d742019-10-31 13:04:37 -0700851 /** @hide */
852 @Retention(RetentionPolicy.SOURCE)
853 @IntDef(
854 prefix = { "PRESENTATION_" },
855 value = {PRESENTATION_ALLOWED, PRESENTATION_RESTRICTED, PRESENTATION_UNKNOWN,
856 PRESENTATION_PAYPHONE})
857 public @interface Presentation {}
858
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700859 private static final String TAG = "TelecomManager";
Yorke Leeb4ce1432014-06-09 13:53:23 -0700860
861 private final Context mContext;
Yorke Leeb4ce1432014-06-09 13:53:23 -0700862
Hall Liue1bc2ec2015-10-09 15:58:37 -0700863 private final ITelecomService mTelecomServiceOverride;
864
Santos Cordon6c7a3882014-06-25 15:30:08 -0700865 /**
866 * @hide
867 */
Chen Xu4c0b06d2018-10-22 16:54:39 +0000868 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700869 public static TelecomManager from(Context context) {
870 return (TelecomManager) context.getSystemService(Context.TELECOM_SERVICE);
Yorke Leeb4ce1432014-06-09 13:53:23 -0700871 }
Santos Cordon6c7a3882014-06-25 15:30:08 -0700872
873 /**
874 * @hide
875 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700876 public TelecomManager(Context context) {
Hall Liue1bc2ec2015-10-09 15:58:37 -0700877 this(context, null);
878 }
879
880 /**
881 * @hide
882 */
883 public TelecomManager(Context context, ITelecomService telecomServiceImpl) {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700884 Context appContext = context.getApplicationContext();
885 if (appContext != null) {
886 mContext = appContext;
887 } else {
888 mContext = context;
889 }
Hall Liue1bc2ec2015-10-09 15:58:37 -0700890 mTelecomServiceOverride = telecomServiceImpl;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700891 }
892
893 /**
Santos Cordon91371dc2015-05-08 13:52:09 -0700894 * Return the {@link PhoneAccount} which will be used to place outgoing calls to addresses with
895 * the specified {@code uriScheme}. This {@link PhoneAccount} will always be a member of the
896 * list which is returned from invoking {@link #getCallCapablePhoneAccounts()}. The specific
897 * account returned depends on the following priorities:
898 * <ul>
899 * <li> If the user-selected default {@link PhoneAccount} supports the specified scheme, it will
900 * be returned.
901 * </li>
902 * <li> If there exists only one {@link PhoneAccount} that supports the specified scheme, it
903 * will be returned.
904 * </li>
905 * </ul>
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700906 * <p>
Santos Cordon91371dc2015-05-08 13:52:09 -0700907 * If no {@link PhoneAccount} fits the criteria above, this method will return {@code null}.
908 *
Yorke Leec61d1362015-09-21 17:25:25 -0700909 * Requires permission: {@link android.Manifest.permission#READ_PHONE_STATE}
910 *
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700911 * @param uriScheme The URI scheme.
Santos Cordon91371dc2015-05-08 13:52:09 -0700912 * @return The {@link PhoneAccountHandle} corresponding to the account to be used.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700913 */
Yorke Leec61d1362015-09-21 17:25:25 -0700914 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700915 public PhoneAccountHandle getDefaultOutgoingPhoneAccount(String uriScheme) {
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700916 try {
917 if (isServiceConnected()) {
Svet Ganov16a16892015-04-16 10:32:04 -0700918 return getTelecomService().getDefaultOutgoingPhoneAccount(uriScheme,
919 mContext.getOpPackageName());
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700920 }
921 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700922 Log.e(TAG, "Error calling ITelecomService#getDefaultOutgoingPhoneAccount", e);
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700923 }
924 return null;
925 }
926
927 /**
Andrew Leed4abbfb2014-09-03 14:58:27 -0700928 * Return the {@link PhoneAccount} which is the user-chosen default for making outgoing phone
929 * calls. This {@code PhoneAccount} will always be a member of the list which is returned from
Nancy Chen210ef032014-09-15 17:58:42 -0700930 * calling {@link #getCallCapablePhoneAccounts()}
Santos Cordon91371dc2015-05-08 13:52:09 -0700931 * <p>
Andrew Leed4abbfb2014-09-03 14:58:27 -0700932 * Apps must be prepared for this method to return {@code null}, indicating that there currently
933 * exists no user-chosen default {@code PhoneAccount}.
Tyler Gunn36c50ed2018-11-15 07:29:49 -0800934 * <p>
935 * The default dialer has access to use this method.
Andrew Leed4abbfb2014-09-03 14:58:27 -0700936 *
Slava Shklyaeve65e4012019-03-04 16:02:34 +0000937 * @return The user outgoing phone account selected by the user, or {@code null} if there is no
938 * user selected outgoing {@link PhoneAccountHandle}.
Andrew Leed4abbfb2014-09-03 14:58:27 -0700939 */
Tyler Gunn36c50ed2018-11-15 07:29:49 -0800940 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
Slava Shklyaeve65e4012019-03-04 16:02:34 +0000941 public @Nullable PhoneAccountHandle getUserSelectedOutgoingPhoneAccount() {
Andrew Leed4abbfb2014-09-03 14:58:27 -0700942 try {
943 if (isServiceConnected()) {
Tyler Gunn36c50ed2018-11-15 07:29:49 -0800944 return getTelecomService().getUserSelectedOutgoingPhoneAccount(
945 mContext.getOpPackageName());
Andrew Leed4abbfb2014-09-03 14:58:27 -0700946 }
947 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700948 Log.e(TAG, "Error calling ITelecomService#getUserSelectedOutgoingPhoneAccount", e);
Andrew Leed4abbfb2014-09-03 14:58:27 -0700949 }
950 return null;
951 }
952
953 /**
Tyler Gunn36c50ed2018-11-15 07:29:49 -0800954 * Sets the user-chosen default {@link PhoneAccountHandle} for making outgoing phone calls.
955 *
956 * @param accountHandle The {@link PhoneAccountHandle} which will be used by default for making
Slava Shklyaeve65e4012019-03-04 16:02:34 +0000957 * outgoing voice calls, or {@code null} if no default is specified (the
958 * user will be asked each time a call is placed in this case).
Andrew Lee59cac3a2014-08-28 16:50:10 -0700959 * @hide
960 */
Tyler Gunn36c50ed2018-11-15 07:29:49 -0800961 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
Tyler Gunn6c14a6992019-02-04 15:12:06 -0800962 @TestApi
Tyler Gunn36c50ed2018-11-15 07:29:49 -0800963 @SystemApi
Slava Shklyaeve65e4012019-03-04 16:02:34 +0000964 public void setUserSelectedOutgoingPhoneAccount(@Nullable PhoneAccountHandle accountHandle) {
Andrew Lee59cac3a2014-08-28 16:50:10 -0700965 try {
966 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700967 getTelecomService().setUserSelectedOutgoingPhoneAccount(accountHandle);
Andrew Lee59cac3a2014-08-28 16:50:10 -0700968 }
969 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700970 Log.e(TAG, "Error calling ITelecomService#setUserSelectedOutgoingPhoneAccount");
Andrew Lee59cac3a2014-08-28 16:50:10 -0700971 }
972 }
973
974 /**
Andrew Lee59cac3a2014-08-28 16:50:10 -0700975 * Returns the current SIM call manager. Apps must be prepared for this method to return
Brad Ebingere7833312019-05-07 10:55:55 -0700976 * {@code null}, indicating that there currently exists no SIM call manager {@link PhoneAccount}
977 * for the default voice subscription.
Santos Cordon91371dc2015-05-08 13:52:09 -0700978 *
Brad Ebingere7833312019-05-07 10:55:55 -0700979 * @return The phone account handle of the current sim call manager for the default voice
980 * subscription.
981 * @see SubscriptionManager#getDefaultVoiceSubscriptionId()
Andrew Lee59cac3a2014-08-28 16:50:10 -0700982 */
983 public PhoneAccountHandle getSimCallManager() {
984 try {
985 if (isServiceConnected()) {
Brad Ebingere7833312019-05-07 10:55:55 -0700986 return getTelecomService().getSimCallManager(
987 SubscriptionManager.getDefaultSubscriptionId());
Andrew Lee59cac3a2014-08-28 16:50:10 -0700988 }
989 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700990 Log.e(TAG, "Error calling ITelecomService#getSimCallManager");
Andrew Lee59cac3a2014-08-28 16:50:10 -0700991 }
992 return null;
993 }
994
995 /**
Brad Ebingere7833312019-05-07 10:55:55 -0700996 * Returns current SIM call manager for the Telephony Subscription ID specified. Apps must be
997 * prepared for this method to return {@code null}, indicating that there currently exists no
998 * SIM call manager {@link PhoneAccount} for the subscription specified.
999 *
1000 * @param subscriptionId The Telephony Subscription ID that the SIM call manager should be
1001 * queried for.
1002 * @return The phone account handle of the current sim call manager.
1003 * @see SubscriptionManager#getActiveSubscriptionInfoList()
Brad Ebingere7833312019-05-07 10:55:55 -07001004 */
Tyler Gunn5567d742019-10-31 13:04:37 -07001005 public @Nullable PhoneAccountHandle getSimCallManagerForSubscription(int subscriptionId) {
Brad Ebingere7833312019-05-07 10:55:55 -07001006 try {
1007 if (isServiceConnected()) {
1008 return getTelecomService().getSimCallManager(subscriptionId);
1009 }
1010 } catch (RemoteException e) {
1011 Log.e(TAG, "Error calling ITelecomService#getSimCallManager");
1012 }
1013 return null;
1014 }
1015
1016 /**
1017 * Returns the current SIM call manager for the user-chosen default Telephony Subscription ID
1018 * (see {@link SubscriptionManager#getDefaultSubscriptionId()}) and the specified user. Apps
1019 * must be prepared for this method to return {@code null}, indicating that there currently
1020 * exists no SIM call manager {@link PhoneAccount} for the default voice subscription.
Sailesh Nepalcf855622015-07-28 19:22:14 -07001021 *
1022 * @return The phone account handle of the current sim call manager.
1023 *
1024 * @hide
Tyler Gunn6e3ecc42018-11-12 11:30:56 -08001025 * @deprecated Use {@link #getSimCallManager()}.
Sailesh Nepalcf855622015-07-28 19:22:14 -07001026 */
Tyler Gunn6e3ecc42018-11-12 11:30:56 -08001027 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 119305590)
Sailesh Nepalcf855622015-07-28 19:22:14 -07001028 public PhoneAccountHandle getSimCallManager(int userId) {
1029 try {
1030 if (isServiceConnected()) {
1031 return getTelecomService().getSimCallManagerForUser(userId);
1032 }
1033 } catch (RemoteException e) {
1034 Log.e(TAG, "Error calling ITelecomService#getSimCallManagerForUser");
1035 }
1036 return null;
1037 }
1038
1039 /**
Evan Charltoneb0a8d52014-09-04 12:03:34 -07001040 * Returns the current connection manager. Apps must be prepared for this method to return
Brad Ebingere7833312019-05-07 10:55:55 -07001041 * {@code null}, indicating that there currently exists no Connection Manager
1042 * {@link PhoneAccount} for the default voice subscription.
Evan Charltoneb0a8d52014-09-04 12:03:34 -07001043 *
1044 * @return The phone account handle of the current connection manager.
Evan Charlton0e094d92014-11-08 15:49:16 -08001045 * @hide
Evan Charltoneb0a8d52014-09-04 12:03:34 -07001046 */
Evan Charlton0e094d92014-11-08 15:49:16 -08001047 @SystemApi
Evan Charltoneb0a8d52014-09-04 12:03:34 -07001048 public PhoneAccountHandle getConnectionManager() {
1049 return getSimCallManager();
1050 }
1051
1052 /**
Nancy Chen210ef032014-09-15 17:58:42 -07001053 * Returns a list of the {@link PhoneAccountHandle}s which can be used to make and receive phone
1054 * calls which support the specified URI scheme.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -07001055 * <P>
1056 * For example, invoking with {@code "tel"} will find all {@link PhoneAccountHandle}s which
1057 * support telephone calls (e.g. URIs such as {@code tel:555-555-1212}). Invoking with
1058 * {@code "sip"} will find all {@link PhoneAccountHandle}s which support SIP calls (e.g. URIs
1059 * such as {@code sip:example@sipexample.com}).
1060 *
1061 * @param uriScheme The URI scheme.
1062 * @return A list of {@code PhoneAccountHandle} objects supporting the URI scheme.
Evan Charlton0e094d92014-11-08 15:49:16 -08001063 * @hide
Tyler Gunnf5b29dc2014-09-03 09:09:12 -07001064 */
Evan Charlton0e094d92014-11-08 15:49:16 -08001065 @SystemApi
Jeff Sharkeybfc4fcd2017-06-05 17:38:17 -06001066 @RequiresPermission(anyOf = {
Tyler Gunn5567d742019-10-31 13:04:37 -07001067 READ_PRIVILEGED_PHONE_STATE,
Jeff Sharkeybfc4fcd2017-06-05 17:38:17 -06001068 android.Manifest.permission.READ_PHONE_STATE
1069 })
Tyler Gunnf5b29dc2014-09-03 09:09:12 -07001070 public List<PhoneAccountHandle> getPhoneAccountsSupportingScheme(String uriScheme) {
1071 try {
1072 if (isServiceConnected()) {
Svet Ganov16a16892015-04-16 10:32:04 -07001073 return getTelecomService().getPhoneAccountsSupportingScheme(uriScheme,
1074 mContext.getOpPackageName());
Tyler Gunnf5b29dc2014-09-03 09:09:12 -07001075 }
1076 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001077 Log.e(TAG, "Error calling ITelecomService#getPhoneAccountsSupportingScheme", e);
Tyler Gunnf5b29dc2014-09-03 09:09:12 -07001078 }
1079 return new ArrayList<>();
1080 }
1081
Nancy Chen513c8922014-09-17 14:47:20 -07001082
1083 /**
Santos Cordon91371dc2015-05-08 13:52:09 -07001084 * Returns a list of {@link PhoneAccountHandle}s which can be used to make and receive phone
1085 * calls. The returned list includes only those accounts which have been explicitly enabled
1086 * by the user.
Nancy Chen513c8922014-09-17 14:47:20 -07001087 *
Yorke Leec61d1362015-09-21 17:25:25 -07001088 * Requires permission: {@link android.Manifest.permission#READ_PHONE_STATE}
1089 *
Nancy Chen513c8922014-09-17 14:47:20 -07001090 * @see #EXTRA_PHONE_ACCOUNT_HANDLE
1091 * @return A list of {@code PhoneAccountHandle} objects.
Nancy Chen513c8922014-09-17 14:47:20 -07001092 */
Yorke Leec61d1362015-09-21 17:25:25 -07001093 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
Nancy Chen513c8922014-09-17 14:47:20 -07001094 public List<PhoneAccountHandle> getCallCapablePhoneAccounts() {
Santos Cordon91371dc2015-05-08 13:52:09 -07001095 return getCallCapablePhoneAccounts(false);
1096 }
1097
1098 /**
Tyler Gunn89317072017-04-07 14:57:37 -07001099 * Returns a list of {@link PhoneAccountHandle}s for self-managed {@link ConnectionService}s.
1100 * <p>
1101 * Self-Managed {@link ConnectionService}s have a {@link PhoneAccount} with
1102 * {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.
1103 * <p>
1104 * Requires permission {@link android.Manifest.permission#READ_PHONE_STATE}, or that the caller
1105 * is the default dialer app.
1106 * <p>
1107 * A {@link SecurityException} will be thrown if a called is not the default dialer, or lacks
1108 * the {@link android.Manifest.permission#READ_PHONE_STATE} permission.
1109 *
1110 * @return A list of {@code PhoneAccountHandle} objects.
1111 */
1112 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
1113 public List<PhoneAccountHandle> getSelfManagedPhoneAccounts() {
1114 try {
1115 if (isServiceConnected()) {
1116 return getTelecomService().getSelfManagedPhoneAccounts(mContext.getOpPackageName());
1117 }
1118 } catch (RemoteException e) {
1119 Log.e(TAG, "Error calling ITelecomService#getSelfManagedPhoneAccounts()", e);
1120 }
1121 return new ArrayList<>();
1122 }
1123
1124 /**
Santos Cordon91371dc2015-05-08 13:52:09 -07001125 * Returns a list of {@link PhoneAccountHandle}s including those which have not been enabled
1126 * by the user.
1127 *
Tyler Gunn6e3ecc42018-11-12 11:30:56 -08001128 * @param includeDisabledAccounts When {@code true}, disabled phone accounts will be included,
Hall Liub2306242019-11-15 17:13:05 -08001129 * when {@code false}, only enabled phone accounts will be
1130 * included.
Santos Cordon91371dc2015-05-08 13:52:09 -07001131 * @return A list of {@code PhoneAccountHandle} objects.
1132 * @hide
1133 */
Hall Liub2306242019-11-15 17:13:05 -08001134 @SystemApi
1135 @TestApi
1136 @RequiresPermission(READ_PRIVILEGED_PHONE_STATE)
1137 public @NonNull List<PhoneAccountHandle> getCallCapablePhoneAccounts(
1138 boolean includeDisabledAccounts) {
Nancy Chen513c8922014-09-17 14:47:20 -07001139 try {
1140 if (isServiceConnected()) {
Santos Cordon91371dc2015-05-08 13:52:09 -07001141 return getTelecomService().getCallCapablePhoneAccounts(
1142 includeDisabledAccounts, mContext.getOpPackageName());
Nancy Chen513c8922014-09-17 14:47:20 -07001143 }
1144 } catch (RemoteException e) {
Santos Cordon91371dc2015-05-08 13:52:09 -07001145 Log.e(TAG, "Error calling ITelecomService#getCallCapablePhoneAccounts(" +
1146 includeDisabledAccounts + ")", e);
Nancy Chen513c8922014-09-17 14:47:20 -07001147 }
1148 return new ArrayList<>();
1149 }
1150
Tyler Gunnf5b29dc2014-09-03 09:09:12 -07001151 /**
Nancy Chen513c8922014-09-17 14:47:20 -07001152 * Returns a list of all {@link PhoneAccount}s registered for the calling package.
1153 *
1154 * @return A list of {@code PhoneAccountHandle} objects.
Evan Charlton0e094d92014-11-08 15:49:16 -08001155 * @hide
Nancy Chen513c8922014-09-17 14:47:20 -07001156 */
Evan Charlton0e094d92014-11-08 15:49:16 -08001157 @SystemApi
Jeff Sharkeybfc4fcd2017-06-05 17:38:17 -06001158 @SuppressLint("Doclava125")
Nancy Chen513c8922014-09-17 14:47:20 -07001159 public List<PhoneAccountHandle> getPhoneAccountsForPackage() {
1160 try {
1161 if (isServiceConnected()) {
1162 return getTelecomService().getPhoneAccountsForPackage(mContext.getPackageName());
1163 }
1164 } catch (RemoteException e) {
1165 Log.e(TAG, "Error calling ITelecomService#getPhoneAccountsForPackage", e);
1166 }
1167 return null;
1168 }
1169
1170 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -07001171 * Return the {@link PhoneAccount} for a specified {@link PhoneAccountHandle}. Object includes
1172 * resources which can be used in a user interface.
Ihab Awad807fe0a2014-07-09 12:30:52 -07001173 *
Evan Charlton6eb262c2014-07-19 18:18:19 -07001174 * @param account The {@link PhoneAccountHandle}.
Evan Charlton8c8a0622014-07-20 12:31:00 -07001175 * @return The {@link PhoneAccount} object.
Ihab Awad807fe0a2014-07-09 12:30:52 -07001176 */
Evan Charlton8c8a0622014-07-20 12:31:00 -07001177 public PhoneAccount getPhoneAccount(PhoneAccountHandle account) {
Ihab Awad807fe0a2014-07-09 12:30:52 -07001178 try {
1179 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001180 return getTelecomService().getPhoneAccount(account);
Ihab Awad807fe0a2014-07-09 12:30:52 -07001181 }
1182 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001183 Log.e(TAG, "Error calling ITelecomService#getPhoneAccount", e);
Ihab Awad807fe0a2014-07-09 12:30:52 -07001184 }
1185 return null;
1186 }
1187
1188 /**
Nancy Chen210ef032014-09-15 17:58:42 -07001189 * Returns a count of all {@link PhoneAccount}s.
Tyler Gunna1ed7d12014-09-08 09:52:22 -07001190 *
Nancy Chen210ef032014-09-15 17:58:42 -07001191 * @return The count of {@link PhoneAccount}s.
Tyler Gunna1ed7d12014-09-08 09:52:22 -07001192 * @hide
1193 */
1194 @SystemApi
1195 public int getAllPhoneAccountsCount() {
1196 try {
1197 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001198 return getTelecomService().getAllPhoneAccountsCount();
Tyler Gunna1ed7d12014-09-08 09:52:22 -07001199 }
1200 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001201 Log.e(TAG, "Error calling ITelecomService#getAllPhoneAccountsCount", e);
Tyler Gunna1ed7d12014-09-08 09:52:22 -07001202 }
1203 return 0;
1204 }
1205
1206 /**
1207 * Returns a list of all {@link PhoneAccount}s.
1208 *
1209 * @return All {@link PhoneAccount}s.
1210 * @hide
1211 */
1212 @SystemApi
1213 public List<PhoneAccount> getAllPhoneAccounts() {
1214 try {
1215 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001216 return getTelecomService().getAllPhoneAccounts();
Tyler Gunna1ed7d12014-09-08 09:52:22 -07001217 }
1218 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001219 Log.e(TAG, "Error calling ITelecomService#getAllPhoneAccounts", e);
Tyler Gunna1ed7d12014-09-08 09:52:22 -07001220 }
1221 return Collections.EMPTY_LIST;
1222 }
1223
1224 /**
1225 * Returns a list of all {@link PhoneAccountHandle}s.
1226 *
1227 * @return All {@link PhoneAccountHandle}s.
1228 * @hide
1229 */
1230 @SystemApi
1231 public List<PhoneAccountHandle> getAllPhoneAccountHandles() {
1232 try {
1233 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001234 return getTelecomService().getAllPhoneAccountHandles();
Tyler Gunna1ed7d12014-09-08 09:52:22 -07001235 }
1236 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001237 Log.e(TAG, "Error calling ITelecomService#getAllPhoneAccountHandles", e);
Tyler Gunna1ed7d12014-09-08 09:52:22 -07001238 }
1239 return Collections.EMPTY_LIST;
1240 }
1241
1242 /**
Brad Ebingerec0d3342016-01-29 15:40:43 -08001243 * Register a {@link PhoneAccount} for use by the system that will be stored in Device Encrypted
1244 * storage. When registering {@link PhoneAccount}s, existing registrations will be overwritten
1245 * if the {@link PhoneAccountHandle} matches that of a {@link PhoneAccount} which is already
Santos Cordond9e614f2014-10-28 13:10:36 -07001246 * registered. Once registered, the {@link PhoneAccount} is listed to the user as an option
1247 * when placing calls. The user may still need to enable the {@link PhoneAccount} within
1248 * the phone app settings before the account is usable.
1249 * <p>
1250 * A {@link SecurityException} will be thrown if an app tries to register a
1251 * {@link PhoneAccountHandle} where the package name specified within
1252 * {@link PhoneAccountHandle#getComponentName()} does not match the package name of the app.
Ihab Awad807fe0a2014-07-09 12:30:52 -07001253 *
Evan Charlton8c8a0622014-07-20 12:31:00 -07001254 * @param account The complete {@link PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -07001255 */
Evan Charlton8c8a0622014-07-20 12:31:00 -07001256 public void registerPhoneAccount(PhoneAccount account) {
Ihab Awad807fe0a2014-07-09 12:30:52 -07001257 try {
1258 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001259 getTelecomService().registerPhoneAccount(account);
Ihab Awad807fe0a2014-07-09 12:30:52 -07001260 }
1261 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001262 Log.e(TAG, "Error calling ITelecomService#registerPhoneAccount", e);
Ihab Awad807fe0a2014-07-09 12:30:52 -07001263 }
1264 }
1265
1266 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -07001267 * Remove a {@link PhoneAccount} registration from the system.
Ihab Awad807fe0a2014-07-09 12:30:52 -07001268 *
Evan Charlton8c8a0622014-07-20 12:31:00 -07001269 * @param accountHandle A {@link PhoneAccountHandle} for the {@link PhoneAccount} to unregister.
Ihab Awad807fe0a2014-07-09 12:30:52 -07001270 */
Evan Charlton8c8a0622014-07-20 12:31:00 -07001271 public void unregisterPhoneAccount(PhoneAccountHandle accountHandle) {
Ihab Awad807fe0a2014-07-09 12:30:52 -07001272 try {
1273 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001274 getTelecomService().unregisterPhoneAccount(accountHandle);
Ihab Awad807fe0a2014-07-09 12:30:52 -07001275 }
1276 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001277 Log.e(TAG, "Error calling ITelecomService#unregisterPhoneAccount", e);
Ihab Awad807fe0a2014-07-09 12:30:52 -07001278 }
1279 }
1280
1281 /**
Nancy Chen7ab1dc42014-09-09 18:18:26 -07001282 * Remove all Accounts that belong to the calling package from the system.
Evan Charlton0e094d92014-11-08 15:49:16 -08001283 * @hide
Ihab Awad807fe0a2014-07-09 12:30:52 -07001284 */
Evan Charlton0e094d92014-11-08 15:49:16 -08001285 @SystemApi
Jeff Sharkeybfc4fcd2017-06-05 17:38:17 -06001286 @SuppressLint("Doclava125")
Yorke Lee06044272015-04-14 15:16:59 -07001287 public void clearPhoneAccounts() {
1288 clearAccounts();
1289 }
1290 /**
1291 * Remove all Accounts that belong to the calling package from the system.
1292 * @deprecated Use {@link #clearPhoneAccounts()} instead.
1293 * @hide
1294 */
1295 @SystemApi
Jeff Sharkeybfc4fcd2017-06-05 17:38:17 -06001296 @SuppressLint("Doclava125")
Nancy Chen7ab1dc42014-09-09 18:18:26 -07001297 public void clearAccounts() {
Ihab Awad807fe0a2014-07-09 12:30:52 -07001298 try {
1299 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001300 getTelecomService().clearAccounts(mContext.getPackageName());
Ihab Awad807fe0a2014-07-09 12:30:52 -07001301 }
1302 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001303 Log.e(TAG, "Error calling ITelecomService#clearAccounts", e);
Ihab Awad807fe0a2014-07-09 12:30:52 -07001304 }
1305 }
1306
1307 /**
Anthony Lee67279262014-10-27 11:28:40 -07001308 * Remove all Accounts that belong to the specified package from the system.
1309 * @hide
1310 */
1311 public void clearAccountsForPackage(String packageName) {
1312 try {
1313 if (isServiceConnected() && !TextUtils.isEmpty(packageName)) {
1314 getTelecomService().clearAccounts(packageName);
1315 }
1316 } catch (RemoteException e) {
Nancy Chen5cf27842015-01-24 23:30:27 -08001317 Log.e(TAG, "Error calling ITelecomService#clearAccountsForPackage", e);
Anthony Lee67279262014-10-27 11:28:40 -07001318 }
1319 }
1320
Yorke Lee1011f482015-04-23 15:58:27 -07001321
Anthony Lee67279262014-10-27 11:28:40 -07001322 /**
Yorke Lee1011f482015-04-23 15:58:27 -07001323 * @deprecated - Use {@link TelecomManager#getDefaultDialerPackage} to directly access
1324 * the default dialer's package name instead.
Ihab Awad807fe0a2014-07-09 12:30:52 -07001325 * @hide
1326 */
Santos Cordon6c7a3882014-06-25 15:30:08 -07001327 @SystemApi
Jeff Sharkeybfc4fcd2017-06-05 17:38:17 -06001328 @SuppressLint("Doclava125")
Santos Cordon6c7a3882014-06-25 15:30:08 -07001329 public ComponentName getDefaultPhoneApp() {
1330 try {
Santos Cordon9eb45932014-06-27 12:28:43 -07001331 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001332 return getTelecomService().getDefaultPhoneApp();
Santos Cordon9eb45932014-06-27 12:28:43 -07001333 }
Santos Cordon6c7a3882014-06-25 15:30:08 -07001334 } catch (RemoteException e) {
1335 Log.e(TAG, "RemoteException attempting to get the default phone app.", e);
1336 }
1337 return null;
1338 }
1339
Santos Cordon9eb45932014-06-27 12:28:43 -07001340 /**
Yorke Lee1011f482015-04-23 15:58:27 -07001341 * Used to determine the currently selected default dialer package.
1342 *
1343 * @return package name for the default dialer package or null if no package has been
1344 * selected as the default dialer.
1345 */
1346 public String getDefaultDialerPackage() {
1347 try {
1348 if (isServiceConnected()) {
1349 return getTelecomService().getDefaultDialerPackage();
1350 }
1351 } catch (RemoteException e) {
1352 Log.e(TAG, "RemoteException attempting to get the default dialer package name.", e);
1353 }
1354 return null;
1355 }
1356
1357 /**
Tyler Gunn5567d742019-10-31 13:04:37 -07001358 * Used to determine the currently selected default dialer package for a specific user.
1359 *
1360 * @param userId the user id to query the default dialer package for.
1361 * @return package name for the default dialer package or null if no package has been
1362 * selected as the default dialer.
1363 * @hide
1364 */
1365 @SystemApi
1366 @TestApi
1367 @RequiresPermission(READ_PRIVILEGED_PHONE_STATE)
1368 public @Nullable String getDefaultDialerPackage(int userId) {
1369 try {
1370 if (isServiceConnected()) {
1371 return getTelecomService().getDefaultDialerPackageForUser(userId);
1372 }
1373 } catch (RemoteException e) {
1374 Log.e(TAG, "RemoteException attempting to get the default dialer package name.", e);
1375 }
1376 return null;
1377 }
1378
1379 /**
Yorke Lee107c4ce2015-06-15 12:08:24 -07001380 * Used to set the default dialer package.
1381 *
Slava Shklyaeve65e4012019-03-04 16:02:34 +00001382 * @param packageName to set the default dialer to, or {@code null} if the system provided
1383 * dialer should be used instead.
Yorke Lee107c4ce2015-06-15 12:08:24 -07001384 *
1385 * @result {@code true} if the default dialer was successfully changed, {@code false} if
1386 * the specified package does not correspond to an installed dialer, or is already
1387 * the default dialer.
1388 *
1389 * Requires permission: {@link android.Manifest.permission#MODIFY_PHONE_STATE}
1390 * Requires permission: {@link android.Manifest.permission#WRITE_SECURE_SETTINGS}
1391 *
1392 * @hide
Tyler Gunn7e45b722018-12-04 12:56:45 -08001393 * @deprecated Use
Hai Zhangf5e8ccd2019-03-06 20:12:24 -08001394 * {@link android.app.role.RoleManager#addRoleHolderAsUser(String, String, int, UserHandle,
1395 * Executor, java.util.function.Consumer)} instead.
Suprabh Shukla169bed72019-05-13 13:54:58 -07001396 * @removed
Yorke Lee107c4ce2015-06-15 12:08:24 -07001397 */
Tyler Gunn6e3ecc42018-11-12 11:30:56 -08001398 @SystemApi
Tyler Gunn7e45b722018-12-04 12:56:45 -08001399 @Deprecated
Tyler Gunn6e3ecc42018-11-12 11:30:56 -08001400 @RequiresPermission(allOf = {
1401 android.Manifest.permission.MODIFY_PHONE_STATE,
1402 android.Manifest.permission.WRITE_SECURE_SETTINGS})
Slava Shklyaeve65e4012019-03-04 16:02:34 +00001403 public boolean setDefaultDialer(@Nullable String packageName) {
Yorke Lee107c4ce2015-06-15 12:08:24 -07001404 try {
1405 if (isServiceConnected()) {
1406 return getTelecomService().setDefaultDialer(packageName);
1407 }
1408 } catch (RemoteException e) {
1409 Log.e(TAG, "RemoteException attempting to set the default dialer.", e);
1410 }
1411 return false;
1412 }
1413
1414 /**
Tyler Gunn6e3ecc42018-11-12 11:30:56 -08001415 * Determines the package name of the system-provided default phone app.
Yorke Lee1011f482015-04-23 15:58:27 -07001416 *
Slava Shklyaeve65e4012019-03-04 16:02:34 +00001417 * @return package name for the system dialer package or {@code null} if no system dialer is
1418 * preloaded.
Yorke Lee1011f482015-04-23 15:58:27 -07001419 */
Slava Shklyaeve65e4012019-03-04 16:02:34 +00001420 public @Nullable String getSystemDialerPackage() {
Yorke Lee1011f482015-04-23 15:58:27 -07001421 try {
1422 if (isServiceConnected()) {
1423 return getTelecomService().getSystemDialerPackage();
1424 }
1425 } catch (RemoteException e) {
1426 Log.e(TAG, "RemoteException attempting to get the system dialer package name.", e);
1427 }
1428 return null;
1429 }
1430
1431 /**
Nancy Chen443e5012014-10-15 15:48:21 -07001432 * Return whether a given phone number is the configured voicemail number for a
1433 * particular phone account.
1434 *
Yorke Leec61d1362015-09-21 17:25:25 -07001435 * Requires permission: {@link android.Manifest.permission#READ_PHONE_STATE}
1436 *
Nancy Chen443e5012014-10-15 15:48:21 -07001437 * @param accountHandle The handle for the account to check the voicemail number against
1438 * @param number The number to look up.
Nancy Chen443e5012014-10-15 15:48:21 -07001439 */
Yorke Leec61d1362015-09-21 17:25:25 -07001440 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
Nancy Chen443e5012014-10-15 15:48:21 -07001441 public boolean isVoiceMailNumber(PhoneAccountHandle accountHandle, String number) {
1442 try {
1443 if (isServiceConnected()) {
Svet Ganov16a16892015-04-16 10:32:04 -07001444 return getTelecomService().isVoiceMailNumber(accountHandle, number,
1445 mContext.getOpPackageName());
Nancy Chen443e5012014-10-15 15:48:21 -07001446 }
1447 } catch (RemoteException e) {
Nancy Chen5cf27842015-01-24 23:30:27 -08001448 Log.e(TAG, "RemoteException calling ITelecomService#isVoiceMailNumber.", e);
Nancy Chen443e5012014-10-15 15:48:21 -07001449 }
1450 return false;
1451 }
1452
1453 /**
Yorke Lee49e2d462015-04-15 16:14:22 -07001454 * Return the voicemail number for a given phone account.
Nancy Chen8c066f72014-12-03 15:18:08 -08001455 *
Yorke Leec61d1362015-09-21 17:25:25 -07001456 * Requires permission: {@link android.Manifest.permission#READ_PHONE_STATE}
1457 *
Yorke Lee49e2d462015-04-15 16:14:22 -07001458 * @param accountHandle The handle for the phone account.
1459 * @return The voicemail number for the phone account, and {@code null} if one has not been
1460 * configured.
Nancy Chen8c066f72014-12-03 15:18:08 -08001461 */
Yorke Leec61d1362015-09-21 17:25:25 -07001462 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
Yorke Lee49e2d462015-04-15 16:14:22 -07001463 public String getVoiceMailNumber(PhoneAccountHandle accountHandle) {
Nancy Chen8c066f72014-12-03 15:18:08 -08001464 try {
1465 if (isServiceConnected()) {
Svet Ganov16a16892015-04-16 10:32:04 -07001466 return getTelecomService().getVoiceMailNumber(accountHandle,
1467 mContext.getOpPackageName());
Nancy Chen8c066f72014-12-03 15:18:08 -08001468 }
1469 } catch (RemoteException e) {
Nancy Chen5cf27842015-01-24 23:30:27 -08001470 Log.e(TAG, "RemoteException calling ITelecomService#hasVoiceMailNumber.", e);
Nancy Chen8c066f72014-12-03 15:18:08 -08001471 }
Yorke Lee49e2d462015-04-15 16:14:22 -07001472 return null;
Nancy Chen8c066f72014-12-03 15:18:08 -08001473 }
1474
1475 /**
Nancy Chen5cf27842015-01-24 23:30:27 -08001476 * Return the line 1 phone number for given phone account.
1477 *
Yorke Leec61d1362015-09-21 17:25:25 -07001478 * Requires permission: {@link android.Manifest.permission#READ_PHONE_STATE}
1479 *
Nancy Chen5cf27842015-01-24 23:30:27 -08001480 * @param accountHandle The handle for the account retrieve a number for.
1481 * @return A string representation of the line 1 phone number.
Nancy Chen5cf27842015-01-24 23:30:27 -08001482 */
Yorke Leec61d1362015-09-21 17:25:25 -07001483 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
Nancy Chen5cf27842015-01-24 23:30:27 -08001484 public String getLine1Number(PhoneAccountHandle accountHandle) {
1485 try {
1486 if (isServiceConnected()) {
Svet Ganov16a16892015-04-16 10:32:04 -07001487 return getTelecomService().getLine1Number(accountHandle,
1488 mContext.getOpPackageName());
Nancy Chen5cf27842015-01-24 23:30:27 -08001489 }
1490 } catch (RemoteException e) {
1491 Log.e(TAG, "RemoteException calling ITelecomService#getLine1Number.", e);
1492 }
1493 return null;
1494 }
1495
1496 /**
Santos Cordon9eb45932014-06-27 12:28:43 -07001497 * Returns whether there is an ongoing phone call (can be in dialing, ringing, active or holding
Tyler Gunn24e18332017-02-10 09:42:49 -08001498 * states) originating from either a manager or self-managed {@link ConnectionService}.
Nancy Chen0eb1e402014-08-21 22:52:29 -07001499 * <p>
1500 * Requires permission: {@link android.Manifest.permission#READ_PHONE_STATE}
Tyler Gunn24e18332017-02-10 09:42:49 -08001501 *
1502 * @return {@code true} if there is an ongoing call in either a managed or self-managed
1503 * {@link ConnectionService}, {@code false} otherwise.
Santos Cordon9eb45932014-06-27 12:28:43 -07001504 */
Yorke Leec61d1362015-09-21 17:25:25 -07001505 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
Nancy Chen0eb1e402014-08-21 22:52:29 -07001506 public boolean isInCall() {
Santos Cordon9eb45932014-06-27 12:28:43 -07001507 try {
1508 if (isServiceConnected()) {
Svet Ganov16a16892015-04-16 10:32:04 -07001509 return getTelecomService().isInCall(mContext.getOpPackageName());
Santos Cordon9eb45932014-06-27 12:28:43 -07001510 }
1511 } catch (RemoteException e) {
Yorke Lee2ae312e2014-09-12 17:58:48 -07001512 Log.e(TAG, "RemoteException calling isInCall().", e);
Santos Cordon9eb45932014-06-27 12:28:43 -07001513 }
1514 return false;
1515 }
1516
1517 /**
Tyler Gunn24e18332017-02-10 09:42:49 -08001518 * Returns whether there is an ongoing call originating from a managed
1519 * {@link ConnectionService}. An ongoing call can be in dialing, ringing, active or holding
1520 * states.
1521 * <p>
1522 * If you also need to know if there are ongoing self-managed calls, use {@link #isInCall()}
1523 * instead.
1524 * <p>
1525 * Requires permission: {@link android.Manifest.permission#READ_PHONE_STATE}
1526 *
1527 * @return {@code true} if there is an ongoing call in a managed {@link ConnectionService},
1528 * {@code false} otherwise.
1529 */
1530 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
1531 public boolean isInManagedCall() {
1532 try {
1533 if (isServiceConnected()) {
1534 return getTelecomService().isInManagedCall(mContext.getOpPackageName());
1535 }
1536 } catch (RemoteException e) {
1537 Log.e(TAG, "RemoteException calling isInManagedCall().", e);
1538 }
1539 return false;
1540 }
1541
1542 /**
Yorke Lee2ae312e2014-09-12 17:58:48 -07001543 * Returns one of the following constants that represents the current state of Telecom:
1544 *
1545 * {@link TelephonyManager#CALL_STATE_RINGING}
1546 * {@link TelephonyManager#CALL_STATE_OFFHOOK}
1547 * {@link TelephonyManager#CALL_STATE_IDLE}
Yorke Lee7c72c2d2014-10-28 14:12:02 -07001548 *
1549 * Note that this API does not require the
1550 * {@link android.Manifest.permission#READ_PHONE_STATE} permission. This is intentional, to
1551 * preserve the behavior of {@link TelephonyManager#getCallState()}, which also did not require
1552 * the permission.
Tyler Gunn24e18332017-02-10 09:42:49 -08001553 *
1554 * Takes into consideration both managed and self-managed calls.
1555 *
Yorke Lee2ae312e2014-09-12 17:58:48 -07001556 * @hide
1557 */
1558 @SystemApi
Chen Xu7631ff72019-09-26 16:11:59 -07001559 public @CallState int getCallState() {
Yorke Lee2ae312e2014-09-12 17:58:48 -07001560 try {
1561 if (isServiceConnected()) {
1562 return getTelecomService().getCallState();
1563 }
1564 } catch (RemoteException e) {
1565 Log.d(TAG, "RemoteException calling getCallState().", e);
1566 }
1567 return TelephonyManager.CALL_STATE_IDLE;
1568 }
1569
1570 /**
Santos Cordon9eb45932014-06-27 12:28:43 -07001571 * Returns whether there currently exists is a ringing incoming-call.
1572 *
Tyler Gunn24e18332017-02-10 09:42:49 -08001573 * @return {@code true} if there is a managed or self-managed ringing call.
Santos Cordon9eb45932014-06-27 12:28:43 -07001574 * @hide
1575 */
1576 @SystemApi
Jeff Sharkeybfc4fcd2017-06-05 17:38:17 -06001577 @RequiresPermission(anyOf = {
Tyler Gunn5567d742019-10-31 13:04:37 -07001578 READ_PRIVILEGED_PHONE_STATE,
Jeff Sharkeybfc4fcd2017-06-05 17:38:17 -06001579 android.Manifest.permission.READ_PHONE_STATE
1580 })
Santos Cordon9eb45932014-06-27 12:28:43 -07001581 public boolean isRinging() {
1582 try {
1583 if (isServiceConnected()) {
Svet Ganov16a16892015-04-16 10:32:04 -07001584 return getTelecomService().isRinging(mContext.getOpPackageName());
Santos Cordon9eb45932014-06-27 12:28:43 -07001585 }
1586 } catch (RemoteException e) {
1587 Log.e(TAG, "RemoteException attempting to get ringing state of phone app.", e);
1588 }
1589 return false;
1590 }
1591
1592 /**
Tyler Gunne1aa26c2018-05-02 13:23:48 -07001593 * Ends the foreground call on the device.
1594 * <p>
1595 * If there is a ringing call, calling this method rejects the ringing call. Otherwise the
1596 * foreground call is ended.
1597 * <p>
1598 * Requires permission {@link android.Manifest.permission#ANSWER_PHONE_CALLS}.
Tyler Gunnf18ee4c2019-05-14 11:08:06 -07001599 * <p>
1600 * Note: this method CANNOT be used to end ongoing emergency calls and will return {@code false}
1601 * if an attempt is made to end an emergency call.
Tyler Gunne1aa26c2018-05-02 13:23:48 -07001602 *
1603 * @return {@code true} if there is a call which will be rejected or terminated, {@code false}
1604 * otherwise.
Tyler Gunn9bd8db42019-01-31 10:54:03 -08001605 * @deprecated Companion apps for wearable devices should use the {@link InCallService} API
1606 * instead. Apps performing call screening should use the {@link CallScreeningService} API
1607 * instead.
Santos Cordon9eb45932014-06-27 12:28:43 -07001608 */
Tyler Gunne1aa26c2018-05-02 13:23:48 -07001609 @RequiresPermission(Manifest.permission.ANSWER_PHONE_CALLS)
Tyler Gunn9bd8db42019-01-31 10:54:03 -08001610 @Deprecated
Santos Cordon9eb45932014-06-27 12:28:43 -07001611 public boolean endCall() {
1612 try {
1613 if (isServiceConnected()) {
Tyler Gunnc8658812018-02-07 16:08:27 -08001614 return getTelecomService().endCall(mContext.getPackageName());
Santos Cordon9eb45932014-06-27 12:28:43 -07001615 }
1616 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001617 Log.e(TAG, "Error calling ITelecomService#endCall", e);
Santos Cordon9eb45932014-06-27 12:28:43 -07001618 }
1619 return false;
1620 }
1621
1622 /**
1623 * If there is a ringing incoming call, this method accepts the call on behalf of the user.
Eugene Suslacae3d3e2017-01-31 11:08:11 -08001624 *
Tyler Gunn6676bb52015-10-23 14:39:49 -07001625 * If the incoming call is a video call, the call will be answered with the same video state as
1626 * the incoming call requests. This means, for example, that an incoming call requesting
1627 * {@link VideoProfile#STATE_BIDIRECTIONAL} will be answered, accepting that state.
Eugene Suslacae3d3e2017-01-31 11:08:11 -08001628 *
1629 * Requires permission: {@link android.Manifest.permission#MODIFY_PHONE_STATE} or
1630 * {@link android.Manifest.permission#ANSWER_PHONE_CALLS}
Tyler Gunn9bd8db42019-01-31 10:54:03 -08001631 *
1632 * @deprecated Companion apps for wearable devices should use the {@link InCallService} API
1633 * instead.
Santos Cordon9eb45932014-06-27 12:28:43 -07001634 */
Eugene Suslacae3d3e2017-01-31 11:08:11 -08001635 //TODO: L-release - need to convert all invocation of ITelecmmService#answerRingingCall to use
1636 // this method (clockwork & gearhead).
1637 @RequiresPermission(anyOf =
1638 {Manifest.permission.ANSWER_PHONE_CALLS, Manifest.permission.MODIFY_PHONE_STATE})
Tyler Gunn9bd8db42019-01-31 10:54:03 -08001639 @Deprecated
Santos Cordon9eb45932014-06-27 12:28:43 -07001640 public void acceptRingingCall() {
1641 try {
1642 if (isServiceConnected()) {
Eugene Suslacae3d3e2017-01-31 11:08:11 -08001643 getTelecomService().acceptRingingCall(mContext.getPackageName());
Santos Cordon9eb45932014-06-27 12:28:43 -07001644 }
1645 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001646 Log.e(TAG, "Error calling ITelecomService#acceptRingingCall", e);
Santos Cordon9eb45932014-06-27 12:28:43 -07001647 }
1648 }
1649
1650 /**
Tyler Gunn6676bb52015-10-23 14:39:49 -07001651 * If there is a ringing incoming call, this method accepts the call on behalf of the user,
1652 * with the specified video state.
1653 *
Eugene Suslacae3d3e2017-01-31 11:08:11 -08001654 * Requires permission: {@link android.Manifest.permission#MODIFY_PHONE_STATE} or
1655 * {@link android.Manifest.permission#ANSWER_PHONE_CALLS}
1656 *
Tyler Gunn6676bb52015-10-23 14:39:49 -07001657 * @param videoState The desired video state to answer the call with.
Tyler Gunn9bd8db42019-01-31 10:54:03 -08001658 * @deprecated Companion apps for wearable devices should use the {@link InCallService} API
1659 * instead.
Tyler Gunn6676bb52015-10-23 14:39:49 -07001660 */
Eugene Suslacae3d3e2017-01-31 11:08:11 -08001661 @RequiresPermission(anyOf =
1662 {Manifest.permission.ANSWER_PHONE_CALLS, Manifest.permission.MODIFY_PHONE_STATE})
Tyler Gunn9bd8db42019-01-31 10:54:03 -08001663 @Deprecated
Tyler Gunn6676bb52015-10-23 14:39:49 -07001664 public void acceptRingingCall(int videoState) {
1665 try {
1666 if (isServiceConnected()) {
Eugene Suslacae3d3e2017-01-31 11:08:11 -08001667 getTelecomService().acceptRingingCallWithVideoState(
1668 mContext.getPackageName(), videoState);
Tyler Gunn6676bb52015-10-23 14:39:49 -07001669 }
1670 } catch (RemoteException e) {
1671 Log.e(TAG, "Error calling ITelecomService#acceptRingingCallWithVideoState", e);
1672 }
1673 }
1674
1675 /**
Santos Cordon9eb45932014-06-27 12:28:43 -07001676 * Silences the ringer if a ringing call exists.
Tyler Gunn556d2402019-04-10 08:59:43 -07001677 * <p>
1678 * This method can only be relied upon to stop the ringtone for a call if the ringtone has
1679 * already started playing. It is intended to handle use-cases such as silencing a ringing call
1680 * when the user presses the volume button during ringing.
1681 * <p>
1682 * If this method is called prior to when the ringtone begins playing, the ringtone will not be
1683 * silenced. As such it is not intended as a means to avoid playing of a ringtone.
1684 * <p>
1685 * A dialer app which wants to have more control over ringtone playing should declare
1686 * {@link TelecomManager#METADATA_IN_CALL_SERVICE_RINGING} in the manifest entry for their
1687 * {@link InCallService} implementation to indicate that the app wants to be responsible for
1688 * playing the ringtone for all incoming calls.
1689 * <p>
1690 * Requires permission: {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the
1691 * app fills the dialer role (see {@link #getDefaultDialerPackage()}).
Santos Cordon9eb45932014-06-27 12:28:43 -07001692 */
Yorke Leec61d1362015-09-21 17:25:25 -07001693 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
Santos Cordon9eb45932014-06-27 12:28:43 -07001694 public void silenceRinger() {
1695 try {
1696 if (isServiceConnected()) {
Yorke Leef1a349b2015-04-29 16:16:50 -07001697 getTelecomService().silenceRinger(mContext.getOpPackageName());
Santos Cordon9eb45932014-06-27 12:28:43 -07001698 }
1699 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001700 Log.e(TAG, "Error calling ITelecomService#silenceRinger", e);
Santos Cordon9eb45932014-06-27 12:28:43 -07001701 }
1702 }
1703
Sailesh Nepal001bbbb2014-07-15 14:40:39 -07001704 /**
1705 * Returns whether TTY is supported on this device.
Sailesh Nepal001bbbb2014-07-15 14:40:39 -07001706 */
Jeff Sharkeybfc4fcd2017-06-05 17:38:17 -06001707 @RequiresPermission(anyOf = {
Tyler Gunn5567d742019-10-31 13:04:37 -07001708 READ_PRIVILEGED_PHONE_STATE,
Jeff Sharkeybfc4fcd2017-06-05 17:38:17 -06001709 android.Manifest.permission.READ_PHONE_STATE
1710 })
Sailesh Nepal001bbbb2014-07-15 14:40:39 -07001711 public boolean isTtySupported() {
1712 try {
1713 if (isServiceConnected()) {
Svet Ganov16a16892015-04-16 10:32:04 -07001714 return getTelecomService().isTtySupported(mContext.getOpPackageName());
Sailesh Nepal001bbbb2014-07-15 14:40:39 -07001715 }
1716 } catch (RemoteException e) {
1717 Log.e(TAG, "RemoteException attempting to get TTY supported state.", e);
1718 }
1719 return false;
1720 }
1721
1722 /**
1723 * Returns the current TTY mode of the device. For TTY to be on the user must enable it in
Santos Cordon96efb482014-07-19 14:57:05 -07001724 * settings and have a wired headset plugged in.
1725 * Valid modes are:
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001726 * - {@link TelecomManager#TTY_MODE_OFF}
1727 * - {@link TelecomManager#TTY_MODE_FULL}
1728 * - {@link TelecomManager#TTY_MODE_HCO}
1729 * - {@link TelecomManager#TTY_MODE_VCO}
Sailesh Nepal001bbbb2014-07-15 14:40:39 -07001730 * @hide
1731 */
Tyler Gunn6e3ecc42018-11-12 11:30:56 -08001732 @SystemApi
Tyler Gunn6c14a6992019-02-04 15:12:06 -08001733 @TestApi
Tyler Gunn5567d742019-10-31 13:04:37 -07001734 @RequiresPermission(READ_PRIVILEGED_PHONE_STATE)
Tyler Gunn6e3ecc42018-11-12 11:30:56 -08001735 public @TtyMode int getCurrentTtyMode() {
Sailesh Nepal001bbbb2014-07-15 14:40:39 -07001736 try {
1737 if (isServiceConnected()) {
Svet Ganov16a16892015-04-16 10:32:04 -07001738 return getTelecomService().getCurrentTtyMode(mContext.getOpPackageName());
Sailesh Nepal001bbbb2014-07-15 14:40:39 -07001739 }
1740 } catch (RemoteException e) {
1741 Log.e(TAG, "RemoteException attempting to get the current TTY mode.", e);
1742 }
Evan Charlton10197192014-07-19 15:00:29 -07001743 return TTY_MODE_OFF;
Sailesh Nepal001bbbb2014-07-15 14:40:39 -07001744 }
1745
Santos Cordon96efb482014-07-19 14:57:05 -07001746 /**
1747 * Registers a new incoming call. A {@link ConnectionService} should invoke this method when it
Tyler Gunnf5035432017-01-09 09:43:12 -08001748 * has an incoming call. For managed {@link ConnectionService}s, the specified
1749 * {@link PhoneAccountHandle} must have been registered with {@link #registerPhoneAccount} and
1750 * the user must have enabled the corresponding {@link PhoneAccount}. This can be checked using
1751 * {@link #getPhoneAccount}. Self-managed {@link ConnectionService}s must have
1752 * {@link android.Manifest.permission#MANAGE_OWN_CALLS} to add a new incoming call.
1753 * <p>
Tyler Gunn37653562017-03-13 18:15:15 -07001754 * The incoming call you are adding is assumed to have a video state of
1755 * {@link VideoProfile#STATE_AUDIO_ONLY}, unless the extra value
1756 * {@link #EXTRA_INCOMING_VIDEO_STATE} is specified.
1757 * <p>
Tyler Gunnf5035432017-01-09 09:43:12 -08001758 * Once invoked, this method will cause the system to bind to the {@link ConnectionService}
1759 * associated with the {@link PhoneAccountHandle} and request additional information about the
1760 * call (See {@link ConnectionService#onCreateIncomingConnection}) before starting the incoming
Brad Ebingerec0d3342016-01-29 15:40:43 -08001761 * call UI.
1762 * <p>
Tyler Gunnf5035432017-01-09 09:43:12 -08001763 * For a managed {@link ConnectionService}, a {@link SecurityException} will be thrown if either
1764 * the {@link PhoneAccountHandle} does not correspond to a registered {@link PhoneAccount} or
1765 * the associated {@link PhoneAccount} is not currently enabled by the user.
1766 * <p>
1767 * For a self-managed {@link ConnectionService}, a {@link SecurityException} will be thrown if
1768 * the {@link PhoneAccount} has {@link PhoneAccount#CAPABILITY_SELF_MANAGED} and the calling app
1769 * does not have {@link android.Manifest.permission#MANAGE_OWN_CALLS}.
1770 *
Santos Cordon96efb482014-07-19 14:57:05 -07001771 * @param phoneAccount A {@link PhoneAccountHandle} registered with
1772 * {@link #registerPhoneAccount}.
1773 * @param extras A bundle that will be passed through to
1774 * {@link ConnectionService#onCreateIncomingConnection}.
1775 */
1776 public void addNewIncomingCall(PhoneAccountHandle phoneAccount, Bundle extras) {
1777 try {
1778 if (isServiceConnected()) {
Sanket Padawef6a9e5b2018-01-05 14:26:16 -08001779 if (extras != null && extras.getBoolean(EXTRA_IS_HANDOVER) &&
1780 mContext.getApplicationContext().getApplicationInfo().targetSdkVersion >
1781 Build.VERSION_CODES.O_MR1) {
1782 Log.e("TAG", "addNewIncomingCall failed. Use public api " +
1783 "acceptHandover for API > O-MR1");
Tyler Gunn9ae6db82019-02-13 13:51:18 -08001784 return;
Sanket Padawef6a9e5b2018-01-05 14:26:16 -08001785 }
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001786 getTelecomService().addNewIncomingCall(
Santos Cordon96efb482014-07-19 14:57:05 -07001787 phoneAccount, extras == null ? new Bundle() : extras);
1788 }
1789 } catch (RemoteException e) {
1790 Log.e(TAG, "RemoteException adding a new incoming call: " + phoneAccount, e);
1791 }
1792 }
1793
Nancy Chen0eb1e402014-08-21 22:52:29 -07001794 /**
Yorke Leec3cf9822014-10-02 09:38:39 -07001795 * Registers a new unknown call with Telecom. This can only be called by the system Telephony
1796 * service. This is invoked when Telephony detects a new unknown connection that was neither
1797 * a new incoming call, nor an user-initiated outgoing call.
1798 *
1799 * @param phoneAccount A {@link PhoneAccountHandle} registered with
1800 * {@link #registerPhoneAccount}.
1801 * @param extras A bundle that will be passed through to
1802 * {@link ConnectionService#onCreateIncomingConnection}.
1803 * @hide
1804 */
1805 @SystemApi
1806 public void addNewUnknownCall(PhoneAccountHandle phoneAccount, Bundle extras) {
1807 try {
1808 if (isServiceConnected()) {
1809 getTelecomService().addNewUnknownCall(
1810 phoneAccount, extras == null ? new Bundle() : extras);
1811 }
1812 } catch (RemoteException e) {
1813 Log.e(TAG, "RemoteException adding a new unknown call: " + phoneAccount, e);
1814 }
1815 }
1816
1817 /**
Nancy Chen0eb1e402014-08-21 22:52:29 -07001818 * Processes the specified dial string as an MMI code.
1819 * MMI codes are any sequence of characters entered into the dialpad that contain a "*" or "#".
1820 * Some of these sequences launch special behavior through handled by Telephony.
Nancy Chen95e8a672014-10-16 18:38:21 -07001821 * This method uses the default subscription.
Nancy Chen0eb1e402014-08-21 22:52:29 -07001822 * <p>
1823 * Requires that the method-caller be set as the system dialer app.
1824 * </p>
1825 *
Yorke Leec61d1362015-09-21 17:25:25 -07001826 * Requires permission: {@link android.Manifest.permission#MODIFY_PHONE_STATE}
1827 *
Nancy Chen0eb1e402014-08-21 22:52:29 -07001828 * @param dialString The digits to dial.
1829 * @return True if the digits were processed as an MMI code, false otherwise.
1830 */
Yorke Leec61d1362015-09-21 17:25:25 -07001831 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
Nancy Chen0eb1e402014-08-21 22:52:29 -07001832 public boolean handleMmi(String dialString) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001833 ITelecomService service = getTelecomService();
Nancy Chen0eb1e402014-08-21 22:52:29 -07001834 if (service != null) {
1835 try {
Yorke Leef1a349b2015-04-29 16:16:50 -07001836 return service.handlePinMmi(dialString, mContext.getOpPackageName());
Nancy Chen0eb1e402014-08-21 22:52:29 -07001837 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001838 Log.e(TAG, "Error calling ITelecomService#handlePinMmi", e);
Nancy Chen0eb1e402014-08-21 22:52:29 -07001839 }
1840 }
1841 return false;
1842 }
1843
1844 /**
Nancy Chen95e8a672014-10-16 18:38:21 -07001845 * Processes the specified dial string as an MMI code.
1846 * MMI codes are any sequence of characters entered into the dialpad that contain a "*" or "#".
1847 * Some of these sequences launch special behavior through handled by Telephony.
1848 * <p>
1849 * Requires that the method-caller be set as the system dialer app.
1850 * </p>
1851 *
Yorke Leec61d1362015-09-21 17:25:25 -07001852 * Requires permission: {@link android.Manifest.permission#MODIFY_PHONE_STATE}
1853 *
Nancy Chen95e8a672014-10-16 18:38:21 -07001854 * @param accountHandle The handle for the account the MMI code should apply to.
1855 * @param dialString The digits to dial.
1856 * @return True if the digits were processed as an MMI code, false otherwise.
Nancy Chen95e8a672014-10-16 18:38:21 -07001857 */
Yorke Leec61d1362015-09-21 17:25:25 -07001858 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
Yorke Lee06044272015-04-14 15:16:59 -07001859 public boolean handleMmi(String dialString, PhoneAccountHandle accountHandle) {
Nancy Chen95e8a672014-10-16 18:38:21 -07001860 ITelecomService service = getTelecomService();
1861 if (service != null) {
1862 try {
Yorke Leef1a349b2015-04-29 16:16:50 -07001863 return service.handlePinMmiForPhoneAccount(accountHandle, dialString,
1864 mContext.getOpPackageName());
Nancy Chen95e8a672014-10-16 18:38:21 -07001865 } catch (RemoteException e) {
1866 Log.e(TAG, "Error calling ITelecomService#handlePinMmi", e);
1867 }
1868 }
1869 return false;
1870 }
1871
1872 /**
Yorke Leec61d1362015-09-21 17:25:25 -07001873 * Requires permission: {@link android.Manifest.permission#MODIFY_PHONE_STATE}
1874 *
Nancy Chenb2299c12014-10-29 18:22:11 -07001875 * @param accountHandle The handle for the account to derive an adn query URI for or
1876 * {@code null} to return a URI which will use the default account.
1877 * @return The URI (with the content:// scheme) specific to the specified {@link PhoneAccount}
1878 * for the the content retrieve.
1879 */
Yorke Leec61d1362015-09-21 17:25:25 -07001880 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
Nancy Chenb2299c12014-10-29 18:22:11 -07001881 public Uri getAdnUriForPhoneAccount(PhoneAccountHandle accountHandle) {
1882 ITelecomService service = getTelecomService();
1883 if (service != null && accountHandle != null) {
1884 try {
Yorke Leef1a349b2015-04-29 16:16:50 -07001885 return service.getAdnUriForPhoneAccount(accountHandle, mContext.getOpPackageName());
Nancy Chenb2299c12014-10-29 18:22:11 -07001886 } catch (RemoteException e) {
1887 Log.e(TAG, "Error calling ITelecomService#getAdnUriForPhoneAccount", e);
1888 }
1889 }
1890 return Uri.parse("content://icc/adn");
1891 }
1892
1893 /**
Nancy Chen0eb1e402014-08-21 22:52:29 -07001894 * Removes the missed-call notification if one is present.
1895 * <p>
1896 * Requires that the method-caller be set as the system dialer app.
1897 * </p>
Yorke Leec61d1362015-09-21 17:25:25 -07001898 *
1899 * Requires permission: {@link android.Manifest.permission#MODIFY_PHONE_STATE}
Nancy Chen0eb1e402014-08-21 22:52:29 -07001900 */
Yorke Leec61d1362015-09-21 17:25:25 -07001901 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
Nancy Chen0eb1e402014-08-21 22:52:29 -07001902 public void cancelMissedCallsNotification() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001903 ITelecomService service = getTelecomService();
Nancy Chen0eb1e402014-08-21 22:52:29 -07001904 if (service != null) {
1905 try {
Yorke Leef1a349b2015-04-29 16:16:50 -07001906 service.cancelMissedCallsNotification(mContext.getOpPackageName());
Nancy Chen0eb1e402014-08-21 22:52:29 -07001907 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001908 Log.e(TAG, "Error calling ITelecomService#cancelMissedCallsNotification", e);
Nancy Chen0eb1e402014-08-21 22:52:29 -07001909 }
1910 }
1911 }
1912
1913 /**
1914 * Brings the in-call screen to the foreground if there is an ongoing call. If there is
1915 * currently no ongoing call, then this method does nothing.
1916 * <p>
1917 * Requires that the method-caller be set as the system dialer app or have the
1918 * {@link android.Manifest.permission#READ_PHONE_STATE} permission.
1919 * </p>
1920 *
1921 * @param showDialpad Brings up the in-call dialpad as part of showing the in-call screen.
1922 */
Yorke Leec61d1362015-09-21 17:25:25 -07001923 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
Nancy Chen0eb1e402014-08-21 22:52:29 -07001924 public void showInCallScreen(boolean showDialpad) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001925 ITelecomService service = getTelecomService();
Nancy Chen0eb1e402014-08-21 22:52:29 -07001926 if (service != null) {
1927 try {
Svet Ganov16a16892015-04-16 10:32:04 -07001928 service.showInCallScreen(showDialpad, mContext.getOpPackageName());
Nancy Chen0eb1e402014-08-21 22:52:29 -07001929 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001930 Log.e(TAG, "Error calling ITelecomService#showCallScreen", e);
Nancy Chen0eb1e402014-08-21 22:52:29 -07001931 }
1932 }
1933 }
1934
Yorke Lee3e56ba12015-04-23 12:32:36 -07001935 /**
1936 * Places a new outgoing call to the provided address using the system telecom service with
1937 * the specified extras.
1938 *
1939 * This method is equivalent to placing an outgoing call using {@link Intent#ACTION_CALL},
1940 * except that the outgoing call will always be sent via the system telecom service. If
1941 * method-caller is either the user selected default dialer app or preloaded system dialer
1942 * app, then emergency calls will also be allowed.
1943 *
Tyler Gunnf5035432017-01-09 09:43:12 -08001944 * Placing a call via a managed {@link ConnectionService} requires permission:
1945 * {@link android.Manifest.permission#CALL_PHONE}
Yorke Lee3e56ba12015-04-23 12:32:36 -07001946 *
1947 * Usage example:
1948 * <pre>
1949 * Uri uri = Uri.fromParts("tel", "12345", null);
1950 * Bundle extras = new Bundle();
1951 * extras.putBoolean(TelecomManager.EXTRA_START_CALL_WITH_SPEAKERPHONE, true);
1952 * telecomManager.placeCall(uri, extras);
1953 * </pre>
1954 *
Santos Cordon7a060d52015-06-19 14:52:04 -07001955 * The following keys are supported in the supplied extras.
1956 * <ul>
1957 * <li>{@link #EXTRA_OUTGOING_CALL_EXTRAS}</li>
1958 * <li>{@link #EXTRA_PHONE_ACCOUNT_HANDLE}</li>
1959 * <li>{@link #EXTRA_START_CALL_WITH_SPEAKERPHONE}</li>
1960 * <li>{@link #EXTRA_START_CALL_WITH_VIDEO_STATE}</li>
1961 * </ul>
Tyler Gunnf5035432017-01-09 09:43:12 -08001962 * <p>
1963 * An app which implements the self-managed {@link ConnectionService} API uses
1964 * {@link #placeCall(Uri, Bundle)} to inform Telecom of a new outgoing call. A self-managed
1965 * {@link ConnectionService} must include {@link #EXTRA_PHONE_ACCOUNT_HANDLE} to specify its
1966 * associated {@link android.telecom.PhoneAccountHandle}.
1967 *
1968 * Self-managed {@link ConnectionService}s require permission
1969 * {@link android.Manifest.permission#MANAGE_OWN_CALLS}.
Santos Cordon7a060d52015-06-19 14:52:04 -07001970 *
Brad Ebinger3636d742019-05-21 15:28:19 -07001971 * <p class="note"><strong>Note:</strong> If this method is used to place an emergency call, it
1972 * is not guaranteed that the call will be placed on the {@link PhoneAccount} provided in
1973 * the {@link #EXTRA_PHONE_ACCOUNT_HANDLE} extra (if specified) and may be placed on another
1974 * {@link PhoneAccount} with the {@link PhoneAccount#CAPABILITY_PLACE_EMERGENCY_CALLS}
1975 * capability, depending on external factors, such as network conditions and Modem/SIM status.
1976 * </p>
1977 *
Yorke Lee3e56ba12015-04-23 12:32:36 -07001978 * @param address The address to make the call to.
1979 * @param extras Bundle of extras to use with the call.
1980 */
Tyler Gunnf5035432017-01-09 09:43:12 -08001981 @RequiresPermission(anyOf = {android.Manifest.permission.CALL_PHONE,
1982 android.Manifest.permission.MANAGE_OWN_CALLS})
Yorke Lee3e56ba12015-04-23 12:32:36 -07001983 public void placeCall(Uri address, Bundle extras) {
1984 ITelecomService service = getTelecomService();
1985 if (service != null) {
Yorke Leea5d5c1d2015-05-05 16:25:55 -07001986 if (address == null) {
1987 Log.w(TAG, "Cannot place call to empty address.");
1988 }
Yorke Lee3e56ba12015-04-23 12:32:36 -07001989 try {
Yorke Leea5d5c1d2015-05-05 16:25:55 -07001990 service.placeCall(address, extras == null ? new Bundle() : extras,
1991 mContext.getOpPackageName());
Yorke Lee3e56ba12015-04-23 12:32:36 -07001992 } catch (RemoteException e) {
1993 Log.e(TAG, "Error calling ITelecomService#placeCall", e);
1994 }
1995 }
1996 }
1997
Santos Cordon91371dc2015-05-08 13:52:09 -07001998 /**
1999 * Enables and disables specified phone account.
2000 *
2001 * @param handle Handle to the phone account.
2002 * @param isEnabled Enable state of the phone account.
2003 * @hide
2004 */
2005 @SystemApi
Jeff Sharkeybfc4fcd2017-06-05 17:38:17 -06002006 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
Santos Cordon91371dc2015-05-08 13:52:09 -07002007 public void enablePhoneAccount(PhoneAccountHandle handle, boolean isEnabled) {
2008 ITelecomService service = getTelecomService();
2009 if (service != null) {
2010 try {
2011 service.enablePhoneAccount(handle, isEnabled);
2012 } catch (RemoteException e) {
2013 Log.e(TAG, "Error enablePhoneAbbount", e);
2014 }
2015 }
2016 }
2017
Hall Liu0464b9b2016-01-12 15:32:58 -08002018 /**
2019 * Dumps telecom analytics for uploading.
2020 *
2021 * @return
2022 * @hide
2023 */
2024 @SystemApi
2025 @RequiresPermission(Manifest.permission.DUMP)
Hall Liu057def52016-05-05 17:17:07 -07002026 public TelecomAnalytics dumpAnalytics() {
Hall Liu0464b9b2016-01-12 15:32:58 -08002027 ITelecomService service = getTelecomService();
Hall Liu057def52016-05-05 17:17:07 -07002028 TelecomAnalytics result = null;
Hall Liu0464b9b2016-01-12 15:32:58 -08002029 if (service != null) {
2030 try {
2031 result = service.dumpCallAnalytics();
2032 } catch (RemoteException e) {
2033 Log.e(TAG, "Error dumping call analytics", e);
2034 }
2035 }
2036 return result;
2037 }
2038
Abhijith Shastry1908cb842016-02-02 11:10:19 -08002039 /**
Abhijith Shastrya26fe992016-02-29 11:40:24 -08002040 * Creates the {@link Intent} which can be used with {@link Context#startActivity(Intent)} to
2041 * launch the activity to manage blocked numbers.
Abhijith Shastryec30d2f2016-03-04 16:46:08 -08002042 * <p> The activity will display the UI to manage blocked numbers only if
Abhijith Shastrya26fe992016-02-29 11:40:24 -08002043 * {@link android.provider.BlockedNumberContract#canCurrentUserBlockNumbers(Context)} returns
2044 * {@code true} for the current user.
2045 */
2046 public Intent createManageBlockedNumbersIntent() {
2047 ITelecomService service = getTelecomService();
2048 Intent result = null;
2049 if (service != null) {
2050 try {
2051 result = service.createManageBlockedNumbersIntent();
2052 } catch (RemoteException e) {
2053 Log.e(TAG, "Error calling ITelecomService#createManageBlockedNumbersIntent", e);
2054 }
2055 }
2056 return result;
2057 }
2058
Fan Zhang2b2458e2019-10-14 13:43:46 -07002059
2060 /**
2061 * Creates the {@link Intent} which can be used with {@link Context#startActivity(Intent)} to
2062 * launch the activity for emergency dialer.
2063 *
2064 * @param number Optional number to call in emergency dialer
2065 * @hide
2066 */
2067 @SystemApi
2068 @NonNull
2069 public Intent createLaunchEmergencyDialerIntent(@Nullable String number) {
2070 ITelecomService service = getTelecomService();
2071 Intent result = null;
2072 if (service != null) {
2073 try {
2074 result = service.createLaunchEmergencyDialerIntent(number);
2075 } catch (RemoteException e) {
2076 Log.e(TAG, "Error createLaunchEmergencyDialerIntent", e);
2077 }
2078 }
2079 return result;
2080 }
2081
Tyler Gunnf5035432017-01-09 09:43:12 -08002082 /**
2083 * Determines whether Telecom would permit an incoming call to be added via the
2084 * {@link #addNewIncomingCall(PhoneAccountHandle, Bundle)} API for the specified
2085 * {@link PhoneAccountHandle}.
2086 * <p>
2087 * A {@link ConnectionService} may not add a call for the specified {@link PhoneAccountHandle}
2088 * in the following situations:
2089 * <ul>
2090 * <li>{@link PhoneAccount} does not have property
2091 * {@link PhoneAccount#CAPABILITY_SELF_MANAGED} set (i.e. it is a managed
2092 * {@link ConnectionService}), and the active or held call limit has
2093 * been reached.</li>
2094 * <li>There is an ongoing emergency call.</li>
2095 * </ul>
2096 *
2097 * @param phoneAccountHandle The {@link PhoneAccountHandle} the call will be added for.
2098 * @return {@code true} if telecom will permit an incoming call to be added, {@code false}
2099 * otherwise.
2100 */
2101 public boolean isIncomingCallPermitted(PhoneAccountHandle phoneAccountHandle) {
Tyler Gunn44e01912017-01-31 10:49:05 -08002102 if (phoneAccountHandle == null) {
2103 return false;
2104 }
2105
Tyler Gunnf5035432017-01-09 09:43:12 -08002106 ITelecomService service = getTelecomService();
2107 if (service != null) {
2108 try {
2109 return service.isIncomingCallPermitted(phoneAccountHandle);
2110 } catch (RemoteException e) {
2111 Log.e(TAG, "Error isIncomingCallPermitted", e);
2112 }
2113 }
2114 return false;
2115 }
2116
2117 /**
2118 * Determines whether Telecom would permit an outgoing call to be placed via the
2119 * {@link #placeCall(Uri, Bundle)} API for the specified {@link PhoneAccountHandle}.
2120 * <p>
2121 * A {@link ConnectionService} may not place a call for the specified {@link PhoneAccountHandle}
2122 * in the following situations:
2123 * <ul>
2124 * <li>{@link PhoneAccount} does not have property
2125 * {@link PhoneAccount#CAPABILITY_SELF_MANAGED} set (i.e. it is a managed
2126 * {@link ConnectionService}), and the active, held or ringing call limit has
2127 * been reached.</li>
2128 * <li>{@link PhoneAccount} has property {@link PhoneAccount#CAPABILITY_SELF_MANAGED} set
2129 * (i.e. it is a self-managed {@link ConnectionService} and there is an ongoing call in
2130 * another {@link ConnectionService}.</li>
2131 * <li>There is an ongoing emergency call.</li>
2132 * </ul>
2133 *
2134 * @param phoneAccountHandle The {@link PhoneAccountHandle} the call will be added for.
2135 * @return {@code true} if telecom will permit an outgoing call to be placed, {@code false}
2136 * otherwise.
2137 */
2138 public boolean isOutgoingCallPermitted(PhoneAccountHandle phoneAccountHandle) {
2139 ITelecomService service = getTelecomService();
2140 if (service != null) {
2141 try {
2142 return service.isOutgoingCallPermitted(phoneAccountHandle);
2143 } catch (RemoteException e) {
2144 Log.e(TAG, "Error isOutgoingCallPermitted", e);
2145 }
2146 }
2147 return false;
2148 }
2149
Sanket Padawea8eddd42017-11-03 11:07:35 -07002150 /**
Tyler Gunn9d127732018-03-02 15:45:51 -08002151 * Called by an app to indicate that it wishes to accept the handover of an ongoing call to a
2152 * {@link PhoneAccountHandle} it defines.
2153 * <p>
2154 * A call handover is the process where an ongoing call is transferred from one app (i.e.
2155 * {@link ConnectionService} to another app. The user could, for example, choose to continue a
2156 * mobile network call in a video calling app. The mobile network call via the Telephony stack
2157 * is referred to as the source of the handover, and the video calling app is referred to as the
2158 * destination.
2159 * <p>
2160 * When considering a handover scenario the <em>initiating</em> device is where a user initiated
2161 * the handover process (e.g. by calling {@link android.telecom.Call#handoverTo(
2162 * PhoneAccountHandle, int, Bundle)}, and the other device is considered the <em>receiving</em>
2163 * device.
2164 * <p>
2165 * For a full discussion of the handover process and the APIs involved, see
2166 * {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int, Bundle)}.
2167 * <p>
2168 * This method is called from the <em>receiving</em> side of a handover to indicate a desire to
2169 * accept the handover of an ongoing call to another {@link ConnectionService} identified by
Sanket Padawea8eddd42017-11-03 11:07:35 -07002170 * {@link PhoneAccountHandle} destAcct. For managed {@link ConnectionService}s, the specified
2171 * {@link PhoneAccountHandle} must have been registered with {@link #registerPhoneAccount} and
2172 * the user must have enabled the corresponding {@link PhoneAccount}. This can be checked using
2173 * {@link #getPhoneAccount}. Self-managed {@link ConnectionService}s must have
2174 * {@link android.Manifest.permission#MANAGE_OWN_CALLS} to handover a call to it.
2175 * <p>
2176 * Once invoked, this method will cause the system to bind to the {@link ConnectionService}
2177 * associated with the {@link PhoneAccountHandle} destAcct and call
2178 * (See {@link ConnectionService#onCreateIncomingHandoverConnection}).
2179 * <p>
2180 * For a managed {@link ConnectionService}, a {@link SecurityException} will be thrown if either
2181 * the {@link PhoneAccountHandle} destAcct does not correspond to a registered
2182 * {@link PhoneAccount} or the associated {@link PhoneAccount} is not currently enabled by the
2183 * user.
2184 * <p>
2185 * For a self-managed {@link ConnectionService}, a {@link SecurityException} will be thrown if
2186 * the calling app does not have {@link android.Manifest.permission#MANAGE_OWN_CALLS}.
2187 *
2188 * @param srcAddr The {@link android.net.Uri} of the ongoing call to handover to the caller’s
2189 * {@link ConnectionService}.
2190 * @param videoState Video state after the handover.
2191 * @param destAcct The {@link PhoneAccountHandle} registered to the calling package.
2192 */
Tyler Gunn9d127732018-03-02 15:45:51 -08002193 public void acceptHandover(Uri srcAddr, @VideoProfile.VideoState int videoState,
2194 PhoneAccountHandle destAcct) {
Sanket Padawea8eddd42017-11-03 11:07:35 -07002195 try {
2196 if (isServiceConnected()) {
2197 getTelecomService().acceptHandover(srcAddr, videoState, destAcct);
2198 }
2199 } catch (RemoteException e) {
2200 Log.e(TAG, "RemoteException acceptHandover: " + e);
2201 }
2202 }
Tyler Gunnf5035432017-01-09 09:43:12 -08002203
Tyler Gunn5bd90852018-09-21 09:37:07 -07002204 /**
2205 * Determines if there is an ongoing emergency call. This can be either an outgoing emergency
2206 * call, as identified by the dialed number, or because a call was identified by the network
2207 * as an emergency call.
2208 * @return {@code true} if there is an ongoing emergency call, {@code false} otherwise.
2209 * @hide
2210 */
2211 @SystemApi
Tyler Gunn6c14a6992019-02-04 15:12:06 -08002212 @TestApi
Tyler Gunn5bd90852018-09-21 09:37:07 -07002213 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2214 public boolean isInEmergencyCall() {
2215 try {
2216 if (isServiceConnected()) {
2217 return getTelecomService().isInEmergencyCall();
2218 }
2219 } catch (RemoteException e) {
2220 Log.e(TAG, "RemoteException isInEmergencyCall: " + e);
2221 return false;
2222 }
2223 return false;
2224 }
2225
Tyler Gunnc37445c2018-09-28 16:16:20 -07002226 /**
2227 * Handles {@link Intent#ACTION_CALL} intents trampolined from UserCallActivity.
2228 * @param intent The {@link Intent#ACTION_CALL} intent to handle.
Brad Ebingera9a33e12019-09-27 16:55:35 -07002229 * @param callingPackageProxy The original package that called this before it was trampolined.
Tyler Gunnc37445c2018-09-28 16:16:20 -07002230 * @hide
2231 */
Brad Ebingera9a33e12019-09-27 16:55:35 -07002232 public void handleCallIntent(Intent intent, String callingPackageProxy) {
Tyler Gunnc37445c2018-09-28 16:16:20 -07002233 try {
2234 if (isServiceConnected()) {
Brad Ebingera9a33e12019-09-27 16:55:35 -07002235 getTelecomService().handleCallIntent(intent, callingPackageProxy);
Tyler Gunnc37445c2018-09-28 16:16:20 -07002236 }
2237 } catch (RemoteException e) {
2238 Log.e(TAG, "RemoteException handleCallIntent: " + e);
2239 }
Tyler Gunnc37445c2018-09-28 16:16:20 -07002240 }
2241
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002242 private ITelecomService getTelecomService() {
Hall Liue1bc2ec2015-10-09 15:58:37 -07002243 if (mTelecomServiceOverride != null) {
2244 return mTelecomServiceOverride;
2245 }
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002246 return ITelecomService.Stub.asInterface(ServiceManager.getService(Context.TELECOM_SERVICE));
Santos Cordon6c7a3882014-06-25 15:30:08 -07002247 }
Santos Cordon9eb45932014-06-27 12:28:43 -07002248
2249 private boolean isServiceConnected() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002250 boolean isConnected = getTelecomService() != null;
Santos Cordon9eb45932014-06-27 12:28:43 -07002251 if (!isConnected) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002252 Log.w(TAG, "Telecom Service not found.");
Santos Cordon9eb45932014-06-27 12:28:43 -07002253 }
2254 return isConnected;
2255 }
Evan Charlton235c1592014-09-05 15:41:23 +00002256}