blob: 6c5f1c62a53959bbbe3c71bdcc64fb01ef995aeb [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.
58 *
Santos Cordon96efb482014-07-19 14:57:05 -070059 * @hide
Evan Charlton10197192014-07-19 15:00:29 -070060 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -070061 public static final String ACTION_INCOMING_CALL = "android.telecom.action.INCOMING_CALL";
Evan Charlton10197192014-07-19 15:00:29 -070062
63 /**
Yorke Leec3cf9822014-10-02 09:38:39 -070064 * Similar to {@link #ACTION_INCOMING_CALL}, but is used only by Telephony to add a new
65 * sim-initiated MO call for carrier testing.
66 * @hide
67 */
68 public static final String ACTION_NEW_UNKNOWN_CALL = "android.telecom.action.NEW_UNKNOWN_CALL";
69
70 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -070071 * The {@link android.content.Intent} action used to configure a
Tyler Gunnef9f6f92014-09-12 22:16:17 -070072 * {@link android.telecom.ConnectionService}.
Evan Charlton0e094d92014-11-08 15:49:16 -080073 * @hide
Evan Charlton10197192014-07-19 15:00:29 -070074 */
Evan Charlton0e094d92014-11-08 15:49:16 -080075 @SystemApi
Evan Charlton10197192014-07-19 15:00:29 -070076 public static final String ACTION_CONNECTION_SERVICE_CONFIGURE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -070077 "android.telecom.action.CONNECTION_SERVICE_CONFIGURE";
Evan Charlton10197192014-07-19 15:00:29 -070078
79 /**
Yorke Lee3818a8922014-07-21 15:57:17 -070080 * The {@link android.content.Intent} action used to show the call settings page.
81 */
82 public static final String ACTION_SHOW_CALL_SETTINGS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -070083 "android.telecom.action.SHOW_CALL_SETTINGS";
Yorke Lee3818a8922014-07-21 15:57:17 -070084
85 /**
Evan Charlton6d8604f2014-09-04 12:38:17 -070086 * The {@link android.content.Intent} action used to show the settings page used to configure
87 * {@link PhoneAccount} preferences.
Evan Charlton0e094d92014-11-08 15:49:16 -080088 * @hide
Evan Charlton6d8604f2014-09-04 12:38:17 -070089 */
Evan Charlton0e094d92014-11-08 15:49:16 -080090 @SystemApi
Evan Charlton6d8604f2014-09-04 12:38:17 -070091 public static final String ACTION_CHANGE_PHONE_ACCOUNTS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -070092 "android.telecom.action.CHANGE_PHONE_ACCOUNTS";
Evan Charlton6d8604f2014-09-04 12:38:17 -070093
94 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -070095 * Optional extra for {@link android.content.Intent#ACTION_CALL} containing a boolean that
96 * determines whether the speakerphone should be automatically turned on for an outgoing call.
Evan Charlton10197192014-07-19 15:00:29 -070097 */
98 public static final String EXTRA_START_CALL_WITH_SPEAKERPHONE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -070099 "android.telecom.extra.START_CALL_WITH_SPEAKERPHONE";
Evan Charlton10197192014-07-19 15:00:29 -0700100
101 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700102 * Optional extra for {@link android.content.Intent#ACTION_CALL} containing an integer that
103 * determines the desired video state for an outgoing call.
Santos Cordon96efb482014-07-19 14:57:05 -0700104 * Valid options:
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700105 * {@link VideoProfile.VideoState#AUDIO_ONLY},
106 * {@link VideoProfile.VideoState#BIDIRECTIONAL},
107 * {@link VideoProfile.VideoState#RX_ENABLED},
108 * {@link VideoProfile.VideoState#TX_ENABLED}.
Evan Charlton10197192014-07-19 15:00:29 -0700109 */
110 public static final String EXTRA_START_CALL_WITH_VIDEO_STATE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700111 "android.telecom.extra.START_CALL_WITH_VIDEO_STATE";
Evan Charlton10197192014-07-19 15:00:29 -0700112
113 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700114 * The extra used with an {@link android.content.Intent#ACTION_CALL} and
115 * {@link android.content.Intent#ACTION_DIAL} {@code Intent} to specify a
116 * {@link PhoneAccountHandle} to use when making the call.
Evan Charlton10197192014-07-19 15:00:29 -0700117 * <p class="note">
Santos Cordon96efb482014-07-19 14:57:05 -0700118 * Retrieve with {@link android.content.Intent#getParcelableExtra(String)}.
Evan Charlton10197192014-07-19 15:00:29 -0700119 */
Evan Charlton6eb262c2014-07-19 18:18:19 -0700120 public static final String EXTRA_PHONE_ACCOUNT_HANDLE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700121 "android.telecom.extra.PHONE_ACCOUNT_HANDLE";
Evan Charlton10197192014-07-19 15:00:29 -0700122
123 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700124 * Optional extra for {@link #ACTION_INCOMING_CALL} containing a {@link Bundle} which contains
125 * metadata about the call. This {@link Bundle} will be returned to the
126 * {@link ConnectionService}.
127 *
128 * @hide
Evan Charlton10197192014-07-19 15:00:29 -0700129 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800130 @SystemApi
Evan Charlton10197192014-07-19 15:00:29 -0700131 public static final String EXTRA_INCOMING_CALL_EXTRAS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700132 "android.telecom.extra.INCOMING_CALL_EXTRAS";
Evan Charlton10197192014-07-19 15:00:29 -0700133
134 /**
Nancy Chen10798dc2014-08-08 14:00:25 -0700135 * Optional extra for {@link android.content.Intent#ACTION_CALL} and
136 * {@link android.content.Intent#ACTION_DIAL} {@code Intent} containing a {@link Bundle}
137 * which contains metadata about the call. This {@link Bundle} will be saved into
138 * {@code Call.Details}.
Nancy Chen10798dc2014-08-08 14:00:25 -0700139 */
140 public static final String EXTRA_OUTGOING_CALL_EXTRAS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700141 "android.telecom.extra.OUTGOING_CALL_EXTRAS";
Nancy Chen10798dc2014-08-08 14:00:25 -0700142
143 /**
Yorke Leec3cf9822014-10-02 09:38:39 -0700144 * @hide
145 */
146 public static final String EXTRA_UNKNOWN_CALL_HANDLE =
147 "android.telecom.extra.UNKNOWN_CALL_HANDLE";
148
149 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700150 * Optional extra for {@link android.telephony.TelephonyManager#ACTION_PHONE_STATE_CHANGED}
151 * containing the disconnect code.
Evan Charlton10197192014-07-19 15:00:29 -0700152 */
153 public static final String EXTRA_CALL_DISCONNECT_CAUSE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700154 "android.telecom.extra.CALL_DISCONNECT_CAUSE";
Evan Charlton10197192014-07-19 15:00:29 -0700155
156 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700157 * Optional extra for {@link android.telephony.TelephonyManager#ACTION_PHONE_STATE_CHANGED}
158 * containing the disconnect message.
Evan Charlton10197192014-07-19 15:00:29 -0700159 */
160 public static final String EXTRA_CALL_DISCONNECT_MESSAGE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700161 "android.telecom.extra.CALL_DISCONNECT_MESSAGE";
Evan Charlton10197192014-07-19 15:00:29 -0700162
163 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700164 * Optional extra for {@link android.telephony.TelephonyManager#ACTION_PHONE_STATE_CHANGED}
165 * containing the component name of the associated connection service.
Evan Charlton0e094d92014-11-08 15:49:16 -0800166 * @hide
Evan Charlton10197192014-07-19 15:00:29 -0700167 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800168 @SystemApi
Evan Charlton10197192014-07-19 15:00:29 -0700169 public static final String EXTRA_CONNECTION_SERVICE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700170 "android.telecom.extra.CONNECTION_SERVICE";
Evan Charlton10197192014-07-19 15:00:29 -0700171
172 /**
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700173 * An optional {@link android.content.Intent#ACTION_CALL} intent extra denoting the
174 * package name of the app specifying an alternative gateway for the call.
175 * The value is a string.
176 *
177 * (The following comment corresponds to the all GATEWAY_* extras)
178 * An app which sends the {@link android.content.Intent#ACTION_CALL} intent can specify an
179 * alternative address to dial which is different from the one specified and displayed to
180 * the user. This alternative address is referred to as the gateway address.
181 */
182 public static final String GATEWAY_PROVIDER_PACKAGE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700183 "android.telecom.extra.GATEWAY_PROVIDER_PACKAGE";
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700184
185 /**
186 * An optional {@link android.content.Intent#ACTION_CALL} intent extra corresponding to the
187 * original address to dial for the call. This is used when an alternative gateway address is
188 * provided to recall the original address.
189 * The value is a {@link android.net.Uri}.
190 *
191 * (See {@link #GATEWAY_PROVIDER_PACKAGE} for details)
192 */
193 public static final String GATEWAY_ORIGINAL_ADDRESS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700194 "android.telecom.extra.GATEWAY_ORIGINAL_ADDRESS";
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700195
196 /**
Evan Charlton10197192014-07-19 15:00:29 -0700197 * The number which the party on the other side of the line will see (and use to return the
198 * call).
199 * <p>
Santos Cordon96efb482014-07-19 14:57:05 -0700200 * {@link ConnectionService}s which interact with {@link RemoteConnection}s should only populate
201 * this if the {@link android.telephony.TelephonyManager#getLine1Number()} value, as that is the
202 * user's expected caller ID.
Evan Charlton0e094d92014-11-08 15:49:16 -0800203 * @hide
Evan Charlton10197192014-07-19 15:00:29 -0700204 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800205 @SystemApi
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.
Evan Charlton0e094d92014-11-08 15:49:16 -0800346 * @hide
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700347 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800348 @SystemApi
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700349 public PhoneAccountHandle getDefaultOutgoingPhoneAccount(String uriScheme) {
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700350 try {
351 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700352 return getTelecomService().getDefaultOutgoingPhoneAccount(uriScheme);
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700353 }
354 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700355 Log.e(TAG, "Error calling ITelecomService#getDefaultOutgoingPhoneAccount", e);
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700356 }
357 return null;
358 }
359
360 /**
Andrew Leed4abbfb2014-09-03 14:58:27 -0700361 * Return the {@link PhoneAccount} which is the user-chosen default for making outgoing phone
362 * calls. This {@code PhoneAccount} will always be a member of the list which is returned from
Nancy Chen210ef032014-09-15 17:58:42 -0700363 * calling {@link #getCallCapablePhoneAccounts()}
Andrew Leed4abbfb2014-09-03 14:58:27 -0700364 *
365 * Apps must be prepared for this method to return {@code null}, indicating that there currently
366 * exists no user-chosen default {@code PhoneAccount}.
367 *
368 * @return The user outgoing phone account selected by the user.
369 * @hide
370 */
371 public PhoneAccountHandle getUserSelectedOutgoingPhoneAccount() {
372 try {
373 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700374 return getTelecomService().getUserSelectedOutgoingPhoneAccount();
Andrew Leed4abbfb2014-09-03 14:58:27 -0700375 }
376 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700377 Log.e(TAG, "Error calling ITelecomService#getUserSelectedOutgoingPhoneAccount", e);
Andrew Leed4abbfb2014-09-03 14:58:27 -0700378 }
379 return null;
380 }
381
382 /**
Andrew Lee59cac3a2014-08-28 16:50:10 -0700383 * Sets the default account for making outgoing phone calls.
384 * @hide
385 */
Andrew Leed4abbfb2014-09-03 14:58:27 -0700386 public void setUserSelectedOutgoingPhoneAccount(PhoneAccountHandle accountHandle) {
Andrew Lee59cac3a2014-08-28 16:50:10 -0700387 try {
388 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700389 getTelecomService().setUserSelectedOutgoingPhoneAccount(accountHandle);
Andrew Lee59cac3a2014-08-28 16:50:10 -0700390 }
391 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700392 Log.e(TAG, "Error calling ITelecomService#setUserSelectedOutgoingPhoneAccount");
Andrew Lee59cac3a2014-08-28 16:50:10 -0700393 }
394 }
395
396 /**
Andrew Lee59cac3a2014-08-28 16:50:10 -0700397 * Returns the current SIM call manager. Apps must be prepared for this method to return
398 * {@code null}, indicating that there currently exists no user-chosen default
399 * {@code PhoneAccount}.
400 * @return The phone account handle of the current sim call manager.
401 * @hide
402 */
403 public PhoneAccountHandle getSimCallManager() {
404 try {
405 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700406 return getTelecomService().getSimCallManager();
Andrew Lee59cac3a2014-08-28 16:50:10 -0700407 }
408 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700409 Log.e(TAG, "Error calling ITelecomService#getSimCallManager");
Andrew Lee59cac3a2014-08-28 16:50:10 -0700410 }
411 return null;
412 }
413
414 /**
415 * Sets the SIM call manager to the specified phone account.
416 * @param accountHandle The phone account handle of the account to set as the sim call manager.
417 * @hide
418 */
419 public void setSimCallManager(PhoneAccountHandle accountHandle) {
420 try {
421 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700422 getTelecomService().setSimCallManager(accountHandle);
Andrew Lee59cac3a2014-08-28 16:50:10 -0700423 }
424 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700425 Log.e(TAG, "Error calling ITelecomService#setSimCallManager");
Andrew Lee59cac3a2014-08-28 16:50:10 -0700426 }
427 }
428
429 /**
430 * Returns the list of registered SIM call managers.
431 * @return List of registered SIM call managers.
432 * @hide
433 */
434 public List<PhoneAccountHandle> getSimCallManagers() {
435 try {
436 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700437 return getTelecomService().getSimCallManagers();
Andrew Lee59cac3a2014-08-28 16:50:10 -0700438 }
439 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700440 Log.e(TAG, "Error calling ITelecomService#getSimCallManagers");
Andrew Lee59cac3a2014-08-28 16:50:10 -0700441 }
442 return new ArrayList<>();
443 }
444
445 /**
Evan Charltoneb0a8d562014-09-04 12:03:34 -0700446 * Returns the current connection manager. Apps must be prepared for this method to return
447 * {@code null}, indicating that there currently exists no user-chosen default
448 * {@code PhoneAccount}.
449 *
450 * @return The phone account handle of the current connection manager.
Evan Charlton0e094d92014-11-08 15:49:16 -0800451 * @hide
Evan Charltoneb0a8d562014-09-04 12:03:34 -0700452 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800453 @SystemApi
Evan Charltoneb0a8d562014-09-04 12:03:34 -0700454 public PhoneAccountHandle getConnectionManager() {
455 return getSimCallManager();
456 }
457
458 /**
Sailesh Nepal7a4e3872014-11-21 11:01:40 -0800459 * Returns the list of registered SIM call managers.
460 * @return List of registered SIM call managers.
461 * @hide
462 */
463 @SystemApi
464 public List<PhoneAccountHandle> getRegisteredConnectionManagers() {
465 return getSimCallManagers();
466 }
467
468 /**
Nancy Chen210ef032014-09-15 17:58:42 -0700469 * Returns a list of the {@link PhoneAccountHandle}s which can be used to make and receive phone
470 * calls which support the specified URI scheme.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700471 * <P>
472 * For example, invoking with {@code "tel"} will find all {@link PhoneAccountHandle}s which
473 * support telephone calls (e.g. URIs such as {@code tel:555-555-1212}). Invoking with
474 * {@code "sip"} will find all {@link PhoneAccountHandle}s which support SIP calls (e.g. URIs
475 * such as {@code sip:example@sipexample.com}).
476 *
477 * @param uriScheme The URI scheme.
478 * @return A list of {@code PhoneAccountHandle} objects supporting the URI scheme.
Evan Charlton0e094d92014-11-08 15:49:16 -0800479 * @hide
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700480 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800481 @SystemApi
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700482 public List<PhoneAccountHandle> getPhoneAccountsSupportingScheme(String uriScheme) {
483 try {
484 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700485 return getTelecomService().getPhoneAccountsSupportingScheme(uriScheme);
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700486 }
487 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700488 Log.e(TAG, "Error calling ITelecomService#getPhoneAccountsSupportingScheme", e);
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700489 }
490 return new ArrayList<>();
491 }
492
Nancy Chen513c8922014-09-17 14:47:20 -0700493
494 /**
495 * Return a list of {@link PhoneAccountHandle}s which can be used to make and receive phone
496 * calls.
497 *
498 * @see #EXTRA_PHONE_ACCOUNT_HANDLE
499 * @return A list of {@code PhoneAccountHandle} objects.
500 *
501 * @hide
502 */
503 public List<PhoneAccountHandle> getCallCapablePhoneAccounts() {
504 try {
505 if (isServiceConnected()) {
506 return getTelecomService().getCallCapablePhoneAccounts();
507 }
508 } catch (RemoteException e) {
509 Log.e(TAG, "Error calling ITelecomService#getCallCapablePhoneAccounts", e);
510 }
511 return new ArrayList<>();
512 }
513
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700514 /**
Nancy Chen210ef032014-09-15 17:58:42 -0700515 * Determine whether the device has more than one account registered that can make and receive
516 * phone calls.
Nancy Chen60801182014-07-22 16:56:49 -0700517 *
Nancy Chen210ef032014-09-15 17:58:42 -0700518 * @return {@code true} if the device has more than one account registered and {@code false}
519 * otherwise.
Evan Charlton0e094d92014-11-08 15:49:16 -0800520 * @hide
Nancy Chen60801182014-07-22 16:56:49 -0700521 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800522 @SystemApi
Nancy Chen210ef032014-09-15 17:58:42 -0700523 public boolean hasMultipleCallCapableAccounts() {
524 return getCallCapablePhoneAccounts().size() > 1;
Nancy Chen60801182014-07-22 16:56:49 -0700525 }
526
527 /**
Nancy Chen513c8922014-09-17 14:47:20 -0700528 * Returns a list of all {@link PhoneAccount}s registered for the calling package.
529 *
530 * @return A list of {@code PhoneAccountHandle} objects.
Evan Charlton0e094d92014-11-08 15:49:16 -0800531 * @hide
Nancy Chen513c8922014-09-17 14:47:20 -0700532 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800533 @SystemApi
Nancy Chen513c8922014-09-17 14:47:20 -0700534 public List<PhoneAccountHandle> getPhoneAccountsForPackage() {
535 try {
536 if (isServiceConnected()) {
537 return getTelecomService().getPhoneAccountsForPackage(mContext.getPackageName());
538 }
539 } catch (RemoteException e) {
540 Log.e(TAG, "Error calling ITelecomService#getPhoneAccountsForPackage", e);
541 }
542 return null;
543 }
544
545 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700546 * Return the {@link PhoneAccount} for a specified {@link PhoneAccountHandle}. Object includes
547 * resources which can be used in a user interface.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700548 *
Evan Charlton6eb262c2014-07-19 18:18:19 -0700549 * @param account The {@link PhoneAccountHandle}.
Evan Charlton8c8a0622014-07-20 12:31:00 -0700550 * @return The {@link PhoneAccount} object.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700551 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700552 public PhoneAccount getPhoneAccount(PhoneAccountHandle account) {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700553 try {
554 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700555 return getTelecomService().getPhoneAccount(account);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700556 }
557 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700558 Log.e(TAG, "Error calling ITelecomService#getPhoneAccount", e);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700559 }
560 return null;
561 }
562
563 /**
Nancy Chen210ef032014-09-15 17:58:42 -0700564 * Returns a count of all {@link PhoneAccount}s.
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700565 *
Nancy Chen210ef032014-09-15 17:58:42 -0700566 * @return The count of {@link PhoneAccount}s.
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700567 * @hide
568 */
569 @SystemApi
570 public int getAllPhoneAccountsCount() {
571 try {
572 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700573 return getTelecomService().getAllPhoneAccountsCount();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700574 }
575 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700576 Log.e(TAG, "Error calling ITelecomService#getAllPhoneAccountsCount", e);
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700577 }
578 return 0;
579 }
580
581 /**
582 * Returns a list of all {@link PhoneAccount}s.
583 *
584 * @return All {@link PhoneAccount}s.
585 * @hide
586 */
587 @SystemApi
588 public List<PhoneAccount> getAllPhoneAccounts() {
589 try {
590 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700591 return getTelecomService().getAllPhoneAccounts();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700592 }
593 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700594 Log.e(TAG, "Error calling ITelecomService#getAllPhoneAccounts", e);
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700595 }
596 return Collections.EMPTY_LIST;
597 }
598
599 /**
600 * Returns a list of all {@link PhoneAccountHandle}s.
601 *
602 * @return All {@link PhoneAccountHandle}s.
603 * @hide
604 */
605 @SystemApi
606 public List<PhoneAccountHandle> getAllPhoneAccountHandles() {
607 try {
608 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700609 return getTelecomService().getAllPhoneAccountHandles();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700610 }
611 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700612 Log.e(TAG, "Error calling ITelecomService#getAllPhoneAccountHandles", e);
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700613 }
614 return Collections.EMPTY_LIST;
615 }
616
617 /**
Santos Cordond9e614f2014-10-28 13:10:36 -0700618 * Register a {@link PhoneAccount} for use by the system. When registering
619 * {@link PhoneAccount}s, existing registrations will be overwritten if the
620 * {@link PhoneAccountHandle} matches that of a {@link PhoneAccount} which is already
621 * registered. Once registered, the {@link PhoneAccount} is listed to the user as an option
622 * when placing calls. The user may still need to enable the {@link PhoneAccount} within
623 * the phone app settings before the account is usable.
624 * <p>
625 * A {@link SecurityException} will be thrown if an app tries to register a
626 * {@link PhoneAccountHandle} where the package name specified within
627 * {@link PhoneAccountHandle#getComponentName()} does not match the package name of the app.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700628 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700629 * @param account The complete {@link PhoneAccount}.
Evan Charlton0e094d92014-11-08 15:49:16 -0800630 *
631 * @hide
Ihab Awad807fe0a2014-07-09 12:30:52 -0700632 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800633 @SystemApi
Evan Charlton8c8a0622014-07-20 12:31:00 -0700634 public void registerPhoneAccount(PhoneAccount account) {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700635 try {
636 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700637 getTelecomService().registerPhoneAccount(account);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700638 }
639 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700640 Log.e(TAG, "Error calling ITelecomService#registerPhoneAccount", e);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700641 }
642 }
643
644 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700645 * Remove a {@link PhoneAccount} registration from the system.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700646 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700647 * @param accountHandle A {@link PhoneAccountHandle} for the {@link PhoneAccount} to unregister.
Evan Charlton0e094d92014-11-08 15:49:16 -0800648 * @hide
Ihab Awad807fe0a2014-07-09 12:30:52 -0700649 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800650 @SystemApi
Evan Charlton8c8a0622014-07-20 12:31:00 -0700651 public void unregisterPhoneAccount(PhoneAccountHandle accountHandle) {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700652 try {
653 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700654 getTelecomService().unregisterPhoneAccount(accountHandle);
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#unregisterPhoneAccount", e);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700658 }
659 }
660
661 /**
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700662 * Remove all Accounts that belong to the calling package from the system.
Evan Charlton0e094d92014-11-08 15:49:16 -0800663 * @hide
Ihab Awad807fe0a2014-07-09 12:30:52 -0700664 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800665 @SystemApi
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700666 public void clearAccounts() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700667 try {
668 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700669 getTelecomService().clearAccounts(mContext.getPackageName());
Ihab Awad807fe0a2014-07-09 12:30:52 -0700670 }
671 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700672 Log.e(TAG, "Error calling ITelecomService#clearAccounts", e);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700673 }
674 }
675
676 /**
Anthony Lee67279262014-10-27 11:28:40 -0700677 * Remove all Accounts that belong to the specified package from the system.
678 * @hide
679 */
680 public void clearAccountsForPackage(String packageName) {
681 try {
682 if (isServiceConnected() && !TextUtils.isEmpty(packageName)) {
683 getTelecomService().clearAccounts(packageName);
684 }
685 } catch (RemoteException e) {
Nancy Chen5cf27842015-01-24 23:30:27 -0800686 Log.e(TAG, "Error calling ITelecomService#clearAccountsForPackage", e);
Anthony Lee67279262014-10-27 11:28:40 -0700687 }
688 }
689
690 /**
Ihab Awad807fe0a2014-07-09 12:30:52 -0700691 * @hide
692 */
Santos Cordon6c7a3882014-06-25 15:30:08 -0700693 @SystemApi
694 public ComponentName getDefaultPhoneApp() {
695 try {
Santos Cordon9eb45932014-06-27 12:28:43 -0700696 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700697 return getTelecomService().getDefaultPhoneApp();
Santos Cordon9eb45932014-06-27 12:28:43 -0700698 }
Santos Cordon6c7a3882014-06-25 15:30:08 -0700699 } catch (RemoteException e) {
700 Log.e(TAG, "RemoteException attempting to get the default phone app.", e);
701 }
702 return null;
703 }
704
Santos Cordon9eb45932014-06-27 12:28:43 -0700705 /**
Nancy Chen443e5012014-10-15 15:48:21 -0700706 * Return whether a given phone number is the configured voicemail number for a
707 * particular phone account.
708 *
709 * @param accountHandle The handle for the account to check the voicemail number against
710 * @param number The number to look up.
711 *
712 * @hide
713 */
714 @SystemApi
715 public boolean isVoiceMailNumber(PhoneAccountHandle accountHandle, String number) {
716 try {
717 if (isServiceConnected()) {
718 return getTelecomService().isVoiceMailNumber(accountHandle, number);
719 }
720 } catch (RemoteException e) {
Nancy Chen5cf27842015-01-24 23:30:27 -0800721 Log.e(TAG, "RemoteException calling ITelecomService#isVoiceMailNumber.", e);
Nancy Chen443e5012014-10-15 15:48:21 -0700722 }
723 return false;
724 }
725
726 /**
Nancy Chen8c066f7c2014-12-03 15:18:08 -0800727 * Return whether a given phone account has a voicemail number configured.
728 *
729 * @param accountHandle The handle for the account to check for a voicemail number.
730 * @return {@code true} If the given phone account has a voicemail number.
731 *
732 * @hide
733 */
734 @SystemApi
735 public boolean hasVoiceMailNumber(PhoneAccountHandle accountHandle) {
736 try {
737 if (isServiceConnected()) {
738 return getTelecomService().hasVoiceMailNumber(accountHandle);
739 }
740 } catch (RemoteException e) {
Nancy Chen5cf27842015-01-24 23:30:27 -0800741 Log.e(TAG, "RemoteException calling ITelecomService#hasVoiceMailNumber.", e);
Nancy Chen8c066f7c2014-12-03 15:18:08 -0800742 }
743 return false;
744 }
745
746 /**
Nancy Chen5cf27842015-01-24 23:30:27 -0800747 * Return the line 1 phone number for given phone account.
748 *
749 * @param accountHandle The handle for the account retrieve a number for.
750 * @return A string representation of the line 1 phone number.
751 *
752 * @hide
753 */
754 @SystemApi
755 public String getLine1Number(PhoneAccountHandle accountHandle) {
756 try {
757 if (isServiceConnected()) {
758 return getTelecomService().getLine1Number(accountHandle);
759 }
760 } catch (RemoteException e) {
761 Log.e(TAG, "RemoteException calling ITelecomService#getLine1Number.", e);
762 }
763 return null;
764 }
765
766 /**
Santos Cordon9eb45932014-06-27 12:28:43 -0700767 * Returns whether there is an ongoing phone call (can be in dialing, ringing, active or holding
768 * states).
Nancy Chen0eb1e402014-08-21 22:52:29 -0700769 * <p>
770 * Requires permission: {@link android.Manifest.permission#READ_PHONE_STATE}
771 * </p>
Santos Cordon9eb45932014-06-27 12:28:43 -0700772 */
Nancy Chen0eb1e402014-08-21 22:52:29 -0700773 public boolean isInCall() {
Santos Cordon9eb45932014-06-27 12:28:43 -0700774 try {
775 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700776 return getTelecomService().isInCall();
Santos Cordon9eb45932014-06-27 12:28:43 -0700777 }
778 } catch (RemoteException e) {
Yorke Lee2ae312e2014-09-12 17:58:48 -0700779 Log.e(TAG, "RemoteException calling isInCall().", e);
Santos Cordon9eb45932014-06-27 12:28:43 -0700780 }
781 return false;
782 }
783
784 /**
Yorke Lee2ae312e2014-09-12 17:58:48 -0700785 * Returns one of the following constants that represents the current state of Telecom:
786 *
787 * {@link TelephonyManager#CALL_STATE_RINGING}
788 * {@link TelephonyManager#CALL_STATE_OFFHOOK}
789 * {@link TelephonyManager#CALL_STATE_IDLE}
Yorke Lee7c72c2d2014-10-28 14:12:02 -0700790 *
791 * Note that this API does not require the
792 * {@link android.Manifest.permission#READ_PHONE_STATE} permission. This is intentional, to
793 * preserve the behavior of {@link TelephonyManager#getCallState()}, which also did not require
794 * the permission.
Yorke Lee2ae312e2014-09-12 17:58:48 -0700795 * @hide
796 */
797 @SystemApi
798 public int getCallState() {
799 try {
800 if (isServiceConnected()) {
801 return getTelecomService().getCallState();
802 }
803 } catch (RemoteException e) {
804 Log.d(TAG, "RemoteException calling getCallState().", e);
805 }
806 return TelephonyManager.CALL_STATE_IDLE;
807 }
808
809 /**
Santos Cordon9eb45932014-06-27 12:28:43 -0700810 * Returns whether there currently exists is a ringing incoming-call.
811 *
812 * @hide
813 */
814 @SystemApi
815 public boolean isRinging() {
816 try {
817 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700818 return getTelecomService().isRinging();
Santos Cordon9eb45932014-06-27 12:28:43 -0700819 }
820 } catch (RemoteException e) {
821 Log.e(TAG, "RemoteException attempting to get ringing state of phone app.", e);
822 }
823 return false;
824 }
825
826 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700827 * Ends an ongoing call.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700828 * TODO: L-release - need to convert all invocations of ITelecomService#endCall to use this
Santos Cordon96efb482014-07-19 14:57:05 -0700829 * method (clockwork & gearhead).
Santos Cordon9eb45932014-06-27 12:28:43 -0700830 * @hide
831 */
832 @SystemApi
833 public boolean endCall() {
834 try {
835 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700836 return getTelecomService().endCall();
Santos Cordon9eb45932014-06-27 12:28:43 -0700837 }
838 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700839 Log.e(TAG, "Error calling ITelecomService#endCall", e);
Santos Cordon9eb45932014-06-27 12:28:43 -0700840 }
841 return false;
842 }
843
844 /**
845 * If there is a ringing incoming call, this method accepts the call on behalf of the user.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700846 * TODO: L-release - need to convert all invocation of ITelecmmService#answerRingingCall to use
Santos Cordon96efb482014-07-19 14:57:05 -0700847 * this method (clockwork & gearhead).
Santos Cordon9eb45932014-06-27 12:28:43 -0700848 *
849 * @hide
850 */
851 @SystemApi
852 public void acceptRingingCall() {
853 try {
854 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700855 getTelecomService().acceptRingingCall();
Santos Cordon9eb45932014-06-27 12:28:43 -0700856 }
857 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700858 Log.e(TAG, "Error calling ITelecomService#acceptRingingCall", e);
Santos Cordon9eb45932014-06-27 12:28:43 -0700859 }
860 }
861
862 /**
863 * Silences the ringer if a ringing call exists.
864 *
865 * @hide
866 */
867 @SystemApi
868 public void silenceRinger() {
869 try {
870 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700871 getTelecomService().silenceRinger();
Santos Cordon9eb45932014-06-27 12:28:43 -0700872 }
873 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700874 Log.e(TAG, "Error calling ITelecomService#silenceRinger", e);
Santos Cordon9eb45932014-06-27 12:28:43 -0700875 }
876 }
877
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700878 /**
879 * Returns whether TTY is supported on this device.
880 *
881 * @hide
882 */
883 @SystemApi
884 public boolean isTtySupported() {
885 try {
886 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700887 return getTelecomService().isTtySupported();
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700888 }
889 } catch (RemoteException e) {
890 Log.e(TAG, "RemoteException attempting to get TTY supported state.", e);
891 }
892 return false;
893 }
894
895 /**
896 * 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 -0700897 * settings and have a wired headset plugged in.
898 * Valid modes are:
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700899 * - {@link TelecomManager#TTY_MODE_OFF}
900 * - {@link TelecomManager#TTY_MODE_FULL}
901 * - {@link TelecomManager#TTY_MODE_HCO}
902 * - {@link TelecomManager#TTY_MODE_VCO}
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700903 * @hide
904 */
905 public int getCurrentTtyMode() {
906 try {
907 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700908 return getTelecomService().getCurrentTtyMode();
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700909 }
910 } catch (RemoteException e) {
911 Log.e(TAG, "RemoteException attempting to get the current TTY mode.", e);
912 }
Evan Charlton10197192014-07-19 15:00:29 -0700913 return TTY_MODE_OFF;
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700914 }
915
Santos Cordon96efb482014-07-19 14:57:05 -0700916 /**
917 * Registers a new incoming call. A {@link ConnectionService} should invoke this method when it
918 * has an incoming call. The specified {@link PhoneAccountHandle} must have been registered
Nancy Chen210ef032014-09-15 17:58:42 -0700919 * with {@link #registerPhoneAccount}. Once invoked, this method will cause the system to bind
920 * to the {@link ConnectionService} associated with the {@link PhoneAccountHandle} and request
Santos Cordon96efb482014-07-19 14:57:05 -0700921 * additional information about the call (See
922 * {@link ConnectionService#onCreateIncomingConnection}) before starting the incoming call UI.
923 *
924 * @param phoneAccount A {@link PhoneAccountHandle} registered with
925 * {@link #registerPhoneAccount}.
926 * @param extras A bundle that will be passed through to
927 * {@link ConnectionService#onCreateIncomingConnection}.
Evan Charlton0e094d92014-11-08 15:49:16 -0800928 * @hide
Santos Cordon96efb482014-07-19 14:57:05 -0700929 */
Evan Charlton0e094d92014-11-08 15:49:16 -0800930 @SystemApi
Santos Cordon96efb482014-07-19 14:57:05 -0700931 public void addNewIncomingCall(PhoneAccountHandle phoneAccount, Bundle extras) {
932 try {
933 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700934 getTelecomService().addNewIncomingCall(
Santos Cordon96efb482014-07-19 14:57:05 -0700935 phoneAccount, extras == null ? new Bundle() : extras);
936 }
937 } catch (RemoteException e) {
938 Log.e(TAG, "RemoteException adding a new incoming call: " + phoneAccount, e);
939 }
940 }
941
Nancy Chen0eb1e402014-08-21 22:52:29 -0700942 /**
Yorke Leec3cf9822014-10-02 09:38:39 -0700943 * Registers a new unknown call with Telecom. This can only be called by the system Telephony
944 * service. This is invoked when Telephony detects a new unknown connection that was neither
945 * a new incoming call, nor an user-initiated outgoing call.
946 *
947 * @param phoneAccount A {@link PhoneAccountHandle} registered with
948 * {@link #registerPhoneAccount}.
949 * @param extras A bundle that will be passed through to
950 * {@link ConnectionService#onCreateIncomingConnection}.
951 * @hide
952 */
953 @SystemApi
954 public void addNewUnknownCall(PhoneAccountHandle phoneAccount, Bundle extras) {
955 try {
956 if (isServiceConnected()) {
957 getTelecomService().addNewUnknownCall(
958 phoneAccount, extras == null ? new Bundle() : extras);
959 }
960 } catch (RemoteException e) {
961 Log.e(TAG, "RemoteException adding a new unknown call: " + phoneAccount, e);
962 }
963 }
964
965 /**
Nancy Chen0eb1e402014-08-21 22:52:29 -0700966 * Processes the specified dial string as an MMI code.
967 * MMI codes are any sequence of characters entered into the dialpad that contain a "*" or "#".
968 * Some of these sequences launch special behavior through handled by Telephony.
Nancy Chen95e8a672014-10-16 18:38:21 -0700969 * This method uses the default subscription.
Nancy Chen0eb1e402014-08-21 22:52:29 -0700970 * <p>
971 * Requires that the method-caller be set as the system dialer app.
972 * </p>
973 *
974 * @param dialString The digits to dial.
975 * @return True if the digits were processed as an MMI code, false otherwise.
976 */
977 public boolean handleMmi(String dialString) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700978 ITelecomService service = getTelecomService();
Nancy Chen0eb1e402014-08-21 22:52:29 -0700979 if (service != null) {
980 try {
981 return service.handlePinMmi(dialString);
982 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700983 Log.e(TAG, "Error calling ITelecomService#handlePinMmi", e);
Nancy Chen0eb1e402014-08-21 22:52:29 -0700984 }
985 }
986 return false;
987 }
988
989 /**
Nancy Chen95e8a672014-10-16 18:38:21 -0700990 * Processes the specified dial string as an MMI code.
991 * MMI codes are any sequence of characters entered into the dialpad that contain a "*" or "#".
992 * Some of these sequences launch special behavior through handled by Telephony.
993 * <p>
994 * Requires that the method-caller be set as the system dialer app.
995 * </p>
996 *
997 * @param accountHandle The handle for the account the MMI code should apply to.
998 * @param dialString The digits to dial.
999 * @return True if the digits were processed as an MMI code, false otherwise.
Evan Charlton0e094d92014-11-08 15:49:16 -08001000 * @hide
Nancy Chen95e8a672014-10-16 18:38:21 -07001001 */
Evan Charlton0e094d92014-11-08 15:49:16 -08001002 @SystemApi
Nancy Chen95e8a672014-10-16 18:38:21 -07001003 public boolean handleMmi(PhoneAccountHandle accountHandle, String dialString) {
1004 ITelecomService service = getTelecomService();
1005 if (service != null) {
1006 try {
1007 return service.handlePinMmiForPhoneAccount(accountHandle, dialString);
1008 } catch (RemoteException e) {
1009 Log.e(TAG, "Error calling ITelecomService#handlePinMmi", e);
1010 }
1011 }
1012 return false;
1013 }
1014
1015 /**
Nancy Chenb2299c12014-10-29 18:22:11 -07001016 * @param accountHandle The handle for the account to derive an adn query URI for or
1017 * {@code null} to return a URI which will use the default account.
1018 * @return The URI (with the content:// scheme) specific to the specified {@link PhoneAccount}
1019 * for the the content retrieve.
Evan Charlton0e094d92014-11-08 15:49:16 -08001020 * @hide
Nancy Chenb2299c12014-10-29 18:22:11 -07001021 */
Evan Charlton0e094d92014-11-08 15:49:16 -08001022 @SystemApi
Nancy Chenb2299c12014-10-29 18:22:11 -07001023 public Uri getAdnUriForPhoneAccount(PhoneAccountHandle accountHandle) {
1024 ITelecomService service = getTelecomService();
1025 if (service != null && accountHandle != null) {
1026 try {
1027 return service.getAdnUriForPhoneAccount(accountHandle);
1028 } catch (RemoteException e) {
1029 Log.e(TAG, "Error calling ITelecomService#getAdnUriForPhoneAccount", e);
1030 }
1031 }
1032 return Uri.parse("content://icc/adn");
1033 }
1034
1035 /**
Nancy Chen0eb1e402014-08-21 22:52:29 -07001036 * Removes the missed-call notification if one is present.
1037 * <p>
1038 * Requires that the method-caller be set as the system dialer app.
1039 * </p>
1040 */
1041 public void cancelMissedCallsNotification() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001042 ITelecomService service = getTelecomService();
Nancy Chen0eb1e402014-08-21 22:52:29 -07001043 if (service != null) {
1044 try {
1045 service.cancelMissedCallsNotification();
1046 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001047 Log.e(TAG, "Error calling ITelecomService#cancelMissedCallsNotification", e);
Nancy Chen0eb1e402014-08-21 22:52:29 -07001048 }
1049 }
1050 }
1051
1052 /**
1053 * Brings the in-call screen to the foreground if there is an ongoing call. If there is
1054 * currently no ongoing call, then this method does nothing.
1055 * <p>
1056 * Requires that the method-caller be set as the system dialer app or have the
1057 * {@link android.Manifest.permission#READ_PHONE_STATE} permission.
1058 * </p>
1059 *
1060 * @param showDialpad Brings up the in-call dialpad as part of showing the in-call screen.
1061 */
1062 public void showInCallScreen(boolean showDialpad) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001063 ITelecomService service = getTelecomService();
Nancy Chen0eb1e402014-08-21 22:52:29 -07001064 if (service != null) {
1065 try {
1066 service.showInCallScreen(showDialpad);
1067 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001068 Log.e(TAG, "Error calling ITelecomService#showCallScreen", e);
Nancy Chen0eb1e402014-08-21 22:52:29 -07001069 }
1070 }
1071 }
1072
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001073 private ITelecomService getTelecomService() {
1074 return ITelecomService.Stub.asInterface(ServiceManager.getService(Context.TELECOM_SERVICE));
Santos Cordon6c7a3882014-06-25 15:30:08 -07001075 }
Santos Cordon9eb45932014-06-27 12:28:43 -07001076
1077 private boolean isServiceConnected() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001078 boolean isConnected = getTelecomService() != null;
Santos Cordon9eb45932014-06-27 12:28:43 -07001079 if (!isConnected) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001080 Log.w(TAG, "Telecom Service not found.");
Santos Cordon9eb45932014-06-27 12:28:43 -07001081 }
1082 return isConnected;
1083 }
Evan Charlton235c1592014-09-05 15:41:23 +00001084}