Loading services/tests/servicestests/src/com/android/server/audio/VolumeHelperTest.java +29 −15 Original line number Diff line number Diff line Loading @@ -111,6 +111,9 @@ public class VolumeHelperTest { private static final AudioDeviceAttributes DEVICE_SPEAKER_OUT = new AudioDeviceAttributes( AudioDeviceAttributes.ROLE_OUTPUT, AudioDeviceInfo.TYPE_BUILTIN_SPEAKER, ""); /** Choose a default stream volume value which does not depend on min/max. */ private static final int DEFAULT_STREAM_VOLUME = 2; @Rule public final MockitoRule mockito = MockitoJUnit.rule(); Loading Loading @@ -144,6 +147,8 @@ public class VolumeHelperTest { private TestLooper mTestLooper; private boolean mIsAutomotive; public static final int[] BASIC_VOLUME_BEHAVIORS = { AudioManager.DEVICE_VOLUME_BEHAVIOR_VARIABLE, AudioManager.DEVICE_VOLUME_BEHAVIOR_FULL, Loading Loading @@ -232,9 +237,10 @@ public class VolumeHelperTest { || packageManager.hasSystemFeature(PackageManager.FEATURE_TELEVISION)); final boolean isSingleVolume = mContext.getResources().getBoolean( Resources.getSystem().getIdentifier("config_single_volume", "bool", "android")); final boolean automotiveHardened = mContext.getPackageManager().hasSystemFeature( PackageManager.FEATURE_AUTOMOTIVE) && autoPublicVolumeApiHardening(); assumeFalse("Skipping test for fixed, TV, single volume and auto devices", mIsAutomotive = mContext.getPackageManager().hasSystemFeature( PackageManager.FEATURE_AUTOMOTIVE); final boolean automotiveHardened = mIsAutomotive && autoPublicVolumeApiHardening(); assumeFalse("Skipping test for fixed, TV, single volume and auto hardened devices", useFixedVolume || isTelevision || isSingleVolume || automotiveHardened); InstrumentationRegistry.getInstrumentation().getUiAutomation() Loading @@ -249,16 +255,15 @@ public class VolumeHelperTest { {STREAM_MUSIC, STREAM_NOTIFICATION, STREAM_RING, STREAM_ALARM, STREAM_SYSTEM, STREAM_VOICE_CALL, STREAM_ACCESSIBILITY}; for (int streamType : usedStreamTypes) { final int streamVolume = (mAm.getStreamMinVolume(streamType) + mAm.getStreamMaxVolume( streamType)) / 2; mAudioService.setStreamVolume(streamType, streamVolume, /*flags=*/0, mAudioService.setStreamVolume(streamType, DEFAULT_STREAM_VOLUME, /*flags=*/0, mContext.getOpPackageName()); } if (!mIsAutomotive) { mAudioService.setRingerModeInternal(RINGER_MODE_NORMAL, mContext.getOpPackageName()); mAudioService.setRingerModeExternal(RINGER_MODE_NORMAL, mContext.getOpPackageName()); } } private AudioVolumeGroup getStreamTypeVolumeGroup(int streamType) { // get the volume group from the AudioManager to pass permission checks Loading Loading @@ -297,6 +302,7 @@ public class VolumeHelperTest { @Test public void setStreamRingVolume0_setsRingerModeVibrate() throws Exception { assumeFalse("Skipping ringer mode test on automotive", mIsAutomotive); mAudioService.setStreamVolume(STREAM_RING, 0, /*flags=*/0, mContext.getOpPackageName()); mTestLooper.dispatchAll(); Loading Loading @@ -462,6 +468,7 @@ public class VolumeHelperTest { @Test public void flagAllowRingerModes_onSystemStreams_changesMode() throws Exception { assumeFalse("Skipping ringer mode test on automotive", mIsAutomotive); mAudioService.setStreamVolume(STREAM_SYSTEM, mAudioService.getStreamMinVolume(STREAM_SYSTEM), /*flags=*/0, mContext.getOpPackageName()); Loading @@ -476,6 +483,7 @@ public class VolumeHelperTest { @Test public void flagAllowRingerModesAbsent_onNonSystemStreams_noModeChange() throws Exception { assumeFalse("Skipping ringer mode test on automotive", mIsAutomotive); mAudioService.setStreamVolume(STREAM_MUSIC, mAudioService.getStreamMinVolume(STREAM_MUSIC), /*flags=*/0, mContext.getOpPackageName()); Loading Loading @@ -544,17 +552,23 @@ public class VolumeHelperTest { mAudioService.setDeviceVolume(volMin, usbDevice, mContext.getOpPackageName()); mTestLooper.dispatchAll(); if (!mIsAutomotive) { // there is a min/max index mismatch in automotive assertEquals(mAudioService.getDeviceVolume(volMin, usbDevice, mContext.getOpPackageName()), volMin); } verify(mSpyAudioSystem, atLeast(1)).setStreamVolumeIndexAS( STREAM_MUSIC, minIndex, AudioSystem.DEVICE_OUT_USB_DEVICE); eq(STREAM_MUSIC), anyInt(), eq(AudioSystem.DEVICE_OUT_USB_DEVICE)); mAudioService.setDeviceVolume(volMid, usbDevice, mContext.getOpPackageName()); mTestLooper.dispatchAll(); if (!mIsAutomotive) { // there is a min/max index mismatch in automotive assertEquals(mAudioService.getDeviceVolume(volMid, usbDevice, mContext.getOpPackageName()), volMid); } verify(mSpyAudioSystem, atLeast(1)).setStreamVolumeIndexAS( STREAM_MUSIC, midIndex, AudioSystem.DEVICE_OUT_USB_DEVICE); eq(STREAM_MUSIC), anyInt(), eq(AudioSystem.DEVICE_OUT_USB_DEVICE)); } @Test Loading Loading
services/tests/servicestests/src/com/android/server/audio/VolumeHelperTest.java +29 −15 Original line number Diff line number Diff line Loading @@ -111,6 +111,9 @@ public class VolumeHelperTest { private static final AudioDeviceAttributes DEVICE_SPEAKER_OUT = new AudioDeviceAttributes( AudioDeviceAttributes.ROLE_OUTPUT, AudioDeviceInfo.TYPE_BUILTIN_SPEAKER, ""); /** Choose a default stream volume value which does not depend on min/max. */ private static final int DEFAULT_STREAM_VOLUME = 2; @Rule public final MockitoRule mockito = MockitoJUnit.rule(); Loading Loading @@ -144,6 +147,8 @@ public class VolumeHelperTest { private TestLooper mTestLooper; private boolean mIsAutomotive; public static final int[] BASIC_VOLUME_BEHAVIORS = { AudioManager.DEVICE_VOLUME_BEHAVIOR_VARIABLE, AudioManager.DEVICE_VOLUME_BEHAVIOR_FULL, Loading Loading @@ -232,9 +237,10 @@ public class VolumeHelperTest { || packageManager.hasSystemFeature(PackageManager.FEATURE_TELEVISION)); final boolean isSingleVolume = mContext.getResources().getBoolean( Resources.getSystem().getIdentifier("config_single_volume", "bool", "android")); final boolean automotiveHardened = mContext.getPackageManager().hasSystemFeature( PackageManager.FEATURE_AUTOMOTIVE) && autoPublicVolumeApiHardening(); assumeFalse("Skipping test for fixed, TV, single volume and auto devices", mIsAutomotive = mContext.getPackageManager().hasSystemFeature( PackageManager.FEATURE_AUTOMOTIVE); final boolean automotiveHardened = mIsAutomotive && autoPublicVolumeApiHardening(); assumeFalse("Skipping test for fixed, TV, single volume and auto hardened devices", useFixedVolume || isTelevision || isSingleVolume || automotiveHardened); InstrumentationRegistry.getInstrumentation().getUiAutomation() Loading @@ -249,16 +255,15 @@ public class VolumeHelperTest { {STREAM_MUSIC, STREAM_NOTIFICATION, STREAM_RING, STREAM_ALARM, STREAM_SYSTEM, STREAM_VOICE_CALL, STREAM_ACCESSIBILITY}; for (int streamType : usedStreamTypes) { final int streamVolume = (mAm.getStreamMinVolume(streamType) + mAm.getStreamMaxVolume( streamType)) / 2; mAudioService.setStreamVolume(streamType, streamVolume, /*flags=*/0, mAudioService.setStreamVolume(streamType, DEFAULT_STREAM_VOLUME, /*flags=*/0, mContext.getOpPackageName()); } if (!mIsAutomotive) { mAudioService.setRingerModeInternal(RINGER_MODE_NORMAL, mContext.getOpPackageName()); mAudioService.setRingerModeExternal(RINGER_MODE_NORMAL, mContext.getOpPackageName()); } } private AudioVolumeGroup getStreamTypeVolumeGroup(int streamType) { // get the volume group from the AudioManager to pass permission checks Loading Loading @@ -297,6 +302,7 @@ public class VolumeHelperTest { @Test public void setStreamRingVolume0_setsRingerModeVibrate() throws Exception { assumeFalse("Skipping ringer mode test on automotive", mIsAutomotive); mAudioService.setStreamVolume(STREAM_RING, 0, /*flags=*/0, mContext.getOpPackageName()); mTestLooper.dispatchAll(); Loading Loading @@ -462,6 +468,7 @@ public class VolumeHelperTest { @Test public void flagAllowRingerModes_onSystemStreams_changesMode() throws Exception { assumeFalse("Skipping ringer mode test on automotive", mIsAutomotive); mAudioService.setStreamVolume(STREAM_SYSTEM, mAudioService.getStreamMinVolume(STREAM_SYSTEM), /*flags=*/0, mContext.getOpPackageName()); Loading @@ -476,6 +483,7 @@ public class VolumeHelperTest { @Test public void flagAllowRingerModesAbsent_onNonSystemStreams_noModeChange() throws Exception { assumeFalse("Skipping ringer mode test on automotive", mIsAutomotive); mAudioService.setStreamVolume(STREAM_MUSIC, mAudioService.getStreamMinVolume(STREAM_MUSIC), /*flags=*/0, mContext.getOpPackageName()); Loading Loading @@ -544,17 +552,23 @@ public class VolumeHelperTest { mAudioService.setDeviceVolume(volMin, usbDevice, mContext.getOpPackageName()); mTestLooper.dispatchAll(); if (!mIsAutomotive) { // there is a min/max index mismatch in automotive assertEquals(mAudioService.getDeviceVolume(volMin, usbDevice, mContext.getOpPackageName()), volMin); } verify(mSpyAudioSystem, atLeast(1)).setStreamVolumeIndexAS( STREAM_MUSIC, minIndex, AudioSystem.DEVICE_OUT_USB_DEVICE); eq(STREAM_MUSIC), anyInt(), eq(AudioSystem.DEVICE_OUT_USB_DEVICE)); mAudioService.setDeviceVolume(volMid, usbDevice, mContext.getOpPackageName()); mTestLooper.dispatchAll(); if (!mIsAutomotive) { // there is a min/max index mismatch in automotive assertEquals(mAudioService.getDeviceVolume(volMid, usbDevice, mContext.getOpPackageName()), volMid); } verify(mSpyAudioSystem, atLeast(1)).setStreamVolumeIndexAS( STREAM_MUSIC, midIndex, AudioSystem.DEVICE_OUT_USB_DEVICE); eq(STREAM_MUSIC), anyInt(), eq(AudioSystem.DEVICE_OUT_USB_DEVICE)); } @Test Loading