Bluetooth: Add flag for human readable name

* Add hasHumanReadableName() method to CachedBluetoothDevice that
  returns True when BluetoothDevice.getAliasName() is not null nor empty

Bug: 34685932
Test: pair Bluetooth device, send file over Bluetooth, unit tests
Change-Id: I197f3f7f3bcb7d785729473b25638006449ae862
diff --git a/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java b/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java
index 734f70d..109446d 100644
--- a/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java
+++ b/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java
@@ -50,8 +50,11 @@
     private final LocalBluetoothAdapter mLocalAdapter;
     private final LocalBluetoothProfileManager mProfileManager;
     private final BluetoothDevice mDevice;
+    //TODO: consider remove, BluetoothDevice.getName() is already cached
     private String mName;
+    // Need this since there is no method for getting RSSI
     private short mRssi;
+    //TODO: consider remove, BluetoothDevice.getBluetoothClass() is already cached
     private BluetoothClass mBtClass;
     private HashMap<LocalBluetoothProfile, Integer> mProfileConnectionState;
 
@@ -394,10 +397,12 @@
     }
 
     /**
-     * user changes the device name
+     * User changes the device name
+     * @param name new alias name to be set, should never be null
      */
     public void setName(String name) {
-        if (!mName.equals(name)) {
+        // Prevent mName to be set to null if setName(null) is called
+        if (name != null && !TextUtils.equals(name, mName)) {
             mName = name;
             mDevice.setAlias(name);
             dispatchAttributesChanged();
@@ -419,6 +424,14 @@
     }
 
     /**
+     * Checks if device has a human readable name besides MAC address
+     * @return true if device's alias name is not null nor empty, false otherwise
+     */
+    public boolean hasHumanReadableName() {
+        return !TextUtils.isEmpty(mDevice.getAliasName());
+    }
+
+    /**
      * Get battery level from remote device
      * @return battery level in percentage [0-100], or {@link BluetoothDevice#BATTERY_LEVEL_UNKNOWN}
      */
@@ -495,7 +508,7 @@
         ParcelUuid[] localUuids = mLocalAdapter.getUuids();
         if (localUuids == null) return false;
 
-        /**
+        /*
          * Now we know if the device supports PBAP, update permissions...
          */
         processPhonebookAccess();