blob: e87615ef450286b18867aa1491002702b9147302 [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 /**
Yorke Leec3cf9822014-10-02 09:38:39 -070054 * Similar to {@link #ACTION_INCOMING_CALL}, but is used only by Telephony to add a new
55 * sim-initiated MO call for carrier testing.
56 * @hide
57 */
58 public static final String ACTION_NEW_UNKNOWN_CALL = "android.telecom.action.NEW_UNKNOWN_CALL";
59
60 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -070061 * The {@link android.content.Intent} action used to configure a
Tyler Gunnef9f6f92014-09-12 22:16:17 -070062 * {@link android.telecom.ConnectionService}.
Tyler Gunn711d876fd2014-09-19 11:17:02 -070063 * @hide
Evan Charlton10197192014-07-19 15:00:29 -070064 */
65 public static final String ACTION_CONNECTION_SERVICE_CONFIGURE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -070066 "android.telecom.action.CONNECTION_SERVICE_CONFIGURE";
Evan Charlton10197192014-07-19 15:00:29 -070067
68 /**
Yorke Lee3818a892014-07-21 15:57:17 -070069 * The {@link android.content.Intent} action used to show the call settings page.
70 */
71 public static final String ACTION_SHOW_CALL_SETTINGS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -070072 "android.telecom.action.SHOW_CALL_SETTINGS";
Yorke Lee3818a892014-07-21 15:57:17 -070073
74 /**
Evan Charlton6d8604f2014-09-04 12:38:17 -070075 * The {@link android.content.Intent} action used to show the settings page used to configure
76 * {@link PhoneAccount} preferences.
Tyler Gunn711d876fd2014-09-19 11:17:02 -070077 * @hide
Evan Charlton6d8604f2014-09-04 12:38:17 -070078 */
79 public static final String ACTION_CHANGE_PHONE_ACCOUNTS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -070080 "android.telecom.action.CHANGE_PHONE_ACCOUNTS";
Evan Charlton6d8604f2014-09-04 12:38:17 -070081
82 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -070083 * Optional extra for {@link android.content.Intent#ACTION_CALL} containing a boolean that
84 * determines whether the speakerphone should be automatically turned on for an outgoing call.
Evan Charlton10197192014-07-19 15:00:29 -070085 */
86 public static final String EXTRA_START_CALL_WITH_SPEAKERPHONE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -070087 "android.telecom.extra.START_CALL_WITH_SPEAKERPHONE";
Evan Charlton10197192014-07-19 15:00:29 -070088
89 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -070090 * Optional extra for {@link android.content.Intent#ACTION_CALL} containing an integer that
91 * determines the desired video state for an outgoing call.
Santos Cordon96efb482014-07-19 14:57:05 -070092 * Valid options:
Ihab Awadb19a0bc2014-08-07 19:46:01 -070093 * {@link VideoProfile.VideoState#AUDIO_ONLY},
94 * {@link VideoProfile.VideoState#BIDIRECTIONAL},
95 * {@link VideoProfile.VideoState#RX_ENABLED},
96 * {@link VideoProfile.VideoState#TX_ENABLED}.
Tyler Gunn27d1e252014-08-21 16:38:40 -070097 * @hide
Evan Charlton10197192014-07-19 15:00:29 -070098 */
99 public static final String EXTRA_START_CALL_WITH_VIDEO_STATE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700100 "android.telecom.extra.START_CALL_WITH_VIDEO_STATE";
Evan Charlton10197192014-07-19 15:00:29 -0700101
102 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700103 * The extra used with an {@link android.content.Intent#ACTION_CALL} and
104 * {@link android.content.Intent#ACTION_DIAL} {@code Intent} to specify a
105 * {@link PhoneAccountHandle} to use when making the call.
Evan Charlton10197192014-07-19 15:00:29 -0700106 * <p class="note">
Santos Cordon96efb482014-07-19 14:57:05 -0700107 * Retrieve with {@link android.content.Intent#getParcelableExtra(String)}.
Tyler Gunn711d876fd2014-09-19 11:17:02 -0700108 * @hide
Evan Charlton10197192014-07-19 15:00:29 -0700109 */
Evan Charlton6eb262c2014-07-19 18:18:19 -0700110 public static final String EXTRA_PHONE_ACCOUNT_HANDLE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700111 "android.telecom.extra.PHONE_ACCOUNT_HANDLE";
Evan Charlton10197192014-07-19 15:00:29 -0700112
113 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700114 * Optional extra for {@link #ACTION_INCOMING_CALL} containing a {@link Bundle} which contains
115 * metadata about the call. This {@link Bundle} will be returned to the
116 * {@link ConnectionService}.
117 *
118 * @hide
Evan Charlton10197192014-07-19 15:00:29 -0700119 */
120 public static final String EXTRA_INCOMING_CALL_EXTRAS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700121 "android.telecom.extra.INCOMING_CALL_EXTRAS";
Evan Charlton10197192014-07-19 15:00:29 -0700122
123 /**
Nancy Chen10798dc2014-08-08 14:00:25 -0700124 * Optional extra for {@link android.content.Intent#ACTION_CALL} and
125 * {@link android.content.Intent#ACTION_DIAL} {@code Intent} containing a {@link Bundle}
126 * which contains metadata about the call. This {@link Bundle} will be saved into
127 * {@code Call.Details}.
128 *
129 * @hide
130 */
131 public static final String EXTRA_OUTGOING_CALL_EXTRAS =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700132 "android.telecom.extra.OUTGOING_CALL_EXTRAS";
Nancy Chen10798dc2014-08-08 14:00:25 -0700133
134 /**
Yorke Leec3cf9822014-10-02 09:38:39 -0700135 * @hide
136 */
137 public static final String EXTRA_UNKNOWN_CALL_HANDLE =
138 "android.telecom.extra.UNKNOWN_CALL_HANDLE";
139
140 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700141 * Optional extra for {@link android.telephony.TelephonyManager#ACTION_PHONE_STATE_CHANGED}
142 * containing the disconnect code.
Evan Charlton10197192014-07-19 15:00:29 -0700143 */
144 public static final String EXTRA_CALL_DISCONNECT_CAUSE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700145 "android.telecom.extra.CALL_DISCONNECT_CAUSE";
Evan Charlton10197192014-07-19 15:00:29 -0700146
147 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700148 * Optional extra for {@link android.telephony.TelephonyManager#ACTION_PHONE_STATE_CHANGED}
149 * containing the disconnect message.
Evan Charlton10197192014-07-19 15:00:29 -0700150 */
151 public static final String EXTRA_CALL_DISCONNECT_MESSAGE =
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700152 "android.telecom.extra.CALL_DISCONNECT_MESSAGE";
Evan Charlton10197192014-07-19 15:00:29 -0700153
154 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700155 * Optional extra for {@link android.telephony.TelephonyManager#ACTION_PHONE_STATE_CHANGED}
156 * containing the component name of the associated connection service.
Tyler Gunn711d876fd2014-09-19 11:17:02 -0700157 * @hide
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.
Tyler Gunn711d876fd2014-09-19 11:17:02 -0700193 * @hide
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
Nancy Chen513c8922014-09-17 14:47:20 -0700327 * calls with a specified URI scheme.
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
Nancy Chen513c8922014-09-17 14:47:20 -0700330 * exists no user-chosen default {@code PhoneAccount}.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700331 * <p>
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700332 * @param uriScheme The URI scheme.
Nancy Chen513c8922014-09-17 14:47:20 -0700333 * @return The {@link PhoneAccountHandle} corresponding to the user-chosen default for outgoing
334 * phone calls for a specified URI scheme.
335 *
336 * @hide
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700337 */
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700338 public PhoneAccountHandle getDefaultOutgoingPhoneAccount(String uriScheme) {
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700339 try {
340 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700341 return getTelecomService().getDefaultOutgoingPhoneAccount(uriScheme);
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700342 }
343 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700344 Log.e(TAG, "Error calling ITelecomService#getDefaultOutgoingPhoneAccount", e);
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700345 }
346 return null;
347 }
348
349 /**
Andrew Leed4abbfb2014-09-03 14:58:27 -0700350 * Return the {@link PhoneAccount} which is the user-chosen default for making outgoing phone
351 * calls. This {@code PhoneAccount} will always be a member of the list which is returned from
Nancy Chen210ef032014-09-15 17:58:42 -0700352 * calling {@link #getCallCapablePhoneAccounts()}
Andrew Leed4abbfb2014-09-03 14:58:27 -0700353 *
354 * Apps must be prepared for this method to return {@code null}, indicating that there currently
355 * exists no user-chosen default {@code PhoneAccount}.
356 *
357 * @return The user outgoing phone account selected by the user.
358 * @hide
359 */
360 public PhoneAccountHandle getUserSelectedOutgoingPhoneAccount() {
361 try {
362 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700363 return getTelecomService().getUserSelectedOutgoingPhoneAccount();
Andrew Leed4abbfb2014-09-03 14:58:27 -0700364 }
365 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700366 Log.e(TAG, "Error calling ITelecomService#getUserSelectedOutgoingPhoneAccount", e);
Andrew Leed4abbfb2014-09-03 14:58:27 -0700367 }
368 return null;
369 }
370
371 /**
Andrew Lee59cac3a2014-08-28 16:50:10 -0700372 * Sets the default account for making outgoing phone calls.
373 * @hide
374 */
Andrew Leed4abbfb2014-09-03 14:58:27 -0700375 public void setUserSelectedOutgoingPhoneAccount(PhoneAccountHandle accountHandle) {
Andrew Lee59cac3a2014-08-28 16:50:10 -0700376 try {
377 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700378 getTelecomService().setUserSelectedOutgoingPhoneAccount(accountHandle);
Andrew Lee59cac3a2014-08-28 16:50:10 -0700379 }
380 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700381 Log.e(TAG, "Error calling ITelecomService#setUserSelectedOutgoingPhoneAccount");
Andrew Lee59cac3a2014-08-28 16:50:10 -0700382 }
383 }
384
385 /**
Andrew Lee59cac3a2014-08-28 16:50:10 -0700386 * Returns the current SIM call manager. Apps must be prepared for this method to return
387 * {@code null}, indicating that there currently exists no user-chosen default
388 * {@code PhoneAccount}.
389 * @return The phone account handle of the current sim call manager.
390 * @hide
391 */
392 public PhoneAccountHandle getSimCallManager() {
393 try {
394 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700395 return getTelecomService().getSimCallManager();
Andrew Lee59cac3a2014-08-28 16:50:10 -0700396 }
397 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700398 Log.e(TAG, "Error calling ITelecomService#getSimCallManager");
Andrew Lee59cac3a2014-08-28 16:50:10 -0700399 }
400 return null;
401 }
402
403 /**
404 * Sets the SIM call manager to the specified phone account.
405 * @param accountHandle The phone account handle of the account to set as the sim call manager.
406 * @hide
407 */
408 public void setSimCallManager(PhoneAccountHandle accountHandle) {
409 try {
410 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700411 getTelecomService().setSimCallManager(accountHandle);
Andrew Lee59cac3a2014-08-28 16:50:10 -0700412 }
413 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700414 Log.e(TAG, "Error calling ITelecomService#setSimCallManager");
Andrew Lee59cac3a2014-08-28 16:50:10 -0700415 }
416 }
417
418 /**
419 * Returns the list of registered SIM call managers.
420 * @return List of registered SIM call managers.
421 * @hide
422 */
423 public List<PhoneAccountHandle> getSimCallManagers() {
424 try {
425 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700426 return getTelecomService().getSimCallManagers();
Andrew Lee59cac3a2014-08-28 16:50:10 -0700427 }
428 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700429 Log.e(TAG, "Error calling ITelecomService#getSimCallManagers");
Andrew Lee59cac3a2014-08-28 16:50:10 -0700430 }
431 return new ArrayList<>();
432 }
433
434 /**
Evan Charltoneb0a8d52014-09-04 12:03:34 -0700435 * Returns the current connection manager. Apps must be prepared for this method to return
436 * {@code null}, indicating that there currently exists no user-chosen default
437 * {@code PhoneAccount}.
438 *
439 * @return The phone account handle of the current connection manager.
Tyler Gunn711d876fd2014-09-19 11:17:02 -0700440 * @hide
Evan Charltoneb0a8d52014-09-04 12:03:34 -0700441 */
442 public PhoneAccountHandle getConnectionManager() {
443 return getSimCallManager();
444 }
445
446 /**
Nancy Chen210ef032014-09-15 17:58:42 -0700447 * Returns a list of the {@link PhoneAccountHandle}s which can be used to make and receive phone
448 * calls which support the specified URI scheme.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700449 * <P>
450 * For example, invoking with {@code "tel"} will find all {@link PhoneAccountHandle}s which
451 * support telephone calls (e.g. URIs such as {@code tel:555-555-1212}). Invoking with
452 * {@code "sip"} will find all {@link PhoneAccountHandle}s which support SIP calls (e.g. URIs
453 * such as {@code sip:example@sipexample.com}).
454 *
455 * @param uriScheme The URI scheme.
456 * @return A list of {@code PhoneAccountHandle} objects supporting the URI scheme.
Nancy Chen513c8922014-09-17 14:47:20 -0700457 *
458 * @hide
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700459 */
460 public List<PhoneAccountHandle> getPhoneAccountsSupportingScheme(String uriScheme) {
461 try {
462 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700463 return getTelecomService().getPhoneAccountsSupportingScheme(uriScheme);
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700464 }
465 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700466 Log.e(TAG, "Error calling ITelecomService#getPhoneAccountsSupportingScheme", e);
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700467 }
468 return new ArrayList<>();
469 }
470
Nancy Chen513c8922014-09-17 14:47:20 -0700471
472 /**
473 * Return a list of {@link PhoneAccountHandle}s which can be used to make and receive phone
474 * calls.
475 *
476 * @see #EXTRA_PHONE_ACCOUNT_HANDLE
477 * @return A list of {@code PhoneAccountHandle} objects.
478 *
479 * @hide
480 */
481 public List<PhoneAccountHandle> getCallCapablePhoneAccounts() {
482 try {
483 if (isServiceConnected()) {
484 return getTelecomService().getCallCapablePhoneAccounts();
485 }
486 } catch (RemoteException e) {
487 Log.e(TAG, "Error calling ITelecomService#getCallCapablePhoneAccounts", e);
488 }
489 return new ArrayList<>();
490 }
491
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700492 /**
Nancy Chen210ef032014-09-15 17:58:42 -0700493 * Determine whether the device has more than one account registered that can make and receive
494 * phone calls.
Nancy Chen60801182014-07-22 16:56:49 -0700495 *
Nancy Chen210ef032014-09-15 17:58:42 -0700496 * @return {@code true} if the device has more than one account registered and {@code false}
497 * otherwise.
Tyler Gunn711d876fd2014-09-19 11:17:02 -0700498 * @hide
Nancy Chen60801182014-07-22 16:56:49 -0700499 */
Nancy Chen210ef032014-09-15 17:58:42 -0700500 public boolean hasMultipleCallCapableAccounts() {
501 return getCallCapablePhoneAccounts().size() > 1;
Nancy Chen60801182014-07-22 16:56:49 -0700502 }
503
504 /**
Nancy Chen513c8922014-09-17 14:47:20 -0700505 * Returns a list of all {@link PhoneAccount}s registered for the calling package.
506 *
507 * @return A list of {@code PhoneAccountHandle} objects.
Tyler Gunn711d876fd2014-09-19 11:17:02 -0700508 * @hide
Nancy Chen513c8922014-09-17 14:47:20 -0700509 */
510 public List<PhoneAccountHandle> getPhoneAccountsForPackage() {
511 try {
512 if (isServiceConnected()) {
513 return getTelecomService().getPhoneAccountsForPackage(mContext.getPackageName());
514 }
515 } catch (RemoteException e) {
516 Log.e(TAG, "Error calling ITelecomService#getPhoneAccountsForPackage", e);
517 }
518 return null;
519 }
520
521 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700522 * Return the {@link PhoneAccount} for a specified {@link PhoneAccountHandle}. Object includes
523 * resources which can be used in a user interface.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700524 *
Evan Charlton6eb262c2014-07-19 18:18:19 -0700525 * @param account The {@link PhoneAccountHandle}.
Evan Charlton8c8a0622014-07-20 12:31:00 -0700526 * @return The {@link PhoneAccount} object.
Tyler Gunn711d876fd2014-09-19 11:17:02 -0700527 * @hide
Ihab Awad807fe0a2014-07-09 12:30:52 -0700528 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700529 public PhoneAccount getPhoneAccount(PhoneAccountHandle account) {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700530 try {
531 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700532 return getTelecomService().getPhoneAccount(account);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700533 }
534 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700535 Log.e(TAG, "Error calling ITelecomService#getPhoneAccount", e);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700536 }
537 return null;
538 }
539
540 /**
Nancy Chen210ef032014-09-15 17:58:42 -0700541 * Returns a count of all {@link PhoneAccount}s.
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700542 *
Nancy Chen210ef032014-09-15 17:58:42 -0700543 * @return The count of {@link PhoneAccount}s.
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700544 * @hide
545 */
546 @SystemApi
547 public int getAllPhoneAccountsCount() {
548 try {
549 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700550 return getTelecomService().getAllPhoneAccountsCount();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700551 }
552 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700553 Log.e(TAG, "Error calling ITelecomService#getAllPhoneAccountsCount", e);
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700554 }
555 return 0;
556 }
557
558 /**
559 * Returns a list of all {@link PhoneAccount}s.
560 *
561 * @return All {@link PhoneAccount}s.
562 * @hide
563 */
564 @SystemApi
565 public List<PhoneAccount> getAllPhoneAccounts() {
566 try {
567 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700568 return getTelecomService().getAllPhoneAccounts();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700569 }
570 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700571 Log.e(TAG, "Error calling ITelecomService#getAllPhoneAccounts", e);
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700572 }
573 return Collections.EMPTY_LIST;
574 }
575
576 /**
577 * Returns a list of all {@link PhoneAccountHandle}s.
578 *
579 * @return All {@link PhoneAccountHandle}s.
580 * @hide
581 */
582 @SystemApi
583 public List<PhoneAccountHandle> getAllPhoneAccountHandles() {
584 try {
585 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700586 return getTelecomService().getAllPhoneAccountHandles();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700587 }
588 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700589 Log.e(TAG, "Error calling ITelecomService#getAllPhoneAccountHandles", e);
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700590 }
591 return Collections.EMPTY_LIST;
592 }
593
594 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700595 * Register a {@link PhoneAccount} for use by the system.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700596 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700597 * @param account The complete {@link PhoneAccount}.
Tyler Gunn711d876fd2014-09-19 11:17:02 -0700598 * @hide
Ihab Awad807fe0a2014-07-09 12:30:52 -0700599 */
Evan Charltonce11dec2014-10-02 13:45:27 -0700600 @SystemApi
Evan Charlton8c8a0622014-07-20 12:31:00 -0700601 public void registerPhoneAccount(PhoneAccount account) {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700602 try {
603 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700604 getTelecomService().registerPhoneAccount(account);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700605 }
606 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700607 Log.e(TAG, "Error calling ITelecomService#registerPhoneAccount", e);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700608 }
609 }
610
611 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700612 * Remove a {@link PhoneAccount} registration from the system.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700613 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700614 * @param accountHandle A {@link PhoneAccountHandle} for the {@link PhoneAccount} to unregister.
Tyler Gunn711d876fd2014-09-19 11:17:02 -0700615 * @hide
Ihab Awad807fe0a2014-07-09 12:30:52 -0700616 */
Evan Charltonce11dec2014-10-02 13:45:27 -0700617 @SystemApi
Evan Charlton8c8a0622014-07-20 12:31:00 -0700618 public void unregisterPhoneAccount(PhoneAccountHandle accountHandle) {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700619 try {
620 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700621 getTelecomService().unregisterPhoneAccount(accountHandle);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700622 }
623 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700624 Log.e(TAG, "Error calling ITelecomService#unregisterPhoneAccount", e);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700625 }
626 }
627
628 /**
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700629 * Remove all Accounts that belong to the calling package from the system.
Tyler Gunn711d876fd2014-09-19 11:17:02 -0700630 * @hide
Ihab Awad807fe0a2014-07-09 12:30:52 -0700631 */
632 @SystemApi
Nancy Chen7ab1dc42014-09-09 18:18:26 -0700633 public void clearAccounts() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700634 try {
635 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700636 getTelecomService().clearAccounts(mContext.getPackageName());
Ihab Awad807fe0a2014-07-09 12:30:52 -0700637 }
638 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700639 Log.e(TAG, "Error calling ITelecomService#clearAccounts", e);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700640 }
641 }
642
643 /**
644 * @hide
645 */
Santos Cordon6c7a3882014-06-25 15:30:08 -0700646 @SystemApi
647 public ComponentName getDefaultPhoneApp() {
648 try {
Santos Cordon9eb45932014-06-27 12:28:43 -0700649 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700650 return getTelecomService().getDefaultPhoneApp();
Santos Cordon9eb45932014-06-27 12:28:43 -0700651 }
Santos Cordon6c7a3882014-06-25 15:30:08 -0700652 } catch (RemoteException e) {
653 Log.e(TAG, "RemoteException attempting to get the default phone app.", e);
654 }
655 return null;
656 }
657
Santos Cordon9eb45932014-06-27 12:28:43 -0700658 /**
Nancy Chen443e5012014-10-15 15:48:21 -0700659 * Return whether a given phone number is the configured voicemail number for a
660 * particular phone account.
661 *
662 * @param accountHandle The handle for the account to check the voicemail number against
663 * @param number The number to look up.
664 *
665 * @hide
666 */
667 @SystemApi
668 public boolean isVoiceMailNumber(PhoneAccountHandle accountHandle, String number) {
669 try {
670 if (isServiceConnected()) {
671 return getTelecomService().isVoiceMailNumber(accountHandle, number);
672 }
673 } catch (RemoteException e) {
674 Log.e(TAG, "RemoteException calling isInCall().", e);
675 }
676 return false;
677 }
678
679 /**
Santos Cordon9eb45932014-06-27 12:28:43 -0700680 * Returns whether there is an ongoing phone call (can be in dialing, ringing, active or holding
681 * states).
Nancy Chen0eb1e402014-08-21 22:52:29 -0700682 * <p>
683 * Requires permission: {@link android.Manifest.permission#READ_PHONE_STATE}
684 * </p>
Santos Cordon9eb45932014-06-27 12:28:43 -0700685 */
686 @SystemApi
Nancy Chen0eb1e402014-08-21 22:52:29 -0700687 public boolean isInCall() {
Santos Cordon9eb45932014-06-27 12:28:43 -0700688 try {
689 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700690 return getTelecomService().isInCall();
Santos Cordon9eb45932014-06-27 12:28:43 -0700691 }
692 } catch (RemoteException e) {
Yorke Lee2ae312e2014-09-12 17:58:48 -0700693 Log.e(TAG, "RemoteException calling isInCall().", e);
Santos Cordon9eb45932014-06-27 12:28:43 -0700694 }
695 return false;
696 }
697
698 /**
Yorke Lee2ae312e2014-09-12 17:58:48 -0700699 * Returns one of the following constants that represents the current state of Telecom:
700 *
701 * {@link TelephonyManager#CALL_STATE_RINGING}
702 * {@link TelephonyManager#CALL_STATE_OFFHOOK}
703 * {@link TelephonyManager#CALL_STATE_IDLE}
Yorke Lee2ae312e2014-09-12 17:58:48 -0700704 * @hide
705 */
706 @SystemApi
707 public int getCallState() {
708 try {
709 if (isServiceConnected()) {
710 return getTelecomService().getCallState();
711 }
712 } catch (RemoteException e) {
713 Log.d(TAG, "RemoteException calling getCallState().", e);
714 }
715 return TelephonyManager.CALL_STATE_IDLE;
716 }
717
718 /**
Santos Cordon9eb45932014-06-27 12:28:43 -0700719 * Returns whether there currently exists is a ringing incoming-call.
720 *
721 * @hide
722 */
723 @SystemApi
724 public boolean isRinging() {
725 try {
726 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700727 return getTelecomService().isRinging();
Santos Cordon9eb45932014-06-27 12:28:43 -0700728 }
729 } catch (RemoteException e) {
730 Log.e(TAG, "RemoteException attempting to get ringing state of phone app.", e);
731 }
732 return false;
733 }
734
735 /**
Santos Cordon96efb482014-07-19 14:57:05 -0700736 * Ends an ongoing call.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700737 * TODO: L-release - need to convert all invocations of ITelecomService#endCall to use this
Santos Cordon96efb482014-07-19 14:57:05 -0700738 * method (clockwork & gearhead).
Santos Cordon9eb45932014-06-27 12:28:43 -0700739 * @hide
740 */
741 @SystemApi
742 public boolean endCall() {
743 try {
744 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700745 return getTelecomService().endCall();
Santos Cordon9eb45932014-06-27 12:28:43 -0700746 }
747 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700748 Log.e(TAG, "Error calling ITelecomService#endCall", e);
Santos Cordon9eb45932014-06-27 12:28:43 -0700749 }
750 return false;
751 }
752
753 /**
754 * If there is a ringing incoming call, this method accepts the call on behalf of the user.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700755 * TODO: L-release - need to convert all invocation of ITelecmmService#answerRingingCall to use
Santos Cordon96efb482014-07-19 14:57:05 -0700756 * this method (clockwork & gearhead).
Santos Cordon9eb45932014-06-27 12:28:43 -0700757 *
758 * @hide
759 */
760 @SystemApi
761 public void acceptRingingCall() {
762 try {
763 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700764 getTelecomService().acceptRingingCall();
Santos Cordon9eb45932014-06-27 12:28:43 -0700765 }
766 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700767 Log.e(TAG, "Error calling ITelecomService#acceptRingingCall", e);
Santos Cordon9eb45932014-06-27 12:28:43 -0700768 }
769 }
770
771 /**
772 * Silences the ringer if a ringing call exists.
773 *
774 * @hide
775 */
776 @SystemApi
777 public void silenceRinger() {
778 try {
779 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700780 getTelecomService().silenceRinger();
Santos Cordon9eb45932014-06-27 12:28:43 -0700781 }
782 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700783 Log.e(TAG, "Error calling ITelecomService#silenceRinger", e);
Santos Cordon9eb45932014-06-27 12:28:43 -0700784 }
785 }
786
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700787 /**
788 * Returns whether TTY is supported on this device.
789 *
790 * @hide
791 */
792 @SystemApi
793 public boolean isTtySupported() {
794 try {
795 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700796 return getTelecomService().isTtySupported();
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700797 }
798 } catch (RemoteException e) {
799 Log.e(TAG, "RemoteException attempting to get TTY supported state.", e);
800 }
801 return false;
802 }
803
804 /**
805 * 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 -0700806 * settings and have a wired headset plugged in.
807 * Valid modes are:
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700808 * - {@link TelecomManager#TTY_MODE_OFF}
809 * - {@link TelecomManager#TTY_MODE_FULL}
810 * - {@link TelecomManager#TTY_MODE_HCO}
811 * - {@link TelecomManager#TTY_MODE_VCO}
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700812 * @hide
813 */
814 public int getCurrentTtyMode() {
815 try {
816 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700817 return getTelecomService().getCurrentTtyMode();
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700818 }
819 } catch (RemoteException e) {
820 Log.e(TAG, "RemoteException attempting to get the current TTY mode.", e);
821 }
Evan Charlton10197192014-07-19 15:00:29 -0700822 return TTY_MODE_OFF;
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700823 }
824
Santos Cordon96efb482014-07-19 14:57:05 -0700825 /**
826 * Registers a new incoming call. A {@link ConnectionService} should invoke this method when it
827 * has an incoming call. The specified {@link PhoneAccountHandle} must have been registered
Nancy Chen210ef032014-09-15 17:58:42 -0700828 * with {@link #registerPhoneAccount}. Once invoked, this method will cause the system to bind
829 * to the {@link ConnectionService} associated with the {@link PhoneAccountHandle} and request
Santos Cordon96efb482014-07-19 14:57:05 -0700830 * additional information about the call (See
831 * {@link ConnectionService#onCreateIncomingConnection}) before starting the incoming call UI.
832 *
833 * @param phoneAccount A {@link PhoneAccountHandle} registered with
834 * {@link #registerPhoneAccount}.
835 * @param extras A bundle that will be passed through to
836 * {@link ConnectionService#onCreateIncomingConnection}.
Tyler Gunn711d876fd2014-09-19 11:17:02 -0700837 * @hide
Santos Cordon96efb482014-07-19 14:57:05 -0700838 */
Evan Charltonce11dec2014-10-02 13:45:27 -0700839 @SystemApi
Santos Cordon96efb482014-07-19 14:57:05 -0700840 public void addNewIncomingCall(PhoneAccountHandle phoneAccount, Bundle extras) {
841 try {
842 if (isServiceConnected()) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700843 getTelecomService().addNewIncomingCall(
Santos Cordon96efb482014-07-19 14:57:05 -0700844 phoneAccount, extras == null ? new Bundle() : extras);
845 }
846 } catch (RemoteException e) {
847 Log.e(TAG, "RemoteException adding a new incoming call: " + phoneAccount, e);
848 }
849 }
850
Nancy Chen0eb1e402014-08-21 22:52:29 -0700851 /**
Yorke Leec3cf9822014-10-02 09:38:39 -0700852 * Registers a new unknown call with Telecom. This can only be called by the system Telephony
853 * service. This is invoked when Telephony detects a new unknown connection that was neither
854 * a new incoming call, nor an user-initiated outgoing call.
855 *
856 * @param phoneAccount A {@link PhoneAccountHandle} registered with
857 * {@link #registerPhoneAccount}.
858 * @param extras A bundle that will be passed through to
859 * {@link ConnectionService#onCreateIncomingConnection}.
860 * @hide
861 */
862 @SystemApi
863 public void addNewUnknownCall(PhoneAccountHandle phoneAccount, Bundle extras) {
864 try {
865 if (isServiceConnected()) {
866 getTelecomService().addNewUnknownCall(
867 phoneAccount, extras == null ? new Bundle() : extras);
868 }
869 } catch (RemoteException e) {
870 Log.e(TAG, "RemoteException adding a new unknown call: " + phoneAccount, e);
871 }
872 }
873
874 /**
Nancy Chen0eb1e402014-08-21 22:52:29 -0700875 * Processes the specified dial string as an MMI code.
876 * MMI codes are any sequence of characters entered into the dialpad that contain a "*" or "#".
877 * Some of these sequences launch special behavior through handled by Telephony.
878 * <p>
879 * Requires that the method-caller be set as the system dialer app.
880 * </p>
881 *
882 * @param dialString The digits to dial.
883 * @return True if the digits were processed as an MMI code, false otherwise.
884 */
885 public boolean handleMmi(String dialString) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700886 ITelecomService service = getTelecomService();
Nancy Chen0eb1e402014-08-21 22:52:29 -0700887 if (service != null) {
888 try {
889 return service.handlePinMmi(dialString);
890 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700891 Log.e(TAG, "Error calling ITelecomService#handlePinMmi", e);
Nancy Chen0eb1e402014-08-21 22:52:29 -0700892 }
893 }
894 return false;
895 }
896
897 /**
898 * Removes the missed-call notification if one is present.
899 * <p>
900 * Requires that the method-caller be set as the system dialer app.
901 * </p>
902 */
903 public void cancelMissedCallsNotification() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700904 ITelecomService service = getTelecomService();
Nancy Chen0eb1e402014-08-21 22:52:29 -0700905 if (service != null) {
906 try {
907 service.cancelMissedCallsNotification();
908 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700909 Log.e(TAG, "Error calling ITelecomService#cancelMissedCallsNotification", e);
Nancy Chen0eb1e402014-08-21 22:52:29 -0700910 }
911 }
912 }
913
914 /**
915 * Brings the in-call screen to the foreground if there is an ongoing call. If there is
916 * currently no ongoing call, then this method does nothing.
917 * <p>
918 * Requires that the method-caller be set as the system dialer app or have the
919 * {@link android.Manifest.permission#READ_PHONE_STATE} permission.
920 * </p>
921 *
922 * @param showDialpad Brings up the in-call dialpad as part of showing the in-call screen.
923 */
924 public void showInCallScreen(boolean showDialpad) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700925 ITelecomService service = getTelecomService();
Nancy Chen0eb1e402014-08-21 22:52:29 -0700926 if (service != null) {
927 try {
928 service.showInCallScreen(showDialpad);
929 } catch (RemoteException e) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700930 Log.e(TAG, "Error calling ITelecomService#showCallScreen", e);
Nancy Chen0eb1e402014-08-21 22:52:29 -0700931 }
932 }
933 }
934
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700935 private ITelecomService getTelecomService() {
936 return ITelecomService.Stub.asInterface(ServiceManager.getService(Context.TELECOM_SERVICE));
Santos Cordon6c7a3882014-06-25 15:30:08 -0700937 }
Santos Cordon9eb45932014-06-27 12:28:43 -0700938
939 private boolean isServiceConnected() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700940 boolean isConnected = getTelecomService() != null;
Santos Cordon9eb45932014-06-27 12:28:43 -0700941 if (!isConnected) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700942 Log.w(TAG, "Telecom Service not found.");
Santos Cordon9eb45932014-06-27 12:28:43 -0700943 }
944 return isConnected;
945 }
Evan Charlton235c1592014-09-05 15:41:23 +0000946}