blob: b07b018f5a19c800006f8d689d47c6538f9c6785 [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 /**
Santos Cordon895d4b82015-06-25 16:41:48 -070070 * An {@link android.content.Intent} action sent by the telecom framework to start a
71 * configuration dialog for a registered {@link PhoneAccount}. There is no default dialog
72 * and each app that registers a {@link PhoneAccount} should provide one if desired.
73 * <p>
74 * A user can access the list of enabled {@link android.telecom.PhoneAccount}s through the Phone
75 * app's settings menu. For each entry, the settings app will add a click action. When
76 * triggered, the click-action will start this intent along with the extra
77 * {@link #EXTRA_PHONE_ACCOUNT_HANDLE} to indicate the {@link PhoneAccount} to configure. If the
78 * {@link PhoneAccount} package does not register an {@link android.app.Activity} for this
79 * intent, then it will not be sent.
Evan Charlton10197192014-07-19 15:00:29 -070080 */
Santos Cordon895d4b82015-06-25 16:41:48 -070081 public static final String ACTION_CONFIGURE_PHONE_ACCOUNT =
82 "android.telecom.action.CONFIGURE_PHONE_ACCOUNT";
Evan Charlton10197192014-07-19 15:00:29 -070083
84 /**
Andrew Lee873cfbf2015-02-26 15:22:00 -080085 * The {@link android.content.Intent} action used to show the call accessibility settings page.
86 */
87 public static final String ACTION_SHOW_CALL_ACCESSIBILITY_SETTINGS =
88 "android.telecom.action.SHOW_CALL_ACCESSIBILITY_SETTINGS";
89
90 /**
Yorke Lee3818a8922014-07-21 15:57:17 -070091 * The {@link android.content.Intent} action used to show the call settings page.
92 */
93 public static final String ACTION_SHOW_CALL_SETTINGS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -070094 "android.telecom.action.SHOW_CALL_SETTINGS";
Yorke Lee3818a8922014-07-21 15:57:17 -070095
96 /**
Andrew Lee866080f2015-02-19 12:05:33 -080097 * The {@link android.content.Intent} action used to show the respond via SMS settings page.
98 */
99 public static final String ACTION_SHOW_RESPOND_VIA_SMS_SETTINGS =
100 "android.telecom.action.SHOW_RESPOND_VIA_SMS_SETTINGS";
101
102 /**
Evan Charlton6d8604f2014-09-04 12:38:17 -0700103 * The {@link android.content.Intent} action used to show the settings page used to configure
104 * {@link PhoneAccount} preferences.
105 */
106 public static final String ACTION_CHANGE_PHONE_ACCOUNTS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700107 "android.telecom.action.CHANGE_PHONE_ACCOUNTS";
Evan Charlton6d8604f2014-09-04 12:38:17 -0700108
109 /**
Santos Cordonc66f3ba2015-02-27 15:22:07 -0800110 * The {@link android.content.Intent} action used indicate that a new phone account was
111 * just registered.
112 * @hide
113 */
114 @SystemApi
115 public static final String ACTION_PHONE_ACCOUNT_REGISTERED =
116 "android.telecom.action.PHONE_ACCOUNT_REGISTERED";
117
118 /**
Bryce Lee30b0aa02015-09-23 21:53:53 -0700119 * The {@link android.content.Intent} action used indicate that a phone account was
120 * just unregistered.
121 * @hide
122 */
123 @SystemApi
124 public static final String ACTION_PHONE_ACCOUNT_UNREGISTERED =
125 "android.telecom.action.PHONE_ACCOUNT_UNREGISTERED";
126
127 /**
Yorke Lee1011f482015-04-23 15:58:27 -0700128 * Activity action: Shows a dialog asking the user whether or not they want to replace the
129 * current default Dialer with the one specified in
130 * {@link #EXTRA_CHANGE_DEFAULT_DIALER_PACKAGE_NAME}.
131 *
132 * Usage example:
133 * <pre>
134 * Intent intent = new Intent(TelecomManager.ACTION_CHANGE_DEFAULT_DIALER);
135 * intent.putExtra(TelecomManager.EXTRA_CHANGE_DEFAULT_DIALER_PACKAGE_NAME,
136 * getActivity().getPackageName());
137 * startActivity(intent);
138 * </pre>
139 */
140 public static final String ACTION_CHANGE_DEFAULT_DIALER =
141 "android.telecom.action.CHANGE_DEFAULT_DIALER";
142
143 /**
Yorke Lee107c4ce2015-06-15 12:08:24 -0700144 * Broadcast intent action indicating that the current default dialer has changed.
145 * The string extra {@link #EXTRA_CHANGE_DEFAULT_DIALER_PACKAGE_NAME} will contain the
146 * name of the package that the default dialer was changed to.
147 *
148 * @see #EXTRA_CHANGE_DEFAULT_DIALER_PACKAGE_NAME
149 */
150 public static final String ACTION_DEFAULT_DIALER_CHANGED =
151 "android.telecom.action.DEFAULT_DIALER_CHANGED";
152
153 /**
Yorke Lee1011f482015-04-23 15:58:27 -0700154 * Extra value used to provide the package name for {@link #ACTION_CHANGE_DEFAULT_DIALER}.
155 */
156 public static final String EXTRA_CHANGE_DEFAULT_DIALER_PACKAGE_NAME =
157 "android.telecom.extra.CHANGE_DEFAULT_DIALER_PACKAGE_NAME";
158
159 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700160 * Optional extra for {@link android.content.Intent#ACTION_CALL} containing a boolean that
161 * determines whether the speakerphone should be automatically turned on for an outgoing call.
Evan Charlton10197192014-07-19 15:00:29 -0700162 */
163 public static final String EXTRA_START_CALL_WITH_SPEAKERPHONE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700164 "android.telecom.extra.START_CALL_WITH_SPEAKERPHONE";
Evan Charlton10197192014-07-19 15:00:29 -0700165
166 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700167 * Optional extra for {@link android.content.Intent#ACTION_CALL} containing an integer that
168 * determines the desired video state for an outgoing call.
Santos Cordon96efb482014-07-19 14:57:05 -0700169 * Valid options:
Yorke Lee32f24732015-05-12 16:18:03 -0700170 * {@link VideoProfile#STATE_AUDIO_ONLY},
171 * {@link VideoProfile#STATE_BIDIRECTIONAL},
172 * {@link VideoProfile#STATE_RX_ENABLED},
173 * {@link VideoProfile#STATE_TX_ENABLED}.
Evan Charlton10197192014-07-19 15:00:29 -0700174 */
175 public static final String EXTRA_START_CALL_WITH_VIDEO_STATE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700176 "android.telecom.extra.START_CALL_WITH_VIDEO_STATE";
Evan Charlton10197192014-07-19 15:00:29 -0700177
178 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700179 * The extra used with an {@link android.content.Intent#ACTION_CALL} and
180 * {@link android.content.Intent#ACTION_DIAL} {@code Intent} to specify a
181 * {@link PhoneAccountHandle} to use when making the call.
Evan Charlton10197192014-07-19 15:00:29 -0700182 * <p class="note">
Santos Cordon96efb482014-07-19 14:57:05 -0700183 * Retrieve with {@link android.content.Intent#getParcelableExtra(String)}.
Evan Charlton10197192014-07-19 15:00:29 -0700184 */
Evan Charlton6eb262c2014-07-19 18:18:19 -0700185 public static final String EXTRA_PHONE_ACCOUNT_HANDLE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700186 "android.telecom.extra.PHONE_ACCOUNT_HANDLE";
Evan Charlton10197192014-07-19 15:00:29 -0700187
188 /**
Tyler Gunn335ff2e2015-07-30 14:18:33 -0700189 * Optional extra for {@link android.content.Intent#ACTION_CALL} containing a string call
190 * subject which will be associated with an outgoing call. Should only be specified if the
191 * {@link PhoneAccount} supports the capability {@link PhoneAccount#CAPABILITY_CALL_SUBJECT}.
192 */
193 public static final String EXTRA_CALL_SUBJECT = "android.telecom.extra.CALL_SUBJECT";
194
195 /**
Yorke Lee04ea7d32015-06-05 15:59:18 -0700196 * The extra used by a {@link ConnectionService} to provide the handle of the caller that
197 * has initiated a new incoming call.
198 */
Yorke Lee02fb5bc2015-06-09 12:27:36 -0700199 public static final String EXTRA_INCOMING_CALL_ADDRESS =
200 "android.telecom.extra.INCOMING_CALL_ADDRESS";
Yorke Lee04ea7d32015-06-05 15:59:18 -0700201
202 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700203 * Optional extra for {@link #ACTION_INCOMING_CALL} containing a {@link Bundle} which contains
204 * metadata about the call. This {@link Bundle} will be returned to the
205 * {@link ConnectionService}.
Evan Charlton10197192014-07-19 15:00:29 -0700206 */
207 public static final String EXTRA_INCOMING_CALL_EXTRAS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700208 "android.telecom.extra.INCOMING_CALL_EXTRAS";
Evan Charlton10197192014-07-19 15:00:29 -0700209
210 /**
Nancy Chen10798dc2014-08-08 14:00:25 -0700211 * Optional extra for {@link android.content.Intent#ACTION_CALL} and
212 * {@link android.content.Intent#ACTION_DIAL} {@code Intent} containing a {@link Bundle}
213 * which contains metadata about the call. This {@link Bundle} will be saved into
Santos Cordon7a060d52015-06-19 14:52:04 -0700214 * {@code Call.Details} and passed to the {@link ConnectionService} when placing the call.
Nancy Chen10798dc2014-08-08 14:00:25 -0700215 */
216 public static final String EXTRA_OUTGOING_CALL_EXTRAS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700217 "android.telecom.extra.OUTGOING_CALL_EXTRAS";
Nancy Chen10798dc2014-08-08 14:00:25 -0700218
219 /**
Yorke Leec3cf9822014-10-02 09:38:39 -0700220 * @hide
221 */
222 public static final String EXTRA_UNKNOWN_CALL_HANDLE =
223 "android.telecom.extra.UNKNOWN_CALL_HANDLE";
224
225 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700226 * Optional extra for {@link android.telephony.TelephonyManager#ACTION_PHONE_STATE_CHANGED}
227 * containing the disconnect code.
Evan Charlton10197192014-07-19 15:00:29 -0700228 */
229 public static final String EXTRA_CALL_DISCONNECT_CAUSE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700230 "android.telecom.extra.CALL_DISCONNECT_CAUSE";
Evan Charlton10197192014-07-19 15:00:29 -0700231
232 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700233 * Optional extra for {@link android.telephony.TelephonyManager#ACTION_PHONE_STATE_CHANGED}
234 * containing the disconnect message.
Evan Charlton10197192014-07-19 15:00:29 -0700235 */
236 public static final String EXTRA_CALL_DISCONNECT_MESSAGE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700237 "android.telecom.extra.CALL_DISCONNECT_MESSAGE";
Evan Charlton10197192014-07-19 15:00:29 -0700238
239 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700240 * Optional extra for {@link android.telephony.TelephonyManager#ACTION_PHONE_STATE_CHANGED}
241 * containing the component name of the associated connection service.
Evan Charlton0e094d92014-11-08 15:49:16 -0800242 * @hide
Evan Charlton10197192014-07-19 15:00:29 -0700243 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800244 @SystemApi
Evan Charlton10197192014-07-19 15:00:29 -0700245 public static final String EXTRA_CONNECTION_SERVICE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700246 "android.telecom.extra.CONNECTION_SERVICE";
Evan Charlton10197192014-07-19 15:00:29 -0700247
248 /**
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700249 * An optional {@link android.content.Intent#ACTION_CALL} intent extra denoting the
250 * package name of the app specifying an alternative gateway for the call.
251 * The value is a string.
252 *
253 * (The following comment corresponds to the all GATEWAY_* extras)
254 * An app which sends the {@link android.content.Intent#ACTION_CALL} intent can specify an
255 * alternative address to dial which is different from the one specified and displayed to
256 * the user. This alternative address is referred to as the gateway address.
257 */
258 public static final String GATEWAY_PROVIDER_PACKAGE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700259 "android.telecom.extra.GATEWAY_PROVIDER_PACKAGE";
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700260
261 /**
262 * An optional {@link android.content.Intent#ACTION_CALL} intent extra corresponding to the
263 * original address to dial for the call. This is used when an alternative gateway address is
264 * provided to recall the original address.
265 * The value is a {@link android.net.Uri}.
266 *
267 * (See {@link #GATEWAY_PROVIDER_PACKAGE} for details)
268 */
269 public static final String GATEWAY_ORIGINAL_ADDRESS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700270 "android.telecom.extra.GATEWAY_ORIGINAL_ADDRESS";
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700271
272 /**
Evan Charlton10197192014-07-19 15:00:29 -0700273 * The number which the party on the other side of the line will see (and use to return the
274 * call).
275 * <p>
Santos Cordon96efb482014-07-19 14:57:05 -0700276 * {@link ConnectionService}s which interact with {@link RemoteConnection}s should only populate
277 * this if the {@link android.telephony.TelephonyManager#getLine1Number()} value, as that is the
278 * user's expected caller ID.
Evan Charlton10197192014-07-19 15:00:29 -0700279 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700280 public static final String EXTRA_CALL_BACK_NUMBER = "android.telecom.extra.CALL_BACK_NUMBER";
Evan Charlton10197192014-07-19 15:00:29 -0700281
282 /**
Santos Cordonf2600eb2015-06-22 15:02:20 -0700283 * A boolean meta-data value indicating whether an {@link InCallService} implements an
284 * in-call user interface. Dialer implementations (see {@link #getDefaultDialerPackage()}) which
285 * would also like to replace the in-call interface should set this meta-data to {@code true} in
286 * the manifest registration of their {@link InCallService}.
287 */
288 public static final String METADATA_IN_CALL_SERVICE_UI = "android.telecom.IN_CALL_SERVICE_UI";
289
290 /**
Evan Charlton10197192014-07-19 15:00:29 -0700291 * The dual tone multi-frequency signaling character sent to indicate the dialing system should
292 * pause for a predefined period.
293 */
294 public static final char DTMF_CHARACTER_PAUSE = ',';
295
296 /**
297 * The dual-tone multi-frequency signaling character sent to indicate the dialing system should
298 * wait for user confirmation before proceeding.
299 */
300 public static final char DTMF_CHARACTER_WAIT = ';';
301
302 /**
303 * TTY (teletypewriter) mode is off.
304 *
305 * @hide
306 */
307 public static final int TTY_MODE_OFF = 0;
308
309 /**
310 * TTY (teletypewriter) mode is on. The speaker is off and the microphone is muted. The user
311 * will communicate with the remote party by sending and receiving text messages.
312 *
313 * @hide
314 */
315 public static final int TTY_MODE_FULL = 1;
316
317 /**
318 * TTY (teletypewriter) mode is in hearing carryover mode (HCO). The microphone is muted but the
319 * speaker is on. The user will communicate with the remote party by sending text messages and
320 * hearing an audible reply.
321 *
322 * @hide
323 */
324 public static final int TTY_MODE_HCO = 2;
325
326 /**
327 * TTY (teletypewriter) mode is in voice carryover mode (VCO). The speaker is off but the
328 * microphone is still on. User will communicate with the remote party by speaking and receiving
329 * text message replies.
330 *
331 * @hide
332 */
333 public static final int TTY_MODE_VCO = 3;
334
335 /**
336 * Broadcast intent action indicating that the current TTY mode has changed. An intent extra
337 * provides this state as an int.
Evan Charlton10197192014-07-19 15:00:29 -0700338 *
Santos Cordon96efb482014-07-19 14:57:05 -0700339 * @see #EXTRA_CURRENT_TTY_MODE
Evan Charlton10197192014-07-19 15:00:29 -0700340 * @hide
341 */
342 public static final String ACTION_CURRENT_TTY_MODE_CHANGED =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700343 "android.telecom.action.CURRENT_TTY_MODE_CHANGED";
Evan Charlton10197192014-07-19 15:00:29 -0700344
345 /**
346 * The lookup key for an int that indicates the current TTY mode.
347 * Valid modes are:
348 * - {@link #TTY_MODE_OFF}
349 * - {@link #TTY_MODE_FULL}
350 * - {@link #TTY_MODE_HCO}
351 * - {@link #TTY_MODE_VCO}
352 *
353 * @hide
354 */
355 public static final String EXTRA_CURRENT_TTY_MODE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700356 "android.telecom.intent.extra.CURRENT_TTY_MODE";
Evan Charlton10197192014-07-19 15:00:29 -0700357
358 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700359 * Broadcast intent action indicating that the TTY preferred operating mode has changed. An
360 * intent extra provides the new mode as an int.
Evan Charlton10197192014-07-19 15:00:29 -0700361 *
Santos Cordon96efb482014-07-19 14:57:05 -0700362 * @see #EXTRA_TTY_PREFERRED_MODE
Evan Charlton10197192014-07-19 15:00:29 -0700363 * @hide
364 */
365 public static final String ACTION_TTY_PREFERRED_MODE_CHANGED =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700366 "android.telecom.action.TTY_PREFERRED_MODE_CHANGED";
Evan Charlton10197192014-07-19 15:00:29 -0700367
368 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700369 * The lookup key for an int that indicates preferred TTY mode. Valid modes are: -
370 * {@link #TTY_MODE_OFF} - {@link #TTY_MODE_FULL} - {@link #TTY_MODE_HCO} -
371 * {@link #TTY_MODE_VCO}
Evan Charlton10197192014-07-19 15:00:29 -0700372 *
373 * @hide
374 */
375 public static final String EXTRA_TTY_PREFERRED_MODE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700376 "android.telecom.intent.extra.TTY_PREFERRED";
Evan Charlton10197192014-07-19 15:00:29 -0700377
Nancy Chen9d568c02014-09-08 14:17:59 -0700378 /**
Bryce Lee5e4dd3e2015-08-03 16:59:10 -0700379 * Broadcast intent action for letting custom component know to show the missed call
380 * notification.
381 * @hide
382 */
383 @SystemApi
384 public static final String ACTION_SHOW_MISSED_CALLS_NOTIFICATION =
385 "android.telecom.action.SHOW_MISSED_CALLS_NOTIFICATION";
386
387 /**
388 * The number of calls associated with the notification.
389 * @hide
390 */
391 @SystemApi
392 public static final String EXTRA_NOTIFICATION_COUNT =
393 "android.telecom.extra.NOTIFICATION_COUNT";
394
395 /**
396 * The number associated with the missed calls. This number is only relevant
397 * when EXTRA_NOTIFICATION_COUNT is 1.
398 * @hide
399 */
400 @SystemApi
401 public static final String EXTRA_NOTIFICATION_PHONE_NUMBER =
402 "android.telecom.extra.NOTIFICATION_PHONE_NUMBER";
403
404 /**
Bryce Lee8d41d1d2015-08-10 07:40:42 -0700405 * The intent to clear missed calls.
406 * @hide
407 */
408 @SystemApi
409 public static final String EXTRA_CLEAR_MISSED_CALLS_INTENT =
410 "android.telecom.extra.CLEAR_MISSED_CALLS_INTENT";
411
412 /**
413 * The intent to call back a missed call.
414 * @hide
415 */
416 @SystemApi
417 public static final String EXTRA_CALL_BACK_INTENT =
418 "android.telecom.extra.CALL_BACK_INTENT";
419
420 /**
Nancy Chen9d568c02014-09-08 14:17:59 -0700421 * The following 4 constants define how properties such as phone numbers and names are
422 * displayed to the user.
423 */
424
Santos Cordoned769ae2015-05-13 18:47:38 -0700425 /**
426 * Indicates that the address or number of a call is allowed to be displayed for caller ID.
427 */
Nancy Chen9d568c02014-09-08 14:17:59 -0700428 public static final int PRESENTATION_ALLOWED = 1;
429
Santos Cordoned769ae2015-05-13 18:47:38 -0700430 /**
431 * Indicates that the address or number of a call is blocked by the other party.
432 */
Nancy Chen9d568c02014-09-08 14:17:59 -0700433 public static final int PRESENTATION_RESTRICTED = 2;
434
Santos Cordoned769ae2015-05-13 18:47:38 -0700435 /**
436 * Indicates that the address or number of a call is not specified or known by the carrier.
437 */
Nancy Chen9d568c02014-09-08 14:17:59 -0700438 public static final int PRESENTATION_UNKNOWN = 3;
439
Santos Cordoned769ae2015-05-13 18:47:38 -0700440 /**
441 * Indicates that the address or number of a call belongs to a pay phone.
442 */
Nancy Chen9d568c02014-09-08 14:17:59 -0700443 public static final int PRESENTATION_PAYPHONE = 4;
444
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700445 private static final String TAG = "TelecomManager";
Yorke Leeb4ce1432014-06-09 13:53:23 -0700446
447 private final Context mContext;
Yorke Leeb4ce1432014-06-09 13:53:23 -0700448
Santos Cordon6c7a3882014-06-25 15:30:08 -0700449 /**
450 * @hide
451 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700452 public static TelecomManager from(Context context) {
453 return (TelecomManager) context.getSystemService(Context.TELECOM_SERVICE);
Yorke Leeb4ce1432014-06-09 13:53:23 -0700454 }
Santos Cordon6c7a3882014-06-25 15:30:08 -0700455
456 /**
457 * @hide
458 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700459 public TelecomManager(Context context) {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700460 Context appContext = context.getApplicationContext();
461 if (appContext != null) {
462 mContext = appContext;
463 } else {
464 mContext = context;
465 }
466 }
467
468 /**
Santos Cordon91371dc02015-05-08 13:52:09 -0700469 * Return the {@link PhoneAccount} which will be used to place outgoing calls to addresses with
470 * the specified {@code uriScheme}. This {@link PhoneAccount} will always be a member of the
471 * list which is returned from invoking {@link #getCallCapablePhoneAccounts()}. The specific
472 * account returned depends on the following priorities:
473 * <ul>
474 * <li> If the user-selected default {@link PhoneAccount} supports the specified scheme, it will
475 * be returned.
476 * </li>
477 * <li> If there exists only one {@link PhoneAccount} that supports the specified scheme, it
478 * will be returned.
479 * </li>
480 * </ul>
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700481 * <p>
Santos Cordon91371dc02015-05-08 13:52:09 -0700482 * If no {@link PhoneAccount} fits the criteria above, this method will return {@code null}.
483 *
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700484 * @param uriScheme The URI scheme.
Santos Cordon91371dc02015-05-08 13:52:09 -0700485 * @return The {@link PhoneAccountHandle} corresponding to the account to be used.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700486 */
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700487 public PhoneAccountHandle getDefaultOutgoingPhoneAccount(String uriScheme) {
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700488 try {
489 if (isServiceConnected()) {
Svet Ganov16a16892015-04-16 10:32:04 -0700490 return getTelecomService().getDefaultOutgoingPhoneAccount(uriScheme,
491 mContext.getOpPackageName());
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700492 }
493 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700494 Log.e(TAG, "Error calling ITelecomService#getDefaultOutgoingPhoneAccount", e);
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700495 }
496 return null;
497 }
498
499 /**
Andrew Leed4abbfb2014-09-03 14:58:27 -0700500 * Return the {@link PhoneAccount} which is the user-chosen default for making outgoing phone
501 * calls. This {@code PhoneAccount} will always be a member of the list which is returned from
Nancy Chen210ef032014-09-15 17:58:42 -0700502 * calling {@link #getCallCapablePhoneAccounts()}
Santos Cordon91371dc02015-05-08 13:52:09 -0700503 * <p>
Andrew Leed4abbfb2014-09-03 14:58:27 -0700504 * Apps must be prepared for this method to return {@code null}, indicating that there currently
505 * exists no user-chosen default {@code PhoneAccount}.
506 *
507 * @return The user outgoing phone account selected by the user.
Jay Shrauner225ccad2015-04-15 15:51:15 -0700508 * @hide
Andrew Leed4abbfb2014-09-03 14:58:27 -0700509 */
510 public PhoneAccountHandle getUserSelectedOutgoingPhoneAccount() {
511 try {
512 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700513 return getTelecomService().getUserSelectedOutgoingPhoneAccount();
Andrew Leed4abbfb2014-09-03 14:58:27 -0700514 }
515 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700516 Log.e(TAG, "Error calling ITelecomService#getUserSelectedOutgoingPhoneAccount", e);
Andrew Leed4abbfb2014-09-03 14:58:27 -0700517 }
518 return null;
519 }
520
521 /**
Santos Cordon91371dc02015-05-08 13:52:09 -0700522 * Sets the user-chosen default for making outgoing phone calls.
Andrew Lee59cac3a2014-08-28 16:50:10 -0700523 * @hide
524 */
Andrew Leed4abbfb2014-09-03 14:58:27 -0700525 public void setUserSelectedOutgoingPhoneAccount(PhoneAccountHandle accountHandle) {
Andrew Lee59cac3a2014-08-28 16:50:10 -0700526 try {
527 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700528 getTelecomService().setUserSelectedOutgoingPhoneAccount(accountHandle);
Andrew Lee59cac3a2014-08-28 16:50:10 -0700529 }
530 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700531 Log.e(TAG, "Error calling ITelecomService#setUserSelectedOutgoingPhoneAccount");
Andrew Lee59cac3a2014-08-28 16:50:10 -0700532 }
533 }
534
535 /**
Andrew Lee59cac3a2014-08-28 16:50:10 -0700536 * Returns the current SIM call manager. Apps must be prepared for this method to return
537 * {@code null}, indicating that there currently exists no user-chosen default
538 * {@code PhoneAccount}.
Santos Cordon91371dc02015-05-08 13:52:09 -0700539 *
Andrew Lee59cac3a2014-08-28 16:50:10 -0700540 * @return The phone account handle of the current sim call manager.
Andrew Lee59cac3a2014-08-28 16:50:10 -0700541 */
542 public PhoneAccountHandle getSimCallManager() {
543 try {
544 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700545 return getTelecomService().getSimCallManager();
Andrew Lee59cac3a2014-08-28 16:50:10 -0700546 }
547 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700548 Log.e(TAG, "Error calling ITelecomService#getSimCallManager");
Andrew Lee59cac3a2014-08-28 16:50:10 -0700549 }
550 return null;
551 }
552
553 /**
Sailesh Nepalcf855622015-07-28 19:22:14 -0700554 * Returns the current SIM call manager for the specified user. Apps must be prepared for this
555 * method to return {@code null}, indicating that there currently exists no user-chosen default
556 * {@code PhoneAccount}.
557 *
558 * @return The phone account handle of the current sim call manager.
559 *
560 * @hide
561 */
562 public PhoneAccountHandle getSimCallManager(int userId) {
563 try {
564 if (isServiceConnected()) {
565 return getTelecomService().getSimCallManagerForUser(userId);
566 }
567 } catch (RemoteException e) {
568 Log.e(TAG, "Error calling ITelecomService#getSimCallManagerForUser");
569 }
570 return null;
571 }
572
573 /**
Evan Charltoneb0a8d562014-09-04 12:03:34 -0700574 * Returns the current connection manager. Apps must be prepared for this method to return
575 * {@code null}, indicating that there currently exists no user-chosen default
576 * {@code PhoneAccount}.
577 *
578 * @return The phone account handle of the current connection manager.
Evan Charlton0e094d92014-11-08 15:49:16 -0800579 * @hide
Evan Charltoneb0a8d562014-09-04 12:03:34 -0700580 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800581 @SystemApi
Evan Charltoneb0a8d562014-09-04 12:03:34 -0700582 public PhoneAccountHandle getConnectionManager() {
583 return getSimCallManager();
584 }
585
586 /**
Nancy Chen210ef032014-09-15 17:58:42 -0700587 * Returns a list of the {@link PhoneAccountHandle}s which can be used to make and receive phone
588 * calls which support the specified URI scheme.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700589 * <P>
590 * For example, invoking with {@code "tel"} will find all {@link PhoneAccountHandle}s which
591 * support telephone calls (e.g. URIs such as {@code tel:555-555-1212}). Invoking with
592 * {@code "sip"} will find all {@link PhoneAccountHandle}s which support SIP calls (e.g. URIs
593 * such as {@code sip:example@sipexample.com}).
594 *
595 * @param uriScheme The URI scheme.
596 * @return A list of {@code PhoneAccountHandle} objects supporting the URI scheme.
Evan Charlton0e094d92014-11-08 15:49:16 -0800597 * @hide
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700598 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800599 @SystemApi
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700600 public List<PhoneAccountHandle> getPhoneAccountsSupportingScheme(String uriScheme) {
601 try {
602 if (isServiceConnected()) {
Svet Ganov16a16892015-04-16 10:32:04 -0700603 return getTelecomService().getPhoneAccountsSupportingScheme(uriScheme,
604 mContext.getOpPackageName());
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700605 }
606 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700607 Log.e(TAG, "Error calling ITelecomService#getPhoneAccountsSupportingScheme", e);
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700608 }
609 return new ArrayList<>();
610 }
611
Nancy Chen513c8922014-09-17 14:47:20 -0700612
613 /**
Santos Cordon91371dc02015-05-08 13:52:09 -0700614 * Returns a list of {@link PhoneAccountHandle}s which can be used to make and receive phone
615 * calls. The returned list includes only those accounts which have been explicitly enabled
616 * by the user.
Nancy Chen513c8922014-09-17 14:47:20 -0700617 *
618 * @see #EXTRA_PHONE_ACCOUNT_HANDLE
619 * @return A list of {@code PhoneAccountHandle} objects.
Nancy Chen513c8922014-09-17 14:47:20 -0700620 */
621 public List<PhoneAccountHandle> getCallCapablePhoneAccounts() {
Santos Cordon91371dc02015-05-08 13:52:09 -0700622 return getCallCapablePhoneAccounts(false);
623 }
624
625 /**
626 * Returns a list of {@link PhoneAccountHandle}s including those which have not been enabled
627 * by the user.
628 *
629 * @return A list of {@code PhoneAccountHandle} objects.
630 * @hide
631 */
632 public List<PhoneAccountHandle> getCallCapablePhoneAccounts(boolean includeDisabledAccounts) {
Nancy Chen513c8922014-09-17 14:47:20 -0700633 try {
634 if (isServiceConnected()) {
Santos Cordon91371dc02015-05-08 13:52:09 -0700635 return getTelecomService().getCallCapablePhoneAccounts(
636 includeDisabledAccounts, mContext.getOpPackageName());
Nancy Chen513c8922014-09-17 14:47:20 -0700637 }
638 } catch (RemoteException e) {
Santos Cordon91371dc02015-05-08 13:52:09 -0700639 Log.e(TAG, "Error calling ITelecomService#getCallCapablePhoneAccounts(" +
640 includeDisabledAccounts + ")", e);
Nancy Chen513c8922014-09-17 14:47:20 -0700641 }
642 return new ArrayList<>();
643 }
644
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700645 /**
Nancy Chen513c8922014-09-17 14:47:20 -0700646 * Returns a list of all {@link PhoneAccount}s registered for the calling package.
647 *
648 * @return A list of {@code PhoneAccountHandle} objects.
Evan Charlton0e094d92014-11-08 15:49:16 -0800649 * @hide
Nancy Chen513c8922014-09-17 14:47:20 -0700650 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800651 @SystemApi
Nancy Chen513c8922014-09-17 14:47:20 -0700652 public List<PhoneAccountHandle> getPhoneAccountsForPackage() {
653 try {
654 if (isServiceConnected()) {
655 return getTelecomService().getPhoneAccountsForPackage(mContext.getPackageName());
656 }
657 } catch (RemoteException e) {
658 Log.e(TAG, "Error calling ITelecomService#getPhoneAccountsForPackage", e);
659 }
660 return null;
661 }
662
663 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700664 * Return the {@link PhoneAccount} for a specified {@link PhoneAccountHandle}. Object includes
665 * resources which can be used in a user interface.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700666 *
Evan Charlton6eb262c2014-07-19 18:18:19 -0700667 * @param account The {@link PhoneAccountHandle}.
Evan Charlton8c8a0622014-07-20 12:31:00 -0700668 * @return The {@link PhoneAccount} object.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700669 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700670 public PhoneAccount getPhoneAccount(PhoneAccountHandle account) {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700671 try {
672 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700673 return getTelecomService().getPhoneAccount(account);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700674 }
675 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700676 Log.e(TAG, "Error calling ITelecomService#getPhoneAccount", e);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700677 }
678 return null;
679 }
680
681 /**
Nancy Chen210ef032014-09-15 17:58:42 -0700682 * Returns a count of all {@link PhoneAccount}s.
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700683 *
Nancy Chen210ef032014-09-15 17:58:42 -0700684 * @return The count of {@link PhoneAccount}s.
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700685 * @hide
686 */
687 @SystemApi
688 public int getAllPhoneAccountsCount() {
689 try {
690 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700691 return getTelecomService().getAllPhoneAccountsCount();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700692 }
693 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700694 Log.e(TAG, "Error calling ITelecomService#getAllPhoneAccountsCount", e);
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700695 }
696 return 0;
697 }
698
699 /**
700 * Returns a list of all {@link PhoneAccount}s.
701 *
702 * @return All {@link PhoneAccount}s.
703 * @hide
704 */
705 @SystemApi
706 public List<PhoneAccount> getAllPhoneAccounts() {
707 try {
708 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700709 return getTelecomService().getAllPhoneAccounts();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700710 }
711 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700712 Log.e(TAG, "Error calling ITelecomService#getAllPhoneAccounts", e);
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700713 }
714 return Collections.EMPTY_LIST;
715 }
716
717 /**
718 * Returns a list of all {@link PhoneAccountHandle}s.
719 *
720 * @return All {@link PhoneAccountHandle}s.
721 * @hide
722 */
723 @SystemApi
724 public List<PhoneAccountHandle> getAllPhoneAccountHandles() {
725 try {
726 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700727 return getTelecomService().getAllPhoneAccountHandles();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700728 }
729 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700730 Log.e(TAG, "Error calling ITelecomService#getAllPhoneAccountHandles", e);
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700731 }
732 return Collections.EMPTY_LIST;
733 }
734
735 /**
Santos Cordond9e614f2014-10-28 13:10:36 -0700736 * Register a {@link PhoneAccount} for use by the system. When registering
737 * {@link PhoneAccount}s, existing registrations will be overwritten if the
738 * {@link PhoneAccountHandle} matches that of a {@link PhoneAccount} which is already
739 * registered. Once registered, the {@link PhoneAccount} is listed to the user as an option
740 * when placing calls. The user may still need to enable the {@link PhoneAccount} within
741 * the phone app settings before the account is usable.
742 * <p>
743 * A {@link SecurityException} will be thrown if an app tries to register a
744 * {@link PhoneAccountHandle} where the package name specified within
745 * {@link PhoneAccountHandle#getComponentName()} does not match the package name of the app.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700746 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700747 * @param account The complete {@link PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700748 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700749 public void registerPhoneAccount(PhoneAccount account) {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700750 try {
751 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700752 getTelecomService().registerPhoneAccount(account);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700753 }
754 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700755 Log.e(TAG, "Error calling ITelecomService#registerPhoneAccount", e);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700756 }
757 }
758
759 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700760 * Remove a {@link PhoneAccount} registration from the system.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700761 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700762 * @param accountHandle A {@link PhoneAccountHandle} for the {@link PhoneAccount} to unregister.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700763 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700764 public void unregisterPhoneAccount(PhoneAccountHandle accountHandle) {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700765 try {
766 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700767 getTelecomService().unregisterPhoneAccount(accountHandle);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700768 }
769 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700770 Log.e(TAG, "Error calling ITelecomService#unregisterPhoneAccount", e);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700771 }
772 }
773
774 /**
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700775 * Remove all Accounts that belong to the calling package from the system.
Evan Charlton0e094d92014-11-08 15:49:16 -0800776 * @hide
Ihab Awad807fe0a2014-07-09 12:30:52 -0700777 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800778 @SystemApi
Yorke Lee06044272015-04-14 15:16:59 -0700779 public void clearPhoneAccounts() {
780 clearAccounts();
781 }
782 /**
783 * Remove all Accounts that belong to the calling package from the system.
784 * @deprecated Use {@link #clearPhoneAccounts()} instead.
785 * @hide
786 */
787 @SystemApi
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700788 public void clearAccounts() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700789 try {
790 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700791 getTelecomService().clearAccounts(mContext.getPackageName());
Ihab Awad807fe0a2014-07-09 12:30:52 -0700792 }
793 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700794 Log.e(TAG, "Error calling ITelecomService#clearAccounts", e);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700795 }
796 }
797
798 /**
Anthony Lee67279262014-10-27 11:28:40 -0700799 * Remove all Accounts that belong to the specified package from the system.
800 * @hide
801 */
802 public void clearAccountsForPackage(String packageName) {
803 try {
804 if (isServiceConnected() && !TextUtils.isEmpty(packageName)) {
805 getTelecomService().clearAccounts(packageName);
806 }
807 } catch (RemoteException e) {
Nancy Chen5cf27842015-01-24 23:30:27 -0800808 Log.e(TAG, "Error calling ITelecomService#clearAccountsForPackage", e);
Anthony Lee67279262014-10-27 11:28:40 -0700809 }
810 }
811
Yorke Lee1011f482015-04-23 15:58:27 -0700812
Anthony Lee67279262014-10-27 11:28:40 -0700813 /**
Yorke Lee1011f482015-04-23 15:58:27 -0700814 * @deprecated - Use {@link TelecomManager#getDefaultDialerPackage} to directly access
815 * the default dialer's package name instead.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700816 * @hide
817 */
Santos Cordon6c7a3882014-06-25 15:30:08 -0700818 @SystemApi
819 public ComponentName getDefaultPhoneApp() {
820 try {
Santos Cordon9eb45932014-06-27 12:28:43 -0700821 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700822 return getTelecomService().getDefaultPhoneApp();
Santos Cordon9eb45932014-06-27 12:28:43 -0700823 }
Santos Cordon6c7a3882014-06-25 15:30:08 -0700824 } catch (RemoteException e) {
825 Log.e(TAG, "RemoteException attempting to get the default phone app.", e);
826 }
827 return null;
828 }
829
Santos Cordon9eb45932014-06-27 12:28:43 -0700830 /**
Yorke Lee1011f482015-04-23 15:58:27 -0700831 * Used to determine the currently selected default dialer package.
832 *
833 * @return package name for the default dialer package or null if no package has been
834 * selected as the default dialer.
835 */
836 public String getDefaultDialerPackage() {
837 try {
838 if (isServiceConnected()) {
839 return getTelecomService().getDefaultDialerPackage();
840 }
841 } catch (RemoteException e) {
842 Log.e(TAG, "RemoteException attempting to get the default dialer package name.", e);
843 }
844 return null;
845 }
846
847 /**
Yorke Lee107c4ce2015-06-15 12:08:24 -0700848 * Used to set the default dialer package.
849 *
850 * @param packageName to set the default dialer to..
851 *
852 * @result {@code true} if the default dialer was successfully changed, {@code false} if
853 * the specified package does not correspond to an installed dialer, or is already
854 * the default dialer.
855 *
856 * Requires permission: {@link android.Manifest.permission#MODIFY_PHONE_STATE}
857 * Requires permission: {@link android.Manifest.permission#WRITE_SECURE_SETTINGS}
858 *
859 * @hide
860 */
861 public boolean setDefaultDialer(String packageName) {
862 try {
863 if (isServiceConnected()) {
864 return getTelecomService().setDefaultDialer(packageName);
865 }
866 } catch (RemoteException e) {
867 Log.e(TAG, "RemoteException attempting to set the default dialer.", e);
868 }
869 return false;
870 }
871
872 /**
Yorke Lee1011f482015-04-23 15:58:27 -0700873 * Used to determine the dialer package that is preloaded on the system partition.
874 *
875 * @return package name for the system dialer package or null if no system dialer is preloaded.
876 * @hide
877 */
878 public String getSystemDialerPackage() {
879 try {
880 if (isServiceConnected()) {
881 return getTelecomService().getSystemDialerPackage();
882 }
883 } catch (RemoteException e) {
884 Log.e(TAG, "RemoteException attempting to get the system dialer package name.", e);
885 }
886 return null;
887 }
888
889 /**
Nancy Chen443e5012014-10-15 15:48:21 -0700890 * Return whether a given phone number is the configured voicemail number for a
891 * particular phone account.
892 *
893 * @param accountHandle The handle for the account to check the voicemail number against
894 * @param number The number to look up.
Nancy Chen443e5012014-10-15 15:48:21 -0700895 */
Nancy Chen443e5012014-10-15 15:48:21 -0700896 public boolean isVoiceMailNumber(PhoneAccountHandle accountHandle, String number) {
897 try {
898 if (isServiceConnected()) {
Svet Ganov16a16892015-04-16 10:32:04 -0700899 return getTelecomService().isVoiceMailNumber(accountHandle, number,
900 mContext.getOpPackageName());
Nancy Chen443e5012014-10-15 15:48:21 -0700901 }
902 } catch (RemoteException e) {
Nancy Chen5cf27842015-01-24 23:30:27 -0800903 Log.e(TAG, "RemoteException calling ITelecomService#isVoiceMailNumber.", e);
Nancy Chen443e5012014-10-15 15:48:21 -0700904 }
905 return false;
906 }
907
908 /**
Yorke Lee49e2d462015-04-15 16:14:22 -0700909 * Return the voicemail number for a given phone account.
Nancy Chen8c066f7c2014-12-03 15:18:08 -0800910 *
Yorke Lee49e2d462015-04-15 16:14:22 -0700911 * @param accountHandle The handle for the phone account.
912 * @return The voicemail number for the phone account, and {@code null} if one has not been
913 * configured.
Nancy Chen8c066f7c2014-12-03 15:18:08 -0800914 */
Yorke Lee49e2d462015-04-15 16:14:22 -0700915 public String getVoiceMailNumber(PhoneAccountHandle accountHandle) {
Nancy Chen8c066f7c2014-12-03 15:18:08 -0800916 try {
917 if (isServiceConnected()) {
Svet Ganov16a16892015-04-16 10:32:04 -0700918 return getTelecomService().getVoiceMailNumber(accountHandle,
919 mContext.getOpPackageName());
Nancy Chen8c066f7c2014-12-03 15:18:08 -0800920 }
921 } catch (RemoteException e) {
Nancy Chen5cf27842015-01-24 23:30:27 -0800922 Log.e(TAG, "RemoteException calling ITelecomService#hasVoiceMailNumber.", e);
Nancy Chen8c066f7c2014-12-03 15:18:08 -0800923 }
Yorke Lee49e2d462015-04-15 16:14:22 -0700924 return null;
Nancy Chen8c066f7c2014-12-03 15:18:08 -0800925 }
926
927 /**
Nancy Chen5cf27842015-01-24 23:30:27 -0800928 * Return the line 1 phone number for given phone account.
929 *
930 * @param accountHandle The handle for the account retrieve a number for.
931 * @return A string representation of the line 1 phone number.
Nancy Chen5cf27842015-01-24 23:30:27 -0800932 */
Nancy Chen5cf27842015-01-24 23:30:27 -0800933 public String getLine1Number(PhoneAccountHandle accountHandle) {
934 try {
935 if (isServiceConnected()) {
Svet Ganov16a16892015-04-16 10:32:04 -0700936 return getTelecomService().getLine1Number(accountHandle,
937 mContext.getOpPackageName());
Nancy Chen5cf27842015-01-24 23:30:27 -0800938 }
939 } catch (RemoteException e) {
940 Log.e(TAG, "RemoteException calling ITelecomService#getLine1Number.", e);
941 }
942 return null;
943 }
944
945 /**
Santos Cordon9eb45932014-06-27 12:28:43 -0700946 * Returns whether there is an ongoing phone call (can be in dialing, ringing, active or holding
947 * states).
Nancy Chen0eb1e402014-08-21 22:52:29 -0700948 * <p>
949 * Requires permission: {@link android.Manifest.permission#READ_PHONE_STATE}
950 * </p>
Santos Cordon9eb45932014-06-27 12:28:43 -0700951 */
Nancy Chen0eb1e402014-08-21 22:52:29 -0700952 public boolean isInCall() {
Santos Cordon9eb45932014-06-27 12:28:43 -0700953 try {
954 if (isServiceConnected()) {
Svet Ganov16a16892015-04-16 10:32:04 -0700955 return getTelecomService().isInCall(mContext.getOpPackageName());
Santos Cordon9eb45932014-06-27 12:28:43 -0700956 }
957 } catch (RemoteException e) {
Yorke Lee2ae312e2014-09-12 17:58:48 -0700958 Log.e(TAG, "RemoteException calling isInCall().", e);
Santos Cordon9eb45932014-06-27 12:28:43 -0700959 }
960 return false;
961 }
962
963 /**
Yorke Lee2ae312e2014-09-12 17:58:48 -0700964 * Returns one of the following constants that represents the current state of Telecom:
965 *
966 * {@link TelephonyManager#CALL_STATE_RINGING}
967 * {@link TelephonyManager#CALL_STATE_OFFHOOK}
968 * {@link TelephonyManager#CALL_STATE_IDLE}
Yorke Lee7c72c2d2014-10-28 14:12:02 -0700969 *
970 * Note that this API does not require the
971 * {@link android.Manifest.permission#READ_PHONE_STATE} permission. This is intentional, to
972 * preserve the behavior of {@link TelephonyManager#getCallState()}, which also did not require
973 * the permission.
Yorke Lee2ae312e2014-09-12 17:58:48 -0700974 * @hide
975 */
976 @SystemApi
977 public int getCallState() {
978 try {
979 if (isServiceConnected()) {
980 return getTelecomService().getCallState();
981 }
982 } catch (RemoteException e) {
983 Log.d(TAG, "RemoteException calling getCallState().", e);
984 }
985 return TelephonyManager.CALL_STATE_IDLE;
986 }
987
988 /**
Santos Cordon9eb45932014-06-27 12:28:43 -0700989 * Returns whether there currently exists is a ringing incoming-call.
990 *
991 * @hide
992 */
993 @SystemApi
994 public boolean isRinging() {
995 try {
996 if (isServiceConnected()) {
Svet Ganov16a16892015-04-16 10:32:04 -0700997 return getTelecomService().isRinging(mContext.getOpPackageName());
Santos Cordon9eb45932014-06-27 12:28:43 -0700998 }
999 } catch (RemoteException e) {
1000 Log.e(TAG, "RemoteException attempting to get ringing state of phone app.", e);
1001 }
1002 return false;
1003 }
1004
1005 /**
Santos Cordon96efb482014-07-19 14:57:05 -07001006 * Ends an ongoing call.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001007 * TODO: L-release - need to convert all invocations of ITelecomService#endCall to use this
Santos Cordon96efb482014-07-19 14:57:05 -07001008 * method (clockwork & gearhead).
Santos Cordon9eb45932014-06-27 12:28:43 -07001009 * @hide
1010 */
1011 @SystemApi
1012 public boolean endCall() {
1013 try {
1014 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001015 return getTelecomService().endCall();
Santos Cordon9eb45932014-06-27 12:28:43 -07001016 }
1017 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001018 Log.e(TAG, "Error calling ITelecomService#endCall", e);
Santos Cordon9eb45932014-06-27 12:28:43 -07001019 }
1020 return false;
1021 }
1022
1023 /**
1024 * If there is a ringing incoming call, this method accepts the call on behalf of the user.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001025 * TODO: L-release - need to convert all invocation of ITelecmmService#answerRingingCall to use
Santos Cordon96efb482014-07-19 14:57:05 -07001026 * this method (clockwork & gearhead).
Santos Cordon9eb45932014-06-27 12:28:43 -07001027 *
1028 * @hide
1029 */
1030 @SystemApi
1031 public void acceptRingingCall() {
1032 try {
1033 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001034 getTelecomService().acceptRingingCall();
Santos Cordon9eb45932014-06-27 12:28:43 -07001035 }
1036 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001037 Log.e(TAG, "Error calling ITelecomService#acceptRingingCall", e);
Santos Cordon9eb45932014-06-27 12:28:43 -07001038 }
1039 }
1040
1041 /**
1042 * Silences the ringer if a ringing call exists.
Santos Cordon9eb45932014-06-27 12:28:43 -07001043 */
Santos Cordon9eb45932014-06-27 12:28:43 -07001044 public void silenceRinger() {
1045 try {
1046 if (isServiceConnected()) {
Yorke Leef1a349b2015-04-29 16:16:50 -07001047 getTelecomService().silenceRinger(mContext.getOpPackageName());
Santos Cordon9eb45932014-06-27 12:28:43 -07001048 }
1049 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001050 Log.e(TAG, "Error calling ITelecomService#silenceRinger", e);
Santos Cordon9eb45932014-06-27 12:28:43 -07001051 }
1052 }
1053
Sailesh Nepal001bbbb2014-07-15 14:40:39 -07001054 /**
1055 * Returns whether TTY is supported on this device.
1056 *
1057 * @hide
1058 */
1059 @SystemApi
1060 public boolean isTtySupported() {
1061 try {
1062 if (isServiceConnected()) {
Svet Ganov16a16892015-04-16 10:32:04 -07001063 return getTelecomService().isTtySupported(mContext.getOpPackageName());
Sailesh Nepal001bbbb2014-07-15 14:40:39 -07001064 }
1065 } catch (RemoteException e) {
1066 Log.e(TAG, "RemoteException attempting to get TTY supported state.", e);
1067 }
1068 return false;
1069 }
1070
1071 /**
1072 * 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 -07001073 * settings and have a wired headset plugged in.
1074 * Valid modes are:
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001075 * - {@link TelecomManager#TTY_MODE_OFF}
1076 * - {@link TelecomManager#TTY_MODE_FULL}
1077 * - {@link TelecomManager#TTY_MODE_HCO}
1078 * - {@link TelecomManager#TTY_MODE_VCO}
Sailesh Nepal001bbbb2014-07-15 14:40:39 -07001079 * @hide
1080 */
1081 public int getCurrentTtyMode() {
1082 try {
1083 if (isServiceConnected()) {
Svet Ganov16a16892015-04-16 10:32:04 -07001084 return getTelecomService().getCurrentTtyMode(mContext.getOpPackageName());
Sailesh Nepal001bbbb2014-07-15 14:40:39 -07001085 }
1086 } catch (RemoteException e) {
1087 Log.e(TAG, "RemoteException attempting to get the current TTY mode.", e);
1088 }
Evan Charlton10197192014-07-19 15:00:29 -07001089 return TTY_MODE_OFF;
Sailesh Nepal001bbbb2014-07-15 14:40:39 -07001090 }
1091
Santos Cordon96efb482014-07-19 14:57:05 -07001092 /**
1093 * Registers a new incoming call. A {@link ConnectionService} should invoke this method when it
1094 * has an incoming call. The specified {@link PhoneAccountHandle} must have been registered
Nancy Chen210ef032014-09-15 17:58:42 -07001095 * with {@link #registerPhoneAccount}. Once invoked, this method will cause the system to bind
1096 * to the {@link ConnectionService} associated with the {@link PhoneAccountHandle} and request
Santos Cordon96efb482014-07-19 14:57:05 -07001097 * additional information about the call (See
1098 * {@link ConnectionService#onCreateIncomingConnection}) before starting the incoming call UI.
1099 *
1100 * @param phoneAccount A {@link PhoneAccountHandle} registered with
1101 * {@link #registerPhoneAccount}.
1102 * @param extras A bundle that will be passed through to
1103 * {@link ConnectionService#onCreateIncomingConnection}.
1104 */
1105 public void addNewIncomingCall(PhoneAccountHandle phoneAccount, Bundle extras) {
1106 try {
1107 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001108 getTelecomService().addNewIncomingCall(
Santos Cordon96efb482014-07-19 14:57:05 -07001109 phoneAccount, extras == null ? new Bundle() : extras);
1110 }
1111 } catch (RemoteException e) {
1112 Log.e(TAG, "RemoteException adding a new incoming call: " + phoneAccount, e);
1113 }
1114 }
1115
Nancy Chen0eb1e402014-08-21 22:52:29 -07001116 /**
Yorke Leec3cf9822014-10-02 09:38:39 -07001117 * Registers a new unknown call with Telecom. This can only be called by the system Telephony
1118 * service. This is invoked when Telephony detects a new unknown connection that was neither
1119 * a new incoming call, nor an user-initiated outgoing call.
1120 *
1121 * @param phoneAccount A {@link PhoneAccountHandle} registered with
1122 * {@link #registerPhoneAccount}.
1123 * @param extras A bundle that will be passed through to
1124 * {@link ConnectionService#onCreateIncomingConnection}.
1125 * @hide
1126 */
1127 @SystemApi
1128 public void addNewUnknownCall(PhoneAccountHandle phoneAccount, Bundle extras) {
1129 try {
1130 if (isServiceConnected()) {
1131 getTelecomService().addNewUnknownCall(
1132 phoneAccount, extras == null ? new Bundle() : extras);
1133 }
1134 } catch (RemoteException e) {
1135 Log.e(TAG, "RemoteException adding a new unknown call: " + phoneAccount, e);
1136 }
1137 }
1138
1139 /**
Nancy Chen0eb1e402014-08-21 22:52:29 -07001140 * Processes the specified dial string as an MMI code.
1141 * MMI codes are any sequence of characters entered into the dialpad that contain a "*" or "#".
1142 * Some of these sequences launch special behavior through handled by Telephony.
Nancy Chen95e8a672014-10-16 18:38:21 -07001143 * This method uses the default subscription.
Nancy Chen0eb1e402014-08-21 22:52:29 -07001144 * <p>
1145 * Requires that the method-caller be set as the system dialer app.
1146 * </p>
1147 *
1148 * @param dialString The digits to dial.
1149 * @return True if the digits were processed as an MMI code, false otherwise.
1150 */
1151 public boolean handleMmi(String dialString) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001152 ITelecomService service = getTelecomService();
Nancy Chen0eb1e402014-08-21 22:52:29 -07001153 if (service != null) {
1154 try {
Yorke Leef1a349b2015-04-29 16:16:50 -07001155 return service.handlePinMmi(dialString, mContext.getOpPackageName());
Nancy Chen0eb1e402014-08-21 22:52:29 -07001156 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001157 Log.e(TAG, "Error calling ITelecomService#handlePinMmi", e);
Nancy Chen0eb1e402014-08-21 22:52:29 -07001158 }
1159 }
1160 return false;
1161 }
1162
1163 /**
Nancy Chen95e8a672014-10-16 18:38:21 -07001164 * Processes the specified dial string as an MMI code.
1165 * MMI codes are any sequence of characters entered into the dialpad that contain a "*" or "#".
1166 * Some of these sequences launch special behavior through handled by Telephony.
1167 * <p>
1168 * Requires that the method-caller be set as the system dialer app.
1169 * </p>
1170 *
1171 * @param accountHandle The handle for the account the MMI code should apply to.
1172 * @param dialString The digits to dial.
1173 * @return True if the digits were processed as an MMI code, false otherwise.
Nancy Chen95e8a672014-10-16 18:38:21 -07001174 */
Yorke Lee06044272015-04-14 15:16:59 -07001175 public boolean handleMmi(String dialString, PhoneAccountHandle accountHandle) {
Nancy Chen95e8a672014-10-16 18:38:21 -07001176 ITelecomService service = getTelecomService();
1177 if (service != null) {
1178 try {
Yorke Leef1a349b2015-04-29 16:16:50 -07001179 return service.handlePinMmiForPhoneAccount(accountHandle, dialString,
1180 mContext.getOpPackageName());
Nancy Chen95e8a672014-10-16 18:38:21 -07001181 } catch (RemoteException e) {
1182 Log.e(TAG, "Error calling ITelecomService#handlePinMmi", e);
1183 }
1184 }
1185 return false;
1186 }
1187
1188 /**
Nancy Chenb2299c12014-10-29 18:22:11 -07001189 * @param accountHandle The handle for the account to derive an adn query URI for or
1190 * {@code null} to return a URI which will use the default account.
1191 * @return The URI (with the content:// scheme) specific to the specified {@link PhoneAccount}
1192 * for the the content retrieve.
1193 */
1194 public Uri getAdnUriForPhoneAccount(PhoneAccountHandle accountHandle) {
1195 ITelecomService service = getTelecomService();
1196 if (service != null && accountHandle != null) {
1197 try {
Yorke Leef1a349b2015-04-29 16:16:50 -07001198 return service.getAdnUriForPhoneAccount(accountHandle, mContext.getOpPackageName());
Nancy Chenb2299c12014-10-29 18:22:11 -07001199 } catch (RemoteException e) {
1200 Log.e(TAG, "Error calling ITelecomService#getAdnUriForPhoneAccount", e);
1201 }
1202 }
1203 return Uri.parse("content://icc/adn");
1204 }
1205
1206 /**
Nancy Chen0eb1e402014-08-21 22:52:29 -07001207 * Removes the missed-call notification if one is present.
1208 * <p>
1209 * Requires that the method-caller be set as the system dialer app.
1210 * </p>
1211 */
1212 public void cancelMissedCallsNotification() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001213 ITelecomService service = getTelecomService();
Nancy Chen0eb1e402014-08-21 22:52:29 -07001214 if (service != null) {
1215 try {
Yorke Leef1a349b2015-04-29 16:16:50 -07001216 service.cancelMissedCallsNotification(mContext.getOpPackageName());
Nancy Chen0eb1e402014-08-21 22:52:29 -07001217 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001218 Log.e(TAG, "Error calling ITelecomService#cancelMissedCallsNotification", e);
Nancy Chen0eb1e402014-08-21 22:52:29 -07001219 }
1220 }
1221 }
1222
1223 /**
1224 * Brings the in-call screen to the foreground if there is an ongoing call. If there is
1225 * currently no ongoing call, then this method does nothing.
1226 * <p>
1227 * Requires that the method-caller be set as the system dialer app or have the
1228 * {@link android.Manifest.permission#READ_PHONE_STATE} permission.
1229 * </p>
1230 *
1231 * @param showDialpad Brings up the in-call dialpad as part of showing the in-call screen.
1232 */
1233 public void showInCallScreen(boolean showDialpad) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001234 ITelecomService service = getTelecomService();
Nancy Chen0eb1e402014-08-21 22:52:29 -07001235 if (service != null) {
1236 try {
Svet Ganov16a16892015-04-16 10:32:04 -07001237 service.showInCallScreen(showDialpad, mContext.getOpPackageName());
Nancy Chen0eb1e402014-08-21 22:52:29 -07001238 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001239 Log.e(TAG, "Error calling ITelecomService#showCallScreen", e);
Nancy Chen0eb1e402014-08-21 22:52:29 -07001240 }
1241 }
1242 }
1243
Yorke Lee3e56ba12015-04-23 12:32:36 -07001244 /**
1245 * Places a new outgoing call to the provided address using the system telecom service with
1246 * the specified extras.
1247 *
1248 * This method is equivalent to placing an outgoing call using {@link Intent#ACTION_CALL},
1249 * except that the outgoing call will always be sent via the system telecom service. If
1250 * method-caller is either the user selected default dialer app or preloaded system dialer
1251 * app, then emergency calls will also be allowed.
1252 *
1253 * Requires permission: {@link android.Manifest.permission#CALL_PHONE}
1254 *
1255 * Usage example:
1256 * <pre>
1257 * Uri uri = Uri.fromParts("tel", "12345", null);
1258 * Bundle extras = new Bundle();
1259 * extras.putBoolean(TelecomManager.EXTRA_START_CALL_WITH_SPEAKERPHONE, true);
1260 * telecomManager.placeCall(uri, extras);
1261 * </pre>
1262 *
Santos Cordon7a060d52015-06-19 14:52:04 -07001263 * The following keys are supported in the supplied extras.
1264 * <ul>
1265 * <li>{@link #EXTRA_OUTGOING_CALL_EXTRAS}</li>
1266 * <li>{@link #EXTRA_PHONE_ACCOUNT_HANDLE}</li>
1267 * <li>{@link #EXTRA_START_CALL_WITH_SPEAKERPHONE}</li>
1268 * <li>{@link #EXTRA_START_CALL_WITH_VIDEO_STATE}</li>
1269 * </ul>
1270 *
Yorke Lee3e56ba12015-04-23 12:32:36 -07001271 * @param address The address to make the call to.
1272 * @param extras Bundle of extras to use with the call.
1273 */
1274 public void placeCall(Uri address, Bundle extras) {
1275 ITelecomService service = getTelecomService();
1276 if (service != null) {
Yorke Leea5d5c1d2015-05-05 16:25:55 -07001277 if (address == null) {
1278 Log.w(TAG, "Cannot place call to empty address.");
1279 }
Yorke Lee3e56ba12015-04-23 12:32:36 -07001280 try {
Yorke Leea5d5c1d2015-05-05 16:25:55 -07001281 service.placeCall(address, extras == null ? new Bundle() : extras,
1282 mContext.getOpPackageName());
Yorke Lee3e56ba12015-04-23 12:32:36 -07001283 } catch (RemoteException e) {
1284 Log.e(TAG, "Error calling ITelecomService#placeCall", e);
1285 }
1286 }
1287 }
1288
Santos Cordon91371dc02015-05-08 13:52:09 -07001289 /**
1290 * Enables and disables specified phone account.
1291 *
1292 * @param handle Handle to the phone account.
1293 * @param isEnabled Enable state of the phone account.
1294 * @hide
1295 */
1296 @SystemApi
1297 public void enablePhoneAccount(PhoneAccountHandle handle, boolean isEnabled) {
1298 ITelecomService service = getTelecomService();
1299 if (service != null) {
1300 try {
1301 service.enablePhoneAccount(handle, isEnabled);
1302 } catch (RemoteException e) {
1303 Log.e(TAG, "Error enablePhoneAbbount", e);
1304 }
1305 }
1306 }
1307
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001308 private ITelecomService getTelecomService() {
1309 return ITelecomService.Stub.asInterface(ServiceManager.getService(Context.TELECOM_SERVICE));
Santos Cordon6c7a3882014-06-25 15:30:08 -07001310 }
Santos Cordon9eb45932014-06-27 12:28:43 -07001311
1312 private boolean isServiceConnected() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001313 boolean isConnected = getTelecomService() != null;
Santos Cordon9eb45932014-06-27 12:28:43 -07001314 if (!isConnected) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001315 Log.w(TAG, "Telecom Service not found.");
Santos Cordon9eb45932014-06-27 12:28:43 -07001316 }
1317 return isConnected;
1318 }
Evan Charlton235c1592014-09-05 15:41:23 +00001319}