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