blob: 1f5be6e4fedee6d169a8b2f5f289ad3918473828 [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;
23import android.util.Log;
Yorke Leeb4ce1432014-06-09 13:53:23 -070024
Tyler Gunnef9f6f92014-09-12 22:16:17 -070025import com.android.internal.telecom.ITelecomService;
Yorke Leeb4ce1432014-06-09 13:53:23 -070026
Jay Shrauner7746a942014-08-26 12:15:15 -070027import java.util.ArrayList;
Tyler Gunna1ed7d12014-09-08 09:52:22 -070028import java.util.Collections;
Ihab Awad807fe0a2014-07-09 12:30:52 -070029import java.util.List;
30
Yorke Leeb4ce1432014-06-09 13:53:23 -070031/**
Tyler Gunnef9f6f92014-09-12 22:16:17 -070032 * Provides access to Telecom-related functionality.
Santos Cordon96efb482014-07-19 14:57:05 -070033 * TODO: Move this all into PhoneManager.
Yorke Leeb4ce1432014-06-09 13:53:23 -070034 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -070035public class TelecomManager {
Ihab Awad807fe0a2014-07-09 12:30:52 -070036
Evan Charlton10197192014-07-19 15:00:29 -070037 /**
Santos Cordon96efb482014-07-19 14:57:05 -070038 * Activity action: Starts the UI for handing an incoming call. This intent starts the in-call
Tyler Gunnef9f6f92014-09-12 22:16:17 -070039 * UI by notifying the Telecom system that an incoming call exists for a specific call service
40 * (see {@link android.telecom.ConnectionService}). Telecom reads the Intent extras to find
41 * and bind to the appropriate {@link android.telecom.ConnectionService} which Telecom will
Santos Cordon96efb482014-07-19 14:57:05 -070042 * ultimately use to control and get information about the call.
43 * <p>
44 * Input: get*Extra field {@link #EXTRA_PHONE_ACCOUNT_HANDLE} contains the component name of the
Tyler Gunnef9f6f92014-09-12 22:16:17 -070045 * {@link android.telecom.ConnectionService} that Telecom should bind to. Telecom will then
Evan Charlton10197192014-07-19 15:00:29 -070046 * ask the connection service for more information about the call prior to showing any UI.
47 *
Santos Cordon96efb482014-07-19 14:57:05 -070048 * @hide
Evan Charlton10197192014-07-19 15:00:29 -070049 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -070050 public static final String ACTION_INCOMING_CALL = "android.telecom.action.INCOMING_CALL";
Evan Charlton10197192014-07-19 15:00:29 -070051
52 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -070053 * The {@link android.content.Intent} action used to configure a
Tyler Gunnef9f6f92014-09-12 22:16:17 -070054 * {@link android.telecom.ConnectionService}.
Evan Charlton10197192014-07-19 15:00:29 -070055 */
56 public static final String ACTION_CONNECTION_SERVICE_CONFIGURE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -070057 "android.telecom.action.CONNECTION_SERVICE_CONFIGURE";
Evan Charlton10197192014-07-19 15:00:29 -070058
59 /**
Yorke Lee3818a892014-07-21 15:57:17 -070060 * The {@link android.content.Intent} action used to show the call settings page.
61 */
62 public static final String ACTION_SHOW_CALL_SETTINGS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -070063 "android.telecom.action.SHOW_CALL_SETTINGS";
Yorke Lee3818a892014-07-21 15:57:17 -070064
65 /**
Evan Charlton6d8604f2014-09-04 12:38:17 -070066 * The {@link android.content.Intent} action used to show the settings page used to configure
67 * {@link PhoneAccount} preferences.
68 */
69 public static final String ACTION_CHANGE_PHONE_ACCOUNTS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -070070 "android.telecom.action.CHANGE_PHONE_ACCOUNTS";
Evan Charlton6d8604f2014-09-04 12:38:17 -070071
72 /**
Tyler Gunn9becf002014-09-11 13:31:57 -070073 * The {@link android.content.Intent} action used to inform a
Tyler Gunnef9f6f92014-09-12 22:16:17 -070074 * {@link android.telecom.ConnectionService} that one of its {@link PhoneAccount}s has been
75 * enabled. The {@link TelecomManager#EXTRA_PHONE_ACCOUNT_HANDLE} extra is used to indicate
Tyler Gunn9becf002014-09-11 13:31:57 -070076 * which {@link PhoneAccount} has been enabled.
77 */
78 public static final String ACTION_PHONE_ACCOUNT_ENABLED =
79 "android.telecom.action.PHONE_ACCOUNT_ENABLED";
80
81 /**
82 * The {@link android.content.Intent} action used to inform a
Tyler Gunnef9f6f92014-09-12 22:16:17 -070083 * {@link android.telecom.ConnectionService} that one of its {@link PhoneAccount}s has been
84 * disabled. The {@link TelecomManager#EXTRA_PHONE_ACCOUNT_HANDLE} extra is used to indicate
Tyler Gunn9becf002014-09-11 13:31:57 -070085 * which {@link PhoneAccount} has been disabled.
86 */
87 public static final String ACTION_PHONE_ACCOUNT_DISABLED =
88 "android.telecom.action.PHONE_ACCOUNT_DISABLED";
89
90 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -070091 * Optional extra for {@link android.content.Intent#ACTION_CALL} containing a boolean that
92 * determines whether the speakerphone should be automatically turned on for an outgoing call.
Evan Charlton10197192014-07-19 15:00:29 -070093 */
94 public static final String EXTRA_START_CALL_WITH_SPEAKERPHONE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -070095 "android.telecom.extra.START_CALL_WITH_SPEAKERPHONE";
Evan Charlton10197192014-07-19 15:00:29 -070096
97 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -070098 * Optional extra for {@link android.content.Intent#ACTION_CALL} containing an integer that
99 * determines the desired video state for an outgoing call.
Santos Cordon96efb482014-07-19 14:57:05 -0700100 * Valid options:
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700101 * {@link VideoProfile.VideoState#AUDIO_ONLY},
102 * {@link VideoProfile.VideoState#BIDIRECTIONAL},
103 * {@link VideoProfile.VideoState#RX_ENABLED},
104 * {@link VideoProfile.VideoState#TX_ENABLED}.
Tyler Gunn27d1e252014-08-21 16:38:40 -0700105 * @hide
Evan Charlton10197192014-07-19 15:00:29 -0700106 */
107 public static final String EXTRA_START_CALL_WITH_VIDEO_STATE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700108 "android.telecom.extra.START_CALL_WITH_VIDEO_STATE";
Evan Charlton10197192014-07-19 15:00:29 -0700109
110 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700111 * The extra used with an {@link android.content.Intent#ACTION_CALL} and
112 * {@link android.content.Intent#ACTION_DIAL} {@code Intent} to specify a
113 * {@link PhoneAccountHandle} to use when making the call.
Evan Charlton10197192014-07-19 15:00:29 -0700114 * <p class="note">
Santos Cordon96efb482014-07-19 14:57:05 -0700115 * Retrieve with {@link android.content.Intent#getParcelableExtra(String)}.
Evan Charlton10197192014-07-19 15:00:29 -0700116 */
Evan Charlton6eb262c2014-07-19 18:18:19 -0700117 public static final String EXTRA_PHONE_ACCOUNT_HANDLE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700118 "android.telecom.extra.PHONE_ACCOUNT_HANDLE";
Evan Charlton10197192014-07-19 15:00:29 -0700119
120 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700121 * Optional extra for {@link #ACTION_INCOMING_CALL} containing a {@link Bundle} which contains
122 * metadata about the call. This {@link Bundle} will be returned to the
123 * {@link ConnectionService}.
124 *
125 * @hide
Evan Charlton10197192014-07-19 15:00:29 -0700126 */
127 public static final String EXTRA_INCOMING_CALL_EXTRAS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700128 "android.telecom.extra.INCOMING_CALL_EXTRAS";
Evan Charlton10197192014-07-19 15:00:29 -0700129
130 /**
Nancy Chen10798dc2014-08-08 14:00:25 -0700131 * Optional extra for {@link android.content.Intent#ACTION_CALL} and
132 * {@link android.content.Intent#ACTION_DIAL} {@code Intent} containing a {@link Bundle}
133 * which contains metadata about the call. This {@link Bundle} will be saved into
134 * {@code Call.Details}.
135 *
136 * @hide
137 */
138 public static final String EXTRA_OUTGOING_CALL_EXTRAS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700139 "android.telecom.extra.OUTGOING_CALL_EXTRAS";
Nancy Chen10798dc2014-08-08 14:00:25 -0700140
141 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700142 * Optional extra for {@link android.telephony.TelephonyManager#ACTION_PHONE_STATE_CHANGED}
143 * containing the disconnect code.
Evan Charlton10197192014-07-19 15:00:29 -0700144 */
145 public static final String EXTRA_CALL_DISCONNECT_CAUSE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700146 "android.telecom.extra.CALL_DISCONNECT_CAUSE";
Evan Charlton10197192014-07-19 15:00:29 -0700147
148 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700149 * Optional extra for {@link android.telephony.TelephonyManager#ACTION_PHONE_STATE_CHANGED}
150 * containing the disconnect message.
Evan Charlton10197192014-07-19 15:00:29 -0700151 */
152 public static final String EXTRA_CALL_DISCONNECT_MESSAGE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700153 "android.telecom.extra.CALL_DISCONNECT_MESSAGE";
Evan Charlton10197192014-07-19 15:00:29 -0700154
155 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700156 * Optional extra for {@link android.telephony.TelephonyManager#ACTION_PHONE_STATE_CHANGED}
157 * containing the component name of the associated connection service.
Evan Charlton10197192014-07-19 15:00:29 -0700158 */
159 public static final String EXTRA_CONNECTION_SERVICE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700160 "android.telecom.extra.CONNECTION_SERVICE";
Evan Charlton10197192014-07-19 15:00:29 -0700161
162 /**
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700163 * An optional {@link android.content.Intent#ACTION_CALL} intent extra denoting the
164 * package name of the app specifying an alternative gateway for the call.
165 * The value is a string.
166 *
167 * (The following comment corresponds to the all GATEWAY_* extras)
168 * An app which sends the {@link android.content.Intent#ACTION_CALL} intent can specify an
169 * alternative address to dial which is different from the one specified and displayed to
170 * the user. This alternative address is referred to as the gateway address.
171 */
172 public static final String GATEWAY_PROVIDER_PACKAGE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700173 "android.telecom.extra.GATEWAY_PROVIDER_PACKAGE";
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700174
175 /**
176 * An optional {@link android.content.Intent#ACTION_CALL} intent extra corresponding to the
177 * original address to dial for the call. This is used when an alternative gateway address is
178 * provided to recall the original address.
179 * The value is a {@link android.net.Uri}.
180 *
181 * (See {@link #GATEWAY_PROVIDER_PACKAGE} for details)
182 */
183 public static final String GATEWAY_ORIGINAL_ADDRESS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700184 "android.telecom.extra.GATEWAY_ORIGINAL_ADDRESS";
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700185
186 /**
Evan Charlton10197192014-07-19 15:00:29 -0700187 * The number which the party on the other side of the line will see (and use to return the
188 * call).
189 * <p>
Santos Cordon96efb482014-07-19 14:57:05 -0700190 * {@link ConnectionService}s which interact with {@link RemoteConnection}s should only populate
191 * this if the {@link android.telephony.TelephonyManager#getLine1Number()} value, as that is the
192 * user's expected caller ID.
Evan Charlton10197192014-07-19 15:00:29 -0700193 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700194 public static final String EXTRA_CALL_BACK_NUMBER = "android.telecom.extra.CALL_BACK_NUMBER";
Evan Charlton10197192014-07-19 15:00:29 -0700195
196 /**
197 * The dual tone multi-frequency signaling character sent to indicate the dialing system should
198 * pause for a predefined period.
199 */
200 public static final char DTMF_CHARACTER_PAUSE = ',';
201
202 /**
203 * The dual-tone multi-frequency signaling character sent to indicate the dialing system should
204 * wait for user confirmation before proceeding.
205 */
206 public static final char DTMF_CHARACTER_WAIT = ';';
207
208 /**
209 * TTY (teletypewriter) mode is off.
210 *
211 * @hide
212 */
213 public static final int TTY_MODE_OFF = 0;
214
215 /**
216 * TTY (teletypewriter) mode is on. The speaker is off and the microphone is muted. The user
217 * will communicate with the remote party by sending and receiving text messages.
218 *
219 * @hide
220 */
221 public static final int TTY_MODE_FULL = 1;
222
223 /**
224 * TTY (teletypewriter) mode is in hearing carryover mode (HCO). The microphone is muted but the
225 * speaker is on. The user will communicate with the remote party by sending text messages and
226 * hearing an audible reply.
227 *
228 * @hide
229 */
230 public static final int TTY_MODE_HCO = 2;
231
232 /**
233 * TTY (teletypewriter) mode is in voice carryover mode (VCO). The speaker is off but the
234 * microphone is still on. User will communicate with the remote party by speaking and receiving
235 * text message replies.
236 *
237 * @hide
238 */
239 public static final int TTY_MODE_VCO = 3;
240
241 /**
242 * Broadcast intent action indicating that the current TTY mode has changed. An intent extra
243 * provides this state as an int.
Evan Charlton10197192014-07-19 15:00:29 -0700244 *
Santos Cordon96efb482014-07-19 14:57:05 -0700245 * @see #EXTRA_CURRENT_TTY_MODE
Evan Charlton10197192014-07-19 15:00:29 -0700246 * @hide
247 */
248 public static final String ACTION_CURRENT_TTY_MODE_CHANGED =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700249 "android.telecom.action.CURRENT_TTY_MODE_CHANGED";
Evan Charlton10197192014-07-19 15:00:29 -0700250
251 /**
252 * The lookup key for an int that indicates the current TTY mode.
253 * Valid modes are:
254 * - {@link #TTY_MODE_OFF}
255 * - {@link #TTY_MODE_FULL}
256 * - {@link #TTY_MODE_HCO}
257 * - {@link #TTY_MODE_VCO}
258 *
259 * @hide
260 */
261 public static final String EXTRA_CURRENT_TTY_MODE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700262 "android.telecom.intent.extra.CURRENT_TTY_MODE";
Evan Charlton10197192014-07-19 15:00:29 -0700263
264 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700265 * Broadcast intent action indicating that the TTY preferred operating mode has changed. An
266 * intent extra provides the new mode as an int.
Evan Charlton10197192014-07-19 15:00:29 -0700267 *
Santos Cordon96efb482014-07-19 14:57:05 -0700268 * @see #EXTRA_TTY_PREFERRED_MODE
Evan Charlton10197192014-07-19 15:00:29 -0700269 * @hide
270 */
271 public static final String ACTION_TTY_PREFERRED_MODE_CHANGED =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700272 "android.telecom.action.TTY_PREFERRED_MODE_CHANGED";
Evan Charlton10197192014-07-19 15:00:29 -0700273
274 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700275 * The lookup key for an int that indicates preferred TTY mode. Valid modes are: -
276 * {@link #TTY_MODE_OFF} - {@link #TTY_MODE_FULL} - {@link #TTY_MODE_HCO} -
277 * {@link #TTY_MODE_VCO}
Evan Charlton10197192014-07-19 15:00:29 -0700278 *
279 * @hide
280 */
281 public static final String EXTRA_TTY_PREFERRED_MODE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700282 "android.telecom.intent.extra.TTY_PREFERRED";
Evan Charlton10197192014-07-19 15:00:29 -0700283
Nancy Chen9d568c02014-09-08 14:17:59 -0700284 /**
285 * The following 4 constants define how properties such as phone numbers and names are
286 * displayed to the user.
287 */
288
289 /** Property is displayed normally. */
290 public static final int PRESENTATION_ALLOWED = 1;
291
292 /** Property was blocked. */
293 public static final int PRESENTATION_RESTRICTED = 2;
294
295 /** Presentation was not specified or is unknown. */
296 public static final int PRESENTATION_UNKNOWN = 3;
297
298 /** Property should be displayed as a pay phone. */
299 public static final int PRESENTATION_PAYPHONE = 4;
300
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700301 private static final String TAG = "TelecomManager";
Yorke Leeb4ce1432014-06-09 13:53:23 -0700302
303 private final Context mContext;
Yorke Leeb4ce1432014-06-09 13:53:23 -0700304
Santos Cordon6c7a3882014-06-25 15:30:08 -0700305 /**
306 * @hide
307 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700308 public static TelecomManager from(Context context) {
309 return (TelecomManager) context.getSystemService(Context.TELECOM_SERVICE);
Yorke Leeb4ce1432014-06-09 13:53:23 -0700310 }
Santos Cordon6c7a3882014-06-25 15:30:08 -0700311
312 /**
313 * @hide
314 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700315 public TelecomManager(Context context) {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700316 Context appContext = context.getApplicationContext();
317 if (appContext != null) {
318 mContext = appContext;
319 } else {
320 mContext = context;
321 }
322 }
323
324 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700325 * Return the {@link PhoneAccount} which is the user-chosen default for making outgoing phone
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700326 * calls with a specified URI scheme. This {@code PhoneAccount} will always be a member of the
327 * list which is returned from calling {@link #getEnabledPhoneAccounts()}.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700328 * <p>
Santos Cordon96efb482014-07-19 14:57:05 -0700329 * Apps must be prepared for this method to return {@code null}, indicating that there currently
330 * exists no user-chosen default {@code PhoneAccount}. In this case, apps wishing to initiate a
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700331 * phone call must either create their {@link android.content.Intent#ACTION_CALL} or
Santos Cordon96efb482014-07-19 14:57:05 -0700332 * {@link android.content.Intent#ACTION_DIAL} {@code Intent} with no
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700333 * {@link TelecomManager#EXTRA_PHONE_ACCOUNT_HANDLE}, or present the user with an affordance to
Santos Cordon96efb482014-07-19 14:57:05 -0700334 * select one of the elements of {@link #getEnabledPhoneAccounts()}.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700335 * <p>
336 * An {@link android.content.Intent#ACTION_CALL} or {@link android.content.Intent#ACTION_DIAL}
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700337 * {@code Intent} with no {@link TelecomManager#EXTRA_PHONE_ACCOUNT_HANDLE} is valid, and
Evan Charlton6eb262c2014-07-19 18:18:19 -0700338 * subsequent steps in the phone call flow are responsible for presenting the user with an
Evan Charlton8c8a0622014-07-20 12:31:00 -0700339 * affordance, if necessary, to choose a {@code PhoneAccount}.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700340 *
341 * @param uriScheme The URI scheme.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700342 */
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700343 public PhoneAccountHandle getDefaultOutgoingPhoneAccount(String uriScheme) {
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700344 try {
345 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700346 return getTelecomService().getDefaultOutgoingPhoneAccount(uriScheme);
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700347 }
348 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700349 Log.e(TAG, "Error calling ITelecomService#getDefaultOutgoingPhoneAccount", e);
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700350 }
351 return null;
352 }
353
354 /**
Andrew Leed4abbfb2014-09-03 14:58:27 -0700355 * Return the {@link PhoneAccount} which is the user-chosen default for making outgoing phone
356 * calls. This {@code PhoneAccount} will always be a member of the list which is returned from
357 * calling {@link #getEnabledPhoneAccounts()}
358 *
359 * Apps must be prepared for this method to return {@code null}, indicating that there currently
360 * exists no user-chosen default {@code PhoneAccount}.
361 *
362 * @return The user outgoing phone account selected by the user.
363 * @hide
364 */
365 public PhoneAccountHandle getUserSelectedOutgoingPhoneAccount() {
366 try {
367 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700368 return getTelecomService().getUserSelectedOutgoingPhoneAccount();
Andrew Leed4abbfb2014-09-03 14:58:27 -0700369 }
370 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700371 Log.e(TAG, "Error calling ITelecomService#getUserSelectedOutgoingPhoneAccount", e);
Andrew Leed4abbfb2014-09-03 14:58:27 -0700372 }
373 return null;
374 }
375
376 /**
Andrew Lee59cac3a2014-08-28 16:50:10 -0700377 * Sets the default account for making outgoing phone calls.
378 * @hide
379 */
Andrew Leed4abbfb2014-09-03 14:58:27 -0700380 public void setUserSelectedOutgoingPhoneAccount(PhoneAccountHandle accountHandle) {
Andrew Lee59cac3a2014-08-28 16:50:10 -0700381 try {
382 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700383 getTelecomService().setUserSelectedOutgoingPhoneAccount(accountHandle);
Andrew Lee59cac3a2014-08-28 16:50:10 -0700384 }
385 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700386 Log.e(TAG, "Error calling ITelecomService#setUserSelectedOutgoingPhoneAccount");
Andrew Lee59cac3a2014-08-28 16:50:10 -0700387 }
388 }
389
390 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700391 * Return a list of enabled {@link PhoneAccountHandle}s which can be used to make and receive
392 * phone calls.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700393 *
Evan Charlton6eb262c2014-07-19 18:18:19 -0700394 * @see #EXTRA_PHONE_ACCOUNT_HANDLE
395 * @return A list of {@code PhoneAccountHandle} objects.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700396 */
Evan Charlton6eb262c2014-07-19 18:18:19 -0700397 public List<PhoneAccountHandle> getEnabledPhoneAccounts() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700398 try {
399 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700400 return getTelecomService().getEnabledPhoneAccounts();
Ihab Awad807fe0a2014-07-09 12:30:52 -0700401 }
402 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700403 Log.e(TAG, "Error calling ITelecomService#getEnabledPhoneAccounts", e);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700404 }
Jay Shrauner7746a942014-08-26 12:15:15 -0700405 return new ArrayList<>();
Ihab Awad807fe0a2014-07-09 12:30:52 -0700406 }
407
408 /**
Andrew Lee59cac3a2014-08-28 16:50:10 -0700409 * Returns the current SIM call manager. Apps must be prepared for this method to return
410 * {@code null}, indicating that there currently exists no user-chosen default
411 * {@code PhoneAccount}.
412 * @return The phone account handle of the current sim call manager.
413 * @hide
414 */
415 public PhoneAccountHandle getSimCallManager() {
416 try {
417 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700418 return getTelecomService().getSimCallManager();
Andrew Lee59cac3a2014-08-28 16:50:10 -0700419 }
420 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700421 Log.e(TAG, "Error calling ITelecomService#getSimCallManager");
Andrew Lee59cac3a2014-08-28 16:50:10 -0700422 }
423 return null;
424 }
425
426 /**
427 * Sets the SIM call manager to the specified phone account.
428 * @param accountHandle The phone account handle of the account to set as the sim call manager.
429 * @hide
430 */
431 public void setSimCallManager(PhoneAccountHandle accountHandle) {
432 try {
433 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700434 getTelecomService().setSimCallManager(accountHandle);
Andrew Lee59cac3a2014-08-28 16:50:10 -0700435 }
436 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700437 Log.e(TAG, "Error calling ITelecomService#setSimCallManager");
Andrew Lee59cac3a2014-08-28 16:50:10 -0700438 }
439 }
440
441 /**
442 * Returns the list of registered SIM call managers.
443 * @return List of registered SIM call managers.
444 * @hide
445 */
446 public List<PhoneAccountHandle> getSimCallManagers() {
447 try {
448 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700449 return getTelecomService().getSimCallManagers();
Andrew Lee59cac3a2014-08-28 16:50:10 -0700450 }
451 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700452 Log.e(TAG, "Error calling ITelecomService#getSimCallManagers");
Andrew Lee59cac3a2014-08-28 16:50:10 -0700453 }
454 return new ArrayList<>();
455 }
456
457 /**
Evan Charltoneb0a8d52014-09-04 12:03:34 -0700458 * Returns the current connection manager. Apps must be prepared for this method to return
459 * {@code null}, indicating that there currently exists no user-chosen default
460 * {@code PhoneAccount}.
461 *
462 * @return The phone account handle of the current connection manager.
463 */
464 public PhoneAccountHandle getConnectionManager() {
465 return getSimCallManager();
466 }
467
468 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700469 * Returns a list of the enabled {@link PhoneAccountHandle}s which can be used to make and
470 * receive phone 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.
479 */
480 public List<PhoneAccountHandle> getPhoneAccountsSupportingScheme(String uriScheme) {
481 try {
482 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700483 return getTelecomService().getPhoneAccountsSupportingScheme(uriScheme);
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700484 }
485 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700486 Log.e(TAG, "Error calling ITelecomService#getPhoneAccountsSupportingScheme", e);
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700487 }
488 return new ArrayList<>();
489 }
490
491 /**
Nancy Chen60801182014-07-22 16:56:49 -0700492 * Determine whether the device has more than one account registered and enabled.
493 *
494 * @return {@code true} if the device has more than one account registered and enabled and
495 * {@code false} otherwise.
496 */
497 public boolean hasMultipleEnabledAccounts() {
498 return getEnabledPhoneAccounts().size() > 1;
499 }
500
501 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700502 * Return the {@link PhoneAccount} for a specified {@link PhoneAccountHandle}. Object includes
503 * resources which can be used in a user interface.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700504 *
Evan Charlton6eb262c2014-07-19 18:18:19 -0700505 * @param account The {@link PhoneAccountHandle}.
Evan Charlton8c8a0622014-07-20 12:31:00 -0700506 * @return The {@link PhoneAccount} object.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700507 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700508 public PhoneAccount getPhoneAccount(PhoneAccountHandle account) {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700509 try {
510 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700511 return getTelecomService().getPhoneAccount(account);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700512 }
513 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700514 Log.e(TAG, "Error calling ITelecomService#getPhoneAccount", e);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700515 }
516 return null;
517 }
518
519 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700520 * Returns a count of enabled and disabled {@link PhoneAccount}s.
521 *
522 * @return The count of enabled and disabled {@link PhoneAccount}s.
523 * @hide
524 */
525 @SystemApi
526 public int getAllPhoneAccountsCount() {
527 try {
528 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700529 return getTelecomService().getAllPhoneAccountsCount();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700530 }
531 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700532 Log.e(TAG, "Error calling ITelecomService#getAllPhoneAccountsCount", e);
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700533 }
534 return 0;
535 }
536
537 /**
538 * Returns a list of all {@link PhoneAccount}s.
539 *
540 * @return All {@link PhoneAccount}s.
541 * @hide
542 */
543 @SystemApi
544 public List<PhoneAccount> getAllPhoneAccounts() {
545 try {
546 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700547 return getTelecomService().getAllPhoneAccounts();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700548 }
549 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700550 Log.e(TAG, "Error calling ITelecomService#getAllPhoneAccounts", e);
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700551 }
552 return Collections.EMPTY_LIST;
553 }
554
555 /**
556 * Returns a list of all {@link PhoneAccountHandle}s.
557 *
558 * @return All {@link PhoneAccountHandle}s.
559 * @hide
560 */
561 @SystemApi
562 public List<PhoneAccountHandle> getAllPhoneAccountHandles() {
563 try {
564 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700565 return getTelecomService().getAllPhoneAccountHandles();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700566 }
567 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700568 Log.e(TAG, "Error calling ITelecomService#getAllPhoneAccountHandles", e);
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700569 }
570 return Collections.EMPTY_LIST;
571 }
572
573 /**
574 * Enables or disables a {@link PhoneAccount}.
575 *
576 * @param account The {@link PhoneAccountHandle} to enable or disable.
577 * @param isEnabled {@code True} if the phone account should be enabled.
578 * @hide
579 */
580 @SystemApi
581 public void setPhoneAccountEnabled(PhoneAccountHandle account, boolean isEnabled) {
582 try {
583 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700584 getTelecomService().setPhoneAccountEnabled(account, isEnabled);
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700585 }
586 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700587 Log.e(TAG, "Error calling ITelecomService#setPhoneAccountEnabled", e);
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700588 }
589 }
590
591 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700592 * Register a {@link PhoneAccount} for use by the system.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700593 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700594 * @param account The complete {@link PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700595 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700596 public void registerPhoneAccount(PhoneAccount account) {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700597 try {
598 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700599 getTelecomService().registerPhoneAccount(account);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700600 }
601 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700602 Log.e(TAG, "Error calling ITelecomService#registerPhoneAccount", e);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700603 }
604 }
605
606 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700607 * Remove a {@link PhoneAccount} registration from the system.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700608 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700609 * @param accountHandle A {@link PhoneAccountHandle} for the {@link PhoneAccount} to unregister.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700610 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700611 public void unregisterPhoneAccount(PhoneAccountHandle accountHandle) {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700612 try {
613 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700614 getTelecomService().unregisterPhoneAccount(accountHandle);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700615 }
616 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700617 Log.e(TAG, "Error calling ITelecomService#unregisterPhoneAccount", e);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700618 }
619 }
620
621 /**
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700622 * Remove all Accounts that belong to the calling package from the system.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700623 */
624 @SystemApi
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700625 public void clearAccounts() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700626 try {
627 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700628 getTelecomService().clearAccounts(mContext.getPackageName());
Ihab Awad807fe0a2014-07-09 12:30:52 -0700629 }
630 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700631 Log.e(TAG, "Error calling ITelecomService#clearAccounts", e);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700632 }
633 }
634
635 /**
636 * @hide
637 */
Santos Cordon6c7a3882014-06-25 15:30:08 -0700638 @SystemApi
639 public ComponentName getDefaultPhoneApp() {
640 try {
Santos Cordon9eb45932014-06-27 12:28:43 -0700641 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700642 return getTelecomService().getDefaultPhoneApp();
Santos Cordon9eb45932014-06-27 12:28:43 -0700643 }
Santos Cordon6c7a3882014-06-25 15:30:08 -0700644 } catch (RemoteException e) {
645 Log.e(TAG, "RemoteException attempting to get the default phone app.", e);
646 }
647 return null;
648 }
649
Santos Cordon9eb45932014-06-27 12:28:43 -0700650 /**
651 * Returns whether there is an ongoing phone call (can be in dialing, ringing, active or holding
652 * states).
Nancy Chen0eb1e402014-08-21 22:52:29 -0700653 * <p>
654 * Requires permission: {@link android.Manifest.permission#READ_PHONE_STATE}
655 * </p>
Santos Cordon9eb45932014-06-27 12:28:43 -0700656 */
657 @SystemApi
Nancy Chen0eb1e402014-08-21 22:52:29 -0700658 public boolean isInCall() {
Santos Cordon9eb45932014-06-27 12:28:43 -0700659 try {
660 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700661 return getTelecomService().isInCall();
Santos Cordon9eb45932014-06-27 12:28:43 -0700662 }
663 } catch (RemoteException e) {
664 Log.e(TAG, "RemoteException attempting to get default phone app.", e);
665 }
666 return false;
667 }
668
669 /**
670 * Returns whether there currently exists is a ringing incoming-call.
671 *
672 * @hide
673 */
674 @SystemApi
675 public boolean isRinging() {
676 try {
677 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700678 return getTelecomService().isRinging();
Santos Cordon9eb45932014-06-27 12:28:43 -0700679 }
680 } catch (RemoteException e) {
681 Log.e(TAG, "RemoteException attempting to get ringing state of phone app.", e);
682 }
683 return false;
684 }
685
686 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700687 * Ends an ongoing call.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700688 * TODO: L-release - need to convert all invocations of ITelecomService#endCall to use this
Santos Cordon96efb482014-07-19 14:57:05 -0700689 * method (clockwork & gearhead).
Santos Cordon9eb45932014-06-27 12:28:43 -0700690 * @hide
691 */
692 @SystemApi
693 public boolean endCall() {
694 try {
695 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700696 return getTelecomService().endCall();
Santos Cordon9eb45932014-06-27 12:28:43 -0700697 }
698 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700699 Log.e(TAG, "Error calling ITelecomService#endCall", e);
Santos Cordon9eb45932014-06-27 12:28:43 -0700700 }
701 return false;
702 }
703
704 /**
705 * If there is a ringing incoming call, this method accepts the call on behalf of the user.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700706 * TODO: L-release - need to convert all invocation of ITelecmmService#answerRingingCall to use
Santos Cordon96efb482014-07-19 14:57:05 -0700707 * this method (clockwork & gearhead).
Santos Cordon9eb45932014-06-27 12:28:43 -0700708 *
709 * @hide
710 */
711 @SystemApi
712 public void acceptRingingCall() {
713 try {
714 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700715 getTelecomService().acceptRingingCall();
Santos Cordon9eb45932014-06-27 12:28:43 -0700716 }
717 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700718 Log.e(TAG, "Error calling ITelecomService#acceptRingingCall", e);
Santos Cordon9eb45932014-06-27 12:28:43 -0700719 }
720 }
721
722 /**
723 * Silences the ringer if a ringing call exists.
724 *
725 * @hide
726 */
727 @SystemApi
728 public void silenceRinger() {
729 try {
730 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700731 getTelecomService().silenceRinger();
Santos Cordon9eb45932014-06-27 12:28:43 -0700732 }
733 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700734 Log.e(TAG, "Error calling ITelecomService#silenceRinger", e);
Santos Cordon9eb45932014-06-27 12:28:43 -0700735 }
736 }
737
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700738 /**
739 * Returns whether TTY is supported on this device.
740 *
741 * @hide
742 */
743 @SystemApi
744 public boolean isTtySupported() {
745 try {
746 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700747 return getTelecomService().isTtySupported();
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700748 }
749 } catch (RemoteException e) {
750 Log.e(TAG, "RemoteException attempting to get TTY supported state.", e);
751 }
752 return false;
753 }
754
755 /**
756 * 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 -0700757 * settings and have a wired headset plugged in.
758 * Valid modes are:
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700759 * - {@link TelecomManager#TTY_MODE_OFF}
760 * - {@link TelecomManager#TTY_MODE_FULL}
761 * - {@link TelecomManager#TTY_MODE_HCO}
762 * - {@link TelecomManager#TTY_MODE_VCO}
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700763 * @hide
764 */
765 public int getCurrentTtyMode() {
766 try {
767 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700768 return getTelecomService().getCurrentTtyMode();
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700769 }
770 } catch (RemoteException e) {
771 Log.e(TAG, "RemoteException attempting to get the current TTY mode.", e);
772 }
Evan Charlton10197192014-07-19 15:00:29 -0700773 return TTY_MODE_OFF;
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700774 }
775
Santos Cordon96efb482014-07-19 14:57:05 -0700776 /**
777 * Registers a new incoming call. A {@link ConnectionService} should invoke this method when it
778 * has an incoming call. The specified {@link PhoneAccountHandle} must have been registered
779 * with {@link #registerPhoneAccount} and subsequently enabled by the user within the phone's
780 * settings. Once invoked, this method will cause the system to bind to the
781 * {@link ConnectionService} associated with the {@link PhoneAccountHandle} and request
782 * additional information about the call (See
783 * {@link ConnectionService#onCreateIncomingConnection}) before starting the incoming call UI.
784 *
785 * @param phoneAccount A {@link PhoneAccountHandle} registered with
786 * {@link #registerPhoneAccount}.
787 * @param extras A bundle that will be passed through to
788 * {@link ConnectionService#onCreateIncomingConnection}.
789 */
790 public void addNewIncomingCall(PhoneAccountHandle phoneAccount, Bundle extras) {
791 try {
792 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700793 getTelecomService().addNewIncomingCall(
Santos Cordon96efb482014-07-19 14:57:05 -0700794 phoneAccount, extras == null ? new Bundle() : extras);
795 }
796 } catch (RemoteException e) {
797 Log.e(TAG, "RemoteException adding a new incoming call: " + phoneAccount, e);
798 }
799 }
800
Nancy Chen0eb1e402014-08-21 22:52:29 -0700801 /**
802 * Processes the specified dial string as an MMI code.
803 * MMI codes are any sequence of characters entered into the dialpad that contain a "*" or "#".
804 * Some of these sequences launch special behavior through handled by Telephony.
805 * <p>
806 * Requires that the method-caller be set as the system dialer app.
807 * </p>
808 *
809 * @param dialString The digits to dial.
810 * @return True if the digits were processed as an MMI code, false otherwise.
811 */
812 public boolean handleMmi(String dialString) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700813 ITelecomService service = getTelecomService();
Nancy Chen0eb1e402014-08-21 22:52:29 -0700814 if (service != null) {
815 try {
816 return service.handlePinMmi(dialString);
817 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700818 Log.e(TAG, "Error calling ITelecomService#handlePinMmi", e);
Nancy Chen0eb1e402014-08-21 22:52:29 -0700819 }
820 }
821 return false;
822 }
823
824 /**
825 * Removes the missed-call notification if one is present.
826 * <p>
827 * Requires that the method-caller be set as the system dialer app.
828 * </p>
829 */
830 public void cancelMissedCallsNotification() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700831 ITelecomService service = getTelecomService();
Nancy Chen0eb1e402014-08-21 22:52:29 -0700832 if (service != null) {
833 try {
834 service.cancelMissedCallsNotification();
835 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700836 Log.e(TAG, "Error calling ITelecomService#cancelMissedCallsNotification", e);
Nancy Chen0eb1e402014-08-21 22:52:29 -0700837 }
838 }
839 }
840
841 /**
842 * Brings the in-call screen to the foreground if there is an ongoing call. If there is
843 * currently no ongoing call, then this method does nothing.
844 * <p>
845 * Requires that the method-caller be set as the system dialer app or have the
846 * {@link android.Manifest.permission#READ_PHONE_STATE} permission.
847 * </p>
848 *
849 * @param showDialpad Brings up the in-call dialpad as part of showing the in-call screen.
850 */
851 public void showInCallScreen(boolean showDialpad) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700852 ITelecomService service = getTelecomService();
Nancy Chen0eb1e402014-08-21 22:52:29 -0700853 if (service != null) {
854 try {
855 service.showInCallScreen(showDialpad);
856 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700857 Log.e(TAG, "Error calling ITelecomService#showCallScreen", e);
Nancy Chen0eb1e402014-08-21 22:52:29 -0700858 }
859 }
860 }
861
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700862 private ITelecomService getTelecomService() {
863 return ITelecomService.Stub.asInterface(ServiceManager.getService(Context.TELECOM_SERVICE));
Santos Cordon6c7a3882014-06-25 15:30:08 -0700864 }
Santos Cordon9eb45932014-06-27 12:28:43 -0700865
866 private boolean isServiceConnected() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700867 boolean isConnected = getTelecomService() != null;
Santos Cordon9eb45932014-06-27 12:28:43 -0700868 if (!isConnected) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700869 Log.w(TAG, "Telecom Service not found.");
Santos Cordon9eb45932014-06-27 12:28:43 -0700870 }
871 return isConnected;
872 }
Evan Charlton235c1592014-09-05 15:41:23 +0000873}