blob: 2227224a6a3201b8589741b8d617758ac6e1df48 [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;
Santos Cordon96efb482014-07-19 14:57:05 -070020import android.os.Bundle;
Santos Cordon6c7a3882014-06-25 15:30:08 -070021import android.os.RemoteException;
22import android.os.ServiceManager;
Yorke Lee2ae312e2014-09-12 17:58:48 -070023import android.telephony.TelephonyManager;
Santos Cordon6c7a3882014-06-25 15:30:08 -070024import android.util.Log;
Yorke Leeb4ce1432014-06-09 13:53:23 -070025
Tyler Gunnef9f6f92014-09-12 22:16:17 -070026import com.android.internal.telecom.ITelecomService;
Yorke Leeb4ce1432014-06-09 13:53:23 -070027
Jay Shrauner7746a942014-08-26 12:15:15 -070028import java.util.ArrayList;
Tyler Gunna1ed7d12014-09-08 09:52:22 -070029import java.util.Collections;
Ihab Awad807fe0a2014-07-09 12:30:52 -070030import java.util.List;
31
Yorke Leeb4ce1432014-06-09 13:53:23 -070032/**
Santos Cordond9e614f2014-10-28 13:10:36 -070033 * Provides access to information about active calls and registration/call-management functionality.
34 * Apps can use methods in this class to determine the current call state. Apps can also register new
35 * {@link PhoneAccount}s and get a listing of existing {@link PhoneAccount}s.
36 * <p>
37 * Apps do not instantiate this class directly; instead, they retrieve a reference to an instance
38 * through {@link Context#getSystemService Context.getSystemService(Context.TELECOM_SERVICE)}.
39 * <p>
40 * Note that access to some telecom information is permission-protected. Your app cannot access the
41 * protected information or gain access to protected functionality unless it has the appropriate
42 * permissions declared in its manifest file. Where permissions apply, they are noted in the method
43 * descriptions.
Yorke Leeb4ce1432014-06-09 13:53:23 -070044 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -070045public class TelecomManager {
Ihab Awad807fe0a2014-07-09 12:30:52 -070046
Evan Charlton10197192014-07-19 15:00:29 -070047 /**
Santos Cordon96efb482014-07-19 14:57:05 -070048 * Activity action: Starts the UI for handing an incoming call. This intent starts the in-call
Tyler Gunnef9f6f92014-09-12 22:16:17 -070049 * UI by notifying the Telecom system that an incoming call exists for a specific call service
50 * (see {@link android.telecom.ConnectionService}). Telecom reads the Intent extras to find
51 * and bind to the appropriate {@link android.telecom.ConnectionService} which Telecom will
Santos Cordon96efb482014-07-19 14:57:05 -070052 * ultimately use to control and get information about the call.
53 * <p>
54 * Input: get*Extra field {@link #EXTRA_PHONE_ACCOUNT_HANDLE} contains the component name of the
Tyler Gunnef9f6f92014-09-12 22:16:17 -070055 * {@link android.telecom.ConnectionService} that Telecom should bind to. Telecom will then
Evan Charlton10197192014-07-19 15:00:29 -070056 * ask the connection service for more information about the call prior to showing any UI.
57 *
Santos Cordon96efb482014-07-19 14:57:05 -070058 * @hide
Evan Charlton10197192014-07-19 15:00:29 -070059 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -070060 public static final String ACTION_INCOMING_CALL = "android.telecom.action.INCOMING_CALL";
Evan Charlton10197192014-07-19 15:00:29 -070061
62 /**
Yorke Leec3cf9822014-10-02 09:38:39 -070063 * Similar to {@link #ACTION_INCOMING_CALL}, but is used only by Telephony to add a new
64 * sim-initiated MO call for carrier testing.
65 * @hide
66 */
67 public static final String ACTION_NEW_UNKNOWN_CALL = "android.telecom.action.NEW_UNKNOWN_CALL";
68
69 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -070070 * The {@link android.content.Intent} action used to configure a
Tyler Gunnef9f6f92014-09-12 22:16:17 -070071 * {@link android.telecom.ConnectionService}.
Evan Charlton10197192014-07-19 15:00:29 -070072 */
73 public static final String ACTION_CONNECTION_SERVICE_CONFIGURE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -070074 "android.telecom.action.CONNECTION_SERVICE_CONFIGURE";
Evan Charlton10197192014-07-19 15:00:29 -070075
76 /**
Yorke Lee3818a8922014-07-21 15:57:17 -070077 * The {@link android.content.Intent} action used to show the call settings page.
78 */
79 public static final String ACTION_SHOW_CALL_SETTINGS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -070080 "android.telecom.action.SHOW_CALL_SETTINGS";
Yorke Lee3818a8922014-07-21 15:57:17 -070081
82 /**
Evan Charlton6d8604f2014-09-04 12:38:17 -070083 * The {@link android.content.Intent} action used to show the settings page used to configure
84 * {@link PhoneAccount} preferences.
85 */
86 public static final String ACTION_CHANGE_PHONE_ACCOUNTS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -070087 "android.telecom.action.CHANGE_PHONE_ACCOUNTS";
Evan Charlton6d8604f2014-09-04 12:38:17 -070088
89 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -070090 * Optional extra for {@link android.content.Intent#ACTION_CALL} containing a boolean that
91 * determines whether the speakerphone should be automatically turned on for an outgoing call.
Evan Charlton10197192014-07-19 15:00:29 -070092 */
93 public static final String EXTRA_START_CALL_WITH_SPEAKERPHONE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -070094 "android.telecom.extra.START_CALL_WITH_SPEAKERPHONE";
Evan Charlton10197192014-07-19 15:00:29 -070095
96 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -070097 * Optional extra for {@link android.content.Intent#ACTION_CALL} containing an integer that
98 * determines the desired video state for an outgoing call.
Santos Cordon96efb482014-07-19 14:57:05 -070099 * Valid options:
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700100 * {@link VideoProfile.VideoState#AUDIO_ONLY},
101 * {@link VideoProfile.VideoState#BIDIRECTIONAL},
102 * {@link VideoProfile.VideoState#RX_ENABLED},
103 * {@link VideoProfile.VideoState#TX_ENABLED}.
Tyler Gunn27d1e252014-08-21 16:38:40 -0700104 * @hide
Evan Charlton10197192014-07-19 15:00:29 -0700105 */
106 public static final String EXTRA_START_CALL_WITH_VIDEO_STATE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700107 "android.telecom.extra.START_CALL_WITH_VIDEO_STATE";
Evan Charlton10197192014-07-19 15:00:29 -0700108
109 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700110 * The extra used with an {@link android.content.Intent#ACTION_CALL} and
111 * {@link android.content.Intent#ACTION_DIAL} {@code Intent} to specify a
112 * {@link PhoneAccountHandle} to use when making the call.
Evan Charlton10197192014-07-19 15:00:29 -0700113 * <p class="note">
Santos Cordon96efb482014-07-19 14:57:05 -0700114 * Retrieve with {@link android.content.Intent#getParcelableExtra(String)}.
Evan Charlton10197192014-07-19 15:00:29 -0700115 */
Evan Charlton6eb262c2014-07-19 18:18:19 -0700116 public static final String EXTRA_PHONE_ACCOUNT_HANDLE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700117 "android.telecom.extra.PHONE_ACCOUNT_HANDLE";
Evan Charlton10197192014-07-19 15:00:29 -0700118
119 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700120 * Optional extra for {@link #ACTION_INCOMING_CALL} containing a {@link Bundle} which contains
121 * metadata about the call. This {@link Bundle} will be returned to the
122 * {@link ConnectionService}.
123 *
124 * @hide
Evan Charlton10197192014-07-19 15:00:29 -0700125 */
126 public static final String EXTRA_INCOMING_CALL_EXTRAS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700127 "android.telecom.extra.INCOMING_CALL_EXTRAS";
Evan Charlton10197192014-07-19 15:00:29 -0700128
129 /**
Nancy Chen10798dc2014-08-08 14:00:25 -0700130 * Optional extra for {@link android.content.Intent#ACTION_CALL} and
131 * {@link android.content.Intent#ACTION_DIAL} {@code Intent} containing a {@link Bundle}
132 * which contains metadata about the call. This {@link Bundle} will be saved into
133 * {@code Call.Details}.
134 *
135 * @hide
136 */
137 public static final String EXTRA_OUTGOING_CALL_EXTRAS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700138 "android.telecom.extra.OUTGOING_CALL_EXTRAS";
Nancy Chen10798dc2014-08-08 14:00:25 -0700139
140 /**
Yorke Leec3cf9822014-10-02 09:38:39 -0700141 * @hide
142 */
143 public static final String EXTRA_UNKNOWN_CALL_HANDLE =
144 "android.telecom.extra.UNKNOWN_CALL_HANDLE";
145
146 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700147 * Optional extra for {@link android.telephony.TelephonyManager#ACTION_PHONE_STATE_CHANGED}
148 * containing the disconnect code.
Evan Charlton10197192014-07-19 15:00:29 -0700149 */
150 public static final String EXTRA_CALL_DISCONNECT_CAUSE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700151 "android.telecom.extra.CALL_DISCONNECT_CAUSE";
Evan Charlton10197192014-07-19 15:00:29 -0700152
153 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700154 * Optional extra for {@link android.telephony.TelephonyManager#ACTION_PHONE_STATE_CHANGED}
155 * containing the disconnect message.
Evan Charlton10197192014-07-19 15:00:29 -0700156 */
157 public static final String EXTRA_CALL_DISCONNECT_MESSAGE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700158 "android.telecom.extra.CALL_DISCONNECT_MESSAGE";
Evan Charlton10197192014-07-19 15:00:29 -0700159
160 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700161 * Optional extra for {@link android.telephony.TelephonyManager#ACTION_PHONE_STATE_CHANGED}
162 * containing the component name of the associated connection service.
Evan Charlton10197192014-07-19 15:00:29 -0700163 */
164 public static final String EXTRA_CONNECTION_SERVICE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700165 "android.telecom.extra.CONNECTION_SERVICE";
Evan Charlton10197192014-07-19 15:00:29 -0700166
167 /**
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700168 * An optional {@link android.content.Intent#ACTION_CALL} intent extra denoting the
169 * package name of the app specifying an alternative gateway for the call.
170 * The value is a string.
171 *
172 * (The following comment corresponds to the all GATEWAY_* extras)
173 * An app which sends the {@link android.content.Intent#ACTION_CALL} intent can specify an
174 * alternative address to dial which is different from the one specified and displayed to
175 * the user. This alternative address is referred to as the gateway address.
176 */
177 public static final String GATEWAY_PROVIDER_PACKAGE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700178 "android.telecom.extra.GATEWAY_PROVIDER_PACKAGE";
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700179
180 /**
181 * An optional {@link android.content.Intent#ACTION_CALL} intent extra corresponding to the
182 * original address to dial for the call. This is used when an alternative gateway address is
183 * provided to recall the original address.
184 * The value is a {@link android.net.Uri}.
185 *
186 * (See {@link #GATEWAY_PROVIDER_PACKAGE} for details)
187 */
188 public static final String GATEWAY_ORIGINAL_ADDRESS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700189 "android.telecom.extra.GATEWAY_ORIGINAL_ADDRESS";
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700190
191 /**
Evan Charlton10197192014-07-19 15:00:29 -0700192 * The number which the party on the other side of the line will see (and use to return the
193 * call).
194 * <p>
Santos Cordon96efb482014-07-19 14:57:05 -0700195 * {@link ConnectionService}s which interact with {@link RemoteConnection}s should only populate
196 * this if the {@link android.telephony.TelephonyManager#getLine1Number()} value, as that is the
197 * user's expected caller ID.
Evan Charlton10197192014-07-19 15:00:29 -0700198 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700199 public static final String EXTRA_CALL_BACK_NUMBER = "android.telecom.extra.CALL_BACK_NUMBER";
Evan Charlton10197192014-07-19 15:00:29 -0700200
201 /**
202 * The dual tone multi-frequency signaling character sent to indicate the dialing system should
203 * pause for a predefined period.
204 */
205 public static final char DTMF_CHARACTER_PAUSE = ',';
206
207 /**
208 * The dual-tone multi-frequency signaling character sent to indicate the dialing system should
209 * wait for user confirmation before proceeding.
210 */
211 public static final char DTMF_CHARACTER_WAIT = ';';
212
213 /**
214 * TTY (teletypewriter) mode is off.
215 *
216 * @hide
217 */
218 public static final int TTY_MODE_OFF = 0;
219
220 /**
221 * TTY (teletypewriter) mode is on. The speaker is off and the microphone is muted. The user
222 * will communicate with the remote party by sending and receiving text messages.
223 *
224 * @hide
225 */
226 public static final int TTY_MODE_FULL = 1;
227
228 /**
229 * TTY (teletypewriter) mode is in hearing carryover mode (HCO). The microphone is muted but the
230 * speaker is on. The user will communicate with the remote party by sending text messages and
231 * hearing an audible reply.
232 *
233 * @hide
234 */
235 public static final int TTY_MODE_HCO = 2;
236
237 /**
238 * TTY (teletypewriter) mode is in voice carryover mode (VCO). The speaker is off but the
239 * microphone is still on. User will communicate with the remote party by speaking and receiving
240 * text message replies.
241 *
242 * @hide
243 */
244 public static final int TTY_MODE_VCO = 3;
245
246 /**
247 * Broadcast intent action indicating that the current TTY mode has changed. An intent extra
248 * provides this state as an int.
Evan Charlton10197192014-07-19 15:00:29 -0700249 *
Santos Cordon96efb482014-07-19 14:57:05 -0700250 * @see #EXTRA_CURRENT_TTY_MODE
Evan Charlton10197192014-07-19 15:00:29 -0700251 * @hide
252 */
253 public static final String ACTION_CURRENT_TTY_MODE_CHANGED =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700254 "android.telecom.action.CURRENT_TTY_MODE_CHANGED";
Evan Charlton10197192014-07-19 15:00:29 -0700255
256 /**
257 * The lookup key for an int that indicates the current TTY mode.
258 * Valid modes are:
259 * - {@link #TTY_MODE_OFF}
260 * - {@link #TTY_MODE_FULL}
261 * - {@link #TTY_MODE_HCO}
262 * - {@link #TTY_MODE_VCO}
263 *
264 * @hide
265 */
266 public static final String EXTRA_CURRENT_TTY_MODE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700267 "android.telecom.intent.extra.CURRENT_TTY_MODE";
Evan Charlton10197192014-07-19 15:00:29 -0700268
269 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700270 * Broadcast intent action indicating that the TTY preferred operating mode has changed. An
271 * intent extra provides the new mode as an int.
Evan Charlton10197192014-07-19 15:00:29 -0700272 *
Santos Cordon96efb482014-07-19 14:57:05 -0700273 * @see #EXTRA_TTY_PREFERRED_MODE
Evan Charlton10197192014-07-19 15:00:29 -0700274 * @hide
275 */
276 public static final String ACTION_TTY_PREFERRED_MODE_CHANGED =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700277 "android.telecom.action.TTY_PREFERRED_MODE_CHANGED";
Evan Charlton10197192014-07-19 15:00:29 -0700278
279 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700280 * The lookup key for an int that indicates preferred TTY mode. Valid modes are: -
281 * {@link #TTY_MODE_OFF} - {@link #TTY_MODE_FULL} - {@link #TTY_MODE_HCO} -
282 * {@link #TTY_MODE_VCO}
Evan Charlton10197192014-07-19 15:00:29 -0700283 *
284 * @hide
285 */
286 public static final String EXTRA_TTY_PREFERRED_MODE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700287 "android.telecom.intent.extra.TTY_PREFERRED";
Evan Charlton10197192014-07-19 15:00:29 -0700288
Nancy Chen9d568c02014-09-08 14:17:59 -0700289 /**
290 * The following 4 constants define how properties such as phone numbers and names are
291 * displayed to the user.
292 */
293
294 /** Property is displayed normally. */
295 public static final int PRESENTATION_ALLOWED = 1;
296
297 /** Property was blocked. */
298 public static final int PRESENTATION_RESTRICTED = 2;
299
300 /** Presentation was not specified or is unknown. */
301 public static final int PRESENTATION_UNKNOWN = 3;
302
303 /** Property should be displayed as a pay phone. */
304 public static final int PRESENTATION_PAYPHONE = 4;
305
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700306 private static final String TAG = "TelecomManager";
Yorke Leeb4ce1432014-06-09 13:53:23 -0700307
308 private final Context mContext;
Yorke Leeb4ce1432014-06-09 13:53:23 -0700309
Santos Cordon6c7a3882014-06-25 15:30:08 -0700310 /**
311 * @hide
312 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700313 public static TelecomManager from(Context context) {
314 return (TelecomManager) context.getSystemService(Context.TELECOM_SERVICE);
Yorke Leeb4ce1432014-06-09 13:53:23 -0700315 }
Santos Cordon6c7a3882014-06-25 15:30:08 -0700316
317 /**
318 * @hide
319 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700320 public TelecomManager(Context context) {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700321 Context appContext = context.getApplicationContext();
322 if (appContext != null) {
323 mContext = appContext;
324 } else {
325 mContext = context;
326 }
327 }
328
329 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700330 * Return the {@link PhoneAccount} which is the user-chosen default for making outgoing phone
Nancy Chen513c8922014-09-17 14:47:20 -0700331 * calls with a specified URI scheme.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700332 * <p>
Santos Cordon96efb482014-07-19 14:57:05 -0700333 * Apps must be prepared for this method to return {@code null}, indicating that there currently
Nancy Chen513c8922014-09-17 14:47:20 -0700334 * exists no user-chosen default {@code PhoneAccount}.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700335 * <p>
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700336 * @param uriScheme The URI scheme.
Nancy Chen513c8922014-09-17 14:47:20 -0700337 * @return The {@link PhoneAccountHandle} corresponding to the user-chosen default for outgoing
338 * phone calls for a specified URI scheme.
339 *
340 * @hide
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700341 */
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700342 public PhoneAccountHandle getDefaultOutgoingPhoneAccount(String uriScheme) {
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700343 try {
344 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700345 return getTelecomService().getDefaultOutgoingPhoneAccount(uriScheme);
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700346 }
347 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700348 Log.e(TAG, "Error calling ITelecomService#getDefaultOutgoingPhoneAccount", e);
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700349 }
350 return null;
351 }
352
353 /**
Andrew Leed4abbfb2014-09-03 14:58:27 -0700354 * Return the {@link PhoneAccount} which is the user-chosen default for making outgoing phone
355 * calls. This {@code PhoneAccount} will always be a member of the list which is returned from
Nancy Chen210ef032014-09-15 17:58:42 -0700356 * calling {@link #getCallCapablePhoneAccounts()}
Andrew Leed4abbfb2014-09-03 14:58:27 -0700357 *
358 * Apps must be prepared for this method to return {@code null}, indicating that there currently
359 * exists no user-chosen default {@code PhoneAccount}.
360 *
361 * @return The user outgoing phone account selected by the user.
362 * @hide
363 */
364 public PhoneAccountHandle getUserSelectedOutgoingPhoneAccount() {
365 try {
366 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700367 return getTelecomService().getUserSelectedOutgoingPhoneAccount();
Andrew Leed4abbfb2014-09-03 14:58:27 -0700368 }
369 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700370 Log.e(TAG, "Error calling ITelecomService#getUserSelectedOutgoingPhoneAccount", e);
Andrew Leed4abbfb2014-09-03 14:58:27 -0700371 }
372 return null;
373 }
374
375 /**
Andrew Lee59cac3a2014-08-28 16:50:10 -0700376 * Sets the default account for making outgoing phone calls.
377 * @hide
378 */
Andrew Leed4abbfb2014-09-03 14:58:27 -0700379 public void setUserSelectedOutgoingPhoneAccount(PhoneAccountHandle accountHandle) {
Andrew Lee59cac3a2014-08-28 16:50:10 -0700380 try {
381 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700382 getTelecomService().setUserSelectedOutgoingPhoneAccount(accountHandle);
Andrew Lee59cac3a2014-08-28 16:50:10 -0700383 }
384 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700385 Log.e(TAG, "Error calling ITelecomService#setUserSelectedOutgoingPhoneAccount");
Andrew Lee59cac3a2014-08-28 16:50:10 -0700386 }
387 }
388
389 /**
Andrew Lee59cac3a2014-08-28 16:50:10 -0700390 * Returns the current SIM call manager. Apps must be prepared for this method to return
391 * {@code null}, indicating that there currently exists no user-chosen default
392 * {@code PhoneAccount}.
393 * @return The phone account handle of the current sim call manager.
394 * @hide
395 */
396 public PhoneAccountHandle getSimCallManager() {
397 try {
398 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700399 return getTelecomService().getSimCallManager();
Andrew Lee59cac3a2014-08-28 16:50:10 -0700400 }
401 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700402 Log.e(TAG, "Error calling ITelecomService#getSimCallManager");
Andrew Lee59cac3a2014-08-28 16:50:10 -0700403 }
404 return null;
405 }
406
407 /**
408 * Sets the SIM call manager to the specified phone account.
409 * @param accountHandle The phone account handle of the account to set as the sim call manager.
410 * @hide
411 */
412 public void setSimCallManager(PhoneAccountHandle accountHandle) {
413 try {
414 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700415 getTelecomService().setSimCallManager(accountHandle);
Andrew Lee59cac3a2014-08-28 16:50:10 -0700416 }
417 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700418 Log.e(TAG, "Error calling ITelecomService#setSimCallManager");
Andrew Lee59cac3a2014-08-28 16:50:10 -0700419 }
420 }
421
422 /**
423 * Returns the list of registered SIM call managers.
424 * @return List of registered SIM call managers.
425 * @hide
426 */
427 public List<PhoneAccountHandle> getSimCallManagers() {
428 try {
429 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700430 return getTelecomService().getSimCallManagers();
Andrew Lee59cac3a2014-08-28 16:50:10 -0700431 }
432 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700433 Log.e(TAG, "Error calling ITelecomService#getSimCallManagers");
Andrew Lee59cac3a2014-08-28 16:50:10 -0700434 }
435 return new ArrayList<>();
436 }
437
438 /**
Evan Charltoneb0a8d562014-09-04 12:03:34 -0700439 * Returns the current connection manager. Apps must be prepared for this method to return
440 * {@code null}, indicating that there currently exists no user-chosen default
441 * {@code PhoneAccount}.
442 *
443 * @return The phone account handle of the current connection manager.
444 */
445 public PhoneAccountHandle getConnectionManager() {
446 return getSimCallManager();
447 }
448
449 /**
Nancy Chen210ef032014-09-15 17:58:42 -0700450 * Returns a list of the {@link PhoneAccountHandle}s which can be used to make and receive phone
451 * calls which support the specified URI scheme.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700452 * <P>
453 * For example, invoking with {@code "tel"} will find all {@link PhoneAccountHandle}s which
454 * support telephone calls (e.g. URIs such as {@code tel:555-555-1212}). Invoking with
455 * {@code "sip"} will find all {@link PhoneAccountHandle}s which support SIP calls (e.g. URIs
456 * such as {@code sip:example@sipexample.com}).
457 *
458 * @param uriScheme The URI scheme.
459 * @return A list of {@code PhoneAccountHandle} objects supporting the URI scheme.
Nancy Chen513c8922014-09-17 14:47:20 -0700460 *
461 * @hide
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700462 */
463 public List<PhoneAccountHandle> getPhoneAccountsSupportingScheme(String uriScheme) {
464 try {
465 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700466 return getTelecomService().getPhoneAccountsSupportingScheme(uriScheme);
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700467 }
468 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700469 Log.e(TAG, "Error calling ITelecomService#getPhoneAccountsSupportingScheme", e);
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700470 }
471 return new ArrayList<>();
472 }
473
Nancy Chen513c8922014-09-17 14:47:20 -0700474
475 /**
476 * Return a list of {@link PhoneAccountHandle}s which can be used to make and receive phone
477 * calls.
478 *
479 * @see #EXTRA_PHONE_ACCOUNT_HANDLE
480 * @return A list of {@code PhoneAccountHandle} objects.
481 *
482 * @hide
483 */
484 public List<PhoneAccountHandle> getCallCapablePhoneAccounts() {
485 try {
486 if (isServiceConnected()) {
487 return getTelecomService().getCallCapablePhoneAccounts();
488 }
489 } catch (RemoteException e) {
490 Log.e(TAG, "Error calling ITelecomService#getCallCapablePhoneAccounts", e);
491 }
492 return new ArrayList<>();
493 }
494
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700495 /**
Nancy Chen210ef032014-09-15 17:58:42 -0700496 * Determine whether the device has more than one account registered that can make and receive
497 * phone calls.
Nancy Chen60801182014-07-22 16:56:49 -0700498 *
Nancy Chen210ef032014-09-15 17:58:42 -0700499 * @return {@code true} if the device has more than one account registered and {@code false}
500 * otherwise.
Nancy Chen60801182014-07-22 16:56:49 -0700501 */
Nancy Chen210ef032014-09-15 17:58:42 -0700502 public boolean hasMultipleCallCapableAccounts() {
503 return getCallCapablePhoneAccounts().size() > 1;
Nancy Chen60801182014-07-22 16:56:49 -0700504 }
505
506 /**
Nancy Chen513c8922014-09-17 14:47:20 -0700507 * Returns a list of all {@link PhoneAccount}s registered for the calling package.
508 *
509 * @return A list of {@code PhoneAccountHandle} objects.
510 */
511 public List<PhoneAccountHandle> getPhoneAccountsForPackage() {
512 try {
513 if (isServiceConnected()) {
514 return getTelecomService().getPhoneAccountsForPackage(mContext.getPackageName());
515 }
516 } catch (RemoteException e) {
517 Log.e(TAG, "Error calling ITelecomService#getPhoneAccountsForPackage", e);
518 }
519 return null;
520 }
521
522 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700523 * Return the {@link PhoneAccount} for a specified {@link PhoneAccountHandle}. Object includes
524 * resources which can be used in a user interface.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700525 *
Evan Charlton6eb262c2014-07-19 18:18:19 -0700526 * @param account The {@link PhoneAccountHandle}.
Evan Charlton8c8a0622014-07-20 12:31:00 -0700527 * @return The {@link PhoneAccount} object.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700528 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700529 public PhoneAccount getPhoneAccount(PhoneAccountHandle account) {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700530 try {
531 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700532 return getTelecomService().getPhoneAccount(account);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700533 }
534 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700535 Log.e(TAG, "Error calling ITelecomService#getPhoneAccount", e);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700536 }
537 return null;
538 }
539
540 /**
Nancy Chen210ef032014-09-15 17:58:42 -0700541 * Returns a count of all {@link PhoneAccount}s.
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700542 *
Nancy Chen210ef032014-09-15 17:58:42 -0700543 * @return The count of {@link PhoneAccount}s.
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700544 * @hide
545 */
546 @SystemApi
547 public int getAllPhoneAccountsCount() {
548 try {
549 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700550 return getTelecomService().getAllPhoneAccountsCount();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700551 }
552 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700553 Log.e(TAG, "Error calling ITelecomService#getAllPhoneAccountsCount", e);
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700554 }
555 return 0;
556 }
557
558 /**
559 * Returns a list of all {@link PhoneAccount}s.
560 *
561 * @return All {@link PhoneAccount}s.
562 * @hide
563 */
564 @SystemApi
565 public List<PhoneAccount> getAllPhoneAccounts() {
566 try {
567 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700568 return getTelecomService().getAllPhoneAccounts();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700569 }
570 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700571 Log.e(TAG, "Error calling ITelecomService#getAllPhoneAccounts", e);
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700572 }
573 return Collections.EMPTY_LIST;
574 }
575
576 /**
577 * Returns a list of all {@link PhoneAccountHandle}s.
578 *
579 * @return All {@link PhoneAccountHandle}s.
580 * @hide
581 */
582 @SystemApi
583 public List<PhoneAccountHandle> getAllPhoneAccountHandles() {
584 try {
585 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700586 return getTelecomService().getAllPhoneAccountHandles();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700587 }
588 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700589 Log.e(TAG, "Error calling ITelecomService#getAllPhoneAccountHandles", e);
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700590 }
591 return Collections.EMPTY_LIST;
592 }
593
594 /**
Santos Cordond9e614f2014-10-28 13:10:36 -0700595 * Register a {@link PhoneAccount} for use by the system. When registering
596 * {@link PhoneAccount}s, existing registrations will be overwritten if the
597 * {@link PhoneAccountHandle} matches that of a {@link PhoneAccount} which is already
598 * registered. Once registered, the {@link PhoneAccount} is listed to the user as an option
599 * when placing calls. The user may still need to enable the {@link PhoneAccount} within
600 * the phone app settings before the account is usable.
601 * <p>
602 * A {@link SecurityException} will be thrown if an app tries to register a
603 * {@link PhoneAccountHandle} where the package name specified within
604 * {@link PhoneAccountHandle#getComponentName()} does not match the package name of the app.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700605 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700606 * @param account The complete {@link PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700607 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700608 public void registerPhoneAccount(PhoneAccount account) {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700609 try {
610 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700611 getTelecomService().registerPhoneAccount(account);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700612 }
613 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700614 Log.e(TAG, "Error calling ITelecomService#registerPhoneAccount", e);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700615 }
616 }
617
618 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700619 * Remove a {@link PhoneAccount} registration from the system.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700620 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700621 * @param accountHandle A {@link PhoneAccountHandle} for the {@link PhoneAccount} to unregister.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700622 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700623 public void unregisterPhoneAccount(PhoneAccountHandle accountHandle) {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700624 try {
625 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700626 getTelecomService().unregisterPhoneAccount(accountHandle);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700627 }
628 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700629 Log.e(TAG, "Error calling ITelecomService#unregisterPhoneAccount", e);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700630 }
631 }
632
633 /**
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700634 * Remove all Accounts that belong to the calling package from the system.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700635 */
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700636 public void clearAccounts() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700637 try {
638 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700639 getTelecomService().clearAccounts(mContext.getPackageName());
Ihab Awad807fe0a2014-07-09 12:30:52 -0700640 }
641 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700642 Log.e(TAG, "Error calling ITelecomService#clearAccounts", e);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700643 }
644 }
645
646 /**
647 * @hide
648 */
Santos Cordon6c7a3882014-06-25 15:30:08 -0700649 @SystemApi
650 public ComponentName getDefaultPhoneApp() {
651 try {
Santos Cordon9eb45932014-06-27 12:28:43 -0700652 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700653 return getTelecomService().getDefaultPhoneApp();
Santos Cordon9eb45932014-06-27 12:28:43 -0700654 }
Santos Cordon6c7a3882014-06-25 15:30:08 -0700655 } catch (RemoteException e) {
656 Log.e(TAG, "RemoteException attempting to get the default phone app.", e);
657 }
658 return null;
659 }
660
Santos Cordon9eb45932014-06-27 12:28:43 -0700661 /**
Nancy Chen443e5012014-10-15 15:48:21 -0700662 * Return whether a given phone number is the configured voicemail number for a
663 * particular phone account.
664 *
665 * @param accountHandle The handle for the account to check the voicemail number against
666 * @param number The number to look up.
667 *
668 * @hide
669 */
670 @SystemApi
671 public boolean isVoiceMailNumber(PhoneAccountHandle accountHandle, String number) {
672 try {
673 if (isServiceConnected()) {
674 return getTelecomService().isVoiceMailNumber(accountHandle, number);
675 }
676 } catch (RemoteException e) {
677 Log.e(TAG, "RemoteException calling isInCall().", e);
678 }
679 return false;
680 }
681
682 /**
Santos Cordon9eb45932014-06-27 12:28:43 -0700683 * Returns whether there is an ongoing phone call (can be in dialing, ringing, active or holding
684 * states).
Nancy Chen0eb1e402014-08-21 22:52:29 -0700685 * <p>
686 * Requires permission: {@link android.Manifest.permission#READ_PHONE_STATE}
687 * </p>
Santos Cordon9eb45932014-06-27 12:28:43 -0700688 */
Nancy Chen0eb1e402014-08-21 22:52:29 -0700689 public boolean isInCall() {
Santos Cordon9eb45932014-06-27 12:28:43 -0700690 try {
691 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700692 return getTelecomService().isInCall();
Santos Cordon9eb45932014-06-27 12:28:43 -0700693 }
694 } catch (RemoteException e) {
Yorke Lee2ae312e2014-09-12 17:58:48 -0700695 Log.e(TAG, "RemoteException calling isInCall().", e);
Santos Cordon9eb45932014-06-27 12:28:43 -0700696 }
697 return false;
698 }
699
700 /**
Yorke Lee2ae312e2014-09-12 17:58:48 -0700701 * Returns one of the following constants that represents the current state of Telecom:
702 *
703 * {@link TelephonyManager#CALL_STATE_RINGING}
704 * {@link TelephonyManager#CALL_STATE_OFFHOOK}
705 * {@link TelephonyManager#CALL_STATE_IDLE}
Yorke Lee2ae312e2014-09-12 17:58:48 -0700706 * @hide
707 */
708 @SystemApi
709 public int getCallState() {
710 try {
711 if (isServiceConnected()) {
712 return getTelecomService().getCallState();
713 }
714 } catch (RemoteException e) {
715 Log.d(TAG, "RemoteException calling getCallState().", e);
716 }
717 return TelephonyManager.CALL_STATE_IDLE;
718 }
719
720 /**
Santos Cordon9eb45932014-06-27 12:28:43 -0700721 * Returns whether there currently exists is a ringing incoming-call.
722 *
723 * @hide
724 */
725 @SystemApi
726 public boolean isRinging() {
727 try {
728 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700729 return getTelecomService().isRinging();
Santos Cordon9eb45932014-06-27 12:28:43 -0700730 }
731 } catch (RemoteException e) {
732 Log.e(TAG, "RemoteException attempting to get ringing state of phone app.", e);
733 }
734 return false;
735 }
736
737 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700738 * Ends an ongoing call.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700739 * TODO: L-release - need to convert all invocations of ITelecomService#endCall to use this
Santos Cordon96efb482014-07-19 14:57:05 -0700740 * method (clockwork & gearhead).
Santos Cordon9eb45932014-06-27 12:28:43 -0700741 * @hide
742 */
743 @SystemApi
744 public boolean endCall() {
745 try {
746 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700747 return getTelecomService().endCall();
Santos Cordon9eb45932014-06-27 12:28:43 -0700748 }
749 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700750 Log.e(TAG, "Error calling ITelecomService#endCall", e);
Santos Cordon9eb45932014-06-27 12:28:43 -0700751 }
752 return false;
753 }
754
755 /**
756 * If there is a ringing incoming call, this method accepts the call on behalf of the user.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700757 * TODO: L-release - need to convert all invocation of ITelecmmService#answerRingingCall to use
Santos Cordon96efb482014-07-19 14:57:05 -0700758 * this method (clockwork & gearhead).
Santos Cordon9eb45932014-06-27 12:28:43 -0700759 *
760 * @hide
761 */
762 @SystemApi
763 public void acceptRingingCall() {
764 try {
765 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700766 getTelecomService().acceptRingingCall();
Santos Cordon9eb45932014-06-27 12:28:43 -0700767 }
768 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700769 Log.e(TAG, "Error calling ITelecomService#acceptRingingCall", e);
Santos Cordon9eb45932014-06-27 12:28:43 -0700770 }
771 }
772
773 /**
774 * Silences the ringer if a ringing call exists.
775 *
776 * @hide
777 */
778 @SystemApi
779 public void silenceRinger() {
780 try {
781 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700782 getTelecomService().silenceRinger();
Santos Cordon9eb45932014-06-27 12:28:43 -0700783 }
784 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700785 Log.e(TAG, "Error calling ITelecomService#silenceRinger", e);
Santos Cordon9eb45932014-06-27 12:28:43 -0700786 }
787 }
788
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700789 /**
790 * Returns whether TTY is supported on this device.
791 *
792 * @hide
793 */
794 @SystemApi
795 public boolean isTtySupported() {
796 try {
797 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700798 return getTelecomService().isTtySupported();
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700799 }
800 } catch (RemoteException e) {
801 Log.e(TAG, "RemoteException attempting to get TTY supported state.", e);
802 }
803 return false;
804 }
805
806 /**
807 * 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 -0700808 * settings and have a wired headset plugged in.
809 * Valid modes are:
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700810 * - {@link TelecomManager#TTY_MODE_OFF}
811 * - {@link TelecomManager#TTY_MODE_FULL}
812 * - {@link TelecomManager#TTY_MODE_HCO}
813 * - {@link TelecomManager#TTY_MODE_VCO}
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700814 * @hide
815 */
816 public int getCurrentTtyMode() {
817 try {
818 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700819 return getTelecomService().getCurrentTtyMode();
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700820 }
821 } catch (RemoteException e) {
822 Log.e(TAG, "RemoteException attempting to get the current TTY mode.", e);
823 }
Evan Charlton10197192014-07-19 15:00:29 -0700824 return TTY_MODE_OFF;
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700825 }
826
Santos Cordon96efb482014-07-19 14:57:05 -0700827 /**
828 * Registers a new incoming call. A {@link ConnectionService} should invoke this method when it
829 * has an incoming call. The specified {@link PhoneAccountHandle} must have been registered
Nancy Chen210ef032014-09-15 17:58:42 -0700830 * with {@link #registerPhoneAccount}. Once invoked, this method will cause the system to bind
831 * to the {@link ConnectionService} associated with the {@link PhoneAccountHandle} and request
Santos Cordon96efb482014-07-19 14:57:05 -0700832 * additional information about the call (See
833 * {@link ConnectionService#onCreateIncomingConnection}) before starting the incoming call UI.
834 *
835 * @param phoneAccount A {@link PhoneAccountHandle} registered with
836 * {@link #registerPhoneAccount}.
837 * @param extras A bundle that will be passed through to
838 * {@link ConnectionService#onCreateIncomingConnection}.
839 */
840 public void addNewIncomingCall(PhoneAccountHandle phoneAccount, Bundle extras) {
841 try {
842 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700843 getTelecomService().addNewIncomingCall(
Santos Cordon96efb482014-07-19 14:57:05 -0700844 phoneAccount, extras == null ? new Bundle() : extras);
845 }
846 } catch (RemoteException e) {
847 Log.e(TAG, "RemoteException adding a new incoming call: " + phoneAccount, e);
848 }
849 }
850
Nancy Chen0eb1e402014-08-21 22:52:29 -0700851 /**
Yorke Leec3cf9822014-10-02 09:38:39 -0700852 * Registers a new unknown call with Telecom. This can only be called by the system Telephony
853 * service. This is invoked when Telephony detects a new unknown connection that was neither
854 * a new incoming call, nor an user-initiated outgoing call.
855 *
856 * @param phoneAccount A {@link PhoneAccountHandle} registered with
857 * {@link #registerPhoneAccount}.
858 * @param extras A bundle that will be passed through to
859 * {@link ConnectionService#onCreateIncomingConnection}.
860 * @hide
861 */
862 @SystemApi
863 public void addNewUnknownCall(PhoneAccountHandle phoneAccount, Bundle extras) {
864 try {
865 if (isServiceConnected()) {
866 getTelecomService().addNewUnknownCall(
867 phoneAccount, extras == null ? new Bundle() : extras);
868 }
869 } catch (RemoteException e) {
870 Log.e(TAG, "RemoteException adding a new unknown call: " + phoneAccount, e);
871 }
872 }
873
874 /**
Nancy Chen0eb1e402014-08-21 22:52:29 -0700875 * Processes the specified dial string as an MMI code.
876 * MMI codes are any sequence of characters entered into the dialpad that contain a "*" or "#".
877 * Some of these sequences launch special behavior through handled by Telephony.
878 * <p>
879 * Requires that the method-caller be set as the system dialer app.
880 * </p>
881 *
882 * @param dialString The digits to dial.
883 * @return True if the digits were processed as an MMI code, false otherwise.
884 */
885 public boolean handleMmi(String dialString) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700886 ITelecomService service = getTelecomService();
Nancy Chen0eb1e402014-08-21 22:52:29 -0700887 if (service != null) {
888 try {
889 return service.handlePinMmi(dialString);
890 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700891 Log.e(TAG, "Error calling ITelecomService#handlePinMmi", e);
Nancy Chen0eb1e402014-08-21 22:52:29 -0700892 }
893 }
894 return false;
895 }
896
897 /**
898 * Removes the missed-call notification if one is present.
899 * <p>
900 * Requires that the method-caller be set as the system dialer app.
901 * </p>
902 */
903 public void cancelMissedCallsNotification() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700904 ITelecomService service = getTelecomService();
Nancy Chen0eb1e402014-08-21 22:52:29 -0700905 if (service != null) {
906 try {
907 service.cancelMissedCallsNotification();
908 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700909 Log.e(TAG, "Error calling ITelecomService#cancelMissedCallsNotification", e);
Nancy Chen0eb1e402014-08-21 22:52:29 -0700910 }
911 }
912 }
913
914 /**
915 * Brings the in-call screen to the foreground if there is an ongoing call. If there is
916 * currently no ongoing call, then this method does nothing.
917 * <p>
918 * Requires that the method-caller be set as the system dialer app or have the
919 * {@link android.Manifest.permission#READ_PHONE_STATE} permission.
920 * </p>
921 *
922 * @param showDialpad Brings up the in-call dialpad as part of showing the in-call screen.
923 */
924 public void showInCallScreen(boolean showDialpad) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700925 ITelecomService service = getTelecomService();
Nancy Chen0eb1e402014-08-21 22:52:29 -0700926 if (service != null) {
927 try {
928 service.showInCallScreen(showDialpad);
929 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700930 Log.e(TAG, "Error calling ITelecomService#showCallScreen", e);
Nancy Chen0eb1e402014-08-21 22:52:29 -0700931 }
932 }
933 }
934
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700935 private ITelecomService getTelecomService() {
936 return ITelecomService.Stub.asInterface(ServiceManager.getService(Context.TELECOM_SERVICE));
Santos Cordon6c7a3882014-06-25 15:30:08 -0700937 }
Santos Cordon9eb45932014-06-27 12:28:43 -0700938
939 private boolean isServiceConnected() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700940 boolean isConnected = getTelecomService() != null;
Santos Cordon9eb45932014-06-27 12:28:43 -0700941 if (!isConnected) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700942 Log.w(TAG, "Telecom Service not found.");
Santos Cordon9eb45932014-06-27 12:28:43 -0700943 }
944 return isConnected;
945 }
Evan Charlton235c1592014-09-05 15:41:23 +0000946}