blob: 9eb16659613217db7ecaf904d4542ca6b249c694 [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
Yorke Leec61d13662015-09-21 17:25:25 -070017import android.annotation.RequiresPermission;
Santos Cordon6c7a3882014-06-25 15:30:08 -070018import android.annotation.SystemApi;
19import android.content.ComponentName;
Yorke Leeb4ce1432014-06-09 13:53:23 -070020import android.content.Context;
Yorke Lee3e56ba12015-04-23 12:32:36 -070021import android.content.Intent;
Nancy Chenb2299c12014-10-29 18:22:11 -070022import android.net.Uri;
Santos Cordon96efb482014-07-19 14:57:05 -070023import android.os.Bundle;
Santos Cordon6c7a3882014-06-25 15:30:08 -070024import android.os.RemoteException;
25import android.os.ServiceManager;
Yorke Lee2ae312e2014-09-12 17:58:48 -070026import android.telephony.TelephonyManager;
Anthony Lee67279262014-10-27 11:28:40 -070027import android.text.TextUtils;
Santos Cordon6c7a3882014-06-25 15:30:08 -070028import android.util.Log;
Yorke Leeb4ce1432014-06-09 13:53:23 -070029
Tyler Gunnef9f6f92014-09-12 22:16:17 -070030import com.android.internal.telecom.ITelecomService;
Yorke Leeb4ce1432014-06-09 13:53:23 -070031
Jay Shrauner7746a942014-08-26 12:15:15 -070032import java.util.ArrayList;
Tyler Gunna1ed7d12014-09-08 09:52:22 -070033import java.util.Collections;
Ihab Awad807fe0a2014-07-09 12:30:52 -070034import java.util.List;
35
Yorke Leeb4ce1432014-06-09 13:53:23 -070036/**
Santos Cordond9e614f2014-10-28 13:10:36 -070037 * Provides access to information about active calls and registration/call-management functionality.
Evan Charlton0e094d92014-11-08 15:49:16 -080038 * Apps can use methods in this class to determine the current call state.
Santos Cordond9e614f2014-10-28 13:10:36 -070039 * <p>
40 * Apps do not instantiate this class directly; instead, they retrieve a reference to an instance
41 * through {@link Context#getSystemService Context.getSystemService(Context.TELECOM_SERVICE)}.
42 * <p>
43 * Note that access to some telecom information is permission-protected. Your app cannot access the
44 * protected information or gain access to protected functionality unless it has the appropriate
45 * permissions declared in its manifest file. Where permissions apply, they are noted in the method
46 * descriptions.
Yorke Leeb4ce1432014-06-09 13:53:23 -070047 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -070048public class TelecomManager {
Ihab Awad807fe0a2014-07-09 12:30:52 -070049
Evan Charlton10197192014-07-19 15:00:29 -070050 /**
Santos Cordon96efb482014-07-19 14:57:05 -070051 * Activity action: Starts the UI for handing an incoming call. This intent starts the in-call
Tyler Gunnef9f6f92014-09-12 22:16:17 -070052 * UI by notifying the Telecom system that an incoming call exists for a specific call service
53 * (see {@link android.telecom.ConnectionService}). Telecom reads the Intent extras to find
54 * and bind to the appropriate {@link android.telecom.ConnectionService} which Telecom will
Santos Cordon96efb482014-07-19 14:57:05 -070055 * ultimately use to control and get information about the call.
56 * <p>
57 * Input: get*Extra field {@link #EXTRA_PHONE_ACCOUNT_HANDLE} contains the component name of the
Tyler Gunnef9f6f92014-09-12 22:16:17 -070058 * {@link android.telecom.ConnectionService} that Telecom should bind to. Telecom will then
Evan Charlton10197192014-07-19 15:00:29 -070059 * ask the connection service for more information about the call prior to showing any UI.
Evan Charlton10197192014-07-19 15:00:29 -070060 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -070061 public static final String ACTION_INCOMING_CALL = "android.telecom.action.INCOMING_CALL";
Evan Charlton10197192014-07-19 15:00:29 -070062
63 /**
Yorke Leec3cf9822014-10-02 09:38:39 -070064 * Similar to {@link #ACTION_INCOMING_CALL}, but is used only by Telephony to add a new
65 * sim-initiated MO call for carrier testing.
66 * @hide
67 */
68 public static final String ACTION_NEW_UNKNOWN_CALL = "android.telecom.action.NEW_UNKNOWN_CALL";
69
70 /**
Santos Cordon895d4b82015-06-25 16:41:48 -070071 * An {@link android.content.Intent} action sent by the telecom framework to start a
72 * configuration dialog for a registered {@link PhoneAccount}. There is no default dialog
73 * and each app that registers a {@link PhoneAccount} should provide one if desired.
74 * <p>
75 * A user can access the list of enabled {@link android.telecom.PhoneAccount}s through the Phone
76 * app's settings menu. For each entry, the settings app will add a click action. When
77 * triggered, the click-action will start this intent along with the extra
78 * {@link #EXTRA_PHONE_ACCOUNT_HANDLE} to indicate the {@link PhoneAccount} to configure. If the
79 * {@link PhoneAccount} package does not register an {@link android.app.Activity} for this
80 * intent, then it will not be sent.
Evan Charlton10197192014-07-19 15:00:29 -070081 */
Santos Cordon895d4b82015-06-25 16:41:48 -070082 public static final String ACTION_CONFIGURE_PHONE_ACCOUNT =
83 "android.telecom.action.CONFIGURE_PHONE_ACCOUNT";
Evan Charlton10197192014-07-19 15:00:29 -070084
85 /**
Andrew Lee873cfbf2015-02-26 15:22:00 -080086 * The {@link android.content.Intent} action used to show the call accessibility settings page.
87 */
88 public static final String ACTION_SHOW_CALL_ACCESSIBILITY_SETTINGS =
89 "android.telecom.action.SHOW_CALL_ACCESSIBILITY_SETTINGS";
90
91 /**
Yorke Lee3818a8922014-07-21 15:57:17 -070092 * The {@link android.content.Intent} action used to show the call settings page.
93 */
94 public static final String ACTION_SHOW_CALL_SETTINGS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -070095 "android.telecom.action.SHOW_CALL_SETTINGS";
Yorke Lee3818a8922014-07-21 15:57:17 -070096
97 /**
Andrew Lee866080f2015-02-19 12:05:33 -080098 * The {@link android.content.Intent} action used to show the respond via SMS settings page.
99 */
100 public static final String ACTION_SHOW_RESPOND_VIA_SMS_SETTINGS =
101 "android.telecom.action.SHOW_RESPOND_VIA_SMS_SETTINGS";
102
103 /**
Evan Charlton6d8604f2014-09-04 12:38:17 -0700104 * The {@link android.content.Intent} action used to show the settings page used to configure
105 * {@link PhoneAccount} preferences.
106 */
107 public static final String ACTION_CHANGE_PHONE_ACCOUNTS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700108 "android.telecom.action.CHANGE_PHONE_ACCOUNTS";
Evan Charlton6d8604f2014-09-04 12:38:17 -0700109
110 /**
Santos Cordonc66f3ba2015-02-27 15:22:07 -0800111 * The {@link android.content.Intent} action used indicate that a new phone account was
112 * just registered.
113 * @hide
114 */
115 @SystemApi
116 public static final String ACTION_PHONE_ACCOUNT_REGISTERED =
117 "android.telecom.action.PHONE_ACCOUNT_REGISTERED";
118
119 /**
Bryce Lee30b0aa02015-09-23 21:53:53 -0700120 * The {@link android.content.Intent} action used indicate that a phone account was
121 * just unregistered.
122 * @hide
123 */
124 @SystemApi
125 public static final String ACTION_PHONE_ACCOUNT_UNREGISTERED =
126 "android.telecom.action.PHONE_ACCOUNT_UNREGISTERED";
127
128 /**
Yorke Lee1011f482015-04-23 15:58:27 -0700129 * Activity action: Shows a dialog asking the user whether or not they want to replace the
130 * current default Dialer with the one specified in
131 * {@link #EXTRA_CHANGE_DEFAULT_DIALER_PACKAGE_NAME}.
132 *
133 * Usage example:
134 * <pre>
135 * Intent intent = new Intent(TelecomManager.ACTION_CHANGE_DEFAULT_DIALER);
136 * intent.putExtra(TelecomManager.EXTRA_CHANGE_DEFAULT_DIALER_PACKAGE_NAME,
137 * getActivity().getPackageName());
138 * startActivity(intent);
139 * </pre>
140 */
141 public static final String ACTION_CHANGE_DEFAULT_DIALER =
142 "android.telecom.action.CHANGE_DEFAULT_DIALER";
143
144 /**
Yorke Lee107c4ce2015-06-15 12:08:24 -0700145 * Broadcast intent action indicating that the current default dialer has changed.
146 * The string extra {@link #EXTRA_CHANGE_DEFAULT_DIALER_PACKAGE_NAME} will contain the
147 * name of the package that the default dialer was changed to.
148 *
149 * @see #EXTRA_CHANGE_DEFAULT_DIALER_PACKAGE_NAME
150 */
151 public static final String ACTION_DEFAULT_DIALER_CHANGED =
152 "android.telecom.action.DEFAULT_DIALER_CHANGED";
153
154 /**
Yorke Lee1011f482015-04-23 15:58:27 -0700155 * Extra value used to provide the package name for {@link #ACTION_CHANGE_DEFAULT_DIALER}.
156 */
157 public static final String EXTRA_CHANGE_DEFAULT_DIALER_PACKAGE_NAME =
158 "android.telecom.extra.CHANGE_DEFAULT_DIALER_PACKAGE_NAME";
159
160 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700161 * Optional extra for {@link android.content.Intent#ACTION_CALL} containing a boolean that
162 * determines whether the speakerphone should be automatically turned on for an outgoing call.
Evan Charlton10197192014-07-19 15:00:29 -0700163 */
164 public static final String EXTRA_START_CALL_WITH_SPEAKERPHONE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700165 "android.telecom.extra.START_CALL_WITH_SPEAKERPHONE";
Evan Charlton10197192014-07-19 15:00:29 -0700166
167 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700168 * Optional extra for {@link android.content.Intent#ACTION_CALL} containing an integer that
169 * determines the desired video state for an outgoing call.
Santos Cordon96efb482014-07-19 14:57:05 -0700170 * Valid options:
Yorke Lee32f24732015-05-12 16:18:03 -0700171 * {@link VideoProfile#STATE_AUDIO_ONLY},
172 * {@link VideoProfile#STATE_BIDIRECTIONAL},
173 * {@link VideoProfile#STATE_RX_ENABLED},
174 * {@link VideoProfile#STATE_TX_ENABLED}.
Evan Charlton10197192014-07-19 15:00:29 -0700175 */
176 public static final String EXTRA_START_CALL_WITH_VIDEO_STATE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700177 "android.telecom.extra.START_CALL_WITH_VIDEO_STATE";
Evan Charlton10197192014-07-19 15:00:29 -0700178
179 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700180 * The extra used with an {@link android.content.Intent#ACTION_CALL} and
181 * {@link android.content.Intent#ACTION_DIAL} {@code Intent} to specify a
182 * {@link PhoneAccountHandle} to use when making the call.
Evan Charlton10197192014-07-19 15:00:29 -0700183 * <p class="note">
Santos Cordon96efb482014-07-19 14:57:05 -0700184 * Retrieve with {@link android.content.Intent#getParcelableExtra(String)}.
Evan Charlton10197192014-07-19 15:00:29 -0700185 */
Evan Charlton6eb262c2014-07-19 18:18:19 -0700186 public static final String EXTRA_PHONE_ACCOUNT_HANDLE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700187 "android.telecom.extra.PHONE_ACCOUNT_HANDLE";
Evan Charlton10197192014-07-19 15:00:29 -0700188
189 /**
Tyler Gunn335ff2e2015-07-30 14:18:33 -0700190 * Optional extra for {@link android.content.Intent#ACTION_CALL} containing a string call
191 * subject which will be associated with an outgoing call. Should only be specified if the
192 * {@link PhoneAccount} supports the capability {@link PhoneAccount#CAPABILITY_CALL_SUBJECT}.
193 */
194 public static final String EXTRA_CALL_SUBJECT = "android.telecom.extra.CALL_SUBJECT";
195
196 /**
Yorke Lee04ea7d32015-06-05 15:59:18 -0700197 * The extra used by a {@link ConnectionService} to provide the handle of the caller that
198 * has initiated a new incoming call.
199 */
Yorke Lee02fb5bc2015-06-09 12:27:36 -0700200 public static final String EXTRA_INCOMING_CALL_ADDRESS =
201 "android.telecom.extra.INCOMING_CALL_ADDRESS";
Yorke Lee04ea7d32015-06-05 15:59:18 -0700202
203 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700204 * Optional extra for {@link #ACTION_INCOMING_CALL} containing a {@link Bundle} which contains
205 * metadata about the call. This {@link Bundle} will be returned to the
206 * {@link ConnectionService}.
Evan Charlton10197192014-07-19 15:00:29 -0700207 */
208 public static final String EXTRA_INCOMING_CALL_EXTRAS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700209 "android.telecom.extra.INCOMING_CALL_EXTRAS";
Evan Charlton10197192014-07-19 15:00:29 -0700210
211 /**
Nancy Chen10798dc2014-08-08 14:00:25 -0700212 * Optional extra for {@link android.content.Intent#ACTION_CALL} and
213 * {@link android.content.Intent#ACTION_DIAL} {@code Intent} containing a {@link Bundle}
214 * which contains metadata about the call. This {@link Bundle} will be saved into
Santos Cordon7a060d52015-06-19 14:52:04 -0700215 * {@code Call.Details} and passed to the {@link ConnectionService} when placing the call.
Nancy Chen10798dc2014-08-08 14:00:25 -0700216 */
217 public static final String EXTRA_OUTGOING_CALL_EXTRAS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700218 "android.telecom.extra.OUTGOING_CALL_EXTRAS";
Nancy Chen10798dc2014-08-08 14:00:25 -0700219
220 /**
Yorke Leec3cf9822014-10-02 09:38:39 -0700221 * @hide
222 */
223 public static final String EXTRA_UNKNOWN_CALL_HANDLE =
224 "android.telecom.extra.UNKNOWN_CALL_HANDLE";
225
226 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700227 * Optional extra for {@link android.telephony.TelephonyManager#ACTION_PHONE_STATE_CHANGED}
228 * containing the disconnect code.
Evan Charlton10197192014-07-19 15:00:29 -0700229 */
230 public static final String EXTRA_CALL_DISCONNECT_CAUSE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700231 "android.telecom.extra.CALL_DISCONNECT_CAUSE";
Evan Charlton10197192014-07-19 15:00:29 -0700232
233 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700234 * Optional extra for {@link android.telephony.TelephonyManager#ACTION_PHONE_STATE_CHANGED}
235 * containing the disconnect message.
Evan Charlton10197192014-07-19 15:00:29 -0700236 */
237 public static final String EXTRA_CALL_DISCONNECT_MESSAGE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700238 "android.telecom.extra.CALL_DISCONNECT_MESSAGE";
Evan Charlton10197192014-07-19 15:00:29 -0700239
240 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700241 * Optional extra for {@link android.telephony.TelephonyManager#ACTION_PHONE_STATE_CHANGED}
242 * containing the component name of the associated connection service.
Evan Charlton0e094d92014-11-08 15:49:16 -0800243 * @hide
Evan Charlton10197192014-07-19 15:00:29 -0700244 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800245 @SystemApi
Evan Charlton10197192014-07-19 15:00:29 -0700246 public static final String EXTRA_CONNECTION_SERVICE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700247 "android.telecom.extra.CONNECTION_SERVICE";
Evan Charlton10197192014-07-19 15:00:29 -0700248
249 /**
Hall Liu90f62902015-11-19 16:19:24 -0800250 * Optional extra for communicating the call technology used by a
251 * {@link com.android.internal.telephony.Connection} to Telecom
252 * @hide
253 */
254 public static final String EXTRA_CALL_TECHNOLOGY_TYPE =
255 "android.telecom.extra.CALL_TECHNOLOGY_TYPE";
256
257 /**
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700258 * An optional {@link android.content.Intent#ACTION_CALL} intent extra denoting the
259 * package name of the app specifying an alternative gateway for the call.
260 * The value is a string.
261 *
262 * (The following comment corresponds to the all GATEWAY_* extras)
263 * An app which sends the {@link android.content.Intent#ACTION_CALL} intent can specify an
264 * alternative address to dial which is different from the one specified and displayed to
265 * the user. This alternative address is referred to as the gateway address.
266 */
267 public static final String GATEWAY_PROVIDER_PACKAGE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700268 "android.telecom.extra.GATEWAY_PROVIDER_PACKAGE";
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700269
270 /**
271 * An optional {@link android.content.Intent#ACTION_CALL} intent extra corresponding to the
272 * original address to dial for the call. This is used when an alternative gateway address is
273 * provided to recall the original address.
274 * The value is a {@link android.net.Uri}.
275 *
276 * (See {@link #GATEWAY_PROVIDER_PACKAGE} for details)
277 */
278 public static final String GATEWAY_ORIGINAL_ADDRESS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700279 "android.telecom.extra.GATEWAY_ORIGINAL_ADDRESS";
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700280
281 /**
Evan Charlton10197192014-07-19 15:00:29 -0700282 * The number which the party on the other side of the line will see (and use to return the
283 * call).
284 * <p>
Santos Cordon96efb482014-07-19 14:57:05 -0700285 * {@link ConnectionService}s which interact with {@link RemoteConnection}s should only populate
286 * this if the {@link android.telephony.TelephonyManager#getLine1Number()} value, as that is the
287 * user's expected caller ID.
Evan Charlton10197192014-07-19 15:00:29 -0700288 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700289 public static final String EXTRA_CALL_BACK_NUMBER = "android.telecom.extra.CALL_BACK_NUMBER";
Evan Charlton10197192014-07-19 15:00:29 -0700290
291 /**
Santos Cordonf2600eb2015-06-22 15:02:20 -0700292 * A boolean meta-data value indicating whether an {@link InCallService} implements an
293 * in-call user interface. Dialer implementations (see {@link #getDefaultDialerPackage()}) which
294 * would also like to replace the in-call interface should set this meta-data to {@code true} in
295 * the manifest registration of their {@link InCallService}.
296 */
297 public static final String METADATA_IN_CALL_SERVICE_UI = "android.telecom.IN_CALL_SERVICE_UI";
298
299 /**
Evan Charlton10197192014-07-19 15:00:29 -0700300 * The dual tone multi-frequency signaling character sent to indicate the dialing system should
301 * pause for a predefined period.
302 */
303 public static final char DTMF_CHARACTER_PAUSE = ',';
304
305 /**
306 * The dual-tone multi-frequency signaling character sent to indicate the dialing system should
307 * wait for user confirmation before proceeding.
308 */
309 public static final char DTMF_CHARACTER_WAIT = ';';
310
311 /**
312 * TTY (teletypewriter) mode is off.
313 *
314 * @hide
315 */
316 public static final int TTY_MODE_OFF = 0;
317
318 /**
319 * TTY (teletypewriter) mode is on. The speaker is off and the microphone is muted. The user
320 * will communicate with the remote party by sending and receiving text messages.
321 *
322 * @hide
323 */
324 public static final int TTY_MODE_FULL = 1;
325
326 /**
327 * TTY (teletypewriter) mode is in hearing carryover mode (HCO). The microphone is muted but the
328 * speaker is on. The user will communicate with the remote party by sending text messages and
329 * hearing an audible reply.
330 *
331 * @hide
332 */
333 public static final int TTY_MODE_HCO = 2;
334
335 /**
336 * TTY (teletypewriter) mode is in voice carryover mode (VCO). The speaker is off but the
337 * microphone is still on. User will communicate with the remote party by speaking and receiving
338 * text message replies.
339 *
340 * @hide
341 */
342 public static final int TTY_MODE_VCO = 3;
343
344 /**
345 * Broadcast intent action indicating that the current TTY mode has changed. An intent extra
346 * provides this state as an int.
Evan Charlton10197192014-07-19 15:00:29 -0700347 *
Santos Cordon96efb482014-07-19 14:57:05 -0700348 * @see #EXTRA_CURRENT_TTY_MODE
Evan Charlton10197192014-07-19 15:00:29 -0700349 * @hide
350 */
351 public static final String ACTION_CURRENT_TTY_MODE_CHANGED =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700352 "android.telecom.action.CURRENT_TTY_MODE_CHANGED";
Evan Charlton10197192014-07-19 15:00:29 -0700353
354 /**
355 * The lookup key for an int that indicates the current TTY mode.
356 * Valid modes are:
357 * - {@link #TTY_MODE_OFF}
358 * - {@link #TTY_MODE_FULL}
359 * - {@link #TTY_MODE_HCO}
360 * - {@link #TTY_MODE_VCO}
361 *
362 * @hide
363 */
364 public static final String EXTRA_CURRENT_TTY_MODE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700365 "android.telecom.intent.extra.CURRENT_TTY_MODE";
Evan Charlton10197192014-07-19 15:00:29 -0700366
367 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700368 * Broadcast intent action indicating that the TTY preferred operating mode has changed. An
369 * intent extra provides the new mode as an int.
Evan Charlton10197192014-07-19 15:00:29 -0700370 *
Santos Cordon96efb482014-07-19 14:57:05 -0700371 * @see #EXTRA_TTY_PREFERRED_MODE
Evan Charlton10197192014-07-19 15:00:29 -0700372 * @hide
373 */
374 public static final String ACTION_TTY_PREFERRED_MODE_CHANGED =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700375 "android.telecom.action.TTY_PREFERRED_MODE_CHANGED";
Evan Charlton10197192014-07-19 15:00:29 -0700376
377 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700378 * The lookup key for an int that indicates preferred TTY mode. Valid modes are: -
379 * {@link #TTY_MODE_OFF} - {@link #TTY_MODE_FULL} - {@link #TTY_MODE_HCO} -
380 * {@link #TTY_MODE_VCO}
Evan Charlton10197192014-07-19 15:00:29 -0700381 *
382 * @hide
383 */
384 public static final String EXTRA_TTY_PREFERRED_MODE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700385 "android.telecom.intent.extra.TTY_PREFERRED";
Evan Charlton10197192014-07-19 15:00:29 -0700386
Nancy Chen9d568c02014-09-08 14:17:59 -0700387 /**
Bryce Lee5e4dd3e2015-08-03 16:59:10 -0700388 * Broadcast intent action for letting custom component know to show the missed call
389 * notification.
390 * @hide
391 */
392 @SystemApi
393 public static final String ACTION_SHOW_MISSED_CALLS_NOTIFICATION =
394 "android.telecom.action.SHOW_MISSED_CALLS_NOTIFICATION";
395
396 /**
397 * The number of calls associated with the notification.
398 * @hide
399 */
400 @SystemApi
401 public static final String EXTRA_NOTIFICATION_COUNT =
402 "android.telecom.extra.NOTIFICATION_COUNT";
403
404 /**
405 * The number associated with the missed calls. This number is only relevant
406 * when EXTRA_NOTIFICATION_COUNT is 1.
407 * @hide
408 */
409 @SystemApi
410 public static final String EXTRA_NOTIFICATION_PHONE_NUMBER =
411 "android.telecom.extra.NOTIFICATION_PHONE_NUMBER";
412
413 /**
Bryce Lee8d41d1d2015-08-10 07:40:42 -0700414 * The intent to clear missed calls.
415 * @hide
416 */
417 @SystemApi
418 public static final String EXTRA_CLEAR_MISSED_CALLS_INTENT =
419 "android.telecom.extra.CLEAR_MISSED_CALLS_INTENT";
420
421 /**
422 * The intent to call back a missed call.
423 * @hide
424 */
425 @SystemApi
426 public static final String EXTRA_CALL_BACK_INTENT =
427 "android.telecom.extra.CALL_BACK_INTENT";
428
429 /**
Nancy Chen9d568c02014-09-08 14:17:59 -0700430 * The following 4 constants define how properties such as phone numbers and names are
431 * displayed to the user.
432 */
433
Santos Cordoned769ae2015-05-13 18:47:38 -0700434 /**
435 * Indicates that the address or number of a call is allowed to be displayed for caller ID.
436 */
Nancy Chen9d568c02014-09-08 14:17:59 -0700437 public static final int PRESENTATION_ALLOWED = 1;
438
Santos Cordoned769ae2015-05-13 18:47:38 -0700439 /**
440 * Indicates that the address or number of a call is blocked by the other party.
441 */
Nancy Chen9d568c02014-09-08 14:17:59 -0700442 public static final int PRESENTATION_RESTRICTED = 2;
443
Santos Cordoned769ae2015-05-13 18:47:38 -0700444 /**
445 * Indicates that the address or number of a call is not specified or known by the carrier.
446 */
Nancy Chen9d568c02014-09-08 14:17:59 -0700447 public static final int PRESENTATION_UNKNOWN = 3;
448
Santos Cordoned769ae2015-05-13 18:47:38 -0700449 /**
450 * Indicates that the address or number of a call belongs to a pay phone.
451 */
Nancy Chen9d568c02014-09-08 14:17:59 -0700452 public static final int PRESENTATION_PAYPHONE = 4;
453
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700454 private static final String TAG = "TelecomManager";
Yorke Leeb4ce1432014-06-09 13:53:23 -0700455
456 private final Context mContext;
Yorke Leeb4ce1432014-06-09 13:53:23 -0700457
Hall Liue1bc2ec2015-10-09 15:58:37 -0700458 private final ITelecomService mTelecomServiceOverride;
459
Santos Cordon6c7a3882014-06-25 15:30:08 -0700460 /**
461 * @hide
462 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700463 public static TelecomManager from(Context context) {
464 return (TelecomManager) context.getSystemService(Context.TELECOM_SERVICE);
Yorke Leeb4ce1432014-06-09 13:53:23 -0700465 }
Santos Cordon6c7a3882014-06-25 15:30:08 -0700466
467 /**
468 * @hide
469 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700470 public TelecomManager(Context context) {
Hall Liue1bc2ec2015-10-09 15:58:37 -0700471 this(context, null);
472 }
473
474 /**
475 * @hide
476 */
477 public TelecomManager(Context context, ITelecomService telecomServiceImpl) {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700478 Context appContext = context.getApplicationContext();
479 if (appContext != null) {
480 mContext = appContext;
481 } else {
482 mContext = context;
483 }
Hall Liue1bc2ec2015-10-09 15:58:37 -0700484 mTelecomServiceOverride = telecomServiceImpl;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700485 }
486
487 /**
Santos Cordon91371dc02015-05-08 13:52:09 -0700488 * Return the {@link PhoneAccount} which will be used to place outgoing calls to addresses with
489 * the specified {@code uriScheme}. This {@link PhoneAccount} will always be a member of the
490 * list which is returned from invoking {@link #getCallCapablePhoneAccounts()}. The specific
491 * account returned depends on the following priorities:
492 * <ul>
493 * <li> If the user-selected default {@link PhoneAccount} supports the specified scheme, it will
494 * be returned.
495 * </li>
496 * <li> If there exists only one {@link PhoneAccount} that supports the specified scheme, it
497 * will be returned.
498 * </li>
499 * </ul>
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700500 * <p>
Santos Cordon91371dc02015-05-08 13:52:09 -0700501 * If no {@link PhoneAccount} fits the criteria above, this method will return {@code null}.
502 *
Yorke Leec61d13662015-09-21 17:25:25 -0700503 * Requires permission: {@link android.Manifest.permission#READ_PHONE_STATE}
504 *
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700505 * @param uriScheme The URI scheme.
Santos Cordon91371dc02015-05-08 13:52:09 -0700506 * @return The {@link PhoneAccountHandle} corresponding to the account to be used.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700507 */
Yorke Leec61d13662015-09-21 17:25:25 -0700508 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700509 public PhoneAccountHandle getDefaultOutgoingPhoneAccount(String uriScheme) {
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700510 try {
511 if (isServiceConnected()) {
Svet Ganov16a16892015-04-16 10:32:04 -0700512 return getTelecomService().getDefaultOutgoingPhoneAccount(uriScheme,
513 mContext.getOpPackageName());
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700514 }
515 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700516 Log.e(TAG, "Error calling ITelecomService#getDefaultOutgoingPhoneAccount", e);
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700517 }
518 return null;
519 }
520
521 /**
Andrew Leed4abbfb2014-09-03 14:58:27 -0700522 * Return the {@link PhoneAccount} which is the user-chosen default for making outgoing phone
523 * calls. This {@code PhoneAccount} will always be a member of the list which is returned from
Nancy Chen210ef032014-09-15 17:58:42 -0700524 * calling {@link #getCallCapablePhoneAccounts()}
Santos Cordon91371dc02015-05-08 13:52:09 -0700525 * <p>
Andrew Leed4abbfb2014-09-03 14:58:27 -0700526 * Apps must be prepared for this method to return {@code null}, indicating that there currently
527 * exists no user-chosen default {@code PhoneAccount}.
528 *
529 * @return The user outgoing phone account selected by the user.
Jay Shrauner225ccad2015-04-15 15:51:15 -0700530 * @hide
Andrew Leed4abbfb2014-09-03 14:58:27 -0700531 */
532 public PhoneAccountHandle getUserSelectedOutgoingPhoneAccount() {
533 try {
534 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700535 return getTelecomService().getUserSelectedOutgoingPhoneAccount();
Andrew Leed4abbfb2014-09-03 14:58:27 -0700536 }
537 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700538 Log.e(TAG, "Error calling ITelecomService#getUserSelectedOutgoingPhoneAccount", e);
Andrew Leed4abbfb2014-09-03 14:58:27 -0700539 }
540 return null;
541 }
542
543 /**
Santos Cordon91371dc02015-05-08 13:52:09 -0700544 * Sets the user-chosen default for making outgoing phone calls.
Andrew Lee59cac3a2014-08-28 16:50:10 -0700545 * @hide
546 */
Andrew Leed4abbfb2014-09-03 14:58:27 -0700547 public void setUserSelectedOutgoingPhoneAccount(PhoneAccountHandle accountHandle) {
Andrew Lee59cac3a2014-08-28 16:50:10 -0700548 try {
549 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700550 getTelecomService().setUserSelectedOutgoingPhoneAccount(accountHandle);
Andrew Lee59cac3a2014-08-28 16:50:10 -0700551 }
552 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700553 Log.e(TAG, "Error calling ITelecomService#setUserSelectedOutgoingPhoneAccount");
Andrew Lee59cac3a2014-08-28 16:50:10 -0700554 }
555 }
556
557 /**
Andrew Lee59cac3a2014-08-28 16:50:10 -0700558 * Returns the current SIM call manager. Apps must be prepared for this method to return
559 * {@code null}, indicating that there currently exists no user-chosen default
560 * {@code PhoneAccount}.
Santos Cordon91371dc02015-05-08 13:52:09 -0700561 *
Andrew Lee59cac3a2014-08-28 16:50:10 -0700562 * @return The phone account handle of the current sim call manager.
Andrew Lee59cac3a2014-08-28 16:50:10 -0700563 */
564 public PhoneAccountHandle getSimCallManager() {
565 try {
566 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700567 return getTelecomService().getSimCallManager();
Andrew Lee59cac3a2014-08-28 16:50:10 -0700568 }
569 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700570 Log.e(TAG, "Error calling ITelecomService#getSimCallManager");
Andrew Lee59cac3a2014-08-28 16:50:10 -0700571 }
572 return null;
573 }
574
575 /**
Sailesh Nepalcf855622015-07-28 19:22:14 -0700576 * Returns the current SIM call manager for the specified user. Apps must be prepared for this
577 * method to return {@code null}, indicating that there currently exists no user-chosen default
578 * {@code PhoneAccount}.
579 *
580 * @return The phone account handle of the current sim call manager.
581 *
582 * @hide
583 */
584 public PhoneAccountHandle getSimCallManager(int userId) {
585 try {
586 if (isServiceConnected()) {
587 return getTelecomService().getSimCallManagerForUser(userId);
588 }
589 } catch (RemoteException e) {
590 Log.e(TAG, "Error calling ITelecomService#getSimCallManagerForUser");
591 }
592 return null;
593 }
594
595 /**
Evan Charltoneb0a8d562014-09-04 12:03:34 -0700596 * Returns the current connection manager. Apps must be prepared for this method to return
597 * {@code null}, indicating that there currently exists no user-chosen default
598 * {@code PhoneAccount}.
599 *
600 * @return The phone account handle of the current connection manager.
Evan Charlton0e094d92014-11-08 15:49:16 -0800601 * @hide
Evan Charltoneb0a8d562014-09-04 12:03:34 -0700602 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800603 @SystemApi
Evan Charltoneb0a8d562014-09-04 12:03:34 -0700604 public PhoneAccountHandle getConnectionManager() {
605 return getSimCallManager();
606 }
607
608 /**
Nancy Chen210ef032014-09-15 17:58:42 -0700609 * Returns a list of the {@link PhoneAccountHandle}s which can be used to make and receive phone
610 * calls which support the specified URI scheme.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700611 * <P>
612 * For example, invoking with {@code "tel"} will find all {@link PhoneAccountHandle}s which
613 * support telephone calls (e.g. URIs such as {@code tel:555-555-1212}). Invoking with
614 * {@code "sip"} will find all {@link PhoneAccountHandle}s which support SIP calls (e.g. URIs
615 * such as {@code sip:example@sipexample.com}).
616 *
617 * @param uriScheme The URI scheme.
618 * @return A list of {@code PhoneAccountHandle} objects supporting the URI scheme.
Evan Charlton0e094d92014-11-08 15:49:16 -0800619 * @hide
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700620 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800621 @SystemApi
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700622 public List<PhoneAccountHandle> getPhoneAccountsSupportingScheme(String uriScheme) {
623 try {
624 if (isServiceConnected()) {
Svet Ganov16a16892015-04-16 10:32:04 -0700625 return getTelecomService().getPhoneAccountsSupportingScheme(uriScheme,
626 mContext.getOpPackageName());
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700627 }
628 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700629 Log.e(TAG, "Error calling ITelecomService#getPhoneAccountsSupportingScheme", e);
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700630 }
631 return new ArrayList<>();
632 }
633
Nancy Chen513c8922014-09-17 14:47:20 -0700634
635 /**
Santos Cordon91371dc02015-05-08 13:52:09 -0700636 * Returns a list of {@link PhoneAccountHandle}s which can be used to make and receive phone
637 * calls. The returned list includes only those accounts which have been explicitly enabled
638 * by the user.
Nancy Chen513c8922014-09-17 14:47:20 -0700639 *
Yorke Leec61d13662015-09-21 17:25:25 -0700640 * Requires permission: {@link android.Manifest.permission#READ_PHONE_STATE}
641 *
Nancy Chen513c8922014-09-17 14:47:20 -0700642 * @see #EXTRA_PHONE_ACCOUNT_HANDLE
643 * @return A list of {@code PhoneAccountHandle} objects.
Nancy Chen513c8922014-09-17 14:47:20 -0700644 */
Yorke Leec61d13662015-09-21 17:25:25 -0700645 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
Nancy Chen513c8922014-09-17 14:47:20 -0700646 public List<PhoneAccountHandle> getCallCapablePhoneAccounts() {
Santos Cordon91371dc02015-05-08 13:52:09 -0700647 return getCallCapablePhoneAccounts(false);
648 }
649
650 /**
651 * Returns a list of {@link PhoneAccountHandle}s including those which have not been enabled
652 * by the user.
653 *
654 * @return A list of {@code PhoneAccountHandle} objects.
655 * @hide
656 */
657 public List<PhoneAccountHandle> getCallCapablePhoneAccounts(boolean includeDisabledAccounts) {
Nancy Chen513c8922014-09-17 14:47:20 -0700658 try {
659 if (isServiceConnected()) {
Santos Cordon91371dc02015-05-08 13:52:09 -0700660 return getTelecomService().getCallCapablePhoneAccounts(
661 includeDisabledAccounts, mContext.getOpPackageName());
Nancy Chen513c8922014-09-17 14:47:20 -0700662 }
663 } catch (RemoteException e) {
Santos Cordon91371dc02015-05-08 13:52:09 -0700664 Log.e(TAG, "Error calling ITelecomService#getCallCapablePhoneAccounts(" +
665 includeDisabledAccounts + ")", e);
Nancy Chen513c8922014-09-17 14:47:20 -0700666 }
667 return new ArrayList<>();
668 }
669
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700670 /**
Nancy Chen513c8922014-09-17 14:47:20 -0700671 * Returns a list of all {@link PhoneAccount}s registered for the calling package.
672 *
673 * @return A list of {@code PhoneAccountHandle} objects.
Evan Charlton0e094d92014-11-08 15:49:16 -0800674 * @hide
Nancy Chen513c8922014-09-17 14:47:20 -0700675 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800676 @SystemApi
Nancy Chen513c8922014-09-17 14:47:20 -0700677 public List<PhoneAccountHandle> getPhoneAccountsForPackage() {
678 try {
679 if (isServiceConnected()) {
680 return getTelecomService().getPhoneAccountsForPackage(mContext.getPackageName());
681 }
682 } catch (RemoteException e) {
683 Log.e(TAG, "Error calling ITelecomService#getPhoneAccountsForPackage", e);
684 }
685 return null;
686 }
687
688 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700689 * Return the {@link PhoneAccount} for a specified {@link PhoneAccountHandle}. Object includes
690 * resources which can be used in a user interface.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700691 *
Evan Charlton6eb262c2014-07-19 18:18:19 -0700692 * @param account The {@link PhoneAccountHandle}.
Evan Charlton8c8a0622014-07-20 12:31:00 -0700693 * @return The {@link PhoneAccount} object.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700694 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700695 public PhoneAccount getPhoneAccount(PhoneAccountHandle account) {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700696 try {
697 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700698 return getTelecomService().getPhoneAccount(account);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700699 }
700 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700701 Log.e(TAG, "Error calling ITelecomService#getPhoneAccount", e);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700702 }
703 return null;
704 }
705
706 /**
Nancy Chen210ef032014-09-15 17:58:42 -0700707 * Returns a count of all {@link PhoneAccount}s.
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700708 *
Nancy Chen210ef032014-09-15 17:58:42 -0700709 * @return The count of {@link PhoneAccount}s.
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700710 * @hide
711 */
712 @SystemApi
713 public int getAllPhoneAccountsCount() {
714 try {
715 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700716 return getTelecomService().getAllPhoneAccountsCount();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700717 }
718 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700719 Log.e(TAG, "Error calling ITelecomService#getAllPhoneAccountsCount", e);
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700720 }
721 return 0;
722 }
723
724 /**
725 * Returns a list of all {@link PhoneAccount}s.
726 *
727 * @return All {@link PhoneAccount}s.
728 * @hide
729 */
730 @SystemApi
731 public List<PhoneAccount> getAllPhoneAccounts() {
732 try {
733 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700734 return getTelecomService().getAllPhoneAccounts();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700735 }
736 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700737 Log.e(TAG, "Error calling ITelecomService#getAllPhoneAccounts", e);
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700738 }
739 return Collections.EMPTY_LIST;
740 }
741
742 /**
743 * Returns a list of all {@link PhoneAccountHandle}s.
744 *
745 * @return All {@link PhoneAccountHandle}s.
746 * @hide
747 */
748 @SystemApi
749 public List<PhoneAccountHandle> getAllPhoneAccountHandles() {
750 try {
751 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700752 return getTelecomService().getAllPhoneAccountHandles();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700753 }
754 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700755 Log.e(TAG, "Error calling ITelecomService#getAllPhoneAccountHandles", e);
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700756 }
757 return Collections.EMPTY_LIST;
758 }
759
760 /**
Santos Cordond9e614f2014-10-28 13:10:36 -0700761 * Register a {@link PhoneAccount} for use by the system. When registering
762 * {@link PhoneAccount}s, existing registrations will be overwritten if the
763 * {@link PhoneAccountHandle} matches that of a {@link PhoneAccount} which is already
764 * registered. Once registered, the {@link PhoneAccount} is listed to the user as an option
765 * when placing calls. The user may still need to enable the {@link PhoneAccount} within
766 * the phone app settings before the account is usable.
767 * <p>
768 * A {@link SecurityException} will be thrown if an app tries to register a
769 * {@link PhoneAccountHandle} where the package name specified within
770 * {@link PhoneAccountHandle#getComponentName()} does not match the package name of the app.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700771 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700772 * @param account The complete {@link PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700773 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700774 public void registerPhoneAccount(PhoneAccount account) {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700775 try {
776 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700777 getTelecomService().registerPhoneAccount(account);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700778 }
779 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700780 Log.e(TAG, "Error calling ITelecomService#registerPhoneAccount", e);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700781 }
782 }
783
784 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700785 * Remove a {@link PhoneAccount} registration from the system.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700786 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700787 * @param accountHandle A {@link PhoneAccountHandle} for the {@link PhoneAccount} to unregister.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700788 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700789 public void unregisterPhoneAccount(PhoneAccountHandle accountHandle) {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700790 try {
791 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700792 getTelecomService().unregisterPhoneAccount(accountHandle);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700793 }
794 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700795 Log.e(TAG, "Error calling ITelecomService#unregisterPhoneAccount", e);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700796 }
797 }
798
799 /**
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700800 * Remove all Accounts that belong to the calling package from the system.
Evan Charlton0e094d92014-11-08 15:49:16 -0800801 * @hide
Ihab Awad807fe0a2014-07-09 12:30:52 -0700802 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800803 @SystemApi
Yorke Lee06044272015-04-14 15:16:59 -0700804 public void clearPhoneAccounts() {
805 clearAccounts();
806 }
807 /**
808 * Remove all Accounts that belong to the calling package from the system.
809 * @deprecated Use {@link #clearPhoneAccounts()} instead.
810 * @hide
811 */
812 @SystemApi
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700813 public void clearAccounts() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700814 try {
815 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700816 getTelecomService().clearAccounts(mContext.getPackageName());
Ihab Awad807fe0a2014-07-09 12:30:52 -0700817 }
818 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700819 Log.e(TAG, "Error calling ITelecomService#clearAccounts", e);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700820 }
821 }
822
823 /**
Anthony Lee67279262014-10-27 11:28:40 -0700824 * Remove all Accounts that belong to the specified package from the system.
825 * @hide
826 */
827 public void clearAccountsForPackage(String packageName) {
828 try {
829 if (isServiceConnected() && !TextUtils.isEmpty(packageName)) {
830 getTelecomService().clearAccounts(packageName);
831 }
832 } catch (RemoteException e) {
Nancy Chen5cf27842015-01-24 23:30:27 -0800833 Log.e(TAG, "Error calling ITelecomService#clearAccountsForPackage", e);
Anthony Lee67279262014-10-27 11:28:40 -0700834 }
835 }
836
Yorke Lee1011f482015-04-23 15:58:27 -0700837
Anthony Lee67279262014-10-27 11:28:40 -0700838 /**
Yorke Lee1011f482015-04-23 15:58:27 -0700839 * @deprecated - Use {@link TelecomManager#getDefaultDialerPackage} to directly access
840 * the default dialer's package name instead.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700841 * @hide
842 */
Santos Cordon6c7a3882014-06-25 15:30:08 -0700843 @SystemApi
844 public ComponentName getDefaultPhoneApp() {
845 try {
Santos Cordon9eb45932014-06-27 12:28:43 -0700846 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700847 return getTelecomService().getDefaultPhoneApp();
Santos Cordon9eb45932014-06-27 12:28:43 -0700848 }
Santos Cordon6c7a3882014-06-25 15:30:08 -0700849 } catch (RemoteException e) {
850 Log.e(TAG, "RemoteException attempting to get the default phone app.", e);
851 }
852 return null;
853 }
854
Santos Cordon9eb45932014-06-27 12:28:43 -0700855 /**
Yorke Lee1011f482015-04-23 15:58:27 -0700856 * Used to determine the currently selected default dialer package.
857 *
858 * @return package name for the default dialer package or null if no package has been
859 * selected as the default dialer.
860 */
861 public String getDefaultDialerPackage() {
862 try {
863 if (isServiceConnected()) {
864 return getTelecomService().getDefaultDialerPackage();
865 }
866 } catch (RemoteException e) {
867 Log.e(TAG, "RemoteException attempting to get the default dialer package name.", e);
868 }
869 return null;
870 }
871
872 /**
Yorke Lee107c4ce2015-06-15 12:08:24 -0700873 * Used to set the default dialer package.
874 *
875 * @param packageName to set the default dialer to..
876 *
877 * @result {@code true} if the default dialer was successfully changed, {@code false} if
878 * the specified package does not correspond to an installed dialer, or is already
879 * the default dialer.
880 *
881 * Requires permission: {@link android.Manifest.permission#MODIFY_PHONE_STATE}
882 * Requires permission: {@link android.Manifest.permission#WRITE_SECURE_SETTINGS}
883 *
884 * @hide
885 */
886 public boolean setDefaultDialer(String packageName) {
887 try {
888 if (isServiceConnected()) {
889 return getTelecomService().setDefaultDialer(packageName);
890 }
891 } catch (RemoteException e) {
892 Log.e(TAG, "RemoteException attempting to set the default dialer.", e);
893 }
894 return false;
895 }
896
897 /**
Yorke Lee1011f482015-04-23 15:58:27 -0700898 * Used to determine the dialer package that is preloaded on the system partition.
899 *
900 * @return package name for the system dialer package or null if no system dialer is preloaded.
901 * @hide
902 */
903 public String getSystemDialerPackage() {
904 try {
905 if (isServiceConnected()) {
906 return getTelecomService().getSystemDialerPackage();
907 }
908 } catch (RemoteException e) {
909 Log.e(TAG, "RemoteException attempting to get the system dialer package name.", e);
910 }
911 return null;
912 }
913
914 /**
Nancy Chen443e5012014-10-15 15:48:21 -0700915 * Return whether a given phone number is the configured voicemail number for a
916 * particular phone account.
917 *
Yorke Leec61d13662015-09-21 17:25:25 -0700918 * Requires permission: {@link android.Manifest.permission#READ_PHONE_STATE}
919 *
Nancy Chen443e5012014-10-15 15:48:21 -0700920 * @param accountHandle The handle for the account to check the voicemail number against
921 * @param number The number to look up.
Nancy Chen443e5012014-10-15 15:48:21 -0700922 */
Yorke Leec61d13662015-09-21 17:25:25 -0700923 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
Nancy Chen443e5012014-10-15 15:48:21 -0700924 public boolean isVoiceMailNumber(PhoneAccountHandle accountHandle, String number) {
925 try {
926 if (isServiceConnected()) {
Svet Ganov16a16892015-04-16 10:32:04 -0700927 return getTelecomService().isVoiceMailNumber(accountHandle, number,
928 mContext.getOpPackageName());
Nancy Chen443e5012014-10-15 15:48:21 -0700929 }
930 } catch (RemoteException e) {
Nancy Chen5cf27842015-01-24 23:30:27 -0800931 Log.e(TAG, "RemoteException calling ITelecomService#isVoiceMailNumber.", e);
Nancy Chen443e5012014-10-15 15:48:21 -0700932 }
933 return false;
934 }
935
936 /**
Yorke Lee49e2d462015-04-15 16:14:22 -0700937 * Return the voicemail number for a given phone account.
Nancy Chen8c066f7c2014-12-03 15:18:08 -0800938 *
Yorke Leec61d13662015-09-21 17:25:25 -0700939 * Requires permission: {@link android.Manifest.permission#READ_PHONE_STATE}
940 *
Yorke Lee49e2d462015-04-15 16:14:22 -0700941 * @param accountHandle The handle for the phone account.
942 * @return The voicemail number for the phone account, and {@code null} if one has not been
943 * configured.
Nancy Chen8c066f7c2014-12-03 15:18:08 -0800944 */
Yorke Leec61d13662015-09-21 17:25:25 -0700945 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
Yorke Lee49e2d462015-04-15 16:14:22 -0700946 public String getVoiceMailNumber(PhoneAccountHandle accountHandle) {
Nancy Chen8c066f7c2014-12-03 15:18:08 -0800947 try {
948 if (isServiceConnected()) {
Svet Ganov16a16892015-04-16 10:32:04 -0700949 return getTelecomService().getVoiceMailNumber(accountHandle,
950 mContext.getOpPackageName());
Nancy Chen8c066f7c2014-12-03 15:18:08 -0800951 }
952 } catch (RemoteException e) {
Nancy Chen5cf27842015-01-24 23:30:27 -0800953 Log.e(TAG, "RemoteException calling ITelecomService#hasVoiceMailNumber.", e);
Nancy Chen8c066f7c2014-12-03 15:18:08 -0800954 }
Yorke Lee49e2d462015-04-15 16:14:22 -0700955 return null;
Nancy Chen8c066f7c2014-12-03 15:18:08 -0800956 }
957
958 /**
Nancy Chen5cf27842015-01-24 23:30:27 -0800959 * Return the line 1 phone number for given phone account.
960 *
Yorke Leec61d13662015-09-21 17:25:25 -0700961 * Requires permission: {@link android.Manifest.permission#READ_PHONE_STATE}
962 *
Nancy Chen5cf27842015-01-24 23:30:27 -0800963 * @param accountHandle The handle for the account retrieve a number for.
964 * @return A string representation of the line 1 phone number.
Nancy Chen5cf27842015-01-24 23:30:27 -0800965 */
Yorke Leec61d13662015-09-21 17:25:25 -0700966 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
Nancy Chen5cf27842015-01-24 23:30:27 -0800967 public String getLine1Number(PhoneAccountHandle accountHandle) {
968 try {
969 if (isServiceConnected()) {
Svet Ganov16a16892015-04-16 10:32:04 -0700970 return getTelecomService().getLine1Number(accountHandle,
971 mContext.getOpPackageName());
Nancy Chen5cf27842015-01-24 23:30:27 -0800972 }
973 } catch (RemoteException e) {
974 Log.e(TAG, "RemoteException calling ITelecomService#getLine1Number.", e);
975 }
976 return null;
977 }
978
979 /**
Santos Cordon9eb45932014-06-27 12:28:43 -0700980 * Returns whether there is an ongoing phone call (can be in dialing, ringing, active or holding
981 * states).
Nancy Chen0eb1e402014-08-21 22:52:29 -0700982 * <p>
983 * Requires permission: {@link android.Manifest.permission#READ_PHONE_STATE}
984 * </p>
Santos Cordon9eb45932014-06-27 12:28:43 -0700985 */
Yorke Leec61d13662015-09-21 17:25:25 -0700986 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
Nancy Chen0eb1e402014-08-21 22:52:29 -0700987 public boolean isInCall() {
Santos Cordon9eb45932014-06-27 12:28:43 -0700988 try {
989 if (isServiceConnected()) {
Svet Ganov16a16892015-04-16 10:32:04 -0700990 return getTelecomService().isInCall(mContext.getOpPackageName());
Santos Cordon9eb45932014-06-27 12:28:43 -0700991 }
992 } catch (RemoteException e) {
Yorke Lee2ae312e2014-09-12 17:58:48 -0700993 Log.e(TAG, "RemoteException calling isInCall().", e);
Santos Cordon9eb45932014-06-27 12:28:43 -0700994 }
995 return false;
996 }
997
998 /**
Yorke Lee2ae312e2014-09-12 17:58:48 -0700999 * Returns one of the following constants that represents the current state of Telecom:
1000 *
1001 * {@link TelephonyManager#CALL_STATE_RINGING}
1002 * {@link TelephonyManager#CALL_STATE_OFFHOOK}
1003 * {@link TelephonyManager#CALL_STATE_IDLE}
Yorke Lee7c72c2d2014-10-28 14:12:02 -07001004 *
1005 * Note that this API does not require the
1006 * {@link android.Manifest.permission#READ_PHONE_STATE} permission. This is intentional, to
1007 * preserve the behavior of {@link TelephonyManager#getCallState()}, which also did not require
1008 * the permission.
Yorke Lee2ae312e2014-09-12 17:58:48 -07001009 * @hide
1010 */
1011 @SystemApi
1012 public int getCallState() {
1013 try {
1014 if (isServiceConnected()) {
1015 return getTelecomService().getCallState();
1016 }
1017 } catch (RemoteException e) {
1018 Log.d(TAG, "RemoteException calling getCallState().", e);
1019 }
1020 return TelephonyManager.CALL_STATE_IDLE;
1021 }
1022
1023 /**
Santos Cordon9eb45932014-06-27 12:28:43 -07001024 * Returns whether there currently exists is a ringing incoming-call.
1025 *
1026 * @hide
1027 */
1028 @SystemApi
1029 public boolean isRinging() {
1030 try {
1031 if (isServiceConnected()) {
Svet Ganov16a16892015-04-16 10:32:04 -07001032 return getTelecomService().isRinging(mContext.getOpPackageName());
Santos Cordon9eb45932014-06-27 12:28:43 -07001033 }
1034 } catch (RemoteException e) {
1035 Log.e(TAG, "RemoteException attempting to get ringing state of phone app.", e);
1036 }
1037 return false;
1038 }
1039
1040 /**
Santos Cordon96efb482014-07-19 14:57:05 -07001041 * Ends an ongoing call.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001042 * TODO: L-release - need to convert all invocations of ITelecomService#endCall to use this
Santos Cordon96efb482014-07-19 14:57:05 -07001043 * method (clockwork & gearhead).
Santos Cordon9eb45932014-06-27 12:28:43 -07001044 * @hide
1045 */
1046 @SystemApi
1047 public boolean endCall() {
1048 try {
1049 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001050 return getTelecomService().endCall();
Santos Cordon9eb45932014-06-27 12:28:43 -07001051 }
1052 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001053 Log.e(TAG, "Error calling ITelecomService#endCall", e);
Santos Cordon9eb45932014-06-27 12:28:43 -07001054 }
1055 return false;
1056 }
1057
1058 /**
1059 * If there is a ringing incoming call, this method accepts the call on behalf of the user.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001060 * TODO: L-release - need to convert all invocation of ITelecmmService#answerRingingCall to use
Santos Cordon96efb482014-07-19 14:57:05 -07001061 * this method (clockwork & gearhead).
Tyler Gunn6676bb52015-10-23 14:39:49 -07001062 * If the incoming call is a video call, the call will be answered with the same video state as
1063 * the incoming call requests. This means, for example, that an incoming call requesting
1064 * {@link VideoProfile#STATE_BIDIRECTIONAL} will be answered, accepting that state.
Santos Cordon9eb45932014-06-27 12:28:43 -07001065 * @hide
1066 */
1067 @SystemApi
1068 public void acceptRingingCall() {
1069 try {
1070 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001071 getTelecomService().acceptRingingCall();
Santos Cordon9eb45932014-06-27 12:28:43 -07001072 }
1073 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001074 Log.e(TAG, "Error calling ITelecomService#acceptRingingCall", e);
Santos Cordon9eb45932014-06-27 12:28:43 -07001075 }
1076 }
1077
1078 /**
Tyler Gunn6676bb52015-10-23 14:39:49 -07001079 * If there is a ringing incoming call, this method accepts the call on behalf of the user,
1080 * with the specified video state.
1081 *
1082 * @param videoState The desired video state to answer the call with.
1083 * @hide
1084 */
1085 @SystemApi
1086 public void acceptRingingCall(int videoState) {
1087 try {
1088 if (isServiceConnected()) {
1089 getTelecomService().acceptRingingCallWithVideoState(videoState);
1090 }
1091 } catch (RemoteException e) {
1092 Log.e(TAG, "Error calling ITelecomService#acceptRingingCallWithVideoState", e);
1093 }
1094 }
1095
1096 /**
Santos Cordon9eb45932014-06-27 12:28:43 -07001097 * Silences the ringer if a ringing call exists.
Yorke Leec61d13662015-09-21 17:25:25 -07001098 *
1099 * Requires permission: {@link android.Manifest.permission#MODIFY_PHONE_STATE}
Santos Cordon9eb45932014-06-27 12:28:43 -07001100 */
Yorke Leec61d13662015-09-21 17:25:25 -07001101 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
Santos Cordon9eb45932014-06-27 12:28:43 -07001102 public void silenceRinger() {
1103 try {
1104 if (isServiceConnected()) {
Yorke Leef1a349b2015-04-29 16:16:50 -07001105 getTelecomService().silenceRinger(mContext.getOpPackageName());
Santos Cordon9eb45932014-06-27 12:28:43 -07001106 }
1107 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001108 Log.e(TAG, "Error calling ITelecomService#silenceRinger", e);
Santos Cordon9eb45932014-06-27 12:28:43 -07001109 }
1110 }
1111
Sailesh Nepal001bbbb2014-07-15 14:40:39 -07001112 /**
1113 * Returns whether TTY is supported on this device.
1114 *
1115 * @hide
1116 */
1117 @SystemApi
1118 public boolean isTtySupported() {
1119 try {
1120 if (isServiceConnected()) {
Svet Ganov16a16892015-04-16 10:32:04 -07001121 return getTelecomService().isTtySupported(mContext.getOpPackageName());
Sailesh Nepal001bbbb2014-07-15 14:40:39 -07001122 }
1123 } catch (RemoteException e) {
1124 Log.e(TAG, "RemoteException attempting to get TTY supported state.", e);
1125 }
1126 return false;
1127 }
1128
1129 /**
1130 * 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 -07001131 * settings and have a wired headset plugged in.
1132 * Valid modes are:
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001133 * - {@link TelecomManager#TTY_MODE_OFF}
1134 * - {@link TelecomManager#TTY_MODE_FULL}
1135 * - {@link TelecomManager#TTY_MODE_HCO}
1136 * - {@link TelecomManager#TTY_MODE_VCO}
Sailesh Nepal001bbbb2014-07-15 14:40:39 -07001137 * @hide
1138 */
1139 public int getCurrentTtyMode() {
1140 try {
1141 if (isServiceConnected()) {
Svet Ganov16a16892015-04-16 10:32:04 -07001142 return getTelecomService().getCurrentTtyMode(mContext.getOpPackageName());
Sailesh Nepal001bbbb2014-07-15 14:40:39 -07001143 }
1144 } catch (RemoteException e) {
1145 Log.e(TAG, "RemoteException attempting to get the current TTY mode.", e);
1146 }
Evan Charlton10197192014-07-19 15:00:29 -07001147 return TTY_MODE_OFF;
Sailesh Nepal001bbbb2014-07-15 14:40:39 -07001148 }
1149
Santos Cordon96efb482014-07-19 14:57:05 -07001150 /**
1151 * Registers a new incoming call. A {@link ConnectionService} should invoke this method when it
1152 * has an incoming call. The specified {@link PhoneAccountHandle} must have been registered
Nancy Chen210ef032014-09-15 17:58:42 -07001153 * with {@link #registerPhoneAccount}. Once invoked, this method will cause the system to bind
1154 * to the {@link ConnectionService} associated with the {@link PhoneAccountHandle} and request
Santos Cordon96efb482014-07-19 14:57:05 -07001155 * additional information about the call (See
1156 * {@link ConnectionService#onCreateIncomingConnection}) before starting the incoming call UI.
1157 *
1158 * @param phoneAccount A {@link PhoneAccountHandle} registered with
1159 * {@link #registerPhoneAccount}.
1160 * @param extras A bundle that will be passed through to
1161 * {@link ConnectionService#onCreateIncomingConnection}.
1162 */
1163 public void addNewIncomingCall(PhoneAccountHandle phoneAccount, Bundle extras) {
1164 try {
1165 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001166 getTelecomService().addNewIncomingCall(
Santos Cordon96efb482014-07-19 14:57:05 -07001167 phoneAccount, extras == null ? new Bundle() : extras);
1168 }
1169 } catch (RemoteException e) {
1170 Log.e(TAG, "RemoteException adding a new incoming call: " + phoneAccount, e);
1171 }
1172 }
1173
Nancy Chen0eb1e402014-08-21 22:52:29 -07001174 /**
Yorke Leec3cf9822014-10-02 09:38:39 -07001175 * Registers a new unknown call with Telecom. This can only be called by the system Telephony
1176 * service. This is invoked when Telephony detects a new unknown connection that was neither
1177 * a new incoming call, nor an user-initiated outgoing call.
1178 *
1179 * @param phoneAccount A {@link PhoneAccountHandle} registered with
1180 * {@link #registerPhoneAccount}.
1181 * @param extras A bundle that will be passed through to
1182 * {@link ConnectionService#onCreateIncomingConnection}.
1183 * @hide
1184 */
1185 @SystemApi
1186 public void addNewUnknownCall(PhoneAccountHandle phoneAccount, Bundle extras) {
1187 try {
1188 if (isServiceConnected()) {
1189 getTelecomService().addNewUnknownCall(
1190 phoneAccount, extras == null ? new Bundle() : extras);
1191 }
1192 } catch (RemoteException e) {
1193 Log.e(TAG, "RemoteException adding a new unknown call: " + phoneAccount, e);
1194 }
1195 }
1196
1197 /**
Nancy Chen0eb1e402014-08-21 22:52:29 -07001198 * Processes the specified dial string as an MMI code.
1199 * MMI codes are any sequence of characters entered into the dialpad that contain a "*" or "#".
1200 * Some of these sequences launch special behavior through handled by Telephony.
Nancy Chen95e8a672014-10-16 18:38:21 -07001201 * This method uses the default subscription.
Nancy Chen0eb1e402014-08-21 22:52:29 -07001202 * <p>
1203 * Requires that the method-caller be set as the system dialer app.
1204 * </p>
1205 *
Yorke Leec61d13662015-09-21 17:25:25 -07001206 * Requires permission: {@link android.Manifest.permission#MODIFY_PHONE_STATE}
1207 *
Nancy Chen0eb1e402014-08-21 22:52:29 -07001208 * @param dialString The digits to dial.
1209 * @return True if the digits were processed as an MMI code, false otherwise.
1210 */
Yorke Leec61d13662015-09-21 17:25:25 -07001211 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
Nancy Chen0eb1e402014-08-21 22:52:29 -07001212 public boolean handleMmi(String dialString) {
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 return service.handlePinMmi(dialString, 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#handlePinMmi", e);
Nancy Chen0eb1e402014-08-21 22:52:29 -07001219 }
1220 }
1221 return false;
1222 }
1223
1224 /**
Nancy Chen95e8a672014-10-16 18:38:21 -07001225 * Processes the specified dial string as an MMI code.
1226 * MMI codes are any sequence of characters entered into the dialpad that contain a "*" or "#".
1227 * Some of these sequences launch special behavior through handled by Telephony.
1228 * <p>
1229 * Requires that the method-caller be set as the system dialer app.
1230 * </p>
1231 *
Yorke Leec61d13662015-09-21 17:25:25 -07001232 * Requires permission: {@link android.Manifest.permission#MODIFY_PHONE_STATE}
1233 *
Nancy Chen95e8a672014-10-16 18:38:21 -07001234 * @param accountHandle The handle for the account the MMI code should apply to.
1235 * @param dialString The digits to dial.
1236 * @return True if the digits were processed as an MMI code, false otherwise.
Nancy Chen95e8a672014-10-16 18:38:21 -07001237 */
Yorke Leec61d13662015-09-21 17:25:25 -07001238 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
Yorke Lee06044272015-04-14 15:16:59 -07001239 public boolean handleMmi(String dialString, PhoneAccountHandle accountHandle) {
Nancy Chen95e8a672014-10-16 18:38:21 -07001240 ITelecomService service = getTelecomService();
1241 if (service != null) {
1242 try {
Yorke Leef1a349b2015-04-29 16:16:50 -07001243 return service.handlePinMmiForPhoneAccount(accountHandle, dialString,
1244 mContext.getOpPackageName());
Nancy Chen95e8a672014-10-16 18:38:21 -07001245 } catch (RemoteException e) {
1246 Log.e(TAG, "Error calling ITelecomService#handlePinMmi", e);
1247 }
1248 }
1249 return false;
1250 }
1251
1252 /**
Yorke Leec61d13662015-09-21 17:25:25 -07001253 * Requires permission: {@link android.Manifest.permission#MODIFY_PHONE_STATE}
1254 *
Nancy Chenb2299c12014-10-29 18:22:11 -07001255 * @param accountHandle The handle for the account to derive an adn query URI for or
1256 * {@code null} to return a URI which will use the default account.
1257 * @return The URI (with the content:// scheme) specific to the specified {@link PhoneAccount}
1258 * for the the content retrieve.
1259 */
Yorke Leec61d13662015-09-21 17:25:25 -07001260 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
Nancy Chenb2299c12014-10-29 18:22:11 -07001261 public Uri getAdnUriForPhoneAccount(PhoneAccountHandle accountHandle) {
1262 ITelecomService service = getTelecomService();
1263 if (service != null && accountHandle != null) {
1264 try {
Yorke Leef1a349b2015-04-29 16:16:50 -07001265 return service.getAdnUriForPhoneAccount(accountHandle, mContext.getOpPackageName());
Nancy Chenb2299c12014-10-29 18:22:11 -07001266 } catch (RemoteException e) {
1267 Log.e(TAG, "Error calling ITelecomService#getAdnUriForPhoneAccount", e);
1268 }
1269 }
1270 return Uri.parse("content://icc/adn");
1271 }
1272
1273 /**
Nancy Chen0eb1e402014-08-21 22:52:29 -07001274 * Removes the missed-call notification if one is present.
1275 * <p>
1276 * Requires that the method-caller be set as the system dialer app.
1277 * </p>
Yorke Leec61d13662015-09-21 17:25:25 -07001278 *
1279 * Requires permission: {@link android.Manifest.permission#MODIFY_PHONE_STATE}
Nancy Chen0eb1e402014-08-21 22:52:29 -07001280 */
Yorke Leec61d13662015-09-21 17:25:25 -07001281 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
Nancy Chen0eb1e402014-08-21 22:52:29 -07001282 public void cancelMissedCallsNotification() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001283 ITelecomService service = getTelecomService();
Nancy Chen0eb1e402014-08-21 22:52:29 -07001284 if (service != null) {
1285 try {
Yorke Leef1a349b2015-04-29 16:16:50 -07001286 service.cancelMissedCallsNotification(mContext.getOpPackageName());
Nancy Chen0eb1e402014-08-21 22:52:29 -07001287 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001288 Log.e(TAG, "Error calling ITelecomService#cancelMissedCallsNotification", e);
Nancy Chen0eb1e402014-08-21 22:52:29 -07001289 }
1290 }
1291 }
1292
1293 /**
1294 * Brings the in-call screen to the foreground if there is an ongoing call. If there is
1295 * currently no ongoing call, then this method does nothing.
1296 * <p>
1297 * Requires that the method-caller be set as the system dialer app or have the
1298 * {@link android.Manifest.permission#READ_PHONE_STATE} permission.
1299 * </p>
1300 *
1301 * @param showDialpad Brings up the in-call dialpad as part of showing the in-call screen.
1302 */
Yorke Leec61d13662015-09-21 17:25:25 -07001303 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
Nancy Chen0eb1e402014-08-21 22:52:29 -07001304 public void showInCallScreen(boolean showDialpad) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001305 ITelecomService service = getTelecomService();
Nancy Chen0eb1e402014-08-21 22:52:29 -07001306 if (service != null) {
1307 try {
Svet Ganov16a16892015-04-16 10:32:04 -07001308 service.showInCallScreen(showDialpad, mContext.getOpPackageName());
Nancy Chen0eb1e402014-08-21 22:52:29 -07001309 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001310 Log.e(TAG, "Error calling ITelecomService#showCallScreen", e);
Nancy Chen0eb1e402014-08-21 22:52:29 -07001311 }
1312 }
1313 }
1314
Yorke Lee3e56ba12015-04-23 12:32:36 -07001315 /**
1316 * Places a new outgoing call to the provided address using the system telecom service with
1317 * the specified extras.
1318 *
1319 * This method is equivalent to placing an outgoing call using {@link Intent#ACTION_CALL},
1320 * except that the outgoing call will always be sent via the system telecom service. If
1321 * method-caller is either the user selected default dialer app or preloaded system dialer
1322 * app, then emergency calls will also be allowed.
1323 *
1324 * Requires permission: {@link android.Manifest.permission#CALL_PHONE}
1325 *
1326 * Usage example:
1327 * <pre>
1328 * Uri uri = Uri.fromParts("tel", "12345", null);
1329 * Bundle extras = new Bundle();
1330 * extras.putBoolean(TelecomManager.EXTRA_START_CALL_WITH_SPEAKERPHONE, true);
1331 * telecomManager.placeCall(uri, extras);
1332 * </pre>
1333 *
Santos Cordon7a060d52015-06-19 14:52:04 -07001334 * The following keys are supported in the supplied extras.
1335 * <ul>
1336 * <li>{@link #EXTRA_OUTGOING_CALL_EXTRAS}</li>
1337 * <li>{@link #EXTRA_PHONE_ACCOUNT_HANDLE}</li>
1338 * <li>{@link #EXTRA_START_CALL_WITH_SPEAKERPHONE}</li>
1339 * <li>{@link #EXTRA_START_CALL_WITH_VIDEO_STATE}</li>
1340 * </ul>
1341 *
Yorke Lee3e56ba12015-04-23 12:32:36 -07001342 * @param address The address to make the call to.
1343 * @param extras Bundle of extras to use with the call.
1344 */
Yorke Leec61d13662015-09-21 17:25:25 -07001345 @RequiresPermission(android.Manifest.permission.CALL_PHONE)
Yorke Lee3e56ba12015-04-23 12:32:36 -07001346 public void placeCall(Uri address, Bundle extras) {
1347 ITelecomService service = getTelecomService();
1348 if (service != null) {
Yorke Leea5d5c1d2015-05-05 16:25:55 -07001349 if (address == null) {
1350 Log.w(TAG, "Cannot place call to empty address.");
1351 }
Yorke Lee3e56ba12015-04-23 12:32:36 -07001352 try {
Yorke Leea5d5c1d2015-05-05 16:25:55 -07001353 service.placeCall(address, extras == null ? new Bundle() : extras,
1354 mContext.getOpPackageName());
Yorke Lee3e56ba12015-04-23 12:32:36 -07001355 } catch (RemoteException e) {
1356 Log.e(TAG, "Error calling ITelecomService#placeCall", e);
1357 }
1358 }
1359 }
1360
Santos Cordon91371dc02015-05-08 13:52:09 -07001361 /**
1362 * Enables and disables specified phone account.
1363 *
1364 * @param handle Handle to the phone account.
1365 * @param isEnabled Enable state of the phone account.
1366 * @hide
1367 */
1368 @SystemApi
1369 public void enablePhoneAccount(PhoneAccountHandle handle, boolean isEnabled) {
1370 ITelecomService service = getTelecomService();
1371 if (service != null) {
1372 try {
1373 service.enablePhoneAccount(handle, isEnabled);
1374 } catch (RemoteException e) {
1375 Log.e(TAG, "Error enablePhoneAbbount", e);
1376 }
1377 }
1378 }
1379
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001380 private ITelecomService getTelecomService() {
Hall Liue1bc2ec2015-10-09 15:58:37 -07001381 if (mTelecomServiceOverride != null) {
1382 return mTelecomServiceOverride;
1383 }
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001384 return ITelecomService.Stub.asInterface(ServiceManager.getService(Context.TELECOM_SERVICE));
Santos Cordon6c7a3882014-06-25 15:30:08 -07001385 }
Santos Cordon9eb45932014-06-27 12:28:43 -07001386
1387 private boolean isServiceConnected() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001388 boolean isConnected = getTelecomService() != null;
Santos Cordon9eb45932014-06-27 12:28:43 -07001389 if (!isConnected) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001390 Log.w(TAG, "Telecom Service not found.");
Santos Cordon9eb45932014-06-27 12:28:43 -07001391 }
1392 return isConnected;
1393 }
Evan Charlton235c1592014-09-05 15:41:23 +00001394}