diff options
| author | Rahul Sabnis <rahulsabnis@google.com> | 2021-05-19 16:00:04 +0000 |
|---|---|---|
| committer | Android (Google) Code Review <android-gerrit@google.com> | 2021-05-19 16:00:04 +0000 |
| commit | b8cfbebbeca8f51b88097071007cfe2a72fe07b5 (patch) | |
| tree | 7f0aa5582c67480aadc25ea70457429f513daa7c /core/java/android/bluetooth/BluetoothDevice.java | |
| parent | ee438f960ad8b47d60bfaaaaa2157ba2e362e083 (diff) | |
| parent | d6b43bb5202c59fba5856f81abb2b9d551a9efc3 (diff) | |
Merge "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." into sc-dev
Diffstat (limited to 'core/java/android/bluetooth/BluetoothDevice.java')
| -rw-r--r-- | core/java/android/bluetooth/BluetoothDevice.java | 38 |
1 files changed, 25 insertions, 13 deletions
diff --git a/core/java/android/bluetooth/BluetoothDevice.java b/core/java/android/bluetooth/BluetoothDevice.java index 52d4c7116a61..f2496fe0cac2 100644 --- a/core/java/android/bluetooth/BluetoothDevice.java +++ b/core/java/android/bluetooth/BluetoothDevice.java @@ -1351,6 +1351,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 @@ -1358,34 +1369,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; } /** |
