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

Commit f96e49ed authored by Bishoy Gendy's avatar Bishoy Gendy Committed by Android (Google) Code Review
Browse files

Merge "Fix volume slider not showing when casting in the background" into udc-dev

parents 3276bd97 1a3415e0
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