Don't unmute when trying to show volume UI. DO NOT MERGE

When a MediaSession is active the adjust volume event to show UI was
causing the stream to be unmuted. Since this happens after every mute
event you were unable to mute while a session was active. This change
doesn't unmute for events that just show the UI.

bug:18844550
Change-Id: Ic8b0f1ab1354646724ead4572a973c302c275eab
This commit is contained in:
RoboErik
2015-01-07 11:10:23 -08:00
committed by Erik Pasternak
parent f61bc8a262
commit 2610d71251
2 changed files with 11 additions and 10 deletions

View File

@@ -93,7 +93,6 @@ public class MediaSessionRecord implements IBinder.DeathRecipient {
private final MediaSessionService mService;
private final boolean mUseMasterVolume;
private final IBinder mICallback = new Binder();
private final Object mLock = new Object();
private final ArrayList<ISessionControllerCallback> mControllerCallbacks =
new ArrayList<ISessionControllerCallback>();
@@ -260,13 +259,13 @@ public class MediaSessionRecord implements IBinder.DeathRecipient {
boolean isMasterMute = mAudioManager.isMasterMute();
if (isMute) {
mAudioManagerInternal.setMasterMuteForUid(!isMasterMute,
flags, packageName, mICallback, uid);
flags, packageName, mService.mICallback, uid);
} else {
mAudioManagerInternal.adjustMasterVolumeForUid(direction, flags, packageName,
uid);
if (isMasterMute) {
mAudioManagerInternal.setMasterMuteForUid(false,
flags, packageName, mICallback, uid);
flags, packageName, mService.mICallback, uid);
}
}
return;
@@ -280,7 +279,7 @@ public class MediaSessionRecord implements IBinder.DeathRecipient {
} else {
mAudioManagerInternal.adjustSuggestedStreamVolumeForUid(stream, direction,
flags, packageName, uid);
if (isStreamMute) {
if (isStreamMute && direction != 0) {
mAudioManager.setStreamMute(stream, false);
}
}
@@ -295,7 +294,7 @@ public class MediaSessionRecord implements IBinder.DeathRecipient {
mAudioManagerInternal.adjustSuggestedStreamVolumeForUid(
AudioManager.USE_DEFAULT_STREAM_TYPE, direction, flags, packageName,
uid);
if (isStreamMute) {
if (isStreamMute && direction != 0) {
mAudioManager.setStreamMute(AudioManager.USE_DEFAULT_STREAM_TYPE,
false);
}
@@ -307,7 +306,7 @@ public class MediaSessionRecord implements IBinder.DeathRecipient {
} else {
mAudioManagerInternal.adjustStreamVolumeForUid(stream, direction, flags,
packageName, uid);
if (isStreamMute) {
if (isStreamMute && direction != 0) {
mAudioManager.setStreamMute(stream, false);
}
}

View File

@@ -77,6 +77,8 @@ public class MediaSessionService extends SystemService implements Monitor {
private static final int WAKELOCK_TIMEOUT = 5000;
/* package */final IBinder mICallback = new Binder();
private final SessionManagerImpl mSessionManagerImpl;
private final MediaSessionStack mPriorityStack;
@@ -91,6 +93,7 @@ public class MediaSessionService extends SystemService implements Monitor {
private KeyguardManager mKeyguardManager;
private IAudioService mAudioService;
private AudioManager mAudioManager;
private ContentResolver mContentResolver;
private SettingsObserver mSettingsObserver;
@@ -118,6 +121,7 @@ public class MediaSessionService extends SystemService implements Monitor {
mKeyguardManager =
(KeyguardManager) getContext().getSystemService(Context.KEYGUARD_SERVICE);
mAudioService = getAudioService();
mAudioManager = (AudioManager) getContext().getSystemService(Context.AUDIO_SERVICE);
mContentResolver = getContext().getContentResolver();
mSettingsObserver = new SettingsObserver();
mSettingsObserver.observe();
@@ -589,8 +593,6 @@ public class MediaSessionService extends SystemService implements Monitor {
"android.media.AudioService.WAKELOCK_ACQUIRED";
private static final int WAKELOCK_RELEASE_ON_FINISHED = 1980; // magic number
private final IBinder mICallback = new Binder();
private boolean mVoiceButtonDown = false;
private boolean mVoiceButtonHandled = false;
@@ -845,14 +847,14 @@ public class MediaSessionService extends SystemService implements Monitor {
} else {
boolean isStreamMute = mAudioService.isStreamMute(suggestedStream);
if (direction == MediaSessionManager.DIRECTION_MUTE) {
mAudioService.setStreamMute(suggestedStream, !isStreamMute, mICallback);
mAudioManager.setStreamMute(suggestedStream, !isStreamMute);
} else {
mAudioService.adjustSuggestedStreamVolume(direction, suggestedStream,
flags, packageName);
// Do not call setStreamMute when direction = 0 which is used just to
// show the UI.
if (isStreamMute && direction != 0) {
mAudioService.setStreamMute(suggestedStream, false, mICallback);
mAudioManager.setStreamMute(suggestedStream, false);
}
}
}