Loading services/core/java/com/android/server/audio/AudioService.java +7 −6 Original line number Diff line number Diff line Loading @@ -781,7 +781,8 @@ public class AudioService extends IAudioService.Stub private int mRingerModeExternal = -1; // reported ringer mode to outside clients (AudioManager) /** @see System#MODE_RINGER_STREAMS_AFFECTED */ private int mRingerModeAffectedStreams = 0; @VisibleForTesting protected int mRingerModeAffectedStreams = 0; private int mZenModeAffectedStreams = 0; Loading Loading @@ -6315,17 +6316,15 @@ public class AudioService extends IAudioService.Stub } } sRingerAndZenModeMutedStreams &= ~(1 << streamType); sMuteLogger.enqueue(new AudioServiceEvents.RingerZenMutedStreamsEvent( sRingerAndZenModeMutedStreams, "muteRingerModeStreams")); vss.mute(false, "muteRingerModeStreams"); } else { // mute sRingerAndZenModeMutedStreams |= (1 << streamType); sMuteLogger.enqueue(new AudioServiceEvents.RingerZenMutedStreamsEvent( sRingerAndZenModeMutedStreams, "muteRingerModeStreams")); vss.mute(true, "muteRingerModeStreams"); } } sMuteLogger.enqueue(new AudioServiceEvents.RingerZenMutedStreamsEvent( sRingerAndZenModeMutedStreams, "muteRingerModeStreams")); } private boolean isAlarm(int streamType) { Loading Loading @@ -10045,12 +10044,14 @@ public class AudioService extends IAudioService.Stub new AudioServiceEvents.StreamMuteEvent(mStreamType, state, src)); // check to see if unmuting should not have happened due to ringer muted streams if (!state && isStreamMutedByRingerOrZenMode(mStreamType)) { Log.e(TAG, "Unmuting stream " + mStreamType Slog.e(TAG, "Attempt to unmute stream " + mStreamType + " despite ringer-zen muted stream 0x" + Integer.toHexString(AudioService.sRingerAndZenModeMutedStreams), new Exception()); // this will put a stack trace in the logs sMuteLogger.enqueue(new AudioServiceEvents.StreamUnmuteErrorEvent( mStreamType, AudioService.sRingerAndZenModeMutedStreams)); // do not change mute state return false; } mIsMuted = state; if (apply) { Loading services/tests/servicestests/src/com/android/server/audio/VolumeHelperTest.java +52 −0 Original line number Diff line number Diff line Loading @@ -117,6 +117,12 @@ public class VolumeHelperTest { /** Choose a default stream volume value which does not depend on min/max. */ private static final int DEFAULT_STREAM_VOLUME = 2; /** * The default ringer mode affected stream value since the ringer mode delegate is not used * for unit testing. */ private static final int DEFAULT_RINGER_MODE_AFFECTED_STREAMS = 0x1a6; @Rule public final MockitoRule mockito = MockitoJUnit.rule(); Loading Loading @@ -186,6 +192,10 @@ public class VolumeHelperTest { public void setMuteAffectedStreams(int muteAffectedStreams) { mMuteAffectedStreams = muteAffectedStreams; } public void setRingerModeAffectedStreams(int ringerModeAffectedStreams) { mRingerModeAffectedStreams = ringerModeAffectedStreams; } } private static class TestDeviceVolumeBehaviorDispatcherStub Loading Loading @@ -550,6 +560,48 @@ public class VolumeHelperTest { assertEquals(RINGER_MODE_VIBRATE, mAudioService.getRingerModeInternal()); } @Test public void setStreamVolume_doesNotUnmuteStreamAffectedByRingerMode() throws Exception { assumeFalse("Skipping ringer mode test on automotive", mIsAutomotive); mAudioService.setRingerModeAffectedStreams(DEFAULT_RINGER_MODE_AFFECTED_STREAMS); mAudioService.setRingerModeInternal(RINGER_MODE_VIBRATE, mContext.getOpPackageName()); mAudioService.setStreamVolume(STREAM_NOTIFICATION, /*index=*/1, /*flags=*/0, mContext.getOpPackageName()); mTestLooper.dispatchAll(); assertEquals(0, mAudioService.getStreamVolume(STREAM_NOTIFICATION)); } @Test public void adjustUnmuteStreamVolume_doesNotUnmuteStreamAffectedByRingerMode() throws Exception { assumeFalse("Skipping ringer mode test on automotive", mIsAutomotive); mAudioService.setRingerModeAffectedStreams(DEFAULT_RINGER_MODE_AFFECTED_STREAMS); mAudioService.setRingerModeInternal(RINGER_MODE_VIBRATE, mContext.getOpPackageName()); mAudioService.adjustStreamVolume(STREAM_NOTIFICATION, ADJUST_UNMUTE, /*flags=*/0, mContext.getOpPackageName()); mTestLooper.dispatchAll(); assertEquals(0, mAudioService.getStreamVolume(STREAM_NOTIFICATION)); } @Test public void adjustRaiseStreamVolume_doesNotUnmuteStreamAffectedByRingerMode() throws Exception { assumeFalse("Skipping ringer mode test on automotive", mIsAutomotive); mAudioService.setRingerModeAffectedStreams(DEFAULT_RINGER_MODE_AFFECTED_STREAMS); mAudioService.setRingerModeInternal(RINGER_MODE_VIBRATE, mContext.getOpPackageName()); mAudioService.adjustStreamVolume(STREAM_NOTIFICATION, ADJUST_RAISE, /*flags=*/0, mContext.getOpPackageName()); mTestLooper.dispatchAll(); assertEquals(0, mAudioService.getStreamVolume(STREAM_NOTIFICATION)); } // --------------------- Permission tests --------------------- @Test Loading Loading
services/core/java/com/android/server/audio/AudioService.java +7 −6 Original line number Diff line number Diff line Loading @@ -781,7 +781,8 @@ public class AudioService extends IAudioService.Stub private int mRingerModeExternal = -1; // reported ringer mode to outside clients (AudioManager) /** @see System#MODE_RINGER_STREAMS_AFFECTED */ private int mRingerModeAffectedStreams = 0; @VisibleForTesting protected int mRingerModeAffectedStreams = 0; private int mZenModeAffectedStreams = 0; Loading Loading @@ -6315,17 +6316,15 @@ public class AudioService extends IAudioService.Stub } } sRingerAndZenModeMutedStreams &= ~(1 << streamType); sMuteLogger.enqueue(new AudioServiceEvents.RingerZenMutedStreamsEvent( sRingerAndZenModeMutedStreams, "muteRingerModeStreams")); vss.mute(false, "muteRingerModeStreams"); } else { // mute sRingerAndZenModeMutedStreams |= (1 << streamType); sMuteLogger.enqueue(new AudioServiceEvents.RingerZenMutedStreamsEvent( sRingerAndZenModeMutedStreams, "muteRingerModeStreams")); vss.mute(true, "muteRingerModeStreams"); } } sMuteLogger.enqueue(new AudioServiceEvents.RingerZenMutedStreamsEvent( sRingerAndZenModeMutedStreams, "muteRingerModeStreams")); } private boolean isAlarm(int streamType) { Loading Loading @@ -10045,12 +10044,14 @@ public class AudioService extends IAudioService.Stub new AudioServiceEvents.StreamMuteEvent(mStreamType, state, src)); // check to see if unmuting should not have happened due to ringer muted streams if (!state && isStreamMutedByRingerOrZenMode(mStreamType)) { Log.e(TAG, "Unmuting stream " + mStreamType Slog.e(TAG, "Attempt to unmute stream " + mStreamType + " despite ringer-zen muted stream 0x" + Integer.toHexString(AudioService.sRingerAndZenModeMutedStreams), new Exception()); // this will put a stack trace in the logs sMuteLogger.enqueue(new AudioServiceEvents.StreamUnmuteErrorEvent( mStreamType, AudioService.sRingerAndZenModeMutedStreams)); // do not change mute state return false; } mIsMuted = state; if (apply) { Loading
services/tests/servicestests/src/com/android/server/audio/VolumeHelperTest.java +52 −0 Original line number Diff line number Diff line Loading @@ -117,6 +117,12 @@ public class VolumeHelperTest { /** Choose a default stream volume value which does not depend on min/max. */ private static final int DEFAULT_STREAM_VOLUME = 2; /** * The default ringer mode affected stream value since the ringer mode delegate is not used * for unit testing. */ private static final int DEFAULT_RINGER_MODE_AFFECTED_STREAMS = 0x1a6; @Rule public final MockitoRule mockito = MockitoJUnit.rule(); Loading Loading @@ -186,6 +192,10 @@ public class VolumeHelperTest { public void setMuteAffectedStreams(int muteAffectedStreams) { mMuteAffectedStreams = muteAffectedStreams; } public void setRingerModeAffectedStreams(int ringerModeAffectedStreams) { mRingerModeAffectedStreams = ringerModeAffectedStreams; } } private static class TestDeviceVolumeBehaviorDispatcherStub Loading Loading @@ -550,6 +560,48 @@ public class VolumeHelperTest { assertEquals(RINGER_MODE_VIBRATE, mAudioService.getRingerModeInternal()); } @Test public void setStreamVolume_doesNotUnmuteStreamAffectedByRingerMode() throws Exception { assumeFalse("Skipping ringer mode test on automotive", mIsAutomotive); mAudioService.setRingerModeAffectedStreams(DEFAULT_RINGER_MODE_AFFECTED_STREAMS); mAudioService.setRingerModeInternal(RINGER_MODE_VIBRATE, mContext.getOpPackageName()); mAudioService.setStreamVolume(STREAM_NOTIFICATION, /*index=*/1, /*flags=*/0, mContext.getOpPackageName()); mTestLooper.dispatchAll(); assertEquals(0, mAudioService.getStreamVolume(STREAM_NOTIFICATION)); } @Test public void adjustUnmuteStreamVolume_doesNotUnmuteStreamAffectedByRingerMode() throws Exception { assumeFalse("Skipping ringer mode test on automotive", mIsAutomotive); mAudioService.setRingerModeAffectedStreams(DEFAULT_RINGER_MODE_AFFECTED_STREAMS); mAudioService.setRingerModeInternal(RINGER_MODE_VIBRATE, mContext.getOpPackageName()); mAudioService.adjustStreamVolume(STREAM_NOTIFICATION, ADJUST_UNMUTE, /*flags=*/0, mContext.getOpPackageName()); mTestLooper.dispatchAll(); assertEquals(0, mAudioService.getStreamVolume(STREAM_NOTIFICATION)); } @Test public void adjustRaiseStreamVolume_doesNotUnmuteStreamAffectedByRingerMode() throws Exception { assumeFalse("Skipping ringer mode test on automotive", mIsAutomotive); mAudioService.setRingerModeAffectedStreams(DEFAULT_RINGER_MODE_AFFECTED_STREAMS); mAudioService.setRingerModeInternal(RINGER_MODE_VIBRATE, mContext.getOpPackageName()); mAudioService.adjustStreamVolume(STREAM_NOTIFICATION, ADJUST_RAISE, /*flags=*/0, mContext.getOpPackageName()); mTestLooper.dispatchAll(); assertEquals(0, mAudioService.getStreamVolume(STREAM_NOTIFICATION)); } // --------------------- Permission tests --------------------- @Test Loading