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

Commit c95056d7 authored by timhypeng's avatar timhypeng Committed by Hugh Chen
Browse files

Make HearingAid code more generic

-handle UI updating when sub device connection state changes
-add test case

Bug: 112735753
Test: make -j42 RunSettingsRoboTests
Change-Id: Ie2643657c47a0956aac3f8cac4bfdbdea0399ce8
parent 2f5200ea
Loading
Loading
Loading
Loading
+4 −6
Original line number Diff line number Diff line
@@ -65,12 +65,10 @@ public class BluetoothDetailsHeaderController extends BluetoothDetailsController
                .getBtClassDrawableWithDescription(mContext, mCachedDevice,
                mContext.getResources().getFraction(R.fraction.bt_battery_scale_fraction, 1, 1));
        String summaryText = mCachedDevice.getConnectionSummary();
        // If both the hearing aids are connected, two battery status should be shown.
        final String pairDeviceSummary = mDeviceManager
            .getHearingAidPairDeviceSummary(mCachedDevice);
        if (pairDeviceSummary != null) {
            mHeaderController.setSecondSummary(pairDeviceSummary);
        }
        // If both the hearing aids are connected, two device status should be shown.
        // If Second Summary is unavailable, to set it to null.
        mHeaderController.setSecondSummary(
                mDeviceManager.getSubDeviceSummary(mCachedDevice));
        mHeaderController.setLabel(mCachedDevice.getName());
        mHeaderController.setIcon(pair.first);
        mHeaderController.setIconContentDescription(pair.second);
+2 −0
Original line number Diff line number Diff line
@@ -51,6 +51,8 @@ public class BluetoothDetailsMacAddressController extends BluetoothDetailsContro

    @Override
    protected void refresh() {
        mFooterPreference.setTitle(mContext.getString(
                R.string.bluetooth_device_mac_address, mCachedDevice.getAddress()));
    }

    @Override
+10 −0
Original line number Diff line number Diff line
@@ -230,9 +230,19 @@ public abstract class BluetoothDeviceUpdater implements BluetoothCallback,
     */
    protected void removePreference(CachedBluetoothDevice cachedDevice) {
        final BluetoothDevice device = cachedDevice.getDevice();
        final CachedBluetoothDevice subCachedDevice = cachedDevice.getSubDevice();
        if (mPreferenceMap.containsKey(device)) {
            mDevicePreferenceCallback.onDeviceRemoved(mPreferenceMap.get(device));
            mPreferenceMap.remove(device);
        } else if (subCachedDevice != null) {
            // When doing remove, to check if preference maps to sub device.
            // This would happen when connection state is changed in detail page that there is no
            // callback from SettingsLib.
            final BluetoothDevice subDevice = subCachedDevice.getDevice();
            if (mPreferenceMap.containsKey(subDevice)) {
                mDevicePreferenceCallback.onDeviceRemoved(mPreferenceMap.get(subDevice));
                mPreferenceMap.remove(subDevice);
            }
        }
    }

+1 −1
Original line number Diff line number Diff line
@@ -72,7 +72,7 @@ public class BluetoothDetailsHeaderControllerTest extends BluetoothDetailsContro
        FakeFeatureFactory.setupForTest();
        ShadowEntityHeaderController.setUseMock(mHeaderController);
        when(mBluetoothManager.getCachedDeviceManager()).thenReturn(mCachedDeviceManager);
        when(mCachedDeviceManager.getHearingAidPairDeviceSummary(mCachedDevice)).thenReturn("abc");
        when(mCachedDeviceManager.getSubDeviceSummary(mCachedDevice)).thenReturn("abc");
        mController =
            new BluetoothDetailsHeaderController(mContext, mFragment, mCachedDevice, mLifecycle,
                mBluetoothManager);
+19 −0
Original line number Diff line number Diff line
@@ -63,8 +63,12 @@ public class BluetoothDeviceUpdaterTest {
    @Mock
    private CachedBluetoothDevice mCachedBluetoothDevice;
    @Mock
    private CachedBluetoothDevice mSubCachedBluetoothDevice;
    @Mock
    private BluetoothDevice mBluetoothDevice;
    @Mock
    private BluetoothDevice mSubBluetoothDevice;
    @Mock
    private SettingsActivity mSettingsActivity;
    @Mock
    private LocalBluetoothManager mLocalManager;
@@ -86,6 +90,7 @@ public class BluetoothDeviceUpdaterTest {
        mCachedDevices.add(mCachedBluetoothDevice);
        doReturn(mContext).when(mDashboardFragment).getContext();
        when(mCachedBluetoothDevice.getDevice()).thenReturn(mBluetoothDevice);
        when(mSubCachedBluetoothDevice.getDevice()).thenReturn(mSubBluetoothDevice);
        when(mLocalManager.getCachedDeviceManager()).thenReturn(mCachedDeviceManager);
        when(mCachedDeviceManager.getCachedDevicesCopy()).thenReturn(mCachedDevices);

@@ -146,6 +151,20 @@ public class BluetoothDeviceUpdaterTest {
        verify(mDevicePreferenceCallback, never()).onDeviceRemoved(any(Preference.class));
    }

    @Test
    public void testRemovePreference_subDeviceExist_removePreference() {
        when(mCachedBluetoothDevice.getSubDevice()).thenReturn(mSubCachedBluetoothDevice);
        mBluetoothDeviceUpdater.mPreferenceMap.put(mSubBluetoothDevice, mPreference);

        assertThat(mBluetoothDeviceUpdater.mPreferenceMap.
                containsKey(mSubBluetoothDevice)).isTrue();
        mBluetoothDeviceUpdater.removePreference(mCachedBluetoothDevice);

        verify(mDevicePreferenceCallback).onDeviceRemoved(mPreference);
        assertThat(mBluetoothDeviceUpdater.mPreferenceMap.
                containsKey(mSubBluetoothDevice)).isFalse();
    }

    @Test
    public void testDeviceProfilesListener_click_startBluetoothDeviceDetailPage() {
        doReturn(mSettingsActivity).when(mDashboardFragment).getContext();