diff options
| author | Rahul Sabnis <rahulsabnis@google.com> | 2019-11-15 15:40:17 -0800 |
|---|---|---|
| committer | android-build-merger <android-build-merger@google.com> | 2019-11-15 15:40:17 -0800 |
| commit | 90a45d63bcdf5dadffe0b2846442974b6582dabb (patch) | |
| tree | 8517b1ad62983a2e02314d153d7c80e1cfe76ce4 /core/java | |
| parent | 179ed7d640799c1d1716552d48fbe37634b4f2bb (diff) | |
| parent | 67bef6ab929ae449c15d725c240b68b74b8fcbcc (diff) | |
Merge "Refactor methods to access/modify BluetoothDevice alias and name"
am: 67bef6ab92
Change-Id: Id0a50d482a7ff33df5fcd990a3ce5273956fcc5c
Diffstat (limited to 'core/java')
| -rw-r--r-- | core/java/android/bluetooth/BluetoothDevice.java | 41 | ||||
| -rw-r--r-- | core/java/android/companion/BluetoothDeviceFilterUtils.java | 2 |
2 files changed, 14 insertions, 29 deletions
diff --git a/core/java/android/bluetooth/BluetoothDevice.java b/core/java/android/bluetooth/BluetoothDevice.java index c6160446c798..0be3eca8239e 100644 --- a/core/java/android/bluetooth/BluetoothDevice.java +++ b/core/java/android/bluetooth/BluetoothDevice.java @@ -173,13 +173,10 @@ public final class BluetoothDevice implements Parcelable { * changed. * <p>Always contains the extra field {@link #EXTRA_DEVICE}. * <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive. - * - * @hide */ @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) - @UnsupportedAppUsage public static final String ACTION_ALIAS_CHANGED = - "android.bluetooth.device.action.ALIAS_CHANGED"; + "android.bluetooth.action.ALIAS_CHANGED"; /** * Broadcast Action: Indicates a change in the bond state of a remote @@ -1048,10 +1045,11 @@ public final class BluetoothDevice implements Parcelable { * Get the Bluetooth alias of the remote device. * <p>Alias is the locally modified name of a remote device. * - * @return the Bluetooth alias, or null if no alias or there was a problem - * @hide + * @return the Bluetooth alias, the friendly device name if no alias, or + * null if there was a problem */ - @UnsupportedAppUsage(publicAlternatives = "Use {@link #getName()} instead.") + @Nullable + @RequiresPermission(Manifest.permission.BLUETOOTH) public String getAlias() { final IBluetooth service = sService; if (service == null) { @@ -1059,7 +1057,11 @@ public final class BluetoothDevice implements Parcelable { return null; } try { - return service.getRemoteAlias(this); + String alias = service.getRemoteAlias(this); + if (alias == null) { + return getName(); + } + return alias; } catch (RemoteException e) { Log.e(TAG, "", e); } @@ -1076,8 +1078,9 @@ public final class BluetoothDevice implements Parcelable { * @return true on success, false on error * @hide */ - @UnsupportedAppUsage - public boolean setAlias(String alias) { + @SystemApi + @RequiresPermission(Manifest.permission.BLUETOOTH) + public boolean setAlias(@NonNull String alias) { final IBluetooth service = sService; if (service == null) { Log.e(TAG, "BT not enabled. Cannot set Remote Device name"); @@ -1092,24 +1095,6 @@ public final class BluetoothDevice implements Parcelable { } /** - * Get the Bluetooth alias of the remote device. - * If Alias is null, get the Bluetooth name instead. - * - * @return the Bluetooth alias, or null if no alias or there was a problem - * @hide - * @see #getAlias() - * @see #getName() - */ - @UnsupportedAppUsage(publicAlternatives = "Use {@link #getName()} instead.") - public String getAliasName() { - String name = getAlias(); - if (name == null) { - name = getName(); - } - return name; - } - - /** * Get the most recent identified battery level of this Bluetooth device * <p>Requires {@link android.Manifest.permission#BLUETOOTH} * diff --git a/core/java/android/companion/BluetoothDeviceFilterUtils.java b/core/java/android/companion/BluetoothDeviceFilterUtils.java index 75e726bfad0d..0f67f6b50251 100644 --- a/core/java/android/companion/BluetoothDeviceFilterUtils.java +++ b/core/java/android/companion/BluetoothDeviceFilterUtils.java @@ -129,7 +129,7 @@ public class BluetoothDeviceFilterUtils { @UnsupportedAppUsage public static String getDeviceDisplayNameInternal(@NonNull BluetoothDevice device) { - return firstNotEmpty(device.getAliasName(), device.getAddress()); + return firstNotEmpty(device.getAlias(), device.getAddress()); } @UnsupportedAppUsage |
