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

Commit fb8a0694 authored by Vlad Popa's avatar Vlad Popa
Browse files

Add method to check if streams can be muted from UI

The new method returns false for STREAM_VOICE_CALL and
STREAM_BLUETOOTH_SCO. They should never be muted by users.
There are only few cases where this is allowed.

Flag: EXEMPT bugfix
Test: manual
Bug: 349592304
Bug: 349604691
Change-Id: Ia312b59bd846190e433ca22de6fe49e5f4f4b0a0
parent d9227e90
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -7006,6 +7006,23 @@ public class AudioManager {
        }
    }

    /**
     * Check whether a user can mute this stream type from a given UI element.
     *
     * <p>Only useful for volume controllers.
     *
     * @param streamType type of stream to check if it's mutable from UI
     *
     * @hide
     */
    public boolean isStreamMutableByUi(int streamType) {
        try {
            return getService().isStreamMutableByUi(streamType);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * Only useful for volume controllers.
     * @hide
+2 −0
Original line number Diff line number Diff line
@@ -305,6 +305,8 @@ interface IAudioService {

    boolean isStreamAffectedByMute(int streamType);

    boolean isStreamMutableByUi(int streamType);

    void disableSafeMediaVolume(String callingPackage);

    oneway void lowerVolumeToRs1(String callingPackage);
+1 −1
Original line number Diff line number Diff line
@@ -179,7 +179,7 @@ class AudioRepositoryImpl(
            minVolume = getMinVolume(audioStream),
            maxVolume = audioManager.getStreamMaxVolume(audioStream.value),
            volume = audioManager.getStreamVolume(audioStream.value),
            isAffectedByMute = audioManager.isStreamAffectedByMute(audioStream.value),
            isAffectedByMute = audioManager.isStreamMutableByUi(audioStream.value),
            isAffectedByRingerMode = audioManager.isStreamAffectedByRingerMode(audioStream.value),
            isMuted = audioManager.isStreamMute(audioStream.value),
        )
+1 −1
Original line number Diff line number Diff line
@@ -567,7 +567,7 @@ public class VolumeDialogControllerImpl implements VolumeDialogController, Dumpa
            streamStateW(stream).levelMax = Math.max(1, getAudioManagerStreamMaxVolume(stream));
            updateStreamMuteW(stream, mAudio.isStreamMute(stream));
            final StreamState ss = streamStateW(stream);
            ss.muteSupported = mAudio.isStreamAffectedByMute(stream);
            ss.muteSupported = mAudio.isStreamMutableByUi(stream);
            ss.name = STREAMS.get(stream);
            checkRoutedToBluetoothW(stream);
        }
+20 −1
Original line number Diff line number Diff line
@@ -707,10 +707,14 @@ public class AudioService extends IAudioService.Stub
    // Streams currently muted by ringer mode and dnd
    protected static volatile int sRingerAndZenModeMutedStreams;
    /** Streams that can be muted. Do not resolve to aliases when checking.
    /** Streams that can be muted by system. Do not resolve to aliases when checking.
     * @see System#MUTE_STREAMS_AFFECTED */
    private int mMuteAffectedStreams;
    /** Streams that can be muted by user. Do not resolve to aliases when checking.
     * @see System#MUTE_STREAMS_AFFECTED */
    private int mUserMutableStreams;
    @NonNull
    private SoundEffectsHelper mSfxHelper;
@@ -2345,6 +2349,7 @@ public class AudioService extends IAudioService.Stub
                mMuteAffectedStreams &= ~(1 << vss.mStreamType);
            }
        }
        updateUserMutableStreams();
    }
    private void createStreamStates() {
@@ -2414,6 +2419,8 @@ public class AudioService extends IAudioService.Stub
        }
        pw.print("\n- mute affected streams = 0x");
        pw.println(Integer.toHexString(mMuteAffectedStreams));
        pw.print("\n- user mutable streams = 0x");
        pw.println(Integer.toHexString(mUserMutableStreams));
    }
    private void updateStreamVolumeAlias(boolean updateVolumes, String caller) {
@@ -2908,6 +2915,7 @@ public class AudioService extends IAudioService.Stub
        mMuteAffectedStreams = mSettings.getSystemIntForUser(cr,
                System.MUTE_STREAMS_AFFECTED, AudioSystem.DEFAULT_MUTE_STREAMS_AFFECTED,
                UserHandle.USER_CURRENT);
        updateUserMutableStreams();
        updateMasterMono(cr);
@@ -2927,6 +2935,12 @@ public class AudioService extends IAudioService.Stub
        mVolumeController.loadSettings(cr);
    }
    private void updateUserMutableStreams() {
        mUserMutableStreams = mMuteAffectedStreams;
        mUserMutableStreams &= ~(1 << AudioSystem.STREAM_VOICE_CALL);
        mUserMutableStreams &= ~(1 << AudioSystem.STREAM_BLUETOOTH_SCO);
    }
    @GuardedBy("mSettingsLock")
    private void resetActiveAssistantUidsLocked() {
        mActiveAssistantServiceUids = NO_ACTIVE_ASSISTANT_SERVICE_UIDS;
@@ -7125,6 +7139,11 @@ public class AudioService extends IAudioService.Stub
        return (mMuteAffectedStreams & (1 << streamType)) != 0;
    }
    @Override
    public boolean isStreamMutableByUi(int streamType) {
        return (mUserMutableStreams & (1 << streamType)) != 0;
    }
    private void ensureValidDirection(int direction) {
        switch (direction) {
            case AudioManager.ADJUST_LOWER: