summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Treehugger Robot <android-test-infra-autosubmit@system.gserviceaccount.com> 2023-05-03 10:39:08 +0000
committer Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> 2023-05-03 10:39:08 +0000
commitf5bc172c3a77b0d9d54f60c2035a49f90a55b52b (patch)
treea77d740fbefb9bf99a0733193720b69eb8a99bfd
parent2287fc55a1d79fb41bd9bff7af23c55b0a6f1a10 (diff)
parent4604f651ec338ae316285894633244a560e6b1d9 (diff)
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: Iab659b6bd99602243bc5e0342dd7990a05114bb1 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r--services/core/java/com/android/server/media/MediaSessionRecord.java69
1 files changed, 55 insertions, 14 deletions
diff --git a/services/core/java/com/android/server/media/MediaSessionRecord.java b/services/core/java/com/android/server/media/MediaSessionRecord.java
index 464a256bd30e..02b705344cb9 100644
--- a/services/core/java/com/android/server/media/MediaSessionRecord.java
+++ b/services/core/java/com/android/server/media/MediaSessionRecord.java
@@ -16,6 +16,12 @@
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.annotation.NonNull;
import android.annotation.Nullable;
@@ -173,8 +179,8 @@ public class MediaSessionRecord implements IBinder.DeathRecipient, MediaSessionR
// Volume handling fields
private AudioAttributes mAudioAttrs;
private AudioManager mAudioManager;
- private int mVolumeType = PlaybackInfo.PLAYBACK_TYPE_LOCAL;
- private int mVolumeControlType = VolumeProvider.VOLUME_CONTROL_ABSOLUTE;
+ private int mVolumeType = PLAYBACK_TYPE_LOCAL;
+ private int mVolumeControlType = VOLUME_CONTROL_ABSOLUTE;
private int mMaxVolume = 0;
private int mCurrentVolume = 0;
private int mOptimisticVolume = -1;
@@ -309,13 +315,13 @@ public class MediaSessionRecord implements IBinder.DeathRecipient, MediaSessionR
if (checkPlaybackActiveState(true) || isSystemPriority()) {
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.
int stream = getVolumeStream(mAudioAttrs);
postAdjustLocalVolume(stream, direction, flags, opPackageName, pid, uid,
asSystemService, useSuggested, previousFlagPlaySound);
} else {
- if (mVolumeControlType == VolumeProvider.VOLUME_CONTROL_FIXED) {
+ if (mVolumeControlType == VOLUME_CONTROL_FIXED) {
if (DEBUG) {
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,
int flags) {
- if (mVolumeType == PlaybackInfo.PLAYBACK_TYPE_LOCAL) {
+ if (mVolumeType == PLAYBACK_TYPE_LOCAL) {
int stream = getVolumeStream(mAudioAttrs);
final int volumeValue = value;
mHandler.post(new Runnable() {
@@ -371,7 +377,7 @@ public class MediaSessionRecord implements IBinder.DeathRecipient, MediaSessionR
}
});
} else {
- if (mVolumeControlType != VolumeProvider.VOLUME_CONTROL_ABSOLUTE) {
+ if (mVolumeControlType != VOLUME_CONTROL_ABSOLUTE) {
if (DEBUG) {
Log.d(TAG, "Session does not support setting volume");
}
@@ -433,7 +439,7 @@ public class MediaSessionRecord implements IBinder.DeathRecipient, MediaSessionR
*/
@Override
public boolean isPlaybackTypeLocal() {
- return mVolumeType == PlaybackInfo.PLAYBACK_TYPE_LOCAL;
+ return mVolumeType == PLAYBACK_TYPE_LOCAL;
}
@Override
@@ -495,7 +501,7 @@ public class MediaSessionRecord implements IBinder.DeathRecipient, MediaSessionR
@Override
public boolean canHandleVolumeKey() {
- return mVolumeControlType != VolumeProvider.VOLUME_CONTROL_FIXED;
+ return mVolumeControlType != VOLUME_CONTROL_FIXED;
}
@Override
@@ -528,13 +534,48 @@ public class MediaSessionRecord implements IBinder.DeathRecipient, MediaSessionR
pw.println(indent + "controllers: " + mControllerCallbackHolders.size());
pw.println(indent + "state=" + (mPlaybackState == null ? null : mPlaybackState.toString()));
pw.println(indent + "audioAttrs=" + mAudioAttrs);
- pw.println(indent + "volumeType=" + mVolumeType + ", controlType=" + mVolumeControlType
- + ", max=" + mMaxVolume + ", current=" + mCurrentVolume);
+ pw.append(indent)
+ .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 + "queueTitle=" + mQueueTitle + ", 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
public String toString() {
return mPackageName + "/" + mTag + " (userId=" + mUserId + ")";
@@ -877,8 +918,8 @@ public class MediaSessionRecord implements IBinder.DeathRecipient, MediaSessionR
int stream = getVolumeStream(attributes);
int max = mAudioManager.getStreamMaxVolume(stream);
int current = mAudioManager.getStreamVolume(stream);
- return new PlaybackInfo(volumeType, VolumeProvider.VOLUME_CONTROL_ABSOLUTE, max,
- current, attributes, null);
+ return new PlaybackInfo(
+ volumeType, VOLUME_CONTROL_ABSOLUTE, max, current, attributes, null);
}
private final Runnable mClearOptimisticVolumeRunnable = new Runnable() {
@@ -1124,7 +1165,7 @@ public class MediaSessionRecord implements IBinder.DeathRecipient, MediaSessionR
boolean typeChanged;
synchronized (mLock) {
typeChanged = mVolumeType == PlaybackInfo.PLAYBACK_TYPE_REMOTE;
- mVolumeType = PlaybackInfo.PLAYBACK_TYPE_LOCAL;
+ mVolumeType = PLAYBACK_TYPE_LOCAL;
mVolumeControlId = null;
if (attributes != null) {
mAudioAttrs = attributes;
@@ -1148,7 +1189,7 @@ public class MediaSessionRecord implements IBinder.DeathRecipient, MediaSessionR
throws RemoteException {
boolean typeChanged;
synchronized (mLock) {
- typeChanged = mVolumeType == PlaybackInfo.PLAYBACK_TYPE_LOCAL;
+ typeChanged = mVolumeType == PLAYBACK_TYPE_LOCAL;
mVolumeType = PlaybackInfo.PLAYBACK_TYPE_REMOTE;
mVolumeControlType = control;
mMaxVolume = max;