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