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

Commit 96a4ea37 authored by Vlad Popa's avatar Vlad Popa Committed by Android (Google) Code Review
Browse files

Merge "AudioService: do not unmute when ringer mode affects stream" into main

parents 9f48f16d 690d3b86
Loading
Loading
Loading
Loading
+7 −6
Original line number Diff line number Diff line
@@ -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;
@@ -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) {
@@ -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) {
+52 −0
Original line number Diff line number Diff line
@@ -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();

@@ -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
@@ -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