blob: 308c204676b4bb78673893e198570da6c79c94f0 [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 Charlton0e094d92014-11-08 15:49:16 -080072 * @hide
Evan Charlton10197192014-07-19 15:00:29 -070073 */
Evan Charlton0e094d92014-11-08 15:49:16 -080074 @SystemApi
Evan Charlton10197192014-07-19 15:00:29 -070075 public static final String ACTION_CONNECTION_SERVICE_CONFIGURE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -070076 "android.telecom.action.CONNECTION_SERVICE_CONFIGURE";
Evan Charlton10197192014-07-19 15:00:29 -070077
78 /**
Andrew Lee873cfbf2015-02-26 15:22:00 -080079 * The {@link android.content.Intent} action used to show the call accessibility settings page.
80 */
81 public static final String ACTION_SHOW_CALL_ACCESSIBILITY_SETTINGS =
82 "android.telecom.action.SHOW_CALL_ACCESSIBILITY_SETTINGS";
83
84 /**
Yorke Lee3818a892014-07-21 15:57:17 -070085 * The {@link android.content.Intent} action used to show the call settings page.
86 */
87 public static final String ACTION_SHOW_CALL_SETTINGS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -070088 "android.telecom.action.SHOW_CALL_SETTINGS";
Yorke Lee3818a892014-07-21 15:57:17 -070089
90 /**
Andrew Lee866080f2015-02-19 12:05:33 -080091 * The {@link android.content.Intent} action used to show the respond via SMS settings page.
92 */
93 public static final String ACTION_SHOW_RESPOND_VIA_SMS_SETTINGS =
94 "android.telecom.action.SHOW_RESPOND_VIA_SMS_SETTINGS";
95
96 /**
Evan Charlton6d8604f2014-09-04 12:38:17 -070097 * The {@link android.content.Intent} action used to show the settings page used to configure
98 * {@link PhoneAccount} preferences.
99 */
100 public static final String ACTION_CHANGE_PHONE_ACCOUNTS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700101 "android.telecom.action.CHANGE_PHONE_ACCOUNTS";
Evan Charlton6d8604f2014-09-04 12:38:17 -0700102
103 /**
Santos Cordonc66f3ba2015-02-27 15:22:07 -0800104 * The {@link android.content.Intent} action used indicate that a new phone account was
105 * just registered.
106 * @hide
107 */
108 @SystemApi
109 public static final String ACTION_PHONE_ACCOUNT_REGISTERED =
110 "android.telecom.action.PHONE_ACCOUNT_REGISTERED";
111
112 /**
Yorke Lee1011f482015-04-23 15:58:27 -0700113 * Activity action: Shows a dialog asking the user whether or not they want to replace the
114 * current default Dialer with the one specified in
115 * {@link #EXTRA_CHANGE_DEFAULT_DIALER_PACKAGE_NAME}.
116 *
117 * Usage example:
118 * <pre>
119 * Intent intent = new Intent(TelecomManager.ACTION_CHANGE_DEFAULT_DIALER);
120 * intent.putExtra(TelecomManager.EXTRA_CHANGE_DEFAULT_DIALER_PACKAGE_NAME,
121 * getActivity().getPackageName());
122 * startActivity(intent);
123 * </pre>
124 */
125 public static final String ACTION_CHANGE_DEFAULT_DIALER =
126 "android.telecom.action.CHANGE_DEFAULT_DIALER";
127
128 /**
129 * Extra value used to provide the package name for {@link #ACTION_CHANGE_DEFAULT_DIALER}.
130 */
131 public static final String EXTRA_CHANGE_DEFAULT_DIALER_PACKAGE_NAME =
132 "android.telecom.extra.CHANGE_DEFAULT_DIALER_PACKAGE_NAME";
133
134 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700135 * Optional extra for {@link android.content.Intent#ACTION_CALL} containing a boolean that
136 * determines whether the speakerphone should be automatically turned on for an outgoing call.
Evan Charlton10197192014-07-19 15:00:29 -0700137 */
138 public static final String EXTRA_START_CALL_WITH_SPEAKERPHONE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700139 "android.telecom.extra.START_CALL_WITH_SPEAKERPHONE";
Evan Charlton10197192014-07-19 15:00:29 -0700140
141 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700142 * Optional extra for {@link android.content.Intent#ACTION_CALL} containing an integer that
143 * determines the desired video state for an outgoing call.
Santos Cordon96efb482014-07-19 14:57:05 -0700144 * Valid options:
Yorke Lee32f24732015-05-12 16:18:03 -0700145 * {@link VideoProfile#STATE_AUDIO_ONLY},
146 * {@link VideoProfile#STATE_BIDIRECTIONAL},
147 * {@link VideoProfile#STATE_RX_ENABLED},
148 * {@link VideoProfile#STATE_TX_ENABLED}.
Evan Charlton10197192014-07-19 15:00:29 -0700149 */
150 public static final String EXTRA_START_CALL_WITH_VIDEO_STATE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700151 "android.telecom.extra.START_CALL_WITH_VIDEO_STATE";
Evan Charlton10197192014-07-19 15:00:29 -0700152
153 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700154 * The extra used with an {@link android.content.Intent#ACTION_CALL} and
155 * {@link android.content.Intent#ACTION_DIAL} {@code Intent} to specify a
156 * {@link PhoneAccountHandle} to use when making the call.
Evan Charlton10197192014-07-19 15:00:29 -0700157 * <p class="note">
Santos Cordon96efb482014-07-19 14:57:05 -0700158 * Retrieve with {@link android.content.Intent#getParcelableExtra(String)}.
Evan Charlton10197192014-07-19 15:00:29 -0700159 */
Evan Charlton6eb262c2014-07-19 18:18:19 -0700160 public static final String EXTRA_PHONE_ACCOUNT_HANDLE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700161 "android.telecom.extra.PHONE_ACCOUNT_HANDLE";
Evan Charlton10197192014-07-19 15:00:29 -0700162
163 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700164 * Optional extra for {@link #ACTION_INCOMING_CALL} containing a {@link Bundle} which contains
165 * metadata about the call. This {@link Bundle} will be returned to the
166 * {@link ConnectionService}.
Evan Charlton10197192014-07-19 15:00:29 -0700167 */
168 public static final String EXTRA_INCOMING_CALL_EXTRAS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700169 "android.telecom.extra.INCOMING_CALL_EXTRAS";
Evan Charlton10197192014-07-19 15:00:29 -0700170
171 /**
Nancy Chen10798dc2014-08-08 14:00:25 -0700172 * Optional extra for {@link android.content.Intent#ACTION_CALL} and
173 * {@link android.content.Intent#ACTION_DIAL} {@code Intent} containing a {@link Bundle}
174 * which contains metadata about the call. This {@link Bundle} will be saved into
175 * {@code Call.Details}.
Nancy Chen10798dc2014-08-08 14:00:25 -0700176 */
177 public static final String EXTRA_OUTGOING_CALL_EXTRAS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700178 "android.telecom.extra.OUTGOING_CALL_EXTRAS";
Nancy Chen10798dc2014-08-08 14:00:25 -0700179
180 /**
Yorke Leec3cf9822014-10-02 09:38:39 -0700181 * @hide
182 */
183 public static final String EXTRA_UNKNOWN_CALL_HANDLE =
184 "android.telecom.extra.UNKNOWN_CALL_HANDLE";
185
186 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700187 * Optional extra for {@link android.telephony.TelephonyManager#ACTION_PHONE_STATE_CHANGED}
188 * containing the disconnect code.
Evan Charlton10197192014-07-19 15:00:29 -0700189 */
190 public static final String EXTRA_CALL_DISCONNECT_CAUSE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700191 "android.telecom.extra.CALL_DISCONNECT_CAUSE";
Evan Charlton10197192014-07-19 15:00:29 -0700192
193 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700194 * Optional extra for {@link android.telephony.TelephonyManager#ACTION_PHONE_STATE_CHANGED}
195 * containing the disconnect message.
Evan Charlton10197192014-07-19 15:00:29 -0700196 */
197 public static final String EXTRA_CALL_DISCONNECT_MESSAGE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700198 "android.telecom.extra.CALL_DISCONNECT_MESSAGE";
Evan Charlton10197192014-07-19 15:00:29 -0700199
200 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700201 * Optional extra for {@link android.telephony.TelephonyManager#ACTION_PHONE_STATE_CHANGED}
202 * containing the component name of the associated connection service.
Evan Charlton0e094d92014-11-08 15:49:16 -0800203 * @hide
Evan Charlton10197192014-07-19 15:00:29 -0700204 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800205 @SystemApi
Evan Charlton10197192014-07-19 15:00:29 -0700206 public static final String EXTRA_CONNECTION_SERVICE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700207 "android.telecom.extra.CONNECTION_SERVICE";
Evan Charlton10197192014-07-19 15:00:29 -0700208
209 /**
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700210 * An optional {@link android.content.Intent#ACTION_CALL} intent extra denoting the
211 * package name of the app specifying an alternative gateway for the call.
212 * The value is a string.
213 *
214 * (The following comment corresponds to the all GATEWAY_* extras)
215 * An app which sends the {@link android.content.Intent#ACTION_CALL} intent can specify an
216 * alternative address to dial which is different from the one specified and displayed to
217 * the user. This alternative address is referred to as the gateway address.
218 */
219 public static final String GATEWAY_PROVIDER_PACKAGE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700220 "android.telecom.extra.GATEWAY_PROVIDER_PACKAGE";
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700221
222 /**
223 * An optional {@link android.content.Intent#ACTION_CALL} intent extra corresponding to the
224 * original address to dial for the call. This is used when an alternative gateway address is
225 * provided to recall the original address.
226 * The value is a {@link android.net.Uri}.
227 *
228 * (See {@link #GATEWAY_PROVIDER_PACKAGE} for details)
229 */
230 public static final String GATEWAY_ORIGINAL_ADDRESS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700231 "android.telecom.extra.GATEWAY_ORIGINAL_ADDRESS";
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700232
233 /**
Evan Charlton10197192014-07-19 15:00:29 -0700234 * The number which the party on the other side of the line will see (and use to return the
235 * call).
236 * <p>
Santos Cordon96efb482014-07-19 14:57:05 -0700237 * {@link ConnectionService}s which interact with {@link RemoteConnection}s should only populate
238 * this if the {@link android.telephony.TelephonyManager#getLine1Number()} value, as that is the
239 * user's expected caller ID.
Evan Charlton10197192014-07-19 15:00:29 -0700240 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700241 public static final String EXTRA_CALL_BACK_NUMBER = "android.telecom.extra.CALL_BACK_NUMBER";
Evan Charlton10197192014-07-19 15:00:29 -0700242
243 /**
244 * The dual tone multi-frequency signaling character sent to indicate the dialing system should
245 * pause for a predefined period.
246 */
247 public static final char DTMF_CHARACTER_PAUSE = ',';
248
249 /**
250 * The dual-tone multi-frequency signaling character sent to indicate the dialing system should
251 * wait for user confirmation before proceeding.
252 */
253 public static final char DTMF_CHARACTER_WAIT = ';';
254
255 /**
256 * TTY (teletypewriter) mode is off.
257 *
258 * @hide
259 */
260 public static final int TTY_MODE_OFF = 0;
261
262 /**
263 * TTY (teletypewriter) mode is on. The speaker is off and the microphone is muted. The user
264 * will communicate with the remote party by sending and receiving text messages.
265 *
266 * @hide
267 */
268 public static final int TTY_MODE_FULL = 1;
269
270 /**
271 * TTY (teletypewriter) mode is in hearing carryover mode (HCO). The microphone is muted but the
272 * speaker is on. The user will communicate with the remote party by sending text messages and
273 * hearing an audible reply.
274 *
275 * @hide
276 */
277 public static final int TTY_MODE_HCO = 2;
278
279 /**
280 * TTY (teletypewriter) mode is in voice carryover mode (VCO). The speaker is off but the
281 * microphone is still on. User will communicate with the remote party by speaking and receiving
282 * text message replies.
283 *
284 * @hide
285 */
286 public static final int TTY_MODE_VCO = 3;
287
288 /**
289 * Broadcast intent action indicating that the current TTY mode has changed. An intent extra
290 * provides this state as an int.
Evan Charlton10197192014-07-19 15:00:29 -0700291 *
Santos Cordon96efb482014-07-19 14:57:05 -0700292 * @see #EXTRA_CURRENT_TTY_MODE
Evan Charlton10197192014-07-19 15:00:29 -0700293 * @hide
294 */
295 public static final String ACTION_CURRENT_TTY_MODE_CHANGED =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700296 "android.telecom.action.CURRENT_TTY_MODE_CHANGED";
Evan Charlton10197192014-07-19 15:00:29 -0700297
298 /**
299 * The lookup key for an int that indicates the current TTY mode.
300 * Valid modes are:
301 * - {@link #TTY_MODE_OFF}
302 * - {@link #TTY_MODE_FULL}
303 * - {@link #TTY_MODE_HCO}
304 * - {@link #TTY_MODE_VCO}
305 *
306 * @hide
307 */
308 public static final String EXTRA_CURRENT_TTY_MODE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700309 "android.telecom.intent.extra.CURRENT_TTY_MODE";
Evan Charlton10197192014-07-19 15:00:29 -0700310
311 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700312 * Broadcast intent action indicating that the TTY preferred operating mode has changed. An
313 * intent extra provides the new mode as an int.
Evan Charlton10197192014-07-19 15:00:29 -0700314 *
Santos Cordon96efb482014-07-19 14:57:05 -0700315 * @see #EXTRA_TTY_PREFERRED_MODE
Evan Charlton10197192014-07-19 15:00:29 -0700316 * @hide
317 */
318 public static final String ACTION_TTY_PREFERRED_MODE_CHANGED =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700319 "android.telecom.action.TTY_PREFERRED_MODE_CHANGED";
Evan Charlton10197192014-07-19 15:00:29 -0700320
321 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700322 * The lookup key for an int that indicates preferred TTY mode. Valid modes are: -
323 * {@link #TTY_MODE_OFF} - {@link #TTY_MODE_FULL} - {@link #TTY_MODE_HCO} -
324 * {@link #TTY_MODE_VCO}
Evan Charlton10197192014-07-19 15:00:29 -0700325 *
326 * @hide
327 */
328 public static final String EXTRA_TTY_PREFERRED_MODE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700329 "android.telecom.intent.extra.TTY_PREFERRED";
Evan Charlton10197192014-07-19 15:00:29 -0700330
Nancy Chen9d568c02014-09-08 14:17:59 -0700331 /**
332 * The following 4 constants define how properties such as phone numbers and names are
333 * displayed to the user.
334 */
335
Santos Cordoned769ae2015-05-13 18:47:38 -0700336 /**
337 * Indicates that the address or number of a call is allowed to be displayed for caller ID.
338 */
Nancy Chen9d568c02014-09-08 14:17:59 -0700339 public static final int PRESENTATION_ALLOWED = 1;
340
Santos Cordoned769ae2015-05-13 18:47:38 -0700341 /**
342 * Indicates that the address or number of a call is blocked by the other party.
343 */
Nancy Chen9d568c02014-09-08 14:17:59 -0700344 public static final int PRESENTATION_RESTRICTED = 2;
345
Santos Cordoned769ae2015-05-13 18:47:38 -0700346 /**
347 * Indicates that the address or number of a call is not specified or known by the carrier.
348 */
Nancy Chen9d568c02014-09-08 14:17:59 -0700349 public static final int PRESENTATION_UNKNOWN = 3;
350
Santos Cordoned769ae2015-05-13 18:47:38 -0700351 /**
352 * Indicates that the address or number of a call belongs to a pay phone.
353 */
Nancy Chen9d568c02014-09-08 14:17:59 -0700354 public static final int PRESENTATION_PAYPHONE = 4;
355
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700356 private static final String TAG = "TelecomManager";
Yorke Leeb4ce1432014-06-09 13:53:23 -0700357
358 private final Context mContext;
Yorke Leeb4ce1432014-06-09 13:53:23 -0700359
Santos Cordon6c7a3882014-06-25 15:30:08 -0700360 /**
361 * @hide
362 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700363 public static TelecomManager from(Context context) {
364 return (TelecomManager) context.getSystemService(Context.TELECOM_SERVICE);
Yorke Leeb4ce1432014-06-09 13:53:23 -0700365 }
Santos Cordon6c7a3882014-06-25 15:30:08 -0700366
367 /**
368 * @hide
369 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700370 public TelecomManager(Context context) {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700371 Context appContext = context.getApplicationContext();
372 if (appContext != null) {
373 mContext = appContext;
374 } else {
375 mContext = context;
376 }
377 }
378
379 /**
Santos Cordon91371dc2015-05-08 13:52:09 -0700380 * Return the {@link PhoneAccount} which will be used to place outgoing calls to addresses with
381 * the specified {@code uriScheme}. This {@link PhoneAccount} will always be a member of the
382 * list which is returned from invoking {@link #getCallCapablePhoneAccounts()}. The specific
383 * account returned depends on the following priorities:
384 * <ul>
385 * <li> If the user-selected default {@link PhoneAccount} supports the specified scheme, it will
386 * be returned.
387 * </li>
388 * <li> If there exists only one {@link PhoneAccount} that supports the specified scheme, it
389 * will be returned.
390 * </li>
391 * </ul>
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700392 * <p>
Santos Cordon91371dc2015-05-08 13:52:09 -0700393 * If no {@link PhoneAccount} fits the criteria above, this method will return {@code null}.
394 *
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700395 * @param uriScheme The URI scheme.
Santos Cordon91371dc2015-05-08 13:52:09 -0700396 * @return The {@link PhoneAccountHandle} corresponding to the account to be used.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700397 */
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700398 public PhoneAccountHandle getDefaultOutgoingPhoneAccount(String uriScheme) {
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700399 try {
400 if (isServiceConnected()) {
Svet Ganov16a16892015-04-16 10:32:04 -0700401 return getTelecomService().getDefaultOutgoingPhoneAccount(uriScheme,
402 mContext.getOpPackageName());
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700403 }
404 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700405 Log.e(TAG, "Error calling ITelecomService#getDefaultOutgoingPhoneAccount", e);
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700406 }
407 return null;
408 }
409
410 /**
Andrew Leed4abbfb2014-09-03 14:58:27 -0700411 * Return the {@link PhoneAccount} which is the user-chosen default for making outgoing phone
412 * calls. This {@code PhoneAccount} will always be a member of the list which is returned from
Nancy Chen210ef032014-09-15 17:58:42 -0700413 * calling {@link #getCallCapablePhoneAccounts()}
Santos Cordon91371dc2015-05-08 13:52:09 -0700414 * <p>
Andrew Leed4abbfb2014-09-03 14:58:27 -0700415 * Apps must be prepared for this method to return {@code null}, indicating that there currently
416 * exists no user-chosen default {@code PhoneAccount}.
417 *
418 * @return The user outgoing phone account selected by the user.
Jay Shrauner225ccad2015-04-15 15:51:15 -0700419 * @hide
Andrew Leed4abbfb2014-09-03 14:58:27 -0700420 */
421 public PhoneAccountHandle getUserSelectedOutgoingPhoneAccount() {
422 try {
423 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700424 return getTelecomService().getUserSelectedOutgoingPhoneAccount();
Andrew Leed4abbfb2014-09-03 14:58:27 -0700425 }
426 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700427 Log.e(TAG, "Error calling ITelecomService#getUserSelectedOutgoingPhoneAccount", e);
Andrew Leed4abbfb2014-09-03 14:58:27 -0700428 }
429 return null;
430 }
431
432 /**
Santos Cordon91371dc2015-05-08 13:52:09 -0700433 * Sets the user-chosen default for making outgoing phone calls.
Andrew Lee59cac3a2014-08-28 16:50:10 -0700434 * @hide
435 */
Andrew Leed4abbfb2014-09-03 14:58:27 -0700436 public void setUserSelectedOutgoingPhoneAccount(PhoneAccountHandle accountHandle) {
Andrew Lee59cac3a2014-08-28 16:50:10 -0700437 try {
438 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700439 getTelecomService().setUserSelectedOutgoingPhoneAccount(accountHandle);
Andrew Lee59cac3a2014-08-28 16:50:10 -0700440 }
441 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700442 Log.e(TAG, "Error calling ITelecomService#setUserSelectedOutgoingPhoneAccount");
Andrew Lee59cac3a2014-08-28 16:50:10 -0700443 }
444 }
445
446 /**
Andrew Lee59cac3a2014-08-28 16:50:10 -0700447 * Returns the current SIM call manager. Apps must be prepared for this method to return
448 * {@code null}, indicating that there currently exists no user-chosen default
449 * {@code PhoneAccount}.
Santos Cordon91371dc2015-05-08 13:52:09 -0700450 *
Andrew Lee59cac3a2014-08-28 16:50:10 -0700451 * @return The phone account handle of the current sim call manager.
Andrew Lee59cac3a2014-08-28 16:50:10 -0700452 */
453 public PhoneAccountHandle getSimCallManager() {
454 try {
455 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700456 return getTelecomService().getSimCallManager();
Andrew Lee59cac3a2014-08-28 16:50:10 -0700457 }
458 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700459 Log.e(TAG, "Error calling ITelecomService#getSimCallManager");
Andrew Lee59cac3a2014-08-28 16:50:10 -0700460 }
461 return null;
462 }
463
464 /**
465 * Sets the SIM call manager to the specified phone account.
Santos Cordon91371dc2015-05-08 13:52:09 -0700466 *
Andrew Lee59cac3a2014-08-28 16:50:10 -0700467 * @param accountHandle The phone account handle of the account to set as the sim call manager.
468 * @hide
469 */
470 public void setSimCallManager(PhoneAccountHandle accountHandle) {
471 try {
472 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700473 getTelecomService().setSimCallManager(accountHandle);
Andrew Lee59cac3a2014-08-28 16:50:10 -0700474 }
475 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700476 Log.e(TAG, "Error calling ITelecomService#setSimCallManager");
Andrew Lee59cac3a2014-08-28 16:50:10 -0700477 }
478 }
479
480 /**
481 * Returns the list of registered SIM call managers.
Santos Cordon91371dc2015-05-08 13:52:09 -0700482 *
Andrew Lee59cac3a2014-08-28 16:50:10 -0700483 * @return List of registered SIM call managers.
484 * @hide
485 */
486 public List<PhoneAccountHandle> getSimCallManagers() {
487 try {
488 if (isServiceConnected()) {
Svet Ganov16a16892015-04-16 10:32:04 -0700489 return getTelecomService().getSimCallManagers(mContext.getOpPackageName());
Andrew Lee59cac3a2014-08-28 16:50:10 -0700490 }
491 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700492 Log.e(TAG, "Error calling ITelecomService#getSimCallManagers");
Andrew Lee59cac3a2014-08-28 16:50:10 -0700493 }
494 return new ArrayList<>();
495 }
496
497 /**
Evan Charltoneb0a8d52014-09-04 12:03:34 -0700498 * Returns the current connection manager. Apps must be prepared for this method to return
499 * {@code null}, indicating that there currently exists no user-chosen default
500 * {@code PhoneAccount}.
501 *
502 * @return The phone account handle of the current connection manager.
Evan Charlton0e094d92014-11-08 15:49:16 -0800503 * @hide
Evan Charltoneb0a8d52014-09-04 12:03:34 -0700504 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800505 @SystemApi
Evan Charltoneb0a8d52014-09-04 12:03:34 -0700506 public PhoneAccountHandle getConnectionManager() {
507 return getSimCallManager();
508 }
509
510 /**
Nancy Chen210ef032014-09-15 17:58:42 -0700511 * Returns a list of the {@link PhoneAccountHandle}s which can be used to make and receive phone
512 * calls which support the specified URI scheme.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700513 * <P>
514 * For example, invoking with {@code "tel"} will find all {@link PhoneAccountHandle}s which
515 * support telephone calls (e.g. URIs such as {@code tel:555-555-1212}). Invoking with
516 * {@code "sip"} will find all {@link PhoneAccountHandle}s which support SIP calls (e.g. URIs
517 * such as {@code sip:example@sipexample.com}).
518 *
519 * @param uriScheme The URI scheme.
520 * @return A list of {@code PhoneAccountHandle} objects supporting the URI scheme.
Evan Charlton0e094d92014-11-08 15:49:16 -0800521 * @hide
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700522 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800523 @SystemApi
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700524 public List<PhoneAccountHandle> getPhoneAccountsSupportingScheme(String uriScheme) {
525 try {
526 if (isServiceConnected()) {
Svet Ganov16a16892015-04-16 10:32:04 -0700527 return getTelecomService().getPhoneAccountsSupportingScheme(uriScheme,
528 mContext.getOpPackageName());
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700529 }
530 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700531 Log.e(TAG, "Error calling ITelecomService#getPhoneAccountsSupportingScheme", e);
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700532 }
533 return new ArrayList<>();
534 }
535
Nancy Chen513c8922014-09-17 14:47:20 -0700536
537 /**
Santos Cordon91371dc2015-05-08 13:52:09 -0700538 * Returns a list of {@link PhoneAccountHandle}s which can be used to make and receive phone
539 * calls. The returned list includes only those accounts which have been explicitly enabled
540 * by the user.
Nancy Chen513c8922014-09-17 14:47:20 -0700541 *
542 * @see #EXTRA_PHONE_ACCOUNT_HANDLE
543 * @return A list of {@code PhoneAccountHandle} objects.
Nancy Chen513c8922014-09-17 14:47:20 -0700544 */
545 public List<PhoneAccountHandle> getCallCapablePhoneAccounts() {
Santos Cordon91371dc2015-05-08 13:52:09 -0700546 return getCallCapablePhoneAccounts(false);
547 }
548
549 /**
550 * Returns a list of {@link PhoneAccountHandle}s including those which have not been enabled
551 * by the user.
552 *
553 * @return A list of {@code PhoneAccountHandle} objects.
554 * @hide
555 */
556 public List<PhoneAccountHandle> getCallCapablePhoneAccounts(boolean includeDisabledAccounts) {
Nancy Chen513c8922014-09-17 14:47:20 -0700557 try {
558 if (isServiceConnected()) {
Santos Cordon91371dc2015-05-08 13:52:09 -0700559 return getTelecomService().getCallCapablePhoneAccounts(
560 includeDisabledAccounts, mContext.getOpPackageName());
Nancy Chen513c8922014-09-17 14:47:20 -0700561 }
562 } catch (RemoteException e) {
Santos Cordon91371dc2015-05-08 13:52:09 -0700563 Log.e(TAG, "Error calling ITelecomService#getCallCapablePhoneAccounts(" +
564 includeDisabledAccounts + ")", e);
Nancy Chen513c8922014-09-17 14:47:20 -0700565 }
566 return new ArrayList<>();
567 }
568
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700569 /**
Nancy Chen513c8922014-09-17 14:47:20 -0700570 * Returns a list of all {@link PhoneAccount}s registered for the calling package.
571 *
572 * @return A list of {@code PhoneAccountHandle} objects.
Evan Charlton0e094d92014-11-08 15:49:16 -0800573 * @hide
Nancy Chen513c8922014-09-17 14:47:20 -0700574 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800575 @SystemApi
Nancy Chen513c8922014-09-17 14:47:20 -0700576 public List<PhoneAccountHandle> getPhoneAccountsForPackage() {
577 try {
578 if (isServiceConnected()) {
579 return getTelecomService().getPhoneAccountsForPackage(mContext.getPackageName());
580 }
581 } catch (RemoteException e) {
582 Log.e(TAG, "Error calling ITelecomService#getPhoneAccountsForPackage", e);
583 }
584 return null;
585 }
586
587 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700588 * Return the {@link PhoneAccount} for a specified {@link PhoneAccountHandle}. Object includes
589 * resources which can be used in a user interface.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700590 *
Evan Charlton6eb262c2014-07-19 18:18:19 -0700591 * @param account The {@link PhoneAccountHandle}.
Evan Charlton8c8a0622014-07-20 12:31:00 -0700592 * @return The {@link PhoneAccount} object.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700593 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700594 public PhoneAccount getPhoneAccount(PhoneAccountHandle account) {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700595 try {
596 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700597 return getTelecomService().getPhoneAccount(account);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700598 }
599 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700600 Log.e(TAG, "Error calling ITelecomService#getPhoneAccount", e);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700601 }
602 return null;
603 }
604
605 /**
Nancy Chen210ef032014-09-15 17:58:42 -0700606 * Returns a count of all {@link PhoneAccount}s.
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700607 *
Nancy Chen210ef032014-09-15 17:58:42 -0700608 * @return The count of {@link PhoneAccount}s.
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700609 * @hide
610 */
611 @SystemApi
612 public int getAllPhoneAccountsCount() {
613 try {
614 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700615 return getTelecomService().getAllPhoneAccountsCount();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700616 }
617 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700618 Log.e(TAG, "Error calling ITelecomService#getAllPhoneAccountsCount", e);
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700619 }
620 return 0;
621 }
622
623 /**
624 * Returns a list of all {@link PhoneAccount}s.
625 *
626 * @return All {@link PhoneAccount}s.
627 * @hide
628 */
629 @SystemApi
630 public List<PhoneAccount> getAllPhoneAccounts() {
631 try {
632 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700633 return getTelecomService().getAllPhoneAccounts();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700634 }
635 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700636 Log.e(TAG, "Error calling ITelecomService#getAllPhoneAccounts", e);
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700637 }
638 return Collections.EMPTY_LIST;
639 }
640
641 /**
642 * Returns a list of all {@link PhoneAccountHandle}s.
643 *
644 * @return All {@link PhoneAccountHandle}s.
645 * @hide
646 */
647 @SystemApi
648 public List<PhoneAccountHandle> getAllPhoneAccountHandles() {
649 try {
650 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700651 return getTelecomService().getAllPhoneAccountHandles();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700652 }
653 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700654 Log.e(TAG, "Error calling ITelecomService#getAllPhoneAccountHandles", e);
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700655 }
656 return Collections.EMPTY_LIST;
657 }
658
659 /**
Santos Cordond9e614f2014-10-28 13:10:36 -0700660 * Register a {@link PhoneAccount} for use by the system. When registering
661 * {@link PhoneAccount}s, existing registrations will be overwritten if the
662 * {@link PhoneAccountHandle} matches that of a {@link PhoneAccount} which is already
663 * registered. Once registered, the {@link PhoneAccount} is listed to the user as an option
664 * when placing calls. The user may still need to enable the {@link PhoneAccount} within
665 * the phone app settings before the account is usable.
666 * <p>
667 * A {@link SecurityException} will be thrown if an app tries to register a
668 * {@link PhoneAccountHandle} where the package name specified within
669 * {@link PhoneAccountHandle#getComponentName()} does not match the package name of the app.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700670 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700671 * @param account The complete {@link PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700672 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700673 public void registerPhoneAccount(PhoneAccount account) {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700674 try {
675 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700676 getTelecomService().registerPhoneAccount(account);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700677 }
678 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700679 Log.e(TAG, "Error calling ITelecomService#registerPhoneAccount", e);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700680 }
681 }
682
683 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700684 * Remove a {@link PhoneAccount} registration from the system.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700685 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700686 * @param accountHandle A {@link PhoneAccountHandle} for the {@link PhoneAccount} to unregister.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700687 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700688 public void unregisterPhoneAccount(PhoneAccountHandle accountHandle) {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700689 try {
690 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700691 getTelecomService().unregisterPhoneAccount(accountHandle);
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#unregisterPhoneAccount", e);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700695 }
696 }
697
698 /**
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700699 * Remove all Accounts that belong to the calling package from the system.
Evan Charlton0e094d92014-11-08 15:49:16 -0800700 * @hide
Ihab Awad807fe0a2014-07-09 12:30:52 -0700701 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800702 @SystemApi
Yorke Lee06044272015-04-14 15:16:59 -0700703 public void clearPhoneAccounts() {
704 clearAccounts();
705 }
706 /**
707 * Remove all Accounts that belong to the calling package from the system.
708 * @deprecated Use {@link #clearPhoneAccounts()} instead.
709 * @hide
710 */
711 @SystemApi
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700712 public void clearAccounts() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700713 try {
714 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700715 getTelecomService().clearAccounts(mContext.getPackageName());
Ihab Awad807fe0a2014-07-09 12:30:52 -0700716 }
717 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700718 Log.e(TAG, "Error calling ITelecomService#clearAccounts", e);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700719 }
720 }
721
722 /**
Anthony Lee67279262014-10-27 11:28:40 -0700723 * Remove all Accounts that belong to the specified package from the system.
724 * @hide
725 */
726 public void clearAccountsForPackage(String packageName) {
727 try {
728 if (isServiceConnected() && !TextUtils.isEmpty(packageName)) {
729 getTelecomService().clearAccounts(packageName);
730 }
731 } catch (RemoteException e) {
Nancy Chen5cf27842015-01-24 23:30:27 -0800732 Log.e(TAG, "Error calling ITelecomService#clearAccountsForPackage", e);
Anthony Lee67279262014-10-27 11:28:40 -0700733 }
734 }
735
Yorke Lee1011f482015-04-23 15:58:27 -0700736
Anthony Lee67279262014-10-27 11:28:40 -0700737 /**
Yorke Lee1011f482015-04-23 15:58:27 -0700738 * @deprecated - Use {@link TelecomManager#getDefaultDialerPackage} to directly access
739 * the default dialer's package name instead.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700740 * @hide
741 */
Santos Cordon6c7a3882014-06-25 15:30:08 -0700742 @SystemApi
743 public ComponentName getDefaultPhoneApp() {
744 try {
Santos Cordon9eb45932014-06-27 12:28:43 -0700745 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700746 return getTelecomService().getDefaultPhoneApp();
Santos Cordon9eb45932014-06-27 12:28:43 -0700747 }
Santos Cordon6c7a3882014-06-25 15:30:08 -0700748 } catch (RemoteException e) {
749 Log.e(TAG, "RemoteException attempting to get the default phone app.", e);
750 }
751 return null;
752 }
753
Santos Cordon9eb45932014-06-27 12:28:43 -0700754 /**
Yorke Lee1011f482015-04-23 15:58:27 -0700755 * Used to determine the currently selected default dialer package.
756 *
757 * @return package name for the default dialer package or null if no package has been
758 * selected as the default dialer.
759 */
760 public String getDefaultDialerPackage() {
761 try {
762 if (isServiceConnected()) {
763 return getTelecomService().getDefaultDialerPackage();
764 }
765 } catch (RemoteException e) {
766 Log.e(TAG, "RemoteException attempting to get the default dialer package name.", e);
767 }
768 return null;
769 }
770
771 /**
772 * Used to determine the dialer package that is preloaded on the system partition.
773 *
774 * @return package name for the system dialer package or null if no system dialer is preloaded.
775 * @hide
776 */
777 public String getSystemDialerPackage() {
778 try {
779 if (isServiceConnected()) {
780 return getTelecomService().getSystemDialerPackage();
781 }
782 } catch (RemoteException e) {
783 Log.e(TAG, "RemoteException attempting to get the system dialer package name.", e);
784 }
785 return null;
786 }
787
788 /**
Nancy Chen443e5012014-10-15 15:48:21 -0700789 * Return whether a given phone number is the configured voicemail number for a
790 * particular phone account.
791 *
792 * @param accountHandle The handle for the account to check the voicemail number against
793 * @param number The number to look up.
Nancy Chen443e5012014-10-15 15:48:21 -0700794 */
Nancy Chen443e5012014-10-15 15:48:21 -0700795 public boolean isVoiceMailNumber(PhoneAccountHandle accountHandle, String number) {
796 try {
797 if (isServiceConnected()) {
Svet Ganov16a16892015-04-16 10:32:04 -0700798 return getTelecomService().isVoiceMailNumber(accountHandle, number,
799 mContext.getOpPackageName());
Nancy Chen443e5012014-10-15 15:48:21 -0700800 }
801 } catch (RemoteException e) {
Nancy Chen5cf27842015-01-24 23:30:27 -0800802 Log.e(TAG, "RemoteException calling ITelecomService#isVoiceMailNumber.", e);
Nancy Chen443e5012014-10-15 15:48:21 -0700803 }
804 return false;
805 }
806
807 /**
Yorke Lee49e2d462015-04-15 16:14:22 -0700808 * Return the voicemail number for a given phone account.
Nancy Chen8c066f72014-12-03 15:18:08 -0800809 *
Yorke Lee49e2d462015-04-15 16:14:22 -0700810 * @param accountHandle The handle for the phone account.
811 * @return The voicemail number for the phone account, and {@code null} if one has not been
812 * configured.
Nancy Chen8c066f72014-12-03 15:18:08 -0800813 */
Yorke Lee49e2d462015-04-15 16:14:22 -0700814 public String getVoiceMailNumber(PhoneAccountHandle accountHandle) {
Nancy Chen8c066f72014-12-03 15:18:08 -0800815 try {
816 if (isServiceConnected()) {
Svet Ganov16a16892015-04-16 10:32:04 -0700817 return getTelecomService().getVoiceMailNumber(accountHandle,
818 mContext.getOpPackageName());
Nancy Chen8c066f72014-12-03 15:18:08 -0800819 }
820 } catch (RemoteException e) {
Nancy Chen5cf27842015-01-24 23:30:27 -0800821 Log.e(TAG, "RemoteException calling ITelecomService#hasVoiceMailNumber.", e);
Nancy Chen8c066f72014-12-03 15:18:08 -0800822 }
Yorke Lee49e2d462015-04-15 16:14:22 -0700823 return null;
Nancy Chen8c066f72014-12-03 15:18:08 -0800824 }
825
826 /**
Nancy Chen5cf27842015-01-24 23:30:27 -0800827 * Return the line 1 phone number for given phone account.
828 *
829 * @param accountHandle The handle for the account retrieve a number for.
830 * @return A string representation of the line 1 phone number.
Nancy Chen5cf27842015-01-24 23:30:27 -0800831 */
Nancy Chen5cf27842015-01-24 23:30:27 -0800832 public String getLine1Number(PhoneAccountHandle accountHandle) {
833 try {
834 if (isServiceConnected()) {
Svet Ganov16a16892015-04-16 10:32:04 -0700835 return getTelecomService().getLine1Number(accountHandle,
836 mContext.getOpPackageName());
Nancy Chen5cf27842015-01-24 23:30:27 -0800837 }
838 } catch (RemoteException e) {
839 Log.e(TAG, "RemoteException calling ITelecomService#getLine1Number.", e);
840 }
841 return null;
842 }
843
844 /**
Santos Cordon9eb45932014-06-27 12:28:43 -0700845 * Returns whether there is an ongoing phone call (can be in dialing, ringing, active or holding
846 * states).
Nancy Chen0eb1e402014-08-21 22:52:29 -0700847 * <p>
848 * Requires permission: {@link android.Manifest.permission#READ_PHONE_STATE}
849 * </p>
Santos Cordon9eb45932014-06-27 12:28:43 -0700850 */
Nancy Chen0eb1e402014-08-21 22:52:29 -0700851 public boolean isInCall() {
Santos Cordon9eb45932014-06-27 12:28:43 -0700852 try {
853 if (isServiceConnected()) {
Svet Ganov16a16892015-04-16 10:32:04 -0700854 return getTelecomService().isInCall(mContext.getOpPackageName());
Santos Cordon9eb45932014-06-27 12:28:43 -0700855 }
856 } catch (RemoteException e) {
Yorke Lee2ae312e2014-09-12 17:58:48 -0700857 Log.e(TAG, "RemoteException calling isInCall().", e);
Santos Cordon9eb45932014-06-27 12:28:43 -0700858 }
859 return false;
860 }
861
862 /**
Yorke Lee2ae312e2014-09-12 17:58:48 -0700863 * Returns one of the following constants that represents the current state of Telecom:
864 *
865 * {@link TelephonyManager#CALL_STATE_RINGING}
866 * {@link TelephonyManager#CALL_STATE_OFFHOOK}
867 * {@link TelephonyManager#CALL_STATE_IDLE}
Yorke Lee7c72c2d2014-10-28 14:12:02 -0700868 *
869 * Note that this API does not require the
870 * {@link android.Manifest.permission#READ_PHONE_STATE} permission. This is intentional, to
871 * preserve the behavior of {@link TelephonyManager#getCallState()}, which also did not require
872 * the permission.
Yorke Lee2ae312e2014-09-12 17:58:48 -0700873 * @hide
874 */
875 @SystemApi
876 public int getCallState() {
877 try {
878 if (isServiceConnected()) {
879 return getTelecomService().getCallState();
880 }
881 } catch (RemoteException e) {
882 Log.d(TAG, "RemoteException calling getCallState().", e);
883 }
884 return TelephonyManager.CALL_STATE_IDLE;
885 }
886
887 /**
Santos Cordon9eb45932014-06-27 12:28:43 -0700888 * Returns whether there currently exists is a ringing incoming-call.
889 *
890 * @hide
891 */
892 @SystemApi
893 public boolean isRinging() {
894 try {
895 if (isServiceConnected()) {
Svet Ganov16a16892015-04-16 10:32:04 -0700896 return getTelecomService().isRinging(mContext.getOpPackageName());
Santos Cordon9eb45932014-06-27 12:28:43 -0700897 }
898 } catch (RemoteException e) {
899 Log.e(TAG, "RemoteException attempting to get ringing state of phone app.", e);
900 }
901 return false;
902 }
903
904 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700905 * Ends an ongoing call.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700906 * TODO: L-release - need to convert all invocations of ITelecomService#endCall to use this
Santos Cordon96efb482014-07-19 14:57:05 -0700907 * method (clockwork & gearhead).
Santos Cordon9eb45932014-06-27 12:28:43 -0700908 * @hide
909 */
910 @SystemApi
911 public boolean endCall() {
912 try {
913 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700914 return getTelecomService().endCall();
Santos Cordon9eb45932014-06-27 12:28:43 -0700915 }
916 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700917 Log.e(TAG, "Error calling ITelecomService#endCall", e);
Santos Cordon9eb45932014-06-27 12:28:43 -0700918 }
919 return false;
920 }
921
922 /**
923 * If there is a ringing incoming call, this method accepts the call on behalf of the user.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700924 * TODO: L-release - need to convert all invocation of ITelecmmService#answerRingingCall to use
Santos Cordon96efb482014-07-19 14:57:05 -0700925 * this method (clockwork & gearhead).
Santos Cordon9eb45932014-06-27 12:28:43 -0700926 *
927 * @hide
928 */
929 @SystemApi
930 public void acceptRingingCall() {
931 try {
932 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700933 getTelecomService().acceptRingingCall();
Santos Cordon9eb45932014-06-27 12:28:43 -0700934 }
935 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700936 Log.e(TAG, "Error calling ITelecomService#acceptRingingCall", e);
Santos Cordon9eb45932014-06-27 12:28:43 -0700937 }
938 }
939
940 /**
941 * Silences the ringer if a ringing call exists.
Santos Cordon9eb45932014-06-27 12:28:43 -0700942 */
Santos Cordon9eb45932014-06-27 12:28:43 -0700943 public void silenceRinger() {
944 try {
945 if (isServiceConnected()) {
Yorke Leef1a349b2015-04-29 16:16:50 -0700946 getTelecomService().silenceRinger(mContext.getOpPackageName());
Santos Cordon9eb45932014-06-27 12:28:43 -0700947 }
948 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700949 Log.e(TAG, "Error calling ITelecomService#silenceRinger", e);
Santos Cordon9eb45932014-06-27 12:28:43 -0700950 }
951 }
952
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700953 /**
954 * Returns whether TTY is supported on this device.
955 *
956 * @hide
957 */
958 @SystemApi
959 public boolean isTtySupported() {
960 try {
961 if (isServiceConnected()) {
Svet Ganov16a16892015-04-16 10:32:04 -0700962 return getTelecomService().isTtySupported(mContext.getOpPackageName());
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700963 }
964 } catch (RemoteException e) {
965 Log.e(TAG, "RemoteException attempting to get TTY supported state.", e);
966 }
967 return false;
968 }
969
970 /**
971 * 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 -0700972 * settings and have a wired headset plugged in.
973 * Valid modes are:
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700974 * - {@link TelecomManager#TTY_MODE_OFF}
975 * - {@link TelecomManager#TTY_MODE_FULL}
976 * - {@link TelecomManager#TTY_MODE_HCO}
977 * - {@link TelecomManager#TTY_MODE_VCO}
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700978 * @hide
979 */
980 public int getCurrentTtyMode() {
981 try {
982 if (isServiceConnected()) {
Svet Ganov16a16892015-04-16 10:32:04 -0700983 return getTelecomService().getCurrentTtyMode(mContext.getOpPackageName());
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700984 }
985 } catch (RemoteException e) {
986 Log.e(TAG, "RemoteException attempting to get the current TTY mode.", e);
987 }
Evan Charlton10197192014-07-19 15:00:29 -0700988 return TTY_MODE_OFF;
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700989 }
990
Santos Cordon96efb482014-07-19 14:57:05 -0700991 /**
992 * Registers a new incoming call. A {@link ConnectionService} should invoke this method when it
993 * has an incoming call. The specified {@link PhoneAccountHandle} must have been registered
Nancy Chen210ef032014-09-15 17:58:42 -0700994 * with {@link #registerPhoneAccount}. Once invoked, this method will cause the system to bind
995 * to the {@link ConnectionService} associated with the {@link PhoneAccountHandle} and request
Santos Cordon96efb482014-07-19 14:57:05 -0700996 * additional information about the call (See
997 * {@link ConnectionService#onCreateIncomingConnection}) before starting the incoming call UI.
998 *
999 * @param phoneAccount A {@link PhoneAccountHandle} registered with
1000 * {@link #registerPhoneAccount}.
1001 * @param extras A bundle that will be passed through to
1002 * {@link ConnectionService#onCreateIncomingConnection}.
1003 */
1004 public void addNewIncomingCall(PhoneAccountHandle phoneAccount, Bundle extras) {
1005 try {
1006 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001007 getTelecomService().addNewIncomingCall(
Santos Cordon96efb482014-07-19 14:57:05 -07001008 phoneAccount, extras == null ? new Bundle() : extras);
1009 }
1010 } catch (RemoteException e) {
1011 Log.e(TAG, "RemoteException adding a new incoming call: " + phoneAccount, e);
1012 }
1013 }
1014
Nancy Chen0eb1e402014-08-21 22:52:29 -07001015 /**
Yorke Leec3cf9822014-10-02 09:38:39 -07001016 * Registers a new unknown call with Telecom. This can only be called by the system Telephony
1017 * service. This is invoked when Telephony detects a new unknown connection that was neither
1018 * a new incoming call, nor an user-initiated outgoing call.
1019 *
1020 * @param phoneAccount A {@link PhoneAccountHandle} registered with
1021 * {@link #registerPhoneAccount}.
1022 * @param extras A bundle that will be passed through to
1023 * {@link ConnectionService#onCreateIncomingConnection}.
1024 * @hide
1025 */
1026 @SystemApi
1027 public void addNewUnknownCall(PhoneAccountHandle phoneAccount, Bundle extras) {
1028 try {
1029 if (isServiceConnected()) {
1030 getTelecomService().addNewUnknownCall(
1031 phoneAccount, extras == null ? new Bundle() : extras);
1032 }
1033 } catch (RemoteException e) {
1034 Log.e(TAG, "RemoteException adding a new unknown call: " + phoneAccount, e);
1035 }
1036 }
1037
1038 /**
Nancy Chen0eb1e402014-08-21 22:52:29 -07001039 * Processes the specified dial string as an MMI code.
1040 * MMI codes are any sequence of characters entered into the dialpad that contain a "*" or "#".
1041 * Some of these sequences launch special behavior through handled by Telephony.
Nancy Chen95e8a672014-10-16 18:38:21 -07001042 * This method uses the default subscription.
Nancy Chen0eb1e402014-08-21 22:52:29 -07001043 * <p>
1044 * Requires that the method-caller be set as the system dialer app.
1045 * </p>
1046 *
1047 * @param dialString The digits to dial.
1048 * @return True if the digits were processed as an MMI code, false otherwise.
1049 */
1050 public boolean handleMmi(String dialString) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001051 ITelecomService service = getTelecomService();
Nancy Chen0eb1e402014-08-21 22:52:29 -07001052 if (service != null) {
1053 try {
Yorke Leef1a349b2015-04-29 16:16:50 -07001054 return service.handlePinMmi(dialString, mContext.getOpPackageName());
Nancy Chen0eb1e402014-08-21 22:52:29 -07001055 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001056 Log.e(TAG, "Error calling ITelecomService#handlePinMmi", e);
Nancy Chen0eb1e402014-08-21 22:52:29 -07001057 }
1058 }
1059 return false;
1060 }
1061
1062 /**
Nancy Chen95e8a672014-10-16 18:38:21 -07001063 * Processes the specified dial string as an MMI code.
1064 * MMI codes are any sequence of characters entered into the dialpad that contain a "*" or "#".
1065 * Some of these sequences launch special behavior through handled by Telephony.
1066 * <p>
1067 * Requires that the method-caller be set as the system dialer app.
1068 * </p>
1069 *
1070 * @param accountHandle The handle for the account the MMI code should apply to.
1071 * @param dialString The digits to dial.
1072 * @return True if the digits were processed as an MMI code, false otherwise.
Nancy Chen95e8a672014-10-16 18:38:21 -07001073 */
Yorke Lee06044272015-04-14 15:16:59 -07001074 public boolean handleMmi(String dialString, PhoneAccountHandle accountHandle) {
Nancy Chen95e8a672014-10-16 18:38:21 -07001075 ITelecomService service = getTelecomService();
1076 if (service != null) {
1077 try {
Yorke Leef1a349b2015-04-29 16:16:50 -07001078 return service.handlePinMmiForPhoneAccount(accountHandle, dialString,
1079 mContext.getOpPackageName());
Nancy Chen95e8a672014-10-16 18:38:21 -07001080 } catch (RemoteException e) {
1081 Log.e(TAG, "Error calling ITelecomService#handlePinMmi", e);
1082 }
1083 }
1084 return false;
1085 }
1086
1087 /**
Nancy Chenb2299c12014-10-29 18:22:11 -07001088 * @param accountHandle The handle for the account to derive an adn query URI for or
1089 * {@code null} to return a URI which will use the default account.
1090 * @return The URI (with the content:// scheme) specific to the specified {@link PhoneAccount}
1091 * for the the content retrieve.
1092 */
1093 public Uri getAdnUriForPhoneAccount(PhoneAccountHandle accountHandle) {
1094 ITelecomService service = getTelecomService();
1095 if (service != null && accountHandle != null) {
1096 try {
Yorke Leef1a349b2015-04-29 16:16:50 -07001097 return service.getAdnUriForPhoneAccount(accountHandle, mContext.getOpPackageName());
Nancy Chenb2299c12014-10-29 18:22:11 -07001098 } catch (RemoteException e) {
1099 Log.e(TAG, "Error calling ITelecomService#getAdnUriForPhoneAccount", e);
1100 }
1101 }
1102 return Uri.parse("content://icc/adn");
1103 }
1104
1105 /**
Nancy Chen0eb1e402014-08-21 22:52:29 -07001106 * Removes the missed-call notification if one is present.
1107 * <p>
1108 * Requires that the method-caller be set as the system dialer app.
1109 * </p>
1110 */
1111 public void cancelMissedCallsNotification() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001112 ITelecomService service = getTelecomService();
Nancy Chen0eb1e402014-08-21 22:52:29 -07001113 if (service != null) {
1114 try {
Yorke Leef1a349b2015-04-29 16:16:50 -07001115 service.cancelMissedCallsNotification(mContext.getOpPackageName());
Nancy Chen0eb1e402014-08-21 22:52:29 -07001116 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001117 Log.e(TAG, "Error calling ITelecomService#cancelMissedCallsNotification", e);
Nancy Chen0eb1e402014-08-21 22:52:29 -07001118 }
1119 }
1120 }
1121
1122 /**
1123 * Brings the in-call screen to the foreground if there is an ongoing call. If there is
1124 * currently no ongoing call, then this method does nothing.
1125 * <p>
1126 * Requires that the method-caller be set as the system dialer app or have the
1127 * {@link android.Manifest.permission#READ_PHONE_STATE} permission.
1128 * </p>
1129 *
1130 * @param showDialpad Brings up the in-call dialpad as part of showing the in-call screen.
1131 */
1132 public void showInCallScreen(boolean showDialpad) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001133 ITelecomService service = getTelecomService();
Nancy Chen0eb1e402014-08-21 22:52:29 -07001134 if (service != null) {
1135 try {
Svet Ganov16a16892015-04-16 10:32:04 -07001136 service.showInCallScreen(showDialpad, mContext.getOpPackageName());
Nancy Chen0eb1e402014-08-21 22:52:29 -07001137 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001138 Log.e(TAG, "Error calling ITelecomService#showCallScreen", e);
Nancy Chen0eb1e402014-08-21 22:52:29 -07001139 }
1140 }
1141 }
1142
Yorke Lee3e56ba12015-04-23 12:32:36 -07001143 /**
1144 * Places a new outgoing call to the provided address using the system telecom service with
1145 * the specified extras.
1146 *
1147 * This method is equivalent to placing an outgoing call using {@link Intent#ACTION_CALL},
1148 * except that the outgoing call will always be sent via the system telecom service. If
1149 * method-caller is either the user selected default dialer app or preloaded system dialer
1150 * app, then emergency calls will also be allowed.
1151 *
1152 * Requires permission: {@link android.Manifest.permission#CALL_PHONE}
1153 *
1154 * Usage example:
1155 * <pre>
1156 * Uri uri = Uri.fromParts("tel", "12345", null);
1157 * Bundle extras = new Bundle();
1158 * extras.putBoolean(TelecomManager.EXTRA_START_CALL_WITH_SPEAKERPHONE, true);
1159 * telecomManager.placeCall(uri, extras);
1160 * </pre>
1161 *
1162 * @param address The address to make the call to.
1163 * @param extras Bundle of extras to use with the call.
1164 */
1165 public void placeCall(Uri address, Bundle extras) {
1166 ITelecomService service = getTelecomService();
1167 if (service != null) {
Yorke Leea5d5c1d2015-05-05 16:25:55 -07001168 if (address == null) {
1169 Log.w(TAG, "Cannot place call to empty address.");
1170 }
Yorke Lee3e56ba12015-04-23 12:32:36 -07001171 try {
Yorke Leea5d5c1d2015-05-05 16:25:55 -07001172 service.placeCall(address, extras == null ? new Bundle() : extras,
1173 mContext.getOpPackageName());
Yorke Lee3e56ba12015-04-23 12:32:36 -07001174 } catch (RemoteException e) {
1175 Log.e(TAG, "Error calling ITelecomService#placeCall", e);
1176 }
1177 }
1178 }
1179
Santos Cordon91371dc2015-05-08 13:52:09 -07001180 /**
1181 * Enables and disables specified phone account.
1182 *
1183 * @param handle Handle to the phone account.
1184 * @param isEnabled Enable state of the phone account.
1185 * @hide
1186 */
1187 @SystemApi
1188 public void enablePhoneAccount(PhoneAccountHandle handle, boolean isEnabled) {
1189 ITelecomService service = getTelecomService();
1190 if (service != null) {
1191 try {
1192 service.enablePhoneAccount(handle, isEnabled);
1193 } catch (RemoteException e) {
1194 Log.e(TAG, "Error enablePhoneAbbount", e);
1195 }
1196 }
1197 }
1198
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001199 private ITelecomService getTelecomService() {
1200 return ITelecomService.Stub.asInterface(ServiceManager.getService(Context.TELECOM_SERVICE));
Santos Cordon6c7a3882014-06-25 15:30:08 -07001201 }
Santos Cordon9eb45932014-06-27 12:28:43 -07001202
1203 private boolean isServiceConnected() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001204 boolean isConnected = getTelecomService() != null;
Santos Cordon9eb45932014-06-27 12:28:43 -07001205 if (!isConnected) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001206 Log.w(TAG, "Telecom Service not found.");
Santos Cordon9eb45932014-06-27 12:28:43 -07001207 }
1208 return isConnected;
1209 }
Evan Charlton235c1592014-09-05 15:41:23 +00001210}