blob: c69a17c04206aa5a857c68bcb74783eb38d5bbd0 [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/**
Tyler Gunnef9f6f92014-09-12 22:16:17 -070033 * Provides access to Telecom-related functionality.
Santos Cordon96efb482014-07-19 14:57:05 -070034 * TODO: Move this all into PhoneManager.
Yorke Leeb4ce1432014-06-09 13:53:23 -070035 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -070036public class TelecomManager {
Ihab Awad807fe0a2014-07-09 12:30:52 -070037
Evan Charlton10197192014-07-19 15:00:29 -070038 /**
Santos Cordon96efb482014-07-19 14:57:05 -070039 * Activity action: Starts the UI for handing an incoming call. This intent starts the in-call
Tyler Gunnef9f6f92014-09-12 22:16:17 -070040 * UI by notifying the Telecom system that an incoming call exists for a specific call service
41 * (see {@link android.telecom.ConnectionService}). Telecom reads the Intent extras to find
42 * and bind to the appropriate {@link android.telecom.ConnectionService} which Telecom will
Santos Cordon96efb482014-07-19 14:57:05 -070043 * ultimately use to control and get information about the call.
44 * <p>
45 * Input: get*Extra field {@link #EXTRA_PHONE_ACCOUNT_HANDLE} contains the component name of the
Tyler Gunnef9f6f92014-09-12 22:16:17 -070046 * {@link android.telecom.ConnectionService} that Telecom should bind to. Telecom will then
Evan Charlton10197192014-07-19 15:00:29 -070047 * ask the connection service for more information about the call prior to showing any UI.
48 *
Santos Cordon96efb482014-07-19 14:57:05 -070049 * @hide
Evan Charlton10197192014-07-19 15:00:29 -070050 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -070051 public static final String ACTION_INCOMING_CALL = "android.telecom.action.INCOMING_CALL";
Evan Charlton10197192014-07-19 15:00:29 -070052
53 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -070054 * The {@link android.content.Intent} action used to configure a
Tyler Gunnef9f6f92014-09-12 22:16:17 -070055 * {@link android.telecom.ConnectionService}.
Evan Charlton10197192014-07-19 15:00:29 -070056 */
57 public static final String ACTION_CONNECTION_SERVICE_CONFIGURE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -070058 "android.telecom.action.CONNECTION_SERVICE_CONFIGURE";
Evan Charlton10197192014-07-19 15:00:29 -070059
60 /**
Yorke Lee3818a892014-07-21 15:57:17 -070061 * The {@link android.content.Intent} action used to show the call settings page.
62 */
63 public static final String ACTION_SHOW_CALL_SETTINGS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -070064 "android.telecom.action.SHOW_CALL_SETTINGS";
Yorke Lee3818a892014-07-21 15:57:17 -070065
66 /**
Evan Charlton6d8604f2014-09-04 12:38:17 -070067 * The {@link android.content.Intent} action used to show the settings page used to configure
68 * {@link PhoneAccount} preferences.
69 */
70 public static final String ACTION_CHANGE_PHONE_ACCOUNTS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -070071 "android.telecom.action.CHANGE_PHONE_ACCOUNTS";
Evan Charlton6d8604f2014-09-04 12:38:17 -070072
73 /**
Tyler Gunn9becf002014-09-11 13:31:57 -070074 * The {@link android.content.Intent} action used to inform a
Tyler Gunnef9f6f92014-09-12 22:16:17 -070075 * {@link android.telecom.ConnectionService} that one of its {@link PhoneAccount}s has been
76 * enabled. The {@link TelecomManager#EXTRA_PHONE_ACCOUNT_HANDLE} extra is used to indicate
Tyler Gunn9becf002014-09-11 13:31:57 -070077 * which {@link PhoneAccount} has been enabled.
78 */
79 public static final String ACTION_PHONE_ACCOUNT_ENABLED =
80 "android.telecom.action.PHONE_ACCOUNT_ENABLED";
81
82 /**
83 * The {@link android.content.Intent} action used to inform a
Tyler Gunnef9f6f92014-09-12 22:16:17 -070084 * {@link android.telecom.ConnectionService} that one of its {@link PhoneAccount}s has been
85 * disabled. The {@link TelecomManager#EXTRA_PHONE_ACCOUNT_HANDLE} extra is used to indicate
Tyler Gunn9becf002014-09-11 13:31:57 -070086 * which {@link PhoneAccount} has been disabled.
87 */
88 public static final String ACTION_PHONE_ACCOUNT_DISABLED =
89 "android.telecom.action.PHONE_ACCOUNT_DISABLED";
90
91 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -070092 * Optional extra for {@link android.content.Intent#ACTION_CALL} containing a boolean that
93 * determines whether the speakerphone should be automatically turned on for an outgoing call.
Evan Charlton10197192014-07-19 15:00:29 -070094 */
95 public static final String EXTRA_START_CALL_WITH_SPEAKERPHONE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -070096 "android.telecom.extra.START_CALL_WITH_SPEAKERPHONE";
Evan Charlton10197192014-07-19 15:00:29 -070097
98 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -070099 * Optional extra for {@link android.content.Intent#ACTION_CALL} containing an integer that
100 * determines the desired video state for an outgoing call.
Santos Cordon96efb482014-07-19 14:57:05 -0700101 * Valid options:
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700102 * {@link VideoProfile.VideoState#AUDIO_ONLY},
103 * {@link VideoProfile.VideoState#BIDIRECTIONAL},
104 * {@link VideoProfile.VideoState#RX_ENABLED},
105 * {@link VideoProfile.VideoState#TX_ENABLED}.
Tyler Gunn27d1e252014-08-21 16:38:40 -0700106 * @hide
Evan Charlton10197192014-07-19 15:00:29 -0700107 */
108 public static final String EXTRA_START_CALL_WITH_VIDEO_STATE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700109 "android.telecom.extra.START_CALL_WITH_VIDEO_STATE";
Evan Charlton10197192014-07-19 15:00:29 -0700110
111 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700112 * The extra used with an {@link android.content.Intent#ACTION_CALL} and
113 * {@link android.content.Intent#ACTION_DIAL} {@code Intent} to specify a
114 * {@link PhoneAccountHandle} to use when making the call.
Evan Charlton10197192014-07-19 15:00:29 -0700115 * <p class="note">
Santos Cordon96efb482014-07-19 14:57:05 -0700116 * Retrieve with {@link android.content.Intent#getParcelableExtra(String)}.
Evan Charlton10197192014-07-19 15:00:29 -0700117 */
Evan Charlton6eb262c2014-07-19 18:18:19 -0700118 public static final String EXTRA_PHONE_ACCOUNT_HANDLE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700119 "android.telecom.extra.PHONE_ACCOUNT_HANDLE";
Evan Charlton10197192014-07-19 15:00:29 -0700120
121 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700122 * Optional extra for {@link #ACTION_INCOMING_CALL} containing a {@link Bundle} which contains
123 * metadata about the call. This {@link Bundle} will be returned to the
124 * {@link ConnectionService}.
125 *
126 * @hide
Evan Charlton10197192014-07-19 15:00:29 -0700127 */
128 public static final String EXTRA_INCOMING_CALL_EXTRAS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700129 "android.telecom.extra.INCOMING_CALL_EXTRAS";
Evan Charlton10197192014-07-19 15:00:29 -0700130
131 /**
Nancy Chen10798dc2014-08-08 14:00:25 -0700132 * Optional extra for {@link android.content.Intent#ACTION_CALL} and
133 * {@link android.content.Intent#ACTION_DIAL} {@code Intent} containing a {@link Bundle}
134 * which contains metadata about the call. This {@link Bundle} will be saved into
135 * {@code Call.Details}.
136 *
137 * @hide
138 */
139 public static final String EXTRA_OUTGOING_CALL_EXTRAS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700140 "android.telecom.extra.OUTGOING_CALL_EXTRAS";
Nancy Chen10798dc2014-08-08 14:00:25 -0700141
142 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700143 * Optional extra for {@link android.telephony.TelephonyManager#ACTION_PHONE_STATE_CHANGED}
144 * containing the disconnect code.
Evan Charlton10197192014-07-19 15:00:29 -0700145 */
146 public static final String EXTRA_CALL_DISCONNECT_CAUSE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700147 "android.telecom.extra.CALL_DISCONNECT_CAUSE";
Evan Charlton10197192014-07-19 15:00:29 -0700148
149 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700150 * Optional extra for {@link android.telephony.TelephonyManager#ACTION_PHONE_STATE_CHANGED}
151 * containing the disconnect message.
Evan Charlton10197192014-07-19 15:00:29 -0700152 */
153 public static final String EXTRA_CALL_DISCONNECT_MESSAGE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700154 "android.telecom.extra.CALL_DISCONNECT_MESSAGE";
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 component name of the associated connection service.
Evan Charlton10197192014-07-19 15:00:29 -0700159 */
160 public static final String EXTRA_CONNECTION_SERVICE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700161 "android.telecom.extra.CONNECTION_SERVICE";
Evan Charlton10197192014-07-19 15:00:29 -0700162
163 /**
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700164 * An optional {@link android.content.Intent#ACTION_CALL} intent extra denoting the
165 * package name of the app specifying an alternative gateway for the call.
166 * The value is a string.
167 *
168 * (The following comment corresponds to the all GATEWAY_* extras)
169 * An app which sends the {@link android.content.Intent#ACTION_CALL} intent can specify an
170 * alternative address to dial which is different from the one specified and displayed to
171 * the user. This alternative address is referred to as the gateway address.
172 */
173 public static final String GATEWAY_PROVIDER_PACKAGE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700174 "android.telecom.extra.GATEWAY_PROVIDER_PACKAGE";
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700175
176 /**
177 * An optional {@link android.content.Intent#ACTION_CALL} intent extra corresponding to the
178 * original address to dial for the call. This is used when an alternative gateway address is
179 * provided to recall the original address.
180 * The value is a {@link android.net.Uri}.
181 *
182 * (See {@link #GATEWAY_PROVIDER_PACKAGE} for details)
183 */
184 public static final String GATEWAY_ORIGINAL_ADDRESS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700185 "android.telecom.extra.GATEWAY_ORIGINAL_ADDRESS";
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700186
187 /**
Evan Charlton10197192014-07-19 15:00:29 -0700188 * The number which the party on the other side of the line will see (and use to return the
189 * call).
190 * <p>
Santos Cordon96efb482014-07-19 14:57:05 -0700191 * {@link ConnectionService}s which interact with {@link RemoteConnection}s should only populate
192 * this if the {@link android.telephony.TelephonyManager#getLine1Number()} value, as that is the
193 * user's expected caller ID.
Evan Charlton10197192014-07-19 15:00:29 -0700194 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700195 public static final String EXTRA_CALL_BACK_NUMBER = "android.telecom.extra.CALL_BACK_NUMBER";
Evan Charlton10197192014-07-19 15:00:29 -0700196
197 /**
198 * The dual tone multi-frequency signaling character sent to indicate the dialing system should
199 * pause for a predefined period.
200 */
201 public static final char DTMF_CHARACTER_PAUSE = ',';
202
203 /**
204 * The dual-tone multi-frequency signaling character sent to indicate the dialing system should
205 * wait for user confirmation before proceeding.
206 */
207 public static final char DTMF_CHARACTER_WAIT = ';';
208
209 /**
210 * TTY (teletypewriter) mode is off.
211 *
212 * @hide
213 */
214 public static final int TTY_MODE_OFF = 0;
215
216 /**
217 * TTY (teletypewriter) mode is on. The speaker is off and the microphone is muted. The user
218 * will communicate with the remote party by sending and receiving text messages.
219 *
220 * @hide
221 */
222 public static final int TTY_MODE_FULL = 1;
223
224 /**
225 * TTY (teletypewriter) mode is in hearing carryover mode (HCO). The microphone is muted but the
226 * speaker is on. The user will communicate with the remote party by sending text messages and
227 * hearing an audible reply.
228 *
229 * @hide
230 */
231 public static final int TTY_MODE_HCO = 2;
232
233 /**
234 * TTY (teletypewriter) mode is in voice carryover mode (VCO). The speaker is off but the
235 * microphone is still on. User will communicate with the remote party by speaking and receiving
236 * text message replies.
237 *
238 * @hide
239 */
240 public static final int TTY_MODE_VCO = 3;
241
242 /**
243 * Broadcast intent action indicating that the current TTY mode has changed. An intent extra
244 * provides this state as an int.
Evan Charlton10197192014-07-19 15:00:29 -0700245 *
Santos Cordon96efb482014-07-19 14:57:05 -0700246 * @see #EXTRA_CURRENT_TTY_MODE
Evan Charlton10197192014-07-19 15:00:29 -0700247 * @hide
248 */
249 public static final String ACTION_CURRENT_TTY_MODE_CHANGED =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700250 "android.telecom.action.CURRENT_TTY_MODE_CHANGED";
Evan Charlton10197192014-07-19 15:00:29 -0700251
252 /**
253 * The lookup key for an int that indicates the current TTY mode.
254 * Valid modes are:
255 * - {@link #TTY_MODE_OFF}
256 * - {@link #TTY_MODE_FULL}
257 * - {@link #TTY_MODE_HCO}
258 * - {@link #TTY_MODE_VCO}
259 *
260 * @hide
261 */
262 public static final String EXTRA_CURRENT_TTY_MODE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700263 "android.telecom.intent.extra.CURRENT_TTY_MODE";
Evan Charlton10197192014-07-19 15:00:29 -0700264
265 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700266 * Broadcast intent action indicating that the TTY preferred operating mode has changed. An
267 * intent extra provides the new mode as an int.
Evan Charlton10197192014-07-19 15:00:29 -0700268 *
Santos Cordon96efb482014-07-19 14:57:05 -0700269 * @see #EXTRA_TTY_PREFERRED_MODE
Evan Charlton10197192014-07-19 15:00:29 -0700270 * @hide
271 */
272 public static final String ACTION_TTY_PREFERRED_MODE_CHANGED =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700273 "android.telecom.action.TTY_PREFERRED_MODE_CHANGED";
Evan Charlton10197192014-07-19 15:00:29 -0700274
275 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700276 * The lookup key for an int that indicates preferred TTY mode. Valid modes are: -
277 * {@link #TTY_MODE_OFF} - {@link #TTY_MODE_FULL} - {@link #TTY_MODE_HCO} -
278 * {@link #TTY_MODE_VCO}
Evan Charlton10197192014-07-19 15:00:29 -0700279 *
280 * @hide
281 */
282 public static final String EXTRA_TTY_PREFERRED_MODE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700283 "android.telecom.intent.extra.TTY_PREFERRED";
Evan Charlton10197192014-07-19 15:00:29 -0700284
Nancy Chen9d568c02014-09-08 14:17:59 -0700285 /**
286 * The following 4 constants define how properties such as phone numbers and names are
287 * displayed to the user.
288 */
289
290 /** Property is displayed normally. */
291 public static final int PRESENTATION_ALLOWED = 1;
292
293 /** Property was blocked. */
294 public static final int PRESENTATION_RESTRICTED = 2;
295
296 /** Presentation was not specified or is unknown. */
297 public static final int PRESENTATION_UNKNOWN = 3;
298
299 /** Property should be displayed as a pay phone. */
300 public static final int PRESENTATION_PAYPHONE = 4;
301
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700302 private static final String TAG = "TelecomManager";
Yorke Leeb4ce1432014-06-09 13:53:23 -0700303
304 private final Context mContext;
Yorke Leeb4ce1432014-06-09 13:53:23 -0700305
Santos Cordon6c7a3882014-06-25 15:30:08 -0700306 /**
307 * @hide
308 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700309 public static TelecomManager from(Context context) {
310 return (TelecomManager) context.getSystemService(Context.TELECOM_SERVICE);
Yorke Leeb4ce1432014-06-09 13:53:23 -0700311 }
Santos Cordon6c7a3882014-06-25 15:30:08 -0700312
313 /**
314 * @hide
315 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700316 public TelecomManager(Context context) {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700317 Context appContext = context.getApplicationContext();
318 if (appContext != null) {
319 mContext = appContext;
320 } else {
321 mContext = context;
322 }
323 }
324
325 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700326 * Return the {@link PhoneAccount} which is the user-chosen default for making outgoing phone
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700327 * calls with a specified URI scheme. This {@code PhoneAccount} will always be a member of the
328 * list which is returned from calling {@link #getEnabledPhoneAccounts()}.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700329 * <p>
Santos Cordon96efb482014-07-19 14:57:05 -0700330 * Apps must be prepared for this method to return {@code null}, indicating that there currently
331 * exists no user-chosen default {@code PhoneAccount}. In this case, apps wishing to initiate a
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700332 * phone call must either create their {@link android.content.Intent#ACTION_CALL} or
Santos Cordon96efb482014-07-19 14:57:05 -0700333 * {@link android.content.Intent#ACTION_DIAL} {@code Intent} with no
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700334 * {@link TelecomManager#EXTRA_PHONE_ACCOUNT_HANDLE}, or present the user with an affordance to
Santos Cordon96efb482014-07-19 14:57:05 -0700335 * select one of the elements of {@link #getEnabledPhoneAccounts()}.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700336 * <p>
337 * An {@link android.content.Intent#ACTION_CALL} or {@link android.content.Intent#ACTION_DIAL}
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700338 * {@code Intent} with no {@link TelecomManager#EXTRA_PHONE_ACCOUNT_HANDLE} is valid, and
Evan Charlton6eb262c2014-07-19 18:18:19 -0700339 * subsequent steps in the phone call flow are responsible for presenting the user with an
Evan Charlton8c8a0622014-07-20 12:31:00 -0700340 * affordance, if necessary, to choose a {@code PhoneAccount}.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700341 *
342 * @param uriScheme The URI scheme.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700343 */
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700344 public PhoneAccountHandle getDefaultOutgoingPhoneAccount(String uriScheme) {
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700345 try {
346 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700347 return getTelecomService().getDefaultOutgoingPhoneAccount(uriScheme);
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700348 }
349 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700350 Log.e(TAG, "Error calling ITelecomService#getDefaultOutgoingPhoneAccount", e);
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700351 }
352 return null;
353 }
354
355 /**
Andrew Leed4abbfb2014-09-03 14:58:27 -0700356 * Return the {@link PhoneAccount} which is the user-chosen default for making outgoing phone
357 * calls. This {@code PhoneAccount} will always be a member of the list which is returned from
358 * calling {@link #getEnabledPhoneAccounts()}
359 *
360 * Apps must be prepared for this method to return {@code null}, indicating that there currently
361 * exists no user-chosen default {@code PhoneAccount}.
362 *
363 * @return The user outgoing phone account selected by the user.
364 * @hide
365 */
366 public PhoneAccountHandle getUserSelectedOutgoingPhoneAccount() {
367 try {
368 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700369 return getTelecomService().getUserSelectedOutgoingPhoneAccount();
Andrew Leed4abbfb2014-09-03 14:58:27 -0700370 }
371 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700372 Log.e(TAG, "Error calling ITelecomService#getUserSelectedOutgoingPhoneAccount", e);
Andrew Leed4abbfb2014-09-03 14:58:27 -0700373 }
374 return null;
375 }
376
377 /**
Andrew Lee59cac3a2014-08-28 16:50:10 -0700378 * Sets the default account for making outgoing phone calls.
379 * @hide
380 */
Andrew Leed4abbfb2014-09-03 14:58:27 -0700381 public void setUserSelectedOutgoingPhoneAccount(PhoneAccountHandle accountHandle) {
Andrew Lee59cac3a2014-08-28 16:50:10 -0700382 try {
383 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700384 getTelecomService().setUserSelectedOutgoingPhoneAccount(accountHandle);
Andrew Lee59cac3a2014-08-28 16:50:10 -0700385 }
386 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700387 Log.e(TAG, "Error calling ITelecomService#setUserSelectedOutgoingPhoneAccount");
Andrew Lee59cac3a2014-08-28 16:50:10 -0700388 }
389 }
390
391 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700392 * Return a list of enabled {@link PhoneAccountHandle}s which can be used to make and receive
393 * phone calls.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700394 *
Evan Charlton6eb262c2014-07-19 18:18:19 -0700395 * @see #EXTRA_PHONE_ACCOUNT_HANDLE
396 * @return A list of {@code PhoneAccountHandle} objects.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700397 */
Evan Charlton6eb262c2014-07-19 18:18:19 -0700398 public List<PhoneAccountHandle> getEnabledPhoneAccounts() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700399 try {
400 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700401 return getTelecomService().getEnabledPhoneAccounts();
Ihab Awad807fe0a2014-07-09 12:30:52 -0700402 }
403 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700404 Log.e(TAG, "Error calling ITelecomService#getEnabledPhoneAccounts", e);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700405 }
Jay Shrauner7746a942014-08-26 12:15:15 -0700406 return new ArrayList<>();
Ihab Awad807fe0a2014-07-09 12:30:52 -0700407 }
408
409 /**
Andrew Lee59cac3a2014-08-28 16:50:10 -0700410 * Returns the current SIM call manager. Apps must be prepared for this method to return
411 * {@code null}, indicating that there currently exists no user-chosen default
412 * {@code PhoneAccount}.
413 * @return The phone account handle of the current sim call manager.
414 * @hide
415 */
416 public PhoneAccountHandle getSimCallManager() {
417 try {
418 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700419 return getTelecomService().getSimCallManager();
Andrew Lee59cac3a2014-08-28 16:50:10 -0700420 }
421 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700422 Log.e(TAG, "Error calling ITelecomService#getSimCallManager");
Andrew Lee59cac3a2014-08-28 16:50:10 -0700423 }
424 return null;
425 }
426
427 /**
428 * Sets the SIM call manager to the specified phone account.
429 * @param accountHandle The phone account handle of the account to set as the sim call manager.
430 * @hide
431 */
432 public void setSimCallManager(PhoneAccountHandle accountHandle) {
433 try {
434 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700435 getTelecomService().setSimCallManager(accountHandle);
Andrew Lee59cac3a2014-08-28 16:50:10 -0700436 }
437 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700438 Log.e(TAG, "Error calling ITelecomService#setSimCallManager");
Andrew Lee59cac3a2014-08-28 16:50:10 -0700439 }
440 }
441
442 /**
443 * Returns the list of registered SIM call managers.
444 * @return List of registered SIM call managers.
445 * @hide
446 */
447 public List<PhoneAccountHandle> getSimCallManagers() {
448 try {
449 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700450 return getTelecomService().getSimCallManagers();
Andrew Lee59cac3a2014-08-28 16:50:10 -0700451 }
452 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700453 Log.e(TAG, "Error calling ITelecomService#getSimCallManagers");
Andrew Lee59cac3a2014-08-28 16:50:10 -0700454 }
455 return new ArrayList<>();
456 }
457
458 /**
Evan Charltoneb0a8d52014-09-04 12:03:34 -0700459 * Returns the current connection manager. Apps must be prepared for this method to return
460 * {@code null}, indicating that there currently exists no user-chosen default
461 * {@code PhoneAccount}.
462 *
463 * @return The phone account handle of the current connection manager.
464 */
465 public PhoneAccountHandle getConnectionManager() {
466 return getSimCallManager();
467 }
468
469 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700470 * Returns a list of the enabled {@link PhoneAccountHandle}s which can be used to make and
471 * receive phone calls which support the specified URI scheme.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700472 * <P>
473 * For example, invoking with {@code "tel"} will find all {@link PhoneAccountHandle}s which
474 * support telephone calls (e.g. URIs such as {@code tel:555-555-1212}). Invoking with
475 * {@code "sip"} will find all {@link PhoneAccountHandle}s which support SIP calls (e.g. URIs
476 * such as {@code sip:example@sipexample.com}).
477 *
478 * @param uriScheme The URI scheme.
479 * @return A list of {@code PhoneAccountHandle} objects supporting the URI scheme.
480 */
481 public List<PhoneAccountHandle> getPhoneAccountsSupportingScheme(String uriScheme) {
482 try {
483 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700484 return getTelecomService().getPhoneAccountsSupportingScheme(uriScheme);
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700485 }
486 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700487 Log.e(TAG, "Error calling ITelecomService#getPhoneAccountsSupportingScheme", e);
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700488 }
489 return new ArrayList<>();
490 }
491
492 /**
Nancy Chen60801182014-07-22 16:56:49 -0700493 * Determine whether the device has more than one account registered and enabled.
494 *
495 * @return {@code true} if the device has more than one account registered and enabled and
496 * {@code false} otherwise.
497 */
498 public boolean hasMultipleEnabledAccounts() {
499 return getEnabledPhoneAccounts().size() > 1;
500 }
501
502 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700503 * Return the {@link PhoneAccount} for a specified {@link PhoneAccountHandle}. Object includes
504 * resources which can be used in a user interface.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700505 *
Evan Charlton6eb262c2014-07-19 18:18:19 -0700506 * @param account The {@link PhoneAccountHandle}.
Evan Charlton8c8a0622014-07-20 12:31:00 -0700507 * @return The {@link PhoneAccount} object.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700508 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700509 public PhoneAccount getPhoneAccount(PhoneAccountHandle account) {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700510 try {
511 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700512 return getTelecomService().getPhoneAccount(account);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700513 }
514 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700515 Log.e(TAG, "Error calling ITelecomService#getPhoneAccount", e);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700516 }
517 return null;
518 }
519
520 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700521 * Returns a count of enabled and disabled {@link PhoneAccount}s.
522 *
523 * @return The count of enabled and disabled {@link PhoneAccount}s.
524 * @hide
525 */
526 @SystemApi
527 public int getAllPhoneAccountsCount() {
528 try {
529 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700530 return getTelecomService().getAllPhoneAccountsCount();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700531 }
532 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700533 Log.e(TAG, "Error calling ITelecomService#getAllPhoneAccountsCount", e);
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700534 }
535 return 0;
536 }
537
538 /**
539 * Returns a list of all {@link PhoneAccount}s.
540 *
541 * @return All {@link PhoneAccount}s.
542 * @hide
543 */
544 @SystemApi
545 public List<PhoneAccount> getAllPhoneAccounts() {
546 try {
547 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700548 return getTelecomService().getAllPhoneAccounts();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700549 }
550 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700551 Log.e(TAG, "Error calling ITelecomService#getAllPhoneAccounts", e);
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700552 }
553 return Collections.EMPTY_LIST;
554 }
555
556 /**
557 * Returns a list of all {@link PhoneAccountHandle}s.
558 *
559 * @return All {@link PhoneAccountHandle}s.
560 * @hide
561 */
562 @SystemApi
563 public List<PhoneAccountHandle> getAllPhoneAccountHandles() {
564 try {
565 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700566 return getTelecomService().getAllPhoneAccountHandles();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700567 }
568 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700569 Log.e(TAG, "Error calling ITelecomService#getAllPhoneAccountHandles", e);
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700570 }
571 return Collections.EMPTY_LIST;
572 }
573
574 /**
575 * Enables or disables a {@link PhoneAccount}.
576 *
577 * @param account The {@link PhoneAccountHandle} to enable or disable.
578 * @param isEnabled {@code True} if the phone account should be enabled.
579 * @hide
580 */
581 @SystemApi
582 public void setPhoneAccountEnabled(PhoneAccountHandle account, boolean isEnabled) {
583 try {
584 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700585 getTelecomService().setPhoneAccountEnabled(account, isEnabled);
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700586 }
587 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700588 Log.e(TAG, "Error calling ITelecomService#setPhoneAccountEnabled", e);
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700589 }
590 }
591
592 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700593 * Register a {@link PhoneAccount} for use by the system.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700594 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700595 * @param account The complete {@link PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700596 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700597 public void registerPhoneAccount(PhoneAccount account) {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700598 try {
599 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700600 getTelecomService().registerPhoneAccount(account);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700601 }
602 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700603 Log.e(TAG, "Error calling ITelecomService#registerPhoneAccount", e);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700604 }
605 }
606
607 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700608 * Remove a {@link PhoneAccount} registration from the system.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700609 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700610 * @param accountHandle A {@link PhoneAccountHandle} for the {@link PhoneAccount} to unregister.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700611 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700612 public void unregisterPhoneAccount(PhoneAccountHandle accountHandle) {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700613 try {
614 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700615 getTelecomService().unregisterPhoneAccount(accountHandle);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700616 }
617 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700618 Log.e(TAG, "Error calling ITelecomService#unregisterPhoneAccount", e);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700619 }
620 }
621
622 /**
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700623 * Remove all Accounts that belong to the calling package from the system.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700624 */
625 @SystemApi
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700626 public void clearAccounts() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700627 try {
628 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700629 getTelecomService().clearAccounts(mContext.getPackageName());
Ihab Awad807fe0a2014-07-09 12:30:52 -0700630 }
631 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700632 Log.e(TAG, "Error calling ITelecomService#clearAccounts", e);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700633 }
634 }
635
636 /**
637 * @hide
638 */
Santos Cordon6c7a3882014-06-25 15:30:08 -0700639 @SystemApi
640 public ComponentName getDefaultPhoneApp() {
641 try {
Santos Cordon9eb45932014-06-27 12:28:43 -0700642 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700643 return getTelecomService().getDefaultPhoneApp();
Santos Cordon9eb45932014-06-27 12:28:43 -0700644 }
Santos Cordon6c7a3882014-06-25 15:30:08 -0700645 } catch (RemoteException e) {
646 Log.e(TAG, "RemoteException attempting to get the default phone app.", e);
647 }
648 return null;
649 }
650
Santos Cordon9eb45932014-06-27 12:28:43 -0700651 /**
652 * Returns whether there is an ongoing phone call (can be in dialing, ringing, active or holding
653 * states).
Nancy Chen0eb1e402014-08-21 22:52:29 -0700654 * <p>
655 * Requires permission: {@link android.Manifest.permission#READ_PHONE_STATE}
656 * </p>
Santos Cordon9eb45932014-06-27 12:28:43 -0700657 */
658 @SystemApi
Nancy Chen0eb1e402014-08-21 22:52:29 -0700659 public boolean isInCall() {
Santos Cordon9eb45932014-06-27 12:28:43 -0700660 try {
661 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700662 return getTelecomService().isInCall();
Santos Cordon9eb45932014-06-27 12:28:43 -0700663 }
664 } catch (RemoteException e) {
Yorke Lee2ae312e2014-09-12 17:58:48 -0700665 Log.e(TAG, "RemoteException calling isInCall().", e);
Santos Cordon9eb45932014-06-27 12:28:43 -0700666 }
667 return false;
668 }
669
670 /**
Yorke Lee2ae312e2014-09-12 17:58:48 -0700671 * Returns one of the following constants that represents the current state of Telecom:
672 *
673 * {@link TelephonyManager#CALL_STATE_RINGING}
674 * {@link TelephonyManager#CALL_STATE_OFFHOOK}
675 * {@link TelephonyManager#CALL_STATE_IDLE}
676 *
677 * <p>
678 * Requires permission: {@link android.Manifest.permission#READ_PHONE_STATE}
679 * </p>
680 * @hide
681 */
682 @SystemApi
683 public int getCallState() {
684 try {
685 if (isServiceConnected()) {
686 return getTelecomService().getCallState();
687 }
688 } catch (RemoteException e) {
689 Log.d(TAG, "RemoteException calling getCallState().", e);
690 }
691 return TelephonyManager.CALL_STATE_IDLE;
692 }
693
694 /**
Santos Cordon9eb45932014-06-27 12:28:43 -0700695 * Returns whether there currently exists is a ringing incoming-call.
696 *
697 * @hide
698 */
699 @SystemApi
700 public boolean isRinging() {
701 try {
702 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700703 return getTelecomService().isRinging();
Santos Cordon9eb45932014-06-27 12:28:43 -0700704 }
705 } catch (RemoteException e) {
706 Log.e(TAG, "RemoteException attempting to get ringing state of phone app.", e);
707 }
708 return false;
709 }
710
711 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700712 * Ends an ongoing call.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700713 * TODO: L-release - need to convert all invocations of ITelecomService#endCall to use this
Santos Cordon96efb482014-07-19 14:57:05 -0700714 * method (clockwork & gearhead).
Santos Cordon9eb45932014-06-27 12:28:43 -0700715 * @hide
716 */
717 @SystemApi
718 public boolean endCall() {
719 try {
720 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700721 return getTelecomService().endCall();
Santos Cordon9eb45932014-06-27 12:28:43 -0700722 }
723 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700724 Log.e(TAG, "Error calling ITelecomService#endCall", e);
Santos Cordon9eb45932014-06-27 12:28:43 -0700725 }
726 return false;
727 }
728
729 /**
730 * If there is a ringing incoming call, this method accepts the call on behalf of the user.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700731 * TODO: L-release - need to convert all invocation of ITelecmmService#answerRingingCall to use
Santos Cordon96efb482014-07-19 14:57:05 -0700732 * this method (clockwork & gearhead).
Santos Cordon9eb45932014-06-27 12:28:43 -0700733 *
734 * @hide
735 */
736 @SystemApi
737 public void acceptRingingCall() {
738 try {
739 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700740 getTelecomService().acceptRingingCall();
Santos Cordon9eb45932014-06-27 12:28:43 -0700741 }
742 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700743 Log.e(TAG, "Error calling ITelecomService#acceptRingingCall", e);
Santos Cordon9eb45932014-06-27 12:28:43 -0700744 }
745 }
746
747 /**
748 * Silences the ringer if a ringing call exists.
749 *
750 * @hide
751 */
752 @SystemApi
753 public void silenceRinger() {
754 try {
755 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700756 getTelecomService().silenceRinger();
Santos Cordon9eb45932014-06-27 12:28:43 -0700757 }
758 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700759 Log.e(TAG, "Error calling ITelecomService#silenceRinger", e);
Santos Cordon9eb45932014-06-27 12:28:43 -0700760 }
761 }
762
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700763 /**
764 * Returns whether TTY is supported on this device.
765 *
766 * @hide
767 */
768 @SystemApi
769 public boolean isTtySupported() {
770 try {
771 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700772 return getTelecomService().isTtySupported();
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700773 }
774 } catch (RemoteException e) {
775 Log.e(TAG, "RemoteException attempting to get TTY supported state.", e);
776 }
777 return false;
778 }
779
780 /**
781 * 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 -0700782 * settings and have a wired headset plugged in.
783 * Valid modes are:
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700784 * - {@link TelecomManager#TTY_MODE_OFF}
785 * - {@link TelecomManager#TTY_MODE_FULL}
786 * - {@link TelecomManager#TTY_MODE_HCO}
787 * - {@link TelecomManager#TTY_MODE_VCO}
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700788 * @hide
789 */
790 public int getCurrentTtyMode() {
791 try {
792 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700793 return getTelecomService().getCurrentTtyMode();
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700794 }
795 } catch (RemoteException e) {
796 Log.e(TAG, "RemoteException attempting to get the current TTY mode.", e);
797 }
Evan Charlton10197192014-07-19 15:00:29 -0700798 return TTY_MODE_OFF;
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700799 }
800
Santos Cordon96efb482014-07-19 14:57:05 -0700801 /**
802 * Registers a new incoming call. A {@link ConnectionService} should invoke this method when it
803 * has an incoming call. The specified {@link PhoneAccountHandle} must have been registered
804 * with {@link #registerPhoneAccount} and subsequently enabled by the user within the phone's
805 * settings. Once invoked, this method will cause the system to bind to the
806 * {@link ConnectionService} associated with the {@link PhoneAccountHandle} and request
807 * additional information about the call (See
808 * {@link ConnectionService#onCreateIncomingConnection}) before starting the incoming call UI.
809 *
810 * @param phoneAccount A {@link PhoneAccountHandle} registered with
811 * {@link #registerPhoneAccount}.
812 * @param extras A bundle that will be passed through to
813 * {@link ConnectionService#onCreateIncomingConnection}.
814 */
815 public void addNewIncomingCall(PhoneAccountHandle phoneAccount, Bundle extras) {
816 try {
817 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700818 getTelecomService().addNewIncomingCall(
Santos Cordon96efb482014-07-19 14:57:05 -0700819 phoneAccount, extras == null ? new Bundle() : extras);
820 }
821 } catch (RemoteException e) {
822 Log.e(TAG, "RemoteException adding a new incoming call: " + phoneAccount, e);
823 }
824 }
825
Nancy Chen0eb1e402014-08-21 22:52:29 -0700826 /**
827 * Processes the specified dial string as an MMI code.
828 * MMI codes are any sequence of characters entered into the dialpad that contain a "*" or "#".
829 * Some of these sequences launch special behavior through handled by Telephony.
830 * <p>
831 * Requires that the method-caller be set as the system dialer app.
832 * </p>
833 *
834 * @param dialString The digits to dial.
835 * @return True if the digits were processed as an MMI code, false otherwise.
836 */
837 public boolean handleMmi(String dialString) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700838 ITelecomService service = getTelecomService();
Nancy Chen0eb1e402014-08-21 22:52:29 -0700839 if (service != null) {
840 try {
841 return service.handlePinMmi(dialString);
842 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700843 Log.e(TAG, "Error calling ITelecomService#handlePinMmi", e);
Nancy Chen0eb1e402014-08-21 22:52:29 -0700844 }
845 }
846 return false;
847 }
848
849 /**
850 * Removes the missed-call notification if one is present.
851 * <p>
852 * Requires that the method-caller be set as the system dialer app.
853 * </p>
854 */
855 public void cancelMissedCallsNotification() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700856 ITelecomService service = getTelecomService();
Nancy Chen0eb1e402014-08-21 22:52:29 -0700857 if (service != null) {
858 try {
859 service.cancelMissedCallsNotification();
860 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700861 Log.e(TAG, "Error calling ITelecomService#cancelMissedCallsNotification", e);
Nancy Chen0eb1e402014-08-21 22:52:29 -0700862 }
863 }
864 }
865
866 /**
867 * Brings the in-call screen to the foreground if there is an ongoing call. If there is
868 * currently no ongoing call, then this method does nothing.
869 * <p>
870 * Requires that the method-caller be set as the system dialer app or have the
871 * {@link android.Manifest.permission#READ_PHONE_STATE} permission.
872 * </p>
873 *
874 * @param showDialpad Brings up the in-call dialpad as part of showing the in-call screen.
875 */
876 public void showInCallScreen(boolean showDialpad) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700877 ITelecomService service = getTelecomService();
Nancy Chen0eb1e402014-08-21 22:52:29 -0700878 if (service != null) {
879 try {
880 service.showInCallScreen(showDialpad);
881 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700882 Log.e(TAG, "Error calling ITelecomService#showCallScreen", e);
Nancy Chen0eb1e402014-08-21 22:52:29 -0700883 }
884 }
885 }
886
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700887 private ITelecomService getTelecomService() {
888 return ITelecomService.Stub.asInterface(ServiceManager.getService(Context.TELECOM_SERVICE));
Santos Cordon6c7a3882014-06-25 15:30:08 -0700889 }
Santos Cordon9eb45932014-06-27 12:28:43 -0700890
891 private boolean isServiceConnected() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700892 boolean isConnected = getTelecomService() != null;
Santos Cordon9eb45932014-06-27 12:28:43 -0700893 if (!isConnected) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700894 Log.w(TAG, "Telecom Service not found.");
Santos Cordon9eb45932014-06-27 12:28:43 -0700895 }
896 return isConnected;
897 }
Evan Charlton235c1592014-09-05 15:41:23 +0000898}