blob: 625cd72542ddd59a936a350bb2f8685a76745519 [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
Hall Liu0464b9b2016-01-12 15:32:58 -080017import android.Manifest;
Tyler Gunn6e3ecc42018-11-12 11:30:56 -080018import android.annotation.IntDef;
Fan Zhang5431ef52019-10-14 13:43:46 -070019import android.annotation.NonNull;
Slava Shklyaeve65e4012019-03-04 16:02:34 +000020import android.annotation.Nullable;
Yorke Leec61d13662015-09-21 17:25:25 -070021import android.annotation.RequiresPermission;
Jeff Sharkey910e0812017-04-21 16:29:27 -060022import android.annotation.SuppressAutoDoc;
Jeff Sharkeybfc4fcd2017-06-05 17:38:17 -060023import android.annotation.SuppressLint;
Santos Cordon6c7a3882014-06-25 15:30:08 -070024import android.annotation.SystemApi;
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -060025import android.annotation.SystemService;
Tyler Gunn6c14a6992019-02-04 15:12:06 -080026import android.annotation.TestApi;
Mathew Inwood42346d12018-08-01 11:33:05 +010027import android.annotation.UnsupportedAppUsage;
Santos Cordon6c7a3882014-06-25 15:30:08 -070028import android.content.ComponentName;
Yorke Leeb4ce1432014-06-09 13:53:23 -070029import android.content.Context;
Yorke Lee3e56ba12015-04-23 12:32:36 -070030import android.content.Intent;
Nancy Chenb2299c12014-10-29 18:22:11 -070031import android.net.Uri;
Sanket Padawef6a9e5b2018-01-05 14:26:16 -080032import android.os.Build;
Santos Cordon96efb482014-07-19 14:57:05 -070033import android.os.Bundle;
Santos Cordon6c7a3882014-06-25 15:30:08 -070034import android.os.RemoteException;
35import android.os.ServiceManager;
Tyler Gunn7e45b722018-12-04 12:56:45 -080036import android.os.UserHandle;
Chen Xuc9d4ee12019-09-26 16:11:59 -070037import android.telephony.Annotation.CallState;
Brad Ebingere7833312019-05-07 10:55:55 -070038import android.telephony.SubscriptionManager;
Yorke Lee2ae312e2014-09-12 17:58:48 -070039import android.telephony.TelephonyManager;
Anthony Lee67279262014-10-27 11:28:40 -070040import android.text.TextUtils;
Santos Cordon6c7a3882014-06-25 15:30:08 -070041import android.util.Log;
Yorke Leeb4ce1432014-06-09 13:53:23 -070042
Tyler Gunnef9f6f92014-09-12 22:16:17 -070043import com.android.internal.telecom.ITelecomService;
Yorke Leeb4ce1432014-06-09 13:53:23 -070044
Tyler Gunn6e3ecc42018-11-12 11:30:56 -080045import java.lang.annotation.Retention;
46import java.lang.annotation.RetentionPolicy;
Jay Shrauner7746a942014-08-26 12:15:15 -070047import java.util.ArrayList;
Tyler Gunna1ed7d12014-09-08 09:52:22 -070048import java.util.Collections;
Ihab Awad807fe0a2014-07-09 12:30:52 -070049import java.util.List;
Tyler Gunn7e45b722018-12-04 12:56:45 -080050import java.util.concurrent.Executor;
Ihab Awad807fe0a2014-07-09 12:30:52 -070051
Yorke Leeb4ce1432014-06-09 13:53:23 -070052/**
Santos Cordond9e614f2014-10-28 13:10:36 -070053 * Provides access to information about active calls and registration/call-management functionality.
Evan Charlton0e094d92014-11-08 15:49:16 -080054 * Apps can use methods in this class to determine the current call state.
Santos Cordond9e614f2014-10-28 13:10:36 -070055 * <p>
56 * Apps do not instantiate this class directly; instead, they retrieve a reference to an instance
57 * through {@link Context#getSystemService Context.getSystemService(Context.TELECOM_SERVICE)}.
58 * <p>
59 * Note that access to some telecom information is permission-protected. Your app cannot access the
60 * protected information or gain access to protected functionality unless it has the appropriate
61 * permissions declared in its manifest file. Where permissions apply, they are noted in the method
62 * descriptions.
Yorke Leeb4ce1432014-06-09 13:53:23 -070063 */
Jeff Sharkey910e0812017-04-21 16:29:27 -060064@SuppressAutoDoc
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -060065@SystemService(Context.TELECOM_SERVICE)
Tyler Gunnef9f6f92014-09-12 22:16:17 -070066public class TelecomManager {
Ihab Awad807fe0a2014-07-09 12:30:52 -070067
Evan Charlton10197192014-07-19 15:00:29 -070068 /**
Santos Cordon96efb482014-07-19 14:57:05 -070069 * Activity action: Starts the UI for handing an incoming call. This intent starts the in-call
Tyler Gunnef9f6f92014-09-12 22:16:17 -070070 * UI by notifying the Telecom system that an incoming call exists for a specific call service
71 * (see {@link android.telecom.ConnectionService}). Telecom reads the Intent extras to find
72 * and bind to the appropriate {@link android.telecom.ConnectionService} which Telecom will
Santos Cordon96efb482014-07-19 14:57:05 -070073 * ultimately use to control and get information about the call.
74 * <p>
75 * Input: get*Extra field {@link #EXTRA_PHONE_ACCOUNT_HANDLE} contains the component name of the
Tyler Gunnef9f6f92014-09-12 22:16:17 -070076 * {@link android.telecom.ConnectionService} that Telecom should bind to. Telecom will then
Evan Charlton10197192014-07-19 15:00:29 -070077 * ask the connection service for more information about the call prior to showing any UI.
Brad Ebinger23b1c6d2017-01-12 13:10:40 -080078 *
79 * @deprecated Use {@link #addNewIncomingCall} instead.
Evan Charlton10197192014-07-19 15:00:29 -070080 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -070081 public static final String ACTION_INCOMING_CALL = "android.telecom.action.INCOMING_CALL";
Evan Charlton10197192014-07-19 15:00:29 -070082
83 /**
Yorke Leec3cf9822014-10-02 09:38:39 -070084 * Similar to {@link #ACTION_INCOMING_CALL}, but is used only by Telephony to add a new
85 * sim-initiated MO call for carrier testing.
Brad Ebinger23b1c6d2017-01-12 13:10:40 -080086 * @deprecated Use {@link #addNewUnknownCall} instead.
Yorke Leec3cf9822014-10-02 09:38:39 -070087 * @hide
88 */
89 public static final String ACTION_NEW_UNKNOWN_CALL = "android.telecom.action.NEW_UNKNOWN_CALL";
90
91 /**
Santos Cordon895d4b82015-06-25 16:41:48 -070092 * An {@link android.content.Intent} action sent by the telecom framework to start a
93 * configuration dialog for a registered {@link PhoneAccount}. There is no default dialog
94 * and each app that registers a {@link PhoneAccount} should provide one if desired.
95 * <p>
96 * A user can access the list of enabled {@link android.telecom.PhoneAccount}s through the Phone
97 * app's settings menu. For each entry, the settings app will add a click action. When
98 * triggered, the click-action will start this intent along with the extra
99 * {@link #EXTRA_PHONE_ACCOUNT_HANDLE} to indicate the {@link PhoneAccount} to configure. If the
100 * {@link PhoneAccount} package does not register an {@link android.app.Activity} for this
101 * intent, then it will not be sent.
Evan Charlton10197192014-07-19 15:00:29 -0700102 */
Santos Cordon895d4b82015-06-25 16:41:48 -0700103 public static final String ACTION_CONFIGURE_PHONE_ACCOUNT =
104 "android.telecom.action.CONFIGURE_PHONE_ACCOUNT";
Evan Charlton10197192014-07-19 15:00:29 -0700105
106 /**
Andrew Lee873cfbf2015-02-26 15:22:00 -0800107 * The {@link android.content.Intent} action used to show the call accessibility settings page.
108 */
109 public static final String ACTION_SHOW_CALL_ACCESSIBILITY_SETTINGS =
110 "android.telecom.action.SHOW_CALL_ACCESSIBILITY_SETTINGS";
111
112 /**
Yorke Lee3818a8922014-07-21 15:57:17 -0700113 * The {@link android.content.Intent} action used to show the call settings page.
114 */
115 public static final String ACTION_SHOW_CALL_SETTINGS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700116 "android.telecom.action.SHOW_CALL_SETTINGS";
Yorke Lee3818a8922014-07-21 15:57:17 -0700117
118 /**
Andrew Lee866080f2015-02-19 12:05:33 -0800119 * The {@link android.content.Intent} action used to show the respond via SMS settings page.
120 */
121 public static final String ACTION_SHOW_RESPOND_VIA_SMS_SETTINGS =
122 "android.telecom.action.SHOW_RESPOND_VIA_SMS_SETTINGS";
123
124 /**
Evan Charlton6d8604f2014-09-04 12:38:17 -0700125 * The {@link android.content.Intent} action used to show the settings page used to configure
126 * {@link PhoneAccount} preferences.
127 */
128 public static final String ACTION_CHANGE_PHONE_ACCOUNTS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700129 "android.telecom.action.CHANGE_PHONE_ACCOUNTS";
Evan Charlton6d8604f2014-09-04 12:38:17 -0700130
131 /**
Tyler Gunnd9da6ce2017-04-14 13:43:30 -0700132 * {@link android.content.Intent} action used indicate that a new phone account was just
133 * registered.
134 * <p>
135 * The Intent {@link Intent#getExtras() extras} will contain {@link #EXTRA_PHONE_ACCOUNT_HANDLE}
136 * to indicate which {@link PhoneAccount} was registered.
137 * <p>
138 * Will only be sent to the default dialer app (see {@link #getDefaultDialerPackage()}).
Santos Cordonc66f3ba2015-02-27 15:22:07 -0800139 */
Santos Cordonc66f3ba2015-02-27 15:22:07 -0800140 public static final String ACTION_PHONE_ACCOUNT_REGISTERED =
141 "android.telecom.action.PHONE_ACCOUNT_REGISTERED";
142
143 /**
Tyler Gunnd9da6ce2017-04-14 13:43:30 -0700144 * {@link android.content.Intent} action used indicate that a phone account was just
145 * unregistered.
146 * <p>
147 * The Intent {@link Intent#getExtras() extras} will contain {@link #EXTRA_PHONE_ACCOUNT_HANDLE}
148 * to indicate which {@link PhoneAccount} was unregistered.
149 * <p>
150 * Will only be sent to the default dialer app (see {@link #getDefaultDialerPackage()}).
Bryce Lee30b0aa02015-09-23 21:53:53 -0700151 */
Bryce Lee30b0aa02015-09-23 21:53:53 -0700152 public static final String ACTION_PHONE_ACCOUNT_UNREGISTERED =
153 "android.telecom.action.PHONE_ACCOUNT_UNREGISTERED";
154
155 /**
Yorke Lee1011f482015-04-23 15:58:27 -0700156 * Activity action: Shows a dialog asking the user whether or not they want to replace the
157 * current default Dialer with the one specified in
158 * {@link #EXTRA_CHANGE_DEFAULT_DIALER_PACKAGE_NAME}.
159 *
160 * Usage example:
161 * <pre>
162 * Intent intent = new Intent(TelecomManager.ACTION_CHANGE_DEFAULT_DIALER);
163 * intent.putExtra(TelecomManager.EXTRA_CHANGE_DEFAULT_DIALER_PACKAGE_NAME,
164 * getActivity().getPackageName());
165 * startActivity(intent);
166 * </pre>
Hai Zhang929085f2019-05-03 15:31:43 +0800167 * <p>
168 * This is no longer supported since Q, please use
169 * {@link android.app.role.RoleManager#createRequestRoleIntent(String)} with
170 * {@link android.app.role.RoleManager#ROLE_DIALER} instead.
Yorke Lee1011f482015-04-23 15:58:27 -0700171 */
172 public static final String ACTION_CHANGE_DEFAULT_DIALER =
173 "android.telecom.action.CHANGE_DEFAULT_DIALER";
174
175 /**
Yorke Lee107c4ce2015-06-15 12:08:24 -0700176 * Broadcast intent action indicating that the current default dialer has changed.
177 * The string extra {@link #EXTRA_CHANGE_DEFAULT_DIALER_PACKAGE_NAME} will contain the
178 * name of the package that the default dialer was changed to.
179 *
180 * @see #EXTRA_CHANGE_DEFAULT_DIALER_PACKAGE_NAME
181 */
182 public static final String ACTION_DEFAULT_DIALER_CHANGED =
183 "android.telecom.action.DEFAULT_DIALER_CHANGED";
184
185 /**
Yorke Lee1011f482015-04-23 15:58:27 -0700186 * Extra value used to provide the package name for {@link #ACTION_CHANGE_DEFAULT_DIALER}.
187 */
188 public static final String EXTRA_CHANGE_DEFAULT_DIALER_PACKAGE_NAME =
189 "android.telecom.extra.CHANGE_DEFAULT_DIALER_PACKAGE_NAME";
190
191 /**
tonyzhuff60f5e2018-10-01 19:14:59 +0800192 * Broadcast intent action indicating that the current default call screening app has changed.
193 *
194 * The string extra {@link #EXTRA_DEFAULT_CALL_SCREENING_APP_COMPONENT_NAME} will contain the
195 * name of the Component of the previous or the new call screening app.
196 *
197 * The boolean extra {@link #EXTRA_IS_DEFAULT_CALL_SCREENING_APP} will indicate the component
198 * name in the String extra {@link #EXTRA_DEFAULT_CALL_SCREENING_APP_COMPONENT_NAME} is default
199 * call screening app or not.
200 */
201 public static final String ACTION_DEFAULT_CALL_SCREENING_APP_CHANGED =
202 "android.telecom.action.DEFAULT_CALL_SCREENING_APP_CHANGED";
203
204 /**
205 * Extra value used with {@link #ACTION_DEFAULT_CALL_SCREENING_APP_CHANGED} broadcast to
206 * indicate the ComponentName of the call screening app which has changed.
207 */
208 public static final String EXTRA_DEFAULT_CALL_SCREENING_APP_COMPONENT_NAME =
209 "android.telecom.extra.DEFAULT_CALL_SCREENING_APP_COMPONENT_NAME";
210
211 /**
212 * Extra value used with {@link #ACTION_DEFAULT_CALL_SCREENING_APP_CHANGED} broadcast to
213 * indicate whether an app is the default call screening app.
214 */
215 public static final String EXTRA_IS_DEFAULT_CALL_SCREENING_APP =
216 "android.telecom.extra.IS_DEFAULT_CALL_SCREENING_APP";
217
218 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700219 * Optional extra for {@link android.content.Intent#ACTION_CALL} containing a boolean that
220 * determines whether the speakerphone should be automatically turned on for an outgoing call.
Evan Charlton10197192014-07-19 15:00:29 -0700221 */
222 public static final String EXTRA_START_CALL_WITH_SPEAKERPHONE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700223 "android.telecom.extra.START_CALL_WITH_SPEAKERPHONE";
Evan Charlton10197192014-07-19 15:00:29 -0700224
225 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700226 * Optional extra for {@link android.content.Intent#ACTION_CALL} containing an integer that
227 * determines the desired video state for an outgoing call.
Santos Cordon96efb482014-07-19 14:57:05 -0700228 * Valid options:
Yorke Lee32f24732015-05-12 16:18:03 -0700229 * {@link VideoProfile#STATE_AUDIO_ONLY},
230 * {@link VideoProfile#STATE_BIDIRECTIONAL},
231 * {@link VideoProfile#STATE_RX_ENABLED},
232 * {@link VideoProfile#STATE_TX_ENABLED}.
Evan Charlton10197192014-07-19 15:00:29 -0700233 */
234 public static final String EXTRA_START_CALL_WITH_VIDEO_STATE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700235 "android.telecom.extra.START_CALL_WITH_VIDEO_STATE";
Evan Charlton10197192014-07-19 15:00:29 -0700236
237 /**
Tyler Gunn37653562017-03-13 18:15:15 -0700238 * Optional extra for {@link #addNewIncomingCall(PhoneAccountHandle, Bundle)} containing an
239 * integer that determines the requested video state for an incoming call.
240 * Valid options:
241 * {@link VideoProfile#STATE_AUDIO_ONLY},
242 * {@link VideoProfile#STATE_BIDIRECTIONAL},
243 * {@link VideoProfile#STATE_RX_ENABLED},
244 * {@link VideoProfile#STATE_TX_ENABLED}.
245 */
246 public static final String EXTRA_INCOMING_VIDEO_STATE =
247 "android.telecom.extra.INCOMING_VIDEO_STATE";
248
249 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700250 * The extra used with an {@link android.content.Intent#ACTION_CALL} and
251 * {@link android.content.Intent#ACTION_DIAL} {@code Intent} to specify a
252 * {@link PhoneAccountHandle} to use when making the call.
Evan Charlton10197192014-07-19 15:00:29 -0700253 * <p class="note">
Santos Cordon96efb482014-07-19 14:57:05 -0700254 * Retrieve with {@link android.content.Intent#getParcelableExtra(String)}.
Evan Charlton10197192014-07-19 15:00:29 -0700255 */
Evan Charlton6eb262c2014-07-19 18:18:19 -0700256 public static final String EXTRA_PHONE_ACCOUNT_HANDLE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700257 "android.telecom.extra.PHONE_ACCOUNT_HANDLE";
Evan Charlton10197192014-07-19 15:00:29 -0700258
259 /**
Tyler Gunn335ff2e2015-07-30 14:18:33 -0700260 * Optional extra for {@link android.content.Intent#ACTION_CALL} containing a string call
261 * subject which will be associated with an outgoing call. Should only be specified if the
262 * {@link PhoneAccount} supports the capability {@link PhoneAccount#CAPABILITY_CALL_SUBJECT}.
263 */
264 public static final String EXTRA_CALL_SUBJECT = "android.telecom.extra.CALL_SUBJECT";
265
266 /**
Yorke Lee04ea7d32015-06-05 15:59:18 -0700267 * The extra used by a {@link ConnectionService} to provide the handle of the caller that
268 * has initiated a new incoming call.
269 */
Yorke Lee02fb5bc2015-06-09 12:27:36 -0700270 public static final String EXTRA_INCOMING_CALL_ADDRESS =
271 "android.telecom.extra.INCOMING_CALL_ADDRESS";
Yorke Lee04ea7d32015-06-05 15:59:18 -0700272
273 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700274 * Optional extra for {@link #ACTION_INCOMING_CALL} containing a {@link Bundle} which contains
275 * metadata about the call. This {@link Bundle} will be returned to the
276 * {@link ConnectionService}.
Evan Charlton10197192014-07-19 15:00:29 -0700277 */
278 public static final String EXTRA_INCOMING_CALL_EXTRAS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700279 "android.telecom.extra.INCOMING_CALL_EXTRAS";
Evan Charlton10197192014-07-19 15:00:29 -0700280
281 /**
Joseph Pirozzo40ea5ee2018-01-02 16:15:23 -0800282 * Optional extra for {@link #ACTION_INCOMING_CALL} containing a boolean to indicate that the
283 * call has an externally generated ringer. Used by the HfpClientConnectionService when In Band
284 * Ringtone is enabled to prevent two ringers from being generated.
285 * @hide
286 */
287 public static final String EXTRA_CALL_EXTERNAL_RINGER =
288 "android.telecom.extra.CALL_EXTERNAL_RINGER";
289
290 /**
Nancy Chen10798dc2014-08-08 14:00:25 -0700291 * Optional extra for {@link android.content.Intent#ACTION_CALL} and
292 * {@link android.content.Intent#ACTION_DIAL} {@code Intent} containing a {@link Bundle}
293 * which contains metadata about the call. This {@link Bundle} will be saved into
Santos Cordon7a060d52015-06-19 14:52:04 -0700294 * {@code Call.Details} and passed to the {@link ConnectionService} when placing the call.
Nancy Chen10798dc2014-08-08 14:00:25 -0700295 */
296 public static final String EXTRA_OUTGOING_CALL_EXTRAS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700297 "android.telecom.extra.OUTGOING_CALL_EXTRAS";
Nancy Chen10798dc2014-08-08 14:00:25 -0700298
299 /**
sqian6d9e7452019-02-08 21:42:15 -0800300 * An optional boolean extra on {@link android.content.Intent#ACTION_CALL_EMERGENCY} to tell
301 * whether the user's dial intent is emergency; this is required to specify when the dialed
302 * number is ambiguous, identified as both emergency number and any other non-emergency number;
303 * e.g. in some situation, 611 could be both an emergency number in a country and a
304 * non-emergency number of a carrier's customer service hotline.
305 *
306 * @hide
307 */
308 @SystemApi
309 public static final String EXTRA_IS_USER_INTENT_EMERGENCY_CALL =
310 "android.telecom.extra.IS_USER_INTENT_EMERGENCY_CALL";
311
312 /**
Yorke Leec3cf9822014-10-02 09:38:39 -0700313 * @hide
314 */
315 public static final String EXTRA_UNKNOWN_CALL_HANDLE =
316 "android.telecom.extra.UNKNOWN_CALL_HANDLE";
317
318 /**
Sailesh Nepalda6bb382016-04-14 19:51:46 -0700319 * Optional extra for incoming and outgoing calls containing a long which specifies the time the
320 * call was created. This value is in milliseconds since boot.
321 * @hide
322 */
323 public static final String EXTRA_CALL_CREATED_TIME_MILLIS =
324 "android.telecom.extra.CALL_CREATED_TIME_MILLIS";
325
326 /**
327 * Optional extra for incoming and outgoing calls containing a long which specifies the time
328 * telecom began routing the call. This value is in milliseconds since boot.
329 * @hide
330 */
331 public static final String EXTRA_CALL_TELECOM_ROUTING_START_TIME_MILLIS =
332 "android.telecom.extra.CALL_TELECOM_ROUTING_START_TIME_MILLIS";
333
334 /**
335 * Optional extra for incoming and outgoing calls containing a long which specifies the time
336 * telecom finished routing the call. This value is in milliseconds since boot.
337 * @hide
338 */
339 public static final String EXTRA_CALL_TELECOM_ROUTING_END_TIME_MILLIS =
340 "android.telecom.extra.CALL_TELECOM_ROUTING_END_TIME_MILLIS";
341
342 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700343 * Optional extra for {@link android.telephony.TelephonyManager#ACTION_PHONE_STATE_CHANGED}
344 * containing the disconnect code.
Evan Charlton10197192014-07-19 15:00:29 -0700345 */
346 public static final String EXTRA_CALL_DISCONNECT_CAUSE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700347 "android.telecom.extra.CALL_DISCONNECT_CAUSE";
Evan Charlton10197192014-07-19 15:00:29 -0700348
349 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700350 * Optional extra for {@link android.telephony.TelephonyManager#ACTION_PHONE_STATE_CHANGED}
351 * containing the disconnect message.
Evan Charlton10197192014-07-19 15:00:29 -0700352 */
353 public static final String EXTRA_CALL_DISCONNECT_MESSAGE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700354 "android.telecom.extra.CALL_DISCONNECT_MESSAGE";
Evan Charlton10197192014-07-19 15:00:29 -0700355
356 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700357 * Optional extra for {@link android.telephony.TelephonyManager#ACTION_PHONE_STATE_CHANGED}
358 * containing the component name of the associated connection service.
Evan Charlton0e094d92014-11-08 15:49:16 -0800359 * @hide
Evan Charlton10197192014-07-19 15:00:29 -0700360 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800361 @SystemApi
Evan Charlton10197192014-07-19 15:00:29 -0700362 public static final String EXTRA_CONNECTION_SERVICE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700363 "android.telecom.extra.CONNECTION_SERVICE";
Evan Charlton10197192014-07-19 15:00:29 -0700364
365 /**
Hall Liu90f62902015-11-19 16:19:24 -0800366 * Optional extra for communicating the call technology used by a
367 * {@link com.android.internal.telephony.Connection} to Telecom
368 * @hide
369 */
370 public static final String EXTRA_CALL_TECHNOLOGY_TYPE =
371 "android.telecom.extra.CALL_TECHNOLOGY_TYPE";
372
373 /**
Wei Huang7f7f72e2018-05-30 19:21:36 +0800374 * Optional extra for communicating the call network technology used by a
375 * {@link android.telecom.Connection} to Telecom and InCallUI.
376 *
377 * @see {@code NETWORK_TYPE_*} in {@link android.telephony.TelephonyManager}.
378 */
379 public static final String EXTRA_CALL_NETWORK_TYPE =
380 "android.telecom.extra.CALL_NETWORK_TYPE";
381
382 /**
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700383 * An optional {@link android.content.Intent#ACTION_CALL} intent extra denoting the
384 * package name of the app specifying an alternative gateway for the call.
385 * The value is a string.
386 *
387 * (The following comment corresponds to the all GATEWAY_* extras)
388 * An app which sends the {@link android.content.Intent#ACTION_CALL} intent can specify an
389 * alternative address to dial which is different from the one specified and displayed to
390 * the user. This alternative address is referred to as the gateway address.
391 */
392 public static final String GATEWAY_PROVIDER_PACKAGE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700393 "android.telecom.extra.GATEWAY_PROVIDER_PACKAGE";
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700394
395 /**
396 * An optional {@link android.content.Intent#ACTION_CALL} intent extra corresponding to the
397 * original address to dial for the call. This is used when an alternative gateway address is
398 * provided to recall the original address.
399 * The value is a {@link android.net.Uri}.
400 *
401 * (See {@link #GATEWAY_PROVIDER_PACKAGE} for details)
402 */
403 public static final String GATEWAY_ORIGINAL_ADDRESS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700404 "android.telecom.extra.GATEWAY_ORIGINAL_ADDRESS";
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700405
406 /**
Evan Charlton10197192014-07-19 15:00:29 -0700407 * The number which the party on the other side of the line will see (and use to return the
408 * call).
409 * <p>
Santos Cordon96efb482014-07-19 14:57:05 -0700410 * {@link ConnectionService}s which interact with {@link RemoteConnection}s should only populate
411 * this if the {@link android.telephony.TelephonyManager#getLine1Number()} value, as that is the
412 * user's expected caller ID.
Evan Charlton10197192014-07-19 15:00:29 -0700413 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700414 public static final String EXTRA_CALL_BACK_NUMBER = "android.telecom.extra.CALL_BACK_NUMBER";
Evan Charlton10197192014-07-19 15:00:29 -0700415
416 /**
Hall Liu8f613fb2017-02-14 18:11:11 -0800417 * The number of milliseconds that Telecom should wait after disconnecting a call via the
418 * ACTION_NEW_OUTGOING_CALL broadcast, in order to wait for the app which cancelled the call
419 * to make a new one.
420 * @hide
421 */
422 public static final String EXTRA_NEW_OUTGOING_CALL_CANCEL_TIMEOUT =
423 "android.telecom.extra.NEW_OUTGOING_CALL_CANCEL_TIMEOUT";
424
425 /**
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700426 * Boolean extra specified to indicate that the intention of adding a call is to handover an
Tyler Gunn8bf76572017-04-06 15:30:08 -0700427 * existing call from the user's device to a different {@link PhoneAccount}.
428 * <p>
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700429 * Used when calling {@link #addNewIncomingCall(PhoneAccountHandle, Bundle)}
430 * to indicate to Telecom that the purpose of adding a new incoming call is to handover an
431 * existing call from the user's device to a different {@link PhoneAccount}. This occurs on
432 * the receiving side of a handover.
433 * <p>
434 * Used when Telecom calls
435 * {@link ConnectionService#onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}
436 * to indicate that the purpose of Telecom requesting a new outgoing connection it to request
437 * a handover to this {@link ConnectionService} from an ongoing call on the user's device. This
438 * occurs on the initiating side of a handover.
439 * <p>
Tyler Gunn727c6bd2017-04-11 09:51:40 -0700440 * The phone number of the call used by Telecom to determine which call should be handed over.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700441 * @hide
Tyler Gunn6e3ecc42018-11-12 11:30:56 -0800442 * @deprecated Use the public handover APIs. See
443 * {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} for more information.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700444 */
Tyler Gunn6e3ecc42018-11-12 11:30:56 -0800445 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 119305590)
Tyler Gunn8bf76572017-04-06 15:30:08 -0700446 public static final String EXTRA_IS_HANDOVER = "android.telecom.extra.IS_HANDOVER";
447
448 /**
Tyler Gunn79bc1ec2018-01-22 15:17:54 -0800449 * When {@code true} indicates that a request to create a new connection is for the purpose of
450 * a handover. Note: This is used with the
451 * {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int, Bundle)} API as part of the
452 * internal communication mechanism with the {@link android.telecom.ConnectionService}. It is
453 * not the same as the legacy {@link #EXTRA_IS_HANDOVER} extra.
454 * @hide
455 */
456 public static final String EXTRA_IS_HANDOVER_CONNECTION =
457 "android.telecom.extra.IS_HANDOVER_CONNECTION";
458
459 /**
Tyler Gunn3af38692017-05-26 13:30:09 -0700460 * Parcelable extra used with {@link #EXTRA_IS_HANDOVER} to indicate the source
461 * {@link PhoneAccountHandle} when initiating a handover which {@link ConnectionService}
462 * the handover is from.
463 * @hide
464 */
465 public static final String EXTRA_HANDOVER_FROM_PHONE_ACCOUNT =
466 "android.telecom.extra.HANDOVER_FROM_PHONE_ACCOUNT";
467
468 /**
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700469 * Extra key specified in the {@link ConnectionRequest#getExtras()} when Telecom calls
470 * {@link ConnectionService#onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}
471 * to inform the {@link ConnectionService} what the initial {@link CallAudioState} of the
472 * {@link Connection} will be.
473 * @hide
474 */
475 public static final String EXTRA_CALL_AUDIO_STATE = "android.telecom.extra.CALL_AUDIO_STATE";
476
477 /**
Hall Liu95d55872017-01-25 17:12:49 -0800478 * A boolean extra, which when set on the {@link Intent#ACTION_CALL} intent or on the bundle
479 * passed into {@link #placeCall(Uri, Bundle)}, indicates that the call should be initiated with
480 * an RTT session open. See {@link android.telecom.Call.RttCall} for more information on RTT.
481 */
482 public static final String EXTRA_START_CALL_WITH_RTT =
483 "android.telecom.extra.START_CALL_WITH_RTT";
484
485 /**
Santos Cordonf2600eb2015-06-22 15:02:20 -0700486 * A boolean meta-data value indicating whether an {@link InCallService} implements an
487 * in-call user interface. Dialer implementations (see {@link #getDefaultDialerPackage()}) which
488 * would also like to replace the in-call interface should set this meta-data to {@code true} in
489 * the manifest registration of their {@link InCallService}.
490 */
491 public static final String METADATA_IN_CALL_SERVICE_UI = "android.telecom.IN_CALL_SERVICE_UI";
492
493 /**
Santos Cordon88881552015-12-10 17:29:54 -0800494 * A boolean meta-data value indicating whether an {@link InCallService} implements an
495 * in-call user interface to be used while the device is in car-mode (see
Hector Dearman923382c2018-12-13 16:42:33 +0000496 * {@link android.content.res.Configuration#UI_MODE_TYPE_CAR}).
Santos Cordon88881552015-12-10 17:29:54 -0800497 */
498 public static final String METADATA_IN_CALL_SERVICE_CAR_MODE_UI =
499 "android.telecom.IN_CALL_SERVICE_CAR_MODE_UI";
500
501 /**
Sailesh Nepal9c2618b2016-01-23 16:28:22 -0800502 * A boolean meta-data value indicating whether an {@link InCallService} implements ringing.
503 * Dialer implementations (see {@link #getDefaultDialerPackage()}) which would also like to
504 * override the system provided ringing should set this meta-data to {@code true} in the
505 * manifest registration of their {@link InCallService}.
Tyler Gunn556d2402019-04-10 08:59:43 -0700506 * <p>
507 * When {@code true}, it is the {@link InCallService}'s responsibility to play a ringtone for
508 * all incoming calls.
Sailesh Nepal9c2618b2016-01-23 16:28:22 -0800509 */
510 public static final String METADATA_IN_CALL_SERVICE_RINGING =
511 "android.telecom.IN_CALL_SERVICE_RINGING";
512
513 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700514 * A boolean meta-data value indicating whether an {@link InCallService} wants to be informed of
515 * calls which have the {@link Call.Details#PROPERTY_IS_EXTERNAL_CALL} property. An external
516 * call is one which a {@link ConnectionService} knows about, but is not connected to directly.
517 * Dialer implementations (see {@link #getDefaultDialerPackage()}) which would like to be
518 * informed of external calls should set this meta-data to {@code true} in the manifest
519 * registration of their {@link InCallService}. By default, the {@link InCallService} will NOT
520 * be informed of external calls.
521 */
522 public static final String METADATA_INCLUDE_EXTERNAL_CALLS =
523 "android.telecom.INCLUDE_EXTERNAL_CALLS";
524
525 /**
Tyler Gunn24e18332017-02-10 09:42:49 -0800526 * A boolean meta-data value indicating whether an {@link InCallService} wants to be informed of
527 * calls which have the {@link Call.Details#PROPERTY_SELF_MANAGED} property. A self-managed
528 * call is one which originates from a self-managed {@link ConnectionService} which has chosen
529 * to implement its own call user interface. An {@link InCallService} implementation which
530 * would like to be informed of external calls should set this meta-data to {@code true} in the
531 * manifest registration of their {@link InCallService}. By default, the {@link InCallService}
532 * will NOT be informed about self-managed calls.
533 * <p>
534 * An {@link InCallService} which receives self-managed calls is free to view and control the
535 * state of calls in the self-managed {@link ConnectionService}. An example use-case is
Tyler Gunn37653562017-03-13 18:15:15 -0700536 * exposing these calls to an automotive device via its companion app.
537 * <p>
538 * This meta-data can only be set for an {@link InCallService} which also sets
539 * {@link #METADATA_IN_CALL_SERVICE_UI}. Only the default phone/dialer app, or a car-mode
540 * {@link InCallService} can see self-managed calls.
Tyler Gunn24e18332017-02-10 09:42:49 -0800541 * <p>
542 * See also {@link Connection#PROPERTY_SELF_MANAGED}.
543 */
544 public static final String METADATA_INCLUDE_SELF_MANAGED_CALLS =
545 "android.telecom.INCLUDE_SELF_MANAGED_CALLS";
546
547 /**
Evan Charlton10197192014-07-19 15:00:29 -0700548 * The dual tone multi-frequency signaling character sent to indicate the dialing system should
549 * pause for a predefined period.
550 */
551 public static final char DTMF_CHARACTER_PAUSE = ',';
552
553 /**
554 * The dual-tone multi-frequency signaling character sent to indicate the dialing system should
555 * wait for user confirmation before proceeding.
556 */
557 public static final char DTMF_CHARACTER_WAIT = ';';
558
559 /**
Tyler Gunn6e3ecc42018-11-12 11:30:56 -0800560 * @hide
561 */
562 @IntDef(prefix = { "TTY_MODE_" },
563 value = {TTY_MODE_OFF, TTY_MODE_FULL, TTY_MODE_HCO, TTY_MODE_VCO})
564 @Retention(RetentionPolicy.SOURCE)
565 public @interface TtyMode {}
566
567 /**
Evan Charlton10197192014-07-19 15:00:29 -0700568 * TTY (teletypewriter) mode is off.
569 *
570 * @hide
571 */
Tyler Gunn6c14a6992019-02-04 15:12:06 -0800572 @TestApi
Tyler Gunn6e3ecc42018-11-12 11:30:56 -0800573 @SystemApi
Evan Charlton10197192014-07-19 15:00:29 -0700574 public static final int TTY_MODE_OFF = 0;
575
576 /**
577 * TTY (teletypewriter) mode is on. The speaker is off and the microphone is muted. The user
578 * will communicate with the remote party by sending and receiving text messages.
579 *
580 * @hide
581 */
Tyler Gunn6c14a6992019-02-04 15:12:06 -0800582 @TestApi
Tyler Gunn6e3ecc42018-11-12 11:30:56 -0800583 @SystemApi
Evan Charlton10197192014-07-19 15:00:29 -0700584 public static final int TTY_MODE_FULL = 1;
585
586 /**
587 * TTY (teletypewriter) mode is in hearing carryover mode (HCO). The microphone is muted but the
588 * speaker is on. The user will communicate with the remote party by sending text messages and
589 * hearing an audible reply.
590 *
591 * @hide
592 */
Tyler Gunn6c14a6992019-02-04 15:12:06 -0800593 @TestApi
Tyler Gunn6e3ecc42018-11-12 11:30:56 -0800594 @SystemApi
Evan Charlton10197192014-07-19 15:00:29 -0700595 public static final int TTY_MODE_HCO = 2;
596
597 /**
598 * TTY (teletypewriter) mode is in voice carryover mode (VCO). The speaker is off but the
599 * microphone is still on. User will communicate with the remote party by speaking and receiving
600 * text message replies.
601 *
602 * @hide
603 */
Tyler Gunn6c14a6992019-02-04 15:12:06 -0800604 @TestApi
Tyler Gunn6e3ecc42018-11-12 11:30:56 -0800605 @SystemApi
Evan Charlton10197192014-07-19 15:00:29 -0700606 public static final int TTY_MODE_VCO = 3;
607
608 /**
609 * Broadcast intent action indicating that the current TTY mode has changed. An intent extra
610 * provides this state as an int.
Evan Charlton10197192014-07-19 15:00:29 -0700611 *
Santos Cordon96efb482014-07-19 14:57:05 -0700612 * @see #EXTRA_CURRENT_TTY_MODE
Evan Charlton10197192014-07-19 15:00:29 -0700613 * @hide
614 */
615 public static final String ACTION_CURRENT_TTY_MODE_CHANGED =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700616 "android.telecom.action.CURRENT_TTY_MODE_CHANGED";
Evan Charlton10197192014-07-19 15:00:29 -0700617
618 /**
619 * The lookup key for an int that indicates the current TTY mode.
620 * Valid modes are:
621 * - {@link #TTY_MODE_OFF}
622 * - {@link #TTY_MODE_FULL}
623 * - {@link #TTY_MODE_HCO}
624 * - {@link #TTY_MODE_VCO}
625 *
626 * @hide
627 */
628 public static final String EXTRA_CURRENT_TTY_MODE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700629 "android.telecom.intent.extra.CURRENT_TTY_MODE";
Evan Charlton10197192014-07-19 15:00:29 -0700630
631 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700632 * Broadcast intent action indicating that the TTY preferred operating mode has changed. An
633 * intent extra provides the new mode as an int.
Evan Charlton10197192014-07-19 15:00:29 -0700634 *
Santos Cordon96efb482014-07-19 14:57:05 -0700635 * @see #EXTRA_TTY_PREFERRED_MODE
Evan Charlton10197192014-07-19 15:00:29 -0700636 * @hide
637 */
638 public static final String ACTION_TTY_PREFERRED_MODE_CHANGED =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700639 "android.telecom.action.TTY_PREFERRED_MODE_CHANGED";
Evan Charlton10197192014-07-19 15:00:29 -0700640
641 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700642 * The lookup key for an int that indicates preferred TTY mode. Valid modes are: -
643 * {@link #TTY_MODE_OFF} - {@link #TTY_MODE_FULL} - {@link #TTY_MODE_HCO} -
644 * {@link #TTY_MODE_VCO}
Evan Charlton10197192014-07-19 15:00:29 -0700645 *
646 * @hide
647 */
648 public static final String EXTRA_TTY_PREFERRED_MODE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700649 "android.telecom.intent.extra.TTY_PREFERRED";
Evan Charlton10197192014-07-19 15:00:29 -0700650
Nancy Chen9d568c02014-09-08 14:17:59 -0700651 /**
Bryce Lee5e4dd3e2015-08-03 16:59:10 -0700652 * Broadcast intent action for letting custom component know to show the missed call
Sailesh Nepalbe15ad92016-01-21 19:26:20 -0800653 * notification. If no custom component exists then this is sent to the default dialer which
654 * should post a missed-call notification.
Bryce Lee5e4dd3e2015-08-03 16:59:10 -0700655 */
Bryce Lee5e4dd3e2015-08-03 16:59:10 -0700656 public static final String ACTION_SHOW_MISSED_CALLS_NOTIFICATION =
657 "android.telecom.action.SHOW_MISSED_CALLS_NOTIFICATION";
658
659 /**
Sailesh Nepalbe15ad92016-01-21 19:26:20 -0800660 * The number of calls associated with the notification. If the number is zero then the missed
661 * call notification should be dismissed.
Bryce Lee5e4dd3e2015-08-03 16:59:10 -0700662 */
Bryce Lee5e4dd3e2015-08-03 16:59:10 -0700663 public static final String EXTRA_NOTIFICATION_COUNT =
664 "android.telecom.extra.NOTIFICATION_COUNT";
665
666 /**
667 * The number associated with the missed calls. This number is only relevant
668 * when EXTRA_NOTIFICATION_COUNT is 1.
Bryce Lee5e4dd3e2015-08-03 16:59:10 -0700669 */
Bryce Lee5e4dd3e2015-08-03 16:59:10 -0700670 public static final String EXTRA_NOTIFICATION_PHONE_NUMBER =
671 "android.telecom.extra.NOTIFICATION_PHONE_NUMBER";
672
673 /**
Bryce Lee8d41d1d2015-08-10 07:40:42 -0700674 * The intent to clear missed calls.
675 * @hide
676 */
677 @SystemApi
678 public static final String EXTRA_CLEAR_MISSED_CALLS_INTENT =
679 "android.telecom.extra.CLEAR_MISSED_CALLS_INTENT";
680
681 /**
682 * The intent to call back a missed call.
683 * @hide
684 */
685 @SystemApi
686 public static final String EXTRA_CALL_BACK_INTENT =
687 "android.telecom.extra.CALL_BACK_INTENT";
688
689 /**
Charles He858f1322017-11-27 17:11:04 -0800690 * The dialer activity responsible for placing emergency calls from, for example, a locked
691 * keyguard.
692 * @hide
693 */
694 public static final ComponentName EMERGENCY_DIALER_COMPONENT =
695 ComponentName.createRelative("com.android.phone", ".EmergencyDialer");
696
697 /**
Eric Erfanian62706c52017-12-06 16:27:53 -0800698 * The boolean indicated by this extra controls whether or not a call is eligible to undergo
699 * assisted dialing. This extra is stored under {@link #EXTRA_OUTGOING_CALL_EXTRAS}.
Eric Erfaniandd2db2f2018-02-21 19:27:53 +0000700 * @hide
Eric Erfanian62706c52017-12-06 16:27:53 -0800701 */
702 public static final String EXTRA_USE_ASSISTED_DIALING =
703 "android.telecom.extra.USE_ASSISTED_DIALING";
704
705 /**
Shaotang Li8cec25c2018-07-19 17:29:39 +0800706 * Optional extra for {@link #placeCall(Uri, Bundle)} containing an integer that specifies
707 * the source where user initiated this call. This data is used in metrics.
708 * Valid source are:
709 * {@link ParcelableCallAnalytics#CALL_SOURCE_UNSPECIFIED},
710 * {@link ParcelableCallAnalytics#CALL_SOURCE_EMERGENCY_DIALPAD},
711 * {@link ParcelableCallAnalytics#CALL_SOURCE_EMERGENCY_SHORTCUT}.
712 *
713 * @hide
714 */
715 public static final String EXTRA_CALL_SOURCE = "android.telecom.extra.CALL_SOURCE";
716
717 /**
Nancy Chen9d568c02014-09-08 14:17:59 -0700718 * The following 4 constants define how properties such as phone numbers and names are
719 * displayed to the user.
720 */
721
Santos Cordoned769ae2015-05-13 18:47:38 -0700722 /**
723 * Indicates that the address or number of a call is allowed to be displayed for caller ID.
Charles He858f1322017-11-27 17:11:04 -0800724 */
Nancy Chen9d568c02014-09-08 14:17:59 -0700725 public static final int PRESENTATION_ALLOWED = 1;
726
Santos Cordoned769ae2015-05-13 18:47:38 -0700727 /**
728 * Indicates that the address or number of a call is blocked by the other party.
729 */
Nancy Chen9d568c02014-09-08 14:17:59 -0700730 public static final int PRESENTATION_RESTRICTED = 2;
731
Santos Cordoned769ae2015-05-13 18:47:38 -0700732 /**
733 * Indicates that the address or number of a call is not specified or known by the carrier.
734 */
Nancy Chen9d568c02014-09-08 14:17:59 -0700735 public static final int PRESENTATION_UNKNOWN = 3;
736
Santos Cordoned769ae2015-05-13 18:47:38 -0700737 /**
738 * Indicates that the address or number of a call belongs to a pay phone.
739 */
Nancy Chen9d568c02014-09-08 14:17:59 -0700740 public static final int PRESENTATION_PAYPHONE = 4;
741
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700742 private static final String TAG = "TelecomManager";
Yorke Leeb4ce1432014-06-09 13:53:23 -0700743
744 private final Context mContext;
Yorke Leeb4ce1432014-06-09 13:53:23 -0700745
Hall Liue1bc2ec2015-10-09 15:58:37 -0700746 private final ITelecomService mTelecomServiceOverride;
747
Santos Cordon6c7a3882014-06-25 15:30:08 -0700748 /**
749 * @hide
750 */
Chen Xu4c0b06d2018-10-22 16:54:39 +0000751 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700752 public static TelecomManager from(Context context) {
753 return (TelecomManager) context.getSystemService(Context.TELECOM_SERVICE);
Yorke Leeb4ce1432014-06-09 13:53:23 -0700754 }
Santos Cordon6c7a3882014-06-25 15:30:08 -0700755
756 /**
757 * @hide
758 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700759 public TelecomManager(Context context) {
Hall Liue1bc2ec2015-10-09 15:58:37 -0700760 this(context, null);
761 }
762
763 /**
764 * @hide
765 */
766 public TelecomManager(Context context, ITelecomService telecomServiceImpl) {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700767 Context appContext = context.getApplicationContext();
768 if (appContext != null) {
769 mContext = appContext;
770 } else {
771 mContext = context;
772 }
Hall Liue1bc2ec2015-10-09 15:58:37 -0700773 mTelecomServiceOverride = telecomServiceImpl;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700774 }
775
776 /**
Santos Cordon91371dc02015-05-08 13:52:09 -0700777 * Return the {@link PhoneAccount} which will be used to place outgoing calls to addresses with
778 * the specified {@code uriScheme}. This {@link PhoneAccount} will always be a member of the
779 * list which is returned from invoking {@link #getCallCapablePhoneAccounts()}. The specific
780 * account returned depends on the following priorities:
781 * <ul>
782 * <li> If the user-selected default {@link PhoneAccount} supports the specified scheme, it will
783 * be returned.
784 * </li>
785 * <li> If there exists only one {@link PhoneAccount} that supports the specified scheme, it
786 * will be returned.
787 * </li>
788 * </ul>
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700789 * <p>
Santos Cordon91371dc02015-05-08 13:52:09 -0700790 * If no {@link PhoneAccount} fits the criteria above, this method will return {@code null}.
791 *
Yorke Leec61d13662015-09-21 17:25:25 -0700792 * Requires permission: {@link android.Manifest.permission#READ_PHONE_STATE}
793 *
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700794 * @param uriScheme The URI scheme.
Santos Cordon91371dc02015-05-08 13:52:09 -0700795 * @return The {@link PhoneAccountHandle} corresponding to the account to be used.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700796 */
Yorke Leec61d13662015-09-21 17:25:25 -0700797 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700798 public PhoneAccountHandle getDefaultOutgoingPhoneAccount(String uriScheme) {
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700799 try {
800 if (isServiceConnected()) {
Svet Ganov16a16892015-04-16 10:32:04 -0700801 return getTelecomService().getDefaultOutgoingPhoneAccount(uriScheme,
802 mContext.getOpPackageName());
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700803 }
804 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700805 Log.e(TAG, "Error calling ITelecomService#getDefaultOutgoingPhoneAccount", e);
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700806 }
807 return null;
808 }
809
810 /**
Andrew Leed4abbfb2014-09-03 14:58:27 -0700811 * Return the {@link PhoneAccount} which is the user-chosen default for making outgoing phone
812 * calls. This {@code PhoneAccount} will always be a member of the list which is returned from
Nancy Chen210ef032014-09-15 17:58:42 -0700813 * calling {@link #getCallCapablePhoneAccounts()}
Santos Cordon91371dc02015-05-08 13:52:09 -0700814 * <p>
Andrew Leed4abbfb2014-09-03 14:58:27 -0700815 * Apps must be prepared for this method to return {@code null}, indicating that there currently
816 * exists no user-chosen default {@code PhoneAccount}.
Tyler Gunn36c50ed2018-11-15 07:29:49 -0800817 * <p>
818 * The default dialer has access to use this method.
Andrew Leed4abbfb2014-09-03 14:58:27 -0700819 *
Slava Shklyaeve65e4012019-03-04 16:02:34 +0000820 * @return The user outgoing phone account selected by the user, or {@code null} if there is no
821 * user selected outgoing {@link PhoneAccountHandle}.
Andrew Leed4abbfb2014-09-03 14:58:27 -0700822 */
Tyler Gunn36c50ed2018-11-15 07:29:49 -0800823 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
Slava Shklyaeve65e4012019-03-04 16:02:34 +0000824 public @Nullable PhoneAccountHandle getUserSelectedOutgoingPhoneAccount() {
Andrew Leed4abbfb2014-09-03 14:58:27 -0700825 try {
826 if (isServiceConnected()) {
Tyler Gunn36c50ed2018-11-15 07:29:49 -0800827 return getTelecomService().getUserSelectedOutgoingPhoneAccount(
828 mContext.getOpPackageName());
Andrew Leed4abbfb2014-09-03 14:58:27 -0700829 }
830 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700831 Log.e(TAG, "Error calling ITelecomService#getUserSelectedOutgoingPhoneAccount", e);
Andrew Leed4abbfb2014-09-03 14:58:27 -0700832 }
833 return null;
834 }
835
836 /**
Tyler Gunn36c50ed2018-11-15 07:29:49 -0800837 * Sets the user-chosen default {@link PhoneAccountHandle} for making outgoing phone calls.
838 *
839 * @param accountHandle The {@link PhoneAccountHandle} which will be used by default for making
Slava Shklyaeve65e4012019-03-04 16:02:34 +0000840 * outgoing voice calls, or {@code null} if no default is specified (the
841 * user will be asked each time a call is placed in this case).
Andrew Lee59cac3a2014-08-28 16:50:10 -0700842 * @hide
843 */
Tyler Gunn36c50ed2018-11-15 07:29:49 -0800844 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
Tyler Gunn6c14a6992019-02-04 15:12:06 -0800845 @TestApi
Tyler Gunn36c50ed2018-11-15 07:29:49 -0800846 @SystemApi
Slava Shklyaeve65e4012019-03-04 16:02:34 +0000847 public void setUserSelectedOutgoingPhoneAccount(@Nullable PhoneAccountHandle accountHandle) {
Andrew Lee59cac3a2014-08-28 16:50:10 -0700848 try {
849 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700850 getTelecomService().setUserSelectedOutgoingPhoneAccount(accountHandle);
Andrew Lee59cac3a2014-08-28 16:50:10 -0700851 }
852 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700853 Log.e(TAG, "Error calling ITelecomService#setUserSelectedOutgoingPhoneAccount");
Andrew Lee59cac3a2014-08-28 16:50:10 -0700854 }
855 }
856
857 /**
Andrew Lee59cac3a2014-08-28 16:50:10 -0700858 * Returns the current SIM call manager. Apps must be prepared for this method to return
Brad Ebingere7833312019-05-07 10:55:55 -0700859 * {@code null}, indicating that there currently exists no SIM call manager {@link PhoneAccount}
860 * for the default voice subscription.
Santos Cordon91371dc02015-05-08 13:52:09 -0700861 *
Brad Ebingere7833312019-05-07 10:55:55 -0700862 * @return The phone account handle of the current sim call manager for the default voice
863 * subscription.
864 * @see SubscriptionManager#getDefaultVoiceSubscriptionId()
Andrew Lee59cac3a2014-08-28 16:50:10 -0700865 */
866 public PhoneAccountHandle getSimCallManager() {
867 try {
868 if (isServiceConnected()) {
Brad Ebingere7833312019-05-07 10:55:55 -0700869 return getTelecomService().getSimCallManager(
870 SubscriptionManager.getDefaultSubscriptionId());
Andrew Lee59cac3a2014-08-28 16:50:10 -0700871 }
872 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700873 Log.e(TAG, "Error calling ITelecomService#getSimCallManager");
Andrew Lee59cac3a2014-08-28 16:50:10 -0700874 }
875 return null;
876 }
877
878 /**
Brad Ebingere7833312019-05-07 10:55:55 -0700879 * Returns current SIM call manager for the Telephony Subscription ID specified. Apps must be
880 * prepared for this method to return {@code null}, indicating that there currently exists no
881 * SIM call manager {@link PhoneAccount} for the subscription specified.
882 *
883 * @param subscriptionId The Telephony Subscription ID that the SIM call manager should be
884 * queried for.
885 * @return The phone account handle of the current sim call manager.
886 * @see SubscriptionManager#getActiveSubscriptionInfoList()
887 * @hide
888 */
889 public PhoneAccountHandle getSimCallManagerForSubscription(int subscriptionId) {
890 try {
891 if (isServiceConnected()) {
892 return getTelecomService().getSimCallManager(subscriptionId);
893 }
894 } catch (RemoteException e) {
895 Log.e(TAG, "Error calling ITelecomService#getSimCallManager");
896 }
897 return null;
898 }
899
900 /**
901 * Returns the current SIM call manager for the user-chosen default Telephony Subscription ID
902 * (see {@link SubscriptionManager#getDefaultSubscriptionId()}) and the specified user. Apps
903 * must be prepared for this method to return {@code null}, indicating that there currently
904 * exists no SIM call manager {@link PhoneAccount} for the default voice subscription.
Sailesh Nepalcf855622015-07-28 19:22:14 -0700905 *
906 * @return The phone account handle of the current sim call manager.
907 *
908 * @hide
Tyler Gunn6e3ecc42018-11-12 11:30:56 -0800909 * @deprecated Use {@link #getSimCallManager()}.
Sailesh Nepalcf855622015-07-28 19:22:14 -0700910 */
Tyler Gunn6e3ecc42018-11-12 11:30:56 -0800911 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 119305590)
Sailesh Nepalcf855622015-07-28 19:22:14 -0700912 public PhoneAccountHandle getSimCallManager(int userId) {
913 try {
914 if (isServiceConnected()) {
915 return getTelecomService().getSimCallManagerForUser(userId);
916 }
917 } catch (RemoteException e) {
918 Log.e(TAG, "Error calling ITelecomService#getSimCallManagerForUser");
919 }
920 return null;
921 }
922
923 /**
Evan Charltoneb0a8d562014-09-04 12:03:34 -0700924 * Returns the current connection manager. Apps must be prepared for this method to return
Brad Ebingere7833312019-05-07 10:55:55 -0700925 * {@code null}, indicating that there currently exists no Connection Manager
926 * {@link PhoneAccount} for the default voice subscription.
Evan Charltoneb0a8d562014-09-04 12:03:34 -0700927 *
928 * @return The phone account handle of the current connection manager.
Evan Charlton0e094d92014-11-08 15:49:16 -0800929 * @hide
Evan Charltoneb0a8d562014-09-04 12:03:34 -0700930 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800931 @SystemApi
Evan Charltoneb0a8d562014-09-04 12:03:34 -0700932 public PhoneAccountHandle getConnectionManager() {
933 return getSimCallManager();
934 }
935
936 /**
Nancy Chen210ef032014-09-15 17:58:42 -0700937 * Returns a list of the {@link PhoneAccountHandle}s which can be used to make and receive phone
938 * calls which support the specified URI scheme.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700939 * <P>
940 * For example, invoking with {@code "tel"} will find all {@link PhoneAccountHandle}s which
941 * support telephone calls (e.g. URIs such as {@code tel:555-555-1212}). Invoking with
942 * {@code "sip"} will find all {@link PhoneAccountHandle}s which support SIP calls (e.g. URIs
943 * such as {@code sip:example@sipexample.com}).
944 *
945 * @param uriScheme The URI scheme.
946 * @return A list of {@code PhoneAccountHandle} objects supporting the URI scheme.
Evan Charlton0e094d92014-11-08 15:49:16 -0800947 * @hide
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700948 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800949 @SystemApi
Jeff Sharkeybfc4fcd2017-06-05 17:38:17 -0600950 @RequiresPermission(anyOf = {
951 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
952 android.Manifest.permission.READ_PHONE_STATE
953 })
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700954 public List<PhoneAccountHandle> getPhoneAccountsSupportingScheme(String uriScheme) {
955 try {
956 if (isServiceConnected()) {
Svet Ganov16a16892015-04-16 10:32:04 -0700957 return getTelecomService().getPhoneAccountsSupportingScheme(uriScheme,
958 mContext.getOpPackageName());
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700959 }
960 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700961 Log.e(TAG, "Error calling ITelecomService#getPhoneAccountsSupportingScheme", e);
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700962 }
963 return new ArrayList<>();
964 }
965
Nancy Chen513c8922014-09-17 14:47:20 -0700966
967 /**
Santos Cordon91371dc02015-05-08 13:52:09 -0700968 * Returns a list of {@link PhoneAccountHandle}s which can be used to make and receive phone
969 * calls. The returned list includes only those accounts which have been explicitly enabled
970 * by the user.
Nancy Chen513c8922014-09-17 14:47:20 -0700971 *
Yorke Leec61d13662015-09-21 17:25:25 -0700972 * Requires permission: {@link android.Manifest.permission#READ_PHONE_STATE}
973 *
Nancy Chen513c8922014-09-17 14:47:20 -0700974 * @see #EXTRA_PHONE_ACCOUNT_HANDLE
975 * @return A list of {@code PhoneAccountHandle} objects.
Nancy Chen513c8922014-09-17 14:47:20 -0700976 */
Yorke Leec61d13662015-09-21 17:25:25 -0700977 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
Nancy Chen513c8922014-09-17 14:47:20 -0700978 public List<PhoneAccountHandle> getCallCapablePhoneAccounts() {
Santos Cordon91371dc02015-05-08 13:52:09 -0700979 return getCallCapablePhoneAccounts(false);
980 }
981
982 /**
Tyler Gunn89317072017-04-07 14:57:37 -0700983 * Returns a list of {@link PhoneAccountHandle}s for self-managed {@link ConnectionService}s.
984 * <p>
985 * Self-Managed {@link ConnectionService}s have a {@link PhoneAccount} with
986 * {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.
987 * <p>
988 * Requires permission {@link android.Manifest.permission#READ_PHONE_STATE}, or that the caller
989 * is the default dialer app.
990 * <p>
991 * A {@link SecurityException} will be thrown if a called is not the default dialer, or lacks
992 * the {@link android.Manifest.permission#READ_PHONE_STATE} permission.
993 *
994 * @return A list of {@code PhoneAccountHandle} objects.
995 */
996 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
997 public List<PhoneAccountHandle> getSelfManagedPhoneAccounts() {
998 try {
999 if (isServiceConnected()) {
1000 return getTelecomService().getSelfManagedPhoneAccounts(mContext.getOpPackageName());
1001 }
1002 } catch (RemoteException e) {
1003 Log.e(TAG, "Error calling ITelecomService#getSelfManagedPhoneAccounts()", e);
1004 }
1005 return new ArrayList<>();
1006 }
1007
1008 /**
Santos Cordon91371dc02015-05-08 13:52:09 -07001009 * Returns a list of {@link PhoneAccountHandle}s including those which have not been enabled
1010 * by the user.
1011 *
Tyler Gunn6e3ecc42018-11-12 11:30:56 -08001012 * @param includeDisabledAccounts When {@code true}, disabled phone accounts will be included,
1013 * when {@code false}, only
Santos Cordon91371dc02015-05-08 13:52:09 -07001014 * @return A list of {@code PhoneAccountHandle} objects.
1015 * @hide
1016 */
Tyler Gunn6e3ecc42018-11-12 11:30:56 -08001017 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 119305590)
Santos Cordon91371dc02015-05-08 13:52:09 -07001018 public List<PhoneAccountHandle> getCallCapablePhoneAccounts(boolean includeDisabledAccounts) {
Nancy Chen513c8922014-09-17 14:47:20 -07001019 try {
1020 if (isServiceConnected()) {
Santos Cordon91371dc02015-05-08 13:52:09 -07001021 return getTelecomService().getCallCapablePhoneAccounts(
1022 includeDisabledAccounts, mContext.getOpPackageName());
Nancy Chen513c8922014-09-17 14:47:20 -07001023 }
1024 } catch (RemoteException e) {
Santos Cordon91371dc02015-05-08 13:52:09 -07001025 Log.e(TAG, "Error calling ITelecomService#getCallCapablePhoneAccounts(" +
1026 includeDisabledAccounts + ")", e);
Nancy Chen513c8922014-09-17 14:47:20 -07001027 }
1028 return new ArrayList<>();
1029 }
1030
Tyler Gunnf5b29dc2014-09-03 09:09:12 -07001031 /**
Nancy Chen513c8922014-09-17 14:47:20 -07001032 * Returns a list of all {@link PhoneAccount}s registered for the calling package.
1033 *
1034 * @return A list of {@code PhoneAccountHandle} objects.
Evan Charlton0e094d92014-11-08 15:49:16 -08001035 * @hide
Nancy Chen513c8922014-09-17 14:47:20 -07001036 */
Evan Charlton0e094d92014-11-08 15:49:16 -08001037 @SystemApi
Jeff Sharkeybfc4fcd2017-06-05 17:38:17 -06001038 @SuppressLint("Doclava125")
Nancy Chen513c8922014-09-17 14:47:20 -07001039 public List<PhoneAccountHandle> getPhoneAccountsForPackage() {
1040 try {
1041 if (isServiceConnected()) {
1042 return getTelecomService().getPhoneAccountsForPackage(mContext.getPackageName());
1043 }
1044 } catch (RemoteException e) {
1045 Log.e(TAG, "Error calling ITelecomService#getPhoneAccountsForPackage", e);
1046 }
1047 return null;
1048 }
1049
1050 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -07001051 * Return the {@link PhoneAccount} for a specified {@link PhoneAccountHandle}. Object includes
1052 * resources which can be used in a user interface.
Ihab Awad807fe0a2014-07-09 12:30:52 -07001053 *
Evan Charlton6eb262c2014-07-19 18:18:19 -07001054 * @param account The {@link PhoneAccountHandle}.
Evan Charlton8c8a0622014-07-20 12:31:00 -07001055 * @return The {@link PhoneAccount} object.
Ihab Awad807fe0a2014-07-09 12:30:52 -07001056 */
Evan Charlton8c8a0622014-07-20 12:31:00 -07001057 public PhoneAccount getPhoneAccount(PhoneAccountHandle account) {
Ihab Awad807fe0a2014-07-09 12:30:52 -07001058 try {
1059 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001060 return getTelecomService().getPhoneAccount(account);
Ihab Awad807fe0a2014-07-09 12:30:52 -07001061 }
1062 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001063 Log.e(TAG, "Error calling ITelecomService#getPhoneAccount", e);
Ihab Awad807fe0a2014-07-09 12:30:52 -07001064 }
1065 return null;
1066 }
1067
1068 /**
Nancy Chen210ef032014-09-15 17:58:42 -07001069 * Returns a count of all {@link PhoneAccount}s.
Tyler Gunna1ed7d12014-09-08 09:52:22 -07001070 *
Nancy Chen210ef032014-09-15 17:58:42 -07001071 * @return The count of {@link PhoneAccount}s.
Tyler Gunna1ed7d12014-09-08 09:52:22 -07001072 * @hide
1073 */
1074 @SystemApi
1075 public int getAllPhoneAccountsCount() {
1076 try {
1077 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001078 return getTelecomService().getAllPhoneAccountsCount();
Tyler Gunna1ed7d12014-09-08 09:52:22 -07001079 }
1080 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001081 Log.e(TAG, "Error calling ITelecomService#getAllPhoneAccountsCount", e);
Tyler Gunna1ed7d12014-09-08 09:52:22 -07001082 }
1083 return 0;
1084 }
1085
1086 /**
1087 * Returns a list of all {@link PhoneAccount}s.
1088 *
1089 * @return All {@link PhoneAccount}s.
1090 * @hide
1091 */
1092 @SystemApi
1093 public List<PhoneAccount> getAllPhoneAccounts() {
1094 try {
1095 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001096 return getTelecomService().getAllPhoneAccounts();
Tyler Gunna1ed7d12014-09-08 09:52:22 -07001097 }
1098 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001099 Log.e(TAG, "Error calling ITelecomService#getAllPhoneAccounts", e);
Tyler Gunna1ed7d12014-09-08 09:52:22 -07001100 }
1101 return Collections.EMPTY_LIST;
1102 }
1103
1104 /**
1105 * Returns a list of all {@link PhoneAccountHandle}s.
1106 *
1107 * @return All {@link PhoneAccountHandle}s.
1108 * @hide
1109 */
1110 @SystemApi
1111 public List<PhoneAccountHandle> getAllPhoneAccountHandles() {
1112 try {
1113 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001114 return getTelecomService().getAllPhoneAccountHandles();
Tyler Gunna1ed7d12014-09-08 09:52:22 -07001115 }
1116 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001117 Log.e(TAG, "Error calling ITelecomService#getAllPhoneAccountHandles", e);
Tyler Gunna1ed7d12014-09-08 09:52:22 -07001118 }
1119 return Collections.EMPTY_LIST;
1120 }
1121
1122 /**
Brad Ebingerec0d3342016-01-29 15:40:43 -08001123 * Register a {@link PhoneAccount} for use by the system that will be stored in Device Encrypted
1124 * storage. When registering {@link PhoneAccount}s, existing registrations will be overwritten
1125 * if the {@link PhoneAccountHandle} matches that of a {@link PhoneAccount} which is already
Santos Cordond9e614f2014-10-28 13:10:36 -07001126 * registered. Once registered, the {@link PhoneAccount} is listed to the user as an option
1127 * when placing calls. The user may still need to enable the {@link PhoneAccount} within
1128 * the phone app settings before the account is usable.
1129 * <p>
1130 * A {@link SecurityException} will be thrown if an app tries to register a
1131 * {@link PhoneAccountHandle} where the package name specified within
1132 * {@link PhoneAccountHandle#getComponentName()} does not match the package name of the app.
Ihab Awad807fe0a2014-07-09 12:30:52 -07001133 *
Evan Charlton8c8a0622014-07-20 12:31:00 -07001134 * @param account The complete {@link PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -07001135 */
Evan Charlton8c8a0622014-07-20 12:31:00 -07001136 public void registerPhoneAccount(PhoneAccount account) {
Ihab Awad807fe0a2014-07-09 12:30:52 -07001137 try {
1138 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001139 getTelecomService().registerPhoneAccount(account);
Ihab Awad807fe0a2014-07-09 12:30:52 -07001140 }
1141 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001142 Log.e(TAG, "Error calling ITelecomService#registerPhoneAccount", e);
Ihab Awad807fe0a2014-07-09 12:30:52 -07001143 }
1144 }
1145
1146 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -07001147 * Remove a {@link PhoneAccount} registration from the system.
Ihab Awad807fe0a2014-07-09 12:30:52 -07001148 *
Evan Charlton8c8a0622014-07-20 12:31:00 -07001149 * @param accountHandle A {@link PhoneAccountHandle} for the {@link PhoneAccount} to unregister.
Ihab Awad807fe0a2014-07-09 12:30:52 -07001150 */
Evan Charlton8c8a0622014-07-20 12:31:00 -07001151 public void unregisterPhoneAccount(PhoneAccountHandle accountHandle) {
Ihab Awad807fe0a2014-07-09 12:30:52 -07001152 try {
1153 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001154 getTelecomService().unregisterPhoneAccount(accountHandle);
Ihab Awad807fe0a2014-07-09 12:30:52 -07001155 }
1156 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001157 Log.e(TAG, "Error calling ITelecomService#unregisterPhoneAccount", e);
Ihab Awad807fe0a2014-07-09 12:30:52 -07001158 }
1159 }
1160
1161 /**
Nancy Chen7ab1dc42014-09-09 18:18:26 -07001162 * Remove all Accounts that belong to the calling package from the system.
Evan Charlton0e094d92014-11-08 15:49:16 -08001163 * @hide
Ihab Awad807fe0a2014-07-09 12:30:52 -07001164 */
Evan Charlton0e094d92014-11-08 15:49:16 -08001165 @SystemApi
Jeff Sharkeybfc4fcd2017-06-05 17:38:17 -06001166 @SuppressLint("Doclava125")
Yorke Lee06044272015-04-14 15:16:59 -07001167 public void clearPhoneAccounts() {
1168 clearAccounts();
1169 }
1170 /**
1171 * Remove all Accounts that belong to the calling package from the system.
1172 * @deprecated Use {@link #clearPhoneAccounts()} instead.
1173 * @hide
1174 */
1175 @SystemApi
Jeff Sharkeybfc4fcd2017-06-05 17:38:17 -06001176 @SuppressLint("Doclava125")
Nancy Chen7ab1dc42014-09-09 18:18:26 -07001177 public void clearAccounts() {
Ihab Awad807fe0a2014-07-09 12:30:52 -07001178 try {
1179 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001180 getTelecomService().clearAccounts(mContext.getPackageName());
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#clearAccounts", e);
Ihab Awad807fe0a2014-07-09 12:30:52 -07001184 }
1185 }
1186
1187 /**
Anthony Lee67279262014-10-27 11:28:40 -07001188 * Remove all Accounts that belong to the specified package from the system.
1189 * @hide
1190 */
1191 public void clearAccountsForPackage(String packageName) {
1192 try {
1193 if (isServiceConnected() && !TextUtils.isEmpty(packageName)) {
1194 getTelecomService().clearAccounts(packageName);
1195 }
1196 } catch (RemoteException e) {
Nancy Chen5cf27842015-01-24 23:30:27 -08001197 Log.e(TAG, "Error calling ITelecomService#clearAccountsForPackage", e);
Anthony Lee67279262014-10-27 11:28:40 -07001198 }
1199 }
1200
Yorke Lee1011f482015-04-23 15:58:27 -07001201
Anthony Lee67279262014-10-27 11:28:40 -07001202 /**
Yorke Lee1011f482015-04-23 15:58:27 -07001203 * @deprecated - Use {@link TelecomManager#getDefaultDialerPackage} to directly access
1204 * the default dialer's package name instead.
Ihab Awad807fe0a2014-07-09 12:30:52 -07001205 * @hide
1206 */
Santos Cordon6c7a3882014-06-25 15:30:08 -07001207 @SystemApi
Jeff Sharkeybfc4fcd2017-06-05 17:38:17 -06001208 @SuppressLint("Doclava125")
Santos Cordon6c7a3882014-06-25 15:30:08 -07001209 public ComponentName getDefaultPhoneApp() {
1210 try {
Santos Cordon9eb45932014-06-27 12:28:43 -07001211 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001212 return getTelecomService().getDefaultPhoneApp();
Santos Cordon9eb45932014-06-27 12:28:43 -07001213 }
Santos Cordon6c7a3882014-06-25 15:30:08 -07001214 } catch (RemoteException e) {
1215 Log.e(TAG, "RemoteException attempting to get the default phone app.", e);
1216 }
1217 return null;
1218 }
1219
Santos Cordon9eb45932014-06-27 12:28:43 -07001220 /**
Yorke Lee1011f482015-04-23 15:58:27 -07001221 * Used to determine the currently selected default dialer package.
1222 *
1223 * @return package name for the default dialer package or null if no package has been
1224 * selected as the default dialer.
1225 */
1226 public String getDefaultDialerPackage() {
1227 try {
1228 if (isServiceConnected()) {
1229 return getTelecomService().getDefaultDialerPackage();
1230 }
1231 } catch (RemoteException e) {
1232 Log.e(TAG, "RemoteException attempting to get the default dialer package name.", e);
1233 }
1234 return null;
1235 }
1236
1237 /**
Yorke Lee107c4ce2015-06-15 12:08:24 -07001238 * Used to set the default dialer package.
1239 *
Slava Shklyaeve65e4012019-03-04 16:02:34 +00001240 * @param packageName to set the default dialer to, or {@code null} if the system provided
1241 * dialer should be used instead.
Yorke Lee107c4ce2015-06-15 12:08:24 -07001242 *
1243 * @result {@code true} if the default dialer was successfully changed, {@code false} if
1244 * the specified package does not correspond to an installed dialer, or is already
1245 * the default dialer.
1246 *
1247 * Requires permission: {@link android.Manifest.permission#MODIFY_PHONE_STATE}
1248 * Requires permission: {@link android.Manifest.permission#WRITE_SECURE_SETTINGS}
1249 *
1250 * @hide
Tyler Gunn7e45b722018-12-04 12:56:45 -08001251 * @deprecated Use
Hai Zhangf5e8ccd2019-03-06 20:12:24 -08001252 * {@link android.app.role.RoleManager#addRoleHolderAsUser(String, String, int, UserHandle,
1253 * Executor, java.util.function.Consumer)} instead.
Suprabh Shukla169bed72019-05-13 13:54:58 -07001254 * @removed
Yorke Lee107c4ce2015-06-15 12:08:24 -07001255 */
Tyler Gunn6e3ecc42018-11-12 11:30:56 -08001256 @SystemApi
Tyler Gunn7e45b722018-12-04 12:56:45 -08001257 @Deprecated
Tyler Gunn6e3ecc42018-11-12 11:30:56 -08001258 @RequiresPermission(allOf = {
1259 android.Manifest.permission.MODIFY_PHONE_STATE,
1260 android.Manifest.permission.WRITE_SECURE_SETTINGS})
Slava Shklyaeve65e4012019-03-04 16:02:34 +00001261 public boolean setDefaultDialer(@Nullable String packageName) {
Yorke Lee107c4ce2015-06-15 12:08:24 -07001262 try {
1263 if (isServiceConnected()) {
1264 return getTelecomService().setDefaultDialer(packageName);
1265 }
1266 } catch (RemoteException e) {
1267 Log.e(TAG, "RemoteException attempting to set the default dialer.", e);
1268 }
1269 return false;
1270 }
1271
1272 /**
Tyler Gunn6e3ecc42018-11-12 11:30:56 -08001273 * Determines the package name of the system-provided default phone app.
Yorke Lee1011f482015-04-23 15:58:27 -07001274 *
Slava Shklyaeve65e4012019-03-04 16:02:34 +00001275 * @return package name for the system dialer package or {@code null} if no system dialer is
1276 * preloaded.
Yorke Lee1011f482015-04-23 15:58:27 -07001277 */
Slava Shklyaeve65e4012019-03-04 16:02:34 +00001278 public @Nullable String getSystemDialerPackage() {
Yorke Lee1011f482015-04-23 15:58:27 -07001279 try {
1280 if (isServiceConnected()) {
1281 return getTelecomService().getSystemDialerPackage();
1282 }
1283 } catch (RemoteException e) {
1284 Log.e(TAG, "RemoteException attempting to get the system dialer package name.", e);
1285 }
1286 return null;
1287 }
1288
1289 /**
Nancy Chen443e5012014-10-15 15:48:21 -07001290 * Return whether a given phone number is the configured voicemail number for a
1291 * particular phone account.
1292 *
Yorke Leec61d13662015-09-21 17:25:25 -07001293 * Requires permission: {@link android.Manifest.permission#READ_PHONE_STATE}
1294 *
Nancy Chen443e5012014-10-15 15:48:21 -07001295 * @param accountHandle The handle for the account to check the voicemail number against
1296 * @param number The number to look up.
Nancy Chen443e5012014-10-15 15:48:21 -07001297 */
Yorke Leec61d13662015-09-21 17:25:25 -07001298 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
Nancy Chen443e5012014-10-15 15:48:21 -07001299 public boolean isVoiceMailNumber(PhoneAccountHandle accountHandle, String number) {
1300 try {
1301 if (isServiceConnected()) {
Svet Ganov16a16892015-04-16 10:32:04 -07001302 return getTelecomService().isVoiceMailNumber(accountHandle, number,
1303 mContext.getOpPackageName());
Nancy Chen443e5012014-10-15 15:48:21 -07001304 }
1305 } catch (RemoteException e) {
Nancy Chen5cf27842015-01-24 23:30:27 -08001306 Log.e(TAG, "RemoteException calling ITelecomService#isVoiceMailNumber.", e);
Nancy Chen443e5012014-10-15 15:48:21 -07001307 }
1308 return false;
1309 }
1310
1311 /**
Yorke Lee49e2d462015-04-15 16:14:22 -07001312 * Return the voicemail number for a given phone account.
Nancy Chen8c066f7c2014-12-03 15:18:08 -08001313 *
Yorke Leec61d13662015-09-21 17:25:25 -07001314 * Requires permission: {@link android.Manifest.permission#READ_PHONE_STATE}
1315 *
Yorke Lee49e2d462015-04-15 16:14:22 -07001316 * @param accountHandle The handle for the phone account.
1317 * @return The voicemail number for the phone account, and {@code null} if one has not been
1318 * configured.
Nancy Chen8c066f7c2014-12-03 15:18:08 -08001319 */
Yorke Leec61d13662015-09-21 17:25:25 -07001320 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
Yorke Lee49e2d462015-04-15 16:14:22 -07001321 public String getVoiceMailNumber(PhoneAccountHandle accountHandle) {
Nancy Chen8c066f7c2014-12-03 15:18:08 -08001322 try {
1323 if (isServiceConnected()) {
Svet Ganov16a16892015-04-16 10:32:04 -07001324 return getTelecomService().getVoiceMailNumber(accountHandle,
1325 mContext.getOpPackageName());
Nancy Chen8c066f7c2014-12-03 15:18:08 -08001326 }
1327 } catch (RemoteException e) {
Nancy Chen5cf27842015-01-24 23:30:27 -08001328 Log.e(TAG, "RemoteException calling ITelecomService#hasVoiceMailNumber.", e);
Nancy Chen8c066f7c2014-12-03 15:18:08 -08001329 }
Yorke Lee49e2d462015-04-15 16:14:22 -07001330 return null;
Nancy Chen8c066f7c2014-12-03 15:18:08 -08001331 }
1332
1333 /**
Nancy Chen5cf27842015-01-24 23:30:27 -08001334 * Return the line 1 phone number for given phone account.
1335 *
Yorke Leec61d13662015-09-21 17:25:25 -07001336 * Requires permission: {@link android.Manifest.permission#READ_PHONE_STATE}
1337 *
Nancy Chen5cf27842015-01-24 23:30:27 -08001338 * @param accountHandle The handle for the account retrieve a number for.
1339 * @return A string representation of the line 1 phone number.
Nancy Chen5cf27842015-01-24 23:30:27 -08001340 */
Yorke Leec61d13662015-09-21 17:25:25 -07001341 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
Nancy Chen5cf27842015-01-24 23:30:27 -08001342 public String getLine1Number(PhoneAccountHandle accountHandle) {
1343 try {
1344 if (isServiceConnected()) {
Svet Ganov16a16892015-04-16 10:32:04 -07001345 return getTelecomService().getLine1Number(accountHandle,
1346 mContext.getOpPackageName());
Nancy Chen5cf27842015-01-24 23:30:27 -08001347 }
1348 } catch (RemoteException e) {
1349 Log.e(TAG, "RemoteException calling ITelecomService#getLine1Number.", e);
1350 }
1351 return null;
1352 }
1353
1354 /**
Santos Cordon9eb45932014-06-27 12:28:43 -07001355 * Returns whether there is an ongoing phone call (can be in dialing, ringing, active or holding
Tyler Gunn24e18332017-02-10 09:42:49 -08001356 * states) originating from either a manager or self-managed {@link ConnectionService}.
Nancy Chen0eb1e402014-08-21 22:52:29 -07001357 * <p>
1358 * Requires permission: {@link android.Manifest.permission#READ_PHONE_STATE}
Tyler Gunn24e18332017-02-10 09:42:49 -08001359 *
1360 * @return {@code true} if there is an ongoing call in either a managed or self-managed
1361 * {@link ConnectionService}, {@code false} otherwise.
Santos Cordon9eb45932014-06-27 12:28:43 -07001362 */
Yorke Leec61d13662015-09-21 17:25:25 -07001363 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
Nancy Chen0eb1e402014-08-21 22:52:29 -07001364 public boolean isInCall() {
Santos Cordon9eb45932014-06-27 12:28:43 -07001365 try {
1366 if (isServiceConnected()) {
Svet Ganov16a16892015-04-16 10:32:04 -07001367 return getTelecomService().isInCall(mContext.getOpPackageName());
Santos Cordon9eb45932014-06-27 12:28:43 -07001368 }
1369 } catch (RemoteException e) {
Yorke Lee2ae312e2014-09-12 17:58:48 -07001370 Log.e(TAG, "RemoteException calling isInCall().", e);
Santos Cordon9eb45932014-06-27 12:28:43 -07001371 }
1372 return false;
1373 }
1374
1375 /**
Tyler Gunn24e18332017-02-10 09:42:49 -08001376 * Returns whether there is an ongoing call originating from a managed
1377 * {@link ConnectionService}. An ongoing call can be in dialing, ringing, active or holding
1378 * states.
1379 * <p>
1380 * If you also need to know if there are ongoing self-managed calls, use {@link #isInCall()}
1381 * instead.
1382 * <p>
1383 * Requires permission: {@link android.Manifest.permission#READ_PHONE_STATE}
1384 *
1385 * @return {@code true} if there is an ongoing call in a managed {@link ConnectionService},
1386 * {@code false} otherwise.
1387 */
1388 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
1389 public boolean isInManagedCall() {
1390 try {
1391 if (isServiceConnected()) {
1392 return getTelecomService().isInManagedCall(mContext.getOpPackageName());
1393 }
1394 } catch (RemoteException e) {
1395 Log.e(TAG, "RemoteException calling isInManagedCall().", e);
1396 }
1397 return false;
1398 }
1399
1400 /**
Yorke Lee2ae312e2014-09-12 17:58:48 -07001401 * Returns one of the following constants that represents the current state of Telecom:
1402 *
1403 * {@link TelephonyManager#CALL_STATE_RINGING}
1404 * {@link TelephonyManager#CALL_STATE_OFFHOOK}
1405 * {@link TelephonyManager#CALL_STATE_IDLE}
Yorke Lee7c72c2d2014-10-28 14:12:02 -07001406 *
1407 * Note that this API does not require the
1408 * {@link android.Manifest.permission#READ_PHONE_STATE} permission. This is intentional, to
1409 * preserve the behavior of {@link TelephonyManager#getCallState()}, which also did not require
1410 * the permission.
Tyler Gunn24e18332017-02-10 09:42:49 -08001411 *
1412 * Takes into consideration both managed and self-managed calls.
1413 *
Yorke Lee2ae312e2014-09-12 17:58:48 -07001414 * @hide
1415 */
1416 @SystemApi
Chen Xuc9d4ee12019-09-26 16:11:59 -07001417 public @CallState int getCallState() {
Yorke Lee2ae312e2014-09-12 17:58:48 -07001418 try {
1419 if (isServiceConnected()) {
1420 return getTelecomService().getCallState();
1421 }
1422 } catch (RemoteException e) {
1423 Log.d(TAG, "RemoteException calling getCallState().", e);
1424 }
1425 return TelephonyManager.CALL_STATE_IDLE;
1426 }
1427
1428 /**
Santos Cordon9eb45932014-06-27 12:28:43 -07001429 * Returns whether there currently exists is a ringing incoming-call.
1430 *
Tyler Gunn24e18332017-02-10 09:42:49 -08001431 * @return {@code true} if there is a managed or self-managed ringing call.
Santos Cordon9eb45932014-06-27 12:28:43 -07001432 * @hide
1433 */
1434 @SystemApi
Jeff Sharkeybfc4fcd2017-06-05 17:38:17 -06001435 @RequiresPermission(anyOf = {
1436 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
1437 android.Manifest.permission.READ_PHONE_STATE
1438 })
Santos Cordon9eb45932014-06-27 12:28:43 -07001439 public boolean isRinging() {
1440 try {
1441 if (isServiceConnected()) {
Svet Ganov16a16892015-04-16 10:32:04 -07001442 return getTelecomService().isRinging(mContext.getOpPackageName());
Santos Cordon9eb45932014-06-27 12:28:43 -07001443 }
1444 } catch (RemoteException e) {
1445 Log.e(TAG, "RemoteException attempting to get ringing state of phone app.", e);
1446 }
1447 return false;
1448 }
1449
1450 /**
Tyler Gunne1aa26c2018-05-02 13:23:48 -07001451 * Ends the foreground call on the device.
1452 * <p>
1453 * If there is a ringing call, calling this method rejects the ringing call. Otherwise the
1454 * foreground call is ended.
1455 * <p>
1456 * Requires permission {@link android.Manifest.permission#ANSWER_PHONE_CALLS}.
Tyler Gunnf18ee4c2019-05-14 11:08:06 -07001457 * <p>
1458 * Note: this method CANNOT be used to end ongoing emergency calls and will return {@code false}
1459 * if an attempt is made to end an emergency call.
Tyler Gunne1aa26c2018-05-02 13:23:48 -07001460 *
1461 * @return {@code true} if there is a call which will be rejected or terminated, {@code false}
1462 * otherwise.
Tyler Gunn9bd8db42019-01-31 10:54:03 -08001463 * @deprecated Companion apps for wearable devices should use the {@link InCallService} API
1464 * instead. Apps performing call screening should use the {@link CallScreeningService} API
1465 * instead.
Santos Cordon9eb45932014-06-27 12:28:43 -07001466 */
Tyler Gunne1aa26c2018-05-02 13:23:48 -07001467 @RequiresPermission(Manifest.permission.ANSWER_PHONE_CALLS)
Tyler Gunn9bd8db42019-01-31 10:54:03 -08001468 @Deprecated
Santos Cordon9eb45932014-06-27 12:28:43 -07001469 public boolean endCall() {
1470 try {
1471 if (isServiceConnected()) {
Tyler Gunnc8658812018-02-07 16:08:27 -08001472 return getTelecomService().endCall(mContext.getPackageName());
Santos Cordon9eb45932014-06-27 12:28:43 -07001473 }
1474 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001475 Log.e(TAG, "Error calling ITelecomService#endCall", e);
Santos Cordon9eb45932014-06-27 12:28:43 -07001476 }
1477 return false;
1478 }
1479
1480 /**
1481 * If there is a ringing incoming call, this method accepts the call on behalf of the user.
Eugene Suslacae3d3e2017-01-31 11:08:11 -08001482 *
Tyler Gunn6676bb52015-10-23 14:39:49 -07001483 * If the incoming call is a video call, the call will be answered with the same video state as
1484 * the incoming call requests. This means, for example, that an incoming call requesting
1485 * {@link VideoProfile#STATE_BIDIRECTIONAL} will be answered, accepting that state.
Eugene Suslacae3d3e2017-01-31 11:08:11 -08001486 *
1487 * Requires permission: {@link android.Manifest.permission#MODIFY_PHONE_STATE} or
1488 * {@link android.Manifest.permission#ANSWER_PHONE_CALLS}
Tyler Gunn9bd8db42019-01-31 10:54:03 -08001489 *
1490 * @deprecated Companion apps for wearable devices should use the {@link InCallService} API
1491 * instead.
Santos Cordon9eb45932014-06-27 12:28:43 -07001492 */
Eugene Suslacae3d3e2017-01-31 11:08:11 -08001493 //TODO: L-release - need to convert all invocation of ITelecmmService#answerRingingCall to use
1494 // this method (clockwork & gearhead).
1495 @RequiresPermission(anyOf =
1496 {Manifest.permission.ANSWER_PHONE_CALLS, Manifest.permission.MODIFY_PHONE_STATE})
Tyler Gunn9bd8db42019-01-31 10:54:03 -08001497 @Deprecated
Santos Cordon9eb45932014-06-27 12:28:43 -07001498 public void acceptRingingCall() {
1499 try {
1500 if (isServiceConnected()) {
Eugene Suslacae3d3e2017-01-31 11:08:11 -08001501 getTelecomService().acceptRingingCall(mContext.getPackageName());
Santos Cordon9eb45932014-06-27 12:28:43 -07001502 }
1503 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001504 Log.e(TAG, "Error calling ITelecomService#acceptRingingCall", e);
Santos Cordon9eb45932014-06-27 12:28:43 -07001505 }
1506 }
1507
1508 /**
Tyler Gunn6676bb52015-10-23 14:39:49 -07001509 * If there is a ringing incoming call, this method accepts the call on behalf of the user,
1510 * with the specified video state.
1511 *
Eugene Suslacae3d3e2017-01-31 11:08:11 -08001512 * Requires permission: {@link android.Manifest.permission#MODIFY_PHONE_STATE} or
1513 * {@link android.Manifest.permission#ANSWER_PHONE_CALLS}
1514 *
Tyler Gunn6676bb52015-10-23 14:39:49 -07001515 * @param videoState The desired video state to answer the call with.
Tyler Gunn9bd8db42019-01-31 10:54:03 -08001516 * @deprecated Companion apps for wearable devices should use the {@link InCallService} API
1517 * instead.
Tyler Gunn6676bb52015-10-23 14:39:49 -07001518 */
Eugene Suslacae3d3e2017-01-31 11:08:11 -08001519 @RequiresPermission(anyOf =
1520 {Manifest.permission.ANSWER_PHONE_CALLS, Manifest.permission.MODIFY_PHONE_STATE})
Tyler Gunn9bd8db42019-01-31 10:54:03 -08001521 @Deprecated
Tyler Gunn6676bb52015-10-23 14:39:49 -07001522 public void acceptRingingCall(int videoState) {
1523 try {
1524 if (isServiceConnected()) {
Eugene Suslacae3d3e2017-01-31 11:08:11 -08001525 getTelecomService().acceptRingingCallWithVideoState(
1526 mContext.getPackageName(), videoState);
Tyler Gunn6676bb52015-10-23 14:39:49 -07001527 }
1528 } catch (RemoteException e) {
1529 Log.e(TAG, "Error calling ITelecomService#acceptRingingCallWithVideoState", e);
1530 }
1531 }
1532
1533 /**
Santos Cordon9eb45932014-06-27 12:28:43 -07001534 * Silences the ringer if a ringing call exists.
Tyler Gunn556d2402019-04-10 08:59:43 -07001535 * <p>
1536 * This method can only be relied upon to stop the ringtone for a call if the ringtone has
1537 * already started playing. It is intended to handle use-cases such as silencing a ringing call
1538 * when the user presses the volume button during ringing.
1539 * <p>
1540 * If this method is called prior to when the ringtone begins playing, the ringtone will not be
1541 * silenced. As such it is not intended as a means to avoid playing of a ringtone.
1542 * <p>
1543 * A dialer app which wants to have more control over ringtone playing should declare
1544 * {@link TelecomManager#METADATA_IN_CALL_SERVICE_RINGING} in the manifest entry for their
1545 * {@link InCallService} implementation to indicate that the app wants to be responsible for
1546 * playing the ringtone for all incoming calls.
1547 * <p>
1548 * Requires permission: {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the
1549 * app fills the dialer role (see {@link #getDefaultDialerPackage()}).
Santos Cordon9eb45932014-06-27 12:28:43 -07001550 */
Yorke Leec61d13662015-09-21 17:25:25 -07001551 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
Santos Cordon9eb45932014-06-27 12:28:43 -07001552 public void silenceRinger() {
1553 try {
1554 if (isServiceConnected()) {
Yorke Leef1a349b2015-04-29 16:16:50 -07001555 getTelecomService().silenceRinger(mContext.getOpPackageName());
Santos Cordon9eb45932014-06-27 12:28:43 -07001556 }
1557 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001558 Log.e(TAG, "Error calling ITelecomService#silenceRinger", e);
Santos Cordon9eb45932014-06-27 12:28:43 -07001559 }
1560 }
1561
Sailesh Nepal001bbbb2014-07-15 14:40:39 -07001562 /**
1563 * Returns whether TTY is supported on this device.
Sailesh Nepal001bbbb2014-07-15 14:40:39 -07001564 */
Jeff Sharkeybfc4fcd2017-06-05 17:38:17 -06001565 @RequiresPermission(anyOf = {
1566 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
1567 android.Manifest.permission.READ_PHONE_STATE
1568 })
Sailesh Nepal001bbbb2014-07-15 14:40:39 -07001569 public boolean isTtySupported() {
1570 try {
1571 if (isServiceConnected()) {
Svet Ganov16a16892015-04-16 10:32:04 -07001572 return getTelecomService().isTtySupported(mContext.getOpPackageName());
Sailesh Nepal001bbbb2014-07-15 14:40:39 -07001573 }
1574 } catch (RemoteException e) {
1575 Log.e(TAG, "RemoteException attempting to get TTY supported state.", e);
1576 }
1577 return false;
1578 }
1579
1580 /**
1581 * 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 -07001582 * settings and have a wired headset plugged in.
1583 * Valid modes are:
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001584 * - {@link TelecomManager#TTY_MODE_OFF}
1585 * - {@link TelecomManager#TTY_MODE_FULL}
1586 * - {@link TelecomManager#TTY_MODE_HCO}
1587 * - {@link TelecomManager#TTY_MODE_VCO}
Sailesh Nepal001bbbb2014-07-15 14:40:39 -07001588 * @hide
1589 */
Tyler Gunn6e3ecc42018-11-12 11:30:56 -08001590 @SystemApi
Tyler Gunn6c14a6992019-02-04 15:12:06 -08001591 @TestApi
Tyler Gunn6e3ecc42018-11-12 11:30:56 -08001592 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
1593 public @TtyMode int getCurrentTtyMode() {
Sailesh Nepal001bbbb2014-07-15 14:40:39 -07001594 try {
1595 if (isServiceConnected()) {
Svet Ganov16a16892015-04-16 10:32:04 -07001596 return getTelecomService().getCurrentTtyMode(mContext.getOpPackageName());
Sailesh Nepal001bbbb2014-07-15 14:40:39 -07001597 }
1598 } catch (RemoteException e) {
1599 Log.e(TAG, "RemoteException attempting to get the current TTY mode.", e);
1600 }
Evan Charlton10197192014-07-19 15:00:29 -07001601 return TTY_MODE_OFF;
Sailesh Nepal001bbbb2014-07-15 14:40:39 -07001602 }
1603
Santos Cordon96efb482014-07-19 14:57:05 -07001604 /**
1605 * Registers a new incoming call. A {@link ConnectionService} should invoke this method when it
Tyler Gunnf5035432017-01-09 09:43:12 -08001606 * has an incoming call. For managed {@link ConnectionService}s, the specified
1607 * {@link PhoneAccountHandle} must have been registered with {@link #registerPhoneAccount} and
1608 * the user must have enabled the corresponding {@link PhoneAccount}. This can be checked using
1609 * {@link #getPhoneAccount}. Self-managed {@link ConnectionService}s must have
1610 * {@link android.Manifest.permission#MANAGE_OWN_CALLS} to add a new incoming call.
1611 * <p>
Tyler Gunn37653562017-03-13 18:15:15 -07001612 * The incoming call you are adding is assumed to have a video state of
1613 * {@link VideoProfile#STATE_AUDIO_ONLY}, unless the extra value
1614 * {@link #EXTRA_INCOMING_VIDEO_STATE} is specified.
1615 * <p>
Tyler Gunnf5035432017-01-09 09:43:12 -08001616 * Once invoked, this method will cause the system to bind to the {@link ConnectionService}
1617 * associated with the {@link PhoneAccountHandle} and request additional information about the
1618 * call (See {@link ConnectionService#onCreateIncomingConnection}) before starting the incoming
Brad Ebingerec0d3342016-01-29 15:40:43 -08001619 * call UI.
1620 * <p>
Tyler Gunnf5035432017-01-09 09:43:12 -08001621 * For a managed {@link ConnectionService}, a {@link SecurityException} will be thrown if either
1622 * the {@link PhoneAccountHandle} does not correspond to a registered {@link PhoneAccount} or
1623 * the associated {@link PhoneAccount} is not currently enabled by the user.
1624 * <p>
1625 * For a self-managed {@link ConnectionService}, a {@link SecurityException} will be thrown if
1626 * the {@link PhoneAccount} has {@link PhoneAccount#CAPABILITY_SELF_MANAGED} and the calling app
1627 * does not have {@link android.Manifest.permission#MANAGE_OWN_CALLS}.
1628 *
Santos Cordon96efb482014-07-19 14:57:05 -07001629 * @param phoneAccount A {@link PhoneAccountHandle} registered with
1630 * {@link #registerPhoneAccount}.
1631 * @param extras A bundle that will be passed through to
1632 * {@link ConnectionService#onCreateIncomingConnection}.
1633 */
1634 public void addNewIncomingCall(PhoneAccountHandle phoneAccount, Bundle extras) {
1635 try {
1636 if (isServiceConnected()) {
Sanket Padawef6a9e5b2018-01-05 14:26:16 -08001637 if (extras != null && extras.getBoolean(EXTRA_IS_HANDOVER) &&
1638 mContext.getApplicationContext().getApplicationInfo().targetSdkVersion >
1639 Build.VERSION_CODES.O_MR1) {
1640 Log.e("TAG", "addNewIncomingCall failed. Use public api " +
1641 "acceptHandover for API > O-MR1");
Tyler Gunn9ae6db82019-02-13 13:51:18 -08001642 return;
Sanket Padawef6a9e5b2018-01-05 14:26:16 -08001643 }
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001644 getTelecomService().addNewIncomingCall(
Santos Cordon96efb482014-07-19 14:57:05 -07001645 phoneAccount, extras == null ? new Bundle() : extras);
1646 }
1647 } catch (RemoteException e) {
1648 Log.e(TAG, "RemoteException adding a new incoming call: " + phoneAccount, e);
1649 }
1650 }
1651
Nancy Chen0eb1e402014-08-21 22:52:29 -07001652 /**
Yorke Leec3cf9822014-10-02 09:38:39 -07001653 * Registers a new unknown call with Telecom. This can only be called by the system Telephony
1654 * service. This is invoked when Telephony detects a new unknown connection that was neither
1655 * a new incoming call, nor an user-initiated outgoing call.
1656 *
1657 * @param phoneAccount A {@link PhoneAccountHandle} registered with
1658 * {@link #registerPhoneAccount}.
1659 * @param extras A bundle that will be passed through to
1660 * {@link ConnectionService#onCreateIncomingConnection}.
1661 * @hide
1662 */
1663 @SystemApi
1664 public void addNewUnknownCall(PhoneAccountHandle phoneAccount, Bundle extras) {
1665 try {
1666 if (isServiceConnected()) {
1667 getTelecomService().addNewUnknownCall(
1668 phoneAccount, extras == null ? new Bundle() : extras);
1669 }
1670 } catch (RemoteException e) {
1671 Log.e(TAG, "RemoteException adding a new unknown call: " + phoneAccount, e);
1672 }
1673 }
1674
1675 /**
Nancy Chen0eb1e402014-08-21 22:52:29 -07001676 * Processes the specified dial string as an MMI code.
1677 * MMI codes are any sequence of characters entered into the dialpad that contain a "*" or "#".
1678 * Some of these sequences launch special behavior through handled by Telephony.
Nancy Chen95e8a672014-10-16 18:38:21 -07001679 * This method uses the default subscription.
Nancy Chen0eb1e402014-08-21 22:52:29 -07001680 * <p>
1681 * Requires that the method-caller be set as the system dialer app.
1682 * </p>
1683 *
Yorke Leec61d13662015-09-21 17:25:25 -07001684 * Requires permission: {@link android.Manifest.permission#MODIFY_PHONE_STATE}
1685 *
Nancy Chen0eb1e402014-08-21 22:52:29 -07001686 * @param dialString The digits to dial.
1687 * @return True if the digits were processed as an MMI code, false otherwise.
1688 */
Yorke Leec61d13662015-09-21 17:25:25 -07001689 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
Nancy Chen0eb1e402014-08-21 22:52:29 -07001690 public boolean handleMmi(String dialString) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001691 ITelecomService service = getTelecomService();
Nancy Chen0eb1e402014-08-21 22:52:29 -07001692 if (service != null) {
1693 try {
Yorke Leef1a349b2015-04-29 16:16:50 -07001694 return service.handlePinMmi(dialString, mContext.getOpPackageName());
Nancy Chen0eb1e402014-08-21 22:52:29 -07001695 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001696 Log.e(TAG, "Error calling ITelecomService#handlePinMmi", e);
Nancy Chen0eb1e402014-08-21 22:52:29 -07001697 }
1698 }
1699 return false;
1700 }
1701
1702 /**
Nancy Chen95e8a672014-10-16 18:38:21 -07001703 * Processes the specified dial string as an MMI code.
1704 * MMI codes are any sequence of characters entered into the dialpad that contain a "*" or "#".
1705 * Some of these sequences launch special behavior through handled by Telephony.
1706 * <p>
1707 * Requires that the method-caller be set as the system dialer app.
1708 * </p>
1709 *
Yorke Leec61d13662015-09-21 17:25:25 -07001710 * Requires permission: {@link android.Manifest.permission#MODIFY_PHONE_STATE}
1711 *
Nancy Chen95e8a672014-10-16 18:38:21 -07001712 * @param accountHandle The handle for the account the MMI code should apply to.
1713 * @param dialString The digits to dial.
1714 * @return True if the digits were processed as an MMI code, false otherwise.
Nancy Chen95e8a672014-10-16 18:38:21 -07001715 */
Yorke Leec61d13662015-09-21 17:25:25 -07001716 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
Yorke Lee06044272015-04-14 15:16:59 -07001717 public boolean handleMmi(String dialString, PhoneAccountHandle accountHandle) {
Nancy Chen95e8a672014-10-16 18:38:21 -07001718 ITelecomService service = getTelecomService();
1719 if (service != null) {
1720 try {
Yorke Leef1a349b2015-04-29 16:16:50 -07001721 return service.handlePinMmiForPhoneAccount(accountHandle, dialString,
1722 mContext.getOpPackageName());
Nancy Chen95e8a672014-10-16 18:38:21 -07001723 } catch (RemoteException e) {
1724 Log.e(TAG, "Error calling ITelecomService#handlePinMmi", e);
1725 }
1726 }
1727 return false;
1728 }
1729
1730 /**
Yorke Leec61d13662015-09-21 17:25:25 -07001731 * Requires permission: {@link android.Manifest.permission#MODIFY_PHONE_STATE}
1732 *
Nancy Chenb2299c12014-10-29 18:22:11 -07001733 * @param accountHandle The handle for the account to derive an adn query URI for or
1734 * {@code null} to return a URI which will use the default account.
1735 * @return The URI (with the content:// scheme) specific to the specified {@link PhoneAccount}
1736 * for the the content retrieve.
1737 */
Yorke Leec61d13662015-09-21 17:25:25 -07001738 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
Nancy Chenb2299c12014-10-29 18:22:11 -07001739 public Uri getAdnUriForPhoneAccount(PhoneAccountHandle accountHandle) {
1740 ITelecomService service = getTelecomService();
1741 if (service != null && accountHandle != null) {
1742 try {
Yorke Leef1a349b2015-04-29 16:16:50 -07001743 return service.getAdnUriForPhoneAccount(accountHandle, mContext.getOpPackageName());
Nancy Chenb2299c12014-10-29 18:22:11 -07001744 } catch (RemoteException e) {
1745 Log.e(TAG, "Error calling ITelecomService#getAdnUriForPhoneAccount", e);
1746 }
1747 }
1748 return Uri.parse("content://icc/adn");
1749 }
1750
1751 /**
Nancy Chen0eb1e402014-08-21 22:52:29 -07001752 * Removes the missed-call notification if one is present.
1753 * <p>
1754 * Requires that the method-caller be set as the system dialer app.
1755 * </p>
Yorke Leec61d13662015-09-21 17:25:25 -07001756 *
1757 * Requires permission: {@link android.Manifest.permission#MODIFY_PHONE_STATE}
Nancy Chen0eb1e402014-08-21 22:52:29 -07001758 */
Yorke Leec61d13662015-09-21 17:25:25 -07001759 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
Nancy Chen0eb1e402014-08-21 22:52:29 -07001760 public void cancelMissedCallsNotification() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001761 ITelecomService service = getTelecomService();
Nancy Chen0eb1e402014-08-21 22:52:29 -07001762 if (service != null) {
1763 try {
Yorke Leef1a349b2015-04-29 16:16:50 -07001764 service.cancelMissedCallsNotification(mContext.getOpPackageName());
Nancy Chen0eb1e402014-08-21 22:52:29 -07001765 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001766 Log.e(TAG, "Error calling ITelecomService#cancelMissedCallsNotification", e);
Nancy Chen0eb1e402014-08-21 22:52:29 -07001767 }
1768 }
1769 }
1770
1771 /**
1772 * Brings the in-call screen to the foreground if there is an ongoing call. If there is
1773 * currently no ongoing call, then this method does nothing.
1774 * <p>
1775 * Requires that the method-caller be set as the system dialer app or have the
1776 * {@link android.Manifest.permission#READ_PHONE_STATE} permission.
1777 * </p>
1778 *
1779 * @param showDialpad Brings up the in-call dialpad as part of showing the in-call screen.
1780 */
Yorke Leec61d13662015-09-21 17:25:25 -07001781 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
Nancy Chen0eb1e402014-08-21 22:52:29 -07001782 public void showInCallScreen(boolean showDialpad) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001783 ITelecomService service = getTelecomService();
Nancy Chen0eb1e402014-08-21 22:52:29 -07001784 if (service != null) {
1785 try {
Svet Ganov16a16892015-04-16 10:32:04 -07001786 service.showInCallScreen(showDialpad, mContext.getOpPackageName());
Nancy Chen0eb1e402014-08-21 22:52:29 -07001787 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001788 Log.e(TAG, "Error calling ITelecomService#showCallScreen", e);
Nancy Chen0eb1e402014-08-21 22:52:29 -07001789 }
1790 }
1791 }
1792
Yorke Lee3e56ba12015-04-23 12:32:36 -07001793 /**
1794 * Places a new outgoing call to the provided address using the system telecom service with
1795 * the specified extras.
1796 *
1797 * This method is equivalent to placing an outgoing call using {@link Intent#ACTION_CALL},
1798 * except that the outgoing call will always be sent via the system telecom service. If
1799 * method-caller is either the user selected default dialer app or preloaded system dialer
1800 * app, then emergency calls will also be allowed.
1801 *
Tyler Gunnf5035432017-01-09 09:43:12 -08001802 * Placing a call via a managed {@link ConnectionService} requires permission:
1803 * {@link android.Manifest.permission#CALL_PHONE}
Yorke Lee3e56ba12015-04-23 12:32:36 -07001804 *
1805 * Usage example:
1806 * <pre>
1807 * Uri uri = Uri.fromParts("tel", "12345", null);
1808 * Bundle extras = new Bundle();
1809 * extras.putBoolean(TelecomManager.EXTRA_START_CALL_WITH_SPEAKERPHONE, true);
1810 * telecomManager.placeCall(uri, extras);
1811 * </pre>
1812 *
Santos Cordon7a060d52015-06-19 14:52:04 -07001813 * The following keys are supported in the supplied extras.
1814 * <ul>
1815 * <li>{@link #EXTRA_OUTGOING_CALL_EXTRAS}</li>
1816 * <li>{@link #EXTRA_PHONE_ACCOUNT_HANDLE}</li>
1817 * <li>{@link #EXTRA_START_CALL_WITH_SPEAKERPHONE}</li>
1818 * <li>{@link #EXTRA_START_CALL_WITH_VIDEO_STATE}</li>
1819 * </ul>
Tyler Gunnf5035432017-01-09 09:43:12 -08001820 * <p>
1821 * An app which implements the self-managed {@link ConnectionService} API uses
1822 * {@link #placeCall(Uri, Bundle)} to inform Telecom of a new outgoing call. A self-managed
1823 * {@link ConnectionService} must include {@link #EXTRA_PHONE_ACCOUNT_HANDLE} to specify its
1824 * associated {@link android.telecom.PhoneAccountHandle}.
1825 *
1826 * Self-managed {@link ConnectionService}s require permission
1827 * {@link android.Manifest.permission#MANAGE_OWN_CALLS}.
Santos Cordon7a060d52015-06-19 14:52:04 -07001828 *
Brad Ebinger3636d742019-05-21 15:28:19 -07001829 * <p class="note"><strong>Note:</strong> If this method is used to place an emergency call, it
1830 * is not guaranteed that the call will be placed on the {@link PhoneAccount} provided in
1831 * the {@link #EXTRA_PHONE_ACCOUNT_HANDLE} extra (if specified) and may be placed on another
1832 * {@link PhoneAccount} with the {@link PhoneAccount#CAPABILITY_PLACE_EMERGENCY_CALLS}
1833 * capability, depending on external factors, such as network conditions and Modem/SIM status.
1834 * </p>
1835 *
Yorke Lee3e56ba12015-04-23 12:32:36 -07001836 * @param address The address to make the call to.
1837 * @param extras Bundle of extras to use with the call.
1838 */
Tyler Gunnf5035432017-01-09 09:43:12 -08001839 @RequiresPermission(anyOf = {android.Manifest.permission.CALL_PHONE,
1840 android.Manifest.permission.MANAGE_OWN_CALLS})
Yorke Lee3e56ba12015-04-23 12:32:36 -07001841 public void placeCall(Uri address, Bundle extras) {
1842 ITelecomService service = getTelecomService();
1843 if (service != null) {
Yorke Leea5d5c1d2015-05-05 16:25:55 -07001844 if (address == null) {
1845 Log.w(TAG, "Cannot place call to empty address.");
1846 }
Yorke Lee3e56ba12015-04-23 12:32:36 -07001847 try {
Yorke Leea5d5c1d2015-05-05 16:25:55 -07001848 service.placeCall(address, extras == null ? new Bundle() : extras,
1849 mContext.getOpPackageName());
Yorke Lee3e56ba12015-04-23 12:32:36 -07001850 } catch (RemoteException e) {
1851 Log.e(TAG, "Error calling ITelecomService#placeCall", e);
1852 }
1853 }
1854 }
1855
Santos Cordon91371dc02015-05-08 13:52:09 -07001856 /**
1857 * Enables and disables specified phone account.
1858 *
1859 * @param handle Handle to the phone account.
1860 * @param isEnabled Enable state of the phone account.
1861 * @hide
1862 */
1863 @SystemApi
Jeff Sharkeybfc4fcd2017-06-05 17:38:17 -06001864 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
Santos Cordon91371dc02015-05-08 13:52:09 -07001865 public void enablePhoneAccount(PhoneAccountHandle handle, boolean isEnabled) {
1866 ITelecomService service = getTelecomService();
1867 if (service != null) {
1868 try {
1869 service.enablePhoneAccount(handle, isEnabled);
1870 } catch (RemoteException e) {
1871 Log.e(TAG, "Error enablePhoneAbbount", e);
1872 }
1873 }
1874 }
1875
Hall Liu0464b9b2016-01-12 15:32:58 -08001876 /**
1877 * Dumps telecom analytics for uploading.
1878 *
1879 * @return
1880 * @hide
1881 */
1882 @SystemApi
1883 @RequiresPermission(Manifest.permission.DUMP)
Hall Liu057def52016-05-05 17:17:07 -07001884 public TelecomAnalytics dumpAnalytics() {
Hall Liu0464b9b2016-01-12 15:32:58 -08001885 ITelecomService service = getTelecomService();
Hall Liu057def52016-05-05 17:17:07 -07001886 TelecomAnalytics result = null;
Hall Liu0464b9b2016-01-12 15:32:58 -08001887 if (service != null) {
1888 try {
1889 result = service.dumpCallAnalytics();
1890 } catch (RemoteException e) {
1891 Log.e(TAG, "Error dumping call analytics", e);
1892 }
1893 }
1894 return result;
1895 }
1896
Abhijith Shastry1908cb842016-02-02 11:10:19 -08001897 /**
Abhijith Shastrya26fe992016-02-29 11:40:24 -08001898 * Creates the {@link Intent} which can be used with {@link Context#startActivity(Intent)} to
1899 * launch the activity to manage blocked numbers.
Abhijith Shastryec30d2f2016-03-04 16:46:08 -08001900 * <p> The activity will display the UI to manage blocked numbers only if
Abhijith Shastrya26fe992016-02-29 11:40:24 -08001901 * {@link android.provider.BlockedNumberContract#canCurrentUserBlockNumbers(Context)} returns
1902 * {@code true} for the current user.
1903 */
1904 public Intent createManageBlockedNumbersIntent() {
1905 ITelecomService service = getTelecomService();
1906 Intent result = null;
1907 if (service != null) {
1908 try {
1909 result = service.createManageBlockedNumbersIntent();
1910 } catch (RemoteException e) {
1911 Log.e(TAG, "Error calling ITelecomService#createManageBlockedNumbersIntent", e);
1912 }
1913 }
1914 return result;
1915 }
1916
Fan Zhang5431ef52019-10-14 13:43:46 -07001917
1918 /**
1919 * Creates the {@link Intent} which can be used with {@link Context#startActivity(Intent)} to
1920 * launch the activity for emergency dialer.
1921 *
1922 * @param number Optional number to call in emergency dialer
1923 * @hide
1924 */
1925 @SystemApi
1926 @NonNull
1927 public Intent createLaunchEmergencyDialerIntent(@Nullable String number) {
1928 ITelecomService service = getTelecomService();
1929 Intent result = null;
1930 if (service != null) {
1931 try {
1932 result = service.createLaunchEmergencyDialerIntent(number);
1933 } catch (RemoteException e) {
1934 Log.e(TAG, "Error createLaunchEmergencyDialerIntent", e);
1935 }
1936 }
1937 return result;
1938 }
1939
Tyler Gunnf5035432017-01-09 09:43:12 -08001940 /**
1941 * Determines whether Telecom would permit an incoming call to be added via the
1942 * {@link #addNewIncomingCall(PhoneAccountHandle, Bundle)} API for the specified
1943 * {@link PhoneAccountHandle}.
1944 * <p>
1945 * A {@link ConnectionService} may not add a call for the specified {@link PhoneAccountHandle}
1946 * in the following situations:
1947 * <ul>
1948 * <li>{@link PhoneAccount} does not have property
1949 * {@link PhoneAccount#CAPABILITY_SELF_MANAGED} set (i.e. it is a managed
1950 * {@link ConnectionService}), and the active or held call limit has
1951 * been reached.</li>
1952 * <li>There is an ongoing emergency call.</li>
1953 * </ul>
1954 *
1955 * @param phoneAccountHandle The {@link PhoneAccountHandle} the call will be added for.
1956 * @return {@code true} if telecom will permit an incoming call to be added, {@code false}
1957 * otherwise.
1958 */
1959 public boolean isIncomingCallPermitted(PhoneAccountHandle phoneAccountHandle) {
Tyler Gunn44e01912017-01-31 10:49:05 -08001960 if (phoneAccountHandle == null) {
1961 return false;
1962 }
1963
Tyler Gunnf5035432017-01-09 09:43:12 -08001964 ITelecomService service = getTelecomService();
1965 if (service != null) {
1966 try {
1967 return service.isIncomingCallPermitted(phoneAccountHandle);
1968 } catch (RemoteException e) {
1969 Log.e(TAG, "Error isIncomingCallPermitted", e);
1970 }
1971 }
1972 return false;
1973 }
1974
1975 /**
1976 * Determines whether Telecom would permit an outgoing call to be placed via the
1977 * {@link #placeCall(Uri, Bundle)} API for the specified {@link PhoneAccountHandle}.
1978 * <p>
1979 * A {@link ConnectionService} may not place a call for the specified {@link PhoneAccountHandle}
1980 * in the following situations:
1981 * <ul>
1982 * <li>{@link PhoneAccount} does not have property
1983 * {@link PhoneAccount#CAPABILITY_SELF_MANAGED} set (i.e. it is a managed
1984 * {@link ConnectionService}), and the active, held or ringing call limit has
1985 * been reached.</li>
1986 * <li>{@link PhoneAccount} has property {@link PhoneAccount#CAPABILITY_SELF_MANAGED} set
1987 * (i.e. it is a self-managed {@link ConnectionService} and there is an ongoing call in
1988 * another {@link ConnectionService}.</li>
1989 * <li>There is an ongoing emergency call.</li>
1990 * </ul>
1991 *
1992 * @param phoneAccountHandle The {@link PhoneAccountHandle} the call will be added for.
1993 * @return {@code true} if telecom will permit an outgoing call to be placed, {@code false}
1994 * otherwise.
1995 */
1996 public boolean isOutgoingCallPermitted(PhoneAccountHandle phoneAccountHandle) {
1997 ITelecomService service = getTelecomService();
1998 if (service != null) {
1999 try {
2000 return service.isOutgoingCallPermitted(phoneAccountHandle);
2001 } catch (RemoteException e) {
2002 Log.e(TAG, "Error isOutgoingCallPermitted", e);
2003 }
2004 }
2005 return false;
2006 }
2007
Sanket Padawea8eddd42017-11-03 11:07:35 -07002008 /**
Tyler Gunn9d127732018-03-02 15:45:51 -08002009 * Called by an app to indicate that it wishes to accept the handover of an ongoing call to a
2010 * {@link PhoneAccountHandle} it defines.
2011 * <p>
2012 * A call handover is the process where an ongoing call is transferred from one app (i.e.
2013 * {@link ConnectionService} to another app. The user could, for example, choose to continue a
2014 * mobile network call in a video calling app. The mobile network call via the Telephony stack
2015 * is referred to as the source of the handover, and the video calling app is referred to as the
2016 * destination.
2017 * <p>
2018 * When considering a handover scenario the <em>initiating</em> device is where a user initiated
2019 * the handover process (e.g. by calling {@link android.telecom.Call#handoverTo(
2020 * PhoneAccountHandle, int, Bundle)}, and the other device is considered the <em>receiving</em>
2021 * device.
2022 * <p>
2023 * For a full discussion of the handover process and the APIs involved, see
2024 * {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int, Bundle)}.
2025 * <p>
2026 * This method is called from the <em>receiving</em> side of a handover to indicate a desire to
2027 * accept the handover of an ongoing call to another {@link ConnectionService} identified by
Sanket Padawea8eddd42017-11-03 11:07:35 -07002028 * {@link PhoneAccountHandle} destAcct. For managed {@link ConnectionService}s, the specified
2029 * {@link PhoneAccountHandle} must have been registered with {@link #registerPhoneAccount} and
2030 * the user must have enabled the corresponding {@link PhoneAccount}. This can be checked using
2031 * {@link #getPhoneAccount}. Self-managed {@link ConnectionService}s must have
2032 * {@link android.Manifest.permission#MANAGE_OWN_CALLS} to handover a call to it.
2033 * <p>
2034 * Once invoked, this method will cause the system to bind to the {@link ConnectionService}
2035 * associated with the {@link PhoneAccountHandle} destAcct and call
2036 * (See {@link ConnectionService#onCreateIncomingHandoverConnection}).
2037 * <p>
2038 * For a managed {@link ConnectionService}, a {@link SecurityException} will be thrown if either
2039 * the {@link PhoneAccountHandle} destAcct does not correspond to a registered
2040 * {@link PhoneAccount} or the associated {@link PhoneAccount} is not currently enabled by the
2041 * user.
2042 * <p>
2043 * For a self-managed {@link ConnectionService}, a {@link SecurityException} will be thrown if
2044 * the calling app does not have {@link android.Manifest.permission#MANAGE_OWN_CALLS}.
2045 *
2046 * @param srcAddr The {@link android.net.Uri} of the ongoing call to handover to the caller’s
2047 * {@link ConnectionService}.
2048 * @param videoState Video state after the handover.
2049 * @param destAcct The {@link PhoneAccountHandle} registered to the calling package.
2050 */
Tyler Gunn9d127732018-03-02 15:45:51 -08002051 public void acceptHandover(Uri srcAddr, @VideoProfile.VideoState int videoState,
2052 PhoneAccountHandle destAcct) {
Sanket Padawea8eddd42017-11-03 11:07:35 -07002053 try {
2054 if (isServiceConnected()) {
2055 getTelecomService().acceptHandover(srcAddr, videoState, destAcct);
2056 }
2057 } catch (RemoteException e) {
2058 Log.e(TAG, "RemoteException acceptHandover: " + e);
2059 }
2060 }
Tyler Gunnf5035432017-01-09 09:43:12 -08002061
Tyler Gunn5bd90852018-09-21 09:37:07 -07002062 /**
2063 * Determines if there is an ongoing emergency call. This can be either an outgoing emergency
2064 * call, as identified by the dialed number, or because a call was identified by the network
2065 * as an emergency call.
2066 * @return {@code true} if there is an ongoing emergency call, {@code false} otherwise.
2067 * @hide
2068 */
2069 @SystemApi
Tyler Gunn6c14a6992019-02-04 15:12:06 -08002070 @TestApi
Tyler Gunn5bd90852018-09-21 09:37:07 -07002071 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2072 public boolean isInEmergencyCall() {
2073 try {
2074 if (isServiceConnected()) {
2075 return getTelecomService().isInEmergencyCall();
2076 }
2077 } catch (RemoteException e) {
2078 Log.e(TAG, "RemoteException isInEmergencyCall: " + e);
2079 return false;
2080 }
2081 return false;
2082 }
2083
Tyler Gunnc37445c2018-09-28 16:16:20 -07002084 /**
2085 * Handles {@link Intent#ACTION_CALL} intents trampolined from UserCallActivity.
2086 * @param intent The {@link Intent#ACTION_CALL} intent to handle.
Brad Ebingera9a33e12019-09-27 16:55:35 -07002087 * @param callingPackageProxy The original package that called this before it was trampolined.
Tyler Gunnc37445c2018-09-28 16:16:20 -07002088 * @hide
2089 */
Brad Ebingera9a33e12019-09-27 16:55:35 -07002090 public void handleCallIntent(Intent intent, String callingPackageProxy) {
Tyler Gunnc37445c2018-09-28 16:16:20 -07002091 try {
2092 if (isServiceConnected()) {
Brad Ebingera9a33e12019-09-27 16:55:35 -07002093 getTelecomService().handleCallIntent(intent, callingPackageProxy);
Tyler Gunnc37445c2018-09-28 16:16:20 -07002094 }
2095 } catch (RemoteException e) {
2096 Log.e(TAG, "RemoteException handleCallIntent: " + e);
2097 }
Tyler Gunnc37445c2018-09-28 16:16:20 -07002098 }
2099
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002100 private ITelecomService getTelecomService() {
Hall Liue1bc2ec2015-10-09 15:58:37 -07002101 if (mTelecomServiceOverride != null) {
2102 return mTelecomServiceOverride;
2103 }
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002104 return ITelecomService.Stub.asInterface(ServiceManager.getService(Context.TELECOM_SERVICE));
Santos Cordon6c7a3882014-06-25 15:30:08 -07002105 }
Santos Cordon9eb45932014-06-27 12:28:43 -07002106
2107 private boolean isServiceConnected() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002108 boolean isConnected = getTelecomService() != null;
Santos Cordon9eb45932014-06-27 12:28:43 -07002109 if (!isConnected) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002110 Log.w(TAG, "Telecom Service not found.");
Santos Cordon9eb45932014-06-27 12:28:43 -07002111 }
2112 return isConnected;
2113 }
Evan Charlton235c1592014-09-05 15:41:23 +00002114}