blob: b40afbfc647ba79481d9a937cb486f3d4e6f3f99 [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.
58 *
Santos Cordon96efb482014-07-19 14:57:05 -070059 * @hide
Evan Charlton10197192014-07-19 15:00:29 -070060 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -070061 public static final String ACTION_INCOMING_CALL = "android.telecom.action.INCOMING_CALL";
Evan Charlton10197192014-07-19 15:00:29 -070062
63 /**
Yorke Leec3cf9822014-10-02 09:38:39 -070064 * Similar to {@link #ACTION_INCOMING_CALL}, but is used only by Telephony to add a new
65 * sim-initiated MO call for carrier testing.
66 * @hide
67 */
68 public static final String ACTION_NEW_UNKNOWN_CALL = "android.telecom.action.NEW_UNKNOWN_CALL";
69
70 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -070071 * The {@link android.content.Intent} action used to configure a
Tyler Gunnef9f6f92014-09-12 22:16:17 -070072 * {@link android.telecom.ConnectionService}.
Evan Charlton0e094d92014-11-08 15:49:16 -080073 * @hide
Evan Charlton10197192014-07-19 15:00:29 -070074 */
Evan Charlton0e094d92014-11-08 15:49:16 -080075 @SystemApi
Evan Charlton10197192014-07-19 15:00:29 -070076 public static final String ACTION_CONNECTION_SERVICE_CONFIGURE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -070077 "android.telecom.action.CONNECTION_SERVICE_CONFIGURE";
Evan Charlton10197192014-07-19 15:00:29 -070078
79 /**
Andrew Lee873cfbf2015-02-26 15:22:00 -080080 * The {@link android.content.Intent} action used to show the call accessibility settings page.
81 */
82 public static final String ACTION_SHOW_CALL_ACCESSIBILITY_SETTINGS =
83 "android.telecom.action.SHOW_CALL_ACCESSIBILITY_SETTINGS";
84
85 /**
Yorke Lee3818a892014-07-21 15:57:17 -070086 * The {@link android.content.Intent} action used to show the call settings page.
87 */
88 public static final String ACTION_SHOW_CALL_SETTINGS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -070089 "android.telecom.action.SHOW_CALL_SETTINGS";
Yorke Lee3818a892014-07-21 15:57:17 -070090
91 /**
Andrew Lee866080f2015-02-19 12:05:33 -080092 * The {@link android.content.Intent} action used to show the respond via SMS settings page.
93 */
94 public static final String ACTION_SHOW_RESPOND_VIA_SMS_SETTINGS =
95 "android.telecom.action.SHOW_RESPOND_VIA_SMS_SETTINGS";
96
97 /**
Evan Charlton6d8604f2014-09-04 12:38:17 -070098 * The {@link android.content.Intent} action used to show the settings page used to configure
99 * {@link PhoneAccount} preferences.
Evan Charlton0e094d92014-11-08 15:49:16 -0800100 * @hide
Evan Charlton6d8604f2014-09-04 12:38:17 -0700101 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800102 @SystemApi
Evan Charlton6d8604f2014-09-04 12:38:17 -0700103 public static final String ACTION_CHANGE_PHONE_ACCOUNTS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700104 "android.telecom.action.CHANGE_PHONE_ACCOUNTS";
Evan Charlton6d8604f2014-09-04 12:38:17 -0700105
106 /**
Santos Cordonc66f3ba2015-02-27 15:22:07 -0800107 * The {@link android.content.Intent} action used indicate that a new phone account was
108 * just registered.
109 * @hide
110 */
111 @SystemApi
112 public static final String ACTION_PHONE_ACCOUNT_REGISTERED =
113 "android.telecom.action.PHONE_ACCOUNT_REGISTERED";
114
115 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700116 * Optional extra for {@link android.content.Intent#ACTION_CALL} containing a boolean that
117 * determines whether the speakerphone should be automatically turned on for an outgoing call.
Evan Charlton10197192014-07-19 15:00:29 -0700118 */
119 public static final String EXTRA_START_CALL_WITH_SPEAKERPHONE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700120 "android.telecom.extra.START_CALL_WITH_SPEAKERPHONE";
Evan Charlton10197192014-07-19 15:00:29 -0700121
122 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700123 * Optional extra for {@link android.content.Intent#ACTION_CALL} containing an integer that
124 * determines the desired video state for an outgoing call.
Santos Cordon96efb482014-07-19 14:57:05 -0700125 * Valid options:
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700126 * {@link VideoProfile.VideoState#AUDIO_ONLY},
127 * {@link VideoProfile.VideoState#BIDIRECTIONAL},
128 * {@link VideoProfile.VideoState#RX_ENABLED},
129 * {@link VideoProfile.VideoState#TX_ENABLED}.
Evan Charlton10197192014-07-19 15:00:29 -0700130 */
131 public static final String EXTRA_START_CALL_WITH_VIDEO_STATE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700132 "android.telecom.extra.START_CALL_WITH_VIDEO_STATE";
Evan Charlton10197192014-07-19 15:00:29 -0700133
134 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700135 * The extra used with an {@link android.content.Intent#ACTION_CALL} and
136 * {@link android.content.Intent#ACTION_DIAL} {@code Intent} to specify a
137 * {@link PhoneAccountHandle} to use when making the call.
Evan Charlton10197192014-07-19 15:00:29 -0700138 * <p class="note">
Santos Cordon96efb482014-07-19 14:57:05 -0700139 * Retrieve with {@link android.content.Intent#getParcelableExtra(String)}.
Evan Charlton10197192014-07-19 15:00:29 -0700140 */
Evan Charlton6eb262c2014-07-19 18:18:19 -0700141 public static final String EXTRA_PHONE_ACCOUNT_HANDLE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700142 "android.telecom.extra.PHONE_ACCOUNT_HANDLE";
Evan Charlton10197192014-07-19 15:00:29 -0700143
144 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700145 * Optional extra for {@link #ACTION_INCOMING_CALL} containing a {@link Bundle} which contains
146 * metadata about the call. This {@link Bundle} will be returned to the
147 * {@link ConnectionService}.
148 *
149 * @hide
Evan Charlton10197192014-07-19 15:00:29 -0700150 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800151 @SystemApi
Evan Charlton10197192014-07-19 15:00:29 -0700152 public static final String EXTRA_INCOMING_CALL_EXTRAS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700153 "android.telecom.extra.INCOMING_CALL_EXTRAS";
Evan Charlton10197192014-07-19 15:00:29 -0700154
155 /**
Nancy Chen10798dc2014-08-08 14:00:25 -0700156 * Optional extra for {@link android.content.Intent#ACTION_CALL} and
157 * {@link android.content.Intent#ACTION_DIAL} {@code Intent} containing a {@link Bundle}
158 * which contains metadata about the call. This {@link Bundle} will be saved into
159 * {@code Call.Details}.
Nancy Chen10798dc2014-08-08 14:00:25 -0700160 */
161 public static final String EXTRA_OUTGOING_CALL_EXTRAS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700162 "android.telecom.extra.OUTGOING_CALL_EXTRAS";
Nancy Chen10798dc2014-08-08 14:00:25 -0700163
164 /**
Yorke Leec3cf9822014-10-02 09:38:39 -0700165 * @hide
166 */
167 public static final String EXTRA_UNKNOWN_CALL_HANDLE =
168 "android.telecom.extra.UNKNOWN_CALL_HANDLE";
169
170 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700171 * Optional extra for {@link android.telephony.TelephonyManager#ACTION_PHONE_STATE_CHANGED}
172 * containing the disconnect code.
Evan Charlton10197192014-07-19 15:00:29 -0700173 */
174 public static final String EXTRA_CALL_DISCONNECT_CAUSE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700175 "android.telecom.extra.CALL_DISCONNECT_CAUSE";
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 disconnect message.
Evan Charlton10197192014-07-19 15:00:29 -0700180 */
181 public static final String EXTRA_CALL_DISCONNECT_MESSAGE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700182 "android.telecom.extra.CALL_DISCONNECT_MESSAGE";
Evan Charlton10197192014-07-19 15:00:29 -0700183
184 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700185 * Optional extra for {@link android.telephony.TelephonyManager#ACTION_PHONE_STATE_CHANGED}
186 * containing the component name of the associated connection service.
Evan Charlton0e094d92014-11-08 15:49:16 -0800187 * @hide
Evan Charlton10197192014-07-19 15:00:29 -0700188 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800189 @SystemApi
Evan Charlton10197192014-07-19 15:00:29 -0700190 public static final String EXTRA_CONNECTION_SERVICE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700191 "android.telecom.extra.CONNECTION_SERVICE";
Evan Charlton10197192014-07-19 15:00:29 -0700192
193 /**
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700194 * An optional {@link android.content.Intent#ACTION_CALL} intent extra denoting the
195 * package name of the app specifying an alternative gateway for the call.
196 * The value is a string.
197 *
198 * (The following comment corresponds to the all GATEWAY_* extras)
199 * An app which sends the {@link android.content.Intent#ACTION_CALL} intent can specify an
200 * alternative address to dial which is different from the one specified and displayed to
201 * the user. This alternative address is referred to as the gateway address.
202 */
203 public static final String GATEWAY_PROVIDER_PACKAGE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700204 "android.telecom.extra.GATEWAY_PROVIDER_PACKAGE";
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700205
206 /**
207 * An optional {@link android.content.Intent#ACTION_CALL} intent extra corresponding to the
208 * original address to dial for the call. This is used when an alternative gateway address is
209 * provided to recall the original address.
210 * The value is a {@link android.net.Uri}.
211 *
212 * (See {@link #GATEWAY_PROVIDER_PACKAGE} for details)
213 */
214 public static final String GATEWAY_ORIGINAL_ADDRESS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700215 "android.telecom.extra.GATEWAY_ORIGINAL_ADDRESS";
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700216
217 /**
Evan Charlton10197192014-07-19 15:00:29 -0700218 * The number which the party on the other side of the line will see (and use to return the
219 * call).
220 * <p>
Santos Cordon96efb482014-07-19 14:57:05 -0700221 * {@link ConnectionService}s which interact with {@link RemoteConnection}s should only populate
222 * this if the {@link android.telephony.TelephonyManager#getLine1Number()} value, as that is the
223 * user's expected caller ID.
Evan Charlton0e094d92014-11-08 15:49:16 -0800224 * @hide
Evan Charlton10197192014-07-19 15:00:29 -0700225 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800226 @SystemApi
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700227 public static final String EXTRA_CALL_BACK_NUMBER = "android.telecom.extra.CALL_BACK_NUMBER";
Evan Charlton10197192014-07-19 15:00:29 -0700228
229 /**
230 * The dual tone multi-frequency signaling character sent to indicate the dialing system should
231 * pause for a predefined period.
232 */
233 public static final char DTMF_CHARACTER_PAUSE = ',';
234
235 /**
236 * The dual-tone multi-frequency signaling character sent to indicate the dialing system should
237 * wait for user confirmation before proceeding.
238 */
239 public static final char DTMF_CHARACTER_WAIT = ';';
240
241 /**
242 * TTY (teletypewriter) mode is off.
243 *
244 * @hide
245 */
246 public static final int TTY_MODE_OFF = 0;
247
248 /**
249 * TTY (teletypewriter) mode is on. The speaker is off and the microphone is muted. The user
250 * will communicate with the remote party by sending and receiving text messages.
251 *
252 * @hide
253 */
254 public static final int TTY_MODE_FULL = 1;
255
256 /**
257 * TTY (teletypewriter) mode is in hearing carryover mode (HCO). The microphone is muted but the
258 * speaker is on. The user will communicate with the remote party by sending text messages and
259 * hearing an audible reply.
260 *
261 * @hide
262 */
263 public static final int TTY_MODE_HCO = 2;
264
265 /**
266 * TTY (teletypewriter) mode is in voice carryover mode (VCO). The speaker is off but the
267 * microphone is still on. User will communicate with the remote party by speaking and receiving
268 * text message replies.
269 *
270 * @hide
271 */
272 public static final int TTY_MODE_VCO = 3;
273
274 /**
275 * Broadcast intent action indicating that the current TTY mode has changed. An intent extra
276 * provides this state as an int.
Evan Charlton10197192014-07-19 15:00:29 -0700277 *
Santos Cordon96efb482014-07-19 14:57:05 -0700278 * @see #EXTRA_CURRENT_TTY_MODE
Evan Charlton10197192014-07-19 15:00:29 -0700279 * @hide
280 */
281 public static final String ACTION_CURRENT_TTY_MODE_CHANGED =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700282 "android.telecom.action.CURRENT_TTY_MODE_CHANGED";
Evan Charlton10197192014-07-19 15:00:29 -0700283
284 /**
285 * The lookup key for an int that indicates the current TTY mode.
286 * Valid modes are:
287 * - {@link #TTY_MODE_OFF}
288 * - {@link #TTY_MODE_FULL}
289 * - {@link #TTY_MODE_HCO}
290 * - {@link #TTY_MODE_VCO}
291 *
292 * @hide
293 */
294 public static final String EXTRA_CURRENT_TTY_MODE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700295 "android.telecom.intent.extra.CURRENT_TTY_MODE";
Evan Charlton10197192014-07-19 15:00:29 -0700296
297 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700298 * Broadcast intent action indicating that the TTY preferred operating mode has changed. An
299 * intent extra provides the new mode as an int.
Evan Charlton10197192014-07-19 15:00:29 -0700300 *
Santos Cordon96efb482014-07-19 14:57:05 -0700301 * @see #EXTRA_TTY_PREFERRED_MODE
Evan Charlton10197192014-07-19 15:00:29 -0700302 * @hide
303 */
304 public static final String ACTION_TTY_PREFERRED_MODE_CHANGED =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700305 "android.telecom.action.TTY_PREFERRED_MODE_CHANGED";
Evan Charlton10197192014-07-19 15:00:29 -0700306
307 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700308 * The lookup key for an int that indicates preferred TTY mode. Valid modes are: -
309 * {@link #TTY_MODE_OFF} - {@link #TTY_MODE_FULL} - {@link #TTY_MODE_HCO} -
310 * {@link #TTY_MODE_VCO}
Evan Charlton10197192014-07-19 15:00:29 -0700311 *
312 * @hide
313 */
314 public static final String EXTRA_TTY_PREFERRED_MODE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700315 "android.telecom.intent.extra.TTY_PREFERRED";
Evan Charlton10197192014-07-19 15:00:29 -0700316
Nancy Chen9d568c02014-09-08 14:17:59 -0700317 /**
318 * The following 4 constants define how properties such as phone numbers and names are
319 * displayed to the user.
320 */
321
322 /** Property is displayed normally. */
323 public static final int PRESENTATION_ALLOWED = 1;
324
325 /** Property was blocked. */
326 public static final int PRESENTATION_RESTRICTED = 2;
327
328 /** Presentation was not specified or is unknown. */
329 public static final int PRESENTATION_UNKNOWN = 3;
330
331 /** Property should be displayed as a pay phone. */
332 public static final int PRESENTATION_PAYPHONE = 4;
333
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700334 private static final String TAG = "TelecomManager";
Yorke Leeb4ce1432014-06-09 13:53:23 -0700335
336 private final Context mContext;
Yorke Leeb4ce1432014-06-09 13:53:23 -0700337
Santos Cordon6c7a3882014-06-25 15:30:08 -0700338 /**
339 * @hide
340 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700341 public static TelecomManager from(Context context) {
342 return (TelecomManager) context.getSystemService(Context.TELECOM_SERVICE);
Yorke Leeb4ce1432014-06-09 13:53:23 -0700343 }
Santos Cordon6c7a3882014-06-25 15:30:08 -0700344
345 /**
346 * @hide
347 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700348 public TelecomManager(Context context) {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700349 Context appContext = context.getApplicationContext();
350 if (appContext != null) {
351 mContext = appContext;
352 } else {
353 mContext = context;
354 }
355 }
356
357 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700358 * Return the {@link PhoneAccount} which is the user-chosen default for making outgoing phone
Nancy Chen513c8922014-09-17 14:47:20 -0700359 * calls with a specified URI scheme.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700360 * <p>
Santos Cordon96efb482014-07-19 14:57:05 -0700361 * Apps must be prepared for this method to return {@code null}, indicating that there currently
Nancy Chen513c8922014-09-17 14:47:20 -0700362 * exists no user-chosen default {@code PhoneAccount}.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700363 * <p>
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700364 * @param uriScheme The URI scheme.
Nancy Chen513c8922014-09-17 14:47:20 -0700365 * @return The {@link PhoneAccountHandle} corresponding to the user-chosen default for outgoing
366 * phone calls for a specified URI scheme.
Evan Charlton0e094d92014-11-08 15:49:16 -0800367 * @hide
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700368 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800369 @SystemApi
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700370 public PhoneAccountHandle getDefaultOutgoingPhoneAccount(String uriScheme) {
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700371 try {
372 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700373 return getTelecomService().getDefaultOutgoingPhoneAccount(uriScheme);
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700374 }
375 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700376 Log.e(TAG, "Error calling ITelecomService#getDefaultOutgoingPhoneAccount", e);
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700377 }
378 return null;
379 }
380
381 /**
Andrew Leed4abbfb2014-09-03 14:58:27 -0700382 * Return the {@link PhoneAccount} which is the user-chosen default for making outgoing phone
383 * calls. This {@code PhoneAccount} will always be a member of the list which is returned from
Nancy Chen210ef032014-09-15 17:58:42 -0700384 * calling {@link #getCallCapablePhoneAccounts()}
Andrew Leed4abbfb2014-09-03 14:58:27 -0700385 *
386 * Apps must be prepared for this method to return {@code null}, indicating that there currently
387 * exists no user-chosen default {@code PhoneAccount}.
388 *
389 * @return The user outgoing phone account selected by the user.
390 * @hide
391 */
392 public PhoneAccountHandle getUserSelectedOutgoingPhoneAccount() {
393 try {
394 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700395 return getTelecomService().getUserSelectedOutgoingPhoneAccount();
Andrew Leed4abbfb2014-09-03 14:58:27 -0700396 }
397 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700398 Log.e(TAG, "Error calling ITelecomService#getUserSelectedOutgoingPhoneAccount", e);
Andrew Leed4abbfb2014-09-03 14:58:27 -0700399 }
400 return null;
401 }
402
403 /**
Andrew Lee59cac3a2014-08-28 16:50:10 -0700404 * Sets the default account for making outgoing phone calls.
405 * @hide
406 */
Andrew Leed4abbfb2014-09-03 14:58:27 -0700407 public void setUserSelectedOutgoingPhoneAccount(PhoneAccountHandle accountHandle) {
Andrew Lee59cac3a2014-08-28 16:50:10 -0700408 try {
409 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700410 getTelecomService().setUserSelectedOutgoingPhoneAccount(accountHandle);
Andrew Lee59cac3a2014-08-28 16:50:10 -0700411 }
412 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700413 Log.e(TAG, "Error calling ITelecomService#setUserSelectedOutgoingPhoneAccount");
Andrew Lee59cac3a2014-08-28 16:50:10 -0700414 }
415 }
416
417 /**
Andrew Lee59cac3a2014-08-28 16:50:10 -0700418 * Returns the current SIM call manager. Apps must be prepared for this method to return
419 * {@code null}, indicating that there currently exists no user-chosen default
420 * {@code PhoneAccount}.
421 * @return The phone account handle of the current sim call manager.
422 * @hide
423 */
424 public PhoneAccountHandle getSimCallManager() {
425 try {
426 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700427 return getTelecomService().getSimCallManager();
Andrew Lee59cac3a2014-08-28 16:50:10 -0700428 }
429 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700430 Log.e(TAG, "Error calling ITelecomService#getSimCallManager");
Andrew Lee59cac3a2014-08-28 16:50:10 -0700431 }
432 return null;
433 }
434
435 /**
436 * Sets the SIM call manager to the specified phone account.
437 * @param accountHandle The phone account handle of the account to set as the sim call manager.
438 * @hide
439 */
440 public void setSimCallManager(PhoneAccountHandle accountHandle) {
441 try {
442 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700443 getTelecomService().setSimCallManager(accountHandle);
Andrew Lee59cac3a2014-08-28 16:50:10 -0700444 }
445 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700446 Log.e(TAG, "Error calling ITelecomService#setSimCallManager");
Andrew Lee59cac3a2014-08-28 16:50:10 -0700447 }
448 }
449
450 /**
451 * Returns the list of registered SIM call managers.
452 * @return List of registered SIM call managers.
453 * @hide
454 */
455 public List<PhoneAccountHandle> getSimCallManagers() {
456 try {
457 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700458 return getTelecomService().getSimCallManagers();
Andrew Lee59cac3a2014-08-28 16:50:10 -0700459 }
460 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700461 Log.e(TAG, "Error calling ITelecomService#getSimCallManagers");
Andrew Lee59cac3a2014-08-28 16:50:10 -0700462 }
463 return new ArrayList<>();
464 }
465
466 /**
Evan Charltoneb0a8d52014-09-04 12:03:34 -0700467 * Returns the current connection manager. Apps must be prepared for this method to return
468 * {@code null}, indicating that there currently exists no user-chosen default
469 * {@code PhoneAccount}.
470 *
471 * @return The phone account handle of the current connection manager.
Evan Charlton0e094d92014-11-08 15:49:16 -0800472 * @hide
Evan Charltoneb0a8d52014-09-04 12:03:34 -0700473 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800474 @SystemApi
Evan Charltoneb0a8d52014-09-04 12:03:34 -0700475 public PhoneAccountHandle getConnectionManager() {
476 return getSimCallManager();
477 }
478
479 /**
Sailesh Nepal7a4e3872014-11-21 11:01:40 -0800480 * Returns the list of registered SIM call managers.
481 * @return List of registered SIM call managers.
482 * @hide
483 */
484 @SystemApi
485 public List<PhoneAccountHandle> getRegisteredConnectionManagers() {
486 return getSimCallManagers();
487 }
488
489 /**
Nancy Chen210ef032014-09-15 17:58:42 -0700490 * Returns a list of the {@link PhoneAccountHandle}s which can be used to make and receive phone
491 * calls which support the specified URI scheme.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700492 * <P>
493 * For example, invoking with {@code "tel"} will find all {@link PhoneAccountHandle}s which
494 * support telephone calls (e.g. URIs such as {@code tel:555-555-1212}). Invoking with
495 * {@code "sip"} will find all {@link PhoneAccountHandle}s which support SIP calls (e.g. URIs
496 * such as {@code sip:example@sipexample.com}).
497 *
498 * @param uriScheme The URI scheme.
499 * @return A list of {@code PhoneAccountHandle} objects supporting the URI scheme.
Evan Charlton0e094d92014-11-08 15:49:16 -0800500 * @hide
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700501 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800502 @SystemApi
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700503 public List<PhoneAccountHandle> getPhoneAccountsSupportingScheme(String uriScheme) {
504 try {
505 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700506 return getTelecomService().getPhoneAccountsSupportingScheme(uriScheme);
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700507 }
508 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700509 Log.e(TAG, "Error calling ITelecomService#getPhoneAccountsSupportingScheme", e);
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700510 }
511 return new ArrayList<>();
512 }
513
Nancy Chen513c8922014-09-17 14:47:20 -0700514
515 /**
516 * Return a list of {@link PhoneAccountHandle}s which can be used to make and receive phone
517 * calls.
518 *
519 * @see #EXTRA_PHONE_ACCOUNT_HANDLE
520 * @return A list of {@code PhoneAccountHandle} objects.
521 *
522 * @hide
523 */
524 public List<PhoneAccountHandle> getCallCapablePhoneAccounts() {
525 try {
526 if (isServiceConnected()) {
527 return getTelecomService().getCallCapablePhoneAccounts();
528 }
529 } catch (RemoteException e) {
530 Log.e(TAG, "Error calling ITelecomService#getCallCapablePhoneAccounts", e);
531 }
532 return new ArrayList<>();
533 }
534
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700535 /**
Nancy Chen210ef032014-09-15 17:58:42 -0700536 * Determine whether the device has more than one account registered that can make and receive
537 * phone calls.
Nancy Chen60801182014-07-22 16:56:49 -0700538 *
Nancy Chen210ef032014-09-15 17:58:42 -0700539 * @return {@code true} if the device has more than one account registered and {@code false}
540 * otherwise.
Evan Charlton0e094d92014-11-08 15:49:16 -0800541 * @hide
Nancy Chen60801182014-07-22 16:56:49 -0700542 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800543 @SystemApi
Nancy Chen210ef032014-09-15 17:58:42 -0700544 public boolean hasMultipleCallCapableAccounts() {
545 return getCallCapablePhoneAccounts().size() > 1;
Nancy Chen60801182014-07-22 16:56:49 -0700546 }
547
548 /**
Nancy Chen513c8922014-09-17 14:47:20 -0700549 * Returns a list of all {@link PhoneAccount}s registered for the calling package.
550 *
551 * @return A list of {@code PhoneAccountHandle} objects.
Evan Charlton0e094d92014-11-08 15:49:16 -0800552 * @hide
Nancy Chen513c8922014-09-17 14:47:20 -0700553 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800554 @SystemApi
Nancy Chen513c8922014-09-17 14:47:20 -0700555 public List<PhoneAccountHandle> getPhoneAccountsForPackage() {
556 try {
557 if (isServiceConnected()) {
558 return getTelecomService().getPhoneAccountsForPackage(mContext.getPackageName());
559 }
560 } catch (RemoteException e) {
561 Log.e(TAG, "Error calling ITelecomService#getPhoneAccountsForPackage", e);
562 }
563 return null;
564 }
565
566 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700567 * Return the {@link PhoneAccount} for a specified {@link PhoneAccountHandle}. Object includes
568 * resources which can be used in a user interface.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700569 *
Evan Charlton6eb262c2014-07-19 18:18:19 -0700570 * @param account The {@link PhoneAccountHandle}.
Evan Charlton8c8a0622014-07-20 12:31:00 -0700571 * @return The {@link PhoneAccount} object.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700572 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700573 public PhoneAccount getPhoneAccount(PhoneAccountHandle account) {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700574 try {
575 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700576 return getTelecomService().getPhoneAccount(account);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700577 }
578 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700579 Log.e(TAG, "Error calling ITelecomService#getPhoneAccount", e);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700580 }
581 return null;
582 }
583
584 /**
Nancy Chen210ef032014-09-15 17:58:42 -0700585 * Returns a count of all {@link PhoneAccount}s.
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700586 *
Nancy Chen210ef032014-09-15 17:58:42 -0700587 * @return The count of {@link PhoneAccount}s.
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700588 * @hide
589 */
590 @SystemApi
591 public int getAllPhoneAccountsCount() {
592 try {
593 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700594 return getTelecomService().getAllPhoneAccountsCount();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700595 }
596 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700597 Log.e(TAG, "Error calling ITelecomService#getAllPhoneAccountsCount", e);
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700598 }
599 return 0;
600 }
601
602 /**
603 * Returns a list of all {@link PhoneAccount}s.
604 *
605 * @return All {@link PhoneAccount}s.
606 * @hide
607 */
608 @SystemApi
609 public List<PhoneAccount> getAllPhoneAccounts() {
610 try {
611 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700612 return getTelecomService().getAllPhoneAccounts();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700613 }
614 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700615 Log.e(TAG, "Error calling ITelecomService#getAllPhoneAccounts", e);
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700616 }
617 return Collections.EMPTY_LIST;
618 }
619
620 /**
621 * Returns a list of all {@link PhoneAccountHandle}s.
622 *
623 * @return All {@link PhoneAccountHandle}s.
624 * @hide
625 */
626 @SystemApi
627 public List<PhoneAccountHandle> getAllPhoneAccountHandles() {
628 try {
629 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700630 return getTelecomService().getAllPhoneAccountHandles();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700631 }
632 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700633 Log.e(TAG, "Error calling ITelecomService#getAllPhoneAccountHandles", e);
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700634 }
635 return Collections.EMPTY_LIST;
636 }
637
638 /**
Santos Cordond9e614f2014-10-28 13:10:36 -0700639 * Register a {@link PhoneAccount} for use by the system. When registering
640 * {@link PhoneAccount}s, existing registrations will be overwritten if the
641 * {@link PhoneAccountHandle} matches that of a {@link PhoneAccount} which is already
642 * registered. Once registered, the {@link PhoneAccount} is listed to the user as an option
643 * when placing calls. The user may still need to enable the {@link PhoneAccount} within
644 * the phone app settings before the account is usable.
645 * <p>
646 * A {@link SecurityException} will be thrown if an app tries to register a
647 * {@link PhoneAccountHandle} where the package name specified within
648 * {@link PhoneAccountHandle#getComponentName()} does not match the package name of the app.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700649 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700650 * @param account The complete {@link PhoneAccount}.
Evan Charlton0e094d92014-11-08 15:49:16 -0800651 *
652 * @hide
Ihab Awad807fe0a2014-07-09 12:30:52 -0700653 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800654 @SystemApi
Evan Charlton8c8a0622014-07-20 12:31:00 -0700655 public void registerPhoneAccount(PhoneAccount account) {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700656 try {
657 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700658 getTelecomService().registerPhoneAccount(account);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700659 }
660 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700661 Log.e(TAG, "Error calling ITelecomService#registerPhoneAccount", e);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700662 }
663 }
664
665 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700666 * Remove a {@link PhoneAccount} registration from the system.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700667 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700668 * @param accountHandle A {@link PhoneAccountHandle} for the {@link PhoneAccount} to unregister.
Evan Charlton0e094d92014-11-08 15:49:16 -0800669 * @hide
Ihab Awad807fe0a2014-07-09 12:30:52 -0700670 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800671 @SystemApi
Evan Charlton8c8a0622014-07-20 12:31:00 -0700672 public void unregisterPhoneAccount(PhoneAccountHandle accountHandle) {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700673 try {
674 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700675 getTelecomService().unregisterPhoneAccount(accountHandle);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700676 }
677 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700678 Log.e(TAG, "Error calling ITelecomService#unregisterPhoneAccount", e);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700679 }
680 }
681
682 /**
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700683 * Remove all Accounts that belong to the calling package from the system.
Evan Charlton0e094d92014-11-08 15:49:16 -0800684 * @hide
Ihab Awad807fe0a2014-07-09 12:30:52 -0700685 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800686 @SystemApi
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700687 public void clearAccounts() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700688 try {
689 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700690 getTelecomService().clearAccounts(mContext.getPackageName());
Ihab Awad807fe0a2014-07-09 12:30:52 -0700691 }
692 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700693 Log.e(TAG, "Error calling ITelecomService#clearAccounts", e);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700694 }
695 }
696
697 /**
Anthony Lee67279262014-10-27 11:28:40 -0700698 * Remove all Accounts that belong to the specified package from the system.
699 * @hide
700 */
701 public void clearAccountsForPackage(String packageName) {
702 try {
703 if (isServiceConnected() && !TextUtils.isEmpty(packageName)) {
704 getTelecomService().clearAccounts(packageName);
705 }
706 } catch (RemoteException e) {
Nancy Chen5cf27842015-01-24 23:30:27 -0800707 Log.e(TAG, "Error calling ITelecomService#clearAccountsForPackage", e);
Anthony Lee67279262014-10-27 11:28:40 -0700708 }
709 }
710
711 /**
Ihab Awad807fe0a2014-07-09 12:30:52 -0700712 * @hide
713 */
Santos Cordon6c7a3882014-06-25 15:30:08 -0700714 @SystemApi
715 public ComponentName getDefaultPhoneApp() {
716 try {
Santos Cordon9eb45932014-06-27 12:28:43 -0700717 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700718 return getTelecomService().getDefaultPhoneApp();
Santos Cordon9eb45932014-06-27 12:28:43 -0700719 }
Santos Cordon6c7a3882014-06-25 15:30:08 -0700720 } catch (RemoteException e) {
721 Log.e(TAG, "RemoteException attempting to get the default phone app.", e);
722 }
723 return null;
724 }
725
Santos Cordon9eb45932014-06-27 12:28:43 -0700726 /**
Nancy Chen443e5012014-10-15 15:48:21 -0700727 * Return whether a given phone number is the configured voicemail number for a
728 * particular phone account.
729 *
730 * @param accountHandle The handle for the account to check the voicemail number against
731 * @param number The number to look up.
732 *
733 * @hide
734 */
735 @SystemApi
736 public boolean isVoiceMailNumber(PhoneAccountHandle accountHandle, String number) {
737 try {
738 if (isServiceConnected()) {
739 return getTelecomService().isVoiceMailNumber(accountHandle, number);
740 }
741 } catch (RemoteException e) {
Nancy Chen5cf27842015-01-24 23:30:27 -0800742 Log.e(TAG, "RemoteException calling ITelecomService#isVoiceMailNumber.", e);
Nancy Chen443e5012014-10-15 15:48:21 -0700743 }
744 return false;
745 }
746
747 /**
Nancy Chen8c066f72014-12-03 15:18:08 -0800748 * Return whether a given phone account has a voicemail number configured.
749 *
750 * @param accountHandle The handle for the account to check for a voicemail number.
751 * @return {@code true} If the given phone account has a voicemail number.
752 *
753 * @hide
754 */
755 @SystemApi
756 public boolean hasVoiceMailNumber(PhoneAccountHandle accountHandle) {
757 try {
758 if (isServiceConnected()) {
759 return getTelecomService().hasVoiceMailNumber(accountHandle);
760 }
761 } catch (RemoteException e) {
Nancy Chen5cf27842015-01-24 23:30:27 -0800762 Log.e(TAG, "RemoteException calling ITelecomService#hasVoiceMailNumber.", e);
Nancy Chen8c066f72014-12-03 15:18:08 -0800763 }
764 return false;
765 }
766
767 /**
Nancy Chen5cf27842015-01-24 23:30:27 -0800768 * Return the line 1 phone number for given phone account.
769 *
770 * @param accountHandle The handle for the account retrieve a number for.
771 * @return A string representation of the line 1 phone number.
772 *
773 * @hide
774 */
775 @SystemApi
776 public String getLine1Number(PhoneAccountHandle accountHandle) {
777 try {
778 if (isServiceConnected()) {
779 return getTelecomService().getLine1Number(accountHandle);
780 }
781 } catch (RemoteException e) {
782 Log.e(TAG, "RemoteException calling ITelecomService#getLine1Number.", e);
783 }
784 return null;
785 }
786
787 /**
Santos Cordon9eb45932014-06-27 12:28:43 -0700788 * Returns whether there is an ongoing phone call (can be in dialing, ringing, active or holding
789 * states).
Nancy Chen0eb1e402014-08-21 22:52:29 -0700790 * <p>
791 * Requires permission: {@link android.Manifest.permission#READ_PHONE_STATE}
792 * </p>
Santos Cordon9eb45932014-06-27 12:28:43 -0700793 */
Nancy Chen0eb1e402014-08-21 22:52:29 -0700794 public boolean isInCall() {
Santos Cordon9eb45932014-06-27 12:28:43 -0700795 try {
796 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700797 return getTelecomService().isInCall();
Santos Cordon9eb45932014-06-27 12:28:43 -0700798 }
799 } catch (RemoteException e) {
Yorke Lee2ae312e2014-09-12 17:58:48 -0700800 Log.e(TAG, "RemoteException calling isInCall().", e);
Santos Cordon9eb45932014-06-27 12:28:43 -0700801 }
802 return false;
803 }
804
805 /**
Yorke Lee2ae312e2014-09-12 17:58:48 -0700806 * Returns one of the following constants that represents the current state of Telecom:
807 *
808 * {@link TelephonyManager#CALL_STATE_RINGING}
809 * {@link TelephonyManager#CALL_STATE_OFFHOOK}
810 * {@link TelephonyManager#CALL_STATE_IDLE}
Yorke Lee7c72c2d2014-10-28 14:12:02 -0700811 *
812 * Note that this API does not require the
813 * {@link android.Manifest.permission#READ_PHONE_STATE} permission. This is intentional, to
814 * preserve the behavior of {@link TelephonyManager#getCallState()}, which also did not require
815 * the permission.
Yorke Lee2ae312e2014-09-12 17:58:48 -0700816 * @hide
817 */
818 @SystemApi
819 public int getCallState() {
820 try {
821 if (isServiceConnected()) {
822 return getTelecomService().getCallState();
823 }
824 } catch (RemoteException e) {
825 Log.d(TAG, "RemoteException calling getCallState().", e);
826 }
827 return TelephonyManager.CALL_STATE_IDLE;
828 }
829
830 /**
Santos Cordon9eb45932014-06-27 12:28:43 -0700831 * Returns whether there currently exists is a ringing incoming-call.
832 *
833 * @hide
834 */
835 @SystemApi
836 public boolean isRinging() {
837 try {
838 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700839 return getTelecomService().isRinging();
Santos Cordon9eb45932014-06-27 12:28:43 -0700840 }
841 } catch (RemoteException e) {
842 Log.e(TAG, "RemoteException attempting to get ringing state of phone app.", e);
843 }
844 return false;
845 }
846
847 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700848 * Ends an ongoing call.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700849 * TODO: L-release - need to convert all invocations of ITelecomService#endCall to use this
Santos Cordon96efb482014-07-19 14:57:05 -0700850 * method (clockwork & gearhead).
Santos Cordon9eb45932014-06-27 12:28:43 -0700851 * @hide
852 */
853 @SystemApi
854 public boolean endCall() {
855 try {
856 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700857 return getTelecomService().endCall();
Santos Cordon9eb45932014-06-27 12:28:43 -0700858 }
859 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700860 Log.e(TAG, "Error calling ITelecomService#endCall", e);
Santos Cordon9eb45932014-06-27 12:28:43 -0700861 }
862 return false;
863 }
864
865 /**
866 * If there is a ringing incoming call, this method accepts the call on behalf of the user.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700867 * TODO: L-release - need to convert all invocation of ITelecmmService#answerRingingCall to use
Santos Cordon96efb482014-07-19 14:57:05 -0700868 * this method (clockwork & gearhead).
Santos Cordon9eb45932014-06-27 12:28:43 -0700869 *
870 * @hide
871 */
872 @SystemApi
873 public void acceptRingingCall() {
874 try {
875 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700876 getTelecomService().acceptRingingCall();
Santos Cordon9eb45932014-06-27 12:28:43 -0700877 }
878 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700879 Log.e(TAG, "Error calling ITelecomService#acceptRingingCall", e);
Santos Cordon9eb45932014-06-27 12:28:43 -0700880 }
881 }
882
883 /**
884 * Silences the ringer if a ringing call exists.
885 *
886 * @hide
887 */
888 @SystemApi
889 public void silenceRinger() {
890 try {
891 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700892 getTelecomService().silenceRinger();
Santos Cordon9eb45932014-06-27 12:28:43 -0700893 }
894 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700895 Log.e(TAG, "Error calling ITelecomService#silenceRinger", e);
Santos Cordon9eb45932014-06-27 12:28:43 -0700896 }
897 }
898
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700899 /**
900 * Returns whether TTY is supported on this device.
901 *
902 * @hide
903 */
904 @SystemApi
905 public boolean isTtySupported() {
906 try {
907 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700908 return getTelecomService().isTtySupported();
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700909 }
910 } catch (RemoteException e) {
911 Log.e(TAG, "RemoteException attempting to get TTY supported state.", e);
912 }
913 return false;
914 }
915
916 /**
917 * 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 -0700918 * settings and have a wired headset plugged in.
919 * Valid modes are:
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700920 * - {@link TelecomManager#TTY_MODE_OFF}
921 * - {@link TelecomManager#TTY_MODE_FULL}
922 * - {@link TelecomManager#TTY_MODE_HCO}
923 * - {@link TelecomManager#TTY_MODE_VCO}
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700924 * @hide
925 */
926 public int getCurrentTtyMode() {
927 try {
928 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700929 return getTelecomService().getCurrentTtyMode();
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700930 }
931 } catch (RemoteException e) {
932 Log.e(TAG, "RemoteException attempting to get the current TTY mode.", e);
933 }
Evan Charlton10197192014-07-19 15:00:29 -0700934 return TTY_MODE_OFF;
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700935 }
936
Santos Cordon96efb482014-07-19 14:57:05 -0700937 /**
938 * Registers a new incoming call. A {@link ConnectionService} should invoke this method when it
939 * has an incoming call. The specified {@link PhoneAccountHandle} must have been registered
Nancy Chen210ef032014-09-15 17:58:42 -0700940 * with {@link #registerPhoneAccount}. Once invoked, this method will cause the system to bind
941 * to the {@link ConnectionService} associated with the {@link PhoneAccountHandle} and request
Santos Cordon96efb482014-07-19 14:57:05 -0700942 * additional information about the call (See
943 * {@link ConnectionService#onCreateIncomingConnection}) before starting the incoming call UI.
944 *
945 * @param phoneAccount A {@link PhoneAccountHandle} registered with
946 * {@link #registerPhoneAccount}.
947 * @param extras A bundle that will be passed through to
948 * {@link ConnectionService#onCreateIncomingConnection}.
Evan Charlton0e094d92014-11-08 15:49:16 -0800949 * @hide
Santos Cordon96efb482014-07-19 14:57:05 -0700950 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800951 @SystemApi
Santos Cordon96efb482014-07-19 14:57:05 -0700952 public void addNewIncomingCall(PhoneAccountHandle phoneAccount, Bundle extras) {
953 try {
954 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700955 getTelecomService().addNewIncomingCall(
Santos Cordon96efb482014-07-19 14:57:05 -0700956 phoneAccount, extras == null ? new Bundle() : extras);
957 }
958 } catch (RemoteException e) {
959 Log.e(TAG, "RemoteException adding a new incoming call: " + phoneAccount, e);
960 }
961 }
962
Nancy Chen0eb1e402014-08-21 22:52:29 -0700963 /**
Yorke Leec3cf9822014-10-02 09:38:39 -0700964 * Registers a new unknown call with Telecom. This can only be called by the system Telephony
965 * service. This is invoked when Telephony detects a new unknown connection that was neither
966 * a new incoming call, nor an user-initiated outgoing call.
967 *
968 * @param phoneAccount A {@link PhoneAccountHandle} registered with
969 * {@link #registerPhoneAccount}.
970 * @param extras A bundle that will be passed through to
971 * {@link ConnectionService#onCreateIncomingConnection}.
972 * @hide
973 */
974 @SystemApi
975 public void addNewUnknownCall(PhoneAccountHandle phoneAccount, Bundle extras) {
976 try {
977 if (isServiceConnected()) {
978 getTelecomService().addNewUnknownCall(
979 phoneAccount, extras == null ? new Bundle() : extras);
980 }
981 } catch (RemoteException e) {
982 Log.e(TAG, "RemoteException adding a new unknown call: " + phoneAccount, e);
983 }
984 }
985
986 /**
Nancy Chen0eb1e402014-08-21 22:52:29 -0700987 * Processes the specified dial string as an MMI code.
988 * MMI codes are any sequence of characters entered into the dialpad that contain a "*" or "#".
989 * Some of these sequences launch special behavior through handled by Telephony.
Nancy Chen95e8a672014-10-16 18:38:21 -0700990 * This method uses the default subscription.
Nancy Chen0eb1e402014-08-21 22:52:29 -0700991 * <p>
992 * Requires that the method-caller be set as the system dialer app.
993 * </p>
994 *
995 * @param dialString The digits to dial.
996 * @return True if the digits were processed as an MMI code, false otherwise.
997 */
998 public boolean handleMmi(String dialString) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700999 ITelecomService service = getTelecomService();
Nancy Chen0eb1e402014-08-21 22:52:29 -07001000 if (service != null) {
1001 try {
1002 return service.handlePinMmi(dialString);
1003 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001004 Log.e(TAG, "Error calling ITelecomService#handlePinMmi", e);
Nancy Chen0eb1e402014-08-21 22:52:29 -07001005 }
1006 }
1007 return false;
1008 }
1009
1010 /**
Nancy Chen95e8a672014-10-16 18:38:21 -07001011 * Processes the specified dial string as an MMI code.
1012 * MMI codes are any sequence of characters entered into the dialpad that contain a "*" or "#".
1013 * Some of these sequences launch special behavior through handled by Telephony.
1014 * <p>
1015 * Requires that the method-caller be set as the system dialer app.
1016 * </p>
1017 *
1018 * @param accountHandle The handle for the account the MMI code should apply to.
1019 * @param dialString The digits to dial.
1020 * @return True if the digits were processed as an MMI code, false otherwise.
Evan Charlton0e094d92014-11-08 15:49:16 -08001021 * @hide
Nancy Chen95e8a672014-10-16 18:38:21 -07001022 */
Evan Charlton0e094d92014-11-08 15:49:16 -08001023 @SystemApi
Nancy Chen95e8a672014-10-16 18:38:21 -07001024 public boolean handleMmi(PhoneAccountHandle accountHandle, String dialString) {
1025 ITelecomService service = getTelecomService();
1026 if (service != null) {
1027 try {
1028 return service.handlePinMmiForPhoneAccount(accountHandle, dialString);
1029 } catch (RemoteException e) {
1030 Log.e(TAG, "Error calling ITelecomService#handlePinMmi", e);
1031 }
1032 }
1033 return false;
1034 }
1035
1036 /**
Nancy Chenb2299c12014-10-29 18:22:11 -07001037 * @param accountHandle The handle for the account to derive an adn query URI for or
1038 * {@code null} to return a URI which will use the default account.
1039 * @return The URI (with the content:// scheme) specific to the specified {@link PhoneAccount}
1040 * for the the content retrieve.
Evan Charlton0e094d92014-11-08 15:49:16 -08001041 * @hide
Nancy Chenb2299c12014-10-29 18:22:11 -07001042 */
Evan Charlton0e094d92014-11-08 15:49:16 -08001043 @SystemApi
Nancy Chenb2299c12014-10-29 18:22:11 -07001044 public Uri getAdnUriForPhoneAccount(PhoneAccountHandle accountHandle) {
1045 ITelecomService service = getTelecomService();
1046 if (service != null && accountHandle != null) {
1047 try {
1048 return service.getAdnUriForPhoneAccount(accountHandle);
1049 } catch (RemoteException e) {
1050 Log.e(TAG, "Error calling ITelecomService#getAdnUriForPhoneAccount", e);
1051 }
1052 }
1053 return Uri.parse("content://icc/adn");
1054 }
1055
1056 /**
Nancy Chen0eb1e402014-08-21 22:52:29 -07001057 * Removes the missed-call notification if one is present.
1058 * <p>
1059 * Requires that the method-caller be set as the system dialer app.
1060 * </p>
1061 */
1062 public void cancelMissedCallsNotification() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001063 ITelecomService service = getTelecomService();
Nancy Chen0eb1e402014-08-21 22:52:29 -07001064 if (service != null) {
1065 try {
1066 service.cancelMissedCallsNotification();
1067 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001068 Log.e(TAG, "Error calling ITelecomService#cancelMissedCallsNotification", e);
Nancy Chen0eb1e402014-08-21 22:52:29 -07001069 }
1070 }
1071 }
1072
1073 /**
1074 * Brings the in-call screen to the foreground if there is an ongoing call. If there is
1075 * currently no ongoing call, then this method does nothing.
1076 * <p>
1077 * Requires that the method-caller be set as the system dialer app or have the
1078 * {@link android.Manifest.permission#READ_PHONE_STATE} permission.
1079 * </p>
1080 *
1081 * @param showDialpad Brings up the in-call dialpad as part of showing the in-call screen.
1082 */
1083 public void showInCallScreen(boolean showDialpad) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001084 ITelecomService service = getTelecomService();
Nancy Chen0eb1e402014-08-21 22:52:29 -07001085 if (service != null) {
1086 try {
1087 service.showInCallScreen(showDialpad);
1088 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001089 Log.e(TAG, "Error calling ITelecomService#showCallScreen", e);
Nancy Chen0eb1e402014-08-21 22:52:29 -07001090 }
1091 }
1092 }
1093
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001094 private ITelecomService getTelecomService() {
1095 return ITelecomService.Stub.asInterface(ServiceManager.getService(Context.TELECOM_SERVICE));
Santos Cordon6c7a3882014-06-25 15:30:08 -07001096 }
Santos Cordon9eb45932014-06-27 12:28:43 -07001097
1098 private boolean isServiceConnected() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001099 boolean isConnected = getTelecomService() != null;
Santos Cordon9eb45932014-06-27 12:28:43 -07001100 if (!isConnected) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001101 Log.w(TAG, "Telecom Service not found.");
Santos Cordon9eb45932014-06-27 12:28:43 -07001102 }
1103 return isConnected;
1104 }
Evan Charlton235c1592014-09-05 15:41:23 +00001105}