blob: c2b6d212204f5152abd0c25d765fef36c1578723 [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;
Divya Sharma1cb8f692015-02-24 16:25:55 -080020import 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;
Sandeep Kunta0f8bfc52014-09-01 17:21:05 +053025import android.telephony.SubscriptionManager;
Anthony Lee9d23ff92014-10-27 11:28:40 -070026import android.text.TextUtils;
Santos Cordon6c7a3882014-06-25 15:30:08 -070027import android.util.Log;
Yorke Leeb4ce1432014-06-09 13:53:23 -070028
Tyler Gunnef9f6f92014-09-12 22:16:17 -070029import com.android.internal.telecom.ITelecomService;
Yorke Leeb4ce1432014-06-09 13:53:23 -070030
Jay Shrauner7746a942014-08-26 12:15:15 -070031import java.util.ArrayList;
Tyler Gunna1ed7d12014-09-08 09:52:22 -070032import java.util.Collections;
Ihab Awad807fe0a2014-07-09 12:30:52 -070033import java.util.List;
34
Yorke Leeb4ce1432014-06-09 13:53:23 -070035/**
Santos Cordond3a0b162014-10-28 13:10:36 -070036 * Provides access to information about active calls and registration/call-management functionality.
Evan Charltonf6a3fef2014-11-08 15:49:16 -080037 * Apps can use methods in this class to determine the current call state.
Santos Cordond3a0b162014-10-28 13:10:36 -070038 * <p>
39 * Apps do not instantiate this class directly; instead, they retrieve a reference to an instance
40 * through {@link Context#getSystemService Context.getSystemService(Context.TELECOM_SERVICE)}.
41 * <p>
42 * Note that access to some telecom information is permission-protected. Your app cannot access the
43 * protected information or gain access to protected functionality unless it has the appropriate
44 * permissions declared in its manifest file. Where permissions apply, they are noted in the method
45 * descriptions.
Yorke Leeb4ce1432014-06-09 13:53:23 -070046 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -070047public class TelecomManager {
Ihab Awad807fe0a2014-07-09 12:30:52 -070048
Evan Charlton10197192014-07-19 15:00:29 -070049 /**
Santos Cordon96efb482014-07-19 14:57:05 -070050 * Activity action: Starts the UI for handing an incoming call. This intent starts the in-call
Tyler Gunnef9f6f92014-09-12 22:16:17 -070051 * UI by notifying the Telecom system that an incoming call exists for a specific call service
52 * (see {@link android.telecom.ConnectionService}). Telecom reads the Intent extras to find
53 * and bind to the appropriate {@link android.telecom.ConnectionService} which Telecom will
Santos Cordon96efb482014-07-19 14:57:05 -070054 * ultimately use to control and get information about the call.
55 * <p>
56 * Input: get*Extra field {@link #EXTRA_PHONE_ACCOUNT_HANDLE} contains the component name of the
Tyler Gunnef9f6f92014-09-12 22:16:17 -070057 * {@link android.telecom.ConnectionService} that Telecom should bind to. Telecom will then
Evan Charlton10197192014-07-19 15:00:29 -070058 * ask the connection service for more information about the call prior to showing any UI.
59 *
Santos Cordon96efb482014-07-19 14:57:05 -070060 * @hide
Evan Charlton10197192014-07-19 15:00:29 -070061 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -070062 public static final String ACTION_INCOMING_CALL = "android.telecom.action.INCOMING_CALL";
Evan Charlton10197192014-07-19 15:00:29 -070063
64 /**
Yorke Leec3cf9822014-10-02 09:38:39 -070065 * Similar to {@link #ACTION_INCOMING_CALL}, but is used only by Telephony to add a new
66 * sim-initiated MO call for carrier testing.
67 * @hide
68 */
69 public static final String ACTION_NEW_UNKNOWN_CALL = "android.telecom.action.NEW_UNKNOWN_CALL";
70
71 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -070072 * The {@link android.content.Intent} action used to configure a
Tyler Gunnef9f6f92014-09-12 22:16:17 -070073 * {@link android.telecom.ConnectionService}.
Tyler Gunn711d876fd2014-09-19 11:17:02 -070074 * @hide
Evan Charlton10197192014-07-19 15:00:29 -070075 */
Divya Sharma1cb8f692015-02-24 16:25:55 -080076 @SystemApi
Evan Charlton10197192014-07-19 15:00:29 -070077 public static final String ACTION_CONNECTION_SERVICE_CONFIGURE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -070078 "android.telecom.action.CONNECTION_SERVICE_CONFIGURE";
Evan Charlton10197192014-07-19 15:00:29 -070079
80 /**
Yorke Lee3818a892014-07-21 15:57:17 -070081 * The {@link android.content.Intent} action used to show the call settings page.
82 */
83 public static final String ACTION_SHOW_CALL_SETTINGS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -070084 "android.telecom.action.SHOW_CALL_SETTINGS";
Yorke Lee3818a892014-07-21 15:57:17 -070085
86 /**
Evan Charlton6d8604f2014-09-04 12:38:17 -070087 * The {@link android.content.Intent} action used to show the settings page used to configure
88 * {@link PhoneAccount} preferences.
Tyler Gunn711d876fd2014-09-19 11:17:02 -070089 * @hide
Evan Charlton6d8604f2014-09-04 12:38:17 -070090 */
Divya Sharma1cb8f692015-02-24 16:25:55 -080091 @SystemApi
Evan Charlton6d8604f2014-09-04 12:38:17 -070092 public static final String ACTION_CHANGE_PHONE_ACCOUNTS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -070093 "android.telecom.action.CHANGE_PHONE_ACCOUNTS";
Evan Charlton6d8604f2014-09-04 12:38:17 -070094
95 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -070096 * Optional extra for {@link android.content.Intent#ACTION_CALL} containing a boolean that
97 * determines whether the speakerphone should be automatically turned on for an outgoing call.
Evan Charlton10197192014-07-19 15:00:29 -070098 */
99 public static final String EXTRA_START_CALL_WITH_SPEAKERPHONE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700100 "android.telecom.extra.START_CALL_WITH_SPEAKERPHONE";
Evan Charlton10197192014-07-19 15:00:29 -0700101
102 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700103 * Optional extra for {@link android.content.Intent#ACTION_CALL} containing an integer that
104 * determines the desired video state for an outgoing call.
Santos Cordon96efb482014-07-19 14:57:05 -0700105 * Valid options:
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700106 * {@link VideoProfile.VideoState#AUDIO_ONLY},
107 * {@link VideoProfile.VideoState#BIDIRECTIONAL},
108 * {@link VideoProfile.VideoState#RX_ENABLED},
109 * {@link VideoProfile.VideoState#TX_ENABLED}.
Tyler Gunn27d1e252014-08-21 16:38:40 -0700110 * @hide
Evan Charlton10197192014-07-19 15:00:29 -0700111 */
112 public static final String EXTRA_START_CALL_WITH_VIDEO_STATE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700113 "android.telecom.extra.START_CALL_WITH_VIDEO_STATE";
Evan Charlton10197192014-07-19 15:00:29 -0700114
115 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700116 * The extra used with an {@link android.content.Intent#ACTION_CALL} and
117 * {@link android.content.Intent#ACTION_DIAL} {@code Intent} to specify a
118 * {@link PhoneAccountHandle} to use when making the call.
Evan Charlton10197192014-07-19 15:00:29 -0700119 * <p class="note">
Santos Cordon96efb482014-07-19 14:57:05 -0700120 * Retrieve with {@link android.content.Intent#getParcelableExtra(String)}.
Tyler Gunn711d876fd2014-09-19 11:17:02 -0700121 * @hide
Evan Charlton10197192014-07-19 15:00:29 -0700122 */
Divya Sharma1cb8f692015-02-24 16:25:55 -0800123 @SystemApi
Evan Charlton6eb262c2014-07-19 18:18:19 -0700124 public static final String EXTRA_PHONE_ACCOUNT_HANDLE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700125 "android.telecom.extra.PHONE_ACCOUNT_HANDLE";
Evan Charlton10197192014-07-19 15:00:29 -0700126
127 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700128 * Optional extra for {@link #ACTION_INCOMING_CALL} containing a {@link Bundle} which contains
129 * metadata about the call. This {@link Bundle} will be returned to the
130 * {@link ConnectionService}.
131 *
132 * @hide
Evan Charlton10197192014-07-19 15:00:29 -0700133 */
Divya Sharma1cb8f692015-02-24 16:25:55 -0800134 @SystemApi
Evan Charlton10197192014-07-19 15:00:29 -0700135 public static final String EXTRA_INCOMING_CALL_EXTRAS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700136 "android.telecom.extra.INCOMING_CALL_EXTRAS";
Evan Charlton10197192014-07-19 15:00:29 -0700137
138 /**
Nancy Chen10798dc2014-08-08 14:00:25 -0700139 * Optional extra for {@link android.content.Intent#ACTION_CALL} and
140 * {@link android.content.Intent#ACTION_DIAL} {@code Intent} containing a {@link Bundle}
141 * which contains metadata about the call. This {@link Bundle} will be saved into
142 * {@code Call.Details}.
143 *
144 * @hide
145 */
Divya Sharma1cb8f692015-02-24 16:25:55 -0800146 @SystemApi
Nancy Chen10798dc2014-08-08 14:00:25 -0700147 public static final String EXTRA_OUTGOING_CALL_EXTRAS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700148 "android.telecom.extra.OUTGOING_CALL_EXTRAS";
Nancy Chen10798dc2014-08-08 14:00:25 -0700149
150 /**
Yorke Leec3cf9822014-10-02 09:38:39 -0700151 * @hide
152 */
153 public static final String EXTRA_UNKNOWN_CALL_HANDLE =
154 "android.telecom.extra.UNKNOWN_CALL_HANDLE";
155
156 /**
Anju Mathapati34a5d422015-01-24 00:34:28 -0800157 * Similar to {@link #ACTION_INCOMING_CALL}, but is used only by Telephony to add a new
158 * sim-initiated MO call for carrier testing and for conference scenarios
159 * @hide
160 */
161 public static final String EXTRA_UNKNOWN_CALL_STATE =
162 "codeaurora.telecom.extra.UNKNOWN_CALL_STATE";
163
164 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700165 * Optional extra for {@link android.telephony.TelephonyManager#ACTION_PHONE_STATE_CHANGED}
166 * containing the disconnect code.
Evan Charlton10197192014-07-19 15:00:29 -0700167 */
168 public static final String EXTRA_CALL_DISCONNECT_CAUSE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700169 "android.telecom.extra.CALL_DISCONNECT_CAUSE";
Evan Charlton10197192014-07-19 15:00:29 -0700170
171 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700172 * Optional extra for {@link android.telephony.TelephonyManager#ACTION_PHONE_STATE_CHANGED}
173 * containing the disconnect message.
Evan Charlton10197192014-07-19 15:00:29 -0700174 */
175 public static final String EXTRA_CALL_DISCONNECT_MESSAGE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700176 "android.telecom.extra.CALL_DISCONNECT_MESSAGE";
Evan Charlton10197192014-07-19 15:00:29 -0700177
178 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700179 * Optional extra for {@link android.telephony.TelephonyManager#ACTION_PHONE_STATE_CHANGED}
180 * containing the component name of the associated connection service.
Tyler Gunn711d876fd2014-09-19 11:17:02 -0700181 * @hide
Evan Charlton10197192014-07-19 15:00:29 -0700182 */
Divya Sharma1cb8f692015-02-24 16:25:55 -0800183 @SystemApi
Evan Charlton10197192014-07-19 15:00:29 -0700184 public static final String EXTRA_CONNECTION_SERVICE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700185 "android.telecom.extra.CONNECTION_SERVICE";
Evan Charlton10197192014-07-19 15:00:29 -0700186
187 /**
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700188 * An optional {@link android.content.Intent#ACTION_CALL} intent extra denoting the
189 * package name of the app specifying an alternative gateway for the call.
190 * The value is a string.
191 *
192 * (The following comment corresponds to the all GATEWAY_* extras)
193 * An app which sends the {@link android.content.Intent#ACTION_CALL} intent can specify an
194 * alternative address to dial which is different from the one specified and displayed to
195 * the user. This alternative address is referred to as the gateway address.
196 */
197 public static final String GATEWAY_PROVIDER_PACKAGE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700198 "android.telecom.extra.GATEWAY_PROVIDER_PACKAGE";
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700199
200 /**
201 * An optional {@link android.content.Intent#ACTION_CALL} intent extra corresponding to the
202 * original address to dial for the call. This is used when an alternative gateway address is
203 * provided to recall the original address.
204 * The value is a {@link android.net.Uri}.
205 *
206 * (See {@link #GATEWAY_PROVIDER_PACKAGE} for details)
207 */
208 public static final String GATEWAY_ORIGINAL_ADDRESS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700209 "android.telecom.extra.GATEWAY_ORIGINAL_ADDRESS";
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700210
211 /**
Evan Charlton10197192014-07-19 15:00:29 -0700212 * The number which the party on the other side of the line will see (and use to return the
213 * call).
214 * <p>
Santos Cordon96efb482014-07-19 14:57:05 -0700215 * {@link ConnectionService}s which interact with {@link RemoteConnection}s should only populate
216 * this if the {@link android.telephony.TelephonyManager#getLine1Number()} value, as that is the
217 * user's expected caller ID.
Tyler Gunn711d876fd2014-09-19 11:17:02 -0700218 * @hide
Evan Charlton10197192014-07-19 15:00:29 -0700219 */
Divya Sharma1cb8f692015-02-24 16:25:55 -0800220 @SystemApi
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700221 public static final String EXTRA_CALL_BACK_NUMBER = "android.telecom.extra.CALL_BACK_NUMBER";
Evan Charlton10197192014-07-19 15:00:29 -0700222
223 /**
224 * The dual tone multi-frequency signaling character sent to indicate the dialing system should
225 * pause for a predefined period.
226 */
227 public static final char DTMF_CHARACTER_PAUSE = ',';
228
229 /**
230 * The dual-tone multi-frequency signaling character sent to indicate the dialing system should
231 * wait for user confirmation before proceeding.
232 */
233 public static final char DTMF_CHARACTER_WAIT = ';';
234
235 /**
236 * TTY (teletypewriter) mode is off.
237 *
238 * @hide
239 */
240 public static final int TTY_MODE_OFF = 0;
241
242 /**
243 * TTY (teletypewriter) mode is on. The speaker is off and the microphone is muted. The user
244 * will communicate with the remote party by sending and receiving text messages.
245 *
246 * @hide
247 */
248 public static final int TTY_MODE_FULL = 1;
249
250 /**
251 * TTY (teletypewriter) mode is in hearing carryover mode (HCO). The microphone is muted but the
252 * speaker is on. The user will communicate with the remote party by sending text messages and
253 * hearing an audible reply.
254 *
255 * @hide
256 */
257 public static final int TTY_MODE_HCO = 2;
258
259 /**
260 * TTY (teletypewriter) mode is in voice carryover mode (VCO). The speaker is off but the
261 * microphone is still on. User will communicate with the remote party by speaking and receiving
262 * text message replies.
263 *
264 * @hide
265 */
266 public static final int TTY_MODE_VCO = 3;
267
268 /**
269 * Broadcast intent action indicating that the current TTY mode has changed. An intent extra
270 * provides this state as an int.
Evan Charlton10197192014-07-19 15:00:29 -0700271 *
Santos Cordon96efb482014-07-19 14:57:05 -0700272 * @see #EXTRA_CURRENT_TTY_MODE
Evan Charlton10197192014-07-19 15:00:29 -0700273 * @hide
274 */
275 public static final String ACTION_CURRENT_TTY_MODE_CHANGED =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700276 "android.telecom.action.CURRENT_TTY_MODE_CHANGED";
Evan Charlton10197192014-07-19 15:00:29 -0700277
278 /**
279 * The lookup key for an int that indicates the current TTY mode.
280 * Valid modes are:
281 * - {@link #TTY_MODE_OFF}
282 * - {@link #TTY_MODE_FULL}
283 * - {@link #TTY_MODE_HCO}
284 * - {@link #TTY_MODE_VCO}
285 *
286 * @hide
287 */
288 public static final String EXTRA_CURRENT_TTY_MODE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700289 "android.telecom.intent.extra.CURRENT_TTY_MODE";
Evan Charlton10197192014-07-19 15:00:29 -0700290
291 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700292 * Broadcast intent action indicating that the TTY preferred operating mode has changed. An
293 * intent extra provides the new mode as an int.
Evan Charlton10197192014-07-19 15:00:29 -0700294 *
Santos Cordon96efb482014-07-19 14:57:05 -0700295 * @see #EXTRA_TTY_PREFERRED_MODE
Evan Charlton10197192014-07-19 15:00:29 -0700296 * @hide
297 */
298 public static final String ACTION_TTY_PREFERRED_MODE_CHANGED =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700299 "android.telecom.action.TTY_PREFERRED_MODE_CHANGED";
Evan Charlton10197192014-07-19 15:00:29 -0700300
301 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700302 * The lookup key for an int that indicates preferred TTY mode. Valid modes are: -
303 * {@link #TTY_MODE_OFF} - {@link #TTY_MODE_FULL} - {@link #TTY_MODE_HCO} -
304 * {@link #TTY_MODE_VCO}
Evan Charlton10197192014-07-19 15:00:29 -0700305 *
306 * @hide
307 */
308 public static final String EXTRA_TTY_PREFERRED_MODE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700309 "android.telecom.intent.extra.TTY_PREFERRED";
Evan Charlton10197192014-07-19 15:00:29 -0700310
Nancy Chen9d568c02014-09-08 14:17:59 -0700311 /**
312 * The following 4 constants define how properties such as phone numbers and names are
313 * displayed to the user.
314 */
315
316 /** Property is displayed normally. */
317 public static final int PRESENTATION_ALLOWED = 1;
318
319 /** Property was blocked. */
320 public static final int PRESENTATION_RESTRICTED = 2;
321
322 /** Presentation was not specified or is unknown. */
323 public static final int PRESENTATION_UNKNOWN = 3;
324
325 /** Property should be displayed as a pay phone. */
326 public static final int PRESENTATION_PAYPHONE = 4;
327
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700328 private static final String TAG = "TelecomManager";
Yorke Leeb4ce1432014-06-09 13:53:23 -0700329
330 private final Context mContext;
Yorke Leeb4ce1432014-06-09 13:53:23 -0700331
Santos Cordon6c7a3882014-06-25 15:30:08 -0700332 /**
333 * @hide
334 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700335 public static TelecomManager from(Context context) {
336 return (TelecomManager) context.getSystemService(Context.TELECOM_SERVICE);
Yorke Leeb4ce1432014-06-09 13:53:23 -0700337 }
Santos Cordon6c7a3882014-06-25 15:30:08 -0700338
339 /**
340 * @hide
341 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700342 public TelecomManager(Context context) {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700343 Context appContext = context.getApplicationContext();
344 if (appContext != null) {
345 mContext = appContext;
346 } else {
347 mContext = context;
348 }
349 }
350
351 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700352 * Return the {@link PhoneAccount} which is the user-chosen default for making outgoing phone
Nancy Chen513c8922014-09-17 14:47:20 -0700353 * calls with a specified URI scheme.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700354 * <p>
Santos Cordon96efb482014-07-19 14:57:05 -0700355 * Apps must be prepared for this method to return {@code null}, indicating that there currently
Nancy Chen513c8922014-09-17 14:47:20 -0700356 * exists no user-chosen default {@code PhoneAccount}.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700357 * <p>
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700358 * @param uriScheme The URI scheme.
Nancy Chen513c8922014-09-17 14:47:20 -0700359 * @return The {@link PhoneAccountHandle} corresponding to the user-chosen default for outgoing
360 * phone calls for a specified URI scheme.
Divya Sharma1cb8f692015-02-24 16:25:55 -0800361 * @hide
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700362 */
Divya Sharma1cb8f692015-02-24 16:25:55 -0800363 @SystemApi
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700364 public PhoneAccountHandle getDefaultOutgoingPhoneAccount(String uriScheme) {
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700365 try {
366 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700367 return getTelecomService().getDefaultOutgoingPhoneAccount(uriScheme);
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700368 }
369 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700370 Log.e(TAG, "Error calling ITelecomService#getDefaultOutgoingPhoneAccount", e);
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700371 }
372 return null;
373 }
374
375 /**
Andrew Leed4abbfb2014-09-03 14:58:27 -0700376 * Return the {@link PhoneAccount} which is the user-chosen default for making outgoing phone
377 * calls. This {@code PhoneAccount} will always be a member of the list which is returned from
Nancy Chen210ef032014-09-15 17:58:42 -0700378 * calling {@link #getCallCapablePhoneAccounts()}
Andrew Leed4abbfb2014-09-03 14:58:27 -0700379 *
380 * Apps must be prepared for this method to return {@code null}, indicating that there currently
381 * exists no user-chosen default {@code PhoneAccount}.
382 *
383 * @return The user outgoing phone account selected by the user.
384 * @hide
385 */
386 public PhoneAccountHandle getUserSelectedOutgoingPhoneAccount() {
387 try {
388 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700389 return getTelecomService().getUserSelectedOutgoingPhoneAccount();
Andrew Leed4abbfb2014-09-03 14:58:27 -0700390 }
391 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700392 Log.e(TAG, "Error calling ITelecomService#getUserSelectedOutgoingPhoneAccount", e);
Andrew Leed4abbfb2014-09-03 14:58:27 -0700393 }
394 return null;
395 }
396
397 /**
Andrew Lee59cac3a2014-08-28 16:50:10 -0700398 * Sets the default account for making outgoing phone calls.
399 * @hide
400 */
Andrew Leed4abbfb2014-09-03 14:58:27 -0700401 public void setUserSelectedOutgoingPhoneAccount(PhoneAccountHandle accountHandle) {
Andrew Lee59cac3a2014-08-28 16:50:10 -0700402 try {
403 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700404 getTelecomService().setUserSelectedOutgoingPhoneAccount(accountHandle);
Andrew Lee59cac3a2014-08-28 16:50:10 -0700405 }
406 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700407 Log.e(TAG, "Error calling ITelecomService#setUserSelectedOutgoingPhoneAccount");
Andrew Lee59cac3a2014-08-28 16:50:10 -0700408 }
409 }
410
411 /**
Andrew Lee59cac3a2014-08-28 16:50:10 -0700412 * Returns the current SIM call manager. Apps must be prepared for this method to return
413 * {@code null}, indicating that there currently exists no user-chosen default
414 * {@code PhoneAccount}.
415 * @return The phone account handle of the current sim call manager.
416 * @hide
417 */
418 public PhoneAccountHandle getSimCallManager() {
419 try {
420 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700421 return getTelecomService().getSimCallManager();
Andrew Lee59cac3a2014-08-28 16:50:10 -0700422 }
423 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700424 Log.e(TAG, "Error calling ITelecomService#getSimCallManager");
Andrew Lee59cac3a2014-08-28 16:50:10 -0700425 }
426 return null;
427 }
428
429 /**
430 * Sets the SIM call manager to the specified phone account.
431 * @param accountHandle The phone account handle of the account to set as the sim call manager.
432 * @hide
433 */
434 public void setSimCallManager(PhoneAccountHandle accountHandle) {
435 try {
436 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700437 getTelecomService().setSimCallManager(accountHandle);
Andrew Lee59cac3a2014-08-28 16:50:10 -0700438 }
439 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700440 Log.e(TAG, "Error calling ITelecomService#setSimCallManager");
Andrew Lee59cac3a2014-08-28 16:50:10 -0700441 }
442 }
443
444 /**
445 * Returns the list of registered SIM call managers.
446 * @return List of registered SIM call managers.
447 * @hide
448 */
449 public List<PhoneAccountHandle> getSimCallManagers() {
450 try {
451 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700452 return getTelecomService().getSimCallManagers();
Andrew Lee59cac3a2014-08-28 16:50:10 -0700453 }
454 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700455 Log.e(TAG, "Error calling ITelecomService#getSimCallManagers");
Andrew Lee59cac3a2014-08-28 16:50:10 -0700456 }
457 return new ArrayList<>();
458 }
459
460 /**
Evan Charltoneb0a8d52014-09-04 12:03:34 -0700461 * Returns the current connection manager. Apps must be prepared for this method to return
462 * {@code null}, indicating that there currently exists no user-chosen default
463 * {@code PhoneAccount}.
464 *
465 * @return The phone account handle of the current connection manager.
Tyler Gunn711d876fd2014-09-19 11:17:02 -0700466 * @hide
Evan Charltoneb0a8d52014-09-04 12:03:34 -0700467 */
Divya Sharma1cb8f692015-02-24 16:25:55 -0800468 @SystemApi
Evan Charltoneb0a8d52014-09-04 12:03:34 -0700469 public PhoneAccountHandle getConnectionManager() {
470 return getSimCallManager();
471 }
472
473 /**
Sailesh Nepald3312c02014-11-21 11:01:40 -0800474 * Returns the list of registered SIM call managers.
475 * @return List of registered SIM call managers.
476 * @hide
477 */
478 @SystemApi
479 public List<PhoneAccountHandle> getRegisteredConnectionManagers() {
480 return getSimCallManagers();
481 }
482
483 /**
Nancy Chen210ef032014-09-15 17:58:42 -0700484 * Returns a list of the {@link PhoneAccountHandle}s which can be used to make and receive phone
485 * calls which support the specified URI scheme.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700486 * <P>
487 * For example, invoking with {@code "tel"} will find all {@link PhoneAccountHandle}s which
488 * support telephone calls (e.g. URIs such as {@code tel:555-555-1212}). Invoking with
489 * {@code "sip"} will find all {@link PhoneAccountHandle}s which support SIP calls (e.g. URIs
490 * such as {@code sip:example@sipexample.com}).
491 *
492 * @param uriScheme The URI scheme.
493 * @return A list of {@code PhoneAccountHandle} objects supporting the URI scheme.
Divya Sharma1cb8f692015-02-24 16:25:55 -0800494 * @hide
495 */
496 @SystemApi
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700497 public List<PhoneAccountHandle> getPhoneAccountsSupportingScheme(String uriScheme) {
498 try {
499 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700500 return getTelecomService().getPhoneAccountsSupportingScheme(uriScheme);
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700501 }
502 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700503 Log.e(TAG, "Error calling ITelecomService#getPhoneAccountsSupportingScheme", e);
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700504 }
505 return new ArrayList<>();
506 }
507
Nancy Chen513c8922014-09-17 14:47:20 -0700508
509 /**
510 * Return a list of {@link PhoneAccountHandle}s which can be used to make and receive phone
511 * calls.
512 *
513 * @see #EXTRA_PHONE_ACCOUNT_HANDLE
514 * @return A list of {@code PhoneAccountHandle} objects.
515 *
516 * @hide
517 */
518 public List<PhoneAccountHandle> getCallCapablePhoneAccounts() {
519 try {
520 if (isServiceConnected()) {
521 return getTelecomService().getCallCapablePhoneAccounts();
522 }
523 } catch (RemoteException e) {
524 Log.e(TAG, "Error calling ITelecomService#getCallCapablePhoneAccounts", e);
525 }
526 return new ArrayList<>();
527 }
528
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700529 /**
Nancy Chen210ef032014-09-15 17:58:42 -0700530 * Determine whether the device has more than one account registered that can make and receive
531 * phone calls.
Nancy Chen60801182014-07-22 16:56:49 -0700532 *
Nancy Chen210ef032014-09-15 17:58:42 -0700533 * @return {@code true} if the device has more than one account registered and {@code false}
534 * otherwise.
Tyler Gunn711d876fd2014-09-19 11:17:02 -0700535 * @hide
Nancy Chen60801182014-07-22 16:56:49 -0700536 */
Divya Sharma1cb8f692015-02-24 16:25:55 -0800537 @SystemApi
Nancy Chen210ef032014-09-15 17:58:42 -0700538 public boolean hasMultipleCallCapableAccounts() {
539 return getCallCapablePhoneAccounts().size() > 1;
Nancy Chen60801182014-07-22 16:56:49 -0700540 }
541
542 /**
Nancy Chen513c8922014-09-17 14:47:20 -0700543 * Returns a list of all {@link PhoneAccount}s registered for the calling package.
544 *
545 * @return A list of {@code PhoneAccountHandle} objects.
Tyler Gunn711d876fd2014-09-19 11:17:02 -0700546 * @hide
Nancy Chen513c8922014-09-17 14:47:20 -0700547 */
Divya Sharma1cb8f692015-02-24 16:25:55 -0800548 @SystemApi
Nancy Chen513c8922014-09-17 14:47:20 -0700549 public List<PhoneAccountHandle> getPhoneAccountsForPackage() {
550 try {
551 if (isServiceConnected()) {
552 return getTelecomService().getPhoneAccountsForPackage(mContext.getPackageName());
553 }
554 } catch (RemoteException e) {
555 Log.e(TAG, "Error calling ITelecomService#getPhoneAccountsForPackage", e);
556 }
557 return null;
558 }
559
560 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700561 * Return the {@link PhoneAccount} for a specified {@link PhoneAccountHandle}. Object includes
562 * resources which can be used in a user interface.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700563 *
Evan Charlton6eb262c2014-07-19 18:18:19 -0700564 * @param account The {@link PhoneAccountHandle}.
Evan Charlton8c8a0622014-07-20 12:31:00 -0700565 * @return The {@link PhoneAccount} object.
Tyler Gunn711d876fd2014-09-19 11:17:02 -0700566 * @hide
Ihab Awad807fe0a2014-07-09 12:30:52 -0700567 */
Divya Sharma1cb8f692015-02-24 16:25:55 -0800568 @SystemApi
Evan Charlton8c8a0622014-07-20 12:31:00 -0700569 public PhoneAccount getPhoneAccount(PhoneAccountHandle account) {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700570 try {
571 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700572 return getTelecomService().getPhoneAccount(account);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700573 }
574 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700575 Log.e(TAG, "Error calling ITelecomService#getPhoneAccount", e);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700576 }
577 return null;
578 }
579
580 /**
Nancy Chen210ef032014-09-15 17:58:42 -0700581 * Returns a count of all {@link PhoneAccount}s.
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700582 *
Nancy Chen210ef032014-09-15 17:58:42 -0700583 * @return The count of {@link PhoneAccount}s.
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700584 * @hide
585 */
586 @SystemApi
587 public int getAllPhoneAccountsCount() {
588 try {
589 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700590 return getTelecomService().getAllPhoneAccountsCount();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700591 }
592 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700593 Log.e(TAG, "Error calling ITelecomService#getAllPhoneAccountsCount", e);
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700594 }
595 return 0;
596 }
597
598 /**
599 * Returns a list of all {@link PhoneAccount}s.
600 *
601 * @return All {@link PhoneAccount}s.
602 * @hide
603 */
604 @SystemApi
605 public List<PhoneAccount> getAllPhoneAccounts() {
606 try {
607 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700608 return getTelecomService().getAllPhoneAccounts();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700609 }
610 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700611 Log.e(TAG, "Error calling ITelecomService#getAllPhoneAccounts", e);
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700612 }
613 return Collections.EMPTY_LIST;
614 }
615
616 /**
617 * Returns a list of all {@link PhoneAccountHandle}s.
618 *
619 * @return All {@link PhoneAccountHandle}s.
620 * @hide
621 */
622 @SystemApi
623 public List<PhoneAccountHandle> getAllPhoneAccountHandles() {
624 try {
625 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700626 return getTelecomService().getAllPhoneAccountHandles();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700627 }
628 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700629 Log.e(TAG, "Error calling ITelecomService#getAllPhoneAccountHandles", e);
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700630 }
631 return Collections.EMPTY_LIST;
632 }
633
634 /**
Santos Cordond3a0b162014-10-28 13:10:36 -0700635 * Register a {@link PhoneAccount} for use by the system. When registering
636 * {@link PhoneAccount}s, existing registrations will be overwritten if the
637 * {@link PhoneAccountHandle} matches that of a {@link PhoneAccount} which is already
638 * registered. Once registered, the {@link PhoneAccount} is listed to the user as an option
639 * when placing calls. The user may still need to enable the {@link PhoneAccount} within
640 * the phone app settings before the account is usable.
641 * <p>
642 * A {@link SecurityException} will be thrown if an app tries to register a
643 * {@link PhoneAccountHandle} where the package name specified within
644 * {@link PhoneAccountHandle#getComponentName()} does not match the package name of the app.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700645 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700646 * @param account The complete {@link PhoneAccount}.
Evan Charltonf6a3fef2014-11-08 15:49:16 -0800647 *
Tyler Gunn711d876fd2014-09-19 11:17:02 -0700648 * @hide
Ihab Awad807fe0a2014-07-09 12:30:52 -0700649 */
Divya Sharma1cb8f692015-02-24 16:25:55 -0800650 @SystemApi
Evan Charlton8c8a0622014-07-20 12:31:00 -0700651 public void registerPhoneAccount(PhoneAccount account) {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700652 try {
653 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700654 getTelecomService().registerPhoneAccount(account);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700655 }
656 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700657 Log.e(TAG, "Error calling ITelecomService#registerPhoneAccount", e);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700658 }
659 }
660
661 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700662 * Remove a {@link PhoneAccount} registration from the system.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700663 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700664 * @param accountHandle A {@link PhoneAccountHandle} for the {@link PhoneAccount} to unregister.
Tyler Gunn711d876fd2014-09-19 11:17:02 -0700665 * @hide
Ihab Awad807fe0a2014-07-09 12:30:52 -0700666 */
Divya Sharma1cb8f692015-02-24 16:25:55 -0800667 @SystemApi
Evan Charlton8c8a0622014-07-20 12:31:00 -0700668 public void unregisterPhoneAccount(PhoneAccountHandle accountHandle) {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700669 try {
670 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700671 getTelecomService().unregisterPhoneAccount(accountHandle);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700672 }
673 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700674 Log.e(TAG, "Error calling ITelecomService#unregisterPhoneAccount", e);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700675 }
676 }
677
678 /**
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700679 * Remove all Accounts that belong to the calling package from the system.
Tyler Gunn711d876fd2014-09-19 11:17:02 -0700680 * @hide
Ihab Awad807fe0a2014-07-09 12:30:52 -0700681 */
Divya Sharma1cb8f692015-02-24 16:25:55 -0800682 @SystemApi
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700683 public void clearAccounts() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700684 try {
685 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700686 getTelecomService().clearAccounts(mContext.getPackageName());
Ihab Awad807fe0a2014-07-09 12:30:52 -0700687 }
688 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700689 Log.e(TAG, "Error calling ITelecomService#clearAccounts", e);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700690 }
691 }
692
693 /**
Anthony Lee9d23ff92014-10-27 11:28:40 -0700694 * Remove all Accounts that belong to the specified package from the system.
695 * @hide
696 */
697 public void clearAccountsForPackage(String packageName) {
698 try {
699 if (isServiceConnected() && !TextUtils.isEmpty(packageName)) {
700 getTelecomService().clearAccounts(packageName);
701 }
702 } catch (RemoteException e) {
Nancy Chenbb715ff2015-01-24 23:30:27 -0800703 Log.e(TAG, "Error calling ITelecomService#clearAccountsForPackage", e);
Anthony Lee9d23ff92014-10-27 11:28:40 -0700704 }
705 }
706
707 /**
Ihab Awad807fe0a2014-07-09 12:30:52 -0700708 * @hide
709 */
Santos Cordon6c7a3882014-06-25 15:30:08 -0700710 @SystemApi
711 public ComponentName getDefaultPhoneApp() {
712 try {
Santos Cordon9eb45932014-06-27 12:28:43 -0700713 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700714 return getTelecomService().getDefaultPhoneApp();
Santos Cordon9eb45932014-06-27 12:28:43 -0700715 }
Santos Cordon6c7a3882014-06-25 15:30:08 -0700716 } catch (RemoteException e) {
717 Log.e(TAG, "RemoteException attempting to get the default phone app.", e);
718 }
719 return null;
720 }
721
Santos Cordon9eb45932014-06-27 12:28:43 -0700722 /**
Nancy Chenb24a3352014-10-15 15:48:21 -0700723 * Return whether a given phone number is the configured voicemail number for a
724 * particular phone account.
725 *
726 * @param accountHandle The handle for the account to check the voicemail number against
727 * @param number The number to look up.
728 *
729 * @hide
730 */
731 @SystemApi
732 public boolean isVoiceMailNumber(PhoneAccountHandle accountHandle, String number) {
733 try {
734 if (isServiceConnected()) {
735 return getTelecomService().isVoiceMailNumber(accountHandle, number);
736 }
737 } catch (RemoteException e) {
Nancy Chenbb715ff2015-01-24 23:30:27 -0800738 Log.e(TAG, "RemoteException calling ITelecomService#isVoiceMailNumber.", e);
Nancy Chenb24a3352014-10-15 15:48:21 -0700739 }
740 return false;
741 }
742
743 /**
Divya Sharma1cb8f692015-02-24 16:25:55 -0800744 * Return whether a given phone account has a voicemail number configured.
745 *
746 * @param accountHandle The handle for the account to check for a voicemail number.
747 * @return {@code true} If the given phone account has a voicemail number.
748 *
749 * @hide
750 */
751 @SystemApi
752 public boolean hasVoiceMailNumber(PhoneAccountHandle accountHandle) {
Nancy Chenb17e9172014-12-03 15:18:08 -0800753 try {
754 if (isServiceConnected()) {
755 return getTelecomService().hasVoiceMailNumber(accountHandle);
756 }
757 } catch (RemoteException e) {
758 Log.e(TAG, "RemoteException calling ITelecomService#hasVoiceMailNumber.", e);
759 }
Divya Sharma1cb8f692015-02-24 16:25:55 -0800760 return false;
761 }
762
763 /**
764 * Return the line 1 phone number for given phone account.
765 *
766 * @param accountHandle The handle for the account retrieve a number for.
767 * @return A string representation of the line 1 phone number.
768 *
769 * @hide
770 */
771 @SystemApi
772 public String getLine1Number(PhoneAccountHandle accountHandle) {
Nancy Chenbb715ff2015-01-24 23:30:27 -0800773 try {
774 if (isServiceConnected()) {
775 return getTelecomService().getLine1Number(accountHandle);
776 }
777 } catch (RemoteException e) {
778 Log.e(TAG, "RemoteException calling ITelecomService#getLine1Number.", e);
779 }
Divya Sharma1cb8f692015-02-24 16:25:55 -0800780 return null;
781 }
782
783 /**
Santos Cordon9eb45932014-06-27 12:28:43 -0700784 * Returns whether there is an ongoing phone call (can be in dialing, ringing, active or holding
785 * states).
Nancy Chen0eb1e402014-08-21 22:52:29 -0700786 * <p>
787 * Requires permission: {@link android.Manifest.permission#READ_PHONE_STATE}
788 * </p>
Santos Cordon9eb45932014-06-27 12:28:43 -0700789 */
Nancy Chen0eb1e402014-08-21 22:52:29 -0700790 public boolean isInCall() {
Santos Cordon9eb45932014-06-27 12:28:43 -0700791 try {
792 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700793 return getTelecomService().isInCall();
Santos Cordon9eb45932014-06-27 12:28:43 -0700794 }
795 } catch (RemoteException e) {
Yorke Lee2ae312e2014-09-12 17:58:48 -0700796 Log.e(TAG, "RemoteException calling isInCall().", e);
Santos Cordon9eb45932014-06-27 12:28:43 -0700797 }
798 return false;
799 }
800
801 /**
Yorke Lee2ae312e2014-09-12 17:58:48 -0700802 * Returns one of the following constants that represents the current state of Telecom:
803 *
804 * {@link TelephonyManager#CALL_STATE_RINGING}
805 * {@link TelephonyManager#CALL_STATE_OFFHOOK}
806 * {@link TelephonyManager#CALL_STATE_IDLE}
Yorke Lee2ae312e2014-09-12 17:58:48 -0700807 * @hide
808 */
809 @SystemApi
810 public int getCallState() {
811 try {
812 if (isServiceConnected()) {
813 return getTelecomService().getCallState();
814 }
815 } catch (RemoteException e) {
816 Log.d(TAG, "RemoteException calling getCallState().", e);
817 }
818 return TelephonyManager.CALL_STATE_IDLE;
819 }
820
821 /**
Santos Cordon9eb45932014-06-27 12:28:43 -0700822 * Returns whether there currently exists is a ringing incoming-call.
823 *
824 * @hide
825 */
826 @SystemApi
827 public boolean isRinging() {
828 try {
829 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700830 return getTelecomService().isRinging();
Santos Cordon9eb45932014-06-27 12:28:43 -0700831 }
832 } catch (RemoteException e) {
833 Log.e(TAG, "RemoteException attempting to get ringing state of phone app.", e);
834 }
835 return false;
836 }
837
838 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700839 * Ends an ongoing call.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700840 * TODO: L-release - need to convert all invocations of ITelecomService#endCall to use this
Santos Cordon96efb482014-07-19 14:57:05 -0700841 * method (clockwork & gearhead).
Santos Cordon9eb45932014-06-27 12:28:43 -0700842 * @hide
843 */
844 @SystemApi
845 public boolean endCall() {
846 try {
847 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700848 return getTelecomService().endCall();
Santos Cordon9eb45932014-06-27 12:28:43 -0700849 }
850 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700851 Log.e(TAG, "Error calling ITelecomService#endCall", e);
Santos Cordon9eb45932014-06-27 12:28:43 -0700852 }
853 return false;
854 }
855
856 /**
857 * If there is a ringing incoming call, this method accepts the call on behalf of the user.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700858 * TODO: L-release - need to convert all invocation of ITelecmmService#answerRingingCall to use
Santos Cordon96efb482014-07-19 14:57:05 -0700859 * this method (clockwork & gearhead).
Santos Cordon9eb45932014-06-27 12:28:43 -0700860 *
861 * @hide
862 */
863 @SystemApi
864 public void acceptRingingCall() {
865 try {
866 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700867 getTelecomService().acceptRingingCall();
Santos Cordon9eb45932014-06-27 12:28:43 -0700868 }
869 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700870 Log.e(TAG, "Error calling ITelecomService#acceptRingingCall", e);
Santos Cordon9eb45932014-06-27 12:28:43 -0700871 }
872 }
873
874 /**
875 * Silences the ringer if a ringing call exists.
876 *
877 * @hide
878 */
879 @SystemApi
880 public void silenceRinger() {
881 try {
882 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700883 getTelecomService().silenceRinger();
Santos Cordon9eb45932014-06-27 12:28:43 -0700884 }
885 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700886 Log.e(TAG, "Error calling ITelecomService#silenceRinger", e);
Santos Cordon9eb45932014-06-27 12:28:43 -0700887 }
888 }
889
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700890 /**
891 * Returns whether TTY is supported on this device.
892 *
893 * @hide
894 */
895 @SystemApi
896 public boolean isTtySupported() {
897 try {
898 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700899 return getTelecomService().isTtySupported();
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700900 }
901 } catch (RemoteException e) {
902 Log.e(TAG, "RemoteException attempting to get TTY supported state.", e);
903 }
904 return false;
905 }
906
907 /**
908 * 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 -0700909 * settings and have a wired headset plugged in.
910 * Valid modes are:
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700911 * - {@link TelecomManager#TTY_MODE_OFF}
912 * - {@link TelecomManager#TTY_MODE_FULL}
913 * - {@link TelecomManager#TTY_MODE_HCO}
914 * - {@link TelecomManager#TTY_MODE_VCO}
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700915 * @hide
916 */
917 public int getCurrentTtyMode() {
918 try {
919 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700920 return getTelecomService().getCurrentTtyMode();
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700921 }
922 } catch (RemoteException e) {
923 Log.e(TAG, "RemoteException attempting to get the current TTY mode.", e);
924 }
Evan Charlton10197192014-07-19 15:00:29 -0700925 return TTY_MODE_OFF;
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700926 }
927
Santos Cordon96efb482014-07-19 14:57:05 -0700928 /**
Sandeep Kunta0f8bfc52014-09-01 17:21:05 +0530929 * Returns current active subscription.
930 * @hide
931 */
Muhammed Siju85e8a60bf2015-03-18 18:20:13 +0530932 public int getActiveSubscription() {
Sandeep Kunta0f8bfc52014-09-01 17:21:05 +0530933 try {
934 if (isServiceConnected()) {
Natiq Ahmed653f5842014-09-30 16:18:10 +0530935 return getTelecomService().getActiveSubscription();
Sandeep Kunta0f8bfc52014-09-01 17:21:05 +0530936 }
937 } catch (RemoteException e) {
938 Log.e(TAG, "RemoteException attempting to get the active subsription.", e);
939 }
Divya Sharma1cb8f692015-02-24 16:25:55 -0800940 return SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Sandeep Kunta0f8bfc52014-09-01 17:21:05 +0530941 }
942
943 /**
944 * switches to other active subscription.
945 * @hide
946 */
Muhammed Siju85e8a60bf2015-03-18 18:20:13 +0530947 public void switchToOtherActiveSub(int subId) {
Sandeep Kunta0f8bfc52014-09-01 17:21:05 +0530948 try {
949 if (isServiceConnected()) {
Natiq Ahmed653f5842014-09-30 16:18:10 +0530950 getTelecomService().switchToOtherActiveSub(subId);
Sandeep Kunta0f8bfc52014-09-01 17:21:05 +0530951 }
952 } catch (RemoteException e) {
953 Log.e(TAG, "RemoteException attempting to switchToOtherActiveSub.", e);
954 }
955 }
956
957 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700958 * Registers a new incoming call. A {@link ConnectionService} should invoke this method when it
959 * has an incoming call. The specified {@link PhoneAccountHandle} must have been registered
Nancy Chen210ef032014-09-15 17:58:42 -0700960 * with {@link #registerPhoneAccount}. Once invoked, this method will cause the system to bind
961 * to the {@link ConnectionService} associated with the {@link PhoneAccountHandle} and request
Santos Cordon96efb482014-07-19 14:57:05 -0700962 * additional information about the call (See
963 * {@link ConnectionService#onCreateIncomingConnection}) before starting the incoming call UI.
964 *
965 * @param phoneAccount A {@link PhoneAccountHandle} registered with
966 * {@link #registerPhoneAccount}.
967 * @param extras A bundle that will be passed through to
968 * {@link ConnectionService#onCreateIncomingConnection}.
Tyler Gunn711d876fd2014-09-19 11:17:02 -0700969 * @hide
Santos Cordon96efb482014-07-19 14:57:05 -0700970 */
Divya Sharma1cb8f692015-02-24 16:25:55 -0800971 @SystemApi
Santos Cordon96efb482014-07-19 14:57:05 -0700972 public void addNewIncomingCall(PhoneAccountHandle phoneAccount, Bundle extras) {
973 try {
974 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700975 getTelecomService().addNewIncomingCall(
Santos Cordon96efb482014-07-19 14:57:05 -0700976 phoneAccount, extras == null ? new Bundle() : extras);
977 }
978 } catch (RemoteException e) {
979 Log.e(TAG, "RemoteException adding a new incoming call: " + phoneAccount, e);
980 }
981 }
982
Nancy Chen0eb1e402014-08-21 22:52:29 -0700983 /**
Yorke Leec3cf9822014-10-02 09:38:39 -0700984 * Registers a new unknown call with Telecom. This can only be called by the system Telephony
985 * service. This is invoked when Telephony detects a new unknown connection that was neither
986 * a new incoming call, nor an user-initiated outgoing call.
987 *
988 * @param phoneAccount A {@link PhoneAccountHandle} registered with
989 * {@link #registerPhoneAccount}.
990 * @param extras A bundle that will be passed through to
991 * {@link ConnectionService#onCreateIncomingConnection}.
992 * @hide
993 */
994 @SystemApi
995 public void addNewUnknownCall(PhoneAccountHandle phoneAccount, Bundle extras) {
996 try {
997 if (isServiceConnected()) {
998 getTelecomService().addNewUnknownCall(
999 phoneAccount, extras == null ? new Bundle() : extras);
1000 }
1001 } catch (RemoteException e) {
1002 Log.e(TAG, "RemoteException adding a new unknown call: " + phoneAccount, e);
1003 }
1004 }
1005
1006 /**
Nancy Chen0eb1e402014-08-21 22:52:29 -07001007 * Processes the specified dial string as an MMI code.
1008 * MMI codes are any sequence of characters entered into the dialpad that contain a "*" or "#".
1009 * Some of these sequences launch special behavior through handled by Telephony.
Nancy Chena487cda2014-10-16 18:38:21 -07001010 * This method uses the default subscription.
Nancy Chen0eb1e402014-08-21 22:52:29 -07001011 * <p>
1012 * Requires that the method-caller be set as the system dialer app.
1013 * </p>
1014 *
1015 * @param dialString The digits to dial.
1016 * @return True if the digits were processed as an MMI code, false otherwise.
1017 */
1018 public boolean handleMmi(String dialString) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001019 ITelecomService service = getTelecomService();
Nancy Chen0eb1e402014-08-21 22:52:29 -07001020 if (service != null) {
1021 try {
1022 return service.handlePinMmi(dialString);
1023 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001024 Log.e(TAG, "Error calling ITelecomService#handlePinMmi", e);
Nancy Chen0eb1e402014-08-21 22:52:29 -07001025 }
1026 }
1027 return false;
1028 }
1029
1030 /**
Divya Sharma1cb8f692015-02-24 16:25:55 -08001031 * Processes the specified dial string as an MMI code.
1032 * MMI codes are any sequence of characters entered into the dialpad that contain a "*" or "#".
1033 * Some of these sequences launch special behavior through handled by Telephony.
1034 * <p>
1035 * Requires that the method-caller be set as the system dialer app.
1036 * </p>
1037 *
1038 * @param accountHandle The handle for the account the MMI code should apply to.
1039 * @param dialString The digits to dial.
1040 * @return True if the digits were processed as an MMI code, false otherwise.
1041 * @hide
1042 */
1043 @SystemApi
Nancy Chena487cda2014-10-16 18:38:21 -07001044 public boolean handleMmi(PhoneAccountHandle accountHandle, String dialString) {
1045 ITelecomService service = getTelecomService();
1046 if (service != null) {
1047 try {
1048 return service.handlePinMmiForPhoneAccount(accountHandle, dialString);
1049 } catch (RemoteException e) {
1050 Log.e(TAG, "Error calling ITelecomService#handlePinMmi", e);
1051 }
1052 }
Divya Sharma1cb8f692015-02-24 16:25:55 -08001053 return false;
Nancy Chena487cda2014-10-16 18:38:21 -07001054 }
Divya Sharma1cb8f692015-02-24 16:25:55 -08001055
1056 /**
1057 * @param accountHandle The handle for the account to derive an adn query URI for or
1058 * {@code null} to return a URI which will use the default account.
1059 * @return The URI (with the content:// scheme) specific to the specified {@link PhoneAccount}
1060 * for the the content retrieve.
1061 * @hide
1062 */
1063 @SystemApi
1064 public Uri getAdnUriForPhoneAccount(PhoneAccountHandle accountHandle) {
Nancy Chen41bbcbe2014-10-29 18:22:11 -07001065 ITelecomService service = getTelecomService();
1066 if (service != null && accountHandle != null) {
1067 try {
1068 return service.getAdnUriForPhoneAccount(accountHandle);
1069 } catch (RemoteException e) {
1070 Log.e(TAG, "Error calling ITelecomService#getAdnUriForPhoneAccount", e);
1071 }
1072 }
1073 return Uri.parse("content://icc/adn");
Divya Sharma1cb8f692015-02-24 16:25:55 -08001074 }
1075
1076 /**
Nancy Chen0eb1e402014-08-21 22:52:29 -07001077 * Removes the missed-call notification if one is present.
1078 * <p>
1079 * Requires that the method-caller be set as the system dialer app.
1080 * </p>
1081 */
1082 public void cancelMissedCallsNotification() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001083 ITelecomService service = getTelecomService();
Nancy Chen0eb1e402014-08-21 22:52:29 -07001084 if (service != null) {
1085 try {
1086 service.cancelMissedCallsNotification();
1087 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001088 Log.e(TAG, "Error calling ITelecomService#cancelMissedCallsNotification", e);
Nancy Chen0eb1e402014-08-21 22:52:29 -07001089 }
1090 }
1091 }
1092
1093 /**
1094 * Brings the in-call screen to the foreground if there is an ongoing call. If there is
1095 * currently no ongoing call, then this method does nothing.
1096 * <p>
1097 * Requires that the method-caller be set as the system dialer app or have the
1098 * {@link android.Manifest.permission#READ_PHONE_STATE} permission.
1099 * </p>
1100 *
1101 * @param showDialpad Brings up the in-call dialpad as part of showing the in-call screen.
1102 */
1103 public void showInCallScreen(boolean showDialpad) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001104 ITelecomService service = getTelecomService();
Nancy Chen0eb1e402014-08-21 22:52:29 -07001105 if (service != null) {
1106 try {
1107 service.showInCallScreen(showDialpad);
1108 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001109 Log.e(TAG, "Error calling ITelecomService#showCallScreen", e);
Nancy Chen0eb1e402014-08-21 22:52:29 -07001110 }
1111 }
1112 }
1113
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001114 private ITelecomService getTelecomService() {
1115 return ITelecomService.Stub.asInterface(ServiceManager.getService(Context.TELECOM_SERVICE));
Santos Cordon6c7a3882014-06-25 15:30:08 -07001116 }
Santos Cordon9eb45932014-06-27 12:28:43 -07001117
1118 private boolean isServiceConnected() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001119 boolean isConnected = getTelecomService() != null;
Santos Cordon9eb45932014-06-27 12:28:43 -07001120 if (!isConnected) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001121 Log.w(TAG, "Telecom Service not found.");
Santos Cordon9eb45932014-06-27 12:28:43 -07001122 }
1123 return isConnected;
1124 }
Evan Charlton235c1592014-09-05 15:41:23 +00001125}