blob: 9b8c536b0876250387bce5d881d0f18ecce04b69 [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
15package android.telecomm;
16
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;
Santos Cordon96efb482014-07-19 14:57:05 -070020import android.os.Bundle;
Santos Cordon6c7a3882014-06-25 15:30:08 -070021import android.os.RemoteException;
22import android.os.ServiceManager;
23import android.util.Log;
Yorke Leeb4ce1432014-06-09 13:53:23 -070024
25import com.android.internal.telecomm.ITelecommService;
26
Jay Shrauner7746a942014-08-26 12:15:15 -070027import java.util.ArrayList;
Tyler Gunna1ed7d12014-09-08 09:52:22 -070028import java.util.Collections;
Ihab Awad807fe0a2014-07-09 12:30:52 -070029import java.util.List;
30
Yorke Leeb4ce1432014-06-09 13:53:23 -070031/**
32 * Provides access to Telecomm-related functionality.
Santos Cordon96efb482014-07-19 14:57:05 -070033 * TODO: Move this all into PhoneManager.
Yorke Leeb4ce1432014-06-09 13:53:23 -070034 */
35public class TelecommManager {
Ihab Awad807fe0a2014-07-09 12:30:52 -070036
Evan Charlton10197192014-07-19 15:00:29 -070037 /**
Santos Cordon96efb482014-07-19 14:57:05 -070038 * Activity action: Starts the UI for handing an incoming call. This intent starts the in-call
39 * UI by notifying the Telecomm system that an incoming call exists for a specific call service
40 * (see {@link android.telecomm.ConnectionService}). Telecomm reads the Intent extras to find
41 * and bind to the appropriate {@link android.telecomm.ConnectionService} which Telecomm will
42 * ultimately use to control and get information about the call.
43 * <p>
44 * Input: get*Extra field {@link #EXTRA_PHONE_ACCOUNT_HANDLE} contains the component name of the
45 * {@link android.telecomm.ConnectionService} that Telecomm should bind to. Telecomm will then
Evan Charlton10197192014-07-19 15:00:29 -070046 * ask the connection service for more information about the call prior to showing any UI.
47 *
Santos Cordon96efb482014-07-19 14:57:05 -070048 * @hide
Evan Charlton10197192014-07-19 15:00:29 -070049 */
Nancy Chen1d834f52014-09-05 11:03:21 -070050 public static final String ACTION_INCOMING_CALL = "android.telecomm.action.INCOMING_CALL";
Evan Charlton10197192014-07-19 15:00:29 -070051
52 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -070053 * The {@link android.content.Intent} action used to configure a
54 * {@link android.telecomm.ConnectionService}.
Evan Charlton10197192014-07-19 15:00:29 -070055 */
56 public static final String ACTION_CONNECTION_SERVICE_CONFIGURE =
Nancy Chen1d834f52014-09-05 11:03:21 -070057 "android.telecomm.action.CONNECTION_SERVICE_CONFIGURE";
Evan Charlton10197192014-07-19 15:00:29 -070058
59 /**
Yorke Lee3818a892014-07-21 15:57:17 -070060 * The {@link android.content.Intent} action used to show the call settings page.
61 */
62 public static final String ACTION_SHOW_CALL_SETTINGS =
Nancy Chen1d834f52014-09-05 11:03:21 -070063 "android.telecomm.action.SHOW_CALL_SETTINGS";
Yorke Lee3818a892014-07-21 15:57:17 -070064
65 /**
Evan Charlton6d8604f2014-09-04 12:38:17 -070066 * The {@link android.content.Intent} action used to show the settings page used to configure
67 * {@link PhoneAccount} preferences.
68 */
69 public static final String ACTION_CHANGE_PHONE_ACCOUNTS =
Nancy Chen1d834f52014-09-05 11:03:21 -070070 "android.telecomm.action.CHANGE_PHONE_ACCOUNTS";
Evan Charlton6d8604f2014-09-04 12:38:17 -070071
72 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -070073 * Optional extra for {@link android.content.Intent#ACTION_CALL} containing a boolean that
74 * determines whether the speakerphone should be automatically turned on for an outgoing call.
Evan Charlton10197192014-07-19 15:00:29 -070075 */
76 public static final String EXTRA_START_CALL_WITH_SPEAKERPHONE =
Nancy Chen1d834f52014-09-05 11:03:21 -070077 "android.telecomm.extra.START_CALL_WITH_SPEAKERPHONE";
Evan Charlton10197192014-07-19 15:00:29 -070078
79 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -070080 * Optional extra for {@link android.content.Intent#ACTION_CALL} containing an integer that
81 * determines the desired video state for an outgoing call.
Santos Cordon96efb482014-07-19 14:57:05 -070082 * Valid options:
Ihab Awadb19a0bc2014-08-07 19:46:01 -070083 * {@link VideoProfile.VideoState#AUDIO_ONLY},
84 * {@link VideoProfile.VideoState#BIDIRECTIONAL},
85 * {@link VideoProfile.VideoState#RX_ENABLED},
86 * {@link VideoProfile.VideoState#TX_ENABLED}.
Tyler Gunn27d1e252014-08-21 16:38:40 -070087 * @hide
Evan Charlton10197192014-07-19 15:00:29 -070088 */
89 public static final String EXTRA_START_CALL_WITH_VIDEO_STATE =
Nancy Chen1d834f52014-09-05 11:03:21 -070090 "android.telecomm.extra.START_CALL_WITH_VIDEO_STATE";
Evan Charlton10197192014-07-19 15:00:29 -070091
92 /**
Santos Cordon96efb482014-07-19 14:57:05 -070093 * The extra used with an {@link android.content.Intent#ACTION_CALL} and
94 * {@link android.content.Intent#ACTION_DIAL} {@code Intent} to specify a
95 * {@link PhoneAccountHandle} to use when making the call.
Evan Charlton10197192014-07-19 15:00:29 -070096 * <p class="note">
Santos Cordon96efb482014-07-19 14:57:05 -070097 * Retrieve with {@link android.content.Intent#getParcelableExtra(String)}.
Evan Charlton10197192014-07-19 15:00:29 -070098 */
Evan Charlton6eb262c2014-07-19 18:18:19 -070099 public static final String EXTRA_PHONE_ACCOUNT_HANDLE =
Nancy Chen1d834f52014-09-05 11:03:21 -0700100 "android.telecomm.extra.PHONE_ACCOUNT_HANDLE";
Evan Charlton10197192014-07-19 15:00:29 -0700101
102 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700103 * Optional extra for {@link #ACTION_INCOMING_CALL} containing a {@link Bundle} which contains
104 * metadata about the call. This {@link Bundle} will be returned to the
105 * {@link ConnectionService}.
106 *
107 * @hide
Evan Charlton10197192014-07-19 15:00:29 -0700108 */
109 public static final String EXTRA_INCOMING_CALL_EXTRAS =
Nancy Chen1d834f52014-09-05 11:03:21 -0700110 "android.telecomm.extra.INCOMING_CALL_EXTRAS";
Evan Charlton10197192014-07-19 15:00:29 -0700111
112 /**
Nancy Chen10798dc2014-08-08 14:00:25 -0700113 * Optional extra for {@link android.content.Intent#ACTION_CALL} and
114 * {@link android.content.Intent#ACTION_DIAL} {@code Intent} containing a {@link Bundle}
115 * which contains metadata about the call. This {@link Bundle} will be saved into
116 * {@code Call.Details}.
117 *
118 * @hide
119 */
120 public static final String EXTRA_OUTGOING_CALL_EXTRAS =
Nancy Chen1d834f52014-09-05 11:03:21 -0700121 "android.telecomm.extra.OUTGOING_CALL_EXTRAS";
Nancy Chen10798dc2014-08-08 14:00:25 -0700122
123 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700124 * Optional extra for {@link android.telephony.TelephonyManager#ACTION_PHONE_STATE_CHANGED}
125 * containing the disconnect code.
Evan Charlton10197192014-07-19 15:00:29 -0700126 */
127 public static final String EXTRA_CALL_DISCONNECT_CAUSE =
128 "android.telecomm.extra.CALL_DISCONNECT_CAUSE";
129
130 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700131 * Optional extra for {@link android.telephony.TelephonyManager#ACTION_PHONE_STATE_CHANGED}
132 * containing the disconnect message.
Evan Charlton10197192014-07-19 15:00:29 -0700133 */
134 public static final String EXTRA_CALL_DISCONNECT_MESSAGE =
135 "android.telecomm.extra.CALL_DISCONNECT_MESSAGE";
136
137 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700138 * Optional extra for {@link android.telephony.TelephonyManager#ACTION_PHONE_STATE_CHANGED}
139 * containing the component name of the associated connection service.
Evan Charlton10197192014-07-19 15:00:29 -0700140 */
141 public static final String EXTRA_CONNECTION_SERVICE =
142 "android.telecomm.extra.CONNECTION_SERVICE";
143
144 /**
145 * The number which the party on the other side of the line will see (and use to return the
146 * call).
147 * <p>
Santos Cordon96efb482014-07-19 14:57:05 -0700148 * {@link ConnectionService}s which interact with {@link RemoteConnection}s should only populate
149 * this if the {@link android.telephony.TelephonyManager#getLine1Number()} value, as that is the
150 * user's expected caller ID.
Evan Charlton10197192014-07-19 15:00:29 -0700151 */
152 public static final String EXTRA_CALL_BACK_NUMBER = "android.telecomm.extra.CALL_BACK_NUMBER";
153
154 /**
155 * The dual tone multi-frequency signaling character sent to indicate the dialing system should
156 * pause for a predefined period.
157 */
158 public static final char DTMF_CHARACTER_PAUSE = ',';
159
160 /**
161 * The dual-tone multi-frequency signaling character sent to indicate the dialing system should
162 * wait for user confirmation before proceeding.
163 */
164 public static final char DTMF_CHARACTER_WAIT = ';';
165
166 /**
167 * TTY (teletypewriter) mode is off.
168 *
169 * @hide
170 */
171 public static final int TTY_MODE_OFF = 0;
172
173 /**
174 * TTY (teletypewriter) mode is on. The speaker is off and the microphone is muted. The user
175 * will communicate with the remote party by sending and receiving text messages.
176 *
177 * @hide
178 */
179 public static final int TTY_MODE_FULL = 1;
180
181 /**
182 * TTY (teletypewriter) mode is in hearing carryover mode (HCO). The microphone is muted but the
183 * speaker is on. The user will communicate with the remote party by sending text messages and
184 * hearing an audible reply.
185 *
186 * @hide
187 */
188 public static final int TTY_MODE_HCO = 2;
189
190 /**
191 * TTY (teletypewriter) mode is in voice carryover mode (VCO). The speaker is off but the
192 * microphone is still on. User will communicate with the remote party by speaking and receiving
193 * text message replies.
194 *
195 * @hide
196 */
197 public static final int TTY_MODE_VCO = 3;
198
199 /**
200 * Broadcast intent action indicating that the current TTY mode has changed. An intent extra
201 * provides this state as an int.
Evan Charlton10197192014-07-19 15:00:29 -0700202 *
Santos Cordon96efb482014-07-19 14:57:05 -0700203 * @see #EXTRA_CURRENT_TTY_MODE
Evan Charlton10197192014-07-19 15:00:29 -0700204 * @hide
205 */
206 public static final String ACTION_CURRENT_TTY_MODE_CHANGED =
Nancy Chen1d834f52014-09-05 11:03:21 -0700207 "android.telecomm.action.CURRENT_TTY_MODE_CHANGED";
Evan Charlton10197192014-07-19 15:00:29 -0700208
209 /**
210 * The lookup key for an int that indicates the current TTY mode.
211 * Valid modes are:
212 * - {@link #TTY_MODE_OFF}
213 * - {@link #TTY_MODE_FULL}
214 * - {@link #TTY_MODE_HCO}
215 * - {@link #TTY_MODE_VCO}
216 *
217 * @hide
218 */
219 public static final String EXTRA_CURRENT_TTY_MODE =
220 "android.telecomm.intent.extra.CURRENT_TTY_MODE";
221
222 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700223 * Broadcast intent action indicating that the TTY preferred operating mode has changed. An
224 * intent extra provides the new mode as an int.
Evan Charlton10197192014-07-19 15:00:29 -0700225 *
Santos Cordon96efb482014-07-19 14:57:05 -0700226 * @see #EXTRA_TTY_PREFERRED_MODE
Evan Charlton10197192014-07-19 15:00:29 -0700227 * @hide
228 */
229 public static final String ACTION_TTY_PREFERRED_MODE_CHANGED =
Nancy Chen1d834f52014-09-05 11:03:21 -0700230 "android.telecomm.action.TTY_PREFERRED_MODE_CHANGED";
Evan Charlton10197192014-07-19 15:00:29 -0700231
232 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700233 * The lookup key for an int that indicates preferred TTY mode. Valid modes are: -
234 * {@link #TTY_MODE_OFF} - {@link #TTY_MODE_FULL} - {@link #TTY_MODE_HCO} -
235 * {@link #TTY_MODE_VCO}
Evan Charlton10197192014-07-19 15:00:29 -0700236 *
237 * @hide
238 */
239 public static final String EXTRA_TTY_PREFERRED_MODE =
240 "android.telecomm.intent.extra.TTY_PREFERRED";
241
Nancy Chen9d568c02014-09-08 14:17:59 -0700242 /**
243 * The following 4 constants define how properties such as phone numbers and names are
244 * displayed to the user.
245 */
246
247 /** Property is displayed normally. */
248 public static final int PRESENTATION_ALLOWED = 1;
249
250 /** Property was blocked. */
251 public static final int PRESENTATION_RESTRICTED = 2;
252
253 /** Presentation was not specified or is unknown. */
254 public static final int PRESENTATION_UNKNOWN = 3;
255
256 /** Property should be displayed as a pay phone. */
257 public static final int PRESENTATION_PAYPHONE = 4;
258
Yorke Leeb4ce1432014-06-09 13:53:23 -0700259 private static final String TAG = "TelecommManager";
Santos Cordon96efb482014-07-19 14:57:05 -0700260
Santos Cordon6c7a3882014-06-25 15:30:08 -0700261 private static final String TELECOMM_SERVICE_NAME = "telecomm";
Yorke Leeb4ce1432014-06-09 13:53:23 -0700262
263 private final Context mContext;
Yorke Leeb4ce1432014-06-09 13:53:23 -0700264
Santos Cordon6c7a3882014-06-25 15:30:08 -0700265 /**
266 * @hide
267 */
Yorke Leeb4ce1432014-06-09 13:53:23 -0700268 public static TelecommManager from(Context context) {
269 return (TelecommManager) context.getSystemService(Context.TELECOMM_SERVICE);
270 }
Santos Cordon6c7a3882014-06-25 15:30:08 -0700271
272 /**
273 * @hide
274 */
Ihab Awad807fe0a2014-07-09 12:30:52 -0700275 public TelecommManager(Context context) {
276 Context appContext = context.getApplicationContext();
277 if (appContext != null) {
278 mContext = appContext;
279 } else {
280 mContext = context;
281 }
282 }
283
284 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700285 * Return the {@link PhoneAccount} which is the user-chosen default for making outgoing phone
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700286 * calls with a specified URI scheme. This {@code PhoneAccount} will always be a member of the
287 * list which is returned from calling {@link #getEnabledPhoneAccounts()}.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700288 * <p>
Santos Cordon96efb482014-07-19 14:57:05 -0700289 * Apps must be prepared for this method to return {@code null}, indicating that there currently
290 * exists no user-chosen default {@code PhoneAccount}. In this case, apps wishing to initiate a
291 * phone call must either create their {@link android.content .Intent#ACTION_CALL} or
292 * {@link android.content.Intent#ACTION_DIAL} {@code Intent} with no
293 * {@link TelecommManager#EXTRA_PHONE_ACCOUNT_HANDLE}, or present the user with an affordance to
294 * select one of the elements of {@link #getEnabledPhoneAccounts()}.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700295 * <p>
296 * An {@link android.content.Intent#ACTION_CALL} or {@link android.content.Intent#ACTION_DIAL}
Evan Charlton6eb262c2014-07-19 18:18:19 -0700297 * {@code Intent} with no {@link TelecommManager#EXTRA_PHONE_ACCOUNT_HANDLE} is valid, and
298 * subsequent steps in the phone call flow are responsible for presenting the user with an
Evan Charlton8c8a0622014-07-20 12:31:00 -0700299 * affordance, if necessary, to choose a {@code PhoneAccount}.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700300 *
301 * @param uriScheme The URI scheme.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700302 */
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700303 public PhoneAccountHandle getDefaultOutgoingPhoneAccount(String uriScheme) {
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700304 try {
305 if (isServiceConnected()) {
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700306 return getTelecommService().getDefaultOutgoingPhoneAccount(uriScheme);
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700307 }
308 } catch (RemoteException e) {
309 Log.e(TAG, "Error calling ITelecommService#getDefaultOutgoingPhoneAccount", e);
310 }
311 return null;
312 }
313
314 /**
Andrew Leed4abbfb2014-09-03 14:58:27 -0700315 * Return the {@link PhoneAccount} which is the user-chosen default for making outgoing phone
316 * calls. This {@code PhoneAccount} will always be a member of the list which is returned from
317 * calling {@link #getEnabledPhoneAccounts()}
318 *
319 * Apps must be prepared for this method to return {@code null}, indicating that there currently
320 * exists no user-chosen default {@code PhoneAccount}.
321 *
322 * @return The user outgoing phone account selected by the user.
323 * @hide
324 */
325 public PhoneAccountHandle getUserSelectedOutgoingPhoneAccount() {
326 try {
327 if (isServiceConnected()) {
328 return getTelecommService().getUserSelectedOutgoingPhoneAccount();
329 }
330 } catch (RemoteException e) {
331 Log.e(TAG, "Error calling ITelecommService#getUserSelectedOutgoingPhoneAccount", e);
332 }
333 return null;
334 }
335
336 /**
Andrew Lee59cac3a2014-08-28 16:50:10 -0700337 * Sets the default account for making outgoing phone calls.
338 * @hide
339 */
Andrew Leed4abbfb2014-09-03 14:58:27 -0700340 public void setUserSelectedOutgoingPhoneAccount(PhoneAccountHandle accountHandle) {
Andrew Lee59cac3a2014-08-28 16:50:10 -0700341 try {
342 if (isServiceConnected()) {
Andrew Leed4abbfb2014-09-03 14:58:27 -0700343 getTelecommService().setUserSelectedOutgoingPhoneAccount(accountHandle);
Andrew Lee59cac3a2014-08-28 16:50:10 -0700344 }
345 } catch (RemoteException e) {
Andrew Leed4abbfb2014-09-03 14:58:27 -0700346 Log.e(TAG, "Error calling ITelecommService#setUserSelectedOutgoingPhoneAccount");
Andrew Lee59cac3a2014-08-28 16:50:10 -0700347 }
348 }
349
350 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700351 * Return a list of enabled {@link PhoneAccountHandle}s which can be used to make and receive
352 * phone calls.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700353 *
Evan Charlton6eb262c2014-07-19 18:18:19 -0700354 * @see #EXTRA_PHONE_ACCOUNT_HANDLE
355 * @return A list of {@code PhoneAccountHandle} objects.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700356 */
Evan Charlton6eb262c2014-07-19 18:18:19 -0700357 public List<PhoneAccountHandle> getEnabledPhoneAccounts() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700358 try {
359 if (isServiceConnected()) {
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700360 return getTelecommService().getEnabledPhoneAccounts();
Ihab Awad807fe0a2014-07-09 12:30:52 -0700361 }
362 } catch (RemoteException e) {
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700363 Log.e(TAG, "Error calling ITelecommService#getEnabledPhoneAccounts", e);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700364 }
Jay Shrauner7746a942014-08-26 12:15:15 -0700365 return new ArrayList<>();
Ihab Awad807fe0a2014-07-09 12:30:52 -0700366 }
367
368 /**
Andrew Lee59cac3a2014-08-28 16:50:10 -0700369 * Returns the current SIM call manager. Apps must be prepared for this method to return
370 * {@code null}, indicating that there currently exists no user-chosen default
371 * {@code PhoneAccount}.
372 * @return The phone account handle of the current sim call manager.
373 * @hide
374 */
375 public PhoneAccountHandle getSimCallManager() {
376 try {
377 if (isServiceConnected()) {
378 return getTelecommService().getSimCallManager();
379 }
380 } catch (RemoteException e) {
381 Log.e(TAG, "Error calling ITelecommService#getSimCallManager");
382 }
383 return null;
384 }
385
386 /**
387 * Sets the SIM call manager to the specified phone account.
388 * @param accountHandle The phone account handle of the account to set as the sim call manager.
389 * @hide
390 */
391 public void setSimCallManager(PhoneAccountHandle accountHandle) {
392 try {
393 if (isServiceConnected()) {
394 getTelecommService().setSimCallManager(accountHandle);
395 }
396 } catch (RemoteException e) {
397 Log.e(TAG, "Error calling ITelecommService#setSimCallManager");
398 }
399 }
400
401 /**
402 * Returns the list of registered SIM call managers.
403 * @return List of registered SIM call managers.
404 * @hide
405 */
406 public List<PhoneAccountHandle> getSimCallManagers() {
407 try {
408 if (isServiceConnected()) {
409 return getTelecommService().getSimCallManagers();
410 }
411 } catch (RemoteException e) {
412 Log.e(TAG, "Error calling ITelecommService#getSimCallManagers");
413 }
414 return new ArrayList<>();
415 }
416
417 /**
Evan Charltoneb0a8d52014-09-04 12:03:34 -0700418 * Returns the current connection manager. Apps must be prepared for this method to return
419 * {@code null}, indicating that there currently exists no user-chosen default
420 * {@code PhoneAccount}.
421 *
422 * @return The phone account handle of the current connection manager.
423 */
424 public PhoneAccountHandle getConnectionManager() {
425 return getSimCallManager();
426 }
427
428 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700429 * Returns a list of the enabled {@link PhoneAccountHandle}s which can be used to make and
430 * receive phone calls which support the specified URI scheme.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700431 * <P>
432 * For example, invoking with {@code "tel"} will find all {@link PhoneAccountHandle}s which
433 * support telephone calls (e.g. URIs such as {@code tel:555-555-1212}). Invoking with
434 * {@code "sip"} will find all {@link PhoneAccountHandle}s which support SIP calls (e.g. URIs
435 * such as {@code sip:example@sipexample.com}).
436 *
437 * @param uriScheme The URI scheme.
438 * @return A list of {@code PhoneAccountHandle} objects supporting the URI scheme.
439 */
440 public List<PhoneAccountHandle> getPhoneAccountsSupportingScheme(String uriScheme) {
441 try {
442 if (isServiceConnected()) {
443 return getTelecommService().getPhoneAccountsSupportingScheme(uriScheme);
444 }
445 } catch (RemoteException e) {
446 Log.e(TAG, "Error calling ITelecommService#getPhoneAccountsSupportingScheme", e);
447 }
448 return new ArrayList<>();
449 }
450
451 /**
Nancy Chen60801182014-07-22 16:56:49 -0700452 * Determine whether the device has more than one account registered and enabled.
453 *
454 * @return {@code true} if the device has more than one account registered and enabled and
455 * {@code false} otherwise.
456 */
457 public boolean hasMultipleEnabledAccounts() {
458 return getEnabledPhoneAccounts().size() > 1;
459 }
460
461 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700462 * Return the {@link PhoneAccount} for a specified {@link PhoneAccountHandle}. Object includes
463 * resources which can be used in a user interface.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700464 *
Evan Charlton6eb262c2014-07-19 18:18:19 -0700465 * @param account The {@link PhoneAccountHandle}.
Evan Charlton8c8a0622014-07-20 12:31:00 -0700466 * @return The {@link PhoneAccount} object.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700467 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700468 public PhoneAccount getPhoneAccount(PhoneAccountHandle account) {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700469 try {
470 if (isServiceConnected()) {
Evan Charlton8c8a0622014-07-20 12:31:00 -0700471 return getTelecommService().getPhoneAccount(account);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700472 }
473 } catch (RemoteException e) {
Evan Charlton8c8a0622014-07-20 12:31:00 -0700474 Log.e(TAG, "Error calling ITelecommService#getPhoneAccount", e);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700475 }
476 return null;
477 }
478
479 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700480 * Returns a count of enabled and disabled {@link PhoneAccount}s.
481 *
482 * @return The count of enabled and disabled {@link PhoneAccount}s.
483 * @hide
484 */
485 @SystemApi
486 public int getAllPhoneAccountsCount() {
487 try {
488 if (isServiceConnected()) {
489 return getTelecommService().getAllPhoneAccountsCount();
490 }
491 } catch (RemoteException e) {
492 Log.e(TAG, "Error calling ITelecommService#getAllPhoneAccountsCount", e);
493 }
494 return 0;
495 }
496
497 /**
498 * Returns a list of all {@link PhoneAccount}s.
499 *
500 * @return All {@link PhoneAccount}s.
501 * @hide
502 */
503 @SystemApi
504 public List<PhoneAccount> getAllPhoneAccounts() {
505 try {
506 if (isServiceConnected()) {
507 return getTelecommService().getAllPhoneAccounts();
508 }
509 } catch (RemoteException e) {
510 Log.e(TAG, "Error calling ITelecommService#getAllPhoneAccounts", e);
511 }
512 return Collections.EMPTY_LIST;
513 }
514
515 /**
516 * Returns a list of all {@link PhoneAccountHandle}s.
517 *
518 * @return All {@link PhoneAccountHandle}s.
519 * @hide
520 */
521 @SystemApi
522 public List<PhoneAccountHandle> getAllPhoneAccountHandles() {
523 try {
524 if (isServiceConnected()) {
525 return getTelecommService().getAllPhoneAccountHandles();
526 }
527 } catch (RemoteException e) {
528 Log.e(TAG, "Error calling ITelecommService#getAllPhoneAccountHandles", e);
529 }
530 return Collections.EMPTY_LIST;
531 }
532
533 /**
534 * Enables or disables a {@link PhoneAccount}.
535 *
536 * @param account The {@link PhoneAccountHandle} to enable or disable.
537 * @param isEnabled {@code True} if the phone account should be enabled.
538 * @hide
539 */
540 @SystemApi
541 public void setPhoneAccountEnabled(PhoneAccountHandle account, boolean isEnabled) {
542 try {
543 if (isServiceConnected()) {
544 getTelecommService().setPhoneAccountEnabled(account, isEnabled);
545 }
546 } catch (RemoteException e) {
547 Log.e(TAG, "Error calling ITelecommService#setPhoneAccountEnabled", e);
548 }
549 }
550
551 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700552 * Register a {@link PhoneAccount} for use by the system.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700553 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700554 * @param account The complete {@link PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700555 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700556 public void registerPhoneAccount(PhoneAccount account) {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700557 try {
558 if (isServiceConnected()) {
Evan Charlton8c8a0622014-07-20 12:31:00 -0700559 getTelecommService().registerPhoneAccount(account);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700560 }
561 } catch (RemoteException e) {
562 Log.e(TAG, "Error calling ITelecommService#registerPhoneAccount", e);
563 }
564 }
565
566 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700567 * Remove a {@link PhoneAccount} registration from the system.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700568 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700569 * @param accountHandle A {@link PhoneAccountHandle} for the {@link PhoneAccount} to unregister.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700570 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700571 public void unregisterPhoneAccount(PhoneAccountHandle accountHandle) {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700572 try {
573 if (isServiceConnected()) {
Evan Charlton8c8a0622014-07-20 12:31:00 -0700574 getTelecommService().unregisterPhoneAccount(accountHandle);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700575 }
576 } catch (RemoteException e) {
577 Log.e(TAG, "Error calling ITelecommService#unregisterPhoneAccount", e);
578 }
579 }
580
581 /**
582 * Remove all Accounts for a given package from the system.
583 *
584 * @param packageName A package name that may have registered Accounts.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700585 */
586 @SystemApi
587 public void clearAccounts(String packageName) {
588 try {
589 if (isServiceConnected()) {
590 getTelecommService().clearAccounts(packageName);
591 }
592 } catch (RemoteException e) {
593 Log.e(TAG, "Error calling ITelecommService#clearAccounts", e);
594 }
595 }
596
597 /**
598 * @hide
599 */
Santos Cordon6c7a3882014-06-25 15:30:08 -0700600 @SystemApi
601 public ComponentName getDefaultPhoneApp() {
602 try {
Santos Cordon9eb45932014-06-27 12:28:43 -0700603 if (isServiceConnected()) {
604 return getTelecommService().getDefaultPhoneApp();
605 }
Santos Cordon6c7a3882014-06-25 15:30:08 -0700606 } catch (RemoteException e) {
607 Log.e(TAG, "RemoteException attempting to get the default phone app.", e);
608 }
609 return null;
610 }
611
Santos Cordon9eb45932014-06-27 12:28:43 -0700612 /**
613 * Returns whether there is an ongoing phone call (can be in dialing, ringing, active or holding
614 * states).
Nancy Chen0eb1e402014-08-21 22:52:29 -0700615 * <p>
616 * Requires permission: {@link android.Manifest.permission#READ_PHONE_STATE}
617 * </p>
Santos Cordon9eb45932014-06-27 12:28:43 -0700618 */
619 @SystemApi
Nancy Chen0eb1e402014-08-21 22:52:29 -0700620 public boolean isInCall() {
Santos Cordon9eb45932014-06-27 12:28:43 -0700621 try {
622 if (isServiceConnected()) {
Nancy Chen0eb1e402014-08-21 22:52:29 -0700623 return getTelecommService().isInCall();
Santos Cordon9eb45932014-06-27 12:28:43 -0700624 }
625 } catch (RemoteException e) {
626 Log.e(TAG, "RemoteException attempting to get default phone app.", e);
627 }
628 return false;
629 }
630
631 /**
632 * Returns whether there currently exists is a ringing incoming-call.
633 *
634 * @hide
635 */
636 @SystemApi
637 public boolean isRinging() {
638 try {
639 if (isServiceConnected()) {
640 return getTelecommService().isRinging();
641 }
642 } catch (RemoteException e) {
643 Log.e(TAG, "RemoteException attempting to get ringing state of phone app.", e);
644 }
645 return false;
646 }
647
648 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700649 * Ends an ongoing call.
650 * TODO: L-release - need to convert all invocations of ITelecommService#endCall to use this
651 * method (clockwork & gearhead).
Santos Cordon9eb45932014-06-27 12:28:43 -0700652 * @hide
653 */
654 @SystemApi
655 public boolean endCall() {
656 try {
657 if (isServiceConnected()) {
658 return getTelecommService().endCall();
659 }
660 } catch (RemoteException e) {
661 Log.e(TAG, "Error calling ITelecommService#endCall", e);
662 }
663 return false;
664 }
665
666 /**
667 * If there is a ringing incoming call, this method accepts the call on behalf of the user.
Santos Cordon96efb482014-07-19 14:57:05 -0700668 * TODO: L-release - need to convert all invocation of ITelecommService#answerRingingCall to use
669 * this method (clockwork & gearhead).
Santos Cordon9eb45932014-06-27 12:28:43 -0700670 *
671 * @hide
672 */
673 @SystemApi
674 public void acceptRingingCall() {
675 try {
676 if (isServiceConnected()) {
677 getTelecommService().acceptRingingCall();
678 }
679 } catch (RemoteException e) {
680 Log.e(TAG, "Error calling ITelecommService#acceptRingingCall", e);
681 }
682 }
683
684 /**
685 * Silences the ringer if a ringing call exists.
686 *
687 * @hide
688 */
689 @SystemApi
690 public void silenceRinger() {
691 try {
692 if (isServiceConnected()) {
693 getTelecommService().silenceRinger();
694 }
695 } catch (RemoteException e) {
696 Log.e(TAG, "Error calling ITelecommService#silenceRinger", e);
697 }
698 }
699
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700700 /**
701 * Returns whether TTY is supported on this device.
702 *
703 * @hide
704 */
705 @SystemApi
706 public boolean isTtySupported() {
707 try {
708 if (isServiceConnected()) {
709 return getTelecommService().isTtySupported();
710 }
711 } catch (RemoteException e) {
712 Log.e(TAG, "RemoteException attempting to get TTY supported state.", e);
713 }
714 return false;
715 }
716
717 /**
718 * 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 -0700719 * settings and have a wired headset plugged in.
720 * Valid modes are:
Evan Charlton10197192014-07-19 15:00:29 -0700721 * - {@link TelecommManager#TTY_MODE_OFF}
722 * - {@link TelecommManager#TTY_MODE_FULL}
723 * - {@link TelecommManager#TTY_MODE_HCO}
724 * - {@link TelecommManager#TTY_MODE_VCO}
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700725 * @hide
726 */
727 public int getCurrentTtyMode() {
728 try {
729 if (isServiceConnected()) {
730 return getTelecommService().getCurrentTtyMode();
731 }
732 } catch (RemoteException e) {
733 Log.e(TAG, "RemoteException attempting to get the current TTY mode.", e);
734 }
Evan Charlton10197192014-07-19 15:00:29 -0700735 return TTY_MODE_OFF;
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700736 }
737
Santos Cordon96efb482014-07-19 14:57:05 -0700738 /**
739 * Registers a new incoming call. A {@link ConnectionService} should invoke this method when it
740 * has an incoming call. The specified {@link PhoneAccountHandle} must have been registered
741 * with {@link #registerPhoneAccount} and subsequently enabled by the user within the phone's
742 * settings. Once invoked, this method will cause the system to bind to the
743 * {@link ConnectionService} associated with the {@link PhoneAccountHandle} and request
744 * additional information about the call (See
745 * {@link ConnectionService#onCreateIncomingConnection}) before starting the incoming call UI.
746 *
747 * @param phoneAccount A {@link PhoneAccountHandle} registered with
748 * {@link #registerPhoneAccount}.
749 * @param extras A bundle that will be passed through to
750 * {@link ConnectionService#onCreateIncomingConnection}.
751 */
752 public void addNewIncomingCall(PhoneAccountHandle phoneAccount, Bundle extras) {
753 try {
754 if (isServiceConnected()) {
755 getTelecommService().addNewIncomingCall(
756 phoneAccount, extras == null ? new Bundle() : extras);
757 }
758 } catch (RemoteException e) {
759 Log.e(TAG, "RemoteException adding a new incoming call: " + phoneAccount, e);
760 }
761 }
762
Nancy Chen0eb1e402014-08-21 22:52:29 -0700763 /**
764 * Processes the specified dial string as an MMI code.
765 * MMI codes are any sequence of characters entered into the dialpad that contain a "*" or "#".
766 * Some of these sequences launch special behavior through handled by Telephony.
767 * <p>
768 * Requires that the method-caller be set as the system dialer app.
769 * </p>
770 *
771 * @param dialString The digits to dial.
772 * @return True if the digits were processed as an MMI code, false otherwise.
773 */
774 public boolean handleMmi(String dialString) {
775 ITelecommService service = getTelecommService();
776 if (service != null) {
777 try {
778 return service.handlePinMmi(dialString);
779 } catch (RemoteException e) {
780 Log.e(TAG, "Error calling ITelecommService#handlePinMmi", e);
781 }
782 }
783 return false;
784 }
785
786 /**
787 * Removes the missed-call notification if one is present.
788 * <p>
789 * Requires that the method-caller be set as the system dialer app.
790 * </p>
791 */
792 public void cancelMissedCallsNotification() {
793 ITelecommService service = getTelecommService();
794 if (service != null) {
795 try {
796 service.cancelMissedCallsNotification();
797 } catch (RemoteException e) {
798 Log.e(TAG, "Error calling ITelecommService#cancelMissedCallsNotification", e);
799 }
800 }
801 }
802
803 /**
804 * Brings the in-call screen to the foreground if there is an ongoing call. If there is
805 * currently no ongoing call, then this method does nothing.
806 * <p>
807 * Requires that the method-caller be set as the system dialer app or have the
808 * {@link android.Manifest.permission#READ_PHONE_STATE} permission.
809 * </p>
810 *
811 * @param showDialpad Brings up the in-call dialpad as part of showing the in-call screen.
812 */
813 public void showInCallScreen(boolean showDialpad) {
814 ITelecommService service = getTelecommService();
815 if (service != null) {
816 try {
817 service.showInCallScreen(showDialpad);
818 } catch (RemoteException e) {
819 Log.e(TAG, "Error calling ITelecommService#showCallScreen", e);
820 }
821 }
822 }
823
Santos Cordon6c7a3882014-06-25 15:30:08 -0700824 private ITelecommService getTelecommService() {
825 return ITelecommService.Stub.asInterface(ServiceManager.getService(TELECOMM_SERVICE_NAME));
826 }
Santos Cordon9eb45932014-06-27 12:28:43 -0700827
828 private boolean isServiceConnected() {
829 boolean isConnected = getTelecommService() != null;
830 if (!isConnected) {
831 Log.w(TAG, "Telecomm Service not found.");
832 }
833 return isConnected;
834 }
Evan Charlton235c1592014-09-05 15:41:23 +0000835}