Loading packages/SettingsLib/src/com/android/settingslib/bluetooth/CsipDeviceManager.java +2 −1 Original line number Diff line number Diff line Loading @@ -178,7 +178,7 @@ public class CsipDeviceManager { } log("updateRelationshipOfGroupDevices: mCachedDevices list =" + mCachedDevices.toString()); // Get the preferred main device by getPreferredMainDeviceWithoutConectionState // Get the preferred main device by getPreferredMainDeviceWithoutConnectionState List<CachedBluetoothDevice> groupDevicesList = getGroupDevicesFromAllOfDevicesList(groupId); CachedBluetoothDevice preferredMainDevice = getPreferredMainDevice(groupId, groupDevicesList); Loading Loading @@ -373,6 +373,7 @@ public class CsipDeviceManager { preferredMainDevice.addMemberDevice(deviceItem); mCachedDevices.remove(deviceItem); mBtManager.getEventManager().dispatchDeviceRemoved(deviceItem); preferredMainDevice.refresh(); hasChanged = true; } } Loading packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/CsipDeviceManagerTest.java +32 −0 Original line number Diff line number Diff line Loading @@ -19,7 +19,9 @@ package com.android.settingslib.bluetooth; import static com.google.common.truth.Truth.assertThat; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.Mockito.atLeastOnce; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import android.bluetooth.BluetoothClass; Loading Loading @@ -352,4 +354,34 @@ public class CsipDeviceManagerTest { assertThat(mCachedDevice1.getMemberDevice()).contains(mCachedDevice3); assertThat(mCachedDevice1.getDevice()).isEqualTo(expectedMainBluetoothDevice); } @Test public void onProfileConnectionStateChangedIfProcessed_addMemberDevice_refreshUI() { mCachedDevice3.setGroupId(GROUP1); mCsipDeviceManager.onProfileConnectionStateChangedIfProcessed(mCachedDevice3, BluetoothProfile.STATE_CONNECTED); verify(mCachedDevice1).refresh(); } @Test public void onProfileConnectionStateChangedIfProcessed_switchMainDevice_refreshUI() { when(mDevice3.isConnected()).thenReturn(true); when(mDevice2.isConnected()).thenReturn(false); when(mDevice1.isConnected()).thenReturn(false); mCachedDevice3.setGroupId(GROUP1); mCsipDeviceManager.onProfileConnectionStateChangedIfProcessed(mCachedDevice3, BluetoothProfile.STATE_CONNECTED); when(mDevice3.isConnected()).thenReturn(false); mCsipDeviceManager.onProfileConnectionStateChangedIfProcessed(mCachedDevice3, BluetoothProfile.STATE_DISCONNECTED); when(mDevice1.isConnected()).thenReturn(true); mCsipDeviceManager.onProfileConnectionStateChangedIfProcessed(mCachedDevice1, BluetoothProfile.STATE_CONNECTED); verify(mCachedDevice3).switchMemberDeviceContent(mCachedDevice1); verify(mCachedDevice3, atLeastOnce()).refresh(); } } Loading
packages/SettingsLib/src/com/android/settingslib/bluetooth/CsipDeviceManager.java +2 −1 Original line number Diff line number Diff line Loading @@ -178,7 +178,7 @@ public class CsipDeviceManager { } log("updateRelationshipOfGroupDevices: mCachedDevices list =" + mCachedDevices.toString()); // Get the preferred main device by getPreferredMainDeviceWithoutConectionState // Get the preferred main device by getPreferredMainDeviceWithoutConnectionState List<CachedBluetoothDevice> groupDevicesList = getGroupDevicesFromAllOfDevicesList(groupId); CachedBluetoothDevice preferredMainDevice = getPreferredMainDevice(groupId, groupDevicesList); Loading Loading @@ -373,6 +373,7 @@ public class CsipDeviceManager { preferredMainDevice.addMemberDevice(deviceItem); mCachedDevices.remove(deviceItem); mBtManager.getEventManager().dispatchDeviceRemoved(deviceItem); preferredMainDevice.refresh(); hasChanged = true; } } Loading
packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/CsipDeviceManagerTest.java +32 −0 Original line number Diff line number Diff line Loading @@ -19,7 +19,9 @@ package com.android.settingslib.bluetooth; import static com.google.common.truth.Truth.assertThat; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.Mockito.atLeastOnce; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import android.bluetooth.BluetoothClass; Loading Loading @@ -352,4 +354,34 @@ public class CsipDeviceManagerTest { assertThat(mCachedDevice1.getMemberDevice()).contains(mCachedDevice3); assertThat(mCachedDevice1.getDevice()).isEqualTo(expectedMainBluetoothDevice); } @Test public void onProfileConnectionStateChangedIfProcessed_addMemberDevice_refreshUI() { mCachedDevice3.setGroupId(GROUP1); mCsipDeviceManager.onProfileConnectionStateChangedIfProcessed(mCachedDevice3, BluetoothProfile.STATE_CONNECTED); verify(mCachedDevice1).refresh(); } @Test public void onProfileConnectionStateChangedIfProcessed_switchMainDevice_refreshUI() { when(mDevice3.isConnected()).thenReturn(true); when(mDevice2.isConnected()).thenReturn(false); when(mDevice1.isConnected()).thenReturn(false); mCachedDevice3.setGroupId(GROUP1); mCsipDeviceManager.onProfileConnectionStateChangedIfProcessed(mCachedDevice3, BluetoothProfile.STATE_CONNECTED); when(mDevice3.isConnected()).thenReturn(false); mCsipDeviceManager.onProfileConnectionStateChangedIfProcessed(mCachedDevice3, BluetoothProfile.STATE_DISCONNECTED); when(mDevice1.isConnected()).thenReturn(true); mCsipDeviceManager.onProfileConnectionStateChangedIfProcessed(mCachedDevice1, BluetoothProfile.STATE_CONNECTED); verify(mCachedDevice3).switchMemberDeviceContent(mCachedDevice1); verify(mCachedDevice3, atLeastOnce()).refresh(); } }