blob: 0cd8c191203ed8beea6bd0484123a3773dbfc97d [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
Santos Cordon6c7a3882014-06-25 15:30:08 -070017import android.annotation.SystemApi;
18import android.content.ComponentName;
Yorke Leeb4ce1432014-06-09 13:53:23 -070019import android.content.Context;
Yorke Lee3e56ba12015-04-23 12:32:36 -070020import android.content.Intent;
Nancy Chenb2299c12014-10-29 18:22:11 -070021import android.net.Uri;
Santos Cordon96efb482014-07-19 14:57:05 -070022import android.os.Bundle;
Santos Cordon6c7a3882014-06-25 15:30:08 -070023import android.os.RemoteException;
24import android.os.ServiceManager;
Yorke Lee2ae312e2014-09-12 17:58:48 -070025import android.telephony.TelephonyManager;
Anthony Lee67279262014-10-27 11:28:40 -070026import android.text.TextUtils;
Santos Cordon6c7a3882014-06-25 15:30:08 -070027import android.util.Log;
Yorke Leeb4ce1432014-06-09 13:53:23 -070028
Tyler Gunnef9f6f92014-09-12 22:16:17 -070029import com.android.internal.telecom.ITelecomService;
Yorke Leeb4ce1432014-06-09 13:53:23 -070030
Jay Shrauner7746a942014-08-26 12:15:15 -070031import java.util.ArrayList;
Tyler Gunna1ed7d12014-09-08 09:52:22 -070032import java.util.Collections;
Ihab Awad807fe0a2014-07-09 12:30:52 -070033import java.util.List;
34
Yorke Leeb4ce1432014-06-09 13:53:23 -070035/**
Santos Cordond9e614f2014-10-28 13:10:36 -070036 * Provides access to information about active calls and registration/call-management functionality.
Evan Charlton0e094d92014-11-08 15:49:16 -080037 * Apps can use methods in this class to determine the current call state.
Santos Cordond9e614f2014-10-28 13:10:36 -070038 * <p>
39 * Apps do not instantiate this class directly; instead, they retrieve a reference to an instance
40 * through {@link Context#getSystemService Context.getSystemService(Context.TELECOM_SERVICE)}.
41 * <p>
42 * Note that access to some telecom information is permission-protected. Your app cannot access the
43 * protected information or gain access to protected functionality unless it has the appropriate
44 * permissions declared in its manifest file. Where permissions apply, they are noted in the method
45 * descriptions.
Yorke Leeb4ce1432014-06-09 13:53:23 -070046 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -070047public class TelecomManager {
Ihab Awad807fe0a2014-07-09 12:30:52 -070048
Evan Charlton10197192014-07-19 15:00:29 -070049 /**
Santos Cordon96efb482014-07-19 14:57:05 -070050 * Activity action: Starts the UI for handing an incoming call. This intent starts the in-call
Tyler Gunnef9f6f92014-09-12 22:16:17 -070051 * UI by notifying the Telecom system that an incoming call exists for a specific call service
52 * (see {@link android.telecom.ConnectionService}). Telecom reads the Intent extras to find
53 * and bind to the appropriate {@link android.telecom.ConnectionService} which Telecom will
Santos Cordon96efb482014-07-19 14:57:05 -070054 * ultimately use to control and get information about the call.
55 * <p>
56 * Input: get*Extra field {@link #EXTRA_PHONE_ACCOUNT_HANDLE} contains the component name of the
Tyler Gunnef9f6f92014-09-12 22:16:17 -070057 * {@link android.telecom.ConnectionService} that Telecom should bind to. Telecom will then
Evan Charlton10197192014-07-19 15:00:29 -070058 * ask the connection service for more information about the call prior to showing any UI.
Evan Charlton10197192014-07-19 15:00:29 -070059 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -070060 public static final String ACTION_INCOMING_CALL = "android.telecom.action.INCOMING_CALL";
Evan Charlton10197192014-07-19 15:00:29 -070061
62 /**
Yorke Leec3cf9822014-10-02 09:38:39 -070063 * Similar to {@link #ACTION_INCOMING_CALL}, but is used only by Telephony to add a new
64 * sim-initiated MO call for carrier testing.
65 * @hide
66 */
67 public static final String ACTION_NEW_UNKNOWN_CALL = "android.telecom.action.NEW_UNKNOWN_CALL";
68
69 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -070070 * The {@link android.content.Intent} action used to configure a
Tyler Gunnef9f6f92014-09-12 22:16:17 -070071 * {@link android.telecom.ConnectionService}.
Evan Charlton10197192014-07-19 15:00:29 -070072 */
73 public static final String ACTION_CONNECTION_SERVICE_CONFIGURE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -070074 "android.telecom.action.CONNECTION_SERVICE_CONFIGURE";
Evan Charlton10197192014-07-19 15:00:29 -070075
76 /**
Andrew Lee873cfbf2015-02-26 15:22:00 -080077 * The {@link android.content.Intent} action used to show the call accessibility settings page.
78 */
79 public static final String ACTION_SHOW_CALL_ACCESSIBILITY_SETTINGS =
80 "android.telecom.action.SHOW_CALL_ACCESSIBILITY_SETTINGS";
81
82 /**
Yorke Lee3818a892014-07-21 15:57:17 -070083 * The {@link android.content.Intent} action used to show the call settings page.
84 */
85 public static final String ACTION_SHOW_CALL_SETTINGS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -070086 "android.telecom.action.SHOW_CALL_SETTINGS";
Yorke Lee3818a892014-07-21 15:57:17 -070087
88 /**
Andrew Lee866080f2015-02-19 12:05:33 -080089 * The {@link android.content.Intent} action used to show the respond via SMS settings page.
90 */
91 public static final String ACTION_SHOW_RESPOND_VIA_SMS_SETTINGS =
92 "android.telecom.action.SHOW_RESPOND_VIA_SMS_SETTINGS";
93
94 /**
Evan Charlton6d8604f2014-09-04 12:38:17 -070095 * The {@link android.content.Intent} action used to show the settings page used to configure
96 * {@link PhoneAccount} preferences.
97 */
98 public static final String ACTION_CHANGE_PHONE_ACCOUNTS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -070099 "android.telecom.action.CHANGE_PHONE_ACCOUNTS";
Evan Charlton6d8604f2014-09-04 12:38:17 -0700100
101 /**
Santos Cordonc66f3ba2015-02-27 15:22:07 -0800102 * The {@link android.content.Intent} action used indicate that a new phone account was
103 * just registered.
104 * @hide
105 */
106 @SystemApi
107 public static final String ACTION_PHONE_ACCOUNT_REGISTERED =
108 "android.telecom.action.PHONE_ACCOUNT_REGISTERED";
109
110 /**
Yorke Lee1011f482015-04-23 15:58:27 -0700111 * Activity action: Shows a dialog asking the user whether or not they want to replace the
112 * current default Dialer with the one specified in
113 * {@link #EXTRA_CHANGE_DEFAULT_DIALER_PACKAGE_NAME}.
114 *
115 * Usage example:
116 * <pre>
117 * Intent intent = new Intent(TelecomManager.ACTION_CHANGE_DEFAULT_DIALER);
118 * intent.putExtra(TelecomManager.EXTRA_CHANGE_DEFAULT_DIALER_PACKAGE_NAME,
119 * getActivity().getPackageName());
120 * startActivity(intent);
121 * </pre>
122 */
123 public static final String ACTION_CHANGE_DEFAULT_DIALER =
124 "android.telecom.action.CHANGE_DEFAULT_DIALER";
125
126 /**
Yorke Lee107c4ce2015-06-15 12:08:24 -0700127 * Broadcast intent action indicating that the current default dialer has changed.
128 * The string extra {@link #EXTRA_CHANGE_DEFAULT_DIALER_PACKAGE_NAME} will contain the
129 * name of the package that the default dialer was changed to.
130 *
131 * @see #EXTRA_CHANGE_DEFAULT_DIALER_PACKAGE_NAME
132 */
133 public static final String ACTION_DEFAULT_DIALER_CHANGED =
134 "android.telecom.action.DEFAULT_DIALER_CHANGED";
135
136 /**
Yorke Lee1011f482015-04-23 15:58:27 -0700137 * Extra value used to provide the package name for {@link #ACTION_CHANGE_DEFAULT_DIALER}.
138 */
139 public static final String EXTRA_CHANGE_DEFAULT_DIALER_PACKAGE_NAME =
140 "android.telecom.extra.CHANGE_DEFAULT_DIALER_PACKAGE_NAME";
141
142 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700143 * Optional extra for {@link android.content.Intent#ACTION_CALL} containing a boolean that
144 * determines whether the speakerphone should be automatically turned on for an outgoing call.
Evan Charlton10197192014-07-19 15:00:29 -0700145 */
146 public static final String EXTRA_START_CALL_WITH_SPEAKERPHONE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700147 "android.telecom.extra.START_CALL_WITH_SPEAKERPHONE";
Evan Charlton10197192014-07-19 15:00:29 -0700148
149 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700150 * Optional extra for {@link android.content.Intent#ACTION_CALL} containing an integer that
151 * determines the desired video state for an outgoing call.
Santos Cordon96efb482014-07-19 14:57:05 -0700152 * Valid options:
Yorke Lee32f24732015-05-12 16:18:03 -0700153 * {@link VideoProfile#STATE_AUDIO_ONLY},
154 * {@link VideoProfile#STATE_BIDIRECTIONAL},
155 * {@link VideoProfile#STATE_RX_ENABLED},
156 * {@link VideoProfile#STATE_TX_ENABLED}.
Evan Charlton10197192014-07-19 15:00:29 -0700157 */
158 public static final String EXTRA_START_CALL_WITH_VIDEO_STATE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700159 "android.telecom.extra.START_CALL_WITH_VIDEO_STATE";
Evan Charlton10197192014-07-19 15:00:29 -0700160
161 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700162 * The extra used with an {@link android.content.Intent#ACTION_CALL} and
163 * {@link android.content.Intent#ACTION_DIAL} {@code Intent} to specify a
164 * {@link PhoneAccountHandle} to use when making the call.
Evan Charlton10197192014-07-19 15:00:29 -0700165 * <p class="note">
Santos Cordon96efb482014-07-19 14:57:05 -0700166 * Retrieve with {@link android.content.Intent#getParcelableExtra(String)}.
Evan Charlton10197192014-07-19 15:00:29 -0700167 */
Evan Charlton6eb262c2014-07-19 18:18:19 -0700168 public static final String EXTRA_PHONE_ACCOUNT_HANDLE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700169 "android.telecom.extra.PHONE_ACCOUNT_HANDLE";
Evan Charlton10197192014-07-19 15:00:29 -0700170
171 /**
Yorke Lee04ea7d32015-06-05 15:59:18 -0700172 * The extra used by a {@link ConnectionService} to provide the handle of the caller that
173 * has initiated a new incoming call.
174 */
Yorke Lee02fb5bc2015-06-09 12:27:36 -0700175 public static final String EXTRA_INCOMING_CALL_ADDRESS =
176 "android.telecom.extra.INCOMING_CALL_ADDRESS";
Yorke Lee04ea7d32015-06-05 15:59:18 -0700177
178 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700179 * Optional extra for {@link #ACTION_INCOMING_CALL} containing a {@link Bundle} which contains
180 * metadata about the call. This {@link Bundle} will be returned to the
181 * {@link ConnectionService}.
Evan Charlton10197192014-07-19 15:00:29 -0700182 */
183 public static final String EXTRA_INCOMING_CALL_EXTRAS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700184 "android.telecom.extra.INCOMING_CALL_EXTRAS";
Evan Charlton10197192014-07-19 15:00:29 -0700185
186 /**
Nancy Chen10798dc2014-08-08 14:00:25 -0700187 * Optional extra for {@link android.content.Intent#ACTION_CALL} and
188 * {@link android.content.Intent#ACTION_DIAL} {@code Intent} containing a {@link Bundle}
189 * which contains metadata about the call. This {@link Bundle} will be saved into
190 * {@code Call.Details}.
Nancy Chen10798dc2014-08-08 14:00:25 -0700191 */
192 public static final String EXTRA_OUTGOING_CALL_EXTRAS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700193 "android.telecom.extra.OUTGOING_CALL_EXTRAS";
Nancy Chen10798dc2014-08-08 14:00:25 -0700194
195 /**
Yorke Leec3cf9822014-10-02 09:38:39 -0700196 * @hide
197 */
198 public static final String EXTRA_UNKNOWN_CALL_HANDLE =
199 "android.telecom.extra.UNKNOWN_CALL_HANDLE";
200
201 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700202 * Optional extra for {@link android.telephony.TelephonyManager#ACTION_PHONE_STATE_CHANGED}
203 * containing the disconnect code.
Evan Charlton10197192014-07-19 15:00:29 -0700204 */
205 public static final String EXTRA_CALL_DISCONNECT_CAUSE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700206 "android.telecom.extra.CALL_DISCONNECT_CAUSE";
Evan Charlton10197192014-07-19 15:00:29 -0700207
208 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700209 * Optional extra for {@link android.telephony.TelephonyManager#ACTION_PHONE_STATE_CHANGED}
210 * containing the disconnect message.
Evan Charlton10197192014-07-19 15:00:29 -0700211 */
212 public static final String EXTRA_CALL_DISCONNECT_MESSAGE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700213 "android.telecom.extra.CALL_DISCONNECT_MESSAGE";
Evan Charlton10197192014-07-19 15:00:29 -0700214
215 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700216 * Optional extra for {@link android.telephony.TelephonyManager#ACTION_PHONE_STATE_CHANGED}
217 * containing the component name of the associated connection service.
Evan Charlton0e094d92014-11-08 15:49:16 -0800218 * @hide
Evan Charlton10197192014-07-19 15:00:29 -0700219 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800220 @SystemApi
Evan Charlton10197192014-07-19 15:00:29 -0700221 public static final String EXTRA_CONNECTION_SERVICE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700222 "android.telecom.extra.CONNECTION_SERVICE";
Evan Charlton10197192014-07-19 15:00:29 -0700223
224 /**
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700225 * An optional {@link android.content.Intent#ACTION_CALL} intent extra denoting the
226 * package name of the app specifying an alternative gateway for the call.
227 * The value is a string.
228 *
229 * (The following comment corresponds to the all GATEWAY_* extras)
230 * An app which sends the {@link android.content.Intent#ACTION_CALL} intent can specify an
231 * alternative address to dial which is different from the one specified and displayed to
232 * the user. This alternative address is referred to as the gateway address.
233 */
234 public static final String GATEWAY_PROVIDER_PACKAGE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700235 "android.telecom.extra.GATEWAY_PROVIDER_PACKAGE";
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700236
237 /**
238 * An optional {@link android.content.Intent#ACTION_CALL} intent extra corresponding to the
239 * original address to dial for the call. This is used when an alternative gateway address is
240 * provided to recall the original address.
241 * The value is a {@link android.net.Uri}.
242 *
243 * (See {@link #GATEWAY_PROVIDER_PACKAGE} for details)
244 */
245 public static final String GATEWAY_ORIGINAL_ADDRESS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700246 "android.telecom.extra.GATEWAY_ORIGINAL_ADDRESS";
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700247
248 /**
Evan Charlton10197192014-07-19 15:00:29 -0700249 * The number which the party on the other side of the line will see (and use to return the
250 * call).
251 * <p>
Santos Cordon96efb482014-07-19 14:57:05 -0700252 * {@link ConnectionService}s which interact with {@link RemoteConnection}s should only populate
253 * this if the {@link android.telephony.TelephonyManager#getLine1Number()} value, as that is the
254 * user's expected caller ID.
Evan Charlton10197192014-07-19 15:00:29 -0700255 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700256 public static final String EXTRA_CALL_BACK_NUMBER = "android.telecom.extra.CALL_BACK_NUMBER";
Evan Charlton10197192014-07-19 15:00:29 -0700257
258 /**
259 * The dual tone multi-frequency signaling character sent to indicate the dialing system should
260 * pause for a predefined period.
261 */
262 public static final char DTMF_CHARACTER_PAUSE = ',';
263
264 /**
265 * The dual-tone multi-frequency signaling character sent to indicate the dialing system should
266 * wait for user confirmation before proceeding.
267 */
268 public static final char DTMF_CHARACTER_WAIT = ';';
269
270 /**
271 * TTY (teletypewriter) mode is off.
272 *
273 * @hide
274 */
275 public static final int TTY_MODE_OFF = 0;
276
277 /**
278 * TTY (teletypewriter) mode is on. The speaker is off and the microphone is muted. The user
279 * will communicate with the remote party by sending and receiving text messages.
280 *
281 * @hide
282 */
283 public static final int TTY_MODE_FULL = 1;
284
285 /**
286 * TTY (teletypewriter) mode is in hearing carryover mode (HCO). The microphone is muted but the
287 * speaker is on. The user will communicate with the remote party by sending text messages and
288 * hearing an audible reply.
289 *
290 * @hide
291 */
292 public static final int TTY_MODE_HCO = 2;
293
294 /**
295 * TTY (teletypewriter) mode is in voice carryover mode (VCO). The speaker is off but the
296 * microphone is still on. User will communicate with the remote party by speaking and receiving
297 * text message replies.
298 *
299 * @hide
300 */
301 public static final int TTY_MODE_VCO = 3;
302
303 /**
304 * Broadcast intent action indicating that the current TTY mode has changed. An intent extra
305 * provides this state as an int.
Evan Charlton10197192014-07-19 15:00:29 -0700306 *
Santos Cordon96efb482014-07-19 14:57:05 -0700307 * @see #EXTRA_CURRENT_TTY_MODE
Evan Charlton10197192014-07-19 15:00:29 -0700308 * @hide
309 */
310 public static final String ACTION_CURRENT_TTY_MODE_CHANGED =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700311 "android.telecom.action.CURRENT_TTY_MODE_CHANGED";
Evan Charlton10197192014-07-19 15:00:29 -0700312
313 /**
314 * The lookup key for an int that indicates the current TTY mode.
315 * Valid modes are:
316 * - {@link #TTY_MODE_OFF}
317 * - {@link #TTY_MODE_FULL}
318 * - {@link #TTY_MODE_HCO}
319 * - {@link #TTY_MODE_VCO}
320 *
321 * @hide
322 */
323 public static final String EXTRA_CURRENT_TTY_MODE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700324 "android.telecom.intent.extra.CURRENT_TTY_MODE";
Evan Charlton10197192014-07-19 15:00:29 -0700325
326 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700327 * Broadcast intent action indicating that the TTY preferred operating mode has changed. An
328 * intent extra provides the new mode as an int.
Evan Charlton10197192014-07-19 15:00:29 -0700329 *
Santos Cordon96efb482014-07-19 14:57:05 -0700330 * @see #EXTRA_TTY_PREFERRED_MODE
Evan Charlton10197192014-07-19 15:00:29 -0700331 * @hide
332 */
333 public static final String ACTION_TTY_PREFERRED_MODE_CHANGED =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700334 "android.telecom.action.TTY_PREFERRED_MODE_CHANGED";
Evan Charlton10197192014-07-19 15:00:29 -0700335
336 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700337 * The lookup key for an int that indicates preferred TTY mode. Valid modes are: -
338 * {@link #TTY_MODE_OFF} - {@link #TTY_MODE_FULL} - {@link #TTY_MODE_HCO} -
339 * {@link #TTY_MODE_VCO}
Evan Charlton10197192014-07-19 15:00:29 -0700340 *
341 * @hide
342 */
343 public static final String EXTRA_TTY_PREFERRED_MODE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700344 "android.telecom.intent.extra.TTY_PREFERRED";
Evan Charlton10197192014-07-19 15:00:29 -0700345
Nancy Chen9d568c02014-09-08 14:17:59 -0700346 /**
347 * The following 4 constants define how properties such as phone numbers and names are
348 * displayed to the user.
349 */
350
Santos Cordoned769ae2015-05-13 18:47:38 -0700351 /**
352 * Indicates that the address or number of a call is allowed to be displayed for caller ID.
353 */
Nancy Chen9d568c02014-09-08 14:17:59 -0700354 public static final int PRESENTATION_ALLOWED = 1;
355
Santos Cordoned769ae2015-05-13 18:47:38 -0700356 /**
357 * Indicates that the address or number of a call is blocked by the other party.
358 */
Nancy Chen9d568c02014-09-08 14:17:59 -0700359 public static final int PRESENTATION_RESTRICTED = 2;
360
Santos Cordoned769ae2015-05-13 18:47:38 -0700361 /**
362 * Indicates that the address or number of a call is not specified or known by the carrier.
363 */
Nancy Chen9d568c02014-09-08 14:17:59 -0700364 public static final int PRESENTATION_UNKNOWN = 3;
365
Santos Cordoned769ae2015-05-13 18:47:38 -0700366 /**
367 * Indicates that the address or number of a call belongs to a pay phone.
368 */
Nancy Chen9d568c02014-09-08 14:17:59 -0700369 public static final int PRESENTATION_PAYPHONE = 4;
370
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700371 private static final String TAG = "TelecomManager";
Yorke Leeb4ce1432014-06-09 13:53:23 -0700372
373 private final Context mContext;
Yorke Leeb4ce1432014-06-09 13:53:23 -0700374
Santos Cordon6c7a3882014-06-25 15:30:08 -0700375 /**
376 * @hide
377 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700378 public static TelecomManager from(Context context) {
379 return (TelecomManager) context.getSystemService(Context.TELECOM_SERVICE);
Yorke Leeb4ce1432014-06-09 13:53:23 -0700380 }
Santos Cordon6c7a3882014-06-25 15:30:08 -0700381
382 /**
383 * @hide
384 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700385 public TelecomManager(Context context) {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700386 Context appContext = context.getApplicationContext();
387 if (appContext != null) {
388 mContext = appContext;
389 } else {
390 mContext = context;
391 }
392 }
393
394 /**
Santos Cordon91371dc2015-05-08 13:52:09 -0700395 * Return the {@link PhoneAccount} which will be used to place outgoing calls to addresses with
396 * the specified {@code uriScheme}. This {@link PhoneAccount} will always be a member of the
397 * list which is returned from invoking {@link #getCallCapablePhoneAccounts()}. The specific
398 * account returned depends on the following priorities:
399 * <ul>
400 * <li> If the user-selected default {@link PhoneAccount} supports the specified scheme, it will
401 * be returned.
402 * </li>
403 * <li> If there exists only one {@link PhoneAccount} that supports the specified scheme, it
404 * will be returned.
405 * </li>
406 * </ul>
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700407 * <p>
Santos Cordon91371dc2015-05-08 13:52:09 -0700408 * If no {@link PhoneAccount} fits the criteria above, this method will return {@code null}.
409 *
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700410 * @param uriScheme The URI scheme.
Santos Cordon91371dc2015-05-08 13:52:09 -0700411 * @return The {@link PhoneAccountHandle} corresponding to the account to be used.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700412 */
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700413 public PhoneAccountHandle getDefaultOutgoingPhoneAccount(String uriScheme) {
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700414 try {
415 if (isServiceConnected()) {
Svet Ganov16a16892015-04-16 10:32:04 -0700416 return getTelecomService().getDefaultOutgoingPhoneAccount(uriScheme,
417 mContext.getOpPackageName());
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700418 }
419 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700420 Log.e(TAG, "Error calling ITelecomService#getDefaultOutgoingPhoneAccount", e);
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700421 }
422 return null;
423 }
424
425 /**
Andrew Leed4abbfb2014-09-03 14:58:27 -0700426 * Return the {@link PhoneAccount} which is the user-chosen default for making outgoing phone
427 * calls. This {@code PhoneAccount} will always be a member of the list which is returned from
Nancy Chen210ef032014-09-15 17:58:42 -0700428 * calling {@link #getCallCapablePhoneAccounts()}
Santos Cordon91371dc2015-05-08 13:52:09 -0700429 * <p>
Andrew Leed4abbfb2014-09-03 14:58:27 -0700430 * Apps must be prepared for this method to return {@code null}, indicating that there currently
431 * exists no user-chosen default {@code PhoneAccount}.
432 *
433 * @return The user outgoing phone account selected by the user.
Jay Shrauner225ccad2015-04-15 15:51:15 -0700434 * @hide
Andrew Leed4abbfb2014-09-03 14:58:27 -0700435 */
436 public PhoneAccountHandle getUserSelectedOutgoingPhoneAccount() {
437 try {
438 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700439 return getTelecomService().getUserSelectedOutgoingPhoneAccount();
Andrew Leed4abbfb2014-09-03 14:58:27 -0700440 }
441 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700442 Log.e(TAG, "Error calling ITelecomService#getUserSelectedOutgoingPhoneAccount", e);
Andrew Leed4abbfb2014-09-03 14:58:27 -0700443 }
444 return null;
445 }
446
447 /**
Santos Cordon91371dc2015-05-08 13:52:09 -0700448 * Sets the user-chosen default for making outgoing phone calls.
Andrew Lee59cac3a2014-08-28 16:50:10 -0700449 * @hide
450 */
Andrew Leed4abbfb2014-09-03 14:58:27 -0700451 public void setUserSelectedOutgoingPhoneAccount(PhoneAccountHandle accountHandle) {
Andrew Lee59cac3a2014-08-28 16:50:10 -0700452 try {
453 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700454 getTelecomService().setUserSelectedOutgoingPhoneAccount(accountHandle);
Andrew Lee59cac3a2014-08-28 16:50:10 -0700455 }
456 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700457 Log.e(TAG, "Error calling ITelecomService#setUserSelectedOutgoingPhoneAccount");
Andrew Lee59cac3a2014-08-28 16:50:10 -0700458 }
459 }
460
461 /**
Andrew Lee59cac3a2014-08-28 16:50:10 -0700462 * Returns the current SIM call manager. Apps must be prepared for this method to return
463 * {@code null}, indicating that there currently exists no user-chosen default
464 * {@code PhoneAccount}.
Santos Cordon91371dc2015-05-08 13:52:09 -0700465 *
Andrew Lee59cac3a2014-08-28 16:50:10 -0700466 * @return The phone account handle of the current sim call manager.
Andrew Lee59cac3a2014-08-28 16:50:10 -0700467 */
468 public PhoneAccountHandle getSimCallManager() {
469 try {
470 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700471 return getTelecomService().getSimCallManager();
Andrew Lee59cac3a2014-08-28 16:50:10 -0700472 }
473 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700474 Log.e(TAG, "Error calling ITelecomService#getSimCallManager");
Andrew Lee59cac3a2014-08-28 16:50:10 -0700475 }
476 return null;
477 }
478
479 /**
480 * Sets the SIM call manager to the specified phone account.
Santos Cordon91371dc2015-05-08 13:52:09 -0700481 *
Andrew Lee59cac3a2014-08-28 16:50:10 -0700482 * @param accountHandle The phone account handle of the account to set as the sim call manager.
483 * @hide
484 */
485 public void setSimCallManager(PhoneAccountHandle accountHandle) {
486 try {
487 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700488 getTelecomService().setSimCallManager(accountHandle);
Andrew Lee59cac3a2014-08-28 16:50:10 -0700489 }
490 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700491 Log.e(TAG, "Error calling ITelecomService#setSimCallManager");
Andrew Lee59cac3a2014-08-28 16:50:10 -0700492 }
493 }
494
495 /**
496 * Returns the list of registered SIM call managers.
Santos Cordon91371dc2015-05-08 13:52:09 -0700497 *
Andrew Lee59cac3a2014-08-28 16:50:10 -0700498 * @return List of registered SIM call managers.
499 * @hide
500 */
501 public List<PhoneAccountHandle> getSimCallManagers() {
502 try {
503 if (isServiceConnected()) {
Svet Ganov16a16892015-04-16 10:32:04 -0700504 return getTelecomService().getSimCallManagers(mContext.getOpPackageName());
Andrew Lee59cac3a2014-08-28 16:50:10 -0700505 }
506 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700507 Log.e(TAG, "Error calling ITelecomService#getSimCallManagers");
Andrew Lee59cac3a2014-08-28 16:50:10 -0700508 }
509 return new ArrayList<>();
510 }
511
512 /**
Evan Charltoneb0a8d52014-09-04 12:03:34 -0700513 * Returns the current connection manager. Apps must be prepared for this method to return
514 * {@code null}, indicating that there currently exists no user-chosen default
515 * {@code PhoneAccount}.
516 *
517 * @return The phone account handle of the current connection manager.
Evan Charlton0e094d92014-11-08 15:49:16 -0800518 * @hide
Evan Charltoneb0a8d52014-09-04 12:03:34 -0700519 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800520 @SystemApi
Evan Charltoneb0a8d52014-09-04 12:03:34 -0700521 public PhoneAccountHandle getConnectionManager() {
522 return getSimCallManager();
523 }
524
525 /**
Nancy Chen210ef032014-09-15 17:58:42 -0700526 * Returns a list of the {@link PhoneAccountHandle}s which can be used to make and receive phone
527 * calls which support the specified URI scheme.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700528 * <P>
529 * For example, invoking with {@code "tel"} will find all {@link PhoneAccountHandle}s which
530 * support telephone calls (e.g. URIs such as {@code tel:555-555-1212}). Invoking with
531 * {@code "sip"} will find all {@link PhoneAccountHandle}s which support SIP calls (e.g. URIs
532 * such as {@code sip:example@sipexample.com}).
533 *
534 * @param uriScheme The URI scheme.
535 * @return A list of {@code PhoneAccountHandle} objects supporting the URI scheme.
Evan Charlton0e094d92014-11-08 15:49:16 -0800536 * @hide
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700537 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800538 @SystemApi
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700539 public List<PhoneAccountHandle> getPhoneAccountsSupportingScheme(String uriScheme) {
540 try {
541 if (isServiceConnected()) {
Svet Ganov16a16892015-04-16 10:32:04 -0700542 return getTelecomService().getPhoneAccountsSupportingScheme(uriScheme,
543 mContext.getOpPackageName());
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700544 }
545 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700546 Log.e(TAG, "Error calling ITelecomService#getPhoneAccountsSupportingScheme", e);
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700547 }
548 return new ArrayList<>();
549 }
550
Nancy Chen513c8922014-09-17 14:47:20 -0700551
552 /**
Santos Cordon91371dc2015-05-08 13:52:09 -0700553 * Returns a list of {@link PhoneAccountHandle}s which can be used to make and receive phone
554 * calls. The returned list includes only those accounts which have been explicitly enabled
555 * by the user.
Nancy Chen513c8922014-09-17 14:47:20 -0700556 *
557 * @see #EXTRA_PHONE_ACCOUNT_HANDLE
558 * @return A list of {@code PhoneAccountHandle} objects.
Nancy Chen513c8922014-09-17 14:47:20 -0700559 */
560 public List<PhoneAccountHandle> getCallCapablePhoneAccounts() {
Santos Cordon91371dc2015-05-08 13:52:09 -0700561 return getCallCapablePhoneAccounts(false);
562 }
563
564 /**
565 * Returns a list of {@link PhoneAccountHandle}s including those which have not been enabled
566 * by the user.
567 *
568 * @return A list of {@code PhoneAccountHandle} objects.
569 * @hide
570 */
571 public List<PhoneAccountHandle> getCallCapablePhoneAccounts(boolean includeDisabledAccounts) {
Nancy Chen513c8922014-09-17 14:47:20 -0700572 try {
573 if (isServiceConnected()) {
Santos Cordon91371dc2015-05-08 13:52:09 -0700574 return getTelecomService().getCallCapablePhoneAccounts(
575 includeDisabledAccounts, mContext.getOpPackageName());
Nancy Chen513c8922014-09-17 14:47:20 -0700576 }
577 } catch (RemoteException e) {
Santos Cordon91371dc2015-05-08 13:52:09 -0700578 Log.e(TAG, "Error calling ITelecomService#getCallCapablePhoneAccounts(" +
579 includeDisabledAccounts + ")", e);
Nancy Chen513c8922014-09-17 14:47:20 -0700580 }
581 return new ArrayList<>();
582 }
583
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700584 /**
Nancy Chen513c8922014-09-17 14:47:20 -0700585 * Returns a list of all {@link PhoneAccount}s registered for the calling package.
586 *
587 * @return A list of {@code PhoneAccountHandle} objects.
Evan Charlton0e094d92014-11-08 15:49:16 -0800588 * @hide
Nancy Chen513c8922014-09-17 14:47:20 -0700589 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800590 @SystemApi
Nancy Chen513c8922014-09-17 14:47:20 -0700591 public List<PhoneAccountHandle> getPhoneAccountsForPackage() {
592 try {
593 if (isServiceConnected()) {
594 return getTelecomService().getPhoneAccountsForPackage(mContext.getPackageName());
595 }
596 } catch (RemoteException e) {
597 Log.e(TAG, "Error calling ITelecomService#getPhoneAccountsForPackage", e);
598 }
599 return null;
600 }
601
602 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700603 * Return the {@link PhoneAccount} for a specified {@link PhoneAccountHandle}. Object includes
604 * resources which can be used in a user interface.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700605 *
Evan Charlton6eb262c2014-07-19 18:18:19 -0700606 * @param account The {@link PhoneAccountHandle}.
Evan Charlton8c8a0622014-07-20 12:31:00 -0700607 * @return The {@link PhoneAccount} object.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700608 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700609 public PhoneAccount getPhoneAccount(PhoneAccountHandle account) {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700610 try {
611 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700612 return getTelecomService().getPhoneAccount(account);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700613 }
614 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700615 Log.e(TAG, "Error calling ITelecomService#getPhoneAccount", e);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700616 }
617 return null;
618 }
619
620 /**
Nancy Chen210ef032014-09-15 17:58:42 -0700621 * Returns a count of all {@link PhoneAccount}s.
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700622 *
Nancy Chen210ef032014-09-15 17:58:42 -0700623 * @return The count of {@link PhoneAccount}s.
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700624 * @hide
625 */
626 @SystemApi
627 public int getAllPhoneAccountsCount() {
628 try {
629 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700630 return getTelecomService().getAllPhoneAccountsCount();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700631 }
632 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700633 Log.e(TAG, "Error calling ITelecomService#getAllPhoneAccountsCount", e);
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700634 }
635 return 0;
636 }
637
638 /**
639 * Returns a list of all {@link PhoneAccount}s.
640 *
641 * @return All {@link PhoneAccount}s.
642 * @hide
643 */
644 @SystemApi
645 public List<PhoneAccount> getAllPhoneAccounts() {
646 try {
647 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700648 return getTelecomService().getAllPhoneAccounts();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700649 }
650 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700651 Log.e(TAG, "Error calling ITelecomService#getAllPhoneAccounts", e);
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700652 }
653 return Collections.EMPTY_LIST;
654 }
655
656 /**
657 * Returns a list of all {@link PhoneAccountHandle}s.
658 *
659 * @return All {@link PhoneAccountHandle}s.
660 * @hide
661 */
662 @SystemApi
663 public List<PhoneAccountHandle> getAllPhoneAccountHandles() {
664 try {
665 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700666 return getTelecomService().getAllPhoneAccountHandles();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700667 }
668 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700669 Log.e(TAG, "Error calling ITelecomService#getAllPhoneAccountHandles", e);
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700670 }
671 return Collections.EMPTY_LIST;
672 }
673
674 /**
Santos Cordond9e614f2014-10-28 13:10:36 -0700675 * Register a {@link PhoneAccount} for use by the system. When registering
676 * {@link PhoneAccount}s, existing registrations will be overwritten if the
677 * {@link PhoneAccountHandle} matches that of a {@link PhoneAccount} which is already
678 * registered. Once registered, the {@link PhoneAccount} is listed to the user as an option
679 * when placing calls. The user may still need to enable the {@link PhoneAccount} within
680 * the phone app settings before the account is usable.
681 * <p>
682 * A {@link SecurityException} will be thrown if an app tries to register a
683 * {@link PhoneAccountHandle} where the package name specified within
684 * {@link PhoneAccountHandle#getComponentName()} does not match the package name of the app.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700685 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700686 * @param account The complete {@link PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700687 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700688 public void registerPhoneAccount(PhoneAccount account) {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700689 try {
690 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700691 getTelecomService().registerPhoneAccount(account);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700692 }
693 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700694 Log.e(TAG, "Error calling ITelecomService#registerPhoneAccount", e);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700695 }
696 }
697
698 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700699 * Remove a {@link PhoneAccount} registration from the system.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700700 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700701 * @param accountHandle A {@link PhoneAccountHandle} for the {@link PhoneAccount} to unregister.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700702 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700703 public void unregisterPhoneAccount(PhoneAccountHandle accountHandle) {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700704 try {
705 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700706 getTelecomService().unregisterPhoneAccount(accountHandle);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700707 }
708 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700709 Log.e(TAG, "Error calling ITelecomService#unregisterPhoneAccount", e);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700710 }
711 }
712
713 /**
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700714 * Remove all Accounts that belong to the calling package from the system.
Evan Charlton0e094d92014-11-08 15:49:16 -0800715 * @hide
Ihab Awad807fe0a2014-07-09 12:30:52 -0700716 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800717 @SystemApi
Yorke Lee06044272015-04-14 15:16:59 -0700718 public void clearPhoneAccounts() {
719 clearAccounts();
720 }
721 /**
722 * Remove all Accounts that belong to the calling package from the system.
723 * @deprecated Use {@link #clearPhoneAccounts()} instead.
724 * @hide
725 */
726 @SystemApi
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700727 public void clearAccounts() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700728 try {
729 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700730 getTelecomService().clearAccounts(mContext.getPackageName());
Ihab Awad807fe0a2014-07-09 12:30:52 -0700731 }
732 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700733 Log.e(TAG, "Error calling ITelecomService#clearAccounts", e);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700734 }
735 }
736
737 /**
Anthony Lee67279262014-10-27 11:28:40 -0700738 * Remove all Accounts that belong to the specified package from the system.
739 * @hide
740 */
741 public void clearAccountsForPackage(String packageName) {
742 try {
743 if (isServiceConnected() && !TextUtils.isEmpty(packageName)) {
744 getTelecomService().clearAccounts(packageName);
745 }
746 } catch (RemoteException e) {
Nancy Chen5cf27842015-01-24 23:30:27 -0800747 Log.e(TAG, "Error calling ITelecomService#clearAccountsForPackage", e);
Anthony Lee67279262014-10-27 11:28:40 -0700748 }
749 }
750
Yorke Lee1011f482015-04-23 15:58:27 -0700751
Anthony Lee67279262014-10-27 11:28:40 -0700752 /**
Yorke Lee1011f482015-04-23 15:58:27 -0700753 * @deprecated - Use {@link TelecomManager#getDefaultDialerPackage} to directly access
754 * the default dialer's package name instead.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700755 * @hide
756 */
Santos Cordon6c7a3882014-06-25 15:30:08 -0700757 @SystemApi
758 public ComponentName getDefaultPhoneApp() {
759 try {
Santos Cordon9eb45932014-06-27 12:28:43 -0700760 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700761 return getTelecomService().getDefaultPhoneApp();
Santos Cordon9eb45932014-06-27 12:28:43 -0700762 }
Santos Cordon6c7a3882014-06-25 15:30:08 -0700763 } catch (RemoteException e) {
764 Log.e(TAG, "RemoteException attempting to get the default phone app.", e);
765 }
766 return null;
767 }
768
Santos Cordon9eb45932014-06-27 12:28:43 -0700769 /**
Yorke Lee1011f482015-04-23 15:58:27 -0700770 * Used to determine the currently selected default dialer package.
771 *
772 * @return package name for the default dialer package or null if no package has been
773 * selected as the default dialer.
774 */
775 public String getDefaultDialerPackage() {
776 try {
777 if (isServiceConnected()) {
778 return getTelecomService().getDefaultDialerPackage();
779 }
780 } catch (RemoteException e) {
781 Log.e(TAG, "RemoteException attempting to get the default dialer package name.", e);
782 }
783 return null;
784 }
785
786 /**
Yorke Lee107c4ce2015-06-15 12:08:24 -0700787 * Used to set the default dialer package.
788 *
789 * @param packageName to set the default dialer to..
790 *
791 * @result {@code true} if the default dialer was successfully changed, {@code false} if
792 * the specified package does not correspond to an installed dialer, or is already
793 * the default dialer.
794 *
795 * Requires permission: {@link android.Manifest.permission#MODIFY_PHONE_STATE}
796 * Requires permission: {@link android.Manifest.permission#WRITE_SECURE_SETTINGS}
797 *
798 * @hide
799 */
800 public boolean setDefaultDialer(String packageName) {
801 try {
802 if (isServiceConnected()) {
803 return getTelecomService().setDefaultDialer(packageName);
804 }
805 } catch (RemoteException e) {
806 Log.e(TAG, "RemoteException attempting to set the default dialer.", e);
807 }
808 return false;
809 }
810
811 /**
Yorke Lee1011f482015-04-23 15:58:27 -0700812 * Used to determine the dialer package that is preloaded on the system partition.
813 *
814 * @return package name for the system dialer package or null if no system dialer is preloaded.
815 * @hide
816 */
817 public String getSystemDialerPackage() {
818 try {
819 if (isServiceConnected()) {
820 return getTelecomService().getSystemDialerPackage();
821 }
822 } catch (RemoteException e) {
823 Log.e(TAG, "RemoteException attempting to get the system dialer package name.", e);
824 }
825 return null;
826 }
827
828 /**
Nancy Chen443e5012014-10-15 15:48:21 -0700829 * Return whether a given phone number is the configured voicemail number for a
830 * particular phone account.
831 *
832 * @param accountHandle The handle for the account to check the voicemail number against
833 * @param number The number to look up.
Nancy Chen443e5012014-10-15 15:48:21 -0700834 */
Nancy Chen443e5012014-10-15 15:48:21 -0700835 public boolean isVoiceMailNumber(PhoneAccountHandle accountHandle, String number) {
836 try {
837 if (isServiceConnected()) {
Svet Ganov16a16892015-04-16 10:32:04 -0700838 return getTelecomService().isVoiceMailNumber(accountHandle, number,
839 mContext.getOpPackageName());
Nancy Chen443e5012014-10-15 15:48:21 -0700840 }
841 } catch (RemoteException e) {
Nancy Chen5cf27842015-01-24 23:30:27 -0800842 Log.e(TAG, "RemoteException calling ITelecomService#isVoiceMailNumber.", e);
Nancy Chen443e5012014-10-15 15:48:21 -0700843 }
844 return false;
845 }
846
847 /**
Yorke Lee49e2d462015-04-15 16:14:22 -0700848 * Return the voicemail number for a given phone account.
Nancy Chen8c066f72014-12-03 15:18:08 -0800849 *
Yorke Lee49e2d462015-04-15 16:14:22 -0700850 * @param accountHandle The handle for the phone account.
851 * @return The voicemail number for the phone account, and {@code null} if one has not been
852 * configured.
Nancy Chen8c066f72014-12-03 15:18:08 -0800853 */
Yorke Lee49e2d462015-04-15 16:14:22 -0700854 public String getVoiceMailNumber(PhoneAccountHandle accountHandle) {
Nancy Chen8c066f72014-12-03 15:18:08 -0800855 try {
856 if (isServiceConnected()) {
Svet Ganov16a16892015-04-16 10:32:04 -0700857 return getTelecomService().getVoiceMailNumber(accountHandle,
858 mContext.getOpPackageName());
Nancy Chen8c066f72014-12-03 15:18:08 -0800859 }
860 } catch (RemoteException e) {
Nancy Chen5cf27842015-01-24 23:30:27 -0800861 Log.e(TAG, "RemoteException calling ITelecomService#hasVoiceMailNumber.", e);
Nancy Chen8c066f72014-12-03 15:18:08 -0800862 }
Yorke Lee49e2d462015-04-15 16:14:22 -0700863 return null;
Nancy Chen8c066f72014-12-03 15:18:08 -0800864 }
865
866 /**
Nancy Chen5cf27842015-01-24 23:30:27 -0800867 * Return the line 1 phone number for given phone account.
868 *
869 * @param accountHandle The handle for the account retrieve a number for.
870 * @return A string representation of the line 1 phone number.
Nancy Chen5cf27842015-01-24 23:30:27 -0800871 */
Nancy Chen5cf27842015-01-24 23:30:27 -0800872 public String getLine1Number(PhoneAccountHandle accountHandle) {
873 try {
874 if (isServiceConnected()) {
Svet Ganov16a16892015-04-16 10:32:04 -0700875 return getTelecomService().getLine1Number(accountHandle,
876 mContext.getOpPackageName());
Nancy Chen5cf27842015-01-24 23:30:27 -0800877 }
878 } catch (RemoteException e) {
879 Log.e(TAG, "RemoteException calling ITelecomService#getLine1Number.", e);
880 }
881 return null;
882 }
883
884 /**
Santos Cordon9eb45932014-06-27 12:28:43 -0700885 * Returns whether there is an ongoing phone call (can be in dialing, ringing, active or holding
886 * states).
Nancy Chen0eb1e402014-08-21 22:52:29 -0700887 * <p>
888 * Requires permission: {@link android.Manifest.permission#READ_PHONE_STATE}
889 * </p>
Santos Cordon9eb45932014-06-27 12:28:43 -0700890 */
Nancy Chen0eb1e402014-08-21 22:52:29 -0700891 public boolean isInCall() {
Santos Cordon9eb45932014-06-27 12:28:43 -0700892 try {
893 if (isServiceConnected()) {
Svet Ganov16a16892015-04-16 10:32:04 -0700894 return getTelecomService().isInCall(mContext.getOpPackageName());
Santos Cordon9eb45932014-06-27 12:28:43 -0700895 }
896 } catch (RemoteException e) {
Yorke Lee2ae312e2014-09-12 17:58:48 -0700897 Log.e(TAG, "RemoteException calling isInCall().", e);
Santos Cordon9eb45932014-06-27 12:28:43 -0700898 }
899 return false;
900 }
901
902 /**
Yorke Lee2ae312e2014-09-12 17:58:48 -0700903 * Returns one of the following constants that represents the current state of Telecom:
904 *
905 * {@link TelephonyManager#CALL_STATE_RINGING}
906 * {@link TelephonyManager#CALL_STATE_OFFHOOK}
907 * {@link TelephonyManager#CALL_STATE_IDLE}
Yorke Lee7c72c2d2014-10-28 14:12:02 -0700908 *
909 * Note that this API does not require the
910 * {@link android.Manifest.permission#READ_PHONE_STATE} permission. This is intentional, to
911 * preserve the behavior of {@link TelephonyManager#getCallState()}, which also did not require
912 * the permission.
Yorke Lee2ae312e2014-09-12 17:58:48 -0700913 * @hide
914 */
915 @SystemApi
916 public int getCallState() {
917 try {
918 if (isServiceConnected()) {
919 return getTelecomService().getCallState();
920 }
921 } catch (RemoteException e) {
922 Log.d(TAG, "RemoteException calling getCallState().", e);
923 }
924 return TelephonyManager.CALL_STATE_IDLE;
925 }
926
927 /**
Santos Cordon9eb45932014-06-27 12:28:43 -0700928 * Returns whether there currently exists is a ringing incoming-call.
929 *
930 * @hide
931 */
932 @SystemApi
933 public boolean isRinging() {
934 try {
935 if (isServiceConnected()) {
Svet Ganov16a16892015-04-16 10:32:04 -0700936 return getTelecomService().isRinging(mContext.getOpPackageName());
Santos Cordon9eb45932014-06-27 12:28:43 -0700937 }
938 } catch (RemoteException e) {
939 Log.e(TAG, "RemoteException attempting to get ringing state of phone app.", e);
940 }
941 return false;
942 }
943
944 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700945 * Ends an ongoing call.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700946 * TODO: L-release - need to convert all invocations of ITelecomService#endCall to use this
Santos Cordon96efb482014-07-19 14:57:05 -0700947 * method (clockwork & gearhead).
Santos Cordon9eb45932014-06-27 12:28:43 -0700948 * @hide
949 */
950 @SystemApi
951 public boolean endCall() {
952 try {
953 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700954 return getTelecomService().endCall();
Santos Cordon9eb45932014-06-27 12:28:43 -0700955 }
956 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700957 Log.e(TAG, "Error calling ITelecomService#endCall", e);
Santos Cordon9eb45932014-06-27 12:28:43 -0700958 }
959 return false;
960 }
961
962 /**
963 * If there is a ringing incoming call, this method accepts the call on behalf of the user.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700964 * TODO: L-release - need to convert all invocation of ITelecmmService#answerRingingCall to use
Santos Cordon96efb482014-07-19 14:57:05 -0700965 * this method (clockwork & gearhead).
Santos Cordon9eb45932014-06-27 12:28:43 -0700966 *
967 * @hide
968 */
969 @SystemApi
970 public void acceptRingingCall() {
971 try {
972 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700973 getTelecomService().acceptRingingCall();
Santos Cordon9eb45932014-06-27 12:28:43 -0700974 }
975 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700976 Log.e(TAG, "Error calling ITelecomService#acceptRingingCall", e);
Santos Cordon9eb45932014-06-27 12:28:43 -0700977 }
978 }
979
980 /**
981 * Silences the ringer if a ringing call exists.
Santos Cordon9eb45932014-06-27 12:28:43 -0700982 */
Santos Cordon9eb45932014-06-27 12:28:43 -0700983 public void silenceRinger() {
984 try {
985 if (isServiceConnected()) {
Yorke Leef1a349b2015-04-29 16:16:50 -0700986 getTelecomService().silenceRinger(mContext.getOpPackageName());
Santos Cordon9eb45932014-06-27 12:28:43 -0700987 }
988 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700989 Log.e(TAG, "Error calling ITelecomService#silenceRinger", e);
Santos Cordon9eb45932014-06-27 12:28:43 -0700990 }
991 }
992
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700993 /**
994 * Returns whether TTY is supported on this device.
995 *
996 * @hide
997 */
998 @SystemApi
999 public boolean isTtySupported() {
1000 try {
1001 if (isServiceConnected()) {
Svet Ganov16a16892015-04-16 10:32:04 -07001002 return getTelecomService().isTtySupported(mContext.getOpPackageName());
Sailesh Nepal001bbbb2014-07-15 14:40:39 -07001003 }
1004 } catch (RemoteException e) {
1005 Log.e(TAG, "RemoteException attempting to get TTY supported state.", e);
1006 }
1007 return false;
1008 }
1009
1010 /**
1011 * 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 -07001012 * settings and have a wired headset plugged in.
1013 * Valid modes are:
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001014 * - {@link TelecomManager#TTY_MODE_OFF}
1015 * - {@link TelecomManager#TTY_MODE_FULL}
1016 * - {@link TelecomManager#TTY_MODE_HCO}
1017 * - {@link TelecomManager#TTY_MODE_VCO}
Sailesh Nepal001bbbb2014-07-15 14:40:39 -07001018 * @hide
1019 */
1020 public int getCurrentTtyMode() {
1021 try {
1022 if (isServiceConnected()) {
Svet Ganov16a16892015-04-16 10:32:04 -07001023 return getTelecomService().getCurrentTtyMode(mContext.getOpPackageName());
Sailesh Nepal001bbbb2014-07-15 14:40:39 -07001024 }
1025 } catch (RemoteException e) {
1026 Log.e(TAG, "RemoteException attempting to get the current TTY mode.", e);
1027 }
Evan Charlton10197192014-07-19 15:00:29 -07001028 return TTY_MODE_OFF;
Sailesh Nepal001bbbb2014-07-15 14:40:39 -07001029 }
1030
Santos Cordon96efb482014-07-19 14:57:05 -07001031 /**
1032 * Registers a new incoming call. A {@link ConnectionService} should invoke this method when it
1033 * has an incoming call. The specified {@link PhoneAccountHandle} must have been registered
Nancy Chen210ef032014-09-15 17:58:42 -07001034 * with {@link #registerPhoneAccount}. Once invoked, this method will cause the system to bind
1035 * to the {@link ConnectionService} associated with the {@link PhoneAccountHandle} and request
Santos Cordon96efb482014-07-19 14:57:05 -07001036 * additional information about the call (See
1037 * {@link ConnectionService#onCreateIncomingConnection}) before starting the incoming call UI.
1038 *
1039 * @param phoneAccount A {@link PhoneAccountHandle} registered with
1040 * {@link #registerPhoneAccount}.
1041 * @param extras A bundle that will be passed through to
1042 * {@link ConnectionService#onCreateIncomingConnection}.
1043 */
1044 public void addNewIncomingCall(PhoneAccountHandle phoneAccount, Bundle extras) {
1045 try {
1046 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001047 getTelecomService().addNewIncomingCall(
Santos Cordon96efb482014-07-19 14:57:05 -07001048 phoneAccount, extras == null ? new Bundle() : extras);
1049 }
1050 } catch (RemoteException e) {
1051 Log.e(TAG, "RemoteException adding a new incoming call: " + phoneAccount, e);
1052 }
1053 }
1054
Nancy Chen0eb1e402014-08-21 22:52:29 -07001055 /**
Yorke Leec3cf9822014-10-02 09:38:39 -07001056 * Registers a new unknown call with Telecom. This can only be called by the system Telephony
1057 * service. This is invoked when Telephony detects a new unknown connection that was neither
1058 * a new incoming call, nor an user-initiated outgoing call.
1059 *
1060 * @param phoneAccount A {@link PhoneAccountHandle} registered with
1061 * {@link #registerPhoneAccount}.
1062 * @param extras A bundle that will be passed through to
1063 * {@link ConnectionService#onCreateIncomingConnection}.
1064 * @hide
1065 */
1066 @SystemApi
1067 public void addNewUnknownCall(PhoneAccountHandle phoneAccount, Bundle extras) {
1068 try {
1069 if (isServiceConnected()) {
1070 getTelecomService().addNewUnknownCall(
1071 phoneAccount, extras == null ? new Bundle() : extras);
1072 }
1073 } catch (RemoteException e) {
1074 Log.e(TAG, "RemoteException adding a new unknown call: " + phoneAccount, e);
1075 }
1076 }
1077
1078 /**
Nancy Chen0eb1e402014-08-21 22:52:29 -07001079 * Processes the specified dial string as an MMI code.
1080 * MMI codes are any sequence of characters entered into the dialpad that contain a "*" or "#".
1081 * Some of these sequences launch special behavior through handled by Telephony.
Nancy Chen95e8a672014-10-16 18:38:21 -07001082 * This method uses the default subscription.
Nancy Chen0eb1e402014-08-21 22:52:29 -07001083 * <p>
1084 * Requires that the method-caller be set as the system dialer app.
1085 * </p>
1086 *
1087 * @param dialString The digits to dial.
1088 * @return True if the digits were processed as an MMI code, false otherwise.
1089 */
1090 public boolean handleMmi(String dialString) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001091 ITelecomService service = getTelecomService();
Nancy Chen0eb1e402014-08-21 22:52:29 -07001092 if (service != null) {
1093 try {
Yorke Leef1a349b2015-04-29 16:16:50 -07001094 return service.handlePinMmi(dialString, mContext.getOpPackageName());
Nancy Chen0eb1e402014-08-21 22:52:29 -07001095 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001096 Log.e(TAG, "Error calling ITelecomService#handlePinMmi", e);
Nancy Chen0eb1e402014-08-21 22:52:29 -07001097 }
1098 }
1099 return false;
1100 }
1101
1102 /**
Nancy Chen95e8a672014-10-16 18:38:21 -07001103 * Processes the specified dial string as an MMI code.
1104 * MMI codes are any sequence of characters entered into the dialpad that contain a "*" or "#".
1105 * Some of these sequences launch special behavior through handled by Telephony.
1106 * <p>
1107 * Requires that the method-caller be set as the system dialer app.
1108 * </p>
1109 *
1110 * @param accountHandle The handle for the account the MMI code should apply to.
1111 * @param dialString The digits to dial.
1112 * @return True if the digits were processed as an MMI code, false otherwise.
Nancy Chen95e8a672014-10-16 18:38:21 -07001113 */
Yorke Lee06044272015-04-14 15:16:59 -07001114 public boolean handleMmi(String dialString, PhoneAccountHandle accountHandle) {
Nancy Chen95e8a672014-10-16 18:38:21 -07001115 ITelecomService service = getTelecomService();
1116 if (service != null) {
1117 try {
Yorke Leef1a349b2015-04-29 16:16:50 -07001118 return service.handlePinMmiForPhoneAccount(accountHandle, dialString,
1119 mContext.getOpPackageName());
Nancy Chen95e8a672014-10-16 18:38:21 -07001120 } catch (RemoteException e) {
1121 Log.e(TAG, "Error calling ITelecomService#handlePinMmi", e);
1122 }
1123 }
1124 return false;
1125 }
1126
1127 /**
Nancy Chenb2299c12014-10-29 18:22:11 -07001128 * @param accountHandle The handle for the account to derive an adn query URI for or
1129 * {@code null} to return a URI which will use the default account.
1130 * @return The URI (with the content:// scheme) specific to the specified {@link PhoneAccount}
1131 * for the the content retrieve.
1132 */
1133 public Uri getAdnUriForPhoneAccount(PhoneAccountHandle accountHandle) {
1134 ITelecomService service = getTelecomService();
1135 if (service != null && accountHandle != null) {
1136 try {
Yorke Leef1a349b2015-04-29 16:16:50 -07001137 return service.getAdnUriForPhoneAccount(accountHandle, mContext.getOpPackageName());
Nancy Chenb2299c12014-10-29 18:22:11 -07001138 } catch (RemoteException e) {
1139 Log.e(TAG, "Error calling ITelecomService#getAdnUriForPhoneAccount", e);
1140 }
1141 }
1142 return Uri.parse("content://icc/adn");
1143 }
1144
1145 /**
Nancy Chen0eb1e402014-08-21 22:52:29 -07001146 * Removes the missed-call notification if one is present.
1147 * <p>
1148 * Requires that the method-caller be set as the system dialer app.
1149 * </p>
1150 */
1151 public void cancelMissedCallsNotification() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001152 ITelecomService service = getTelecomService();
Nancy Chen0eb1e402014-08-21 22:52:29 -07001153 if (service != null) {
1154 try {
Yorke Leef1a349b2015-04-29 16:16:50 -07001155 service.cancelMissedCallsNotification(mContext.getOpPackageName());
Nancy Chen0eb1e402014-08-21 22:52:29 -07001156 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001157 Log.e(TAG, "Error calling ITelecomService#cancelMissedCallsNotification", e);
Nancy Chen0eb1e402014-08-21 22:52:29 -07001158 }
1159 }
1160 }
1161
1162 /**
1163 * Brings the in-call screen to the foreground if there is an ongoing call. If there is
1164 * currently no ongoing call, then this method does nothing.
1165 * <p>
1166 * Requires that the method-caller be set as the system dialer app or have the
1167 * {@link android.Manifest.permission#READ_PHONE_STATE} permission.
1168 * </p>
1169 *
1170 * @param showDialpad Brings up the in-call dialpad as part of showing the in-call screen.
1171 */
1172 public void showInCallScreen(boolean showDialpad) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001173 ITelecomService service = getTelecomService();
Nancy Chen0eb1e402014-08-21 22:52:29 -07001174 if (service != null) {
1175 try {
Svet Ganov16a16892015-04-16 10:32:04 -07001176 service.showInCallScreen(showDialpad, mContext.getOpPackageName());
Nancy Chen0eb1e402014-08-21 22:52:29 -07001177 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001178 Log.e(TAG, "Error calling ITelecomService#showCallScreen", e);
Nancy Chen0eb1e402014-08-21 22:52:29 -07001179 }
1180 }
1181 }
1182
Yorke Lee3e56ba12015-04-23 12:32:36 -07001183 /**
1184 * Places a new outgoing call to the provided address using the system telecom service with
1185 * the specified extras.
1186 *
1187 * This method is equivalent to placing an outgoing call using {@link Intent#ACTION_CALL},
1188 * except that the outgoing call will always be sent via the system telecom service. If
1189 * method-caller is either the user selected default dialer app or preloaded system dialer
1190 * app, then emergency calls will also be allowed.
1191 *
1192 * Requires permission: {@link android.Manifest.permission#CALL_PHONE}
1193 *
1194 * Usage example:
1195 * <pre>
1196 * Uri uri = Uri.fromParts("tel", "12345", null);
1197 * Bundle extras = new Bundle();
1198 * extras.putBoolean(TelecomManager.EXTRA_START_CALL_WITH_SPEAKERPHONE, true);
1199 * telecomManager.placeCall(uri, extras);
1200 * </pre>
1201 *
1202 * @param address The address to make the call to.
1203 * @param extras Bundle of extras to use with the call.
1204 */
1205 public void placeCall(Uri address, Bundle extras) {
1206 ITelecomService service = getTelecomService();
1207 if (service != null) {
Yorke Leea5d5c1d2015-05-05 16:25:55 -07001208 if (address == null) {
1209 Log.w(TAG, "Cannot place call to empty address.");
1210 }
Yorke Lee3e56ba12015-04-23 12:32:36 -07001211 try {
Yorke Leea5d5c1d2015-05-05 16:25:55 -07001212 service.placeCall(address, extras == null ? new Bundle() : extras,
1213 mContext.getOpPackageName());
Yorke Lee3e56ba12015-04-23 12:32:36 -07001214 } catch (RemoteException e) {
1215 Log.e(TAG, "Error calling ITelecomService#placeCall", e);
1216 }
1217 }
1218 }
1219
Santos Cordon91371dc2015-05-08 13:52:09 -07001220 /**
1221 * Enables and disables specified phone account.
1222 *
1223 * @param handle Handle to the phone account.
1224 * @param isEnabled Enable state of the phone account.
1225 * @hide
1226 */
1227 @SystemApi
1228 public void enablePhoneAccount(PhoneAccountHandle handle, boolean isEnabled) {
1229 ITelecomService service = getTelecomService();
1230 if (service != null) {
1231 try {
1232 service.enablePhoneAccount(handle, isEnabled);
1233 } catch (RemoteException e) {
1234 Log.e(TAG, "Error enablePhoneAbbount", e);
1235 }
1236 }
1237 }
1238
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001239 private ITelecomService getTelecomService() {
1240 return ITelecomService.Stub.asInterface(ServiceManager.getService(Context.TELECOM_SERVICE));
Santos Cordon6c7a3882014-06-25 15:30:08 -07001241 }
Santos Cordon9eb45932014-06-27 12:28:43 -07001242
1243 private boolean isServiceConnected() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001244 boolean isConnected = getTelecomService() != null;
Santos Cordon9eb45932014-06-27 12:28:43 -07001245 if (!isConnected) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001246 Log.w(TAG, "Telecom Service not found.");
Santos Cordon9eb45932014-06-27 12:28:43 -07001247 }
1248 return isConnected;
1249 }
Evan Charlton235c1592014-09-05 15:41:23 +00001250}