Jakub Pawlowski | ea580fa | 2017-11-22 11:02:34 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018 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 | |
| 19 | import android.Manifest; |
Stanley Tng | 9d37667 | 2019-02-28 12:22:45 -0800 | [diff] [blame] | 20 | import android.annotation.NonNull; |
Hansong Zhang | 7ca303c | 2018-03-16 09:15:48 -0700 | [diff] [blame] | 21 | import android.annotation.Nullable; |
Jakub Pawlowski | ea580fa | 2017-11-22 11:02:34 -0800 | [diff] [blame] | 22 | import android.annotation.RequiresPermission; |
| 23 | import android.annotation.SdkConstant; |
| 24 | import android.annotation.SdkConstant.SdkConstantType; |
Rahul Sabnis | df1ef4a | 2019-11-27 18:09:33 -0800 | [diff] [blame] | 25 | import android.annotation.SystemApi; |
Mathew Inwood | 3a75f26 | 2019-06-27 12:47:38 +0100 | [diff] [blame] | 26 | import android.annotation.UnsupportedAppUsage; |
Jakub Pawlowski | ea580fa | 2017-11-22 11:02:34 -0800 | [diff] [blame] | 27 | import android.content.Context; |
Jakub Pawlowski | ea580fa | 2017-11-22 11:02:34 -0800 | [diff] [blame] | 28 | import android.os.Binder; |
| 29 | import android.os.IBinder; |
| 30 | import android.os.RemoteException; |
| 31 | import android.util.Log; |
| 32 | |
Jakub Pawlowski | ea580fa | 2017-11-22 11:02:34 -0800 | [diff] [blame] | 33 | import java.util.ArrayList; |
| 34 | import java.util.List; |
Jakub Pawlowski | ea580fa | 2017-11-22 11:02:34 -0800 | [diff] [blame] | 35 | |
| 36 | /** |
Stanley Tng | 1f5ea66 | 2018-11-15 17:11:36 -0800 | [diff] [blame] | 37 | * This class provides the public APIs to control the Hearing Aid profile. |
Jakub Pawlowski | ea580fa | 2017-11-22 11:02:34 -0800 | [diff] [blame] | 38 | * |
| 39 | * <p>BluetoothHearingAid is a proxy object for controlling the Bluetooth Hearing Aid |
| 40 | * Service via IPC. Use {@link BluetoothAdapter#getProfileProxy} to get |
| 41 | * the BluetoothHearingAid proxy object. |
| 42 | * |
Stanley Tng | 1f5ea66 | 2018-11-15 17:11:36 -0800 | [diff] [blame] | 43 | * <p> Android only supports one set of connected Bluetooth Hearing Aid device at a time. Each |
| 44 | * method is protected with its appropriate permission. |
Jakub Pawlowski | ea580fa | 2017-11-22 11:02:34 -0800 | [diff] [blame] | 45 | */ |
| 46 | public final class BluetoothHearingAid implements BluetoothProfile { |
| 47 | private static final String TAG = "BluetoothHearingAid"; |
Stanley Tng | 420a0eb | 2018-11-15 10:22:07 -0800 | [diff] [blame] | 48 | private static final boolean DBG = true; |
Jakub Pawlowski | ea580fa | 2017-11-22 11:02:34 -0800 | [diff] [blame] | 49 | private static final boolean VDBG = false; |
| 50 | |
| 51 | /** |
| 52 | * Intent used to broadcast the change in connection state of the Hearing Aid |
Stanley Tng | 1f5ea66 | 2018-11-15 17:11:36 -0800 | [diff] [blame] | 53 | * profile. Please note that in the binaural case, there will be two different LE devices for |
| 54 | * the left and right side and each device will have their own connection state changes.S |
Jakub Pawlowski | ea580fa | 2017-11-22 11:02:34 -0800 | [diff] [blame] | 55 | * |
| 56 | * <p>This intent will have 3 extras: |
| 57 | * <ul> |
| 58 | * <li> {@link #EXTRA_STATE} - The current state of the profile. </li> |
| 59 | * <li> {@link #EXTRA_PREVIOUS_STATE}- The previous state of the profile.</li> |
| 60 | * <li> {@link BluetoothDevice#EXTRA_DEVICE} - The remote device. </li> |
| 61 | * </ul> |
| 62 | * |
| 63 | * <p>{@link #EXTRA_STATE} or {@link #EXTRA_PREVIOUS_STATE} can be any of |
| 64 | * {@link #STATE_DISCONNECTED}, {@link #STATE_CONNECTING}, |
| 65 | * {@link #STATE_CONNECTED}, {@link #STATE_DISCONNECTING}. |
| 66 | * |
| 67 | * <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission to |
| 68 | * receive. |
| 69 | */ |
| 70 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
| 71 | public static final String ACTION_CONNECTION_STATE_CHANGED = |
| 72 | "android.bluetooth.hearingaid.profile.action.CONNECTION_STATE_CHANGED"; |
| 73 | |
| 74 | /** |
Jakub Pawlowski | ea580fa | 2017-11-22 11:02:34 -0800 | [diff] [blame] | 75 | * Intent used to broadcast the selection of a connected device as active. |
| 76 | * |
| 77 | * <p>This intent will have one extra: |
| 78 | * <ul> |
| 79 | * <li> {@link BluetoothDevice#EXTRA_DEVICE} - The remote device. It can |
| 80 | * be null if no device is active. </li> |
| 81 | * </ul> |
| 82 | * |
| 83 | * <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission to |
| 84 | * receive. |
Stanley Tng | 1f5ea66 | 2018-11-15 17:11:36 -0800 | [diff] [blame] | 85 | * |
| 86 | * @hide |
Jakub Pawlowski | ea580fa | 2017-11-22 11:02:34 -0800 | [diff] [blame] | 87 | */ |
Mathew Inwood | 3a75f26 | 2019-06-27 12:47:38 +0100 | [diff] [blame] | 88 | @UnsupportedAppUsage |
Jakub Pawlowski | ea580fa | 2017-11-22 11:02:34 -0800 | [diff] [blame] | 89 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
| 90 | public static final String ACTION_ACTIVE_DEVICE_CHANGED = |
| 91 | "android.bluetooth.hearingaid.profile.action.ACTIVE_DEVICE_CHANGED"; |
| 92 | |
| 93 | /** |
Stanley Tng | 1f5ea66 | 2018-11-15 17:11:36 -0800 | [diff] [blame] | 94 | * This device represents Left Hearing Aid. |
| 95 | * |
| 96 | * @hide |
Jakub Pawlowski | ea580fa | 2017-11-22 11:02:34 -0800 | [diff] [blame] | 97 | */ |
Jakub Pawlowski | ea580fa | 2017-11-22 11:02:34 -0800 | [diff] [blame] | 98 | public static final int SIDE_LEFT = IBluetoothHearingAid.SIDE_LEFT; |
| 99 | |
Stanley Tng | 1f5ea66 | 2018-11-15 17:11:36 -0800 | [diff] [blame] | 100 | /** |
| 101 | * This device represents Right Hearing Aid. |
| 102 | * |
| 103 | * @hide |
| 104 | */ |
Jakub Pawlowski | ea580fa | 2017-11-22 11:02:34 -0800 | [diff] [blame] | 105 | public static final int SIDE_RIGHT = IBluetoothHearingAid.SIDE_RIGHT; |
| 106 | |
Stanley Tng | 1f5ea66 | 2018-11-15 17:11:36 -0800 | [diff] [blame] | 107 | /** |
| 108 | * This device is Monaural. |
| 109 | * |
| 110 | * @hide |
| 111 | */ |
Jakub Pawlowski | ea580fa | 2017-11-22 11:02:34 -0800 | [diff] [blame] | 112 | public static final int MODE_MONAURAL = IBluetoothHearingAid.MODE_MONAURAL; |
| 113 | |
Stanley Tng | 1f5ea66 | 2018-11-15 17:11:36 -0800 | [diff] [blame] | 114 | /** |
| 115 | * This device is Binaural (should receive only left or right audio). |
| 116 | * |
| 117 | * @hide |
| 118 | */ |
Jakub Pawlowski | ea580fa | 2017-11-22 11:02:34 -0800 | [diff] [blame] | 119 | public static final int MODE_BINAURAL = IBluetoothHearingAid.MODE_BINAURAL; |
| 120 | |
Stanley Tng | 1f5ea66 | 2018-11-15 17:11:36 -0800 | [diff] [blame] | 121 | /** |
| 122 | * Indicates the HiSyncID could not be read and is unavailable. |
| 123 | * |
| 124 | * @hide |
| 125 | */ |
Jakub Pawlowski | ea580fa | 2017-11-22 11:02:34 -0800 | [diff] [blame] | 126 | public static final long HI_SYNC_ID_INVALID = IBluetoothHearingAid.HI_SYNC_ID_INVALID; |
| 127 | |
Jakub Pawlowski | ea580fa | 2017-11-22 11:02:34 -0800 | [diff] [blame] | 128 | private BluetoothAdapter mAdapter; |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 129 | private final BluetoothProfileConnector<IBluetoothHearingAid> mProfileConnector = |
| 130 | new BluetoothProfileConnector(this, BluetoothProfile.HEARING_AID, |
| 131 | "BluetoothHearingAid", IBluetoothHearingAid.class.getName()) { |
| 132 | @Override |
| 133 | public IBluetoothHearingAid getServiceInterface(IBinder service) { |
| 134 | return IBluetoothHearingAid.Stub.asInterface(Binder.allowBlocking(service)); |
Jakub Pawlowski | ea580fa | 2017-11-22 11:02:34 -0800 | [diff] [blame] | 135 | } |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 136 | }; |
Jakub Pawlowski | ea580fa | 2017-11-22 11:02:34 -0800 | [diff] [blame] | 137 | |
| 138 | /** |
| 139 | * Create a BluetoothHearingAid proxy object for interacting with the local |
| 140 | * Bluetooth Hearing Aid service. |
| 141 | */ |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 142 | /*package*/ BluetoothHearingAid(Context context, ServiceListener listener) { |
Jakub Pawlowski | ea580fa | 2017-11-22 11:02:34 -0800 | [diff] [blame] | 143 | mAdapter = BluetoothAdapter.getDefaultAdapter(); |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 144 | mProfileConnector.connect(context, listener); |
Jakub Pawlowski | ea580fa | 2017-11-22 11:02:34 -0800 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | /*package*/ void close() { |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 148 | mProfileConnector.disconnect(); |
| 149 | } |
Jakub Pawlowski | ea580fa | 2017-11-22 11:02:34 -0800 | [diff] [blame] | 150 | |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 151 | private IBluetoothHearingAid getService() { |
| 152 | return mProfileConnector.getService(); |
Jakub Pawlowski | ea580fa | 2017-11-22 11:02:34 -0800 | [diff] [blame] | 153 | } |
| 154 | |
Jakub Pawlowski | ea580fa | 2017-11-22 11:02:34 -0800 | [diff] [blame] | 155 | /** |
| 156 | * Initiate connection to a profile of the remote bluetooth device. |
| 157 | * |
| 158 | * <p> This API returns false in scenarios like the profile on the |
| 159 | * device is already connected or Bluetooth is not turned on. |
| 160 | * When this API returns true, it is guaranteed that |
| 161 | * connection state intent for the profile will be broadcasted with |
| 162 | * the state. Users can get the connection state of the profile |
| 163 | * from this intent. |
| 164 | * |
| 165 | * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN} |
| 166 | * permission. |
| 167 | * |
| 168 | * @param device Remote Bluetooth Device |
| 169 | * @return false on immediate error, true otherwise |
| 170 | * @hide |
| 171 | */ |
| 172 | public boolean connect(BluetoothDevice device) { |
| 173 | if (DBG) log("connect(" + device + ")"); |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 174 | final IBluetoothHearingAid service = getService(); |
Jakub Pawlowski | ea580fa | 2017-11-22 11:02:34 -0800 | [diff] [blame] | 175 | try { |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 176 | if (service != null && isEnabled() && isValidDevice(device)) { |
| 177 | return service.connect(device); |
Jakub Pawlowski | ea580fa | 2017-11-22 11:02:34 -0800 | [diff] [blame] | 178 | } |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 179 | if (service == null) Log.w(TAG, "Proxy not attached to service"); |
Jakub Pawlowski | ea580fa | 2017-11-22 11:02:34 -0800 | [diff] [blame] | 180 | return false; |
| 181 | } catch (RemoteException e) { |
| 182 | Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable())); |
| 183 | return false; |
Jakub Pawlowski | ea580fa | 2017-11-22 11:02:34 -0800 | [diff] [blame] | 184 | } |
| 185 | } |
| 186 | |
| 187 | /** |
| 188 | * Initiate disconnection from a profile |
| 189 | * |
| 190 | * <p> This API will return false in scenarios like the profile on the |
| 191 | * Bluetooth device is not in connected state etc. When this API returns, |
| 192 | * true, it is guaranteed that the connection state change |
| 193 | * intent will be broadcasted with the state. Users can get the |
| 194 | * disconnection state of the profile from this intent. |
| 195 | * |
| 196 | * <p> If the disconnection is initiated by a remote device, the state |
| 197 | * will transition from {@link #STATE_CONNECTED} to |
| 198 | * {@link #STATE_DISCONNECTED}. If the disconnect is initiated by the |
| 199 | * host (local) device the state will transition from |
| 200 | * {@link #STATE_CONNECTED} to state {@link #STATE_DISCONNECTING} to |
| 201 | * state {@link #STATE_DISCONNECTED}. The transition to |
| 202 | * {@link #STATE_DISCONNECTING} can be used to distinguish between the |
| 203 | * two scenarios. |
| 204 | * |
| 205 | * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN} |
| 206 | * permission. |
| 207 | * |
| 208 | * @param device Remote Bluetooth Device |
| 209 | * @return false on immediate error, true otherwise |
| 210 | * @hide |
| 211 | */ |
| 212 | public boolean disconnect(BluetoothDevice device) { |
| 213 | if (DBG) log("disconnect(" + device + ")"); |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 214 | final IBluetoothHearingAid service = getService(); |
Jakub Pawlowski | ea580fa | 2017-11-22 11:02:34 -0800 | [diff] [blame] | 215 | try { |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 216 | if (service != null && isEnabled() && isValidDevice(device)) { |
| 217 | return service.disconnect(device); |
Jakub Pawlowski | ea580fa | 2017-11-22 11:02:34 -0800 | [diff] [blame] | 218 | } |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 219 | if (service == null) Log.w(TAG, "Proxy not attached to service"); |
Jakub Pawlowski | ea580fa | 2017-11-22 11:02:34 -0800 | [diff] [blame] | 220 | return false; |
| 221 | } catch (RemoteException e) { |
| 222 | Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable())); |
| 223 | return false; |
Jakub Pawlowski | ea580fa | 2017-11-22 11:02:34 -0800 | [diff] [blame] | 224 | } |
| 225 | } |
| 226 | |
| 227 | /** |
| 228 | * {@inheritDoc} |
| 229 | */ |
| 230 | @Override |
Stanley Tng | 9d37667 | 2019-02-28 12:22:45 -0800 | [diff] [blame] | 231 | public @NonNull List<BluetoothDevice> getConnectedDevices() { |
Jakub Pawlowski | ea580fa | 2017-11-22 11:02:34 -0800 | [diff] [blame] | 232 | if (VDBG) log("getConnectedDevices()"); |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 233 | final IBluetoothHearingAid service = getService(); |
Jakub Pawlowski | ea580fa | 2017-11-22 11:02:34 -0800 | [diff] [blame] | 234 | try { |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 235 | if (service != null && isEnabled()) { |
| 236 | return service.getConnectedDevices(); |
Jakub Pawlowski | ea580fa | 2017-11-22 11:02:34 -0800 | [diff] [blame] | 237 | } |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 238 | if (service == null) Log.w(TAG, "Proxy not attached to service"); |
Jakub Pawlowski | ea580fa | 2017-11-22 11:02:34 -0800 | [diff] [blame] | 239 | return new ArrayList<BluetoothDevice>(); |
| 240 | } catch (RemoteException e) { |
| 241 | Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable())); |
| 242 | return new ArrayList<BluetoothDevice>(); |
Jakub Pawlowski | ea580fa | 2017-11-22 11:02:34 -0800 | [diff] [blame] | 243 | } |
| 244 | } |
| 245 | |
| 246 | /** |
| 247 | * {@inheritDoc} |
| 248 | */ |
Stanley Tng | 7f3b781 | 2019-03-14 16:18:29 -0700 | [diff] [blame] | 249 | @Override |
| 250 | public @NonNull List<BluetoothDevice> getDevicesMatchingConnectionStates( |
Stanley Tng | 9d37667 | 2019-02-28 12:22:45 -0800 | [diff] [blame] | 251 | @NonNull int[] states) { |
Jakub Pawlowski | ea580fa | 2017-11-22 11:02:34 -0800 | [diff] [blame] | 252 | if (VDBG) log("getDevicesMatchingStates()"); |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 253 | final IBluetoothHearingAid service = getService(); |
Jakub Pawlowski | ea580fa | 2017-11-22 11:02:34 -0800 | [diff] [blame] | 254 | try { |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 255 | if (service != null && isEnabled()) { |
| 256 | return service.getDevicesMatchingConnectionStates(states); |
Jakub Pawlowski | ea580fa | 2017-11-22 11:02:34 -0800 | [diff] [blame] | 257 | } |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 258 | if (service == null) Log.w(TAG, "Proxy not attached to service"); |
Jakub Pawlowski | ea580fa | 2017-11-22 11:02:34 -0800 | [diff] [blame] | 259 | return new ArrayList<BluetoothDevice>(); |
| 260 | } catch (RemoteException e) { |
| 261 | Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable())); |
| 262 | return new ArrayList<BluetoothDevice>(); |
Jakub Pawlowski | ea580fa | 2017-11-22 11:02:34 -0800 | [diff] [blame] | 263 | } |
| 264 | } |
| 265 | |
| 266 | /** |
| 267 | * {@inheritDoc} |
| 268 | */ |
| 269 | @Override |
Stanley Tng | 7f3b781 | 2019-03-14 16:18:29 -0700 | [diff] [blame] | 270 | public @BluetoothProfile.BtProfileState int getConnectionState( |
| 271 | @NonNull BluetoothDevice device) { |
Jakub Pawlowski | ea580fa | 2017-11-22 11:02:34 -0800 | [diff] [blame] | 272 | if (VDBG) log("getState(" + device + ")"); |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 273 | final IBluetoothHearingAid service = getService(); |
Jakub Pawlowski | ea580fa | 2017-11-22 11:02:34 -0800 | [diff] [blame] | 274 | try { |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 275 | if (service != null && isEnabled() |
Jakub Pawlowski | ea580fa | 2017-11-22 11:02:34 -0800 | [diff] [blame] | 276 | && isValidDevice(device)) { |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 277 | return service.getConnectionState(device); |
Jakub Pawlowski | ea580fa | 2017-11-22 11:02:34 -0800 | [diff] [blame] | 278 | } |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 279 | if (service == null) Log.w(TAG, "Proxy not attached to service"); |
Jakub Pawlowski | ea580fa | 2017-11-22 11:02:34 -0800 | [diff] [blame] | 280 | return BluetoothProfile.STATE_DISCONNECTED; |
| 281 | } catch (RemoteException e) { |
| 282 | Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable())); |
| 283 | return BluetoothProfile.STATE_DISCONNECTED; |
Jakub Pawlowski | ea580fa | 2017-11-22 11:02:34 -0800 | [diff] [blame] | 284 | } |
| 285 | } |
| 286 | |
| 287 | /** |
Hansong Zhang | 7ca303c | 2018-03-16 09:15:48 -0700 | [diff] [blame] | 288 | * Select a connected device as active. |
| 289 | * |
| 290 | * The active device selection is per profile. An active device's |
| 291 | * purpose is profile-specific. For example, Hearing Aid audio |
| 292 | * streaming is to the active Hearing Aid device. If a remote device |
| 293 | * is not connected, it cannot be selected as active. |
| 294 | * |
| 295 | * <p> This API returns false in scenarios like the profile on the |
| 296 | * device is not connected or Bluetooth is not turned on. |
| 297 | * When this API returns true, it is guaranteed that the |
| 298 | * {@link #ACTION_ACTIVE_DEVICE_CHANGED} intent will be broadcasted |
| 299 | * with the active device. |
| 300 | * |
| 301 | * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN} |
| 302 | * permission. |
| 303 | * |
| 304 | * @param device the remote Bluetooth device. Could be null to clear |
| 305 | * the active device and stop streaming audio to a Bluetooth device. |
| 306 | * @return false on immediate error, true otherwise |
| 307 | * @hide |
| 308 | */ |
Mathew Inwood | 3a75f26 | 2019-06-27 12:47:38 +0100 | [diff] [blame] | 309 | @UnsupportedAppUsage |
Hansong Zhang | 7ca303c | 2018-03-16 09:15:48 -0700 | [diff] [blame] | 310 | public boolean setActiveDevice(@Nullable BluetoothDevice device) { |
| 311 | if (DBG) log("setActiveDevice(" + device + ")"); |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 312 | final IBluetoothHearingAid service = getService(); |
Hansong Zhang | 7ca303c | 2018-03-16 09:15:48 -0700 | [diff] [blame] | 313 | try { |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 314 | if (service != null && isEnabled() |
Hansong Zhang | 7ca303c | 2018-03-16 09:15:48 -0700 | [diff] [blame] | 315 | && ((device == null) || isValidDevice(device))) { |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 316 | service.setActiveDevice(device); |
Hansong Zhang | 7ca303c | 2018-03-16 09:15:48 -0700 | [diff] [blame] | 317 | return true; |
| 318 | } |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 319 | if (service == null) Log.w(TAG, "Proxy not attached to service"); |
Hansong Zhang | 7ca303c | 2018-03-16 09:15:48 -0700 | [diff] [blame] | 320 | return false; |
| 321 | } catch (RemoteException e) { |
| 322 | Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable())); |
| 323 | return false; |
Hansong Zhang | 7ca303c | 2018-03-16 09:15:48 -0700 | [diff] [blame] | 324 | } |
| 325 | } |
| 326 | |
| 327 | /** |
Hansong Zhang | 8d799f8 | 2018-03-28 16:53:10 -0700 | [diff] [blame] | 328 | * Get the connected physical Hearing Aid devices that are active |
Hansong Zhang | 7ca303c | 2018-03-16 09:15:48 -0700 | [diff] [blame] | 329 | * |
| 330 | * <p>Requires {@link android.Manifest.permission#BLUETOOTH} |
| 331 | * permission. |
| 332 | * |
Hansong Zhang | 8d799f8 | 2018-03-28 16:53:10 -0700 | [diff] [blame] | 333 | * @return the list of active devices. The first element is the left active |
| 334 | * device; the second element is the right active device. If either or both side |
| 335 | * is not active, it will be null on that position. Returns empty list on error. |
Hansong Zhang | 7ca303c | 2018-03-16 09:15:48 -0700 | [diff] [blame] | 336 | * @hide |
| 337 | */ |
Mathew Inwood | 3a75f26 | 2019-06-27 12:47:38 +0100 | [diff] [blame] | 338 | @UnsupportedAppUsage |
Hansong Zhang | 7ca303c | 2018-03-16 09:15:48 -0700 | [diff] [blame] | 339 | @RequiresPermission(Manifest.permission.BLUETOOTH) |
Hansong Zhang | 8d799f8 | 2018-03-28 16:53:10 -0700 | [diff] [blame] | 340 | public List<BluetoothDevice> getActiveDevices() { |
| 341 | if (VDBG) log("getActiveDevices()"); |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 342 | final IBluetoothHearingAid service = getService(); |
Hansong Zhang | 7ca303c | 2018-03-16 09:15:48 -0700 | [diff] [blame] | 343 | try { |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 344 | if (service != null && isEnabled()) { |
| 345 | return service.getActiveDevices(); |
Hansong Zhang | 7ca303c | 2018-03-16 09:15:48 -0700 | [diff] [blame] | 346 | } |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 347 | if (service == null) Log.w(TAG, "Proxy not attached to service"); |
Hansong Zhang | 8d799f8 | 2018-03-28 16:53:10 -0700 | [diff] [blame] | 348 | return new ArrayList<>(); |
Hansong Zhang | 7ca303c | 2018-03-16 09:15:48 -0700 | [diff] [blame] | 349 | } catch (RemoteException e) { |
| 350 | Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable())); |
Hansong Zhang | 8d799f8 | 2018-03-28 16:53:10 -0700 | [diff] [blame] | 351 | return new ArrayList<>(); |
Hansong Zhang | 7ca303c | 2018-03-16 09:15:48 -0700 | [diff] [blame] | 352 | } |
| 353 | } |
| 354 | |
| 355 | /** |
Jakub Pawlowski | ea580fa | 2017-11-22 11:02:34 -0800 | [diff] [blame] | 356 | * Set priority of the profile |
| 357 | * |
| 358 | * <p> The device should already be paired. |
Rahul Sabnis | df1ef4a | 2019-11-27 18:09:33 -0800 | [diff] [blame] | 359 | * Priority can be one of {@link #PRIORITY_ON} or {@link #PRIORITY_OFF}, |
Jakub Pawlowski | ea580fa | 2017-11-22 11:02:34 -0800 | [diff] [blame] | 360 | * |
| 361 | * @param device Paired bluetooth device |
| 362 | * @param priority |
| 363 | * @return true if priority is set, false on error |
| 364 | * @hide |
| 365 | */ |
Rahul Sabnis | df1ef4a | 2019-11-27 18:09:33 -0800 | [diff] [blame] | 366 | @RequiresPermission(Manifest.permission.BLUETOOTH_ADMIN) |
Jakub Pawlowski | ea580fa | 2017-11-22 11:02:34 -0800 | [diff] [blame] | 367 | public boolean setPriority(BluetoothDevice device, int priority) { |
| 368 | if (DBG) log("setPriority(" + device + ", " + priority + ")"); |
Rahul Sabnis | df1ef4a | 2019-11-27 18:09:33 -0800 | [diff] [blame] | 369 | return setConnectionPolicy(device, BluetoothAdapter.priorityToConnectionPolicy(priority)); |
| 370 | } |
| 371 | |
| 372 | /** |
| 373 | * Set connection policy of the profile |
| 374 | * |
| 375 | * <p> The device should already be paired. |
| 376 | * Connection policy can be one of {@link #CONNECTION_POLICY_ALLOWED}, |
| 377 | * {@link #CONNECTION_POLICY_FORBIDDEN}, {@link #CONNECTION_POLICY_UNKNOWN} |
| 378 | * |
| 379 | * @param device Paired bluetooth device |
| 380 | * @param connectionPolicy is the connection policy to set to for this profile |
| 381 | * @return true if connectionPolicy is set, false on error |
| 382 | * @hide |
| 383 | */ |
| 384 | @SystemApi |
| 385 | @RequiresPermission(Manifest.permission.BLUETOOTH_ADMIN) |
| 386 | public boolean setConnectionPolicy(@NonNull BluetoothDevice device, |
| 387 | @ConnectionPolicy int connectionPolicy) { |
| 388 | if (DBG) log("setConnectionPolicy(" + device + ", " + connectionPolicy + ")"); |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 389 | final IBluetoothHearingAid service = getService(); |
Jakub Pawlowski | ea580fa | 2017-11-22 11:02:34 -0800 | [diff] [blame] | 390 | try { |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 391 | if (service != null && isEnabled() |
Jakub Pawlowski | ea580fa | 2017-11-22 11:02:34 -0800 | [diff] [blame] | 392 | && isValidDevice(device)) { |
Rahul Sabnis | df1ef4a | 2019-11-27 18:09:33 -0800 | [diff] [blame] | 393 | if (connectionPolicy != BluetoothProfile.CONNECTION_POLICY_FORBIDDEN |
| 394 | && connectionPolicy != BluetoothProfile.CONNECTION_POLICY_ALLOWED) { |
Jakub Pawlowski | ea580fa | 2017-11-22 11:02:34 -0800 | [diff] [blame] | 395 | return false; |
| 396 | } |
Rahul Sabnis | df1ef4a | 2019-11-27 18:09:33 -0800 | [diff] [blame] | 397 | return service.setConnectionPolicy(device, connectionPolicy); |
Jakub Pawlowski | ea580fa | 2017-11-22 11:02:34 -0800 | [diff] [blame] | 398 | } |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 399 | if (service == null) Log.w(TAG, "Proxy not attached to service"); |
Jakub Pawlowski | ea580fa | 2017-11-22 11:02:34 -0800 | [diff] [blame] | 400 | return false; |
| 401 | } catch (RemoteException e) { |
| 402 | Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable())); |
| 403 | return false; |
Jakub Pawlowski | ea580fa | 2017-11-22 11:02:34 -0800 | [diff] [blame] | 404 | } |
| 405 | } |
| 406 | |
| 407 | /** |
| 408 | * Get the priority of the profile. |
| 409 | * |
| 410 | * <p> The priority can be any of: |
Rahul Sabnis | df1ef4a | 2019-11-27 18:09:33 -0800 | [diff] [blame] | 411 | * {@link #PRIORITY_OFF}, {@link #PRIORITY_ON}, {@link #PRIORITY_UNDEFINED} |
Jakub Pawlowski | ea580fa | 2017-11-22 11:02:34 -0800 | [diff] [blame] | 412 | * |
| 413 | * @param device Bluetooth device |
| 414 | * @return priority of the device |
| 415 | * @hide |
| 416 | */ |
| 417 | @RequiresPermission(Manifest.permission.BLUETOOTH) |
| 418 | public int getPriority(BluetoothDevice device) { |
| 419 | if (VDBG) log("getPriority(" + device + ")"); |
Rahul Sabnis | df1ef4a | 2019-11-27 18:09:33 -0800 | [diff] [blame] | 420 | return BluetoothAdapter.connectionPolicyToPriority(getConnectionPolicy(device)); |
| 421 | } |
| 422 | |
| 423 | /** |
| 424 | * Get the connection policy of the profile. |
| 425 | * |
| 426 | * <p> The connection policy can be any of: |
| 427 | * {@link #CONNECTION_POLICY_ALLOWED}, {@link #CONNECTION_POLICY_FORBIDDEN}, |
| 428 | * {@link #CONNECTION_POLICY_UNKNOWN} |
| 429 | * |
| 430 | * @param device Bluetooth device |
| 431 | * @return connection policy of the device |
| 432 | * @hide |
| 433 | */ |
| 434 | @SystemApi |
| 435 | @RequiresPermission(Manifest.permission.BLUETOOTH) |
| 436 | public @ConnectionPolicy int getConnectionPolicy(@NonNull BluetoothDevice device) { |
| 437 | if (VDBG) log("getConnectionPolicy(" + device + ")"); |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 438 | final IBluetoothHearingAid service = getService(); |
Jakub Pawlowski | ea580fa | 2017-11-22 11:02:34 -0800 | [diff] [blame] | 439 | try { |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 440 | if (service != null && isEnabled() |
Jakub Pawlowski | ea580fa | 2017-11-22 11:02:34 -0800 | [diff] [blame] | 441 | && isValidDevice(device)) { |
Rahul Sabnis | df1ef4a | 2019-11-27 18:09:33 -0800 | [diff] [blame] | 442 | return service.getConnectionPolicy(device); |
Jakub Pawlowski | ea580fa | 2017-11-22 11:02:34 -0800 | [diff] [blame] | 443 | } |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 444 | if (service == null) Log.w(TAG, "Proxy not attached to service"); |
Rahul Sabnis | df1ef4a | 2019-11-27 18:09:33 -0800 | [diff] [blame] | 445 | return BluetoothProfile.CONNECTION_POLICY_FORBIDDEN; |
Jakub Pawlowski | ea580fa | 2017-11-22 11:02:34 -0800 | [diff] [blame] | 446 | } catch (RemoteException e) { |
| 447 | Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable())); |
Rahul Sabnis | df1ef4a | 2019-11-27 18:09:33 -0800 | [diff] [blame] | 448 | return BluetoothProfile.CONNECTION_POLICY_FORBIDDEN; |
Jakub Pawlowski | ea580fa | 2017-11-22 11:02:34 -0800 | [diff] [blame] | 449 | } |
| 450 | } |
| 451 | |
| 452 | /** |
| 453 | * Helper for converting a state to a string. |
| 454 | * |
| 455 | * For debug use only - strings are not internationalized. |
| 456 | * |
| 457 | * @hide |
| 458 | */ |
| 459 | public static String stateToString(int state) { |
| 460 | switch (state) { |
| 461 | case STATE_DISCONNECTED: |
| 462 | return "disconnected"; |
| 463 | case STATE_CONNECTING: |
| 464 | return "connecting"; |
| 465 | case STATE_CONNECTED: |
| 466 | return "connected"; |
| 467 | case STATE_DISCONNECTING: |
| 468 | return "disconnecting"; |
Jakub Pawlowski | ea580fa | 2017-11-22 11:02:34 -0800 | [diff] [blame] | 469 | default: |
| 470 | return "<unknown state " + state + ">"; |
| 471 | } |
| 472 | } |
| 473 | |
| 474 | /** |
| 475 | * Get the volume of the device. |
| 476 | * |
| 477 | * <p> The volume is between -128 dB (mute) to 0 dB. |
| 478 | * |
| 479 | * @return volume of the hearing aid device. |
| 480 | * @hide |
| 481 | */ |
| 482 | @RequiresPermission(Manifest.permission.BLUETOOTH) |
| 483 | public int getVolume() { |
| 484 | if (VDBG) { |
| 485 | log("getVolume()"); |
| 486 | } |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 487 | final IBluetoothHearingAid service = getService(); |
Jakub Pawlowski | ea580fa | 2017-11-22 11:02:34 -0800 | [diff] [blame] | 488 | try { |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 489 | if (service != null && isEnabled()) { |
| 490 | return service.getVolume(); |
Jakub Pawlowski | ea580fa | 2017-11-22 11:02:34 -0800 | [diff] [blame] | 491 | } |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 492 | if (service == null) Log.w(TAG, "Proxy not attached to service"); |
Jakub Pawlowski | ea580fa | 2017-11-22 11:02:34 -0800 | [diff] [blame] | 493 | return 0; |
| 494 | } catch (RemoteException e) { |
| 495 | Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable())); |
| 496 | return 0; |
Jakub Pawlowski | ea580fa | 2017-11-22 11:02:34 -0800 | [diff] [blame] | 497 | } |
| 498 | } |
| 499 | |
| 500 | /** |
| 501 | * Tells remote device to adjust volume. Uses the following values: |
| 502 | * <ul> |
| 503 | * <li>{@link AudioManager#ADJUST_LOWER}</li> |
| 504 | * <li>{@link AudioManager#ADJUST_RAISE}</li> |
| 505 | * <li>{@link AudioManager#ADJUST_MUTE}</li> |
| 506 | * <li>{@link AudioManager#ADJUST_UNMUTE}</li> |
| 507 | * </ul> |
| 508 | * |
| 509 | * @param direction One of the supported adjust values. |
| 510 | * @hide |
| 511 | */ |
| 512 | @RequiresPermission(Manifest.permission.BLUETOOTH) |
| 513 | public void adjustVolume(int direction) { |
| 514 | if (DBG) log("adjustVolume(" + direction + ")"); |
| 515 | |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 516 | final IBluetoothHearingAid service = getService(); |
Jakub Pawlowski | ea580fa | 2017-11-22 11:02:34 -0800 | [diff] [blame] | 517 | try { |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 518 | if (service == null) { |
Jakub Pawlowski | ea580fa | 2017-11-22 11:02:34 -0800 | [diff] [blame] | 519 | Log.w(TAG, "Proxy not attached to service"); |
| 520 | return; |
| 521 | } |
| 522 | |
| 523 | if (!isEnabled()) return; |
| 524 | |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 525 | service.adjustVolume(direction); |
Jakub Pawlowski | ea580fa | 2017-11-22 11:02:34 -0800 | [diff] [blame] | 526 | } catch (RemoteException e) { |
| 527 | Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable())); |
Jakub Pawlowski | ea580fa | 2017-11-22 11:02:34 -0800 | [diff] [blame] | 528 | } |
| 529 | } |
| 530 | |
| 531 | /** |
| 532 | * Tells remote device to set an absolute volume. |
| 533 | * |
| 534 | * @param volume Absolute volume to be set on remote |
| 535 | * @hide |
| 536 | */ |
| 537 | public void setVolume(int volume) { |
| 538 | if (DBG) Log.d(TAG, "setVolume(" + volume + ")"); |
| 539 | |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 540 | final IBluetoothHearingAid service = getService(); |
Jakub Pawlowski | ea580fa | 2017-11-22 11:02:34 -0800 | [diff] [blame] | 541 | try { |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 542 | if (service == null) { |
Jakub Pawlowski | ea580fa | 2017-11-22 11:02:34 -0800 | [diff] [blame] | 543 | Log.w(TAG, "Proxy not attached to service"); |
| 544 | return; |
| 545 | } |
| 546 | |
| 547 | if (!isEnabled()) return; |
| 548 | |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 549 | service.setVolume(volume); |
Jakub Pawlowski | ea580fa | 2017-11-22 11:02:34 -0800 | [diff] [blame] | 550 | } catch (RemoteException e) { |
| 551 | Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable())); |
Jakub Pawlowski | ea580fa | 2017-11-22 11:02:34 -0800 | [diff] [blame] | 552 | } |
| 553 | } |
| 554 | |
| 555 | /** |
| 556 | * Get the CustomerId of the device. |
| 557 | * |
| 558 | * @param device Bluetooth device |
| 559 | * @return the CustomerId of the device |
| 560 | * @hide |
| 561 | */ |
| 562 | @RequiresPermission(Manifest.permission.BLUETOOTH) |
| 563 | public long getHiSyncId(BluetoothDevice device) { |
| 564 | if (VDBG) { |
| 565 | log("getCustomerId(" + device + ")"); |
| 566 | } |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 567 | final IBluetoothHearingAid service = getService(); |
Jakub Pawlowski | ea580fa | 2017-11-22 11:02:34 -0800 | [diff] [blame] | 568 | try { |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 569 | if (service == null) { |
Jakub Pawlowski | ea580fa | 2017-11-22 11:02:34 -0800 | [diff] [blame] | 570 | Log.w(TAG, "Proxy not attached to service"); |
| 571 | return HI_SYNC_ID_INVALID; |
| 572 | } |
| 573 | |
| 574 | if (!isEnabled() || !isValidDevice(device)) return HI_SYNC_ID_INVALID; |
| 575 | |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 576 | return service.getHiSyncId(device); |
Jakub Pawlowski | ea580fa | 2017-11-22 11:02:34 -0800 | [diff] [blame] | 577 | } catch (RemoteException e) { |
| 578 | Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable())); |
| 579 | return HI_SYNC_ID_INVALID; |
Jakub Pawlowski | ea580fa | 2017-11-22 11:02:34 -0800 | [diff] [blame] | 580 | } |
| 581 | } |
| 582 | |
| 583 | /** |
| 584 | * Get the side of the device. |
| 585 | * |
| 586 | * @param device Bluetooth device. |
| 587 | * @return SIDE_LEFT or SIDE_RIGHT |
| 588 | * @hide |
| 589 | */ |
| 590 | @RequiresPermission(Manifest.permission.BLUETOOTH) |
| 591 | public int getDeviceSide(BluetoothDevice device) { |
| 592 | if (VDBG) { |
| 593 | log("getDeviceSide(" + device + ")"); |
| 594 | } |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 595 | final IBluetoothHearingAid service = getService(); |
Jakub Pawlowski | ea580fa | 2017-11-22 11:02:34 -0800 | [diff] [blame] | 596 | try { |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 597 | if (service != null && isEnabled() |
Jakub Pawlowski | ea580fa | 2017-11-22 11:02:34 -0800 | [diff] [blame] | 598 | && isValidDevice(device)) { |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 599 | return service.getDeviceSide(device); |
Jakub Pawlowski | ea580fa | 2017-11-22 11:02:34 -0800 | [diff] [blame] | 600 | } |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 601 | if (service == null) Log.w(TAG, "Proxy not attached to service"); |
Jakub Pawlowski | ea580fa | 2017-11-22 11:02:34 -0800 | [diff] [blame] | 602 | return SIDE_LEFT; |
| 603 | } catch (RemoteException e) { |
| 604 | Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable())); |
| 605 | return SIDE_LEFT; |
Jakub Pawlowski | ea580fa | 2017-11-22 11:02:34 -0800 | [diff] [blame] | 606 | } |
| 607 | } |
| 608 | |
| 609 | /** |
| 610 | * Get the mode of the device. |
| 611 | * |
| 612 | * @param device Bluetooth device |
| 613 | * @return MODE_MONAURAL or MODE_BINAURAL |
| 614 | * @hide |
| 615 | */ |
| 616 | @RequiresPermission(Manifest.permission.BLUETOOTH) |
| 617 | public int getDeviceMode(BluetoothDevice device) { |
| 618 | if (VDBG) { |
| 619 | log("getDeviceMode(" + device + ")"); |
| 620 | } |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 621 | final IBluetoothHearingAid service = getService(); |
Jakub Pawlowski | ea580fa | 2017-11-22 11:02:34 -0800 | [diff] [blame] | 622 | try { |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 623 | if (service != null && isEnabled() |
Jakub Pawlowski | ea580fa | 2017-11-22 11:02:34 -0800 | [diff] [blame] | 624 | && isValidDevice(device)) { |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 625 | return service.getDeviceMode(device); |
Jakub Pawlowski | ea580fa | 2017-11-22 11:02:34 -0800 | [diff] [blame] | 626 | } |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 627 | if (service == null) Log.w(TAG, "Proxy not attached to service"); |
Jakub Pawlowski | ea580fa | 2017-11-22 11:02:34 -0800 | [diff] [blame] | 628 | return MODE_MONAURAL; |
| 629 | } catch (RemoteException e) { |
| 630 | Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable())); |
| 631 | return MODE_MONAURAL; |
Jakub Pawlowski | ea580fa | 2017-11-22 11:02:34 -0800 | [diff] [blame] | 632 | } |
| 633 | } |
| 634 | |
Jakub Pawlowski | ea580fa | 2017-11-22 11:02:34 -0800 | [diff] [blame] | 635 | private boolean isEnabled() { |
| 636 | if (mAdapter.getState() == BluetoothAdapter.STATE_ON) return true; |
| 637 | return false; |
| 638 | } |
| 639 | |
| 640 | private boolean isValidDevice(BluetoothDevice device) { |
| 641 | if (device == null) return false; |
| 642 | |
| 643 | if (BluetoothAdapter.checkBluetoothAddress(device.getAddress())) return true; |
| 644 | return false; |
| 645 | } |
| 646 | |
| 647 | private static void log(String msg) { |
| 648 | Log.d(TAG, msg); |
| 649 | } |
| 650 | } |