blob: fd953271022419457ae6e76f9303e05e49e7f114 [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;
Yorke Lee3e56ba12015-04-23 12:32:36 -070020import android.content.Intent;
Nancy Chenb2299c12014-10-29 18:22:11 -070021import android.net.Uri;
Santos Cordon96efb482014-07-19 14:57:05 -070022import android.os.Bundle;
Santos Cordon6c7a3882014-06-25 15:30:08 -070023import android.os.RemoteException;
24import android.os.ServiceManager;
Yorke Lee2ae312e2014-09-12 17:58:48 -070025import android.telephony.TelephonyManager;
Anthony Lee67279262014-10-27 11:28:40 -070026import android.text.TextUtils;
Santos Cordon6c7a3882014-06-25 15:30:08 -070027import android.util.Log;
Yorke Leeb4ce1432014-06-09 13:53:23 -070028
Tyler Gunnef9f6f92014-09-12 22:16:17 -070029import com.android.internal.telecom.ITelecomService;
Yorke Leeb4ce1432014-06-09 13:53:23 -070030
Jay Shrauner7746a942014-08-26 12:15:15 -070031import java.util.ArrayList;
Tyler Gunna1ed7d12014-09-08 09:52:22 -070032import java.util.Collections;
Ihab Awad807fe0a2014-07-09 12:30:52 -070033import java.util.List;
34
Yorke Leeb4ce1432014-06-09 13:53:23 -070035/**
Santos Cordond9e614f2014-10-28 13:10:36 -070036 * Provides access to information about active calls and registration/call-management functionality.
Evan Charlton0e094d92014-11-08 15:49:16 -080037 * Apps can use methods in this class to determine the current call state.
Santos Cordond9e614f2014-10-28 13:10:36 -070038 * <p>
39 * Apps do not instantiate this class directly; instead, they retrieve a reference to an instance
40 * through {@link Context#getSystemService Context.getSystemService(Context.TELECOM_SERVICE)}.
41 * <p>
42 * Note that access to some telecom information is permission-protected. Your app cannot access the
43 * protected information or gain access to protected functionality unless it has the appropriate
44 * permissions declared in its manifest file. Where permissions apply, they are noted in the method
45 * descriptions.
Yorke Leeb4ce1432014-06-09 13:53:23 -070046 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -070047public class TelecomManager {
Ihab Awad807fe0a2014-07-09 12:30:52 -070048
Evan Charlton10197192014-07-19 15:00:29 -070049 /**
Santos Cordon96efb482014-07-19 14:57:05 -070050 * Activity action: Starts the UI for handing an incoming call. This intent starts the in-call
Tyler Gunnef9f6f92014-09-12 22:16:17 -070051 * UI by notifying the Telecom system that an incoming call exists for a specific call service
52 * (see {@link android.telecom.ConnectionService}). Telecom reads the Intent extras to find
53 * and bind to the appropriate {@link android.telecom.ConnectionService} which Telecom will
Santos Cordon96efb482014-07-19 14:57:05 -070054 * ultimately use to control and get information about the call.
55 * <p>
56 * Input: get*Extra field {@link #EXTRA_PHONE_ACCOUNT_HANDLE} contains the component name of the
Tyler Gunnef9f6f92014-09-12 22:16:17 -070057 * {@link android.telecom.ConnectionService} that Telecom should bind to. Telecom will then
Evan Charlton10197192014-07-19 15:00:29 -070058 * ask the connection service for more information about the call prior to showing any UI.
Evan Charlton10197192014-07-19 15:00:29 -070059 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -070060 public static final String ACTION_INCOMING_CALL = "android.telecom.action.INCOMING_CALL";
Evan Charlton10197192014-07-19 15:00:29 -070061
62 /**
Yorke Leec3cf9822014-10-02 09:38:39 -070063 * Similar to {@link #ACTION_INCOMING_CALL}, but is used only by Telephony to add a new
64 * sim-initiated MO call for carrier testing.
65 * @hide
66 */
67 public static final String ACTION_NEW_UNKNOWN_CALL = "android.telecom.action.NEW_UNKNOWN_CALL";
68
69 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -070070 * The {@link android.content.Intent} action used to configure a
Tyler Gunnef9f6f92014-09-12 22:16:17 -070071 * {@link android.telecom.ConnectionService}.
Evan Charlton0e094d92014-11-08 15:49:16 -080072 * @hide
Evan Charlton10197192014-07-19 15:00:29 -070073 */
Evan Charlton0e094d92014-11-08 15:49:16 -080074 @SystemApi
Evan Charlton10197192014-07-19 15:00:29 -070075 public static final String ACTION_CONNECTION_SERVICE_CONFIGURE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -070076 "android.telecom.action.CONNECTION_SERVICE_CONFIGURE";
Evan Charlton10197192014-07-19 15:00:29 -070077
78 /**
Andrew Lee873cfbf2015-02-26 15:22:00 -080079 * The {@link android.content.Intent} action used to show the call accessibility settings page.
80 */
81 public static final String ACTION_SHOW_CALL_ACCESSIBILITY_SETTINGS =
82 "android.telecom.action.SHOW_CALL_ACCESSIBILITY_SETTINGS";
83
84 /**
Yorke Lee3818a8922014-07-21 15:57:17 -070085 * The {@link android.content.Intent} action used to show the call settings page.
86 */
87 public static final String ACTION_SHOW_CALL_SETTINGS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -070088 "android.telecom.action.SHOW_CALL_SETTINGS";
Yorke Lee3818a8922014-07-21 15:57:17 -070089
90 /**
Andrew Lee866080f2015-02-19 12:05:33 -080091 * The {@link android.content.Intent} action used to show the respond via SMS settings page.
92 */
93 public static final String ACTION_SHOW_RESPOND_VIA_SMS_SETTINGS =
94 "android.telecom.action.SHOW_RESPOND_VIA_SMS_SETTINGS";
95
96 /**
Evan Charlton6d8604f2014-09-04 12:38:17 -070097 * The {@link android.content.Intent} action used to show the settings page used to configure
98 * {@link PhoneAccount} preferences.
99 */
100 public static final String ACTION_CHANGE_PHONE_ACCOUNTS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700101 "android.telecom.action.CHANGE_PHONE_ACCOUNTS";
Evan Charlton6d8604f2014-09-04 12:38:17 -0700102
103 /**
Santos Cordonc66f3ba2015-02-27 15:22:07 -0800104 * The {@link android.content.Intent} action used indicate that a new phone account was
105 * just registered.
106 * @hide
107 */
108 @SystemApi
109 public static final String ACTION_PHONE_ACCOUNT_REGISTERED =
110 "android.telecom.action.PHONE_ACCOUNT_REGISTERED";
111
112 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700113 * Optional extra for {@link android.content.Intent#ACTION_CALL} containing a boolean that
114 * determines whether the speakerphone should be automatically turned on for an outgoing call.
Evan Charlton10197192014-07-19 15:00:29 -0700115 */
116 public static final String EXTRA_START_CALL_WITH_SPEAKERPHONE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700117 "android.telecom.extra.START_CALL_WITH_SPEAKERPHONE";
Evan Charlton10197192014-07-19 15:00:29 -0700118
119 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700120 * Optional extra for {@link android.content.Intent#ACTION_CALL} containing an integer that
121 * determines the desired video state for an outgoing call.
Santos Cordon96efb482014-07-19 14:57:05 -0700122 * Valid options:
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700123 * {@link VideoProfile.VideoState#AUDIO_ONLY},
124 * {@link VideoProfile.VideoState#BIDIRECTIONAL},
125 * {@link VideoProfile.VideoState#RX_ENABLED},
126 * {@link VideoProfile.VideoState#TX_ENABLED}.
Evan Charlton10197192014-07-19 15:00:29 -0700127 */
128 public static final String EXTRA_START_CALL_WITH_VIDEO_STATE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700129 "android.telecom.extra.START_CALL_WITH_VIDEO_STATE";
Evan Charlton10197192014-07-19 15:00:29 -0700130
131 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700132 * The extra used with an {@link android.content.Intent#ACTION_CALL} and
133 * {@link android.content.Intent#ACTION_DIAL} {@code Intent} to specify a
134 * {@link PhoneAccountHandle} to use when making the call.
Evan Charlton10197192014-07-19 15:00:29 -0700135 * <p class="note">
Santos Cordon96efb482014-07-19 14:57:05 -0700136 * Retrieve with {@link android.content.Intent#getParcelableExtra(String)}.
Evan Charlton10197192014-07-19 15:00:29 -0700137 */
Evan Charlton6eb262c2014-07-19 18:18:19 -0700138 public static final String EXTRA_PHONE_ACCOUNT_HANDLE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700139 "android.telecom.extra.PHONE_ACCOUNT_HANDLE";
Evan Charlton10197192014-07-19 15:00:29 -0700140
141 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700142 * Optional extra for {@link #ACTION_INCOMING_CALL} containing a {@link Bundle} which contains
143 * metadata about the call. This {@link Bundle} will be returned to the
144 * {@link ConnectionService}.
Evan Charlton10197192014-07-19 15:00:29 -0700145 */
146 public static final String EXTRA_INCOMING_CALL_EXTRAS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700147 "android.telecom.extra.INCOMING_CALL_EXTRAS";
Evan Charlton10197192014-07-19 15:00:29 -0700148
149 /**
Nancy Chen10798dc2014-08-08 14:00:25 -0700150 * Optional extra for {@link android.content.Intent#ACTION_CALL} and
151 * {@link android.content.Intent#ACTION_DIAL} {@code Intent} containing a {@link Bundle}
152 * which contains metadata about the call. This {@link Bundle} will be saved into
153 * {@code Call.Details}.
Nancy Chen10798dc2014-08-08 14:00:25 -0700154 */
155 public static final String EXTRA_OUTGOING_CALL_EXTRAS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700156 "android.telecom.extra.OUTGOING_CALL_EXTRAS";
Nancy Chen10798dc2014-08-08 14:00:25 -0700157
158 /**
Yorke Leec3cf9822014-10-02 09:38:39 -0700159 * @hide
160 */
161 public static final String EXTRA_UNKNOWN_CALL_HANDLE =
162 "android.telecom.extra.UNKNOWN_CALL_HANDLE";
163
164 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700165 * Optional extra for {@link android.telephony.TelephonyManager#ACTION_PHONE_STATE_CHANGED}
166 * containing the disconnect code.
Evan Charlton10197192014-07-19 15:00:29 -0700167 */
168 public static final String EXTRA_CALL_DISCONNECT_CAUSE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700169 "android.telecom.extra.CALL_DISCONNECT_CAUSE";
Evan Charlton10197192014-07-19 15:00:29 -0700170
171 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700172 * Optional extra for {@link android.telephony.TelephonyManager#ACTION_PHONE_STATE_CHANGED}
173 * containing the disconnect message.
Evan Charlton10197192014-07-19 15:00:29 -0700174 */
175 public static final String EXTRA_CALL_DISCONNECT_MESSAGE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700176 "android.telecom.extra.CALL_DISCONNECT_MESSAGE";
Evan Charlton10197192014-07-19 15:00:29 -0700177
178 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700179 * Optional extra for {@link android.telephony.TelephonyManager#ACTION_PHONE_STATE_CHANGED}
180 * containing the component name of the associated connection service.
Evan Charlton0e094d92014-11-08 15:49:16 -0800181 * @hide
Evan Charlton10197192014-07-19 15:00:29 -0700182 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800183 @SystemApi
Evan Charlton10197192014-07-19 15:00:29 -0700184 public static final String EXTRA_CONNECTION_SERVICE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700185 "android.telecom.extra.CONNECTION_SERVICE";
Evan Charlton10197192014-07-19 15:00:29 -0700186
187 /**
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700188 * An optional {@link android.content.Intent#ACTION_CALL} intent extra denoting the
189 * package name of the app specifying an alternative gateway for the call.
190 * The value is a string.
191 *
192 * (The following comment corresponds to the all GATEWAY_* extras)
193 * An app which sends the {@link android.content.Intent#ACTION_CALL} intent can specify an
194 * alternative address to dial which is different from the one specified and displayed to
195 * the user. This alternative address is referred to as the gateway address.
196 */
197 public static final String GATEWAY_PROVIDER_PACKAGE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700198 "android.telecom.extra.GATEWAY_PROVIDER_PACKAGE";
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700199
200 /**
201 * An optional {@link android.content.Intent#ACTION_CALL} intent extra corresponding to the
202 * original address to dial for the call. This is used when an alternative gateway address is
203 * provided to recall the original address.
204 * The value is a {@link android.net.Uri}.
205 *
206 * (See {@link #GATEWAY_PROVIDER_PACKAGE} for details)
207 */
208 public static final String GATEWAY_ORIGINAL_ADDRESS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700209 "android.telecom.extra.GATEWAY_ORIGINAL_ADDRESS";
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700210
211 /**
Evan Charlton10197192014-07-19 15:00:29 -0700212 * The number which the party on the other side of the line will see (and use to return the
213 * call).
214 * <p>
Santos Cordon96efb482014-07-19 14:57:05 -0700215 * {@link ConnectionService}s which interact with {@link RemoteConnection}s should only populate
216 * this if the {@link android.telephony.TelephonyManager#getLine1Number()} value, as that is the
217 * user's expected caller ID.
Evan Charlton10197192014-07-19 15:00:29 -0700218 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700219 public static final String EXTRA_CALL_BACK_NUMBER = "android.telecom.extra.CALL_BACK_NUMBER";
Evan Charlton10197192014-07-19 15:00:29 -0700220
221 /**
222 * The dual tone multi-frequency signaling character sent to indicate the dialing system should
223 * pause for a predefined period.
224 */
225 public static final char DTMF_CHARACTER_PAUSE = ',';
226
227 /**
228 * The dual-tone multi-frequency signaling character sent to indicate the dialing system should
229 * wait for user confirmation before proceeding.
230 */
231 public static final char DTMF_CHARACTER_WAIT = ';';
232
233 /**
234 * TTY (teletypewriter) mode is off.
235 *
236 * @hide
237 */
238 public static final int TTY_MODE_OFF = 0;
239
240 /**
241 * TTY (teletypewriter) mode is on. The speaker is off and the microphone is muted. The user
242 * will communicate with the remote party by sending and receiving text messages.
243 *
244 * @hide
245 */
246 public static final int TTY_MODE_FULL = 1;
247
248 /**
249 * TTY (teletypewriter) mode is in hearing carryover mode (HCO). The microphone is muted but the
250 * speaker is on. The user will communicate with the remote party by sending text messages and
251 * hearing an audible reply.
252 *
253 * @hide
254 */
255 public static final int TTY_MODE_HCO = 2;
256
257 /**
258 * TTY (teletypewriter) mode is in voice carryover mode (VCO). The speaker is off but the
259 * microphone is still on. User will communicate with the remote party by speaking and receiving
260 * text message replies.
261 *
262 * @hide
263 */
264 public static final int TTY_MODE_VCO = 3;
265
266 /**
267 * Broadcast intent action indicating that the current TTY mode has changed. An intent extra
268 * provides this state as an int.
Evan Charlton10197192014-07-19 15:00:29 -0700269 *
Santos Cordon96efb482014-07-19 14:57:05 -0700270 * @see #EXTRA_CURRENT_TTY_MODE
Evan Charlton10197192014-07-19 15:00:29 -0700271 * @hide
272 */
273 public static final String ACTION_CURRENT_TTY_MODE_CHANGED =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700274 "android.telecom.action.CURRENT_TTY_MODE_CHANGED";
Evan Charlton10197192014-07-19 15:00:29 -0700275
276 /**
277 * The lookup key for an int that indicates the current TTY mode.
278 * Valid modes are:
279 * - {@link #TTY_MODE_OFF}
280 * - {@link #TTY_MODE_FULL}
281 * - {@link #TTY_MODE_HCO}
282 * - {@link #TTY_MODE_VCO}
283 *
284 * @hide
285 */
286 public static final String EXTRA_CURRENT_TTY_MODE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700287 "android.telecom.intent.extra.CURRENT_TTY_MODE";
Evan Charlton10197192014-07-19 15:00:29 -0700288
289 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700290 * Broadcast intent action indicating that the TTY preferred operating mode has changed. An
291 * intent extra provides the new mode as an int.
Evan Charlton10197192014-07-19 15:00:29 -0700292 *
Santos Cordon96efb482014-07-19 14:57:05 -0700293 * @see #EXTRA_TTY_PREFERRED_MODE
Evan Charlton10197192014-07-19 15:00:29 -0700294 * @hide
295 */
296 public static final String ACTION_TTY_PREFERRED_MODE_CHANGED =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700297 "android.telecom.action.TTY_PREFERRED_MODE_CHANGED";
Evan Charlton10197192014-07-19 15:00:29 -0700298
299 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700300 * The lookup key for an int that indicates preferred TTY mode. Valid modes are: -
301 * {@link #TTY_MODE_OFF} - {@link #TTY_MODE_FULL} - {@link #TTY_MODE_HCO} -
302 * {@link #TTY_MODE_VCO}
Evan Charlton10197192014-07-19 15:00:29 -0700303 *
304 * @hide
305 */
306 public static final String EXTRA_TTY_PREFERRED_MODE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700307 "android.telecom.intent.extra.TTY_PREFERRED";
Evan Charlton10197192014-07-19 15:00:29 -0700308
Nancy Chen9d568c02014-09-08 14:17:59 -0700309 /**
310 * The following 4 constants define how properties such as phone numbers and names are
311 * displayed to the user.
312 */
313
314 /** Property is displayed normally. */
315 public static final int PRESENTATION_ALLOWED = 1;
316
317 /** Property was blocked. */
318 public static final int PRESENTATION_RESTRICTED = 2;
319
320 /** Presentation was not specified or is unknown. */
321 public static final int PRESENTATION_UNKNOWN = 3;
322
323 /** Property should be displayed as a pay phone. */
324 public static final int PRESENTATION_PAYPHONE = 4;
325
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700326 private static final String TAG = "TelecomManager";
Yorke Leeb4ce1432014-06-09 13:53:23 -0700327
328 private final Context mContext;
Yorke Leeb4ce1432014-06-09 13:53:23 -0700329
Santos Cordon6c7a3882014-06-25 15:30:08 -0700330 /**
331 * @hide
332 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700333 public static TelecomManager from(Context context) {
334 return (TelecomManager) context.getSystemService(Context.TELECOM_SERVICE);
Yorke Leeb4ce1432014-06-09 13:53:23 -0700335 }
Santos Cordon6c7a3882014-06-25 15:30:08 -0700336
337 /**
338 * @hide
339 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700340 public TelecomManager(Context context) {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700341 Context appContext = context.getApplicationContext();
342 if (appContext != null) {
343 mContext = appContext;
344 } else {
345 mContext = context;
346 }
347 }
348
349 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700350 * Return the {@link PhoneAccount} which is the user-chosen default for making outgoing phone
Nancy Chen513c8922014-09-17 14:47:20 -0700351 * calls with a specified URI scheme.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700352 * <p>
Santos Cordon96efb482014-07-19 14:57:05 -0700353 * Apps must be prepared for this method to return {@code null}, indicating that there currently
Nancy Chen513c8922014-09-17 14:47:20 -0700354 * exists no user-chosen default {@code PhoneAccount}.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700355 * <p>
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700356 * @param uriScheme The URI scheme.
Nancy Chen513c8922014-09-17 14:47:20 -0700357 * @return The {@link PhoneAccountHandle} corresponding to the user-chosen default for outgoing
358 * phone calls for a specified URI scheme.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700359 */
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700360 public PhoneAccountHandle getDefaultOutgoingPhoneAccount(String uriScheme) {
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700361 try {
362 if (isServiceConnected()) {
Svet Ganov16a16892015-04-16 10:32:04 -0700363 return getTelecomService().getDefaultOutgoingPhoneAccount(uriScheme,
364 mContext.getOpPackageName());
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.
Jay Shrauner225ccad2015-04-15 15:51:15 -0700381 * @hide
Andrew Leed4abbfb2014-09-03 14:58:27 -0700382 */
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.
Andrew Lee59cac3a2014-08-28 16:50:10 -0700413 */
414 public PhoneAccountHandle getSimCallManager() {
415 try {
416 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700417 return getTelecomService().getSimCallManager();
Andrew Lee59cac3a2014-08-28 16:50:10 -0700418 }
419 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700420 Log.e(TAG, "Error calling ITelecomService#getSimCallManager");
Andrew Lee59cac3a2014-08-28 16:50:10 -0700421 }
422 return null;
423 }
424
425 /**
426 * Sets the SIM call manager to the specified phone account.
427 * @param accountHandle The phone account handle of the account to set as the sim call manager.
428 * @hide
429 */
430 public void setSimCallManager(PhoneAccountHandle accountHandle) {
431 try {
432 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700433 getTelecomService().setSimCallManager(accountHandle);
Andrew Lee59cac3a2014-08-28 16:50:10 -0700434 }
435 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700436 Log.e(TAG, "Error calling ITelecomService#setSimCallManager");
Andrew Lee59cac3a2014-08-28 16:50:10 -0700437 }
438 }
439
440 /**
441 * Returns the list of registered SIM call managers.
442 * @return List of registered SIM call managers.
443 * @hide
444 */
445 public List<PhoneAccountHandle> getSimCallManagers() {
446 try {
447 if (isServiceConnected()) {
Svet Ganov16a16892015-04-16 10:32:04 -0700448 return getTelecomService().getSimCallManagers(mContext.getOpPackageName());
Andrew Lee59cac3a2014-08-28 16:50:10 -0700449 }
450 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700451 Log.e(TAG, "Error calling ITelecomService#getSimCallManagers");
Andrew Lee59cac3a2014-08-28 16:50:10 -0700452 }
453 return new ArrayList<>();
454 }
455
456 /**
Evan Charltoneb0a8d562014-09-04 12:03:34 -0700457 * Returns the current connection manager. Apps must be prepared for this method to return
458 * {@code null}, indicating that there currently exists no user-chosen default
459 * {@code PhoneAccount}.
460 *
461 * @return The phone account handle of the current connection manager.
Evan Charlton0e094d92014-11-08 15:49:16 -0800462 * @hide
Evan Charltoneb0a8d562014-09-04 12:03:34 -0700463 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800464 @SystemApi
Evan Charltoneb0a8d562014-09-04 12:03:34 -0700465 public PhoneAccountHandle getConnectionManager() {
466 return getSimCallManager();
467 }
468
469 /**
Sailesh Nepal7a4e3872014-11-21 11:01:40 -0800470 * Returns the list of registered SIM call managers.
471 * @return List of registered SIM call managers.
472 * @hide
473 */
474 @SystemApi
475 public List<PhoneAccountHandle> getRegisteredConnectionManagers() {
476 return getSimCallManagers();
477 }
478
479 /**
Nancy Chen210ef032014-09-15 17:58:42 -0700480 * Returns a list of the {@link PhoneAccountHandle}s which can be used to make and receive phone
481 * calls which support the specified URI scheme.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700482 * <P>
483 * For example, invoking with {@code "tel"} will find all {@link PhoneAccountHandle}s which
484 * support telephone calls (e.g. URIs such as {@code tel:555-555-1212}). Invoking with
485 * {@code "sip"} will find all {@link PhoneAccountHandle}s which support SIP calls (e.g. URIs
486 * such as {@code sip:example@sipexample.com}).
487 *
488 * @param uriScheme The URI scheme.
489 * @return A list of {@code PhoneAccountHandle} objects supporting the URI scheme.
Evan Charlton0e094d92014-11-08 15:49:16 -0800490 * @hide
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700491 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800492 @SystemApi
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700493 public List<PhoneAccountHandle> getPhoneAccountsSupportingScheme(String uriScheme) {
494 try {
495 if (isServiceConnected()) {
Svet Ganov16a16892015-04-16 10:32:04 -0700496 return getTelecomService().getPhoneAccountsSupportingScheme(uriScheme,
497 mContext.getOpPackageName());
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 *
Nancy Chen513c8922014-09-17 14:47:20 -0700513 */
514 public List<PhoneAccountHandle> getCallCapablePhoneAccounts() {
515 try {
516 if (isServiceConnected()) {
Svet Ganov16a16892015-04-16 10:32:04 -0700517 return getTelecomService().getCallCapablePhoneAccounts(mContext.getOpPackageName());
Nancy Chen513c8922014-09-17 14:47:20 -0700518 }
519 } catch (RemoteException e) {
520 Log.e(TAG, "Error calling ITelecomService#getCallCapablePhoneAccounts", e);
521 }
522 return new ArrayList<>();
523 }
524
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700525 /**
Nancy Chen513c8922014-09-17 14:47:20 -0700526 * Returns a list of all {@link PhoneAccount}s registered for the calling package.
527 *
528 * @return A list of {@code PhoneAccountHandle} objects.
Evan Charlton0e094d92014-11-08 15:49:16 -0800529 * @hide
Nancy Chen513c8922014-09-17 14:47:20 -0700530 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800531 @SystemApi
Nancy Chen513c8922014-09-17 14:47:20 -0700532 public List<PhoneAccountHandle> getPhoneAccountsForPackage() {
533 try {
534 if (isServiceConnected()) {
535 return getTelecomService().getPhoneAccountsForPackage(mContext.getPackageName());
536 }
537 } catch (RemoteException e) {
538 Log.e(TAG, "Error calling ITelecomService#getPhoneAccountsForPackage", e);
539 }
540 return null;
541 }
542
543 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700544 * Return the {@link PhoneAccount} for a specified {@link PhoneAccountHandle}. Object includes
545 * resources which can be used in a user interface.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700546 *
Evan Charlton6eb262c2014-07-19 18:18:19 -0700547 * @param account The {@link PhoneAccountHandle}.
Evan Charlton8c8a0622014-07-20 12:31:00 -0700548 * @return The {@link PhoneAccount} object.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700549 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700550 public PhoneAccount getPhoneAccount(PhoneAccountHandle account) {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700551 try {
552 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700553 return getTelecomService().getPhoneAccount(account);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700554 }
555 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700556 Log.e(TAG, "Error calling ITelecomService#getPhoneAccount", e);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700557 }
558 return null;
559 }
560
561 /**
Nancy Chen210ef032014-09-15 17:58:42 -0700562 * Returns a count of all {@link PhoneAccount}s.
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700563 *
Nancy Chen210ef032014-09-15 17:58:42 -0700564 * @return The count of {@link PhoneAccount}s.
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700565 * @hide
566 */
567 @SystemApi
568 public int getAllPhoneAccountsCount() {
569 try {
570 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700571 return getTelecomService().getAllPhoneAccountsCount();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700572 }
573 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700574 Log.e(TAG, "Error calling ITelecomService#getAllPhoneAccountsCount", e);
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700575 }
576 return 0;
577 }
578
579 /**
580 * Returns a list of all {@link PhoneAccount}s.
581 *
582 * @return All {@link PhoneAccount}s.
583 * @hide
584 */
585 @SystemApi
586 public List<PhoneAccount> getAllPhoneAccounts() {
587 try {
588 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700589 return getTelecomService().getAllPhoneAccounts();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700590 }
591 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700592 Log.e(TAG, "Error calling ITelecomService#getAllPhoneAccounts", e);
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700593 }
594 return Collections.EMPTY_LIST;
595 }
596
597 /**
598 * Returns a list of all {@link PhoneAccountHandle}s.
599 *
600 * @return All {@link PhoneAccountHandle}s.
601 * @hide
602 */
603 @SystemApi
604 public List<PhoneAccountHandle> getAllPhoneAccountHandles() {
605 try {
606 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700607 return getTelecomService().getAllPhoneAccountHandles();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700608 }
609 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700610 Log.e(TAG, "Error calling ITelecomService#getAllPhoneAccountHandles", e);
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700611 }
612 return Collections.EMPTY_LIST;
613 }
614
615 /**
Santos Cordond9e614f2014-10-28 13:10:36 -0700616 * Register a {@link PhoneAccount} for use by the system. When registering
617 * {@link PhoneAccount}s, existing registrations will be overwritten if the
618 * {@link PhoneAccountHandle} matches that of a {@link PhoneAccount} which is already
619 * registered. Once registered, the {@link PhoneAccount} is listed to the user as an option
620 * when placing calls. The user may still need to enable the {@link PhoneAccount} within
621 * the phone app settings before the account is usable.
622 * <p>
623 * A {@link SecurityException} will be thrown if an app tries to register a
624 * {@link PhoneAccountHandle} where the package name specified within
625 * {@link PhoneAccountHandle#getComponentName()} does not match the package name of the app.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700626 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700627 * @param account The complete {@link PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700628 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700629 public void registerPhoneAccount(PhoneAccount account) {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700630 try {
631 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700632 getTelecomService().registerPhoneAccount(account);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700633 }
634 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700635 Log.e(TAG, "Error calling ITelecomService#registerPhoneAccount", e);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700636 }
637 }
638
639 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700640 * Remove a {@link PhoneAccount} registration from the system.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700641 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700642 * @param accountHandle A {@link PhoneAccountHandle} for the {@link PhoneAccount} to unregister.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700643 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700644 public void unregisterPhoneAccount(PhoneAccountHandle accountHandle) {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700645 try {
646 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700647 getTelecomService().unregisterPhoneAccount(accountHandle);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700648 }
649 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700650 Log.e(TAG, "Error calling ITelecomService#unregisterPhoneAccount", e);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700651 }
652 }
653
654 /**
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700655 * Remove all Accounts that belong to the calling package from the system.
Evan Charlton0e094d92014-11-08 15:49:16 -0800656 * @hide
Ihab Awad807fe0a2014-07-09 12:30:52 -0700657 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800658 @SystemApi
Yorke Lee06044272015-04-14 15:16:59 -0700659 public void clearPhoneAccounts() {
660 clearAccounts();
661 }
662 /**
663 * Remove all Accounts that belong to the calling package from the system.
664 * @deprecated Use {@link #clearPhoneAccounts()} instead.
665 * @hide
666 */
667 @SystemApi
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700668 public void clearAccounts() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700669 try {
670 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700671 getTelecomService().clearAccounts(mContext.getPackageName());
Ihab Awad807fe0a2014-07-09 12:30:52 -0700672 }
673 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700674 Log.e(TAG, "Error calling ITelecomService#clearAccounts", e);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700675 }
676 }
677
678 /**
Anthony Lee67279262014-10-27 11:28:40 -0700679 * Remove all Accounts that belong to the specified package from the system.
680 * @hide
681 */
682 public void clearAccountsForPackage(String packageName) {
683 try {
684 if (isServiceConnected() && !TextUtils.isEmpty(packageName)) {
685 getTelecomService().clearAccounts(packageName);
686 }
687 } catch (RemoteException e) {
Nancy Chen5cf27842015-01-24 23:30:27 -0800688 Log.e(TAG, "Error calling ITelecomService#clearAccountsForPackage", e);
Anthony Lee67279262014-10-27 11:28:40 -0700689 }
690 }
691
692 /**
Ihab Awad807fe0a2014-07-09 12:30:52 -0700693 * @hide
694 */
Santos Cordon6c7a3882014-06-25 15:30:08 -0700695 @SystemApi
696 public ComponentName getDefaultPhoneApp() {
697 try {
Santos Cordon9eb45932014-06-27 12:28:43 -0700698 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700699 return getTelecomService().getDefaultPhoneApp();
Santos Cordon9eb45932014-06-27 12:28:43 -0700700 }
Santos Cordon6c7a3882014-06-25 15:30:08 -0700701 } catch (RemoteException e) {
702 Log.e(TAG, "RemoteException attempting to get the default phone app.", e);
703 }
704 return null;
705 }
706
Santos Cordon9eb45932014-06-27 12:28:43 -0700707 /**
Nancy Chen443e5012014-10-15 15:48:21 -0700708 * Return whether a given phone number is the configured voicemail number for a
709 * particular phone account.
710 *
711 * @param accountHandle The handle for the account to check the voicemail number against
712 * @param number The number to look up.
Nancy Chen443e5012014-10-15 15:48:21 -0700713 */
Nancy Chen443e5012014-10-15 15:48:21 -0700714 public boolean isVoiceMailNumber(PhoneAccountHandle accountHandle, String number) {
715 try {
716 if (isServiceConnected()) {
Svet Ganov16a16892015-04-16 10:32:04 -0700717 return getTelecomService().isVoiceMailNumber(accountHandle, number,
718 mContext.getOpPackageName());
Nancy Chen443e5012014-10-15 15:48:21 -0700719 }
720 } catch (RemoteException e) {
Nancy Chen5cf27842015-01-24 23:30:27 -0800721 Log.e(TAG, "RemoteException calling ITelecomService#isVoiceMailNumber.", e);
Nancy Chen443e5012014-10-15 15:48:21 -0700722 }
723 return false;
724 }
725
726 /**
Yorke Lee49e2d462015-04-15 16:14:22 -0700727 * Return the voicemail number for a given phone account.
Nancy Chen8c066f7c2014-12-03 15:18:08 -0800728 *
Yorke Lee49e2d462015-04-15 16:14:22 -0700729 * @param accountHandle The handle for the phone account.
730 * @return The voicemail number for the phone account, and {@code null} if one has not been
731 * configured.
Nancy Chen8c066f7c2014-12-03 15:18:08 -0800732 */
Yorke Lee49e2d462015-04-15 16:14:22 -0700733 public String getVoiceMailNumber(PhoneAccountHandle accountHandle) {
Nancy Chen8c066f7c2014-12-03 15:18:08 -0800734 try {
735 if (isServiceConnected()) {
Svet Ganov16a16892015-04-16 10:32:04 -0700736 return getTelecomService().getVoiceMailNumber(accountHandle,
737 mContext.getOpPackageName());
Nancy Chen8c066f7c2014-12-03 15:18:08 -0800738 }
739 } catch (RemoteException e) {
Nancy Chen5cf27842015-01-24 23:30:27 -0800740 Log.e(TAG, "RemoteException calling ITelecomService#hasVoiceMailNumber.", e);
Nancy Chen8c066f7c2014-12-03 15:18:08 -0800741 }
Yorke Lee49e2d462015-04-15 16:14:22 -0700742 return null;
Nancy Chen8c066f7c2014-12-03 15:18:08 -0800743 }
744
745 /**
Nancy Chen5cf27842015-01-24 23:30:27 -0800746 * Return the line 1 phone number for given phone account.
747 *
748 * @param accountHandle The handle for the account retrieve a number for.
749 * @return A string representation of the line 1 phone number.
Nancy Chen5cf27842015-01-24 23:30:27 -0800750 */
Nancy Chen5cf27842015-01-24 23:30:27 -0800751 public String getLine1Number(PhoneAccountHandle accountHandle) {
752 try {
753 if (isServiceConnected()) {
Svet Ganov16a16892015-04-16 10:32:04 -0700754 return getTelecomService().getLine1Number(accountHandle,
755 mContext.getOpPackageName());
Nancy Chen5cf27842015-01-24 23:30:27 -0800756 }
757 } catch (RemoteException e) {
758 Log.e(TAG, "RemoteException calling ITelecomService#getLine1Number.", e);
759 }
760 return null;
761 }
762
763 /**
Santos Cordon9eb45932014-06-27 12:28:43 -0700764 * Returns whether there is an ongoing phone call (can be in dialing, ringing, active or holding
765 * states).
Nancy Chen0eb1e402014-08-21 22:52:29 -0700766 * <p>
767 * Requires permission: {@link android.Manifest.permission#READ_PHONE_STATE}
768 * </p>
Santos Cordon9eb45932014-06-27 12:28:43 -0700769 */
Nancy Chen0eb1e402014-08-21 22:52:29 -0700770 public boolean isInCall() {
Santos Cordon9eb45932014-06-27 12:28:43 -0700771 try {
772 if (isServiceConnected()) {
Svet Ganov16a16892015-04-16 10:32:04 -0700773 return getTelecomService().isInCall(mContext.getOpPackageName());
Santos Cordon9eb45932014-06-27 12:28:43 -0700774 }
775 } catch (RemoteException e) {
Yorke Lee2ae312e2014-09-12 17:58:48 -0700776 Log.e(TAG, "RemoteException calling isInCall().", e);
Santos Cordon9eb45932014-06-27 12:28:43 -0700777 }
778 return false;
779 }
780
781 /**
Yorke Lee2ae312e2014-09-12 17:58:48 -0700782 * Returns one of the following constants that represents the current state of Telecom:
783 *
784 * {@link TelephonyManager#CALL_STATE_RINGING}
785 * {@link TelephonyManager#CALL_STATE_OFFHOOK}
786 * {@link TelephonyManager#CALL_STATE_IDLE}
Yorke Lee7c72c2d2014-10-28 14:12:02 -0700787 *
788 * Note that this API does not require the
789 * {@link android.Manifest.permission#READ_PHONE_STATE} permission. This is intentional, to
790 * preserve the behavior of {@link TelephonyManager#getCallState()}, which also did not require
791 * the permission.
Yorke Lee2ae312e2014-09-12 17:58:48 -0700792 * @hide
793 */
794 @SystemApi
795 public int getCallState() {
796 try {
797 if (isServiceConnected()) {
798 return getTelecomService().getCallState();
799 }
800 } catch (RemoteException e) {
801 Log.d(TAG, "RemoteException calling getCallState().", e);
802 }
803 return TelephonyManager.CALL_STATE_IDLE;
804 }
805
806 /**
Santos Cordon9eb45932014-06-27 12:28:43 -0700807 * Returns whether there currently exists is a ringing incoming-call.
808 *
809 * @hide
810 */
811 @SystemApi
812 public boolean isRinging() {
813 try {
814 if (isServiceConnected()) {
Svet Ganov16a16892015-04-16 10:32:04 -0700815 return getTelecomService().isRinging(mContext.getOpPackageName());
Santos Cordon9eb45932014-06-27 12:28:43 -0700816 }
817 } catch (RemoteException e) {
818 Log.e(TAG, "RemoteException attempting to get ringing state of phone app.", e);
819 }
820 return false;
821 }
822
823 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700824 * Ends an ongoing call.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700825 * TODO: L-release - need to convert all invocations of ITelecomService#endCall to use this
Santos Cordon96efb482014-07-19 14:57:05 -0700826 * method (clockwork & gearhead).
Santos Cordon9eb45932014-06-27 12:28:43 -0700827 * @hide
828 */
829 @SystemApi
830 public boolean endCall() {
831 try {
832 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700833 return getTelecomService().endCall();
Santos Cordon9eb45932014-06-27 12:28:43 -0700834 }
835 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700836 Log.e(TAG, "Error calling ITelecomService#endCall", e);
Santos Cordon9eb45932014-06-27 12:28:43 -0700837 }
838 return false;
839 }
840
841 /**
842 * If there is a ringing incoming call, this method accepts the call on behalf of the user.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700843 * TODO: L-release - need to convert all invocation of ITelecmmService#answerRingingCall to use
Santos Cordon96efb482014-07-19 14:57:05 -0700844 * this method (clockwork & gearhead).
Santos Cordon9eb45932014-06-27 12:28:43 -0700845 *
846 * @hide
847 */
848 @SystemApi
849 public void acceptRingingCall() {
850 try {
851 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700852 getTelecomService().acceptRingingCall();
Santos Cordon9eb45932014-06-27 12:28:43 -0700853 }
854 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700855 Log.e(TAG, "Error calling ITelecomService#acceptRingingCall", e);
Santos Cordon9eb45932014-06-27 12:28:43 -0700856 }
857 }
858
859 /**
860 * Silences the ringer if a ringing call exists.
Santos Cordon9eb45932014-06-27 12:28:43 -0700861 */
Santos Cordon9eb45932014-06-27 12:28:43 -0700862 public void silenceRinger() {
863 try {
864 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700865 getTelecomService().silenceRinger();
Santos Cordon9eb45932014-06-27 12:28:43 -0700866 }
867 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700868 Log.e(TAG, "Error calling ITelecomService#silenceRinger", e);
Santos Cordon9eb45932014-06-27 12:28:43 -0700869 }
870 }
871
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700872 /**
873 * Returns whether TTY is supported on this device.
874 *
875 * @hide
876 */
877 @SystemApi
878 public boolean isTtySupported() {
879 try {
880 if (isServiceConnected()) {
Svet Ganov16a16892015-04-16 10:32:04 -0700881 return getTelecomService().isTtySupported(mContext.getOpPackageName());
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700882 }
883 } catch (RemoteException e) {
884 Log.e(TAG, "RemoteException attempting to get TTY supported state.", e);
885 }
886 return false;
887 }
888
889 /**
890 * 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 -0700891 * settings and have a wired headset plugged in.
892 * Valid modes are:
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700893 * - {@link TelecomManager#TTY_MODE_OFF}
894 * - {@link TelecomManager#TTY_MODE_FULL}
895 * - {@link TelecomManager#TTY_MODE_HCO}
896 * - {@link TelecomManager#TTY_MODE_VCO}
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700897 * @hide
898 */
899 public int getCurrentTtyMode() {
900 try {
901 if (isServiceConnected()) {
Svet Ganov16a16892015-04-16 10:32:04 -0700902 return getTelecomService().getCurrentTtyMode(mContext.getOpPackageName());
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700903 }
904 } catch (RemoteException e) {
905 Log.e(TAG, "RemoteException attempting to get the current TTY mode.", e);
906 }
Evan Charlton10197192014-07-19 15:00:29 -0700907 return TTY_MODE_OFF;
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700908 }
909
Santos Cordon96efb482014-07-19 14:57:05 -0700910 /**
911 * Registers a new incoming call. A {@link ConnectionService} should invoke this method when it
912 * has an incoming call. The specified {@link PhoneAccountHandle} must have been registered
Nancy Chen210ef032014-09-15 17:58:42 -0700913 * with {@link #registerPhoneAccount}. Once invoked, this method will cause the system to bind
914 * to the {@link ConnectionService} associated with the {@link PhoneAccountHandle} and request
Santos Cordon96efb482014-07-19 14:57:05 -0700915 * additional information about the call (See
916 * {@link ConnectionService#onCreateIncomingConnection}) before starting the incoming call UI.
917 *
918 * @param phoneAccount A {@link PhoneAccountHandle} registered with
919 * {@link #registerPhoneAccount}.
920 * @param extras A bundle that will be passed through to
921 * {@link ConnectionService#onCreateIncomingConnection}.
922 */
923 public void addNewIncomingCall(PhoneAccountHandle phoneAccount, Bundle extras) {
924 try {
925 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700926 getTelecomService().addNewIncomingCall(
Santos Cordon96efb482014-07-19 14:57:05 -0700927 phoneAccount, extras == null ? new Bundle() : extras);
928 }
929 } catch (RemoteException e) {
930 Log.e(TAG, "RemoteException adding a new incoming call: " + phoneAccount, e);
931 }
932 }
933
Nancy Chen0eb1e402014-08-21 22:52:29 -0700934 /**
Yorke Leec3cf9822014-10-02 09:38:39 -0700935 * Registers a new unknown call with Telecom. This can only be called by the system Telephony
936 * service. This is invoked when Telephony detects a new unknown connection that was neither
937 * a new incoming call, nor an user-initiated outgoing call.
938 *
939 * @param phoneAccount A {@link PhoneAccountHandle} registered with
940 * {@link #registerPhoneAccount}.
941 * @param extras A bundle that will be passed through to
942 * {@link ConnectionService#onCreateIncomingConnection}.
943 * @hide
944 */
945 @SystemApi
946 public void addNewUnknownCall(PhoneAccountHandle phoneAccount, Bundle extras) {
947 try {
948 if (isServiceConnected()) {
949 getTelecomService().addNewUnknownCall(
950 phoneAccount, extras == null ? new Bundle() : extras);
951 }
952 } catch (RemoteException e) {
953 Log.e(TAG, "RemoteException adding a new unknown call: " + phoneAccount, e);
954 }
955 }
956
957 /**
Nancy Chen0eb1e402014-08-21 22:52:29 -0700958 * Processes the specified dial string as an MMI code.
959 * MMI codes are any sequence of characters entered into the dialpad that contain a "*" or "#".
960 * Some of these sequences launch special behavior through handled by Telephony.
Nancy Chen95e8a672014-10-16 18:38:21 -0700961 * This method uses the default subscription.
Nancy Chen0eb1e402014-08-21 22:52:29 -0700962 * <p>
963 * Requires that the method-caller be set as the system dialer app.
964 * </p>
965 *
966 * @param dialString The digits to dial.
967 * @return True if the digits were processed as an MMI code, false otherwise.
968 */
969 public boolean handleMmi(String dialString) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700970 ITelecomService service = getTelecomService();
Nancy Chen0eb1e402014-08-21 22:52:29 -0700971 if (service != null) {
972 try {
973 return service.handlePinMmi(dialString);
974 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700975 Log.e(TAG, "Error calling ITelecomService#handlePinMmi", e);
Nancy Chen0eb1e402014-08-21 22:52:29 -0700976 }
977 }
978 return false;
979 }
980
981 /**
Nancy Chen95e8a672014-10-16 18:38:21 -0700982 * Processes the specified dial string as an MMI code.
983 * MMI codes are any sequence of characters entered into the dialpad that contain a "*" or "#".
984 * Some of these sequences launch special behavior through handled by Telephony.
985 * <p>
986 * Requires that the method-caller be set as the system dialer app.
987 * </p>
988 *
989 * @param accountHandle The handle for the account the MMI code should apply to.
990 * @param dialString The digits to dial.
991 * @return True if the digits were processed as an MMI code, false otherwise.
Nancy Chen95e8a672014-10-16 18:38:21 -0700992 */
Yorke Lee06044272015-04-14 15:16:59 -0700993 public boolean handleMmi(String dialString, PhoneAccountHandle accountHandle) {
Nancy Chen95e8a672014-10-16 18:38:21 -0700994 ITelecomService service = getTelecomService();
995 if (service != null) {
996 try {
997 return service.handlePinMmiForPhoneAccount(accountHandle, dialString);
998 } catch (RemoteException e) {
999 Log.e(TAG, "Error calling ITelecomService#handlePinMmi", e);
1000 }
1001 }
1002 return false;
1003 }
1004
1005 /**
Nancy Chenb2299c12014-10-29 18:22:11 -07001006 * @param accountHandle The handle for the account to derive an adn query URI for or
1007 * {@code null} to return a URI which will use the default account.
1008 * @return The URI (with the content:// scheme) specific to the specified {@link PhoneAccount}
1009 * for the the content retrieve.
1010 */
1011 public Uri getAdnUriForPhoneAccount(PhoneAccountHandle accountHandle) {
1012 ITelecomService service = getTelecomService();
1013 if (service != null && accountHandle != null) {
1014 try {
1015 return service.getAdnUriForPhoneAccount(accountHandle);
1016 } catch (RemoteException e) {
1017 Log.e(TAG, "Error calling ITelecomService#getAdnUriForPhoneAccount", e);
1018 }
1019 }
1020 return Uri.parse("content://icc/adn");
1021 }
1022
1023 /**
Nancy Chen0eb1e402014-08-21 22:52:29 -07001024 * Removes the missed-call notification if one is present.
1025 * <p>
1026 * Requires that the method-caller be set as the system dialer app.
1027 * </p>
1028 */
1029 public void cancelMissedCallsNotification() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001030 ITelecomService service = getTelecomService();
Nancy Chen0eb1e402014-08-21 22:52:29 -07001031 if (service != null) {
1032 try {
1033 service.cancelMissedCallsNotification();
1034 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001035 Log.e(TAG, "Error calling ITelecomService#cancelMissedCallsNotification", e);
Nancy Chen0eb1e402014-08-21 22:52:29 -07001036 }
1037 }
1038 }
1039
1040 /**
1041 * Brings the in-call screen to the foreground if there is an ongoing call. If there is
1042 * currently no ongoing call, then this method does nothing.
1043 * <p>
1044 * Requires that the method-caller be set as the system dialer app or have the
1045 * {@link android.Manifest.permission#READ_PHONE_STATE} permission.
1046 * </p>
1047 *
1048 * @param showDialpad Brings up the in-call dialpad as part of showing the in-call screen.
1049 */
1050 public void showInCallScreen(boolean showDialpad) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001051 ITelecomService service = getTelecomService();
Nancy Chen0eb1e402014-08-21 22:52:29 -07001052 if (service != null) {
1053 try {
Svet Ganov16a16892015-04-16 10:32:04 -07001054 service.showInCallScreen(showDialpad, mContext.getOpPackageName());
Nancy Chen0eb1e402014-08-21 22:52:29 -07001055 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001056 Log.e(TAG, "Error calling ITelecomService#showCallScreen", e);
Nancy Chen0eb1e402014-08-21 22:52:29 -07001057 }
1058 }
1059 }
1060
Yorke Lee3e56ba12015-04-23 12:32:36 -07001061 /**
1062 * Places a new outgoing call to the provided address using the system telecom service with
1063 * the specified extras.
1064 *
1065 * This method is equivalent to placing an outgoing call using {@link Intent#ACTION_CALL},
1066 * except that the outgoing call will always be sent via the system telecom service. If
1067 * method-caller is either the user selected default dialer app or preloaded system dialer
1068 * app, then emergency calls will also be allowed.
1069 *
1070 * Requires permission: {@link android.Manifest.permission#CALL_PHONE}
1071 *
1072 * Usage example:
1073 * <pre>
1074 * Uri uri = Uri.fromParts("tel", "12345", null);
1075 * Bundle extras = new Bundle();
1076 * extras.putBoolean(TelecomManager.EXTRA_START_CALL_WITH_SPEAKERPHONE, true);
1077 * telecomManager.placeCall(uri, extras);
1078 * </pre>
1079 *
1080 * @param address The address to make the call to.
1081 * @param extras Bundle of extras to use with the call.
1082 */
1083 public void placeCall(Uri address, Bundle extras) {
1084 ITelecomService service = getTelecomService();
1085 if (service != null) {
1086 try {
1087 service.placeCall(address, extras, mContext.getOpPackageName());
1088 } catch (RemoteException e) {
1089 Log.e(TAG, "Error calling ITelecomService#placeCall", e);
1090 }
1091 }
1092 }
1093
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001094 private ITelecomService getTelecomService() {
1095 return ITelecomService.Stub.asInterface(ServiceManager.getService(Context.TELECOM_SERVICE));
Santos Cordon6c7a3882014-06-25 15:30:08 -07001096 }
Santos Cordon9eb45932014-06-27 12:28:43 -07001097
1098 private boolean isServiceConnected() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001099 boolean isConnected = getTelecomService() != null;
Santos Cordon9eb45932014-06-27 12:28:43 -07001100 if (!isConnected) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001101 Log.w(TAG, "Telecom Service not found.");
Santos Cordon9eb45932014-06-27 12:28:43 -07001102 }
1103 return isConnected;
1104 }
Evan Charlton235c1592014-09-05 15:41:23 +00001105}