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

Commit a00b43bc authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Fix tests when absolute index volume flag is enabled" into main

parents caa4db5e 480d055b
Loading
Loading
Loading
Loading
+12 −3
Original line number Diff line number Diff line
@@ -16,7 +16,9 @@

package com.android.server.audio;

import static com.android.media.audio.Flags.FLAG_ABS_VOLUME_INDEX_FIX;
import static com.android.media.audio.Flags.FLAG_DISABLE_PRESCALE_ABSOLUTE_VOLUME;
import static com.android.media.audio.Flags.absVolumeIndexFix;

import static org.mockito.Mockito.atLeast;
import static org.mockito.Mockito.mock;
@@ -116,7 +118,7 @@ public class AudioDeviceVolumeManagerTest {
    }

    @Test
    @RequiresFlagsDisabled(FLAG_DISABLE_PRESCALE_ABSOLUTE_VOLUME)
    @RequiresFlagsDisabled({FLAG_DISABLE_PRESCALE_ABSOLUTE_VOLUME, FLAG_ABS_VOLUME_INDEX_FIX})
    public void configurablePreScaleAbsoluteVolume_checkIndex() throws Exception {
        AudioManager am = mContext.getSystemService(AudioManager.class);
        final int minIndex = am.getStreamMinVolume(AudioManager.STREAM_MUSIC);
@@ -177,6 +179,7 @@ public class AudioDeviceVolumeManagerTest {
        final AudioDeviceAttributes bleDevice = new AudioDeviceAttributes(
                /*native type*/ AudioSystem.DEVICE_OUT_BLE_HEADSET, /*address*/ "bla");
        final int maxPreScaleIndex = 3;
        int passedIndex = maxIndex;

        for (int i = 0; i < maxPreScaleIndex; i++) {
            final VolumeInfo volCur = new VolumeInfo.Builder(volMedia)
@@ -185,9 +188,12 @@ public class AudioDeviceVolumeManagerTest {
            mAudioService.setDeviceVolume(volCur, bleDevice, mPackageName);
            mTestLooper.dispatchAll();

            if (absVolumeIndexFix()) {
                passedIndex = i + 1;
            }
            // Stream volume changes
            verify(mSpyAudioSystem, atLeast(1)).setStreamVolumeIndexAS(
                            AudioManager.STREAM_MUSIC, maxIndex,
                            AudioManager.STREAM_MUSIC, passedIndex,
                            AudioSystem.DEVICE_OUT_BLE_HEADSET);
        }

@@ -197,8 +203,11 @@ public class AudioDeviceVolumeManagerTest {
        mAudioService.setDeviceVolume(volIndex4, bleDevice, mPackageName);
        mTestLooper.dispatchAll();

        if (absVolumeIndexFix()) {
            passedIndex = 4;
        }
        verify(mSpyAudioSystem, atLeast(1)).setStreamVolumeIndexAS(
                        AudioManager.STREAM_MUSIC, maxIndex,
                        AudioManager.STREAM_MUSIC, passedIndex,
                        AudioSystem.DEVICE_OUT_BLE_HEADSET);
    }
}
+11 −4
Original line number Diff line number Diff line
@@ -39,8 +39,9 @@ import static android.media.audio.Flags.autoPublicVolumeApiHardening;
import static android.view.KeyEvent.ACTION_DOWN;
import static android.view.KeyEvent.KEYCODE_VOLUME_UP;

import static com.android.media.audio.Flags.FLAG_DISABLE_PRESCALE_ABSOLUTE_VOLUME;
import static com.android.media.audio.Flags.FLAG_ABS_VOLUME_INDEX_FIX;
import static com.android.media.audio.Flags.FLAG_DISABLE_PRESCALE_ABSOLUTE_VOLUME;
import static com.android.media.audio.Flags.absVolumeIndexFix;

import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertWithMessage;
@@ -627,7 +628,6 @@ public class VolumeHelperTest {

    @Test
    @RequiresFlagsEnabled(FLAG_DISABLE_PRESCALE_ABSOLUTE_VOLUME)
    @RequiresFlagsDisabled(FLAG_ABS_VOLUME_INDEX_FIX)
    public void disablePreScaleAbsoluteVolume_checkIndex() throws Exception {
        final int minIndex = mAm.getStreamMinVolume(STREAM_MUSIC);
        final int maxIndex = mAm.getStreamMaxVolume(STREAM_MUSIC);
@@ -638,6 +638,7 @@ public class VolumeHelperTest {
        final AudioDeviceAttributes bleDevice = new AudioDeviceAttributes(
                /*native type*/ AudioSystem.DEVICE_OUT_BLE_HEADSET, /*address*/ "bla");
        final int maxPreScaleIndex = 3;
        int passedIndex = maxIndex;

        for (int i = 0; i < maxPreScaleIndex; i++) {
            final VolumeInfo volCur = new VolumeInfo.Builder(volMedia)
@@ -646,9 +647,12 @@ public class VolumeHelperTest {
            mAudioService.setDeviceVolume(volCur, bleDevice, mContext.getOpPackageName());
            mTestLooper.dispatchAll();

            if (absVolumeIndexFix()) {
                passedIndex = i + 1;
            }
            // Stream volume changes
            verify(mSpyAudioSystem, atLeast(1)).setStreamVolumeIndexAS(
                    STREAM_MUSIC, maxIndex,
                    STREAM_MUSIC, passedIndex,
                    AudioSystem.DEVICE_OUT_BLE_HEADSET);
        }

@@ -658,8 +662,11 @@ public class VolumeHelperTest {
        mAudioService.setDeviceVolume(volIndex4, bleDevice, mContext.getOpPackageName());
        mTestLooper.dispatchAll();

        if (absVolumeIndexFix()) {
            passedIndex = 4;
        }
        verify(mSpyAudioSystem, atLeast(1)).setStreamVolumeIndexAS(
                STREAM_MUSIC, maxIndex,
                STREAM_MUSIC, passedIndex,
                AudioSystem.DEVICE_OUT_BLE_HEADSET);
    }