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