blob: 9739d4e3f0735e7f60bf572b151adc00e216e8dd [file] [log] [blame]
Yorke Leeb4ce1432014-06-09 13:53:23 -07001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
Santos Cordon9eb45932014-06-27 12:28:43 -07004 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5 * in compliance with the License. You may obtain a copy of the License at
Yorke Leeb4ce1432014-06-09 13:53:23 -07006 *
Santos Cordon9eb45932014-06-27 12:28:43 -07007 * http://www.apache.org/licenses/LICENSE-2.0
Yorke Leeb4ce1432014-06-09 13:53:23 -07008 *
Santos Cordon9eb45932014-06-27 12:28:43 -07009 * Unless required by applicable law or agreed to in writing, software distributed under the License
10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11 * or implied. See the License for the specific language governing permissions and limitations under
12 * the License.
Yorke Leeb4ce1432014-06-09 13:53:23 -070013 */
14
Tyler Gunnef9f6f92014-09-12 22:16:17 -070015package android.telecom;
Yorke Leeb4ce1432014-06-09 13:53:23 -070016
Santos Cordon6c7a3882014-06-25 15:30:08 -070017import android.annotation.SystemApi;
18import android.content.ComponentName;
Yorke Leeb4ce1432014-06-09 13:53:23 -070019import android.content.Context;
Nancy Chenb2299c12014-10-29 18:22:11 -070020import android.net.Uri;
Santos Cordon96efb482014-07-19 14:57:05 -070021import android.os.Bundle;
Santos Cordon6c7a3882014-06-25 15:30:08 -070022import android.os.RemoteException;
23import android.os.ServiceManager;
Yorke Lee2ae312e2014-09-12 17:58:48 -070024import android.telephony.TelephonyManager;
Anthony Lee67279262014-10-27 11:28:40 -070025import android.text.TextUtils;
Santos Cordon6c7a3882014-06-25 15:30:08 -070026import android.util.Log;
Yorke Leeb4ce1432014-06-09 13:53:23 -070027
Tyler Gunnef9f6f92014-09-12 22:16:17 -070028import com.android.internal.telecom.ITelecomService;
Yorke Leeb4ce1432014-06-09 13:53:23 -070029
Jay Shrauner7746a942014-08-26 12:15:15 -070030import java.util.ArrayList;
Tyler Gunna1ed7d12014-09-08 09:52:22 -070031import java.util.Collections;
Ihab Awad807fe0a2014-07-09 12:30:52 -070032import java.util.List;
33
Yorke Leeb4ce1432014-06-09 13:53:23 -070034/**
Santos Cordond9e614f2014-10-28 13:10:36 -070035 * Provides access to information about active calls and registration/call-management functionality.
Evan Charlton0e094d92014-11-08 15:49:16 -080036 * Apps can use methods in this class to determine the current call state.
Santos Cordond9e614f2014-10-28 13:10:36 -070037 * <p>
38 * Apps do not instantiate this class directly; instead, they retrieve a reference to an instance
39 * through {@link Context#getSystemService Context.getSystemService(Context.TELECOM_SERVICE)}.
40 * <p>
41 * Note that access to some telecom information is permission-protected. Your app cannot access the
42 * protected information or gain access to protected functionality unless it has the appropriate
43 * permissions declared in its manifest file. Where permissions apply, they are noted in the method
44 * descriptions.
Yorke Leeb4ce1432014-06-09 13:53:23 -070045 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -070046public class TelecomManager {
Ihab Awad807fe0a2014-07-09 12:30:52 -070047
Evan Charlton10197192014-07-19 15:00:29 -070048 /**
Santos Cordon96efb482014-07-19 14:57:05 -070049 * Activity action: Starts the UI for handing an incoming call. This intent starts the in-call
Tyler Gunnef9f6f92014-09-12 22:16:17 -070050 * UI by notifying the Telecom system that an incoming call exists for a specific call service
51 * (see {@link android.telecom.ConnectionService}). Telecom reads the Intent extras to find
52 * and bind to the appropriate {@link android.telecom.ConnectionService} which Telecom will
Santos Cordon96efb482014-07-19 14:57:05 -070053 * ultimately use to control and get information about the call.
54 * <p>
55 * Input: get*Extra field {@link #EXTRA_PHONE_ACCOUNT_HANDLE} contains the component name of the
Tyler Gunnef9f6f92014-09-12 22:16:17 -070056 * {@link android.telecom.ConnectionService} that Telecom should bind to. Telecom will then
Evan Charlton10197192014-07-19 15:00:29 -070057 * ask the connection service for more information about the call prior to showing any UI.
58 *
Santos Cordon96efb482014-07-19 14:57:05 -070059 * @hide
Evan Charlton10197192014-07-19 15:00:29 -070060 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -070061 public static final String ACTION_INCOMING_CALL = "android.telecom.action.INCOMING_CALL";
Evan Charlton10197192014-07-19 15:00:29 -070062
63 /**
Yorke Leec3cf9822014-10-02 09:38:39 -070064 * Similar to {@link #ACTION_INCOMING_CALL}, but is used only by Telephony to add a new
65 * sim-initiated MO call for carrier testing.
66 * @hide
67 */
68 public static final String ACTION_NEW_UNKNOWN_CALL = "android.telecom.action.NEW_UNKNOWN_CALL";
69
70 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -070071 * The {@link android.content.Intent} action used to configure a
Tyler Gunnef9f6f92014-09-12 22:16:17 -070072 * {@link android.telecom.ConnectionService}.
Evan Charlton0e094d92014-11-08 15:49:16 -080073 * @hide
Evan Charlton10197192014-07-19 15:00:29 -070074 */
Evan Charlton0e094d92014-11-08 15:49:16 -080075 @SystemApi
Evan Charlton10197192014-07-19 15:00:29 -070076 public static final String ACTION_CONNECTION_SERVICE_CONFIGURE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -070077 "android.telecom.action.CONNECTION_SERVICE_CONFIGURE";
Evan Charlton10197192014-07-19 15:00:29 -070078
79 /**
Andrew Lee873cfbf2015-02-26 15:22:00 -080080 * The {@link android.content.Intent} action used to show the call accessibility settings page.
81 */
82 public static final String ACTION_SHOW_CALL_ACCESSIBILITY_SETTINGS =
83 "android.telecom.action.SHOW_CALL_ACCESSIBILITY_SETTINGS";
84
85 /**
Yorke Lee3818a8922014-07-21 15:57:17 -070086 * The {@link android.content.Intent} action used to show the call settings page.
87 */
88 public static final String ACTION_SHOW_CALL_SETTINGS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -070089 "android.telecom.action.SHOW_CALL_SETTINGS";
Yorke Lee3818a8922014-07-21 15:57:17 -070090
91 /**
Andrew Lee866080f2015-02-19 12:05:33 -080092 * The {@link android.content.Intent} action used to show the respond via SMS settings page.
93 */
94 public static final String ACTION_SHOW_RESPOND_VIA_SMS_SETTINGS =
95 "android.telecom.action.SHOW_RESPOND_VIA_SMS_SETTINGS";
96
97 /**
Evan Charlton6d8604f2014-09-04 12:38:17 -070098 * The {@link android.content.Intent} action used to show the settings page used to configure
99 * {@link PhoneAccount} preferences.
Evan Charlton0e094d92014-11-08 15:49:16 -0800100 * @hide
Evan Charlton6d8604f2014-09-04 12:38:17 -0700101 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800102 @SystemApi
Evan Charlton6d8604f2014-09-04 12:38:17 -0700103 public static final String ACTION_CHANGE_PHONE_ACCOUNTS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700104 "android.telecom.action.CHANGE_PHONE_ACCOUNTS";
Evan Charlton6d8604f2014-09-04 12:38:17 -0700105
106 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700107 * Optional extra for {@link android.content.Intent#ACTION_CALL} containing a boolean that
108 * determines whether the speakerphone should be automatically turned on for an outgoing call.
Evan Charlton10197192014-07-19 15:00:29 -0700109 */
110 public static final String EXTRA_START_CALL_WITH_SPEAKERPHONE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700111 "android.telecom.extra.START_CALL_WITH_SPEAKERPHONE";
Evan Charlton10197192014-07-19 15:00:29 -0700112
113 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700114 * Optional extra for {@link android.content.Intent#ACTION_CALL} containing an integer that
115 * determines the desired video state for an outgoing call.
Santos Cordon96efb482014-07-19 14:57:05 -0700116 * Valid options:
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700117 * {@link VideoProfile.VideoState#AUDIO_ONLY},
118 * {@link VideoProfile.VideoState#BIDIRECTIONAL},
119 * {@link VideoProfile.VideoState#RX_ENABLED},
120 * {@link VideoProfile.VideoState#TX_ENABLED}.
Evan Charlton10197192014-07-19 15:00:29 -0700121 */
122 public static final String EXTRA_START_CALL_WITH_VIDEO_STATE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700123 "android.telecom.extra.START_CALL_WITH_VIDEO_STATE";
Evan Charlton10197192014-07-19 15:00:29 -0700124
125 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700126 * The extra used with an {@link android.content.Intent#ACTION_CALL} and
127 * {@link android.content.Intent#ACTION_DIAL} {@code Intent} to specify a
128 * {@link PhoneAccountHandle} to use when making the call.
Evan Charlton10197192014-07-19 15:00:29 -0700129 * <p class="note">
Santos Cordon96efb482014-07-19 14:57:05 -0700130 * Retrieve with {@link android.content.Intent#getParcelableExtra(String)}.
Evan Charlton10197192014-07-19 15:00:29 -0700131 */
Evan Charlton6eb262c2014-07-19 18:18:19 -0700132 public static final String EXTRA_PHONE_ACCOUNT_HANDLE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700133 "android.telecom.extra.PHONE_ACCOUNT_HANDLE";
Evan Charlton10197192014-07-19 15:00:29 -0700134
135 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700136 * Optional extra for {@link #ACTION_INCOMING_CALL} containing a {@link Bundle} which contains
137 * metadata about the call. This {@link Bundle} will be returned to the
138 * {@link ConnectionService}.
139 *
140 * @hide
Evan Charlton10197192014-07-19 15:00:29 -0700141 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800142 @SystemApi
Evan Charlton10197192014-07-19 15:00:29 -0700143 public static final String EXTRA_INCOMING_CALL_EXTRAS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700144 "android.telecom.extra.INCOMING_CALL_EXTRAS";
Evan Charlton10197192014-07-19 15:00:29 -0700145
146 /**
Nancy Chen10798dc2014-08-08 14:00:25 -0700147 * Optional extra for {@link android.content.Intent#ACTION_CALL} and
148 * {@link android.content.Intent#ACTION_DIAL} {@code Intent} containing a {@link Bundle}
149 * which contains metadata about the call. This {@link Bundle} will be saved into
150 * {@code Call.Details}.
Nancy Chen10798dc2014-08-08 14:00:25 -0700151 */
152 public static final String EXTRA_OUTGOING_CALL_EXTRAS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700153 "android.telecom.extra.OUTGOING_CALL_EXTRAS";
Nancy Chen10798dc2014-08-08 14:00:25 -0700154
155 /**
Yorke Leec3cf9822014-10-02 09:38:39 -0700156 * @hide
157 */
158 public static final String EXTRA_UNKNOWN_CALL_HANDLE =
159 "android.telecom.extra.UNKNOWN_CALL_HANDLE";
160
161 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700162 * Optional extra for {@link android.telephony.TelephonyManager#ACTION_PHONE_STATE_CHANGED}
163 * containing the disconnect code.
Evan Charlton10197192014-07-19 15:00:29 -0700164 */
165 public static final String EXTRA_CALL_DISCONNECT_CAUSE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700166 "android.telecom.extra.CALL_DISCONNECT_CAUSE";
Evan Charlton10197192014-07-19 15:00:29 -0700167
168 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700169 * Optional extra for {@link android.telephony.TelephonyManager#ACTION_PHONE_STATE_CHANGED}
170 * containing the disconnect message.
Evan Charlton10197192014-07-19 15:00:29 -0700171 */
172 public static final String EXTRA_CALL_DISCONNECT_MESSAGE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700173 "android.telecom.extra.CALL_DISCONNECT_MESSAGE";
Evan Charlton10197192014-07-19 15:00:29 -0700174
175 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700176 * Optional extra for {@link android.telephony.TelephonyManager#ACTION_PHONE_STATE_CHANGED}
177 * containing the component name of the associated connection service.
Evan Charlton0e094d92014-11-08 15:49:16 -0800178 * @hide
Evan Charlton10197192014-07-19 15:00:29 -0700179 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800180 @SystemApi
Evan Charlton10197192014-07-19 15:00:29 -0700181 public static final String EXTRA_CONNECTION_SERVICE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700182 "android.telecom.extra.CONNECTION_SERVICE";
Evan Charlton10197192014-07-19 15:00:29 -0700183
184 /**
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700185 * An optional {@link android.content.Intent#ACTION_CALL} intent extra denoting the
186 * package name of the app specifying an alternative gateway for the call.
187 * The value is a string.
188 *
189 * (The following comment corresponds to the all GATEWAY_* extras)
190 * An app which sends the {@link android.content.Intent#ACTION_CALL} intent can specify an
191 * alternative address to dial which is different from the one specified and displayed to
192 * the user. This alternative address is referred to as the gateway address.
193 */
194 public static final String GATEWAY_PROVIDER_PACKAGE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700195 "android.telecom.extra.GATEWAY_PROVIDER_PACKAGE";
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700196
197 /**
198 * An optional {@link android.content.Intent#ACTION_CALL} intent extra corresponding to the
199 * original address to dial for the call. This is used when an alternative gateway address is
200 * provided to recall the original address.
201 * The value is a {@link android.net.Uri}.
202 *
203 * (See {@link #GATEWAY_PROVIDER_PACKAGE} for details)
204 */
205 public static final String GATEWAY_ORIGINAL_ADDRESS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700206 "android.telecom.extra.GATEWAY_ORIGINAL_ADDRESS";
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700207
208 /**
Evan Charlton10197192014-07-19 15:00:29 -0700209 * The number which the party on the other side of the line will see (and use to return the
210 * call).
211 * <p>
Santos Cordon96efb482014-07-19 14:57:05 -0700212 * {@link ConnectionService}s which interact with {@link RemoteConnection}s should only populate
213 * this if the {@link android.telephony.TelephonyManager#getLine1Number()} value, as that is the
214 * user's expected caller ID.
Evan Charlton0e094d92014-11-08 15:49:16 -0800215 * @hide
Evan Charlton10197192014-07-19 15:00:29 -0700216 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800217 @SystemApi
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700218 public static final String EXTRA_CALL_BACK_NUMBER = "android.telecom.extra.CALL_BACK_NUMBER";
Evan Charlton10197192014-07-19 15:00:29 -0700219
220 /**
221 * The dual tone multi-frequency signaling character sent to indicate the dialing system should
222 * pause for a predefined period.
223 */
224 public static final char DTMF_CHARACTER_PAUSE = ',';
225
226 /**
227 * The dual-tone multi-frequency signaling character sent to indicate the dialing system should
228 * wait for user confirmation before proceeding.
229 */
230 public static final char DTMF_CHARACTER_WAIT = ';';
231
232 /**
233 * TTY (teletypewriter) mode is off.
234 *
235 * @hide
236 */
237 public static final int TTY_MODE_OFF = 0;
238
239 /**
240 * TTY (teletypewriter) mode is on. The speaker is off and the microphone is muted. The user
241 * will communicate with the remote party by sending and receiving text messages.
242 *
243 * @hide
244 */
245 public static final int TTY_MODE_FULL = 1;
246
247 /**
248 * TTY (teletypewriter) mode is in hearing carryover mode (HCO). The microphone is muted but the
249 * speaker is on. The user will communicate with the remote party by sending text messages and
250 * hearing an audible reply.
251 *
252 * @hide
253 */
254 public static final int TTY_MODE_HCO = 2;
255
256 /**
257 * TTY (teletypewriter) mode is in voice carryover mode (VCO). The speaker is off but the
258 * microphone is still on. User will communicate with the remote party by speaking and receiving
259 * text message replies.
260 *
261 * @hide
262 */
263 public static final int TTY_MODE_VCO = 3;
264
265 /**
266 * Broadcast intent action indicating that the current TTY mode has changed. An intent extra
267 * provides this state as an int.
Evan Charlton10197192014-07-19 15:00:29 -0700268 *
Santos Cordon96efb482014-07-19 14:57:05 -0700269 * @see #EXTRA_CURRENT_TTY_MODE
Evan Charlton10197192014-07-19 15:00:29 -0700270 * @hide
271 */
272 public static final String ACTION_CURRENT_TTY_MODE_CHANGED =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700273 "android.telecom.action.CURRENT_TTY_MODE_CHANGED";
Evan Charlton10197192014-07-19 15:00:29 -0700274
275 /**
276 * The lookup key for an int that indicates the current TTY mode.
277 * Valid modes are:
278 * - {@link #TTY_MODE_OFF}
279 * - {@link #TTY_MODE_FULL}
280 * - {@link #TTY_MODE_HCO}
281 * - {@link #TTY_MODE_VCO}
282 *
283 * @hide
284 */
285 public static final String EXTRA_CURRENT_TTY_MODE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700286 "android.telecom.intent.extra.CURRENT_TTY_MODE";
Evan Charlton10197192014-07-19 15:00:29 -0700287
288 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700289 * Broadcast intent action indicating that the TTY preferred operating mode has changed. An
290 * intent extra provides the new mode as an int.
Evan Charlton10197192014-07-19 15:00:29 -0700291 *
Santos Cordon96efb482014-07-19 14:57:05 -0700292 * @see #EXTRA_TTY_PREFERRED_MODE
Evan Charlton10197192014-07-19 15:00:29 -0700293 * @hide
294 */
295 public static final String ACTION_TTY_PREFERRED_MODE_CHANGED =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700296 "android.telecom.action.TTY_PREFERRED_MODE_CHANGED";
Evan Charlton10197192014-07-19 15:00:29 -0700297
298 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700299 * The lookup key for an int that indicates preferred TTY mode. Valid modes are: -
300 * {@link #TTY_MODE_OFF} - {@link #TTY_MODE_FULL} - {@link #TTY_MODE_HCO} -
301 * {@link #TTY_MODE_VCO}
Evan Charlton10197192014-07-19 15:00:29 -0700302 *
303 * @hide
304 */
305 public static final String EXTRA_TTY_PREFERRED_MODE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700306 "android.telecom.intent.extra.TTY_PREFERRED";
Evan Charlton10197192014-07-19 15:00:29 -0700307
Nancy Chen9d568c02014-09-08 14:17:59 -0700308 /**
309 * The following 4 constants define how properties such as phone numbers and names are
310 * displayed to the user.
311 */
312
313 /** Property is displayed normally. */
314 public static final int PRESENTATION_ALLOWED = 1;
315
316 /** Property was blocked. */
317 public static final int PRESENTATION_RESTRICTED = 2;
318
319 /** Presentation was not specified or is unknown. */
320 public static final int PRESENTATION_UNKNOWN = 3;
321
322 /** Property should be displayed as a pay phone. */
323 public static final int PRESENTATION_PAYPHONE = 4;
324
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700325 private static final String TAG = "TelecomManager";
Yorke Leeb4ce1432014-06-09 13:53:23 -0700326
327 private final Context mContext;
Yorke Leeb4ce1432014-06-09 13:53:23 -0700328
Santos Cordon6c7a3882014-06-25 15:30:08 -0700329 /**
330 * @hide
331 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700332 public static TelecomManager from(Context context) {
333 return (TelecomManager) context.getSystemService(Context.TELECOM_SERVICE);
Yorke Leeb4ce1432014-06-09 13:53:23 -0700334 }
Santos Cordon6c7a3882014-06-25 15:30:08 -0700335
336 /**
337 * @hide
338 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700339 public TelecomManager(Context context) {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700340 Context appContext = context.getApplicationContext();
341 if (appContext != null) {
342 mContext = appContext;
343 } else {
344 mContext = context;
345 }
346 }
347
348 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700349 * Return the {@link PhoneAccount} which is the user-chosen default for making outgoing phone
Nancy Chen513c8922014-09-17 14:47:20 -0700350 * calls with a specified URI scheme.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700351 * <p>
Santos Cordon96efb482014-07-19 14:57:05 -0700352 * Apps must be prepared for this method to return {@code null}, indicating that there currently
Nancy Chen513c8922014-09-17 14:47:20 -0700353 * exists no user-chosen default {@code PhoneAccount}.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700354 * <p>
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700355 * @param uriScheme The URI scheme.
Nancy Chen513c8922014-09-17 14:47:20 -0700356 * @return The {@link PhoneAccountHandle} corresponding to the user-chosen default for outgoing
357 * phone calls for a specified URI scheme.
Evan Charlton0e094d92014-11-08 15:49:16 -0800358 * @hide
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700359 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800360 @SystemApi
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700361 public PhoneAccountHandle getDefaultOutgoingPhoneAccount(String uriScheme) {
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700362 try {
363 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700364 return getTelecomService().getDefaultOutgoingPhoneAccount(uriScheme);
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700365 }
366 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700367 Log.e(TAG, "Error calling ITelecomService#getDefaultOutgoingPhoneAccount", e);
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700368 }
369 return null;
370 }
371
372 /**
Andrew Leed4abbfb2014-09-03 14:58:27 -0700373 * Return the {@link PhoneAccount} which is the user-chosen default for making outgoing phone
374 * calls. This {@code PhoneAccount} will always be a member of the list which is returned from
Nancy Chen210ef032014-09-15 17:58:42 -0700375 * calling {@link #getCallCapablePhoneAccounts()}
Andrew Leed4abbfb2014-09-03 14:58:27 -0700376 *
377 * Apps must be prepared for this method to return {@code null}, indicating that there currently
378 * exists no user-chosen default {@code PhoneAccount}.
379 *
380 * @return The user outgoing phone account selected by the user.
381 * @hide
382 */
383 public PhoneAccountHandle getUserSelectedOutgoingPhoneAccount() {
384 try {
385 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700386 return getTelecomService().getUserSelectedOutgoingPhoneAccount();
Andrew Leed4abbfb2014-09-03 14:58:27 -0700387 }
388 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700389 Log.e(TAG, "Error calling ITelecomService#getUserSelectedOutgoingPhoneAccount", e);
Andrew Leed4abbfb2014-09-03 14:58:27 -0700390 }
391 return null;
392 }
393
394 /**
Andrew Lee59cac3a2014-08-28 16:50:10 -0700395 * Sets the default account for making outgoing phone calls.
396 * @hide
397 */
Andrew Leed4abbfb2014-09-03 14:58:27 -0700398 public void setUserSelectedOutgoingPhoneAccount(PhoneAccountHandle accountHandle) {
Andrew Lee59cac3a2014-08-28 16:50:10 -0700399 try {
400 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700401 getTelecomService().setUserSelectedOutgoingPhoneAccount(accountHandle);
Andrew Lee59cac3a2014-08-28 16:50:10 -0700402 }
403 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700404 Log.e(TAG, "Error calling ITelecomService#setUserSelectedOutgoingPhoneAccount");
Andrew Lee59cac3a2014-08-28 16:50:10 -0700405 }
406 }
407
408 /**
Andrew Lee59cac3a2014-08-28 16:50:10 -0700409 * Returns the current SIM call manager. Apps must be prepared for this method to return
410 * {@code null}, indicating that there currently exists no user-chosen default
411 * {@code PhoneAccount}.
412 * @return The phone account handle of the current sim call manager.
413 * @hide
414 */
415 public PhoneAccountHandle getSimCallManager() {
416 try {
417 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700418 return getTelecomService().getSimCallManager();
Andrew Lee59cac3a2014-08-28 16:50:10 -0700419 }
420 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700421 Log.e(TAG, "Error calling ITelecomService#getSimCallManager");
Andrew Lee59cac3a2014-08-28 16:50:10 -0700422 }
423 return null;
424 }
425
426 /**
427 * Sets the SIM call manager to the specified phone account.
428 * @param accountHandle The phone account handle of the account to set as the sim call manager.
429 * @hide
430 */
431 public void setSimCallManager(PhoneAccountHandle accountHandle) {
432 try {
433 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700434 getTelecomService().setSimCallManager(accountHandle);
Andrew Lee59cac3a2014-08-28 16:50:10 -0700435 }
436 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700437 Log.e(TAG, "Error calling ITelecomService#setSimCallManager");
Andrew Lee59cac3a2014-08-28 16:50:10 -0700438 }
439 }
440
441 /**
442 * Returns the list of registered SIM call managers.
443 * @return List of registered SIM call managers.
444 * @hide
445 */
446 public List<PhoneAccountHandle> getSimCallManagers() {
447 try {
448 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700449 return getTelecomService().getSimCallManagers();
Andrew Lee59cac3a2014-08-28 16:50:10 -0700450 }
451 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700452 Log.e(TAG, "Error calling ITelecomService#getSimCallManagers");
Andrew Lee59cac3a2014-08-28 16:50:10 -0700453 }
454 return new ArrayList<>();
455 }
456
457 /**
Evan Charltoneb0a8d562014-09-04 12:03:34 -0700458 * Returns the current connection manager. Apps must be prepared for this method to return
459 * {@code null}, indicating that there currently exists no user-chosen default
460 * {@code PhoneAccount}.
461 *
462 * @return The phone account handle of the current connection manager.
Evan Charlton0e094d92014-11-08 15:49:16 -0800463 * @hide
Evan Charltoneb0a8d562014-09-04 12:03:34 -0700464 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800465 @SystemApi
Evan Charltoneb0a8d562014-09-04 12:03:34 -0700466 public PhoneAccountHandle getConnectionManager() {
467 return getSimCallManager();
468 }
469
470 /**
Sailesh Nepal7a4e3872014-11-21 11:01:40 -0800471 * Returns the list of registered SIM call managers.
472 * @return List of registered SIM call managers.
473 * @hide
474 */
475 @SystemApi
476 public List<PhoneAccountHandle> getRegisteredConnectionManagers() {
477 return getSimCallManagers();
478 }
479
480 /**
Nancy Chen210ef032014-09-15 17:58:42 -0700481 * Returns a list of the {@link PhoneAccountHandle}s which can be used to make and receive phone
482 * calls which support the specified URI scheme.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700483 * <P>
484 * For example, invoking with {@code "tel"} will find all {@link PhoneAccountHandle}s which
485 * support telephone calls (e.g. URIs such as {@code tel:555-555-1212}). Invoking with
486 * {@code "sip"} will find all {@link PhoneAccountHandle}s which support SIP calls (e.g. URIs
487 * such as {@code sip:example@sipexample.com}).
488 *
489 * @param uriScheme The URI scheme.
490 * @return A list of {@code PhoneAccountHandle} objects supporting the URI scheme.
Evan Charlton0e094d92014-11-08 15:49:16 -0800491 * @hide
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700492 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800493 @SystemApi
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700494 public List<PhoneAccountHandle> getPhoneAccountsSupportingScheme(String uriScheme) {
495 try {
496 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700497 return getTelecomService().getPhoneAccountsSupportingScheme(uriScheme);
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700498 }
499 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700500 Log.e(TAG, "Error calling ITelecomService#getPhoneAccountsSupportingScheme", e);
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700501 }
502 return new ArrayList<>();
503 }
504
Nancy Chen513c8922014-09-17 14:47:20 -0700505
506 /**
507 * Return a list of {@link PhoneAccountHandle}s which can be used to make and receive phone
508 * calls.
509 *
510 * @see #EXTRA_PHONE_ACCOUNT_HANDLE
511 * @return A list of {@code PhoneAccountHandle} objects.
512 *
513 * @hide
514 */
515 public List<PhoneAccountHandle> getCallCapablePhoneAccounts() {
516 try {
517 if (isServiceConnected()) {
518 return getTelecomService().getCallCapablePhoneAccounts();
519 }
520 } catch (RemoteException e) {
521 Log.e(TAG, "Error calling ITelecomService#getCallCapablePhoneAccounts", e);
522 }
523 return new ArrayList<>();
524 }
525
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700526 /**
Nancy Chen210ef032014-09-15 17:58:42 -0700527 * Determine whether the device has more than one account registered that can make and receive
528 * phone calls.
Nancy Chen60801182014-07-22 16:56:49 -0700529 *
Nancy Chen210ef032014-09-15 17:58:42 -0700530 * @return {@code true} if the device has more than one account registered and {@code false}
531 * otherwise.
Evan Charlton0e094d92014-11-08 15:49:16 -0800532 * @hide
Nancy Chen60801182014-07-22 16:56:49 -0700533 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800534 @SystemApi
Nancy Chen210ef032014-09-15 17:58:42 -0700535 public boolean hasMultipleCallCapableAccounts() {
536 return getCallCapablePhoneAccounts().size() > 1;
Nancy Chen60801182014-07-22 16:56:49 -0700537 }
538
539 /**
Nancy Chen513c8922014-09-17 14:47:20 -0700540 * Returns a list of all {@link PhoneAccount}s registered for the calling package.
541 *
542 * @return A list of {@code PhoneAccountHandle} objects.
Evan Charlton0e094d92014-11-08 15:49:16 -0800543 * @hide
Nancy Chen513c8922014-09-17 14:47:20 -0700544 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800545 @SystemApi
Nancy Chen513c8922014-09-17 14:47:20 -0700546 public List<PhoneAccountHandle> getPhoneAccountsForPackage() {
547 try {
548 if (isServiceConnected()) {
549 return getTelecomService().getPhoneAccountsForPackage(mContext.getPackageName());
550 }
551 } catch (RemoteException e) {
552 Log.e(TAG, "Error calling ITelecomService#getPhoneAccountsForPackage", e);
553 }
554 return null;
555 }
556
557 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700558 * Return the {@link PhoneAccount} for a specified {@link PhoneAccountHandle}. Object includes
559 * resources which can be used in a user interface.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700560 *
Evan Charlton6eb262c2014-07-19 18:18:19 -0700561 * @param account The {@link PhoneAccountHandle}.
Evan Charlton8c8a0622014-07-20 12:31:00 -0700562 * @return The {@link PhoneAccount} object.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700563 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700564 public PhoneAccount getPhoneAccount(PhoneAccountHandle account) {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700565 try {
566 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700567 return getTelecomService().getPhoneAccount(account);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700568 }
569 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700570 Log.e(TAG, "Error calling ITelecomService#getPhoneAccount", e);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700571 }
572 return null;
573 }
574
575 /**
Nancy Chen210ef032014-09-15 17:58:42 -0700576 * Returns a count of all {@link PhoneAccount}s.
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700577 *
Nancy Chen210ef032014-09-15 17:58:42 -0700578 * @return The count of {@link PhoneAccount}s.
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700579 * @hide
580 */
581 @SystemApi
582 public int getAllPhoneAccountsCount() {
583 try {
584 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700585 return getTelecomService().getAllPhoneAccountsCount();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700586 }
587 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700588 Log.e(TAG, "Error calling ITelecomService#getAllPhoneAccountsCount", e);
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700589 }
590 return 0;
591 }
592
593 /**
594 * Returns a list of all {@link PhoneAccount}s.
595 *
596 * @return All {@link PhoneAccount}s.
597 * @hide
598 */
599 @SystemApi
600 public List<PhoneAccount> getAllPhoneAccounts() {
601 try {
602 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700603 return getTelecomService().getAllPhoneAccounts();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700604 }
605 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700606 Log.e(TAG, "Error calling ITelecomService#getAllPhoneAccounts", e);
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700607 }
608 return Collections.EMPTY_LIST;
609 }
610
611 /**
612 * Returns a list of all {@link PhoneAccountHandle}s.
613 *
614 * @return All {@link PhoneAccountHandle}s.
615 * @hide
616 */
617 @SystemApi
618 public List<PhoneAccountHandle> getAllPhoneAccountHandles() {
619 try {
620 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700621 return getTelecomService().getAllPhoneAccountHandles();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700622 }
623 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700624 Log.e(TAG, "Error calling ITelecomService#getAllPhoneAccountHandles", e);
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700625 }
626 return Collections.EMPTY_LIST;
627 }
628
629 /**
Santos Cordond9e614f2014-10-28 13:10:36 -0700630 * Register a {@link PhoneAccount} for use by the system. When registering
631 * {@link PhoneAccount}s, existing registrations will be overwritten if the
632 * {@link PhoneAccountHandle} matches that of a {@link PhoneAccount} which is already
633 * registered. Once registered, the {@link PhoneAccount} is listed to the user as an option
634 * when placing calls. The user may still need to enable the {@link PhoneAccount} within
635 * the phone app settings before the account is usable.
636 * <p>
637 * A {@link SecurityException} will be thrown if an app tries to register a
638 * {@link PhoneAccountHandle} where the package name specified within
639 * {@link PhoneAccountHandle#getComponentName()} does not match the package name of the app.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700640 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700641 * @param account The complete {@link PhoneAccount}.
Evan Charlton0e094d92014-11-08 15:49:16 -0800642 *
643 * @hide
Ihab Awad807fe0a2014-07-09 12:30:52 -0700644 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800645 @SystemApi
Evan Charlton8c8a0622014-07-20 12:31:00 -0700646 public void registerPhoneAccount(PhoneAccount account) {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700647 try {
648 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700649 getTelecomService().registerPhoneAccount(account);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700650 }
651 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700652 Log.e(TAG, "Error calling ITelecomService#registerPhoneAccount", e);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700653 }
654 }
655
656 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700657 * Remove a {@link PhoneAccount} registration from the system.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700658 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700659 * @param accountHandle A {@link PhoneAccountHandle} for the {@link PhoneAccount} to unregister.
Evan Charlton0e094d92014-11-08 15:49:16 -0800660 * @hide
Ihab Awad807fe0a2014-07-09 12:30:52 -0700661 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800662 @SystemApi
Evan Charlton8c8a0622014-07-20 12:31:00 -0700663 public void unregisterPhoneAccount(PhoneAccountHandle accountHandle) {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700664 try {
665 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700666 getTelecomService().unregisterPhoneAccount(accountHandle);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700667 }
668 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700669 Log.e(TAG, "Error calling ITelecomService#unregisterPhoneAccount", e);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700670 }
671 }
672
673 /**
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700674 * Remove all Accounts that belong to the calling package from the system.
Evan Charlton0e094d92014-11-08 15:49:16 -0800675 * @hide
Ihab Awad807fe0a2014-07-09 12:30:52 -0700676 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800677 @SystemApi
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700678 public void clearAccounts() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700679 try {
680 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700681 getTelecomService().clearAccounts(mContext.getPackageName());
Ihab Awad807fe0a2014-07-09 12:30:52 -0700682 }
683 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700684 Log.e(TAG, "Error calling ITelecomService#clearAccounts", e);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700685 }
686 }
687
688 /**
Anthony Lee67279262014-10-27 11:28:40 -0700689 * Remove all Accounts that belong to the specified package from the system.
690 * @hide
691 */
692 public void clearAccountsForPackage(String packageName) {
693 try {
694 if (isServiceConnected() && !TextUtils.isEmpty(packageName)) {
695 getTelecomService().clearAccounts(packageName);
696 }
697 } catch (RemoteException e) {
Nancy Chen5cf27842015-01-24 23:30:27 -0800698 Log.e(TAG, "Error calling ITelecomService#clearAccountsForPackage", e);
Anthony Lee67279262014-10-27 11:28:40 -0700699 }
700 }
701
702 /**
Ihab Awad807fe0a2014-07-09 12:30:52 -0700703 * @hide
704 */
Santos Cordon6c7a3882014-06-25 15:30:08 -0700705 @SystemApi
706 public ComponentName getDefaultPhoneApp() {
707 try {
Santos Cordon9eb45932014-06-27 12:28:43 -0700708 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700709 return getTelecomService().getDefaultPhoneApp();
Santos Cordon9eb45932014-06-27 12:28:43 -0700710 }
Santos Cordon6c7a3882014-06-25 15:30:08 -0700711 } catch (RemoteException e) {
712 Log.e(TAG, "RemoteException attempting to get the default phone app.", e);
713 }
714 return null;
715 }
716
Santos Cordon9eb45932014-06-27 12:28:43 -0700717 /**
Nancy Chen443e5012014-10-15 15:48:21 -0700718 * Return whether a given phone number is the configured voicemail number for a
719 * particular phone account.
720 *
721 * @param accountHandle The handle for the account to check the voicemail number against
722 * @param number The number to look up.
723 *
724 * @hide
725 */
726 @SystemApi
727 public boolean isVoiceMailNumber(PhoneAccountHandle accountHandle, String number) {
728 try {
729 if (isServiceConnected()) {
730 return getTelecomService().isVoiceMailNumber(accountHandle, number);
731 }
732 } catch (RemoteException e) {
Nancy Chen5cf27842015-01-24 23:30:27 -0800733 Log.e(TAG, "RemoteException calling ITelecomService#isVoiceMailNumber.", e);
Nancy Chen443e5012014-10-15 15:48:21 -0700734 }
735 return false;
736 }
737
738 /**
Nancy Chen8c066f7c2014-12-03 15:18:08 -0800739 * Return whether a given phone account has a voicemail number configured.
740 *
741 * @param accountHandle The handle for the account to check for a voicemail number.
742 * @return {@code true} If the given phone account has a voicemail number.
743 *
744 * @hide
745 */
746 @SystemApi
747 public boolean hasVoiceMailNumber(PhoneAccountHandle accountHandle) {
748 try {
749 if (isServiceConnected()) {
750 return getTelecomService().hasVoiceMailNumber(accountHandle);
751 }
752 } catch (RemoteException e) {
Nancy Chen5cf27842015-01-24 23:30:27 -0800753 Log.e(TAG, "RemoteException calling ITelecomService#hasVoiceMailNumber.", e);
Nancy Chen8c066f7c2014-12-03 15:18:08 -0800754 }
755 return false;
756 }
757
758 /**
Nancy Chen5cf27842015-01-24 23:30:27 -0800759 * Return the line 1 phone number for given phone account.
760 *
761 * @param accountHandle The handle for the account retrieve a number for.
762 * @return A string representation of the line 1 phone number.
763 *
764 * @hide
765 */
766 @SystemApi
767 public String getLine1Number(PhoneAccountHandle accountHandle) {
768 try {
769 if (isServiceConnected()) {
770 return getTelecomService().getLine1Number(accountHandle);
771 }
772 } catch (RemoteException e) {
773 Log.e(TAG, "RemoteException calling ITelecomService#getLine1Number.", e);
774 }
775 return null;
776 }
777
778 /**
Santos Cordon9eb45932014-06-27 12:28:43 -0700779 * Returns whether there is an ongoing phone call (can be in dialing, ringing, active or holding
780 * states).
Nancy Chen0eb1e402014-08-21 22:52:29 -0700781 * <p>
782 * Requires permission: {@link android.Manifest.permission#READ_PHONE_STATE}
783 * </p>
Santos Cordon9eb45932014-06-27 12:28:43 -0700784 */
Nancy Chen0eb1e402014-08-21 22:52:29 -0700785 public boolean isInCall() {
Santos Cordon9eb45932014-06-27 12:28:43 -0700786 try {
787 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700788 return getTelecomService().isInCall();
Santos Cordon9eb45932014-06-27 12:28:43 -0700789 }
790 } catch (RemoteException e) {
Yorke Lee2ae312e2014-09-12 17:58:48 -0700791 Log.e(TAG, "RemoteException calling isInCall().", e);
Santos Cordon9eb45932014-06-27 12:28:43 -0700792 }
793 return false;
794 }
795
796 /**
Yorke Lee2ae312e2014-09-12 17:58:48 -0700797 * Returns one of the following constants that represents the current state of Telecom:
798 *
799 * {@link TelephonyManager#CALL_STATE_RINGING}
800 * {@link TelephonyManager#CALL_STATE_OFFHOOK}
801 * {@link TelephonyManager#CALL_STATE_IDLE}
Yorke Lee7c72c2d2014-10-28 14:12:02 -0700802 *
803 * Note that this API does not require the
804 * {@link android.Manifest.permission#READ_PHONE_STATE} permission. This is intentional, to
805 * preserve the behavior of {@link TelephonyManager#getCallState()}, which also did not require
806 * the permission.
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 /**
929 * Registers a new incoming call. A {@link ConnectionService} should invoke this method when it
930 * has an incoming call. The specified {@link PhoneAccountHandle} must have been registered
Nancy Chen210ef032014-09-15 17:58:42 -0700931 * with {@link #registerPhoneAccount}. Once invoked, this method will cause the system to bind
932 * to the {@link ConnectionService} associated with the {@link PhoneAccountHandle} and request
Santos Cordon96efb482014-07-19 14:57:05 -0700933 * additional information about the call (See
934 * {@link ConnectionService#onCreateIncomingConnection}) before starting the incoming call UI.
935 *
936 * @param phoneAccount A {@link PhoneAccountHandle} registered with
937 * {@link #registerPhoneAccount}.
938 * @param extras A bundle that will be passed through to
939 * {@link ConnectionService#onCreateIncomingConnection}.
Evan Charlton0e094d92014-11-08 15:49:16 -0800940 * @hide
Santos Cordon96efb482014-07-19 14:57:05 -0700941 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800942 @SystemApi
Santos Cordon96efb482014-07-19 14:57:05 -0700943 public void addNewIncomingCall(PhoneAccountHandle phoneAccount, Bundle extras) {
944 try {
945 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700946 getTelecomService().addNewIncomingCall(
Santos Cordon96efb482014-07-19 14:57:05 -0700947 phoneAccount, extras == null ? new Bundle() : extras);
948 }
949 } catch (RemoteException e) {
950 Log.e(TAG, "RemoteException adding a new incoming call: " + phoneAccount, e);
951 }
952 }
953
Nancy Chen0eb1e402014-08-21 22:52:29 -0700954 /**
Yorke Leec3cf9822014-10-02 09:38:39 -0700955 * Registers a new unknown call with Telecom. This can only be called by the system Telephony
956 * service. This is invoked when Telephony detects a new unknown connection that was neither
957 * a new incoming call, nor an user-initiated outgoing call.
958 *
959 * @param phoneAccount A {@link PhoneAccountHandle} registered with
960 * {@link #registerPhoneAccount}.
961 * @param extras A bundle that will be passed through to
962 * {@link ConnectionService#onCreateIncomingConnection}.
963 * @hide
964 */
965 @SystemApi
966 public void addNewUnknownCall(PhoneAccountHandle phoneAccount, Bundle extras) {
967 try {
968 if (isServiceConnected()) {
969 getTelecomService().addNewUnknownCall(
970 phoneAccount, extras == null ? new Bundle() : extras);
971 }
972 } catch (RemoteException e) {
973 Log.e(TAG, "RemoteException adding a new unknown call: " + phoneAccount, e);
974 }
975 }
976
977 /**
Nancy Chen0eb1e402014-08-21 22:52:29 -0700978 * Processes the specified dial string as an MMI code.
979 * MMI codes are any sequence of characters entered into the dialpad that contain a "*" or "#".
980 * Some of these sequences launch special behavior through handled by Telephony.
Nancy Chen95e8a672014-10-16 18:38:21 -0700981 * This method uses the default subscription.
Nancy Chen0eb1e402014-08-21 22:52:29 -0700982 * <p>
983 * Requires that the method-caller be set as the system dialer app.
984 * </p>
985 *
986 * @param dialString The digits to dial.
987 * @return True if the digits were processed as an MMI code, false otherwise.
988 */
989 public boolean handleMmi(String dialString) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700990 ITelecomService service = getTelecomService();
Nancy Chen0eb1e402014-08-21 22:52:29 -0700991 if (service != null) {
992 try {
993 return service.handlePinMmi(dialString);
994 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700995 Log.e(TAG, "Error calling ITelecomService#handlePinMmi", e);
Nancy Chen0eb1e402014-08-21 22:52:29 -0700996 }
997 }
998 return false;
999 }
1000
1001 /**
Nancy Chen95e8a672014-10-16 18:38:21 -07001002 * Processes the specified dial string as an MMI code.
1003 * MMI codes are any sequence of characters entered into the dialpad that contain a "*" or "#".
1004 * Some of these sequences launch special behavior through handled by Telephony.
1005 * <p>
1006 * Requires that the method-caller be set as the system dialer app.
1007 * </p>
1008 *
1009 * @param accountHandle The handle for the account the MMI code should apply to.
1010 * @param dialString The digits to dial.
1011 * @return True if the digits were processed as an MMI code, false otherwise.
Evan Charlton0e094d92014-11-08 15:49:16 -08001012 * @hide
Nancy Chen95e8a672014-10-16 18:38:21 -07001013 */
Evan Charlton0e094d92014-11-08 15:49:16 -08001014 @SystemApi
Nancy Chen95e8a672014-10-16 18:38:21 -07001015 public boolean handleMmi(PhoneAccountHandle accountHandle, String dialString) {
1016 ITelecomService service = getTelecomService();
1017 if (service != null) {
1018 try {
1019 return service.handlePinMmiForPhoneAccount(accountHandle, dialString);
1020 } catch (RemoteException e) {
1021 Log.e(TAG, "Error calling ITelecomService#handlePinMmi", e);
1022 }
1023 }
1024 return false;
1025 }
1026
1027 /**
Nancy Chenb2299c12014-10-29 18:22:11 -07001028 * @param accountHandle The handle for the account to derive an adn query URI for or
1029 * {@code null} to return a URI which will use the default account.
1030 * @return The URI (with the content:// scheme) specific to the specified {@link PhoneAccount}
1031 * for the the content retrieve.
Evan Charlton0e094d92014-11-08 15:49:16 -08001032 * @hide
Nancy Chenb2299c12014-10-29 18:22:11 -07001033 */
Evan Charlton0e094d92014-11-08 15:49:16 -08001034 @SystemApi
Nancy Chenb2299c12014-10-29 18:22:11 -07001035 public Uri getAdnUriForPhoneAccount(PhoneAccountHandle accountHandle) {
1036 ITelecomService service = getTelecomService();
1037 if (service != null && accountHandle != null) {
1038 try {
1039 return service.getAdnUriForPhoneAccount(accountHandle);
1040 } catch (RemoteException e) {
1041 Log.e(TAG, "Error calling ITelecomService#getAdnUriForPhoneAccount", e);
1042 }
1043 }
1044 return Uri.parse("content://icc/adn");
1045 }
1046
1047 /**
Nancy Chen0eb1e402014-08-21 22:52:29 -07001048 * Removes the missed-call notification if one is present.
1049 * <p>
1050 * Requires that the method-caller be set as the system dialer app.
1051 * </p>
1052 */
1053 public void cancelMissedCallsNotification() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001054 ITelecomService service = getTelecomService();
Nancy Chen0eb1e402014-08-21 22:52:29 -07001055 if (service != null) {
1056 try {
1057 service.cancelMissedCallsNotification();
1058 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001059 Log.e(TAG, "Error calling ITelecomService#cancelMissedCallsNotification", e);
Nancy Chen0eb1e402014-08-21 22:52:29 -07001060 }
1061 }
1062 }
1063
1064 /**
1065 * Brings the in-call screen to the foreground if there is an ongoing call. If there is
1066 * currently no ongoing call, then this method does nothing.
1067 * <p>
1068 * Requires that the method-caller be set as the system dialer app or have the
1069 * {@link android.Manifest.permission#READ_PHONE_STATE} permission.
1070 * </p>
1071 *
1072 * @param showDialpad Brings up the in-call dialpad as part of showing the in-call screen.
1073 */
1074 public void showInCallScreen(boolean showDialpad) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001075 ITelecomService service = getTelecomService();
Nancy Chen0eb1e402014-08-21 22:52:29 -07001076 if (service != null) {
1077 try {
1078 service.showInCallScreen(showDialpad);
1079 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001080 Log.e(TAG, "Error calling ITelecomService#showCallScreen", e);
Nancy Chen0eb1e402014-08-21 22:52:29 -07001081 }
1082 }
1083 }
1084
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001085 private ITelecomService getTelecomService() {
1086 return ITelecomService.Stub.asInterface(ServiceManager.getService(Context.TELECOM_SERVICE));
Santos Cordon6c7a3882014-06-25 15:30:08 -07001087 }
Santos Cordon9eb45932014-06-27 12:28:43 -07001088
1089 private boolean isServiceConnected() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001090 boolean isConnected = getTelecomService() != null;
Santos Cordon9eb45932014-06-27 12:28:43 -07001091 if (!isConnected) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001092 Log.w(TAG, "Telecom Service not found.");
Santos Cordon9eb45932014-06-27 12:28:43 -07001093 }
1094 return isConnected;
1095 }
Evan Charlton235c1592014-09-05 15:41:23 +00001096}