diff options
| author | 2020-02-01 23:27:10 +0000 | |
|---|---|---|
| committer | 2020-02-01 23:27:10 +0000 | |
| commit | f0f3a0f48ea816cb7d79bd36a402aeeb799b5dcd (patch) | |
| tree | 6ee7288a909e646a7e237a00f01c98edeac22fea | |
| parent | ea711aba95b5e873cffcc5991af910f9c15a07e9 (diff) | |
| parent | e6f17155daf20714da0503ede9fea2b307ecc214 (diff) | |
Merge "Add new API BluetoothAdapter#removeActiveDevice to replace calls to BluetoothAdapter#setActiveDevice with a null device"
| -rwxr-xr-x | api/system-current.txt | 3 | ||||
| -rw-r--r-- | core/java/android/bluetooth/BluetoothAdapter.java | 55 |
2 files changed, 53 insertions, 5 deletions
diff --git a/api/system-current.txt b/api/system-current.txt index b60d321e61e8..d95ee3008411 100755 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -1302,8 +1302,9 @@ package android.bluetooth { method @RequiresPermission(android.Manifest.permission.BLUETOOTH) public long getDiscoveryEndMillis(); method public boolean isBleScanAlwaysAvailable(); method public boolean isLeEnabled(); + method @RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED) public boolean removeActiveDevice(int); method @RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED) public boolean removeOnMetadataChangedListener(@NonNull android.bluetooth.BluetoothDevice, @NonNull android.bluetooth.BluetoothAdapter.OnMetadataChangedListener); - method @RequiresPermission(android.Manifest.permission.BLUETOOTH_ADMIN) public boolean setActiveDevice(@Nullable android.bluetooth.BluetoothDevice, int); + method @RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED) public boolean setActiveDevice(@NonNull android.bluetooth.BluetoothDevice, int); method @RequiresPermission(android.Manifest.permission.BLUETOOTH) public boolean setScanMode(int, int); method @RequiresPermission(android.Manifest.permission.BLUETOOTH) public boolean setScanMode(int); field public static final String ACTION_BLE_STATE_CHANGED = "android.bluetooth.adapter.action.BLE_STATE_CHANGED"; diff --git a/core/java/android/bluetooth/BluetoothAdapter.java b/core/java/android/bluetooth/BluetoothAdapter.java index b6d096c2524a..3bc83dbcd04e 100644 --- a/core/java/android/bluetooth/BluetoothAdapter.java +++ b/core/java/android/bluetooth/BluetoothAdapter.java @@ -1766,6 +1766,45 @@ public final class BluetoothAdapter { } /** + * Removes the active device for the grouping of @ActiveDeviceUse specified + * + * @param profiles represents the purpose for which we are setting this as the active device. + * Possible values are: + * {@link BluetoothAdapter#ACTIVE_DEVICE_AUDIO}, + * {@link BluetoothAdapter#ACTIVE_DEVICE_PHONE_CALL}, + * {@link BluetoothAdapter#ACTIVE_DEVICE_ALL} + * @return false on immediate error, true otherwise + * @throws IllegalArgumentException if device is null or profiles is not one of + * {@link ActiveDeviceUse} + * @hide + */ + @SystemApi + @RequiresPermission(Manifest.permission.BLUETOOTH_PRIVILEGED) + public boolean removeActiveDevice(@ActiveDeviceUse int profiles) { + if (profiles != ACTIVE_DEVICE_AUDIO && profiles != ACTIVE_DEVICE_PHONE_CALL + && profiles != ACTIVE_DEVICE_ALL) { + Log.e(TAG, "Invalid profiles param value in removeActiveDevice"); + throw new IllegalArgumentException("Profiles must be one of " + + "BluetoothAdapter.ACTIVE_DEVICE_AUDIO, " + + "BluetoothAdapter.ACTIVE_DEVICE_PHONE_CALL, or " + + "BluetoothAdapter.ACTIVE_DEVICE_ALL"); + } + try { + mServiceLock.readLock().lock(); + if (mService != null) { + return mService.removeActiveDevice(profiles); + } + } catch (RemoteException e) { + Log.e(TAG, "", e); + } finally { + mServiceLock.readLock().unlock(); + } + + return false; + } + + /** + * Sets device as the active devices for the profiles passed into the function * * @param device is the remote bluetooth device * @param profiles represents the purpose for which we are setting this as the active device. @@ -1774,18 +1813,26 @@ public final class BluetoothAdapter { * {@link BluetoothAdapter#ACTIVE_DEVICE_PHONE_CALL}, * {@link BluetoothAdapter#ACTIVE_DEVICE_ALL} * @return false on immediate error, true otherwise + * @throws IllegalArgumentException if device is null or profiles is not one of + * {@link ActiveDeviceUse} * @hide */ @SystemApi - @RequiresPermission(Manifest.permission.BLUETOOTH_ADMIN) - public boolean setActiveDevice(@Nullable BluetoothDevice device, + @RequiresPermission(Manifest.permission.BLUETOOTH_PRIVILEGED) + public boolean setActiveDevice(@NonNull BluetoothDevice device, @ActiveDeviceUse int profiles) { + if (device == null) { + Log.e(TAG, "setActiveDevice: Null device passed as parameter"); + throw new IllegalArgumentException("device cannot be null"); + } if (profiles != ACTIVE_DEVICE_AUDIO && profiles != ACTIVE_DEVICE_PHONE_CALL && profiles != ACTIVE_DEVICE_ALL) { Log.e(TAG, "Invalid profiles param value in setActiveDevice"); - return false; + throw new IllegalArgumentException("Profiles must be one of " + + "BluetoothAdapter.ACTIVE_DEVICE_AUDIO, " + + "BluetoothAdapter.ACTIVE_DEVICE_PHONE_CALL, or " + + "BluetoothAdapter.ACTIVE_DEVICE_ALL"); } - try { mServiceLock.readLock().lock(); if (mService != null) { |