| The Android Open Source Project | 3389776 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 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 | |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 19 | import static android.bluetooth.BluetoothUtils.getSyncTimeout; |
| 20 | |
| Rahul Sabnis | 5ed1b84 | 2021-12-23 11:36:40 -0800 | [diff] [blame] | 21 | import android.annotation.IntDef; |
| Rahul Sabnis | e8bac9b | 2019-11-27 18:09:33 -0800 | [diff] [blame] | 22 | import android.annotation.NonNull; |
| Jack He | 889d234 | 2018-01-03 12:13:26 -0800 | [diff] [blame] | 23 | import android.annotation.Nullable; |
| Selim Gurun | a117cb37 | 2017-10-17 17:01:38 -0700 | [diff] [blame] | 24 | import android.annotation.RequiresPermission; |
| Nick Pelly | dac4c0d | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 25 | import android.annotation.SdkConstant; |
| 26 | import android.annotation.SdkConstant.SdkConstantType; |
| Roopa Sattiraju | ffab995 | 2021-08-20 15:06:57 -0700 | [diff] [blame] | 27 | import android.annotation.SuppressLint; |
| 28 | import android.annotation.SystemApi; |
| Jeff Sharkey | 8f80e4a | 2021-04-02 08:06:09 -0600 | [diff] [blame] | 29 | import android.bluetooth.annotations.RequiresBluetoothConnectPermission; |
| 30 | import android.bluetooth.annotations.RequiresLegacyBluetoothAdminPermission; |
| 31 | import android.bluetooth.annotations.RequiresLegacyBluetoothPermission; |
| Artur Satayev | 3625be4 | 2019-12-10 17:47:52 +0000 | [diff] [blame] | 32 | import android.compat.annotation.UnsupportedAppUsage; |
| Jeff Sharkey | f9e176c | 2021-04-22 16:01:29 -0600 | [diff] [blame] | 33 | import android.content.AttributionSource; |
| The Android Open Source Project | 3389776 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 34 | import android.content.Context; |
| Mathew Inwood | 049f0f5 | 2020-11-04 09:29:36 +0000 | [diff] [blame] | 35 | import android.os.Build; |
| The Android Open Source Project | 3389776 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 36 | import android.os.IBinder; |
| Jaikumar Ganesh | d8fc4dd | 2010-10-18 16:41:53 -0700 | [diff] [blame] | 37 | import android.os.RemoteException; |
| The Android Open Source Project | 3389776 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 38 | import android.util.Log; |
| 39 | |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 40 | import com.android.modules.utils.SynchronousResultReceiver; |
| 41 | |
| Rahul Sabnis | 5ed1b84 | 2021-12-23 11:36:40 -0800 | [diff] [blame] | 42 | import java.lang.annotation.Retention; |
| 43 | import java.lang.annotation.RetentionPolicy; |
| Jaikumar Ganesh | d8fc4dd | 2010-10-18 16:41:53 -0700 | [diff] [blame] | 44 | import java.util.ArrayList; |
| 45 | import java.util.List; |
| Rahul Sabnis | 9a5e351 | 2022-03-17 23:37:38 -0700 | [diff] [blame] | 46 | import java.util.Objects; |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 47 | import java.util.concurrent.TimeoutException; |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 48 | |
| The Android Open Source Project | 3389776 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 49 | /** |
| The Android Open Source Project | 3389776 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 50 | * Public API for controlling the Bluetooth Headset Service. This includes both |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 51 | * Bluetooth Headset and Handsfree (v1.5) profiles. |
| The Android Open Source Project | 3389776 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 52 | * |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 53 | * <p>BluetoothHeadset is a proxy object for controlling the Bluetooth Headset |
| The Android Open Source Project | 3389776 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 54 | * Service via IPC. |
| 55 | * |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 56 | * <p> Use {@link BluetoothAdapter#getProfileProxy} to get |
| 57 | * the BluetoothHeadset proxy object. Use |
| 58 | * {@link BluetoothAdapter#closeProfileProxy} to close the service connection. |
| The Android Open Source Project | 3389776 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 59 | * |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 60 | * <p> Android only supports one connected Bluetooth Headset at a time. |
| 61 | * Each method is protected with its appropriate permission. |
| The Android Open Source Project | 3389776 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 62 | */ |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 63 | public final class BluetoothHeadset implements BluetoothProfile { |
| The Android Open Source Project | 3389776 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 64 | private static final String TAG = "BluetoothHeadset"; |
| William Escande | 60874f8 | 2022-10-27 22:51:52 -0700 | [diff] [blame] | 65 | private static final boolean DBG = Log.isLoggable(TAG, Log.DEBUG); |
| Matthew Xie | f8035a7 | 2012-10-09 22:10:37 -0700 | [diff] [blame] | 66 | private static final boolean VDBG = false; |
| The Android Open Source Project | 3389776 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 67 | |
| Nick Pelly | dac4c0d | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 68 | /** |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 69 | * Intent used to broadcast the change in connection state of the Headset |
| 70 | * profile. |
| 71 | * |
| 72 | * <p>This intent will have 3 extras: |
| Jaikumar Ganesh | b342757 | 2011-01-25 16:03:13 -0800 | [diff] [blame] | 73 | * <ul> |
| Jack He | 910201b | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 74 | * <li> {@link #EXTRA_STATE} - The current state of the profile. </li> |
| 75 | * <li> {@link #EXTRA_PREVIOUS_STATE}- The previous state of the profile. </li> |
| 76 | * <li> {@link BluetoothDevice#EXTRA_DEVICE} - The remote device. </li> |
| Jaikumar Ganesh | b342757 | 2011-01-25 16:03:13 -0800 | [diff] [blame] | 77 | * </ul> |
| Jaikumar Ganesh | aa0427e | 2011-01-26 11:46:56 -0800 | [diff] [blame] | 78 | * <p>{@link #EXTRA_STATE} or {@link #EXTRA_PREVIOUS_STATE} can be any of |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 79 | * {@link #STATE_DISCONNECTED}, {@link #STATE_CONNECTING}, |
| 80 | * {@link #STATE_CONNECTED}, {@link #STATE_DISCONNECTING}. |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 81 | */ |
| Jeff Sharkey | 8f80e4a | 2021-04-02 08:06:09 -0600 | [diff] [blame] | 82 | @RequiresLegacyBluetoothPermission |
| 83 | @RequiresBluetoothConnectPermission |
| 84 | @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 85 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
| 86 | public static final String ACTION_CONNECTION_STATE_CHANGED = |
| Jack He | 910201b | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 87 | "android.bluetooth.headset.profile.action.CONNECTION_STATE_CHANGED"; |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 88 | |
| 89 | /** |
| 90 | * Intent used to broadcast the change in the Audio Connection state of the |
| Jakub Pawlowski | 9965bf7 | 2021-01-29 09:20:44 +0100 | [diff] [blame] | 91 | * HFP profile. |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 92 | * |
| 93 | * <p>This intent will have 3 extras: |
| Jaikumar Ganesh | b342757 | 2011-01-25 16:03:13 -0800 | [diff] [blame] | 94 | * <ul> |
| Jack He | 910201b | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 95 | * <li> {@link #EXTRA_STATE} - The current state of the profile. </li> |
| 96 | * <li> {@link #EXTRA_PREVIOUS_STATE}- The previous state of the profile. </li> |
| 97 | * <li> {@link BluetoothDevice#EXTRA_DEVICE} - The remote device. </li> |
| Jaikumar Ganesh | b342757 | 2011-01-25 16:03:13 -0800 | [diff] [blame] | 98 | * </ul> |
| Jaikumar Ganesh | aa0427e | 2011-01-26 11:46:56 -0800 | [diff] [blame] | 99 | * <p>{@link #EXTRA_STATE} or {@link #EXTRA_PREVIOUS_STATE} can be any of |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 100 | * {@link #STATE_AUDIO_CONNECTED}, {@link #STATE_AUDIO_DISCONNECTED}, |
| Nick Pelly | dac4c0d | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 101 | */ |
| Jeff Sharkey | 8f80e4a | 2021-04-02 08:06:09 -0600 | [diff] [blame] | 102 | @RequiresLegacyBluetoothPermission |
| 103 | @RequiresBluetoothConnectPermission |
| 104 | @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) |
| Nick Pelly | dac4c0d | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 105 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
| 106 | public static final String ACTION_AUDIO_STATE_CHANGED = |
| Jack He | 910201b | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 107 | "android.bluetooth.headset.profile.action.AUDIO_STATE_CHANGED"; |
| Nick Pelly | dac4c0d | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 108 | |
| Jack He | 889d234 | 2018-01-03 12:13:26 -0800 | [diff] [blame] | 109 | /** |
| 110 | * Intent used to broadcast the selection of a connected device as active. |
| 111 | * |
| 112 | * <p>This intent will have one extra: |
| 113 | * <ul> |
| 114 | * <li> {@link BluetoothDevice#EXTRA_DEVICE} - The remote device. It can |
| 115 | * be null if no device is active. </li> |
| 116 | * </ul> |
| 117 | * |
| Jack He | 889d234 | 2018-01-03 12:13:26 -0800 | [diff] [blame] | 118 | * @hide |
| 119 | */ |
| William Escande | 5d864a4 | 2022-01-27 13:42:05 +0100 | [diff] [blame] | 120 | @SystemApi |
| Jeff Sharkey | 8f80e4a | 2021-04-02 08:06:09 -0600 | [diff] [blame] | 121 | @RequiresLegacyBluetoothPermission |
| 122 | @RequiresBluetoothConnectPermission |
| 123 | @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) |
| Jack He | 889d234 | 2018-01-03 12:13:26 -0800 | [diff] [blame] | 124 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
| William Escande | 5d864a4 | 2022-01-27 13:42:05 +0100 | [diff] [blame] | 125 | @SuppressLint("ActionValue") |
| Jack He | 889d234 | 2018-01-03 12:13:26 -0800 | [diff] [blame] | 126 | public static final String ACTION_ACTIVE_DEVICE_CHANGED = |
| 127 | "android.bluetooth.headset.profile.action.ACTIVE_DEVICE_CHANGED"; |
| Jaikumar Ganesh | f48cda5 | 2010-04-02 14:44:43 -0700 | [diff] [blame] | 128 | |
| Nick Pelly | dac4c0d | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 129 | /** |
| Jaikumar Ganesh | ee628ed | 2010-09-29 11:34:59 -0700 | [diff] [blame] | 130 | * Intent used to broadcast that the headset has posted a |
| 131 | * vendor-specific event. |
| 132 | * |
| 133 | * <p>This intent will have 4 extras and 1 category. |
| Jaikumar Ganesh | b342757 | 2011-01-25 16:03:13 -0800 | [diff] [blame] | 134 | * <ul> |
| Jack He | 910201b | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 135 | * <li> {@link BluetoothDevice#EXTRA_DEVICE} - The remote Bluetooth Device |
| 136 | * </li> |
| 137 | * <li> {@link #EXTRA_VENDOR_SPECIFIC_HEADSET_EVENT_CMD} - The vendor |
| 138 | * specific command </li> |
| 139 | * <li> {@link #EXTRA_VENDOR_SPECIFIC_HEADSET_EVENT_CMD_TYPE} - The AT |
| 140 | * command type which can be one of {@link #AT_CMD_TYPE_READ}, |
| 141 | * {@link #AT_CMD_TYPE_TEST}, or {@link #AT_CMD_TYPE_SET}, |
| 142 | * {@link #AT_CMD_TYPE_BASIC},{@link #AT_CMD_TYPE_ACTION}. </li> |
| 143 | * <li> {@link #EXTRA_VENDOR_SPECIFIC_HEADSET_EVENT_ARGS} - Command |
| 144 | * arguments. </li> |
| Jaikumar Ganesh | b342757 | 2011-01-25 16:03:13 -0800 | [diff] [blame] | 145 | * </ul> |
| Jaikumar Ganesh | ee628ed | 2010-09-29 11:34:59 -0700 | [diff] [blame] | 146 | * |
| Jack He | 910201b | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 147 | * <p> The category is the Company ID of the vendor defining the |
| Jaikumar Ganesh | ee628ed | 2010-09-29 11:34:59 -0700 | [diff] [blame] | 148 | * vendor-specific command. {@link BluetoothAssignedNumbers} |
| Jaikumar Ganesh | ee628ed | 2010-09-29 11:34:59 -0700 | [diff] [blame] | 149 | * |
| 150 | * For example, for Plantronics specific events |
| 151 | * Category will be {@link #VENDOR_SPECIFIC_HEADSET_EVENT_COMPANY_ID_CATEGORY}.55 |
| 152 | * |
| 153 | * <p> For example, an AT+XEVENT=foo,3 will get translated into |
| Jaikumar Ganesh | b342757 | 2011-01-25 16:03:13 -0800 | [diff] [blame] | 154 | * <ul> |
| Jack He | 910201b | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 155 | * <li> EXTRA_VENDOR_SPECIFIC_HEADSET_EVENT_CMD = +XEVENT </li> |
| 156 | * <li> EXTRA_VENDOR_SPECIFIC_HEADSET_EVENT_CMD_TYPE = AT_CMD_TYPE_SET </li> |
| 157 | * <li> EXTRA_VENDOR_SPECIFIC_HEADSET_EVENT_ARGS = foo, 3 </li> |
| Jaikumar Ganesh | b342757 | 2011-01-25 16:03:13 -0800 | [diff] [blame] | 158 | * </ul> |
| Herb Jellinek | aad41c5 | 2010-08-10 13:17:43 -0700 | [diff] [blame] | 159 | */ |
| Jeff Sharkey | 8f80e4a | 2021-04-02 08:06:09 -0600 | [diff] [blame] | 160 | @RequiresLegacyBluetoothPermission |
| 161 | @RequiresBluetoothConnectPermission |
| 162 | @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) |
| Herb Jellinek | aad41c5 | 2010-08-10 13:17:43 -0700 | [diff] [blame] | 163 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
| 164 | public static final String ACTION_VENDOR_SPECIFIC_HEADSET_EVENT = |
| 165 | "android.bluetooth.headset.action.VENDOR_SPECIFIC_HEADSET_EVENT"; |
| 166 | |
| 167 | /** |
| 168 | * A String extra field in {@link #ACTION_VENDOR_SPECIFIC_HEADSET_EVENT} |
| 169 | * intents that contains the name of the vendor-specific command. |
| 170 | */ |
| 171 | public static final String EXTRA_VENDOR_SPECIFIC_HEADSET_EVENT_CMD = |
| 172 | "android.bluetooth.headset.extra.VENDOR_SPECIFIC_HEADSET_EVENT_CMD"; |
| 173 | |
| 174 | /** |
| 175 | * An int extra field in {@link #ACTION_VENDOR_SPECIFIC_HEADSET_EVENT} |
| Jaikumar Ganesh | ee628ed | 2010-09-29 11:34:59 -0700 | [diff] [blame] | 176 | * intents that contains the AT command type of the vendor-specific command. |
| Herb Jellinek | aad41c5 | 2010-08-10 13:17:43 -0700 | [diff] [blame] | 177 | */ |
| Jaikumar Ganesh | ee628ed | 2010-09-29 11:34:59 -0700 | [diff] [blame] | 178 | public static final String EXTRA_VENDOR_SPECIFIC_HEADSET_EVENT_CMD_TYPE = |
| 179 | "android.bluetooth.headset.extra.VENDOR_SPECIFIC_HEADSET_EVENT_CMD_TYPE"; |
| 180 | |
| 181 | /** |
| 182 | * AT command type READ used with |
| 183 | * {@link #EXTRA_VENDOR_SPECIFIC_HEADSET_EVENT_CMD_TYPE} |
| 184 | * For example, AT+VGM?. There are no arguments for this command type. |
| 185 | */ |
| 186 | public static final int AT_CMD_TYPE_READ = 0; |
| 187 | |
| 188 | /** |
| 189 | * AT command type TEST used with |
| 190 | * {@link #EXTRA_VENDOR_SPECIFIC_HEADSET_EVENT_CMD_TYPE} |
| 191 | * For example, AT+VGM=?. There are no arguments for this command type. |
| 192 | */ |
| 193 | public static final int AT_CMD_TYPE_TEST = 1; |
| 194 | |
| 195 | /** |
| 196 | * AT command type SET used with |
| 197 | * {@link #EXTRA_VENDOR_SPECIFIC_HEADSET_EVENT_CMD_TYPE} |
| 198 | * For example, AT+VGM=<args>. |
| 199 | */ |
| 200 | public static final int AT_CMD_TYPE_SET = 2; |
| 201 | |
| 202 | /** |
| 203 | * AT command type BASIC used with |
| 204 | * {@link #EXTRA_VENDOR_SPECIFIC_HEADSET_EVENT_CMD_TYPE} |
| 205 | * For example, ATD. Single character commands and everything following the |
| 206 | * character are arguments. |
| 207 | */ |
| 208 | public static final int AT_CMD_TYPE_BASIC = 3; |
| 209 | |
| 210 | /** |
| 211 | * AT command type ACTION used with |
| 212 | * {@link #EXTRA_VENDOR_SPECIFIC_HEADSET_EVENT_CMD_TYPE} |
| 213 | * For example, AT+CHUP. There are no arguments for action commands. |
| 214 | */ |
| 215 | public static final int AT_CMD_TYPE_ACTION = 4; |
| Herb Jellinek | aad41c5 | 2010-08-10 13:17:43 -0700 | [diff] [blame] | 216 | |
| 217 | /** |
| 218 | * A Parcelable String array extra field in |
| 219 | * {@link #ACTION_VENDOR_SPECIFIC_HEADSET_EVENT} intents that contains |
| 220 | * the arguments to the vendor-specific command. |
| 221 | */ |
| 222 | public static final String EXTRA_VENDOR_SPECIFIC_HEADSET_EVENT_ARGS = |
| 223 | "android.bluetooth.headset.extra.VENDOR_SPECIFIC_HEADSET_EVENT_ARGS"; |
| 224 | |
| Jaikumar Ganesh | ee628ed | 2010-09-29 11:34:59 -0700 | [diff] [blame] | 225 | /** |
| 226 | * The intent category to be used with {@link #ACTION_VENDOR_SPECIFIC_HEADSET_EVENT} |
| 227 | * for the companyId |
| 228 | */ |
| Jack He | 910201b | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 229 | public static final String VENDOR_SPECIFIC_HEADSET_EVENT_COMPANY_ID_CATEGORY = |
| Jaikumar Ganesh | ee628ed | 2010-09-29 11:34:59 -0700 | [diff] [blame] | 230 | "android.bluetooth.headset.intent.category.companyid"; |
| 231 | |
| Jaikumar Ganesh | 23501e2 | 2010-11-01 11:59:57 -0700 | [diff] [blame] | 232 | /** |
| Edward Jee | 7c81f1f | 2013-08-16 04:07:49 -0700 | [diff] [blame] | 233 | * A vendor-specific command for unsolicited result code. |
| 234 | */ |
| 235 | public static final String VENDOR_RESULT_CODE_COMMAND_ANDROID = "+ANDROID"; |
| 236 | |
| 237 | /** |
| Jack He | 7f9c70b | 2017-06-20 17:07:40 -0700 | [diff] [blame] | 238 | * A vendor-specific AT command |
| Jack He | 910201b | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 239 | * |
| Jack He | 7f9c70b | 2017-06-20 17:07:40 -0700 | [diff] [blame] | 240 | * @hide |
| 241 | */ |
| Jack He | 0dfd69b | 2017-06-20 17:09:47 -0700 | [diff] [blame] | 242 | public static final String VENDOR_SPECIFIC_HEADSET_EVENT_XAPL = "+XAPL"; |
| 243 | |
| 244 | /** |
| 245 | * A vendor-specific AT command |
| Jack He | 910201b | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 246 | * |
| Jack He | 0dfd69b | 2017-06-20 17:09:47 -0700 | [diff] [blame] | 247 | * @hide |
| 248 | */ |
| 249 | public static final String VENDOR_SPECIFIC_HEADSET_EVENT_IPHONEACCEV = "+IPHONEACCEV"; |
| 250 | |
| 251 | /** |
| 252 | * Battery level indicator associated with |
| 253 | * {@link #VENDOR_SPECIFIC_HEADSET_EVENT_IPHONEACCEV} |
| Jack He | 910201b | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 254 | * |
| Jack He | 0dfd69b | 2017-06-20 17:09:47 -0700 | [diff] [blame] | 255 | * @hide |
| 256 | */ |
| 257 | public static final int VENDOR_SPECIFIC_HEADSET_EVENT_IPHONEACCEV_BATTERY_LEVEL = 1; |
| 258 | |
| 259 | /** |
| 260 | * A vendor-specific AT command |
| Jack He | 910201b | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 261 | * |
| Jack He | 0dfd69b | 2017-06-20 17:09:47 -0700 | [diff] [blame] | 262 | * @hide |
| 263 | */ |
| Jack He | 7f9c70b | 2017-06-20 17:07:40 -0700 | [diff] [blame] | 264 | public static final String VENDOR_SPECIFIC_HEADSET_EVENT_XEVENT = "+XEVENT"; |
| 265 | |
| 266 | /** |
| 267 | * Battery level indicator associated with {@link #VENDOR_SPECIFIC_HEADSET_EVENT_XEVENT} |
| Jack He | 910201b | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 268 | * |
| Jack He | 7f9c70b | 2017-06-20 17:07:40 -0700 | [diff] [blame] | 269 | * @hide |
| 270 | */ |
| 271 | public static final String VENDOR_SPECIFIC_HEADSET_EVENT_XEVENT_BATTERY_LEVEL = "BATTERY"; |
| 272 | |
| 273 | /** |
| Jaikumar Ganesh | b342757 | 2011-01-25 16:03:13 -0800 | [diff] [blame] | 274 | * Headset state when SCO audio is not connected. |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 275 | * This state can be one of |
| 276 | * {@link #EXTRA_STATE} or {@link #EXTRA_PREVIOUS_STATE} of |
| 277 | * {@link #ACTION_AUDIO_STATE_CHANGED} intent. |
| 278 | */ |
| Jaikumar Ganesh | 8ea890d | 2010-11-11 10:49:46 -0800 | [diff] [blame] | 279 | public static final int STATE_AUDIO_DISCONNECTED = 10; |
| Herb Jellinek | aad41c5 | 2010-08-10 13:17:43 -0700 | [diff] [blame] | 280 | |
| 281 | /** |
| Jaikumar Ganesh | b342757 | 2011-01-25 16:03:13 -0800 | [diff] [blame] | 282 | * Headset state when SCO audio is connecting. |
| Jaikumar Ganesh | 23501e2 | 2010-11-01 11:59:57 -0700 | [diff] [blame] | 283 | * This state can be one of |
| 284 | * {@link #EXTRA_STATE} or {@link #EXTRA_PREVIOUS_STATE} of |
| 285 | * {@link #ACTION_AUDIO_STATE_CHANGED} intent. |
| Jaikumar Ganesh | 23501e2 | 2010-11-01 11:59:57 -0700 | [diff] [blame] | 286 | */ |
| Jaikumar Ganesh | 8ea890d | 2010-11-11 10:49:46 -0800 | [diff] [blame] | 287 | public static final int STATE_AUDIO_CONNECTING = 11; |
| Jaikumar Ganesh | 23501e2 | 2010-11-01 11:59:57 -0700 | [diff] [blame] | 288 | |
| 289 | /** |
| Jaikumar Ganesh | b342757 | 2011-01-25 16:03:13 -0800 | [diff] [blame] | 290 | * Headset state when SCO audio is connected. |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 291 | * This state can be one of |
| 292 | * {@link #EXTRA_STATE} or {@link #EXTRA_PREVIOUS_STATE} of |
| 293 | * {@link #ACTION_AUDIO_STATE_CHANGED} intent. |
| Nick Pelly | dac4c0d | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 294 | */ |
| Chienyuan | 0d3bada | 2019-05-29 10:29:30 +0800 | [diff] [blame] | 295 | public static final int STATE_AUDIO_CONNECTED = 12; |
| Mudumba Ananth | 3246de6 | 2016-02-29 02:14:36 -0800 | [diff] [blame] | 296 | |
| 297 | /** |
| 298 | * Intent used to broadcast the headset's indicator status |
| 299 | * |
| 300 | * <p>This intent will have 3 extras: |
| 301 | * <ul> |
| Jack He | 910201b | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 302 | * <li> {@link #EXTRA_HF_INDICATORS_IND_ID} - The Assigned number of headset Indicator which |
| 303 | * is supported by the headset ( as indicated by AT+BIND command in the SLC |
| 304 | * sequence) or whose value is changed (indicated by AT+BIEV command) </li> |
| 305 | * <li> {@link #EXTRA_HF_INDICATORS_IND_VALUE} - Updated value of headset indicator. </li> |
| 306 | * <li> {@link BluetoothDevice#EXTRA_DEVICE} - Remote device. </li> |
| Mudumba Ananth | 3246de6 | 2016-02-29 02:14:36 -0800 | [diff] [blame] | 307 | * </ul> |
| Jack He | 48f6a8a | 2017-06-22 12:56:54 -0700 | [diff] [blame] | 308 | * <p>{@link #EXTRA_HF_INDICATORS_IND_ID} is defined by Bluetooth SIG and each of the indicators |
| Jack He | 910201b | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 309 | * are given an assigned number. Below shows the assigned number of Indicator added so far |
| Jack He | 48f6a8a | 2017-06-22 12:56:54 -0700 | [diff] [blame] | 310 | * - Enhanced Safety - 1, Valid Values: 0 - Disabled, 1 - Enabled |
| 311 | * - Battery Level - 2, Valid Values: 0~100 - Remaining level of Battery |
| Jack He | 910201b | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 312 | * |
| Mudumba Ananth | 3246de6 | 2016-02-29 02:14:36 -0800 | [diff] [blame] | 313 | * @hide |
| 314 | */ |
| Jeff Sharkey | 8f80e4a | 2021-04-02 08:06:09 -0600 | [diff] [blame] | 315 | @RequiresLegacyBluetoothPermission |
| 316 | @RequiresBluetoothConnectPermission |
| 317 | @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) |
| Jeff Sharkey | d7c5566 | 2021-04-20 12:30:37 -0600 | [diff] [blame] | 318 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
| Mudumba Ananth | 3246de6 | 2016-02-29 02:14:36 -0800 | [diff] [blame] | 319 | public static final String ACTION_HF_INDICATORS_VALUE_CHANGED = |
| 320 | "android.bluetooth.headset.action.HF_INDICATORS_VALUE_CHANGED"; |
| 321 | |
| 322 | /** |
| Jack He | 48f6a8a | 2017-06-22 12:56:54 -0700 | [diff] [blame] | 323 | * A int extra field in {@link #ACTION_HF_INDICATORS_VALUE_CHANGED} |
| 324 | * intents that contains the assigned number of the headset indicator as defined by |
| 325 | * Bluetooth SIG that is being sent. Value range is 0-65535 as defined in HFP 1.7 |
| Jack He | 910201b | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 326 | * |
| Mudumba Ananth | 3246de6 | 2016-02-29 02:14:36 -0800 | [diff] [blame] | 327 | * @hide |
| 328 | */ |
| 329 | public static final String EXTRA_HF_INDICATORS_IND_ID = |
| 330 | "android.bluetooth.headset.extra.HF_INDICATORS_IND_ID"; |
| 331 | |
| 332 | /** |
| Jack He | 48f6a8a | 2017-06-22 12:56:54 -0700 | [diff] [blame] | 333 | * A int extra field in {@link #ACTION_HF_INDICATORS_VALUE_CHANGED} |
| Mudumba Ananth | 3246de6 | 2016-02-29 02:14:36 -0800 | [diff] [blame] | 334 | * intents that contains the value of the Headset indicator that is being sent. |
| Jack He | 910201b | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 335 | * |
| Mudumba Ananth | 3246de6 | 2016-02-29 02:14:36 -0800 | [diff] [blame] | 336 | * @hide |
| 337 | */ |
| 338 | public static final String EXTRA_HF_INDICATORS_IND_VALUE = |
| 339 | "android.bluetooth.headset.extra.HF_INDICATORS_IND_VALUE"; |
| 340 | |
| Jeff Sharkey | f9e176c | 2021-04-22 16:01:29 -0600 | [diff] [blame] | 341 | private final BluetoothAdapter mAdapter; |
| 342 | private final AttributionSource mAttributionSource; |
| Etienne Ruffieux | c3bbf1a | 2022-11-07 14:40:27 -0800 | [diff] [blame] | 343 | private final BluetoothProfileConnector<IBluetoothHeadset> mProfileConnector = |
| 344 | new BluetoothProfileConnector(this, BluetoothProfile.HEADSET, "BluetoothHeadset", |
| 345 | IBluetoothHeadset.class.getName()) { |
| 346 | @Override |
| 347 | public IBluetoothHeadset getServiceInterface(IBinder service) { |
| 348 | return IBluetoothHeadset.Stub.asInterface(service); |
| fredc | 3c71964 | 2012-04-12 00:02:00 -0700 | [diff] [blame] | 349 | } |
| Etienne Ruffieux | c3bbf1a | 2022-11-07 14:40:27 -0800 | [diff] [blame] | 350 | }; |
| fredc | 3c71964 | 2012-04-12 00:02:00 -0700 | [diff] [blame] | 351 | |
| The Android Open Source Project | 3389776 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 352 | /** |
| 353 | * Create a BluetoothHeadset proxy object. |
| 354 | */ |
| Etienne Ruffieux | c3bbf1a | 2022-11-07 14:40:27 -0800 | [diff] [blame] | 355 | /* package */ BluetoothHeadset(Context context, ServiceListener listener, |
| 356 | BluetoothAdapter adapter) { |
| Jeff Sharkey | f9e176c | 2021-04-22 16:01:29 -0600 | [diff] [blame] | 357 | mAdapter = adapter; |
| 358 | mAttributionSource = adapter.getAttributionSource(); |
| Etienne Ruffieux | c3bbf1a | 2022-11-07 14:40:27 -0800 | [diff] [blame] | 359 | mProfileConnector.connect(context, listener); |
| The Android Open Source Project | 3389776 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 360 | } |
| 361 | |
| The Android Open Source Project | 3389776 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 362 | /** |
| Santiago Seifert | efe4071 | 2023-01-06 13:54:17 +0000 | [diff] [blame] | 363 | * Close the connection to the backing service. Other public functions of BluetoothHeadset will |
| 364 | * return default error results once close() has been called. Multiple invocations of close() |
| The Android Open Source Project | 3389776 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 365 | * are ok. |
| Santiago Seifert | efe4071 | 2023-01-06 13:54:17 +0000 | [diff] [blame] | 366 | * |
| 367 | * @hide |
| The Android Open Source Project | 3389776 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 368 | */ |
| Mathew Inwood | 7d54389 | 2018-08-01 15:07:20 +0100 | [diff] [blame] | 369 | @UnsupportedAppUsage |
| Santiago Seifert | efe4071 | 2023-01-06 13:54:17 +0000 | [diff] [blame] | 370 | public void close() { |
| Etienne Ruffieux | c3bbf1a | 2022-11-07 14:40:27 -0800 | [diff] [blame] | 371 | mProfileConnector.disconnect(); |
| 372 | } |
| fredc | 3c71964 | 2012-04-12 00:02:00 -0700 | [diff] [blame] | 373 | |
| Etienne Ruffieux | c3bbf1a | 2022-11-07 14:40:27 -0800 | [diff] [blame] | 374 | private IBluetoothHeadset getService() { |
| 375 | return mProfileConnector.getService(); |
| Jeff Sharkey | db38eb7 | 2021-05-24 10:00:23 -0600 | [diff] [blame] | 376 | } |
| 377 | |
| 378 | /** {@hide} */ |
| 379 | @Override |
| 380 | protected void finalize() throws Throwable { |
| Etienne Ruffieux | c3bbf1a | 2022-11-07 14:40:27 -0800 | [diff] [blame] | 381 | // The empty finalize needs to be kept or the |
| 382 | // cts signature tests would fail. |
| The Android Open Source Project | 3389776 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 383 | } |
| 384 | |
| 385 | /** |
| Jaikumar Ganesh | a7266d3 | 2011-05-26 13:56:40 -0700 | [diff] [blame] | 386 | * Initiate connection to a profile of the remote bluetooth device. |
| 387 | * |
| 388 | * <p> Currently, the system supports only 1 connection to the |
| 389 | * headset/handsfree profile. The API will automatically disconnect connected |
| 390 | * devices before connecting. |
| 391 | * |
| 392 | * <p> This API returns false in scenarios like the profile on the |
| 393 | * device is already connected or Bluetooth is not turned on. |
| 394 | * When this API returns true, it is guaranteed that |
| 395 | * connection state intent for the profile will be broadcasted with |
| 396 | * the state. Users can get the connection state of the profile |
| 397 | * from this intent. |
| 398 | * |
| Jaikumar Ganesh | a7266d3 | 2011-05-26 13:56:40 -0700 | [diff] [blame] | 399 | * @param device Remote Bluetooth Device |
| Jack He | 910201b | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 400 | * @return false on immediate error, true otherwise |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 401 | * @hide |
| The Android Open Source Project | 3389776 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 402 | */ |
| Selim Gurun | a117cb37 | 2017-10-17 17:01:38 -0700 | [diff] [blame] | 403 | @SystemApi |
| Jeff Sharkey | 8f80e4a | 2021-04-02 08:06:09 -0600 | [diff] [blame] | 404 | @RequiresLegacyBluetoothAdminPermission |
| 405 | @RequiresBluetoothConnectPermission |
| 406 | @RequiresPermission(allOf = { |
| 407 | android.Manifest.permission.BLUETOOTH_CONNECT, |
| 408 | android.Manifest.permission.MODIFY_PHONE_STATE, |
| 409 | }) |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 410 | public boolean connect(BluetoothDevice device) { |
| 411 | if (DBG) log("connect(" + device + ")"); |
| Etienne Ruffieux | c3bbf1a | 2022-11-07 14:40:27 -0800 | [diff] [blame] | 412 | final IBluetoothHeadset service = getService(); |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 413 | final boolean defaultValue = false; |
| 414 | if (service == null) { |
| 415 | Log.w(TAG, "Proxy not attached to service"); |
| 416 | if (DBG) log(Log.getStackTraceString(new Throwable())); |
| 417 | } else if (isEnabled() && isValidDevice(device)) { |
| The Android Open Source Project | 3389776 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 418 | try { |
| Etienne Ruffieux | 02dcbe7 | 2022-06-22 13:54:25 -0700 | [diff] [blame] | 419 | final SynchronousResultReceiver<Boolean> recv = SynchronousResultReceiver.get(); |
| William Escande | 4644ccd | 2022-08-24 18:07:07 -0700 | [diff] [blame] | 420 | service.connect(device, mAttributionSource, recv); |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 421 | return recv.awaitResultNoInterrupt(getSyncTimeout()).getValue(defaultValue); |
| 422 | } catch (RemoteException | TimeoutException e) { |
| 423 | Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable())); |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 424 | } |
| The Android Open Source Project | 3389776 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 425 | } |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 426 | return defaultValue; |
| The Android Open Source Project | 3389776 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 427 | } |
| 428 | |
| 429 | /** |
| Jaikumar Ganesh | a7266d3 | 2011-05-26 13:56:40 -0700 | [diff] [blame] | 430 | * Initiate disconnection from a profile |
| 431 | * |
| 432 | * <p> This API will return false in scenarios like the profile on the |
| 433 | * Bluetooth device is not in connected state etc. When this API returns, |
| 434 | * true, it is guaranteed that the connection state change |
| 435 | * intent will be broadcasted with the state. Users can get the |
| 436 | * disconnection state of the profile from this intent. |
| 437 | * |
| 438 | * <p> If the disconnection is initiated by a remote device, the state |
| 439 | * will transition from {@link #STATE_CONNECTED} to |
| 440 | * {@link #STATE_DISCONNECTED}. If the disconnect is initiated by the |
| 441 | * host (local) device the state will transition from |
| 442 | * {@link #STATE_CONNECTED} to state {@link #STATE_DISCONNECTING} to |
| 443 | * state {@link #STATE_DISCONNECTED}. The transition to |
| 444 | * {@link #STATE_DISCONNECTING} can be used to distinguish between the |
| 445 | * two scenarios. |
| 446 | * |
| Jaikumar Ganesh | a7266d3 | 2011-05-26 13:56:40 -0700 | [diff] [blame] | 447 | * @param device Remote Bluetooth Device |
| Jack He | 910201b | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 448 | * @return false on immediate error, true otherwise |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 449 | * @hide |
| The Android Open Source Project | 3389776 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 450 | */ |
| Selim Gurun | a117cb37 | 2017-10-17 17:01:38 -0700 | [diff] [blame] | 451 | @SystemApi |
| Jeff Sharkey | 8f80e4a | 2021-04-02 08:06:09 -0600 | [diff] [blame] | 452 | @RequiresLegacyBluetoothAdminPermission |
| 453 | @RequiresBluetoothConnectPermission |
| 454 | @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 455 | public boolean disconnect(BluetoothDevice device) { |
| 456 | if (DBG) log("disconnect(" + device + ")"); |
| Etienne Ruffieux | c3bbf1a | 2022-11-07 14:40:27 -0800 | [diff] [blame] | 457 | final IBluetoothHeadset service = getService(); |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 458 | final boolean defaultValue = false; |
| 459 | if (service == null) { |
| 460 | Log.w(TAG, "Proxy not attached to service"); |
| 461 | if (DBG) log(Log.getStackTraceString(new Throwable())); |
| 462 | } else if (isEnabled() && isValidDevice(device)) { |
| The Android Open Source Project | 3389776 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 463 | try { |
| Etienne Ruffieux | 02dcbe7 | 2022-06-22 13:54:25 -0700 | [diff] [blame] | 464 | final SynchronousResultReceiver<Boolean> recv = SynchronousResultReceiver.get(); |
| William Escande | 4644ccd | 2022-08-24 18:07:07 -0700 | [diff] [blame] | 465 | service.disconnect(device, mAttributionSource, recv); |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 466 | return recv.awaitResultNoInterrupt(getSyncTimeout()).getValue(defaultValue); |
| 467 | } catch (RemoteException | TimeoutException e) { |
| 468 | Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable())); |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 469 | } |
| The Android Open Source Project | 3389776 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 470 | } |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 471 | return defaultValue; |
| The Android Open Source Project | 3389776 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 472 | } |
| 473 | |
| 474 | /** |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 475 | * {@inheritDoc} |
| The Android Open Source Project | 3389776 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 476 | */ |
| Jack He | 9e045d2 | 2017-08-22 21:21:23 -0700 | [diff] [blame] | 477 | @Override |
| Jeff Sharkey | 5ba8bfc | 2021-04-16 09:53:23 -0600 | [diff] [blame] | 478 | @RequiresBluetoothConnectPermission |
| Jeff Sharkey | 8f80e4a | 2021-04-02 08:06:09 -0600 | [diff] [blame] | 479 | @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) |
| Jaikumar Ganesh | d8fc4dd | 2010-10-18 16:41:53 -0700 | [diff] [blame] | 480 | public List<BluetoothDevice> getConnectedDevices() { |
| Matthew Xie | f8035a7 | 2012-10-09 22:10:37 -0700 | [diff] [blame] | 481 | if (VDBG) log("getConnectedDevices()"); |
| Etienne Ruffieux | c3bbf1a | 2022-11-07 14:40:27 -0800 | [diff] [blame] | 482 | final IBluetoothHeadset service = getService(); |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 483 | final List<BluetoothDevice> defaultValue = new ArrayList<BluetoothDevice>(); |
| 484 | if (service == null) { |
| 485 | Log.w(TAG, "Proxy not attached to service"); |
| 486 | if (DBG) log(Log.getStackTraceString(new Throwable())); |
| 487 | } else if (isEnabled()) { |
| The Android Open Source Project | 3389776 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 488 | try { |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 489 | final SynchronousResultReceiver<List<BluetoothDevice>> recv = |
| Etienne Ruffieux | 02dcbe7 | 2022-06-22 13:54:25 -0700 | [diff] [blame] | 490 | SynchronousResultReceiver.get(); |
| William Escande | 4644ccd | 2022-08-24 18:07:07 -0700 | [diff] [blame] | 491 | service.getConnectedDevices(mAttributionSource, recv); |
| Jeff Sharkey | 98f3044 | 2021-06-03 09:26:53 -0600 | [diff] [blame] | 492 | return Attributable.setAttributionSource( |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 493 | recv.awaitResultNoInterrupt(getSyncTimeout()).getValue(defaultValue), |
| Jeff Sharkey | 98f3044 | 2021-06-03 09:26:53 -0600 | [diff] [blame] | 494 | mAttributionSource); |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 495 | } catch (RemoteException | TimeoutException e) { |
| 496 | Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable())); |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 497 | } |
| The Android Open Source Project | 3389776 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 498 | } |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 499 | return defaultValue; |
| The Android Open Source Project | 3389776 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 500 | } |
| 501 | |
| 502 | /** |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 503 | * {@inheritDoc} |
| The Android Open Source Project | 3389776 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 504 | */ |
| Jack He | 9e045d2 | 2017-08-22 21:21:23 -0700 | [diff] [blame] | 505 | @Override |
| Jeff Sharkey | 5ba8bfc | 2021-04-16 09:53:23 -0600 | [diff] [blame] | 506 | @RequiresBluetoothConnectPermission |
| Jeff Sharkey | 8f80e4a | 2021-04-02 08:06:09 -0600 | [diff] [blame] | 507 | @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) |
| Jaikumar Ganesh | d8fc4dd | 2010-10-18 16:41:53 -0700 | [diff] [blame] | 508 | public List<BluetoothDevice> getDevicesMatchingConnectionStates(int[] states) { |
| Matthew Xie | f8035a7 | 2012-10-09 22:10:37 -0700 | [diff] [blame] | 509 | if (VDBG) log("getDevicesMatchingStates()"); |
| Etienne Ruffieux | c3bbf1a | 2022-11-07 14:40:27 -0800 | [diff] [blame] | 510 | final IBluetoothHeadset service = getService(); |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 511 | final List<BluetoothDevice> defaultValue = new ArrayList<BluetoothDevice>(); |
| 512 | if (service == null) { |
| 513 | Log.w(TAG, "Proxy not attached to service"); |
| 514 | if (DBG) log(Log.getStackTraceString(new Throwable())); |
| 515 | } else if (isEnabled()) { |
| The Android Open Source Project | 3389776 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 516 | try { |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 517 | final SynchronousResultReceiver<List<BluetoothDevice>> recv = |
| Etienne Ruffieux | 02dcbe7 | 2022-06-22 13:54:25 -0700 | [diff] [blame] | 518 | SynchronousResultReceiver.get(); |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 519 | service.getDevicesMatchingConnectionStates(states, mAttributionSource, recv); |
| Jeff Sharkey | 98f3044 | 2021-06-03 09:26:53 -0600 | [diff] [blame] | 520 | return Attributable.setAttributionSource( |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 521 | recv.awaitResultNoInterrupt(getSyncTimeout()).getValue(defaultValue), |
| Jeff Sharkey | 43ee69e | 2021-04-23 14:13:57 -0600 | [diff] [blame] | 522 | mAttributionSource); |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 523 | } catch (RemoteException | TimeoutException e) { |
| 524 | Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable())); |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 525 | } |
| The Android Open Source Project | 3389776 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 526 | } |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 527 | return defaultValue; |
| The Android Open Source Project | 3389776 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 528 | } |
| 529 | |
| 530 | /** |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 531 | * {@inheritDoc} |
| The Android Open Source Project | 3389776 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 532 | */ |
| Jack He | 9e045d2 | 2017-08-22 21:21:23 -0700 | [diff] [blame] | 533 | @Override |
| Jeff Sharkey | 5ba8bfc | 2021-04-16 09:53:23 -0600 | [diff] [blame] | 534 | @RequiresBluetoothConnectPermission |
| Jeff Sharkey | 8f80e4a | 2021-04-02 08:06:09 -0600 | [diff] [blame] | 535 | @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 536 | public int getConnectionState(BluetoothDevice device) { |
| Matthew Xie | f8035a7 | 2012-10-09 22:10:37 -0700 | [diff] [blame] | 537 | if (VDBG) log("getConnectionState(" + device + ")"); |
| Etienne Ruffieux | c3bbf1a | 2022-11-07 14:40:27 -0800 | [diff] [blame] | 538 | final IBluetoothHeadset service = getService(); |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 539 | final int defaultValue = BluetoothProfile.STATE_DISCONNECTED; |
| 540 | if (service == null) { |
| 541 | Log.w(TAG, "Proxy not attached to service"); |
| 542 | if (DBG) log(Log.getStackTraceString(new Throwable())); |
| 543 | } else if (isEnabled() && isValidDevice(device)) { |
| The Android Open Source Project | 3389776 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 544 | try { |
| Etienne Ruffieux | 02dcbe7 | 2022-06-22 13:54:25 -0700 | [diff] [blame] | 545 | final SynchronousResultReceiver<Integer> recv = SynchronousResultReceiver.get(); |
| William Escande | 4644ccd | 2022-08-24 18:07:07 -0700 | [diff] [blame] | 546 | service.getConnectionState(device, mAttributionSource, recv); |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 547 | return recv.awaitResultNoInterrupt(getSyncTimeout()).getValue(defaultValue); |
| 548 | } catch (RemoteException | TimeoutException e) { |
| 549 | Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable())); |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 550 | } |
| The Android Open Source Project | 3389776 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 551 | } |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 552 | return defaultValue; |
| The Android Open Source Project | 3389776 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 553 | } |
| 554 | |
| 555 | /** |
| Rahul Sabnis | e8bac9b | 2019-11-27 18:09:33 -0800 | [diff] [blame] | 556 | * Set connection policy of the profile |
| 557 | * |
| 558 | * <p> The device should already be paired. |
| 559 | * Connection policy can be one of {@link #CONNECTION_POLICY_ALLOWED}, |
| 560 | * {@link #CONNECTION_POLICY_FORBIDDEN}, {@link #CONNECTION_POLICY_UNKNOWN} |
| 561 | * |
| 562 | * @param device Paired bluetooth device |
| 563 | * @param connectionPolicy is the connection policy to set to for this profile |
| 564 | * @return true if connectionPolicy is set, false on error |
| 565 | * @hide |
| 566 | */ |
| 567 | @SystemApi |
| Jeff Sharkey | 5ba8bfc | 2021-04-16 09:53:23 -0600 | [diff] [blame] | 568 | @RequiresBluetoothConnectPermission |
| Jeff Sharkey | 8f80e4a | 2021-04-02 08:06:09 -0600 | [diff] [blame] | 569 | @RequiresPermission(allOf = { |
| 570 | android.Manifest.permission.BLUETOOTH_CONNECT, |
| 571 | android.Manifest.permission.BLUETOOTH_PRIVILEGED, |
| 572 | android.Manifest.permission.MODIFY_PHONE_STATE, |
| 573 | }) |
| Rahul Sabnis | e8bac9b | 2019-11-27 18:09:33 -0800 | [diff] [blame] | 574 | public boolean setConnectionPolicy(@NonNull BluetoothDevice device, |
| 575 | @ConnectionPolicy int connectionPolicy) { |
| 576 | if (DBG) log("setConnectionPolicy(" + device + ", " + connectionPolicy + ")"); |
| Etienne Ruffieux | c3bbf1a | 2022-11-07 14:40:27 -0800 | [diff] [blame] | 577 | final IBluetoothHeadset service = getService(); |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 578 | final boolean defaultValue = false; |
| 579 | if (service == null) { |
| 580 | Log.w(TAG, "Proxy not attached to service"); |
| 581 | if (DBG) log(Log.getStackTraceString(new Throwable())); |
| 582 | } else if (isEnabled() && isValidDevice(device) |
| 583 | && (connectionPolicy == BluetoothProfile.CONNECTION_POLICY_FORBIDDEN |
| 584 | || connectionPolicy == BluetoothProfile.CONNECTION_POLICY_ALLOWED)) { |
| The Android Open Source Project | 3389776 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 585 | try { |
| Etienne Ruffieux | 02dcbe7 | 2022-06-22 13:54:25 -0700 | [diff] [blame] | 586 | final SynchronousResultReceiver<Boolean> recv = SynchronousResultReceiver.get(); |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 587 | service.setConnectionPolicy(device, connectionPolicy, mAttributionSource, recv); |
| 588 | return recv.awaitResultNoInterrupt(getSyncTimeout()).getValue(defaultValue); |
| 589 | } catch (RemoteException | TimeoutException e) { |
| 590 | Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable())); |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 591 | } |
| The Android Open Source Project | 3389776 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 592 | } |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 593 | return defaultValue; |
| The Android Open Source Project | 3389776 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 594 | } |
| 595 | |
| 596 | /** |
| Felix Stern | 692d36d | 2023-09-08 09:55:56 +0000 | [diff] [blame^] | 597 | * Get the priority of the profile. |
| 598 | * |
| 599 | * <p> The priority can be any of: |
| 600 | * {@link #PRIORITY_AUTO_CONNECT}, {@link #PRIORITY_OFF}, |
| 601 | * {@link #PRIORITY_ON}, {@link #PRIORITY_UNDEFINED} |
| 602 | * |
| 603 | * @param device Bluetooth device |
| 604 | * @return priority of the device |
| 605 | * @hide |
| 606 | */ |
| 607 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) |
| 608 | @RequiresLegacyBluetoothPermission |
| 609 | @RequiresBluetoothConnectPermission |
| 610 | @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) |
| 611 | public int getPriority(BluetoothDevice device) { |
| 612 | if (VDBG) log("getPriority(" + device + ")"); |
| 613 | return BluetoothAdapter.connectionPolicyToPriority(getConnectionPolicy(device)); |
| 614 | } |
| 615 | |
| 616 | /** |
| Rahul Sabnis | e8bac9b | 2019-11-27 18:09:33 -0800 | [diff] [blame] | 617 | * Get the connection policy of the profile. |
| 618 | * |
| 619 | * <p> The connection policy can be any of: |
| 620 | * {@link #CONNECTION_POLICY_ALLOWED}, {@link #CONNECTION_POLICY_FORBIDDEN}, |
| 621 | * {@link #CONNECTION_POLICY_UNKNOWN} |
| 622 | * |
| 623 | * @param device Bluetooth device |
| 624 | * @return connection policy of the device |
| 625 | * @hide |
| 626 | */ |
| 627 | @SystemApi |
| Jeff Sharkey | 43ee69e | 2021-04-23 14:13:57 -0600 | [diff] [blame] | 628 | @RequiresBluetoothConnectPermission |
| 629 | @RequiresPermission(allOf = { |
| 630 | android.Manifest.permission.BLUETOOTH_CONNECT, |
| 631 | android.Manifest.permission.BLUETOOTH_PRIVILEGED, |
| 632 | }) |
| Rahul Sabnis | e8bac9b | 2019-11-27 18:09:33 -0800 | [diff] [blame] | 633 | public @ConnectionPolicy int getConnectionPolicy(@NonNull BluetoothDevice device) { |
| 634 | if (VDBG) log("getConnectionPolicy(" + device + ")"); |
| Etienne Ruffieux | c3bbf1a | 2022-11-07 14:40:27 -0800 | [diff] [blame] | 635 | final IBluetoothHeadset service = getService(); |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 636 | final int defaultValue = BluetoothProfile.CONNECTION_POLICY_FORBIDDEN; |
| 637 | if (service == null) { |
| 638 | Log.w(TAG, "Proxy not attached to service"); |
| 639 | if (DBG) log(Log.getStackTraceString(new Throwable())); |
| 640 | } else if (isEnabled() && isValidDevice(device)) { |
| The Android Open Source Project | 3389776 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 641 | try { |
| Etienne Ruffieux | 02dcbe7 | 2022-06-22 13:54:25 -0700 | [diff] [blame] | 642 | final SynchronousResultReceiver<Integer> recv = SynchronousResultReceiver.get(); |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 643 | service.getConnectionPolicy(device, mAttributionSource, recv); |
| 644 | return recv.awaitResultNoInterrupt(getSyncTimeout()).getValue(defaultValue); |
| 645 | } catch (RemoteException | TimeoutException e) { |
| 646 | Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable())); |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 647 | } |
| The Android Open Source Project | 3389776 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 648 | } |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 649 | return defaultValue; |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 650 | } |
| 651 | |
| 652 | /** |
| Rahul Sabnis | c611e73 | 2020-12-14 10:54:45 -0800 | [diff] [blame] | 653 | * Checks whether the headset supports some form of noise reduction |
| 654 | * |
| 655 | * @param device Bluetooth device |
| 656 | * @return true if echo cancellation and/or noise reduction is supported, false otherwise |
| 657 | */ |
| Jeff Sharkey | 8f80e4a | 2021-04-02 08:06:09 -0600 | [diff] [blame] | 658 | @RequiresLegacyBluetoothPermission |
| 659 | @RequiresBluetoothConnectPermission |
| 660 | @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) |
| Rahul Sabnis | c611e73 | 2020-12-14 10:54:45 -0800 | [diff] [blame] | 661 | public boolean isNoiseReductionSupported(@NonNull BluetoothDevice device) { |
| 662 | if (DBG) log("isNoiseReductionSupported()"); |
| Etienne Ruffieux | c3bbf1a | 2022-11-07 14:40:27 -0800 | [diff] [blame] | 663 | final IBluetoothHeadset service = getService(); |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 664 | final boolean defaultValue = false; |
| 665 | if (service == null) { |
| 666 | Log.w(TAG, "Proxy not attached to service"); |
| 667 | if (DBG) log(Log.getStackTraceString(new Throwable())); |
| 668 | } else if (isEnabled() && isValidDevice(device)) { |
| Rahul Sabnis | c611e73 | 2020-12-14 10:54:45 -0800 | [diff] [blame] | 669 | try { |
| Etienne Ruffieux | 02dcbe7 | 2022-06-22 13:54:25 -0700 | [diff] [blame] | 670 | final SynchronousResultReceiver<Boolean> recv = SynchronousResultReceiver.get(); |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 671 | service.isNoiseReductionSupported(device, mAttributionSource, recv); |
| 672 | return recv.awaitResultNoInterrupt(getSyncTimeout()).getValue(defaultValue); |
| 673 | } catch (RemoteException | TimeoutException e) { |
| 674 | Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable())); |
| Rahul Sabnis | c611e73 | 2020-12-14 10:54:45 -0800 | [diff] [blame] | 675 | } |
| 676 | } |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 677 | return defaultValue; |
| Rahul Sabnis | c611e73 | 2020-12-14 10:54:45 -0800 | [diff] [blame] | 678 | } |
| 679 | |
| 680 | /** |
| 681 | * Checks whether the headset supports voice recognition |
| 682 | * |
| 683 | * @param device Bluetooth device |
| 684 | * @return true if voice recognition is supported, false otherwise |
| 685 | */ |
| Jeff Sharkey | 8f80e4a | 2021-04-02 08:06:09 -0600 | [diff] [blame] | 686 | @RequiresLegacyBluetoothPermission |
| 687 | @RequiresBluetoothConnectPermission |
| 688 | @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) |
| Rahul Sabnis | c611e73 | 2020-12-14 10:54:45 -0800 | [diff] [blame] | 689 | public boolean isVoiceRecognitionSupported(@NonNull BluetoothDevice device) { |
| 690 | if (DBG) log("isVoiceRecognitionSupported()"); |
| Etienne Ruffieux | c3bbf1a | 2022-11-07 14:40:27 -0800 | [diff] [blame] | 691 | final IBluetoothHeadset service = getService(); |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 692 | final boolean defaultValue = false; |
| 693 | if (service == null) { |
| 694 | Log.w(TAG, "Proxy not attached to service"); |
| 695 | if (DBG) log(Log.getStackTraceString(new Throwable())); |
| 696 | } else if (isEnabled() && isValidDevice(device)) { |
| Rahul Sabnis | c611e73 | 2020-12-14 10:54:45 -0800 | [diff] [blame] | 697 | try { |
| Etienne Ruffieux | 02dcbe7 | 2022-06-22 13:54:25 -0700 | [diff] [blame] | 698 | final SynchronousResultReceiver<Boolean> recv = SynchronousResultReceiver.get(); |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 699 | service.isVoiceRecognitionSupported(device, mAttributionSource, recv); |
| 700 | return recv.awaitResultNoInterrupt(getSyncTimeout()).getValue(defaultValue); |
| 701 | } catch (RemoteException | TimeoutException e) { |
| 702 | Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable())); |
| Rahul Sabnis | c611e73 | 2020-12-14 10:54:45 -0800 | [diff] [blame] | 703 | } |
| 704 | } |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 705 | return defaultValue; |
| Rahul Sabnis | c611e73 | 2020-12-14 10:54:45 -0800 | [diff] [blame] | 706 | } |
| 707 | |
| 708 | /** |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 709 | * Start Bluetooth voice recognition. This methods sends the voice |
| 710 | * recognition AT command to the headset and establishes the |
| 711 | * audio connection. |
| 712 | * |
| 713 | * <p> Users can listen to {@link #ACTION_AUDIO_STATE_CHANGED}. |
| Jaikumar Ganesh | 8ea890d | 2010-11-11 10:49:46 -0800 | [diff] [blame] | 714 | * If this function returns true, this intent will be broadcasted with |
| 715 | * {@link #EXTRA_STATE} set to {@link #STATE_AUDIO_CONNECTING}. |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 716 | * |
| Jaikumar Ganesh | 8ea890d | 2010-11-11 10:49:46 -0800 | [diff] [blame] | 717 | * <p> {@link #EXTRA_STATE} will transition from |
| 718 | * {@link #STATE_AUDIO_CONNECTING} to {@link #STATE_AUDIO_CONNECTED} when |
| 719 | * audio connection is established and to {@link #STATE_AUDIO_DISCONNECTED} |
| 720 | * in case of failure to establish the audio connection. |
| 721 | * |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 722 | * @param device Bluetooth headset |
| Jack He | c46a01e | 2018-05-02 19:10:56 -0700 | [diff] [blame] | 723 | * @return false if there is no headset connected, or the connected headset doesn't support |
| 724 | * voice recognition, or voice recognition is already started, or audio channel is occupied, |
| 725 | * or on error, true otherwise |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 726 | */ |
| Jeff Sharkey | 8f80e4a | 2021-04-02 08:06:09 -0600 | [diff] [blame] | 727 | @RequiresLegacyBluetoothPermission |
| 728 | @RequiresBluetoothConnectPermission |
| 729 | @RequiresPermission(allOf = { |
| 730 | android.Manifest.permission.BLUETOOTH_CONNECT, |
| 731 | android.Manifest.permission.MODIFY_PHONE_STATE, |
| 732 | }) |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 733 | public boolean startVoiceRecognition(BluetoothDevice device) { |
| 734 | if (DBG) log("startVoiceRecognition()"); |
| Etienne Ruffieux | c3bbf1a | 2022-11-07 14:40:27 -0800 | [diff] [blame] | 735 | final IBluetoothHeadset service = getService(); |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 736 | final boolean defaultValue = false; |
| 737 | if (service == null) { |
| 738 | Log.w(TAG, "Proxy not attached to service"); |
| 739 | if (DBG) log(Log.getStackTraceString(new Throwable())); |
| 740 | } else if (isEnabled() && isValidDevice(device)) { |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 741 | try { |
| Etienne Ruffieux | 02dcbe7 | 2022-06-22 13:54:25 -0700 | [diff] [blame] | 742 | final SynchronousResultReceiver<Boolean> recv = SynchronousResultReceiver.get(); |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 743 | service.startVoiceRecognition(device, mAttributionSource, recv); |
| 744 | return recv.awaitResultNoInterrupt(getSyncTimeout()).getValue(defaultValue); |
| 745 | } catch (RemoteException | TimeoutException e) { |
| 746 | Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable())); |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 747 | } |
| 748 | } |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 749 | return defaultValue; |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 750 | } |
| 751 | |
| 752 | /** |
| 753 | * Stop Bluetooth Voice Recognition mode, and shut down the |
| 754 | * Bluetooth audio path. |
| 755 | * |
| Jack He | c46a01e | 2018-05-02 19:10:56 -0700 | [diff] [blame] | 756 | * <p> Users can listen to {@link #ACTION_AUDIO_STATE_CHANGED}. |
| 757 | * If this function returns true, this intent will be broadcasted with |
| 758 | * {@link #EXTRA_STATE} set to {@link #STATE_AUDIO_DISCONNECTED}. |
| 759 | * |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 760 | * @param device Bluetooth headset |
| Jack He | c46a01e | 2018-05-02 19:10:56 -0700 | [diff] [blame] | 761 | * @return false if there is no headset connected, or voice recognition has not started, |
| 762 | * or voice recognition has ended on this headset, or on error, true otherwise |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 763 | */ |
| Jeff Sharkey | 8f80e4a | 2021-04-02 08:06:09 -0600 | [diff] [blame] | 764 | @RequiresLegacyBluetoothPermission |
| 765 | @RequiresBluetoothConnectPermission |
| 766 | @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 767 | public boolean stopVoiceRecognition(BluetoothDevice device) { |
| 768 | if (DBG) log("stopVoiceRecognition()"); |
| Etienne Ruffieux | c3bbf1a | 2022-11-07 14:40:27 -0800 | [diff] [blame] | 769 | final IBluetoothHeadset service = getService(); |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 770 | final boolean defaultValue = false; |
| 771 | if (service == null) { |
| 772 | Log.w(TAG, "Proxy not attached to service"); |
| 773 | if (DBG) log(Log.getStackTraceString(new Throwable())); |
| 774 | } else if (isEnabled() && isValidDevice(device)) { |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 775 | try { |
| Etienne Ruffieux | 02dcbe7 | 2022-06-22 13:54:25 -0700 | [diff] [blame] | 776 | final SynchronousResultReceiver<Boolean> recv = SynchronousResultReceiver.get(); |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 777 | service.stopVoiceRecognition(device, mAttributionSource, recv); |
| 778 | return recv.awaitResultNoInterrupt(getSyncTimeout()).getValue(defaultValue); |
| 779 | } catch (RemoteException | TimeoutException e) { |
| 780 | Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable())); |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 781 | } |
| 782 | } |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 783 | return defaultValue; |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 784 | } |
| 785 | |
| 786 | /** |
| 787 | * Check if Bluetooth SCO audio is connected. |
| 788 | * |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 789 | * @param device Bluetooth headset |
| Jack He | 910201b | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 790 | * @return true if SCO is connected, false otherwise or on error |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 791 | */ |
| Jeff Sharkey | 8f80e4a | 2021-04-02 08:06:09 -0600 | [diff] [blame] | 792 | @RequiresLegacyBluetoothPermission |
| 793 | @RequiresBluetoothConnectPermission |
| 794 | @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 795 | public boolean isAudioConnected(BluetoothDevice device) { |
| Matthew Xie | f8035a7 | 2012-10-09 22:10:37 -0700 | [diff] [blame] | 796 | if (VDBG) log("isAudioConnected()"); |
| Etienne Ruffieux | c3bbf1a | 2022-11-07 14:40:27 -0800 | [diff] [blame] | 797 | final IBluetoothHeadset service = getService(); |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 798 | final boolean defaultValue = false; |
| 799 | if (service == null) { |
| 800 | Log.w(TAG, "Proxy not attached to service"); |
| 801 | if (DBG) log(Log.getStackTraceString(new Throwable())); |
| 802 | } else if (isEnabled() && isValidDevice(device)) { |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 803 | try { |
| Etienne Ruffieux | 02dcbe7 | 2022-06-22 13:54:25 -0700 | [diff] [blame] | 804 | final SynchronousResultReceiver<Boolean> recv = SynchronousResultReceiver.get(); |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 805 | service.isAudioConnected(device, mAttributionSource, recv); |
| 806 | return recv.awaitResultNoInterrupt(getSyncTimeout()).getValue(defaultValue); |
| 807 | } catch (RemoteException | TimeoutException e) { |
| 808 | Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable())); |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 809 | } |
| 810 | } |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 811 | return defaultValue; |
| The Android Open Source Project | 3389776 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 812 | } |
| 813 | |
| Eric Laurent | 2e66fa2 | 2010-03-17 14:59:27 -0700 | [diff] [blame] | 814 | |
| Rahul Sabnis | 5ed1b84 | 2021-12-23 11:36:40 -0800 | [diff] [blame] | 815 | /** @hide */ |
| 816 | @Retention(RetentionPolicy.SOURCE) |
| 817 | @IntDef(value = { |
| 818 | BluetoothHeadset.STATE_AUDIO_DISCONNECTED, |
| 819 | BluetoothHeadset.STATE_AUDIO_CONNECTING, |
| 820 | BluetoothHeadset.STATE_AUDIO_CONNECTED, |
| 821 | BluetoothStatusCodes.ERROR_TIMEOUT |
| 822 | }) |
| 823 | public @interface GetAudioStateReturnValues {} |
| 824 | |
| Jaikumar Ganesh | b84bbd9 | 2010-06-02 14:36:14 -0700 | [diff] [blame] | 825 | /** |
| Jaikumar Ganesh | 23501e2 | 2010-11-01 11:59:57 -0700 | [diff] [blame] | 826 | * Get the current audio state of the Headset. |
| Rahul Sabnis | 5ed1b84 | 2021-12-23 11:36:40 -0800 | [diff] [blame] | 827 | * |
| 828 | * @param device is the Bluetooth device for which the audio state is being queried |
| 829 | * @return the audio state of the device or an error code |
| Rahul Sabnis | 9a5e351 | 2022-03-17 23:37:38 -0700 | [diff] [blame] | 830 | * @throws NullPointerException if the device is null |
| Jaikumar Ganesh | 23501e2 | 2010-11-01 11:59:57 -0700 | [diff] [blame] | 831 | * |
| 832 | * @hide |
| 833 | */ |
| Rahul Sabnis | 5ed1b84 | 2021-12-23 11:36:40 -0800 | [diff] [blame] | 834 | @SystemApi |
| Jeff Sharkey | 5ba8bfc | 2021-04-16 09:53:23 -0600 | [diff] [blame] | 835 | @RequiresBluetoothConnectPermission |
| Rahul Sabnis | 5ed1b84 | 2021-12-23 11:36:40 -0800 | [diff] [blame] | 836 | @RequiresPermission(allOf = { |
| 837 | android.Manifest.permission.BLUETOOTH_CONNECT, |
| 838 | android.Manifest.permission.BLUETOOTH_PRIVILEGED, |
| 839 | }) |
| 840 | public @GetAudioStateReturnValues int getAudioState(@NonNull BluetoothDevice device) { |
| Matthew Xie | f8035a7 | 2012-10-09 22:10:37 -0700 | [diff] [blame] | 841 | if (VDBG) log("getAudioState"); |
| Rahul Sabnis | 9a5e351 | 2022-03-17 23:37:38 -0700 | [diff] [blame] | 842 | Objects.requireNonNull(device); |
| Etienne Ruffieux | c3bbf1a | 2022-11-07 14:40:27 -0800 | [diff] [blame] | 843 | final IBluetoothHeadset service = getService(); |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 844 | final int defaultValue = BluetoothHeadset.STATE_AUDIO_DISCONNECTED; |
| 845 | if (service == null) { |
| Jaikumar Ganesh | 23501e2 | 2010-11-01 11:59:57 -0700 | [diff] [blame] | 846 | Log.w(TAG, "Proxy not attached to service"); |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 847 | if (DBG) log(Log.getStackTraceString(new Throwable())); |
| 848 | } else if (!isDisabled()) { |
| 849 | try { |
| Etienne Ruffieux | 02dcbe7 | 2022-06-22 13:54:25 -0700 | [diff] [blame] | 850 | final SynchronousResultReceiver<Integer> recv = SynchronousResultReceiver.get(); |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 851 | service.getAudioState(device, mAttributionSource, recv); |
| 852 | return recv.awaitResultNoInterrupt(getSyncTimeout()).getValue(defaultValue); |
| Rahul Sabnis | 5ed1b84 | 2021-12-23 11:36:40 -0800 | [diff] [blame] | 853 | } catch (RemoteException e) { |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 854 | Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable())); |
| Rahul Sabnis | 5ed1b84 | 2021-12-23 11:36:40 -0800 | [diff] [blame] | 855 | throw e.rethrowFromSystemServer(); |
| 856 | } catch (TimeoutException e) { |
| 857 | Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable())); |
| 858 | return BluetoothStatusCodes.ERROR_TIMEOUT; |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 859 | } |
| Jaikumar Ganesh | 23501e2 | 2010-11-01 11:59:57 -0700 | [diff] [blame] | 860 | } |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 861 | return defaultValue; |
| Jaikumar Ganesh | 23501e2 | 2010-11-01 11:59:57 -0700 | [diff] [blame] | 862 | } |
| 863 | |
| Md Shahriar Hossain Sajib | 7901c00 | 2022-01-19 15:37:26 +0800 | [diff] [blame] | 864 | /** @hide */ |
| 865 | @Retention(RetentionPolicy.SOURCE) |
| 866 | @IntDef(value = { |
| 867 | BluetoothStatusCodes.SUCCESS, |
| Md Shahriar Hossain Sajib | 7901c00 | 2022-01-19 15:37:26 +0800 | [diff] [blame] | 868 | BluetoothStatusCodes.ERROR_PROFILE_SERVICE_NOT_BOUND, |
| 869 | BluetoothStatusCodes.ERROR_TIMEOUT, |
| Md Shahriar Hossain Sajib | 8b4df2f | 2022-02-18 13:56:27 +0800 | [diff] [blame] | 870 | BluetoothStatusCodes.ERROR_UNKNOWN, |
| 871 | }) |
| 872 | public @interface SetAudioRouteAllowedReturnValues {} |
| 873 | |
| 874 | /** @hide */ |
| 875 | @Retention(RetentionPolicy.SOURCE) |
| 876 | @IntDef(value = { |
| Md Shahriar Hossain Sajib | 7901c00 | 2022-01-19 15:37:26 +0800 | [diff] [blame] | 877 | BluetoothStatusCodes.ALLOWED, |
| 878 | BluetoothStatusCodes.NOT_ALLOWED, |
| Md Shahriar Hossain Sajib | 8b4df2f | 2022-02-18 13:56:27 +0800 | [diff] [blame] | 879 | BluetoothStatusCodes.ERROR_PROFILE_SERVICE_NOT_BOUND, |
| 880 | BluetoothStatusCodes.ERROR_TIMEOUT, |
| 881 | BluetoothStatusCodes.ERROR_UNKNOWN, |
| Md Shahriar Hossain Sajib | 7901c00 | 2022-01-19 15:37:26 +0800 | [diff] [blame] | 882 | }) |
| Md Shahriar Hossain Sajib | 8b4df2f | 2022-02-18 13:56:27 +0800 | [diff] [blame] | 883 | public @interface GetAudioRouteAllowedReturnValues {} |
| Md Shahriar Hossain Sajib | 7901c00 | 2022-01-19 15:37:26 +0800 | [diff] [blame] | 884 | |
| Jaikumar Ganesh | 7af32b4 | 2010-10-26 17:10:09 -0700 | [diff] [blame] | 885 | /** |
| Md Shahriar Hossain Sajib | 7901c00 | 2022-01-19 15:37:26 +0800 | [diff] [blame] | 886 | * Sets whether audio routing is allowed. When set to {@code false}, the AG |
| 887 | * will not route any audio to the HF unless explicitly told to. This method |
| 888 | * should be used in cases where the SCO channel is shared between multiple |
| 889 | * profiles and must be delegated by a source knowledgeable. |
| Bryce Lee | 0e154a3 | 2015-11-16 08:55:52 -0800 | [diff] [blame] | 890 | * |
| Md Shahriar Hossain Sajib | 7901c00 | 2022-01-19 15:37:26 +0800 | [diff] [blame] | 891 | * @param allowed {@code true} if the profile can reroute audio, |
| 892 | * {@code false} otherwise. |
| 893 | * @return {@link BluetoothStatusCodes#SUCCESS} upon successful setting, |
| 894 | * otherwise an error code. |
| 895 | * |
| Bryce Lee | 0e154a3 | 2015-11-16 08:55:52 -0800 | [diff] [blame] | 896 | * @hide |
| 897 | */ |
| Md Shahriar Hossain Sajib | 7901c00 | 2022-01-19 15:37:26 +0800 | [diff] [blame] | 898 | @SystemApi |
| Jeff Sharkey | 5ba8bfc | 2021-04-16 09:53:23 -0600 | [diff] [blame] | 899 | @RequiresBluetoothConnectPermission |
| Md Shahriar Hossain Sajib | 7901c00 | 2022-01-19 15:37:26 +0800 | [diff] [blame] | 900 | @RequiresPermission(allOf = { |
| 901 | android.Manifest.permission.BLUETOOTH_CONNECT, |
| 902 | android.Manifest.permission.BLUETOOTH_PRIVILEGED, |
| 903 | }) |
| Md Shahriar Hossain Sajib | 8b4df2f | 2022-02-18 13:56:27 +0800 | [diff] [blame] | 904 | public @SetAudioRouteAllowedReturnValues int setAudioRouteAllowed(boolean allowed) { |
| Bryce Lee | 0e154a3 | 2015-11-16 08:55:52 -0800 | [diff] [blame] | 905 | if (VDBG) log("setAudioRouteAllowed"); |
| Etienne Ruffieux | c3bbf1a | 2022-11-07 14:40:27 -0800 | [diff] [blame] | 906 | final IBluetoothHeadset service = getService(); |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 907 | if (service == null) { |
| Bryce Lee | 0e154a3 | 2015-11-16 08:55:52 -0800 | [diff] [blame] | 908 | Log.w(TAG, "Proxy not attached to service"); |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 909 | if (DBG) log(Log.getStackTraceString(new Throwable())); |
| Md Shahriar Hossain Sajib | 7901c00 | 2022-01-19 15:37:26 +0800 | [diff] [blame] | 910 | return BluetoothStatusCodes.ERROR_PROFILE_SERVICE_NOT_BOUND; |
| Rahul Sabnis | fc0cd8b | 2022-03-22 16:38:38 -0700 | [diff] [blame] | 911 | } else if (isEnabled()) { |
| 912 | try { |
| Etienne Ruffieux | 02dcbe7 | 2022-06-22 13:54:25 -0700 | [diff] [blame] | 913 | final SynchronousResultReceiver recv = SynchronousResultReceiver.get(); |
| Rahul Sabnis | fc0cd8b | 2022-03-22 16:38:38 -0700 | [diff] [blame] | 914 | service.setAudioRouteAllowed(allowed, mAttributionSource, recv); |
| 915 | recv.awaitResultNoInterrupt(getSyncTimeout()).getValue(null); |
| 916 | return BluetoothStatusCodes.SUCCESS; |
| 917 | } catch (TimeoutException e) { |
| 918 | Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable())); |
| 919 | return BluetoothStatusCodes.ERROR_TIMEOUT; |
| 920 | } catch (RemoteException e) { |
| 921 | Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable())); |
| 922 | e.rethrowFromSystemServer(); |
| 923 | } |
| Bryce Lee | 0e154a3 | 2015-11-16 08:55:52 -0800 | [diff] [blame] | 924 | } |
| Rahul Sabnis | fc0cd8b | 2022-03-22 16:38:38 -0700 | [diff] [blame] | 925 | |
| 926 | Log.e(TAG, "setAudioRouteAllowed: Bluetooth disabled, but profile service still bound"); |
| Md Shahriar Hossain Sajib | 7901c00 | 2022-01-19 15:37:26 +0800 | [diff] [blame] | 927 | return BluetoothStatusCodes.ERROR_UNKNOWN; |
| Bryce Lee | 0e154a3 | 2015-11-16 08:55:52 -0800 | [diff] [blame] | 928 | } |
| 929 | |
| 930 | /** |
| Md Shahriar Hossain Sajib | 7901c00 | 2022-01-19 15:37:26 +0800 | [diff] [blame] | 931 | * @return {@link BluetoothStatusCodes#ALLOWED} if audio routing is allowed, |
| 932 | * {@link BluetoothStatusCodes#NOT_ALLOWED} if audio routing is not allowed, or |
| 933 | * an error code if an error occurs. |
| 934 | * see {@link #setAudioRouteAllowed(boolean)}. |
| Bryce Lee | 0e154a3 | 2015-11-16 08:55:52 -0800 | [diff] [blame] | 935 | * |
| 936 | * @hide |
| 937 | */ |
| Md Shahriar Hossain Sajib | 7901c00 | 2022-01-19 15:37:26 +0800 | [diff] [blame] | 938 | @SystemApi |
| Jeff Sharkey | 5ba8bfc | 2021-04-16 09:53:23 -0600 | [diff] [blame] | 939 | @RequiresBluetoothConnectPermission |
| Md Shahriar Hossain Sajib | 7901c00 | 2022-01-19 15:37:26 +0800 | [diff] [blame] | 940 | @RequiresPermission(allOf = { |
| 941 | android.Manifest.permission.BLUETOOTH_CONNECT, |
| 942 | android.Manifest.permission.BLUETOOTH_PRIVILEGED, |
| 943 | }) |
| Md Shahriar Hossain Sajib | 8b4df2f | 2022-02-18 13:56:27 +0800 | [diff] [blame] | 944 | public @GetAudioRouteAllowedReturnValues int getAudioRouteAllowed() { |
| Bryce Lee | 0e154a3 | 2015-11-16 08:55:52 -0800 | [diff] [blame] | 945 | if (VDBG) log("getAudioRouteAllowed"); |
| Etienne Ruffieux | c3bbf1a | 2022-11-07 14:40:27 -0800 | [diff] [blame] | 946 | final IBluetoothHeadset service = getService(); |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 947 | if (service == null) { |
| Bryce Lee | 0e154a3 | 2015-11-16 08:55:52 -0800 | [diff] [blame] | 948 | Log.w(TAG, "Proxy not attached to service"); |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 949 | if (DBG) log(Log.getStackTraceString(new Throwable())); |
| Md Shahriar Hossain Sajib | 7901c00 | 2022-01-19 15:37:26 +0800 | [diff] [blame] | 950 | return BluetoothStatusCodes.ERROR_PROFILE_SERVICE_NOT_BOUND; |
| Rahul Sabnis | fc0cd8b | 2022-03-22 16:38:38 -0700 | [diff] [blame] | 951 | } else if (isEnabled()) { |
| 952 | try { |
| Etienne Ruffieux | 02dcbe7 | 2022-06-22 13:54:25 -0700 | [diff] [blame] | 953 | final SynchronousResultReceiver<Boolean> recv = SynchronousResultReceiver.get(); |
| Rahul Sabnis | fc0cd8b | 2022-03-22 16:38:38 -0700 | [diff] [blame] | 954 | service.getAudioRouteAllowed(mAttributionSource, recv); |
| 955 | return recv.awaitResultNoInterrupt(getSyncTimeout()).getValue(false) |
| 956 | ? BluetoothStatusCodes.ALLOWED : BluetoothStatusCodes.NOT_ALLOWED; |
| 957 | } catch (TimeoutException e) { |
| 958 | Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable())); |
| 959 | return BluetoothStatusCodes.ERROR_TIMEOUT; |
| 960 | } catch (RemoteException e) { |
| 961 | Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable())); |
| 962 | e.rethrowFromSystemServer(); |
| 963 | } |
| Bryce Lee | 0e154a3 | 2015-11-16 08:55:52 -0800 | [diff] [blame] | 964 | } |
| Rahul Sabnis | fc0cd8b | 2022-03-22 16:38:38 -0700 | [diff] [blame] | 965 | |
| 966 | Log.e(TAG, "getAudioRouteAllowed: Bluetooth disabled, but profile service still bound"); |
| Md Shahriar Hossain Sajib | 7901c00 | 2022-01-19 15:37:26 +0800 | [diff] [blame] | 967 | return BluetoothStatusCodes.ERROR_UNKNOWN; |
| Bryce Lee | 0e154a3 | 2015-11-16 08:55:52 -0800 | [diff] [blame] | 968 | } |
| 969 | |
| 970 | /** |
| Jack He | 798d728 | 2017-05-09 17:16:01 -0700 | [diff] [blame] | 971 | * Force SCO audio to be opened regardless any other restrictions |
| 972 | * |
| Jack He | 910201b | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 973 | * @param forced Whether or not SCO audio connection should be forced: True to force SCO audio |
| 974 | * False to use SCO audio in normal manner |
| Jack He | 798d728 | 2017-05-09 17:16:01 -0700 | [diff] [blame] | 975 | * @hide |
| 976 | */ |
| Jeff Sharkey | 5ba8bfc | 2021-04-16 09:53:23 -0600 | [diff] [blame] | 977 | @RequiresBluetoothConnectPermission |
| Jeff Sharkey | 8f80e4a | 2021-04-02 08:06:09 -0600 | [diff] [blame] | 978 | @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) |
| Jack He | 798d728 | 2017-05-09 17:16:01 -0700 | [diff] [blame] | 979 | public void setForceScoAudio(boolean forced) { |
| 980 | if (VDBG) log("setForceScoAudio " + String.valueOf(forced)); |
| Etienne Ruffieux | c3bbf1a | 2022-11-07 14:40:27 -0800 | [diff] [blame] | 981 | final IBluetoothHeadset service = getService(); |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 982 | if (service == null) { |
| Jack He | 798d728 | 2017-05-09 17:16:01 -0700 | [diff] [blame] | 983 | Log.w(TAG, "Proxy not attached to service"); |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 984 | if (DBG) log(Log.getStackTraceString(new Throwable())); |
| 985 | } else if (isEnabled()) { |
| 986 | try { |
| Etienne Ruffieux | 02dcbe7 | 2022-06-22 13:54:25 -0700 | [diff] [blame] | 987 | final SynchronousResultReceiver recv = SynchronousResultReceiver.get(); |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 988 | service.setForceScoAudio(forced, mAttributionSource, recv); |
| 989 | recv.awaitResultNoInterrupt(getSyncTimeout()).getValue(null); |
| 990 | } catch (RemoteException | TimeoutException e) { |
| 991 | Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable())); |
| 992 | } |
| Jack He | 798d728 | 2017-05-09 17:16:01 -0700 | [diff] [blame] | 993 | } |
| 994 | } |
| 995 | |
| Rahul Sabnis | 5ed1b84 | 2021-12-23 11:36:40 -0800 | [diff] [blame] | 996 | /** @hide */ |
| 997 | @Retention(RetentionPolicy.SOURCE) |
| 998 | @IntDef(value = { |
| 999 | BluetoothStatusCodes.SUCCESS, |
| 1000 | BluetoothStatusCodes.ERROR_UNKNOWN, |
| 1001 | BluetoothStatusCodes.ERROR_PROFILE_SERVICE_NOT_BOUND, |
| 1002 | BluetoothStatusCodes.ERROR_TIMEOUT, |
| 1003 | BluetoothStatusCodes.ERROR_AUDIO_DEVICE_ALREADY_CONNECTED, |
| 1004 | BluetoothStatusCodes.ERROR_NO_ACTIVE_DEVICES, |
| 1005 | BluetoothStatusCodes.ERROR_NOT_ACTIVE_DEVICE, |
| 1006 | BluetoothStatusCodes.ERROR_AUDIO_ROUTE_BLOCKED, |
| 1007 | BluetoothStatusCodes.ERROR_CALL_ACTIVE, |
| 1008 | BluetoothStatusCodes.ERROR_PROFILE_NOT_CONNECTED |
| 1009 | }) |
| 1010 | public @interface ConnectAudioReturnValues {} |
| Matthew Xie | f3ee351 | 2012-02-16 16:57:18 -0800 | [diff] [blame] | 1011 | |
| 1012 | /** |
| Rahul Sabnis | 5ed1b84 | 2021-12-23 11:36:40 -0800 | [diff] [blame] | 1013 | * Initiates a connection of SCO audio to the current active HFP device. The active HFP device |
| 1014 | * can be identified with {@link BluetoothAdapter#getActiveDevices(int)}. |
| Rahul Sabnis | b83a2fe | 2022-01-24 14:38:40 -0800 | [diff] [blame] | 1015 | * <p> |
| Rahul Sabnis | 5ed1b84 | 2021-12-23 11:36:40 -0800 | [diff] [blame] | 1016 | * If this function returns {@link BluetoothStatusCodes#SUCCESS}, the intent |
| Rahul Sabnis | b83a2fe | 2022-01-24 14:38:40 -0800 | [diff] [blame] | 1017 | * {@link #ACTION_AUDIO_STATE_CHANGED} will be broadcasted twice. First with |
| 1018 | * {@link #EXTRA_STATE} set to {@link #STATE_AUDIO_CONNECTING}. This will be followed by a |
| 1019 | * broadcast with {@link #EXTRA_STATE} set to either {@link #STATE_AUDIO_CONNECTED} if the audio |
| 1020 | * connection is established or {@link #STATE_AUDIO_DISCONNECTED} if there was a failure in |
| 1021 | * establishing the audio connection. |
| Matthew Xie | f3ee351 | 2012-02-16 16:57:18 -0800 | [diff] [blame] | 1022 | * |
| Rahul Sabnis | 5ed1b84 | 2021-12-23 11:36:40 -0800 | [diff] [blame] | 1023 | * @return whether the connection was successfully initiated or an error code on failure |
| Matthew Xie | f3ee351 | 2012-02-16 16:57:18 -0800 | [diff] [blame] | 1024 | * @hide |
| 1025 | */ |
| Rahul Sabnis | 5ed1b84 | 2021-12-23 11:36:40 -0800 | [diff] [blame] | 1026 | @SystemApi |
| Jeff Sharkey | 5ba8bfc | 2021-04-16 09:53:23 -0600 | [diff] [blame] | 1027 | @RequiresBluetoothConnectPermission |
| Rahul Sabnis | 5ed1b84 | 2021-12-23 11:36:40 -0800 | [diff] [blame] | 1028 | @RequiresPermission(allOf = { |
| 1029 | android.Manifest.permission.BLUETOOTH_CONNECT, |
| 1030 | android.Manifest.permission.BLUETOOTH_PRIVILEGED, |
| 1031 | }) |
| 1032 | public @ConnectAudioReturnValues int connectAudio() { |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 1033 | if (VDBG) log("connectAudio()"); |
| Etienne Ruffieux | c3bbf1a | 2022-11-07 14:40:27 -0800 | [diff] [blame] | 1034 | final IBluetoothHeadset service = getService(); |
| Rahul Sabnis | 5ed1b84 | 2021-12-23 11:36:40 -0800 | [diff] [blame] | 1035 | final int defaultValue = BluetoothStatusCodes.ERROR_UNKNOWN; |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 1036 | if (service == null) { |
| Matthew Xie | f3ee351 | 2012-02-16 16:57:18 -0800 | [diff] [blame] | 1037 | Log.w(TAG, "Proxy not attached to service"); |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 1038 | if (DBG) log(Log.getStackTraceString(new Throwable())); |
| Rahul Sabnis | b83a2fe | 2022-01-24 14:38:40 -0800 | [diff] [blame] | 1039 | return BluetoothStatusCodes.ERROR_PROFILE_SERVICE_NOT_BOUND; |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 1040 | } else if (isEnabled()) { |
| 1041 | try { |
| Etienne Ruffieux | 02dcbe7 | 2022-06-22 13:54:25 -0700 | [diff] [blame] | 1042 | final SynchronousResultReceiver<Integer> recv = SynchronousResultReceiver.get(); |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 1043 | service.connectAudio(mAttributionSource, recv); |
| 1044 | return recv.awaitResultNoInterrupt(getSyncTimeout()).getValue(defaultValue); |
| Rahul Sabnis | 5ed1b84 | 2021-12-23 11:36:40 -0800 | [diff] [blame] | 1045 | } catch (RemoteException e) { |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 1046 | Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable())); |
| Rahul Sabnis | 5ed1b84 | 2021-12-23 11:36:40 -0800 | [diff] [blame] | 1047 | throw e.rethrowFromSystemServer(); |
| 1048 | } catch (TimeoutException e) { |
| 1049 | Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable())); |
| 1050 | return BluetoothStatusCodes.ERROR_TIMEOUT; |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 1051 | } |
| Matthew Xie | f3ee351 | 2012-02-16 16:57:18 -0800 | [diff] [blame] | 1052 | } |
| Rahul Sabnis | fc0cd8b | 2022-03-22 16:38:38 -0700 | [diff] [blame] | 1053 | |
| 1054 | Log.e(TAG, "connectAudio: Bluetooth disabled, but profile service still bound"); |
| 1055 | return defaultValue; |
| Matthew Xie | f3ee351 | 2012-02-16 16:57:18 -0800 | [diff] [blame] | 1056 | } |
| 1057 | |
| Rahul Sabnis | 5ed1b84 | 2021-12-23 11:36:40 -0800 | [diff] [blame] | 1058 | /** @hide */ |
| 1059 | @Retention(RetentionPolicy.SOURCE) |
| 1060 | @IntDef(value = { |
| 1061 | BluetoothStatusCodes.SUCCESS, |
| 1062 | BluetoothStatusCodes.ERROR_UNKNOWN, |
| 1063 | BluetoothStatusCodes.ERROR_PROFILE_SERVICE_NOT_BOUND, |
| 1064 | BluetoothStatusCodes.ERROR_TIMEOUT, |
| 1065 | BluetoothStatusCodes.ERROR_PROFILE_NOT_CONNECTED, |
| 1066 | BluetoothStatusCodes.ERROR_AUDIO_DEVICE_ALREADY_DISCONNECTED |
| 1067 | }) |
| 1068 | public @interface DisconnectAudioReturnValues {} |
| 1069 | |
| Matthew Xie | f3ee351 | 2012-02-16 16:57:18 -0800 | [diff] [blame] | 1070 | /** |
| Rahul Sabnis | 5ed1b84 | 2021-12-23 11:36:40 -0800 | [diff] [blame] | 1071 | * Initiates a disconnection of HFP SCO audio from actively connected devices. It also tears |
| 1072 | * down voice recognition or virtual voice call, if any exists. |
| Matthew Xie | f3ee351 | 2012-02-16 16:57:18 -0800 | [diff] [blame] | 1073 | * |
| Rahul Sabnis | 5ed1b84 | 2021-12-23 11:36:40 -0800 | [diff] [blame] | 1074 | * <p> If this function returns {@link BluetoothStatusCodes#SUCCESS}, the intent |
| 1075 | * {@link #ACTION_AUDIO_STATE_CHANGED} will be broadcasted with {@link #EXTRA_STATE} set to |
| 1076 | * {@link #STATE_AUDIO_DISCONNECTED}. |
| Jack He | c46a01e | 2018-05-02 19:10:56 -0700 | [diff] [blame] | 1077 | * |
| Rahul Sabnis | 5ed1b84 | 2021-12-23 11:36:40 -0800 | [diff] [blame] | 1078 | * @return whether the disconnection was initiated successfully or an error code on failure |
| Matthew Xie | f3ee351 | 2012-02-16 16:57:18 -0800 | [diff] [blame] | 1079 | * @hide |
| 1080 | */ |
| Rahul Sabnis | 5ed1b84 | 2021-12-23 11:36:40 -0800 | [diff] [blame] | 1081 | @SystemApi |
| Jeff Sharkey | 5ba8bfc | 2021-04-16 09:53:23 -0600 | [diff] [blame] | 1082 | @RequiresBluetoothConnectPermission |
| Rahul Sabnis | 5ed1b84 | 2021-12-23 11:36:40 -0800 | [diff] [blame] | 1083 | @RequiresPermission(allOf = { |
| 1084 | android.Manifest.permission.BLUETOOTH_CONNECT, |
| 1085 | android.Manifest.permission.BLUETOOTH_PRIVILEGED, |
| 1086 | }) |
| 1087 | public @DisconnectAudioReturnValues int disconnectAudio() { |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 1088 | if (VDBG) log("disconnectAudio()"); |
| Etienne Ruffieux | c3bbf1a | 2022-11-07 14:40:27 -0800 | [diff] [blame] | 1089 | final IBluetoothHeadset service = getService(); |
| Rahul Sabnis | 5ed1b84 | 2021-12-23 11:36:40 -0800 | [diff] [blame] | 1090 | final int defaultValue = BluetoothStatusCodes.ERROR_UNKNOWN; |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 1091 | if (service == null) { |
| Matthew Xie | f3ee351 | 2012-02-16 16:57:18 -0800 | [diff] [blame] | 1092 | Log.w(TAG, "Proxy not attached to service"); |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 1093 | if (DBG) log(Log.getStackTraceString(new Throwable())); |
| Rahul Sabnis | b83a2fe | 2022-01-24 14:38:40 -0800 | [diff] [blame] | 1094 | return BluetoothStatusCodes.ERROR_PROFILE_SERVICE_NOT_BOUND; |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 1095 | } else if (isEnabled()) { |
| 1096 | try { |
| Etienne Ruffieux | 02dcbe7 | 2022-06-22 13:54:25 -0700 | [diff] [blame] | 1097 | final SynchronousResultReceiver<Integer> recv = SynchronousResultReceiver.get(); |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 1098 | service.disconnectAudio(mAttributionSource, recv); |
| 1099 | return recv.awaitResultNoInterrupt(getSyncTimeout()).getValue(defaultValue); |
| Rahul Sabnis | 5ed1b84 | 2021-12-23 11:36:40 -0800 | [diff] [blame] | 1100 | } catch (RemoteException e) { |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 1101 | Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable())); |
| Rahul Sabnis | 5ed1b84 | 2021-12-23 11:36:40 -0800 | [diff] [blame] | 1102 | throw e.rethrowFromSystemServer(); |
| 1103 | } catch (TimeoutException e) { |
| 1104 | Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable())); |
| 1105 | return BluetoothStatusCodes.ERROR_TIMEOUT; |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 1106 | } |
| Matthew Xie | f3ee351 | 2012-02-16 16:57:18 -0800 | [diff] [blame] | 1107 | } |
| Rahul Sabnis | fc0cd8b | 2022-03-22 16:38:38 -0700 | [diff] [blame] | 1108 | |
| 1109 | Log.e(TAG, "disconnectAudio: Bluetooth disabled, but profile service still bound"); |
| 1110 | return defaultValue; |
| Matthew Xie | f3ee351 | 2012-02-16 16:57:18 -0800 | [diff] [blame] | 1111 | } |
| 1112 | |
| 1113 | /** |
| Jack He | c46a01e | 2018-05-02 19:10:56 -0700 | [diff] [blame] | 1114 | * Initiates a SCO channel connection as a virtual voice call to the current active device |
| 1115 | * Active handsfree device will be notified of incoming call and connected call. |
| Jaikumar Ganesh | 7af32b4 | 2010-10-26 17:10:09 -0700 | [diff] [blame] | 1116 | * |
| Jack He | c46a01e | 2018-05-02 19:10:56 -0700 | [diff] [blame] | 1117 | * <p> Users can listen to {@link #ACTION_AUDIO_STATE_CHANGED}. |
| 1118 | * If this function returns true, this intent will be broadcasted with |
| 1119 | * {@link #EXTRA_STATE} set to {@link #STATE_AUDIO_CONNECTING}. |
| 1120 | * |
| 1121 | * <p> {@link #EXTRA_STATE} will transition from |
| 1122 | * {@link #STATE_AUDIO_CONNECTING} to {@link #STATE_AUDIO_CONNECTED} when |
| 1123 | * audio connection is established and to {@link #STATE_AUDIO_DISCONNECTED} |
| 1124 | * in case of failure to establish the audio connection. |
| 1125 | * |
| 1126 | * @return true if successful, false if one of the following case applies |
| 1127 | * - SCO audio is not idle (connecting or connected) |
| 1128 | * - virtual call has already started |
| 1129 | * - there is no active device |
| 1130 | * - a Telecom managed call is going on |
| 1131 | * - binder is dead or Bluetooth is disabled or other error |
| Jaikumar Ganesh | 7af32b4 | 2010-10-26 17:10:09 -0700 | [diff] [blame] | 1132 | * @hide |
| 1133 | */ |
| Roopa Sattiraju | ffab995 | 2021-08-20 15:06:57 -0700 | [diff] [blame] | 1134 | @SystemApi |
| Jeff Sharkey | 8f80e4a | 2021-04-02 08:06:09 -0600 | [diff] [blame] | 1135 | @RequiresLegacyBluetoothAdminPermission |
| 1136 | @RequiresBluetoothConnectPermission |
| 1137 | @RequiresPermission(allOf = { |
| 1138 | android.Manifest.permission.BLUETOOTH_CONNECT, |
| 1139 | android.Manifest.permission.MODIFY_PHONE_STATE, |
| Etienne Ruffieux | b5ae5d3 | 2022-02-25 14:08:27 +0000 | [diff] [blame] | 1140 | android.Manifest.permission.BLUETOOTH_PRIVILEGED, |
| Jeff Sharkey | 8f80e4a | 2021-04-02 08:06:09 -0600 | [diff] [blame] | 1141 | }) |
| Jack He | c46a01e | 2018-05-02 19:10:56 -0700 | [diff] [blame] | 1142 | public boolean startScoUsingVirtualVoiceCall() { |
| Jaikumar Ganesh | eea6d26 | 2011-01-24 13:55:27 -0800 | [diff] [blame] | 1143 | if (DBG) log("startScoUsingVirtualVoiceCall()"); |
| Etienne Ruffieux | c3bbf1a | 2022-11-07 14:40:27 -0800 | [diff] [blame] | 1144 | final IBluetoothHeadset service = getService(); |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 1145 | final boolean defaultValue = false; |
| 1146 | if (service == null) { |
| Jaikumar Ganesh | 7af32b4 | 2010-10-26 17:10:09 -0700 | [diff] [blame] | 1147 | Log.w(TAG, "Proxy not attached to service"); |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 1148 | if (DBG) log(Log.getStackTraceString(new Throwable())); |
| 1149 | } else if (isEnabled()) { |
| 1150 | try { |
| Etienne Ruffieux | 02dcbe7 | 2022-06-22 13:54:25 -0700 | [diff] [blame] | 1151 | final SynchronousResultReceiver<Boolean> recv = SynchronousResultReceiver.get(); |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 1152 | service.startScoUsingVirtualVoiceCall(mAttributionSource, recv); |
| 1153 | return recv.awaitResultNoInterrupt(getSyncTimeout()).getValue(defaultValue); |
| 1154 | } catch (RemoteException | TimeoutException e) { |
| 1155 | Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable())); |
| 1156 | } |
| Jaikumar Ganesh | 7af32b4 | 2010-10-26 17:10:09 -0700 | [diff] [blame] | 1157 | } |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 1158 | return defaultValue; |
| Jaikumar Ganesh | 7af32b4 | 2010-10-26 17:10:09 -0700 | [diff] [blame] | 1159 | } |
| 1160 | |
| 1161 | /** |
| Jack He | c46a01e | 2018-05-02 19:10:56 -0700 | [diff] [blame] | 1162 | * Terminates an ongoing SCO connection and the associated virtual call. |
| Jaikumar Ganesh | 7af32b4 | 2010-10-26 17:10:09 -0700 | [diff] [blame] | 1163 | * |
| Jack He | c46a01e | 2018-05-02 19:10:56 -0700 | [diff] [blame] | 1164 | * <p> Users can listen to {@link #ACTION_AUDIO_STATE_CHANGED}. |
| 1165 | * If this function returns true, this intent will be broadcasted with |
| 1166 | * {@link #EXTRA_STATE} set to {@link #STATE_AUDIO_DISCONNECTED}. |
| 1167 | * |
| 1168 | * @return true if successful, false if one of the following case applies |
| 1169 | * - virtual voice call is not started or has ended |
| 1170 | * - binder is dead or Bluetooth is disabled or other error |
| Jaikumar Ganesh | 7af32b4 | 2010-10-26 17:10:09 -0700 | [diff] [blame] | 1171 | * @hide |
| 1172 | */ |
| Roopa Sattiraju | ffab995 | 2021-08-20 15:06:57 -0700 | [diff] [blame] | 1173 | @SystemApi |
| Jeff Sharkey | 8f80e4a | 2021-04-02 08:06:09 -0600 | [diff] [blame] | 1174 | @RequiresLegacyBluetoothAdminPermission |
| 1175 | @RequiresBluetoothConnectPermission |
| 1176 | @RequiresPermission(allOf = { |
| 1177 | android.Manifest.permission.BLUETOOTH_CONNECT, |
| 1178 | android.Manifest.permission.MODIFY_PHONE_STATE, |
| Etienne Ruffieux | b5ae5d3 | 2022-02-25 14:08:27 +0000 | [diff] [blame] | 1179 | android.Manifest.permission.BLUETOOTH_PRIVILEGED, |
| Jeff Sharkey | 8f80e4a | 2021-04-02 08:06:09 -0600 | [diff] [blame] | 1180 | }) |
| Jack He | c46a01e | 2018-05-02 19:10:56 -0700 | [diff] [blame] | 1181 | public boolean stopScoUsingVirtualVoiceCall() { |
| Jaikumar Ganesh | eea6d26 | 2011-01-24 13:55:27 -0800 | [diff] [blame] | 1182 | if (DBG) log("stopScoUsingVirtualVoiceCall()"); |
| Etienne Ruffieux | c3bbf1a | 2022-11-07 14:40:27 -0800 | [diff] [blame] | 1183 | final IBluetoothHeadset service = getService(); |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 1184 | final boolean defaultValue = false; |
| 1185 | if (service == null) { |
| Jaikumar Ganesh | 7af32b4 | 2010-10-26 17:10:09 -0700 | [diff] [blame] | 1186 | Log.w(TAG, "Proxy not attached to service"); |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 1187 | if (DBG) log(Log.getStackTraceString(new Throwable())); |
| 1188 | } else if (isEnabled()) { |
| 1189 | try { |
| Etienne Ruffieux | 02dcbe7 | 2022-06-22 13:54:25 -0700 | [diff] [blame] | 1190 | final SynchronousResultReceiver<Boolean> recv = SynchronousResultReceiver.get(); |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 1191 | service.stopScoUsingVirtualVoiceCall(mAttributionSource, recv); |
| 1192 | return recv.awaitResultNoInterrupt(getSyncTimeout()).getValue(defaultValue); |
| 1193 | } catch (RemoteException | TimeoutException e) { |
| 1194 | Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable())); |
| 1195 | } |
| Jaikumar Ganesh | 7af32b4 | 2010-10-26 17:10:09 -0700 | [diff] [blame] | 1196 | } |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 1197 | return defaultValue; |
| Jaikumar Ganesh | 7af32b4 | 2010-10-26 17:10:09 -0700 | [diff] [blame] | 1198 | } |
| 1199 | |
| Matthew Xie | f3ee351 | 2012-02-16 16:57:18 -0800 | [diff] [blame] | 1200 | /** |
| 1201 | * Notify Headset of phone state change. |
| 1202 | * This is a backdoor for phone app to call BluetoothHeadset since |
| 1203 | * there is currently not a good way to get precise call state change outside |
| 1204 | * of phone app. |
| 1205 | * |
| 1206 | * @hide |
| 1207 | */ |
| Mathew Inwood | 049f0f5 | 2020-11-04 09:29:36 +0000 | [diff] [blame] | 1208 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) |
| Jeff Sharkey | 5ba8bfc | 2021-04-16 09:53:23 -0600 | [diff] [blame] | 1209 | @RequiresBluetoothConnectPermission |
| Jeff Sharkey | 8f80e4a | 2021-04-02 08:06:09 -0600 | [diff] [blame] | 1210 | @RequiresPermission(allOf = { |
| 1211 | android.Manifest.permission.BLUETOOTH_CONNECT, |
| 1212 | android.Manifest.permission.MODIFY_PHONE_STATE, |
| 1213 | }) |
| Matthew Xie | f3ee351 | 2012-02-16 16:57:18 -0800 | [diff] [blame] | 1214 | public void phoneStateChanged(int numActive, int numHeld, int callState, String number, |
| Benson Li | ed8d339 | 2018-07-17 18:19:59 +0800 | [diff] [blame] | 1215 | int type, String name) { |
| Etienne Ruffieux | c3bbf1a | 2022-11-07 14:40:27 -0800 | [diff] [blame] | 1216 | final IBluetoothHeadset service = getService(); |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 1217 | if (service == null) { |
| 1218 | Log.w(TAG, "Proxy not attached to service"); |
| 1219 | if (DBG) log(Log.getStackTraceString(new Throwable())); |
| 1220 | } else if (isEnabled()) { |
| Matthew Xie | f3ee351 | 2012-02-16 16:57:18 -0800 | [diff] [blame] | 1221 | try { |
| Jeff Sharkey | 43ee69e | 2021-04-23 14:13:57 -0600 | [diff] [blame] | 1222 | service.phoneStateChanged(numActive, numHeld, callState, number, type, name, |
| 1223 | mAttributionSource); |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 1224 | } catch (RemoteException e) { |
| 1225 | Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable())); |
| Matthew Xie | f3ee351 | 2012-02-16 16:57:18 -0800 | [diff] [blame] | 1226 | } |
| Matthew Xie | f3ee351 | 2012-02-16 16:57:18 -0800 | [diff] [blame] | 1227 | } |
| 1228 | } |
| 1229 | |
| 1230 | /** |
| Matthew Xie | f3ee351 | 2012-02-16 16:57:18 -0800 | [diff] [blame] | 1231 | * Send Headset of CLCC response |
| 1232 | * |
| 1233 | * @hide |
| 1234 | */ |
| Jeff Sharkey | 5ba8bfc | 2021-04-16 09:53:23 -0600 | [diff] [blame] | 1235 | @RequiresBluetoothConnectPermission |
| Jeff Sharkey | 8f80e4a | 2021-04-02 08:06:09 -0600 | [diff] [blame] | 1236 | @RequiresPermission(allOf = { |
| 1237 | android.Manifest.permission.BLUETOOTH_CONNECT, |
| 1238 | android.Manifest.permission.MODIFY_PHONE_STATE, |
| 1239 | }) |
| Matthew Xie | f3ee351 | 2012-02-16 16:57:18 -0800 | [diff] [blame] | 1240 | public void clccResponse(int index, int direction, int status, int mode, boolean mpty, |
| Jack He | 910201b | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 1241 | String number, int type) { |
| Etienne Ruffieux | c3bbf1a | 2022-11-07 14:40:27 -0800 | [diff] [blame] | 1242 | final IBluetoothHeadset service = getService(); |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 1243 | if (service == null) { |
| Matthew Xie | f3ee351 | 2012-02-16 16:57:18 -0800 | [diff] [blame] | 1244 | Log.w(TAG, "Proxy not attached to service"); |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 1245 | if (DBG) log(Log.getStackTraceString(new Throwable())); |
| 1246 | } else if (isEnabled()) { |
| 1247 | try { |
| Etienne Ruffieux | 02dcbe7 | 2022-06-22 13:54:25 -0700 | [diff] [blame] | 1248 | final SynchronousResultReceiver recv = SynchronousResultReceiver.get(); |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 1249 | service.clccResponse(index, direction, status, mode, mpty, number, type, |
| 1250 | mAttributionSource, recv); |
| 1251 | recv.awaitResultNoInterrupt(getSyncTimeout()).getValue(null); |
| 1252 | } catch (RemoteException | TimeoutException e) { |
| 1253 | Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable())); |
| 1254 | } |
| Matthew Xie | f3ee351 | 2012-02-16 16:57:18 -0800 | [diff] [blame] | 1255 | } |
| 1256 | } |
| 1257 | |
| Edward Jee | 7c81f1f | 2013-08-16 04:07:49 -0700 | [diff] [blame] | 1258 | /** |
| 1259 | * Sends a vendor-specific unsolicited result code to the headset. |
| 1260 | * |
| Jack He | 910201b | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 1261 | * <p>The actual string to be sent is <code>command + ": " + arg</code>. For example, if {@code |
| 1262 | * command} is {@link #VENDOR_RESULT_CODE_COMMAND_ANDROID} and {@code arg} is {@code "0"}, the |
| 1263 | * string <code>"+ANDROID: 0"</code> will be sent. |
| Edward Jee | 7c81f1f | 2013-08-16 04:07:49 -0700 | [diff] [blame] | 1264 | * |
| Ying Wang | 29d9389 | 2013-08-26 17:48:22 -0700 | [diff] [blame] | 1265 | * <p>Currently only {@link #VENDOR_RESULT_CODE_COMMAND_ANDROID} is allowed as {@code command}. |
| Edward Jee | 7c81f1f | 2013-08-16 04:07:49 -0700 | [diff] [blame] | 1266 | * |
| Edward Jee | 7c81f1f | 2013-08-16 04:07:49 -0700 | [diff] [blame] | 1267 | * @param device Bluetooth headset. |
| 1268 | * @param command A vendor-specific command. |
| 1269 | * @param arg The argument that will be attached to the command. |
| 1270 | * @return {@code false} if there is no headset connected, or if the command is not an allowed |
| Jack He | 910201b | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 1271 | * vendor-specific unsolicited result code, or on error. {@code true} otherwise. |
| Edward Jee | 7c81f1f | 2013-08-16 04:07:49 -0700 | [diff] [blame] | 1272 | * @throws IllegalArgumentException if {@code command} is {@code null}. |
| 1273 | */ |
| Jeff Sharkey | 8f80e4a | 2021-04-02 08:06:09 -0600 | [diff] [blame] | 1274 | @RequiresLegacyBluetoothPermission |
| 1275 | @RequiresBluetoothConnectPermission |
| 1276 | @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) |
| Edward Jee | 7c81f1f | 2013-08-16 04:07:49 -0700 | [diff] [blame] | 1277 | public boolean sendVendorSpecificResultCode(BluetoothDevice device, String command, |
| 1278 | String arg) { |
| 1279 | if (DBG) { |
| 1280 | log("sendVendorSpecificResultCode()"); |
| 1281 | } |
| 1282 | if (command == null) { |
| 1283 | throw new IllegalArgumentException("command is null"); |
| 1284 | } |
| Etienne Ruffieux | c3bbf1a | 2022-11-07 14:40:27 -0800 | [diff] [blame] | 1285 | final IBluetoothHeadset service = getService(); |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 1286 | final boolean defaultValue = false; |
| Jack He | 1f686f6 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 1287 | if (service == null) { |
| Edward Jee | 7c81f1f | 2013-08-16 04:07:49 -0700 | [diff] [blame] | 1288 | Log.w(TAG, "Proxy not attached to service"); |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 1289 | if (DBG) log(Log.getStackTraceString(new Throwable())); |
| 1290 | } else if (isEnabled() && isValidDevice(device)) { |
| 1291 | try { |
| Etienne Ruffieux | 02dcbe7 | 2022-06-22 13:54:25 -0700 | [diff] [blame] | 1292 | final SynchronousResultReceiver<Boolean> recv = SynchronousResultReceiver.get(); |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 1293 | service.sendVendorSpecificResultCode(device, command, arg, |
| 1294 | mAttributionSource, recv); |
| 1295 | return recv.awaitResultNoInterrupt(getSyncTimeout()).getValue(defaultValue); |
| 1296 | } catch (RemoteException | TimeoutException e) { |
| 1297 | Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable())); |
| 1298 | } |
| Edward Jee | 7c81f1f | 2013-08-16 04:07:49 -0700 | [diff] [blame] | 1299 | } |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 1300 | return defaultValue; |
| Edward Jee | 7c81f1f | 2013-08-16 04:07:49 -0700 | [diff] [blame] | 1301 | } |
| 1302 | |
| Mudumba Ananth | 80bf628 | 2014-04-27 13:11:00 -0700 | [diff] [blame] | 1303 | /** |
| Jack He | 889d234 | 2018-01-03 12:13:26 -0800 | [diff] [blame] | 1304 | * Select a connected device as active. |
| 1305 | * |
| 1306 | * The active device selection is per profile. An active device's |
| 1307 | * purpose is profile-specific. For example, in HFP and HSP profiles, |
| 1308 | * it is the device used for phone call audio. If a remote device is not |
| 1309 | * connected, it cannot be selected as active. |
| 1310 | * |
| 1311 | * <p> This API returns false in scenarios like the profile on the |
| 1312 | * device is not connected or Bluetooth is not turned on. |
| 1313 | * When this API returns true, it is guaranteed that the |
| 1314 | * {@link #ACTION_ACTIVE_DEVICE_CHANGED} intent will be broadcasted |
| 1315 | * with the active device. |
| 1316 | * |
| Jack He | 889d234 | 2018-01-03 12:13:26 -0800 | [diff] [blame] | 1317 | * @param device Remote Bluetooth Device, could be null if phone call audio should not be |
| 1318 | * streamed to a headset |
| 1319 | * @return false on immediate error, true otherwise |
| 1320 | * @hide |
| 1321 | */ |
| Jeff Sharkey | 8f80e4a | 2021-04-02 08:06:09 -0600 | [diff] [blame] | 1322 | @RequiresLegacyBluetoothAdminPermission |
| 1323 | @RequiresBluetoothConnectPermission |
| 1324 | @RequiresPermission(allOf = { |
| 1325 | android.Manifest.permission.BLUETOOTH_CONNECT, |
| 1326 | android.Manifest.permission.MODIFY_PHONE_STATE, |
| 1327 | }) |
| Mathew Inwood | b426f90 | 2021-01-06 12:05:47 +0000 | [diff] [blame] | 1328 | @UnsupportedAppUsage(trackingBug = 171933273) |
| Jack He | 889d234 | 2018-01-03 12:13:26 -0800 | [diff] [blame] | 1329 | public boolean setActiveDevice(@Nullable BluetoothDevice device) { |
| 1330 | if (DBG) { |
| 1331 | Log.d(TAG, "setActiveDevice: " + device); |
| 1332 | } |
| Etienne Ruffieux | c3bbf1a | 2022-11-07 14:40:27 -0800 | [diff] [blame] | 1333 | final IBluetoothHeadset service = getService(); |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 1334 | final boolean defaultValue = false; |
| Jack He | 889d234 | 2018-01-03 12:13:26 -0800 | [diff] [blame] | 1335 | if (service == null) { |
| 1336 | Log.w(TAG, "Proxy not attached to service"); |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 1337 | if (DBG) log(Log.getStackTraceString(new Throwable())); |
| 1338 | } else if (isEnabled() && (device == null || isValidDevice(device))) { |
| 1339 | try { |
| Etienne Ruffieux | 02dcbe7 | 2022-06-22 13:54:25 -0700 | [diff] [blame] | 1340 | final SynchronousResultReceiver<Boolean> recv = SynchronousResultReceiver.get(); |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 1341 | service.setActiveDevice(device, mAttributionSource, recv); |
| 1342 | return recv.awaitResultNoInterrupt(getSyncTimeout()).getValue(defaultValue); |
| 1343 | } catch (RemoteException | TimeoutException e) { |
| 1344 | Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable())); |
| 1345 | } |
| Jack He | 889d234 | 2018-01-03 12:13:26 -0800 | [diff] [blame] | 1346 | } |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 1347 | return defaultValue; |
| Jack He | 889d234 | 2018-01-03 12:13:26 -0800 | [diff] [blame] | 1348 | } |
| 1349 | |
| 1350 | /** |
| 1351 | * Get the connected device that is active. |
| 1352 | * |
| Jack He | 889d234 | 2018-01-03 12:13:26 -0800 | [diff] [blame] | 1353 | * @return the connected device that is active or null if no device |
| 1354 | * is active. |
| 1355 | * @hide |
| 1356 | */ |
| Mathew Inwood | b426f90 | 2021-01-06 12:05:47 +0000 | [diff] [blame] | 1357 | @UnsupportedAppUsage(trackingBug = 171933273) |
| Rahul Sabnis | d979861 | 2019-12-04 14:21:10 -0800 | [diff] [blame] | 1358 | @Nullable |
| Jeff Sharkey | 8f80e4a | 2021-04-02 08:06:09 -0600 | [diff] [blame] | 1359 | @RequiresLegacyBluetoothPermission |
| 1360 | @RequiresBluetoothConnectPermission |
| 1361 | @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) |
| Jack He | 889d234 | 2018-01-03 12:13:26 -0800 | [diff] [blame] | 1362 | public BluetoothDevice getActiveDevice() { |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 1363 | if (VDBG) Log.d(TAG, "getActiveDevice"); |
| Etienne Ruffieux | c3bbf1a | 2022-11-07 14:40:27 -0800 | [diff] [blame] | 1364 | final IBluetoothHeadset service = getService(); |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 1365 | final BluetoothDevice defaultValue = null; |
| Jack He | 889d234 | 2018-01-03 12:13:26 -0800 | [diff] [blame] | 1366 | if (service == null) { |
| 1367 | Log.w(TAG, "Proxy not attached to service"); |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 1368 | if (DBG) log(Log.getStackTraceString(new Throwable())); |
| 1369 | } else if (isEnabled()) { |
| 1370 | try { |
| 1371 | final SynchronousResultReceiver<BluetoothDevice> recv = |
| Etienne Ruffieux | 02dcbe7 | 2022-06-22 13:54:25 -0700 | [diff] [blame] | 1372 | SynchronousResultReceiver.get(); |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 1373 | service.getActiveDevice(mAttributionSource, recv); |
| 1374 | return Attributable.setAttributionSource( |
| 1375 | recv.awaitResultNoInterrupt(getSyncTimeout()).getValue(defaultValue), |
| 1376 | mAttributionSource); |
| 1377 | } catch (RemoteException | TimeoutException e) { |
| 1378 | Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable())); |
| 1379 | } |
| Jack He | 889d234 | 2018-01-03 12:13:26 -0800 | [diff] [blame] | 1380 | } |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 1381 | return defaultValue; |
| Jack He | 889d234 | 2018-01-03 12:13:26 -0800 | [diff] [blame] | 1382 | } |
| 1383 | |
| 1384 | /** |
| Jack He | c5fde73 | 2018-01-05 17:17:06 -0800 | [diff] [blame] | 1385 | * Check if in-band ringing is currently enabled. In-band ringing could be disabled during an |
| 1386 | * active connection. |
| Jack He | d8d204d | 2016-11-17 16:19:43 -0800 | [diff] [blame] | 1387 | * |
| Jack He | c5fde73 | 2018-01-05 17:17:06 -0800 | [diff] [blame] | 1388 | * @return true if in-band ringing is enabled, false if in-band ringing is disabled |
| 1389 | * @hide |
| 1390 | */ |
| Roopa Sattiraju | ffab995 | 2021-08-20 15:06:57 -0700 | [diff] [blame] | 1391 | @SystemApi |
| Jeff Sharkey | 8f80e4a | 2021-04-02 08:06:09 -0600 | [diff] [blame] | 1392 | @RequiresLegacyBluetoothPermission |
| 1393 | @RequiresBluetoothConnectPermission |
| Rahul Sabnis | 5ed1b84 | 2021-12-23 11:36:40 -0800 | [diff] [blame] | 1394 | @RequiresPermission(allOf = { |
| 1395 | android.Manifest.permission.BLUETOOTH_CONNECT, |
| 1396 | android.Manifest.permission.BLUETOOTH_PRIVILEGED, |
| 1397 | }) |
| Jack He | c5fde73 | 2018-01-05 17:17:06 -0800 | [diff] [blame] | 1398 | public boolean isInbandRingingEnabled() { |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 1399 | if (DBG) log("isInbandRingingEnabled()"); |
| Etienne Ruffieux | c3bbf1a | 2022-11-07 14:40:27 -0800 | [diff] [blame] | 1400 | final IBluetoothHeadset service = getService(); |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 1401 | final boolean defaultValue = false; |
| Jack He | c5fde73 | 2018-01-05 17:17:06 -0800 | [diff] [blame] | 1402 | if (service == null) { |
| 1403 | Log.w(TAG, "Proxy not attached to service"); |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 1404 | if (DBG) log(Log.getStackTraceString(new Throwable())); |
| 1405 | } else if (isEnabled()) { |
| 1406 | try { |
| Etienne Ruffieux | 02dcbe7 | 2022-06-22 13:54:25 -0700 | [diff] [blame] | 1407 | final SynchronousResultReceiver<Boolean> recv = SynchronousResultReceiver.get(); |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 1408 | service.isInbandRingingEnabled(mAttributionSource, recv); |
| 1409 | return recv.awaitResultNoInterrupt(getSyncTimeout()).getValue(defaultValue); |
| 1410 | } catch (RemoteException | TimeoutException e) { |
| 1411 | Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable())); |
| 1412 | } |
| Jack He | c5fde73 | 2018-01-05 17:17:06 -0800 | [diff] [blame] | 1413 | } |
| William Escande | 9a4b7c1 | 2021-12-16 16:07:55 +0100 | [diff] [blame] | 1414 | return defaultValue; |
| Jack He | c5fde73 | 2018-01-05 17:17:06 -0800 | [diff] [blame] | 1415 | } |
| 1416 | |
| Mathew Inwood | 7d54389 | 2018-08-01 15:07:20 +0100 | [diff] [blame] | 1417 | @UnsupportedAppUsage |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 1418 | private boolean isEnabled() { |
| Jack He | 1f686f6 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 1419 | return mAdapter.getState() == BluetoothAdapter.STATE_ON; |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 1420 | } |
| 1421 | |
| Jaikumar Ganesh | 2fbe8f4 | 2011-04-06 11:09:30 -0700 | [diff] [blame] | 1422 | private boolean isDisabled() { |
| Jack He | 1f686f6 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 1423 | return mAdapter.getState() == BluetoothAdapter.STATE_OFF; |
| Jaikumar Ganesh | 2fbe8f4 | 2011-04-06 11:09:30 -0700 | [diff] [blame] | 1424 | } |
| 1425 | |
| Jack He | 1f686f6 | 2017-08-17 12:11:18 -0700 | [diff] [blame] | 1426 | private static boolean isValidDevice(BluetoothDevice device) { |
| 1427 | return device != null && BluetoothAdapter.checkBluetoothAddress(device.getAddress()); |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 1428 | } |
| 1429 | |
| The Android Open Source Project | 0047a0f | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 1430 | private static void log(String msg) { |
| 1431 | Log.d(TAG, msg); |
| 1432 | } |
| The Android Open Source Project | 3389776 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1433 | } |