Loading packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothEventManager.java +0 −1 Original line number Diff line number Diff line Loading @@ -286,7 +286,6 @@ public class BluetoothEventManager { } cachedDevice.setRssi(rssi); cachedDevice.setBtClass(btClass); cachedDevice.setNewName(name); cachedDevice.setJustDiscovered(true); } } Loading packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java +14 −33 Original line number Diff line number Diff line Loading @@ -51,8 +51,6 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice> private final BluetoothAdapter mLocalAdapter; private final LocalBluetoothProfileManager mProfileManager; private final BluetoothDevice mDevice; //TODO: consider remove, BluetoothDevice.getName() is already cached private String mName; private long mHiSyncId; // Need this since there is no method for getting RSSI private short mRssi; Loading Loading @@ -299,7 +297,7 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice> } return; } Log.i(TAG, "Failed to connect " + profile.toString() + " to " + mName); Log.i(TAG, "Failed to connect " + profile.toString() + " to " + getName()); } private boolean ensurePaired() { Loading Loading @@ -376,7 +374,6 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice> // TODO: do any of these need to run async on a background thread? private void fillData() { fetchName(); fetchBtClass(); updateProfiles(); fetchActiveDevices(); Loading @@ -400,21 +397,15 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice> return mDevice.getAddress(); } public String getName() { return mName; } /** * Populate name from BluetoothDevice.ACTION_FOUND intent * Get name from remote device * @return {@link BluetoothDevice#getAliasName()} if * {@link BluetoothDevice#getAliasName()} is not null otherwise return * {@link BluetoothDevice#getAddress()} */ void setNewName(String name) { if (mName == null) { mName = name; if (mName == null || TextUtils.isEmpty(mName)) { mName = mDevice.getAddress(); } dispatchAttributesChanged(); } public String getName() { final String aliasName = mDevice.getAliasName(); return TextUtils.isEmpty(aliasName) ? getAddress() : aliasName; } /** Loading @@ -422,9 +413,8 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice> * @param name new alias name to be set, should never be null */ public void setName(String name) { // Prevent mName to be set to null if setName(null) is called if (name != null && !TextUtils.equals(name, mName)) { mName = name; // Prevent getName() to be set to null if setName(null) is called if (name != null && !TextUtils.equals(name, getName())) { mDevice.setAlias(name); dispatchAttributesChanged(); } Loading Loading @@ -461,19 +451,10 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice> } void refreshName() { fetchName(); dispatchAttributesChanged(); } private void fetchName() { mName = mDevice.getAliasName(); if (TextUtils.isEmpty(mName)) { mName = mDevice.getAddress(); if (BluetoothUtils.D) { Log.d(TAG, "Device has no name (yet), use address: " + mName); } Log.d(TAG, "Device name: " + getName()); } dispatchAttributesChanged(); } /** Loading Loading @@ -805,7 +786,7 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice> if (comparison != 0) return comparison; // Fallback on name return mName.compareTo(another.mName); return getName().compareTo(another.getName()); } public interface Callback { Loading packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/CachedBluetoothDeviceTest.java +31 −0 Original line number Diff line number Diff line Loading @@ -606,4 +606,35 @@ public class CachedBluetoothDeviceTest { assertThat(mCachedDevice.isConnectedHearingAidDevice()).isFalse(); } @Test public void getName_aliasNameNotNull_returnAliasName() { when(mDevice.getAliasName()).thenReturn(DEVICE_NAME); assertThat(mCachedDevice.getName()).isEqualTo(DEVICE_NAME); } @Test public void getName_aliasNameIsNull_returnAddress() { when(mDevice.getAliasName()).thenReturn(null); assertThat(mCachedDevice.getName()).isEqualTo(DEVICE_ADDRESS); } @Test public void setName_setDeviceNameIsNotNull() { final String name = "test name"; when(mDevice.getAliasName()).thenReturn(DEVICE_NAME); mCachedDevice.setName(name); verify(mDevice).setAlias(name); } @Test public void setName_setDeviceNameIsNull() { mCachedDevice.setName(null); verify(mDevice, never()).setAlias(any()); } } Loading
packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothEventManager.java +0 −1 Original line number Diff line number Diff line Loading @@ -286,7 +286,6 @@ public class BluetoothEventManager { } cachedDevice.setRssi(rssi); cachedDevice.setBtClass(btClass); cachedDevice.setNewName(name); cachedDevice.setJustDiscovered(true); } } Loading
packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java +14 −33 Original line number Diff line number Diff line Loading @@ -51,8 +51,6 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice> private final BluetoothAdapter mLocalAdapter; private final LocalBluetoothProfileManager mProfileManager; private final BluetoothDevice mDevice; //TODO: consider remove, BluetoothDevice.getName() is already cached private String mName; private long mHiSyncId; // Need this since there is no method for getting RSSI private short mRssi; Loading Loading @@ -299,7 +297,7 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice> } return; } Log.i(TAG, "Failed to connect " + profile.toString() + " to " + mName); Log.i(TAG, "Failed to connect " + profile.toString() + " to " + getName()); } private boolean ensurePaired() { Loading Loading @@ -376,7 +374,6 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice> // TODO: do any of these need to run async on a background thread? private void fillData() { fetchName(); fetchBtClass(); updateProfiles(); fetchActiveDevices(); Loading @@ -400,21 +397,15 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice> return mDevice.getAddress(); } public String getName() { return mName; } /** * Populate name from BluetoothDevice.ACTION_FOUND intent * Get name from remote device * @return {@link BluetoothDevice#getAliasName()} if * {@link BluetoothDevice#getAliasName()} is not null otherwise return * {@link BluetoothDevice#getAddress()} */ void setNewName(String name) { if (mName == null) { mName = name; if (mName == null || TextUtils.isEmpty(mName)) { mName = mDevice.getAddress(); } dispatchAttributesChanged(); } public String getName() { final String aliasName = mDevice.getAliasName(); return TextUtils.isEmpty(aliasName) ? getAddress() : aliasName; } /** Loading @@ -422,9 +413,8 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice> * @param name new alias name to be set, should never be null */ public void setName(String name) { // Prevent mName to be set to null if setName(null) is called if (name != null && !TextUtils.equals(name, mName)) { mName = name; // Prevent getName() to be set to null if setName(null) is called if (name != null && !TextUtils.equals(name, getName())) { mDevice.setAlias(name); dispatchAttributesChanged(); } Loading Loading @@ -461,19 +451,10 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice> } void refreshName() { fetchName(); dispatchAttributesChanged(); } private void fetchName() { mName = mDevice.getAliasName(); if (TextUtils.isEmpty(mName)) { mName = mDevice.getAddress(); if (BluetoothUtils.D) { Log.d(TAG, "Device has no name (yet), use address: " + mName); } Log.d(TAG, "Device name: " + getName()); } dispatchAttributesChanged(); } /** Loading Loading @@ -805,7 +786,7 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice> if (comparison != 0) return comparison; // Fallback on name return mName.compareTo(another.mName); return getName().compareTo(another.getName()); } public interface Callback { Loading
packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/CachedBluetoothDeviceTest.java +31 −0 Original line number Diff line number Diff line Loading @@ -606,4 +606,35 @@ public class CachedBluetoothDeviceTest { assertThat(mCachedDevice.isConnectedHearingAidDevice()).isFalse(); } @Test public void getName_aliasNameNotNull_returnAliasName() { when(mDevice.getAliasName()).thenReturn(DEVICE_NAME); assertThat(mCachedDevice.getName()).isEqualTo(DEVICE_NAME); } @Test public void getName_aliasNameIsNull_returnAddress() { when(mDevice.getAliasName()).thenReturn(null); assertThat(mCachedDevice.getName()).isEqualTo(DEVICE_ADDRESS); } @Test public void setName_setDeviceNameIsNotNull() { final String name = "test name"; when(mDevice.getAliasName()).thenReturn(DEVICE_NAME); mCachedDevice.setName(name); verify(mDevice).setAlias(name); } @Test public void setName_setDeviceNameIsNull() { mCachedDevice.setName(null); verify(mDevice, never()).setAlias(any()); } }