Loading services/core/java/com/android/server/media/MediaSessionRecord.java +55 −14 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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; Loading Loading @@ -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"); } Loading Loading @@ -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() { Loading @@ -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"); } Loading Loading @@ -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 Loading Loading @@ -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 Loading Loading @@ -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 + ")"; Loading Loading @@ -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() { Loading Loading @@ -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; Loading @@ -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; Loading Loading
services/core/java/com/android/server/media/MediaSessionRecord.java +55 −14 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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; Loading Loading @@ -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"); } Loading Loading @@ -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() { Loading @@ -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"); } Loading Loading @@ -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 Loading Loading @@ -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 Loading Loading @@ -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 + ")"; Loading Loading @@ -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() { Loading Loading @@ -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; Loading @@ -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; Loading