blob: 8be3e66ca331b52a28a6353f5489d0dd0e49b781 [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 /**
Yorke Lee3818a8922014-07-21 15:57:17 -070080 * The {@link android.content.Intent} action used to show the call settings page.
81 */
82 public static final String ACTION_SHOW_CALL_SETTINGS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -070083 "android.telecom.action.SHOW_CALL_SETTINGS";
Yorke Lee3818a8922014-07-21 15:57:17 -070084
85 /**
Evan Charlton6d8604f2014-09-04 12:38:17 -070086 * The {@link android.content.Intent} action used to show the settings page used to configure
87 * {@link PhoneAccount} preferences.
Evan Charlton0e094d92014-11-08 15:49:16 -080088 * @hide
Evan Charlton6d8604f2014-09-04 12:38:17 -070089 */
Evan Charlton0e094d92014-11-08 15:49:16 -080090 @SystemApi
Evan Charlton6d8604f2014-09-04 12:38:17 -070091 public static final String ACTION_CHANGE_PHONE_ACCOUNTS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -070092 "android.telecom.action.CHANGE_PHONE_ACCOUNTS";
Evan Charlton6d8604f2014-09-04 12:38:17 -070093
94 /**
Santos Cordon2d2bc162015-02-27 15:22:07 -080095 * The {@link android.content.Intent} action used indicate that a new phone account was
96 * just registered.
97 * @hide
98 */
99 @SystemApi
100 public static final String ACTION_PHONE_ACCOUNT_REGISTERED =
101 "android.telecom.action.PHONE_ACCOUNT_REGISTERED";
102
103 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700104 * Optional extra for {@link android.content.Intent#ACTION_CALL} containing a boolean that
105 * determines whether the speakerphone should be automatically turned on for an outgoing call.
Evan Charlton10197192014-07-19 15:00:29 -0700106 */
107 public static final String EXTRA_START_CALL_WITH_SPEAKERPHONE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700108 "android.telecom.extra.START_CALL_WITH_SPEAKERPHONE";
Evan Charlton10197192014-07-19 15:00:29 -0700109
110 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700111 * Optional extra for {@link android.content.Intent#ACTION_CALL} containing an integer that
112 * determines the desired video state for an outgoing call.
Santos Cordon96efb482014-07-19 14:57:05 -0700113 * Valid options:
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700114 * {@link VideoProfile.VideoState#AUDIO_ONLY},
115 * {@link VideoProfile.VideoState#BIDIRECTIONAL},
116 * {@link VideoProfile.VideoState#RX_ENABLED},
117 * {@link VideoProfile.VideoState#TX_ENABLED}.
Evan Charlton10197192014-07-19 15:00:29 -0700118 */
119 public static final String EXTRA_START_CALL_WITH_VIDEO_STATE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700120 "android.telecom.extra.START_CALL_WITH_VIDEO_STATE";
Evan Charlton10197192014-07-19 15:00:29 -0700121
122 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700123 * The extra used with an {@link android.content.Intent#ACTION_CALL} and
124 * {@link android.content.Intent#ACTION_DIAL} {@code Intent} to specify a
125 * {@link PhoneAccountHandle} to use when making the call.
Evan Charlton10197192014-07-19 15:00:29 -0700126 * <p class="note">
Santos Cordon96efb482014-07-19 14:57:05 -0700127 * Retrieve with {@link android.content.Intent#getParcelableExtra(String)}.
Evan Charlton10197192014-07-19 15:00:29 -0700128 */
Evan Charlton6eb262c2014-07-19 18:18:19 -0700129 public static final String EXTRA_PHONE_ACCOUNT_HANDLE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700130 "android.telecom.extra.PHONE_ACCOUNT_HANDLE";
Evan Charlton10197192014-07-19 15:00:29 -0700131
132 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700133 * Optional extra for {@link #ACTION_INCOMING_CALL} containing a {@link Bundle} which contains
134 * metadata about the call. This {@link Bundle} will be returned to the
135 * {@link ConnectionService}.
136 *
137 * @hide
Evan Charlton10197192014-07-19 15:00:29 -0700138 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800139 @SystemApi
Evan Charlton10197192014-07-19 15:00:29 -0700140 public static final String EXTRA_INCOMING_CALL_EXTRAS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700141 "android.telecom.extra.INCOMING_CALL_EXTRAS";
Evan Charlton10197192014-07-19 15:00:29 -0700142
143 /**
Nancy Chen10798dc2014-08-08 14:00:25 -0700144 * Optional extra for {@link android.content.Intent#ACTION_CALL} and
145 * {@link android.content.Intent#ACTION_DIAL} {@code Intent} containing a {@link Bundle}
146 * which contains metadata about the call. This {@link Bundle} will be saved into
147 * {@code Call.Details}.
Nancy Chen10798dc2014-08-08 14:00:25 -0700148 */
149 public static final String EXTRA_OUTGOING_CALL_EXTRAS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700150 "android.telecom.extra.OUTGOING_CALL_EXTRAS";
Nancy Chen10798dc2014-08-08 14:00:25 -0700151
152 /**
Yorke Leec3cf9822014-10-02 09:38:39 -0700153 * @hide
154 */
155 public static final String EXTRA_UNKNOWN_CALL_HANDLE =
156 "android.telecom.extra.UNKNOWN_CALL_HANDLE";
157
158 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700159 * Optional extra for {@link android.telephony.TelephonyManager#ACTION_PHONE_STATE_CHANGED}
160 * containing the disconnect code.
Evan Charlton10197192014-07-19 15:00:29 -0700161 */
162 public static final String EXTRA_CALL_DISCONNECT_CAUSE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700163 "android.telecom.extra.CALL_DISCONNECT_CAUSE";
Evan Charlton10197192014-07-19 15:00:29 -0700164
165 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700166 * Optional extra for {@link android.telephony.TelephonyManager#ACTION_PHONE_STATE_CHANGED}
167 * containing the disconnect message.
Evan Charlton10197192014-07-19 15:00:29 -0700168 */
169 public static final String EXTRA_CALL_DISCONNECT_MESSAGE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700170 "android.telecom.extra.CALL_DISCONNECT_MESSAGE";
Evan Charlton10197192014-07-19 15:00:29 -0700171
172 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700173 * Optional extra for {@link android.telephony.TelephonyManager#ACTION_PHONE_STATE_CHANGED}
174 * containing the component name of the associated connection service.
Evan Charlton0e094d92014-11-08 15:49:16 -0800175 * @hide
Evan Charlton10197192014-07-19 15:00:29 -0700176 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800177 @SystemApi
Evan Charlton10197192014-07-19 15:00:29 -0700178 public static final String EXTRA_CONNECTION_SERVICE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700179 "android.telecom.extra.CONNECTION_SERVICE";
Evan Charlton10197192014-07-19 15:00:29 -0700180
181 /**
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700182 * An optional {@link android.content.Intent#ACTION_CALL} intent extra denoting the
183 * package name of the app specifying an alternative gateway for the call.
184 * The value is a string.
185 *
186 * (The following comment corresponds to the all GATEWAY_* extras)
187 * An app which sends the {@link android.content.Intent#ACTION_CALL} intent can specify an
188 * alternative address to dial which is different from the one specified and displayed to
189 * the user. This alternative address is referred to as the gateway address.
190 */
191 public static final String GATEWAY_PROVIDER_PACKAGE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700192 "android.telecom.extra.GATEWAY_PROVIDER_PACKAGE";
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700193
194 /**
195 * An optional {@link android.content.Intent#ACTION_CALL} intent extra corresponding to the
196 * original address to dial for the call. This is used when an alternative gateway address is
197 * provided to recall the original address.
198 * The value is a {@link android.net.Uri}.
199 *
200 * (See {@link #GATEWAY_PROVIDER_PACKAGE} for details)
201 */
202 public static final String GATEWAY_ORIGINAL_ADDRESS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700203 "android.telecom.extra.GATEWAY_ORIGINAL_ADDRESS";
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700204
205 /**
Evan Charlton10197192014-07-19 15:00:29 -0700206 * The number which the party on the other side of the line will see (and use to return the
207 * call).
208 * <p>
Santos Cordon96efb482014-07-19 14:57:05 -0700209 * {@link ConnectionService}s which interact with {@link RemoteConnection}s should only populate
210 * this if the {@link android.telephony.TelephonyManager#getLine1Number()} value, as that is the
211 * user's expected caller ID.
Evan Charlton0e094d92014-11-08 15:49:16 -0800212 * @hide
Evan Charlton10197192014-07-19 15:00:29 -0700213 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800214 @SystemApi
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700215 public static final String EXTRA_CALL_BACK_NUMBER = "android.telecom.extra.CALL_BACK_NUMBER";
Evan Charlton10197192014-07-19 15:00:29 -0700216
217 /**
218 * The dual tone multi-frequency signaling character sent to indicate the dialing system should
219 * pause for a predefined period.
220 */
221 public static final char DTMF_CHARACTER_PAUSE = ',';
222
223 /**
224 * The dual-tone multi-frequency signaling character sent to indicate the dialing system should
225 * wait for user confirmation before proceeding.
226 */
227 public static final char DTMF_CHARACTER_WAIT = ';';
228
229 /**
230 * TTY (teletypewriter) mode is off.
231 *
232 * @hide
233 */
234 public static final int TTY_MODE_OFF = 0;
235
236 /**
237 * TTY (teletypewriter) mode is on. The speaker is off and the microphone is muted. The user
238 * will communicate with the remote party by sending and receiving text messages.
239 *
240 * @hide
241 */
242 public static final int TTY_MODE_FULL = 1;
243
244 /**
245 * TTY (teletypewriter) mode is in hearing carryover mode (HCO). The microphone is muted but the
246 * speaker is on. The user will communicate with the remote party by sending text messages and
247 * hearing an audible reply.
248 *
249 * @hide
250 */
251 public static final int TTY_MODE_HCO = 2;
252
253 /**
254 * TTY (teletypewriter) mode is in voice carryover mode (VCO). The speaker is off but the
255 * microphone is still on. User will communicate with the remote party by speaking and receiving
256 * text message replies.
257 *
258 * @hide
259 */
260 public static final int TTY_MODE_VCO = 3;
261
262 /**
263 * Broadcast intent action indicating that the current TTY mode has changed. An intent extra
264 * provides this state as an int.
Evan Charlton10197192014-07-19 15:00:29 -0700265 *
Santos Cordon96efb482014-07-19 14:57:05 -0700266 * @see #EXTRA_CURRENT_TTY_MODE
Evan Charlton10197192014-07-19 15:00:29 -0700267 * @hide
268 */
269 public static final String ACTION_CURRENT_TTY_MODE_CHANGED =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700270 "android.telecom.action.CURRENT_TTY_MODE_CHANGED";
Evan Charlton10197192014-07-19 15:00:29 -0700271
272 /**
273 * The lookup key for an int that indicates the current TTY mode.
274 * Valid modes are:
275 * - {@link #TTY_MODE_OFF}
276 * - {@link #TTY_MODE_FULL}
277 * - {@link #TTY_MODE_HCO}
278 * - {@link #TTY_MODE_VCO}
279 *
280 * @hide
281 */
282 public static final String EXTRA_CURRENT_TTY_MODE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700283 "android.telecom.intent.extra.CURRENT_TTY_MODE";
Evan Charlton10197192014-07-19 15:00:29 -0700284
285 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700286 * Broadcast intent action indicating that the TTY preferred operating mode has changed. An
287 * intent extra provides the new mode as an int.
Evan Charlton10197192014-07-19 15:00:29 -0700288 *
Santos Cordon96efb482014-07-19 14:57:05 -0700289 * @see #EXTRA_TTY_PREFERRED_MODE
Evan Charlton10197192014-07-19 15:00:29 -0700290 * @hide
291 */
292 public static final String ACTION_TTY_PREFERRED_MODE_CHANGED =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700293 "android.telecom.action.TTY_PREFERRED_MODE_CHANGED";
Evan Charlton10197192014-07-19 15:00:29 -0700294
295 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700296 * The lookup key for an int that indicates preferred TTY mode. Valid modes are: -
297 * {@link #TTY_MODE_OFF} - {@link #TTY_MODE_FULL} - {@link #TTY_MODE_HCO} -
298 * {@link #TTY_MODE_VCO}
Evan Charlton10197192014-07-19 15:00:29 -0700299 *
300 * @hide
301 */
302 public static final String EXTRA_TTY_PREFERRED_MODE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700303 "android.telecom.intent.extra.TTY_PREFERRED";
Evan Charlton10197192014-07-19 15:00:29 -0700304
Nancy Chen9d568c02014-09-08 14:17:59 -0700305 /**
306 * The following 4 constants define how properties such as phone numbers and names are
307 * displayed to the user.
308 */
309
310 /** Property is displayed normally. */
311 public static final int PRESENTATION_ALLOWED = 1;
312
313 /** Property was blocked. */
314 public static final int PRESENTATION_RESTRICTED = 2;
315
316 /** Presentation was not specified or is unknown. */
317 public static final int PRESENTATION_UNKNOWN = 3;
318
319 /** Property should be displayed as a pay phone. */
320 public static final int PRESENTATION_PAYPHONE = 4;
321
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700322 private static final String TAG = "TelecomManager";
Yorke Leeb4ce1432014-06-09 13:53:23 -0700323
324 private final Context mContext;
Yorke Leeb4ce1432014-06-09 13:53:23 -0700325
Santos Cordon6c7a3882014-06-25 15:30:08 -0700326 /**
327 * @hide
328 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700329 public static TelecomManager from(Context context) {
330 return (TelecomManager) context.getSystemService(Context.TELECOM_SERVICE);
Yorke Leeb4ce1432014-06-09 13:53:23 -0700331 }
Santos Cordon6c7a3882014-06-25 15:30:08 -0700332
333 /**
334 * @hide
335 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700336 public TelecomManager(Context context) {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700337 Context appContext = context.getApplicationContext();
338 if (appContext != null) {
339 mContext = appContext;
340 } else {
341 mContext = context;
342 }
343 }
344
345 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700346 * Return the {@link PhoneAccount} which is the user-chosen default for making outgoing phone
Nancy Chen513c8922014-09-17 14:47:20 -0700347 * calls with a specified URI scheme.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700348 * <p>
Santos Cordon96efb482014-07-19 14:57:05 -0700349 * Apps must be prepared for this method to return {@code null}, indicating that there currently
Nancy Chen513c8922014-09-17 14:47:20 -0700350 * exists no user-chosen default {@code PhoneAccount}.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700351 * <p>
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700352 * @param uriScheme The URI scheme.
Nancy Chen513c8922014-09-17 14:47:20 -0700353 * @return The {@link PhoneAccountHandle} corresponding to the user-chosen default for outgoing
354 * phone calls for a specified URI scheme.
Evan Charlton0e094d92014-11-08 15:49:16 -0800355 * @hide
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700356 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800357 @SystemApi
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700358 public PhoneAccountHandle getDefaultOutgoingPhoneAccount(String uriScheme) {
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700359 try {
360 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700361 return getTelecomService().getDefaultOutgoingPhoneAccount(uriScheme);
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700362 }
363 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700364 Log.e(TAG, "Error calling ITelecomService#getDefaultOutgoingPhoneAccount", e);
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700365 }
366 return null;
367 }
368
369 /**
Andrew Leed4abbfb2014-09-03 14:58:27 -0700370 * Return the {@link PhoneAccount} which is the user-chosen default for making outgoing phone
371 * calls. This {@code PhoneAccount} will always be a member of the list which is returned from
Nancy Chen210ef032014-09-15 17:58:42 -0700372 * calling {@link #getCallCapablePhoneAccounts()}
Andrew Leed4abbfb2014-09-03 14:58:27 -0700373 *
374 * Apps must be prepared for this method to return {@code null}, indicating that there currently
375 * exists no user-chosen default {@code PhoneAccount}.
376 *
377 * @return The user outgoing phone account selected by the user.
378 * @hide
379 */
380 public PhoneAccountHandle getUserSelectedOutgoingPhoneAccount() {
381 try {
382 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700383 return getTelecomService().getUserSelectedOutgoingPhoneAccount();
Andrew Leed4abbfb2014-09-03 14:58:27 -0700384 }
385 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700386 Log.e(TAG, "Error calling ITelecomService#getUserSelectedOutgoingPhoneAccount", e);
Andrew Leed4abbfb2014-09-03 14:58:27 -0700387 }
388 return null;
389 }
390
391 /**
Andrew Lee59cac3a2014-08-28 16:50:10 -0700392 * Sets the default account for making outgoing phone calls.
393 * @hide
394 */
Andrew Leed4abbfb2014-09-03 14:58:27 -0700395 public void setUserSelectedOutgoingPhoneAccount(PhoneAccountHandle accountHandle) {
Andrew Lee59cac3a2014-08-28 16:50:10 -0700396 try {
397 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700398 getTelecomService().setUserSelectedOutgoingPhoneAccount(accountHandle);
Andrew Lee59cac3a2014-08-28 16:50:10 -0700399 }
400 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700401 Log.e(TAG, "Error calling ITelecomService#setUserSelectedOutgoingPhoneAccount");
Andrew Lee59cac3a2014-08-28 16:50:10 -0700402 }
403 }
404
405 /**
Andrew Lee59cac3a2014-08-28 16:50:10 -0700406 * Returns the current SIM call manager. Apps must be prepared for this method to return
407 * {@code null}, indicating that there currently exists no user-chosen default
408 * {@code PhoneAccount}.
409 * @return The phone account handle of the current sim call manager.
410 * @hide
411 */
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 *
510 * @hide
511 */
512 public List<PhoneAccountHandle> getCallCapablePhoneAccounts() {
513 try {
514 if (isServiceConnected()) {
515 return getTelecomService().getCallCapablePhoneAccounts();
516 }
517 } catch (RemoteException e) {
518 Log.e(TAG, "Error calling ITelecomService#getCallCapablePhoneAccounts", e);
519 }
520 return new ArrayList<>();
521 }
522
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700523 /**
Nancy Chen210ef032014-09-15 17:58:42 -0700524 * Determine whether the device has more than one account registered that can make and receive
525 * phone calls.
Nancy Chen60801182014-07-22 16:56:49 -0700526 *
Nancy Chen210ef032014-09-15 17:58:42 -0700527 * @return {@code true} if the device has more than one account registered and {@code false}
528 * otherwise.
Evan Charlton0e094d92014-11-08 15:49:16 -0800529 * @hide
Nancy Chen60801182014-07-22 16:56:49 -0700530 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800531 @SystemApi
Nancy Chen210ef032014-09-15 17:58:42 -0700532 public boolean hasMultipleCallCapableAccounts() {
533 return getCallCapablePhoneAccounts().size() > 1;
Nancy Chen60801182014-07-22 16:56:49 -0700534 }
535
536 /**
Nancy Chen513c8922014-09-17 14:47:20 -0700537 * Returns a list of all {@link PhoneAccount}s registered for the calling package.
538 *
539 * @return A list of {@code PhoneAccountHandle} objects.
Evan Charlton0e094d92014-11-08 15:49:16 -0800540 * @hide
Nancy Chen513c8922014-09-17 14:47:20 -0700541 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800542 @SystemApi
Nancy Chen513c8922014-09-17 14:47:20 -0700543 public List<PhoneAccountHandle> getPhoneAccountsForPackage() {
544 try {
545 if (isServiceConnected()) {
546 return getTelecomService().getPhoneAccountsForPackage(mContext.getPackageName());
547 }
548 } catch (RemoteException e) {
549 Log.e(TAG, "Error calling ITelecomService#getPhoneAccountsForPackage", e);
550 }
551 return null;
552 }
553
554 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700555 * Return the {@link PhoneAccount} for a specified {@link PhoneAccountHandle}. Object includes
556 * resources which can be used in a user interface.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700557 *
Evan Charlton6eb262c2014-07-19 18:18:19 -0700558 * @param account The {@link PhoneAccountHandle}.
Evan Charlton8c8a0622014-07-20 12:31:00 -0700559 * @return The {@link PhoneAccount} object.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700560 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700561 public PhoneAccount getPhoneAccount(PhoneAccountHandle account) {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700562 try {
563 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700564 return getTelecomService().getPhoneAccount(account);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700565 }
566 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700567 Log.e(TAG, "Error calling ITelecomService#getPhoneAccount", e);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700568 }
569 return null;
570 }
571
572 /**
Nancy Chen210ef032014-09-15 17:58:42 -0700573 * Returns a count of all {@link PhoneAccount}s.
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700574 *
Nancy Chen210ef032014-09-15 17:58:42 -0700575 * @return The count of {@link PhoneAccount}s.
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700576 * @hide
577 */
578 @SystemApi
579 public int getAllPhoneAccountsCount() {
580 try {
581 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700582 return getTelecomService().getAllPhoneAccountsCount();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700583 }
584 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700585 Log.e(TAG, "Error calling ITelecomService#getAllPhoneAccountsCount", e);
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700586 }
587 return 0;
588 }
589
590 /**
591 * Returns a list of all {@link PhoneAccount}s.
592 *
593 * @return All {@link PhoneAccount}s.
594 * @hide
595 */
596 @SystemApi
597 public List<PhoneAccount> getAllPhoneAccounts() {
598 try {
599 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700600 return getTelecomService().getAllPhoneAccounts();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700601 }
602 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700603 Log.e(TAG, "Error calling ITelecomService#getAllPhoneAccounts", e);
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700604 }
605 return Collections.EMPTY_LIST;
606 }
607
608 /**
609 * Returns a list of all {@link PhoneAccountHandle}s.
610 *
611 * @return All {@link PhoneAccountHandle}s.
612 * @hide
613 */
614 @SystemApi
615 public List<PhoneAccountHandle> getAllPhoneAccountHandles() {
616 try {
617 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700618 return getTelecomService().getAllPhoneAccountHandles();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700619 }
620 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700621 Log.e(TAG, "Error calling ITelecomService#getAllPhoneAccountHandles", e);
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700622 }
623 return Collections.EMPTY_LIST;
624 }
625
626 /**
Santos Cordond9e614f2014-10-28 13:10:36 -0700627 * Register a {@link PhoneAccount} for use by the system. When registering
628 * {@link PhoneAccount}s, existing registrations will be overwritten if the
629 * {@link PhoneAccountHandle} matches that of a {@link PhoneAccount} which is already
630 * registered. Once registered, the {@link PhoneAccount} is listed to the user as an option
631 * when placing calls. The user may still need to enable the {@link PhoneAccount} within
632 * the phone app settings before the account is usable.
633 * <p>
634 * A {@link SecurityException} will be thrown if an app tries to register a
635 * {@link PhoneAccountHandle} where the package name specified within
636 * {@link PhoneAccountHandle#getComponentName()} does not match the package name of the app.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700637 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700638 * @param account The complete {@link PhoneAccount}.
Evan Charlton0e094d92014-11-08 15:49:16 -0800639 *
640 * @hide
Ihab Awad807fe0a2014-07-09 12:30:52 -0700641 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800642 @SystemApi
Evan Charlton8c8a0622014-07-20 12:31:00 -0700643 public void registerPhoneAccount(PhoneAccount account) {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700644 try {
645 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700646 getTelecomService().registerPhoneAccount(account);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700647 }
648 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700649 Log.e(TAG, "Error calling ITelecomService#registerPhoneAccount", e);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700650 }
651 }
652
653 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700654 * Remove a {@link PhoneAccount} registration from the system.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700655 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700656 * @param accountHandle A {@link PhoneAccountHandle} for the {@link PhoneAccount} to unregister.
Evan Charlton0e094d92014-11-08 15:49:16 -0800657 * @hide
Ihab Awad807fe0a2014-07-09 12:30:52 -0700658 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800659 @SystemApi
Evan Charlton8c8a0622014-07-20 12:31:00 -0700660 public void unregisterPhoneAccount(PhoneAccountHandle accountHandle) {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700661 try {
662 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700663 getTelecomService().unregisterPhoneAccount(accountHandle);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700664 }
665 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700666 Log.e(TAG, "Error calling ITelecomService#unregisterPhoneAccount", e);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700667 }
668 }
669
670 /**
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700671 * Remove all Accounts that belong to the calling package from the system.
Evan Charlton0e094d92014-11-08 15:49:16 -0800672 * @hide
Ihab Awad807fe0a2014-07-09 12:30:52 -0700673 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800674 @SystemApi
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700675 public void clearAccounts() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700676 try {
677 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700678 getTelecomService().clearAccounts(mContext.getPackageName());
Ihab Awad807fe0a2014-07-09 12:30:52 -0700679 }
680 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700681 Log.e(TAG, "Error calling ITelecomService#clearAccounts", e);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700682 }
683 }
684
685 /**
Anthony Lee67279262014-10-27 11:28:40 -0700686 * Remove all Accounts that belong to the specified package from the system.
687 * @hide
688 */
689 public void clearAccountsForPackage(String packageName) {
690 try {
691 if (isServiceConnected() && !TextUtils.isEmpty(packageName)) {
692 getTelecomService().clearAccounts(packageName);
693 }
694 } catch (RemoteException e) {
Nancy Chen5cf27842015-01-24 23:30:27 -0800695 Log.e(TAG, "Error calling ITelecomService#clearAccountsForPackage", e);
Anthony Lee67279262014-10-27 11:28:40 -0700696 }
697 }
698
699 /**
Ihab Awad807fe0a2014-07-09 12:30:52 -0700700 * @hide
701 */
Santos Cordon6c7a3882014-06-25 15:30:08 -0700702 @SystemApi
703 public ComponentName getDefaultPhoneApp() {
704 try {
Santos Cordon9eb45932014-06-27 12:28:43 -0700705 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700706 return getTelecomService().getDefaultPhoneApp();
Santos Cordon9eb45932014-06-27 12:28:43 -0700707 }
Santos Cordon6c7a3882014-06-25 15:30:08 -0700708 } catch (RemoteException e) {
709 Log.e(TAG, "RemoteException attempting to get the default phone app.", e);
710 }
711 return null;
712 }
713
Santos Cordon9eb45932014-06-27 12:28:43 -0700714 /**
Nancy Chen443e5012014-10-15 15:48:21 -0700715 * Return whether a given phone number is the configured voicemail number for a
716 * particular phone account.
717 *
718 * @param accountHandle The handle for the account to check the voicemail number against
719 * @param number The number to look up.
720 *
721 * @hide
722 */
723 @SystemApi
724 public boolean isVoiceMailNumber(PhoneAccountHandle accountHandle, String number) {
725 try {
726 if (isServiceConnected()) {
727 return getTelecomService().isVoiceMailNumber(accountHandle, number);
728 }
729 } catch (RemoteException e) {
Nancy Chen5cf27842015-01-24 23:30:27 -0800730 Log.e(TAG, "RemoteException calling ITelecomService#isVoiceMailNumber.", e);
Nancy Chen443e5012014-10-15 15:48:21 -0700731 }
732 return false;
733 }
734
735 /**
Nancy Chen8c066f7c2014-12-03 15:18:08 -0800736 * Return whether a given phone account has a voicemail number configured.
737 *
738 * @param accountHandle The handle for the account to check for a voicemail number.
739 * @return {@code true} If the given phone account has a voicemail number.
740 *
741 * @hide
742 */
743 @SystemApi
744 public boolean hasVoiceMailNumber(PhoneAccountHandle accountHandle) {
745 try {
746 if (isServiceConnected()) {
747 return getTelecomService().hasVoiceMailNumber(accountHandle);
748 }
749 } catch (RemoteException e) {
Nancy Chen5cf27842015-01-24 23:30:27 -0800750 Log.e(TAG, "RemoteException calling ITelecomService#hasVoiceMailNumber.", e);
Nancy Chen8c066f7c2014-12-03 15:18:08 -0800751 }
752 return false;
753 }
754
755 /**
Nancy Chen5cf27842015-01-24 23:30:27 -0800756 * Return the line 1 phone number for given phone account.
757 *
758 * @param accountHandle The handle for the account retrieve a number for.
759 * @return A string representation of the line 1 phone number.
760 *
761 * @hide
762 */
763 @SystemApi
764 public String getLine1Number(PhoneAccountHandle accountHandle) {
765 try {
766 if (isServiceConnected()) {
767 return getTelecomService().getLine1Number(accountHandle);
768 }
769 } catch (RemoteException e) {
770 Log.e(TAG, "RemoteException calling ITelecomService#getLine1Number.", e);
771 }
772 return null;
773 }
774
775 /**
Santos Cordon9eb45932014-06-27 12:28:43 -0700776 * Returns whether there is an ongoing phone call (can be in dialing, ringing, active or holding
777 * states).
Nancy Chen0eb1e402014-08-21 22:52:29 -0700778 * <p>
779 * Requires permission: {@link android.Manifest.permission#READ_PHONE_STATE}
780 * </p>
Santos Cordon9eb45932014-06-27 12:28:43 -0700781 */
Nancy Chen0eb1e402014-08-21 22:52:29 -0700782 public boolean isInCall() {
Santos Cordon9eb45932014-06-27 12:28:43 -0700783 try {
784 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700785 return getTelecomService().isInCall();
Santos Cordon9eb45932014-06-27 12:28:43 -0700786 }
787 } catch (RemoteException e) {
Yorke Lee2ae312e2014-09-12 17:58:48 -0700788 Log.e(TAG, "RemoteException calling isInCall().", e);
Santos Cordon9eb45932014-06-27 12:28:43 -0700789 }
790 return false;
791 }
792
793 /**
Yorke Lee2ae312e2014-09-12 17:58:48 -0700794 * Returns one of the following constants that represents the current state of Telecom:
795 *
796 * {@link TelephonyManager#CALL_STATE_RINGING}
797 * {@link TelephonyManager#CALL_STATE_OFFHOOK}
798 * {@link TelephonyManager#CALL_STATE_IDLE}
Yorke Lee7c72c2d2014-10-28 14:12:02 -0700799 *
800 * Note that this API does not require the
801 * {@link android.Manifest.permission#READ_PHONE_STATE} permission. This is intentional, to
802 * preserve the behavior of {@link TelephonyManager#getCallState()}, which also did not require
803 * the permission.
Yorke Lee2ae312e2014-09-12 17:58:48 -0700804 * @hide
805 */
806 @SystemApi
807 public int getCallState() {
808 try {
809 if (isServiceConnected()) {
810 return getTelecomService().getCallState();
811 }
812 } catch (RemoteException e) {
813 Log.d(TAG, "RemoteException calling getCallState().", e);
814 }
815 return TelephonyManager.CALL_STATE_IDLE;
816 }
817
818 /**
Santos Cordon9eb45932014-06-27 12:28:43 -0700819 * Returns whether there currently exists is a ringing incoming-call.
820 *
821 * @hide
822 */
823 @SystemApi
824 public boolean isRinging() {
825 try {
826 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700827 return getTelecomService().isRinging();
Santos Cordon9eb45932014-06-27 12:28:43 -0700828 }
829 } catch (RemoteException e) {
830 Log.e(TAG, "RemoteException attempting to get ringing state of phone app.", e);
831 }
832 return false;
833 }
834
835 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700836 * Ends an ongoing call.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700837 * TODO: L-release - need to convert all invocations of ITelecomService#endCall to use this
Santos Cordon96efb482014-07-19 14:57:05 -0700838 * method (clockwork & gearhead).
Santos Cordon9eb45932014-06-27 12:28:43 -0700839 * @hide
840 */
841 @SystemApi
842 public boolean endCall() {
843 try {
844 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700845 return getTelecomService().endCall();
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#endCall", e);
Santos Cordon9eb45932014-06-27 12:28:43 -0700849 }
850 return false;
851 }
852
853 /**
854 * If there is a ringing incoming call, this method accepts the call on behalf of the user.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700855 * TODO: L-release - need to convert all invocation of ITelecmmService#answerRingingCall to use
Santos Cordon96efb482014-07-19 14:57:05 -0700856 * this method (clockwork & gearhead).
Santos Cordon9eb45932014-06-27 12:28:43 -0700857 *
858 * @hide
859 */
860 @SystemApi
861 public void acceptRingingCall() {
862 try {
863 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700864 getTelecomService().acceptRingingCall();
Santos Cordon9eb45932014-06-27 12:28:43 -0700865 }
866 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700867 Log.e(TAG, "Error calling ITelecomService#acceptRingingCall", e);
Santos Cordon9eb45932014-06-27 12:28:43 -0700868 }
869 }
870
871 /**
872 * Silences the ringer if a ringing call exists.
873 *
874 * @hide
875 */
876 @SystemApi
877 public void silenceRinger() {
878 try {
879 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700880 getTelecomService().silenceRinger();
Santos Cordon9eb45932014-06-27 12:28:43 -0700881 }
882 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700883 Log.e(TAG, "Error calling ITelecomService#silenceRinger", e);
Santos Cordon9eb45932014-06-27 12:28:43 -0700884 }
885 }
886
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700887 /**
888 * Returns whether TTY is supported on this device.
889 *
890 * @hide
891 */
892 @SystemApi
893 public boolean isTtySupported() {
894 try {
895 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700896 return getTelecomService().isTtySupported();
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700897 }
898 } catch (RemoteException e) {
899 Log.e(TAG, "RemoteException attempting to get TTY supported state.", e);
900 }
901 return false;
902 }
903
904 /**
905 * 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 -0700906 * settings and have a wired headset plugged in.
907 * Valid modes are:
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700908 * - {@link TelecomManager#TTY_MODE_OFF}
909 * - {@link TelecomManager#TTY_MODE_FULL}
910 * - {@link TelecomManager#TTY_MODE_HCO}
911 * - {@link TelecomManager#TTY_MODE_VCO}
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700912 * @hide
913 */
914 public int getCurrentTtyMode() {
915 try {
916 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700917 return getTelecomService().getCurrentTtyMode();
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700918 }
919 } catch (RemoteException e) {
920 Log.e(TAG, "RemoteException attempting to get the current TTY mode.", e);
921 }
Evan Charlton10197192014-07-19 15:00:29 -0700922 return TTY_MODE_OFF;
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700923 }
924
Santos Cordon96efb482014-07-19 14:57:05 -0700925 /**
926 * Registers a new incoming call. A {@link ConnectionService} should invoke this method when it
927 * has an incoming call. The specified {@link PhoneAccountHandle} must have been registered
Nancy Chen210ef032014-09-15 17:58:42 -0700928 * with {@link #registerPhoneAccount}. Once invoked, this method will cause the system to bind
929 * to the {@link ConnectionService} associated with the {@link PhoneAccountHandle} and request
Santos Cordon96efb482014-07-19 14:57:05 -0700930 * additional information about the call (See
931 * {@link ConnectionService#onCreateIncomingConnection}) before starting the incoming call UI.
932 *
933 * @param phoneAccount A {@link PhoneAccountHandle} registered with
934 * {@link #registerPhoneAccount}.
935 * @param extras A bundle that will be passed through to
936 * {@link ConnectionService#onCreateIncomingConnection}.
Evan Charlton0e094d92014-11-08 15:49:16 -0800937 * @hide
Santos Cordon96efb482014-07-19 14:57:05 -0700938 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800939 @SystemApi
Santos Cordon96efb482014-07-19 14:57:05 -0700940 public void addNewIncomingCall(PhoneAccountHandle phoneAccount, Bundle extras) {
941 try {
942 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700943 getTelecomService().addNewIncomingCall(
Santos Cordon96efb482014-07-19 14:57:05 -0700944 phoneAccount, extras == null ? new Bundle() : extras);
945 }
946 } catch (RemoteException e) {
947 Log.e(TAG, "RemoteException adding a new incoming call: " + phoneAccount, e);
948 }
949 }
950
Nancy Chen0eb1e402014-08-21 22:52:29 -0700951 /**
Yorke Leec3cf9822014-10-02 09:38:39 -0700952 * Registers a new unknown call with Telecom. This can only be called by the system Telephony
953 * service. This is invoked when Telephony detects a new unknown connection that was neither
954 * a new incoming call, nor an user-initiated outgoing call.
955 *
956 * @param phoneAccount A {@link PhoneAccountHandle} registered with
957 * {@link #registerPhoneAccount}.
958 * @param extras A bundle that will be passed through to
959 * {@link ConnectionService#onCreateIncomingConnection}.
960 * @hide
961 */
962 @SystemApi
963 public void addNewUnknownCall(PhoneAccountHandle phoneAccount, Bundle extras) {
964 try {
965 if (isServiceConnected()) {
966 getTelecomService().addNewUnknownCall(
967 phoneAccount, extras == null ? new Bundle() : extras);
968 }
969 } catch (RemoteException e) {
970 Log.e(TAG, "RemoteException adding a new unknown call: " + phoneAccount, e);
971 }
972 }
973
974 /**
Nancy Chen0eb1e402014-08-21 22:52:29 -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.
Nancy Chen95e8a672014-10-16 18:38:21 -0700978 * This method uses the default subscription.
Nancy Chen0eb1e402014-08-21 22:52:29 -0700979 * <p>
980 * Requires that the method-caller be set as the system dialer app.
981 * </p>
982 *
983 * @param dialString The digits to dial.
984 * @return True if the digits were processed as an MMI code, false otherwise.
985 */
986 public boolean handleMmi(String dialString) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700987 ITelecomService service = getTelecomService();
Nancy Chen0eb1e402014-08-21 22:52:29 -0700988 if (service != null) {
989 try {
990 return service.handlePinMmi(dialString);
991 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700992 Log.e(TAG, "Error calling ITelecomService#handlePinMmi", e);
Nancy Chen0eb1e402014-08-21 22:52:29 -0700993 }
994 }
995 return false;
996 }
997
998 /**
Nancy Chen95e8a672014-10-16 18:38:21 -0700999 * Processes the specified dial string as an MMI code.
1000 * MMI codes are any sequence of characters entered into the dialpad that contain a "*" or "#".
1001 * Some of these sequences launch special behavior through handled by Telephony.
1002 * <p>
1003 * Requires that the method-caller be set as the system dialer app.
1004 * </p>
1005 *
1006 * @param accountHandle The handle for the account the MMI code should apply to.
1007 * @param dialString The digits to dial.
1008 * @return True if the digits were processed as an MMI code, false otherwise.
Evan Charlton0e094d92014-11-08 15:49:16 -08001009 * @hide
Nancy Chen95e8a672014-10-16 18:38:21 -07001010 */
Evan Charlton0e094d92014-11-08 15:49:16 -08001011 @SystemApi
Nancy Chen95e8a672014-10-16 18:38:21 -07001012 public boolean handleMmi(PhoneAccountHandle accountHandle, String dialString) {
1013 ITelecomService service = getTelecomService();
1014 if (service != null) {
1015 try {
1016 return service.handlePinMmiForPhoneAccount(accountHandle, dialString);
1017 } catch (RemoteException e) {
1018 Log.e(TAG, "Error calling ITelecomService#handlePinMmi", e);
1019 }
1020 }
1021 return false;
1022 }
1023
1024 /**
Nancy Chenb2299c12014-10-29 18:22:11 -07001025 * @param accountHandle The handle for the account to derive an adn query URI for or
1026 * {@code null} to return a URI which will use the default account.
1027 * @return The URI (with the content:// scheme) specific to the specified {@link PhoneAccount}
1028 * for the the content retrieve.
Evan Charlton0e094d92014-11-08 15:49:16 -08001029 * @hide
Nancy Chenb2299c12014-10-29 18:22:11 -07001030 */
Evan Charlton0e094d92014-11-08 15:49:16 -08001031 @SystemApi
Nancy Chenb2299c12014-10-29 18:22:11 -07001032 public Uri getAdnUriForPhoneAccount(PhoneAccountHandle accountHandle) {
1033 ITelecomService service = getTelecomService();
1034 if (service != null && accountHandle != null) {
1035 try {
1036 return service.getAdnUriForPhoneAccount(accountHandle);
1037 } catch (RemoteException e) {
1038 Log.e(TAG, "Error calling ITelecomService#getAdnUriForPhoneAccount", e);
1039 }
1040 }
1041 return Uri.parse("content://icc/adn");
1042 }
1043
1044 /**
Nancy Chen0eb1e402014-08-21 22:52:29 -07001045 * Removes the missed-call notification if one is present.
1046 * <p>
1047 * Requires that the method-caller be set as the system dialer app.
1048 * </p>
1049 */
1050 public void cancelMissedCallsNotification() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001051 ITelecomService service = getTelecomService();
Nancy Chen0eb1e402014-08-21 22:52:29 -07001052 if (service != null) {
1053 try {
1054 service.cancelMissedCallsNotification();
1055 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001056 Log.e(TAG, "Error calling ITelecomService#cancelMissedCallsNotification", e);
Nancy Chen0eb1e402014-08-21 22:52:29 -07001057 }
1058 }
1059 }
1060
1061 /**
1062 * Brings the in-call screen to the foreground if there is an ongoing call. If there is
1063 * currently no ongoing call, then this method does nothing.
1064 * <p>
1065 * Requires that the method-caller be set as the system dialer app or have the
1066 * {@link android.Manifest.permission#READ_PHONE_STATE} permission.
1067 * </p>
1068 *
1069 * @param showDialpad Brings up the in-call dialpad as part of showing the in-call screen.
1070 */
1071 public void showInCallScreen(boolean showDialpad) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001072 ITelecomService service = getTelecomService();
Nancy Chen0eb1e402014-08-21 22:52:29 -07001073 if (service != null) {
1074 try {
1075 service.showInCallScreen(showDialpad);
1076 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001077 Log.e(TAG, "Error calling ITelecomService#showCallScreen", e);
Nancy Chen0eb1e402014-08-21 22:52:29 -07001078 }
1079 }
1080 }
1081
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001082 private ITelecomService getTelecomService() {
1083 return ITelecomService.Stub.asInterface(ServiceManager.getService(Context.TELECOM_SERVICE));
Santos Cordon6c7a3882014-06-25 15:30:08 -07001084 }
Santos Cordon9eb45932014-06-27 12:28:43 -07001085
1086 private boolean isServiceConnected() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001087 boolean isConnected = getTelecomService() != null;
Santos Cordon9eb45932014-06-27 12:28:43 -07001088 if (!isConnected) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001089 Log.w(TAG, "Telecom Service not found.");
Santos Cordon9eb45932014-06-27 12:28:43 -07001090 }
1091 return isConnected;
1092 }
Evan Charlton235c1592014-09-05 15:41:23 +00001093}