Do not overwrite alias with device name

Bug: 17287682
Change-Id: Iea29e85125ae4720fd99f893f516c301b7aed7c6
diff --git a/src/com/android/settings/bluetooth/BluetoothEventManager.java b/src/com/android/settings/bluetooth/BluetoothEventManager.java
index 0eead85..bf7606e 100755
--- a/src/com/android/settings/bluetooth/BluetoothEventManager.java
+++ b/src/com/android/settings/bluetooth/BluetoothEventManager.java
@@ -206,7 +206,7 @@
             }
             cachedDevice.setRssi(rssi);
             cachedDevice.setBtClass(btClass);
-            cachedDevice.setName(name);
+            cachedDevice.setNewName(name);
             cachedDevice.setVisible(true);
         }
     }
diff --git a/src/com/android/settings/bluetooth/CachedBluetoothDevice.java b/src/com/android/settings/bluetooth/CachedBluetoothDevice.java
index 3b64ade..c19f754 100755
--- a/src/com/android/settings/bluetooth/CachedBluetoothDevice.java
+++ b/src/com/android/settings/bluetooth/CachedBluetoothDevice.java
@@ -387,15 +387,26 @@
         return mName;
     }
 
+    /**
+     * 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();
+            }
+            dispatchAttributesChanged();
+        }
+    }
+
+    /**
+     * user changes the device name
+     */
     void setName(String name) {
         if (!mName.equals(name)) {
-            if (TextUtils.isEmpty(name)) {
-                // TODO: use friendly name for unknown device (bug 1181856)
-                mName = mDevice.getAddress();
-            } else {
-                mName = name;
-                mDevice.setAlias(name);
-            }
+            mName = name;
+            mDevice.setAlias(name);
             dispatchAttributesChanged();
         }
     }