blob: 6e60d607fc089288c923fc7c46a746f5cf1c1829 [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 /**
Yorke Lee1011f482015-04-23 15:58:27 -0700120 * Activity action: Shows a dialog asking the user whether or not they want to replace the
121 * current default Dialer with the one specified in
122 * {@link #EXTRA_CHANGE_DEFAULT_DIALER_PACKAGE_NAME}.
123 *
124 * Usage example:
125 * <pre>
126 * Intent intent = new Intent(TelecomManager.ACTION_CHANGE_DEFAULT_DIALER);
127 * intent.putExtra(TelecomManager.EXTRA_CHANGE_DEFAULT_DIALER_PACKAGE_NAME,
128 * getActivity().getPackageName());
129 * startActivity(intent);
130 * </pre>
131 */
132 public static final String ACTION_CHANGE_DEFAULT_DIALER =
133 "android.telecom.action.CHANGE_DEFAULT_DIALER";
134
135 /**
Yorke Lee107c4ce2015-06-15 12:08:24 -0700136 * Broadcast intent action indicating that the current default dialer has changed.
137 * The string extra {@link #EXTRA_CHANGE_DEFAULT_DIALER_PACKAGE_NAME} will contain the
138 * name of the package that the default dialer was changed to.
139 *
140 * @see #EXTRA_CHANGE_DEFAULT_DIALER_PACKAGE_NAME
141 */
142 public static final String ACTION_DEFAULT_DIALER_CHANGED =
143 "android.telecom.action.DEFAULT_DIALER_CHANGED";
144
145 /**
Yorke Lee1011f482015-04-23 15:58:27 -0700146 * Extra value used to provide the package name for {@link #ACTION_CHANGE_DEFAULT_DIALER}.
147 */
148 public static final String EXTRA_CHANGE_DEFAULT_DIALER_PACKAGE_NAME =
149 "android.telecom.extra.CHANGE_DEFAULT_DIALER_PACKAGE_NAME";
150
151 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700152 * Optional extra for {@link android.content.Intent#ACTION_CALL} containing a boolean that
153 * determines whether the speakerphone should be automatically turned on for an outgoing call.
Evan Charlton10197192014-07-19 15:00:29 -0700154 */
155 public static final String EXTRA_START_CALL_WITH_SPEAKERPHONE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700156 "android.telecom.extra.START_CALL_WITH_SPEAKERPHONE";
Evan Charlton10197192014-07-19 15:00:29 -0700157
158 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700159 * Optional extra for {@link android.content.Intent#ACTION_CALL} containing an integer that
160 * determines the desired video state for an outgoing call.
Santos Cordon96efb482014-07-19 14:57:05 -0700161 * Valid options:
Yorke Lee32f24732015-05-12 16:18:03 -0700162 * {@link VideoProfile#STATE_AUDIO_ONLY},
163 * {@link VideoProfile#STATE_BIDIRECTIONAL},
164 * {@link VideoProfile#STATE_RX_ENABLED},
165 * {@link VideoProfile#STATE_TX_ENABLED}.
Evan Charlton10197192014-07-19 15:00:29 -0700166 */
167 public static final String EXTRA_START_CALL_WITH_VIDEO_STATE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700168 "android.telecom.extra.START_CALL_WITH_VIDEO_STATE";
Evan Charlton10197192014-07-19 15:00:29 -0700169
170 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700171 * The extra used with an {@link android.content.Intent#ACTION_CALL} and
172 * {@link android.content.Intent#ACTION_DIAL} {@code Intent} to specify a
173 * {@link PhoneAccountHandle} to use when making the call.
Evan Charlton10197192014-07-19 15:00:29 -0700174 * <p class="note">
Santos Cordon96efb482014-07-19 14:57:05 -0700175 * Retrieve with {@link android.content.Intent#getParcelableExtra(String)}.
Evan Charlton10197192014-07-19 15:00:29 -0700176 */
Evan Charlton6eb262c2014-07-19 18:18:19 -0700177 public static final String EXTRA_PHONE_ACCOUNT_HANDLE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700178 "android.telecom.extra.PHONE_ACCOUNT_HANDLE";
Evan Charlton10197192014-07-19 15:00:29 -0700179
180 /**
Tyler Gunn335ff2e2015-07-30 14:18:33 -0700181 * Optional extra for {@link android.content.Intent#ACTION_CALL} containing a string call
182 * subject which will be associated with an outgoing call. Should only be specified if the
183 * {@link PhoneAccount} supports the capability {@link PhoneAccount#CAPABILITY_CALL_SUBJECT}.
184 */
185 public static final String EXTRA_CALL_SUBJECT = "android.telecom.extra.CALL_SUBJECT";
186
187 /**
Yorke Lee04ea7d32015-06-05 15:59:18 -0700188 * The extra used by a {@link ConnectionService} to provide the handle of the caller that
189 * has initiated a new incoming call.
190 */
Yorke Lee02fb5bc2015-06-09 12:27:36 -0700191 public static final String EXTRA_INCOMING_CALL_ADDRESS =
192 "android.telecom.extra.INCOMING_CALL_ADDRESS";
Yorke Lee04ea7d32015-06-05 15:59:18 -0700193
194 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700195 * Optional extra for {@link #ACTION_INCOMING_CALL} containing a {@link Bundle} which contains
196 * metadata about the call. This {@link Bundle} will be returned to the
197 * {@link ConnectionService}.
Evan Charlton10197192014-07-19 15:00:29 -0700198 */
199 public static final String EXTRA_INCOMING_CALL_EXTRAS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700200 "android.telecom.extra.INCOMING_CALL_EXTRAS";
Evan Charlton10197192014-07-19 15:00:29 -0700201
202 /**
Nancy Chen10798dc2014-08-08 14:00:25 -0700203 * Optional extra for {@link android.content.Intent#ACTION_CALL} and
204 * {@link android.content.Intent#ACTION_DIAL} {@code Intent} containing a {@link Bundle}
205 * which contains metadata about the call. This {@link Bundle} will be saved into
Santos Cordon7a060d52015-06-19 14:52:04 -0700206 * {@code Call.Details} and passed to the {@link ConnectionService} when placing the call.
Nancy Chen10798dc2014-08-08 14:00:25 -0700207 */
208 public static final String EXTRA_OUTGOING_CALL_EXTRAS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700209 "android.telecom.extra.OUTGOING_CALL_EXTRAS";
Nancy Chen10798dc2014-08-08 14:00:25 -0700210
211 /**
Yorke Leec3cf9822014-10-02 09:38:39 -0700212 * @hide
213 */
214 public static final String EXTRA_UNKNOWN_CALL_HANDLE =
215 "android.telecom.extra.UNKNOWN_CALL_HANDLE";
216
217 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700218 * Optional extra for {@link android.telephony.TelephonyManager#ACTION_PHONE_STATE_CHANGED}
219 * containing the disconnect code.
Evan Charlton10197192014-07-19 15:00:29 -0700220 */
221 public static final String EXTRA_CALL_DISCONNECT_CAUSE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700222 "android.telecom.extra.CALL_DISCONNECT_CAUSE";
Evan Charlton10197192014-07-19 15:00:29 -0700223
224 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700225 * Optional extra for {@link android.telephony.TelephonyManager#ACTION_PHONE_STATE_CHANGED}
226 * containing the disconnect message.
Evan Charlton10197192014-07-19 15:00:29 -0700227 */
228 public static final String EXTRA_CALL_DISCONNECT_MESSAGE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700229 "android.telecom.extra.CALL_DISCONNECT_MESSAGE";
Evan Charlton10197192014-07-19 15:00:29 -0700230
231 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700232 * Optional extra for {@link android.telephony.TelephonyManager#ACTION_PHONE_STATE_CHANGED}
233 * containing the component name of the associated connection service.
Evan Charlton0e094d92014-11-08 15:49:16 -0800234 * @hide
Evan Charlton10197192014-07-19 15:00:29 -0700235 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800236 @SystemApi
Evan Charlton10197192014-07-19 15:00:29 -0700237 public static final String EXTRA_CONNECTION_SERVICE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700238 "android.telecom.extra.CONNECTION_SERVICE";
Evan Charlton10197192014-07-19 15:00:29 -0700239
240 /**
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700241 * An optional {@link android.content.Intent#ACTION_CALL} intent extra denoting the
242 * package name of the app specifying an alternative gateway for the call.
243 * The value is a string.
244 *
245 * (The following comment corresponds to the all GATEWAY_* extras)
246 * An app which sends the {@link android.content.Intent#ACTION_CALL} intent can specify an
247 * alternative address to dial which is different from the one specified and displayed to
248 * the user. This alternative address is referred to as the gateway address.
249 */
250 public static final String GATEWAY_PROVIDER_PACKAGE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700251 "android.telecom.extra.GATEWAY_PROVIDER_PACKAGE";
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700252
253 /**
254 * An optional {@link android.content.Intent#ACTION_CALL} intent extra corresponding to the
255 * original address to dial for the call. This is used when an alternative gateway address is
256 * provided to recall the original address.
257 * The value is a {@link android.net.Uri}.
258 *
259 * (See {@link #GATEWAY_PROVIDER_PACKAGE} for details)
260 */
261 public static final String GATEWAY_ORIGINAL_ADDRESS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700262 "android.telecom.extra.GATEWAY_ORIGINAL_ADDRESS";
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700263
264 /**
Evan Charlton10197192014-07-19 15:00:29 -0700265 * The number which the party on the other side of the line will see (and use to return the
266 * call).
267 * <p>
Santos Cordon96efb482014-07-19 14:57:05 -0700268 * {@link ConnectionService}s which interact with {@link RemoteConnection}s should only populate
269 * this if the {@link android.telephony.TelephonyManager#getLine1Number()} value, as that is the
270 * user's expected caller ID.
Evan Charlton10197192014-07-19 15:00:29 -0700271 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700272 public static final String EXTRA_CALL_BACK_NUMBER = "android.telecom.extra.CALL_BACK_NUMBER";
Evan Charlton10197192014-07-19 15:00:29 -0700273
274 /**
Santos Cordonf2600eb2015-06-22 15:02:20 -0700275 * A boolean meta-data value indicating whether an {@link InCallService} implements an
276 * in-call user interface. Dialer implementations (see {@link #getDefaultDialerPackage()}) which
277 * would also like to replace the in-call interface should set this meta-data to {@code true} in
278 * the manifest registration of their {@link InCallService}.
279 */
280 public static final String METADATA_IN_CALL_SERVICE_UI = "android.telecom.IN_CALL_SERVICE_UI";
281
282 /**
Evan Charlton10197192014-07-19 15:00:29 -0700283 * The dual tone multi-frequency signaling character sent to indicate the dialing system should
284 * pause for a predefined period.
285 */
286 public static final char DTMF_CHARACTER_PAUSE = ',';
287
288 /**
289 * The dual-tone multi-frequency signaling character sent to indicate the dialing system should
290 * wait for user confirmation before proceeding.
291 */
292 public static final char DTMF_CHARACTER_WAIT = ';';
293
294 /**
295 * TTY (teletypewriter) mode is off.
296 *
297 * @hide
298 */
299 public static final int TTY_MODE_OFF = 0;
300
301 /**
302 * TTY (teletypewriter) mode is on. The speaker is off and the microphone is muted. The user
303 * will communicate with the remote party by sending and receiving text messages.
304 *
305 * @hide
306 */
307 public static final int TTY_MODE_FULL = 1;
308
309 /**
310 * TTY (teletypewriter) mode is in hearing carryover mode (HCO). The microphone is muted but the
311 * speaker is on. The user will communicate with the remote party by sending text messages and
312 * hearing an audible reply.
313 *
314 * @hide
315 */
316 public static final int TTY_MODE_HCO = 2;
317
318 /**
319 * TTY (teletypewriter) mode is in voice carryover mode (VCO). The speaker is off but the
320 * microphone is still on. User will communicate with the remote party by speaking and receiving
321 * text message replies.
322 *
323 * @hide
324 */
325 public static final int TTY_MODE_VCO = 3;
326
327 /**
328 * Broadcast intent action indicating that the current TTY mode has changed. An intent extra
329 * provides this state as an int.
Evan Charlton10197192014-07-19 15:00:29 -0700330 *
Santos Cordon96efb482014-07-19 14:57:05 -0700331 * @see #EXTRA_CURRENT_TTY_MODE
Evan Charlton10197192014-07-19 15:00:29 -0700332 * @hide
333 */
334 public static final String ACTION_CURRENT_TTY_MODE_CHANGED =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700335 "android.telecom.action.CURRENT_TTY_MODE_CHANGED";
Evan Charlton10197192014-07-19 15:00:29 -0700336
337 /**
338 * The lookup key for an int that indicates the current TTY mode.
339 * Valid modes are:
340 * - {@link #TTY_MODE_OFF}
341 * - {@link #TTY_MODE_FULL}
342 * - {@link #TTY_MODE_HCO}
343 * - {@link #TTY_MODE_VCO}
344 *
345 * @hide
346 */
347 public static final String EXTRA_CURRENT_TTY_MODE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700348 "android.telecom.intent.extra.CURRENT_TTY_MODE";
Evan Charlton10197192014-07-19 15:00:29 -0700349
350 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700351 * Broadcast intent action indicating that the TTY preferred operating mode has changed. An
352 * intent extra provides the new mode as an int.
Evan Charlton10197192014-07-19 15:00:29 -0700353 *
Santos Cordon96efb482014-07-19 14:57:05 -0700354 * @see #EXTRA_TTY_PREFERRED_MODE
Evan Charlton10197192014-07-19 15:00:29 -0700355 * @hide
356 */
357 public static final String ACTION_TTY_PREFERRED_MODE_CHANGED =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700358 "android.telecom.action.TTY_PREFERRED_MODE_CHANGED";
Evan Charlton10197192014-07-19 15:00:29 -0700359
360 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700361 * The lookup key for an int that indicates preferred TTY mode. Valid modes are: -
362 * {@link #TTY_MODE_OFF} - {@link #TTY_MODE_FULL} - {@link #TTY_MODE_HCO} -
363 * {@link #TTY_MODE_VCO}
Evan Charlton10197192014-07-19 15:00:29 -0700364 *
365 * @hide
366 */
367 public static final String EXTRA_TTY_PREFERRED_MODE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700368 "android.telecom.intent.extra.TTY_PREFERRED";
Evan Charlton10197192014-07-19 15:00:29 -0700369
Nancy Chen9d568c02014-09-08 14:17:59 -0700370 /**
Bryce Lee5e4dd3e2015-08-03 16:59:10 -0700371 * Broadcast intent action for letting custom component know to show the missed call
372 * notification.
373 * @hide
374 */
375 @SystemApi
376 public static final String ACTION_SHOW_MISSED_CALLS_NOTIFICATION =
377 "android.telecom.action.SHOW_MISSED_CALLS_NOTIFICATION";
378
379 /**
380 * The number of calls associated with the notification.
381 * @hide
382 */
383 @SystemApi
384 public static final String EXTRA_NOTIFICATION_COUNT =
385 "android.telecom.extra.NOTIFICATION_COUNT";
386
387 /**
388 * The number associated with the missed calls. This number is only relevant
389 * when EXTRA_NOTIFICATION_COUNT is 1.
390 * @hide
391 */
392 @SystemApi
393 public static final String EXTRA_NOTIFICATION_PHONE_NUMBER =
394 "android.telecom.extra.NOTIFICATION_PHONE_NUMBER";
395
396 /**
Bryce Lee8d41d1d2015-08-10 07:40:42 -0700397 * The intent to clear missed calls.
398 * @hide
399 */
400 @SystemApi
401 public static final String EXTRA_CLEAR_MISSED_CALLS_INTENT =
402 "android.telecom.extra.CLEAR_MISSED_CALLS_INTENT";
403
404 /**
405 * The intent to call back a missed call.
406 * @hide
407 */
408 @SystemApi
409 public static final String EXTRA_CALL_BACK_INTENT =
410 "android.telecom.extra.CALL_BACK_INTENT";
411
412 /**
Nancy Chen9d568c02014-09-08 14:17:59 -0700413 * The following 4 constants define how properties such as phone numbers and names are
414 * displayed to the user.
415 */
416
Santos Cordoned769ae2015-05-13 18:47:38 -0700417 /**
418 * Indicates that the address or number of a call is allowed to be displayed for caller ID.
419 */
Nancy Chen9d568c02014-09-08 14:17:59 -0700420 public static final int PRESENTATION_ALLOWED = 1;
421
Santos Cordoned769ae2015-05-13 18:47:38 -0700422 /**
423 * Indicates that the address or number of a call is blocked by the other party.
424 */
Nancy Chen9d568c02014-09-08 14:17:59 -0700425 public static final int PRESENTATION_RESTRICTED = 2;
426
Santos Cordoned769ae2015-05-13 18:47:38 -0700427 /**
428 * Indicates that the address or number of a call is not specified or known by the carrier.
429 */
Nancy Chen9d568c02014-09-08 14:17:59 -0700430 public static final int PRESENTATION_UNKNOWN = 3;
431
Santos Cordoned769ae2015-05-13 18:47:38 -0700432 /**
433 * Indicates that the address or number of a call belongs to a pay phone.
434 */
Nancy Chen9d568c02014-09-08 14:17:59 -0700435 public static final int PRESENTATION_PAYPHONE = 4;
436
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700437 private static final String TAG = "TelecomManager";
Yorke Leeb4ce1432014-06-09 13:53:23 -0700438
439 private final Context mContext;
Yorke Leeb4ce1432014-06-09 13:53:23 -0700440
Santos Cordon6c7a3882014-06-25 15:30:08 -0700441 /**
442 * @hide
443 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700444 public static TelecomManager from(Context context) {
445 return (TelecomManager) context.getSystemService(Context.TELECOM_SERVICE);
Yorke Leeb4ce1432014-06-09 13:53:23 -0700446 }
Santos Cordon6c7a3882014-06-25 15:30:08 -0700447
448 /**
449 * @hide
450 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700451 public TelecomManager(Context context) {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700452 Context appContext = context.getApplicationContext();
453 if (appContext != null) {
454 mContext = appContext;
455 } else {
456 mContext = context;
457 }
458 }
459
460 /**
Santos Cordon91371dc2015-05-08 13:52:09 -0700461 * Return the {@link PhoneAccount} which will be used to place outgoing calls to addresses with
462 * the specified {@code uriScheme}. This {@link PhoneAccount} will always be a member of the
463 * list which is returned from invoking {@link #getCallCapablePhoneAccounts()}. The specific
464 * account returned depends on the following priorities:
465 * <ul>
466 * <li> If the user-selected default {@link PhoneAccount} supports the specified scheme, it will
467 * be returned.
468 * </li>
469 * <li> If there exists only one {@link PhoneAccount} that supports the specified scheme, it
470 * will be returned.
471 * </li>
472 * </ul>
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700473 * <p>
Santos Cordon91371dc2015-05-08 13:52:09 -0700474 * If no {@link PhoneAccount} fits the criteria above, this method will return {@code null}.
475 *
Yorke Leec61d1362015-09-21 17:25:25 -0700476 * Requires permission: {@link android.Manifest.permission#READ_PHONE_STATE}
477 *
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700478 * @param uriScheme The URI scheme.
Santos Cordon91371dc2015-05-08 13:52:09 -0700479 * @return The {@link PhoneAccountHandle} corresponding to the account to be used.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700480 */
Yorke Leec61d1362015-09-21 17:25:25 -0700481 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700482 public PhoneAccountHandle getDefaultOutgoingPhoneAccount(String uriScheme) {
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700483 try {
484 if (isServiceConnected()) {
Svet Ganov16a16892015-04-16 10:32:04 -0700485 return getTelecomService().getDefaultOutgoingPhoneAccount(uriScheme,
486 mContext.getOpPackageName());
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700487 }
488 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700489 Log.e(TAG, "Error calling ITelecomService#getDefaultOutgoingPhoneAccount", e);
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700490 }
491 return null;
492 }
493
494 /**
Andrew Leed4abbfb2014-09-03 14:58:27 -0700495 * Return the {@link PhoneAccount} which is the user-chosen default for making outgoing phone
496 * calls. This {@code PhoneAccount} will always be a member of the list which is returned from
Nancy Chen210ef032014-09-15 17:58:42 -0700497 * calling {@link #getCallCapablePhoneAccounts()}
Santos Cordon91371dc2015-05-08 13:52:09 -0700498 * <p>
Andrew Leed4abbfb2014-09-03 14:58:27 -0700499 * Apps must be prepared for this method to return {@code null}, indicating that there currently
500 * exists no user-chosen default {@code PhoneAccount}.
501 *
502 * @return The user outgoing phone account selected by the user.
Jay Shrauner225ccad2015-04-15 15:51:15 -0700503 * @hide
Andrew Leed4abbfb2014-09-03 14:58:27 -0700504 */
505 public PhoneAccountHandle getUserSelectedOutgoingPhoneAccount() {
506 try {
507 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700508 return getTelecomService().getUserSelectedOutgoingPhoneAccount();
Andrew Leed4abbfb2014-09-03 14:58:27 -0700509 }
510 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700511 Log.e(TAG, "Error calling ITelecomService#getUserSelectedOutgoingPhoneAccount", e);
Andrew Leed4abbfb2014-09-03 14:58:27 -0700512 }
513 return null;
514 }
515
516 /**
Santos Cordon91371dc2015-05-08 13:52:09 -0700517 * Sets the user-chosen default for making outgoing phone calls.
Andrew Lee59cac3a2014-08-28 16:50:10 -0700518 * @hide
519 */
Andrew Leed4abbfb2014-09-03 14:58:27 -0700520 public void setUserSelectedOutgoingPhoneAccount(PhoneAccountHandle accountHandle) {
Andrew Lee59cac3a2014-08-28 16:50:10 -0700521 try {
522 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700523 getTelecomService().setUserSelectedOutgoingPhoneAccount(accountHandle);
Andrew Lee59cac3a2014-08-28 16:50:10 -0700524 }
525 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700526 Log.e(TAG, "Error calling ITelecomService#setUserSelectedOutgoingPhoneAccount");
Andrew Lee59cac3a2014-08-28 16:50:10 -0700527 }
528 }
529
530 /**
Andrew Lee59cac3a2014-08-28 16:50:10 -0700531 * Returns the current SIM call manager. Apps must be prepared for this method to return
532 * {@code null}, indicating that there currently exists no user-chosen default
533 * {@code PhoneAccount}.
Santos Cordon91371dc2015-05-08 13:52:09 -0700534 *
Andrew Lee59cac3a2014-08-28 16:50:10 -0700535 * @return The phone account handle of the current sim call manager.
Andrew Lee59cac3a2014-08-28 16:50:10 -0700536 */
537 public PhoneAccountHandle getSimCallManager() {
538 try {
539 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700540 return getTelecomService().getSimCallManager();
Andrew Lee59cac3a2014-08-28 16:50:10 -0700541 }
542 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700543 Log.e(TAG, "Error calling ITelecomService#getSimCallManager");
Andrew Lee59cac3a2014-08-28 16:50:10 -0700544 }
545 return null;
546 }
547
548 /**
Sailesh Nepalcf855622015-07-28 19:22:14 -0700549 * Returns the current SIM call manager for the specified user. Apps must be prepared for this
550 * method to return {@code null}, indicating that there currently exists no user-chosen default
551 * {@code PhoneAccount}.
552 *
553 * @return The phone account handle of the current sim call manager.
554 *
555 * @hide
556 */
557 public PhoneAccountHandle getSimCallManager(int userId) {
558 try {
559 if (isServiceConnected()) {
560 return getTelecomService().getSimCallManagerForUser(userId);
561 }
562 } catch (RemoteException e) {
563 Log.e(TAG, "Error calling ITelecomService#getSimCallManagerForUser");
564 }
565 return null;
566 }
567
568 /**
Evan Charltoneb0a8d52014-09-04 12:03:34 -0700569 * Returns the current connection manager. Apps must be prepared for this method to return
570 * {@code null}, indicating that there currently exists no user-chosen default
571 * {@code PhoneAccount}.
572 *
573 * @return The phone account handle of the current connection manager.
Evan Charlton0e094d92014-11-08 15:49:16 -0800574 * @hide
Evan Charltoneb0a8d52014-09-04 12:03:34 -0700575 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800576 @SystemApi
Evan Charltoneb0a8d52014-09-04 12:03:34 -0700577 public PhoneAccountHandle getConnectionManager() {
578 return getSimCallManager();
579 }
580
581 /**
Nancy Chen210ef032014-09-15 17:58:42 -0700582 * Returns a list of the {@link PhoneAccountHandle}s which can be used to make and receive phone
583 * calls which support the specified URI scheme.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700584 * <P>
585 * For example, invoking with {@code "tel"} will find all {@link PhoneAccountHandle}s which
586 * support telephone calls (e.g. URIs such as {@code tel:555-555-1212}). Invoking with
587 * {@code "sip"} will find all {@link PhoneAccountHandle}s which support SIP calls (e.g. URIs
588 * such as {@code sip:example@sipexample.com}).
589 *
590 * @param uriScheme The URI scheme.
591 * @return A list of {@code PhoneAccountHandle} objects supporting the URI scheme.
Evan Charlton0e094d92014-11-08 15:49:16 -0800592 * @hide
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700593 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800594 @SystemApi
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700595 public List<PhoneAccountHandle> getPhoneAccountsSupportingScheme(String uriScheme) {
596 try {
597 if (isServiceConnected()) {
Svet Ganov16a16892015-04-16 10:32:04 -0700598 return getTelecomService().getPhoneAccountsSupportingScheme(uriScheme,
599 mContext.getOpPackageName());
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700600 }
601 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700602 Log.e(TAG, "Error calling ITelecomService#getPhoneAccountsSupportingScheme", e);
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700603 }
604 return new ArrayList<>();
605 }
606
Nancy Chen513c8922014-09-17 14:47:20 -0700607
608 /**
Santos Cordon91371dc2015-05-08 13:52:09 -0700609 * Returns a list of {@link PhoneAccountHandle}s which can be used to make and receive phone
610 * calls. The returned list includes only those accounts which have been explicitly enabled
611 * by the user.
Nancy Chen513c8922014-09-17 14:47:20 -0700612 *
Yorke Leec61d1362015-09-21 17:25:25 -0700613 * Requires permission: {@link android.Manifest.permission#READ_PHONE_STATE}
614 *
Nancy Chen513c8922014-09-17 14:47:20 -0700615 * @see #EXTRA_PHONE_ACCOUNT_HANDLE
616 * @return A list of {@code PhoneAccountHandle} objects.
Nancy Chen513c8922014-09-17 14:47:20 -0700617 */
Yorke Leec61d1362015-09-21 17:25:25 -0700618 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
Nancy Chen513c8922014-09-17 14:47:20 -0700619 public List<PhoneAccountHandle> getCallCapablePhoneAccounts() {
Santos Cordon91371dc2015-05-08 13:52:09 -0700620 return getCallCapablePhoneAccounts(false);
621 }
622
623 /**
624 * Returns a list of {@link PhoneAccountHandle}s including those which have not been enabled
625 * by the user.
626 *
627 * @return A list of {@code PhoneAccountHandle} objects.
628 * @hide
629 */
630 public List<PhoneAccountHandle> getCallCapablePhoneAccounts(boolean includeDisabledAccounts) {
Nancy Chen513c8922014-09-17 14:47:20 -0700631 try {
632 if (isServiceConnected()) {
Santos Cordon91371dc2015-05-08 13:52:09 -0700633 return getTelecomService().getCallCapablePhoneAccounts(
634 includeDisabledAccounts, mContext.getOpPackageName());
Nancy Chen513c8922014-09-17 14:47:20 -0700635 }
636 } catch (RemoteException e) {
Santos Cordon91371dc2015-05-08 13:52:09 -0700637 Log.e(TAG, "Error calling ITelecomService#getCallCapablePhoneAccounts(" +
638 includeDisabledAccounts + ")", e);
Nancy Chen513c8922014-09-17 14:47:20 -0700639 }
640 return new ArrayList<>();
641 }
642
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700643 /**
Nancy Chen513c8922014-09-17 14:47:20 -0700644 * Returns a list of all {@link PhoneAccount}s registered for the calling package.
645 *
646 * @return A list of {@code PhoneAccountHandle} objects.
Evan Charlton0e094d92014-11-08 15:49:16 -0800647 * @hide
Nancy Chen513c8922014-09-17 14:47:20 -0700648 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800649 @SystemApi
Nancy Chen513c8922014-09-17 14:47:20 -0700650 public List<PhoneAccountHandle> getPhoneAccountsForPackage() {
651 try {
652 if (isServiceConnected()) {
653 return getTelecomService().getPhoneAccountsForPackage(mContext.getPackageName());
654 }
655 } catch (RemoteException e) {
656 Log.e(TAG, "Error calling ITelecomService#getPhoneAccountsForPackage", e);
657 }
658 return null;
659 }
660
661 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700662 * Return the {@link PhoneAccount} for a specified {@link PhoneAccountHandle}. Object includes
663 * resources which can be used in a user interface.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700664 *
Evan Charlton6eb262c2014-07-19 18:18:19 -0700665 * @param account The {@link PhoneAccountHandle}.
Evan Charlton8c8a0622014-07-20 12:31:00 -0700666 * @return The {@link PhoneAccount} object.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700667 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700668 public PhoneAccount getPhoneAccount(PhoneAccountHandle account) {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700669 try {
670 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700671 return getTelecomService().getPhoneAccount(account);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700672 }
673 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700674 Log.e(TAG, "Error calling ITelecomService#getPhoneAccount", e);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700675 }
676 return null;
677 }
678
679 /**
Nancy Chen210ef032014-09-15 17:58:42 -0700680 * Returns a count of all {@link PhoneAccount}s.
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700681 *
Nancy Chen210ef032014-09-15 17:58:42 -0700682 * @return The count of {@link PhoneAccount}s.
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700683 * @hide
684 */
685 @SystemApi
686 public int getAllPhoneAccountsCount() {
687 try {
688 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700689 return getTelecomService().getAllPhoneAccountsCount();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700690 }
691 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700692 Log.e(TAG, "Error calling ITelecomService#getAllPhoneAccountsCount", e);
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700693 }
694 return 0;
695 }
696
697 /**
698 * Returns a list of all {@link PhoneAccount}s.
699 *
700 * @return All {@link PhoneAccount}s.
701 * @hide
702 */
703 @SystemApi
704 public List<PhoneAccount> getAllPhoneAccounts() {
705 try {
706 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700707 return getTelecomService().getAllPhoneAccounts();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700708 }
709 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700710 Log.e(TAG, "Error calling ITelecomService#getAllPhoneAccounts", e);
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700711 }
712 return Collections.EMPTY_LIST;
713 }
714
715 /**
716 * Returns a list of all {@link PhoneAccountHandle}s.
717 *
718 * @return All {@link PhoneAccountHandle}s.
719 * @hide
720 */
721 @SystemApi
722 public List<PhoneAccountHandle> getAllPhoneAccountHandles() {
723 try {
724 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700725 return getTelecomService().getAllPhoneAccountHandles();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700726 }
727 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700728 Log.e(TAG, "Error calling ITelecomService#getAllPhoneAccountHandles", e);
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700729 }
730 return Collections.EMPTY_LIST;
731 }
732
733 /**
Santos Cordond9e614f2014-10-28 13:10:36 -0700734 * Register a {@link PhoneAccount} for use by the system. When registering
735 * {@link PhoneAccount}s, existing registrations will be overwritten if the
736 * {@link PhoneAccountHandle} matches that of a {@link PhoneAccount} which is already
737 * registered. Once registered, the {@link PhoneAccount} is listed to the user as an option
738 * when placing calls. The user may still need to enable the {@link PhoneAccount} within
739 * the phone app settings before the account is usable.
740 * <p>
741 * A {@link SecurityException} will be thrown if an app tries to register a
742 * {@link PhoneAccountHandle} where the package name specified within
743 * {@link PhoneAccountHandle#getComponentName()} does not match the package name of the app.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700744 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700745 * @param account The complete {@link PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700746 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700747 public void registerPhoneAccount(PhoneAccount account) {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700748 try {
749 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700750 getTelecomService().registerPhoneAccount(account);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700751 }
752 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700753 Log.e(TAG, "Error calling ITelecomService#registerPhoneAccount", e);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700754 }
755 }
756
757 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700758 * Remove a {@link PhoneAccount} registration from the system.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700759 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700760 * @param accountHandle A {@link PhoneAccountHandle} for the {@link PhoneAccount} to unregister.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700761 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700762 public void unregisterPhoneAccount(PhoneAccountHandle accountHandle) {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700763 try {
764 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700765 getTelecomService().unregisterPhoneAccount(accountHandle);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700766 }
767 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700768 Log.e(TAG, "Error calling ITelecomService#unregisterPhoneAccount", e);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700769 }
770 }
771
772 /**
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700773 * Remove all Accounts that belong to the calling package from the system.
Evan Charlton0e094d92014-11-08 15:49:16 -0800774 * @hide
Ihab Awad807fe0a2014-07-09 12:30:52 -0700775 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800776 @SystemApi
Yorke Lee06044272015-04-14 15:16:59 -0700777 public void clearPhoneAccounts() {
778 clearAccounts();
779 }
780 /**
781 * Remove all Accounts that belong to the calling package from the system.
782 * @deprecated Use {@link #clearPhoneAccounts()} instead.
783 * @hide
784 */
785 @SystemApi
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700786 public void clearAccounts() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700787 try {
788 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700789 getTelecomService().clearAccounts(mContext.getPackageName());
Ihab Awad807fe0a2014-07-09 12:30:52 -0700790 }
791 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700792 Log.e(TAG, "Error calling ITelecomService#clearAccounts", e);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700793 }
794 }
795
796 /**
Anthony Lee67279262014-10-27 11:28:40 -0700797 * Remove all Accounts that belong to the specified package from the system.
798 * @hide
799 */
800 public void clearAccountsForPackage(String packageName) {
801 try {
802 if (isServiceConnected() && !TextUtils.isEmpty(packageName)) {
803 getTelecomService().clearAccounts(packageName);
804 }
805 } catch (RemoteException e) {
Nancy Chen5cf27842015-01-24 23:30:27 -0800806 Log.e(TAG, "Error calling ITelecomService#clearAccountsForPackage", e);
Anthony Lee67279262014-10-27 11:28:40 -0700807 }
808 }
809
Yorke Lee1011f482015-04-23 15:58:27 -0700810
Anthony Lee67279262014-10-27 11:28:40 -0700811 /**
Yorke Lee1011f482015-04-23 15:58:27 -0700812 * @deprecated - Use {@link TelecomManager#getDefaultDialerPackage} to directly access
813 * the default dialer's package name instead.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700814 * @hide
815 */
Santos Cordon6c7a3882014-06-25 15:30:08 -0700816 @SystemApi
817 public ComponentName getDefaultPhoneApp() {
818 try {
Santos Cordon9eb45932014-06-27 12:28:43 -0700819 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700820 return getTelecomService().getDefaultPhoneApp();
Santos Cordon9eb45932014-06-27 12:28:43 -0700821 }
Santos Cordon6c7a3882014-06-25 15:30:08 -0700822 } catch (RemoteException e) {
823 Log.e(TAG, "RemoteException attempting to get the default phone app.", e);
824 }
825 return null;
826 }
827
Santos Cordon9eb45932014-06-27 12:28:43 -0700828 /**
Yorke Lee1011f482015-04-23 15:58:27 -0700829 * Used to determine the currently selected default dialer package.
830 *
831 * @return package name for the default dialer package or null if no package has been
832 * selected as the default dialer.
833 */
834 public String getDefaultDialerPackage() {
835 try {
836 if (isServiceConnected()) {
837 return getTelecomService().getDefaultDialerPackage();
838 }
839 } catch (RemoteException e) {
840 Log.e(TAG, "RemoteException attempting to get the default dialer package name.", e);
841 }
842 return null;
843 }
844
845 /**
Yorke Lee107c4ce2015-06-15 12:08:24 -0700846 * Used to set the default dialer package.
847 *
848 * @param packageName to set the default dialer to..
849 *
850 * @result {@code true} if the default dialer was successfully changed, {@code false} if
851 * the specified package does not correspond to an installed dialer, or is already
852 * the default dialer.
853 *
854 * Requires permission: {@link android.Manifest.permission#MODIFY_PHONE_STATE}
855 * Requires permission: {@link android.Manifest.permission#WRITE_SECURE_SETTINGS}
856 *
857 * @hide
858 */
859 public boolean setDefaultDialer(String packageName) {
860 try {
861 if (isServiceConnected()) {
862 return getTelecomService().setDefaultDialer(packageName);
863 }
864 } catch (RemoteException e) {
865 Log.e(TAG, "RemoteException attempting to set the default dialer.", e);
866 }
867 return false;
868 }
869
870 /**
Yorke Lee1011f482015-04-23 15:58:27 -0700871 * Used to determine the dialer package that is preloaded on the system partition.
872 *
873 * @return package name for the system dialer package or null if no system dialer is preloaded.
874 * @hide
875 */
876 public String getSystemDialerPackage() {
877 try {
878 if (isServiceConnected()) {
879 return getTelecomService().getSystemDialerPackage();
880 }
881 } catch (RemoteException e) {
882 Log.e(TAG, "RemoteException attempting to get the system dialer package name.", e);
883 }
884 return null;
885 }
886
887 /**
Nancy Chen443e5012014-10-15 15:48:21 -0700888 * Return whether a given phone number is the configured voicemail number for a
889 * particular phone account.
890 *
Yorke Leec61d1362015-09-21 17:25:25 -0700891 * Requires permission: {@link android.Manifest.permission#READ_PHONE_STATE}
892 *
Nancy Chen443e5012014-10-15 15:48:21 -0700893 * @param accountHandle The handle for the account to check the voicemail number against
894 * @param number The number to look up.
Nancy Chen443e5012014-10-15 15:48:21 -0700895 */
Yorke Leec61d1362015-09-21 17:25:25 -0700896 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
Nancy Chen443e5012014-10-15 15:48:21 -0700897 public boolean isVoiceMailNumber(PhoneAccountHandle accountHandle, String number) {
898 try {
899 if (isServiceConnected()) {
Svet Ganov16a16892015-04-16 10:32:04 -0700900 return getTelecomService().isVoiceMailNumber(accountHandle, number,
901 mContext.getOpPackageName());
Nancy Chen443e5012014-10-15 15:48:21 -0700902 }
903 } catch (RemoteException e) {
Nancy Chen5cf27842015-01-24 23:30:27 -0800904 Log.e(TAG, "RemoteException calling ITelecomService#isVoiceMailNumber.", e);
Nancy Chen443e5012014-10-15 15:48:21 -0700905 }
906 return false;
907 }
908
909 /**
Yorke Lee49e2d462015-04-15 16:14:22 -0700910 * Return the voicemail number for a given phone account.
Nancy Chen8c066f72014-12-03 15:18:08 -0800911 *
Yorke Leec61d1362015-09-21 17:25:25 -0700912 * Requires permission: {@link android.Manifest.permission#READ_PHONE_STATE}
913 *
Yorke Lee49e2d462015-04-15 16:14:22 -0700914 * @param accountHandle The handle for the phone account.
915 * @return The voicemail number for the phone account, and {@code null} if one has not been
916 * configured.
Nancy Chen8c066f72014-12-03 15:18:08 -0800917 */
Yorke Leec61d1362015-09-21 17:25:25 -0700918 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
Yorke Lee49e2d462015-04-15 16:14:22 -0700919 public String getVoiceMailNumber(PhoneAccountHandle accountHandle) {
Nancy Chen8c066f72014-12-03 15:18:08 -0800920 try {
921 if (isServiceConnected()) {
Svet Ganov16a16892015-04-16 10:32:04 -0700922 return getTelecomService().getVoiceMailNumber(accountHandle,
923 mContext.getOpPackageName());
Nancy Chen8c066f72014-12-03 15:18:08 -0800924 }
925 } catch (RemoteException e) {
Nancy Chen5cf27842015-01-24 23:30:27 -0800926 Log.e(TAG, "RemoteException calling ITelecomService#hasVoiceMailNumber.", e);
Nancy Chen8c066f72014-12-03 15:18:08 -0800927 }
Yorke Lee49e2d462015-04-15 16:14:22 -0700928 return null;
Nancy Chen8c066f72014-12-03 15:18:08 -0800929 }
930
931 /**
Nancy Chen5cf27842015-01-24 23:30:27 -0800932 * Return the line 1 phone number for given phone account.
933 *
Yorke Leec61d1362015-09-21 17:25:25 -0700934 * Requires permission: {@link android.Manifest.permission#READ_PHONE_STATE}
935 *
Nancy Chen5cf27842015-01-24 23:30:27 -0800936 * @param accountHandle The handle for the account retrieve a number for.
937 * @return A string representation of the line 1 phone number.
Nancy Chen5cf27842015-01-24 23:30:27 -0800938 */
Yorke Leec61d1362015-09-21 17:25:25 -0700939 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
Nancy Chen5cf27842015-01-24 23:30:27 -0800940 public String getLine1Number(PhoneAccountHandle accountHandle) {
941 try {
942 if (isServiceConnected()) {
Svet Ganov16a16892015-04-16 10:32:04 -0700943 return getTelecomService().getLine1Number(accountHandle,
944 mContext.getOpPackageName());
Nancy Chen5cf27842015-01-24 23:30:27 -0800945 }
946 } catch (RemoteException e) {
947 Log.e(TAG, "RemoteException calling ITelecomService#getLine1Number.", e);
948 }
949 return null;
950 }
951
952 /**
Santos Cordon9eb45932014-06-27 12:28:43 -0700953 * Returns whether there is an ongoing phone call (can be in dialing, ringing, active or holding
954 * states).
Nancy Chen0eb1e402014-08-21 22:52:29 -0700955 * <p>
956 * Requires permission: {@link android.Manifest.permission#READ_PHONE_STATE}
957 * </p>
Santos Cordon9eb45932014-06-27 12:28:43 -0700958 */
Yorke Leec61d1362015-09-21 17:25:25 -0700959 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
Nancy Chen0eb1e402014-08-21 22:52:29 -0700960 public boolean isInCall() {
Santos Cordon9eb45932014-06-27 12:28:43 -0700961 try {
962 if (isServiceConnected()) {
Svet Ganov16a16892015-04-16 10:32:04 -0700963 return getTelecomService().isInCall(mContext.getOpPackageName());
Santos Cordon9eb45932014-06-27 12:28:43 -0700964 }
965 } catch (RemoteException e) {
Yorke Lee2ae312e2014-09-12 17:58:48 -0700966 Log.e(TAG, "RemoteException calling isInCall().", e);
Santos Cordon9eb45932014-06-27 12:28:43 -0700967 }
968 return false;
969 }
970
971 /**
Yorke Lee2ae312e2014-09-12 17:58:48 -0700972 * Returns one of the following constants that represents the current state of Telecom:
973 *
974 * {@link TelephonyManager#CALL_STATE_RINGING}
975 * {@link TelephonyManager#CALL_STATE_OFFHOOK}
976 * {@link TelephonyManager#CALL_STATE_IDLE}
Yorke Lee7c72c2d2014-10-28 14:12:02 -0700977 *
978 * Note that this API does not require the
979 * {@link android.Manifest.permission#READ_PHONE_STATE} permission. This is intentional, to
980 * preserve the behavior of {@link TelephonyManager#getCallState()}, which also did not require
981 * the permission.
Yorke Lee2ae312e2014-09-12 17:58:48 -0700982 * @hide
983 */
984 @SystemApi
985 public int getCallState() {
986 try {
987 if (isServiceConnected()) {
988 return getTelecomService().getCallState();
989 }
990 } catch (RemoteException e) {
991 Log.d(TAG, "RemoteException calling getCallState().", e);
992 }
993 return TelephonyManager.CALL_STATE_IDLE;
994 }
995
996 /**
Santos Cordon9eb45932014-06-27 12:28:43 -0700997 * Returns whether there currently exists is a ringing incoming-call.
998 *
999 * @hide
1000 */
1001 @SystemApi
1002 public boolean isRinging() {
1003 try {
1004 if (isServiceConnected()) {
Svet Ganov16a16892015-04-16 10:32:04 -07001005 return getTelecomService().isRinging(mContext.getOpPackageName());
Santos Cordon9eb45932014-06-27 12:28:43 -07001006 }
1007 } catch (RemoteException e) {
1008 Log.e(TAG, "RemoteException attempting to get ringing state of phone app.", e);
1009 }
1010 return false;
1011 }
1012
1013 /**
Santos Cordon96efb482014-07-19 14:57:05 -07001014 * Ends an ongoing call.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001015 * TODO: L-release - need to convert all invocations of ITelecomService#endCall to use this
Santos Cordon96efb482014-07-19 14:57:05 -07001016 * method (clockwork & gearhead).
Santos Cordon9eb45932014-06-27 12:28:43 -07001017 * @hide
1018 */
1019 @SystemApi
1020 public boolean endCall() {
1021 try {
1022 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001023 return getTelecomService().endCall();
Santos Cordon9eb45932014-06-27 12:28:43 -07001024 }
1025 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001026 Log.e(TAG, "Error calling ITelecomService#endCall", e);
Santos Cordon9eb45932014-06-27 12:28:43 -07001027 }
1028 return false;
1029 }
1030
1031 /**
1032 * If there is a ringing incoming call, this method accepts the call on behalf of the user.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001033 * TODO: L-release - need to convert all invocation of ITelecmmService#answerRingingCall to use
Santos Cordon96efb482014-07-19 14:57:05 -07001034 * this method (clockwork & gearhead).
Santos Cordon9eb45932014-06-27 12:28:43 -07001035 *
1036 * @hide
1037 */
1038 @SystemApi
1039 public void acceptRingingCall() {
1040 try {
1041 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001042 getTelecomService().acceptRingingCall();
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#acceptRingingCall", e);
Santos Cordon9eb45932014-06-27 12:28:43 -07001046 }
1047 }
1048
1049 /**
1050 * Silences the ringer if a ringing call exists.
Yorke Leec61d1362015-09-21 17:25:25 -07001051 *
1052 * Requires permission: {@link android.Manifest.permission#MODIFY_PHONE_STATE}
Santos Cordon9eb45932014-06-27 12:28:43 -07001053 */
Yorke Leec61d1362015-09-21 17:25:25 -07001054 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
Santos Cordon9eb45932014-06-27 12:28:43 -07001055 public void silenceRinger() {
1056 try {
1057 if (isServiceConnected()) {
Yorke Leef1a349b2015-04-29 16:16:50 -07001058 getTelecomService().silenceRinger(mContext.getOpPackageName());
Santos Cordon9eb45932014-06-27 12:28:43 -07001059 }
1060 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001061 Log.e(TAG, "Error calling ITelecomService#silenceRinger", e);
Santos Cordon9eb45932014-06-27 12:28:43 -07001062 }
1063 }
1064
Sailesh Nepal001bbbb2014-07-15 14:40:39 -07001065 /**
1066 * Returns whether TTY is supported on this device.
1067 *
1068 * @hide
1069 */
1070 @SystemApi
1071 public boolean isTtySupported() {
1072 try {
1073 if (isServiceConnected()) {
Svet Ganov16a16892015-04-16 10:32:04 -07001074 return getTelecomService().isTtySupported(mContext.getOpPackageName());
Sailesh Nepal001bbbb2014-07-15 14:40:39 -07001075 }
1076 } catch (RemoteException e) {
1077 Log.e(TAG, "RemoteException attempting to get TTY supported state.", e);
1078 }
1079 return false;
1080 }
1081
1082 /**
1083 * 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 -07001084 * settings and have a wired headset plugged in.
1085 * Valid modes are:
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001086 * - {@link TelecomManager#TTY_MODE_OFF}
1087 * - {@link TelecomManager#TTY_MODE_FULL}
1088 * - {@link TelecomManager#TTY_MODE_HCO}
1089 * - {@link TelecomManager#TTY_MODE_VCO}
Sailesh Nepal001bbbb2014-07-15 14:40:39 -07001090 * @hide
1091 */
1092 public int getCurrentTtyMode() {
1093 try {
1094 if (isServiceConnected()) {
Svet Ganov16a16892015-04-16 10:32:04 -07001095 return getTelecomService().getCurrentTtyMode(mContext.getOpPackageName());
Sailesh Nepal001bbbb2014-07-15 14:40:39 -07001096 }
1097 } catch (RemoteException e) {
1098 Log.e(TAG, "RemoteException attempting to get the current TTY mode.", e);
1099 }
Evan Charlton10197192014-07-19 15:00:29 -07001100 return TTY_MODE_OFF;
Sailesh Nepal001bbbb2014-07-15 14:40:39 -07001101 }
1102
Santos Cordon96efb482014-07-19 14:57:05 -07001103 /**
1104 * Registers a new incoming call. A {@link ConnectionService} should invoke this method when it
1105 * has an incoming call. The specified {@link PhoneAccountHandle} must have been registered
Nancy Chen210ef032014-09-15 17:58:42 -07001106 * with {@link #registerPhoneAccount}. Once invoked, this method will cause the system to bind
1107 * to the {@link ConnectionService} associated with the {@link PhoneAccountHandle} and request
Santos Cordon96efb482014-07-19 14:57:05 -07001108 * additional information about the call (See
1109 * {@link ConnectionService#onCreateIncomingConnection}) before starting the incoming call UI.
1110 *
1111 * @param phoneAccount A {@link PhoneAccountHandle} registered with
1112 * {@link #registerPhoneAccount}.
1113 * @param extras A bundle that will be passed through to
1114 * {@link ConnectionService#onCreateIncomingConnection}.
1115 */
1116 public void addNewIncomingCall(PhoneAccountHandle phoneAccount, Bundle extras) {
1117 try {
1118 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001119 getTelecomService().addNewIncomingCall(
Santos Cordon96efb482014-07-19 14:57:05 -07001120 phoneAccount, extras == null ? new Bundle() : extras);
1121 }
1122 } catch (RemoteException e) {
1123 Log.e(TAG, "RemoteException adding a new incoming call: " + phoneAccount, e);
1124 }
1125 }
1126
Nancy Chen0eb1e402014-08-21 22:52:29 -07001127 /**
Yorke Leec3cf9822014-10-02 09:38:39 -07001128 * Registers a new unknown call with Telecom. This can only be called by the system Telephony
1129 * service. This is invoked when Telephony detects a new unknown connection that was neither
1130 * a new incoming call, nor an user-initiated outgoing call.
1131 *
1132 * @param phoneAccount A {@link PhoneAccountHandle} registered with
1133 * {@link #registerPhoneAccount}.
1134 * @param extras A bundle that will be passed through to
1135 * {@link ConnectionService#onCreateIncomingConnection}.
1136 * @hide
1137 */
1138 @SystemApi
1139 public void addNewUnknownCall(PhoneAccountHandle phoneAccount, Bundle extras) {
1140 try {
1141 if (isServiceConnected()) {
1142 getTelecomService().addNewUnknownCall(
1143 phoneAccount, extras == null ? new Bundle() : extras);
1144 }
1145 } catch (RemoteException e) {
1146 Log.e(TAG, "RemoteException adding a new unknown call: " + phoneAccount, e);
1147 }
1148 }
1149
1150 /**
Nancy Chen0eb1e402014-08-21 22:52:29 -07001151 * Processes the specified dial string as an MMI code.
1152 * MMI codes are any sequence of characters entered into the dialpad that contain a "*" or "#".
1153 * Some of these sequences launch special behavior through handled by Telephony.
Nancy Chen95e8a672014-10-16 18:38:21 -07001154 * This method uses the default subscription.
Nancy Chen0eb1e402014-08-21 22:52:29 -07001155 * <p>
1156 * Requires that the method-caller be set as the system dialer app.
1157 * </p>
1158 *
Yorke Leec61d1362015-09-21 17:25:25 -07001159 * Requires permission: {@link android.Manifest.permission#MODIFY_PHONE_STATE}
1160 *
Nancy Chen0eb1e402014-08-21 22:52:29 -07001161 * @param dialString The digits to dial.
1162 * @return True if the digits were processed as an MMI code, false otherwise.
1163 */
Yorke Leec61d1362015-09-21 17:25:25 -07001164 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
Nancy Chen0eb1e402014-08-21 22:52:29 -07001165 public boolean handleMmi(String dialString) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001166 ITelecomService service = getTelecomService();
Nancy Chen0eb1e402014-08-21 22:52:29 -07001167 if (service != null) {
1168 try {
Yorke Leef1a349b2015-04-29 16:16:50 -07001169 return service.handlePinMmi(dialString, mContext.getOpPackageName());
Nancy Chen0eb1e402014-08-21 22:52:29 -07001170 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001171 Log.e(TAG, "Error calling ITelecomService#handlePinMmi", e);
Nancy Chen0eb1e402014-08-21 22:52:29 -07001172 }
1173 }
1174 return false;
1175 }
1176
1177 /**
Nancy Chen95e8a672014-10-16 18:38:21 -07001178 * Processes the specified dial string as an MMI code.
1179 * MMI codes are any sequence of characters entered into the dialpad that contain a "*" or "#".
1180 * Some of these sequences launch special behavior through handled by Telephony.
1181 * <p>
1182 * Requires that the method-caller be set as the system dialer app.
1183 * </p>
1184 *
Yorke Leec61d1362015-09-21 17:25:25 -07001185 * Requires permission: {@link android.Manifest.permission#MODIFY_PHONE_STATE}
1186 *
Nancy Chen95e8a672014-10-16 18:38:21 -07001187 * @param accountHandle The handle for the account the MMI code should apply to.
1188 * @param dialString The digits to dial.
1189 * @return True if the digits were processed as an MMI code, false otherwise.
Nancy Chen95e8a672014-10-16 18:38:21 -07001190 */
Yorke Leec61d1362015-09-21 17:25:25 -07001191 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
Yorke Lee06044272015-04-14 15:16:59 -07001192 public boolean handleMmi(String dialString, PhoneAccountHandle accountHandle) {
Nancy Chen95e8a672014-10-16 18:38:21 -07001193 ITelecomService service = getTelecomService();
1194 if (service != null) {
1195 try {
Yorke Leef1a349b2015-04-29 16:16:50 -07001196 return service.handlePinMmiForPhoneAccount(accountHandle, dialString,
1197 mContext.getOpPackageName());
Nancy Chen95e8a672014-10-16 18:38:21 -07001198 } catch (RemoteException e) {
1199 Log.e(TAG, "Error calling ITelecomService#handlePinMmi", e);
1200 }
1201 }
1202 return false;
1203 }
1204
1205 /**
Yorke Leec61d1362015-09-21 17:25:25 -07001206 * Requires permission: {@link android.Manifest.permission#MODIFY_PHONE_STATE}
1207 *
Nancy Chenb2299c12014-10-29 18:22:11 -07001208 * @param accountHandle The handle for the account to derive an adn query URI for or
1209 * {@code null} to return a URI which will use the default account.
1210 * @return The URI (with the content:// scheme) specific to the specified {@link PhoneAccount}
1211 * for the the content retrieve.
1212 */
Yorke Leec61d1362015-09-21 17:25:25 -07001213 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
Nancy Chenb2299c12014-10-29 18:22:11 -07001214 public Uri getAdnUriForPhoneAccount(PhoneAccountHandle accountHandle) {
1215 ITelecomService service = getTelecomService();
1216 if (service != null && accountHandle != null) {
1217 try {
Yorke Leef1a349b2015-04-29 16:16:50 -07001218 return service.getAdnUriForPhoneAccount(accountHandle, mContext.getOpPackageName());
Nancy Chenb2299c12014-10-29 18:22:11 -07001219 } catch (RemoteException e) {
1220 Log.e(TAG, "Error calling ITelecomService#getAdnUriForPhoneAccount", e);
1221 }
1222 }
1223 return Uri.parse("content://icc/adn");
1224 }
1225
1226 /**
Nancy Chen0eb1e402014-08-21 22:52:29 -07001227 * Removes the missed-call notification if one is present.
1228 * <p>
1229 * Requires that the method-caller be set as the system dialer app.
1230 * </p>
Yorke Leec61d1362015-09-21 17:25:25 -07001231 *
1232 * Requires permission: {@link android.Manifest.permission#MODIFY_PHONE_STATE}
Nancy Chen0eb1e402014-08-21 22:52:29 -07001233 */
Yorke Leec61d1362015-09-21 17:25:25 -07001234 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
Nancy Chen0eb1e402014-08-21 22:52:29 -07001235 public void cancelMissedCallsNotification() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001236 ITelecomService service = getTelecomService();
Nancy Chen0eb1e402014-08-21 22:52:29 -07001237 if (service != null) {
1238 try {
Yorke Leef1a349b2015-04-29 16:16:50 -07001239 service.cancelMissedCallsNotification(mContext.getOpPackageName());
Nancy Chen0eb1e402014-08-21 22:52:29 -07001240 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001241 Log.e(TAG, "Error calling ITelecomService#cancelMissedCallsNotification", e);
Nancy Chen0eb1e402014-08-21 22:52:29 -07001242 }
1243 }
1244 }
1245
1246 /**
1247 * Brings the in-call screen to the foreground if there is an ongoing call. If there is
1248 * currently no ongoing call, then this method does nothing.
1249 * <p>
1250 * Requires that the method-caller be set as the system dialer app or have the
1251 * {@link android.Manifest.permission#READ_PHONE_STATE} permission.
1252 * </p>
1253 *
1254 * @param showDialpad Brings up the in-call dialpad as part of showing the in-call screen.
1255 */
Yorke Leec61d1362015-09-21 17:25:25 -07001256 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
Nancy Chen0eb1e402014-08-21 22:52:29 -07001257 public void showInCallScreen(boolean showDialpad) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001258 ITelecomService service = getTelecomService();
Nancy Chen0eb1e402014-08-21 22:52:29 -07001259 if (service != null) {
1260 try {
Svet Ganov16a16892015-04-16 10:32:04 -07001261 service.showInCallScreen(showDialpad, mContext.getOpPackageName());
Nancy Chen0eb1e402014-08-21 22:52:29 -07001262 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001263 Log.e(TAG, "Error calling ITelecomService#showCallScreen", e);
Nancy Chen0eb1e402014-08-21 22:52:29 -07001264 }
1265 }
1266 }
1267
Yorke Lee3e56ba12015-04-23 12:32:36 -07001268 /**
1269 * Places a new outgoing call to the provided address using the system telecom service with
1270 * the specified extras.
1271 *
1272 * This method is equivalent to placing an outgoing call using {@link Intent#ACTION_CALL},
1273 * except that the outgoing call will always be sent via the system telecom service. If
1274 * method-caller is either the user selected default dialer app or preloaded system dialer
1275 * app, then emergency calls will also be allowed.
1276 *
1277 * Requires permission: {@link android.Manifest.permission#CALL_PHONE}
1278 *
1279 * Usage example:
1280 * <pre>
1281 * Uri uri = Uri.fromParts("tel", "12345", null);
1282 * Bundle extras = new Bundle();
1283 * extras.putBoolean(TelecomManager.EXTRA_START_CALL_WITH_SPEAKERPHONE, true);
1284 * telecomManager.placeCall(uri, extras);
1285 * </pre>
1286 *
Santos Cordon7a060d52015-06-19 14:52:04 -07001287 * The following keys are supported in the supplied extras.
1288 * <ul>
1289 * <li>{@link #EXTRA_OUTGOING_CALL_EXTRAS}</li>
1290 * <li>{@link #EXTRA_PHONE_ACCOUNT_HANDLE}</li>
1291 * <li>{@link #EXTRA_START_CALL_WITH_SPEAKERPHONE}</li>
1292 * <li>{@link #EXTRA_START_CALL_WITH_VIDEO_STATE}</li>
1293 * </ul>
1294 *
Yorke Lee3e56ba12015-04-23 12:32:36 -07001295 * @param address The address to make the call to.
1296 * @param extras Bundle of extras to use with the call.
1297 */
Yorke Leec61d1362015-09-21 17:25:25 -07001298 @RequiresPermission(android.Manifest.permission.CALL_PHONE)
Yorke Lee3e56ba12015-04-23 12:32:36 -07001299 public void placeCall(Uri address, Bundle extras) {
1300 ITelecomService service = getTelecomService();
1301 if (service != null) {
Yorke Leea5d5c1d2015-05-05 16:25:55 -07001302 if (address == null) {
1303 Log.w(TAG, "Cannot place call to empty address.");
1304 }
Yorke Lee3e56ba12015-04-23 12:32:36 -07001305 try {
Yorke Leea5d5c1d2015-05-05 16:25:55 -07001306 service.placeCall(address, extras == null ? new Bundle() : extras,
1307 mContext.getOpPackageName());
Yorke Lee3e56ba12015-04-23 12:32:36 -07001308 } catch (RemoteException e) {
1309 Log.e(TAG, "Error calling ITelecomService#placeCall", e);
1310 }
1311 }
1312 }
1313
Santos Cordon91371dc2015-05-08 13:52:09 -07001314 /**
1315 * Enables and disables specified phone account.
1316 *
1317 * @param handle Handle to the phone account.
1318 * @param isEnabled Enable state of the phone account.
1319 * @hide
1320 */
1321 @SystemApi
1322 public void enablePhoneAccount(PhoneAccountHandle handle, boolean isEnabled) {
1323 ITelecomService service = getTelecomService();
1324 if (service != null) {
1325 try {
1326 service.enablePhoneAccount(handle, isEnabled);
1327 } catch (RemoteException e) {
1328 Log.e(TAG, "Error enablePhoneAbbount", e);
1329 }
1330 }
1331 }
1332
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001333 private ITelecomService getTelecomService() {
1334 return ITelecomService.Stub.asInterface(ServiceManager.getService(Context.TELECOM_SERVICE));
Santos Cordon6c7a3882014-06-25 15:30:08 -07001335 }
Santos Cordon9eb45932014-06-27 12:28:43 -07001336
1337 private boolean isServiceConnected() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001338 boolean isConnected = getTelecomService() != null;
Santos Cordon9eb45932014-06-27 12:28:43 -07001339 if (!isConnected) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001340 Log.w(TAG, "Telecom Service not found.");
Santos Cordon9eb45932014-06-27 12:28:43 -07001341 }
1342 return isConnected;
1343 }
Evan Charlton235c1592014-09-05 15:41:23 +00001344}