diff options
Diffstat (limited to 'core/java/android')
-rw-r--r-- | core/java/android/bluetooth/BluetoothDevice.java | 48 | ||||
-rw-r--r-- | core/java/android/bluetooth/IBluetooth.aidl | 2 | ||||
-rw-r--r-- | core/java/android/server/BluetoothEventLoop.java | 2 | ||||
-rwxr-xr-x | core/java/android/server/BluetoothService.java | 37 |
4 files changed, 88 insertions, 1 deletions
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. + * <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 + */ + 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. + * <p>Alias is the locally modified name of a remote device. + * <p>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. * <p>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); diff --git a/core/java/android/server/BluetoothEventLoop.java b/core/java/android/server/BluetoothEventLoop.java index 107a2a9..5273910 100644 --- a/core/java/android/server/BluetoothEventLoop.java +++ b/core/java/android/server/BluetoothEventLoop.java @@ -418,6 +418,8 @@ class BluetoothEventLoop { intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device); intent.putExtra(BluetoothDevice.EXTRA_NAME, propValues[1]); mContext.sendBroadcast(intent, BLUETOOTH_PERM); + } else if (name.equals("Alias")) { + mBluetoothService.setRemoteDeviceProperty(address, name, propValues[1]); } else if (name.equals("Class")) { mBluetoothService.setRemoteDeviceProperty(address, name, propValues[1]); Intent intent = new Intent(BluetoothDevice.ACTION_CLASS_CHANGED); diff --git a/core/java/android/server/BluetoothService.java b/core/java/android/server/BluetoothService.java index 34f1971..3a563e6 100755 --- a/core/java/android/server/BluetoothService.java +++ b/core/java/android/server/BluetoothService.java @@ -843,7 +843,6 @@ public class BluetoothService extends IBluetooth.Stub { return uuids; } - /** * Returns the user-friendly name of a remote device. This value is * returned from our local cache, which is updated when onPropertyChange @@ -864,6 +863,40 @@ public class BluetoothService extends IBluetooth.Stub { } /** + * Returns alias of a remote device. This value is returned from our + * local cache, which is updated when onPropertyChange event is received. + * + * @param address Bluetooth address of remote device. + * + * @return The alias of the specified remote device. + */ + public synchronized String getRemoteAlias(String address) { + + mContext.enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission"); + if (!BluetoothAdapter.checkBluetoothAddress(address)) { + return null; + } + return mDeviceProperties.getProperty(address, "Alias"); + } + + /** + * Set the alias of a remote device. + * + * @param address Bluetooth address of remote device. + * @param alias new alias to change to + * @return true on success, false on error + */ + public synchronized boolean setRemoteAlias(String address, String alias) { + mContext.enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission"); + if (!BluetoothAdapter.checkBluetoothAddress(address)) { + return false; + } + + return setDevicePropertyStringNative(getObjectPathFromAddress(address), + "Alias", alias); + } + + /** * Get the discoverability window for the device. A timeout of zero * means that the device is permanently discoverable (if the device is * in the discoverable mode). @@ -2553,6 +2586,8 @@ public class BluetoothService extends IBluetooth.Stub { private native boolean setDevicePropertyBooleanNative(String objectPath, String key, int value); + private native boolean setDevicePropertyStringNative(String objectPath, String key, + String value); private native boolean createDeviceNative(String address); /*package*/ native boolean discoverServicesNative(String objectPath, String pattern); |