blob: 60b9cb9f7aa7e67e13afe88c5a753e9a0f12dab3 [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;
Nancy Chenb2299c12014-10-29 18:22:11 -070020import android.net.Uri;
Santos Cordon96efb482014-07-19 14:57:05 -070021import android.os.Bundle;
Santos Cordon6c7a3882014-06-25 15:30:08 -070022import android.os.RemoteException;
23import android.os.ServiceManager;
Yorke Lee2ae312e2014-09-12 17:58:48 -070024import android.telephony.TelephonyManager;
Anthony Lee67279262014-10-27 11:28:40 -070025import android.text.TextUtils;
Santos Cordon6c7a3882014-06-25 15:30:08 -070026import android.util.Log;
Yorke Leeb4ce1432014-06-09 13:53:23 -070027
Tyler Gunnef9f6f92014-09-12 22:16:17 -070028import com.android.internal.telecom.ITelecomService;
Yorke Leeb4ce1432014-06-09 13:53:23 -070029
Jay Shrauner7746a942014-08-26 12:15:15 -070030import java.util.ArrayList;
Tyler Gunna1ed7d12014-09-08 09:52:22 -070031import java.util.Collections;
Ihab Awad807fe0a2014-07-09 12:30:52 -070032import java.util.List;
33
Yorke Leeb4ce1432014-06-09 13:53:23 -070034/**
Santos Cordond9e614f2014-10-28 13:10:36 -070035 * Provides access to information about active calls and registration/call-management functionality.
Evan Charlton0e094d92014-11-08 15:49:16 -080036 * Apps can use methods in this class to determine the current call state.
Santos Cordond9e614f2014-10-28 13:10:36 -070037 * <p>
38 * Apps do not instantiate this class directly; instead, they retrieve a reference to an instance
39 * through {@link Context#getSystemService Context.getSystemService(Context.TELECOM_SERVICE)}.
40 * <p>
41 * Note that access to some telecom information is permission-protected. Your app cannot access the
42 * protected information or gain access to protected functionality unless it has the appropriate
43 * permissions declared in its manifest file. Where permissions apply, they are noted in the method
44 * descriptions.
Yorke Leeb4ce1432014-06-09 13:53:23 -070045 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -070046public class TelecomManager {
Ihab Awad807fe0a2014-07-09 12:30:52 -070047
Evan Charlton10197192014-07-19 15:00:29 -070048 /**
Santos Cordon96efb482014-07-19 14:57:05 -070049 * Activity action: Starts the UI for handing an incoming call. This intent starts the in-call
Tyler Gunnef9f6f92014-09-12 22:16:17 -070050 * UI by notifying the Telecom system that an incoming call exists for a specific call service
51 * (see {@link android.telecom.ConnectionService}). Telecom reads the Intent extras to find
52 * and bind to the appropriate {@link android.telecom.ConnectionService} which Telecom will
Santos Cordon96efb482014-07-19 14:57:05 -070053 * ultimately use to control and get information about the call.
54 * <p>
55 * Input: get*Extra field {@link #EXTRA_PHONE_ACCOUNT_HANDLE} contains the component name of the
Tyler Gunnef9f6f92014-09-12 22:16:17 -070056 * {@link android.telecom.ConnectionService} that Telecom should bind to. Telecom will then
Evan Charlton10197192014-07-19 15:00:29 -070057 * ask the connection service for more information about the call prior to showing any UI.
Evan Charlton10197192014-07-19 15:00:29 -070058 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -070059 public static final String ACTION_INCOMING_CALL = "android.telecom.action.INCOMING_CALL";
Evan Charlton10197192014-07-19 15:00:29 -070060
61 /**
Yorke Leec3cf9822014-10-02 09:38:39 -070062 * Similar to {@link #ACTION_INCOMING_CALL}, but is used only by Telephony to add a new
63 * sim-initiated MO call for carrier testing.
64 * @hide
65 */
66 public static final String ACTION_NEW_UNKNOWN_CALL = "android.telecom.action.NEW_UNKNOWN_CALL";
67
68 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -070069 * The {@link android.content.Intent} action used to configure a
Tyler Gunnef9f6f92014-09-12 22:16:17 -070070 * {@link android.telecom.ConnectionService}.
Evan Charlton0e094d92014-11-08 15:49:16 -080071 * @hide
Evan Charlton10197192014-07-19 15:00:29 -070072 */
Evan Charlton0e094d92014-11-08 15:49:16 -080073 @SystemApi
Evan Charlton10197192014-07-19 15:00:29 -070074 public static final String ACTION_CONNECTION_SERVICE_CONFIGURE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -070075 "android.telecom.action.CONNECTION_SERVICE_CONFIGURE";
Evan Charlton10197192014-07-19 15:00:29 -070076
77 /**
Andrew Lee873cfbf2015-02-26 15:22:00 -080078 * The {@link android.content.Intent} action used to show the call accessibility settings page.
79 */
80 public static final String ACTION_SHOW_CALL_ACCESSIBILITY_SETTINGS =
81 "android.telecom.action.SHOW_CALL_ACCESSIBILITY_SETTINGS";
82
83 /**
Yorke Lee3818a8922014-07-21 15:57:17 -070084 * The {@link android.content.Intent} action used to show the call settings page.
85 */
86 public static final String ACTION_SHOW_CALL_SETTINGS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -070087 "android.telecom.action.SHOW_CALL_SETTINGS";
Yorke Lee3818a8922014-07-21 15:57:17 -070088
89 /**
Andrew Lee866080f2015-02-19 12:05:33 -080090 * The {@link android.content.Intent} action used to show the respond via SMS settings page.
91 */
92 public static final String ACTION_SHOW_RESPOND_VIA_SMS_SETTINGS =
93 "android.telecom.action.SHOW_RESPOND_VIA_SMS_SETTINGS";
94
95 /**
Evan Charlton6d8604f2014-09-04 12:38:17 -070096 * The {@link android.content.Intent} action used to show the settings page used to configure
97 * {@link PhoneAccount} preferences.
98 */
99 public static final String ACTION_CHANGE_PHONE_ACCOUNTS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700100 "android.telecom.action.CHANGE_PHONE_ACCOUNTS";
Evan Charlton6d8604f2014-09-04 12:38:17 -0700101
102 /**
Santos Cordonc66f3ba2015-02-27 15:22:07 -0800103 * The {@link android.content.Intent} action used indicate that a new phone account was
104 * just registered.
105 * @hide
106 */
107 @SystemApi
108 public static final String ACTION_PHONE_ACCOUNT_REGISTERED =
109 "android.telecom.action.PHONE_ACCOUNT_REGISTERED";
110
111 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700112 * Optional extra for {@link android.content.Intent#ACTION_CALL} containing a boolean that
113 * determines whether the speakerphone should be automatically turned on for an outgoing call.
Evan Charlton10197192014-07-19 15:00:29 -0700114 */
115 public static final String EXTRA_START_CALL_WITH_SPEAKERPHONE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700116 "android.telecom.extra.START_CALL_WITH_SPEAKERPHONE";
Evan Charlton10197192014-07-19 15:00:29 -0700117
118 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700119 * Optional extra for {@link android.content.Intent#ACTION_CALL} containing an integer that
120 * determines the desired video state for an outgoing call.
Santos Cordon96efb482014-07-19 14:57:05 -0700121 * Valid options:
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700122 * {@link VideoProfile.VideoState#AUDIO_ONLY},
123 * {@link VideoProfile.VideoState#BIDIRECTIONAL},
124 * {@link VideoProfile.VideoState#RX_ENABLED},
125 * {@link VideoProfile.VideoState#TX_ENABLED}.
Evan Charlton10197192014-07-19 15:00:29 -0700126 */
127 public static final String EXTRA_START_CALL_WITH_VIDEO_STATE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700128 "android.telecom.extra.START_CALL_WITH_VIDEO_STATE";
Evan Charlton10197192014-07-19 15:00:29 -0700129
130 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700131 * The extra used with an {@link android.content.Intent#ACTION_CALL} and
132 * {@link android.content.Intent#ACTION_DIAL} {@code Intent} to specify a
133 * {@link PhoneAccountHandle} to use when making the call.
Evan Charlton10197192014-07-19 15:00:29 -0700134 * <p class="note">
Santos Cordon96efb482014-07-19 14:57:05 -0700135 * Retrieve with {@link android.content.Intent#getParcelableExtra(String)}.
Evan Charlton10197192014-07-19 15:00:29 -0700136 */
Evan Charlton6eb262c2014-07-19 18:18:19 -0700137 public static final String EXTRA_PHONE_ACCOUNT_HANDLE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700138 "android.telecom.extra.PHONE_ACCOUNT_HANDLE";
Evan Charlton10197192014-07-19 15:00:29 -0700139
140 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700141 * Optional extra for {@link #ACTION_INCOMING_CALL} containing a {@link Bundle} which contains
142 * metadata about the call. This {@link Bundle} will be returned to the
143 * {@link ConnectionService}.
Evan Charlton10197192014-07-19 15:00:29 -0700144 */
145 public static final String EXTRA_INCOMING_CALL_EXTRAS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700146 "android.telecom.extra.INCOMING_CALL_EXTRAS";
Evan Charlton10197192014-07-19 15:00:29 -0700147
148 /**
Nancy Chen10798dc2014-08-08 14:00:25 -0700149 * Optional extra for {@link android.content.Intent#ACTION_CALL} and
150 * {@link android.content.Intent#ACTION_DIAL} {@code Intent} containing a {@link Bundle}
151 * which contains metadata about the call. This {@link Bundle} will be saved into
152 * {@code Call.Details}.
Nancy Chen10798dc2014-08-08 14:00:25 -0700153 */
154 public static final String EXTRA_OUTGOING_CALL_EXTRAS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700155 "android.telecom.extra.OUTGOING_CALL_EXTRAS";
Nancy Chen10798dc2014-08-08 14:00:25 -0700156
157 /**
Yorke Leec3cf9822014-10-02 09:38:39 -0700158 * @hide
159 */
160 public static final String EXTRA_UNKNOWN_CALL_HANDLE =
161 "android.telecom.extra.UNKNOWN_CALL_HANDLE";
162
163 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700164 * Optional extra for {@link android.telephony.TelephonyManager#ACTION_PHONE_STATE_CHANGED}
165 * containing the disconnect code.
Evan Charlton10197192014-07-19 15:00:29 -0700166 */
167 public static final String EXTRA_CALL_DISCONNECT_CAUSE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700168 "android.telecom.extra.CALL_DISCONNECT_CAUSE";
Evan Charlton10197192014-07-19 15:00:29 -0700169
170 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700171 * Optional extra for {@link android.telephony.TelephonyManager#ACTION_PHONE_STATE_CHANGED}
172 * containing the disconnect message.
Evan Charlton10197192014-07-19 15:00:29 -0700173 */
174 public static final String EXTRA_CALL_DISCONNECT_MESSAGE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700175 "android.telecom.extra.CALL_DISCONNECT_MESSAGE";
Evan Charlton10197192014-07-19 15:00:29 -0700176
177 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700178 * Optional extra for {@link android.telephony.TelephonyManager#ACTION_PHONE_STATE_CHANGED}
179 * containing the component name of the associated connection service.
Evan Charlton0e094d92014-11-08 15:49:16 -0800180 * @hide
Evan Charlton10197192014-07-19 15:00:29 -0700181 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800182 @SystemApi
Evan Charlton10197192014-07-19 15:00:29 -0700183 public static final String EXTRA_CONNECTION_SERVICE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700184 "android.telecom.extra.CONNECTION_SERVICE";
Evan Charlton10197192014-07-19 15:00:29 -0700185
186 /**
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700187 * An optional {@link android.content.Intent#ACTION_CALL} intent extra denoting the
188 * package name of the app specifying an alternative gateway for the call.
189 * The value is a string.
190 *
191 * (The following comment corresponds to the all GATEWAY_* extras)
192 * An app which sends the {@link android.content.Intent#ACTION_CALL} intent can specify an
193 * alternative address to dial which is different from the one specified and displayed to
194 * the user. This alternative address is referred to as the gateway address.
195 */
196 public static final String GATEWAY_PROVIDER_PACKAGE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700197 "android.telecom.extra.GATEWAY_PROVIDER_PACKAGE";
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700198
199 /**
200 * An optional {@link android.content.Intent#ACTION_CALL} intent extra corresponding to the
201 * original address to dial for the call. This is used when an alternative gateway address is
202 * provided to recall the original address.
203 * The value is a {@link android.net.Uri}.
204 *
205 * (See {@link #GATEWAY_PROVIDER_PACKAGE} for details)
206 */
207 public static final String GATEWAY_ORIGINAL_ADDRESS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700208 "android.telecom.extra.GATEWAY_ORIGINAL_ADDRESS";
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700209
210 /**
Evan Charlton10197192014-07-19 15:00:29 -0700211 * The number which the party on the other side of the line will see (and use to return the
212 * call).
213 * <p>
Santos Cordon96efb482014-07-19 14:57:05 -0700214 * {@link ConnectionService}s which interact with {@link RemoteConnection}s should only populate
215 * this if the {@link android.telephony.TelephonyManager#getLine1Number()} value, as that is the
216 * user's expected caller ID.
Evan Charlton10197192014-07-19 15:00:29 -0700217 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700218 public static final String EXTRA_CALL_BACK_NUMBER = "android.telecom.extra.CALL_BACK_NUMBER";
Evan Charlton10197192014-07-19 15:00:29 -0700219
220 /**
221 * The dual tone multi-frequency signaling character sent to indicate the dialing system should
222 * pause for a predefined period.
223 */
224 public static final char DTMF_CHARACTER_PAUSE = ',';
225
226 /**
227 * The dual-tone multi-frequency signaling character sent to indicate the dialing system should
228 * wait for user confirmation before proceeding.
229 */
230 public static final char DTMF_CHARACTER_WAIT = ';';
231
232 /**
233 * TTY (teletypewriter) mode is off.
234 *
235 * @hide
236 */
237 public static final int TTY_MODE_OFF = 0;
238
239 /**
240 * TTY (teletypewriter) mode is on. The speaker is off and the microphone is muted. The user
241 * will communicate with the remote party by sending and receiving text messages.
242 *
243 * @hide
244 */
245 public static final int TTY_MODE_FULL = 1;
246
247 /**
248 * TTY (teletypewriter) mode is in hearing carryover mode (HCO). The microphone is muted but the
249 * speaker is on. The user will communicate with the remote party by sending text messages and
250 * hearing an audible reply.
251 *
252 * @hide
253 */
254 public static final int TTY_MODE_HCO = 2;
255
256 /**
257 * TTY (teletypewriter) mode is in voice carryover mode (VCO). The speaker is off but the
258 * microphone is still on. User will communicate with the remote party by speaking and receiving
259 * text message replies.
260 *
261 * @hide
262 */
263 public static final int TTY_MODE_VCO = 3;
264
265 /**
266 * Broadcast intent action indicating that the current TTY mode has changed. An intent extra
267 * provides this state as an int.
Evan Charlton10197192014-07-19 15:00:29 -0700268 *
Santos Cordon96efb482014-07-19 14:57:05 -0700269 * @see #EXTRA_CURRENT_TTY_MODE
Evan Charlton10197192014-07-19 15:00:29 -0700270 * @hide
271 */
272 public static final String ACTION_CURRENT_TTY_MODE_CHANGED =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700273 "android.telecom.action.CURRENT_TTY_MODE_CHANGED";
Evan Charlton10197192014-07-19 15:00:29 -0700274
275 /**
276 * The lookup key for an int that indicates the current TTY mode.
277 * Valid modes are:
278 * - {@link #TTY_MODE_OFF}
279 * - {@link #TTY_MODE_FULL}
280 * - {@link #TTY_MODE_HCO}
281 * - {@link #TTY_MODE_VCO}
282 *
283 * @hide
284 */
285 public static final String EXTRA_CURRENT_TTY_MODE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700286 "android.telecom.intent.extra.CURRENT_TTY_MODE";
Evan Charlton10197192014-07-19 15:00:29 -0700287
288 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700289 * Broadcast intent action indicating that the TTY preferred operating mode has changed. An
290 * intent extra provides the new mode as an int.
Evan Charlton10197192014-07-19 15:00:29 -0700291 *
Santos Cordon96efb482014-07-19 14:57:05 -0700292 * @see #EXTRA_TTY_PREFERRED_MODE
Evan Charlton10197192014-07-19 15:00:29 -0700293 * @hide
294 */
295 public static final String ACTION_TTY_PREFERRED_MODE_CHANGED =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700296 "android.telecom.action.TTY_PREFERRED_MODE_CHANGED";
Evan Charlton10197192014-07-19 15:00:29 -0700297
298 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700299 * The lookup key for an int that indicates preferred TTY mode. Valid modes are: -
300 * {@link #TTY_MODE_OFF} - {@link #TTY_MODE_FULL} - {@link #TTY_MODE_HCO} -
301 * {@link #TTY_MODE_VCO}
Evan Charlton10197192014-07-19 15:00:29 -0700302 *
303 * @hide
304 */
305 public static final String EXTRA_TTY_PREFERRED_MODE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700306 "android.telecom.intent.extra.TTY_PREFERRED";
Evan Charlton10197192014-07-19 15:00:29 -0700307
Nancy Chen9d568c02014-09-08 14:17:59 -0700308 /**
309 * The following 4 constants define how properties such as phone numbers and names are
310 * displayed to the user.
311 */
312
313 /** Property is displayed normally. */
314 public static final int PRESENTATION_ALLOWED = 1;
315
316 /** Property was blocked. */
317 public static final int PRESENTATION_RESTRICTED = 2;
318
319 /** Presentation was not specified or is unknown. */
320 public static final int PRESENTATION_UNKNOWN = 3;
321
322 /** Property should be displayed as a pay phone. */
323 public static final int PRESENTATION_PAYPHONE = 4;
324
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700325 private static final String TAG = "TelecomManager";
Yorke Leeb4ce1432014-06-09 13:53:23 -0700326
327 private final Context mContext;
Yorke Leeb4ce1432014-06-09 13:53:23 -0700328
Santos Cordon6c7a3882014-06-25 15:30:08 -0700329 /**
330 * @hide
331 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700332 public static TelecomManager from(Context context) {
333 return (TelecomManager) context.getSystemService(Context.TELECOM_SERVICE);
Yorke Leeb4ce1432014-06-09 13:53:23 -0700334 }
Santos Cordon6c7a3882014-06-25 15:30:08 -0700335
336 /**
337 * @hide
338 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700339 public TelecomManager(Context context) {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700340 Context appContext = context.getApplicationContext();
341 if (appContext != null) {
342 mContext = appContext;
343 } else {
344 mContext = context;
345 }
346 }
347
348 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700349 * Return the {@link PhoneAccount} which is the user-chosen default for making outgoing phone
Nancy Chen513c8922014-09-17 14:47:20 -0700350 * calls with a specified URI scheme.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700351 * <p>
Santos Cordon96efb482014-07-19 14:57:05 -0700352 * Apps must be prepared for this method to return {@code null}, indicating that there currently
Nancy Chen513c8922014-09-17 14:47:20 -0700353 * exists no user-chosen default {@code PhoneAccount}.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700354 * <p>
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700355 * @param uriScheme The URI scheme.
Nancy Chen513c8922014-09-17 14:47:20 -0700356 * @return The {@link PhoneAccountHandle} corresponding to the user-chosen default for outgoing
357 * phone calls for a specified URI scheme.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700358 */
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700359 public PhoneAccountHandle getDefaultOutgoingPhoneAccount(String uriScheme) {
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700360 try {
361 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700362 return getTelecomService().getDefaultOutgoingPhoneAccount(uriScheme);
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700363 }
364 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700365 Log.e(TAG, "Error calling ITelecomService#getDefaultOutgoingPhoneAccount", e);
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700366 }
367 return null;
368 }
369
370 /**
Andrew Leed4abbfb2014-09-03 14:58:27 -0700371 * Return the {@link PhoneAccount} which is the user-chosen default for making outgoing phone
372 * calls. This {@code PhoneAccount} will always be a member of the list which is returned from
Nancy Chen210ef032014-09-15 17:58:42 -0700373 * calling {@link #getCallCapablePhoneAccounts()}
Andrew Leed4abbfb2014-09-03 14:58:27 -0700374 *
375 * Apps must be prepared for this method to return {@code null}, indicating that there currently
376 * exists no user-chosen default {@code PhoneAccount}.
377 *
378 * @return The user outgoing phone account selected by the user.
Jay Shrauner225ccad2015-04-15 15:51:15 -0700379 * @hide
Andrew Leed4abbfb2014-09-03 14:58:27 -0700380 */
381 public PhoneAccountHandle getUserSelectedOutgoingPhoneAccount() {
382 try {
383 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700384 return getTelecomService().getUserSelectedOutgoingPhoneAccount();
Andrew Leed4abbfb2014-09-03 14:58:27 -0700385 }
386 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700387 Log.e(TAG, "Error calling ITelecomService#getUserSelectedOutgoingPhoneAccount", e);
Andrew Leed4abbfb2014-09-03 14:58:27 -0700388 }
389 return null;
390 }
391
392 /**
Andrew Lee59cac3a2014-08-28 16:50:10 -0700393 * Sets the default account for making outgoing phone calls.
394 * @hide
395 */
Andrew Leed4abbfb2014-09-03 14:58:27 -0700396 public void setUserSelectedOutgoingPhoneAccount(PhoneAccountHandle accountHandle) {
Andrew Lee59cac3a2014-08-28 16:50:10 -0700397 try {
398 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700399 getTelecomService().setUserSelectedOutgoingPhoneAccount(accountHandle);
Andrew Lee59cac3a2014-08-28 16:50:10 -0700400 }
401 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700402 Log.e(TAG, "Error calling ITelecomService#setUserSelectedOutgoingPhoneAccount");
Andrew Lee59cac3a2014-08-28 16:50:10 -0700403 }
404 }
405
406 /**
Andrew Lee59cac3a2014-08-28 16:50:10 -0700407 * Returns the current SIM call manager. Apps must be prepared for this method to return
408 * {@code null}, indicating that there currently exists no user-chosen default
409 * {@code PhoneAccount}.
410 * @return The phone account handle of the current sim call manager.
Andrew Lee59cac3a2014-08-28 16:50:10 -0700411 */
412 public PhoneAccountHandle getSimCallManager() {
413 try {
414 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700415 return getTelecomService().getSimCallManager();
Andrew Lee59cac3a2014-08-28 16:50:10 -0700416 }
417 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700418 Log.e(TAG, "Error calling ITelecomService#getSimCallManager");
Andrew Lee59cac3a2014-08-28 16:50:10 -0700419 }
420 return null;
421 }
422
423 /**
424 * Sets the SIM call manager to the specified phone account.
425 * @param accountHandle The phone account handle of the account to set as the sim call manager.
426 * @hide
427 */
428 public void setSimCallManager(PhoneAccountHandle accountHandle) {
429 try {
430 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700431 getTelecomService().setSimCallManager(accountHandle);
Andrew Lee59cac3a2014-08-28 16:50:10 -0700432 }
433 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700434 Log.e(TAG, "Error calling ITelecomService#setSimCallManager");
Andrew Lee59cac3a2014-08-28 16:50:10 -0700435 }
436 }
437
438 /**
439 * Returns the list of registered SIM call managers.
440 * @return List of registered SIM call managers.
441 * @hide
442 */
443 public List<PhoneAccountHandle> getSimCallManagers() {
444 try {
445 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700446 return getTelecomService().getSimCallManagers();
Andrew Lee59cac3a2014-08-28 16:50:10 -0700447 }
448 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700449 Log.e(TAG, "Error calling ITelecomService#getSimCallManagers");
Andrew Lee59cac3a2014-08-28 16:50:10 -0700450 }
451 return new ArrayList<>();
452 }
453
454 /**
Evan Charltoneb0a8d562014-09-04 12:03:34 -0700455 * Returns the current connection manager. Apps must be prepared for this method to return
456 * {@code null}, indicating that there currently exists no user-chosen default
457 * {@code PhoneAccount}.
458 *
459 * @return The phone account handle of the current connection manager.
Evan Charlton0e094d92014-11-08 15:49:16 -0800460 * @hide
Evan Charltoneb0a8d562014-09-04 12:03:34 -0700461 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800462 @SystemApi
Evan Charltoneb0a8d562014-09-04 12:03:34 -0700463 public PhoneAccountHandle getConnectionManager() {
464 return getSimCallManager();
465 }
466
467 /**
Sailesh Nepal7a4e3872014-11-21 11:01:40 -0800468 * Returns the list of registered SIM call managers.
469 * @return List of registered SIM call managers.
470 * @hide
471 */
472 @SystemApi
473 public List<PhoneAccountHandle> getRegisteredConnectionManagers() {
474 return getSimCallManagers();
475 }
476
477 /**
Nancy Chen210ef032014-09-15 17:58:42 -0700478 * Returns a list of the {@link PhoneAccountHandle}s which can be used to make and receive phone
479 * calls which support the specified URI scheme.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700480 * <P>
481 * For example, invoking with {@code "tel"} will find all {@link PhoneAccountHandle}s which
482 * support telephone calls (e.g. URIs such as {@code tel:555-555-1212}). Invoking with
483 * {@code "sip"} will find all {@link PhoneAccountHandle}s which support SIP calls (e.g. URIs
484 * such as {@code sip:example@sipexample.com}).
485 *
486 * @param uriScheme The URI scheme.
487 * @return A list of {@code PhoneAccountHandle} objects supporting the URI scheme.
Evan Charlton0e094d92014-11-08 15:49:16 -0800488 * @hide
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700489 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800490 @SystemApi
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700491 public List<PhoneAccountHandle> getPhoneAccountsSupportingScheme(String uriScheme) {
492 try {
493 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700494 return getTelecomService().getPhoneAccountsSupportingScheme(uriScheme);
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700495 }
496 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700497 Log.e(TAG, "Error calling ITelecomService#getPhoneAccountsSupportingScheme", e);
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700498 }
499 return new ArrayList<>();
500 }
501
Nancy Chen513c8922014-09-17 14:47:20 -0700502
503 /**
504 * Return a list of {@link PhoneAccountHandle}s which can be used to make and receive phone
505 * calls.
506 *
507 * @see #EXTRA_PHONE_ACCOUNT_HANDLE
508 * @return A list of {@code PhoneAccountHandle} objects.
509 *
Nancy Chen513c8922014-09-17 14:47:20 -0700510 */
511 public List<PhoneAccountHandle> getCallCapablePhoneAccounts() {
512 try {
513 if (isServiceConnected()) {
514 return getTelecomService().getCallCapablePhoneAccounts();
515 }
516 } catch (RemoteException e) {
517 Log.e(TAG, "Error calling ITelecomService#getCallCapablePhoneAccounts", e);
518 }
519 return new ArrayList<>();
520 }
521
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700522 /**
Nancy Chen513c8922014-09-17 14:47:20 -0700523 * Returns a list of all {@link PhoneAccount}s registered for the calling package.
524 *
525 * @return A list of {@code PhoneAccountHandle} objects.
Evan Charlton0e094d92014-11-08 15:49:16 -0800526 * @hide
Nancy Chen513c8922014-09-17 14:47:20 -0700527 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800528 @SystemApi
Nancy Chen513c8922014-09-17 14:47:20 -0700529 public List<PhoneAccountHandle> getPhoneAccountsForPackage() {
530 try {
531 if (isServiceConnected()) {
532 return getTelecomService().getPhoneAccountsForPackage(mContext.getPackageName());
533 }
534 } catch (RemoteException e) {
535 Log.e(TAG, "Error calling ITelecomService#getPhoneAccountsForPackage", e);
536 }
537 return null;
538 }
539
540 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700541 * Return the {@link PhoneAccount} for a specified {@link PhoneAccountHandle}. Object includes
542 * resources which can be used in a user interface.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700543 *
Evan Charlton6eb262c2014-07-19 18:18:19 -0700544 * @param account The {@link PhoneAccountHandle}.
Evan Charlton8c8a0622014-07-20 12:31:00 -0700545 * @return The {@link PhoneAccount} object.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700546 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700547 public PhoneAccount getPhoneAccount(PhoneAccountHandle account) {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700548 try {
549 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700550 return getTelecomService().getPhoneAccount(account);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700551 }
552 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700553 Log.e(TAG, "Error calling ITelecomService#getPhoneAccount", e);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700554 }
555 return null;
556 }
557
558 /**
Nancy Chen210ef032014-09-15 17:58:42 -0700559 * Returns a count of all {@link PhoneAccount}s.
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700560 *
Nancy Chen210ef032014-09-15 17:58:42 -0700561 * @return The count of {@link PhoneAccount}s.
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700562 * @hide
563 */
564 @SystemApi
565 public int getAllPhoneAccountsCount() {
566 try {
567 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700568 return getTelecomService().getAllPhoneAccountsCount();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700569 }
570 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700571 Log.e(TAG, "Error calling ITelecomService#getAllPhoneAccountsCount", e);
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700572 }
573 return 0;
574 }
575
576 /**
577 * Returns a list of all {@link PhoneAccount}s.
578 *
579 * @return All {@link PhoneAccount}s.
580 * @hide
581 */
582 @SystemApi
583 public List<PhoneAccount> getAllPhoneAccounts() {
584 try {
585 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700586 return getTelecomService().getAllPhoneAccounts();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700587 }
588 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700589 Log.e(TAG, "Error calling ITelecomService#getAllPhoneAccounts", e);
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700590 }
591 return Collections.EMPTY_LIST;
592 }
593
594 /**
595 * Returns a list of all {@link PhoneAccountHandle}s.
596 *
597 * @return All {@link PhoneAccountHandle}s.
598 * @hide
599 */
600 @SystemApi
601 public List<PhoneAccountHandle> getAllPhoneAccountHandles() {
602 try {
603 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700604 return getTelecomService().getAllPhoneAccountHandles();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700605 }
606 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700607 Log.e(TAG, "Error calling ITelecomService#getAllPhoneAccountHandles", e);
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700608 }
609 return Collections.EMPTY_LIST;
610 }
611
612 /**
Santos Cordond9e614f2014-10-28 13:10:36 -0700613 * Register a {@link PhoneAccount} for use by the system. When registering
614 * {@link PhoneAccount}s, existing registrations will be overwritten if the
615 * {@link PhoneAccountHandle} matches that of a {@link PhoneAccount} which is already
616 * registered. Once registered, the {@link PhoneAccount} is listed to the user as an option
617 * when placing calls. The user may still need to enable the {@link PhoneAccount} within
618 * the phone app settings before the account is usable.
619 * <p>
620 * A {@link SecurityException} will be thrown if an app tries to register a
621 * {@link PhoneAccountHandle} where the package name specified within
622 * {@link PhoneAccountHandle#getComponentName()} does not match the package name of the app.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700623 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700624 * @param account The complete {@link PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700625 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700626 public void registerPhoneAccount(PhoneAccount account) {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700627 try {
628 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700629 getTelecomService().registerPhoneAccount(account);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700630 }
631 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700632 Log.e(TAG, "Error calling ITelecomService#registerPhoneAccount", e);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700633 }
634 }
635
636 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700637 * Remove a {@link PhoneAccount} registration from the system.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700638 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700639 * @param accountHandle A {@link PhoneAccountHandle} for the {@link PhoneAccount} to unregister.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700640 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700641 public void unregisterPhoneAccount(PhoneAccountHandle accountHandle) {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700642 try {
643 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700644 getTelecomService().unregisterPhoneAccount(accountHandle);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700645 }
646 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700647 Log.e(TAG, "Error calling ITelecomService#unregisterPhoneAccount", e);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700648 }
649 }
650
651 /**
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700652 * Remove all Accounts that belong to the calling package from the system.
Evan Charlton0e094d92014-11-08 15:49:16 -0800653 * @hide
Ihab Awad807fe0a2014-07-09 12:30:52 -0700654 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800655 @SystemApi
Yorke Lee06044272015-04-14 15:16:59 -0700656 public void clearPhoneAccounts() {
657 clearAccounts();
658 }
659 /**
660 * Remove all Accounts that belong to the calling package from the system.
661 * @deprecated Use {@link #clearPhoneAccounts()} instead.
662 * @hide
663 */
664 @SystemApi
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700665 public void clearAccounts() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700666 try {
667 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700668 getTelecomService().clearAccounts(mContext.getPackageName());
Ihab Awad807fe0a2014-07-09 12:30:52 -0700669 }
670 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700671 Log.e(TAG, "Error calling ITelecomService#clearAccounts", e);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700672 }
673 }
674
675 /**
Anthony Lee67279262014-10-27 11:28:40 -0700676 * Remove all Accounts that belong to the specified package from the system.
677 * @hide
678 */
679 public void clearAccountsForPackage(String packageName) {
680 try {
681 if (isServiceConnected() && !TextUtils.isEmpty(packageName)) {
682 getTelecomService().clearAccounts(packageName);
683 }
684 } catch (RemoteException e) {
Nancy Chen5cf27842015-01-24 23:30:27 -0800685 Log.e(TAG, "Error calling ITelecomService#clearAccountsForPackage", e);
Anthony Lee67279262014-10-27 11:28:40 -0700686 }
687 }
688
689 /**
Ihab Awad807fe0a2014-07-09 12:30:52 -0700690 * @hide
691 */
Santos Cordon6c7a3882014-06-25 15:30:08 -0700692 @SystemApi
693 public ComponentName getDefaultPhoneApp() {
694 try {
Santos Cordon9eb45932014-06-27 12:28:43 -0700695 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700696 return getTelecomService().getDefaultPhoneApp();
Santos Cordon9eb45932014-06-27 12:28:43 -0700697 }
Santos Cordon6c7a3882014-06-25 15:30:08 -0700698 } catch (RemoteException e) {
699 Log.e(TAG, "RemoteException attempting to get the default phone app.", e);
700 }
701 return null;
702 }
703
Santos Cordon9eb45932014-06-27 12:28:43 -0700704 /**
Nancy Chen443e5012014-10-15 15:48:21 -0700705 * Return whether a given phone number is the configured voicemail number for a
706 * particular phone account.
707 *
708 * @param accountHandle The handle for the account to check the voicemail number against
709 * @param number The number to look up.
Nancy Chen443e5012014-10-15 15:48:21 -0700710 */
Nancy Chen443e5012014-10-15 15:48:21 -0700711 public boolean isVoiceMailNumber(PhoneAccountHandle accountHandle, String number) {
712 try {
713 if (isServiceConnected()) {
714 return getTelecomService().isVoiceMailNumber(accountHandle, number);
715 }
716 } catch (RemoteException e) {
Nancy Chen5cf27842015-01-24 23:30:27 -0800717 Log.e(TAG, "RemoteException calling ITelecomService#isVoiceMailNumber.", e);
Nancy Chen443e5012014-10-15 15:48:21 -0700718 }
719 return false;
720 }
721
722 /**
Nancy Chen8c066f7c2014-12-03 15:18:08 -0800723 * Return whether a given phone account has a voicemail number configured.
724 *
725 * @param accountHandle The handle for the account to check for a voicemail number.
726 * @return {@code true} If the given phone account has a voicemail number.
Nancy Chen8c066f7c2014-12-03 15:18:08 -0800727 */
Nancy Chen8c066f7c2014-12-03 15:18:08 -0800728 public boolean hasVoiceMailNumber(PhoneAccountHandle accountHandle) {
729 try {
730 if (isServiceConnected()) {
731 return getTelecomService().hasVoiceMailNumber(accountHandle);
732 }
733 } catch (RemoteException e) {
Nancy Chen5cf27842015-01-24 23:30:27 -0800734 Log.e(TAG, "RemoteException calling ITelecomService#hasVoiceMailNumber.", e);
Nancy Chen8c066f7c2014-12-03 15:18:08 -0800735 }
736 return false;
737 }
738
739 /**
Nancy Chen5cf27842015-01-24 23:30:27 -0800740 * Return the line 1 phone number for given phone account.
741 *
742 * @param accountHandle The handle for the account retrieve a number for.
743 * @return A string representation of the line 1 phone number.
Nancy Chen5cf27842015-01-24 23:30:27 -0800744 */
Nancy Chen5cf27842015-01-24 23:30:27 -0800745 public String getLine1Number(PhoneAccountHandle accountHandle) {
746 try {
747 if (isServiceConnected()) {
748 return getTelecomService().getLine1Number(accountHandle);
749 }
750 } catch (RemoteException e) {
751 Log.e(TAG, "RemoteException calling ITelecomService#getLine1Number.", e);
752 }
753 return null;
754 }
755
756 /**
Santos Cordon9eb45932014-06-27 12:28:43 -0700757 * Returns whether there is an ongoing phone call (can be in dialing, ringing, active or holding
758 * states).
Nancy Chen0eb1e402014-08-21 22:52:29 -0700759 * <p>
760 * Requires permission: {@link android.Manifest.permission#READ_PHONE_STATE}
761 * </p>
Santos Cordon9eb45932014-06-27 12:28:43 -0700762 */
Nancy Chen0eb1e402014-08-21 22:52:29 -0700763 public boolean isInCall() {
Santos Cordon9eb45932014-06-27 12:28:43 -0700764 try {
765 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700766 return getTelecomService().isInCall();
Santos Cordon9eb45932014-06-27 12:28:43 -0700767 }
768 } catch (RemoteException e) {
Yorke Lee2ae312e2014-09-12 17:58:48 -0700769 Log.e(TAG, "RemoteException calling isInCall().", e);
Santos Cordon9eb45932014-06-27 12:28:43 -0700770 }
771 return false;
772 }
773
774 /**
Yorke Lee2ae312e2014-09-12 17:58:48 -0700775 * Returns one of the following constants that represents the current state of Telecom:
776 *
777 * {@link TelephonyManager#CALL_STATE_RINGING}
778 * {@link TelephonyManager#CALL_STATE_OFFHOOK}
779 * {@link TelephonyManager#CALL_STATE_IDLE}
Yorke Lee7c72c2d2014-10-28 14:12:02 -0700780 *
781 * Note that this API does not require the
782 * {@link android.Manifest.permission#READ_PHONE_STATE} permission. This is intentional, to
783 * preserve the behavior of {@link TelephonyManager#getCallState()}, which also did not require
784 * the permission.
Yorke Lee2ae312e2014-09-12 17:58:48 -0700785 * @hide
786 */
787 @SystemApi
788 public int getCallState() {
789 try {
790 if (isServiceConnected()) {
791 return getTelecomService().getCallState();
792 }
793 } catch (RemoteException e) {
794 Log.d(TAG, "RemoteException calling getCallState().", e);
795 }
796 return TelephonyManager.CALL_STATE_IDLE;
797 }
798
799 /**
Santos Cordon9eb45932014-06-27 12:28:43 -0700800 * Returns whether there currently exists is a ringing incoming-call.
801 *
802 * @hide
803 */
804 @SystemApi
805 public boolean isRinging() {
806 try {
807 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700808 return getTelecomService().isRinging();
Santos Cordon9eb45932014-06-27 12:28:43 -0700809 }
810 } catch (RemoteException e) {
811 Log.e(TAG, "RemoteException attempting to get ringing state of phone app.", e);
812 }
813 return false;
814 }
815
816 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700817 * Ends an ongoing call.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700818 * TODO: L-release - need to convert all invocations of ITelecomService#endCall to use this
Santos Cordon96efb482014-07-19 14:57:05 -0700819 * method (clockwork & gearhead).
Santos Cordon9eb45932014-06-27 12:28:43 -0700820 * @hide
821 */
822 @SystemApi
823 public boolean endCall() {
824 try {
825 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700826 return getTelecomService().endCall();
Santos Cordon9eb45932014-06-27 12:28:43 -0700827 }
828 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700829 Log.e(TAG, "Error calling ITelecomService#endCall", e);
Santos Cordon9eb45932014-06-27 12:28:43 -0700830 }
831 return false;
832 }
833
834 /**
835 * If there is a ringing incoming call, this method accepts the call on behalf of the user.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700836 * TODO: L-release - need to convert all invocation of ITelecmmService#answerRingingCall to use
Santos Cordon96efb482014-07-19 14:57:05 -0700837 * this method (clockwork & gearhead).
Santos Cordon9eb45932014-06-27 12:28:43 -0700838 *
839 * @hide
840 */
841 @SystemApi
842 public void acceptRingingCall() {
843 try {
844 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700845 getTelecomService().acceptRingingCall();
Santos Cordon9eb45932014-06-27 12:28:43 -0700846 }
847 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700848 Log.e(TAG, "Error calling ITelecomService#acceptRingingCall", e);
Santos Cordon9eb45932014-06-27 12:28:43 -0700849 }
850 }
851
852 /**
853 * Silences the ringer if a ringing call exists.
Santos Cordon9eb45932014-06-27 12:28:43 -0700854 */
Santos Cordon9eb45932014-06-27 12:28:43 -0700855 public void silenceRinger() {
856 try {
857 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700858 getTelecomService().silenceRinger();
Santos Cordon9eb45932014-06-27 12:28:43 -0700859 }
860 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700861 Log.e(TAG, "Error calling ITelecomService#silenceRinger", e);
Santos Cordon9eb45932014-06-27 12:28:43 -0700862 }
863 }
864
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700865 /**
866 * Returns whether TTY is supported on this device.
867 *
868 * @hide
869 */
870 @SystemApi
871 public boolean isTtySupported() {
872 try {
873 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700874 return getTelecomService().isTtySupported();
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700875 }
876 } catch (RemoteException e) {
877 Log.e(TAG, "RemoteException attempting to get TTY supported state.", e);
878 }
879 return false;
880 }
881
882 /**
883 * 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 -0700884 * settings and have a wired headset plugged in.
885 * Valid modes are:
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700886 * - {@link TelecomManager#TTY_MODE_OFF}
887 * - {@link TelecomManager#TTY_MODE_FULL}
888 * - {@link TelecomManager#TTY_MODE_HCO}
889 * - {@link TelecomManager#TTY_MODE_VCO}
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700890 * @hide
891 */
892 public int getCurrentTtyMode() {
893 try {
894 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700895 return getTelecomService().getCurrentTtyMode();
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700896 }
897 } catch (RemoteException e) {
898 Log.e(TAG, "RemoteException attempting to get the current TTY mode.", e);
899 }
Evan Charlton10197192014-07-19 15:00:29 -0700900 return TTY_MODE_OFF;
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700901 }
902
Santos Cordon96efb482014-07-19 14:57:05 -0700903 /**
904 * Registers a new incoming call. A {@link ConnectionService} should invoke this method when it
905 * has an incoming call. The specified {@link PhoneAccountHandle} must have been registered
Nancy Chen210ef032014-09-15 17:58:42 -0700906 * with {@link #registerPhoneAccount}. Once invoked, this method will cause the system to bind
907 * to the {@link ConnectionService} associated with the {@link PhoneAccountHandle} and request
Santos Cordon96efb482014-07-19 14:57:05 -0700908 * additional information about the call (See
909 * {@link ConnectionService#onCreateIncomingConnection}) before starting the incoming call UI.
910 *
911 * @param phoneAccount A {@link PhoneAccountHandle} registered with
912 * {@link #registerPhoneAccount}.
913 * @param extras A bundle that will be passed through to
914 * {@link ConnectionService#onCreateIncomingConnection}.
915 */
916 public void addNewIncomingCall(PhoneAccountHandle phoneAccount, Bundle extras) {
917 try {
918 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700919 getTelecomService().addNewIncomingCall(
Santos Cordon96efb482014-07-19 14:57:05 -0700920 phoneAccount, extras == null ? new Bundle() : extras);
921 }
922 } catch (RemoteException e) {
923 Log.e(TAG, "RemoteException adding a new incoming call: " + phoneAccount, e);
924 }
925 }
926
Nancy Chen0eb1e402014-08-21 22:52:29 -0700927 /**
Yorke Leec3cf9822014-10-02 09:38:39 -0700928 * Registers a new unknown call with Telecom. This can only be called by the system Telephony
929 * service. This is invoked when Telephony detects a new unknown connection that was neither
930 * a new incoming call, nor an user-initiated outgoing call.
931 *
932 * @param phoneAccount A {@link PhoneAccountHandle} registered with
933 * {@link #registerPhoneAccount}.
934 * @param extras A bundle that will be passed through to
935 * {@link ConnectionService#onCreateIncomingConnection}.
936 * @hide
937 */
938 @SystemApi
939 public void addNewUnknownCall(PhoneAccountHandle phoneAccount, Bundle extras) {
940 try {
941 if (isServiceConnected()) {
942 getTelecomService().addNewUnknownCall(
943 phoneAccount, extras == null ? new Bundle() : extras);
944 }
945 } catch (RemoteException e) {
946 Log.e(TAG, "RemoteException adding a new unknown call: " + phoneAccount, e);
947 }
948 }
949
950 /**
Nancy Chen0eb1e402014-08-21 22:52:29 -0700951 * Processes the specified dial string as an MMI code.
952 * MMI codes are any sequence of characters entered into the dialpad that contain a "*" or "#".
953 * Some of these sequences launch special behavior through handled by Telephony.
Nancy Chen95e8a672014-10-16 18:38:21 -0700954 * This method uses the default subscription.
Nancy Chen0eb1e402014-08-21 22:52:29 -0700955 * <p>
956 * Requires that the method-caller be set as the system dialer app.
957 * </p>
958 *
959 * @param dialString The digits to dial.
960 * @return True if the digits were processed as an MMI code, false otherwise.
961 */
962 public boolean handleMmi(String dialString) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700963 ITelecomService service = getTelecomService();
Nancy Chen0eb1e402014-08-21 22:52:29 -0700964 if (service != null) {
965 try {
966 return service.handlePinMmi(dialString);
967 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700968 Log.e(TAG, "Error calling ITelecomService#handlePinMmi", e);
Nancy Chen0eb1e402014-08-21 22:52:29 -0700969 }
970 }
971 return false;
972 }
973
974 /**
Nancy Chen95e8a672014-10-16 18:38:21 -0700975 * Processes the specified dial string as an MMI code.
976 * MMI codes are any sequence of characters entered into the dialpad that contain a "*" or "#".
977 * Some of these sequences launch special behavior through handled by Telephony.
978 * <p>
979 * Requires that the method-caller be set as the system dialer app.
980 * </p>
981 *
982 * @param accountHandle The handle for the account the MMI code should apply to.
983 * @param dialString The digits to dial.
984 * @return True if the digits were processed as an MMI code, false otherwise.
Nancy Chen95e8a672014-10-16 18:38:21 -0700985 */
Yorke Lee06044272015-04-14 15:16:59 -0700986 public boolean handleMmi(String dialString, PhoneAccountHandle accountHandle) {
Nancy Chen95e8a672014-10-16 18:38:21 -0700987 ITelecomService service = getTelecomService();
988 if (service != null) {
989 try {
990 return service.handlePinMmiForPhoneAccount(accountHandle, dialString);
991 } catch (RemoteException e) {
992 Log.e(TAG, "Error calling ITelecomService#handlePinMmi", e);
993 }
994 }
995 return false;
996 }
997
998 /**
Nancy Chenb2299c12014-10-29 18:22:11 -0700999 * @param accountHandle The handle for the account to derive an adn query URI for or
1000 * {@code null} to return a URI which will use the default account.
1001 * @return The URI (with the content:// scheme) specific to the specified {@link PhoneAccount}
1002 * for the the content retrieve.
1003 */
1004 public Uri getAdnUriForPhoneAccount(PhoneAccountHandle accountHandle) {
1005 ITelecomService service = getTelecomService();
1006 if (service != null && accountHandle != null) {
1007 try {
1008 return service.getAdnUriForPhoneAccount(accountHandle);
1009 } catch (RemoteException e) {
1010 Log.e(TAG, "Error calling ITelecomService#getAdnUriForPhoneAccount", e);
1011 }
1012 }
1013 return Uri.parse("content://icc/adn");
1014 }
1015
1016 /**
Nancy Chen0eb1e402014-08-21 22:52:29 -07001017 * Removes the missed-call notification if one is present.
1018 * <p>
1019 * Requires that the method-caller be set as the system dialer app.
1020 * </p>
1021 */
1022 public void cancelMissedCallsNotification() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001023 ITelecomService service = getTelecomService();
Nancy Chen0eb1e402014-08-21 22:52:29 -07001024 if (service != null) {
1025 try {
1026 service.cancelMissedCallsNotification();
1027 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001028 Log.e(TAG, "Error calling ITelecomService#cancelMissedCallsNotification", e);
Nancy Chen0eb1e402014-08-21 22:52:29 -07001029 }
1030 }
1031 }
1032
1033 /**
1034 * Brings the in-call screen to the foreground if there is an ongoing call. If there is
1035 * currently no ongoing call, then this method does nothing.
1036 * <p>
1037 * Requires that the method-caller be set as the system dialer app or have the
1038 * {@link android.Manifest.permission#READ_PHONE_STATE} permission.
1039 * </p>
1040 *
1041 * @param showDialpad Brings up the in-call dialpad as part of showing the in-call screen.
1042 */
1043 public void showInCallScreen(boolean showDialpad) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001044 ITelecomService service = getTelecomService();
Nancy Chen0eb1e402014-08-21 22:52:29 -07001045 if (service != null) {
1046 try {
1047 service.showInCallScreen(showDialpad);
1048 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001049 Log.e(TAG, "Error calling ITelecomService#showCallScreen", e);
Nancy Chen0eb1e402014-08-21 22:52:29 -07001050 }
1051 }
1052 }
1053
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001054 private ITelecomService getTelecomService() {
1055 return ITelecomService.Stub.asInterface(ServiceManager.getService(Context.TELECOM_SERVICE));
Santos Cordon6c7a3882014-06-25 15:30:08 -07001056 }
Santos Cordon9eb45932014-06-27 12:28:43 -07001057
1058 private boolean isServiceConnected() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001059 boolean isConnected = getTelecomService() != null;
Santos Cordon9eb45932014-06-27 12:28:43 -07001060 if (!isConnected) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001061 Log.w(TAG, "Telecom Service not found.");
Santos Cordon9eb45932014-06-27 12:28:43 -07001062 }
1063 return isConnected;
1064 }
Evan Charlton235c1592014-09-05 15:41:23 +00001065}