blob: c2f89d0bcb2ac614a9aa2c272925da9d5f43c1d4 [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 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -070074 * Optional extra for {@link android.content.Intent#ACTION_CALL} containing a boolean that
75 * determines whether the speakerphone should be automatically turned on for an outgoing call.
Evan Charlton10197192014-07-19 15:00:29 -070076 */
77 public static final String EXTRA_START_CALL_WITH_SPEAKERPHONE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -070078 "android.telecom.extra.START_CALL_WITH_SPEAKERPHONE";
Evan Charlton10197192014-07-19 15:00:29 -070079
80 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -070081 * Optional extra for {@link android.content.Intent#ACTION_CALL} containing an integer that
82 * determines the desired video state for an outgoing call.
Santos Cordon96efb482014-07-19 14:57:05 -070083 * Valid options:
Ihab Awadb19a0bc2014-08-07 19:46:01 -070084 * {@link VideoProfile.VideoState#AUDIO_ONLY},
85 * {@link VideoProfile.VideoState#BIDIRECTIONAL},
86 * {@link VideoProfile.VideoState#RX_ENABLED},
87 * {@link VideoProfile.VideoState#TX_ENABLED}.
Tyler Gunn27d1e252014-08-21 16:38:40 -070088 * @hide
Evan Charlton10197192014-07-19 15:00:29 -070089 */
90 public static final String EXTRA_START_CALL_WITH_VIDEO_STATE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -070091 "android.telecom.extra.START_CALL_WITH_VIDEO_STATE";
Evan Charlton10197192014-07-19 15:00:29 -070092
93 /**
Santos Cordon96efb482014-07-19 14:57:05 -070094 * The extra used with an {@link android.content.Intent#ACTION_CALL} and
95 * {@link android.content.Intent#ACTION_DIAL} {@code Intent} to specify a
96 * {@link PhoneAccountHandle} to use when making the call.
Evan Charlton10197192014-07-19 15:00:29 -070097 * <p class="note">
Santos Cordon96efb482014-07-19 14:57:05 -070098 * Retrieve with {@link android.content.Intent#getParcelableExtra(String)}.
Evan Charlton10197192014-07-19 15:00:29 -070099 */
Evan Charlton6eb262c2014-07-19 18:18:19 -0700100 public static final String EXTRA_PHONE_ACCOUNT_HANDLE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700101 "android.telecom.extra.PHONE_ACCOUNT_HANDLE";
Evan Charlton10197192014-07-19 15:00:29 -0700102
103 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700104 * Optional extra for {@link #ACTION_INCOMING_CALL} containing a {@link Bundle} which contains
105 * metadata about the call. This {@link Bundle} will be returned to the
106 * {@link ConnectionService}.
107 *
108 * @hide
Evan Charlton10197192014-07-19 15:00:29 -0700109 */
110 public static final String EXTRA_INCOMING_CALL_EXTRAS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700111 "android.telecom.extra.INCOMING_CALL_EXTRAS";
Evan Charlton10197192014-07-19 15:00:29 -0700112
113 /**
Nancy Chen10798dc2014-08-08 14:00:25 -0700114 * Optional extra for {@link android.content.Intent#ACTION_CALL} and
115 * {@link android.content.Intent#ACTION_DIAL} {@code Intent} containing a {@link Bundle}
116 * which contains metadata about the call. This {@link Bundle} will be saved into
117 * {@code Call.Details}.
118 *
119 * @hide
120 */
121 public static final String EXTRA_OUTGOING_CALL_EXTRAS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700122 "android.telecom.extra.OUTGOING_CALL_EXTRAS";
Nancy Chen10798dc2014-08-08 14:00:25 -0700123
124 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700125 * Optional extra for {@link android.telephony.TelephonyManager#ACTION_PHONE_STATE_CHANGED}
126 * containing the disconnect code.
Evan Charlton10197192014-07-19 15:00:29 -0700127 */
128 public static final String EXTRA_CALL_DISCONNECT_CAUSE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700129 "android.telecom.extra.CALL_DISCONNECT_CAUSE";
Evan Charlton10197192014-07-19 15:00:29 -0700130
131 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700132 * Optional extra for {@link android.telephony.TelephonyManager#ACTION_PHONE_STATE_CHANGED}
133 * containing the disconnect message.
Evan Charlton10197192014-07-19 15:00:29 -0700134 */
135 public static final String EXTRA_CALL_DISCONNECT_MESSAGE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700136 "android.telecom.extra.CALL_DISCONNECT_MESSAGE";
Evan Charlton10197192014-07-19 15:00:29 -0700137
138 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700139 * Optional extra for {@link android.telephony.TelephonyManager#ACTION_PHONE_STATE_CHANGED}
140 * containing the component name of the associated connection service.
Evan Charlton10197192014-07-19 15:00:29 -0700141 */
142 public static final String EXTRA_CONNECTION_SERVICE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700143 "android.telecom.extra.CONNECTION_SERVICE";
Evan Charlton10197192014-07-19 15:00:29 -0700144
145 /**
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700146 * An optional {@link android.content.Intent#ACTION_CALL} intent extra denoting the
147 * package name of the app specifying an alternative gateway for the call.
148 * The value is a string.
149 *
150 * (The following comment corresponds to the all GATEWAY_* extras)
151 * An app which sends the {@link android.content.Intent#ACTION_CALL} intent can specify an
152 * alternative address to dial which is different from the one specified and displayed to
153 * the user. This alternative address is referred to as the gateway address.
154 */
155 public static final String GATEWAY_PROVIDER_PACKAGE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700156 "android.telecom.extra.GATEWAY_PROVIDER_PACKAGE";
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700157
158 /**
159 * An optional {@link android.content.Intent#ACTION_CALL} intent extra corresponding to the
160 * original address to dial for the call. This is used when an alternative gateway address is
161 * provided to recall the original address.
162 * The value is a {@link android.net.Uri}.
163 *
164 * (See {@link #GATEWAY_PROVIDER_PACKAGE} for details)
165 */
166 public static final String GATEWAY_ORIGINAL_ADDRESS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700167 "android.telecom.extra.GATEWAY_ORIGINAL_ADDRESS";
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700168
169 /**
Evan Charlton10197192014-07-19 15:00:29 -0700170 * The number which the party on the other side of the line will see (and use to return the
171 * call).
172 * <p>
Santos Cordon96efb482014-07-19 14:57:05 -0700173 * {@link ConnectionService}s which interact with {@link RemoteConnection}s should only populate
174 * this if the {@link android.telephony.TelephonyManager#getLine1Number()} value, as that is the
175 * user's expected caller ID.
Evan Charlton10197192014-07-19 15:00:29 -0700176 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700177 public static final String EXTRA_CALL_BACK_NUMBER = "android.telecom.extra.CALL_BACK_NUMBER";
Evan Charlton10197192014-07-19 15:00:29 -0700178
179 /**
180 * The dual tone multi-frequency signaling character sent to indicate the dialing system should
181 * pause for a predefined period.
182 */
183 public static final char DTMF_CHARACTER_PAUSE = ',';
184
185 /**
186 * The dual-tone multi-frequency signaling character sent to indicate the dialing system should
187 * wait for user confirmation before proceeding.
188 */
189 public static final char DTMF_CHARACTER_WAIT = ';';
190
191 /**
192 * TTY (teletypewriter) mode is off.
193 *
194 * @hide
195 */
196 public static final int TTY_MODE_OFF = 0;
197
198 /**
199 * TTY (teletypewriter) mode is on. The speaker is off and the microphone is muted. The user
200 * will communicate with the remote party by sending and receiving text messages.
201 *
202 * @hide
203 */
204 public static final int TTY_MODE_FULL = 1;
205
206 /**
207 * TTY (teletypewriter) mode is in hearing carryover mode (HCO). The microphone is muted but the
208 * speaker is on. The user will communicate with the remote party by sending text messages and
209 * hearing an audible reply.
210 *
211 * @hide
212 */
213 public static final int TTY_MODE_HCO = 2;
214
215 /**
216 * TTY (teletypewriter) mode is in voice carryover mode (VCO). The speaker is off but the
217 * microphone is still on. User will communicate with the remote party by speaking and receiving
218 * text message replies.
219 *
220 * @hide
221 */
222 public static final int TTY_MODE_VCO = 3;
223
224 /**
225 * Broadcast intent action indicating that the current TTY mode has changed. An intent extra
226 * provides this state as an int.
Evan Charlton10197192014-07-19 15:00:29 -0700227 *
Santos Cordon96efb482014-07-19 14:57:05 -0700228 * @see #EXTRA_CURRENT_TTY_MODE
Evan Charlton10197192014-07-19 15:00:29 -0700229 * @hide
230 */
231 public static final String ACTION_CURRENT_TTY_MODE_CHANGED =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700232 "android.telecom.action.CURRENT_TTY_MODE_CHANGED";
Evan Charlton10197192014-07-19 15:00:29 -0700233
234 /**
235 * The lookup key for an int that indicates the current TTY mode.
236 * Valid modes are:
237 * - {@link #TTY_MODE_OFF}
238 * - {@link #TTY_MODE_FULL}
239 * - {@link #TTY_MODE_HCO}
240 * - {@link #TTY_MODE_VCO}
241 *
242 * @hide
243 */
244 public static final String EXTRA_CURRENT_TTY_MODE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700245 "android.telecom.intent.extra.CURRENT_TTY_MODE";
Evan Charlton10197192014-07-19 15:00:29 -0700246
247 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700248 * Broadcast intent action indicating that the TTY preferred operating mode has changed. An
249 * intent extra provides the new mode as an int.
Evan Charlton10197192014-07-19 15:00:29 -0700250 *
Santos Cordon96efb482014-07-19 14:57:05 -0700251 * @see #EXTRA_TTY_PREFERRED_MODE
Evan Charlton10197192014-07-19 15:00:29 -0700252 * @hide
253 */
254 public static final String ACTION_TTY_PREFERRED_MODE_CHANGED =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700255 "android.telecom.action.TTY_PREFERRED_MODE_CHANGED";
Evan Charlton10197192014-07-19 15:00:29 -0700256
257 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700258 * The lookup key for an int that indicates preferred TTY mode. Valid modes are: -
259 * {@link #TTY_MODE_OFF} - {@link #TTY_MODE_FULL} - {@link #TTY_MODE_HCO} -
260 * {@link #TTY_MODE_VCO}
Evan Charlton10197192014-07-19 15:00:29 -0700261 *
262 * @hide
263 */
264 public static final String EXTRA_TTY_PREFERRED_MODE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700265 "android.telecom.intent.extra.TTY_PREFERRED";
Evan Charlton10197192014-07-19 15:00:29 -0700266
Nancy Chen9d568c02014-09-08 14:17:59 -0700267 /**
268 * The following 4 constants define how properties such as phone numbers and names are
269 * displayed to the user.
270 */
271
272 /** Property is displayed normally. */
273 public static final int PRESENTATION_ALLOWED = 1;
274
275 /** Property was blocked. */
276 public static final int PRESENTATION_RESTRICTED = 2;
277
278 /** Presentation was not specified or is unknown. */
279 public static final int PRESENTATION_UNKNOWN = 3;
280
281 /** Property should be displayed as a pay phone. */
282 public static final int PRESENTATION_PAYPHONE = 4;
283
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700284 private static final String TAG = "TelecomManager";
Yorke Leeb4ce1432014-06-09 13:53:23 -0700285
286 private final Context mContext;
Yorke Leeb4ce1432014-06-09 13:53:23 -0700287
Santos Cordon6c7a3882014-06-25 15:30:08 -0700288 /**
289 * @hide
290 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700291 public static TelecomManager from(Context context) {
292 return (TelecomManager) context.getSystemService(Context.TELECOM_SERVICE);
Yorke Leeb4ce1432014-06-09 13:53:23 -0700293 }
Santos Cordon6c7a3882014-06-25 15:30:08 -0700294
295 /**
296 * @hide
297 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700298 public TelecomManager(Context context) {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700299 Context appContext = context.getApplicationContext();
300 if (appContext != null) {
301 mContext = appContext;
302 } else {
303 mContext = context;
304 }
305 }
306
307 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700308 * Return the {@link PhoneAccount} which is the user-chosen default for making outgoing phone
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700309 * calls with a specified URI scheme. This {@code PhoneAccount} will always be a member of the
Nancy Chen210ef032014-09-15 17:58:42 -0700310 * list which is returned from calling {@link #getCallCapablePhoneAccounts()}.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700311 * <p>
Santos Cordon96efb482014-07-19 14:57:05 -0700312 * Apps must be prepared for this method to return {@code null}, indicating that there currently
313 * exists no user-chosen default {@code PhoneAccount}. In this case, apps wishing to initiate a
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700314 * phone call must either create their {@link android.content.Intent#ACTION_CALL} or
Santos Cordon96efb482014-07-19 14:57:05 -0700315 * {@link android.content.Intent#ACTION_DIAL} {@code Intent} with no
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700316 * {@link TelecomManager#EXTRA_PHONE_ACCOUNT_HANDLE}, or present the user with an affordance to
Nancy Chen210ef032014-09-15 17:58:42 -0700317 * select one of the elements of {@link #getCallCapablePhoneAccounts()}.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700318 * <p>
319 * An {@link android.content.Intent#ACTION_CALL} or {@link android.content.Intent#ACTION_DIAL}
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700320 * {@code Intent} with no {@link TelecomManager#EXTRA_PHONE_ACCOUNT_HANDLE} is valid, and
Evan Charlton6eb262c2014-07-19 18:18:19 -0700321 * subsequent steps in the phone call flow are responsible for presenting the user with an
Evan Charlton8c8a0622014-07-20 12:31:00 -0700322 * affordance, if necessary, to choose a {@code PhoneAccount}.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700323 *
324 * @param uriScheme The URI scheme.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700325 */
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700326 public PhoneAccountHandle getDefaultOutgoingPhoneAccount(String uriScheme) {
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700327 try {
328 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700329 return getTelecomService().getDefaultOutgoingPhoneAccount(uriScheme);
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700330 }
331 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700332 Log.e(TAG, "Error calling ITelecomService#getDefaultOutgoingPhoneAccount", e);
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700333 }
334 return null;
335 }
336
337 /**
Andrew Leed4abbfb2014-09-03 14:58:27 -0700338 * Return the {@link PhoneAccount} which is the user-chosen default for making outgoing phone
339 * calls. This {@code PhoneAccount} will always be a member of the list which is returned from
Nancy Chen210ef032014-09-15 17:58:42 -0700340 * calling {@link #getCallCapablePhoneAccounts()}
Andrew Leed4abbfb2014-09-03 14:58:27 -0700341 *
342 * Apps must be prepared for this method to return {@code null}, indicating that there currently
343 * exists no user-chosen default {@code PhoneAccount}.
344 *
345 * @return The user outgoing phone account selected by the user.
346 * @hide
347 */
348 public PhoneAccountHandle getUserSelectedOutgoingPhoneAccount() {
349 try {
350 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700351 return getTelecomService().getUserSelectedOutgoingPhoneAccount();
Andrew Leed4abbfb2014-09-03 14:58:27 -0700352 }
353 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700354 Log.e(TAG, "Error calling ITelecomService#getUserSelectedOutgoingPhoneAccount", e);
Andrew Leed4abbfb2014-09-03 14:58:27 -0700355 }
356 return null;
357 }
358
359 /**
Andrew Lee59cac3a2014-08-28 16:50:10 -0700360 * Sets the default account for making outgoing phone calls.
361 * @hide
362 */
Andrew Leed4abbfb2014-09-03 14:58:27 -0700363 public void setUserSelectedOutgoingPhoneAccount(PhoneAccountHandle accountHandle) {
Andrew Lee59cac3a2014-08-28 16:50:10 -0700364 try {
365 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700366 getTelecomService().setUserSelectedOutgoingPhoneAccount(accountHandle);
Andrew Lee59cac3a2014-08-28 16:50:10 -0700367 }
368 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700369 Log.e(TAG, "Error calling ITelecomService#setUserSelectedOutgoingPhoneAccount");
Andrew Lee59cac3a2014-08-28 16:50:10 -0700370 }
371 }
372
373 /**
Nancy Chen210ef032014-09-15 17:58:42 -0700374 * Return a list of {@link PhoneAccountHandle}s which can be used to make and receive phone
375 * calls.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700376 *
Evan Charlton6eb262c2014-07-19 18:18:19 -0700377 * @see #EXTRA_PHONE_ACCOUNT_HANDLE
378 * @return A list of {@code PhoneAccountHandle} objects.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700379 */
Nancy Chen210ef032014-09-15 17:58:42 -0700380 public List<PhoneAccountHandle> getCallCapablePhoneAccounts() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700381 try {
382 if (isServiceConnected()) {
Nancy Chen210ef032014-09-15 17:58:42 -0700383 return getTelecomService().getCallCapablePhoneAccounts();
Ihab Awad807fe0a2014-07-09 12:30:52 -0700384 }
385 } catch (RemoteException e) {
Nancy Chen210ef032014-09-15 17:58:42 -0700386 Log.e(TAG, "Error calling ITelecomService#getCallCapablePhoneAccounts", e);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700387 }
Jay Shrauner7746a942014-08-26 12:15:15 -0700388 return new ArrayList<>();
Ihab Awad807fe0a2014-07-09 12:30:52 -0700389 }
390
391 /**
Andrew Lee59cac3a2014-08-28 16:50:10 -0700392 * Returns the current SIM call manager. Apps must be prepared for this method to return
393 * {@code null}, indicating that there currently exists no user-chosen default
394 * {@code PhoneAccount}.
395 * @return The phone account handle of the current sim call manager.
396 * @hide
397 */
398 public PhoneAccountHandle getSimCallManager() {
399 try {
400 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700401 return getTelecomService().getSimCallManager();
Andrew Lee59cac3a2014-08-28 16:50:10 -0700402 }
403 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700404 Log.e(TAG, "Error calling ITelecomService#getSimCallManager");
Andrew Lee59cac3a2014-08-28 16:50:10 -0700405 }
406 return null;
407 }
408
409 /**
410 * Sets the SIM call manager to the specified phone account.
411 * @param accountHandle The phone account handle of the account to set as the sim call manager.
412 * @hide
413 */
414 public void setSimCallManager(PhoneAccountHandle accountHandle) {
415 try {
416 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700417 getTelecomService().setSimCallManager(accountHandle);
Andrew Lee59cac3a2014-08-28 16:50:10 -0700418 }
419 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700420 Log.e(TAG, "Error calling ITelecomService#setSimCallManager");
Andrew Lee59cac3a2014-08-28 16:50:10 -0700421 }
422 }
423
424 /**
425 * Returns the list of registered SIM call managers.
426 * @return List of registered SIM call managers.
427 * @hide
428 */
429 public List<PhoneAccountHandle> getSimCallManagers() {
430 try {
431 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700432 return getTelecomService().getSimCallManagers();
Andrew Lee59cac3a2014-08-28 16:50:10 -0700433 }
434 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700435 Log.e(TAG, "Error calling ITelecomService#getSimCallManagers");
Andrew Lee59cac3a2014-08-28 16:50:10 -0700436 }
437 return new ArrayList<>();
438 }
439
440 /**
Evan Charltoneb0a8d52014-09-04 12:03:34 -0700441 * Returns the current connection manager. Apps must be prepared for this method to return
442 * {@code null}, indicating that there currently exists no user-chosen default
443 * {@code PhoneAccount}.
444 *
445 * @return The phone account handle of the current connection manager.
446 */
447 public PhoneAccountHandle getConnectionManager() {
448 return getSimCallManager();
449 }
450
451 /**
Nancy Chen210ef032014-09-15 17:58:42 -0700452 * Returns a list of the {@link PhoneAccountHandle}s which can be used to make and receive phone
453 * calls which support the specified URI scheme.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700454 * <P>
455 * For example, invoking with {@code "tel"} will find all {@link PhoneAccountHandle}s which
456 * support telephone calls (e.g. URIs such as {@code tel:555-555-1212}). Invoking with
457 * {@code "sip"} will find all {@link PhoneAccountHandle}s which support SIP calls (e.g. URIs
458 * such as {@code sip:example@sipexample.com}).
459 *
460 * @param uriScheme The URI scheme.
461 * @return A list of {@code PhoneAccountHandle} objects supporting the URI scheme.
462 */
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
474 /**
Nancy Chen210ef032014-09-15 17:58:42 -0700475 * Determine whether the device has more than one account registered that can make and receive
476 * phone calls.
Nancy Chen60801182014-07-22 16:56:49 -0700477 *
Nancy Chen210ef032014-09-15 17:58:42 -0700478 * @return {@code true} if the device has more than one account registered and {@code false}
479 * otherwise.
Nancy Chen60801182014-07-22 16:56:49 -0700480 */
Nancy Chen210ef032014-09-15 17:58:42 -0700481 public boolean hasMultipleCallCapableAccounts() {
482 return getCallCapablePhoneAccounts().size() > 1;
Nancy Chen60801182014-07-22 16:56:49 -0700483 }
484
485 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700486 * Return the {@link PhoneAccount} for a specified {@link PhoneAccountHandle}. Object includes
487 * resources which can be used in a user interface.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700488 *
Evan Charlton6eb262c2014-07-19 18:18:19 -0700489 * @param account The {@link PhoneAccountHandle}.
Evan Charlton8c8a0622014-07-20 12:31:00 -0700490 * @return The {@link PhoneAccount} object.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700491 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700492 public PhoneAccount getPhoneAccount(PhoneAccountHandle account) {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700493 try {
494 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700495 return getTelecomService().getPhoneAccount(account);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700496 }
497 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700498 Log.e(TAG, "Error calling ITelecomService#getPhoneAccount", e);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700499 }
500 return null;
501 }
502
503 /**
Nancy Chen210ef032014-09-15 17:58:42 -0700504 * Returns a count of all {@link PhoneAccount}s.
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700505 *
Nancy Chen210ef032014-09-15 17:58:42 -0700506 * @return The count of {@link PhoneAccount}s.
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700507 * @hide
508 */
509 @SystemApi
510 public int getAllPhoneAccountsCount() {
511 try {
512 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700513 return getTelecomService().getAllPhoneAccountsCount();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700514 }
515 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700516 Log.e(TAG, "Error calling ITelecomService#getAllPhoneAccountsCount", e);
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700517 }
518 return 0;
519 }
520
521 /**
522 * Returns a list of all {@link PhoneAccount}s.
523 *
524 * @return All {@link PhoneAccount}s.
525 * @hide
526 */
527 @SystemApi
528 public List<PhoneAccount> getAllPhoneAccounts() {
529 try {
530 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700531 return getTelecomService().getAllPhoneAccounts();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700532 }
533 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700534 Log.e(TAG, "Error calling ITelecomService#getAllPhoneAccounts", e);
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700535 }
536 return Collections.EMPTY_LIST;
537 }
538
539 /**
540 * Returns a list of all {@link PhoneAccountHandle}s.
541 *
542 * @return All {@link PhoneAccountHandle}s.
543 * @hide
544 */
545 @SystemApi
546 public List<PhoneAccountHandle> getAllPhoneAccountHandles() {
547 try {
548 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700549 return getTelecomService().getAllPhoneAccountHandles();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700550 }
551 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700552 Log.e(TAG, "Error calling ITelecomService#getAllPhoneAccountHandles", e);
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700553 }
554 return Collections.EMPTY_LIST;
555 }
556
557 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700558 * Register a {@link PhoneAccount} for use by the system.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700559 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700560 * @param account The complete {@link PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700561 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700562 public void registerPhoneAccount(PhoneAccount account) {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700563 try {
564 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700565 getTelecomService().registerPhoneAccount(account);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700566 }
567 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700568 Log.e(TAG, "Error calling ITelecomService#registerPhoneAccount", e);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700569 }
570 }
571
572 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700573 * Remove a {@link PhoneAccount} registration from the system.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700574 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700575 * @param accountHandle A {@link PhoneAccountHandle} for the {@link PhoneAccount} to unregister.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700576 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700577 public void unregisterPhoneAccount(PhoneAccountHandle accountHandle) {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700578 try {
579 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700580 getTelecomService().unregisterPhoneAccount(accountHandle);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700581 }
582 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700583 Log.e(TAG, "Error calling ITelecomService#unregisterPhoneAccount", e);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700584 }
585 }
586
587 /**
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700588 * Remove all Accounts that belong to the calling package from the system.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700589 */
590 @SystemApi
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700591 public void clearAccounts() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700592 try {
593 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700594 getTelecomService().clearAccounts(mContext.getPackageName());
Ihab Awad807fe0a2014-07-09 12:30:52 -0700595 }
596 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700597 Log.e(TAG, "Error calling ITelecomService#clearAccounts", e);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700598 }
599 }
600
601 /**
602 * @hide
603 */
Santos Cordon6c7a3882014-06-25 15:30:08 -0700604 @SystemApi
605 public ComponentName getDefaultPhoneApp() {
606 try {
Santos Cordon9eb45932014-06-27 12:28:43 -0700607 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700608 return getTelecomService().getDefaultPhoneApp();
Santos Cordon9eb45932014-06-27 12:28:43 -0700609 }
Santos Cordon6c7a3882014-06-25 15:30:08 -0700610 } catch (RemoteException e) {
611 Log.e(TAG, "RemoteException attempting to get the default phone app.", e);
612 }
613 return null;
614 }
615
Santos Cordon9eb45932014-06-27 12:28:43 -0700616 /**
617 * Returns whether there is an ongoing phone call (can be in dialing, ringing, active or holding
618 * states).
Nancy Chen0eb1e402014-08-21 22:52:29 -0700619 * <p>
620 * Requires permission: {@link android.Manifest.permission#READ_PHONE_STATE}
621 * </p>
Santos Cordon9eb45932014-06-27 12:28:43 -0700622 */
623 @SystemApi
Nancy Chen0eb1e402014-08-21 22:52:29 -0700624 public boolean isInCall() {
Santos Cordon9eb45932014-06-27 12:28:43 -0700625 try {
626 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700627 return getTelecomService().isInCall();
Santos Cordon9eb45932014-06-27 12:28:43 -0700628 }
629 } catch (RemoteException e) {
Yorke Lee2ae312e2014-09-12 17:58:48 -0700630 Log.e(TAG, "RemoteException calling isInCall().", e);
Santos Cordon9eb45932014-06-27 12:28:43 -0700631 }
632 return false;
633 }
634
635 /**
Yorke Lee2ae312e2014-09-12 17:58:48 -0700636 * Returns one of the following constants that represents the current state of Telecom:
637 *
638 * {@link TelephonyManager#CALL_STATE_RINGING}
639 * {@link TelephonyManager#CALL_STATE_OFFHOOK}
640 * {@link TelephonyManager#CALL_STATE_IDLE}
641 *
642 * <p>
643 * Requires permission: {@link android.Manifest.permission#READ_PHONE_STATE}
644 * </p>
645 * @hide
646 */
647 @SystemApi
648 public int getCallState() {
649 try {
650 if (isServiceConnected()) {
651 return getTelecomService().getCallState();
652 }
653 } catch (RemoteException e) {
654 Log.d(TAG, "RemoteException calling getCallState().", e);
655 }
656 return TelephonyManager.CALL_STATE_IDLE;
657 }
658
659 /**
Santos Cordon9eb45932014-06-27 12:28:43 -0700660 * Returns whether there currently exists is a ringing incoming-call.
661 *
662 * @hide
663 */
664 @SystemApi
665 public boolean isRinging() {
666 try {
667 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700668 return getTelecomService().isRinging();
Santos Cordon9eb45932014-06-27 12:28:43 -0700669 }
670 } catch (RemoteException e) {
671 Log.e(TAG, "RemoteException attempting to get ringing state of phone app.", e);
672 }
673 return false;
674 }
675
676 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700677 * Ends an ongoing call.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700678 * TODO: L-release - need to convert all invocations of ITelecomService#endCall to use this
Santos Cordon96efb482014-07-19 14:57:05 -0700679 * method (clockwork & gearhead).
Santos Cordon9eb45932014-06-27 12:28:43 -0700680 * @hide
681 */
682 @SystemApi
683 public boolean endCall() {
684 try {
685 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700686 return getTelecomService().endCall();
Santos Cordon9eb45932014-06-27 12:28:43 -0700687 }
688 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700689 Log.e(TAG, "Error calling ITelecomService#endCall", e);
Santos Cordon9eb45932014-06-27 12:28:43 -0700690 }
691 return false;
692 }
693
694 /**
695 * If there is a ringing incoming call, this method accepts the call on behalf of the user.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700696 * TODO: L-release - need to convert all invocation of ITelecmmService#answerRingingCall to use
Santos Cordon96efb482014-07-19 14:57:05 -0700697 * this method (clockwork & gearhead).
Santos Cordon9eb45932014-06-27 12:28:43 -0700698 *
699 * @hide
700 */
701 @SystemApi
702 public void acceptRingingCall() {
703 try {
704 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700705 getTelecomService().acceptRingingCall();
Santos Cordon9eb45932014-06-27 12:28:43 -0700706 }
707 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700708 Log.e(TAG, "Error calling ITelecomService#acceptRingingCall", e);
Santos Cordon9eb45932014-06-27 12:28:43 -0700709 }
710 }
711
712 /**
713 * Silences the ringer if a ringing call exists.
714 *
715 * @hide
716 */
717 @SystemApi
718 public void silenceRinger() {
719 try {
720 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700721 getTelecomService().silenceRinger();
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#silenceRinger", e);
Santos Cordon9eb45932014-06-27 12:28:43 -0700725 }
726 }
727
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700728 /**
729 * Returns whether TTY is supported on this device.
730 *
731 * @hide
732 */
733 @SystemApi
734 public boolean isTtySupported() {
735 try {
736 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700737 return getTelecomService().isTtySupported();
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700738 }
739 } catch (RemoteException e) {
740 Log.e(TAG, "RemoteException attempting to get TTY supported state.", e);
741 }
742 return false;
743 }
744
745 /**
746 * 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 -0700747 * settings and have a wired headset plugged in.
748 * Valid modes are:
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700749 * - {@link TelecomManager#TTY_MODE_OFF}
750 * - {@link TelecomManager#TTY_MODE_FULL}
751 * - {@link TelecomManager#TTY_MODE_HCO}
752 * - {@link TelecomManager#TTY_MODE_VCO}
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700753 * @hide
754 */
755 public int getCurrentTtyMode() {
756 try {
757 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700758 return getTelecomService().getCurrentTtyMode();
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700759 }
760 } catch (RemoteException e) {
761 Log.e(TAG, "RemoteException attempting to get the current TTY mode.", e);
762 }
Evan Charlton10197192014-07-19 15:00:29 -0700763 return TTY_MODE_OFF;
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700764 }
765
Santos Cordon96efb482014-07-19 14:57:05 -0700766 /**
767 * Registers a new incoming call. A {@link ConnectionService} should invoke this method when it
768 * has an incoming call. The specified {@link PhoneAccountHandle} must have been registered
Nancy Chen210ef032014-09-15 17:58:42 -0700769 * with {@link #registerPhoneAccount}. Once invoked, this method will cause the system to bind
770 * to the {@link ConnectionService} associated with the {@link PhoneAccountHandle} and request
Santos Cordon96efb482014-07-19 14:57:05 -0700771 * additional information about the call (See
772 * {@link ConnectionService#onCreateIncomingConnection}) before starting the incoming call UI.
773 *
774 * @param phoneAccount A {@link PhoneAccountHandle} registered with
775 * {@link #registerPhoneAccount}.
776 * @param extras A bundle that will be passed through to
777 * {@link ConnectionService#onCreateIncomingConnection}.
778 */
779 public void addNewIncomingCall(PhoneAccountHandle phoneAccount, Bundle extras) {
780 try {
781 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700782 getTelecomService().addNewIncomingCall(
Santos Cordon96efb482014-07-19 14:57:05 -0700783 phoneAccount, extras == null ? new Bundle() : extras);
784 }
785 } catch (RemoteException e) {
786 Log.e(TAG, "RemoteException adding a new incoming call: " + phoneAccount, e);
787 }
788 }
789
Nancy Chen0eb1e402014-08-21 22:52:29 -0700790 /**
791 * Processes the specified dial string as an MMI code.
792 * MMI codes are any sequence of characters entered into the dialpad that contain a "*" or "#".
793 * Some of these sequences launch special behavior through handled by Telephony.
794 * <p>
795 * Requires that the method-caller be set as the system dialer app.
796 * </p>
797 *
798 * @param dialString The digits to dial.
799 * @return True if the digits were processed as an MMI code, false otherwise.
800 */
801 public boolean handleMmi(String dialString) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700802 ITelecomService service = getTelecomService();
Nancy Chen0eb1e402014-08-21 22:52:29 -0700803 if (service != null) {
804 try {
805 return service.handlePinMmi(dialString);
806 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700807 Log.e(TAG, "Error calling ITelecomService#handlePinMmi", e);
Nancy Chen0eb1e402014-08-21 22:52:29 -0700808 }
809 }
810 return false;
811 }
812
813 /**
814 * Removes the missed-call notification if one is present.
815 * <p>
816 * Requires that the method-caller be set as the system dialer app.
817 * </p>
818 */
819 public void cancelMissedCallsNotification() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700820 ITelecomService service = getTelecomService();
Nancy Chen0eb1e402014-08-21 22:52:29 -0700821 if (service != null) {
822 try {
823 service.cancelMissedCallsNotification();
824 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700825 Log.e(TAG, "Error calling ITelecomService#cancelMissedCallsNotification", e);
Nancy Chen0eb1e402014-08-21 22:52:29 -0700826 }
827 }
828 }
829
830 /**
831 * Brings the in-call screen to the foreground if there is an ongoing call. If there is
832 * currently no ongoing call, then this method does nothing.
833 * <p>
834 * Requires that the method-caller be set as the system dialer app or have the
835 * {@link android.Manifest.permission#READ_PHONE_STATE} permission.
836 * </p>
837 *
838 * @param showDialpad Brings up the in-call dialpad as part of showing the in-call screen.
839 */
840 public void showInCallScreen(boolean showDialpad) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700841 ITelecomService service = getTelecomService();
Nancy Chen0eb1e402014-08-21 22:52:29 -0700842 if (service != null) {
843 try {
844 service.showInCallScreen(showDialpad);
845 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700846 Log.e(TAG, "Error calling ITelecomService#showCallScreen", e);
Nancy Chen0eb1e402014-08-21 22:52:29 -0700847 }
848 }
849 }
850
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700851 private ITelecomService getTelecomService() {
852 return ITelecomService.Stub.asInterface(ServiceManager.getService(Context.TELECOM_SERVICE));
Santos Cordon6c7a3882014-06-25 15:30:08 -0700853 }
Santos Cordon9eb45932014-06-27 12:28:43 -0700854
855 private boolean isServiceConnected() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700856 boolean isConnected = getTelecomService() != null;
Santos Cordon9eb45932014-06-27 12:28:43 -0700857 if (!isConnected) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700858 Log.w(TAG, "Telecom Service not found.");
Santos Cordon9eb45932014-06-27 12:28:43 -0700859 }
860 return isConnected;
861 }
Evan Charlton235c1592014-09-05 15:41:23 +0000862}