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

Commit 1a3415e0 authored by Bishoy Gendy's avatar Bishoy Gendy
Browse files

Fix volume slider not showing when casting in the background

- Modify MediaSessionRecord.canHandleVolume() to check system flag and
prevent non system group routes and session records with no routing
sessions from receiving volume evenets.

Bug: 278071711
Test: Manually using 1P and 3P apps on single / group speakers.
Change-Id: I22f53994bd25509c6d6f8c5761304d2dca9c4e8d
parent be4b8621
Loading
Loading
Loading
Loading
+30 −1
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.server.media;

import static android.media.MediaRoute2Info.PLAYBACK_VOLUME_FIXED;
import static android.media.VolumeProvider.VOLUME_CONTROL_ABSOLUTE;
import static android.media.VolumeProvider.VOLUME_CONTROL_FIXED;
import static android.media.VolumeProvider.VOLUME_CONTROL_RELATIVE;
@@ -44,7 +45,9 @@ import android.media.AudioAttributes;
import android.media.AudioManager;
import android.media.AudioSystem;
import android.media.MediaMetadata;
import android.media.MediaRouter2Manager;
import android.media.Rating;
import android.media.RoutingSessionInfo;
import android.media.VolumeProvider;
import android.media.session.ISession;
import android.media.session.ISessionCallback;
@@ -510,7 +513,33 @@ public class MediaSessionRecord implements IBinder.DeathRecipient, MediaSessionR

    @Override
    public boolean canHandleVolumeKey() {
        return mVolumeControlType != VOLUME_CONTROL_FIXED;
        if (isPlaybackTypeLocal()) {
            return true;
        }
        if (mVolumeControlType == VOLUME_CONTROL_FIXED) {
            return false;
        }
        if (mVolumeAdjustmentForRemoteGroupSessions) {
            return true;
        }
        // See b/228021646 for details.
        MediaRouter2Manager mRouter2Manager = MediaRouter2Manager.getInstance(mContext);
        List<RoutingSessionInfo> sessions = mRouter2Manager.getRoutingSessions(mPackageName);
        boolean foundNonSystemSession = false;
        boolean remoteSessionAllowVolumeAdjustment = true;
        for (RoutingSessionInfo session : sessions) {
            if (!session.isSystemSession()) {
                foundNonSystemSession = true;
                if (session.getVolumeHandling() == PLAYBACK_VOLUME_FIXED) {
                    remoteSessionAllowVolumeAdjustment = false;
                }
            }
        }
        if (!foundNonSystemSession) {
            Log.d(TAG, "Package " + mPackageName
                    + " has a remote media session but no associated routing session");
        }
        return foundNonSystemSession && remoteSessionAllowVolumeAdjustment;
    }

    @Override