From 269e81a563cfe080d7f241d0d46411d3c946c111 Mon Sep 17 00:00:00 2001 From: Matthew Xie Date: Tue, 26 Jul 2011 18:36:49 -0700 Subject: Provide an API to set the friendly name of a remote device. BluetoothDevice setName overwrite the locally cached remote name. The changed name is saved in the local storage so that the change is preserved over power cycle. bug 5081605 Change-Id: I486966033828d153bfb1076a99e274c8a7f41636 --- core/java/android/bluetooth/BluetoothDevice.java | 48 ++++++++++++++++++++++++ core/java/android/bluetooth/IBluetooth.aidl | 2 + 2 files changed, 50 insertions(+) (limited to 'core/java/android/bluetooth') diff --git a/core/java/android/bluetooth/BluetoothDevice.java b/core/java/android/bluetooth/BluetoothDevice.java index d9525a3..4cb8220 100644 --- a/core/java/android/bluetooth/BluetoothDevice.java +++ b/core/java/android/bluetooth/BluetoothDevice.java @@ -566,6 +566,54 @@ public final class BluetoothDevice implements Parcelable { } /** + * Get the Bluetooth alias of the remote device. + *

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 + */ + public String getAlias() { + try { + return sService.getRemoteAlias(mAddress); + } catch (RemoteException e) {Log.e(TAG, "", e);} + return null; + } + + /** + * Set the Bluetooth alias of the remote device. + *

Alias is the locally modified name of a remote device. + *

This methoid overwrites the alias. The changed + * alias is saved in the local storage so that the change + * is preserved over power cycle. + * + * @return true on success, false on error + * @hide + */ + public boolean setAlias(String alias) { + try { + return sService.setRemoteAlias(mAddress, alias); + } catch (RemoteException e) {Log.e(TAG, "", e);} + return false; + } + + /** + * Get the Bluetooth alias of the remote device. + * If Alias is null, get the Bluetooth name instead. + * @see #getAlias() + * @see #getName() + * + * @return the Bluetooth alias, or null if no alias or there was a problem + * @hide + */ + public String getAliasName() { + String name = getAlias(); + if (name == null) { + name = getName(); + } + return name; + } + + /** * Start the bonding (pairing) process with the remote device. *

This is an asynchronous call, it will return immediately. Register * for {@link #ACTION_BOND_STATE_CHANGED} intents to be notified when diff --git a/core/java/android/bluetooth/IBluetooth.aidl b/core/java/android/bluetooth/IBluetooth.aidl index 183772d..da66b1a 100644 --- a/core/java/android/bluetooth/IBluetooth.aidl +++ b/core/java/android/bluetooth/IBluetooth.aidl @@ -62,6 +62,8 @@ interface IBluetooth boolean setDeviceOutOfBandData(in String address, in byte[] hash, in byte[] randomizer); String getRemoteName(in String address); + String getRemoteAlias(in String address); + boolean setRemoteAlias(in String address, in String name); int getRemoteClass(in String address); ParcelUuid[] getRemoteUuids(in String address); boolean fetchRemoteUuids(in String address, in ParcelUuid uuid, in IBluetoothCallback callback); -- cgit v1.1