Merge "Handle volume events on master volume devices correctly" into lmp-mr1-dev
This commit is contained in:
@ -35,4 +35,7 @@ public abstract class AudioManagerInternal {
|
|||||||
|
|
||||||
public abstract void setStreamVolumeForUid(int streamType, int direction, int flags,
|
public abstract void setStreamVolumeForUid(int streamType, int direction, int flags,
|
||||||
String callingPackage, int uid);
|
String callingPackage, int uid);
|
||||||
|
|
||||||
|
public abstract void adjustMasterVolumeForUid(int steps, int flags, String callingPackage,
|
||||||
|
int uid);
|
||||||
}
|
}
|
||||||
|
@ -50,7 +50,6 @@ import android.media.MediaPlayer.OnCompletionListener;
|
|||||||
import android.media.MediaPlayer.OnErrorListener;
|
import android.media.MediaPlayer.OnErrorListener;
|
||||||
import android.media.audiopolicy.AudioMix;
|
import android.media.audiopolicy.AudioMix;
|
||||||
import android.media.audiopolicy.AudioPolicyConfig;
|
import android.media.audiopolicy.AudioPolicyConfig;
|
||||||
import android.media.session.MediaSessionLegacyHelper;
|
|
||||||
import android.os.Binder;
|
import android.os.Binder;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
@ -61,7 +60,6 @@ import android.os.Message;
|
|||||||
import android.os.PowerManager;
|
import android.os.PowerManager;
|
||||||
import android.os.RemoteCallbackList;
|
import android.os.RemoteCallbackList;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.os.ServiceManager;
|
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
import android.os.SystemProperties;
|
import android.os.SystemProperties;
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
@ -75,12 +73,11 @@ import android.util.Log;
|
|||||||
import android.util.MathUtils;
|
import android.util.MathUtils;
|
||||||
import android.util.Slog;
|
import android.util.Slog;
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
|
import android.view.OrientationEventListener;
|
||||||
import android.view.Surface;
|
import android.view.Surface;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
import android.view.accessibility.AccessibilityManager;
|
import android.view.accessibility.AccessibilityManager;
|
||||||
import android.view.OrientationEventListener;
|
|
||||||
|
|
||||||
import com.android.internal.telephony.ITelephony;
|
|
||||||
import com.android.internal.util.XmlUtils;
|
import com.android.internal.util.XmlUtils;
|
||||||
import com.android.server.LocalServices;
|
import com.android.server.LocalServices;
|
||||||
|
|
||||||
@ -91,8 +88,6 @@ import java.io.IOException;
|
|||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -100,6 +95,7 @@ import java.util.Map;
|
|||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The implementation of the volume manager service.
|
* The implementation of the volume manager service.
|
||||||
@ -1152,6 +1148,10 @@ public class AudioService extends IAudioService.Stub {
|
|||||||
|
|
||||||
/** @see AudioManager#adjustMasterVolume(int, int) */
|
/** @see AudioManager#adjustMasterVolume(int, int) */
|
||||||
public void adjustMasterVolume(int steps, int flags, String callingPackage) {
|
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) {
|
if (mUseFixedVolume) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -1166,7 +1166,7 @@ public class AudioService extends IAudioService.Stub {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Log.d(TAG, "adjustMasterVolume volume: " + volume + " steps: " + steps);
|
//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
|
// StreamVolumeCommand contains the information needed to defer the process of
|
||||||
@ -1679,18 +1679,24 @@ public class AudioService extends IAudioService.Stub {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public int getMasterVolume() {
|
public int getMasterVolume() {
|
||||||
if (isMasterMute()) return 0;
|
if (isMasterMute()) return 0;
|
||||||
return getLastAudibleMasterVolume();
|
return getLastAudibleMasterVolume();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void setMasterVolume(int volume, int flags, String callingPackage) {
|
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) {
|
if (mUseFixedVolume) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mAppOps.noteOp(AppOpsManager.OP_AUDIO_MASTER_VOLUME, Binder.getCallingUid(),
|
if (mAppOps.noteOp(AppOpsManager.OP_AUDIO_MASTER_VOLUME, uid, callingPackage)
|
||||||
callingPackage) != AppOpsManager.MODE_ALLOWED) {
|
!= AppOpsManager.MODE_ALLOWED) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -5667,6 +5673,12 @@ public class AudioService extends IAudioService.Stub {
|
|||||||
String callingPackage, int uid) {
|
String callingPackage, int uid) {
|
||||||
setStreamVolume(streamType, direction, flags, callingPackage, uid);
|
setStreamVolume(streamType, direction, flags, callingPackage, uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void adjustMasterVolumeForUid(int steps, int flags, String callingPackage,
|
||||||
|
int uid) {
|
||||||
|
adjustMasterVolume(steps, flags, callingPackage, uid);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//==========================================================================================
|
//==========================================================================================
|
||||||
|
@ -90,6 +90,7 @@ public class MediaSessionRecord implements IBinder.DeathRecipient {
|
|||||||
private final SessionStub mSession;
|
private final SessionStub mSession;
|
||||||
private final SessionCb mSessionCb;
|
private final SessionCb mSessionCb;
|
||||||
private final MediaSessionService mService;
|
private final MediaSessionService mService;
|
||||||
|
private final boolean mUseMasterVolume;
|
||||||
|
|
||||||
private final Object mLock = new Object();
|
private final Object mLock = new Object();
|
||||||
private final ArrayList<ISessionControllerCallback> mControllerCallbacks =
|
private final ArrayList<ISessionControllerCallback> mControllerCallbacks =
|
||||||
@ -139,6 +140,8 @@ public class MediaSessionRecord implements IBinder.DeathRecipient {
|
|||||||
mAudioManager = (AudioManager) service.getContext().getSystemService(Context.AUDIO_SERVICE);
|
mAudioManager = (AudioManager) service.getContext().getSystemService(Context.AUDIO_SERVICE);
|
||||||
mAudioManagerInternal = LocalServices.getService(AudioManagerInternal.class);
|
mAudioManagerInternal = LocalServices.getService(AudioManagerInternal.class);
|
||||||
mAudioAttrs = new AudioAttributes.Builder().setUsage(AudioAttributes.USAGE_MEDIA).build();
|
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;
|
direction = -1;
|
||||||
}
|
}
|
||||||
if (mVolumeType == PlaybackInfo.PLAYBACK_TYPE_LOCAL) {
|
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);
|
int stream = AudioAttributes.toLegacyStreamType(mAudioAttrs);
|
||||||
if (useSuggested) {
|
if (useSuggested) {
|
||||||
if (AudioSystem.isStreamActive(stream, 0)) {
|
if (AudioSystem.isStreamActive(stream, 0)) {
|
||||||
|
@ -86,6 +86,7 @@ public class MediaSessionService extends SystemService implements Monitor {
|
|||||||
private final Object mLock = new Object();
|
private final Object mLock = new Object();
|
||||||
private final MessageHandler mHandler = new MessageHandler();
|
private final MessageHandler mHandler = new MessageHandler();
|
||||||
private final PowerManager.WakeLock mMediaEventWakeLock;
|
private final PowerManager.WakeLock mMediaEventWakeLock;
|
||||||
|
private final boolean mUseMasterVolume;
|
||||||
|
|
||||||
private KeyguardManager mKeyguardManager;
|
private KeyguardManager mKeyguardManager;
|
||||||
private IAudioService mAudioService;
|
private IAudioService mAudioService;
|
||||||
@ -104,6 +105,8 @@ public class MediaSessionService extends SystemService implements Monitor {
|
|||||||
mPriorityStack = new MediaSessionStack();
|
mPriorityStack = new MediaSessionStack();
|
||||||
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
|
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
|
||||||
mMediaEventWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "handleMediaEvent");
|
mMediaEventWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "handleMediaEvent");
|
||||||
|
mUseMasterVolume = context.getResources().getBoolean(
|
||||||
|
com.android.internal.R.bool.config_useMasterVolume);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -819,8 +822,13 @@ public class MediaSessionService extends SystemService implements Monitor {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
mAudioService.adjustSuggestedStreamVolume(direction, suggestedStream, flags,
|
if (mUseMasterVolume) {
|
||||||
getContext().getOpPackageName());
|
mAudioService.adjustMasterVolume(direction, flags,
|
||||||
|
getContext().getOpPackageName());
|
||||||
|
} else {
|
||||||
|
mAudioService.adjustSuggestedStreamVolume(direction, suggestedStream, flags,
|
||||||
|
getContext().getOpPackageName());
|
||||||
|
}
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
Log.e(TAG, "Error adjusting default volume.", e);
|
Log.e(TAG, "Error adjusting default volume.", e);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user