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

This commit is contained in:
Bishoy Gendy
2023-06-22 07:50:50 +00:00
committed by Android (Google) Code Review

View File

@@ -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