[Bluetooth] Avoid crash from emtpy devcie name.

Bug: 288233931
Test: atest passed
Change-Id: I85be66e6b985edcf1b02c55cc33236f9347846cf
This commit is contained in:
tom hsu
2023-06-29 22:37:37 +08:00
parent a56a9d9a56
commit a1e2436061
2 changed files with 8 additions and 1 deletions

View File

@@ -583,7 +583,7 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
*/
public void setName(String name) {
// Prevent getName() to be set to null if setName(null) is called
if (name == null || TextUtils.equals(name, getName())) {
if (TextUtils.isEmpty(name) || TextUtils.equals(name, getName())) {
return;
}
mDevice.setAlias(name);

View File

@@ -1014,6 +1014,13 @@ public class CachedBluetoothDeviceTest {
verify(mDevice, never()).setAlias(any());
}
@Test
public void setName_setDeviceNameIsEmpty() {
mCachedDevice.setName("");
verify(mDevice, never()).setAlias(any());
}
@Test
public void getProfileConnectionState_nullProfile_returnDisconnected() {
assertThat(mCachedDevice.getProfileConnectionState(null)).isEqualTo(