blob: bcc1ccc439cf156789baac4839ec09743dd5c9ea [file] [log] [blame]
Yorke Leeb4ce1432014-06-09 13:53:23 -07001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
Santos Cordon9eb45932014-06-27 12:28:43 -07004 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5 * in compliance with the License. You may obtain a copy of the License at
Yorke Leeb4ce1432014-06-09 13:53:23 -07006 *
Santos Cordon9eb45932014-06-27 12:28:43 -07007 * http://www.apache.org/licenses/LICENSE-2.0
Yorke Leeb4ce1432014-06-09 13:53:23 -07008 *
Santos Cordon9eb45932014-06-27 12:28:43 -07009 * Unless required by applicable law or agreed to in writing, software distributed under the License
10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11 * or implied. See the License for the specific language governing permissions and limitations under
12 * the License.
Yorke Leeb4ce1432014-06-09 13:53:23 -070013 */
14
Tyler Gunnef9f6f92014-09-12 22:16:17 -070015package android.telecom;
Yorke Leeb4ce1432014-06-09 13:53:23 -070016
Santos Cordon6c7a3882014-06-25 15:30:08 -070017import android.annotation.SystemApi;
18import android.content.ComponentName;
Yorke Leeb4ce1432014-06-09 13:53:23 -070019import android.content.Context;
Nancy Chenb2299c12014-10-29 18:22:11 -070020import android.net.Uri;
Santos Cordon96efb482014-07-19 14:57:05 -070021import android.os.Bundle;
Santos Cordon6c7a3882014-06-25 15:30:08 -070022import android.os.RemoteException;
23import android.os.ServiceManager;
Yorke Lee2ae312e2014-09-12 17:58:48 -070024import android.telephony.TelephonyManager;
Anthony Lee67279262014-10-27 11:28:40 -070025import android.text.TextUtils;
Santos Cordon6c7a3882014-06-25 15:30:08 -070026import android.util.Log;
Yorke Leeb4ce1432014-06-09 13:53:23 -070027
Tyler Gunnef9f6f92014-09-12 22:16:17 -070028import com.android.internal.telecom.ITelecomService;
Yorke Leeb4ce1432014-06-09 13:53:23 -070029
Jay Shrauner7746a942014-08-26 12:15:15 -070030import java.util.ArrayList;
Tyler Gunna1ed7d12014-09-08 09:52:22 -070031import java.util.Collections;
Ihab Awad807fe0a2014-07-09 12:30:52 -070032import java.util.List;
33
Yorke Leeb4ce1432014-06-09 13:53:23 -070034/**
Santos Cordond9e614f2014-10-28 13:10:36 -070035 * Provides access to information about active calls and registration/call-management functionality.
Evan Charlton0e094d92014-11-08 15:49:16 -080036 * Apps can use methods in this class to determine the current call state.
Santos Cordond9e614f2014-10-28 13:10:36 -070037 * <p>
38 * Apps do not instantiate this class directly; instead, they retrieve a reference to an instance
39 * through {@link Context#getSystemService Context.getSystemService(Context.TELECOM_SERVICE)}.
40 * <p>
41 * Note that access to some telecom information is permission-protected. Your app cannot access the
42 * protected information or gain access to protected functionality unless it has the appropriate
43 * permissions declared in its manifest file. Where permissions apply, they are noted in the method
44 * descriptions.
Yorke Leeb4ce1432014-06-09 13:53:23 -070045 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -070046public class TelecomManager {
Ihab Awad807fe0a2014-07-09 12:30:52 -070047
Evan Charlton10197192014-07-19 15:00:29 -070048 /**
Santos Cordon96efb482014-07-19 14:57:05 -070049 * Activity action: Starts the UI for handing an incoming call. This intent starts the in-call
Tyler Gunnef9f6f92014-09-12 22:16:17 -070050 * UI by notifying the Telecom system that an incoming call exists for a specific call service
51 * (see {@link android.telecom.ConnectionService}). Telecom reads the Intent extras to find
52 * and bind to the appropriate {@link android.telecom.ConnectionService} which Telecom will
Santos Cordon96efb482014-07-19 14:57:05 -070053 * ultimately use to control and get information about the call.
54 * <p>
55 * Input: get*Extra field {@link #EXTRA_PHONE_ACCOUNT_HANDLE} contains the component name of the
Tyler Gunnef9f6f92014-09-12 22:16:17 -070056 * {@link android.telecom.ConnectionService} that Telecom should bind to. Telecom will then
Evan Charlton10197192014-07-19 15:00:29 -070057 * ask the connection service for more information about the call prior to showing any UI.
58 *
Santos Cordon96efb482014-07-19 14:57:05 -070059 * @hide
Evan Charlton10197192014-07-19 15:00:29 -070060 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -070061 public static final String ACTION_INCOMING_CALL = "android.telecom.action.INCOMING_CALL";
Evan Charlton10197192014-07-19 15:00:29 -070062
63 /**
Yorke Leec3cf9822014-10-02 09:38:39 -070064 * Similar to {@link #ACTION_INCOMING_CALL}, but is used only by Telephony to add a new
65 * sim-initiated MO call for carrier testing.
66 * @hide
67 */
68 public static final String ACTION_NEW_UNKNOWN_CALL = "android.telecom.action.NEW_UNKNOWN_CALL";
69
70 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -070071 * The {@link android.content.Intent} action used to configure a
Tyler Gunnef9f6f92014-09-12 22:16:17 -070072 * {@link android.telecom.ConnectionService}.
Evan Charlton0e094d92014-11-08 15:49:16 -080073 * @hide
Evan Charlton10197192014-07-19 15:00:29 -070074 */
Evan Charlton0e094d92014-11-08 15:49:16 -080075 @SystemApi
Evan Charlton10197192014-07-19 15:00:29 -070076 public static final String ACTION_CONNECTION_SERVICE_CONFIGURE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -070077 "android.telecom.action.CONNECTION_SERVICE_CONFIGURE";
Evan Charlton10197192014-07-19 15:00:29 -070078
79 /**
Yorke Lee3818a8922014-07-21 15:57:17 -070080 * The {@link android.content.Intent} action used to show the call settings page.
81 */
82 public static final String ACTION_SHOW_CALL_SETTINGS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -070083 "android.telecom.action.SHOW_CALL_SETTINGS";
Yorke Lee3818a8922014-07-21 15:57:17 -070084
85 /**
Andrew Lee866080f2015-02-19 12:05:33 -080086 * The {@link android.content.Intent} action used to show the respond via SMS settings page.
87 */
88 public static final String ACTION_SHOW_RESPOND_VIA_SMS_SETTINGS =
89 "android.telecom.action.SHOW_RESPOND_VIA_SMS_SETTINGS";
90
91 /**
Evan Charlton6d8604f2014-09-04 12:38:17 -070092 * The {@link android.content.Intent} action used to show the settings page used to configure
93 * {@link PhoneAccount} preferences.
Evan Charlton0e094d92014-11-08 15:49:16 -080094 * @hide
Evan Charlton6d8604f2014-09-04 12:38:17 -070095 */
Evan Charlton0e094d92014-11-08 15:49:16 -080096 @SystemApi
Evan Charlton6d8604f2014-09-04 12:38:17 -070097 public static final String ACTION_CHANGE_PHONE_ACCOUNTS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -070098 "android.telecom.action.CHANGE_PHONE_ACCOUNTS";
Evan Charlton6d8604f2014-09-04 12:38:17 -070099
100 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700101 * Optional extra for {@link android.content.Intent#ACTION_CALL} containing a boolean that
102 * determines whether the speakerphone should be automatically turned on for an outgoing call.
Evan Charlton10197192014-07-19 15:00:29 -0700103 */
104 public static final String EXTRA_START_CALL_WITH_SPEAKERPHONE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700105 "android.telecom.extra.START_CALL_WITH_SPEAKERPHONE";
Evan Charlton10197192014-07-19 15:00:29 -0700106
107 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700108 * Optional extra for {@link android.content.Intent#ACTION_CALL} containing an integer that
109 * determines the desired video state for an outgoing call.
Santos Cordon96efb482014-07-19 14:57:05 -0700110 * Valid options:
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700111 * {@link VideoProfile.VideoState#AUDIO_ONLY},
112 * {@link VideoProfile.VideoState#BIDIRECTIONAL},
113 * {@link VideoProfile.VideoState#RX_ENABLED},
114 * {@link VideoProfile.VideoState#TX_ENABLED}.
Evan Charlton10197192014-07-19 15:00:29 -0700115 */
116 public static final String EXTRA_START_CALL_WITH_VIDEO_STATE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700117 "android.telecom.extra.START_CALL_WITH_VIDEO_STATE";
Evan Charlton10197192014-07-19 15:00:29 -0700118
119 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700120 * The extra used with an {@link android.content.Intent#ACTION_CALL} and
121 * {@link android.content.Intent#ACTION_DIAL} {@code Intent} to specify a
122 * {@link PhoneAccountHandle} to use when making the call.
Evan Charlton10197192014-07-19 15:00:29 -0700123 * <p class="note">
Santos Cordon96efb482014-07-19 14:57:05 -0700124 * Retrieve with {@link android.content.Intent#getParcelableExtra(String)}.
Evan Charlton10197192014-07-19 15:00:29 -0700125 */
Evan Charlton6eb262c2014-07-19 18:18:19 -0700126 public static final String EXTRA_PHONE_ACCOUNT_HANDLE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700127 "android.telecom.extra.PHONE_ACCOUNT_HANDLE";
Evan Charlton10197192014-07-19 15:00:29 -0700128
129 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700130 * Optional extra for {@link #ACTION_INCOMING_CALL} containing a {@link Bundle} which contains
131 * metadata about the call. This {@link Bundle} will be returned to the
132 * {@link ConnectionService}.
133 *
134 * @hide
Evan Charlton10197192014-07-19 15:00:29 -0700135 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800136 @SystemApi
Evan Charlton10197192014-07-19 15:00:29 -0700137 public static final String EXTRA_INCOMING_CALL_EXTRAS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700138 "android.telecom.extra.INCOMING_CALL_EXTRAS";
Evan Charlton10197192014-07-19 15:00:29 -0700139
140 /**
Nancy Chen10798dc2014-08-08 14:00:25 -0700141 * Optional extra for {@link android.content.Intent#ACTION_CALL} and
142 * {@link android.content.Intent#ACTION_DIAL} {@code Intent} containing a {@link Bundle}
143 * which contains metadata about the call. This {@link Bundle} will be saved into
144 * {@code Call.Details}.
Nancy Chen10798dc2014-08-08 14:00:25 -0700145 */
146 public static final String EXTRA_OUTGOING_CALL_EXTRAS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700147 "android.telecom.extra.OUTGOING_CALL_EXTRAS";
Nancy Chen10798dc2014-08-08 14:00:25 -0700148
149 /**
Yorke Leec3cf9822014-10-02 09:38:39 -0700150 * @hide
151 */
152 public static final String EXTRA_UNKNOWN_CALL_HANDLE =
153 "android.telecom.extra.UNKNOWN_CALL_HANDLE";
154
155 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700156 * Optional extra for {@link android.telephony.TelephonyManager#ACTION_PHONE_STATE_CHANGED}
157 * containing the disconnect code.
Evan Charlton10197192014-07-19 15:00:29 -0700158 */
159 public static final String EXTRA_CALL_DISCONNECT_CAUSE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700160 "android.telecom.extra.CALL_DISCONNECT_CAUSE";
Evan Charlton10197192014-07-19 15:00:29 -0700161
162 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700163 * Optional extra for {@link android.telephony.TelephonyManager#ACTION_PHONE_STATE_CHANGED}
164 * containing the disconnect message.
Evan Charlton10197192014-07-19 15:00:29 -0700165 */
166 public static final String EXTRA_CALL_DISCONNECT_MESSAGE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700167 "android.telecom.extra.CALL_DISCONNECT_MESSAGE";
Evan Charlton10197192014-07-19 15:00:29 -0700168
169 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700170 * Optional extra for {@link android.telephony.TelephonyManager#ACTION_PHONE_STATE_CHANGED}
171 * containing the component name of the associated connection service.
Evan Charlton0e094d92014-11-08 15:49:16 -0800172 * @hide
Evan Charlton10197192014-07-19 15:00:29 -0700173 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800174 @SystemApi
Evan Charlton10197192014-07-19 15:00:29 -0700175 public static final String EXTRA_CONNECTION_SERVICE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700176 "android.telecom.extra.CONNECTION_SERVICE";
Evan Charlton10197192014-07-19 15:00:29 -0700177
178 /**
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700179 * An optional {@link android.content.Intent#ACTION_CALL} intent extra denoting the
180 * package name of the app specifying an alternative gateway for the call.
181 * The value is a string.
182 *
183 * (The following comment corresponds to the all GATEWAY_* extras)
184 * An app which sends the {@link android.content.Intent#ACTION_CALL} intent can specify an
185 * alternative address to dial which is different from the one specified and displayed to
186 * the user. This alternative address is referred to as the gateway address.
187 */
188 public static final String GATEWAY_PROVIDER_PACKAGE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700189 "android.telecom.extra.GATEWAY_PROVIDER_PACKAGE";
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700190
191 /**
192 * An optional {@link android.content.Intent#ACTION_CALL} intent extra corresponding to the
193 * original address to dial for the call. This is used when an alternative gateway address is
194 * provided to recall the original address.
195 * The value is a {@link android.net.Uri}.
196 *
197 * (See {@link #GATEWAY_PROVIDER_PACKAGE} for details)
198 */
199 public static final String GATEWAY_ORIGINAL_ADDRESS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700200 "android.telecom.extra.GATEWAY_ORIGINAL_ADDRESS";
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700201
202 /**
Evan Charlton10197192014-07-19 15:00:29 -0700203 * The number which the party on the other side of the line will see (and use to return the
204 * call).
205 * <p>
Santos Cordon96efb482014-07-19 14:57:05 -0700206 * {@link ConnectionService}s which interact with {@link RemoteConnection}s should only populate
207 * this if the {@link android.telephony.TelephonyManager#getLine1Number()} value, as that is the
208 * user's expected caller ID.
Evan Charlton0e094d92014-11-08 15:49:16 -0800209 * @hide
Evan Charlton10197192014-07-19 15:00:29 -0700210 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800211 @SystemApi
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700212 public static final String EXTRA_CALL_BACK_NUMBER = "android.telecom.extra.CALL_BACK_NUMBER";
Evan Charlton10197192014-07-19 15:00:29 -0700213
214 /**
215 * The dual tone multi-frequency signaling character sent to indicate the dialing system should
216 * pause for a predefined period.
217 */
218 public static final char DTMF_CHARACTER_PAUSE = ',';
219
220 /**
221 * The dual-tone multi-frequency signaling character sent to indicate the dialing system should
222 * wait for user confirmation before proceeding.
223 */
224 public static final char DTMF_CHARACTER_WAIT = ';';
225
226 /**
227 * TTY (teletypewriter) mode is off.
228 *
229 * @hide
230 */
231 public static final int TTY_MODE_OFF = 0;
232
233 /**
234 * TTY (teletypewriter) mode is on. The speaker is off and the microphone is muted. The user
235 * will communicate with the remote party by sending and receiving text messages.
236 *
237 * @hide
238 */
239 public static final int TTY_MODE_FULL = 1;
240
241 /**
242 * TTY (teletypewriter) mode is in hearing carryover mode (HCO). The microphone is muted but the
243 * speaker is on. The user will communicate with the remote party by sending text messages and
244 * hearing an audible reply.
245 *
246 * @hide
247 */
248 public static final int TTY_MODE_HCO = 2;
249
250 /**
251 * TTY (teletypewriter) mode is in voice carryover mode (VCO). The speaker is off but the
252 * microphone is still on. User will communicate with the remote party by speaking and receiving
253 * text message replies.
254 *
255 * @hide
256 */
257 public static final int TTY_MODE_VCO = 3;
258
259 /**
260 * Broadcast intent action indicating that the current TTY mode has changed. An intent extra
261 * provides this state as an int.
Evan Charlton10197192014-07-19 15:00:29 -0700262 *
Santos Cordon96efb482014-07-19 14:57:05 -0700263 * @see #EXTRA_CURRENT_TTY_MODE
Evan Charlton10197192014-07-19 15:00:29 -0700264 * @hide
265 */
266 public static final String ACTION_CURRENT_TTY_MODE_CHANGED =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700267 "android.telecom.action.CURRENT_TTY_MODE_CHANGED";
Evan Charlton10197192014-07-19 15:00:29 -0700268
269 /**
270 * The lookup key for an int that indicates the current TTY mode.
271 * Valid modes are:
272 * - {@link #TTY_MODE_OFF}
273 * - {@link #TTY_MODE_FULL}
274 * - {@link #TTY_MODE_HCO}
275 * - {@link #TTY_MODE_VCO}
276 *
277 * @hide
278 */
279 public static final String EXTRA_CURRENT_TTY_MODE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700280 "android.telecom.intent.extra.CURRENT_TTY_MODE";
Evan Charlton10197192014-07-19 15:00:29 -0700281
282 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700283 * Broadcast intent action indicating that the TTY preferred operating mode has changed. An
284 * intent extra provides the new mode as an int.
Evan Charlton10197192014-07-19 15:00:29 -0700285 *
Santos Cordon96efb482014-07-19 14:57:05 -0700286 * @see #EXTRA_TTY_PREFERRED_MODE
Evan Charlton10197192014-07-19 15:00:29 -0700287 * @hide
288 */
289 public static final String ACTION_TTY_PREFERRED_MODE_CHANGED =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700290 "android.telecom.action.TTY_PREFERRED_MODE_CHANGED";
Evan Charlton10197192014-07-19 15:00:29 -0700291
292 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700293 * The lookup key for an int that indicates preferred TTY mode. Valid modes are: -
294 * {@link #TTY_MODE_OFF} - {@link #TTY_MODE_FULL} - {@link #TTY_MODE_HCO} -
295 * {@link #TTY_MODE_VCO}
Evan Charlton10197192014-07-19 15:00:29 -0700296 *
297 * @hide
298 */
299 public static final String EXTRA_TTY_PREFERRED_MODE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700300 "android.telecom.intent.extra.TTY_PREFERRED";
Evan Charlton10197192014-07-19 15:00:29 -0700301
Nancy Chen9d568c02014-09-08 14:17:59 -0700302 /**
303 * The following 4 constants define how properties such as phone numbers and names are
304 * displayed to the user.
305 */
306
307 /** Property is displayed normally. */
308 public static final int PRESENTATION_ALLOWED = 1;
309
310 /** Property was blocked. */
311 public static final int PRESENTATION_RESTRICTED = 2;
312
313 /** Presentation was not specified or is unknown. */
314 public static final int PRESENTATION_UNKNOWN = 3;
315
316 /** Property should be displayed as a pay phone. */
317 public static final int PRESENTATION_PAYPHONE = 4;
318
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700319 private static final String TAG = "TelecomManager";
Yorke Leeb4ce1432014-06-09 13:53:23 -0700320
321 private final Context mContext;
Yorke Leeb4ce1432014-06-09 13:53:23 -0700322
Santos Cordon6c7a3882014-06-25 15:30:08 -0700323 /**
324 * @hide
325 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700326 public static TelecomManager from(Context context) {
327 return (TelecomManager) context.getSystemService(Context.TELECOM_SERVICE);
Yorke Leeb4ce1432014-06-09 13:53:23 -0700328 }
Santos Cordon6c7a3882014-06-25 15:30:08 -0700329
330 /**
331 * @hide
332 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700333 public TelecomManager(Context context) {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700334 Context appContext = context.getApplicationContext();
335 if (appContext != null) {
336 mContext = appContext;
337 } else {
338 mContext = context;
339 }
340 }
341
342 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700343 * Return the {@link PhoneAccount} which is the user-chosen default for making outgoing phone
Nancy Chen513c8922014-09-17 14:47:20 -0700344 * calls with a specified URI scheme.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700345 * <p>
Santos Cordon96efb482014-07-19 14:57:05 -0700346 * Apps must be prepared for this method to return {@code null}, indicating that there currently
Nancy Chen513c8922014-09-17 14:47:20 -0700347 * exists no user-chosen default {@code PhoneAccount}.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700348 * <p>
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700349 * @param uriScheme The URI scheme.
Nancy Chen513c8922014-09-17 14:47:20 -0700350 * @return The {@link PhoneAccountHandle} corresponding to the user-chosen default for outgoing
351 * phone calls for a specified URI scheme.
Evan Charlton0e094d92014-11-08 15:49:16 -0800352 * @hide
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700353 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800354 @SystemApi
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700355 public PhoneAccountHandle getDefaultOutgoingPhoneAccount(String uriScheme) {
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700356 try {
357 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700358 return getTelecomService().getDefaultOutgoingPhoneAccount(uriScheme);
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700359 }
360 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700361 Log.e(TAG, "Error calling ITelecomService#getDefaultOutgoingPhoneAccount", e);
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700362 }
363 return null;
364 }
365
366 /**
Andrew Leed4abbfb2014-09-03 14:58:27 -0700367 * Return the {@link PhoneAccount} which is the user-chosen default for making outgoing phone
368 * calls. This {@code PhoneAccount} will always be a member of the list which is returned from
Nancy Chen210ef032014-09-15 17:58:42 -0700369 * calling {@link #getCallCapablePhoneAccounts()}
Andrew Leed4abbfb2014-09-03 14:58:27 -0700370 *
371 * Apps must be prepared for this method to return {@code null}, indicating that there currently
372 * exists no user-chosen default {@code PhoneAccount}.
373 *
374 * @return The user outgoing phone account selected by the user.
375 * @hide
376 */
377 public PhoneAccountHandle getUserSelectedOutgoingPhoneAccount() {
378 try {
379 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700380 return getTelecomService().getUserSelectedOutgoingPhoneAccount();
Andrew Leed4abbfb2014-09-03 14:58:27 -0700381 }
382 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700383 Log.e(TAG, "Error calling ITelecomService#getUserSelectedOutgoingPhoneAccount", e);
Andrew Leed4abbfb2014-09-03 14:58:27 -0700384 }
385 return null;
386 }
387
388 /**
Andrew Lee59cac3a2014-08-28 16:50:10 -0700389 * Sets the default account for making outgoing phone calls.
390 * @hide
391 */
Andrew Leed4abbfb2014-09-03 14:58:27 -0700392 public void setUserSelectedOutgoingPhoneAccount(PhoneAccountHandle accountHandle) {
Andrew Lee59cac3a2014-08-28 16:50:10 -0700393 try {
394 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700395 getTelecomService().setUserSelectedOutgoingPhoneAccount(accountHandle);
Andrew Lee59cac3a2014-08-28 16:50:10 -0700396 }
397 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700398 Log.e(TAG, "Error calling ITelecomService#setUserSelectedOutgoingPhoneAccount");
Andrew Lee59cac3a2014-08-28 16:50:10 -0700399 }
400 }
401
402 /**
Andrew Lee59cac3a2014-08-28 16:50:10 -0700403 * Returns the current SIM call manager. Apps must be prepared for this method to return
404 * {@code null}, indicating that there currently exists no user-chosen default
405 * {@code PhoneAccount}.
406 * @return The phone account handle of the current sim call manager.
407 * @hide
408 */
409 public PhoneAccountHandle getSimCallManager() {
410 try {
411 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700412 return getTelecomService().getSimCallManager();
Andrew Lee59cac3a2014-08-28 16:50:10 -0700413 }
414 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700415 Log.e(TAG, "Error calling ITelecomService#getSimCallManager");
Andrew Lee59cac3a2014-08-28 16:50:10 -0700416 }
417 return null;
418 }
419
420 /**
421 * Sets the SIM call manager to the specified phone account.
422 * @param accountHandle The phone account handle of the account to set as the sim call manager.
423 * @hide
424 */
425 public void setSimCallManager(PhoneAccountHandle accountHandle) {
426 try {
427 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700428 getTelecomService().setSimCallManager(accountHandle);
Andrew Lee59cac3a2014-08-28 16:50:10 -0700429 }
430 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700431 Log.e(TAG, "Error calling ITelecomService#setSimCallManager");
Andrew Lee59cac3a2014-08-28 16:50:10 -0700432 }
433 }
434
435 /**
436 * Returns the list of registered SIM call managers.
437 * @return List of registered SIM call managers.
438 * @hide
439 */
440 public List<PhoneAccountHandle> getSimCallManagers() {
441 try {
442 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700443 return getTelecomService().getSimCallManagers();
Andrew Lee59cac3a2014-08-28 16:50:10 -0700444 }
445 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700446 Log.e(TAG, "Error calling ITelecomService#getSimCallManagers");
Andrew Lee59cac3a2014-08-28 16:50:10 -0700447 }
448 return new ArrayList<>();
449 }
450
451 /**
Evan Charltoneb0a8d562014-09-04 12:03:34 -0700452 * Returns the current connection manager. Apps must be prepared for this method to return
453 * {@code null}, indicating that there currently exists no user-chosen default
454 * {@code PhoneAccount}.
455 *
456 * @return The phone account handle of the current connection manager.
Evan Charlton0e094d92014-11-08 15:49:16 -0800457 * @hide
Evan Charltoneb0a8d562014-09-04 12:03:34 -0700458 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800459 @SystemApi
Evan Charltoneb0a8d562014-09-04 12:03:34 -0700460 public PhoneAccountHandle getConnectionManager() {
461 return getSimCallManager();
462 }
463
464 /**
Sailesh Nepal7a4e3872014-11-21 11:01:40 -0800465 * Returns the list of registered SIM call managers.
466 * @return List of registered SIM call managers.
467 * @hide
468 */
469 @SystemApi
470 public List<PhoneAccountHandle> getRegisteredConnectionManagers() {
471 return getSimCallManagers();
472 }
473
474 /**
Nancy Chen210ef032014-09-15 17:58:42 -0700475 * Returns a list of the {@link PhoneAccountHandle}s which can be used to make and receive phone
476 * calls which support the specified URI scheme.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700477 * <P>
478 * For example, invoking with {@code "tel"} will find all {@link PhoneAccountHandle}s which
479 * support telephone calls (e.g. URIs such as {@code tel:555-555-1212}). Invoking with
480 * {@code "sip"} will find all {@link PhoneAccountHandle}s which support SIP calls (e.g. URIs
481 * such as {@code sip:example@sipexample.com}).
482 *
483 * @param uriScheme The URI scheme.
484 * @return A list of {@code PhoneAccountHandle} objects supporting the URI scheme.
Evan Charlton0e094d92014-11-08 15:49:16 -0800485 * @hide
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700486 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800487 @SystemApi
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700488 public List<PhoneAccountHandle> getPhoneAccountsSupportingScheme(String uriScheme) {
489 try {
490 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700491 return getTelecomService().getPhoneAccountsSupportingScheme(uriScheme);
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700492 }
493 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700494 Log.e(TAG, "Error calling ITelecomService#getPhoneAccountsSupportingScheme", e);
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700495 }
496 return new ArrayList<>();
497 }
498
Nancy Chen513c8922014-09-17 14:47:20 -0700499
500 /**
501 * Return a list of {@link PhoneAccountHandle}s which can be used to make and receive phone
502 * calls.
503 *
504 * @see #EXTRA_PHONE_ACCOUNT_HANDLE
505 * @return A list of {@code PhoneAccountHandle} objects.
506 *
507 * @hide
508 */
509 public List<PhoneAccountHandle> getCallCapablePhoneAccounts() {
510 try {
511 if (isServiceConnected()) {
512 return getTelecomService().getCallCapablePhoneAccounts();
513 }
514 } catch (RemoteException e) {
515 Log.e(TAG, "Error calling ITelecomService#getCallCapablePhoneAccounts", e);
516 }
517 return new ArrayList<>();
518 }
519
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700520 /**
Nancy Chen210ef032014-09-15 17:58:42 -0700521 * Determine whether the device has more than one account registered that can make and receive
522 * phone calls.
Nancy Chen60801182014-07-22 16:56:49 -0700523 *
Nancy Chen210ef032014-09-15 17:58:42 -0700524 * @return {@code true} if the device has more than one account registered and {@code false}
525 * otherwise.
Evan Charlton0e094d92014-11-08 15:49:16 -0800526 * @hide
Nancy Chen60801182014-07-22 16:56:49 -0700527 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800528 @SystemApi
Nancy Chen210ef032014-09-15 17:58:42 -0700529 public boolean hasMultipleCallCapableAccounts() {
530 return getCallCapablePhoneAccounts().size() > 1;
Nancy Chen60801182014-07-22 16:56:49 -0700531 }
532
533 /**
Nancy Chen513c8922014-09-17 14:47:20 -0700534 * Returns a list of all {@link PhoneAccount}s registered for the calling package.
535 *
536 * @return A list of {@code PhoneAccountHandle} objects.
Evan Charlton0e094d92014-11-08 15:49:16 -0800537 * @hide
Nancy Chen513c8922014-09-17 14:47:20 -0700538 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800539 @SystemApi
Nancy Chen513c8922014-09-17 14:47:20 -0700540 public List<PhoneAccountHandle> getPhoneAccountsForPackage() {
541 try {
542 if (isServiceConnected()) {
543 return getTelecomService().getPhoneAccountsForPackage(mContext.getPackageName());
544 }
545 } catch (RemoteException e) {
546 Log.e(TAG, "Error calling ITelecomService#getPhoneAccountsForPackage", e);
547 }
548 return null;
549 }
550
551 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700552 * Return the {@link PhoneAccount} for a specified {@link PhoneAccountHandle}. Object includes
553 * resources which can be used in a user interface.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700554 *
Evan Charlton6eb262c2014-07-19 18:18:19 -0700555 * @param account The {@link PhoneAccountHandle}.
Evan Charlton8c8a0622014-07-20 12:31:00 -0700556 * @return The {@link PhoneAccount} object.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700557 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700558 public PhoneAccount getPhoneAccount(PhoneAccountHandle account) {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700559 try {
560 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700561 return getTelecomService().getPhoneAccount(account);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700562 }
563 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700564 Log.e(TAG, "Error calling ITelecomService#getPhoneAccount", e);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700565 }
566 return null;
567 }
568
569 /**
Nancy Chen210ef032014-09-15 17:58:42 -0700570 * Returns a count of all {@link PhoneAccount}s.
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700571 *
Nancy Chen210ef032014-09-15 17:58:42 -0700572 * @return The count of {@link PhoneAccount}s.
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700573 * @hide
574 */
575 @SystemApi
576 public int getAllPhoneAccountsCount() {
577 try {
578 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700579 return getTelecomService().getAllPhoneAccountsCount();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700580 }
581 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700582 Log.e(TAG, "Error calling ITelecomService#getAllPhoneAccountsCount", e);
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700583 }
584 return 0;
585 }
586
587 /**
588 * Returns a list of all {@link PhoneAccount}s.
589 *
590 * @return All {@link PhoneAccount}s.
591 * @hide
592 */
593 @SystemApi
594 public List<PhoneAccount> getAllPhoneAccounts() {
595 try {
596 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700597 return getTelecomService().getAllPhoneAccounts();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700598 }
599 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700600 Log.e(TAG, "Error calling ITelecomService#getAllPhoneAccounts", e);
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700601 }
602 return Collections.EMPTY_LIST;
603 }
604
605 /**
606 * Returns a list of all {@link PhoneAccountHandle}s.
607 *
608 * @return All {@link PhoneAccountHandle}s.
609 * @hide
610 */
611 @SystemApi
612 public List<PhoneAccountHandle> getAllPhoneAccountHandles() {
613 try {
614 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700615 return getTelecomService().getAllPhoneAccountHandles();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700616 }
617 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700618 Log.e(TAG, "Error calling ITelecomService#getAllPhoneAccountHandles", e);
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700619 }
620 return Collections.EMPTY_LIST;
621 }
622
623 /**
Santos Cordond9e614f2014-10-28 13:10:36 -0700624 * Register a {@link PhoneAccount} for use by the system. When registering
625 * {@link PhoneAccount}s, existing registrations will be overwritten if the
626 * {@link PhoneAccountHandle} matches that of a {@link PhoneAccount} which is already
627 * registered. Once registered, the {@link PhoneAccount} is listed to the user as an option
628 * when placing calls. The user may still need to enable the {@link PhoneAccount} within
629 * the phone app settings before the account is usable.
630 * <p>
631 * A {@link SecurityException} will be thrown if an app tries to register a
632 * {@link PhoneAccountHandle} where the package name specified within
633 * {@link PhoneAccountHandle#getComponentName()} does not match the package name of the app.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700634 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700635 * @param account The complete {@link PhoneAccount}.
Evan Charlton0e094d92014-11-08 15:49:16 -0800636 *
637 * @hide
Ihab Awad807fe0a2014-07-09 12:30:52 -0700638 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800639 @SystemApi
Evan Charlton8c8a0622014-07-20 12:31:00 -0700640 public void registerPhoneAccount(PhoneAccount account) {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700641 try {
642 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700643 getTelecomService().registerPhoneAccount(account);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700644 }
645 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700646 Log.e(TAG, "Error calling ITelecomService#registerPhoneAccount", e);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700647 }
648 }
649
650 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700651 * Remove a {@link PhoneAccount} registration from the system.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700652 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700653 * @param accountHandle A {@link PhoneAccountHandle} for the {@link PhoneAccount} to unregister.
Evan Charlton0e094d92014-11-08 15:49:16 -0800654 * @hide
Ihab Awad807fe0a2014-07-09 12:30:52 -0700655 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800656 @SystemApi
Evan Charlton8c8a0622014-07-20 12:31:00 -0700657 public void unregisterPhoneAccount(PhoneAccountHandle accountHandle) {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700658 try {
659 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700660 getTelecomService().unregisterPhoneAccount(accountHandle);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700661 }
662 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700663 Log.e(TAG, "Error calling ITelecomService#unregisterPhoneAccount", e);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700664 }
665 }
666
667 /**
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700668 * Remove all Accounts that belong to the calling package from the system.
Evan Charlton0e094d92014-11-08 15:49:16 -0800669 * @hide
Ihab Awad807fe0a2014-07-09 12:30:52 -0700670 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800671 @SystemApi
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700672 public void clearAccounts() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700673 try {
674 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700675 getTelecomService().clearAccounts(mContext.getPackageName());
Ihab Awad807fe0a2014-07-09 12:30:52 -0700676 }
677 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700678 Log.e(TAG, "Error calling ITelecomService#clearAccounts", e);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700679 }
680 }
681
682 /**
Anthony Lee67279262014-10-27 11:28:40 -0700683 * Remove all Accounts that belong to the specified package from the system.
684 * @hide
685 */
686 public void clearAccountsForPackage(String packageName) {
687 try {
688 if (isServiceConnected() && !TextUtils.isEmpty(packageName)) {
689 getTelecomService().clearAccounts(packageName);
690 }
691 } catch (RemoteException e) {
Nancy Chen5cf27842015-01-24 23:30:27 -0800692 Log.e(TAG, "Error calling ITelecomService#clearAccountsForPackage", e);
Anthony Lee67279262014-10-27 11:28:40 -0700693 }
694 }
695
696 /**
Ihab Awad807fe0a2014-07-09 12:30:52 -0700697 * @hide
698 */
Santos Cordon6c7a3882014-06-25 15:30:08 -0700699 @SystemApi
700 public ComponentName getDefaultPhoneApp() {
701 try {
Santos Cordon9eb45932014-06-27 12:28:43 -0700702 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700703 return getTelecomService().getDefaultPhoneApp();
Santos Cordon9eb45932014-06-27 12:28:43 -0700704 }
Santos Cordon6c7a3882014-06-25 15:30:08 -0700705 } catch (RemoteException e) {
706 Log.e(TAG, "RemoteException attempting to get the default phone app.", e);
707 }
708 return null;
709 }
710
Santos Cordon9eb45932014-06-27 12:28:43 -0700711 /**
Nancy Chen443e5012014-10-15 15:48:21 -0700712 * Return whether a given phone number is the configured voicemail number for a
713 * particular phone account.
714 *
715 * @param accountHandle The handle for the account to check the voicemail number against
716 * @param number The number to look up.
717 *
718 * @hide
719 */
720 @SystemApi
721 public boolean isVoiceMailNumber(PhoneAccountHandle accountHandle, String number) {
722 try {
723 if (isServiceConnected()) {
724 return getTelecomService().isVoiceMailNumber(accountHandle, number);
725 }
726 } catch (RemoteException e) {
Nancy Chen5cf27842015-01-24 23:30:27 -0800727 Log.e(TAG, "RemoteException calling ITelecomService#isVoiceMailNumber.", e);
Nancy Chen443e5012014-10-15 15:48:21 -0700728 }
729 return false;
730 }
731
732 /**
Nancy Chen8c066f7c2014-12-03 15:18:08 -0800733 * Return whether a given phone account has a voicemail number configured.
734 *
735 * @param accountHandle The handle for the account to check for a voicemail number.
736 * @return {@code true} If the given phone account has a voicemail number.
737 *
738 * @hide
739 */
740 @SystemApi
741 public boolean hasVoiceMailNumber(PhoneAccountHandle accountHandle) {
742 try {
743 if (isServiceConnected()) {
744 return getTelecomService().hasVoiceMailNumber(accountHandle);
745 }
746 } catch (RemoteException e) {
Nancy Chen5cf27842015-01-24 23:30:27 -0800747 Log.e(TAG, "RemoteException calling ITelecomService#hasVoiceMailNumber.", e);
Nancy Chen8c066f7c2014-12-03 15:18:08 -0800748 }
749 return false;
750 }
751
752 /**
Nancy Chen5cf27842015-01-24 23:30:27 -0800753 * Return the line 1 phone number for given phone account.
754 *
755 * @param accountHandle The handle for the account retrieve a number for.
756 * @return A string representation of the line 1 phone number.
757 *
758 * @hide
759 */
760 @SystemApi
761 public String getLine1Number(PhoneAccountHandle accountHandle) {
762 try {
763 if (isServiceConnected()) {
764 return getTelecomService().getLine1Number(accountHandle);
765 }
766 } catch (RemoteException e) {
767 Log.e(TAG, "RemoteException calling ITelecomService#getLine1Number.", e);
768 }
769 return null;
770 }
771
772 /**
Santos Cordon9eb45932014-06-27 12:28:43 -0700773 * Returns whether there is an ongoing phone call (can be in dialing, ringing, active or holding
774 * states).
Nancy Chen0eb1e402014-08-21 22:52:29 -0700775 * <p>
776 * Requires permission: {@link android.Manifest.permission#READ_PHONE_STATE}
777 * </p>
Santos Cordon9eb45932014-06-27 12:28:43 -0700778 */
Nancy Chen0eb1e402014-08-21 22:52:29 -0700779 public boolean isInCall() {
Santos Cordon9eb45932014-06-27 12:28:43 -0700780 try {
781 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700782 return getTelecomService().isInCall();
Santos Cordon9eb45932014-06-27 12:28:43 -0700783 }
784 } catch (RemoteException e) {
Yorke Lee2ae312e2014-09-12 17:58:48 -0700785 Log.e(TAG, "RemoteException calling isInCall().", e);
Santos Cordon9eb45932014-06-27 12:28:43 -0700786 }
787 return false;
788 }
789
790 /**
Yorke Lee2ae312e2014-09-12 17:58:48 -0700791 * Returns one of the following constants that represents the current state of Telecom:
792 *
793 * {@link TelephonyManager#CALL_STATE_RINGING}
794 * {@link TelephonyManager#CALL_STATE_OFFHOOK}
795 * {@link TelephonyManager#CALL_STATE_IDLE}
Yorke Lee7c72c2d2014-10-28 14:12:02 -0700796 *
797 * Note that this API does not require the
798 * {@link android.Manifest.permission#READ_PHONE_STATE} permission. This is intentional, to
799 * preserve the behavior of {@link TelephonyManager#getCallState()}, which also did not require
800 * the permission.
Yorke Lee2ae312e2014-09-12 17:58:48 -0700801 * @hide
802 */
803 @SystemApi
804 public int getCallState() {
805 try {
806 if (isServiceConnected()) {
807 return getTelecomService().getCallState();
808 }
809 } catch (RemoteException e) {
810 Log.d(TAG, "RemoteException calling getCallState().", e);
811 }
812 return TelephonyManager.CALL_STATE_IDLE;
813 }
814
815 /**
Santos Cordon9eb45932014-06-27 12:28:43 -0700816 * Returns whether there currently exists is a ringing incoming-call.
817 *
818 * @hide
819 */
820 @SystemApi
821 public boolean isRinging() {
822 try {
823 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700824 return getTelecomService().isRinging();
Santos Cordon9eb45932014-06-27 12:28:43 -0700825 }
826 } catch (RemoteException e) {
827 Log.e(TAG, "RemoteException attempting to get ringing state of phone app.", e);
828 }
829 return false;
830 }
831
832 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700833 * Ends an ongoing call.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700834 * TODO: L-release - need to convert all invocations of ITelecomService#endCall to use this
Santos Cordon96efb482014-07-19 14:57:05 -0700835 * method (clockwork & gearhead).
Santos Cordon9eb45932014-06-27 12:28:43 -0700836 * @hide
837 */
838 @SystemApi
839 public boolean endCall() {
840 try {
841 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700842 return getTelecomService().endCall();
Santos Cordon9eb45932014-06-27 12:28:43 -0700843 }
844 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700845 Log.e(TAG, "Error calling ITelecomService#endCall", e);
Santos Cordon9eb45932014-06-27 12:28:43 -0700846 }
847 return false;
848 }
849
850 /**
851 * If there is a ringing incoming call, this method accepts the call on behalf of the user.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700852 * TODO: L-release - need to convert all invocation of ITelecmmService#answerRingingCall to use
Santos Cordon96efb482014-07-19 14:57:05 -0700853 * this method (clockwork & gearhead).
Santos Cordon9eb45932014-06-27 12:28:43 -0700854 *
855 * @hide
856 */
857 @SystemApi
858 public void acceptRingingCall() {
859 try {
860 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700861 getTelecomService().acceptRingingCall();
Santos Cordon9eb45932014-06-27 12:28:43 -0700862 }
863 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700864 Log.e(TAG, "Error calling ITelecomService#acceptRingingCall", e);
Santos Cordon9eb45932014-06-27 12:28:43 -0700865 }
866 }
867
868 /**
869 * Silences the ringer if a ringing call exists.
870 *
871 * @hide
872 */
873 @SystemApi
874 public void silenceRinger() {
875 try {
876 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700877 getTelecomService().silenceRinger();
Santos Cordon9eb45932014-06-27 12:28:43 -0700878 }
879 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700880 Log.e(TAG, "Error calling ITelecomService#silenceRinger", e);
Santos Cordon9eb45932014-06-27 12:28:43 -0700881 }
882 }
883
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700884 /**
885 * Returns whether TTY is supported on this device.
886 *
887 * @hide
888 */
889 @SystemApi
890 public boolean isTtySupported() {
891 try {
892 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700893 return getTelecomService().isTtySupported();
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700894 }
895 } catch (RemoteException e) {
896 Log.e(TAG, "RemoteException attempting to get TTY supported state.", e);
897 }
898 return false;
899 }
900
901 /**
902 * 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 -0700903 * settings and have a wired headset plugged in.
904 * Valid modes are:
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700905 * - {@link TelecomManager#TTY_MODE_OFF}
906 * - {@link TelecomManager#TTY_MODE_FULL}
907 * - {@link TelecomManager#TTY_MODE_HCO}
908 * - {@link TelecomManager#TTY_MODE_VCO}
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700909 * @hide
910 */
911 public int getCurrentTtyMode() {
912 try {
913 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700914 return getTelecomService().getCurrentTtyMode();
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700915 }
916 } catch (RemoteException e) {
917 Log.e(TAG, "RemoteException attempting to get the current TTY mode.", e);
918 }
Evan Charlton10197192014-07-19 15:00:29 -0700919 return TTY_MODE_OFF;
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700920 }
921
Santos Cordon96efb482014-07-19 14:57:05 -0700922 /**
923 * Registers a new incoming call. A {@link ConnectionService} should invoke this method when it
924 * has an incoming call. The specified {@link PhoneAccountHandle} must have been registered
Nancy Chen210ef032014-09-15 17:58:42 -0700925 * with {@link #registerPhoneAccount}. Once invoked, this method will cause the system to bind
926 * to the {@link ConnectionService} associated with the {@link PhoneAccountHandle} and request
Santos Cordon96efb482014-07-19 14:57:05 -0700927 * additional information about the call (See
928 * {@link ConnectionService#onCreateIncomingConnection}) before starting the incoming call UI.
929 *
930 * @param phoneAccount A {@link PhoneAccountHandle} registered with
931 * {@link #registerPhoneAccount}.
932 * @param extras A bundle that will be passed through to
933 * {@link ConnectionService#onCreateIncomingConnection}.
Evan Charlton0e094d92014-11-08 15:49:16 -0800934 * @hide
Santos Cordon96efb482014-07-19 14:57:05 -0700935 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800936 @SystemApi
Santos Cordon96efb482014-07-19 14:57:05 -0700937 public void addNewIncomingCall(PhoneAccountHandle phoneAccount, Bundle extras) {
938 try {
939 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700940 getTelecomService().addNewIncomingCall(
Santos Cordon96efb482014-07-19 14:57:05 -0700941 phoneAccount, extras == null ? new Bundle() : extras);
942 }
943 } catch (RemoteException e) {
944 Log.e(TAG, "RemoteException adding a new incoming call: " + phoneAccount, e);
945 }
946 }
947
Nancy Chen0eb1e402014-08-21 22:52:29 -0700948 /**
Yorke Leec3cf9822014-10-02 09:38:39 -0700949 * Registers a new unknown call with Telecom. This can only be called by the system Telephony
950 * service. This is invoked when Telephony detects a new unknown connection that was neither
951 * a new incoming call, nor an user-initiated outgoing call.
952 *
953 * @param phoneAccount A {@link PhoneAccountHandle} registered with
954 * {@link #registerPhoneAccount}.
955 * @param extras A bundle that will be passed through to
956 * {@link ConnectionService#onCreateIncomingConnection}.
957 * @hide
958 */
959 @SystemApi
960 public void addNewUnknownCall(PhoneAccountHandle phoneAccount, Bundle extras) {
961 try {
962 if (isServiceConnected()) {
963 getTelecomService().addNewUnknownCall(
964 phoneAccount, extras == null ? new Bundle() : extras);
965 }
966 } catch (RemoteException e) {
967 Log.e(TAG, "RemoteException adding a new unknown call: " + phoneAccount, e);
968 }
969 }
970
971 /**
Nancy Chen0eb1e402014-08-21 22:52:29 -0700972 * Processes the specified dial string as an MMI code.
973 * MMI codes are any sequence of characters entered into the dialpad that contain a "*" or "#".
974 * Some of these sequences launch special behavior through handled by Telephony.
Nancy Chen95e8a672014-10-16 18:38:21 -0700975 * This method uses the default subscription.
Nancy Chen0eb1e402014-08-21 22:52:29 -0700976 * <p>
977 * Requires that the method-caller be set as the system dialer app.
978 * </p>
979 *
980 * @param dialString The digits to dial.
981 * @return True if the digits were processed as an MMI code, false otherwise.
982 */
983 public boolean handleMmi(String dialString) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700984 ITelecomService service = getTelecomService();
Nancy Chen0eb1e402014-08-21 22:52:29 -0700985 if (service != null) {
986 try {
987 return service.handlePinMmi(dialString);
988 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700989 Log.e(TAG, "Error calling ITelecomService#handlePinMmi", e);
Nancy Chen0eb1e402014-08-21 22:52:29 -0700990 }
991 }
992 return false;
993 }
994
995 /**
Nancy Chen95e8a672014-10-16 18:38:21 -0700996 * Processes the specified dial string as an MMI code.
997 * MMI codes are any sequence of characters entered into the dialpad that contain a "*" or "#".
998 * Some of these sequences launch special behavior through handled by Telephony.
999 * <p>
1000 * Requires that the method-caller be set as the system dialer app.
1001 * </p>
1002 *
1003 * @param accountHandle The handle for the account the MMI code should apply to.
1004 * @param dialString The digits to dial.
1005 * @return True if the digits were processed as an MMI code, false otherwise.
Evan Charlton0e094d92014-11-08 15:49:16 -08001006 * @hide
Nancy Chen95e8a672014-10-16 18:38:21 -07001007 */
Evan Charlton0e094d92014-11-08 15:49:16 -08001008 @SystemApi
Nancy Chen95e8a672014-10-16 18:38:21 -07001009 public boolean handleMmi(PhoneAccountHandle accountHandle, String dialString) {
1010 ITelecomService service = getTelecomService();
1011 if (service != null) {
1012 try {
1013 return service.handlePinMmiForPhoneAccount(accountHandle, dialString);
1014 } catch (RemoteException e) {
1015 Log.e(TAG, "Error calling ITelecomService#handlePinMmi", e);
1016 }
1017 }
1018 return false;
1019 }
1020
1021 /**
Nancy Chenb2299c12014-10-29 18:22:11 -07001022 * @param accountHandle The handle for the account to derive an adn query URI for or
1023 * {@code null} to return a URI which will use the default account.
1024 * @return The URI (with the content:// scheme) specific to the specified {@link PhoneAccount}
1025 * for the the content retrieve.
Evan Charlton0e094d92014-11-08 15:49:16 -08001026 * @hide
Nancy Chenb2299c12014-10-29 18:22:11 -07001027 */
Evan Charlton0e094d92014-11-08 15:49:16 -08001028 @SystemApi
Nancy Chenb2299c12014-10-29 18:22:11 -07001029 public Uri getAdnUriForPhoneAccount(PhoneAccountHandle accountHandle) {
1030 ITelecomService service = getTelecomService();
1031 if (service != null && accountHandle != null) {
1032 try {
1033 return service.getAdnUriForPhoneAccount(accountHandle);
1034 } catch (RemoteException e) {
1035 Log.e(TAG, "Error calling ITelecomService#getAdnUriForPhoneAccount", e);
1036 }
1037 }
1038 return Uri.parse("content://icc/adn");
1039 }
1040
1041 /**
Nancy Chen0eb1e402014-08-21 22:52:29 -07001042 * Removes the missed-call notification if one is present.
1043 * <p>
1044 * Requires that the method-caller be set as the system dialer app.
1045 * </p>
1046 */
1047 public void cancelMissedCallsNotification() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001048 ITelecomService service = getTelecomService();
Nancy Chen0eb1e402014-08-21 22:52:29 -07001049 if (service != null) {
1050 try {
1051 service.cancelMissedCallsNotification();
1052 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001053 Log.e(TAG, "Error calling ITelecomService#cancelMissedCallsNotification", e);
Nancy Chen0eb1e402014-08-21 22:52:29 -07001054 }
1055 }
1056 }
1057
1058 /**
1059 * Brings the in-call screen to the foreground if there is an ongoing call. If there is
1060 * currently no ongoing call, then this method does nothing.
1061 * <p>
1062 * Requires that the method-caller be set as the system dialer app or have the
1063 * {@link android.Manifest.permission#READ_PHONE_STATE} permission.
1064 * </p>
1065 *
1066 * @param showDialpad Brings up the in-call dialpad as part of showing the in-call screen.
1067 */
1068 public void showInCallScreen(boolean showDialpad) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001069 ITelecomService service = getTelecomService();
Nancy Chen0eb1e402014-08-21 22:52:29 -07001070 if (service != null) {
1071 try {
1072 service.showInCallScreen(showDialpad);
1073 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001074 Log.e(TAG, "Error calling ITelecomService#showCallScreen", e);
Nancy Chen0eb1e402014-08-21 22:52:29 -07001075 }
1076 }
1077 }
1078
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001079 private ITelecomService getTelecomService() {
1080 return ITelecomService.Stub.asInterface(ServiceManager.getService(Context.TELECOM_SERVICE));
Santos Cordon6c7a3882014-06-25 15:30:08 -07001081 }
Santos Cordon9eb45932014-06-27 12:28:43 -07001082
1083 private boolean isServiceConnected() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001084 boolean isConnected = getTelecomService() != null;
Santos Cordon9eb45932014-06-27 12:28:43 -07001085 if (!isConnected) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001086 Log.w(TAG, "Telecom Service not found.");
Santos Cordon9eb45932014-06-27 12:28:43 -07001087 }
1088 return isConnected;
1089 }
Evan Charlton235c1592014-09-05 15:41:23 +00001090}