Merge "Fix SysUI volume controls not appearing" into sc-dev am: adc5f9571f am: 66ad53f958

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/16286398

Change-Id: If987800466c4f267ff09884f6452f673a7b9bd82
This commit is contained in:
Oliver Woodman
2021-11-22 21:09:59 +00:00
committed by Automerger Merge Worker

View File

@@ -291,15 +291,14 @@ public class MediaSessionRecord implements IBinder.DeathRecipient, MediaSessionR
asSystemService, useSuggested, previousFlagPlaySound); asSystemService, useSuggested, previousFlagPlaySound);
} else { } else {
if (mVolumeControlType == VolumeProvider.VOLUME_CONTROL_FIXED) { if (mVolumeControlType == VolumeProvider.VOLUME_CONTROL_FIXED) {
// Nothing to do, the volume cannot be changed if (DEBUG) {
return; Log.d(TAG, "Session does not support volume adjustment");
} }
if (direction == AudioManager.ADJUST_TOGGLE_MUTE } else if (direction == AudioManager.ADJUST_TOGGLE_MUTE
|| direction == AudioManager.ADJUST_MUTE || direction == AudioManager.ADJUST_MUTE
|| direction == AudioManager.ADJUST_UNMUTE) { || direction == AudioManager.ADJUST_UNMUTE) {
Log.w(TAG, "Muting remote playback is not supported"); Log.w(TAG, "Muting remote playback is not supported");
return; } else {
}
if (DEBUG) { if (DEBUG) {
Log.w(TAG, "adjusting volume, pkg=" + packageName + ", asSystemService=" Log.w(TAG, "adjusting volume, pkg=" + packageName + ", asSystemService="
+ asSystemService + ", dir=" + direction); + asSystemService + ", dir=" + direction);
@@ -314,13 +313,18 @@ public class MediaSessionRecord implements IBinder.DeathRecipient, MediaSessionR
if (volumeBefore != mOptimisticVolume) { if (volumeBefore != mOptimisticVolume) {
pushVolumeUpdate(); pushVolumeUpdate();
} }
mService.notifyRemoteVolumeChanged(flags, this);
if (DEBUG) { if (DEBUG) {
Log.d(TAG, "Adjusted optimistic volume to " + mOptimisticVolume + " max is " Log.d(TAG, "Adjusted optimistic volume to " + mOptimisticVolume + " max is "
+ mMaxVolume); + mMaxVolume);
} }
} }
// Always notify, even if the volume hasn't changed. This is important to ensure that
// System UI receives an event if a hardware volume key is pressed but the session that
// handles it does not allow volume adjustment. Without such an event, System UI would
// not show volume controls to the user.
mService.notifyRemoteVolumeChanged(flags, this);
}
} }
private void setVolumeTo(String packageName, String opPackageName, int pid, int uid, int value, private void setVolumeTo(String packageName, String opPackageName, int pid, int uid, int value,
@@ -343,9 +347,10 @@ public class MediaSessionRecord implements IBinder.DeathRecipient, MediaSessionR
}); });
} else { } else {
if (mVolumeControlType != VolumeProvider.VOLUME_CONTROL_ABSOLUTE) { if (mVolumeControlType != VolumeProvider.VOLUME_CONTROL_ABSOLUTE) {
// Nothing to do. The volume can't be set directly. if (DEBUG) {
return; Log.d(TAG, "Session does not support setting volume");
} }
} else {
value = Math.max(0, Math.min(value, mMaxVolume)); value = Math.max(0, Math.min(value, mMaxVolume));
mSessionCb.setVolumeTo(packageName, pid, uid, value); mSessionCb.setVolumeTo(packageName, pid, uid, value);
@@ -356,13 +361,15 @@ public class MediaSessionRecord implements IBinder.DeathRecipient, MediaSessionR
if (volumeBefore != mOptimisticVolume) { if (volumeBefore != mOptimisticVolume) {
pushVolumeUpdate(); pushVolumeUpdate();
} }
mService.notifyRemoteVolumeChanged(flags, this);
if (DEBUG) { if (DEBUG) {
Log.d(TAG, "Set optimistic volume to " + mOptimisticVolume + " max is " Log.d(TAG, "Set optimistic volume to " + mOptimisticVolume + " max is "
+ mMaxVolume); + mMaxVolume);
} }
} }
// Always notify, even if the volume hasn't changed.
mService.notifyRemoteVolumeChanged(flags, this);
}
} }
/** /**