diff options
author | Rahul Sabnis <rahulsabnis@google.com> | 2021-05-05 14:04:04 -0700 |
---|---|---|
committer | Rahul Sabnis <rahulsabnis@google.com> | 2021-05-17 16:47:55 -0700 |
commit | 4c2ce6e1885c73085bd2eece5cdc53e141348258 (patch) | |
tree | 378b3905c25a69f7559fc1171285f3d050fb97f6 /framework/java/android/bluetooth/BluetoothDevice.java | |
parent | cfb0ad04a3ad8c15e37ab7cdb58e014c41b3eed6 (diff) |
Update BluetoothDevice#setAlias based on API council feedback: now
accepts null input and returns an int (with error codes).
Update CompanionDeviceManager#canPairWithoutPrompt to take a
UserHandle instead of an int. Adds BluetoothStatusCodes class for all
new Bluetooth error / success codes. Moved OOB and hci disconnect
constants to the new BluetoothStatusCodes class.
Tag: #feature
Bug: 184714087
Test: atest BluetoothDeviceTest#test_setAlias_getAlias
Change-Id: Ife03506f2cf68800f5824cb5fa94fec8aa34a39c
Diffstat (limited to 'framework/java/android/bluetooth/BluetoothDevice.java')
-rw-r--r-- | framework/java/android/bluetooth/BluetoothDevice.java | 38 |
1 files changed, 25 insertions, 13 deletions
diff --git a/framework/java/android/bluetooth/BluetoothDevice.java b/framework/java/android/bluetooth/BluetoothDevice.java index 0ca6d74c67..15b058a28a 100644 --- a/framework/java/android/bluetooth/BluetoothDevice.java +++ b/framework/java/android/bluetooth/BluetoothDevice.java @@ -1346,6 +1346,17 @@ public final class BluetoothDevice implements Parcelable { return null; } + /** @hide */ + @Retention(RetentionPolicy.SOURCE) + @IntDef(value = { + BluetoothStatusCodes.SUCCESS, + BluetoothStatusCodes.ERROR_BLUETOOTH_NOT_ENABLED, + BluetoothStatusCodes.ERROR_BLUETOOTH_NOT_ALLOWED, + BluetoothStatusCodes.ERROR_MISSING_BLUETOOTH_CONNECT_PERMISSION, + BluetoothStatusCodes.ERROR_DEVICE_NOT_BONDED + }) + public @interface SetAliasReturnValues{} + /** * Sets the locally modifiable name (alias) of the remote Bluetooth device. This method * overwrites the previously stored alias. The new alias is saved in local @@ -1353,34 +1364,35 @@ public final class BluetoothDevice implements Parcelable { * * <p>This method requires the calling app to be associated with Companion Device Manager (see * {@link android.companion.CompanionDeviceManager#associate(AssociationRequest, - * android.companion.CompanionDeviceManager.Callback, Handler)}) and have the {@link - * android.Manifest.permission#BLUETOOTH} permission. Alternatively, if the caller has the - * {@link android.Manifest.permission#BLUETOOTH_PRIVILEGED} permission, they can bypass the - * Companion Device Manager association requirement. + * android.companion.CompanionDeviceManager.Callback, Handler)}) and have the + * {@link android.Manifest.permission#BLUETOOTH_CONNECT} permission. Alternatively, if the + * caller has the {@link android.Manifest.permission#BLUETOOTH_PRIVILEGED} permission, they can + * bypass the Companion Device Manager association requirement as well as other permission + * requirements. * - * @param alias is the new locally modifiable name for the remote Bluetooth device which must be - * non-null and not the empty string. - * @return {@code true} if the alias is successfully set, {@code false} on error - * @throws IllegalArgumentException if the alias is {@code null} or the empty string + * @param alias is the new locally modifiable name for the remote Bluetooth device which must + * be the empty string. If null, we clear the alias. + * @return whether the alias was successfully changed + * @throws IllegalArgumentException if the alias is the empty string */ @RequiresLegacyBluetoothPermission @RequiresBluetoothConnectPermission @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) - public boolean setAlias(@NonNull String alias) { - if (alias == null || alias.isEmpty()) { - throw new IllegalArgumentException("Cannot set the alias to null or the empty string"); + public @SetAliasReturnValues int setAlias(@Nullable String alias) { + if (alias != null && alias.isEmpty()) { + throw new IllegalArgumentException("alias cannot be the empty string"); } final IBluetooth service = sService; if (service == null) { Log.e(TAG, "BT not enabled. Cannot set Remote Device name"); - return false; + return BluetoothStatusCodes.ERROR_BLUETOOTH_NOT_ENABLED; } try { return service.setRemoteAlias(this, alias, mAttributionSource); } catch (RemoteException e) { Log.e(TAG, "", e); + throw e.rethrowFromSystemServer(); } - return false; } /** |