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 | |
| 15 | package android.telecomm; |
| 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; |
Santos Cordon | 96efb48 | 2014-07-19 14:57:05 -0700 | [diff] [blame] | 20 | import android.os.Bundle; |
Santos Cordon | 6c7a388 | 2014-06-25 15:30:08 -0700 | [diff] [blame] | 21 | import android.os.RemoteException; |
| 22 | import android.os.ServiceManager; |
| 23 | import android.util.Log; |
Yorke Lee | b4ce143 | 2014-06-09 13:53:23 -0700 | [diff] [blame] | 24 | |
| 25 | import com.android.internal.telecomm.ITelecommService; |
| 26 | |
Jay Shrauner | 7746a94 | 2014-08-26 12:15:15 -0700 | [diff] [blame] | 27 | import java.util.ArrayList; |
Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame^] | 28 | import java.util.Collections; |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 29 | import java.util.List; |
| 30 | |
Yorke Lee | b4ce143 | 2014-06-09 13:53:23 -0700 | [diff] [blame] | 31 | /** |
| 32 | * Provides access to Telecomm-related functionality. |
Santos Cordon | 96efb48 | 2014-07-19 14:57:05 -0700 | [diff] [blame] | 33 | * TODO: Move this all into PhoneManager. |
Yorke Lee | b4ce143 | 2014-06-09 13:53:23 -0700 | [diff] [blame] | 34 | */ |
| 35 | public class TelecommManager { |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 36 | |
Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 37 | /** |
Santos Cordon | 96efb48 | 2014-07-19 14:57:05 -0700 | [diff] [blame] | 38 | * Activity action: Starts the UI for handing an incoming call. This intent starts the in-call |
| 39 | * UI by notifying the Telecomm system that an incoming call exists for a specific call service |
| 40 | * (see {@link android.telecomm.ConnectionService}). Telecomm reads the Intent extras to find |
| 41 | * and bind to the appropriate {@link android.telecomm.ConnectionService} which Telecomm will |
| 42 | * ultimately use to control and get information about the call. |
| 43 | * <p> |
| 44 | * Input: get*Extra field {@link #EXTRA_PHONE_ACCOUNT_HANDLE} contains the component name of the |
| 45 | * {@link android.telecomm.ConnectionService} that Telecomm should bind to. Telecomm will then |
Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 46 | * ask the connection service for more information about the call prior to showing any UI. |
| 47 | * |
Santos Cordon | 96efb48 | 2014-07-19 14:57:05 -0700 | [diff] [blame] | 48 | * @hide |
Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 49 | */ |
Nancy Chen | 1d834f5 | 2014-09-05 11:03:21 -0700 | [diff] [blame] | 50 | public static final String ACTION_INCOMING_CALL = "android.telecomm.action.INCOMING_CALL"; |
Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 51 | |
| 52 | /** |
Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 53 | * The {@link android.content.Intent} action used to configure a |
| 54 | * {@link android.telecomm.ConnectionService}. |
Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 55 | */ |
| 56 | public static final String ACTION_CONNECTION_SERVICE_CONFIGURE = |
Nancy Chen | 1d834f5 | 2014-09-05 11:03:21 -0700 | [diff] [blame] | 57 | "android.telecomm.action.CONNECTION_SERVICE_CONFIGURE"; |
Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 58 | |
| 59 | /** |
Yorke Lee | 3818a892 | 2014-07-21 15:57:17 -0700 | [diff] [blame] | 60 | * The {@link android.content.Intent} action used to show the call settings page. |
| 61 | */ |
| 62 | public static final String ACTION_SHOW_CALL_SETTINGS = |
Nancy Chen | 1d834f5 | 2014-09-05 11:03:21 -0700 | [diff] [blame] | 63 | "android.telecomm.action.SHOW_CALL_SETTINGS"; |
Yorke Lee | 3818a892 | 2014-07-21 15:57:17 -0700 | [diff] [blame] | 64 | |
| 65 | /** |
Evan Charlton | 6d8604f | 2014-09-04 12:38:17 -0700 | [diff] [blame] | 66 | * The {@link android.content.Intent} action used to show the settings page used to configure |
| 67 | * {@link PhoneAccount} preferences. |
| 68 | */ |
| 69 | public static final String ACTION_CHANGE_PHONE_ACCOUNTS = |
Nancy Chen | 1d834f5 | 2014-09-05 11:03:21 -0700 | [diff] [blame] | 70 | "android.telecomm.action.CHANGE_PHONE_ACCOUNTS"; |
Evan Charlton | 6d8604f | 2014-09-04 12:38:17 -0700 | [diff] [blame] | 71 | |
| 72 | /** |
Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 73 | * Optional extra for {@link android.content.Intent#ACTION_CALL} containing a boolean that |
| 74 | * 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] | 75 | */ |
| 76 | public static final String EXTRA_START_CALL_WITH_SPEAKERPHONE = |
Nancy Chen | 1d834f5 | 2014-09-05 11:03:21 -0700 | [diff] [blame] | 77 | "android.telecomm.extra.START_CALL_WITH_SPEAKERPHONE"; |
Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 78 | |
| 79 | /** |
Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 80 | * Optional extra for {@link android.content.Intent#ACTION_CALL} containing an integer that |
| 81 | * determines the desired video state for an outgoing call. |
Santos Cordon | 96efb48 | 2014-07-19 14:57:05 -0700 | [diff] [blame] | 82 | * Valid options: |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 83 | * {@link VideoProfile.VideoState#AUDIO_ONLY}, |
| 84 | * {@link VideoProfile.VideoState#BIDIRECTIONAL}, |
| 85 | * {@link VideoProfile.VideoState#RX_ENABLED}, |
| 86 | * {@link VideoProfile.VideoState#TX_ENABLED}. |
Tyler Gunn | 27d1e25 | 2014-08-21 16:38:40 -0700 | [diff] [blame] | 87 | * @hide |
Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 88 | */ |
| 89 | public static final String EXTRA_START_CALL_WITH_VIDEO_STATE = |
Nancy Chen | 1d834f5 | 2014-09-05 11:03:21 -0700 | [diff] [blame] | 90 | "android.telecomm.extra.START_CALL_WITH_VIDEO_STATE"; |
Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 91 | |
| 92 | /** |
Santos Cordon | 96efb48 | 2014-07-19 14:57:05 -0700 | [diff] [blame] | 93 | * The extra used with an {@link android.content.Intent#ACTION_CALL} and |
| 94 | * {@link android.content.Intent#ACTION_DIAL} {@code Intent} to specify a |
| 95 | * {@link PhoneAccountHandle} to use when making the call. |
Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 96 | * <p class="note"> |
Santos Cordon | 96efb48 | 2014-07-19 14:57:05 -0700 | [diff] [blame] | 97 | * Retrieve with {@link android.content.Intent#getParcelableExtra(String)}. |
Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 98 | */ |
Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 99 | public static final String EXTRA_PHONE_ACCOUNT_HANDLE = |
Nancy Chen | 1d834f5 | 2014-09-05 11:03:21 -0700 | [diff] [blame] | 100 | "android.telecomm.extra.PHONE_ACCOUNT_HANDLE"; |
Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 101 | |
| 102 | /** |
Santos Cordon | 96efb48 | 2014-07-19 14:57:05 -0700 | [diff] [blame] | 103 | * Optional extra for {@link #ACTION_INCOMING_CALL} containing a {@link Bundle} which contains |
| 104 | * metadata about the call. This {@link Bundle} will be returned to the |
| 105 | * {@link ConnectionService}. |
| 106 | * |
| 107 | * @hide |
Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 108 | */ |
| 109 | public static final String EXTRA_INCOMING_CALL_EXTRAS = |
Nancy Chen | 1d834f5 | 2014-09-05 11:03:21 -0700 | [diff] [blame] | 110 | "android.telecomm.extra.INCOMING_CALL_EXTRAS"; |
Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 111 | |
| 112 | /** |
Nancy Chen | 10798dc | 2014-08-08 14:00:25 -0700 | [diff] [blame] | 113 | * Optional extra for {@link android.content.Intent#ACTION_CALL} and |
| 114 | * {@link android.content.Intent#ACTION_DIAL} {@code Intent} containing a {@link Bundle} |
| 115 | * which contains metadata about the call. This {@link Bundle} will be saved into |
| 116 | * {@code Call.Details}. |
| 117 | * |
| 118 | * @hide |
| 119 | */ |
| 120 | public static final String EXTRA_OUTGOING_CALL_EXTRAS = |
Nancy Chen | 1d834f5 | 2014-09-05 11:03:21 -0700 | [diff] [blame] | 121 | "android.telecomm.extra.OUTGOING_CALL_EXTRAS"; |
Nancy Chen | 10798dc | 2014-08-08 14:00:25 -0700 | [diff] [blame] | 122 | |
| 123 | /** |
Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 124 | * Optional extra for {@link android.telephony.TelephonyManager#ACTION_PHONE_STATE_CHANGED} |
| 125 | * containing the disconnect code. |
Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 126 | */ |
| 127 | public static final String EXTRA_CALL_DISCONNECT_CAUSE = |
| 128 | "android.telecomm.extra.CALL_DISCONNECT_CAUSE"; |
| 129 | |
| 130 | /** |
Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 131 | * Optional extra for {@link android.telephony.TelephonyManager#ACTION_PHONE_STATE_CHANGED} |
| 132 | * containing the disconnect message. |
Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 133 | */ |
| 134 | public static final String EXTRA_CALL_DISCONNECT_MESSAGE = |
| 135 | "android.telecomm.extra.CALL_DISCONNECT_MESSAGE"; |
| 136 | |
| 137 | /** |
Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 138 | * Optional extra for {@link android.telephony.TelephonyManager#ACTION_PHONE_STATE_CHANGED} |
| 139 | * containing the component name of the associated connection service. |
Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 140 | */ |
| 141 | public static final String EXTRA_CONNECTION_SERVICE = |
| 142 | "android.telecomm.extra.CONNECTION_SERVICE"; |
| 143 | |
| 144 | /** |
| 145 | * The number which the party on the other side of the line will see (and use to return the |
| 146 | * call). |
| 147 | * <p> |
Santos Cordon | 96efb48 | 2014-07-19 14:57:05 -0700 | [diff] [blame] | 148 | * {@link ConnectionService}s which interact with {@link RemoteConnection}s should only populate |
| 149 | * this if the {@link android.telephony.TelephonyManager#getLine1Number()} value, as that is the |
| 150 | * user's expected caller ID. |
Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 151 | */ |
| 152 | public static final String EXTRA_CALL_BACK_NUMBER = "android.telecomm.extra.CALL_BACK_NUMBER"; |
| 153 | |
| 154 | /** |
| 155 | * The dual tone multi-frequency signaling character sent to indicate the dialing system should |
| 156 | * pause for a predefined period. |
| 157 | */ |
| 158 | public static final char DTMF_CHARACTER_PAUSE = ','; |
| 159 | |
| 160 | /** |
| 161 | * The dual-tone multi-frequency signaling character sent to indicate the dialing system should |
| 162 | * wait for user confirmation before proceeding. |
| 163 | */ |
| 164 | public static final char DTMF_CHARACTER_WAIT = ';'; |
| 165 | |
| 166 | /** |
| 167 | * TTY (teletypewriter) mode is off. |
| 168 | * |
| 169 | * @hide |
| 170 | */ |
| 171 | public static final int TTY_MODE_OFF = 0; |
| 172 | |
| 173 | /** |
| 174 | * TTY (teletypewriter) mode is on. The speaker is off and the microphone is muted. The user |
| 175 | * will communicate with the remote party by sending and receiving text messages. |
| 176 | * |
| 177 | * @hide |
| 178 | */ |
| 179 | public static final int TTY_MODE_FULL = 1; |
| 180 | |
| 181 | /** |
| 182 | * TTY (teletypewriter) mode is in hearing carryover mode (HCO). The microphone is muted but the |
| 183 | * speaker is on. The user will communicate with the remote party by sending text messages and |
| 184 | * hearing an audible reply. |
| 185 | * |
| 186 | * @hide |
| 187 | */ |
| 188 | public static final int TTY_MODE_HCO = 2; |
| 189 | |
| 190 | /** |
| 191 | * TTY (teletypewriter) mode is in voice carryover mode (VCO). The speaker is off but the |
| 192 | * microphone is still on. User will communicate with the remote party by speaking and receiving |
| 193 | * text message replies. |
| 194 | * |
| 195 | * @hide |
| 196 | */ |
| 197 | public static final int TTY_MODE_VCO = 3; |
| 198 | |
| 199 | /** |
| 200 | * Broadcast intent action indicating that the current TTY mode has changed. An intent extra |
| 201 | * provides this state as an int. |
Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 202 | * |
Santos Cordon | 96efb48 | 2014-07-19 14:57:05 -0700 | [diff] [blame] | 203 | * @see #EXTRA_CURRENT_TTY_MODE |
Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 204 | * @hide |
| 205 | */ |
| 206 | public static final String ACTION_CURRENT_TTY_MODE_CHANGED = |
Nancy Chen | 1d834f5 | 2014-09-05 11:03:21 -0700 | [diff] [blame] | 207 | "android.telecomm.action.CURRENT_TTY_MODE_CHANGED"; |
Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 208 | |
| 209 | /** |
| 210 | * The lookup key for an int that indicates the current TTY mode. |
| 211 | * Valid modes are: |
| 212 | * - {@link #TTY_MODE_OFF} |
| 213 | * - {@link #TTY_MODE_FULL} |
| 214 | * - {@link #TTY_MODE_HCO} |
| 215 | * - {@link #TTY_MODE_VCO} |
| 216 | * |
| 217 | * @hide |
| 218 | */ |
| 219 | public static final String EXTRA_CURRENT_TTY_MODE = |
| 220 | "android.telecomm.intent.extra.CURRENT_TTY_MODE"; |
| 221 | |
| 222 | /** |
Santos Cordon | 96efb48 | 2014-07-19 14:57:05 -0700 | [diff] [blame] | 223 | * Broadcast intent action indicating that the TTY preferred operating mode has changed. An |
| 224 | * intent extra provides the new mode as an int. |
Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 225 | * |
Santos Cordon | 96efb48 | 2014-07-19 14:57:05 -0700 | [diff] [blame] | 226 | * @see #EXTRA_TTY_PREFERRED_MODE |
Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 227 | * @hide |
| 228 | */ |
| 229 | public static final String ACTION_TTY_PREFERRED_MODE_CHANGED = |
Nancy Chen | 1d834f5 | 2014-09-05 11:03:21 -0700 | [diff] [blame] | 230 | "android.telecomm.action.TTY_PREFERRED_MODE_CHANGED"; |
Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 231 | |
| 232 | /** |
Santos Cordon | 96efb48 | 2014-07-19 14:57:05 -0700 | [diff] [blame] | 233 | * The lookup key for an int that indicates preferred TTY mode. Valid modes are: - |
| 234 | * {@link #TTY_MODE_OFF} - {@link #TTY_MODE_FULL} - {@link #TTY_MODE_HCO} - |
| 235 | * {@link #TTY_MODE_VCO} |
Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 236 | * |
| 237 | * @hide |
| 238 | */ |
| 239 | public static final String EXTRA_TTY_PREFERRED_MODE = |
| 240 | "android.telecomm.intent.extra.TTY_PREFERRED"; |
| 241 | |
Nancy Chen | 9d568c0 | 2014-09-08 14:17:59 -0700 | [diff] [blame] | 242 | /** |
| 243 | * The following 4 constants define how properties such as phone numbers and names are |
| 244 | * displayed to the user. |
| 245 | */ |
| 246 | |
| 247 | /** Property is displayed normally. */ |
| 248 | public static final int PRESENTATION_ALLOWED = 1; |
| 249 | |
| 250 | /** Property was blocked. */ |
| 251 | public static final int PRESENTATION_RESTRICTED = 2; |
| 252 | |
| 253 | /** Presentation was not specified or is unknown. */ |
| 254 | public static final int PRESENTATION_UNKNOWN = 3; |
| 255 | |
| 256 | /** Property should be displayed as a pay phone. */ |
| 257 | public static final int PRESENTATION_PAYPHONE = 4; |
| 258 | |
Yorke Lee | b4ce143 | 2014-06-09 13:53:23 -0700 | [diff] [blame] | 259 | private static final String TAG = "TelecommManager"; |
Santos Cordon | 96efb48 | 2014-07-19 14:57:05 -0700 | [diff] [blame] | 260 | |
Santos Cordon | 6c7a388 | 2014-06-25 15:30:08 -0700 | [diff] [blame] | 261 | private static final String TELECOMM_SERVICE_NAME = "telecomm"; |
Yorke Lee | b4ce143 | 2014-06-09 13:53:23 -0700 | [diff] [blame] | 262 | |
| 263 | private final Context mContext; |
Yorke Lee | b4ce143 | 2014-06-09 13:53:23 -0700 | [diff] [blame] | 264 | |
Santos Cordon | 6c7a388 | 2014-06-25 15:30:08 -0700 | [diff] [blame] | 265 | /** |
| 266 | * @hide |
| 267 | */ |
Yorke Lee | b4ce143 | 2014-06-09 13:53:23 -0700 | [diff] [blame] | 268 | public static TelecommManager from(Context context) { |
| 269 | return (TelecommManager) context.getSystemService(Context.TELECOMM_SERVICE); |
| 270 | } |
Santos Cordon | 6c7a388 | 2014-06-25 15:30:08 -0700 | [diff] [blame] | 271 | |
| 272 | /** |
| 273 | * @hide |
| 274 | */ |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 275 | public TelecommManager(Context context) { |
| 276 | Context appContext = context.getApplicationContext(); |
| 277 | if (appContext != null) { |
| 278 | mContext = appContext; |
| 279 | } else { |
| 280 | mContext = context; |
| 281 | } |
| 282 | } |
| 283 | |
| 284 | /** |
Santos Cordon | 96efb48 | 2014-07-19 14:57:05 -0700 | [diff] [blame] | 285 | * Return the {@link PhoneAccount} which is the user-chosen default for making outgoing phone |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 286 | * calls with a specified URI scheme. This {@code PhoneAccount} will always be a member of the |
| 287 | * list which is returned from calling {@link #getEnabledPhoneAccounts()}. |
Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 288 | * <p> |
Santos Cordon | 96efb48 | 2014-07-19 14:57:05 -0700 | [diff] [blame] | 289 | * Apps must be prepared for this method to return {@code null}, indicating that there currently |
| 290 | * exists no user-chosen default {@code PhoneAccount}. In this case, apps wishing to initiate a |
| 291 | * phone call must either create their {@link android.content .Intent#ACTION_CALL} or |
| 292 | * {@link android.content.Intent#ACTION_DIAL} {@code Intent} with no |
| 293 | * {@link TelecommManager#EXTRA_PHONE_ACCOUNT_HANDLE}, or present the user with an affordance to |
| 294 | * select one of the elements of {@link #getEnabledPhoneAccounts()}. |
Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 295 | * <p> |
| 296 | * An {@link android.content.Intent#ACTION_CALL} or {@link android.content.Intent#ACTION_DIAL} |
Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 297 | * {@code Intent} with no {@link TelecommManager#EXTRA_PHONE_ACCOUNT_HANDLE} is valid, and |
| 298 | * subsequent steps in the phone call flow are responsible for presenting the user with an |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 299 | * affordance, if necessary, to choose a {@code PhoneAccount}. |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 300 | * |
| 301 | * @param uriScheme The URI scheme. |
Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 302 | */ |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 303 | public PhoneAccountHandle getDefaultOutgoingPhoneAccount(String uriScheme) { |
Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 304 | try { |
| 305 | if (isServiceConnected()) { |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 306 | return getTelecommService().getDefaultOutgoingPhoneAccount(uriScheme); |
Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 307 | } |
| 308 | } catch (RemoteException e) { |
| 309 | Log.e(TAG, "Error calling ITelecommService#getDefaultOutgoingPhoneAccount", e); |
| 310 | } |
| 311 | return null; |
| 312 | } |
| 313 | |
| 314 | /** |
Andrew Lee | d4abbfb | 2014-09-03 14:58:27 -0700 | [diff] [blame] | 315 | * Return the {@link PhoneAccount} which is the user-chosen default for making outgoing phone |
| 316 | * calls. This {@code PhoneAccount} will always be a member of the list which is returned from |
| 317 | * calling {@link #getEnabledPhoneAccounts()} |
| 318 | * |
| 319 | * Apps must be prepared for this method to return {@code null}, indicating that there currently |
| 320 | * exists no user-chosen default {@code PhoneAccount}. |
| 321 | * |
| 322 | * @return The user outgoing phone account selected by the user. |
| 323 | * @hide |
| 324 | */ |
| 325 | public PhoneAccountHandle getUserSelectedOutgoingPhoneAccount() { |
| 326 | try { |
| 327 | if (isServiceConnected()) { |
| 328 | return getTelecommService().getUserSelectedOutgoingPhoneAccount(); |
| 329 | } |
| 330 | } catch (RemoteException e) { |
| 331 | Log.e(TAG, "Error calling ITelecommService#getUserSelectedOutgoingPhoneAccount", e); |
| 332 | } |
| 333 | return null; |
| 334 | } |
| 335 | |
| 336 | /** |
Andrew Lee | 59cac3a | 2014-08-28 16:50:10 -0700 | [diff] [blame] | 337 | * Sets the default account for making outgoing phone calls. |
| 338 | * @hide |
| 339 | */ |
Andrew Lee | d4abbfb | 2014-09-03 14:58:27 -0700 | [diff] [blame] | 340 | public void setUserSelectedOutgoingPhoneAccount(PhoneAccountHandle accountHandle) { |
Andrew Lee | 59cac3a | 2014-08-28 16:50:10 -0700 | [diff] [blame] | 341 | try { |
| 342 | if (isServiceConnected()) { |
Andrew Lee | d4abbfb | 2014-09-03 14:58:27 -0700 | [diff] [blame] | 343 | getTelecommService().setUserSelectedOutgoingPhoneAccount(accountHandle); |
Andrew Lee | 59cac3a | 2014-08-28 16:50:10 -0700 | [diff] [blame] | 344 | } |
| 345 | } catch (RemoteException e) { |
Andrew Lee | d4abbfb | 2014-09-03 14:58:27 -0700 | [diff] [blame] | 346 | Log.e(TAG, "Error calling ITelecommService#setUserSelectedOutgoingPhoneAccount"); |
Andrew Lee | 59cac3a | 2014-08-28 16:50:10 -0700 | [diff] [blame] | 347 | } |
| 348 | } |
| 349 | |
| 350 | /** |
Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame^] | 351 | * Return a list of enabled {@link PhoneAccountHandle}s which can be used to make and receive |
| 352 | * phone calls. |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 353 | * |
Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 354 | * @see #EXTRA_PHONE_ACCOUNT_HANDLE |
| 355 | * @return A list of {@code PhoneAccountHandle} objects. |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 356 | */ |
Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 357 | public List<PhoneAccountHandle> getEnabledPhoneAccounts() { |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 358 | try { |
| 359 | if (isServiceConnected()) { |
Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame^] | 360 | return getTelecommService().getEnabledPhoneAccounts(); |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 361 | } |
| 362 | } catch (RemoteException e) { |
Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame^] | 363 | Log.e(TAG, "Error calling ITelecommService#getEnabledPhoneAccounts", e); |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 364 | } |
Jay Shrauner | 7746a94 | 2014-08-26 12:15:15 -0700 | [diff] [blame] | 365 | return new ArrayList<>(); |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 366 | } |
| 367 | |
| 368 | /** |
Andrew Lee | 59cac3a | 2014-08-28 16:50:10 -0700 | [diff] [blame] | 369 | * Returns the current SIM call manager. Apps must be prepared for this method to return |
| 370 | * {@code null}, indicating that there currently exists no user-chosen default |
| 371 | * {@code PhoneAccount}. |
| 372 | * @return The phone account handle of the current sim call manager. |
| 373 | * @hide |
| 374 | */ |
| 375 | public PhoneAccountHandle getSimCallManager() { |
| 376 | try { |
| 377 | if (isServiceConnected()) { |
| 378 | return getTelecommService().getSimCallManager(); |
| 379 | } |
| 380 | } catch (RemoteException e) { |
| 381 | Log.e(TAG, "Error calling ITelecommService#getSimCallManager"); |
| 382 | } |
| 383 | return null; |
| 384 | } |
| 385 | |
| 386 | /** |
| 387 | * Sets the SIM call manager to the specified phone account. |
| 388 | * @param accountHandle The phone account handle of the account to set as the sim call manager. |
| 389 | * @hide |
| 390 | */ |
| 391 | public void setSimCallManager(PhoneAccountHandle accountHandle) { |
| 392 | try { |
| 393 | if (isServiceConnected()) { |
| 394 | getTelecommService().setSimCallManager(accountHandle); |
| 395 | } |
| 396 | } catch (RemoteException e) { |
| 397 | Log.e(TAG, "Error calling ITelecommService#setSimCallManager"); |
| 398 | } |
| 399 | } |
| 400 | |
| 401 | /** |
| 402 | * Returns the list of registered SIM call managers. |
| 403 | * @return List of registered SIM call managers. |
| 404 | * @hide |
| 405 | */ |
| 406 | public List<PhoneAccountHandle> getSimCallManagers() { |
| 407 | try { |
| 408 | if (isServiceConnected()) { |
| 409 | return getTelecommService().getSimCallManagers(); |
| 410 | } |
| 411 | } catch (RemoteException e) { |
| 412 | Log.e(TAG, "Error calling ITelecommService#getSimCallManagers"); |
| 413 | } |
| 414 | return new ArrayList<>(); |
| 415 | } |
| 416 | |
| 417 | /** |
Evan Charlton | eb0a8d5 | 2014-09-04 12:03:34 -0700 | [diff] [blame] | 418 | * Returns the current connection manager. Apps must be prepared for this method to return |
| 419 | * {@code null}, indicating that there currently exists no user-chosen default |
| 420 | * {@code PhoneAccount}. |
| 421 | * |
| 422 | * @return The phone account handle of the current connection manager. |
| 423 | */ |
| 424 | public PhoneAccountHandle getConnectionManager() { |
| 425 | return getSimCallManager(); |
| 426 | } |
| 427 | |
| 428 | /** |
Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame^] | 429 | * Returns a list of the enabled {@link PhoneAccountHandle}s which can be used to make and |
| 430 | * receive phone calls which support the specified URI scheme. |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 431 | * <P> |
| 432 | * For example, invoking with {@code "tel"} will find all {@link PhoneAccountHandle}s which |
| 433 | * support telephone calls (e.g. URIs such as {@code tel:555-555-1212}). Invoking with |
| 434 | * {@code "sip"} will find all {@link PhoneAccountHandle}s which support SIP calls (e.g. URIs |
| 435 | * such as {@code sip:example@sipexample.com}). |
| 436 | * |
| 437 | * @param uriScheme The URI scheme. |
| 438 | * @return A list of {@code PhoneAccountHandle} objects supporting the URI scheme. |
| 439 | */ |
| 440 | public List<PhoneAccountHandle> getPhoneAccountsSupportingScheme(String uriScheme) { |
| 441 | try { |
| 442 | if (isServiceConnected()) { |
| 443 | return getTelecommService().getPhoneAccountsSupportingScheme(uriScheme); |
| 444 | } |
| 445 | } catch (RemoteException e) { |
| 446 | Log.e(TAG, "Error calling ITelecommService#getPhoneAccountsSupportingScheme", e); |
| 447 | } |
| 448 | return new ArrayList<>(); |
| 449 | } |
| 450 | |
| 451 | /** |
Nancy Chen | 6080118 | 2014-07-22 16:56:49 -0700 | [diff] [blame] | 452 | * Determine whether the device has more than one account registered and enabled. |
| 453 | * |
| 454 | * @return {@code true} if the device has more than one account registered and enabled and |
| 455 | * {@code false} otherwise. |
| 456 | */ |
| 457 | public boolean hasMultipleEnabledAccounts() { |
| 458 | return getEnabledPhoneAccounts().size() > 1; |
| 459 | } |
| 460 | |
| 461 | /** |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 462 | * Return the {@link PhoneAccount} for a specified {@link PhoneAccountHandle}. Object includes |
| 463 | * resources which can be used in a user interface. |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 464 | * |
Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 465 | * @param account The {@link PhoneAccountHandle}. |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 466 | * @return The {@link PhoneAccount} object. |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 467 | */ |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 468 | public PhoneAccount getPhoneAccount(PhoneAccountHandle account) { |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 469 | try { |
| 470 | if (isServiceConnected()) { |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 471 | return getTelecommService().getPhoneAccount(account); |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 472 | } |
| 473 | } catch (RemoteException e) { |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 474 | Log.e(TAG, "Error calling ITelecommService#getPhoneAccount", e); |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 475 | } |
| 476 | return null; |
| 477 | } |
| 478 | |
| 479 | /** |
Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame^] | 480 | * Returns a count of enabled and disabled {@link PhoneAccount}s. |
| 481 | * |
| 482 | * @return The count of enabled and disabled {@link PhoneAccount}s. |
| 483 | * @hide |
| 484 | */ |
| 485 | @SystemApi |
| 486 | public int getAllPhoneAccountsCount() { |
| 487 | try { |
| 488 | if (isServiceConnected()) { |
| 489 | return getTelecommService().getAllPhoneAccountsCount(); |
| 490 | } |
| 491 | } catch (RemoteException e) { |
| 492 | Log.e(TAG, "Error calling ITelecommService#getAllPhoneAccountsCount", e); |
| 493 | } |
| 494 | return 0; |
| 495 | } |
| 496 | |
| 497 | /** |
| 498 | * Returns a list of all {@link PhoneAccount}s. |
| 499 | * |
| 500 | * @return All {@link PhoneAccount}s. |
| 501 | * @hide |
| 502 | */ |
| 503 | @SystemApi |
| 504 | public List<PhoneAccount> getAllPhoneAccounts() { |
| 505 | try { |
| 506 | if (isServiceConnected()) { |
| 507 | return getTelecommService().getAllPhoneAccounts(); |
| 508 | } |
| 509 | } catch (RemoteException e) { |
| 510 | Log.e(TAG, "Error calling ITelecommService#getAllPhoneAccounts", e); |
| 511 | } |
| 512 | return Collections.EMPTY_LIST; |
| 513 | } |
| 514 | |
| 515 | /** |
| 516 | * Returns a list of all {@link PhoneAccountHandle}s. |
| 517 | * |
| 518 | * @return All {@link PhoneAccountHandle}s. |
| 519 | * @hide |
| 520 | */ |
| 521 | @SystemApi |
| 522 | public List<PhoneAccountHandle> getAllPhoneAccountHandles() { |
| 523 | try { |
| 524 | if (isServiceConnected()) { |
| 525 | return getTelecommService().getAllPhoneAccountHandles(); |
| 526 | } |
| 527 | } catch (RemoteException e) { |
| 528 | Log.e(TAG, "Error calling ITelecommService#getAllPhoneAccountHandles", e); |
| 529 | } |
| 530 | return Collections.EMPTY_LIST; |
| 531 | } |
| 532 | |
| 533 | /** |
| 534 | * Enables or disables a {@link PhoneAccount}. |
| 535 | * |
| 536 | * @param account The {@link PhoneAccountHandle} to enable or disable. |
| 537 | * @param isEnabled {@code True} if the phone account should be enabled. |
| 538 | * @hide |
| 539 | */ |
| 540 | @SystemApi |
| 541 | public void setPhoneAccountEnabled(PhoneAccountHandle account, boolean isEnabled) { |
| 542 | try { |
| 543 | if (isServiceConnected()) { |
| 544 | getTelecommService().setPhoneAccountEnabled(account, isEnabled); |
| 545 | } |
| 546 | } catch (RemoteException e) { |
| 547 | Log.e(TAG, "Error calling ITelecommService#setPhoneAccountEnabled", e); |
| 548 | } |
| 549 | } |
| 550 | |
| 551 | /** |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 552 | * Register a {@link PhoneAccount} for use by the system. |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 553 | * |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 554 | * @param account The complete {@link PhoneAccount}. |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 555 | */ |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 556 | public void registerPhoneAccount(PhoneAccount account) { |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 557 | try { |
| 558 | if (isServiceConnected()) { |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 559 | getTelecommService().registerPhoneAccount(account); |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 560 | } |
| 561 | } catch (RemoteException e) { |
| 562 | Log.e(TAG, "Error calling ITelecommService#registerPhoneAccount", e); |
| 563 | } |
| 564 | } |
| 565 | |
| 566 | /** |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 567 | * Remove a {@link PhoneAccount} registration from the system. |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 568 | * |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 569 | * @param accountHandle A {@link PhoneAccountHandle} for the {@link PhoneAccount} to unregister. |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 570 | */ |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 571 | public void unregisterPhoneAccount(PhoneAccountHandle accountHandle) { |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 572 | try { |
| 573 | if (isServiceConnected()) { |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 574 | getTelecommService().unregisterPhoneAccount(accountHandle); |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 575 | } |
| 576 | } catch (RemoteException e) { |
| 577 | Log.e(TAG, "Error calling ITelecommService#unregisterPhoneAccount", e); |
| 578 | } |
| 579 | } |
| 580 | |
| 581 | /** |
| 582 | * Remove all Accounts for a given package from the system. |
| 583 | * |
| 584 | * @param packageName A package name that may have registered Accounts. |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 585 | */ |
| 586 | @SystemApi |
| 587 | public void clearAccounts(String packageName) { |
| 588 | try { |
| 589 | if (isServiceConnected()) { |
| 590 | getTelecommService().clearAccounts(packageName); |
| 591 | } |
| 592 | } catch (RemoteException e) { |
| 593 | Log.e(TAG, "Error calling ITelecommService#clearAccounts", e); |
| 594 | } |
| 595 | } |
| 596 | |
| 597 | /** |
| 598 | * @hide |
| 599 | */ |
Santos Cordon | 6c7a388 | 2014-06-25 15:30:08 -0700 | [diff] [blame] | 600 | @SystemApi |
| 601 | public ComponentName getDefaultPhoneApp() { |
| 602 | try { |
Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 603 | if (isServiceConnected()) { |
| 604 | return getTelecommService().getDefaultPhoneApp(); |
| 605 | } |
Santos Cordon | 6c7a388 | 2014-06-25 15:30:08 -0700 | [diff] [blame] | 606 | } catch (RemoteException e) { |
| 607 | Log.e(TAG, "RemoteException attempting to get the default phone app.", e); |
| 608 | } |
| 609 | return null; |
| 610 | } |
| 611 | |
Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 612 | /** |
| 613 | * Returns whether there is an ongoing phone call (can be in dialing, ringing, active or holding |
| 614 | * states). |
Nancy Chen | 0eb1e40 | 2014-08-21 22:52:29 -0700 | [diff] [blame] | 615 | * <p> |
| 616 | * Requires permission: {@link android.Manifest.permission#READ_PHONE_STATE} |
| 617 | * </p> |
Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 618 | */ |
| 619 | @SystemApi |
Nancy Chen | 0eb1e40 | 2014-08-21 22:52:29 -0700 | [diff] [blame] | 620 | public boolean isInCall() { |
Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 621 | try { |
| 622 | if (isServiceConnected()) { |
Nancy Chen | 0eb1e40 | 2014-08-21 22:52:29 -0700 | [diff] [blame] | 623 | return getTelecommService().isInCall(); |
Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 624 | } |
| 625 | } catch (RemoteException e) { |
| 626 | Log.e(TAG, "RemoteException attempting to get default phone app.", e); |
| 627 | } |
| 628 | return false; |
| 629 | } |
| 630 | |
| 631 | /** |
| 632 | * Returns whether there currently exists is a ringing incoming-call. |
| 633 | * |
| 634 | * @hide |
| 635 | */ |
| 636 | @SystemApi |
| 637 | public boolean isRinging() { |
| 638 | try { |
| 639 | if (isServiceConnected()) { |
| 640 | return getTelecommService().isRinging(); |
| 641 | } |
| 642 | } catch (RemoteException e) { |
| 643 | Log.e(TAG, "RemoteException attempting to get ringing state of phone app.", e); |
| 644 | } |
| 645 | return false; |
| 646 | } |
| 647 | |
| 648 | /** |
Santos Cordon | 96efb48 | 2014-07-19 14:57:05 -0700 | [diff] [blame] | 649 | * Ends an ongoing call. |
| 650 | * TODO: L-release - need to convert all invocations of ITelecommService#endCall to use this |
| 651 | * method (clockwork & gearhead). |
Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 652 | * @hide |
| 653 | */ |
| 654 | @SystemApi |
| 655 | public boolean endCall() { |
| 656 | try { |
| 657 | if (isServiceConnected()) { |
| 658 | return getTelecommService().endCall(); |
| 659 | } |
| 660 | } catch (RemoteException e) { |
| 661 | Log.e(TAG, "Error calling ITelecommService#endCall", e); |
| 662 | } |
| 663 | return false; |
| 664 | } |
| 665 | |
| 666 | /** |
| 667 | * If there is a ringing incoming call, this method accepts the call on behalf of the user. |
Santos Cordon | 96efb48 | 2014-07-19 14:57:05 -0700 | [diff] [blame] | 668 | * TODO: L-release - need to convert all invocation of ITelecommService#answerRingingCall to use |
| 669 | * this method (clockwork & gearhead). |
Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 670 | * |
| 671 | * @hide |
| 672 | */ |
| 673 | @SystemApi |
| 674 | public void acceptRingingCall() { |
| 675 | try { |
| 676 | if (isServiceConnected()) { |
| 677 | getTelecommService().acceptRingingCall(); |
| 678 | } |
| 679 | } catch (RemoteException e) { |
| 680 | Log.e(TAG, "Error calling ITelecommService#acceptRingingCall", e); |
| 681 | } |
| 682 | } |
| 683 | |
| 684 | /** |
| 685 | * Silences the ringer if a ringing call exists. |
| 686 | * |
| 687 | * @hide |
| 688 | */ |
| 689 | @SystemApi |
| 690 | public void silenceRinger() { |
| 691 | try { |
| 692 | if (isServiceConnected()) { |
| 693 | getTelecommService().silenceRinger(); |
| 694 | } |
| 695 | } catch (RemoteException e) { |
| 696 | Log.e(TAG, "Error calling ITelecommService#silenceRinger", e); |
| 697 | } |
| 698 | } |
| 699 | |
Sailesh Nepal | 001bbbb | 2014-07-15 14:40:39 -0700 | [diff] [blame] | 700 | /** |
| 701 | * Returns whether TTY is supported on this device. |
| 702 | * |
| 703 | * @hide |
| 704 | */ |
| 705 | @SystemApi |
| 706 | public boolean isTtySupported() { |
| 707 | try { |
| 708 | if (isServiceConnected()) { |
| 709 | return getTelecommService().isTtySupported(); |
| 710 | } |
| 711 | } catch (RemoteException e) { |
| 712 | Log.e(TAG, "RemoteException attempting to get TTY supported state.", e); |
| 713 | } |
| 714 | return false; |
| 715 | } |
| 716 | |
| 717 | /** |
| 718 | * 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] | 719 | * settings and have a wired headset plugged in. |
| 720 | * Valid modes are: |
Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 721 | * - {@link TelecommManager#TTY_MODE_OFF} |
| 722 | * - {@link TelecommManager#TTY_MODE_FULL} |
| 723 | * - {@link TelecommManager#TTY_MODE_HCO} |
| 724 | * - {@link TelecommManager#TTY_MODE_VCO} |
Sailesh Nepal | 001bbbb | 2014-07-15 14:40:39 -0700 | [diff] [blame] | 725 | * @hide |
| 726 | */ |
| 727 | public int getCurrentTtyMode() { |
| 728 | try { |
| 729 | if (isServiceConnected()) { |
| 730 | return getTelecommService().getCurrentTtyMode(); |
| 731 | } |
| 732 | } catch (RemoteException e) { |
| 733 | Log.e(TAG, "RemoteException attempting to get the current TTY mode.", e); |
| 734 | } |
Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 735 | return TTY_MODE_OFF; |
Sailesh Nepal | 001bbbb | 2014-07-15 14:40:39 -0700 | [diff] [blame] | 736 | } |
| 737 | |
Santos Cordon | 96efb48 | 2014-07-19 14:57:05 -0700 | [diff] [blame] | 738 | /** |
| 739 | * Registers a new incoming call. A {@link ConnectionService} should invoke this method when it |
| 740 | * has an incoming call. The specified {@link PhoneAccountHandle} must have been registered |
| 741 | * with {@link #registerPhoneAccount} and subsequently enabled by the user within the phone's |
| 742 | * settings. Once invoked, this method will cause the system to bind to the |
| 743 | * {@link ConnectionService} associated with the {@link PhoneAccountHandle} and request |
| 744 | * additional information about the call (See |
| 745 | * {@link ConnectionService#onCreateIncomingConnection}) before starting the incoming call UI. |
| 746 | * |
| 747 | * @param phoneAccount A {@link PhoneAccountHandle} registered with |
| 748 | * {@link #registerPhoneAccount}. |
| 749 | * @param extras A bundle that will be passed through to |
| 750 | * {@link ConnectionService#onCreateIncomingConnection}. |
| 751 | */ |
| 752 | public void addNewIncomingCall(PhoneAccountHandle phoneAccount, Bundle extras) { |
| 753 | try { |
| 754 | if (isServiceConnected()) { |
| 755 | getTelecommService().addNewIncomingCall( |
| 756 | phoneAccount, extras == null ? new Bundle() : extras); |
| 757 | } |
| 758 | } catch (RemoteException e) { |
| 759 | Log.e(TAG, "RemoteException adding a new incoming call: " + phoneAccount, e); |
| 760 | } |
| 761 | } |
| 762 | |
Nancy Chen | 0eb1e40 | 2014-08-21 22:52:29 -0700 | [diff] [blame] | 763 | /** |
| 764 | * Processes the specified dial string as an MMI code. |
| 765 | * MMI codes are any sequence of characters entered into the dialpad that contain a "*" or "#". |
| 766 | * Some of these sequences launch special behavior through handled by Telephony. |
| 767 | * <p> |
| 768 | * Requires that the method-caller be set as the system dialer app. |
| 769 | * </p> |
| 770 | * |
| 771 | * @param dialString The digits to dial. |
| 772 | * @return True if the digits were processed as an MMI code, false otherwise. |
| 773 | */ |
| 774 | public boolean handleMmi(String dialString) { |
| 775 | ITelecommService service = getTelecommService(); |
| 776 | if (service != null) { |
| 777 | try { |
| 778 | return service.handlePinMmi(dialString); |
| 779 | } catch (RemoteException e) { |
| 780 | Log.e(TAG, "Error calling ITelecommService#handlePinMmi", e); |
| 781 | } |
| 782 | } |
| 783 | return false; |
| 784 | } |
| 785 | |
| 786 | /** |
| 787 | * Removes the missed-call notification if one is present. |
| 788 | * <p> |
| 789 | * Requires that the method-caller be set as the system dialer app. |
| 790 | * </p> |
| 791 | */ |
| 792 | public void cancelMissedCallsNotification() { |
| 793 | ITelecommService service = getTelecommService(); |
| 794 | if (service != null) { |
| 795 | try { |
| 796 | service.cancelMissedCallsNotification(); |
| 797 | } catch (RemoteException e) { |
| 798 | Log.e(TAG, "Error calling ITelecommService#cancelMissedCallsNotification", e); |
| 799 | } |
| 800 | } |
| 801 | } |
| 802 | |
| 803 | /** |
| 804 | * Brings the in-call screen to the foreground if there is an ongoing call. If there is |
| 805 | * currently no ongoing call, then this method does nothing. |
| 806 | * <p> |
| 807 | * Requires that the method-caller be set as the system dialer app or have the |
| 808 | * {@link android.Manifest.permission#READ_PHONE_STATE} permission. |
| 809 | * </p> |
| 810 | * |
| 811 | * @param showDialpad Brings up the in-call dialpad as part of showing the in-call screen. |
| 812 | */ |
| 813 | public void showInCallScreen(boolean showDialpad) { |
| 814 | ITelecommService service = getTelecommService(); |
| 815 | if (service != null) { |
| 816 | try { |
| 817 | service.showInCallScreen(showDialpad); |
| 818 | } catch (RemoteException e) { |
| 819 | Log.e(TAG, "Error calling ITelecommService#showCallScreen", e); |
| 820 | } |
| 821 | } |
| 822 | } |
| 823 | |
Santos Cordon | 6c7a388 | 2014-06-25 15:30:08 -0700 | [diff] [blame] | 824 | private ITelecommService getTelecommService() { |
| 825 | return ITelecommService.Stub.asInterface(ServiceManager.getService(TELECOMM_SERVICE_NAME)); |
| 826 | } |
Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 827 | |
| 828 | private boolean isServiceConnected() { |
| 829 | boolean isConnected = getTelecommService() != null; |
| 830 | if (!isConnected) { |
| 831 | Log.w(TAG, "Telecomm Service not found."); |
| 832 | } |
| 833 | return isConnected; |
| 834 | } |
Evan Charlton | 235c159 | 2014-09-05 15:41:23 +0000 | [diff] [blame] | 835 | } |