summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Xie <mattx@google.com>2011-07-28 17:46:45 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2011-07-28 17:46:45 -0700
commit6903a7de88e32e04965f41f1cf6371d855cdfa88 (patch)
tree060a2c949c9ab70c5fffc7dbe8e0ce55e3ad07f7
parent318fecea61f65e74b52116f8d1196b33646d477a (diff)
parent269e81a563cfe080d7f241d0d46411d3c946c111 (diff)
downloadframeworks_base-6903a7de88e32e04965f41f1cf6371d855cdfa88.zip
frameworks_base-6903a7de88e32e04965f41f1cf6371d855cdfa88.tar.gz
frameworks_base-6903a7de88e32e04965f41f1cf6371d855cdfa88.tar.bz2
Merge "Provide an API to set the friendly name of a remote device."
-rw-r--r--core/java/android/bluetooth/BluetoothDevice.java48
-rw-r--r--core/java/android/bluetooth/IBluetooth.aidl2
-rw-r--r--core/java/android/server/BluetoothEventLoop.java2
-rwxr-xr-xcore/java/android/server/BluetoothService.java37
-rw-r--r--core/jni/android_server_BluetoothService.cpp14
5 files changed, 102 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 be43c51..ddede9c 100644
--- a/core/java/android/bluetooth/IBluetooth.aidl
+++ b/core/java/android/bluetooth/IBluetooth.aidl
@@ -66,6 +66,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 2cab05c..9b9196a 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 9e66957..0d95a58 100755
--- a/core/java/android/server/BluetoothService.java
+++ b/core/java/android/server/BluetoothService.java
@@ -851,7 +851,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
@@ -872,6 +871,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).
@@ -2626,6 +2659,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);
diff --git a/core/jni/android_server_BluetoothService.cpp b/core/jni/android_server_BluetoothService.cpp
index 86e7cc0..41056fd 100644
--- a/core/jni/android_server_BluetoothService.cpp
+++ b/core/jni/android_server_BluetoothService.cpp
@@ -895,6 +895,18 @@ static jboolean setDevicePropertyBooleanNative(JNIEnv *env, jobject object,
#endif
}
+static jboolean setDevicePropertyStringNative(JNIEnv *env, jobject object,
+ jstring path, jstring key, jstring value) {
+#ifdef HAVE_BLUETOOTH
+ const char *c_value = env->GetStringUTFChars(value, NULL);
+ jboolean ret = setDevicePropertyNative(env, object, path, key,
+ (void *)&c_value, DBUS_TYPE_STRING);
+ env->ReleaseStringUTFChars(value, (char *)c_value);
+ return ret;
+#else
+ return JNI_FALSE;
+#endif
+}
static jboolean createDeviceNative(JNIEnv *env, jobject object,
jstring address) {
@@ -1718,6 +1730,8 @@ static JNINativeMethod sMethods[] = {
(void *)cancelPairingUserInputNative},
{"setDevicePropertyBooleanNative", "(Ljava/lang/String;Ljava/lang/String;I)Z",
(void *)setDevicePropertyBooleanNative},
+ {"setDevicePropertyStringNative", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Z",
+ (void *)setDevicePropertyStringNative},
{"createDeviceNative", "(Ljava/lang/String;)Z", (void *)createDeviceNative},
{"discoverServicesNative", "(Ljava/lang/String;Ljava/lang/String;)Z", (void *)discoverServicesNative},
{"addRfcommServiceRecordNative", "(Ljava/lang/String;JJS)I", (void *)addRfcommServiceRecordNative},