Merge "Add volume control id to MediaSessionRecord.dump" into udc-dev am: 4604f651ec

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

Change-Id: I45f54977ac1414391c904b6355043dd8bd63ed77
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Treehugger Robot
2023-05-03 10:39:04 +00:00
committed by Automerger Merge Worker

View File

@@ -16,6 +16,12 @@
package com.android.server.media; package com.android.server.media;
import static android.media.VolumeProvider.VOLUME_CONTROL_ABSOLUTE;
import static android.media.VolumeProvider.VOLUME_CONTROL_FIXED;
import static android.media.VolumeProvider.VOLUME_CONTROL_RELATIVE;
import static android.media.session.MediaController.PlaybackInfo.PLAYBACK_TYPE_LOCAL;
import static android.media.session.MediaController.PlaybackInfo.PLAYBACK_TYPE_REMOTE;
import android.Manifest; import android.Manifest;
import android.annotation.NonNull; import android.annotation.NonNull;
import android.annotation.Nullable; import android.annotation.Nullable;
@@ -173,8 +179,8 @@ public class MediaSessionRecord implements IBinder.DeathRecipient, MediaSessionR
// Volume handling fields // Volume handling fields
private AudioAttributes mAudioAttrs; private AudioAttributes mAudioAttrs;
private AudioManager mAudioManager; private AudioManager mAudioManager;
private int mVolumeType = PlaybackInfo.PLAYBACK_TYPE_LOCAL; private int mVolumeType = PLAYBACK_TYPE_LOCAL;
private int mVolumeControlType = VolumeProvider.VOLUME_CONTROL_ABSOLUTE; private int mVolumeControlType = VOLUME_CONTROL_ABSOLUTE;
private int mMaxVolume = 0; private int mMaxVolume = 0;
private int mCurrentVolume = 0; private int mCurrentVolume = 0;
private int mOptimisticVolume = -1; private int mOptimisticVolume = -1;
@@ -309,13 +315,13 @@ public class MediaSessionRecord implements IBinder.DeathRecipient, MediaSessionR
if (checkPlaybackActiveState(true) || isSystemPriority()) { if (checkPlaybackActiveState(true) || isSystemPriority()) {
flags &= ~AudioManager.FLAG_PLAY_SOUND; flags &= ~AudioManager.FLAG_PLAY_SOUND;
} }
if (mVolumeType == PlaybackInfo.PLAYBACK_TYPE_LOCAL) { if (mVolumeType == PLAYBACK_TYPE_LOCAL) {
// Adjust the volume with a handler not to be blocked by other system service. // Adjust the volume with a handler not to be blocked by other system service.
int stream = getVolumeStream(mAudioAttrs); int stream = getVolumeStream(mAudioAttrs);
postAdjustLocalVolume(stream, direction, flags, opPackageName, pid, uid, postAdjustLocalVolume(stream, direction, flags, opPackageName, pid, uid,
asSystemService, useSuggested, previousFlagPlaySound); asSystemService, useSuggested, previousFlagPlaySound);
} else { } else {
if (mVolumeControlType == VolumeProvider.VOLUME_CONTROL_FIXED) { if (mVolumeControlType == VOLUME_CONTROL_FIXED) {
if (DEBUG) { if (DEBUG) {
Log.d(TAG, "Session does not support volume adjustment"); Log.d(TAG, "Session does not support volume adjustment");
} }
@@ -354,7 +360,7 @@ public class MediaSessionRecord implements IBinder.DeathRecipient, MediaSessionR
private void setVolumeTo(String packageName, String opPackageName, int pid, int uid, int value, private void setVolumeTo(String packageName, String opPackageName, int pid, int uid, int value,
int flags) { int flags) {
if (mVolumeType == PlaybackInfo.PLAYBACK_TYPE_LOCAL) { if (mVolumeType == PLAYBACK_TYPE_LOCAL) {
int stream = getVolumeStream(mAudioAttrs); int stream = getVolumeStream(mAudioAttrs);
final int volumeValue = value; final int volumeValue = value;
mHandler.post(new Runnable() { mHandler.post(new Runnable() {
@@ -371,7 +377,7 @@ public class MediaSessionRecord implements IBinder.DeathRecipient, MediaSessionR
} }
}); });
} else { } else {
if (mVolumeControlType != VolumeProvider.VOLUME_CONTROL_ABSOLUTE) { if (mVolumeControlType != VOLUME_CONTROL_ABSOLUTE) {
if (DEBUG) { if (DEBUG) {
Log.d(TAG, "Session does not support setting volume"); Log.d(TAG, "Session does not support setting volume");
} }
@@ -433,7 +439,7 @@ public class MediaSessionRecord implements IBinder.DeathRecipient, MediaSessionR
*/ */
@Override @Override
public boolean isPlaybackTypeLocal() { public boolean isPlaybackTypeLocal() {
return mVolumeType == PlaybackInfo.PLAYBACK_TYPE_LOCAL; return mVolumeType == PLAYBACK_TYPE_LOCAL;
} }
@Override @Override
@@ -495,7 +501,7 @@ public class MediaSessionRecord implements IBinder.DeathRecipient, MediaSessionR
@Override @Override
public boolean canHandleVolumeKey() { public boolean canHandleVolumeKey() {
return mVolumeControlType != VolumeProvider.VOLUME_CONTROL_FIXED; return mVolumeControlType != VOLUME_CONTROL_FIXED;
} }
@Override @Override
@@ -528,13 +534,48 @@ public class MediaSessionRecord implements IBinder.DeathRecipient, MediaSessionR
pw.println(indent + "controllers: " + mControllerCallbackHolders.size()); pw.println(indent + "controllers: " + mControllerCallbackHolders.size());
pw.println(indent + "state=" + (mPlaybackState == null ? null : mPlaybackState.toString())); pw.println(indent + "state=" + (mPlaybackState == null ? null : mPlaybackState.toString()));
pw.println(indent + "audioAttrs=" + mAudioAttrs); pw.println(indent + "audioAttrs=" + mAudioAttrs);
pw.println(indent + "volumeType=" + mVolumeType + ", controlType=" + mVolumeControlType pw.append(indent)
+ ", max=" + mMaxVolume + ", current=" + mCurrentVolume); .append("volumeType=")
.append(toVolumeTypeString(mVolumeType))
.append(", controlType=")
.append(toVolumeControlTypeString(mVolumeControlType))
.append(", max=")
.append(Integer.toString(mMaxVolume))
.append(", current=")
.append(Integer.toString(mCurrentVolume))
.append(", volumeControlId=")
.append(mVolumeControlId)
.println();
pw.println(indent + "metadata: " + mMetadataDescription); pw.println(indent + "metadata: " + mMetadataDescription);
pw.println(indent + "queueTitle=" + mQueueTitle + ", size=" pw.println(indent + "queueTitle=" + mQueueTitle + ", size="
+ (mQueue == null ? 0 : mQueue.size())); + (mQueue == null ? 0 : mQueue.size()));
} }
private static String toVolumeControlTypeString(
@VolumeProvider.ControlType int volumeControlType) {
switch (volumeControlType) {
case VOLUME_CONTROL_FIXED:
return "FIXED";
case VOLUME_CONTROL_RELATIVE:
return "RELATIVE";
case VOLUME_CONTROL_ABSOLUTE:
return "ABSOLUTE";
default:
return TextUtils.formatSimple("unknown(%d)", volumeControlType);
}
}
private static String toVolumeTypeString(@PlaybackInfo.PlaybackType int volumeType) {
switch (volumeType) {
case PLAYBACK_TYPE_LOCAL:
return "LOCAL";
case PLAYBACK_TYPE_REMOTE:
return "REMOTE";
default:
return TextUtils.formatSimple("unknown(%d)", volumeType);
}
}
@Override @Override
public String toString() { public String toString() {
return mPackageName + "/" + mTag + " (userId=" + mUserId + ")"; return mPackageName + "/" + mTag + " (userId=" + mUserId + ")";
@@ -877,8 +918,8 @@ public class MediaSessionRecord implements IBinder.DeathRecipient, MediaSessionR
int stream = getVolumeStream(attributes); int stream = getVolumeStream(attributes);
int max = mAudioManager.getStreamMaxVolume(stream); int max = mAudioManager.getStreamMaxVolume(stream);
int current = mAudioManager.getStreamVolume(stream); int current = mAudioManager.getStreamVolume(stream);
return new PlaybackInfo(volumeType, VolumeProvider.VOLUME_CONTROL_ABSOLUTE, max, return new PlaybackInfo(
current, attributes, null); volumeType, VOLUME_CONTROL_ABSOLUTE, max, current, attributes, null);
} }
private final Runnable mClearOptimisticVolumeRunnable = new Runnable() { private final Runnable mClearOptimisticVolumeRunnable = new Runnable() {
@@ -1124,7 +1165,7 @@ public class MediaSessionRecord implements IBinder.DeathRecipient, MediaSessionR
boolean typeChanged; boolean typeChanged;
synchronized (mLock) { synchronized (mLock) {
typeChanged = mVolumeType == PlaybackInfo.PLAYBACK_TYPE_REMOTE; typeChanged = mVolumeType == PlaybackInfo.PLAYBACK_TYPE_REMOTE;
mVolumeType = PlaybackInfo.PLAYBACK_TYPE_LOCAL; mVolumeType = PLAYBACK_TYPE_LOCAL;
mVolumeControlId = null; mVolumeControlId = null;
if (attributes != null) { if (attributes != null) {
mAudioAttrs = attributes; mAudioAttrs = attributes;
@@ -1148,7 +1189,7 @@ public class MediaSessionRecord implements IBinder.DeathRecipient, MediaSessionR
throws RemoteException { throws RemoteException {
boolean typeChanged; boolean typeChanged;
synchronized (mLock) { synchronized (mLock) {
typeChanged = mVolumeType == PlaybackInfo.PLAYBACK_TYPE_LOCAL; typeChanged = mVolumeType == PLAYBACK_TYPE_LOCAL;
mVolumeType = PlaybackInfo.PLAYBACK_TYPE_REMOTE; mVolumeType = PlaybackInfo.PLAYBACK_TYPE_REMOTE;
mVolumeControlType = control; mVolumeControlType = control;
mMaxVolume = max; mMaxVolume = max;