blob: 3c8cc9aa1a189858e6ffce122584ddb389fb14dd [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 Lee3818a8922014-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 Lee3818a8922014-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 /**
127 * Extra value used to provide the package name for {@link #ACTION_CHANGE_DEFAULT_DIALER}.
128 */
129 public static final String EXTRA_CHANGE_DEFAULT_DIALER_PACKAGE_NAME =
130 "android.telecom.extra.CHANGE_DEFAULT_DIALER_PACKAGE_NAME";
131
132 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700133 * Optional extra for {@link android.content.Intent#ACTION_CALL} containing a boolean that
134 * determines whether the speakerphone should be automatically turned on for an outgoing call.
Evan Charlton10197192014-07-19 15:00:29 -0700135 */
136 public static final String EXTRA_START_CALL_WITH_SPEAKERPHONE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700137 "android.telecom.extra.START_CALL_WITH_SPEAKERPHONE";
Evan Charlton10197192014-07-19 15:00:29 -0700138
139 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700140 * Optional extra for {@link android.content.Intent#ACTION_CALL} containing an integer that
141 * determines the desired video state for an outgoing call.
Santos Cordon96efb482014-07-19 14:57:05 -0700142 * Valid options:
Yorke Lee32f24732015-05-12 16:18:03 -0700143 * {@link VideoProfile#STATE_AUDIO_ONLY},
144 * {@link VideoProfile#STATE_BIDIRECTIONAL},
145 * {@link VideoProfile#STATE_RX_ENABLED},
146 * {@link VideoProfile#STATE_TX_ENABLED}.
Evan Charlton10197192014-07-19 15:00:29 -0700147 */
148 public static final String EXTRA_START_CALL_WITH_VIDEO_STATE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700149 "android.telecom.extra.START_CALL_WITH_VIDEO_STATE";
Evan Charlton10197192014-07-19 15:00:29 -0700150
151 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700152 * The extra used with an {@link android.content.Intent#ACTION_CALL} and
153 * {@link android.content.Intent#ACTION_DIAL} {@code Intent} to specify a
154 * {@link PhoneAccountHandle} to use when making the call.
Evan Charlton10197192014-07-19 15:00:29 -0700155 * <p class="note">
Santos Cordon96efb482014-07-19 14:57:05 -0700156 * Retrieve with {@link android.content.Intent#getParcelableExtra(String)}.
Evan Charlton10197192014-07-19 15:00:29 -0700157 */
Evan Charlton6eb262c2014-07-19 18:18:19 -0700158 public static final String EXTRA_PHONE_ACCOUNT_HANDLE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700159 "android.telecom.extra.PHONE_ACCOUNT_HANDLE";
Evan Charlton10197192014-07-19 15:00:29 -0700160
161 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700162 * Optional extra for {@link #ACTION_INCOMING_CALL} containing a {@link Bundle} which contains
163 * metadata about the call. This {@link Bundle} will be returned to the
164 * {@link ConnectionService}.
Evan Charlton10197192014-07-19 15:00:29 -0700165 */
166 public static final String EXTRA_INCOMING_CALL_EXTRAS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700167 "android.telecom.extra.INCOMING_CALL_EXTRAS";
Evan Charlton10197192014-07-19 15:00:29 -0700168
169 /**
Nancy Chen10798dc2014-08-08 14:00:25 -0700170 * Optional extra for {@link android.content.Intent#ACTION_CALL} and
171 * {@link android.content.Intent#ACTION_DIAL} {@code Intent} containing a {@link Bundle}
172 * which contains metadata about the call. This {@link Bundle} will be saved into
173 * {@code Call.Details}.
Nancy Chen10798dc2014-08-08 14:00:25 -0700174 */
175 public static final String EXTRA_OUTGOING_CALL_EXTRAS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700176 "android.telecom.extra.OUTGOING_CALL_EXTRAS";
Nancy Chen10798dc2014-08-08 14:00:25 -0700177
178 /**
Yorke Leec3cf9822014-10-02 09:38:39 -0700179 * @hide
180 */
181 public static final String EXTRA_UNKNOWN_CALL_HANDLE =
182 "android.telecom.extra.UNKNOWN_CALL_HANDLE";
183
184 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700185 * Optional extra for {@link android.telephony.TelephonyManager#ACTION_PHONE_STATE_CHANGED}
186 * containing the disconnect code.
Evan Charlton10197192014-07-19 15:00:29 -0700187 */
188 public static final String EXTRA_CALL_DISCONNECT_CAUSE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700189 "android.telecom.extra.CALL_DISCONNECT_CAUSE";
Evan Charlton10197192014-07-19 15:00:29 -0700190
191 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700192 * Optional extra for {@link android.telephony.TelephonyManager#ACTION_PHONE_STATE_CHANGED}
193 * containing the disconnect message.
Evan Charlton10197192014-07-19 15:00:29 -0700194 */
195 public static final String EXTRA_CALL_DISCONNECT_MESSAGE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700196 "android.telecom.extra.CALL_DISCONNECT_MESSAGE";
Evan Charlton10197192014-07-19 15:00:29 -0700197
198 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700199 * Optional extra for {@link android.telephony.TelephonyManager#ACTION_PHONE_STATE_CHANGED}
200 * containing the component name of the associated connection service.
Evan Charlton0e094d92014-11-08 15:49:16 -0800201 * @hide
Evan Charlton10197192014-07-19 15:00:29 -0700202 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800203 @SystemApi
Evan Charlton10197192014-07-19 15:00:29 -0700204 public static final String EXTRA_CONNECTION_SERVICE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700205 "android.telecom.extra.CONNECTION_SERVICE";
Evan Charlton10197192014-07-19 15:00:29 -0700206
207 /**
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700208 * An optional {@link android.content.Intent#ACTION_CALL} intent extra denoting the
209 * package name of the app specifying an alternative gateway for the call.
210 * The value is a string.
211 *
212 * (The following comment corresponds to the all GATEWAY_* extras)
213 * An app which sends the {@link android.content.Intent#ACTION_CALL} intent can specify an
214 * alternative address to dial which is different from the one specified and displayed to
215 * the user. This alternative address is referred to as the gateway address.
216 */
217 public static final String GATEWAY_PROVIDER_PACKAGE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700218 "android.telecom.extra.GATEWAY_PROVIDER_PACKAGE";
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700219
220 /**
221 * An optional {@link android.content.Intent#ACTION_CALL} intent extra corresponding to the
222 * original address to dial for the call. This is used when an alternative gateway address is
223 * provided to recall the original address.
224 * The value is a {@link android.net.Uri}.
225 *
226 * (See {@link #GATEWAY_PROVIDER_PACKAGE} for details)
227 */
228 public static final String GATEWAY_ORIGINAL_ADDRESS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700229 "android.telecom.extra.GATEWAY_ORIGINAL_ADDRESS";
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700230
231 /**
Evan Charlton10197192014-07-19 15:00:29 -0700232 * The number which the party on the other side of the line will see (and use to return the
233 * call).
234 * <p>
Santos Cordon96efb482014-07-19 14:57:05 -0700235 * {@link ConnectionService}s which interact with {@link RemoteConnection}s should only populate
236 * this if the {@link android.telephony.TelephonyManager#getLine1Number()} value, as that is the
237 * user's expected caller ID.
Evan Charlton10197192014-07-19 15:00:29 -0700238 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700239 public static final String EXTRA_CALL_BACK_NUMBER = "android.telecom.extra.CALL_BACK_NUMBER";
Evan Charlton10197192014-07-19 15:00:29 -0700240
241 /**
242 * The dual tone multi-frequency signaling character sent to indicate the dialing system should
243 * pause for a predefined period.
244 */
245 public static final char DTMF_CHARACTER_PAUSE = ',';
246
247 /**
248 * The dual-tone multi-frequency signaling character sent to indicate the dialing system should
249 * wait for user confirmation before proceeding.
250 */
251 public static final char DTMF_CHARACTER_WAIT = ';';
252
253 /**
254 * TTY (teletypewriter) mode is off.
255 *
256 * @hide
257 */
258 public static final int TTY_MODE_OFF = 0;
259
260 /**
261 * TTY (teletypewriter) mode is on. The speaker is off and the microphone is muted. The user
262 * will communicate with the remote party by sending and receiving text messages.
263 *
264 * @hide
265 */
266 public static final int TTY_MODE_FULL = 1;
267
268 /**
269 * TTY (teletypewriter) mode is in hearing carryover mode (HCO). The microphone is muted but the
270 * speaker is on. The user will communicate with the remote party by sending text messages and
271 * hearing an audible reply.
272 *
273 * @hide
274 */
275 public static final int TTY_MODE_HCO = 2;
276
277 /**
278 * TTY (teletypewriter) mode is in voice carryover mode (VCO). The speaker is off but the
279 * microphone is still on. User will communicate with the remote party by speaking and receiving
280 * text message replies.
281 *
282 * @hide
283 */
284 public static final int TTY_MODE_VCO = 3;
285
286 /**
287 * Broadcast intent action indicating that the current TTY mode has changed. An intent extra
288 * provides this state as an int.
Evan Charlton10197192014-07-19 15:00:29 -0700289 *
Santos Cordon96efb482014-07-19 14:57:05 -0700290 * @see #EXTRA_CURRENT_TTY_MODE
Evan Charlton10197192014-07-19 15:00:29 -0700291 * @hide
292 */
293 public static final String ACTION_CURRENT_TTY_MODE_CHANGED =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700294 "android.telecom.action.CURRENT_TTY_MODE_CHANGED";
Evan Charlton10197192014-07-19 15:00:29 -0700295
296 /**
297 * The lookup key for an int that indicates the current TTY mode.
298 * Valid modes are:
299 * - {@link #TTY_MODE_OFF}
300 * - {@link #TTY_MODE_FULL}
301 * - {@link #TTY_MODE_HCO}
302 * - {@link #TTY_MODE_VCO}
303 *
304 * @hide
305 */
306 public static final String EXTRA_CURRENT_TTY_MODE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700307 "android.telecom.intent.extra.CURRENT_TTY_MODE";
Evan Charlton10197192014-07-19 15:00:29 -0700308
309 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700310 * Broadcast intent action indicating that the TTY preferred operating mode has changed. An
311 * intent extra provides the new mode as an int.
Evan Charlton10197192014-07-19 15:00:29 -0700312 *
Santos Cordon96efb482014-07-19 14:57:05 -0700313 * @see #EXTRA_TTY_PREFERRED_MODE
Evan Charlton10197192014-07-19 15:00:29 -0700314 * @hide
315 */
316 public static final String ACTION_TTY_PREFERRED_MODE_CHANGED =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700317 "android.telecom.action.TTY_PREFERRED_MODE_CHANGED";
Evan Charlton10197192014-07-19 15:00:29 -0700318
319 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700320 * The lookup key for an int that indicates preferred TTY mode. Valid modes are: -
321 * {@link #TTY_MODE_OFF} - {@link #TTY_MODE_FULL} - {@link #TTY_MODE_HCO} -
322 * {@link #TTY_MODE_VCO}
Evan Charlton10197192014-07-19 15:00:29 -0700323 *
324 * @hide
325 */
326 public static final String EXTRA_TTY_PREFERRED_MODE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700327 "android.telecom.intent.extra.TTY_PREFERRED";
Evan Charlton10197192014-07-19 15:00:29 -0700328
Nancy Chen9d568c02014-09-08 14:17:59 -0700329 /**
330 * The following 4 constants define how properties such as phone numbers and names are
331 * displayed to the user.
332 */
333
Santos Cordoned769ae2015-05-13 18:47:38 -0700334 /**
335 * Indicates that the address or number of a call is allowed to be displayed for caller ID.
336 */
Nancy Chen9d568c02014-09-08 14:17:59 -0700337 public static final int PRESENTATION_ALLOWED = 1;
338
Santos Cordoned769ae2015-05-13 18:47:38 -0700339 /**
340 * Indicates that the address or number of a call is blocked by the other party.
341 */
Nancy Chen9d568c02014-09-08 14:17:59 -0700342 public static final int PRESENTATION_RESTRICTED = 2;
343
Santos Cordoned769ae2015-05-13 18:47:38 -0700344 /**
345 * Indicates that the address or number of a call is not specified or known by the carrier.
346 */
Nancy Chen9d568c02014-09-08 14:17:59 -0700347 public static final int PRESENTATION_UNKNOWN = 3;
348
Santos Cordoned769ae2015-05-13 18:47:38 -0700349 /**
350 * Indicates that the address or number of a call belongs to a pay phone.
351 */
Nancy Chen9d568c02014-09-08 14:17:59 -0700352 public static final int PRESENTATION_PAYPHONE = 4;
353
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700354 private static final String TAG = "TelecomManager";
Yorke Leeb4ce1432014-06-09 13:53:23 -0700355
356 private final Context mContext;
Yorke Leeb4ce1432014-06-09 13:53:23 -0700357
Santos Cordon6c7a3882014-06-25 15:30:08 -0700358 /**
359 * @hide
360 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700361 public static TelecomManager from(Context context) {
362 return (TelecomManager) context.getSystemService(Context.TELECOM_SERVICE);
Yorke Leeb4ce1432014-06-09 13:53:23 -0700363 }
Santos Cordon6c7a3882014-06-25 15:30:08 -0700364
365 /**
366 * @hide
367 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700368 public TelecomManager(Context context) {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700369 Context appContext = context.getApplicationContext();
370 if (appContext != null) {
371 mContext = appContext;
372 } else {
373 mContext = context;
374 }
375 }
376
377 /**
Santos Cordon91371dc02015-05-08 13:52:09 -0700378 * Return the {@link PhoneAccount} which will be used to place outgoing calls to addresses with
379 * the specified {@code uriScheme}. This {@link PhoneAccount} will always be a member of the
380 * list which is returned from invoking {@link #getCallCapablePhoneAccounts()}. The specific
381 * account returned depends on the following priorities:
382 * <ul>
383 * <li> If the user-selected default {@link PhoneAccount} supports the specified scheme, it will
384 * be returned.
385 * </li>
386 * <li> If there exists only one {@link PhoneAccount} that supports the specified scheme, it
387 * will be returned.
388 * </li>
389 * </ul>
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700390 * <p>
Santos Cordon91371dc02015-05-08 13:52:09 -0700391 * If no {@link PhoneAccount} fits the criteria above, this method will return {@code null}.
392 *
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700393 * @param uriScheme The URI scheme.
Santos Cordon91371dc02015-05-08 13:52:09 -0700394 * @return The {@link PhoneAccountHandle} corresponding to the account to be used.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700395 */
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700396 public PhoneAccountHandle getDefaultOutgoingPhoneAccount(String uriScheme) {
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700397 try {
398 if (isServiceConnected()) {
Svet Ganov16a16892015-04-16 10:32:04 -0700399 return getTelecomService().getDefaultOutgoingPhoneAccount(uriScheme,
400 mContext.getOpPackageName());
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700401 }
402 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700403 Log.e(TAG, "Error calling ITelecomService#getDefaultOutgoingPhoneAccount", e);
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700404 }
405 return null;
406 }
407
408 /**
Andrew Leed4abbfb2014-09-03 14:58:27 -0700409 * Return the {@link PhoneAccount} which is the user-chosen default for making outgoing phone
410 * calls. This {@code PhoneAccount} will always be a member of the list which is returned from
Nancy Chen210ef032014-09-15 17:58:42 -0700411 * calling {@link #getCallCapablePhoneAccounts()}
Santos Cordon91371dc02015-05-08 13:52:09 -0700412 * <p>
Andrew Leed4abbfb2014-09-03 14:58:27 -0700413 * Apps must be prepared for this method to return {@code null}, indicating that there currently
414 * exists no user-chosen default {@code PhoneAccount}.
415 *
416 * @return The user outgoing phone account selected by the user.
Jay Shrauner225ccad2015-04-15 15:51:15 -0700417 * @hide
Andrew Leed4abbfb2014-09-03 14:58:27 -0700418 */
419 public PhoneAccountHandle getUserSelectedOutgoingPhoneAccount() {
420 try {
421 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700422 return getTelecomService().getUserSelectedOutgoingPhoneAccount();
Andrew Leed4abbfb2014-09-03 14:58:27 -0700423 }
424 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700425 Log.e(TAG, "Error calling ITelecomService#getUserSelectedOutgoingPhoneAccount", e);
Andrew Leed4abbfb2014-09-03 14:58:27 -0700426 }
427 return null;
428 }
429
430 /**
Santos Cordon91371dc02015-05-08 13:52:09 -0700431 * Sets the user-chosen default for making outgoing phone calls.
Andrew Lee59cac3a2014-08-28 16:50:10 -0700432 * @hide
433 */
Andrew Leed4abbfb2014-09-03 14:58:27 -0700434 public void setUserSelectedOutgoingPhoneAccount(PhoneAccountHandle accountHandle) {
Andrew Lee59cac3a2014-08-28 16:50:10 -0700435 try {
436 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700437 getTelecomService().setUserSelectedOutgoingPhoneAccount(accountHandle);
Andrew Lee59cac3a2014-08-28 16:50:10 -0700438 }
439 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700440 Log.e(TAG, "Error calling ITelecomService#setUserSelectedOutgoingPhoneAccount");
Andrew Lee59cac3a2014-08-28 16:50:10 -0700441 }
442 }
443
444 /**
Andrew Lee59cac3a2014-08-28 16:50:10 -0700445 * Returns the current SIM call manager. Apps must be prepared for this method to return
446 * {@code null}, indicating that there currently exists no user-chosen default
447 * {@code PhoneAccount}.
Santos Cordon91371dc02015-05-08 13:52:09 -0700448 *
Andrew Lee59cac3a2014-08-28 16:50:10 -0700449 * @return The phone account handle of the current sim call manager.
Andrew Lee59cac3a2014-08-28 16:50:10 -0700450 */
451 public PhoneAccountHandle getSimCallManager() {
452 try {
453 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700454 return getTelecomService().getSimCallManager();
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#getSimCallManager");
Andrew Lee59cac3a2014-08-28 16:50:10 -0700458 }
459 return null;
460 }
461
462 /**
463 * Sets the SIM call manager to the specified phone account.
Santos Cordon91371dc02015-05-08 13:52:09 -0700464 *
Andrew Lee59cac3a2014-08-28 16:50:10 -0700465 * @param accountHandle The phone account handle of the account to set as the sim call manager.
466 * @hide
467 */
468 public void setSimCallManager(PhoneAccountHandle accountHandle) {
469 try {
470 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700471 getTelecomService().setSimCallManager(accountHandle);
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#setSimCallManager");
Andrew Lee59cac3a2014-08-28 16:50:10 -0700475 }
476 }
477
478 /**
479 * Returns the list of registered SIM call managers.
Santos Cordon91371dc02015-05-08 13:52:09 -0700480 *
Andrew Lee59cac3a2014-08-28 16:50:10 -0700481 * @return List of registered SIM call managers.
482 * @hide
483 */
484 public List<PhoneAccountHandle> getSimCallManagers() {
485 try {
486 if (isServiceConnected()) {
Svet Ganov16a16892015-04-16 10:32:04 -0700487 return getTelecomService().getSimCallManagers(mContext.getOpPackageName());
Andrew Lee59cac3a2014-08-28 16:50:10 -0700488 }
489 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700490 Log.e(TAG, "Error calling ITelecomService#getSimCallManagers");
Andrew Lee59cac3a2014-08-28 16:50:10 -0700491 }
492 return new ArrayList<>();
493 }
494
495 /**
Evan Charltoneb0a8d562014-09-04 12:03:34 -0700496 * Returns the current connection manager. Apps must be prepared for this method to return
497 * {@code null}, indicating that there currently exists no user-chosen default
498 * {@code PhoneAccount}.
499 *
500 * @return The phone account handle of the current connection manager.
Evan Charlton0e094d92014-11-08 15:49:16 -0800501 * @hide
Evan Charltoneb0a8d562014-09-04 12:03:34 -0700502 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800503 @SystemApi
Evan Charltoneb0a8d562014-09-04 12:03:34 -0700504 public PhoneAccountHandle getConnectionManager() {
505 return getSimCallManager();
506 }
507
508 /**
Nancy Chen210ef032014-09-15 17:58:42 -0700509 * Returns a list of the {@link PhoneAccountHandle}s which can be used to make and receive phone
510 * calls which support the specified URI scheme.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700511 * <P>
512 * For example, invoking with {@code "tel"} will find all {@link PhoneAccountHandle}s which
513 * support telephone calls (e.g. URIs such as {@code tel:555-555-1212}). Invoking with
514 * {@code "sip"} will find all {@link PhoneAccountHandle}s which support SIP calls (e.g. URIs
515 * such as {@code sip:example@sipexample.com}).
516 *
517 * @param uriScheme The URI scheme.
518 * @return A list of {@code PhoneAccountHandle} objects supporting the URI scheme.
Evan Charlton0e094d92014-11-08 15:49:16 -0800519 * @hide
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700520 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800521 @SystemApi
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700522 public List<PhoneAccountHandle> getPhoneAccountsSupportingScheme(String uriScheme) {
523 try {
524 if (isServiceConnected()) {
Svet Ganov16a16892015-04-16 10:32:04 -0700525 return getTelecomService().getPhoneAccountsSupportingScheme(uriScheme,
526 mContext.getOpPackageName());
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700527 }
528 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700529 Log.e(TAG, "Error calling ITelecomService#getPhoneAccountsSupportingScheme", e);
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700530 }
531 return new ArrayList<>();
532 }
533
Nancy Chen513c8922014-09-17 14:47:20 -0700534
535 /**
Santos Cordon91371dc02015-05-08 13:52:09 -0700536 * Returns a list of {@link PhoneAccountHandle}s which can be used to make and receive phone
537 * calls. The returned list includes only those accounts which have been explicitly enabled
538 * by the user.
Nancy Chen513c8922014-09-17 14:47:20 -0700539 *
540 * @see #EXTRA_PHONE_ACCOUNT_HANDLE
541 * @return A list of {@code PhoneAccountHandle} objects.
Nancy Chen513c8922014-09-17 14:47:20 -0700542 */
543 public List<PhoneAccountHandle> getCallCapablePhoneAccounts() {
Santos Cordon91371dc02015-05-08 13:52:09 -0700544 return getCallCapablePhoneAccounts(false);
545 }
546
547 /**
548 * Returns a list of {@link PhoneAccountHandle}s including those which have not been enabled
549 * by the user.
550 *
551 * @return A list of {@code PhoneAccountHandle} objects.
552 * @hide
553 */
554 public List<PhoneAccountHandle> getCallCapablePhoneAccounts(boolean includeDisabledAccounts) {
Nancy Chen513c8922014-09-17 14:47:20 -0700555 try {
556 if (isServiceConnected()) {
Santos Cordon91371dc02015-05-08 13:52:09 -0700557 return getTelecomService().getCallCapablePhoneAccounts(
558 includeDisabledAccounts, mContext.getOpPackageName());
Nancy Chen513c8922014-09-17 14:47:20 -0700559 }
560 } catch (RemoteException e) {
Santos Cordon91371dc02015-05-08 13:52:09 -0700561 Log.e(TAG, "Error calling ITelecomService#getCallCapablePhoneAccounts(" +
562 includeDisabledAccounts + ")", e);
Nancy Chen513c8922014-09-17 14:47:20 -0700563 }
564 return new ArrayList<>();
565 }
566
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700567 /**
Nancy Chen513c8922014-09-17 14:47:20 -0700568 * Returns a list of all {@link PhoneAccount}s registered for the calling package.
569 *
570 * @return A list of {@code PhoneAccountHandle} objects.
Evan Charlton0e094d92014-11-08 15:49:16 -0800571 * @hide
Nancy Chen513c8922014-09-17 14:47:20 -0700572 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800573 @SystemApi
Nancy Chen513c8922014-09-17 14:47:20 -0700574 public List<PhoneAccountHandle> getPhoneAccountsForPackage() {
575 try {
576 if (isServiceConnected()) {
577 return getTelecomService().getPhoneAccountsForPackage(mContext.getPackageName());
578 }
579 } catch (RemoteException e) {
580 Log.e(TAG, "Error calling ITelecomService#getPhoneAccountsForPackage", e);
581 }
582 return null;
583 }
584
585 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700586 * Return the {@link PhoneAccount} for a specified {@link PhoneAccountHandle}. Object includes
587 * resources which can be used in a user interface.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700588 *
Evan Charlton6eb262c2014-07-19 18:18:19 -0700589 * @param account The {@link PhoneAccountHandle}.
Evan Charlton8c8a0622014-07-20 12:31:00 -0700590 * @return The {@link PhoneAccount} object.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700591 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700592 public PhoneAccount getPhoneAccount(PhoneAccountHandle account) {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700593 try {
594 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700595 return getTelecomService().getPhoneAccount(account);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700596 }
597 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700598 Log.e(TAG, "Error calling ITelecomService#getPhoneAccount", e);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700599 }
600 return null;
601 }
602
603 /**
Nancy Chen210ef032014-09-15 17:58:42 -0700604 * Returns a count of all {@link PhoneAccount}s.
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700605 *
Nancy Chen210ef032014-09-15 17:58:42 -0700606 * @return The count of {@link PhoneAccount}s.
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700607 * @hide
608 */
609 @SystemApi
610 public int getAllPhoneAccountsCount() {
611 try {
612 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700613 return getTelecomService().getAllPhoneAccountsCount();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700614 }
615 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700616 Log.e(TAG, "Error calling ITelecomService#getAllPhoneAccountsCount", e);
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700617 }
618 return 0;
619 }
620
621 /**
622 * Returns a list of all {@link PhoneAccount}s.
623 *
624 * @return All {@link PhoneAccount}s.
625 * @hide
626 */
627 @SystemApi
628 public List<PhoneAccount> getAllPhoneAccounts() {
629 try {
630 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700631 return getTelecomService().getAllPhoneAccounts();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700632 }
633 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700634 Log.e(TAG, "Error calling ITelecomService#getAllPhoneAccounts", e);
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700635 }
636 return Collections.EMPTY_LIST;
637 }
638
639 /**
640 * Returns a list of all {@link PhoneAccountHandle}s.
641 *
642 * @return All {@link PhoneAccountHandle}s.
643 * @hide
644 */
645 @SystemApi
646 public List<PhoneAccountHandle> getAllPhoneAccountHandles() {
647 try {
648 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700649 return getTelecomService().getAllPhoneAccountHandles();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700650 }
651 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700652 Log.e(TAG, "Error calling ITelecomService#getAllPhoneAccountHandles", e);
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700653 }
654 return Collections.EMPTY_LIST;
655 }
656
657 /**
Santos Cordond9e614f2014-10-28 13:10:36 -0700658 * Register a {@link PhoneAccount} for use by the system. When registering
659 * {@link PhoneAccount}s, existing registrations will be overwritten if the
660 * {@link PhoneAccountHandle} matches that of a {@link PhoneAccount} which is already
661 * registered. Once registered, the {@link PhoneAccount} is listed to the user as an option
662 * when placing calls. The user may still need to enable the {@link PhoneAccount} within
663 * the phone app settings before the account is usable.
664 * <p>
665 * A {@link SecurityException} will be thrown if an app tries to register a
666 * {@link PhoneAccountHandle} where the package name specified within
667 * {@link PhoneAccountHandle#getComponentName()} does not match the package name of the app.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700668 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700669 * @param account The complete {@link PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700670 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700671 public void registerPhoneAccount(PhoneAccount account) {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700672 try {
673 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700674 getTelecomService().registerPhoneAccount(account);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700675 }
676 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700677 Log.e(TAG, "Error calling ITelecomService#registerPhoneAccount", e);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700678 }
679 }
680
681 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700682 * Remove a {@link PhoneAccount} registration from the system.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700683 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700684 * @param accountHandle A {@link PhoneAccountHandle} for the {@link PhoneAccount} to unregister.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700685 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700686 public void unregisterPhoneAccount(PhoneAccountHandle accountHandle) {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700687 try {
688 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700689 getTelecomService().unregisterPhoneAccount(accountHandle);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700690 }
691 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700692 Log.e(TAG, "Error calling ITelecomService#unregisterPhoneAccount", e);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700693 }
694 }
695
696 /**
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700697 * Remove all Accounts that belong to the calling package from the system.
Evan Charlton0e094d92014-11-08 15:49:16 -0800698 * @hide
Ihab Awad807fe0a2014-07-09 12:30:52 -0700699 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800700 @SystemApi
Yorke Lee06044272015-04-14 15:16:59 -0700701 public void clearPhoneAccounts() {
702 clearAccounts();
703 }
704 /**
705 * Remove all Accounts that belong to the calling package from the system.
706 * @deprecated Use {@link #clearPhoneAccounts()} instead.
707 * @hide
708 */
709 @SystemApi
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700710 public void clearAccounts() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700711 try {
712 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700713 getTelecomService().clearAccounts(mContext.getPackageName());
Ihab Awad807fe0a2014-07-09 12:30:52 -0700714 }
715 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700716 Log.e(TAG, "Error calling ITelecomService#clearAccounts", e);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700717 }
718 }
719
720 /**
Anthony Lee67279262014-10-27 11:28:40 -0700721 * Remove all Accounts that belong to the specified package from the system.
722 * @hide
723 */
724 public void clearAccountsForPackage(String packageName) {
725 try {
726 if (isServiceConnected() && !TextUtils.isEmpty(packageName)) {
727 getTelecomService().clearAccounts(packageName);
728 }
729 } catch (RemoteException e) {
Nancy Chen5cf27842015-01-24 23:30:27 -0800730 Log.e(TAG, "Error calling ITelecomService#clearAccountsForPackage", e);
Anthony Lee67279262014-10-27 11:28:40 -0700731 }
732 }
733
Yorke Lee1011f482015-04-23 15:58:27 -0700734
Anthony Lee67279262014-10-27 11:28:40 -0700735 /**
Yorke Lee1011f482015-04-23 15:58:27 -0700736 * @deprecated - Use {@link TelecomManager#getDefaultDialerPackage} to directly access
737 * the default dialer's package name instead.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700738 * @hide
739 */
Santos Cordon6c7a3882014-06-25 15:30:08 -0700740 @SystemApi
741 public ComponentName getDefaultPhoneApp() {
742 try {
Santos Cordon9eb45932014-06-27 12:28:43 -0700743 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700744 return getTelecomService().getDefaultPhoneApp();
Santos Cordon9eb45932014-06-27 12:28:43 -0700745 }
Santos Cordon6c7a3882014-06-25 15:30:08 -0700746 } catch (RemoteException e) {
747 Log.e(TAG, "RemoteException attempting to get the default phone app.", e);
748 }
749 return null;
750 }
751
Santos Cordon9eb45932014-06-27 12:28:43 -0700752 /**
Yorke Lee1011f482015-04-23 15:58:27 -0700753 * Used to determine the currently selected default dialer package.
754 *
755 * @return package name for the default dialer package or null if no package has been
756 * selected as the default dialer.
757 */
758 public String getDefaultDialerPackage() {
759 try {
760 if (isServiceConnected()) {
761 return getTelecomService().getDefaultDialerPackage();
762 }
763 } catch (RemoteException e) {
764 Log.e(TAG, "RemoteException attempting to get the default dialer package name.", e);
765 }
766 return null;
767 }
768
769 /**
770 * Used to determine the dialer package that is preloaded on the system partition.
771 *
772 * @return package name for the system dialer package or null if no system dialer is preloaded.
773 * @hide
774 */
775 public String getSystemDialerPackage() {
776 try {
777 if (isServiceConnected()) {
778 return getTelecomService().getSystemDialerPackage();
779 }
780 } catch (RemoteException e) {
781 Log.e(TAG, "RemoteException attempting to get the system dialer package name.", e);
782 }
783 return null;
784 }
785
786 /**
Nancy Chen443e5012014-10-15 15:48:21 -0700787 * Return whether a given phone number is the configured voicemail number for a
788 * particular phone account.
789 *
790 * @param accountHandle The handle for the account to check the voicemail number against
791 * @param number The number to look up.
Nancy Chen443e5012014-10-15 15:48:21 -0700792 */
Nancy Chen443e5012014-10-15 15:48:21 -0700793 public boolean isVoiceMailNumber(PhoneAccountHandle accountHandle, String number) {
794 try {
795 if (isServiceConnected()) {
Svet Ganov16a16892015-04-16 10:32:04 -0700796 return getTelecomService().isVoiceMailNumber(accountHandle, number,
797 mContext.getOpPackageName());
Nancy Chen443e5012014-10-15 15:48:21 -0700798 }
799 } catch (RemoteException e) {
Nancy Chen5cf27842015-01-24 23:30:27 -0800800 Log.e(TAG, "RemoteException calling ITelecomService#isVoiceMailNumber.", e);
Nancy Chen443e5012014-10-15 15:48:21 -0700801 }
802 return false;
803 }
804
805 /**
Yorke Lee49e2d462015-04-15 16:14:22 -0700806 * Return the voicemail number for a given phone account.
Nancy Chen8c066f7c2014-12-03 15:18:08 -0800807 *
Yorke Lee49e2d462015-04-15 16:14:22 -0700808 * @param accountHandle The handle for the phone account.
809 * @return The voicemail number for the phone account, and {@code null} if one has not been
810 * configured.
Nancy Chen8c066f7c2014-12-03 15:18:08 -0800811 */
Yorke Lee49e2d462015-04-15 16:14:22 -0700812 public String getVoiceMailNumber(PhoneAccountHandle accountHandle) {
Nancy Chen8c066f7c2014-12-03 15:18:08 -0800813 try {
814 if (isServiceConnected()) {
Svet Ganov16a16892015-04-16 10:32:04 -0700815 return getTelecomService().getVoiceMailNumber(accountHandle,
816 mContext.getOpPackageName());
Nancy Chen8c066f7c2014-12-03 15:18:08 -0800817 }
818 } catch (RemoteException e) {
Nancy Chen5cf27842015-01-24 23:30:27 -0800819 Log.e(TAG, "RemoteException calling ITelecomService#hasVoiceMailNumber.", e);
Nancy Chen8c066f7c2014-12-03 15:18:08 -0800820 }
Yorke Lee49e2d462015-04-15 16:14:22 -0700821 return null;
Nancy Chen8c066f7c2014-12-03 15:18:08 -0800822 }
823
824 /**
Nancy Chen5cf27842015-01-24 23:30:27 -0800825 * Return the line 1 phone number for given phone account.
826 *
827 * @param accountHandle The handle for the account retrieve a number for.
828 * @return A string representation of the line 1 phone number.
Nancy Chen5cf27842015-01-24 23:30:27 -0800829 */
Nancy Chen5cf27842015-01-24 23:30:27 -0800830 public String getLine1Number(PhoneAccountHandle accountHandle) {
831 try {
832 if (isServiceConnected()) {
Svet Ganov16a16892015-04-16 10:32:04 -0700833 return getTelecomService().getLine1Number(accountHandle,
834 mContext.getOpPackageName());
Nancy Chen5cf27842015-01-24 23:30:27 -0800835 }
836 } catch (RemoteException e) {
837 Log.e(TAG, "RemoteException calling ITelecomService#getLine1Number.", e);
838 }
839 return null;
840 }
841
842 /**
Santos Cordon9eb45932014-06-27 12:28:43 -0700843 * Returns whether there is an ongoing phone call (can be in dialing, ringing, active or holding
844 * states).
Nancy Chen0eb1e402014-08-21 22:52:29 -0700845 * <p>
846 * Requires permission: {@link android.Manifest.permission#READ_PHONE_STATE}
847 * </p>
Santos Cordon9eb45932014-06-27 12:28:43 -0700848 */
Nancy Chen0eb1e402014-08-21 22:52:29 -0700849 public boolean isInCall() {
Santos Cordon9eb45932014-06-27 12:28:43 -0700850 try {
851 if (isServiceConnected()) {
Svet Ganov16a16892015-04-16 10:32:04 -0700852 return getTelecomService().isInCall(mContext.getOpPackageName());
Santos Cordon9eb45932014-06-27 12:28:43 -0700853 }
854 } catch (RemoteException e) {
Yorke Lee2ae312e2014-09-12 17:58:48 -0700855 Log.e(TAG, "RemoteException calling isInCall().", e);
Santos Cordon9eb45932014-06-27 12:28:43 -0700856 }
857 return false;
858 }
859
860 /**
Yorke Lee2ae312e2014-09-12 17:58:48 -0700861 * Returns one of the following constants that represents the current state of Telecom:
862 *
863 * {@link TelephonyManager#CALL_STATE_RINGING}
864 * {@link TelephonyManager#CALL_STATE_OFFHOOK}
865 * {@link TelephonyManager#CALL_STATE_IDLE}
Yorke Lee7c72c2d2014-10-28 14:12:02 -0700866 *
867 * Note that this API does not require the
868 * {@link android.Manifest.permission#READ_PHONE_STATE} permission. This is intentional, to
869 * preserve the behavior of {@link TelephonyManager#getCallState()}, which also did not require
870 * the permission.
Yorke Lee2ae312e2014-09-12 17:58:48 -0700871 * @hide
872 */
873 @SystemApi
874 public int getCallState() {
875 try {
876 if (isServiceConnected()) {
877 return getTelecomService().getCallState();
878 }
879 } catch (RemoteException e) {
880 Log.d(TAG, "RemoteException calling getCallState().", e);
881 }
882 return TelephonyManager.CALL_STATE_IDLE;
883 }
884
885 /**
Santos Cordon9eb45932014-06-27 12:28:43 -0700886 * Returns whether there currently exists is a ringing incoming-call.
887 *
888 * @hide
889 */
890 @SystemApi
891 public boolean isRinging() {
892 try {
893 if (isServiceConnected()) {
Svet Ganov16a16892015-04-16 10:32:04 -0700894 return getTelecomService().isRinging(mContext.getOpPackageName());
Santos Cordon9eb45932014-06-27 12:28:43 -0700895 }
896 } catch (RemoteException e) {
897 Log.e(TAG, "RemoteException attempting to get ringing state of phone app.", e);
898 }
899 return false;
900 }
901
902 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700903 * Ends an ongoing call.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700904 * TODO: L-release - need to convert all invocations of ITelecomService#endCall to use this
Santos Cordon96efb482014-07-19 14:57:05 -0700905 * method (clockwork & gearhead).
Santos Cordon9eb45932014-06-27 12:28:43 -0700906 * @hide
907 */
908 @SystemApi
909 public boolean endCall() {
910 try {
911 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700912 return getTelecomService().endCall();
Santos Cordon9eb45932014-06-27 12:28:43 -0700913 }
914 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700915 Log.e(TAG, "Error calling ITelecomService#endCall", e);
Santos Cordon9eb45932014-06-27 12:28:43 -0700916 }
917 return false;
918 }
919
920 /**
921 * If there is a ringing incoming call, this method accepts the call on behalf of the user.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700922 * TODO: L-release - need to convert all invocation of ITelecmmService#answerRingingCall to use
Santos Cordon96efb482014-07-19 14:57:05 -0700923 * this method (clockwork & gearhead).
Santos Cordon9eb45932014-06-27 12:28:43 -0700924 *
925 * @hide
926 */
927 @SystemApi
928 public void acceptRingingCall() {
929 try {
930 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700931 getTelecomService().acceptRingingCall();
Santos Cordon9eb45932014-06-27 12:28:43 -0700932 }
933 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700934 Log.e(TAG, "Error calling ITelecomService#acceptRingingCall", e);
Santos Cordon9eb45932014-06-27 12:28:43 -0700935 }
936 }
937
938 /**
939 * Silences the ringer if a ringing call exists.
Santos Cordon9eb45932014-06-27 12:28:43 -0700940 */
Santos Cordon9eb45932014-06-27 12:28:43 -0700941 public void silenceRinger() {
942 try {
943 if (isServiceConnected()) {
Yorke Leef1a349b2015-04-29 16:16:50 -0700944 getTelecomService().silenceRinger(mContext.getOpPackageName());
Santos Cordon9eb45932014-06-27 12:28:43 -0700945 }
946 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700947 Log.e(TAG, "Error calling ITelecomService#silenceRinger", e);
Santos Cordon9eb45932014-06-27 12:28:43 -0700948 }
949 }
950
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700951 /**
952 * Returns whether TTY is supported on this device.
953 *
954 * @hide
955 */
956 @SystemApi
957 public boolean isTtySupported() {
958 try {
959 if (isServiceConnected()) {
Svet Ganov16a16892015-04-16 10:32:04 -0700960 return getTelecomService().isTtySupported(mContext.getOpPackageName());
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700961 }
962 } catch (RemoteException e) {
963 Log.e(TAG, "RemoteException attempting to get TTY supported state.", e);
964 }
965 return false;
966 }
967
968 /**
969 * 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 -0700970 * settings and have a wired headset plugged in.
971 * Valid modes are:
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700972 * - {@link TelecomManager#TTY_MODE_OFF}
973 * - {@link TelecomManager#TTY_MODE_FULL}
974 * - {@link TelecomManager#TTY_MODE_HCO}
975 * - {@link TelecomManager#TTY_MODE_VCO}
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700976 * @hide
977 */
978 public int getCurrentTtyMode() {
979 try {
980 if (isServiceConnected()) {
Svet Ganov16a16892015-04-16 10:32:04 -0700981 return getTelecomService().getCurrentTtyMode(mContext.getOpPackageName());
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700982 }
983 } catch (RemoteException e) {
984 Log.e(TAG, "RemoteException attempting to get the current TTY mode.", e);
985 }
Evan Charlton10197192014-07-19 15:00:29 -0700986 return TTY_MODE_OFF;
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700987 }
988
Santos Cordon96efb482014-07-19 14:57:05 -0700989 /**
990 * Registers a new incoming call. A {@link ConnectionService} should invoke this method when it
991 * has an incoming call. The specified {@link PhoneAccountHandle} must have been registered
Nancy Chen210ef032014-09-15 17:58:42 -0700992 * with {@link #registerPhoneAccount}. Once invoked, this method will cause the system to bind
993 * to the {@link ConnectionService} associated with the {@link PhoneAccountHandle} and request
Santos Cordon96efb482014-07-19 14:57:05 -0700994 * additional information about the call (See
995 * {@link ConnectionService#onCreateIncomingConnection}) before starting the incoming call UI.
996 *
997 * @param phoneAccount A {@link PhoneAccountHandle} registered with
998 * {@link #registerPhoneAccount}.
999 * @param extras A bundle that will be passed through to
1000 * {@link ConnectionService#onCreateIncomingConnection}.
1001 */
1002 public void addNewIncomingCall(PhoneAccountHandle phoneAccount, Bundle extras) {
1003 try {
1004 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001005 getTelecomService().addNewIncomingCall(
Santos Cordon96efb482014-07-19 14:57:05 -07001006 phoneAccount, extras == null ? new Bundle() : extras);
1007 }
1008 } catch (RemoteException e) {
1009 Log.e(TAG, "RemoteException adding a new incoming call: " + phoneAccount, e);
1010 }
1011 }
1012
Nancy Chen0eb1e402014-08-21 22:52:29 -07001013 /**
Yorke Leec3cf9822014-10-02 09:38:39 -07001014 * Registers a new unknown call with Telecom. This can only be called by the system Telephony
1015 * service. This is invoked when Telephony detects a new unknown connection that was neither
1016 * a new incoming call, nor an user-initiated outgoing call.
1017 *
1018 * @param phoneAccount A {@link PhoneAccountHandle} registered with
1019 * {@link #registerPhoneAccount}.
1020 * @param extras A bundle that will be passed through to
1021 * {@link ConnectionService#onCreateIncomingConnection}.
1022 * @hide
1023 */
1024 @SystemApi
1025 public void addNewUnknownCall(PhoneAccountHandle phoneAccount, Bundle extras) {
1026 try {
1027 if (isServiceConnected()) {
1028 getTelecomService().addNewUnknownCall(
1029 phoneAccount, extras == null ? new Bundle() : extras);
1030 }
1031 } catch (RemoteException e) {
1032 Log.e(TAG, "RemoteException adding a new unknown call: " + phoneAccount, e);
1033 }
1034 }
1035
1036 /**
Nancy Chen0eb1e402014-08-21 22:52:29 -07001037 * Processes the specified dial string as an MMI code.
1038 * MMI codes are any sequence of characters entered into the dialpad that contain a "*" or "#".
1039 * Some of these sequences launch special behavior through handled by Telephony.
Nancy Chen95e8a672014-10-16 18:38:21 -07001040 * This method uses the default subscription.
Nancy Chen0eb1e402014-08-21 22:52:29 -07001041 * <p>
1042 * Requires that the method-caller be set as the system dialer app.
1043 * </p>
1044 *
1045 * @param dialString The digits to dial.
1046 * @return True if the digits were processed as an MMI code, false otherwise.
1047 */
1048 public boolean handleMmi(String dialString) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001049 ITelecomService service = getTelecomService();
Nancy Chen0eb1e402014-08-21 22:52:29 -07001050 if (service != null) {
1051 try {
Yorke Leef1a349b2015-04-29 16:16:50 -07001052 return service.handlePinMmi(dialString, mContext.getOpPackageName());
Nancy Chen0eb1e402014-08-21 22:52:29 -07001053 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001054 Log.e(TAG, "Error calling ITelecomService#handlePinMmi", e);
Nancy Chen0eb1e402014-08-21 22:52:29 -07001055 }
1056 }
1057 return false;
1058 }
1059
1060 /**
Nancy Chen95e8a672014-10-16 18:38:21 -07001061 * Processes the specified dial string as an MMI code.
1062 * MMI codes are any sequence of characters entered into the dialpad that contain a "*" or "#".
1063 * Some of these sequences launch special behavior through handled by Telephony.
1064 * <p>
1065 * Requires that the method-caller be set as the system dialer app.
1066 * </p>
1067 *
1068 * @param accountHandle The handle for the account the MMI code should apply to.
1069 * @param dialString The digits to dial.
1070 * @return True if the digits were processed as an MMI code, false otherwise.
Nancy Chen95e8a672014-10-16 18:38:21 -07001071 */
Yorke Lee06044272015-04-14 15:16:59 -07001072 public boolean handleMmi(String dialString, PhoneAccountHandle accountHandle) {
Nancy Chen95e8a672014-10-16 18:38:21 -07001073 ITelecomService service = getTelecomService();
1074 if (service != null) {
1075 try {
Yorke Leef1a349b2015-04-29 16:16:50 -07001076 return service.handlePinMmiForPhoneAccount(accountHandle, dialString,
1077 mContext.getOpPackageName());
Nancy Chen95e8a672014-10-16 18:38:21 -07001078 } catch (RemoteException e) {
1079 Log.e(TAG, "Error calling ITelecomService#handlePinMmi", e);
1080 }
1081 }
1082 return false;
1083 }
1084
1085 /**
Nancy Chenb2299c12014-10-29 18:22:11 -07001086 * @param accountHandle The handle for the account to derive an adn query URI for or
1087 * {@code null} to return a URI which will use the default account.
1088 * @return The URI (with the content:// scheme) specific to the specified {@link PhoneAccount}
1089 * for the the content retrieve.
1090 */
1091 public Uri getAdnUriForPhoneAccount(PhoneAccountHandle accountHandle) {
1092 ITelecomService service = getTelecomService();
1093 if (service != null && accountHandle != null) {
1094 try {
Yorke Leef1a349b2015-04-29 16:16:50 -07001095 return service.getAdnUriForPhoneAccount(accountHandle, mContext.getOpPackageName());
Nancy Chenb2299c12014-10-29 18:22:11 -07001096 } catch (RemoteException e) {
1097 Log.e(TAG, "Error calling ITelecomService#getAdnUriForPhoneAccount", e);
1098 }
1099 }
1100 return Uri.parse("content://icc/adn");
1101 }
1102
1103 /**
Nancy Chen0eb1e402014-08-21 22:52:29 -07001104 * Removes the missed-call notification if one is present.
1105 * <p>
1106 * Requires that the method-caller be set as the system dialer app.
1107 * </p>
1108 */
1109 public void cancelMissedCallsNotification() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001110 ITelecomService service = getTelecomService();
Nancy Chen0eb1e402014-08-21 22:52:29 -07001111 if (service != null) {
1112 try {
Yorke Leef1a349b2015-04-29 16:16:50 -07001113 service.cancelMissedCallsNotification(mContext.getOpPackageName());
Nancy Chen0eb1e402014-08-21 22:52:29 -07001114 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001115 Log.e(TAG, "Error calling ITelecomService#cancelMissedCallsNotification", e);
Nancy Chen0eb1e402014-08-21 22:52:29 -07001116 }
1117 }
1118 }
1119
1120 /**
1121 * Brings the in-call screen to the foreground if there is an ongoing call. If there is
1122 * currently no ongoing call, then this method does nothing.
1123 * <p>
1124 * Requires that the method-caller be set as the system dialer app or have the
1125 * {@link android.Manifest.permission#READ_PHONE_STATE} permission.
1126 * </p>
1127 *
1128 * @param showDialpad Brings up the in-call dialpad as part of showing the in-call screen.
1129 */
1130 public void showInCallScreen(boolean showDialpad) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001131 ITelecomService service = getTelecomService();
Nancy Chen0eb1e402014-08-21 22:52:29 -07001132 if (service != null) {
1133 try {
Svet Ganov16a16892015-04-16 10:32:04 -07001134 service.showInCallScreen(showDialpad, mContext.getOpPackageName());
Nancy Chen0eb1e402014-08-21 22:52:29 -07001135 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001136 Log.e(TAG, "Error calling ITelecomService#showCallScreen", e);
Nancy Chen0eb1e402014-08-21 22:52:29 -07001137 }
1138 }
1139 }
1140
Yorke Lee3e56ba12015-04-23 12:32:36 -07001141 /**
1142 * Places a new outgoing call to the provided address using the system telecom service with
1143 * the specified extras.
1144 *
1145 * This method is equivalent to placing an outgoing call using {@link Intent#ACTION_CALL},
1146 * except that the outgoing call will always be sent via the system telecom service. If
1147 * method-caller is either the user selected default dialer app or preloaded system dialer
1148 * app, then emergency calls will also be allowed.
1149 *
1150 * Requires permission: {@link android.Manifest.permission#CALL_PHONE}
1151 *
1152 * Usage example:
1153 * <pre>
1154 * Uri uri = Uri.fromParts("tel", "12345", null);
1155 * Bundle extras = new Bundle();
1156 * extras.putBoolean(TelecomManager.EXTRA_START_CALL_WITH_SPEAKERPHONE, true);
1157 * telecomManager.placeCall(uri, extras);
1158 * </pre>
1159 *
1160 * @param address The address to make the call to.
1161 * @param extras Bundle of extras to use with the call.
1162 */
1163 public void placeCall(Uri address, Bundle extras) {
1164 ITelecomService service = getTelecomService();
1165 if (service != null) {
Yorke Leea5d5c1d2015-05-05 16:25:55 -07001166 if (address == null) {
1167 Log.w(TAG, "Cannot place call to empty address.");
1168 }
Yorke Lee3e56ba12015-04-23 12:32:36 -07001169 try {
Yorke Leea5d5c1d2015-05-05 16:25:55 -07001170 service.placeCall(address, extras == null ? new Bundle() : extras,
1171 mContext.getOpPackageName());
Yorke Lee3e56ba12015-04-23 12:32:36 -07001172 } catch (RemoteException e) {
1173 Log.e(TAG, "Error calling ITelecomService#placeCall", e);
1174 }
1175 }
1176 }
1177
Santos Cordon91371dc02015-05-08 13:52:09 -07001178 /**
1179 * Enables and disables specified phone account.
1180 *
1181 * @param handle Handle to the phone account.
1182 * @param isEnabled Enable state of the phone account.
1183 * @hide
1184 */
1185 @SystemApi
1186 public void enablePhoneAccount(PhoneAccountHandle handle, boolean isEnabled) {
1187 ITelecomService service = getTelecomService();
1188 if (service != null) {
1189 try {
1190 service.enablePhoneAccount(handle, isEnabled);
1191 } catch (RemoteException e) {
1192 Log.e(TAG, "Error enablePhoneAbbount", e);
1193 }
1194 }
1195 }
1196
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001197 private ITelecomService getTelecomService() {
1198 return ITelecomService.Stub.asInterface(ServiceManager.getService(Context.TELECOM_SERVICE));
Santos Cordon6c7a3882014-06-25 15:30:08 -07001199 }
Santos Cordon9eb45932014-06-27 12:28:43 -07001200
1201 private boolean isServiceConnected() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001202 boolean isConnected = getTelecomService() != null;
Santos Cordon9eb45932014-06-27 12:28:43 -07001203 if (!isConnected) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001204 Log.w(TAG, "Telecom Service not found.");
Santos Cordon9eb45932014-06-27 12:28:43 -07001205 }
1206 return isConnected;
1207 }
Evan Charlton235c1592014-09-05 15:41:23 +00001208}