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

Commit d0bce501 authored by Oliver Woodman's avatar Oliver Woodman Committed by Automerger Merge Worker
Browse files

Merge "Fix SysUI volume controls not appearing" into sc-dev am: adc5f957 am: 66ad53f9

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

Change-Id: If987800466c4f267ff09884f6452f673a7b9bd82
parents 59c6401d 66ad53f9
Loading
Loading
Loading
Loading
+46 −39
Original line number Diff line number Diff line
@@ -291,15 +291,14 @@ public class MediaSessionRecord implements IBinder.DeathRecipient, MediaSessionR
                    asSystemService, useSuggested, previousFlagPlaySound);
        } else {
            if (mVolumeControlType == VolumeProvider.VOLUME_CONTROL_FIXED) {
                // Nothing to do, the volume cannot be changed
                return;
                if (DEBUG) {
                    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_UNMUTE) {
                Log.w(TAG, "Muting remote playback is not supported");
                return;
            }
            } else {
                if (DEBUG) {
                    Log.w(TAG, "adjusting volume, pkg=" + packageName + ", asSystemService="
                            + asSystemService + ", dir=" + direction);
@@ -314,13 +313,18 @@ public class MediaSessionRecord implements IBinder.DeathRecipient, MediaSessionR
                if (volumeBefore != mOptimisticVolume) {
                    pushVolumeUpdate();
                }
            mService.notifyRemoteVolumeChanged(flags, this);

                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);
        }
    }

    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 {
            if (mVolumeControlType != VolumeProvider.VOLUME_CONTROL_ABSOLUTE) {
                // Nothing to do. The volume can't be set directly.
                return;
                if (DEBUG) {
                    Log.d(TAG, "Session does not support setting volume");
                }
            } else {
                value = Math.max(0, Math.min(value, mMaxVolume));
                mSessionCb.setVolumeTo(packageName, pid, uid, value);

@@ -356,13 +361,15 @@ public class MediaSessionRecord implements IBinder.DeathRecipient, MediaSessionR
                if (volumeBefore != mOptimisticVolume) {
                    pushVolumeUpdate();
                }
            mService.notifyRemoteVolumeChanged(flags, this);

                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);
        }
    }

    /**