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

Commit 64795ff0 authored by shaoweishen's avatar shaoweishen Committed by Android Build Coastguard Worker
Browse files

[Output Swithcer] Fix volume control issue for Group

Bug: 241448326
Test: verified on device, atest MediaOutputAdapterTest
Change-Id: I5d2ab2e1a6cb8341871305a729d8584ca15c4dcc
(cherry picked from commit 9673316c)
(cherry picked from commit 2e1bb637)
Merged-In: I5d2ab2e1a6cb8341871305a729d8584ca15c4dcc
parent 0c607e70
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -269,6 +269,7 @@ public class MediaOutputAdapter extends MediaOutputBaseAdapter {
        }
        }


        private void onGroupActionTriggered(boolean isChecked, MediaDevice device) {
        private void onGroupActionTriggered(boolean isChecked, MediaDevice device) {
            disableSeekBar();
            if (isChecked && isDeviceIncluded(mController.getSelectableMediaDevice(), device)) {
            if (isChecked && isDeviceIncluded(mController.getSelectableMediaDevice(), device)) {
                mController.addDeviceToPlayMedia(device);
                mController.addDeviceToPlayMedia(device);
            } else if (!isChecked && isDeviceIncluded(mController.getDeselectableMediaDevice(),
            } else if (!isChecked && isDeviceIncluded(mController.getDeselectableMediaDevice(),
+8 −1
Original line number Original line Diff line number Diff line
@@ -273,6 +273,8 @@ public abstract class MediaOutputBaseAdapter extends
        void initSeekbar(MediaDevice device, boolean isCurrentSeekbarInvisible) {
        void initSeekbar(MediaDevice device, boolean isCurrentSeekbarInvisible) {
            if (!mController.isVolumeControlEnabled(device)) {
            if (!mController.isVolumeControlEnabled(device)) {
                disableSeekBar();
                disableSeekBar();
            } else {
                enableSeekBar();
            }
            }
            mSeekBar.setMaxVolume(device.getMaxVolume());
            mSeekBar.setMaxVolume(device.getMaxVolume());
            final int currentVolume = device.getCurrentVolume();
            final int currentVolume = device.getCurrentVolume();
@@ -417,11 +419,16 @@ public abstract class MediaOutputBaseAdapter extends
            return drawable;
            return drawable;
        }
        }


        private void disableSeekBar() {
        protected void disableSeekBar() {
            mSeekBar.setEnabled(false);
            mSeekBar.setEnabled(false);
            mSeekBar.setOnTouchListener((v, event) -> true);
            mSeekBar.setOnTouchListener((v, event) -> true);
        }
        }


        private void enableSeekBar() {
            mSeekBar.setEnabled(true);
            mSeekBar.setOnTouchListener((v, event) -> false);
        }

        protected void setUpDeviceIcon(MediaDevice device) {
        protected void setUpDeviceIcon(MediaDevice device) {
            ThreadUtils.postOnBackgroundThread(() -> {
            ThreadUtils.postOnBackgroundThread(() -> {
                Icon icon = mController.getDeviceIconCompat(device).toIcon(mContext);
                Icon icon = mController.getDeviceIconCompat(device).toIcon(mContext);
+8 −0
Original line number Original line Diff line number Diff line
@@ -194,6 +194,11 @@ public class MediaOutputMetricLogger {
    }
    }


    private int getLoggingDeviceType(MediaDevice device, boolean isSourceDevice) {
    private int getLoggingDeviceType(MediaDevice device, boolean isSourceDevice) {
        if (device == null) {
            return isSourceDevice
                    ? SysUiStatsLog.MEDIA_OUTPUT_OP_SWITCH_REPORTED__SOURCE__UNKNOWN_TYPE
                    : SysUiStatsLog.MEDIA_OUTPUT_OP_SWITCH_REPORTED__TARGET__UNKNOWN_TYPE;
        }
        switch (device.getDeviceType()) {
        switch (device.getDeviceType()) {
            case MediaDevice.MediaDeviceType.TYPE_PHONE_DEVICE:
            case MediaDevice.MediaDeviceType.TYPE_PHONE_DEVICE:
                return isSourceDevice
                return isSourceDevice
@@ -229,6 +234,9 @@ public class MediaOutputMetricLogger {
    }
    }


    private int getInteractionDeviceType(MediaDevice device) {
    private int getInteractionDeviceType(MediaDevice device) {
        if (device == null) {
            return SysUiStatsLog.MEDIA_OUTPUT_OP_INTERACTION_REPORTED__TARGET__UNKNOWN_TYPE;
        }
        switch (device.getDeviceType()) {
        switch (device.getDeviceType()) {
            case MediaDevice.MediaDeviceType.TYPE_PHONE_DEVICE:
            case MediaDevice.MediaDeviceType.TYPE_PHONE_DEVICE:
                return SysUiStatsLog.MEDIA_OUTPUT_OP_INTERACTION_REPORTED__TARGET__BUILTIN_SPEAKER;
                return SysUiStatsLog.MEDIA_OUTPUT_OP_INTERACTION_REPORTED__TARGET__BUILTIN_SPEAKER;
+26 −0
Original line number Original line Diff line number Diff line
@@ -274,4 +274,30 @@ public class MediaOutputAdapterTest extends SysuiTestCase {


        verify(mMediaOutputController).connectDevice(mMediaDevice2);
        verify(mMediaOutputController).connectDevice(mMediaDevice2);
    }
    }

    @Test
    public void onItemClick_onGroupActionTriggered_verifySeekbarDisabled() {
        when(mMediaOutputController.getSelectedMediaDevice()).thenReturn(mMediaDevices);
        List<MediaDevice> selectableDevices = new ArrayList<>();
        selectableDevices.add(mMediaDevice1);
        when(mMediaOutputController.getSelectableMediaDevice()).thenReturn(selectableDevices);
        when(mMediaOutputController.hasAdjustVolumeUserRestriction()).thenReturn(true);
        mMediaOutputAdapter.onBindViewHolder(mViewHolder, 0);

        mViewHolder.mContainerLayout.performClick();

        assertThat(mViewHolder.mSeekBar.isEnabled()).isFalse();
    }

    @Test
    public void onBindViewHolder_volumeControlChangeToEnabled_enableSeekbarAgain() {
        when(mMediaOutputController.isVolumeControlEnabled(mMediaDevice1)).thenReturn(false);
        mMediaOutputAdapter.onBindViewHolder(mViewHolder, 0);
        assertThat(mViewHolder.mSeekBar.isEnabled()).isFalse();

        when(mMediaOutputController.isVolumeControlEnabled(mMediaDevice1)).thenReturn(true);
        mMediaOutputAdapter.onBindViewHolder(mViewHolder, 0);

        assertThat(mViewHolder.mSeekBar.isEnabled()).isTrue();
    }
}
}