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

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

Merge "Add method to check if streams can be muted from UI" into main

parents fcbc60ea fb8a0694
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
@@ -182,7 +182,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
@@ -708,10 +708,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;
@@ -2346,6 +2350,7 @@ public class AudioService extends IAudioService.Stub
                mMuteAffectedStreams &= ~(1 << vss.mStreamType);
            }
        }
        updateUserMutableStreams();
    }
    private void createStreamStates() {
@@ -2415,6 +2420,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) {
@@ -2909,6 +2916,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);
@@ -2928,6 +2936,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;
@@ -7142,6 +7156,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: