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

Commit bbf0f662 authored by RoboErik's avatar RoboErik Committed by Android Git Automerger
Browse files

am 3ef3a9bf: am ac4af18b: Merge "Handle volume events on master volume devices...

am 3ef3a9bf: am ac4af18b: Merge "Handle volume events on master volume devices correctly" into lmp-mr1-dev

* commit '3ef3a9bf':
  Handle volume events on master volume devices correctly
parents 216c0898 3ef3a9bf
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -35,4 +35,7 @@ public abstract class AudioManagerInternal {

    public abstract void setStreamVolumeForUid(int streamType, int direction, int flags,
            String callingPackage, int uid);

    public abstract void adjustMasterVolumeForUid(int steps, int flags, String callingPackage,
            int uid);
}
+21 −9
Original line number Diff line number Diff line
@@ -50,7 +50,6 @@ import android.media.MediaPlayer.OnCompletionListener;
import android.media.MediaPlayer.OnErrorListener;
import android.media.audiopolicy.AudioMix;
import android.media.audiopolicy.AudioPolicyConfig;
import android.media.session.MediaSessionLegacyHelper;
import android.os.Binder;
import android.os.Build;
import android.os.Environment;
@@ -61,7 +60,6 @@ import android.os.Message;
import android.os.PowerManager;
import android.os.RemoteCallbackList;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.SystemClock;
import android.os.SystemProperties;
import android.os.UserHandle;
@@ -75,12 +73,11 @@ import android.util.Log;
import android.util.MathUtils;
import android.util.Slog;
import android.view.KeyEvent;
import android.view.OrientationEventListener;
import android.view.Surface;
import android.view.WindowManager;
import android.view.accessibility.AccessibilityManager;
import android.view.OrientationEventListener;

import com.android.internal.telephony.ITelephony;
import com.android.internal.util.XmlUtils;
import com.android.server.LocalServices;

@@ -91,8 +88,6 @@ import java.io.IOException;
import java.io.PrintWriter;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.concurrent.ConcurrentHashMap;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
@@ -100,6 +95,7 @@ import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

/**
 * The implementation of the volume manager service.
@@ -1152,6 +1148,10 @@ public class AudioService extends IAudioService.Stub {

    /** @see AudioManager#adjustMasterVolume(int, int) */
    public void adjustMasterVolume(int steps, int flags, String callingPackage) {
        adjustMasterVolume(steps, flags, callingPackage, Binder.getCallingUid());
    }

    public void adjustMasterVolume(int steps, int flags, String callingPackage, int uid) {
        if (mUseFixedVolume) {
            return;
        }
@@ -1166,7 +1166,7 @@ public class AudioService extends IAudioService.Stub {
        }

        //Log.d(TAG, "adjustMasterVolume volume: " + volume + " steps: " + steps);
        setMasterVolume(volume, flags, callingPackage);
        setMasterVolume(volume, flags, callingPackage, uid);
    }

    // StreamVolumeCommand contains the information needed to defer the process of
@@ -1679,18 +1679,24 @@ public class AudioService extends IAudioService.Stub {
        }
    }

    @Override
    public int getMasterVolume() {
        if (isMasterMute()) return 0;
        return getLastAudibleMasterVolume();
    }

    @Override
    public void setMasterVolume(int volume, int flags, String callingPackage) {
        setMasterVolume(volume, flags, callingPackage, Binder.getCallingUid());
    }

    public void setMasterVolume(int volume, int flags, String callingPackage, int uid) {
        if (mUseFixedVolume) {
            return;
        }

        if (mAppOps.noteOp(AppOpsManager.OP_AUDIO_MASTER_VOLUME, Binder.getCallingUid(),
                callingPackage) != AppOpsManager.MODE_ALLOWED) {
        if (mAppOps.noteOp(AppOpsManager.OP_AUDIO_MASTER_VOLUME, uid, callingPackage)
                != AppOpsManager.MODE_ALLOWED) {
            return;
        }

@@ -5667,6 +5673,12 @@ public class AudioService extends IAudioService.Stub {
                String callingPackage, int uid) {
            setStreamVolume(streamType, direction, flags, callingPackage, uid);
        }

        @Override
        public void adjustMasterVolumeForUid(int steps, int flags, String callingPackage,
                int uid) {
            adjustMasterVolume(steps, flags, callingPackage, uid);
        }
    }

    //==========================================================================================
+9 −0
Original line number Diff line number Diff line
@@ -90,6 +90,7 @@ public class MediaSessionRecord implements IBinder.DeathRecipient {
    private final SessionStub mSession;
    private final SessionCb mSessionCb;
    private final MediaSessionService mService;
    private final boolean mUseMasterVolume;

    private final Object mLock = new Object();
    private final ArrayList<ISessionControllerCallback> mControllerCallbacks =
@@ -139,6 +140,8 @@ public class MediaSessionRecord implements IBinder.DeathRecipient {
        mAudioManager = (AudioManager) service.getContext().getSystemService(Context.AUDIO_SERVICE);
        mAudioManagerInternal = LocalServices.getService(AudioManagerInternal.class);
        mAudioAttrs = new AudioAttributes.Builder().setUsage(AudioAttributes.USAGE_MEDIA).build();
        mUseMasterVolume = service.getContext().getResources().getBoolean(
                com.android.internal.R.bool.config_useMasterVolume);
    }

    /**
@@ -248,6 +251,12 @@ public class MediaSessionRecord implements IBinder.DeathRecipient {
            direction = -1;
        }
        if (mVolumeType == PlaybackInfo.PLAYBACK_TYPE_LOCAL) {
            if (mUseMasterVolume) {
                // If this device only uses master volume and playback is local
                // just adjust the master volume and return.
                mAudioManagerInternal.adjustMasterVolumeForUid(direction, flags, packageName, uid);
                return;
            }
            int stream = AudioAttributes.toLegacyStreamType(mAudioAttrs);
            if (useSuggested) {
                if (AudioSystem.isStreamActive(stream, 0)) {
+10 −2
Original line number Diff line number Diff line
@@ -86,6 +86,7 @@ public class MediaSessionService extends SystemService implements Monitor {
    private final Object mLock = new Object();
    private final MessageHandler mHandler = new MessageHandler();
    private final PowerManager.WakeLock mMediaEventWakeLock;
    private final boolean mUseMasterVolume;

    private KeyguardManager mKeyguardManager;
    private IAudioService mAudioService;
@@ -104,6 +105,8 @@ public class MediaSessionService extends SystemService implements Monitor {
        mPriorityStack = new MediaSessionStack();
        PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
        mMediaEventWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "handleMediaEvent");
        mUseMasterVolume = context.getResources().getBoolean(
                com.android.internal.R.bool.config_useMasterVolume);
    }

    @Override
@@ -819,8 +822,13 @@ public class MediaSessionService extends SystemService implements Monitor {
                    return;
                }
                try {
                    if (mUseMasterVolume) {
                        mAudioService.adjustMasterVolume(direction, flags,
                                getContext().getOpPackageName());
                    } else {
                        mAudioService.adjustSuggestedStreamVolume(direction, suggestedStream, flags,
                                getContext().getOpPackageName());
                    }
                } catch (RemoteException e) {
                    Log.e(TAG, "Error adjusting default volume.", e);
                }