diff options
author | Hansong Zhang <hsz@google.com> | 2018-03-16 09:15:48 -0700 |
---|---|---|
committer | Hansong Zhang <hsz@google.com> | 2018-03-23 12:27:33 -0700 |
commit | e98595e5217cf5ed2576be51ba2c97ddc3078cc3 (patch) | |
tree | ab68cf79d846acccc5d3d0ab86b7f7fafb28fbeb /framework/java/android/bluetooth/BluetoothHearingAid.java | |
parent | fabf2009ae85dc98f735135f83405321d5bb90c2 (diff) |
Hearing Aid Profile: set and get activeDevice
Add setActiveDevice() for Hearing Aid Profile in SettingsLib
Bug: 69623109
Test: robolectric test and manual test
Change-Id: I70eafe030747053876e2ab8a125d5dd01c5e0eb9
Merged-In: I70eafe030747053876e2ab8a125d5dd01c5e0eb9
(cherry picked from commit befadbc4a5450e3140293c37ecd5533581659687)
Diffstat (limited to 'framework/java/android/bluetooth/BluetoothHearingAid.java')
-rw-r--r-- | framework/java/android/bluetooth/BluetoothHearingAid.java | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/framework/java/android/bluetooth/BluetoothHearingAid.java b/framework/java/android/bluetooth/BluetoothHearingAid.java index 647e0d033f..8f8083ed73 100644 --- a/framework/java/android/bluetooth/BluetoothHearingAid.java +++ b/framework/java/android/bluetooth/BluetoothHearingAid.java @@ -17,6 +17,7 @@ package android.bluetooth; import android.Manifest; +import android.annotation.Nullable; import android.annotation.RequiresPermission; import android.annotation.SdkConstant; import android.annotation.SdkConstant.SdkConstantType; @@ -379,6 +380,76 @@ public final class BluetoothHearingAid implements BluetoothProfile { } /** + * Select a connected device as active. + * + * The active device selection is per profile. An active device's + * purpose is profile-specific. For example, Hearing Aid audio + * streaming is to the active Hearing Aid device. If a remote device + * is not connected, it cannot be selected as active. + * + * <p> This API returns false in scenarios like the profile on the + * device is not connected or Bluetooth is not turned on. + * When this API returns true, it is guaranteed that the + * {@link #ACTION_ACTIVE_DEVICE_CHANGED} intent will be broadcasted + * with the active device. + * + * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN} + * permission. + * + * @param device the remote Bluetooth device. Could be null to clear + * the active device and stop streaming audio to a Bluetooth device. + * @return false on immediate error, true otherwise + * @hide + */ + public boolean setActiveDevice(@Nullable BluetoothDevice device) { + if (DBG) log("setActiveDevice(" + device + ")"); + try { + mServiceLock.readLock().lock(); + if (mService != null && isEnabled() + && ((device == null) || isValidDevice(device))) { + mService.setActiveDevice(device); + return true; + } + if (mService == null) Log.w(TAG, "Proxy not attached to service"); + return false; + } catch (RemoteException e) { + Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable())); + return false; + } finally { + mServiceLock.readLock().unlock(); + } + } + + /** + * Check whether the device is active. + * + * <p>Requires {@link android.Manifest.permission#BLUETOOTH} + * permission. + * + * @return the connected device that is active or null if no device + * is active + * @hide + */ + @RequiresPermission(Manifest.permission.BLUETOOTH) + public boolean isActiveDevice(@Nullable BluetoothDevice device) { + if (VDBG) log("isActiveDevice()"); + try { + mServiceLock.readLock().lock(); + if (mService != null && isEnabled() + && ((device == null) || isValidDevice(device))) { + return mService.isActiveDevice(device); + } + if (mService == null) Log.w(TAG, "Proxy not attached to service"); + return false; + } catch (RemoteException e) { + Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable())); + return false; + } finally { + mServiceLock.readLock().unlock(); + } + } + + /** * Set priority of the profile * * <p> The device should already be paired. |