blob: b5b4e5f5450613e5ff34e10d4afcdd79f4b4ae5d [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
Yorke Leec61d1362015-09-21 17:25:25 -070017import android.annotation.RequiresPermission;
Santos Cordon6c7a3882014-06-25 15:30:08 -070018import android.annotation.SystemApi;
19import android.content.ComponentName;
Yorke Leeb4ce1432014-06-09 13:53:23 -070020import android.content.Context;
Yorke Lee3e56ba12015-04-23 12:32:36 -070021import android.content.Intent;
Nancy Chenb2299c12014-10-29 18:22:11 -070022import android.net.Uri;
Santos Cordon96efb482014-07-19 14:57:05 -070023import android.os.Bundle;
Santos Cordon6c7a3882014-06-25 15:30:08 -070024import android.os.RemoteException;
25import android.os.ServiceManager;
Yorke Lee2ae312e2014-09-12 17:58:48 -070026import android.telephony.TelephonyManager;
Anthony Lee67279262014-10-27 11:28:40 -070027import android.text.TextUtils;
Santos Cordon6c7a3882014-06-25 15:30:08 -070028import android.util.Log;
Yorke Leeb4ce1432014-06-09 13:53:23 -070029
Tyler Gunnef9f6f92014-09-12 22:16:17 -070030import com.android.internal.telecom.ITelecomService;
Yorke Leeb4ce1432014-06-09 13:53:23 -070031
Jay Shrauner7746a942014-08-26 12:15:15 -070032import java.util.ArrayList;
Tyler Gunna1ed7d12014-09-08 09:52:22 -070033import java.util.Collections;
Ihab Awad807fe0a2014-07-09 12:30:52 -070034import java.util.List;
35
Yorke Leeb4ce1432014-06-09 13:53:23 -070036/**
Santos Cordond9e614f2014-10-28 13:10:36 -070037 * Provides access to information about active calls and registration/call-management functionality.
Evan Charlton0e094d92014-11-08 15:49:16 -080038 * Apps can use methods in this class to determine the current call state.
Santos Cordond9e614f2014-10-28 13:10:36 -070039 * <p>
40 * Apps do not instantiate this class directly; instead, they retrieve a reference to an instance
41 * through {@link Context#getSystemService Context.getSystemService(Context.TELECOM_SERVICE)}.
42 * <p>
43 * Note that access to some telecom information is permission-protected. Your app cannot access the
44 * protected information or gain access to protected functionality unless it has the appropriate
45 * permissions declared in its manifest file. Where permissions apply, they are noted in the method
46 * descriptions.
Yorke Leeb4ce1432014-06-09 13:53:23 -070047 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -070048public class TelecomManager {
Ihab Awad807fe0a2014-07-09 12:30:52 -070049
Evan Charlton10197192014-07-19 15:00:29 -070050 /**
Santos Cordon96efb482014-07-19 14:57:05 -070051 * Activity action: Starts the UI for handing an incoming call. This intent starts the in-call
Tyler Gunnef9f6f92014-09-12 22:16:17 -070052 * UI by notifying the Telecom system that an incoming call exists for a specific call service
53 * (see {@link android.telecom.ConnectionService}). Telecom reads the Intent extras to find
54 * and bind to the appropriate {@link android.telecom.ConnectionService} which Telecom will
Santos Cordon96efb482014-07-19 14:57:05 -070055 * ultimately use to control and get information about the call.
56 * <p>
57 * Input: get*Extra field {@link #EXTRA_PHONE_ACCOUNT_HANDLE} contains the component name of the
Tyler Gunnef9f6f92014-09-12 22:16:17 -070058 * {@link android.telecom.ConnectionService} that Telecom should bind to. Telecom will then
Evan Charlton10197192014-07-19 15:00:29 -070059 * ask the connection service for more information about the call prior to showing any UI.
Evan Charlton10197192014-07-19 15:00:29 -070060 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -070061 public static final String ACTION_INCOMING_CALL = "android.telecom.action.INCOMING_CALL";
Evan Charlton10197192014-07-19 15:00:29 -070062
63 /**
Yorke Leec3cf9822014-10-02 09:38:39 -070064 * Similar to {@link #ACTION_INCOMING_CALL}, but is used only by Telephony to add a new
65 * sim-initiated MO call for carrier testing.
66 * @hide
67 */
68 public static final String ACTION_NEW_UNKNOWN_CALL = "android.telecom.action.NEW_UNKNOWN_CALL";
69
70 /**
Santos Cordon895d4b82015-06-25 16:41:48 -070071 * An {@link android.content.Intent} action sent by the telecom framework to start a
72 * configuration dialog for a registered {@link PhoneAccount}. There is no default dialog
73 * and each app that registers a {@link PhoneAccount} should provide one if desired.
74 * <p>
75 * A user can access the list of enabled {@link android.telecom.PhoneAccount}s through the Phone
76 * app's settings menu. For each entry, the settings app will add a click action. When
77 * triggered, the click-action will start this intent along with the extra
78 * {@link #EXTRA_PHONE_ACCOUNT_HANDLE} to indicate the {@link PhoneAccount} to configure. If the
79 * {@link PhoneAccount} package does not register an {@link android.app.Activity} for this
80 * intent, then it will not be sent.
Evan Charlton10197192014-07-19 15:00:29 -070081 */
Santos Cordon895d4b82015-06-25 16:41:48 -070082 public static final String ACTION_CONFIGURE_PHONE_ACCOUNT =
83 "android.telecom.action.CONFIGURE_PHONE_ACCOUNT";
Evan Charlton10197192014-07-19 15:00:29 -070084
85 /**
Andrew Lee873cfbf2015-02-26 15:22:00 -080086 * The {@link android.content.Intent} action used to show the call accessibility settings page.
87 */
88 public static final String ACTION_SHOW_CALL_ACCESSIBILITY_SETTINGS =
89 "android.telecom.action.SHOW_CALL_ACCESSIBILITY_SETTINGS";
90
91 /**
Yorke Lee3818a892014-07-21 15:57:17 -070092 * The {@link android.content.Intent} action used to show the call settings page.
93 */
94 public static final String ACTION_SHOW_CALL_SETTINGS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -070095 "android.telecom.action.SHOW_CALL_SETTINGS";
Yorke Lee3818a892014-07-21 15:57:17 -070096
97 /**
Andrew Lee866080f2015-02-19 12:05:33 -080098 * The {@link android.content.Intent} action used to show the respond via SMS settings page.
99 */
100 public static final String ACTION_SHOW_RESPOND_VIA_SMS_SETTINGS =
101 "android.telecom.action.SHOW_RESPOND_VIA_SMS_SETTINGS";
102
103 /**
Evan Charlton6d8604f2014-09-04 12:38:17 -0700104 * The {@link android.content.Intent} action used to show the settings page used to configure
105 * {@link PhoneAccount} preferences.
106 */
107 public static final String ACTION_CHANGE_PHONE_ACCOUNTS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700108 "android.telecom.action.CHANGE_PHONE_ACCOUNTS";
Evan Charlton6d8604f2014-09-04 12:38:17 -0700109
110 /**
Santos Cordonc66f3ba2015-02-27 15:22:07 -0800111 * The {@link android.content.Intent} action used indicate that a new phone account was
112 * just registered.
113 * @hide
114 */
115 @SystemApi
116 public static final String ACTION_PHONE_ACCOUNT_REGISTERED =
117 "android.telecom.action.PHONE_ACCOUNT_REGISTERED";
118
119 /**
Bryce Lee30b0aa02015-09-23 21:53:53 -0700120 * The {@link android.content.Intent} action used indicate that a phone account was
121 * just unregistered.
122 * @hide
123 */
124 @SystemApi
125 public static final String ACTION_PHONE_ACCOUNT_UNREGISTERED =
126 "android.telecom.action.PHONE_ACCOUNT_UNREGISTERED";
127
128 /**
Yorke Lee1011f482015-04-23 15:58:27 -0700129 * Activity action: Shows a dialog asking the user whether or not they want to replace the
130 * current default Dialer with the one specified in
131 * {@link #EXTRA_CHANGE_DEFAULT_DIALER_PACKAGE_NAME}.
132 *
133 * Usage example:
134 * <pre>
135 * Intent intent = new Intent(TelecomManager.ACTION_CHANGE_DEFAULT_DIALER);
136 * intent.putExtra(TelecomManager.EXTRA_CHANGE_DEFAULT_DIALER_PACKAGE_NAME,
137 * getActivity().getPackageName());
138 * startActivity(intent);
139 * </pre>
140 */
141 public static final String ACTION_CHANGE_DEFAULT_DIALER =
142 "android.telecom.action.CHANGE_DEFAULT_DIALER";
143
144 /**
Yorke Lee107c4ce2015-06-15 12:08:24 -0700145 * Broadcast intent action indicating that the current default dialer has changed.
146 * The string extra {@link #EXTRA_CHANGE_DEFAULT_DIALER_PACKAGE_NAME} will contain the
147 * name of the package that the default dialer was changed to.
148 *
149 * @see #EXTRA_CHANGE_DEFAULT_DIALER_PACKAGE_NAME
150 */
151 public static final String ACTION_DEFAULT_DIALER_CHANGED =
152 "android.telecom.action.DEFAULT_DIALER_CHANGED";
153
154 /**
Yorke Lee1011f482015-04-23 15:58:27 -0700155 * Extra value used to provide the package name for {@link #ACTION_CHANGE_DEFAULT_DIALER}.
156 */
157 public static final String EXTRA_CHANGE_DEFAULT_DIALER_PACKAGE_NAME =
158 "android.telecom.extra.CHANGE_DEFAULT_DIALER_PACKAGE_NAME";
159
160 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700161 * Optional extra for {@link android.content.Intent#ACTION_CALL} containing a boolean that
162 * determines whether the speakerphone should be automatically turned on for an outgoing call.
Evan Charlton10197192014-07-19 15:00:29 -0700163 */
164 public static final String EXTRA_START_CALL_WITH_SPEAKERPHONE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700165 "android.telecom.extra.START_CALL_WITH_SPEAKERPHONE";
Evan Charlton10197192014-07-19 15:00:29 -0700166
167 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700168 * Optional extra for {@link android.content.Intent#ACTION_CALL} containing an integer that
169 * determines the desired video state for an outgoing call.
Santos Cordon96efb482014-07-19 14:57:05 -0700170 * Valid options:
Yorke Lee32f24732015-05-12 16:18:03 -0700171 * {@link VideoProfile#STATE_AUDIO_ONLY},
172 * {@link VideoProfile#STATE_BIDIRECTIONAL},
173 * {@link VideoProfile#STATE_RX_ENABLED},
174 * {@link VideoProfile#STATE_TX_ENABLED}.
Evan Charlton10197192014-07-19 15:00:29 -0700175 */
176 public static final String EXTRA_START_CALL_WITH_VIDEO_STATE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700177 "android.telecom.extra.START_CALL_WITH_VIDEO_STATE";
Evan Charlton10197192014-07-19 15:00:29 -0700178
179 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700180 * The extra used with an {@link android.content.Intent#ACTION_CALL} and
181 * {@link android.content.Intent#ACTION_DIAL} {@code Intent} to specify a
182 * {@link PhoneAccountHandle} to use when making the call.
Evan Charlton10197192014-07-19 15:00:29 -0700183 * <p class="note">
Santos Cordon96efb482014-07-19 14:57:05 -0700184 * Retrieve with {@link android.content.Intent#getParcelableExtra(String)}.
Evan Charlton10197192014-07-19 15:00:29 -0700185 */
Evan Charlton6eb262c2014-07-19 18:18:19 -0700186 public static final String EXTRA_PHONE_ACCOUNT_HANDLE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700187 "android.telecom.extra.PHONE_ACCOUNT_HANDLE";
Evan Charlton10197192014-07-19 15:00:29 -0700188
189 /**
Tyler Gunn335ff2e2015-07-30 14:18:33 -0700190 * Optional extra for {@link android.content.Intent#ACTION_CALL} containing a string call
191 * subject which will be associated with an outgoing call. Should only be specified if the
192 * {@link PhoneAccount} supports the capability {@link PhoneAccount#CAPABILITY_CALL_SUBJECT}.
193 */
194 public static final String EXTRA_CALL_SUBJECT = "android.telecom.extra.CALL_SUBJECT";
195
196 /**
Yorke Lee04ea7d32015-06-05 15:59:18 -0700197 * The extra used by a {@link ConnectionService} to provide the handle of the caller that
198 * has initiated a new incoming call.
199 */
Yorke Lee02fb5bc2015-06-09 12:27:36 -0700200 public static final String EXTRA_INCOMING_CALL_ADDRESS =
201 "android.telecom.extra.INCOMING_CALL_ADDRESS";
Yorke Lee04ea7d32015-06-05 15:59:18 -0700202
203 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700204 * Optional extra for {@link #ACTION_INCOMING_CALL} containing a {@link Bundle} which contains
205 * metadata about the call. This {@link Bundle} will be returned to the
206 * {@link ConnectionService}.
Evan Charlton10197192014-07-19 15:00:29 -0700207 */
208 public static final String EXTRA_INCOMING_CALL_EXTRAS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700209 "android.telecom.extra.INCOMING_CALL_EXTRAS";
Evan Charlton10197192014-07-19 15:00:29 -0700210
211 /**
Nancy Chen10798dc2014-08-08 14:00:25 -0700212 * Optional extra for {@link android.content.Intent#ACTION_CALL} and
213 * {@link android.content.Intent#ACTION_DIAL} {@code Intent} containing a {@link Bundle}
214 * which contains metadata about the call. This {@link Bundle} will be saved into
Santos Cordon7a060d52015-06-19 14:52:04 -0700215 * {@code Call.Details} and passed to the {@link ConnectionService} when placing the call.
Nancy Chen10798dc2014-08-08 14:00:25 -0700216 */
217 public static final String EXTRA_OUTGOING_CALL_EXTRAS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700218 "android.telecom.extra.OUTGOING_CALL_EXTRAS";
Nancy Chen10798dc2014-08-08 14:00:25 -0700219
220 /**
Yorke Leec3cf9822014-10-02 09:38:39 -0700221 * @hide
222 */
223 public static final String EXTRA_UNKNOWN_CALL_HANDLE =
224 "android.telecom.extra.UNKNOWN_CALL_HANDLE";
225
226 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700227 * Optional extra for {@link android.telephony.TelephonyManager#ACTION_PHONE_STATE_CHANGED}
228 * containing the disconnect code.
Evan Charlton10197192014-07-19 15:00:29 -0700229 */
230 public static final String EXTRA_CALL_DISCONNECT_CAUSE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700231 "android.telecom.extra.CALL_DISCONNECT_CAUSE";
Evan Charlton10197192014-07-19 15:00:29 -0700232
233 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700234 * Optional extra for {@link android.telephony.TelephonyManager#ACTION_PHONE_STATE_CHANGED}
235 * containing the disconnect message.
Evan Charlton10197192014-07-19 15:00:29 -0700236 */
237 public static final String EXTRA_CALL_DISCONNECT_MESSAGE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700238 "android.telecom.extra.CALL_DISCONNECT_MESSAGE";
Evan Charlton10197192014-07-19 15:00:29 -0700239
240 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700241 * Optional extra for {@link android.telephony.TelephonyManager#ACTION_PHONE_STATE_CHANGED}
242 * containing the component name of the associated connection service.
Evan Charlton0e094d92014-11-08 15:49:16 -0800243 * @hide
Evan Charlton10197192014-07-19 15:00:29 -0700244 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800245 @SystemApi
Evan Charlton10197192014-07-19 15:00:29 -0700246 public static final String EXTRA_CONNECTION_SERVICE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700247 "android.telecom.extra.CONNECTION_SERVICE";
Evan Charlton10197192014-07-19 15:00:29 -0700248
249 /**
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700250 * An optional {@link android.content.Intent#ACTION_CALL} intent extra denoting the
251 * package name of the app specifying an alternative gateway for the call.
252 * The value is a string.
253 *
254 * (The following comment corresponds to the all GATEWAY_* extras)
255 * An app which sends the {@link android.content.Intent#ACTION_CALL} intent can specify an
256 * alternative address to dial which is different from the one specified and displayed to
257 * the user. This alternative address is referred to as the gateway address.
258 */
259 public static final String GATEWAY_PROVIDER_PACKAGE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700260 "android.telecom.extra.GATEWAY_PROVIDER_PACKAGE";
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700261
262 /**
263 * An optional {@link android.content.Intent#ACTION_CALL} intent extra corresponding to the
264 * original address to dial for the call. This is used when an alternative gateway address is
265 * provided to recall the original address.
266 * The value is a {@link android.net.Uri}.
267 *
268 * (See {@link #GATEWAY_PROVIDER_PACKAGE} for details)
269 */
270 public static final String GATEWAY_ORIGINAL_ADDRESS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700271 "android.telecom.extra.GATEWAY_ORIGINAL_ADDRESS";
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700272
273 /**
Evan Charlton10197192014-07-19 15:00:29 -0700274 * The number which the party on the other side of the line will see (and use to return the
275 * call).
276 * <p>
Santos Cordon96efb482014-07-19 14:57:05 -0700277 * {@link ConnectionService}s which interact with {@link RemoteConnection}s should only populate
278 * this if the {@link android.telephony.TelephonyManager#getLine1Number()} value, as that is the
279 * user's expected caller ID.
Evan Charlton10197192014-07-19 15:00:29 -0700280 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700281 public static final String EXTRA_CALL_BACK_NUMBER = "android.telecom.extra.CALL_BACK_NUMBER";
Evan Charlton10197192014-07-19 15:00:29 -0700282
283 /**
Santos Cordonf2600eb2015-06-22 15:02:20 -0700284 * A boolean meta-data value indicating whether an {@link InCallService} implements an
285 * in-call user interface. Dialer implementations (see {@link #getDefaultDialerPackage()}) which
286 * would also like to replace the in-call interface should set this meta-data to {@code true} in
287 * the manifest registration of their {@link InCallService}.
288 */
289 public static final String METADATA_IN_CALL_SERVICE_UI = "android.telecom.IN_CALL_SERVICE_UI";
290
291 /**
Evan Charlton10197192014-07-19 15:00:29 -0700292 * The dual tone multi-frequency signaling character sent to indicate the dialing system should
293 * pause for a predefined period.
294 */
295 public static final char DTMF_CHARACTER_PAUSE = ',';
296
297 /**
298 * The dual-tone multi-frequency signaling character sent to indicate the dialing system should
299 * wait for user confirmation before proceeding.
300 */
301 public static final char DTMF_CHARACTER_WAIT = ';';
302
303 /**
304 * TTY (teletypewriter) mode is off.
305 *
306 * @hide
307 */
308 public static final int TTY_MODE_OFF = 0;
309
310 /**
311 * TTY (teletypewriter) mode is on. The speaker is off and the microphone is muted. The user
312 * will communicate with the remote party by sending and receiving text messages.
313 *
314 * @hide
315 */
316 public static final int TTY_MODE_FULL = 1;
317
318 /**
319 * TTY (teletypewriter) mode is in hearing carryover mode (HCO). The microphone is muted but the
320 * speaker is on. The user will communicate with the remote party by sending text messages and
321 * hearing an audible reply.
322 *
323 * @hide
324 */
325 public static final int TTY_MODE_HCO = 2;
326
327 /**
328 * TTY (teletypewriter) mode is in voice carryover mode (VCO). The speaker is off but the
329 * microphone is still on. User will communicate with the remote party by speaking and receiving
330 * text message replies.
331 *
332 * @hide
333 */
334 public static final int TTY_MODE_VCO = 3;
335
336 /**
337 * Broadcast intent action indicating that the current TTY mode has changed. An intent extra
338 * provides this state as an int.
Evan Charlton10197192014-07-19 15:00:29 -0700339 *
Santos Cordon96efb482014-07-19 14:57:05 -0700340 * @see #EXTRA_CURRENT_TTY_MODE
Evan Charlton10197192014-07-19 15:00:29 -0700341 * @hide
342 */
343 public static final String ACTION_CURRENT_TTY_MODE_CHANGED =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700344 "android.telecom.action.CURRENT_TTY_MODE_CHANGED";
Evan Charlton10197192014-07-19 15:00:29 -0700345
346 /**
347 * The lookup key for an int that indicates the current TTY mode.
348 * Valid modes are:
349 * - {@link #TTY_MODE_OFF}
350 * - {@link #TTY_MODE_FULL}
351 * - {@link #TTY_MODE_HCO}
352 * - {@link #TTY_MODE_VCO}
353 *
354 * @hide
355 */
356 public static final String EXTRA_CURRENT_TTY_MODE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700357 "android.telecom.intent.extra.CURRENT_TTY_MODE";
Evan Charlton10197192014-07-19 15:00:29 -0700358
359 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700360 * Broadcast intent action indicating that the TTY preferred operating mode has changed. An
361 * intent extra provides the new mode as an int.
Evan Charlton10197192014-07-19 15:00:29 -0700362 *
Santos Cordon96efb482014-07-19 14:57:05 -0700363 * @see #EXTRA_TTY_PREFERRED_MODE
Evan Charlton10197192014-07-19 15:00:29 -0700364 * @hide
365 */
366 public static final String ACTION_TTY_PREFERRED_MODE_CHANGED =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700367 "android.telecom.action.TTY_PREFERRED_MODE_CHANGED";
Evan Charlton10197192014-07-19 15:00:29 -0700368
369 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700370 * The lookup key for an int that indicates preferred TTY mode. Valid modes are: -
371 * {@link #TTY_MODE_OFF} - {@link #TTY_MODE_FULL} - {@link #TTY_MODE_HCO} -
372 * {@link #TTY_MODE_VCO}
Evan Charlton10197192014-07-19 15:00:29 -0700373 *
374 * @hide
375 */
376 public static final String EXTRA_TTY_PREFERRED_MODE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700377 "android.telecom.intent.extra.TTY_PREFERRED";
Evan Charlton10197192014-07-19 15:00:29 -0700378
Nancy Chen9d568c02014-09-08 14:17:59 -0700379 /**
Bryce Lee5e4dd3e2015-08-03 16:59:10 -0700380 * Broadcast intent action for letting custom component know to show the missed call
381 * notification.
382 * @hide
383 */
384 @SystemApi
385 public static final String ACTION_SHOW_MISSED_CALLS_NOTIFICATION =
386 "android.telecom.action.SHOW_MISSED_CALLS_NOTIFICATION";
387
388 /**
389 * The number of calls associated with the notification.
390 * @hide
391 */
392 @SystemApi
393 public static final String EXTRA_NOTIFICATION_COUNT =
394 "android.telecom.extra.NOTIFICATION_COUNT";
395
396 /**
397 * The number associated with the missed calls. This number is only relevant
398 * when EXTRA_NOTIFICATION_COUNT is 1.
399 * @hide
400 */
401 @SystemApi
402 public static final String EXTRA_NOTIFICATION_PHONE_NUMBER =
403 "android.telecom.extra.NOTIFICATION_PHONE_NUMBER";
404
405 /**
Bryce Lee8d41d1d2015-08-10 07:40:42 -0700406 * The intent to clear missed calls.
407 * @hide
408 */
409 @SystemApi
410 public static final String EXTRA_CLEAR_MISSED_CALLS_INTENT =
411 "android.telecom.extra.CLEAR_MISSED_CALLS_INTENT";
412
413 /**
414 * The intent to call back a missed call.
415 * @hide
416 */
417 @SystemApi
418 public static final String EXTRA_CALL_BACK_INTENT =
419 "android.telecom.extra.CALL_BACK_INTENT";
420
421 /**
Nancy Chen9d568c02014-09-08 14:17:59 -0700422 * The following 4 constants define how properties such as phone numbers and names are
423 * displayed to the user.
424 */
425
Santos Cordoned769ae2015-05-13 18:47:38 -0700426 /**
427 * Indicates that the address or number of a call is allowed to be displayed for caller ID.
428 */
Nancy Chen9d568c02014-09-08 14:17:59 -0700429 public static final int PRESENTATION_ALLOWED = 1;
430
Santos Cordoned769ae2015-05-13 18:47:38 -0700431 /**
432 * Indicates that the address or number of a call is blocked by the other party.
433 */
Nancy Chen9d568c02014-09-08 14:17:59 -0700434 public static final int PRESENTATION_RESTRICTED = 2;
435
Santos Cordoned769ae2015-05-13 18:47:38 -0700436 /**
437 * Indicates that the address or number of a call is not specified or known by the carrier.
438 */
Nancy Chen9d568c02014-09-08 14:17:59 -0700439 public static final int PRESENTATION_UNKNOWN = 3;
440
Santos Cordoned769ae2015-05-13 18:47:38 -0700441 /**
442 * Indicates that the address or number of a call belongs to a pay phone.
443 */
Nancy Chen9d568c02014-09-08 14:17:59 -0700444 public static final int PRESENTATION_PAYPHONE = 4;
445
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700446 private static final String TAG = "TelecomManager";
Yorke Leeb4ce1432014-06-09 13:53:23 -0700447
448 private final Context mContext;
Yorke Leeb4ce1432014-06-09 13:53:23 -0700449
Hall Liue1bc2ec2015-10-09 15:58:37 -0700450 private final ITelecomService mTelecomServiceOverride;
451
Santos Cordon6c7a3882014-06-25 15:30:08 -0700452 /**
453 * @hide
454 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700455 public static TelecomManager from(Context context) {
456 return (TelecomManager) context.getSystemService(Context.TELECOM_SERVICE);
Yorke Leeb4ce1432014-06-09 13:53:23 -0700457 }
Santos Cordon6c7a3882014-06-25 15:30:08 -0700458
459 /**
460 * @hide
461 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700462 public TelecomManager(Context context) {
Hall Liue1bc2ec2015-10-09 15:58:37 -0700463 this(context, null);
464 }
465
466 /**
467 * @hide
468 */
469 public TelecomManager(Context context, ITelecomService telecomServiceImpl) {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700470 Context appContext = context.getApplicationContext();
471 if (appContext != null) {
472 mContext = appContext;
473 } else {
474 mContext = context;
475 }
Hall Liue1bc2ec2015-10-09 15:58:37 -0700476 mTelecomServiceOverride = telecomServiceImpl;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700477 }
478
479 /**
Santos Cordon91371dc2015-05-08 13:52:09 -0700480 * Return the {@link PhoneAccount} which will be used to place outgoing calls to addresses with
481 * the specified {@code uriScheme}. This {@link PhoneAccount} will always be a member of the
482 * list which is returned from invoking {@link #getCallCapablePhoneAccounts()}. The specific
483 * account returned depends on the following priorities:
484 * <ul>
485 * <li> If the user-selected default {@link PhoneAccount} supports the specified scheme, it will
486 * be returned.
487 * </li>
488 * <li> If there exists only one {@link PhoneAccount} that supports the specified scheme, it
489 * will be returned.
490 * </li>
491 * </ul>
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700492 * <p>
Santos Cordon91371dc2015-05-08 13:52:09 -0700493 * If no {@link PhoneAccount} fits the criteria above, this method will return {@code null}.
494 *
Yorke Leec61d1362015-09-21 17:25:25 -0700495 * Requires permission: {@link android.Manifest.permission#READ_PHONE_STATE}
496 *
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700497 * @param uriScheme The URI scheme.
Santos Cordon91371dc2015-05-08 13:52:09 -0700498 * @return The {@link PhoneAccountHandle} corresponding to the account to be used.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700499 */
Yorke Leec61d1362015-09-21 17:25:25 -0700500 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700501 public PhoneAccountHandle getDefaultOutgoingPhoneAccount(String uriScheme) {
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700502 try {
503 if (isServiceConnected()) {
Svet Ganov16a16892015-04-16 10:32:04 -0700504 return getTelecomService().getDefaultOutgoingPhoneAccount(uriScheme,
505 mContext.getOpPackageName());
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700506 }
507 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700508 Log.e(TAG, "Error calling ITelecomService#getDefaultOutgoingPhoneAccount", e);
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700509 }
510 return null;
511 }
512
513 /**
Andrew Leed4abbfb2014-09-03 14:58:27 -0700514 * Return the {@link PhoneAccount} which is the user-chosen default for making outgoing phone
515 * calls. This {@code PhoneAccount} will always be a member of the list which is returned from
Nancy Chen210ef032014-09-15 17:58:42 -0700516 * calling {@link #getCallCapablePhoneAccounts()}
Santos Cordon91371dc2015-05-08 13:52:09 -0700517 * <p>
Andrew Leed4abbfb2014-09-03 14:58:27 -0700518 * Apps must be prepared for this method to return {@code null}, indicating that there currently
519 * exists no user-chosen default {@code PhoneAccount}.
520 *
521 * @return The user outgoing phone account selected by the user.
Jay Shrauner225ccad2015-04-15 15:51:15 -0700522 * @hide
Andrew Leed4abbfb2014-09-03 14:58:27 -0700523 */
524 public PhoneAccountHandle getUserSelectedOutgoingPhoneAccount() {
525 try {
526 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700527 return getTelecomService().getUserSelectedOutgoingPhoneAccount();
Andrew Leed4abbfb2014-09-03 14:58:27 -0700528 }
529 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700530 Log.e(TAG, "Error calling ITelecomService#getUserSelectedOutgoingPhoneAccount", e);
Andrew Leed4abbfb2014-09-03 14:58:27 -0700531 }
532 return null;
533 }
534
535 /**
Santos Cordon91371dc2015-05-08 13:52:09 -0700536 * Sets the user-chosen default for making outgoing phone calls.
Andrew Lee59cac3a2014-08-28 16:50:10 -0700537 * @hide
538 */
Andrew Leed4abbfb2014-09-03 14:58:27 -0700539 public void setUserSelectedOutgoingPhoneAccount(PhoneAccountHandle accountHandle) {
Andrew Lee59cac3a2014-08-28 16:50:10 -0700540 try {
541 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700542 getTelecomService().setUserSelectedOutgoingPhoneAccount(accountHandle);
Andrew Lee59cac3a2014-08-28 16:50:10 -0700543 }
544 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700545 Log.e(TAG, "Error calling ITelecomService#setUserSelectedOutgoingPhoneAccount");
Andrew Lee59cac3a2014-08-28 16:50:10 -0700546 }
547 }
548
549 /**
Andrew Lee59cac3a2014-08-28 16:50:10 -0700550 * Returns the current SIM call manager. Apps must be prepared for this method to return
551 * {@code null}, indicating that there currently exists no user-chosen default
552 * {@code PhoneAccount}.
Santos Cordon91371dc2015-05-08 13:52:09 -0700553 *
Andrew Lee59cac3a2014-08-28 16:50:10 -0700554 * @return The phone account handle of the current sim call manager.
Andrew Lee59cac3a2014-08-28 16:50:10 -0700555 */
556 public PhoneAccountHandle getSimCallManager() {
557 try {
558 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700559 return getTelecomService().getSimCallManager();
Andrew Lee59cac3a2014-08-28 16:50:10 -0700560 }
561 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700562 Log.e(TAG, "Error calling ITelecomService#getSimCallManager");
Andrew Lee59cac3a2014-08-28 16:50:10 -0700563 }
564 return null;
565 }
566
567 /**
Sailesh Nepalcf855622015-07-28 19:22:14 -0700568 * Returns the current SIM call manager for the specified user. Apps must be prepared for this
569 * method to return {@code null}, indicating that there currently exists no user-chosen default
570 * {@code PhoneAccount}.
571 *
572 * @return The phone account handle of the current sim call manager.
573 *
574 * @hide
575 */
576 public PhoneAccountHandle getSimCallManager(int userId) {
577 try {
578 if (isServiceConnected()) {
579 return getTelecomService().getSimCallManagerForUser(userId);
580 }
581 } catch (RemoteException e) {
582 Log.e(TAG, "Error calling ITelecomService#getSimCallManagerForUser");
583 }
584 return null;
585 }
586
587 /**
Evan Charltoneb0a8d52014-09-04 12:03:34 -0700588 * Returns the current connection manager. Apps must be prepared for this method to return
589 * {@code null}, indicating that there currently exists no user-chosen default
590 * {@code PhoneAccount}.
591 *
592 * @return The phone account handle of the current connection manager.
Evan Charlton0e094d92014-11-08 15:49:16 -0800593 * @hide
Evan Charltoneb0a8d52014-09-04 12:03:34 -0700594 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800595 @SystemApi
Evan Charltoneb0a8d52014-09-04 12:03:34 -0700596 public PhoneAccountHandle getConnectionManager() {
597 return getSimCallManager();
598 }
599
600 /**
Nancy Chen210ef032014-09-15 17:58:42 -0700601 * Returns a list of the {@link PhoneAccountHandle}s which can be used to make and receive phone
602 * calls which support the specified URI scheme.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700603 * <P>
604 * For example, invoking with {@code "tel"} will find all {@link PhoneAccountHandle}s which
605 * support telephone calls (e.g. URIs such as {@code tel:555-555-1212}). Invoking with
606 * {@code "sip"} will find all {@link PhoneAccountHandle}s which support SIP calls (e.g. URIs
607 * such as {@code sip:example@sipexample.com}).
608 *
609 * @param uriScheme The URI scheme.
610 * @return A list of {@code PhoneAccountHandle} objects supporting the URI scheme.
Evan Charlton0e094d92014-11-08 15:49:16 -0800611 * @hide
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700612 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800613 @SystemApi
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700614 public List<PhoneAccountHandle> getPhoneAccountsSupportingScheme(String uriScheme) {
615 try {
616 if (isServiceConnected()) {
Svet Ganov16a16892015-04-16 10:32:04 -0700617 return getTelecomService().getPhoneAccountsSupportingScheme(uriScheme,
618 mContext.getOpPackageName());
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700619 }
620 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700621 Log.e(TAG, "Error calling ITelecomService#getPhoneAccountsSupportingScheme", e);
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700622 }
623 return new ArrayList<>();
624 }
625
Nancy Chen513c8922014-09-17 14:47:20 -0700626
627 /**
Santos Cordon91371dc2015-05-08 13:52:09 -0700628 * Returns a list of {@link PhoneAccountHandle}s which can be used to make and receive phone
629 * calls. The returned list includes only those accounts which have been explicitly enabled
630 * by the user.
Nancy Chen513c8922014-09-17 14:47:20 -0700631 *
Yorke Leec61d1362015-09-21 17:25:25 -0700632 * Requires permission: {@link android.Manifest.permission#READ_PHONE_STATE}
633 *
Nancy Chen513c8922014-09-17 14:47:20 -0700634 * @see #EXTRA_PHONE_ACCOUNT_HANDLE
635 * @return A list of {@code PhoneAccountHandle} objects.
Nancy Chen513c8922014-09-17 14:47:20 -0700636 */
Yorke Leec61d1362015-09-21 17:25:25 -0700637 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
Nancy Chen513c8922014-09-17 14:47:20 -0700638 public List<PhoneAccountHandle> getCallCapablePhoneAccounts() {
Santos Cordon91371dc2015-05-08 13:52:09 -0700639 return getCallCapablePhoneAccounts(false);
640 }
641
642 /**
643 * Returns a list of {@link PhoneAccountHandle}s including those which have not been enabled
644 * by the user.
645 *
646 * @return A list of {@code PhoneAccountHandle} objects.
647 * @hide
648 */
649 public List<PhoneAccountHandle> getCallCapablePhoneAccounts(boolean includeDisabledAccounts) {
Nancy Chen513c8922014-09-17 14:47:20 -0700650 try {
651 if (isServiceConnected()) {
Santos Cordon91371dc2015-05-08 13:52:09 -0700652 return getTelecomService().getCallCapablePhoneAccounts(
653 includeDisabledAccounts, mContext.getOpPackageName());
Nancy Chen513c8922014-09-17 14:47:20 -0700654 }
655 } catch (RemoteException e) {
Santos Cordon91371dc2015-05-08 13:52:09 -0700656 Log.e(TAG, "Error calling ITelecomService#getCallCapablePhoneAccounts(" +
657 includeDisabledAccounts + ")", e);
Nancy Chen513c8922014-09-17 14:47:20 -0700658 }
659 return new ArrayList<>();
660 }
661
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700662 /**
Nancy Chen513c8922014-09-17 14:47:20 -0700663 * Returns a list of all {@link PhoneAccount}s registered for the calling package.
664 *
665 * @return A list of {@code PhoneAccountHandle} objects.
Evan Charlton0e094d92014-11-08 15:49:16 -0800666 * @hide
Nancy Chen513c8922014-09-17 14:47:20 -0700667 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800668 @SystemApi
Nancy Chen513c8922014-09-17 14:47:20 -0700669 public List<PhoneAccountHandle> getPhoneAccountsForPackage() {
670 try {
671 if (isServiceConnected()) {
672 return getTelecomService().getPhoneAccountsForPackage(mContext.getPackageName());
673 }
674 } catch (RemoteException e) {
675 Log.e(TAG, "Error calling ITelecomService#getPhoneAccountsForPackage", e);
676 }
677 return null;
678 }
679
680 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700681 * Return the {@link PhoneAccount} for a specified {@link PhoneAccountHandle}. Object includes
682 * resources which can be used in a user interface.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700683 *
Evan Charlton6eb262c2014-07-19 18:18:19 -0700684 * @param account The {@link PhoneAccountHandle}.
Evan Charlton8c8a0622014-07-20 12:31:00 -0700685 * @return The {@link PhoneAccount} object.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700686 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700687 public PhoneAccount getPhoneAccount(PhoneAccountHandle account) {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700688 try {
689 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700690 return getTelecomService().getPhoneAccount(account);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700691 }
692 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700693 Log.e(TAG, "Error calling ITelecomService#getPhoneAccount", e);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700694 }
695 return null;
696 }
697
698 /**
Nancy Chen210ef032014-09-15 17:58:42 -0700699 * Returns a count of all {@link PhoneAccount}s.
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700700 *
Nancy Chen210ef032014-09-15 17:58:42 -0700701 * @return The count of {@link PhoneAccount}s.
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700702 * @hide
703 */
704 @SystemApi
705 public int getAllPhoneAccountsCount() {
706 try {
707 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700708 return getTelecomService().getAllPhoneAccountsCount();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700709 }
710 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700711 Log.e(TAG, "Error calling ITelecomService#getAllPhoneAccountsCount", e);
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700712 }
713 return 0;
714 }
715
716 /**
717 * Returns a list of all {@link PhoneAccount}s.
718 *
719 * @return All {@link PhoneAccount}s.
720 * @hide
721 */
722 @SystemApi
723 public List<PhoneAccount> getAllPhoneAccounts() {
724 try {
725 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700726 return getTelecomService().getAllPhoneAccounts();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700727 }
728 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700729 Log.e(TAG, "Error calling ITelecomService#getAllPhoneAccounts", e);
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700730 }
731 return Collections.EMPTY_LIST;
732 }
733
734 /**
735 * Returns a list of all {@link PhoneAccountHandle}s.
736 *
737 * @return All {@link PhoneAccountHandle}s.
738 * @hide
739 */
740 @SystemApi
741 public List<PhoneAccountHandle> getAllPhoneAccountHandles() {
742 try {
743 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700744 return getTelecomService().getAllPhoneAccountHandles();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700745 }
746 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700747 Log.e(TAG, "Error calling ITelecomService#getAllPhoneAccountHandles", e);
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700748 }
749 return Collections.EMPTY_LIST;
750 }
751
752 /**
Santos Cordond9e614f2014-10-28 13:10:36 -0700753 * Register a {@link PhoneAccount} for use by the system. When registering
754 * {@link PhoneAccount}s, existing registrations will be overwritten if the
755 * {@link PhoneAccountHandle} matches that of a {@link PhoneAccount} which is already
756 * registered. Once registered, the {@link PhoneAccount} is listed to the user as an option
757 * when placing calls. The user may still need to enable the {@link PhoneAccount} within
758 * the phone app settings before the account is usable.
759 * <p>
760 * A {@link SecurityException} will be thrown if an app tries to register a
761 * {@link PhoneAccountHandle} where the package name specified within
762 * {@link PhoneAccountHandle#getComponentName()} does not match the package name of the app.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700763 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700764 * @param account The complete {@link PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700765 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700766 public void registerPhoneAccount(PhoneAccount account) {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700767 try {
768 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700769 getTelecomService().registerPhoneAccount(account);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700770 }
771 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700772 Log.e(TAG, "Error calling ITelecomService#registerPhoneAccount", e);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700773 }
774 }
775
776 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700777 * Remove a {@link PhoneAccount} registration from the system.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700778 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700779 * @param accountHandle A {@link PhoneAccountHandle} for the {@link PhoneAccount} to unregister.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700780 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700781 public void unregisterPhoneAccount(PhoneAccountHandle accountHandle) {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700782 try {
783 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700784 getTelecomService().unregisterPhoneAccount(accountHandle);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700785 }
786 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700787 Log.e(TAG, "Error calling ITelecomService#unregisterPhoneAccount", e);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700788 }
789 }
790
791 /**
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700792 * Remove all Accounts that belong to the calling package from the system.
Evan Charlton0e094d92014-11-08 15:49:16 -0800793 * @hide
Ihab Awad807fe0a2014-07-09 12:30:52 -0700794 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800795 @SystemApi
Yorke Lee06044272015-04-14 15:16:59 -0700796 public void clearPhoneAccounts() {
797 clearAccounts();
798 }
799 /**
800 * Remove all Accounts that belong to the calling package from the system.
801 * @deprecated Use {@link #clearPhoneAccounts()} instead.
802 * @hide
803 */
804 @SystemApi
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700805 public void clearAccounts() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700806 try {
807 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700808 getTelecomService().clearAccounts(mContext.getPackageName());
Ihab Awad807fe0a2014-07-09 12:30:52 -0700809 }
810 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700811 Log.e(TAG, "Error calling ITelecomService#clearAccounts", e);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700812 }
813 }
814
815 /**
Anthony Lee67279262014-10-27 11:28:40 -0700816 * Remove all Accounts that belong to the specified package from the system.
817 * @hide
818 */
819 public void clearAccountsForPackage(String packageName) {
820 try {
821 if (isServiceConnected() && !TextUtils.isEmpty(packageName)) {
822 getTelecomService().clearAccounts(packageName);
823 }
824 } catch (RemoteException e) {
Nancy Chen5cf27842015-01-24 23:30:27 -0800825 Log.e(TAG, "Error calling ITelecomService#clearAccountsForPackage", e);
Anthony Lee67279262014-10-27 11:28:40 -0700826 }
827 }
828
Yorke Lee1011f482015-04-23 15:58:27 -0700829
Anthony Lee67279262014-10-27 11:28:40 -0700830 /**
Yorke Lee1011f482015-04-23 15:58:27 -0700831 * @deprecated - Use {@link TelecomManager#getDefaultDialerPackage} to directly access
832 * the default dialer's package name instead.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700833 * @hide
834 */
Santos Cordon6c7a3882014-06-25 15:30:08 -0700835 @SystemApi
836 public ComponentName getDefaultPhoneApp() {
837 try {
Santos Cordon9eb45932014-06-27 12:28:43 -0700838 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700839 return getTelecomService().getDefaultPhoneApp();
Santos Cordon9eb45932014-06-27 12:28:43 -0700840 }
Santos Cordon6c7a3882014-06-25 15:30:08 -0700841 } catch (RemoteException e) {
842 Log.e(TAG, "RemoteException attempting to get the default phone app.", e);
843 }
844 return null;
845 }
846
Santos Cordon9eb45932014-06-27 12:28:43 -0700847 /**
Yorke Lee1011f482015-04-23 15:58:27 -0700848 * Used to determine the currently selected default dialer package.
849 *
850 * @return package name for the default dialer package or null if no package has been
851 * selected as the default dialer.
852 */
853 public String getDefaultDialerPackage() {
854 try {
855 if (isServiceConnected()) {
856 return getTelecomService().getDefaultDialerPackage();
857 }
858 } catch (RemoteException e) {
859 Log.e(TAG, "RemoteException attempting to get the default dialer package name.", e);
860 }
861 return null;
862 }
863
864 /**
Yorke Lee107c4ce2015-06-15 12:08:24 -0700865 * Used to set the default dialer package.
866 *
867 * @param packageName to set the default dialer to..
868 *
869 * @result {@code true} if the default dialer was successfully changed, {@code false} if
870 * the specified package does not correspond to an installed dialer, or is already
871 * the default dialer.
872 *
873 * Requires permission: {@link android.Manifest.permission#MODIFY_PHONE_STATE}
874 * Requires permission: {@link android.Manifest.permission#WRITE_SECURE_SETTINGS}
875 *
876 * @hide
877 */
878 public boolean setDefaultDialer(String packageName) {
879 try {
880 if (isServiceConnected()) {
881 return getTelecomService().setDefaultDialer(packageName);
882 }
883 } catch (RemoteException e) {
884 Log.e(TAG, "RemoteException attempting to set the default dialer.", e);
885 }
886 return false;
887 }
888
889 /**
Yorke Lee1011f482015-04-23 15:58:27 -0700890 * Used to determine the dialer package that is preloaded on the system partition.
891 *
892 * @return package name for the system dialer package or null if no system dialer is preloaded.
893 * @hide
894 */
895 public String getSystemDialerPackage() {
896 try {
897 if (isServiceConnected()) {
898 return getTelecomService().getSystemDialerPackage();
899 }
900 } catch (RemoteException e) {
901 Log.e(TAG, "RemoteException attempting to get the system dialer package name.", e);
902 }
903 return null;
904 }
905
906 /**
Nancy Chen443e5012014-10-15 15:48:21 -0700907 * Return whether a given phone number is the configured voicemail number for a
908 * particular phone account.
909 *
Yorke Leec61d1362015-09-21 17:25:25 -0700910 * Requires permission: {@link android.Manifest.permission#READ_PHONE_STATE}
911 *
Nancy Chen443e5012014-10-15 15:48:21 -0700912 * @param accountHandle The handle for the account to check the voicemail number against
913 * @param number The number to look up.
Nancy Chen443e5012014-10-15 15:48:21 -0700914 */
Yorke Leec61d1362015-09-21 17:25:25 -0700915 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
Nancy Chen443e5012014-10-15 15:48:21 -0700916 public boolean isVoiceMailNumber(PhoneAccountHandle accountHandle, String number) {
917 try {
918 if (isServiceConnected()) {
Svet Ganov16a16892015-04-16 10:32:04 -0700919 return getTelecomService().isVoiceMailNumber(accountHandle, number,
920 mContext.getOpPackageName());
Nancy Chen443e5012014-10-15 15:48:21 -0700921 }
922 } catch (RemoteException e) {
Nancy Chen5cf27842015-01-24 23:30:27 -0800923 Log.e(TAG, "RemoteException calling ITelecomService#isVoiceMailNumber.", e);
Nancy Chen443e5012014-10-15 15:48:21 -0700924 }
925 return false;
926 }
927
928 /**
Yorke Lee49e2d462015-04-15 16:14:22 -0700929 * Return the voicemail number for a given phone account.
Nancy Chen8c066f72014-12-03 15:18:08 -0800930 *
Yorke Leec61d1362015-09-21 17:25:25 -0700931 * Requires permission: {@link android.Manifest.permission#READ_PHONE_STATE}
932 *
Yorke Lee49e2d462015-04-15 16:14:22 -0700933 * @param accountHandle The handle for the phone account.
934 * @return The voicemail number for the phone account, and {@code null} if one has not been
935 * configured.
Nancy Chen8c066f72014-12-03 15:18:08 -0800936 */
Yorke Leec61d1362015-09-21 17:25:25 -0700937 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
Yorke Lee49e2d462015-04-15 16:14:22 -0700938 public String getVoiceMailNumber(PhoneAccountHandle accountHandle) {
Nancy Chen8c066f72014-12-03 15:18:08 -0800939 try {
940 if (isServiceConnected()) {
Svet Ganov16a16892015-04-16 10:32:04 -0700941 return getTelecomService().getVoiceMailNumber(accountHandle,
942 mContext.getOpPackageName());
Nancy Chen8c066f72014-12-03 15:18:08 -0800943 }
944 } catch (RemoteException e) {
Nancy Chen5cf27842015-01-24 23:30:27 -0800945 Log.e(TAG, "RemoteException calling ITelecomService#hasVoiceMailNumber.", e);
Nancy Chen8c066f72014-12-03 15:18:08 -0800946 }
Yorke Lee49e2d462015-04-15 16:14:22 -0700947 return null;
Nancy Chen8c066f72014-12-03 15:18:08 -0800948 }
949
950 /**
Nancy Chen5cf27842015-01-24 23:30:27 -0800951 * Return the line 1 phone number for given phone account.
952 *
Yorke Leec61d1362015-09-21 17:25:25 -0700953 * Requires permission: {@link android.Manifest.permission#READ_PHONE_STATE}
954 *
Nancy Chen5cf27842015-01-24 23:30:27 -0800955 * @param accountHandle The handle for the account retrieve a number for.
956 * @return A string representation of the line 1 phone number.
Nancy Chen5cf27842015-01-24 23:30:27 -0800957 */
Yorke Leec61d1362015-09-21 17:25:25 -0700958 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
Nancy Chen5cf27842015-01-24 23:30:27 -0800959 public String getLine1Number(PhoneAccountHandle accountHandle) {
960 try {
961 if (isServiceConnected()) {
Svet Ganov16a16892015-04-16 10:32:04 -0700962 return getTelecomService().getLine1Number(accountHandle,
963 mContext.getOpPackageName());
Nancy Chen5cf27842015-01-24 23:30:27 -0800964 }
965 } catch (RemoteException e) {
966 Log.e(TAG, "RemoteException calling ITelecomService#getLine1Number.", e);
967 }
968 return null;
969 }
970
971 /**
Santos Cordon9eb45932014-06-27 12:28:43 -0700972 * Returns whether there is an ongoing phone call (can be in dialing, ringing, active or holding
973 * states).
Nancy Chen0eb1e402014-08-21 22:52:29 -0700974 * <p>
975 * Requires permission: {@link android.Manifest.permission#READ_PHONE_STATE}
976 * </p>
Santos Cordon9eb45932014-06-27 12:28:43 -0700977 */
Yorke Leec61d1362015-09-21 17:25:25 -0700978 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
Nancy Chen0eb1e402014-08-21 22:52:29 -0700979 public boolean isInCall() {
Santos Cordon9eb45932014-06-27 12:28:43 -0700980 try {
981 if (isServiceConnected()) {
Svet Ganov16a16892015-04-16 10:32:04 -0700982 return getTelecomService().isInCall(mContext.getOpPackageName());
Santos Cordon9eb45932014-06-27 12:28:43 -0700983 }
984 } catch (RemoteException e) {
Yorke Lee2ae312e2014-09-12 17:58:48 -0700985 Log.e(TAG, "RemoteException calling isInCall().", e);
Santos Cordon9eb45932014-06-27 12:28:43 -0700986 }
987 return false;
988 }
989
990 /**
Yorke Lee2ae312e2014-09-12 17:58:48 -0700991 * Returns one of the following constants that represents the current state of Telecom:
992 *
993 * {@link TelephonyManager#CALL_STATE_RINGING}
994 * {@link TelephonyManager#CALL_STATE_OFFHOOK}
995 * {@link TelephonyManager#CALL_STATE_IDLE}
Yorke Lee7c72c2d2014-10-28 14:12:02 -0700996 *
997 * Note that this API does not require the
998 * {@link android.Manifest.permission#READ_PHONE_STATE} permission. This is intentional, to
999 * preserve the behavior of {@link TelephonyManager#getCallState()}, which also did not require
1000 * the permission.
Yorke Lee2ae312e2014-09-12 17:58:48 -07001001 * @hide
1002 */
1003 @SystemApi
1004 public int getCallState() {
1005 try {
1006 if (isServiceConnected()) {
1007 return getTelecomService().getCallState();
1008 }
1009 } catch (RemoteException e) {
1010 Log.d(TAG, "RemoteException calling getCallState().", e);
1011 }
1012 return TelephonyManager.CALL_STATE_IDLE;
1013 }
1014
1015 /**
Santos Cordon9eb45932014-06-27 12:28:43 -07001016 * Returns whether there currently exists is a ringing incoming-call.
1017 *
1018 * @hide
1019 */
1020 @SystemApi
1021 public boolean isRinging() {
1022 try {
1023 if (isServiceConnected()) {
Svet Ganov16a16892015-04-16 10:32:04 -07001024 return getTelecomService().isRinging(mContext.getOpPackageName());
Santos Cordon9eb45932014-06-27 12:28:43 -07001025 }
1026 } catch (RemoteException e) {
1027 Log.e(TAG, "RemoteException attempting to get ringing state of phone app.", e);
1028 }
1029 return false;
1030 }
1031
1032 /**
Santos Cordon96efb482014-07-19 14:57:05 -07001033 * Ends an ongoing call.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001034 * TODO: L-release - need to convert all invocations of ITelecomService#endCall to use this
Santos Cordon96efb482014-07-19 14:57:05 -07001035 * method (clockwork & gearhead).
Santos Cordon9eb45932014-06-27 12:28:43 -07001036 * @hide
1037 */
1038 @SystemApi
1039 public boolean endCall() {
1040 try {
1041 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001042 return getTelecomService().endCall();
Santos Cordon9eb45932014-06-27 12:28:43 -07001043 }
1044 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001045 Log.e(TAG, "Error calling ITelecomService#endCall", e);
Santos Cordon9eb45932014-06-27 12:28:43 -07001046 }
1047 return false;
1048 }
1049
1050 /**
1051 * If there is a ringing incoming call, this method accepts the call on behalf of the user.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001052 * TODO: L-release - need to convert all invocation of ITelecmmService#answerRingingCall to use
Santos Cordon96efb482014-07-19 14:57:05 -07001053 * this method (clockwork & gearhead).
Tyler Gunn6676bb52015-10-23 14:39:49 -07001054 * If the incoming call is a video call, the call will be answered with the same video state as
1055 * the incoming call requests. This means, for example, that an incoming call requesting
1056 * {@link VideoProfile#STATE_BIDIRECTIONAL} will be answered, accepting that state.
Santos Cordon9eb45932014-06-27 12:28:43 -07001057 * @hide
1058 */
1059 @SystemApi
1060 public void acceptRingingCall() {
1061 try {
1062 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001063 getTelecomService().acceptRingingCall();
Santos Cordon9eb45932014-06-27 12:28:43 -07001064 }
1065 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001066 Log.e(TAG, "Error calling ITelecomService#acceptRingingCall", e);
Santos Cordon9eb45932014-06-27 12:28:43 -07001067 }
1068 }
1069
1070 /**
Tyler Gunn6676bb52015-10-23 14:39:49 -07001071 * If there is a ringing incoming call, this method accepts the call on behalf of the user,
1072 * with the specified video state.
1073 *
1074 * @param videoState The desired video state to answer the call with.
1075 * @hide
1076 */
1077 @SystemApi
1078 public void acceptRingingCall(int videoState) {
1079 try {
1080 if (isServiceConnected()) {
1081 getTelecomService().acceptRingingCallWithVideoState(videoState);
1082 }
1083 } catch (RemoteException e) {
1084 Log.e(TAG, "Error calling ITelecomService#acceptRingingCallWithVideoState", e);
1085 }
1086 }
1087
1088 /**
Santos Cordon9eb45932014-06-27 12:28:43 -07001089 * Silences the ringer if a ringing call exists.
Yorke Leec61d1362015-09-21 17:25:25 -07001090 *
1091 * Requires permission: {@link android.Manifest.permission#MODIFY_PHONE_STATE}
Santos Cordon9eb45932014-06-27 12:28:43 -07001092 */
Yorke Leec61d1362015-09-21 17:25:25 -07001093 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
Santos Cordon9eb45932014-06-27 12:28:43 -07001094 public void silenceRinger() {
1095 try {
1096 if (isServiceConnected()) {
Yorke Leef1a349b2015-04-29 16:16:50 -07001097 getTelecomService().silenceRinger(mContext.getOpPackageName());
Santos Cordon9eb45932014-06-27 12:28:43 -07001098 }
1099 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001100 Log.e(TAG, "Error calling ITelecomService#silenceRinger", e);
Santos Cordon9eb45932014-06-27 12:28:43 -07001101 }
1102 }
1103
Sailesh Nepal001bbbb2014-07-15 14:40:39 -07001104 /**
1105 * Returns whether TTY is supported on this device.
1106 *
1107 * @hide
1108 */
1109 @SystemApi
1110 public boolean isTtySupported() {
1111 try {
1112 if (isServiceConnected()) {
Svet Ganov16a16892015-04-16 10:32:04 -07001113 return getTelecomService().isTtySupported(mContext.getOpPackageName());
Sailesh Nepal001bbbb2014-07-15 14:40:39 -07001114 }
1115 } catch (RemoteException e) {
1116 Log.e(TAG, "RemoteException attempting to get TTY supported state.", e);
1117 }
1118 return false;
1119 }
1120
1121 /**
1122 * 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 -07001123 * settings and have a wired headset plugged in.
1124 * Valid modes are:
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001125 * - {@link TelecomManager#TTY_MODE_OFF}
1126 * - {@link TelecomManager#TTY_MODE_FULL}
1127 * - {@link TelecomManager#TTY_MODE_HCO}
1128 * - {@link TelecomManager#TTY_MODE_VCO}
Sailesh Nepal001bbbb2014-07-15 14:40:39 -07001129 * @hide
1130 */
1131 public int getCurrentTtyMode() {
1132 try {
1133 if (isServiceConnected()) {
Svet Ganov16a16892015-04-16 10:32:04 -07001134 return getTelecomService().getCurrentTtyMode(mContext.getOpPackageName());
Sailesh Nepal001bbbb2014-07-15 14:40:39 -07001135 }
1136 } catch (RemoteException e) {
1137 Log.e(TAG, "RemoteException attempting to get the current TTY mode.", e);
1138 }
Evan Charlton10197192014-07-19 15:00:29 -07001139 return TTY_MODE_OFF;
Sailesh Nepal001bbbb2014-07-15 14:40:39 -07001140 }
1141
Santos Cordon96efb482014-07-19 14:57:05 -07001142 /**
1143 * Registers a new incoming call. A {@link ConnectionService} should invoke this method when it
1144 * has an incoming call. The specified {@link PhoneAccountHandle} must have been registered
Nancy Chen210ef032014-09-15 17:58:42 -07001145 * with {@link #registerPhoneAccount}. Once invoked, this method will cause the system to bind
1146 * to the {@link ConnectionService} associated with the {@link PhoneAccountHandle} and request
Santos Cordon96efb482014-07-19 14:57:05 -07001147 * additional information about the call (See
1148 * {@link ConnectionService#onCreateIncomingConnection}) before starting the incoming call UI.
1149 *
1150 * @param phoneAccount A {@link PhoneAccountHandle} registered with
1151 * {@link #registerPhoneAccount}.
1152 * @param extras A bundle that will be passed through to
1153 * {@link ConnectionService#onCreateIncomingConnection}.
1154 */
1155 public void addNewIncomingCall(PhoneAccountHandle phoneAccount, Bundle extras) {
1156 try {
1157 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001158 getTelecomService().addNewIncomingCall(
Santos Cordon96efb482014-07-19 14:57:05 -07001159 phoneAccount, extras == null ? new Bundle() : extras);
1160 }
1161 } catch (RemoteException e) {
1162 Log.e(TAG, "RemoteException adding a new incoming call: " + phoneAccount, e);
1163 }
1164 }
1165
Nancy Chen0eb1e402014-08-21 22:52:29 -07001166 /**
Yorke Leec3cf9822014-10-02 09:38:39 -07001167 * Registers a new unknown call with Telecom. This can only be called by the system Telephony
1168 * service. This is invoked when Telephony detects a new unknown connection that was neither
1169 * a new incoming call, nor an user-initiated outgoing call.
1170 *
1171 * @param phoneAccount A {@link PhoneAccountHandle} registered with
1172 * {@link #registerPhoneAccount}.
1173 * @param extras A bundle that will be passed through to
1174 * {@link ConnectionService#onCreateIncomingConnection}.
1175 * @hide
1176 */
1177 @SystemApi
1178 public void addNewUnknownCall(PhoneAccountHandle phoneAccount, Bundle extras) {
1179 try {
1180 if (isServiceConnected()) {
1181 getTelecomService().addNewUnknownCall(
1182 phoneAccount, extras == null ? new Bundle() : extras);
1183 }
1184 } catch (RemoteException e) {
1185 Log.e(TAG, "RemoteException adding a new unknown call: " + phoneAccount, e);
1186 }
1187 }
1188
1189 /**
Nancy Chen0eb1e402014-08-21 22:52:29 -07001190 * Processes the specified dial string as an MMI code.
1191 * MMI codes are any sequence of characters entered into the dialpad that contain a "*" or "#".
1192 * Some of these sequences launch special behavior through handled by Telephony.
Nancy Chen95e8a672014-10-16 18:38:21 -07001193 * This method uses the default subscription.
Nancy Chen0eb1e402014-08-21 22:52:29 -07001194 * <p>
1195 * Requires that the method-caller be set as the system dialer app.
1196 * </p>
1197 *
Yorke Leec61d1362015-09-21 17:25:25 -07001198 * Requires permission: {@link android.Manifest.permission#MODIFY_PHONE_STATE}
1199 *
Nancy Chen0eb1e402014-08-21 22:52:29 -07001200 * @param dialString The digits to dial.
1201 * @return True if the digits were processed as an MMI code, false otherwise.
1202 */
Yorke Leec61d1362015-09-21 17:25:25 -07001203 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
Nancy Chen0eb1e402014-08-21 22:52:29 -07001204 public boolean handleMmi(String dialString) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001205 ITelecomService service = getTelecomService();
Nancy Chen0eb1e402014-08-21 22:52:29 -07001206 if (service != null) {
1207 try {
Yorke Leef1a349b2015-04-29 16:16:50 -07001208 return service.handlePinMmi(dialString, mContext.getOpPackageName());
Nancy Chen0eb1e402014-08-21 22:52:29 -07001209 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001210 Log.e(TAG, "Error calling ITelecomService#handlePinMmi", e);
Nancy Chen0eb1e402014-08-21 22:52:29 -07001211 }
1212 }
1213 return false;
1214 }
1215
1216 /**
Nancy Chen95e8a672014-10-16 18:38:21 -07001217 * Processes the specified dial string as an MMI code.
1218 * MMI codes are any sequence of characters entered into the dialpad that contain a "*" or "#".
1219 * Some of these sequences launch special behavior through handled by Telephony.
1220 * <p>
1221 * Requires that the method-caller be set as the system dialer app.
1222 * </p>
1223 *
Yorke Leec61d1362015-09-21 17:25:25 -07001224 * Requires permission: {@link android.Manifest.permission#MODIFY_PHONE_STATE}
1225 *
Nancy Chen95e8a672014-10-16 18:38:21 -07001226 * @param accountHandle The handle for the account the MMI code should apply to.
1227 * @param dialString The digits to dial.
1228 * @return True if the digits were processed as an MMI code, false otherwise.
Nancy Chen95e8a672014-10-16 18:38:21 -07001229 */
Yorke Leec61d1362015-09-21 17:25:25 -07001230 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
Yorke Lee06044272015-04-14 15:16:59 -07001231 public boolean handleMmi(String dialString, PhoneAccountHandle accountHandle) {
Nancy Chen95e8a672014-10-16 18:38:21 -07001232 ITelecomService service = getTelecomService();
1233 if (service != null) {
1234 try {
Yorke Leef1a349b2015-04-29 16:16:50 -07001235 return service.handlePinMmiForPhoneAccount(accountHandle, dialString,
1236 mContext.getOpPackageName());
Nancy Chen95e8a672014-10-16 18:38:21 -07001237 } catch (RemoteException e) {
1238 Log.e(TAG, "Error calling ITelecomService#handlePinMmi", e);
1239 }
1240 }
1241 return false;
1242 }
1243
1244 /**
Yorke Leec61d1362015-09-21 17:25:25 -07001245 * Requires permission: {@link android.Manifest.permission#MODIFY_PHONE_STATE}
1246 *
Nancy Chenb2299c12014-10-29 18:22:11 -07001247 * @param accountHandle The handle for the account to derive an adn query URI for or
1248 * {@code null} to return a URI which will use the default account.
1249 * @return The URI (with the content:// scheme) specific to the specified {@link PhoneAccount}
1250 * for the the content retrieve.
1251 */
Yorke Leec61d1362015-09-21 17:25:25 -07001252 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
Nancy Chenb2299c12014-10-29 18:22:11 -07001253 public Uri getAdnUriForPhoneAccount(PhoneAccountHandle accountHandle) {
1254 ITelecomService service = getTelecomService();
1255 if (service != null && accountHandle != null) {
1256 try {
Yorke Leef1a349b2015-04-29 16:16:50 -07001257 return service.getAdnUriForPhoneAccount(accountHandle, mContext.getOpPackageName());
Nancy Chenb2299c12014-10-29 18:22:11 -07001258 } catch (RemoteException e) {
1259 Log.e(TAG, "Error calling ITelecomService#getAdnUriForPhoneAccount", e);
1260 }
1261 }
1262 return Uri.parse("content://icc/adn");
1263 }
1264
1265 /**
Nancy Chen0eb1e402014-08-21 22:52:29 -07001266 * Removes the missed-call notification if one is present.
1267 * <p>
1268 * Requires that the method-caller be set as the system dialer app.
1269 * </p>
Yorke Leec61d1362015-09-21 17:25:25 -07001270 *
1271 * Requires permission: {@link android.Manifest.permission#MODIFY_PHONE_STATE}
Nancy Chen0eb1e402014-08-21 22:52:29 -07001272 */
Yorke Leec61d1362015-09-21 17:25:25 -07001273 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
Nancy Chen0eb1e402014-08-21 22:52:29 -07001274 public void cancelMissedCallsNotification() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001275 ITelecomService service = getTelecomService();
Nancy Chen0eb1e402014-08-21 22:52:29 -07001276 if (service != null) {
1277 try {
Yorke Leef1a349b2015-04-29 16:16:50 -07001278 service.cancelMissedCallsNotification(mContext.getOpPackageName());
Nancy Chen0eb1e402014-08-21 22:52:29 -07001279 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001280 Log.e(TAG, "Error calling ITelecomService#cancelMissedCallsNotification", e);
Nancy Chen0eb1e402014-08-21 22:52:29 -07001281 }
1282 }
1283 }
1284
1285 /**
1286 * Brings the in-call screen to the foreground if there is an ongoing call. If there is
1287 * currently no ongoing call, then this method does nothing.
1288 * <p>
1289 * Requires that the method-caller be set as the system dialer app or have the
1290 * {@link android.Manifest.permission#READ_PHONE_STATE} permission.
1291 * </p>
1292 *
1293 * @param showDialpad Brings up the in-call dialpad as part of showing the in-call screen.
1294 */
Yorke Leec61d1362015-09-21 17:25:25 -07001295 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
Nancy Chen0eb1e402014-08-21 22:52:29 -07001296 public void showInCallScreen(boolean showDialpad) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001297 ITelecomService service = getTelecomService();
Nancy Chen0eb1e402014-08-21 22:52:29 -07001298 if (service != null) {
1299 try {
Svet Ganov16a16892015-04-16 10:32:04 -07001300 service.showInCallScreen(showDialpad, mContext.getOpPackageName());
Nancy Chen0eb1e402014-08-21 22:52:29 -07001301 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001302 Log.e(TAG, "Error calling ITelecomService#showCallScreen", e);
Nancy Chen0eb1e402014-08-21 22:52:29 -07001303 }
1304 }
1305 }
1306
Yorke Lee3e56ba12015-04-23 12:32:36 -07001307 /**
1308 * Places a new outgoing call to the provided address using the system telecom service with
1309 * the specified extras.
1310 *
1311 * This method is equivalent to placing an outgoing call using {@link Intent#ACTION_CALL},
1312 * except that the outgoing call will always be sent via the system telecom service. If
1313 * method-caller is either the user selected default dialer app or preloaded system dialer
1314 * app, then emergency calls will also be allowed.
1315 *
1316 * Requires permission: {@link android.Manifest.permission#CALL_PHONE}
1317 *
1318 * Usage example:
1319 * <pre>
1320 * Uri uri = Uri.fromParts("tel", "12345", null);
1321 * Bundle extras = new Bundle();
1322 * extras.putBoolean(TelecomManager.EXTRA_START_CALL_WITH_SPEAKERPHONE, true);
1323 * telecomManager.placeCall(uri, extras);
1324 * </pre>
1325 *
Santos Cordon7a060d52015-06-19 14:52:04 -07001326 * The following keys are supported in the supplied extras.
1327 * <ul>
1328 * <li>{@link #EXTRA_OUTGOING_CALL_EXTRAS}</li>
1329 * <li>{@link #EXTRA_PHONE_ACCOUNT_HANDLE}</li>
1330 * <li>{@link #EXTRA_START_CALL_WITH_SPEAKERPHONE}</li>
1331 * <li>{@link #EXTRA_START_CALL_WITH_VIDEO_STATE}</li>
1332 * </ul>
1333 *
Yorke Lee3e56ba12015-04-23 12:32:36 -07001334 * @param address The address to make the call to.
1335 * @param extras Bundle of extras to use with the call.
1336 */
Yorke Leec61d1362015-09-21 17:25:25 -07001337 @RequiresPermission(android.Manifest.permission.CALL_PHONE)
Yorke Lee3e56ba12015-04-23 12:32:36 -07001338 public void placeCall(Uri address, Bundle extras) {
1339 ITelecomService service = getTelecomService();
1340 if (service != null) {
Yorke Leea5d5c1d2015-05-05 16:25:55 -07001341 if (address == null) {
1342 Log.w(TAG, "Cannot place call to empty address.");
1343 }
Yorke Lee3e56ba12015-04-23 12:32:36 -07001344 try {
Yorke Leea5d5c1d2015-05-05 16:25:55 -07001345 service.placeCall(address, extras == null ? new Bundle() : extras,
1346 mContext.getOpPackageName());
Yorke Lee3e56ba12015-04-23 12:32:36 -07001347 } catch (RemoteException e) {
1348 Log.e(TAG, "Error calling ITelecomService#placeCall", e);
1349 }
1350 }
1351 }
1352
Santos Cordon91371dc2015-05-08 13:52:09 -07001353 /**
1354 * Enables and disables specified phone account.
1355 *
1356 * @param handle Handle to the phone account.
1357 * @param isEnabled Enable state of the phone account.
1358 * @hide
1359 */
1360 @SystemApi
1361 public void enablePhoneAccount(PhoneAccountHandle handle, boolean isEnabled) {
1362 ITelecomService service = getTelecomService();
1363 if (service != null) {
1364 try {
1365 service.enablePhoneAccount(handle, isEnabled);
1366 } catch (RemoteException e) {
1367 Log.e(TAG, "Error enablePhoneAbbount", e);
1368 }
1369 }
1370 }
1371
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001372 private ITelecomService getTelecomService() {
Hall Liue1bc2ec2015-10-09 15:58:37 -07001373 if (mTelecomServiceOverride != null) {
1374 return mTelecomServiceOverride;
1375 }
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001376 return ITelecomService.Stub.asInterface(ServiceManager.getService(Context.TELECOM_SERVICE));
Santos Cordon6c7a3882014-06-25 15:30:08 -07001377 }
Santos Cordon9eb45932014-06-27 12:28:43 -07001378
1379 private boolean isServiceConnected() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001380 boolean isConnected = getTelecomService() != null;
Santos Cordon9eb45932014-06-27 12:28:43 -07001381 if (!isConnected) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001382 Log.w(TAG, "Telecom Service not found.");
Santos Cordon9eb45932014-06-27 12:28:43 -07001383 }
1384 return isConnected;
1385 }
Evan Charlton235c1592014-09-05 15:41:23 +00001386}