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

Commit 7495c0c2 authored by jasonwshsu's avatar jasonwshsu Committed by Jason Hsu
Browse files

Connected devices page did not show correct summary when member device connect

Root Cause: CsipDeviceManager only refreshes UI when switching member device content.

Solution:
* CsipDeviceManager needs to call refresh() on main device when it's new
  member device added.
* UI widget Settings/BluetoothDevice also need to monitor it's member device status to refresh UI.

Bug: 344947362
Test: atest CsipDeviceManagerTest
Flag: EXEMPT bugfix
Change-Id: Iecfe7c4dd16f61d52a14c3afae47275897817324
parent 9f94e49d
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();
    }
}