Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ad78c25b authored by Jason Hsu's avatar Jason Hsu Committed by Android (Google) Code Review
Browse files

Merge "Connected devices page did not show correct summary when member device connect" into main

parents 16b407b9 7495c0c2
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -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);
@@ -373,6 +373,7 @@ public class CsipDeviceManager {
                preferredMainDevice.addMemberDevice(deviceItem);
                mCachedDevices.remove(deviceItem);
                mBtManager.getEventManager().dispatchDeviceRemoved(deviceItem);
                preferredMainDevice.refresh();
                hasChanged = true;
            }
        }
+32 −0
Original line number Diff line number Diff line
@@ -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;
@@ -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();
    }
}