Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package android.bluetooth; |
| 18 | |
Mathew Inwood | 4dc66d3 | 2018-08-01 15:07:20 +0100 | [diff] [blame] | 19 | import android.annotation.UnsupportedAppUsage; |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 20 | import android.content.Context; |
Jeff Sharkey | 0a17db1 | 2016-11-04 11:23:46 -0600 | [diff] [blame] | 21 | import android.os.Binder; |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 22 | import android.os.Bundle; |
| 23 | import android.os.IBinder; |
| 24 | import android.os.RemoteException; |
| 25 | import android.util.Log; |
| 26 | |
| 27 | import java.util.ArrayList; |
| 28 | import java.util.List; |
| 29 | |
| 30 | /** |
| 31 | * Public API to control Hands Free Profile (HFP role only). |
| 32 | * <p> |
| 33 | * This class defines methods that shall be used by application to manage profile |
| 34 | * connection, calls states and calls actions. |
| 35 | * <p> |
| 36 | * |
| 37 | * @hide |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 38 | */ |
Mike Lockwood | cf916d3 | 2014-06-12 11:23:40 -0700 | [diff] [blame] | 39 | public final class BluetoothHeadsetClient implements BluetoothProfile { |
| 40 | private static final String TAG = "BluetoothHeadsetClient"; |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 41 | private static final boolean DBG = true; |
| 42 | private static final boolean VDBG = false; |
| 43 | |
| 44 | /** |
| 45 | * Intent sent whenever connection to remote changes. |
| 46 | * |
| 47 | * <p>It includes two extras: |
| 48 | * <code>BluetoothProfile.EXTRA_PREVIOUS_STATE</code> |
| 49 | * and <code>BluetoothProfile.EXTRA_STATE</code>, which |
| 50 | * are mandatory. |
| 51 | * <p>There are also non mandatory feature extras: |
| 52 | * {@link #EXTRA_AG_FEATURE_3WAY_CALLING}, |
| 53 | * {@link #EXTRA_AG_FEATURE_VOICE_RECOGNITION}, |
| 54 | * {@link #EXTRA_AG_FEATURE_ATTACH_NUMBER_TO_VT}, |
| 55 | * {@link #EXTRA_AG_FEATURE_REJECT_CALL}, |
| 56 | * {@link #EXTRA_AG_FEATURE_ECC}, |
| 57 | * {@link #EXTRA_AG_FEATURE_RESPONSE_AND_HOLD}, |
| 58 | * {@link #EXTRA_AG_FEATURE_ACCEPT_HELD_OR_WAITING_CALL}, |
| 59 | * {@link #EXTRA_AG_FEATURE_RELEASE_HELD_OR_WAITING_CALL}, |
| 60 | * {@link #EXTRA_AG_FEATURE_RELEASE_AND_ACCEPT}, |
| 61 | * {@link #EXTRA_AG_FEATURE_MERGE}, |
| 62 | * {@link #EXTRA_AG_FEATURE_MERGE_AND_DETACH}, |
| 63 | * sent as boolean values only when <code>EXTRA_STATE</code> |
| 64 | * is set to <code>STATE_CONNECTED</code>.</p> |
| 65 | * |
| 66 | * <p>Note that features supported by AG are being sent as |
| 67 | * booleans with value <code>true</code>, |
| 68 | * and not supported ones are <strong>not</strong> being sent at all.</p> |
| 69 | */ |
| 70 | public static final String ACTION_CONNECTION_STATE_CHANGED = |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 71 | "android.bluetooth.headsetclient.profile.action.CONNECTION_STATE_CHANGED"; |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 72 | |
| 73 | /** |
| 74 | * Intent sent whenever audio state changes. |
| 75 | * |
| 76 | * <p>It includes two mandatory extras: |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 77 | * {@link BluetoothProfile#EXTRA_STATE}, |
| 78 | * {@link BluetoothProfile#EXTRA_PREVIOUS_STATE}, |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 79 | * with possible values: |
| 80 | * {@link #STATE_AUDIO_CONNECTING}, |
| 81 | * {@link #STATE_AUDIO_CONNECTED}, |
| 82 | * {@link #STATE_AUDIO_DISCONNECTED}</p> |
| 83 | * <p>When <code>EXTRA_STATE</code> is set |
| 84 | * to </code>STATE_AUDIO_CONNECTED</code>, |
| 85 | * it also includes {@link #EXTRA_AUDIO_WBS} |
| 86 | * indicating wide band speech support.</p> |
| 87 | */ |
| 88 | public static final String ACTION_AUDIO_STATE_CHANGED = |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 89 | "android.bluetooth.headsetclient.profile.action.AUDIO_STATE_CHANGED"; |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 90 | |
| 91 | /** |
| 92 | * Intent sending updates of the Audio Gateway state. |
| 93 | * Each extra is being sent only when value it |
| 94 | * represents has been changed recently on AG. |
| 95 | * <p>It can contain one or more of the following extras: |
| 96 | * {@link #EXTRA_NETWORK_STATUS}, |
| 97 | * {@link #EXTRA_NETWORK_SIGNAL_STRENGTH}, |
| 98 | * {@link #EXTRA_NETWORK_ROAMING}, |
| 99 | * {@link #EXTRA_BATTERY_LEVEL}, |
| 100 | * {@link #EXTRA_OPERATOR_NAME}, |
| 101 | * {@link #EXTRA_VOICE_RECOGNITION}, |
| 102 | * {@link #EXTRA_IN_BAND_RING}</p> |
| 103 | */ |
| 104 | public static final String ACTION_AG_EVENT = |
Mike Lockwood | cf916d3 | 2014-06-12 11:23:40 -0700 | [diff] [blame] | 105 | "android.bluetooth.headsetclient.profile.action.AG_EVENT"; |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 106 | |
| 107 | /** |
| 108 | * Intent sent whenever state of a call changes. |
| 109 | * |
| 110 | * <p>It includes: |
| 111 | * {@link #EXTRA_CALL}, |
Mike Lockwood | cf916d3 | 2014-06-12 11:23:40 -0700 | [diff] [blame] | 112 | * with value of {@link BluetoothHeadsetClientCall} instance, |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 113 | * representing actual call state.</p> |
| 114 | */ |
| 115 | public static final String ACTION_CALL_CHANGED = |
Mike Lockwood | cf916d3 | 2014-06-12 11:23:40 -0700 | [diff] [blame] | 116 | "android.bluetooth.headsetclient.profile.action.AG_CALL_CHANGED"; |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 117 | |
| 118 | /** |
| 119 | * Intent that notifies about the result of the last issued action. |
| 120 | * Please note that not every action results in explicit action result code being sent. |
| 121 | * Instead other notifications about new Audio Gateway state might be sent, |
| 122 | * like <code>ACTION_AG_EVENT</code> with <code>EXTRA_VOICE_RECOGNITION</code> value |
| 123 | * when for example user started voice recognition from HF unit. |
| 124 | */ |
| 125 | public static final String ACTION_RESULT = |
Mike Lockwood | cf916d3 | 2014-06-12 11:23:40 -0700 | [diff] [blame] | 126 | "android.bluetooth.headsetclient.profile.action.RESULT"; |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 127 | |
| 128 | /** |
Deqiang Chen | 2fec85d | 2019-06-25 14:30:55 -0700 | [diff] [blame] | 129 | * Intent that notifies about vendor specific event arrival. Events not defined in |
| 130 | * HFP spec will be matched with supported vendor event list and this intent will |
| 131 | * be broadcasted upon a match. Supported vendor events are of format of |
| 132 | * of "+eventCode" or "+eventCode=xxxx" or "+eventCode:=xxxx". |
| 133 | * Vendor event can be a response to an vendor specific command or unsolicited. |
| 134 | * |
| 135 | */ |
| 136 | public static final String ACTION_VENDOR_SPECIFIC_HEADSETCLIENT_EVENT = |
| 137 | "android.bluetooth.headsetclient.profile.action.VENDOR_SPECIFIC_EVENT"; |
| 138 | |
| 139 | /** |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 140 | * Intent that notifies about the number attached to the last voice tag |
| 141 | * recorded on AG. |
| 142 | * |
| 143 | * <p>It contains: |
| 144 | * {@link #EXTRA_NUMBER}, |
| 145 | * with a <code>String</code> value representing phone number.</p> |
| 146 | */ |
| 147 | public static final String ACTION_LAST_VTAG = |
Mike Lockwood | cf916d3 | 2014-06-12 11:23:40 -0700 | [diff] [blame] | 148 | "android.bluetooth.headsetclient.profile.action.LAST_VTAG"; |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 149 | |
| 150 | public static final int STATE_AUDIO_DISCONNECTED = 0; |
| 151 | public static final int STATE_AUDIO_CONNECTING = 1; |
| 152 | public static final int STATE_AUDIO_CONNECTED = 2; |
| 153 | |
| 154 | /** |
| 155 | * Extra with information if connected audio is WBS. |
| 156 | * <p>Possible values: <code>true</code>, |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 157 | * <code>false</code>.</p> |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 158 | */ |
| 159 | public static final String EXTRA_AUDIO_WBS = |
Mike Lockwood | cf916d3 | 2014-06-12 11:23:40 -0700 | [diff] [blame] | 160 | "android.bluetooth.headsetclient.extra.AUDIO_WBS"; |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 161 | |
| 162 | /** |
| 163 | * Extra for AG_EVENT indicates network status. |
| 164 | * <p>Value: 0 - network unavailable, |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 165 | * 1 - network available </p> |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 166 | */ |
| 167 | public static final String EXTRA_NETWORK_STATUS = |
Mike Lockwood | cf916d3 | 2014-06-12 11:23:40 -0700 | [diff] [blame] | 168 | "android.bluetooth.headsetclient.extra.NETWORK_STATUS"; |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 169 | /** |
| 170 | * Extra for AG_EVENT intent indicates network signal strength. |
| 171 | * <p>Value: <code>Integer</code> representing signal strength.</p> |
| 172 | */ |
| 173 | public static final String EXTRA_NETWORK_SIGNAL_STRENGTH = |
Mike Lockwood | cf916d3 | 2014-06-12 11:23:40 -0700 | [diff] [blame] | 174 | "android.bluetooth.headsetclient.extra.NETWORK_SIGNAL_STRENGTH"; |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 175 | /** |
| 176 | * Extra for AG_EVENT intent indicates roaming state. |
| 177 | * <p>Value: 0 - no roaming |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 178 | * 1 - active roaming</p> |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 179 | */ |
| 180 | public static final String EXTRA_NETWORK_ROAMING = |
Mike Lockwood | cf916d3 | 2014-06-12 11:23:40 -0700 | [diff] [blame] | 181 | "android.bluetooth.headsetclient.extra.NETWORK_ROAMING"; |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 182 | /** |
| 183 | * Extra for AG_EVENT intent indicates the battery level. |
| 184 | * <p>Value: <code>Integer</code> representing signal strength.</p> |
| 185 | */ |
| 186 | public static final String EXTRA_BATTERY_LEVEL = |
Mike Lockwood | cf916d3 | 2014-06-12 11:23:40 -0700 | [diff] [blame] | 187 | "android.bluetooth.headsetclient.extra.BATTERY_LEVEL"; |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 188 | /** |
| 189 | * Extra for AG_EVENT intent indicates operator name. |
| 190 | * <p>Value: <code>String</code> representing operator name.</p> |
| 191 | */ |
| 192 | public static final String EXTRA_OPERATOR_NAME = |
Mike Lockwood | cf916d3 | 2014-06-12 11:23:40 -0700 | [diff] [blame] | 193 | "android.bluetooth.headsetclient.extra.OPERATOR_NAME"; |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 194 | /** |
| 195 | * Extra for AG_EVENT intent indicates voice recognition state. |
| 196 | * <p>Value: |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 197 | * 0 - voice recognition stopped, |
| 198 | * 1 - voice recognition started.</p> |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 199 | */ |
| 200 | public static final String EXTRA_VOICE_RECOGNITION = |
Mike Lockwood | cf916d3 | 2014-06-12 11:23:40 -0700 | [diff] [blame] | 201 | "android.bluetooth.headsetclient.extra.VOICE_RECOGNITION"; |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 202 | /** |
| 203 | * Extra for AG_EVENT intent indicates in band ring state. |
| 204 | * <p>Value: |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 205 | * 0 - in band ring tone not supported, or |
| 206 | * 1 - in band ring tone supported.</p> |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 207 | */ |
| 208 | public static final String EXTRA_IN_BAND_RING = |
Mike Lockwood | cf916d3 | 2014-06-12 11:23:40 -0700 | [diff] [blame] | 209 | "android.bluetooth.headsetclient.extra.IN_BAND_RING"; |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 210 | |
| 211 | /** |
| 212 | * Extra for AG_EVENT intent indicates subscriber info. |
| 213 | * <p>Value: <code>String</code> containing subscriber information.</p> |
| 214 | */ |
| 215 | public static final String EXTRA_SUBSCRIBER_INFO = |
Mike Lockwood | cf916d3 | 2014-06-12 11:23:40 -0700 | [diff] [blame] | 216 | "android.bluetooth.headsetclient.extra.SUBSCRIBER_INFO"; |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 217 | |
| 218 | /** |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 219 | * Extra for AG_CALL_CHANGED intent indicates the |
| 220 | * {@link BluetoothHeadsetClientCall} object that has changed. |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 221 | */ |
| 222 | public static final String EXTRA_CALL = |
Mike Lockwood | cf916d3 | 2014-06-12 11:23:40 -0700 | [diff] [blame] | 223 | "android.bluetooth.headsetclient.extra.CALL"; |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 224 | |
| 225 | /** |
| 226 | * Extra for ACTION_LAST_VTAG intent. |
| 227 | * <p>Value: <code>String</code> representing phone number |
| 228 | * corresponding to last voice tag recorded on AG</p> |
| 229 | */ |
| 230 | public static final String EXTRA_NUMBER = |
Mike Lockwood | cf916d3 | 2014-06-12 11:23:40 -0700 | [diff] [blame] | 231 | "android.bluetooth.headsetclient.extra.NUMBER"; |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 232 | |
| 233 | /** |
| 234 | * Extra for ACTION_RESULT intent that shows the result code of |
| 235 | * last issued action. |
| 236 | * <p>Possible results: |
| 237 | * {@link #ACTION_RESULT_OK}, |
| 238 | * {@link #ACTION_RESULT_ERROR}, |
| 239 | * {@link #ACTION_RESULT_ERROR_NO_CARRIER}, |
| 240 | * {@link #ACTION_RESULT_ERROR_BUSY}, |
| 241 | * {@link #ACTION_RESULT_ERROR_NO_ANSWER}, |
| 242 | * {@link #ACTION_RESULT_ERROR_DELAYED}, |
| 243 | * {@link #ACTION_RESULT_ERROR_BLACKLISTED}, |
| 244 | * {@link #ACTION_RESULT_ERROR_CME}</p> |
| 245 | */ |
| 246 | public static final String EXTRA_RESULT_CODE = |
Mike Lockwood | cf916d3 | 2014-06-12 11:23:40 -0700 | [diff] [blame] | 247 | "android.bluetooth.headsetclient.extra.RESULT_CODE"; |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 248 | |
| 249 | /** |
| 250 | * Extra for ACTION_RESULT intent that shows the extended result code of |
| 251 | * last issued action. |
| 252 | * <p>Value: <code>Integer</code> - error code.</p> |
| 253 | */ |
| 254 | public static final String EXTRA_CME_CODE = |
Mike Lockwood | cf916d3 | 2014-06-12 11:23:40 -0700 | [diff] [blame] | 255 | "android.bluetooth.headsetclient.extra.CME_CODE"; |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 256 | |
Deqiang Chen | 2fec85d | 2019-06-25 14:30:55 -0700 | [diff] [blame] | 257 | /** |
| 258 | * Extra for VENDOR_SPECIFIC_HEADSETCLIENT_EVENT intent that |
| 259 | * indicates vendor ID. |
| 260 | */ |
| 261 | public static final String EXTRA_VENDOR_ID = |
| 262 | "android.bluetooth.headsetclient.extra.VENDOR_ID"; |
| 263 | |
| 264 | /** |
| 265 | * Extra for VENDOR_SPECIFIC_HEADSETCLIENT_EVENT intent that |
| 266 | * indicates vendor event code. |
| 267 | */ |
| 268 | public static final String EXTRA_VENDOR_EVENT_CODE = |
| 269 | "android.bluetooth.headsetclient.extra.VENDOR_EVENT_CODE"; |
| 270 | |
| 271 | /** |
| 272 | * Extra for VENDOR_SPECIFIC_HEADSETCLIENT_EVENT intent that |
| 273 | * contains full vendor event including event code and full arguments. |
| 274 | */ |
| 275 | public static final String EXTRA_VENDOR_EVENT_FULL_ARGS = |
| 276 | "android.bluetooth.headsetclient.extra.VENDOR_EVENT_FULL_ARGS"; |
| 277 | |
| 278 | |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 279 | /* Extras for AG_FEATURES, extras type is boolean */ |
| 280 | // TODO verify if all of those are actually useful |
| 281 | /** |
| 282 | * AG feature: three way calling. |
| 283 | */ |
Jack He | 2992cd0 | 2017-08-22 21:21:23 -0700 | [diff] [blame] | 284 | public static final String EXTRA_AG_FEATURE_3WAY_CALLING = |
Mike Lockwood | cf916d3 | 2014-06-12 11:23:40 -0700 | [diff] [blame] | 285 | "android.bluetooth.headsetclient.extra.EXTRA_AG_FEATURE_3WAY_CALLING"; |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 286 | /** |
| 287 | * AG feature: voice recognition. |
| 288 | */ |
Jack He | 2992cd0 | 2017-08-22 21:21:23 -0700 | [diff] [blame] | 289 | public static final String EXTRA_AG_FEATURE_VOICE_RECOGNITION = |
Mike Lockwood | cf916d3 | 2014-06-12 11:23:40 -0700 | [diff] [blame] | 290 | "android.bluetooth.headsetclient.extra.EXTRA_AG_FEATURE_VOICE_RECOGNITION"; |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 291 | /** |
| 292 | * AG feature: fetching phone number for voice tagging procedure. |
| 293 | */ |
Jack He | 2992cd0 | 2017-08-22 21:21:23 -0700 | [diff] [blame] | 294 | public static final String EXTRA_AG_FEATURE_ATTACH_NUMBER_TO_VT = |
Mike Lockwood | cf916d3 | 2014-06-12 11:23:40 -0700 | [diff] [blame] | 295 | "android.bluetooth.headsetclient.extra.EXTRA_AG_FEATURE_ATTACH_NUMBER_TO_VT"; |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 296 | /** |
| 297 | * AG feature: ability to reject incoming call. |
| 298 | */ |
Jack He | 2992cd0 | 2017-08-22 21:21:23 -0700 | [diff] [blame] | 299 | public static final String EXTRA_AG_FEATURE_REJECT_CALL = |
Mike Lockwood | cf916d3 | 2014-06-12 11:23:40 -0700 | [diff] [blame] | 300 | "android.bluetooth.headsetclient.extra.EXTRA_AG_FEATURE_REJECT_CALL"; |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 301 | /** |
| 302 | * AG feature: enhanced call handling (terminate specific call, private consultation). |
| 303 | */ |
Jack He | 2992cd0 | 2017-08-22 21:21:23 -0700 | [diff] [blame] | 304 | public static final String EXTRA_AG_FEATURE_ECC = |
Mike Lockwood | cf916d3 | 2014-06-12 11:23:40 -0700 | [diff] [blame] | 305 | "android.bluetooth.headsetclient.extra.EXTRA_AG_FEATURE_ECC"; |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 306 | /** |
| 307 | * AG feature: response and hold. |
| 308 | */ |
Jack He | 2992cd0 | 2017-08-22 21:21:23 -0700 | [diff] [blame] | 309 | public static final String EXTRA_AG_FEATURE_RESPONSE_AND_HOLD = |
Mike Lockwood | cf916d3 | 2014-06-12 11:23:40 -0700 | [diff] [blame] | 310 | "android.bluetooth.headsetclient.extra.EXTRA_AG_FEATURE_RESPONSE_AND_HOLD"; |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 311 | /** |
| 312 | * AG call handling feature: accept held or waiting call in three way calling scenarios. |
| 313 | */ |
Jack He | 2992cd0 | 2017-08-22 21:21:23 -0700 | [diff] [blame] | 314 | public static final String EXTRA_AG_FEATURE_ACCEPT_HELD_OR_WAITING_CALL = |
Mike Lockwood | cf916d3 | 2014-06-12 11:23:40 -0700 | [diff] [blame] | 315 | "android.bluetooth.headsetclient.extra.EXTRA_AG_FEATURE_ACCEPT_HELD_OR_WAITING_CALL"; |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 316 | /** |
| 317 | * AG call handling feature: release held or waiting call in three way calling scenarios. |
| 318 | */ |
Jack He | 2992cd0 | 2017-08-22 21:21:23 -0700 | [diff] [blame] | 319 | public static final String EXTRA_AG_FEATURE_RELEASE_HELD_OR_WAITING_CALL = |
Mike Lockwood | cf916d3 | 2014-06-12 11:23:40 -0700 | [diff] [blame] | 320 | "android.bluetooth.headsetclient.extra.EXTRA_AG_FEATURE_RELEASE_HELD_OR_WAITING_CALL"; |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 321 | /** |
| 322 | * AG call handling feature: release active call and accept held or waiting call in three way |
| 323 | * calling scenarios. |
| 324 | */ |
Jack He | 2992cd0 | 2017-08-22 21:21:23 -0700 | [diff] [blame] | 325 | public static final String EXTRA_AG_FEATURE_RELEASE_AND_ACCEPT = |
Mike Lockwood | cf916d3 | 2014-06-12 11:23:40 -0700 | [diff] [blame] | 326 | "android.bluetooth.headsetclient.extra.EXTRA_AG_FEATURE_RELEASE_AND_ACCEPT"; |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 327 | /** |
| 328 | * AG call handling feature: merge two calls, held and active - multi party conference mode. |
| 329 | */ |
Jack He | 2992cd0 | 2017-08-22 21:21:23 -0700 | [diff] [blame] | 330 | public static final String EXTRA_AG_FEATURE_MERGE = |
Mike Lockwood | cf916d3 | 2014-06-12 11:23:40 -0700 | [diff] [blame] | 331 | "android.bluetooth.headsetclient.extra.EXTRA_AG_FEATURE_MERGE"; |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 332 | /** |
| 333 | * AG call handling feature: merge calls and disconnect from multi party |
| 334 | * conversation leaving peers connected to each other. |
| 335 | * Note that this feature needs to be supported by mobile network operator |
| 336 | * as it requires connection and billing transfer. |
| 337 | */ |
Jack He | 2992cd0 | 2017-08-22 21:21:23 -0700 | [diff] [blame] | 338 | public static final String EXTRA_AG_FEATURE_MERGE_AND_DETACH = |
Mike Lockwood | cf916d3 | 2014-06-12 11:23:40 -0700 | [diff] [blame] | 339 | "android.bluetooth.headsetclient.extra.EXTRA_AG_FEATURE_MERGE_AND_DETACH"; |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 340 | |
| 341 | /* Action result codes */ |
Jack He | 2992cd0 | 2017-08-22 21:21:23 -0700 | [diff] [blame] | 342 | public static final int ACTION_RESULT_OK = 0; |
| 343 | public static final int ACTION_RESULT_ERROR = 1; |
| 344 | public static final int ACTION_RESULT_ERROR_NO_CARRIER = 2; |
| 345 | public static final int ACTION_RESULT_ERROR_BUSY = 3; |
| 346 | public static final int ACTION_RESULT_ERROR_NO_ANSWER = 4; |
| 347 | public static final int ACTION_RESULT_ERROR_DELAYED = 5; |
| 348 | public static final int ACTION_RESULT_ERROR_BLACKLISTED = 6; |
| 349 | public static final int ACTION_RESULT_ERROR_CME = 7; |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 350 | |
| 351 | /* Detailed CME error codes */ |
Jack He | 2992cd0 | 2017-08-22 21:21:23 -0700 | [diff] [blame] | 352 | public static final int CME_PHONE_FAILURE = 0; |
| 353 | public static final int CME_NO_CONNECTION_TO_PHONE = 1; |
| 354 | public static final int CME_OPERATION_NOT_ALLOWED = 3; |
| 355 | public static final int CME_OPERATION_NOT_SUPPORTED = 4; |
| 356 | public static final int CME_PHSIM_PIN_REQUIRED = 5; |
| 357 | public static final int CME_PHFSIM_PIN_REQUIRED = 6; |
| 358 | public static final int CME_PHFSIM_PUK_REQUIRED = 7; |
| 359 | public static final int CME_SIM_NOT_INSERTED = 10; |
| 360 | public static final int CME_SIM_PIN_REQUIRED = 11; |
| 361 | public static final int CME_SIM_PUK_REQUIRED = 12; |
| 362 | public static final int CME_SIM_FAILURE = 13; |
| 363 | public static final int CME_SIM_BUSY = 14; |
| 364 | public static final int CME_SIM_WRONG = 15; |
| 365 | public static final int CME_INCORRECT_PASSWORD = 16; |
| 366 | public static final int CME_SIM_PIN2_REQUIRED = 17; |
| 367 | public static final int CME_SIM_PUK2_REQUIRED = 18; |
| 368 | public static final int CME_MEMORY_FULL = 20; |
| 369 | public static final int CME_INVALID_INDEX = 21; |
| 370 | public static final int CME_NOT_FOUND = 22; |
| 371 | public static final int CME_MEMORY_FAILURE = 23; |
| 372 | public static final int CME_TEXT_STRING_TOO_LONG = 24; |
| 373 | public static final int CME_INVALID_CHARACTER_IN_TEXT_STRING = 25; |
| 374 | public static final int CME_DIAL_STRING_TOO_LONG = 26; |
| 375 | public static final int CME_INVALID_CHARACTER_IN_DIAL_STRING = 27; |
| 376 | public static final int CME_NO_NETWORK_SERVICE = 30; |
| 377 | public static final int CME_NETWORK_TIMEOUT = 31; |
| 378 | public static final int CME_EMERGENCY_SERVICE_ONLY = 32; |
| 379 | public static final int CME_NO_SIMULTANOUS_VOIP_CS_CALLS = 33; |
| 380 | public static final int CME_NOT_SUPPORTED_FOR_VOIP = 34; |
| 381 | public static final int CME_SIP_RESPONSE_CODE = 35; |
| 382 | public static final int CME_NETWORK_PERSONALIZATION_PIN_REQUIRED = 40; |
| 383 | public static final int CME_NETWORK_PERSONALIZATION_PUK_REQUIRED = 41; |
| 384 | public static final int CME_NETWORK_SUBSET_PERSONALIZATION_PIN_REQUIRED = 42; |
| 385 | public static final int CME_NETWORK_SUBSET_PERSONALIZATION_PUK_REQUIRED = 43; |
| 386 | public static final int CME_SERVICE_PROVIDER_PERSONALIZATION_PIN_REQUIRED = 44; |
| 387 | public static final int CME_SERVICE_PROVIDER_PERSONALIZATION_PUK_REQUIRED = 45; |
| 388 | public static final int CME_CORPORATE_PERSONALIZATION_PIN_REQUIRED = 46; |
| 389 | public static final int CME_CORPORATE_PERSONALIZATION_PUK_REQUIRED = 47; |
| 390 | public static final int CME_HIDDEN_KEY_REQUIRED = 48; |
| 391 | public static final int CME_EAP_NOT_SUPPORTED = 49; |
| 392 | public static final int CME_INCORRECT_PARAMETERS = 50; |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 393 | |
| 394 | /* Action policy for other calls when accepting call */ |
| 395 | public static final int CALL_ACCEPT_NONE = 0; |
| 396 | public static final int CALL_ACCEPT_HOLD = 1; |
| 397 | public static final int CALL_ACCEPT_TERMINATE = 2; |
| 398 | |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 399 | private BluetoothAdapter mAdapter; |
Ugo Yu | d011546 | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 400 | private final BluetoothProfileConnector<IBluetoothHeadsetClient> mProfileConnector = |
| 401 | new BluetoothProfileConnector(this, BluetoothProfile.HEADSET_CLIENT, |
| 402 | "BluetoothHeadsetClient", IBluetoothHeadsetClient.class.getName()) { |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 403 | @Override |
Ugo Yu | d011546 | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 404 | public IBluetoothHeadsetClient getServiceInterface(IBinder service) { |
| 405 | return IBluetoothHeadsetClient.Stub.asInterface(Binder.allowBlocking(service)); |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 406 | } |
Ugo Yu | d011546 | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 407 | }; |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 408 | |
| 409 | /** |
Mike Lockwood | cf916d3 | 2014-06-12 11:23:40 -0700 | [diff] [blame] | 410 | * Create a BluetoothHeadsetClient proxy object. |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 411 | */ |
Ugo Yu | d011546 | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 412 | /*package*/ BluetoothHeadsetClient(Context context, ServiceListener listener) { |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 413 | mAdapter = BluetoothAdapter.getDefaultAdapter(); |
Ugo Yu | d011546 | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 414 | mProfileConnector.connect(context, listener); |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 415 | } |
| 416 | |
| 417 | /** |
| 418 | * Close the connection to the backing service. |
Mike Lockwood | cf916d3 | 2014-06-12 11:23:40 -0700 | [diff] [blame] | 419 | * Other public functions of BluetoothHeadsetClient will return default error |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 420 | * results once close() has been called. Multiple invocations of close() |
| 421 | * are ok. |
| 422 | */ |
| 423 | /*package*/ void close() { |
| 424 | if (VDBG) log("close()"); |
Ugo Yu | d011546 | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 425 | mProfileConnector.disconnect(); |
| 426 | } |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 427 | |
Ugo Yu | d011546 | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 428 | private IBluetoothHeadsetClient getService() { |
| 429 | return mProfileConnector.getService(); |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 430 | } |
| 431 | |
| 432 | /** |
| 433 | * Connects to remote device. |
| 434 | * |
| 435 | * Currently, the system supports only 1 connection. So, in case of the |
| 436 | * second connection, this implementation will disconnect already connected |
| 437 | * device automatically and will process the new one. |
| 438 | * |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 439 | * @param device a remote device we want connect to |
| 440 | * @return <code>true</code> if command has been issued successfully; <code>false</code> |
| 441 | * otherwise; upon completion HFP sends {@link #ACTION_CONNECTION_STATE_CHANGED} intent. |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 442 | */ |
Mathew Inwood | 4dc66d3 | 2018-08-01 15:07:20 +0100 | [diff] [blame] | 443 | @UnsupportedAppUsage |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 444 | public boolean connect(BluetoothDevice device) { |
| 445 | if (DBG) log("connect(" + device + ")"); |
Ugo Yu | d011546 | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 446 | final IBluetoothHeadsetClient service = |
| 447 | getService(); |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 448 | if (service != null && isEnabled() && isValidDevice(device)) { |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 449 | try { |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 450 | return service.connect(device); |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 451 | } catch (RemoteException e) { |
| 452 | Log.e(TAG, Log.getStackTraceString(new Throwable())); |
| 453 | return false; |
| 454 | } |
| 455 | } |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 456 | if (service == null) Log.w(TAG, "Proxy not attached to service"); |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 457 | return false; |
| 458 | } |
| 459 | |
| 460 | /** |
| 461 | * Disconnects remote device |
| 462 | * |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 463 | * @param device a remote device we want disconnect |
| 464 | * @return <code>true</code> if command has been issued successfully; <code>false</code> |
| 465 | * otherwise; upon completion HFP sends {@link #ACTION_CONNECTION_STATE_CHANGED} intent. |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 466 | */ |
Mathew Inwood | 4dc66d3 | 2018-08-01 15:07:20 +0100 | [diff] [blame] | 467 | @UnsupportedAppUsage |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 468 | public boolean disconnect(BluetoothDevice device) { |
| 469 | if (DBG) log("disconnect(" + device + ")"); |
Ugo Yu | d011546 | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 470 | final IBluetoothHeadsetClient service = |
| 471 | getService(); |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 472 | if (service != null && isEnabled() && isValidDevice(device)) { |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 473 | try { |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 474 | return service.disconnect(device); |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 475 | } catch (RemoteException e) { |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 476 | Log.e(TAG, Log.getStackTraceString(new Throwable())); |
| 477 | return false; |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 478 | } |
| 479 | } |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 480 | if (service == null) Log.w(TAG, "Proxy not attached to service"); |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 481 | return false; |
| 482 | } |
| 483 | |
| 484 | /** |
| 485 | * Return the list of connected remote devices |
| 486 | * |
| 487 | * @return list of connected devices; empty list if nothing is connected. |
| 488 | */ |
| 489 | @Override |
| 490 | public List<BluetoothDevice> getConnectedDevices() { |
| 491 | if (VDBG) log("getConnectedDevices()"); |
Ugo Yu | d011546 | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 492 | final IBluetoothHeadsetClient service = |
| 493 | getService(); |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 494 | if (service != null && isEnabled()) { |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 495 | try { |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 496 | return service.getConnectedDevices(); |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 497 | } catch (RemoteException e) { |
| 498 | Log.e(TAG, Log.getStackTraceString(new Throwable())); |
| 499 | return new ArrayList<BluetoothDevice>(); |
| 500 | } |
| 501 | } |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 502 | if (service == null) Log.w(TAG, "Proxy not attached to service"); |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 503 | return new ArrayList<BluetoothDevice>(); |
| 504 | } |
| 505 | |
| 506 | /** |
| 507 | * Returns list of remote devices in a particular state |
| 508 | * |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 509 | * @param states collection of states |
| 510 | * @return list of devices that state matches the states listed in <code>states</code>; empty |
| 511 | * list if nothing matches the <code>states</code> |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 512 | */ |
| 513 | @Override |
| 514 | public List<BluetoothDevice> getDevicesMatchingConnectionStates(int[] states) { |
| 515 | if (VDBG) log("getDevicesMatchingStates()"); |
Ugo Yu | d011546 | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 516 | final IBluetoothHeadsetClient service = |
| 517 | getService(); |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 518 | if (service != null && isEnabled()) { |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 519 | try { |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 520 | return service.getDevicesMatchingConnectionStates(states); |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 521 | } catch (RemoteException e) { |
| 522 | Log.e(TAG, Log.getStackTraceString(new Throwable())); |
| 523 | return new ArrayList<BluetoothDevice>(); |
| 524 | } |
| 525 | } |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 526 | if (service == null) Log.w(TAG, "Proxy not attached to service"); |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 527 | return new ArrayList<BluetoothDevice>(); |
| 528 | } |
| 529 | |
| 530 | /** |
| 531 | * Returns state of the <code>device</code> |
| 532 | * |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 533 | * @param device a remote device |
| 534 | * @return the state of connection of the device |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 535 | */ |
| 536 | @Override |
| 537 | public int getConnectionState(BluetoothDevice device) { |
| 538 | if (VDBG) log("getConnectionState(" + device + ")"); |
Ugo Yu | d011546 | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 539 | final IBluetoothHeadsetClient service = |
| 540 | getService(); |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 541 | if (service != null && isEnabled() && isValidDevice(device)) { |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 542 | try { |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 543 | return service.getConnectionState(device); |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 544 | } catch (RemoteException e) { |
| 545 | Log.e(TAG, Log.getStackTraceString(new Throwable())); |
| 546 | return BluetoothProfile.STATE_DISCONNECTED; |
| 547 | } |
| 548 | } |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 549 | if (service == null) Log.w(TAG, "Proxy not attached to service"); |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 550 | return BluetoothProfile.STATE_DISCONNECTED; |
| 551 | } |
| 552 | |
| 553 | /** |
| 554 | * Set priority of the profile |
| 555 | * |
| 556 | * The device should already be paired. |
| 557 | */ |
| 558 | public boolean setPriority(BluetoothDevice device, int priority) { |
| 559 | if (DBG) log("setPriority(" + device + ", " + priority + ")"); |
Ugo Yu | d011546 | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 560 | final IBluetoothHeadsetClient service = |
| 561 | getService(); |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 562 | if (service != null && isEnabled() && isValidDevice(device)) { |
Jack He | 2992cd0 | 2017-08-22 21:21:23 -0700 | [diff] [blame] | 563 | if (priority != BluetoothProfile.PRIORITY_OFF |
| 564 | && priority != BluetoothProfile.PRIORITY_ON) { |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 565 | return false; |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 566 | } |
| 567 | try { |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 568 | return service.setPriority(device, priority); |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 569 | } catch (RemoteException e) { |
| 570 | Log.e(TAG, Log.getStackTraceString(new Throwable())); |
| 571 | return false; |
| 572 | } |
| 573 | } |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 574 | if (service == null) Log.w(TAG, "Proxy not attached to service"); |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 575 | return false; |
| 576 | } |
| 577 | |
| 578 | /** |
| 579 | * Get the priority of the profile. |
| 580 | */ |
| 581 | public int getPriority(BluetoothDevice device) { |
| 582 | if (VDBG) log("getPriority(" + device + ")"); |
Ugo Yu | d011546 | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 583 | final IBluetoothHeadsetClient service = |
| 584 | getService(); |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 585 | if (service != null && isEnabled() && isValidDevice(device)) { |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 586 | try { |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 587 | return service.getPriority(device); |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 588 | } catch (RemoteException e) { |
| 589 | Log.e(TAG, Log.getStackTraceString(new Throwable())); |
| 590 | return PRIORITY_OFF; |
| 591 | } |
| 592 | } |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 593 | if (service == null) Log.w(TAG, "Proxy not attached to service"); |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 594 | return PRIORITY_OFF; |
| 595 | } |
| 596 | |
| 597 | /** |
| 598 | * Starts voice recognition. |
| 599 | * |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 600 | * @param device remote device |
| 601 | * @return <code>true</code> if command has been issued successfully; <code>false</code> |
| 602 | * otherwise; upon completion HFP sends {@link #ACTION_AG_EVENT} intent. |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 603 | * |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 604 | * <p>Feature required for successful execution is being reported by: {@link |
| 605 | * #EXTRA_AG_FEATURE_VOICE_RECOGNITION}. This method invocation will fail silently when feature |
| 606 | * is not supported.</p> |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 607 | */ |
| 608 | public boolean startVoiceRecognition(BluetoothDevice device) { |
| 609 | if (DBG) log("startVoiceRecognition()"); |
Ugo Yu | d011546 | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 610 | final IBluetoothHeadsetClient service = |
| 611 | getService(); |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 612 | if (service != null && isEnabled() && isValidDevice(device)) { |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 613 | try { |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 614 | return service.startVoiceRecognition(device); |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 615 | } catch (RemoteException e) { |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 616 | Log.e(TAG, Log.getStackTraceString(new Throwable())); |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 617 | } |
| 618 | } |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 619 | if (service == null) Log.w(TAG, "Proxy not attached to service"); |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 620 | return false; |
| 621 | } |
| 622 | |
| 623 | /** |
Deqiang Chen | 2fec85d | 2019-06-25 14:30:55 -0700 | [diff] [blame] | 624 | * Send vendor specific AT command. |
| 625 | * |
| 626 | * @param device remote device |
| 627 | * @param vendorId vendor number by Bluetooth SIG |
| 628 | * @param atCommand command to be sent. It start with + prefix and only one command at one time. |
| 629 | * @return <code>true</code> if command has been issued successfully; <code>false</code> |
| 630 | * otherwise. |
| 631 | */ |
| 632 | public boolean sendVendorAtCommand(BluetoothDevice device, int vendorId, |
| 633 | String atCommand) { |
| 634 | if (DBG) log("sendVendorSpecificCommand()"); |
| 635 | final IBluetoothHeadsetClient service = |
| 636 | getService(); |
| 637 | if (service != null && isEnabled() && isValidDevice(device)) { |
| 638 | try { |
| 639 | return service.sendVendorAtCommand(device, vendorId, atCommand); |
| 640 | } catch (RemoteException e) { |
| 641 | Log.e(TAG, Log.getStackTraceString(new Throwable())); |
| 642 | } |
| 643 | } |
| 644 | if (service == null) Log.w(TAG, "Proxy not attached to service"); |
| 645 | return false; |
| 646 | } |
| 647 | |
| 648 | /** |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 649 | * Stops voice recognition. |
| 650 | * |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 651 | * @param device remote device |
| 652 | * @return <code>true</code> if command has been issued successfully; <code>false</code> |
| 653 | * otherwise; upon completion HFP sends {@link #ACTION_AG_EVENT} intent. |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 654 | * |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 655 | * <p>Feature required for successful execution is being reported by: {@link |
| 656 | * #EXTRA_AG_FEATURE_VOICE_RECOGNITION}. This method invocation will fail silently when feature |
| 657 | * is not supported.</p> |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 658 | */ |
| 659 | public boolean stopVoiceRecognition(BluetoothDevice device) { |
| 660 | if (DBG) log("stopVoiceRecognition()"); |
Ugo Yu | d011546 | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 661 | final IBluetoothHeadsetClient service = |
| 662 | getService(); |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 663 | if (service != null && isEnabled() && isValidDevice(device)) { |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 664 | try { |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 665 | return service.stopVoiceRecognition(device); |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 666 | } catch (RemoteException e) { |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 667 | Log.e(TAG, Log.getStackTraceString(new Throwable())); |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 668 | } |
| 669 | } |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 670 | if (service == null) Log.w(TAG, "Proxy not attached to service"); |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 671 | return false; |
| 672 | } |
| 673 | |
| 674 | /** |
| 675 | * Returns list of all calls in any state. |
| 676 | * |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 677 | * @param device remote device |
| 678 | * @return list of calls; empty list if none call exists |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 679 | */ |
Mike Lockwood | cf916d3 | 2014-06-12 11:23:40 -0700 | [diff] [blame] | 680 | public List<BluetoothHeadsetClientCall> getCurrentCalls(BluetoothDevice device) { |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 681 | if (DBG) log("getCurrentCalls()"); |
Ugo Yu | d011546 | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 682 | final IBluetoothHeadsetClient service = |
| 683 | getService(); |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 684 | if (service != null && isEnabled() && isValidDevice(device)) { |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 685 | try { |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 686 | return service.getCurrentCalls(device); |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 687 | } catch (RemoteException e) { |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 688 | Log.e(TAG, Log.getStackTraceString(new Throwable())); |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 689 | } |
| 690 | } |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 691 | if (service == null) Log.w(TAG, "Proxy not attached to service"); |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 692 | return null; |
| 693 | } |
| 694 | |
| 695 | /** |
| 696 | * Returns list of current values of AG indicators. |
| 697 | * |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 698 | * @param device remote device |
| 699 | * @return bundle of AG indicators; null if device is not in CONNECTED state |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 700 | */ |
| 701 | public Bundle getCurrentAgEvents(BluetoothDevice device) { |
| 702 | if (DBG) log("getCurrentCalls()"); |
Ugo Yu | d011546 | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 703 | final IBluetoothHeadsetClient service = |
| 704 | getService(); |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 705 | if (service != null && isEnabled() && isValidDevice(device)) { |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 706 | try { |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 707 | return service.getCurrentAgEvents(device); |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 708 | } catch (RemoteException e) { |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 709 | Log.e(TAG, Log.getStackTraceString(new Throwable())); |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 710 | } |
| 711 | } |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 712 | if (service == null) Log.w(TAG, "Proxy not attached to service"); |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 713 | return null; |
| 714 | } |
| 715 | |
| 716 | /** |
| 717 | * Accepts a call |
| 718 | * |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 719 | * @param device remote device |
| 720 | * @param flag action policy while accepting a call. Possible values {@link #CALL_ACCEPT_NONE}, |
| 721 | * {@link #CALL_ACCEPT_HOLD}, {@link #CALL_ACCEPT_TERMINATE} |
| 722 | * @return <code>true</code> if command has been issued successfully; <code>false</code> |
| 723 | * otherwise; upon completion HFP sends {@link #ACTION_CALL_CHANGED} intent. |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 724 | */ |
Mathew Inwood | 4dc66d3 | 2018-08-01 15:07:20 +0100 | [diff] [blame] | 725 | @UnsupportedAppUsage |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 726 | public boolean acceptCall(BluetoothDevice device, int flag) { |
| 727 | if (DBG) log("acceptCall()"); |
Ugo Yu | d011546 | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 728 | final IBluetoothHeadsetClient service = |
| 729 | getService(); |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 730 | if (service != null && isEnabled() && isValidDevice(device)) { |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 731 | try { |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 732 | return service.acceptCall(device, flag); |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 733 | } catch (RemoteException e) { |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 734 | Log.e(TAG, Log.getStackTraceString(new Throwable())); |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 735 | } |
| 736 | } |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 737 | if (service == null) Log.w(TAG, "Proxy not attached to service"); |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 738 | return false; |
| 739 | } |
| 740 | |
| 741 | /** |
| 742 | * Holds a call. |
| 743 | * |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 744 | * @param device remote device |
| 745 | * @return <code>true</code> if command has been issued successfully; <code>false</code> |
| 746 | * otherwise; upon completion HFP sends {@link #ACTION_CALL_CHANGED} intent. |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 747 | */ |
| 748 | public boolean holdCall(BluetoothDevice device) { |
| 749 | if (DBG) log("holdCall()"); |
Ugo Yu | d011546 | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 750 | final IBluetoothHeadsetClient service = |
| 751 | getService(); |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 752 | if (service != null && isEnabled() && isValidDevice(device)) { |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 753 | try { |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 754 | return service.holdCall(device); |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 755 | } catch (RemoteException e) { |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 756 | Log.e(TAG, Log.getStackTraceString(new Throwable())); |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 757 | } |
| 758 | } |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 759 | if (service == null) Log.w(TAG, "Proxy not attached to service"); |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 760 | return false; |
| 761 | } |
| 762 | |
| 763 | /** |
| 764 | * Rejects a call. |
| 765 | * |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 766 | * @param device remote device |
| 767 | * @return <code>true</code> if command has been issued successfully; <code>false</code> |
| 768 | * otherwise; upon completion HFP sends {@link #ACTION_CALL_CHANGED} intent. |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 769 | * |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 770 | * <p>Feature required for successful execution is being reported by: {@link |
| 771 | * #EXTRA_AG_FEATURE_REJECT_CALL}. This method invocation will fail silently when feature is not |
| 772 | * supported.</p> |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 773 | */ |
Mathew Inwood | 4dc66d3 | 2018-08-01 15:07:20 +0100 | [diff] [blame] | 774 | @UnsupportedAppUsage |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 775 | public boolean rejectCall(BluetoothDevice device) { |
| 776 | if (DBG) log("rejectCall()"); |
Ugo Yu | d011546 | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 777 | final IBluetoothHeadsetClient service = |
| 778 | getService(); |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 779 | if (service != null && isEnabled() && isValidDevice(device)) { |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 780 | try { |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 781 | return service.rejectCall(device); |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 782 | } catch (RemoteException e) { |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 783 | Log.e(TAG, Log.getStackTraceString(new Throwable())); |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 784 | } |
| 785 | } |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 786 | if (service == null) Log.w(TAG, "Proxy not attached to service"); |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 787 | return false; |
| 788 | } |
| 789 | |
| 790 | /** |
| 791 | * Terminates a specified call. |
| 792 | * |
| 793 | * Works only when Extended Call Control is supported by Audio Gateway. |
| 794 | * |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 795 | * @param device remote device |
Jack He | 2992cd0 | 2017-08-22 21:21:23 -0700 | [diff] [blame] | 796 | * @param call Handle of call obtained in {@link #dial(BluetoothDevice, String)} or obtained via |
| 797 | * {@link #ACTION_CALL_CHANGED}. {@code call} may be null in which case we will hangup all active |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 798 | * calls. |
| 799 | * @return <code>true</code> if command has been issued successfully; <code>false</code> |
| 800 | * otherwise; upon completion HFP sends {@link #ACTION_CALL_CHANGED} intent. |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 801 | * |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 802 | * <p>Feature required for successful execution is being reported by: {@link |
| 803 | * #EXTRA_AG_FEATURE_ECC}. This method invocation will fail silently when feature is not |
| 804 | * supported.</p> |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 805 | */ |
Sanket Agarwal | 40bb6f3 | 2016-06-27 20:13:54 -0700 | [diff] [blame] | 806 | public boolean terminateCall(BluetoothDevice device, BluetoothHeadsetClientCall call) { |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 807 | if (DBG) log("terminateCall()"); |
Ugo Yu | d011546 | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 808 | final IBluetoothHeadsetClient service = |
| 809 | getService(); |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 810 | if (service != null && isEnabled() && isValidDevice(device)) { |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 811 | try { |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 812 | return service.terminateCall(device, call); |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 813 | } catch (RemoteException e) { |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 814 | Log.e(TAG, Log.getStackTraceString(new Throwable())); |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 815 | } |
| 816 | } |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 817 | if (service == null) Log.w(TAG, "Proxy not attached to service"); |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 818 | return false; |
| 819 | } |
| 820 | |
| 821 | /** |
| 822 | * Enters private mode with a specified call. |
| 823 | * |
| 824 | * Works only when Extended Call Control is supported by Audio Gateway. |
| 825 | * |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 826 | * @param device remote device |
| 827 | * @param index index of the call to connect in private mode |
| 828 | * @return <code>true</code> if command has been issued successfully; <code>false</code> |
| 829 | * otherwise; upon completion HFP sends {@link #ACTION_CALL_CHANGED} intent. |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 830 | * |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 831 | * <p>Feature required for successful execution is being reported by: {@link |
| 832 | * #EXTRA_AG_FEATURE_ECC}. This method invocation will fail silently when feature is not |
| 833 | * supported.</p> |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 834 | */ |
| 835 | public boolean enterPrivateMode(BluetoothDevice device, int index) { |
| 836 | if (DBG) log("enterPrivateMode()"); |
Ugo Yu | d011546 | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 837 | final IBluetoothHeadsetClient service = |
| 838 | getService(); |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 839 | if (service != null && isEnabled() && isValidDevice(device)) { |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 840 | try { |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 841 | return service.enterPrivateMode(device, index); |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 842 | } catch (RemoteException e) { |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 843 | Log.e(TAG, Log.getStackTraceString(new Throwable())); |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 844 | } |
| 845 | } |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 846 | if (service == null) Log.w(TAG, "Proxy not attached to service"); |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 847 | return false; |
| 848 | } |
| 849 | |
| 850 | /** |
| 851 | * Performs explicit call transfer. |
| 852 | * |
| 853 | * That means connect other calls and disconnect. |
| 854 | * |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 855 | * @param device remote device |
| 856 | * @return <code>true</code> if command has been issued successfully; <code>false</code> |
| 857 | * otherwise; upon completion HFP sends {@link #ACTION_CALL_CHANGED} intent. |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 858 | * |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 859 | * <p>Feature required for successful execution is being reported by: {@link |
| 860 | * #EXTRA_AG_FEATURE_MERGE_AND_DETACH}. This method invocation will fail silently when feature |
| 861 | * is not supported.</p> |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 862 | */ |
| 863 | public boolean explicitCallTransfer(BluetoothDevice device) { |
| 864 | if (DBG) log("explicitCallTransfer()"); |
Ugo Yu | d011546 | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 865 | final IBluetoothHeadsetClient service = |
| 866 | getService(); |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 867 | if (service != null && isEnabled() && isValidDevice(device)) { |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 868 | try { |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 869 | return service.explicitCallTransfer(device); |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 870 | } catch (RemoteException e) { |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 871 | Log.e(TAG, Log.getStackTraceString(new Throwable())); |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 872 | } |
| 873 | } |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 874 | if (service == null) Log.w(TAG, "Proxy not attached to service"); |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 875 | return false; |
| 876 | } |
| 877 | |
| 878 | /** |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 879 | * Places a call with specified number. |
| 880 | * |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 881 | * @param device remote device |
| 882 | * @param number valid phone number |
| 883 | * @return <code>{@link BluetoothHeadsetClientCall} call</code> if command has been issued |
| 884 | * successfully; <code>{@link null}</code> otherwise; upon completion HFP sends {@link |
| 885 | * #ACTION_CALL_CHANGED} intent in case of success; {@link #ACTION_RESULT} is sent otherwise; |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 886 | */ |
Sanket Agarwal | 40bb6f3 | 2016-06-27 20:13:54 -0700 | [diff] [blame] | 887 | public BluetoothHeadsetClientCall dial(BluetoothDevice device, String number) { |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 888 | if (DBG) log("dial()"); |
Ugo Yu | d011546 | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 889 | final IBluetoothHeadsetClient service = |
| 890 | getService(); |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 891 | if (service != null && isEnabled() && isValidDevice(device)) { |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 892 | try { |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 893 | return service.dial(device, number); |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 894 | } catch (RemoteException e) { |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 895 | Log.e(TAG, Log.getStackTraceString(new Throwable())); |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 896 | } |
| 897 | } |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 898 | if (service == null) Log.w(TAG, "Proxy not attached to service"); |
Sanket Agarwal | 40bb6f3 | 2016-06-27 20:13:54 -0700 | [diff] [blame] | 899 | return null; |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 900 | } |
| 901 | |
| 902 | /** |
| 903 | * Sends DTMF code. |
| 904 | * |
| 905 | * Possible code values : 0,1,2,3,4,5,6,7,8,9,A,B,C,D,*,# |
| 906 | * |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 907 | * @param device remote device |
| 908 | * @param code ASCII code |
| 909 | * @return <code>true</code> if command has been issued successfully; <code>false</code> |
| 910 | * otherwise; upon completion HFP sends {@link #ACTION_RESULT} intent; |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 911 | */ |
| 912 | public boolean sendDTMF(BluetoothDevice device, byte code) { |
| 913 | if (DBG) log("sendDTMF()"); |
Ugo Yu | d011546 | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 914 | final IBluetoothHeadsetClient service = |
| 915 | getService(); |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 916 | if (service != null && isEnabled() && isValidDevice(device)) { |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 917 | try { |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 918 | return service.sendDTMF(device, code); |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 919 | } catch (RemoteException e) { |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 920 | Log.e(TAG, Log.getStackTraceString(new Throwable())); |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 921 | } |
| 922 | } |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 923 | if (service == null) Log.w(TAG, "Proxy not attached to service"); |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 924 | return false; |
| 925 | } |
| 926 | |
| 927 | /** |
| 928 | * Get a number corresponding to last voice tag recorded on AG. |
| 929 | * |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 930 | * @param device remote device |
| 931 | * @return <code>true</code> if command has been issued successfully; <code>false</code> |
| 932 | * otherwise; upon completion HFP sends {@link #ACTION_LAST_VTAG} or {@link #ACTION_RESULT} |
| 933 | * intent; |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 934 | * |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 935 | * <p>Feature required for successful execution is being reported by: {@link |
| 936 | * #EXTRA_AG_FEATURE_ATTACH_NUMBER_TO_VT}. This method invocation will fail silently when |
| 937 | * feature is not supported.</p> |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 938 | */ |
| 939 | public boolean getLastVoiceTagNumber(BluetoothDevice device) { |
| 940 | if (DBG) log("getLastVoiceTagNumber()"); |
Ugo Yu | d011546 | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 941 | final IBluetoothHeadsetClient service = |
| 942 | getService(); |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 943 | if (service != null && isEnabled() && isValidDevice(device)) { |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 944 | try { |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 945 | return service.getLastVoiceTagNumber(device); |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 946 | } catch (RemoteException e) { |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 947 | Log.e(TAG, Log.getStackTraceString(new Throwable())); |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 948 | } |
| 949 | } |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 950 | if (service == null) Log.w(TAG, "Proxy not attached to service"); |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 951 | return false; |
| 952 | } |
| 953 | |
| 954 | /** |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 955 | * Returns current audio state of Audio Gateway. |
| 956 | * |
| 957 | * Note: This is an internal function and shouldn't be exposed |
| 958 | */ |
Mathew Inwood | 4dc66d3 | 2018-08-01 15:07:20 +0100 | [diff] [blame] | 959 | @UnsupportedAppUsage |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 960 | public int getAudioState(BluetoothDevice device) { |
| 961 | if (VDBG) log("getAudioState"); |
Ugo Yu | d011546 | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 962 | final IBluetoothHeadsetClient service = |
| 963 | getService(); |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 964 | if (service != null && isEnabled()) { |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 965 | try { |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 966 | return service.getAudioState(device); |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 967 | } catch (RemoteException e) { |
| 968 | Log.e(TAG, e.toString()); |
| 969 | } |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 970 | } else { |
| 971 | Log.w(TAG, "Proxy not attached to service"); |
| 972 | if (DBG) Log.d(TAG, Log.getStackTraceString(new Throwable())); |
| 973 | } |
Mike Lockwood | cf916d3 | 2014-06-12 11:23:40 -0700 | [diff] [blame] | 974 | return BluetoothHeadsetClient.STATE_AUDIO_DISCONNECTED; |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 975 | } |
| 976 | |
| 977 | /** |
Bryce Lee | dc13382 | 2015-10-28 22:21:54 -0700 | [diff] [blame] | 978 | * Sets whether audio routing is allowed. |
| 979 | * |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 980 | * @param device remote device |
| 981 | * @param allowed if routing is allowed to the device Note: This is an internal function and |
| 982 | * shouldn't be exposed |
Bryce Lee | dc13382 | 2015-10-28 22:21:54 -0700 | [diff] [blame] | 983 | */ |
Sanket Agarwal | 039eeb8 | 2017-01-20 14:55:15 -0800 | [diff] [blame] | 984 | public void setAudioRouteAllowed(BluetoothDevice device, boolean allowed) { |
Bryce Lee | dc13382 | 2015-10-28 22:21:54 -0700 | [diff] [blame] | 985 | if (VDBG) log("setAudioRouteAllowed"); |
Ugo Yu | d011546 | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 986 | final IBluetoothHeadsetClient service = |
| 987 | getService(); |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 988 | if (service != null && isEnabled()) { |
Bryce Lee | dc13382 | 2015-10-28 22:21:54 -0700 | [diff] [blame] | 989 | try { |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 990 | service.setAudioRouteAllowed(device, allowed); |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 991 | } catch (RemoteException e) { |
| 992 | Log.e(TAG, e.toString()); |
| 993 | } |
Bryce Lee | dc13382 | 2015-10-28 22:21:54 -0700 | [diff] [blame] | 994 | } else { |
| 995 | Log.w(TAG, "Proxy not attached to service"); |
| 996 | if (DBG) Log.d(TAG, Log.getStackTraceString(new Throwable())); |
| 997 | } |
| 998 | } |
| 999 | |
| 1000 | /** |
| 1001 | * Returns whether audio routing is allowed. |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 1002 | * |
| 1003 | * @param device remote device |
| 1004 | * @return whether the command succeeded Note: This is an internal function and shouldn't be |
| 1005 | * exposed |
Bryce Lee | dc13382 | 2015-10-28 22:21:54 -0700 | [diff] [blame] | 1006 | */ |
Sanket Agarwal | 039eeb8 | 2017-01-20 14:55:15 -0800 | [diff] [blame] | 1007 | public boolean getAudioRouteAllowed(BluetoothDevice device) { |
Bryce Lee | dc13382 | 2015-10-28 22:21:54 -0700 | [diff] [blame] | 1008 | if (VDBG) log("getAudioRouteAllowed"); |
Ugo Yu | d011546 | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 1009 | final IBluetoothHeadsetClient service = |
| 1010 | getService(); |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 1011 | if (service != null && isEnabled()) { |
Bryce Lee | dc13382 | 2015-10-28 22:21:54 -0700 | [diff] [blame] | 1012 | try { |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 1013 | return service.getAudioRouteAllowed(device); |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 1014 | } catch (RemoteException e) { |
| 1015 | Log.e(TAG, e.toString()); |
| 1016 | } |
Bryce Lee | dc13382 | 2015-10-28 22:21:54 -0700 | [diff] [blame] | 1017 | } else { |
| 1018 | Log.w(TAG, "Proxy not attached to service"); |
| 1019 | if (DBG) Log.d(TAG, Log.getStackTraceString(new Throwable())); |
| 1020 | } |
| 1021 | return false; |
| 1022 | } |
| 1023 | |
| 1024 | /** |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 1025 | * Initiates a connection of audio channel. |
| 1026 | * |
| 1027 | * It setup SCO channel with remote connected Handsfree AG device. |
| 1028 | * |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 1029 | * @param device remote device |
| 1030 | * @return <code>true</code> if command has been issued successfully; <code>false</code> |
| 1031 | * otherwise; upon completion HFP sends {@link #ACTION_AUDIO_STATE_CHANGED} intent; |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 1032 | */ |
Sanket Agarwal | 039eeb8 | 2017-01-20 14:55:15 -0800 | [diff] [blame] | 1033 | public boolean connectAudio(BluetoothDevice device) { |
Ugo Yu | d011546 | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 1034 | final IBluetoothHeadsetClient service = |
| 1035 | getService(); |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 1036 | if (service != null && isEnabled()) { |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 1037 | try { |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 1038 | return service.connectAudio(device); |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 1039 | } catch (RemoteException e) { |
| 1040 | Log.e(TAG, e.toString()); |
| 1041 | } |
| 1042 | } else { |
| 1043 | Log.w(TAG, "Proxy not attached to service"); |
| 1044 | if (DBG) Log.d(TAG, Log.getStackTraceString(new Throwable())); |
| 1045 | } |
| 1046 | return false; |
| 1047 | } |
| 1048 | |
| 1049 | /** |
| 1050 | * Disconnects audio channel. |
| 1051 | * |
| 1052 | * It tears down the SCO channel from remote AG device. |
| 1053 | * |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 1054 | * @param device remote device |
| 1055 | * @return <code>true</code> if command has been issued successfully; <code>false</code> |
| 1056 | * otherwise; upon completion HFP sends {@link #ACTION_AUDIO_STATE_CHANGED} intent; |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 1057 | */ |
Sanket Agarwal | 039eeb8 | 2017-01-20 14:55:15 -0800 | [diff] [blame] | 1058 | public boolean disconnectAudio(BluetoothDevice device) { |
Ugo Yu | d011546 | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 1059 | final IBluetoothHeadsetClient service = |
| 1060 | getService(); |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 1061 | if (service != null && isEnabled()) { |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 1062 | try { |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 1063 | return service.disconnectAudio(device); |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 1064 | } catch (RemoteException e) { |
| 1065 | Log.e(TAG, e.toString()); |
| 1066 | } |
| 1067 | } else { |
| 1068 | Log.w(TAG, "Proxy not attached to service"); |
| 1069 | if (DBG) Log.d(TAG, Log.getStackTraceString(new Throwable())); |
| 1070 | } |
| 1071 | return false; |
| 1072 | } |
| 1073 | |
| 1074 | /** |
| 1075 | * Get Audio Gateway features |
| 1076 | * |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 1077 | * @param device remote device |
| 1078 | * @return bundle of AG features; null if no service or AG not connected |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 1079 | */ |
| 1080 | public Bundle getCurrentAgFeatures(BluetoothDevice device) { |
Ugo Yu | d011546 | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 1081 | final IBluetoothHeadsetClient service = |
| 1082 | getService(); |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 1083 | if (service != null && isEnabled()) { |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 1084 | try { |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 1085 | return service.getCurrentAgFeatures(device); |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 1086 | } catch (RemoteException e) { |
| 1087 | Log.e(TAG, e.toString()); |
| 1088 | } |
| 1089 | } else { |
| 1090 | Log.w(TAG, "Proxy not attached to service"); |
| 1091 | if (DBG) Log.d(TAG, Log.getStackTraceString(new Throwable())); |
| 1092 | } |
| 1093 | return null; |
| 1094 | } |
| 1095 | |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 1096 | private boolean isEnabled() { |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 1097 | return mAdapter.getState() == BluetoothAdapter.STATE_ON; |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 1098 | } |
| 1099 | |
Jack He | 16eeac3 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 1100 | private static boolean isValidDevice(BluetoothDevice device) { |
| 1101 | return device != null && BluetoothAdapter.checkBluetoothAddress(device.getAddress()); |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 1102 | } |
| 1103 | |
| 1104 | private static void log(String msg) { |
| 1105 | Log.d(TAG, msg); |
| 1106 | } |
| 1107 | } |