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

Commit 713efe93 authored by Angela Wang's avatar Angela Wang
Browse files

Show ambient volume contrl only for hearing devices

Flag: EXEMPT bugfix
Bug: 388156028
Test: atest BluetoothDetailsAmbientVolumePreferenceControllerTest
Change-Id: Ia38fd90f798dec9a46366ca15e358b42f7d7fe70
parent fd4c6d10
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -129,7 +129,7 @@ public class BluetoothDetailsAmbientVolumePreferenceController extends Bluetooth

    @Override
    public boolean isAvailable() {
        return mCachedDevice.getProfiles().stream().anyMatch(
        return mCachedDevice.isHearingDevice() && mCachedDevice.getProfiles().stream().anyMatch(
                profile -> profile instanceof VolumeControlProfile);
    }

+27 −15
Original line number Diff line number Diff line
@@ -21,15 +21,11 @@ import static com.android.settings.bluetooth.BluetoothDetailsHearingDeviceContro

import static com.google.common.truth.Truth.assertThat;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import android.os.Handler;

import androidx.preference.PreferenceCategory;

import com.android.settings.testutils.shadow.ShadowThreadUtils;
@@ -70,8 +66,6 @@ public class BluetoothDetailsAmbientVolumePreferenceControllerTest extends
    @Mock
    private VolumeControlProfile mVolumeControlProfile;
    @Mock
    private Handler mTestHandler;
    @Mock
    private AmbientVolumeUiController mUiController;

    private BluetoothDetailsAmbientVolumePreferenceController mController;
@@ -91,13 +85,6 @@ public class BluetoothDetailsAmbientVolumePreferenceControllerTest extends
        PreferenceCategory deviceControls = new PreferenceCategory(mContext);
        deviceControls.setKey(KEY_HEARING_DEVICE_GROUP);
        mScreen.addPreference(deviceControls);

        when(mContext.getMainThreadHandler()).thenReturn(mTestHandler);
        when(mTestHandler.postDelayed(any(Runnable.class), anyLong())).thenAnswer(
                invocationOnMock -> {
                    invocationOnMock.getArgument(0, Runnable.class).run();
                    return null;
                });
    }

    @Test
@@ -109,7 +96,31 @@ public class BluetoothDetailsAmbientVolumePreferenceControllerTest extends
    }

    @Test
    public void refresh_deviceNotSupportVcp_verifyUiControllerNoRefresh() {
    public void isAvailable_notHearingDevice_returnFalse() {
        when(mCachedDevice.isHearingDevice()).thenReturn(false);

        assertThat(mController.isAvailable()).isFalse();
    }

    @Test
    public void isAvailable_isHearingDeviceAndNotSupportVcp_returnFalse() {
        when(mCachedDevice.isHearingDevice()).thenReturn(true);
        when(mCachedDevice.getProfiles()).thenReturn(List.of());

        assertThat(mController.isAvailable()).isFalse();
    }

    @Test
    public void isAvailable_isHearingDeviceAndSupportVcp_returnTrue() {
        when(mCachedDevice.isHearingDevice()).thenReturn(true);
        when(mCachedDevice.getProfiles()).thenReturn(List.of(mVolumeControlProfile));

        assertThat(mController.isAvailable()).isTrue();
    }

    @Test
    public void refresh_isHearingDeviceAndNotSupportVcp_verifyUiControllerNoRefresh() {
        when(mCachedDevice.isHearingDevice()).thenReturn(true);
        when(mCachedDevice.getProfiles()).thenReturn(List.of());

        mController.refresh();
@@ -118,7 +129,8 @@ public class BluetoothDetailsAmbientVolumePreferenceControllerTest extends
    }

    @Test
    public void refresh_deviceSupportVcp_verifyUiControllerRefresh() {
    public void refresh_isHearingDeviceAndSupportVcp_verifyUiControllerRefresh() {
        when(mCachedDevice.isHearingDevice()).thenReturn(true);
        when(mCachedDevice.getProfiles()).thenReturn(List.of(mVolumeControlProfile));

        mController.refresh();