Merge "Fix SysUI volume controls not appearing" into sc-dev

This commit is contained in:
Oliver Woodman
2021-11-22 20:33:14 +00:00
committed by Android (Google) Code Review

View File

@@ -291,35 +291,39 @@ 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); }
} mSessionCb.adjustVolume(packageName, pid, uid, asSystemService, direction);
mSessionCb.adjustVolume(packageName, pid, uid, asSystemService, direction);
int volumeBefore = (mOptimisticVolume < 0 ? mCurrentVolume : mOptimisticVolume); int volumeBefore = (mOptimisticVolume < 0 ? mCurrentVolume : mOptimisticVolume);
mOptimisticVolume = volumeBefore + direction; mOptimisticVolume = volumeBefore + direction;
mOptimisticVolume = Math.max(0, Math.min(mOptimisticVolume, mMaxVolume)); mOptimisticVolume = Math.max(0, Math.min(mOptimisticVolume, mMaxVolume));
mHandler.removeCallbacks(mClearOptimisticVolumeRunnable); mHandler.removeCallbacks(mClearOptimisticVolumeRunnable);
mHandler.postDelayed(mClearOptimisticVolumeRunnable, OPTIMISTIC_VOLUME_TIMEOUT); mHandler.postDelayed(mClearOptimisticVolumeRunnable, OPTIMISTIC_VOLUME_TIMEOUT);
if (volumeBefore != mOptimisticVolume) { if (volumeBefore != mOptimisticVolume) {
pushVolumeUpdate(); pushVolumeUpdate();
}
if (DEBUG) {
Log.d(TAG, "Adjusted optimistic volume to " + mOptimisticVolume + " max is "
+ 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); mService.notifyRemoteVolumeChanged(flags, this);
if (DEBUG) {
Log.d(TAG, "Adjusted optimistic volume to " + mOptimisticVolume + " max is "
+ mMaxVolume);
}
} }
} }
@@ -343,25 +347,28 @@ 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");
} }
value = Math.max(0, Math.min(value, mMaxVolume)); } else {
mSessionCb.setVolumeTo(packageName, pid, uid, value); value = Math.max(0, Math.min(value, mMaxVolume));
mSessionCb.setVolumeTo(packageName, pid, uid, value);
int volumeBefore = (mOptimisticVolume < 0 ? mCurrentVolume : mOptimisticVolume); int volumeBefore = (mOptimisticVolume < 0 ? mCurrentVolume : mOptimisticVolume);
mOptimisticVolume = Math.max(0, Math.min(value, mMaxVolume)); mOptimisticVolume = Math.max(0, Math.min(value, mMaxVolume));
mHandler.removeCallbacks(mClearOptimisticVolumeRunnable); mHandler.removeCallbacks(mClearOptimisticVolumeRunnable);
mHandler.postDelayed(mClearOptimisticVolumeRunnable, OPTIMISTIC_VOLUME_TIMEOUT); mHandler.postDelayed(mClearOptimisticVolumeRunnable, OPTIMISTIC_VOLUME_TIMEOUT);
if (volumeBefore != mOptimisticVolume) { if (volumeBefore != mOptimisticVolume) {
pushVolumeUpdate(); pushVolumeUpdate();
}
if (DEBUG) {
Log.d(TAG, "Set optimistic volume to " + mOptimisticVolume + " max is "
+ mMaxVolume);
}
} }
// Always notify, even if the volume hasn't changed.
mService.notifyRemoteVolumeChanged(flags, this); mService.notifyRemoteVolumeChanged(flags, this);
if (DEBUG) {
Log.d(TAG, "Set optimistic volume to " + mOptimisticVolume + " max is "
+ mMaxVolume);
}
} }
} }