OSDN Git Service

Do not overwrite alias with device name
authorMatthew Xie <mattx@google.com>
Thu, 18 Sep 2014 05:43:49 +0000 (22:43 -0700)
committerMatthew Xie <mattx@google.com>
Thu, 18 Sep 2014 22:54:22 +0000 (22:54 +0000)
Bug: 17287682
Change-Id: Iea29e85125ae4720fd99f893f516c301b7aed7c6

src/com/android/settings/bluetooth/BluetoothEventManager.java
src/com/android/settings/bluetooth/CachedBluetoothDevice.java

index 0eead85..bf7606e 100755 (executable)
@@ -206,7 +206,7 @@ final class BluetoothEventManager {
             }
             cachedDevice.setRssi(rssi);
             cachedDevice.setBtClass(btClass);
-            cachedDevice.setName(name);
+            cachedDevice.setNewName(name);
             cachedDevice.setVisible(true);
         }
     }
index 3b64ade..c19f754 100755 (executable)
@@ -387,19 +387,30 @@ final class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice> {
         return mName;
     }
 
-    void setName(String name) {
-        if (!mName.equals(name)) {
-            if (TextUtils.isEmpty(name)) {
-                // TODO: use friendly name for unknown device (bug 1181856)
+    /**
+     * Populate name from BluetoothDevice.ACTION_FOUND intent
+     */
+    void setNewName(String name) {
+        if (mName == null) {
+            mName = name;
+            if (mName == null || TextUtils.isEmpty(mName)) {
                 mName = mDevice.getAddress();
-            } else {
-                mName = name;
-                mDevice.setAlias(name);
             }
             dispatchAttributesChanged();
         }
     }
 
+    /**
+     * user changes the device name
+     */
+    void setName(String name) {
+        if (!mName.equals(name)) {
+            mName = name;
+            mDevice.setAlias(name);
+            dispatchAttributesChanged();
+        }
+    }
+
     void refreshName() {
         fetchName();
         dispatchAttributesChanged();