blob: 9069ec01cfb144d610f8c8e2e1a5165955f70588 [file] [log] [blame]
Yorke Leeb4ce1432014-06-09 13:53:23 -07001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
Santos Cordon9eb45932014-06-27 12:28:43 -07004 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5 * in compliance with the License. You may obtain a copy of the License at
Yorke Leeb4ce1432014-06-09 13:53:23 -07006 *
Santos Cordon9eb45932014-06-27 12:28:43 -07007 * http://www.apache.org/licenses/LICENSE-2.0
Yorke Leeb4ce1432014-06-09 13:53:23 -07008 *
Santos Cordon9eb45932014-06-27 12:28:43 -07009 * Unless required by applicable law or agreed to in writing, software distributed under the License
10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11 * or implied. See the License for the specific language governing permissions and limitations under
12 * the License.
Yorke Leeb4ce1432014-06-09 13:53:23 -070013 */
14
Tyler Gunnef9f6f92014-09-12 22:16:17 -070015package android.telecom;
Yorke Leeb4ce1432014-06-09 13:53:23 -070016
Santos Cordon6c7a3882014-06-25 15:30:08 -070017import android.annotation.SystemApi;
18import android.content.ComponentName;
Yorke Leeb4ce1432014-06-09 13:53:23 -070019import android.content.Context;
Nancy Chenb2299c12014-10-29 18:22:11 -070020import android.net.Uri;
Santos Cordon96efb482014-07-19 14:57:05 -070021import android.os.Bundle;
Santos Cordon6c7a3882014-06-25 15:30:08 -070022import android.os.RemoteException;
23import android.os.ServiceManager;
Yorke Lee2ae312e2014-09-12 17:58:48 -070024import android.telephony.TelephonyManager;
Anthony Lee67279262014-10-27 11:28:40 -070025import android.text.TextUtils;
Santos Cordon6c7a3882014-06-25 15:30:08 -070026import android.util.Log;
Yorke Leeb4ce1432014-06-09 13:53:23 -070027
Tyler Gunnef9f6f92014-09-12 22:16:17 -070028import com.android.internal.telecom.ITelecomService;
Yorke Leeb4ce1432014-06-09 13:53:23 -070029
Jay Shrauner7746a942014-08-26 12:15:15 -070030import java.util.ArrayList;
Tyler Gunna1ed7d12014-09-08 09:52:22 -070031import java.util.Collections;
Ihab Awad807fe0a2014-07-09 12:30:52 -070032import java.util.List;
33
Yorke Leeb4ce1432014-06-09 13:53:23 -070034/**
Santos Cordond9e614f2014-10-28 13:10:36 -070035 * Provides access to information about active calls and registration/call-management functionality.
Evan Charlton0e094d92014-11-08 15:49:16 -080036 * Apps can use methods in this class to determine the current call state.
Santos Cordond9e614f2014-10-28 13:10:36 -070037 * <p>
38 * Apps do not instantiate this class directly; instead, they retrieve a reference to an instance
39 * through {@link Context#getSystemService Context.getSystemService(Context.TELECOM_SERVICE)}.
40 * <p>
41 * Note that access to some telecom information is permission-protected. Your app cannot access the
42 * protected information or gain access to protected functionality unless it has the appropriate
43 * permissions declared in its manifest file. Where permissions apply, they are noted in the method
44 * descriptions.
Yorke Leeb4ce1432014-06-09 13:53:23 -070045 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -070046public class TelecomManager {
Ihab Awad807fe0a2014-07-09 12:30:52 -070047
Evan Charlton10197192014-07-19 15:00:29 -070048 /**
Santos Cordon96efb482014-07-19 14:57:05 -070049 * Activity action: Starts the UI for handing an incoming call. This intent starts the in-call
Tyler Gunnef9f6f92014-09-12 22:16:17 -070050 * UI by notifying the Telecom system that an incoming call exists for a specific call service
51 * (see {@link android.telecom.ConnectionService}). Telecom reads the Intent extras to find
52 * and bind to the appropriate {@link android.telecom.ConnectionService} which Telecom will
Santos Cordon96efb482014-07-19 14:57:05 -070053 * ultimately use to control and get information about the call.
54 * <p>
55 * Input: get*Extra field {@link #EXTRA_PHONE_ACCOUNT_HANDLE} contains the component name of the
Tyler Gunnef9f6f92014-09-12 22:16:17 -070056 * {@link android.telecom.ConnectionService} that Telecom should bind to. Telecom will then
Evan Charlton10197192014-07-19 15:00:29 -070057 * ask the connection service for more information about the call prior to showing any UI.
Evan Charlton10197192014-07-19 15:00:29 -070058 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -070059 public static final String ACTION_INCOMING_CALL = "android.telecom.action.INCOMING_CALL";
Evan Charlton10197192014-07-19 15:00:29 -070060
61 /**
Yorke Leec3cf9822014-10-02 09:38:39 -070062 * Similar to {@link #ACTION_INCOMING_CALL}, but is used only by Telephony to add a new
63 * sim-initiated MO call for carrier testing.
64 * @hide
65 */
66 public static final String ACTION_NEW_UNKNOWN_CALL = "android.telecom.action.NEW_UNKNOWN_CALL";
67
68 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -070069 * The {@link android.content.Intent} action used to configure a
Tyler Gunnef9f6f92014-09-12 22:16:17 -070070 * {@link android.telecom.ConnectionService}.
Evan Charlton0e094d92014-11-08 15:49:16 -080071 * @hide
Evan Charlton10197192014-07-19 15:00:29 -070072 */
Evan Charlton0e094d92014-11-08 15:49:16 -080073 @SystemApi
Evan Charlton10197192014-07-19 15:00:29 -070074 public static final String ACTION_CONNECTION_SERVICE_CONFIGURE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -070075 "android.telecom.action.CONNECTION_SERVICE_CONFIGURE";
Evan Charlton10197192014-07-19 15:00:29 -070076
77 /**
Yorke Lee3818a8922014-07-21 15:57:17 -070078 * The {@link android.content.Intent} action used to show the call settings page.
79 */
80 public static final String ACTION_SHOW_CALL_SETTINGS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -070081 "android.telecom.action.SHOW_CALL_SETTINGS";
Yorke Lee3818a8922014-07-21 15:57:17 -070082
83 /**
Evan Charlton6d8604f2014-09-04 12:38:17 -070084 * The {@link android.content.Intent} action used to show the settings page used to configure
85 * {@link PhoneAccount} preferences.
86 */
87 public static final String ACTION_CHANGE_PHONE_ACCOUNTS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -070088 "android.telecom.action.CHANGE_PHONE_ACCOUNTS";
Evan Charlton6d8604f2014-09-04 12:38:17 -070089
90 /**
Santos Cordon2d2bc162015-02-27 15:22:07 -080091 * The {@link android.content.Intent} action used indicate that a new phone account was
92 * just registered.
93 * @hide
94 */
95 @SystemApi
96 public static final String ACTION_PHONE_ACCOUNT_REGISTERED =
97 "android.telecom.action.PHONE_ACCOUNT_REGISTERED";
98
99 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700100 * Optional extra for {@link android.content.Intent#ACTION_CALL} containing a boolean that
101 * determines whether the speakerphone should be automatically turned on for an outgoing call.
Evan Charlton10197192014-07-19 15:00:29 -0700102 */
103 public static final String EXTRA_START_CALL_WITH_SPEAKERPHONE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700104 "android.telecom.extra.START_CALL_WITH_SPEAKERPHONE";
Evan Charlton10197192014-07-19 15:00:29 -0700105
106 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700107 * Optional extra for {@link android.content.Intent#ACTION_CALL} containing an integer that
108 * determines the desired video state for an outgoing call.
Santos Cordon96efb482014-07-19 14:57:05 -0700109 * Valid options:
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700110 * {@link VideoProfile.VideoState#AUDIO_ONLY},
111 * {@link VideoProfile.VideoState#BIDIRECTIONAL},
112 * {@link VideoProfile.VideoState#RX_ENABLED},
113 * {@link VideoProfile.VideoState#TX_ENABLED}.
Evan Charlton10197192014-07-19 15:00:29 -0700114 */
115 public static final String EXTRA_START_CALL_WITH_VIDEO_STATE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700116 "android.telecom.extra.START_CALL_WITH_VIDEO_STATE";
Evan Charlton10197192014-07-19 15:00:29 -0700117
118 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700119 * The extra used with an {@link android.content.Intent#ACTION_CALL} and
120 * {@link android.content.Intent#ACTION_DIAL} {@code Intent} to specify a
121 * {@link PhoneAccountHandle} to use when making the call.
Evan Charlton10197192014-07-19 15:00:29 -0700122 * <p class="note">
Santos Cordon96efb482014-07-19 14:57:05 -0700123 * Retrieve with {@link android.content.Intent#getParcelableExtra(String)}.
Evan Charlton10197192014-07-19 15:00:29 -0700124 */
Evan Charlton6eb262c2014-07-19 18:18:19 -0700125 public static final String EXTRA_PHONE_ACCOUNT_HANDLE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700126 "android.telecom.extra.PHONE_ACCOUNT_HANDLE";
Evan Charlton10197192014-07-19 15:00:29 -0700127
128 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700129 * Optional extra for {@link #ACTION_INCOMING_CALL} containing a {@link Bundle} which contains
130 * metadata about the call. This {@link Bundle} will be returned to the
131 * {@link ConnectionService}.
Evan Charlton10197192014-07-19 15:00:29 -0700132 */
133 public static final String EXTRA_INCOMING_CALL_EXTRAS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700134 "android.telecom.extra.INCOMING_CALL_EXTRAS";
Evan Charlton10197192014-07-19 15:00:29 -0700135
136 /**
Nancy Chen10798dc2014-08-08 14:00:25 -0700137 * Optional extra for {@link android.content.Intent#ACTION_CALL} and
138 * {@link android.content.Intent#ACTION_DIAL} {@code Intent} containing a {@link Bundle}
139 * which contains metadata about the call. This {@link Bundle} will be saved into
140 * {@code Call.Details}.
Nancy Chen10798dc2014-08-08 14:00:25 -0700141 */
142 public static final String EXTRA_OUTGOING_CALL_EXTRAS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700143 "android.telecom.extra.OUTGOING_CALL_EXTRAS";
Nancy Chen10798dc2014-08-08 14:00:25 -0700144
145 /**
Yorke Leec3cf9822014-10-02 09:38:39 -0700146 * @hide
147 */
148 public static final String EXTRA_UNKNOWN_CALL_HANDLE =
149 "android.telecom.extra.UNKNOWN_CALL_HANDLE";
150
151 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700152 * Optional extra for {@link android.telephony.TelephonyManager#ACTION_PHONE_STATE_CHANGED}
153 * containing the disconnect code.
Evan Charlton10197192014-07-19 15:00:29 -0700154 */
155 public static final String EXTRA_CALL_DISCONNECT_CAUSE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700156 "android.telecom.extra.CALL_DISCONNECT_CAUSE";
Evan Charlton10197192014-07-19 15:00:29 -0700157
158 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700159 * Optional extra for {@link android.telephony.TelephonyManager#ACTION_PHONE_STATE_CHANGED}
160 * containing the disconnect message.
Evan Charlton10197192014-07-19 15:00:29 -0700161 */
162 public static final String EXTRA_CALL_DISCONNECT_MESSAGE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700163 "android.telecom.extra.CALL_DISCONNECT_MESSAGE";
Evan Charlton10197192014-07-19 15:00:29 -0700164
165 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700166 * Optional extra for {@link android.telephony.TelephonyManager#ACTION_PHONE_STATE_CHANGED}
167 * containing the component name of the associated connection service.
Evan Charlton0e094d92014-11-08 15:49:16 -0800168 * @hide
Evan Charlton10197192014-07-19 15:00:29 -0700169 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800170 @SystemApi
Evan Charlton10197192014-07-19 15:00:29 -0700171 public static final String EXTRA_CONNECTION_SERVICE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700172 "android.telecom.extra.CONNECTION_SERVICE";
Evan Charlton10197192014-07-19 15:00:29 -0700173
174 /**
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700175 * An optional {@link android.content.Intent#ACTION_CALL} intent extra denoting the
176 * package name of the app specifying an alternative gateway for the call.
177 * The value is a string.
178 *
179 * (The following comment corresponds to the all GATEWAY_* extras)
180 * An app which sends the {@link android.content.Intent#ACTION_CALL} intent can specify an
181 * alternative address to dial which is different from the one specified and displayed to
182 * the user. This alternative address is referred to as the gateway address.
183 */
184 public static final String GATEWAY_PROVIDER_PACKAGE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700185 "android.telecom.extra.GATEWAY_PROVIDER_PACKAGE";
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700186
187 /**
188 * An optional {@link android.content.Intent#ACTION_CALL} intent extra corresponding to the
189 * original address to dial for the call. This is used when an alternative gateway address is
190 * provided to recall the original address.
191 * The value is a {@link android.net.Uri}.
192 *
193 * (See {@link #GATEWAY_PROVIDER_PACKAGE} for details)
194 */
195 public static final String GATEWAY_ORIGINAL_ADDRESS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700196 "android.telecom.extra.GATEWAY_ORIGINAL_ADDRESS";
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700197
198 /**
Evan Charlton10197192014-07-19 15:00:29 -0700199 * The number which the party on the other side of the line will see (and use to return the
200 * call).
201 * <p>
Santos Cordon96efb482014-07-19 14:57:05 -0700202 * {@link ConnectionService}s which interact with {@link RemoteConnection}s should only populate
203 * this if the {@link android.telephony.TelephonyManager#getLine1Number()} value, as that is the
204 * user's expected caller ID.
Evan Charlton10197192014-07-19 15:00:29 -0700205 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700206 public static final String EXTRA_CALL_BACK_NUMBER = "android.telecom.extra.CALL_BACK_NUMBER";
Evan Charlton10197192014-07-19 15:00:29 -0700207
208 /**
209 * The dual tone multi-frequency signaling character sent to indicate the dialing system should
210 * pause for a predefined period.
211 */
212 public static final char DTMF_CHARACTER_PAUSE = ',';
213
214 /**
215 * The dual-tone multi-frequency signaling character sent to indicate the dialing system should
216 * wait for user confirmation before proceeding.
217 */
218 public static final char DTMF_CHARACTER_WAIT = ';';
219
220 /**
221 * TTY (teletypewriter) mode is off.
222 *
223 * @hide
224 */
225 public static final int TTY_MODE_OFF = 0;
226
227 /**
228 * TTY (teletypewriter) mode is on. The speaker is off and the microphone is muted. The user
229 * will communicate with the remote party by sending and receiving text messages.
230 *
231 * @hide
232 */
233 public static final int TTY_MODE_FULL = 1;
234
235 /**
236 * TTY (teletypewriter) mode is in hearing carryover mode (HCO). The microphone is muted but the
237 * speaker is on. The user will communicate with the remote party by sending text messages and
238 * hearing an audible reply.
239 *
240 * @hide
241 */
242 public static final int TTY_MODE_HCO = 2;
243
244 /**
245 * TTY (teletypewriter) mode is in voice carryover mode (VCO). The speaker is off but the
246 * microphone is still on. User will communicate with the remote party by speaking and receiving
247 * text message replies.
248 *
249 * @hide
250 */
251 public static final int TTY_MODE_VCO = 3;
252
253 /**
254 * Broadcast intent action indicating that the current TTY mode has changed. An intent extra
255 * provides this state as an int.
Evan Charlton10197192014-07-19 15:00:29 -0700256 *
Santos Cordon96efb482014-07-19 14:57:05 -0700257 * @see #EXTRA_CURRENT_TTY_MODE
Evan Charlton10197192014-07-19 15:00:29 -0700258 * @hide
259 */
260 public static final String ACTION_CURRENT_TTY_MODE_CHANGED =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700261 "android.telecom.action.CURRENT_TTY_MODE_CHANGED";
Evan Charlton10197192014-07-19 15:00:29 -0700262
263 /**
264 * The lookup key for an int that indicates the current TTY mode.
265 * Valid modes are:
266 * - {@link #TTY_MODE_OFF}
267 * - {@link #TTY_MODE_FULL}
268 * - {@link #TTY_MODE_HCO}
269 * - {@link #TTY_MODE_VCO}
270 *
271 * @hide
272 */
273 public static final String EXTRA_CURRENT_TTY_MODE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700274 "android.telecom.intent.extra.CURRENT_TTY_MODE";
Evan Charlton10197192014-07-19 15:00:29 -0700275
276 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700277 * Broadcast intent action indicating that the TTY preferred operating mode has changed. An
278 * intent extra provides the new mode as an int.
Evan Charlton10197192014-07-19 15:00:29 -0700279 *
Santos Cordon96efb482014-07-19 14:57:05 -0700280 * @see #EXTRA_TTY_PREFERRED_MODE
Evan Charlton10197192014-07-19 15:00:29 -0700281 * @hide
282 */
283 public static final String ACTION_TTY_PREFERRED_MODE_CHANGED =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700284 "android.telecom.action.TTY_PREFERRED_MODE_CHANGED";
Evan Charlton10197192014-07-19 15:00:29 -0700285
286 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700287 * The lookup key for an int that indicates preferred TTY mode. Valid modes are: -
288 * {@link #TTY_MODE_OFF} - {@link #TTY_MODE_FULL} - {@link #TTY_MODE_HCO} -
289 * {@link #TTY_MODE_VCO}
Evan Charlton10197192014-07-19 15:00:29 -0700290 *
291 * @hide
292 */
293 public static final String EXTRA_TTY_PREFERRED_MODE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700294 "android.telecom.intent.extra.TTY_PREFERRED";
Evan Charlton10197192014-07-19 15:00:29 -0700295
Nancy Chen9d568c02014-09-08 14:17:59 -0700296 /**
297 * The following 4 constants define how properties such as phone numbers and names are
298 * displayed to the user.
299 */
300
301 /** Property is displayed normally. */
302 public static final int PRESENTATION_ALLOWED = 1;
303
304 /** Property was blocked. */
305 public static final int PRESENTATION_RESTRICTED = 2;
306
307 /** Presentation was not specified or is unknown. */
308 public static final int PRESENTATION_UNKNOWN = 3;
309
310 /** Property should be displayed as a pay phone. */
311 public static final int PRESENTATION_PAYPHONE = 4;
312
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700313 private static final String TAG = "TelecomManager";
Yorke Leeb4ce1432014-06-09 13:53:23 -0700314
315 private final Context mContext;
Yorke Leeb4ce1432014-06-09 13:53:23 -0700316
Santos Cordon6c7a3882014-06-25 15:30:08 -0700317 /**
318 * @hide
319 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700320 public static TelecomManager from(Context context) {
321 return (TelecomManager) context.getSystemService(Context.TELECOM_SERVICE);
Yorke Leeb4ce1432014-06-09 13:53:23 -0700322 }
Santos Cordon6c7a3882014-06-25 15:30:08 -0700323
324 /**
325 * @hide
326 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700327 public TelecomManager(Context context) {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700328 Context appContext = context.getApplicationContext();
329 if (appContext != null) {
330 mContext = appContext;
331 } else {
332 mContext = context;
333 }
334 }
335
336 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700337 * Return the {@link PhoneAccount} which is the user-chosen default for making outgoing phone
Nancy Chen513c8922014-09-17 14:47:20 -0700338 * calls with a specified URI scheme.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700339 * <p>
Santos Cordon96efb482014-07-19 14:57:05 -0700340 * Apps must be prepared for this method to return {@code null}, indicating that there currently
Nancy Chen513c8922014-09-17 14:47:20 -0700341 * exists no user-chosen default {@code PhoneAccount}.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700342 * <p>
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700343 * @param uriScheme The URI scheme.
Nancy Chen513c8922014-09-17 14:47:20 -0700344 * @return The {@link PhoneAccountHandle} corresponding to the user-chosen default for outgoing
345 * phone calls for a specified URI scheme.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700346 */
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700347 public PhoneAccountHandle getDefaultOutgoingPhoneAccount(String uriScheme) {
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700348 try {
349 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700350 return getTelecomService().getDefaultOutgoingPhoneAccount(uriScheme);
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700351 }
352 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700353 Log.e(TAG, "Error calling ITelecomService#getDefaultOutgoingPhoneAccount", e);
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700354 }
355 return null;
356 }
357
358 /**
Andrew Leed4abbfb2014-09-03 14:58:27 -0700359 * Return the {@link PhoneAccount} which is the user-chosen default for making outgoing phone
360 * calls. This {@code PhoneAccount} will always be a member of the list which is returned from
Nancy Chen210ef032014-09-15 17:58:42 -0700361 * calling {@link #getCallCapablePhoneAccounts()}
Andrew Leed4abbfb2014-09-03 14:58:27 -0700362 *
363 * Apps must be prepared for this method to return {@code null}, indicating that there currently
364 * exists no user-chosen default {@code PhoneAccount}.
365 *
366 * @return The user outgoing phone account selected by the user.
Andrew Leed4abbfb2014-09-03 14:58:27 -0700367 */
368 public PhoneAccountHandle getUserSelectedOutgoingPhoneAccount() {
369 try {
370 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700371 return getTelecomService().getUserSelectedOutgoingPhoneAccount();
Andrew Leed4abbfb2014-09-03 14:58:27 -0700372 }
373 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700374 Log.e(TAG, "Error calling ITelecomService#getUserSelectedOutgoingPhoneAccount", e);
Andrew Leed4abbfb2014-09-03 14:58:27 -0700375 }
376 return null;
377 }
378
379 /**
Andrew Lee59cac3a2014-08-28 16:50:10 -0700380 * Sets the default account for making outgoing phone calls.
381 * @hide
382 */
Andrew Leed4abbfb2014-09-03 14:58:27 -0700383 public void setUserSelectedOutgoingPhoneAccount(PhoneAccountHandle accountHandle) {
Andrew Lee59cac3a2014-08-28 16:50:10 -0700384 try {
385 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700386 getTelecomService().setUserSelectedOutgoingPhoneAccount(accountHandle);
Andrew Lee59cac3a2014-08-28 16:50:10 -0700387 }
388 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700389 Log.e(TAG, "Error calling ITelecomService#setUserSelectedOutgoingPhoneAccount");
Andrew Lee59cac3a2014-08-28 16:50:10 -0700390 }
391 }
392
393 /**
Andrew Lee59cac3a2014-08-28 16:50:10 -0700394 * Returns the current SIM call manager. Apps must be prepared for this method to return
395 * {@code null}, indicating that there currently exists no user-chosen default
396 * {@code PhoneAccount}.
397 * @return The phone account handle of the current sim call manager.
Andrew Lee59cac3a2014-08-28 16:50:10 -0700398 */
399 public PhoneAccountHandle getSimCallManager() {
400 try {
401 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700402 return getTelecomService().getSimCallManager();
Andrew Lee59cac3a2014-08-28 16:50:10 -0700403 }
404 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700405 Log.e(TAG, "Error calling ITelecomService#getSimCallManager");
Andrew Lee59cac3a2014-08-28 16:50:10 -0700406 }
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()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700418 getTelecomService().setSimCallManager(accountHandle);
Andrew Lee59cac3a2014-08-28 16:50:10 -0700419 }
420 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700421 Log.e(TAG, "Error calling ITelecomService#setSimCallManager");
Andrew Lee59cac3a2014-08-28 16:50:10 -0700422 }
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()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700433 return getTelecomService().getSimCallManagers();
Andrew Lee59cac3a2014-08-28 16:50:10 -0700434 }
435 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700436 Log.e(TAG, "Error calling ITelecomService#getSimCallManagers");
Andrew Lee59cac3a2014-08-28 16:50:10 -0700437 }
438 return new ArrayList<>();
439 }
440
441 /**
Evan Charltoneb0a8d562014-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.
Evan Charlton0e094d92014-11-08 15:49:16 -0800447 * @hide
Evan Charltoneb0a8d562014-09-04 12:03:34 -0700448 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800449 @SystemApi
Evan Charltoneb0a8d562014-09-04 12:03:34 -0700450 public PhoneAccountHandle getConnectionManager() {
451 return getSimCallManager();
452 }
453
454 /**
Sailesh Nepal7a4e3872014-11-21 11:01:40 -0800455 * Returns the list of registered SIM call managers.
456 * @return List of registered SIM call managers.
457 * @hide
458 */
459 @SystemApi
460 public List<PhoneAccountHandle> getRegisteredConnectionManagers() {
461 return getSimCallManagers();
462 }
463
464 /**
Nancy Chen210ef032014-09-15 17:58:42 -0700465 * Returns a list of the {@link PhoneAccountHandle}s which can be used to make and receive phone
466 * calls which support the specified URI scheme.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700467 * <P>
468 * For example, invoking with {@code "tel"} will find all {@link PhoneAccountHandle}s which
469 * support telephone calls (e.g. URIs such as {@code tel:555-555-1212}). Invoking with
470 * {@code "sip"} will find all {@link PhoneAccountHandle}s which support SIP calls (e.g. URIs
471 * such as {@code sip:example@sipexample.com}).
472 *
473 * @param uriScheme The URI scheme.
474 * @return A list of {@code PhoneAccountHandle} objects supporting the URI scheme.
Evan Charlton0e094d92014-11-08 15:49:16 -0800475 * @hide
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700476 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800477 @SystemApi
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700478 public List<PhoneAccountHandle> getPhoneAccountsSupportingScheme(String uriScheme) {
479 try {
480 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700481 return getTelecomService().getPhoneAccountsSupportingScheme(uriScheme);
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700482 }
483 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700484 Log.e(TAG, "Error calling ITelecomService#getPhoneAccountsSupportingScheme", e);
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700485 }
486 return new ArrayList<>();
487 }
488
Nancy Chen513c8922014-09-17 14:47:20 -0700489
490 /**
491 * Return a list of {@link PhoneAccountHandle}s which can be used to make and receive phone
492 * calls.
493 *
494 * @see #EXTRA_PHONE_ACCOUNT_HANDLE
495 * @return A list of {@code PhoneAccountHandle} objects.
Nancy Chen513c8922014-09-17 14:47:20 -0700496 */
497 public List<PhoneAccountHandle> getCallCapablePhoneAccounts() {
498 try {
499 if (isServiceConnected()) {
500 return getTelecomService().getCallCapablePhoneAccounts();
501 }
502 } catch (RemoteException e) {
503 Log.e(TAG, "Error calling ITelecomService#getCallCapablePhoneAccounts", e);
504 }
505 return new ArrayList<>();
506 }
507
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700508 /**
Nancy Chen513c8922014-09-17 14:47:20 -0700509 * Returns a list of all {@link PhoneAccount}s registered for the calling package.
510 *
511 * @return A list of {@code PhoneAccountHandle} objects.
Evan Charlton0e094d92014-11-08 15:49:16 -0800512 * @hide
Nancy Chen513c8922014-09-17 14:47:20 -0700513 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800514 @SystemApi
Nancy Chen513c8922014-09-17 14:47:20 -0700515 public List<PhoneAccountHandle> getPhoneAccountsForPackage() {
516 try {
517 if (isServiceConnected()) {
518 return getTelecomService().getPhoneAccountsForPackage(mContext.getPackageName());
519 }
520 } catch (RemoteException e) {
521 Log.e(TAG, "Error calling ITelecomService#getPhoneAccountsForPackage", e);
522 }
523 return null;
524 }
525
526 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700527 * Return the {@link PhoneAccount} for a specified {@link PhoneAccountHandle}. Object includes
528 * resources which can be used in a user interface.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700529 *
Evan Charlton6eb262c2014-07-19 18:18:19 -0700530 * @param account The {@link PhoneAccountHandle}.
Evan Charlton8c8a0622014-07-20 12:31:00 -0700531 * @return The {@link PhoneAccount} object.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700532 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700533 public PhoneAccount getPhoneAccount(PhoneAccountHandle account) {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700534 try {
535 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700536 return getTelecomService().getPhoneAccount(account);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700537 }
538 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700539 Log.e(TAG, "Error calling ITelecomService#getPhoneAccount", e);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700540 }
541 return null;
542 }
543
544 /**
Nancy Chen210ef032014-09-15 17:58:42 -0700545 * Returns a count of all {@link PhoneAccount}s.
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700546 *
Nancy Chen210ef032014-09-15 17:58:42 -0700547 * @return The count of {@link PhoneAccount}s.
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700548 * @hide
549 */
550 @SystemApi
551 public int getAllPhoneAccountsCount() {
552 try {
553 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700554 return getTelecomService().getAllPhoneAccountsCount();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700555 }
556 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700557 Log.e(TAG, "Error calling ITelecomService#getAllPhoneAccountsCount", e);
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700558 }
559 return 0;
560 }
561
562 /**
563 * Returns a list of all {@link PhoneAccount}s.
564 *
565 * @return All {@link PhoneAccount}s.
566 * @hide
567 */
568 @SystemApi
569 public List<PhoneAccount> getAllPhoneAccounts() {
570 try {
571 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700572 return getTelecomService().getAllPhoneAccounts();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700573 }
574 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700575 Log.e(TAG, "Error calling ITelecomService#getAllPhoneAccounts", e);
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700576 }
577 return Collections.EMPTY_LIST;
578 }
579
580 /**
581 * Returns a list of all {@link PhoneAccountHandle}s.
582 *
583 * @return All {@link PhoneAccountHandle}s.
584 * @hide
585 */
586 @SystemApi
587 public List<PhoneAccountHandle> getAllPhoneAccountHandles() {
588 try {
589 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700590 return getTelecomService().getAllPhoneAccountHandles();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700591 }
592 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700593 Log.e(TAG, "Error calling ITelecomService#getAllPhoneAccountHandles", e);
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700594 }
595 return Collections.EMPTY_LIST;
596 }
597
598 /**
Santos Cordond9e614f2014-10-28 13:10:36 -0700599 * Register a {@link PhoneAccount} for use by the system. When registering
600 * {@link PhoneAccount}s, existing registrations will be overwritten if the
601 * {@link PhoneAccountHandle} matches that of a {@link PhoneAccount} which is already
602 * registered. Once registered, the {@link PhoneAccount} is listed to the user as an option
603 * when placing calls. The user may still need to enable the {@link PhoneAccount} within
604 * the phone app settings before the account is usable.
605 * <p>
606 * A {@link SecurityException} will be thrown if an app tries to register a
607 * {@link PhoneAccountHandle} where the package name specified within
608 * {@link PhoneAccountHandle#getComponentName()} does not match the package name of the app.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700609 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700610 * @param account The complete {@link PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700611 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700612 public void registerPhoneAccount(PhoneAccount account) {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700613 try {
614 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700615 getTelecomService().registerPhoneAccount(account);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700616 }
617 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700618 Log.e(TAG, "Error calling ITelecomService#registerPhoneAccount", e);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700619 }
620 }
621
622 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700623 * Remove a {@link PhoneAccount} registration from the system.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700624 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700625 * @param accountHandle A {@link PhoneAccountHandle} for the {@link PhoneAccount} to unregister.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700626 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700627 public void unregisterPhoneAccount(PhoneAccountHandle accountHandle) {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700628 try {
629 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700630 getTelecomService().unregisterPhoneAccount(accountHandle);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700631 }
632 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700633 Log.e(TAG, "Error calling ITelecomService#unregisterPhoneAccount", e);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700634 }
635 }
636
637 /**
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700638 * Remove all Accounts that belong to the calling package from the system.
Evan Charlton0e094d92014-11-08 15:49:16 -0800639 * @hide
Ihab Awad807fe0a2014-07-09 12:30:52 -0700640 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800641 @SystemApi
Yorke Lee0bce8902015-04-14 15:16:59 -0700642 public void clearPhoneAccounts() {
643 clearAccounts();
644 }
645 /**
646 * Remove all Accounts that belong to the calling package from the system.
647 * @deprecated Use {@link #clearPhoneAccounts()} instead.
648 * @hide
649 */
650 @SystemApi
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700651 public void clearAccounts() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700652 try {
653 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700654 getTelecomService().clearAccounts(mContext.getPackageName());
Ihab Awad807fe0a2014-07-09 12:30:52 -0700655 }
656 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700657 Log.e(TAG, "Error calling ITelecomService#clearAccounts", e);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700658 }
659 }
660
661 /**
Anthony Lee67279262014-10-27 11:28:40 -0700662 * Remove all Accounts that belong to the specified package from the system.
663 * @hide
664 */
665 public void clearAccountsForPackage(String packageName) {
666 try {
667 if (isServiceConnected() && !TextUtils.isEmpty(packageName)) {
668 getTelecomService().clearAccounts(packageName);
669 }
670 } catch (RemoteException e) {
Nancy Chen5cf27842015-01-24 23:30:27 -0800671 Log.e(TAG, "Error calling ITelecomService#clearAccountsForPackage", e);
Anthony Lee67279262014-10-27 11:28:40 -0700672 }
673 }
674
675 /**
Ihab Awad807fe0a2014-07-09 12:30:52 -0700676 * @hide
677 */
Santos Cordon6c7a3882014-06-25 15:30:08 -0700678 @SystemApi
679 public ComponentName getDefaultPhoneApp() {
680 try {
Santos Cordon9eb45932014-06-27 12:28:43 -0700681 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700682 return getTelecomService().getDefaultPhoneApp();
Santos Cordon9eb45932014-06-27 12:28:43 -0700683 }
Santos Cordon6c7a3882014-06-25 15:30:08 -0700684 } catch (RemoteException e) {
685 Log.e(TAG, "RemoteException attempting to get the default phone app.", e);
686 }
687 return null;
688 }
689
Santos Cordon9eb45932014-06-27 12:28:43 -0700690 /**
Nancy Chen443e5012014-10-15 15:48:21 -0700691 * Return whether a given phone number is the configured voicemail number for a
692 * particular phone account.
693 *
694 * @param accountHandle The handle for the account to check the voicemail number against
695 * @param number The number to look up.
Nancy Chen443e5012014-10-15 15:48:21 -0700696 */
Nancy Chen443e5012014-10-15 15:48:21 -0700697 public boolean isVoiceMailNumber(PhoneAccountHandle accountHandle, String number) {
698 try {
699 if (isServiceConnected()) {
700 return getTelecomService().isVoiceMailNumber(accountHandle, number);
701 }
702 } catch (RemoteException e) {
Nancy Chen5cf27842015-01-24 23:30:27 -0800703 Log.e(TAG, "RemoteException calling ITelecomService#isVoiceMailNumber.", e);
Nancy Chen443e5012014-10-15 15:48:21 -0700704 }
705 return false;
706 }
707
708 /**
Nancy Chen8c066f7c2014-12-03 15:18:08 -0800709 * Return whether a given phone account has a voicemail number configured.
710 *
711 * @param accountHandle The handle for the account to check for a voicemail number.
712 * @return {@code true} If the given phone account has a voicemail number.
Nancy Chen8c066f7c2014-12-03 15:18:08 -0800713 */
Nancy Chen8c066f7c2014-12-03 15:18:08 -0800714 public boolean hasVoiceMailNumber(PhoneAccountHandle accountHandle) {
715 try {
716 if (isServiceConnected()) {
717 return getTelecomService().hasVoiceMailNumber(accountHandle);
718 }
719 } catch (RemoteException e) {
Nancy Chen5cf27842015-01-24 23:30:27 -0800720 Log.e(TAG, "RemoteException calling ITelecomService#hasVoiceMailNumber.", e);
Nancy Chen8c066f7c2014-12-03 15:18:08 -0800721 }
722 return false;
723 }
724
725 /**
Nancy Chen5cf27842015-01-24 23:30:27 -0800726 * Return the line 1 phone number for given phone account.
727 *
728 * @param accountHandle The handle for the account retrieve a number for.
729 * @return A string representation of the line 1 phone number.
Nancy Chen5cf27842015-01-24 23:30:27 -0800730 */
Nancy Chen5cf27842015-01-24 23:30:27 -0800731 public String getLine1Number(PhoneAccountHandle accountHandle) {
732 try {
733 if (isServiceConnected()) {
734 return getTelecomService().getLine1Number(accountHandle);
735 }
736 } catch (RemoteException e) {
737 Log.e(TAG, "RemoteException calling ITelecomService#getLine1Number.", e);
738 }
739 return null;
740 }
741
742 /**
Santos Cordon9eb45932014-06-27 12:28:43 -0700743 * Returns whether there is an ongoing phone call (can be in dialing, ringing, active or holding
744 * states).
Nancy Chen0eb1e402014-08-21 22:52:29 -0700745 * <p>
746 * Requires permission: {@link android.Manifest.permission#READ_PHONE_STATE}
747 * </p>
Santos Cordon9eb45932014-06-27 12:28:43 -0700748 */
Nancy Chen0eb1e402014-08-21 22:52:29 -0700749 public boolean isInCall() {
Santos Cordon9eb45932014-06-27 12:28:43 -0700750 try {
751 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700752 return getTelecomService().isInCall();
Santos Cordon9eb45932014-06-27 12:28:43 -0700753 }
754 } catch (RemoteException e) {
Yorke Lee2ae312e2014-09-12 17:58:48 -0700755 Log.e(TAG, "RemoteException calling isInCall().", e);
Santos Cordon9eb45932014-06-27 12:28:43 -0700756 }
757 return false;
758 }
759
760 /**
Yorke Lee2ae312e2014-09-12 17:58:48 -0700761 * Returns one of the following constants that represents the current state of Telecom:
762 *
763 * {@link TelephonyManager#CALL_STATE_RINGING}
764 * {@link TelephonyManager#CALL_STATE_OFFHOOK}
765 * {@link TelephonyManager#CALL_STATE_IDLE}
Yorke Lee7c72c2d2014-10-28 14:12:02 -0700766 *
767 * Note that this API does not require the
768 * {@link android.Manifest.permission#READ_PHONE_STATE} permission. This is intentional, to
769 * preserve the behavior of {@link TelephonyManager#getCallState()}, which also did not require
770 * the permission.
Yorke Lee2ae312e2014-09-12 17:58:48 -0700771 * @hide
772 */
773 @SystemApi
774 public int getCallState() {
775 try {
776 if (isServiceConnected()) {
777 return getTelecomService().getCallState();
778 }
779 } catch (RemoteException e) {
780 Log.d(TAG, "RemoteException calling getCallState().", e);
781 }
782 return TelephonyManager.CALL_STATE_IDLE;
783 }
784
785 /**
Santos Cordon9eb45932014-06-27 12:28:43 -0700786 * Returns whether there currently exists is a ringing incoming-call.
787 *
788 * @hide
789 */
790 @SystemApi
791 public boolean isRinging() {
792 try {
793 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700794 return getTelecomService().isRinging();
Santos Cordon9eb45932014-06-27 12:28:43 -0700795 }
796 } catch (RemoteException e) {
797 Log.e(TAG, "RemoteException attempting to get ringing state of phone app.", e);
798 }
799 return false;
800 }
801
802 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700803 * Ends an ongoing call.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700804 * TODO: L-release - need to convert all invocations of ITelecomService#endCall to use this
Santos Cordon96efb482014-07-19 14:57:05 -0700805 * method (clockwork & gearhead).
Santos Cordon9eb45932014-06-27 12:28:43 -0700806 * @hide
807 */
808 @SystemApi
809 public boolean endCall() {
810 try {
811 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700812 return getTelecomService().endCall();
Santos Cordon9eb45932014-06-27 12:28:43 -0700813 }
814 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700815 Log.e(TAG, "Error calling ITelecomService#endCall", e);
Santos Cordon9eb45932014-06-27 12:28:43 -0700816 }
817 return false;
818 }
819
820 /**
821 * If there is a ringing incoming call, this method accepts the call on behalf of the user.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700822 * TODO: L-release - need to convert all invocation of ITelecmmService#answerRingingCall to use
Santos Cordon96efb482014-07-19 14:57:05 -0700823 * this method (clockwork & gearhead).
Santos Cordon9eb45932014-06-27 12:28:43 -0700824 *
825 * @hide
826 */
827 @SystemApi
828 public void acceptRingingCall() {
829 try {
830 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700831 getTelecomService().acceptRingingCall();
Santos Cordon9eb45932014-06-27 12:28:43 -0700832 }
833 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700834 Log.e(TAG, "Error calling ITelecomService#acceptRingingCall", e);
Santos Cordon9eb45932014-06-27 12:28:43 -0700835 }
836 }
837
838 /**
839 * Silences the ringer if a ringing call exists.
Santos Cordon9eb45932014-06-27 12:28:43 -0700840 */
Santos Cordon9eb45932014-06-27 12:28:43 -0700841 public void silenceRinger() {
842 try {
843 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700844 getTelecomService().silenceRinger();
Santos Cordon9eb45932014-06-27 12:28:43 -0700845 }
846 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700847 Log.e(TAG, "Error calling ITelecomService#silenceRinger", e);
Santos Cordon9eb45932014-06-27 12:28:43 -0700848 }
849 }
850
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700851 /**
852 * Returns whether TTY is supported on this device.
853 *
854 * @hide
855 */
856 @SystemApi
857 public boolean isTtySupported() {
858 try {
859 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700860 return getTelecomService().isTtySupported();
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700861 }
862 } catch (RemoteException e) {
863 Log.e(TAG, "RemoteException attempting to get TTY supported state.", e);
864 }
865 return false;
866 }
867
868 /**
869 * 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 -0700870 * settings and have a wired headset plugged in.
871 * Valid modes are:
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700872 * - {@link TelecomManager#TTY_MODE_OFF}
873 * - {@link TelecomManager#TTY_MODE_FULL}
874 * - {@link TelecomManager#TTY_MODE_HCO}
875 * - {@link TelecomManager#TTY_MODE_VCO}
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700876 * @hide
877 */
878 public int getCurrentTtyMode() {
879 try {
880 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700881 return getTelecomService().getCurrentTtyMode();
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700882 }
883 } catch (RemoteException e) {
884 Log.e(TAG, "RemoteException attempting to get the current TTY mode.", e);
885 }
Evan Charlton10197192014-07-19 15:00:29 -0700886 return TTY_MODE_OFF;
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700887 }
888
Santos Cordon96efb482014-07-19 14:57:05 -0700889 /**
890 * Registers a new incoming call. A {@link ConnectionService} should invoke this method when it
891 * has an incoming call. The specified {@link PhoneAccountHandle} must have been registered
Nancy Chen210ef032014-09-15 17:58:42 -0700892 * with {@link #registerPhoneAccount}. Once invoked, this method will cause the system to bind
893 * to the {@link ConnectionService} associated with the {@link PhoneAccountHandle} and request
Santos Cordon96efb482014-07-19 14:57:05 -0700894 * additional information about the call (See
895 * {@link ConnectionService#onCreateIncomingConnection}) before starting the incoming call UI.
896 *
897 * @param phoneAccount A {@link PhoneAccountHandle} registered with
898 * {@link #registerPhoneAccount}.
899 * @param extras A bundle that will be passed through to
900 * {@link ConnectionService#onCreateIncomingConnection}.
901 */
902 public void addNewIncomingCall(PhoneAccountHandle phoneAccount, Bundle extras) {
903 try {
904 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700905 getTelecomService().addNewIncomingCall(
Santos Cordon96efb482014-07-19 14:57:05 -0700906 phoneAccount, extras == null ? new Bundle() : extras);
907 }
908 } catch (RemoteException e) {
909 Log.e(TAG, "RemoteException adding a new incoming call: " + phoneAccount, e);
910 }
911 }
912
Nancy Chen0eb1e402014-08-21 22:52:29 -0700913 /**
Yorke Leec3cf9822014-10-02 09:38:39 -0700914 * Registers a new unknown call with Telecom. This can only be called by the system Telephony
915 * service. This is invoked when Telephony detects a new unknown connection that was neither
916 * a new incoming call, nor an user-initiated outgoing call.
917 *
918 * @param phoneAccount A {@link PhoneAccountHandle} registered with
919 * {@link #registerPhoneAccount}.
920 * @param extras A bundle that will be passed through to
921 * {@link ConnectionService#onCreateIncomingConnection}.
922 * @hide
923 */
924 @SystemApi
925 public void addNewUnknownCall(PhoneAccountHandle phoneAccount, Bundle extras) {
926 try {
927 if (isServiceConnected()) {
928 getTelecomService().addNewUnknownCall(
929 phoneAccount, extras == null ? new Bundle() : extras);
930 }
931 } catch (RemoteException e) {
932 Log.e(TAG, "RemoteException adding a new unknown call: " + phoneAccount, e);
933 }
934 }
935
936 /**
Nancy Chen0eb1e402014-08-21 22:52:29 -0700937 * Processes the specified dial string as an MMI code.
938 * MMI codes are any sequence of characters entered into the dialpad that contain a "*" or "#".
939 * Some of these sequences launch special behavior through handled by Telephony.
Nancy Chen95e8a672014-10-16 18:38:21 -0700940 * This method uses the default subscription.
Nancy Chen0eb1e402014-08-21 22:52:29 -0700941 * <p>
942 * Requires that the method-caller be set as the system dialer app.
943 * </p>
944 *
945 * @param dialString The digits to dial.
946 * @return True if the digits were processed as an MMI code, false otherwise.
947 */
948 public boolean handleMmi(String dialString) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700949 ITelecomService service = getTelecomService();
Nancy Chen0eb1e402014-08-21 22:52:29 -0700950 if (service != null) {
951 try {
952 return service.handlePinMmi(dialString);
953 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700954 Log.e(TAG, "Error calling ITelecomService#handlePinMmi", e);
Nancy Chen0eb1e402014-08-21 22:52:29 -0700955 }
956 }
957 return false;
958 }
959
960 /**
Nancy Chen95e8a672014-10-16 18:38:21 -0700961 * Processes the specified dial string as an MMI code.
962 * MMI codes are any sequence of characters entered into the dialpad that contain a "*" or "#".
963 * Some of these sequences launch special behavior through handled by Telephony.
964 * <p>
965 * Requires that the method-caller be set as the system dialer app.
966 * </p>
967 *
968 * @param accountHandle The handle for the account the MMI code should apply to.
969 * @param dialString The digits to dial.
970 * @return True if the digits were processed as an MMI code, false otherwise.
Nancy Chen95e8a672014-10-16 18:38:21 -0700971 */
Yorke Lee0bce8902015-04-14 15:16:59 -0700972 public boolean handleMmi(String dialString, PhoneAccountHandle accountHandle) {
Nancy Chen95e8a672014-10-16 18:38:21 -0700973 ITelecomService service = getTelecomService();
974 if (service != null) {
975 try {
976 return service.handlePinMmiForPhoneAccount(accountHandle, dialString);
977 } catch (RemoteException e) {
978 Log.e(TAG, "Error calling ITelecomService#handlePinMmi", e);
979 }
980 }
981 return false;
982 }
983
984 /**
Nancy Chenb2299c12014-10-29 18:22:11 -0700985 * @param accountHandle The handle for the account to derive an adn query URI for or
986 * {@code null} to return a URI which will use the default account.
987 * @return The URI (with the content:// scheme) specific to the specified {@link PhoneAccount}
988 * for the the content retrieve.
989 */
990 public Uri getAdnUriForPhoneAccount(PhoneAccountHandle accountHandle) {
991 ITelecomService service = getTelecomService();
992 if (service != null && accountHandle != null) {
993 try {
994 return service.getAdnUriForPhoneAccount(accountHandle);
995 } catch (RemoteException e) {
996 Log.e(TAG, "Error calling ITelecomService#getAdnUriForPhoneAccount", e);
997 }
998 }
999 return Uri.parse("content://icc/adn");
1000 }
1001
1002 /**
Nancy Chen0eb1e402014-08-21 22:52:29 -07001003 * Removes the missed-call notification if one is present.
1004 * <p>
1005 * Requires that the method-caller be set as the system dialer app.
1006 * </p>
1007 */
1008 public void cancelMissedCallsNotification() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001009 ITelecomService service = getTelecomService();
Nancy Chen0eb1e402014-08-21 22:52:29 -07001010 if (service != null) {
1011 try {
1012 service.cancelMissedCallsNotification();
1013 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001014 Log.e(TAG, "Error calling ITelecomService#cancelMissedCallsNotification", e);
Nancy Chen0eb1e402014-08-21 22:52:29 -07001015 }
1016 }
1017 }
1018
1019 /**
1020 * Brings the in-call screen to the foreground if there is an ongoing call. If there is
1021 * currently no ongoing call, then this method does nothing.
1022 * <p>
1023 * Requires that the method-caller be set as the system dialer app or have the
1024 * {@link android.Manifest.permission#READ_PHONE_STATE} permission.
1025 * </p>
1026 *
1027 * @param showDialpad Brings up the in-call dialpad as part of showing the in-call screen.
1028 */
1029 public void showInCallScreen(boolean showDialpad) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001030 ITelecomService service = getTelecomService();
Nancy Chen0eb1e402014-08-21 22:52:29 -07001031 if (service != null) {
1032 try {
1033 service.showInCallScreen(showDialpad);
1034 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001035 Log.e(TAG, "Error calling ITelecomService#showCallScreen", e);
Nancy Chen0eb1e402014-08-21 22:52:29 -07001036 }
1037 }
1038 }
1039
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001040 private ITelecomService getTelecomService() {
1041 return ITelecomService.Stub.asInterface(ServiceManager.getService(Context.TELECOM_SERVICE));
Santos Cordon6c7a3882014-06-25 15:30:08 -07001042 }
Santos Cordon9eb45932014-06-27 12:28:43 -07001043
1044 private boolean isServiceConnected() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001045 boolean isConnected = getTelecomService() != null;
Santos Cordon9eb45932014-06-27 12:28:43 -07001046 if (!isConnected) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001047 Log.w(TAG, "Telecom Service not found.");
Santos Cordon9eb45932014-06-27 12:28:43 -07001048 }
1049 return isConnected;
1050 }
Evan Charlton235c1592014-09-05 15:41:23 +00001051}