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

Commit 2ab128ac authored by Alexander Hofbauer's avatar Alexander Hofbauer Committed by Gerrit Code Review
Browse files

AudioManager: Mute on KEYCODE_VOLUME_MUTE

Calls to AudioManager added in KeyguardViewBase and PhoneWindowManager
as well. Toggles mute state by changing the ringer mode.

Change-Id: I7178d3eb7bc62cfc872eb12b3e8d39e4c0a5bf35
parent 202d90af
Loading
Loading
Loading
Loading
+15 −1
Original line number Diff line number Diff line
@@ -487,7 +487,7 @@ public class AudioManager {
                    if (mUseMasterVolume) {
                        setMasterMute(!isMasterMute());
                    } else {
                        // TODO: Actually handle MUTE.
                        toggleGlobalMute();
                    }
                }
                break;
@@ -958,6 +958,20 @@ public class AudioManager {
        }
    }

    /**
     * Toggles global mute state via ringer mode.
     * @param streamType The suggested stream type that is to be muted.
     * @hide
     */
    public void toggleGlobalMute() {
        IAudioService service = getService();
        try {
            service.toggleGlobalMute();
        } catch (RemoteException e) {
            Log.e(TAG, "Dead object in toggleGlobalMute", e);
        }
    }

    /**
     * forces the stream controlled by hard volume keys
     * specifying streamType == -1 releases control to the
+25 −0
Original line number Diff line number Diff line
@@ -1081,6 +1081,31 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
        }
    }

    /**
     * @see AudioManager#toggleGlobalMute()
     * @hide
     */
    public void toggleGlobalMute() {
        int currentMode = getRingerMode();

        if (currentMode == RINGER_MODE_VIBRATE || currentMode == RINGER_MODE_SILENT) {
            setRingerMode(RINGER_MODE_NORMAL);

        } else {
            int ringerMode = mHasVibrator ? RINGER_MODE_VIBRATE : RINGER_MODE_SILENT;
            setRingerMode(ringerMode);
        }

        if (mVolumePanel != null) {
            int streamType = getActiveStreamType(AudioManager.USE_DEFAULT_STREAM_TYPE);
            if (streamType == STREAM_REMOTE_MUSIC) {
                streamType = AudioManager.STREAM_MUSIC;
            }
            mVolumePanel.postMuteChanged(streamType,
                    AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_VIBRATE);
        }
    }

    /** get stream mute state. */
    public boolean isStreamMute(int streamType) {
        return (mStreamStates[streamType].muteCount() != 0);
+2 −0
Original line number Diff line number Diff line
@@ -60,6 +60,8 @@ interface IAudioService {

    boolean isMasterMute();

    void toggleGlobalMute();

    int getStreamVolume(int streamType);

    int getMasterVolume();
+9 −6
Original line number Diff line number Diff line
@@ -214,12 +214,15 @@ public abstract class KeyguardViewBase extends FrameLayout {
                            }
                        }
                        // Volume buttons should only function for music (local or remote).
                        // TODO: Actually handle MUTE.
                        if (keyCode == KeyEvent.KEYCODE_VOLUME_MUTE) {
                                mAudioManager.toggleGlobalMute();
                        } else {
                            mAudioManager.adjustLocalOrRemoteStreamVolume(
                                    AudioManager.STREAM_MUSIC,
                                    keyCode == KeyEvent.KEYCODE_VOLUME_UP
                                            ? AudioManager.ADJUST_RAISE
                                            : AudioManager.ADJUST_LOWER);
                        }
                        // Don't execute default volume behavior
                        return true;
                    } else {
+18 −10
Original line number Diff line number Diff line
@@ -3352,16 +3352,24 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            return;
        }
        try {
            if (keycode == KeyEvent.KEYCODE_VOLUME_MUTE) {
                final AudioManager am = (AudioManager)mContext.getSystemService(Context.AUDIO_SERVICE);
                if (am == null) {
                    Log.w(TAG, "handleVolumeKey: couldn't get AudioManager reference");
                } else {
                    am.toggleGlobalMute();
                }
            } else {
                // since audio is playing, we shouldn't have to hold a wake lock
                // during the call, but we do it as a precaution for the rare possibility
                // that the music stops right before we call this
            // TODO: Actually handle MUTE.
                mBroadcastWakeLock.acquire();
                audioService.adjustStreamVolume(stream,
                    keycode == KeyEvent.KEYCODE_VOLUME_UP
                                ? AudioManager.ADJUST_RAISE
                                : AudioManager.ADJUST_LOWER,
                        0);
            }
        } catch (RemoteException e) {
            Log.w(TAG, "IAudioService.adjustStreamVolume() threw RemoteException " + e);
        } finally {