| Yorke Lee | b4ce143 | 2014-06-09 13:53:23 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 4 | * 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 Lee | b4ce143 | 2014-06-09 13:53:23 -0700 | [diff] [blame] | 6 | * |
| Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| Yorke Lee | b4ce143 | 2014-06-09 13:53:23 -0700 | [diff] [blame] | 8 | * |
| Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 9 | * 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 Lee | b4ce143 | 2014-06-09 13:53:23 -0700 | [diff] [blame] | 13 | */ |
| 14 | |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 15 | package android.telecom; |
| Yorke Lee | b4ce143 | 2014-06-09 13:53:23 -0700 | [diff] [blame] | 16 | |
| Santos Cordon | 6c7a388 | 2014-06-25 15:30:08 -0700 | [diff] [blame] | 17 | import android.annotation.SystemApi; |
| 18 | import android.content.ComponentName; |
| Yorke Lee | b4ce143 | 2014-06-09 13:53:23 -0700 | [diff] [blame] | 19 | import android.content.Context; |
| Nancy Chen | b2299c1 | 2014-10-29 18:22:11 -0700 | [diff] [blame] | 20 | import android.net.Uri; |
| Santos Cordon | 96efb48 | 2014-07-19 14:57:05 -0700 | [diff] [blame] | 21 | import android.os.Bundle; |
| Santos Cordon | 6c7a388 | 2014-06-25 15:30:08 -0700 | [diff] [blame] | 22 | import android.os.RemoteException; |
| 23 | import android.os.ServiceManager; |
| Yorke Lee | 2ae312e | 2014-09-12 17:58:48 -0700 | [diff] [blame] | 24 | import android.telephony.TelephonyManager; |
| Anthony Lee | 6727926 | 2014-10-27 11:28:40 -0700 | [diff] [blame] | 25 | import android.text.TextUtils; |
| Santos Cordon | 6c7a388 | 2014-06-25 15:30:08 -0700 | [diff] [blame] | 26 | import android.util.Log; |
| Yorke Lee | b4ce143 | 2014-06-09 13:53:23 -0700 | [diff] [blame] | 27 | |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 28 | import com.android.internal.telecom.ITelecomService; |
| Yorke Lee | b4ce143 | 2014-06-09 13:53:23 -0700 | [diff] [blame] | 29 | |
| Jay Shrauner | 7746a94 | 2014-08-26 12:15:15 -0700 | [diff] [blame] | 30 | import java.util.ArrayList; |
| Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 31 | import java.util.Collections; |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 32 | import java.util.List; |
| 33 | |
| Yorke Lee | b4ce143 | 2014-06-09 13:53:23 -0700 | [diff] [blame] | 34 | /** |
| Santos Cordon | d9e614f | 2014-10-28 13:10:36 -0700 | [diff] [blame] | 35 | * Provides access to information about active calls and registration/call-management functionality. |
| 36 | * Apps can use methods in this class to determine the current call state. Apps can also register new |
| 37 | * {@link PhoneAccount}s and get a listing of existing {@link PhoneAccount}s. |
| 38 | * <p> |
| 39 | * Apps do not instantiate this class directly; instead, they retrieve a reference to an instance |
| 40 | * through {@link Context#getSystemService Context.getSystemService(Context.TELECOM_SERVICE)}. |
| 41 | * <p> |
| 42 | * Note that access to some telecom information is permission-protected. Your app cannot access the |
| 43 | * protected information or gain access to protected functionality unless it has the appropriate |
| 44 | * permissions declared in its manifest file. Where permissions apply, they are noted in the method |
| 45 | * descriptions. |
| Yorke Lee | b4ce143 | 2014-06-09 13:53:23 -0700 | [diff] [blame] | 46 | */ |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 47 | public class TelecomManager { |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 48 | |
| Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 49 | /** |
| Santos Cordon | 96efb48 | 2014-07-19 14:57:05 -0700 | [diff] [blame] | 50 | * Activity action: Starts the UI for handing an incoming call. This intent starts the in-call |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 51 | * UI by notifying the Telecom system that an incoming call exists for a specific call service |
| 52 | * (see {@link android.telecom.ConnectionService}). Telecom reads the Intent extras to find |
| 53 | * and bind to the appropriate {@link android.telecom.ConnectionService} which Telecom will |
| Santos Cordon | 96efb48 | 2014-07-19 14:57:05 -0700 | [diff] [blame] | 54 | * ultimately use to control and get information about the call. |
| 55 | * <p> |
| 56 | * Input: get*Extra field {@link #EXTRA_PHONE_ACCOUNT_HANDLE} contains the component name of the |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 57 | * {@link android.telecom.ConnectionService} that Telecom should bind to. Telecom will then |
| Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 58 | * ask the connection service for more information about the call prior to showing any UI. |
| 59 | * |
| Santos Cordon | 96efb48 | 2014-07-19 14:57:05 -0700 | [diff] [blame] | 60 | * @hide |
| Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 61 | */ |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 62 | public static final String ACTION_INCOMING_CALL = "android.telecom.action.INCOMING_CALL"; |
| Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 63 | |
| 64 | /** |
| Yorke Lee | c3cf982 | 2014-10-02 09:38:39 -0700 | [diff] [blame] | 65 | * Similar to {@link #ACTION_INCOMING_CALL}, but is used only by Telephony to add a new |
| 66 | * sim-initiated MO call for carrier testing. |
| 67 | * @hide |
| 68 | */ |
| 69 | public static final String ACTION_NEW_UNKNOWN_CALL = "android.telecom.action.NEW_UNKNOWN_CALL"; |
| 70 | |
| 71 | /** |
| Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 72 | * The {@link android.content.Intent} action used to configure a |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 73 | * {@link android.telecom.ConnectionService}. |
| Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 74 | */ |
| 75 | public static final String ACTION_CONNECTION_SERVICE_CONFIGURE = |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 76 | "android.telecom.action.CONNECTION_SERVICE_CONFIGURE"; |
| Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 77 | |
| 78 | /** |
| Yorke Lee | 3818a892 | 2014-07-21 15:57:17 -0700 | [diff] [blame] | 79 | * The {@link android.content.Intent} action used to show the call settings page. |
| 80 | */ |
| 81 | public static final String ACTION_SHOW_CALL_SETTINGS = |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 82 | "android.telecom.action.SHOW_CALL_SETTINGS"; |
| Yorke Lee | 3818a892 | 2014-07-21 15:57:17 -0700 | [diff] [blame] | 83 | |
| 84 | /** |
| Evan Charlton | 6d8604f | 2014-09-04 12:38:17 -0700 | [diff] [blame] | 85 | * The {@link android.content.Intent} action used to show the settings page used to configure |
| 86 | * {@link PhoneAccount} preferences. |
| 87 | */ |
| 88 | public static final String ACTION_CHANGE_PHONE_ACCOUNTS = |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 89 | "android.telecom.action.CHANGE_PHONE_ACCOUNTS"; |
| Evan Charlton | 6d8604f | 2014-09-04 12:38:17 -0700 | [diff] [blame] | 90 | |
| 91 | /** |
| Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 92 | * Optional extra for {@link android.content.Intent#ACTION_CALL} containing a boolean that |
| 93 | * determines whether the speakerphone should be automatically turned on for an outgoing call. |
| Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 94 | */ |
| 95 | public static final String EXTRA_START_CALL_WITH_SPEAKERPHONE = |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 96 | "android.telecom.extra.START_CALL_WITH_SPEAKERPHONE"; |
| Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 97 | |
| 98 | /** |
| Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 99 | * Optional extra for {@link android.content.Intent#ACTION_CALL} containing an integer that |
| 100 | * determines the desired video state for an outgoing call. |
| Santos Cordon | 96efb48 | 2014-07-19 14:57:05 -0700 | [diff] [blame] | 101 | * Valid options: |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 102 | * {@link VideoProfile.VideoState#AUDIO_ONLY}, |
| 103 | * {@link VideoProfile.VideoState#BIDIRECTIONAL}, |
| 104 | * {@link VideoProfile.VideoState#RX_ENABLED}, |
| 105 | * {@link VideoProfile.VideoState#TX_ENABLED}. |
| Tyler Gunn | 27d1e25 | 2014-08-21 16:38:40 -0700 | [diff] [blame] | 106 | * @hide |
| Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 107 | */ |
| 108 | public static final String EXTRA_START_CALL_WITH_VIDEO_STATE = |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 109 | "android.telecom.extra.START_CALL_WITH_VIDEO_STATE"; |
| Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 110 | |
| 111 | /** |
| Santos Cordon | 96efb48 | 2014-07-19 14:57:05 -0700 | [diff] [blame] | 112 | * The extra used with an {@link android.content.Intent#ACTION_CALL} and |
| 113 | * {@link android.content.Intent#ACTION_DIAL} {@code Intent} to specify a |
| 114 | * {@link PhoneAccountHandle} to use when making the call. |
| Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 115 | * <p class="note"> |
| Santos Cordon | 96efb48 | 2014-07-19 14:57:05 -0700 | [diff] [blame] | 116 | * Retrieve with {@link android.content.Intent#getParcelableExtra(String)}. |
| Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 117 | */ |
| Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 118 | public static final String EXTRA_PHONE_ACCOUNT_HANDLE = |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 119 | "android.telecom.extra.PHONE_ACCOUNT_HANDLE"; |
| Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 120 | |
| 121 | /** |
| Santos Cordon | 96efb48 | 2014-07-19 14:57:05 -0700 | [diff] [blame] | 122 | * Optional extra for {@link #ACTION_INCOMING_CALL} containing a {@link Bundle} which contains |
| 123 | * metadata about the call. This {@link Bundle} will be returned to the |
| 124 | * {@link ConnectionService}. |
| 125 | * |
| 126 | * @hide |
| Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 127 | */ |
| 128 | public static final String EXTRA_INCOMING_CALL_EXTRAS = |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 129 | "android.telecom.extra.INCOMING_CALL_EXTRAS"; |
| Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 130 | |
| 131 | /** |
| Nancy Chen | 10798dc | 2014-08-08 14:00:25 -0700 | [diff] [blame] | 132 | * Optional extra for {@link android.content.Intent#ACTION_CALL} and |
| 133 | * {@link android.content.Intent#ACTION_DIAL} {@code Intent} containing a {@link Bundle} |
| 134 | * which contains metadata about the call. This {@link Bundle} will be saved into |
| 135 | * {@code Call.Details}. |
| 136 | * |
| 137 | * @hide |
| 138 | */ |
| 139 | public static final String EXTRA_OUTGOING_CALL_EXTRAS = |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 140 | "android.telecom.extra.OUTGOING_CALL_EXTRAS"; |
| Nancy Chen | 10798dc | 2014-08-08 14:00:25 -0700 | [diff] [blame] | 141 | |
| 142 | /** |
| Yorke Lee | c3cf982 | 2014-10-02 09:38:39 -0700 | [diff] [blame] | 143 | * @hide |
| 144 | */ |
| 145 | public static final String EXTRA_UNKNOWN_CALL_HANDLE = |
| 146 | "android.telecom.extra.UNKNOWN_CALL_HANDLE"; |
| 147 | |
| 148 | /** |
| Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 149 | * Optional extra for {@link android.telephony.TelephonyManager#ACTION_PHONE_STATE_CHANGED} |
| 150 | * containing the disconnect code. |
| Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 151 | */ |
| 152 | public static final String EXTRA_CALL_DISCONNECT_CAUSE = |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 153 | "android.telecom.extra.CALL_DISCONNECT_CAUSE"; |
| Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 154 | |
| 155 | /** |
| Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 156 | * Optional extra for {@link android.telephony.TelephonyManager#ACTION_PHONE_STATE_CHANGED} |
| 157 | * containing the disconnect message. |
| Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 158 | */ |
| 159 | public static final String EXTRA_CALL_DISCONNECT_MESSAGE = |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 160 | "android.telecom.extra.CALL_DISCONNECT_MESSAGE"; |
| Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 161 | |
| 162 | /** |
| Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 163 | * Optional extra for {@link android.telephony.TelephonyManager#ACTION_PHONE_STATE_CHANGED} |
| 164 | * containing the component name of the associated connection service. |
| Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 165 | */ |
| 166 | public static final String EXTRA_CONNECTION_SERVICE = |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 167 | "android.telecom.extra.CONNECTION_SERVICE"; |
| Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 168 | |
| 169 | /** |
| Nancy Chen | 7ab1dc4 | 2014-09-09 18:18:26 -0700 | [diff] [blame] | 170 | * An optional {@link android.content.Intent#ACTION_CALL} intent extra denoting the |
| 171 | * package name of the app specifying an alternative gateway for the call. |
| 172 | * The value is a string. |
| 173 | * |
| 174 | * (The following comment corresponds to the all GATEWAY_* extras) |
| 175 | * An app which sends the {@link android.content.Intent#ACTION_CALL} intent can specify an |
| 176 | * alternative address to dial which is different from the one specified and displayed to |
| 177 | * the user. This alternative address is referred to as the gateway address. |
| 178 | */ |
| 179 | public static final String GATEWAY_PROVIDER_PACKAGE = |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 180 | "android.telecom.extra.GATEWAY_PROVIDER_PACKAGE"; |
| Nancy Chen | 7ab1dc4 | 2014-09-09 18:18:26 -0700 | [diff] [blame] | 181 | |
| 182 | /** |
| 183 | * An optional {@link android.content.Intent#ACTION_CALL} intent extra corresponding to the |
| 184 | * original address to dial for the call. This is used when an alternative gateway address is |
| 185 | * provided to recall the original address. |
| 186 | * The value is a {@link android.net.Uri}. |
| 187 | * |
| 188 | * (See {@link #GATEWAY_PROVIDER_PACKAGE} for details) |
| 189 | */ |
| 190 | public static final String GATEWAY_ORIGINAL_ADDRESS = |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 191 | "android.telecom.extra.GATEWAY_ORIGINAL_ADDRESS"; |
| Nancy Chen | 7ab1dc4 | 2014-09-09 18:18:26 -0700 | [diff] [blame] | 192 | |
| 193 | /** |
| Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 194 | * The number which the party on the other side of the line will see (and use to return the |
| 195 | * call). |
| 196 | * <p> |
| Santos Cordon | 96efb48 | 2014-07-19 14:57:05 -0700 | [diff] [blame] | 197 | * {@link ConnectionService}s which interact with {@link RemoteConnection}s should only populate |
| 198 | * this if the {@link android.telephony.TelephonyManager#getLine1Number()} value, as that is the |
| 199 | * user's expected caller ID. |
| Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 200 | */ |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 201 | public static final String EXTRA_CALL_BACK_NUMBER = "android.telecom.extra.CALL_BACK_NUMBER"; |
| Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 202 | |
| 203 | /** |
| 204 | * The dual tone multi-frequency signaling character sent to indicate the dialing system should |
| 205 | * pause for a predefined period. |
| 206 | */ |
| 207 | public static final char DTMF_CHARACTER_PAUSE = ','; |
| 208 | |
| 209 | /** |
| 210 | * The dual-tone multi-frequency signaling character sent to indicate the dialing system should |
| 211 | * wait for user confirmation before proceeding. |
| 212 | */ |
| 213 | public static final char DTMF_CHARACTER_WAIT = ';'; |
| 214 | |
| 215 | /** |
| 216 | * TTY (teletypewriter) mode is off. |
| 217 | * |
| 218 | * @hide |
| 219 | */ |
| 220 | public static final int TTY_MODE_OFF = 0; |
| 221 | |
| 222 | /** |
| 223 | * TTY (teletypewriter) mode is on. The speaker is off and the microphone is muted. The user |
| 224 | * will communicate with the remote party by sending and receiving text messages. |
| 225 | * |
| 226 | * @hide |
| 227 | */ |
| 228 | public static final int TTY_MODE_FULL = 1; |
| 229 | |
| 230 | /** |
| 231 | * TTY (teletypewriter) mode is in hearing carryover mode (HCO). The microphone is muted but the |
| 232 | * speaker is on. The user will communicate with the remote party by sending text messages and |
| 233 | * hearing an audible reply. |
| 234 | * |
| 235 | * @hide |
| 236 | */ |
| 237 | public static final int TTY_MODE_HCO = 2; |
| 238 | |
| 239 | /** |
| 240 | * TTY (teletypewriter) mode is in voice carryover mode (VCO). The speaker is off but the |
| 241 | * microphone is still on. User will communicate with the remote party by speaking and receiving |
| 242 | * text message replies. |
| 243 | * |
| 244 | * @hide |
| 245 | */ |
| 246 | public static final int TTY_MODE_VCO = 3; |
| 247 | |
| 248 | /** |
| 249 | * Broadcast intent action indicating that the current TTY mode has changed. An intent extra |
| 250 | * provides this state as an int. |
| Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 251 | * |
| Santos Cordon | 96efb48 | 2014-07-19 14:57:05 -0700 | [diff] [blame] | 252 | * @see #EXTRA_CURRENT_TTY_MODE |
| Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 253 | * @hide |
| 254 | */ |
| 255 | public static final String ACTION_CURRENT_TTY_MODE_CHANGED = |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 256 | "android.telecom.action.CURRENT_TTY_MODE_CHANGED"; |
| Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 257 | |
| 258 | /** |
| 259 | * The lookup key for an int that indicates the current TTY mode. |
| 260 | * Valid modes are: |
| 261 | * - {@link #TTY_MODE_OFF} |
| 262 | * - {@link #TTY_MODE_FULL} |
| 263 | * - {@link #TTY_MODE_HCO} |
| 264 | * - {@link #TTY_MODE_VCO} |
| 265 | * |
| 266 | * @hide |
| 267 | */ |
| 268 | public static final String EXTRA_CURRENT_TTY_MODE = |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 269 | "android.telecom.intent.extra.CURRENT_TTY_MODE"; |
| Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 270 | |
| 271 | /** |
| Santos Cordon | 96efb48 | 2014-07-19 14:57:05 -0700 | [diff] [blame] | 272 | * Broadcast intent action indicating that the TTY preferred operating mode has changed. An |
| 273 | * intent extra provides the new mode as an int. |
| Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 274 | * |
| Santos Cordon | 96efb48 | 2014-07-19 14:57:05 -0700 | [diff] [blame] | 275 | * @see #EXTRA_TTY_PREFERRED_MODE |
| Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 276 | * @hide |
| 277 | */ |
| 278 | public static final String ACTION_TTY_PREFERRED_MODE_CHANGED = |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 279 | "android.telecom.action.TTY_PREFERRED_MODE_CHANGED"; |
| Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 280 | |
| 281 | /** |
| Santos Cordon | 96efb48 | 2014-07-19 14:57:05 -0700 | [diff] [blame] | 282 | * The lookup key for an int that indicates preferred TTY mode. Valid modes are: - |
| 283 | * {@link #TTY_MODE_OFF} - {@link #TTY_MODE_FULL} - {@link #TTY_MODE_HCO} - |
| 284 | * {@link #TTY_MODE_VCO} |
| Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 285 | * |
| 286 | * @hide |
| 287 | */ |
| 288 | public static final String EXTRA_TTY_PREFERRED_MODE = |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 289 | "android.telecom.intent.extra.TTY_PREFERRED"; |
| Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 290 | |
| Nancy Chen | 9d568c0 | 2014-09-08 14:17:59 -0700 | [diff] [blame] | 291 | /** |
| 292 | * The following 4 constants define how properties such as phone numbers and names are |
| 293 | * displayed to the user. |
| 294 | */ |
| 295 | |
| 296 | /** Property is displayed normally. */ |
| 297 | public static final int PRESENTATION_ALLOWED = 1; |
| 298 | |
| 299 | /** Property was blocked. */ |
| 300 | public static final int PRESENTATION_RESTRICTED = 2; |
| 301 | |
| 302 | /** Presentation was not specified or is unknown. */ |
| 303 | public static final int PRESENTATION_UNKNOWN = 3; |
| 304 | |
| 305 | /** Property should be displayed as a pay phone. */ |
| 306 | public static final int PRESENTATION_PAYPHONE = 4; |
| 307 | |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 308 | private static final String TAG = "TelecomManager"; |
| Yorke Lee | b4ce143 | 2014-06-09 13:53:23 -0700 | [diff] [blame] | 309 | |
| 310 | private final Context mContext; |
| Yorke Lee | b4ce143 | 2014-06-09 13:53:23 -0700 | [diff] [blame] | 311 | |
| Santos Cordon | 6c7a388 | 2014-06-25 15:30:08 -0700 | [diff] [blame] | 312 | /** |
| 313 | * @hide |
| 314 | */ |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 315 | public static TelecomManager from(Context context) { |
| 316 | return (TelecomManager) context.getSystemService(Context.TELECOM_SERVICE); |
| Yorke Lee | b4ce143 | 2014-06-09 13:53:23 -0700 | [diff] [blame] | 317 | } |
| Santos Cordon | 6c7a388 | 2014-06-25 15:30:08 -0700 | [diff] [blame] | 318 | |
| 319 | /** |
| 320 | * @hide |
| 321 | */ |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 322 | public TelecomManager(Context context) { |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 323 | Context appContext = context.getApplicationContext(); |
| 324 | if (appContext != null) { |
| 325 | mContext = appContext; |
| 326 | } else { |
| 327 | mContext = context; |
| 328 | } |
| 329 | } |
| 330 | |
| 331 | /** |
| Santos Cordon | 96efb48 | 2014-07-19 14:57:05 -0700 | [diff] [blame] | 332 | * Return the {@link PhoneAccount} which is the user-chosen default for making outgoing phone |
| Nancy Chen | 513c892 | 2014-09-17 14:47:20 -0700 | [diff] [blame] | 333 | * calls with a specified URI scheme. |
| Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 334 | * <p> |
| Santos Cordon | 96efb48 | 2014-07-19 14:57:05 -0700 | [diff] [blame] | 335 | * Apps must be prepared for this method to return {@code null}, indicating that there currently |
| Nancy Chen | 513c892 | 2014-09-17 14:47:20 -0700 | [diff] [blame] | 336 | * exists no user-chosen default {@code PhoneAccount}. |
| Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 337 | * <p> |
| Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 338 | * @param uriScheme The URI scheme. |
| Nancy Chen | 513c892 | 2014-09-17 14:47:20 -0700 | [diff] [blame] | 339 | * @return The {@link PhoneAccountHandle} corresponding to the user-chosen default for outgoing |
| 340 | * phone calls for a specified URI scheme. |
| Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 341 | */ |
| Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 342 | public PhoneAccountHandle getDefaultOutgoingPhoneAccount(String uriScheme) { |
| Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 343 | try { |
| 344 | if (isServiceConnected()) { |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 345 | return getTelecomService().getDefaultOutgoingPhoneAccount(uriScheme); |
| Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 346 | } |
| 347 | } catch (RemoteException e) { |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 348 | Log.e(TAG, "Error calling ITelecomService#getDefaultOutgoingPhoneAccount", e); |
| Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 349 | } |
| 350 | return null; |
| 351 | } |
| 352 | |
| 353 | /** |
| Andrew Lee | d4abbfb | 2014-09-03 14:58:27 -0700 | [diff] [blame] | 354 | * Return the {@link PhoneAccount} which is the user-chosen default for making outgoing phone |
| 355 | * calls. This {@code PhoneAccount} will always be a member of the list which is returned from |
| Nancy Chen | 210ef03 | 2014-09-15 17:58:42 -0700 | [diff] [blame] | 356 | * calling {@link #getCallCapablePhoneAccounts()} |
| Andrew Lee | d4abbfb | 2014-09-03 14:58:27 -0700 | [diff] [blame] | 357 | * |
| 358 | * Apps must be prepared for this method to return {@code null}, indicating that there currently |
| 359 | * exists no user-chosen default {@code PhoneAccount}. |
| 360 | * |
| 361 | * @return The user outgoing phone account selected by the user. |
| 362 | * @hide |
| 363 | */ |
| 364 | public PhoneAccountHandle getUserSelectedOutgoingPhoneAccount() { |
| 365 | try { |
| 366 | if (isServiceConnected()) { |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 367 | return getTelecomService().getUserSelectedOutgoingPhoneAccount(); |
| Andrew Lee | d4abbfb | 2014-09-03 14:58:27 -0700 | [diff] [blame] | 368 | } |
| 369 | } catch (RemoteException e) { |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 370 | Log.e(TAG, "Error calling ITelecomService#getUserSelectedOutgoingPhoneAccount", e); |
| Andrew Lee | d4abbfb | 2014-09-03 14:58:27 -0700 | [diff] [blame] | 371 | } |
| 372 | return null; |
| 373 | } |
| 374 | |
| 375 | /** |
| Andrew Lee | 59cac3a | 2014-08-28 16:50:10 -0700 | [diff] [blame] | 376 | * Sets the default account for making outgoing phone calls. |
| 377 | * @hide |
| 378 | */ |
| Andrew Lee | d4abbfb | 2014-09-03 14:58:27 -0700 | [diff] [blame] | 379 | public void setUserSelectedOutgoingPhoneAccount(PhoneAccountHandle accountHandle) { |
| Andrew Lee | 59cac3a | 2014-08-28 16:50:10 -0700 | [diff] [blame] | 380 | try { |
| 381 | if (isServiceConnected()) { |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 382 | getTelecomService().setUserSelectedOutgoingPhoneAccount(accountHandle); |
| Andrew Lee | 59cac3a | 2014-08-28 16:50:10 -0700 | [diff] [blame] | 383 | } |
| 384 | } catch (RemoteException e) { |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 385 | Log.e(TAG, "Error calling ITelecomService#setUserSelectedOutgoingPhoneAccount"); |
| Andrew Lee | 59cac3a | 2014-08-28 16:50:10 -0700 | [diff] [blame] | 386 | } |
| 387 | } |
| 388 | |
| 389 | /** |
| Andrew Lee | 59cac3a | 2014-08-28 16:50:10 -0700 | [diff] [blame] | 390 | * Returns the current SIM call manager. Apps must be prepared for this method to return |
| 391 | * {@code null}, indicating that there currently exists no user-chosen default |
| 392 | * {@code PhoneAccount}. |
| 393 | * @return The phone account handle of the current sim call manager. |
| 394 | * @hide |
| 395 | */ |
| 396 | public PhoneAccountHandle getSimCallManager() { |
| 397 | try { |
| 398 | if (isServiceConnected()) { |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 399 | return getTelecomService().getSimCallManager(); |
| Andrew Lee | 59cac3a | 2014-08-28 16:50:10 -0700 | [diff] [blame] | 400 | } |
| 401 | } catch (RemoteException e) { |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 402 | Log.e(TAG, "Error calling ITelecomService#getSimCallManager"); |
| Andrew Lee | 59cac3a | 2014-08-28 16:50:10 -0700 | [diff] [blame] | 403 | } |
| 404 | return null; |
| 405 | } |
| 406 | |
| 407 | /** |
| 408 | * Sets the SIM call manager to the specified phone account. |
| 409 | * @param accountHandle The phone account handle of the account to set as the sim call manager. |
| 410 | * @hide |
| 411 | */ |
| 412 | public void setSimCallManager(PhoneAccountHandle accountHandle) { |
| 413 | try { |
| 414 | if (isServiceConnected()) { |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 415 | getTelecomService().setSimCallManager(accountHandle); |
| Andrew Lee | 59cac3a | 2014-08-28 16:50:10 -0700 | [diff] [blame] | 416 | } |
| 417 | } catch (RemoteException e) { |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 418 | Log.e(TAG, "Error calling ITelecomService#setSimCallManager"); |
| Andrew Lee | 59cac3a | 2014-08-28 16:50:10 -0700 | [diff] [blame] | 419 | } |
| 420 | } |
| 421 | |
| 422 | /** |
| 423 | * Returns the list of registered SIM call managers. |
| 424 | * @return List of registered SIM call managers. |
| 425 | * @hide |
| 426 | */ |
| 427 | public List<PhoneAccountHandle> getSimCallManagers() { |
| 428 | try { |
| 429 | if (isServiceConnected()) { |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 430 | return getTelecomService().getSimCallManagers(); |
| Andrew Lee | 59cac3a | 2014-08-28 16:50:10 -0700 | [diff] [blame] | 431 | } |
| 432 | } catch (RemoteException e) { |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 433 | Log.e(TAG, "Error calling ITelecomService#getSimCallManagers"); |
| Andrew Lee | 59cac3a | 2014-08-28 16:50:10 -0700 | [diff] [blame] | 434 | } |
| 435 | return new ArrayList<>(); |
| 436 | } |
| 437 | |
| 438 | /** |
| Evan Charlton | eb0a8d56 | 2014-09-04 12:03:34 -0700 | [diff] [blame] | 439 | * Returns the current connection manager. Apps must be prepared for this method to return |
| 440 | * {@code null}, indicating that there currently exists no user-chosen default |
| 441 | * {@code PhoneAccount}. |
| 442 | * |
| 443 | * @return The phone account handle of the current connection manager. |
| 444 | */ |
| 445 | public PhoneAccountHandle getConnectionManager() { |
| 446 | return getSimCallManager(); |
| 447 | } |
| 448 | |
| 449 | /** |
| Nancy Chen | 210ef03 | 2014-09-15 17:58:42 -0700 | [diff] [blame] | 450 | * Returns a list of the {@link PhoneAccountHandle}s which can be used to make and receive phone |
| 451 | * calls which support the specified URI scheme. |
| Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 452 | * <P> |
| 453 | * For example, invoking with {@code "tel"} will find all {@link PhoneAccountHandle}s which |
| 454 | * support telephone calls (e.g. URIs such as {@code tel:555-555-1212}). Invoking with |
| 455 | * {@code "sip"} will find all {@link PhoneAccountHandle}s which support SIP calls (e.g. URIs |
| 456 | * such as {@code sip:example@sipexample.com}). |
| 457 | * |
| 458 | * @param uriScheme The URI scheme. |
| 459 | * @return A list of {@code PhoneAccountHandle} objects supporting the URI scheme. |
| 460 | */ |
| 461 | public List<PhoneAccountHandle> getPhoneAccountsSupportingScheme(String uriScheme) { |
| 462 | try { |
| 463 | if (isServiceConnected()) { |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 464 | return getTelecomService().getPhoneAccountsSupportingScheme(uriScheme); |
| Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 465 | } |
| 466 | } catch (RemoteException e) { |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 467 | Log.e(TAG, "Error calling ITelecomService#getPhoneAccountsSupportingScheme", e); |
| Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 468 | } |
| 469 | return new ArrayList<>(); |
| 470 | } |
| 471 | |
| Nancy Chen | 513c892 | 2014-09-17 14:47:20 -0700 | [diff] [blame] | 472 | |
| 473 | /** |
| 474 | * Return a list of {@link PhoneAccountHandle}s which can be used to make and receive phone |
| 475 | * calls. |
| 476 | * |
| 477 | * @see #EXTRA_PHONE_ACCOUNT_HANDLE |
| 478 | * @return A list of {@code PhoneAccountHandle} objects. |
| 479 | * |
| 480 | * @hide |
| 481 | */ |
| 482 | public List<PhoneAccountHandle> getCallCapablePhoneAccounts() { |
| 483 | try { |
| 484 | if (isServiceConnected()) { |
| 485 | return getTelecomService().getCallCapablePhoneAccounts(); |
| 486 | } |
| 487 | } catch (RemoteException e) { |
| 488 | Log.e(TAG, "Error calling ITelecomService#getCallCapablePhoneAccounts", e); |
| 489 | } |
| 490 | return new ArrayList<>(); |
| 491 | } |
| 492 | |
| Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 493 | /** |
| Nancy Chen | 210ef03 | 2014-09-15 17:58:42 -0700 | [diff] [blame] | 494 | * Determine whether the device has more than one account registered that can make and receive |
| 495 | * phone calls. |
| Nancy Chen | 6080118 | 2014-07-22 16:56:49 -0700 | [diff] [blame] | 496 | * |
| Nancy Chen | 210ef03 | 2014-09-15 17:58:42 -0700 | [diff] [blame] | 497 | * @return {@code true} if the device has more than one account registered and {@code false} |
| 498 | * otherwise. |
| Nancy Chen | 6080118 | 2014-07-22 16:56:49 -0700 | [diff] [blame] | 499 | */ |
| Nancy Chen | 210ef03 | 2014-09-15 17:58:42 -0700 | [diff] [blame] | 500 | public boolean hasMultipleCallCapableAccounts() { |
| 501 | return getCallCapablePhoneAccounts().size() > 1; |
| Nancy Chen | 6080118 | 2014-07-22 16:56:49 -0700 | [diff] [blame] | 502 | } |
| 503 | |
| 504 | /** |
| Nancy Chen | 513c892 | 2014-09-17 14:47:20 -0700 | [diff] [blame] | 505 | * Returns a list of all {@link PhoneAccount}s registered for the calling package. |
| 506 | * |
| 507 | * @return A list of {@code PhoneAccountHandle} objects. |
| 508 | */ |
| 509 | public List<PhoneAccountHandle> getPhoneAccountsForPackage() { |
| 510 | try { |
| 511 | if (isServiceConnected()) { |
| 512 | return getTelecomService().getPhoneAccountsForPackage(mContext.getPackageName()); |
| 513 | } |
| 514 | } catch (RemoteException e) { |
| 515 | Log.e(TAG, "Error calling ITelecomService#getPhoneAccountsForPackage", e); |
| 516 | } |
| 517 | return null; |
| 518 | } |
| 519 | |
| 520 | /** |
| Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 521 | * Return the {@link PhoneAccount} for a specified {@link PhoneAccountHandle}. Object includes |
| 522 | * resources which can be used in a user interface. |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 523 | * |
| Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 524 | * @param account The {@link PhoneAccountHandle}. |
| Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 525 | * @return The {@link PhoneAccount} object. |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 526 | */ |
| Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 527 | public PhoneAccount getPhoneAccount(PhoneAccountHandle account) { |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 528 | try { |
| 529 | if (isServiceConnected()) { |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 530 | return getTelecomService().getPhoneAccount(account); |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 531 | } |
| 532 | } catch (RemoteException e) { |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 533 | Log.e(TAG, "Error calling ITelecomService#getPhoneAccount", e); |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 534 | } |
| 535 | return null; |
| 536 | } |
| 537 | |
| 538 | /** |
| Nancy Chen | 210ef03 | 2014-09-15 17:58:42 -0700 | [diff] [blame] | 539 | * Returns a count of all {@link PhoneAccount}s. |
| Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 540 | * |
| Nancy Chen | 210ef03 | 2014-09-15 17:58:42 -0700 | [diff] [blame] | 541 | * @return The count of {@link PhoneAccount}s. |
| Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 542 | * @hide |
| 543 | */ |
| 544 | @SystemApi |
| 545 | public int getAllPhoneAccountsCount() { |
| 546 | try { |
| 547 | if (isServiceConnected()) { |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 548 | return getTelecomService().getAllPhoneAccountsCount(); |
| Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 549 | } |
| 550 | } catch (RemoteException e) { |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 551 | Log.e(TAG, "Error calling ITelecomService#getAllPhoneAccountsCount", e); |
| Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 552 | } |
| 553 | return 0; |
| 554 | } |
| 555 | |
| 556 | /** |
| 557 | * Returns a list of all {@link PhoneAccount}s. |
| 558 | * |
| 559 | * @return All {@link PhoneAccount}s. |
| 560 | * @hide |
| 561 | */ |
| 562 | @SystemApi |
| 563 | public List<PhoneAccount> getAllPhoneAccounts() { |
| 564 | try { |
| 565 | if (isServiceConnected()) { |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 566 | return getTelecomService().getAllPhoneAccounts(); |
| Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 567 | } |
| 568 | } catch (RemoteException e) { |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 569 | Log.e(TAG, "Error calling ITelecomService#getAllPhoneAccounts", e); |
| Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 570 | } |
| 571 | return Collections.EMPTY_LIST; |
| 572 | } |
| 573 | |
| 574 | /** |
| 575 | * Returns a list of all {@link PhoneAccountHandle}s. |
| 576 | * |
| 577 | * @return All {@link PhoneAccountHandle}s. |
| 578 | * @hide |
| 579 | */ |
| 580 | @SystemApi |
| 581 | public List<PhoneAccountHandle> getAllPhoneAccountHandles() { |
| 582 | try { |
| 583 | if (isServiceConnected()) { |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 584 | return getTelecomService().getAllPhoneAccountHandles(); |
| Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 585 | } |
| 586 | } catch (RemoteException e) { |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 587 | Log.e(TAG, "Error calling ITelecomService#getAllPhoneAccountHandles", e); |
| Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 588 | } |
| 589 | return Collections.EMPTY_LIST; |
| 590 | } |
| 591 | |
| 592 | /** |
| Santos Cordon | d9e614f | 2014-10-28 13:10:36 -0700 | [diff] [blame] | 593 | * Register a {@link PhoneAccount} for use by the system. When registering |
| 594 | * {@link PhoneAccount}s, existing registrations will be overwritten if the |
| 595 | * {@link PhoneAccountHandle} matches that of a {@link PhoneAccount} which is already |
| 596 | * registered. Once registered, the {@link PhoneAccount} is listed to the user as an option |
| 597 | * when placing calls. The user may still need to enable the {@link PhoneAccount} within |
| 598 | * the phone app settings before the account is usable. |
| 599 | * <p> |
| 600 | * A {@link SecurityException} will be thrown if an app tries to register a |
| 601 | * {@link PhoneAccountHandle} where the package name specified within |
| 602 | * {@link PhoneAccountHandle#getComponentName()} does not match the package name of the app. |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 603 | * |
| Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 604 | * @param account The complete {@link PhoneAccount}. |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 605 | */ |
| Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 606 | public void registerPhoneAccount(PhoneAccount account) { |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 607 | try { |
| 608 | if (isServiceConnected()) { |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 609 | getTelecomService().registerPhoneAccount(account); |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 610 | } |
| 611 | } catch (RemoteException e) { |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 612 | Log.e(TAG, "Error calling ITelecomService#registerPhoneAccount", e); |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 613 | } |
| 614 | } |
| 615 | |
| 616 | /** |
| Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 617 | * Remove a {@link PhoneAccount} registration from the system. |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 618 | * |
| Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 619 | * @param accountHandle A {@link PhoneAccountHandle} for the {@link PhoneAccount} to unregister. |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 620 | */ |
| Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 621 | public void unregisterPhoneAccount(PhoneAccountHandle accountHandle) { |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 622 | try { |
| 623 | if (isServiceConnected()) { |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 624 | getTelecomService().unregisterPhoneAccount(accountHandle); |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 625 | } |
| 626 | } catch (RemoteException e) { |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 627 | Log.e(TAG, "Error calling ITelecomService#unregisterPhoneAccount", e); |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 628 | } |
| 629 | } |
| 630 | |
| 631 | /** |
| Nancy Chen | 7ab1dc4 | 2014-09-09 18:18:26 -0700 | [diff] [blame] | 632 | * Remove all Accounts that belong to the calling package from the system. |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 633 | */ |
| Nancy Chen | 7ab1dc4 | 2014-09-09 18:18:26 -0700 | [diff] [blame] | 634 | public void clearAccounts() { |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 635 | try { |
| 636 | if (isServiceConnected()) { |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 637 | getTelecomService().clearAccounts(mContext.getPackageName()); |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 638 | } |
| 639 | } catch (RemoteException e) { |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 640 | Log.e(TAG, "Error calling ITelecomService#clearAccounts", e); |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 641 | } |
| 642 | } |
| 643 | |
| 644 | /** |
| Anthony Lee | 6727926 | 2014-10-27 11:28:40 -0700 | [diff] [blame] | 645 | * Remove all Accounts that belong to the specified package from the system. |
| 646 | * @hide |
| 647 | */ |
| 648 | public void clearAccountsForPackage(String packageName) { |
| 649 | try { |
| 650 | if (isServiceConnected() && !TextUtils.isEmpty(packageName)) { |
| 651 | getTelecomService().clearAccounts(packageName); |
| 652 | } |
| 653 | } catch (RemoteException e) { |
| 654 | Log.e(TAG, "Error calling ITelecomService#clearAccountsForPackage()", e); |
| 655 | } |
| 656 | } |
| 657 | |
| 658 | /** |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 659 | * @hide |
| 660 | */ |
| Santos Cordon | 6c7a388 | 2014-06-25 15:30:08 -0700 | [diff] [blame] | 661 | @SystemApi |
| 662 | public ComponentName getDefaultPhoneApp() { |
| 663 | try { |
| Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 664 | if (isServiceConnected()) { |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 665 | return getTelecomService().getDefaultPhoneApp(); |
| Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 666 | } |
| Santos Cordon | 6c7a388 | 2014-06-25 15:30:08 -0700 | [diff] [blame] | 667 | } catch (RemoteException e) { |
| 668 | Log.e(TAG, "RemoteException attempting to get the default phone app.", e); |
| 669 | } |
| 670 | return null; |
| 671 | } |
| 672 | |
| Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 673 | /** |
| Nancy Chen | 443e501 | 2014-10-15 15:48:21 -0700 | [diff] [blame] | 674 | * Return whether a given phone number is the configured voicemail number for a |
| 675 | * particular phone account. |
| 676 | * |
| 677 | * @param accountHandle The handle for the account to check the voicemail number against |
| 678 | * @param number The number to look up. |
| 679 | * |
| 680 | * @hide |
| 681 | */ |
| 682 | @SystemApi |
| 683 | public boolean isVoiceMailNumber(PhoneAccountHandle accountHandle, String number) { |
| 684 | try { |
| 685 | if (isServiceConnected()) { |
| 686 | return getTelecomService().isVoiceMailNumber(accountHandle, number); |
| 687 | } |
| 688 | } catch (RemoteException e) { |
| 689 | Log.e(TAG, "RemoteException calling isInCall().", e); |
| 690 | } |
| 691 | return false; |
| 692 | } |
| 693 | |
| 694 | /** |
| Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 695 | * Returns whether there is an ongoing phone call (can be in dialing, ringing, active or holding |
| 696 | * states). |
| Nancy Chen | 0eb1e40 | 2014-08-21 22:52:29 -0700 | [diff] [blame] | 697 | * <p> |
| 698 | * Requires permission: {@link android.Manifest.permission#READ_PHONE_STATE} |
| 699 | * </p> |
| Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 700 | */ |
| Nancy Chen | 0eb1e40 | 2014-08-21 22:52:29 -0700 | [diff] [blame] | 701 | public boolean isInCall() { |
| Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 702 | try { |
| 703 | if (isServiceConnected()) { |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 704 | return getTelecomService().isInCall(); |
| Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 705 | } |
| 706 | } catch (RemoteException e) { |
| Yorke Lee | 2ae312e | 2014-09-12 17:58:48 -0700 | [diff] [blame] | 707 | Log.e(TAG, "RemoteException calling isInCall().", e); |
| Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 708 | } |
| 709 | return false; |
| 710 | } |
| 711 | |
| 712 | /** |
| Yorke Lee | 2ae312e | 2014-09-12 17:58:48 -0700 | [diff] [blame] | 713 | * Returns one of the following constants that represents the current state of Telecom: |
| 714 | * |
| 715 | * {@link TelephonyManager#CALL_STATE_RINGING} |
| 716 | * {@link TelephonyManager#CALL_STATE_OFFHOOK} |
| 717 | * {@link TelephonyManager#CALL_STATE_IDLE} |
| Yorke Lee | 7c72c2d | 2014-10-28 14:12:02 -0700 | [diff] [blame] | 718 | * |
| 719 | * Note that this API does not require the |
| 720 | * {@link android.Manifest.permission#READ_PHONE_STATE} permission. This is intentional, to |
| 721 | * preserve the behavior of {@link TelephonyManager#getCallState()}, which also did not require |
| 722 | * the permission. |
| Yorke Lee | 2ae312e | 2014-09-12 17:58:48 -0700 | [diff] [blame] | 723 | * @hide |
| 724 | */ |
| 725 | @SystemApi |
| 726 | public int getCallState() { |
| 727 | try { |
| 728 | if (isServiceConnected()) { |
| 729 | return getTelecomService().getCallState(); |
| 730 | } |
| 731 | } catch (RemoteException e) { |
| 732 | Log.d(TAG, "RemoteException calling getCallState().", e); |
| 733 | } |
| 734 | return TelephonyManager.CALL_STATE_IDLE; |
| 735 | } |
| 736 | |
| 737 | /** |
| Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 738 | * Returns whether there currently exists is a ringing incoming-call. |
| 739 | * |
| 740 | * @hide |
| 741 | */ |
| 742 | @SystemApi |
| 743 | public boolean isRinging() { |
| 744 | try { |
| 745 | if (isServiceConnected()) { |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 746 | return getTelecomService().isRinging(); |
| Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 747 | } |
| 748 | } catch (RemoteException e) { |
| 749 | Log.e(TAG, "RemoteException attempting to get ringing state of phone app.", e); |
| 750 | } |
| 751 | return false; |
| 752 | } |
| 753 | |
| 754 | /** |
| Santos Cordon | 96efb48 | 2014-07-19 14:57:05 -0700 | [diff] [blame] | 755 | * Ends an ongoing call. |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 756 | * TODO: L-release - need to convert all invocations of ITelecomService#endCall to use this |
| Santos Cordon | 96efb48 | 2014-07-19 14:57:05 -0700 | [diff] [blame] | 757 | * method (clockwork & gearhead). |
| Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 758 | * @hide |
| 759 | */ |
| 760 | @SystemApi |
| 761 | public boolean endCall() { |
| 762 | try { |
| 763 | if (isServiceConnected()) { |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 764 | return getTelecomService().endCall(); |
| Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 765 | } |
| 766 | } catch (RemoteException e) { |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 767 | Log.e(TAG, "Error calling ITelecomService#endCall", e); |
| Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 768 | } |
| 769 | return false; |
| 770 | } |
| 771 | |
| 772 | /** |
| 773 | * If there is a ringing incoming call, this method accepts the call on behalf of the user. |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 774 | * TODO: L-release - need to convert all invocation of ITelecmmService#answerRingingCall to use |
| Santos Cordon | 96efb48 | 2014-07-19 14:57:05 -0700 | [diff] [blame] | 775 | * this method (clockwork & gearhead). |
| Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 776 | * |
| 777 | * @hide |
| 778 | */ |
| 779 | @SystemApi |
| 780 | public void acceptRingingCall() { |
| 781 | try { |
| 782 | if (isServiceConnected()) { |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 783 | getTelecomService().acceptRingingCall(); |
| Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 784 | } |
| 785 | } catch (RemoteException e) { |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 786 | Log.e(TAG, "Error calling ITelecomService#acceptRingingCall", e); |
| Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 787 | } |
| 788 | } |
| 789 | |
| 790 | /** |
| 791 | * Silences the ringer if a ringing call exists. |
| 792 | * |
| 793 | * @hide |
| 794 | */ |
| 795 | @SystemApi |
| 796 | public void silenceRinger() { |
| 797 | try { |
| 798 | if (isServiceConnected()) { |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 799 | getTelecomService().silenceRinger(); |
| Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 800 | } |
| 801 | } catch (RemoteException e) { |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 802 | Log.e(TAG, "Error calling ITelecomService#silenceRinger", e); |
| Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 803 | } |
| 804 | } |
| 805 | |
| Sailesh Nepal | 001bbbb | 2014-07-15 14:40:39 -0700 | [diff] [blame] | 806 | /** |
| 807 | * Returns whether TTY is supported on this device. |
| 808 | * |
| 809 | * @hide |
| 810 | */ |
| 811 | @SystemApi |
| 812 | public boolean isTtySupported() { |
| 813 | try { |
| 814 | if (isServiceConnected()) { |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 815 | return getTelecomService().isTtySupported(); |
| Sailesh Nepal | 001bbbb | 2014-07-15 14:40:39 -0700 | [diff] [blame] | 816 | } |
| 817 | } catch (RemoteException e) { |
| 818 | Log.e(TAG, "RemoteException attempting to get TTY supported state.", e); |
| 819 | } |
| 820 | return false; |
| 821 | } |
| 822 | |
| 823 | /** |
| 824 | * Returns the current TTY mode of the device. For TTY to be on the user must enable it in |
| Santos Cordon | 96efb48 | 2014-07-19 14:57:05 -0700 | [diff] [blame] | 825 | * settings and have a wired headset plugged in. |
| 826 | * Valid modes are: |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 827 | * - {@link TelecomManager#TTY_MODE_OFF} |
| 828 | * - {@link TelecomManager#TTY_MODE_FULL} |
| 829 | * - {@link TelecomManager#TTY_MODE_HCO} |
| 830 | * - {@link TelecomManager#TTY_MODE_VCO} |
| Sailesh Nepal | 001bbbb | 2014-07-15 14:40:39 -0700 | [diff] [blame] | 831 | * @hide |
| 832 | */ |
| 833 | public int getCurrentTtyMode() { |
| 834 | try { |
| 835 | if (isServiceConnected()) { |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 836 | return getTelecomService().getCurrentTtyMode(); |
| Sailesh Nepal | 001bbbb | 2014-07-15 14:40:39 -0700 | [diff] [blame] | 837 | } |
| 838 | } catch (RemoteException e) { |
| 839 | Log.e(TAG, "RemoteException attempting to get the current TTY mode.", e); |
| 840 | } |
| Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 841 | return TTY_MODE_OFF; |
| Sailesh Nepal | 001bbbb | 2014-07-15 14:40:39 -0700 | [diff] [blame] | 842 | } |
| 843 | |
| Santos Cordon | 96efb48 | 2014-07-19 14:57:05 -0700 | [diff] [blame] | 844 | /** |
| 845 | * Registers a new incoming call. A {@link ConnectionService} should invoke this method when it |
| 846 | * has an incoming call. The specified {@link PhoneAccountHandle} must have been registered |
| Nancy Chen | 210ef03 | 2014-09-15 17:58:42 -0700 | [diff] [blame] | 847 | * with {@link #registerPhoneAccount}. Once invoked, this method will cause the system to bind |
| 848 | * to the {@link ConnectionService} associated with the {@link PhoneAccountHandle} and request |
| Santos Cordon | 96efb48 | 2014-07-19 14:57:05 -0700 | [diff] [blame] | 849 | * additional information about the call (See |
| 850 | * {@link ConnectionService#onCreateIncomingConnection}) before starting the incoming call UI. |
| 851 | * |
| 852 | * @param phoneAccount A {@link PhoneAccountHandle} registered with |
| 853 | * {@link #registerPhoneAccount}. |
| 854 | * @param extras A bundle that will be passed through to |
| 855 | * {@link ConnectionService#onCreateIncomingConnection}. |
| 856 | */ |
| 857 | public void addNewIncomingCall(PhoneAccountHandle phoneAccount, Bundle extras) { |
| 858 | try { |
| 859 | if (isServiceConnected()) { |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 860 | getTelecomService().addNewIncomingCall( |
| Santos Cordon | 96efb48 | 2014-07-19 14:57:05 -0700 | [diff] [blame] | 861 | phoneAccount, extras == null ? new Bundle() : extras); |
| 862 | } |
| 863 | } catch (RemoteException e) { |
| 864 | Log.e(TAG, "RemoteException adding a new incoming call: " + phoneAccount, e); |
| 865 | } |
| 866 | } |
| 867 | |
| Nancy Chen | 0eb1e40 | 2014-08-21 22:52:29 -0700 | [diff] [blame] | 868 | /** |
| Yorke Lee | c3cf982 | 2014-10-02 09:38:39 -0700 | [diff] [blame] | 869 | * Registers a new unknown call with Telecom. This can only be called by the system Telephony |
| 870 | * service. This is invoked when Telephony detects a new unknown connection that was neither |
| 871 | * a new incoming call, nor an user-initiated outgoing call. |
| 872 | * |
| 873 | * @param phoneAccount A {@link PhoneAccountHandle} registered with |
| 874 | * {@link #registerPhoneAccount}. |
| 875 | * @param extras A bundle that will be passed through to |
| 876 | * {@link ConnectionService#onCreateIncomingConnection}. |
| 877 | * @hide |
| 878 | */ |
| 879 | @SystemApi |
| 880 | public void addNewUnknownCall(PhoneAccountHandle phoneAccount, Bundle extras) { |
| 881 | try { |
| 882 | if (isServiceConnected()) { |
| 883 | getTelecomService().addNewUnknownCall( |
| 884 | phoneAccount, extras == null ? new Bundle() : extras); |
| 885 | } |
| 886 | } catch (RemoteException e) { |
| 887 | Log.e(TAG, "RemoteException adding a new unknown call: " + phoneAccount, e); |
| 888 | } |
| 889 | } |
| 890 | |
| 891 | /** |
| Nancy Chen | 0eb1e40 | 2014-08-21 22:52:29 -0700 | [diff] [blame] | 892 | * Processes the specified dial string as an MMI code. |
| 893 | * MMI codes are any sequence of characters entered into the dialpad that contain a "*" or "#". |
| 894 | * Some of these sequences launch special behavior through handled by Telephony. |
| Nancy Chen | 95e8a67 | 2014-10-16 18:38:21 -0700 | [diff] [blame] | 895 | * This method uses the default subscription. |
| Nancy Chen | 0eb1e40 | 2014-08-21 22:52:29 -0700 | [diff] [blame] | 896 | * <p> |
| 897 | * Requires that the method-caller be set as the system dialer app. |
| 898 | * </p> |
| 899 | * |
| 900 | * @param dialString The digits to dial. |
| 901 | * @return True if the digits were processed as an MMI code, false otherwise. |
| 902 | */ |
| 903 | public boolean handleMmi(String dialString) { |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 904 | ITelecomService service = getTelecomService(); |
| Nancy Chen | 0eb1e40 | 2014-08-21 22:52:29 -0700 | [diff] [blame] | 905 | if (service != null) { |
| 906 | try { |
| 907 | return service.handlePinMmi(dialString); |
| 908 | } catch (RemoteException e) { |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 909 | Log.e(TAG, "Error calling ITelecomService#handlePinMmi", e); |
| Nancy Chen | 0eb1e40 | 2014-08-21 22:52:29 -0700 | [diff] [blame] | 910 | } |
| 911 | } |
| 912 | return false; |
| 913 | } |
| 914 | |
| 915 | /** |
| Nancy Chen | 95e8a67 | 2014-10-16 18:38:21 -0700 | [diff] [blame] | 916 | * Processes the specified dial string as an MMI code. |
| 917 | * MMI codes are any sequence of characters entered into the dialpad that contain a "*" or "#". |
| 918 | * Some of these sequences launch special behavior through handled by Telephony. |
| 919 | * <p> |
| 920 | * Requires that the method-caller be set as the system dialer app. |
| 921 | * </p> |
| 922 | * |
| 923 | * @param accountHandle The handle for the account the MMI code should apply to. |
| 924 | * @param dialString The digits to dial. |
| 925 | * @return True if the digits were processed as an MMI code, false otherwise. |
| Nancy Chen | 95e8a67 | 2014-10-16 18:38:21 -0700 | [diff] [blame] | 926 | */ |
| 927 | public boolean handleMmi(PhoneAccountHandle accountHandle, String dialString) { |
| 928 | ITelecomService service = getTelecomService(); |
| 929 | if (service != null) { |
| 930 | try { |
| 931 | return service.handlePinMmiForPhoneAccount(accountHandle, dialString); |
| 932 | } catch (RemoteException e) { |
| 933 | Log.e(TAG, "Error calling ITelecomService#handlePinMmi", e); |
| 934 | } |
| 935 | } |
| 936 | return false; |
| 937 | } |
| 938 | |
| 939 | /** |
| Nancy Chen | b2299c1 | 2014-10-29 18:22:11 -0700 | [diff] [blame] | 940 | * @param accountHandle The handle for the account to derive an adn query URI for or |
| 941 | * {@code null} to return a URI which will use the default account. |
| 942 | * @return The URI (with the content:// scheme) specific to the specified {@link PhoneAccount} |
| 943 | * for the the content retrieve. |
| 944 | */ |
| 945 | public Uri getAdnUriForPhoneAccount(PhoneAccountHandle accountHandle) { |
| 946 | ITelecomService service = getTelecomService(); |
| 947 | if (service != null && accountHandle != null) { |
| 948 | try { |
| 949 | return service.getAdnUriForPhoneAccount(accountHandle); |
| 950 | } catch (RemoteException e) { |
| 951 | Log.e(TAG, "Error calling ITelecomService#getAdnUriForPhoneAccount", e); |
| 952 | } |
| 953 | } |
| 954 | return Uri.parse("content://icc/adn"); |
| 955 | } |
| 956 | |
| 957 | /** |
| Nancy Chen | 0eb1e40 | 2014-08-21 22:52:29 -0700 | [diff] [blame] | 958 | * Removes the missed-call notification if one is present. |
| 959 | * <p> |
| 960 | * Requires that the method-caller be set as the system dialer app. |
| 961 | * </p> |
| 962 | */ |
| 963 | public void cancelMissedCallsNotification() { |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 964 | ITelecomService service = getTelecomService(); |
| Nancy Chen | 0eb1e40 | 2014-08-21 22:52:29 -0700 | [diff] [blame] | 965 | if (service != null) { |
| 966 | try { |
| 967 | service.cancelMissedCallsNotification(); |
| 968 | } catch (RemoteException e) { |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 969 | Log.e(TAG, "Error calling ITelecomService#cancelMissedCallsNotification", e); |
| Nancy Chen | 0eb1e40 | 2014-08-21 22:52:29 -0700 | [diff] [blame] | 970 | } |
| 971 | } |
| 972 | } |
| 973 | |
| 974 | /** |
| 975 | * Brings the in-call screen to the foreground if there is an ongoing call. If there is |
| 976 | * currently no ongoing call, then this method does nothing. |
| 977 | * <p> |
| 978 | * Requires that the method-caller be set as the system dialer app or have the |
| 979 | * {@link android.Manifest.permission#READ_PHONE_STATE} permission. |
| 980 | * </p> |
| 981 | * |
| 982 | * @param showDialpad Brings up the in-call dialpad as part of showing the in-call screen. |
| 983 | */ |
| 984 | public void showInCallScreen(boolean showDialpad) { |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 985 | ITelecomService service = getTelecomService(); |
| Nancy Chen | 0eb1e40 | 2014-08-21 22:52:29 -0700 | [diff] [blame] | 986 | if (service != null) { |
| 987 | try { |
| 988 | service.showInCallScreen(showDialpad); |
| 989 | } catch (RemoteException e) { |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 990 | Log.e(TAG, "Error calling ITelecomService#showCallScreen", e); |
| Nancy Chen | 0eb1e40 | 2014-08-21 22:52:29 -0700 | [diff] [blame] | 991 | } |
| 992 | } |
| 993 | } |
| 994 | |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 995 | private ITelecomService getTelecomService() { |
| 996 | return ITelecomService.Stub.asInterface(ServiceManager.getService(Context.TELECOM_SERVICE)); |
| Santos Cordon | 6c7a388 | 2014-06-25 15:30:08 -0700 | [diff] [blame] | 997 | } |
| Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 998 | |
| 999 | private boolean isServiceConnected() { |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 1000 | boolean isConnected = getTelecomService() != null; |
| Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 1001 | if (!isConnected) { |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 1002 | Log.w(TAG, "Telecom Service not found."); |
| Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 1003 | } |
| 1004 | return isConnected; |
| 1005 | } |
| Evan Charlton | 235c159 | 2014-09-05 15:41:23 +0000 | [diff] [blame] | 1006 | } |