blob: a19f51bc459d968e90e32b1f3a61fd065d600899 [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 /**
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700145 * An optional {@link android.content.Intent#ACTION_CALL} intent extra denoting the
146 * package name of the app specifying an alternative gateway for the call.
147 * The value is a string.
148 *
149 * (The following comment corresponds to the all GATEWAY_* extras)
150 * An app which sends the {@link android.content.Intent#ACTION_CALL} intent can specify an
151 * alternative address to dial which is different from the one specified and displayed to
152 * the user. This alternative address is referred to as the gateway address.
153 */
154 public static final String GATEWAY_PROVIDER_PACKAGE =
155 "android.telecomm.extra.GATEWAY_PROVIDER_PACKAGE";
156
157 /**
158 * An optional {@link android.content.Intent#ACTION_CALL} intent extra corresponding to the
159 * original address to dial for the call. This is used when an alternative gateway address is
160 * provided to recall the original address.
161 * The value is a {@link android.net.Uri}.
162 *
163 * (See {@link #GATEWAY_PROVIDER_PACKAGE} for details)
164 */
165 public static final String GATEWAY_ORIGINAL_ADDRESS =
166 "android.telecomm.extra.GATEWAY_ORIGINAL_ADDRESS";
167
168 /**
Evan Charlton10197192014-07-19 15:00:29 -0700169 * The number which the party on the other side of the line will see (and use to return the
170 * call).
171 * <p>
Santos Cordon96efb482014-07-19 14:57:05 -0700172 * {@link ConnectionService}s which interact with {@link RemoteConnection}s should only populate
173 * this if the {@link android.telephony.TelephonyManager#getLine1Number()} value, as that is the
174 * user's expected caller ID.
Evan Charlton10197192014-07-19 15:00:29 -0700175 */
176 public static final String EXTRA_CALL_BACK_NUMBER = "android.telecomm.extra.CALL_BACK_NUMBER";
177
178 /**
179 * The dual tone multi-frequency signaling character sent to indicate the dialing system should
180 * pause for a predefined period.
181 */
182 public static final char DTMF_CHARACTER_PAUSE = ',';
183
184 /**
185 * The dual-tone multi-frequency signaling character sent to indicate the dialing system should
186 * wait for user confirmation before proceeding.
187 */
188 public static final char DTMF_CHARACTER_WAIT = ';';
189
190 /**
191 * TTY (teletypewriter) mode is off.
192 *
193 * @hide
194 */
195 public static final int TTY_MODE_OFF = 0;
196
197 /**
198 * TTY (teletypewriter) mode is on. The speaker is off and the microphone is muted. The user
199 * will communicate with the remote party by sending and receiving text messages.
200 *
201 * @hide
202 */
203 public static final int TTY_MODE_FULL = 1;
204
205 /**
206 * TTY (teletypewriter) mode is in hearing carryover mode (HCO). The microphone is muted but the
207 * speaker is on. The user will communicate with the remote party by sending text messages and
208 * hearing an audible reply.
209 *
210 * @hide
211 */
212 public static final int TTY_MODE_HCO = 2;
213
214 /**
215 * TTY (teletypewriter) mode is in voice carryover mode (VCO). The speaker is off but the
216 * microphone is still on. User will communicate with the remote party by speaking and receiving
217 * text message replies.
218 *
219 * @hide
220 */
221 public static final int TTY_MODE_VCO = 3;
222
223 /**
224 * Broadcast intent action indicating that the current TTY mode has changed. An intent extra
225 * provides this state as an int.
Evan Charlton10197192014-07-19 15:00:29 -0700226 *
Santos Cordon96efb482014-07-19 14:57:05 -0700227 * @see #EXTRA_CURRENT_TTY_MODE
Evan Charlton10197192014-07-19 15:00:29 -0700228 * @hide
229 */
230 public static final String ACTION_CURRENT_TTY_MODE_CHANGED =
Nancy Chen1d834f52014-09-05 11:03:21 -0700231 "android.telecomm.action.CURRENT_TTY_MODE_CHANGED";
Evan Charlton10197192014-07-19 15:00:29 -0700232
233 /**
234 * The lookup key for an int that indicates the current TTY mode.
235 * Valid modes are:
236 * - {@link #TTY_MODE_OFF}
237 * - {@link #TTY_MODE_FULL}
238 * - {@link #TTY_MODE_HCO}
239 * - {@link #TTY_MODE_VCO}
240 *
241 * @hide
242 */
243 public static final String EXTRA_CURRENT_TTY_MODE =
244 "android.telecomm.intent.extra.CURRENT_TTY_MODE";
245
246 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700247 * Broadcast intent action indicating that the TTY preferred operating mode has changed. An
248 * intent extra provides the new mode as an int.
Evan Charlton10197192014-07-19 15:00:29 -0700249 *
Santos Cordon96efb482014-07-19 14:57:05 -0700250 * @see #EXTRA_TTY_PREFERRED_MODE
Evan Charlton10197192014-07-19 15:00:29 -0700251 * @hide
252 */
253 public static final String ACTION_TTY_PREFERRED_MODE_CHANGED =
Nancy Chen1d834f52014-09-05 11:03:21 -0700254 "android.telecomm.action.TTY_PREFERRED_MODE_CHANGED";
Evan Charlton10197192014-07-19 15:00:29 -0700255
256 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700257 * The lookup key for an int that indicates preferred TTY mode. Valid modes are: -
258 * {@link #TTY_MODE_OFF} - {@link #TTY_MODE_FULL} - {@link #TTY_MODE_HCO} -
259 * {@link #TTY_MODE_VCO}
Evan Charlton10197192014-07-19 15:00:29 -0700260 *
261 * @hide
262 */
263 public static final String EXTRA_TTY_PREFERRED_MODE =
264 "android.telecomm.intent.extra.TTY_PREFERRED";
265
Nancy Chen9d568c02014-09-08 14:17:59 -0700266 /**
267 * The following 4 constants define how properties such as phone numbers and names are
268 * displayed to the user.
269 */
270
271 /** Property is displayed normally. */
272 public static final int PRESENTATION_ALLOWED = 1;
273
274 /** Property was blocked. */
275 public static final int PRESENTATION_RESTRICTED = 2;
276
277 /** Presentation was not specified or is unknown. */
278 public static final int PRESENTATION_UNKNOWN = 3;
279
280 /** Property should be displayed as a pay phone. */
281 public static final int PRESENTATION_PAYPHONE = 4;
282
Yorke Leeb4ce1432014-06-09 13:53:23 -0700283 private static final String TAG = "TelecommManager";
Santos Cordon96efb482014-07-19 14:57:05 -0700284
Santos Cordon6c7a3882014-06-25 15:30:08 -0700285 private static final String TELECOMM_SERVICE_NAME = "telecomm";
Yorke Leeb4ce1432014-06-09 13:53:23 -0700286
287 private final Context mContext;
Yorke Leeb4ce1432014-06-09 13:53:23 -0700288
Santos Cordon6c7a3882014-06-25 15:30:08 -0700289 /**
290 * @hide
291 */
Yorke Leeb4ce1432014-06-09 13:53:23 -0700292 public static TelecommManager from(Context context) {
293 return (TelecommManager) context.getSystemService(Context.TELECOMM_SERVICE);
294 }
Santos Cordon6c7a3882014-06-25 15:30:08 -0700295
296 /**
297 * @hide
298 */
Ihab Awad807fe0a2014-07-09 12:30:52 -0700299 public TelecommManager(Context context) {
300 Context appContext = context.getApplicationContext();
301 if (appContext != null) {
302 mContext = appContext;
303 } else {
304 mContext = context;
305 }
306 }
307
308 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700309 * Return the {@link PhoneAccount} which is the user-chosen default for making outgoing phone
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700310 * calls with a specified URI scheme. This {@code PhoneAccount} will always be a member of the
311 * list which is returned from calling {@link #getEnabledPhoneAccounts()}.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700312 * <p>
Santos Cordon96efb482014-07-19 14:57:05 -0700313 * Apps must be prepared for this method to return {@code null}, indicating that there currently
314 * exists no user-chosen default {@code PhoneAccount}. In this case, apps wishing to initiate a
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700315 * phone call must either create their {@link android.content.Intent#ACTION_CALL} or
Santos Cordon96efb482014-07-19 14:57:05 -0700316 * {@link android.content.Intent#ACTION_DIAL} {@code Intent} with no
317 * {@link TelecommManager#EXTRA_PHONE_ACCOUNT_HANDLE}, or present the user with an affordance to
318 * select one of the elements of {@link #getEnabledPhoneAccounts()}.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700319 * <p>
320 * An {@link android.content.Intent#ACTION_CALL} or {@link android.content.Intent#ACTION_DIAL}
Evan Charlton6eb262c2014-07-19 18:18:19 -0700321 * {@code Intent} with no {@link TelecommManager#EXTRA_PHONE_ACCOUNT_HANDLE} is valid, and
322 * subsequent steps in the phone call flow are responsible for presenting the user with an
Evan Charlton8c8a0622014-07-20 12:31:00 -0700323 * affordance, if necessary, to choose a {@code PhoneAccount}.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700324 *
325 * @param uriScheme The URI scheme.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700326 */
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700327 public PhoneAccountHandle getDefaultOutgoingPhoneAccount(String uriScheme) {
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700328 try {
329 if (isServiceConnected()) {
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700330 return getTelecommService().getDefaultOutgoingPhoneAccount(uriScheme);
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700331 }
332 } catch (RemoteException e) {
333 Log.e(TAG, "Error calling ITelecommService#getDefaultOutgoingPhoneAccount", e);
334 }
335 return null;
336 }
337
338 /**
Andrew Leed4abbfb2014-09-03 14:58:27 -0700339 * Return the {@link PhoneAccount} which is the user-chosen default for making outgoing phone
340 * calls. This {@code PhoneAccount} will always be a member of the list which is returned from
341 * calling {@link #getEnabledPhoneAccounts()}
342 *
343 * Apps must be prepared for this method to return {@code null}, indicating that there currently
344 * exists no user-chosen default {@code PhoneAccount}.
345 *
346 * @return The user outgoing phone account selected by the user.
347 * @hide
348 */
349 public PhoneAccountHandle getUserSelectedOutgoingPhoneAccount() {
350 try {
351 if (isServiceConnected()) {
352 return getTelecommService().getUserSelectedOutgoingPhoneAccount();
353 }
354 } catch (RemoteException e) {
355 Log.e(TAG, "Error calling ITelecommService#getUserSelectedOutgoingPhoneAccount", e);
356 }
357 return null;
358 }
359
360 /**
Andrew Lee59cac3a2014-08-28 16:50:10 -0700361 * Sets the default account for making outgoing phone calls.
362 * @hide
363 */
Andrew Leed4abbfb2014-09-03 14:58:27 -0700364 public void setUserSelectedOutgoingPhoneAccount(PhoneAccountHandle accountHandle) {
Andrew Lee59cac3a2014-08-28 16:50:10 -0700365 try {
366 if (isServiceConnected()) {
Andrew Leed4abbfb2014-09-03 14:58:27 -0700367 getTelecommService().setUserSelectedOutgoingPhoneAccount(accountHandle);
Andrew Lee59cac3a2014-08-28 16:50:10 -0700368 }
369 } catch (RemoteException e) {
Andrew Leed4abbfb2014-09-03 14:58:27 -0700370 Log.e(TAG, "Error calling ITelecommService#setUserSelectedOutgoingPhoneAccount");
Andrew Lee59cac3a2014-08-28 16:50:10 -0700371 }
372 }
373
374 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700375 * Return a list of enabled {@link PhoneAccountHandle}s which can be used to make and receive
376 * phone calls.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700377 *
Evan Charlton6eb262c2014-07-19 18:18:19 -0700378 * @see #EXTRA_PHONE_ACCOUNT_HANDLE
379 * @return A list of {@code PhoneAccountHandle} objects.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700380 */
Evan Charlton6eb262c2014-07-19 18:18:19 -0700381 public List<PhoneAccountHandle> getEnabledPhoneAccounts() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700382 try {
383 if (isServiceConnected()) {
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700384 return getTelecommService().getEnabledPhoneAccounts();
Ihab Awad807fe0a2014-07-09 12:30:52 -0700385 }
386 } catch (RemoteException e) {
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700387 Log.e(TAG, "Error calling ITelecommService#getEnabledPhoneAccounts", e);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700388 }
Jay Shrauner7746a942014-08-26 12:15:15 -0700389 return new ArrayList<>();
Ihab Awad807fe0a2014-07-09 12:30:52 -0700390 }
391
392 /**
Andrew Lee59cac3a2014-08-28 16:50:10 -0700393 * Returns the current SIM call manager. Apps must be prepared for this method to return
394 * {@code null}, indicating that there currently exists no user-chosen default
395 * {@code PhoneAccount}.
396 * @return The phone account handle of the current sim call manager.
397 * @hide
398 */
399 public PhoneAccountHandle getSimCallManager() {
400 try {
401 if (isServiceConnected()) {
402 return getTelecommService().getSimCallManager();
403 }
404 } catch (RemoteException e) {
405 Log.e(TAG, "Error calling ITelecommService#getSimCallManager");
406 }
407 return null;
408 }
409
410 /**
411 * Sets the SIM call manager to the specified phone account.
412 * @param accountHandle The phone account handle of the account to set as the sim call manager.
413 * @hide
414 */
415 public void setSimCallManager(PhoneAccountHandle accountHandle) {
416 try {
417 if (isServiceConnected()) {
418 getTelecommService().setSimCallManager(accountHandle);
419 }
420 } catch (RemoteException e) {
421 Log.e(TAG, "Error calling ITelecommService#setSimCallManager");
422 }
423 }
424
425 /**
426 * Returns the list of registered SIM call managers.
427 * @return List of registered SIM call managers.
428 * @hide
429 */
430 public List<PhoneAccountHandle> getSimCallManagers() {
431 try {
432 if (isServiceConnected()) {
433 return getTelecommService().getSimCallManagers();
434 }
435 } catch (RemoteException e) {
436 Log.e(TAG, "Error calling ITelecommService#getSimCallManagers");
437 }
438 return new ArrayList<>();
439 }
440
441 /**
Evan Charltoneb0a8d52014-09-04 12:03:34 -0700442 * Returns the current connection manager. Apps must be prepared for this method to return
443 * {@code null}, indicating that there currently exists no user-chosen default
444 * {@code PhoneAccount}.
445 *
446 * @return The phone account handle of the current connection manager.
447 */
448 public PhoneAccountHandle getConnectionManager() {
449 return getSimCallManager();
450 }
451
452 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700453 * Returns a list of the enabled {@link PhoneAccountHandle}s which can be used to make and
454 * receive phone calls which support the specified URI scheme.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700455 * <P>
456 * For example, invoking with {@code "tel"} will find all {@link PhoneAccountHandle}s which
457 * support telephone calls (e.g. URIs such as {@code tel:555-555-1212}). Invoking with
458 * {@code "sip"} will find all {@link PhoneAccountHandle}s which support SIP calls (e.g. URIs
459 * such as {@code sip:example@sipexample.com}).
460 *
461 * @param uriScheme The URI scheme.
462 * @return A list of {@code PhoneAccountHandle} objects supporting the URI scheme.
463 */
464 public List<PhoneAccountHandle> getPhoneAccountsSupportingScheme(String uriScheme) {
465 try {
466 if (isServiceConnected()) {
467 return getTelecommService().getPhoneAccountsSupportingScheme(uriScheme);
468 }
469 } catch (RemoteException e) {
470 Log.e(TAG, "Error calling ITelecommService#getPhoneAccountsSupportingScheme", e);
471 }
472 return new ArrayList<>();
473 }
474
475 /**
Nancy Chen60801182014-07-22 16:56:49 -0700476 * Determine whether the device has more than one account registered and enabled.
477 *
478 * @return {@code true} if the device has more than one account registered and enabled and
479 * {@code false} otherwise.
480 */
481 public boolean hasMultipleEnabledAccounts() {
482 return getEnabledPhoneAccounts().size() > 1;
483 }
484
485 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700486 * Return the {@link PhoneAccount} for a specified {@link PhoneAccountHandle}. Object includes
487 * resources which can be used in a user interface.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700488 *
Evan Charlton6eb262c2014-07-19 18:18:19 -0700489 * @param account The {@link PhoneAccountHandle}.
Evan Charlton8c8a0622014-07-20 12:31:00 -0700490 * @return The {@link PhoneAccount} object.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700491 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700492 public PhoneAccount getPhoneAccount(PhoneAccountHandle account) {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700493 try {
494 if (isServiceConnected()) {
Evan Charlton8c8a0622014-07-20 12:31:00 -0700495 return getTelecommService().getPhoneAccount(account);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700496 }
497 } catch (RemoteException e) {
Evan Charlton8c8a0622014-07-20 12:31:00 -0700498 Log.e(TAG, "Error calling ITelecommService#getPhoneAccount", e);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700499 }
500 return null;
501 }
502
503 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700504 * Returns a count of enabled and disabled {@link PhoneAccount}s.
505 *
506 * @return The count of enabled and disabled {@link PhoneAccount}s.
507 * @hide
508 */
509 @SystemApi
510 public int getAllPhoneAccountsCount() {
511 try {
512 if (isServiceConnected()) {
513 return getTelecommService().getAllPhoneAccountsCount();
514 }
515 } catch (RemoteException e) {
516 Log.e(TAG, "Error calling ITelecommService#getAllPhoneAccountsCount", e);
517 }
518 return 0;
519 }
520
521 /**
522 * Returns a list of all {@link PhoneAccount}s.
523 *
524 * @return All {@link PhoneAccount}s.
525 * @hide
526 */
527 @SystemApi
528 public List<PhoneAccount> getAllPhoneAccounts() {
529 try {
530 if (isServiceConnected()) {
531 return getTelecommService().getAllPhoneAccounts();
532 }
533 } catch (RemoteException e) {
534 Log.e(TAG, "Error calling ITelecommService#getAllPhoneAccounts", e);
535 }
536 return Collections.EMPTY_LIST;
537 }
538
539 /**
540 * Returns a list of all {@link PhoneAccountHandle}s.
541 *
542 * @return All {@link PhoneAccountHandle}s.
543 * @hide
544 */
545 @SystemApi
546 public List<PhoneAccountHandle> getAllPhoneAccountHandles() {
547 try {
548 if (isServiceConnected()) {
549 return getTelecommService().getAllPhoneAccountHandles();
550 }
551 } catch (RemoteException e) {
552 Log.e(TAG, "Error calling ITelecommService#getAllPhoneAccountHandles", e);
553 }
554 return Collections.EMPTY_LIST;
555 }
556
557 /**
558 * Enables or disables a {@link PhoneAccount}.
559 *
560 * @param account The {@link PhoneAccountHandle} to enable or disable.
561 * @param isEnabled {@code True} if the phone account should be enabled.
562 * @hide
563 */
564 @SystemApi
565 public void setPhoneAccountEnabled(PhoneAccountHandle account, boolean isEnabled) {
566 try {
567 if (isServiceConnected()) {
568 getTelecommService().setPhoneAccountEnabled(account, isEnabled);
569 }
570 } catch (RemoteException e) {
571 Log.e(TAG, "Error calling ITelecommService#setPhoneAccountEnabled", e);
572 }
573 }
574
575 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700576 * Register a {@link PhoneAccount} for use by the system.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700577 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700578 * @param account The complete {@link PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700579 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700580 public void registerPhoneAccount(PhoneAccount account) {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700581 try {
582 if (isServiceConnected()) {
Evan Charlton8c8a0622014-07-20 12:31:00 -0700583 getTelecommService().registerPhoneAccount(account);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700584 }
585 } catch (RemoteException e) {
586 Log.e(TAG, "Error calling ITelecommService#registerPhoneAccount", e);
587 }
588 }
589
590 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700591 * Remove a {@link PhoneAccount} registration from the system.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700592 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700593 * @param accountHandle A {@link PhoneAccountHandle} for the {@link PhoneAccount} to unregister.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700594 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700595 public void unregisterPhoneAccount(PhoneAccountHandle accountHandle) {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700596 try {
597 if (isServiceConnected()) {
Evan Charlton8c8a0622014-07-20 12:31:00 -0700598 getTelecommService().unregisterPhoneAccount(accountHandle);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700599 }
600 } catch (RemoteException e) {
601 Log.e(TAG, "Error calling ITelecommService#unregisterPhoneAccount", e);
602 }
603 }
604
605 /**
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700606 * Remove all Accounts that belong to the calling package from the system.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700607 */
608 @SystemApi
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700609 public void clearAccounts() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700610 try {
611 if (isServiceConnected()) {
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700612 getTelecommService().clearAccounts(mContext.getPackageName());
Ihab Awad807fe0a2014-07-09 12:30:52 -0700613 }
614 } catch (RemoteException e) {
615 Log.e(TAG, "Error calling ITelecommService#clearAccounts", e);
616 }
617 }
618
619 /**
620 * @hide
621 */
Santos Cordon6c7a3882014-06-25 15:30:08 -0700622 @SystemApi
623 public ComponentName getDefaultPhoneApp() {
624 try {
Santos Cordon9eb45932014-06-27 12:28:43 -0700625 if (isServiceConnected()) {
626 return getTelecommService().getDefaultPhoneApp();
627 }
Santos Cordon6c7a3882014-06-25 15:30:08 -0700628 } catch (RemoteException e) {
629 Log.e(TAG, "RemoteException attempting to get the default phone app.", e);
630 }
631 return null;
632 }
633
Santos Cordon9eb45932014-06-27 12:28:43 -0700634 /**
635 * Returns whether there is an ongoing phone call (can be in dialing, ringing, active or holding
636 * states).
Nancy Chen0eb1e402014-08-21 22:52:29 -0700637 * <p>
638 * Requires permission: {@link android.Manifest.permission#READ_PHONE_STATE}
639 * </p>
Santos Cordon9eb45932014-06-27 12:28:43 -0700640 */
641 @SystemApi
Nancy Chen0eb1e402014-08-21 22:52:29 -0700642 public boolean isInCall() {
Santos Cordon9eb45932014-06-27 12:28:43 -0700643 try {
644 if (isServiceConnected()) {
Nancy Chen0eb1e402014-08-21 22:52:29 -0700645 return getTelecommService().isInCall();
Santos Cordon9eb45932014-06-27 12:28:43 -0700646 }
647 } catch (RemoteException e) {
648 Log.e(TAG, "RemoteException attempting to get default phone app.", e);
649 }
650 return false;
651 }
652
653 /**
654 * Returns whether there currently exists is a ringing incoming-call.
655 *
656 * @hide
657 */
658 @SystemApi
659 public boolean isRinging() {
660 try {
661 if (isServiceConnected()) {
662 return getTelecommService().isRinging();
663 }
664 } catch (RemoteException e) {
665 Log.e(TAG, "RemoteException attempting to get ringing state of phone app.", e);
666 }
667 return false;
668 }
669
670 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700671 * Ends an ongoing call.
672 * TODO: L-release - need to convert all invocations of ITelecommService#endCall to use this
673 * method (clockwork & gearhead).
Santos Cordon9eb45932014-06-27 12:28:43 -0700674 * @hide
675 */
676 @SystemApi
677 public boolean endCall() {
678 try {
679 if (isServiceConnected()) {
680 return getTelecommService().endCall();
681 }
682 } catch (RemoteException e) {
683 Log.e(TAG, "Error calling ITelecommService#endCall", e);
684 }
685 return false;
686 }
687
688 /**
689 * If there is a ringing incoming call, this method accepts the call on behalf of the user.
Santos Cordon96efb482014-07-19 14:57:05 -0700690 * TODO: L-release - need to convert all invocation of ITelecommService#answerRingingCall to use
691 * this method (clockwork & gearhead).
Santos Cordon9eb45932014-06-27 12:28:43 -0700692 *
693 * @hide
694 */
695 @SystemApi
696 public void acceptRingingCall() {
697 try {
698 if (isServiceConnected()) {
699 getTelecommService().acceptRingingCall();
700 }
701 } catch (RemoteException e) {
702 Log.e(TAG, "Error calling ITelecommService#acceptRingingCall", e);
703 }
704 }
705
706 /**
707 * Silences the ringer if a ringing call exists.
708 *
709 * @hide
710 */
711 @SystemApi
712 public void silenceRinger() {
713 try {
714 if (isServiceConnected()) {
715 getTelecommService().silenceRinger();
716 }
717 } catch (RemoteException e) {
718 Log.e(TAG, "Error calling ITelecommService#silenceRinger", e);
719 }
720 }
721
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700722 /**
723 * Returns whether TTY is supported on this device.
724 *
725 * @hide
726 */
727 @SystemApi
728 public boolean isTtySupported() {
729 try {
730 if (isServiceConnected()) {
731 return getTelecommService().isTtySupported();
732 }
733 } catch (RemoteException e) {
734 Log.e(TAG, "RemoteException attempting to get TTY supported state.", e);
735 }
736 return false;
737 }
738
739 /**
740 * 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 -0700741 * settings and have a wired headset plugged in.
742 * Valid modes are:
Evan Charlton10197192014-07-19 15:00:29 -0700743 * - {@link TelecommManager#TTY_MODE_OFF}
744 * - {@link TelecommManager#TTY_MODE_FULL}
745 * - {@link TelecommManager#TTY_MODE_HCO}
746 * - {@link TelecommManager#TTY_MODE_VCO}
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700747 * @hide
748 */
749 public int getCurrentTtyMode() {
750 try {
751 if (isServiceConnected()) {
752 return getTelecommService().getCurrentTtyMode();
753 }
754 } catch (RemoteException e) {
755 Log.e(TAG, "RemoteException attempting to get the current TTY mode.", e);
756 }
Evan Charlton10197192014-07-19 15:00:29 -0700757 return TTY_MODE_OFF;
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700758 }
759
Santos Cordon96efb482014-07-19 14:57:05 -0700760 /**
761 * Registers a new incoming call. A {@link ConnectionService} should invoke this method when it
762 * has an incoming call. The specified {@link PhoneAccountHandle} must have been registered
763 * with {@link #registerPhoneAccount} and subsequently enabled by the user within the phone's
764 * settings. Once invoked, this method will cause the system to bind to the
765 * {@link ConnectionService} associated with the {@link PhoneAccountHandle} and request
766 * additional information about the call (See
767 * {@link ConnectionService#onCreateIncomingConnection}) before starting the incoming call UI.
768 *
769 * @param phoneAccount A {@link PhoneAccountHandle} registered with
770 * {@link #registerPhoneAccount}.
771 * @param extras A bundle that will be passed through to
772 * {@link ConnectionService#onCreateIncomingConnection}.
773 */
774 public void addNewIncomingCall(PhoneAccountHandle phoneAccount, Bundle extras) {
775 try {
776 if (isServiceConnected()) {
777 getTelecommService().addNewIncomingCall(
778 phoneAccount, extras == null ? new Bundle() : extras);
779 }
780 } catch (RemoteException e) {
781 Log.e(TAG, "RemoteException adding a new incoming call: " + phoneAccount, e);
782 }
783 }
784
Nancy Chen0eb1e402014-08-21 22:52:29 -0700785 /**
786 * Processes the specified dial string as an MMI code.
787 * MMI codes are any sequence of characters entered into the dialpad that contain a "*" or "#".
788 * Some of these sequences launch special behavior through handled by Telephony.
789 * <p>
790 * Requires that the method-caller be set as the system dialer app.
791 * </p>
792 *
793 * @param dialString The digits to dial.
794 * @return True if the digits were processed as an MMI code, false otherwise.
795 */
796 public boolean handleMmi(String dialString) {
797 ITelecommService service = getTelecommService();
798 if (service != null) {
799 try {
800 return service.handlePinMmi(dialString);
801 } catch (RemoteException e) {
802 Log.e(TAG, "Error calling ITelecommService#handlePinMmi", e);
803 }
804 }
805 return false;
806 }
807
808 /**
809 * Removes the missed-call notification if one is present.
810 * <p>
811 * Requires that the method-caller be set as the system dialer app.
812 * </p>
813 */
814 public void cancelMissedCallsNotification() {
815 ITelecommService service = getTelecommService();
816 if (service != null) {
817 try {
818 service.cancelMissedCallsNotification();
819 } catch (RemoteException e) {
820 Log.e(TAG, "Error calling ITelecommService#cancelMissedCallsNotification", e);
821 }
822 }
823 }
824
825 /**
826 * Brings the in-call screen to the foreground if there is an ongoing call. If there is
827 * currently no ongoing call, then this method does nothing.
828 * <p>
829 * Requires that the method-caller be set as the system dialer app or have the
830 * {@link android.Manifest.permission#READ_PHONE_STATE} permission.
831 * </p>
832 *
833 * @param showDialpad Brings up the in-call dialpad as part of showing the in-call screen.
834 */
835 public void showInCallScreen(boolean showDialpad) {
836 ITelecommService service = getTelecommService();
837 if (service != null) {
838 try {
839 service.showInCallScreen(showDialpad);
840 } catch (RemoteException e) {
841 Log.e(TAG, "Error calling ITelecommService#showCallScreen", e);
842 }
843 }
844 }
845
Santos Cordon6c7a3882014-06-25 15:30:08 -0700846 private ITelecommService getTelecommService() {
847 return ITelecommService.Stub.asInterface(ServiceManager.getService(TELECOMM_SERVICE_NAME));
848 }
Santos Cordon9eb45932014-06-27 12:28:43 -0700849
850 private boolean isServiceConnected() {
851 boolean isConnected = getTelecommService() != null;
852 if (!isConnected) {
853 Log.w(TAG, "Telecomm Service not found.");
854 }
855 return isConnected;
856 }
Evan Charlton235c1592014-09-05 15:41:23 +0000857}