diff options
13 files changed, 62 insertions, 78 deletions
diff --git a/api/current.txt b/api/current.txt index 5abb0d2..f9a6e96 100644 --- a/api/current.txt +++ b/api/current.txt @@ -15617,7 +15617,7 @@ package android.media { method public final int getMaxVolume(); method public final int getVolumeControl(); method public final void notifyVolumeChanged(); - method public void onAdjustVolumeBy(int); + method public void onAdjustVolume(int); method public abstract int onGetCurrentVolume(); method public void onSetVolumeTo(int); field public static final int VOLUME_CONTROL_ABSOLUTE = 2; // 0x2 @@ -16222,7 +16222,7 @@ package android.media.session { ctor public MediaController(android.media.session.MediaSession.Token); method public void addCallback(android.media.session.MediaController.Callback); method public void addCallback(android.media.session.MediaController.Callback, android.os.Handler); - method public void adjustVolumeBy(int, int); + method public void adjustVolume(int, int); method public android.media.routing.MediaRouter.Delegate createMediaRouterDelegate(); method public boolean dispatchMediaButtonEvent(android.view.KeyEvent); method public android.media.MediaMetadata getMetadata(); diff --git a/media/java/android/media/MediaRouter.java b/media/java/android/media/MediaRouter.java index 3336694..7d1de24 100644 --- a/media/java/android/media/MediaRouter.java +++ b/media/java/android/media/MediaRouter.java @@ -2249,12 +2249,12 @@ public class MediaRouter { } @Override - public void onAdjustVolumeBy(final int delta) { + public void onAdjustVolume(final int direction) { sStatic.mHandler.post(new Runnable() { @Override public void run() { if (mVcb != null) { - mVcb.vcb.onVolumeUpdateRequest(mVcb.route, delta); + mVcb.vcb.onVolumeUpdateRequest(mVcb.route, direction); } } }); diff --git a/media/java/android/media/VolumeProvider.java b/media/java/android/media/VolumeProvider.java index d151e66..9bda1d4 100644 --- a/media/java/android/media/VolumeProvider.java +++ b/media/java/android/media/VolumeProvider.java @@ -32,14 +32,14 @@ public abstract class VolumeProvider { /** * The volume control uses relative adjustment via - * {@link #onAdjustVolumeBy(int)}. Attempts to set the volume to a specific + * {@link #onAdjustVolume(int)}. Attempts to set the volume to a specific * value should be ignored. */ public static final int VOLUME_CONTROL_RELATIVE = 1; /** * The volume control uses an absolute value. It may be adjusted using - * {@link #onAdjustVolumeBy(int)} or set directly using + * {@link #onAdjustVolume(int)} or set directly using * {@link #onSetVolumeTo(int)}. */ public static final int VOLUME_CONTROL_ABSOLUTE = 2; @@ -104,12 +104,13 @@ public abstract class VolumeProvider { } /** - * Override to handle requests to adjust the volume of the current - * output. - * - * @param delta The amount to change the volume + * Override to handle requests to adjust the volume of the current output. + * Direction will be one of {@link AudioManager#ADJUST_LOWER}, + * {@link AudioManager#ADJUST_RAISE}, {@link AudioManager#ADJUST_SAME}. + * + * @param direction The direction to change the volume in. */ - public void onAdjustVolumeBy(int delta) { + public void onAdjustVolume(int direction) { } /** diff --git a/media/java/android/media/session/ISessionCallback.aidl b/media/java/android/media/session/ISessionCallback.aidl index e554e27..39391b6 100644 --- a/media/java/android/media/session/ISessionCallback.aidl +++ b/media/java/android/media/session/ISessionCallback.aidl @@ -39,6 +39,6 @@ oneway interface ISessionCallback { void onRate(in Rating rating); // These callbacks are for volume handling - void onAdjustVolumeBy(int delta); + void onAdjustVolume(int direction); void onSetVolumeTo(int value); } diff --git a/media/java/android/media/session/ISessionController.aidl b/media/java/android/media/session/ISessionController.aidl index 6cf5ef2..b555220 100644 --- a/media/java/android/media/session/ISessionController.aidl +++ b/media/java/android/media/session/ISessionController.aidl @@ -41,7 +41,7 @@ interface ISessionController { MediaSessionInfo getSessionInfo(); long getFlags(); ParcelableVolumeInfo getVolumeAttributes(); - void adjustVolumeBy(int delta, int flags); + void adjustVolume(int direction, int flags); void setVolumeTo(int value, int flags); IMediaRouterDelegate createMediaRouterDelegate(IMediaRouterStateCallback callback); diff --git a/media/java/android/media/session/ISessionManager.aidl b/media/java/android/media/session/ISessionManager.aidl index dce84d4..95c2d61 100644 --- a/media/java/android/media/session/ISessionManager.aidl +++ b/media/java/android/media/session/ISessionManager.aidl @@ -31,7 +31,7 @@ interface ISessionManager { ISession createSession(String packageName, in ISessionCallback cb, String tag, int userId); List<IBinder> getSessions(in ComponentName compName, int userId); void dispatchMediaKeyEvent(in KeyEvent keyEvent, boolean needWakeLock); - void dispatchAdjustVolumeBy(int suggestedStream, int delta, int flags); + void dispatchAdjustVolume(int suggestedStream, int delta, int flags); void addSessionsListener(in IActiveSessionsListener listener, in ComponentName compName, int userId); void removeSessionsListener(in IActiveSessionsListener listener); diff --git a/media/java/android/media/session/MediaController.java b/media/java/android/media/session/MediaController.java index ed45a08..7fedd82 100644 --- a/media/java/android/media/session/MediaController.java +++ b/media/java/android/media/session/MediaController.java @@ -234,19 +234,21 @@ public final class MediaController { } /** - * Adjust the volume of the stream or output this session is playing on. - * Negative values will lower the volume. The command will be ignored if it - * does not support {@link VolumeProvider#VOLUME_CONTROL_RELATIVE} or + * Adjust the volume of the stream or output this session is playing on. The + * direction must be one of {@link AudioManager#ADJUST_LOWER}, + * {@link AudioManager#ADJUST_RAISE}, or {@link AudioManager#ADJUST_SAME}. + * The command will be ignored if the session does not support + * {@link VolumeProvider#VOLUME_CONTROL_RELATIVE} or * {@link VolumeProvider#VOLUME_CONTROL_ABSOLUTE}. The flags in * {@link AudioManager} may be used to affect the handling. * * @see #getVolumeInfo() - * @param delta The number of steps to adjust the volume by. + * @param direction The direction to adjust the volume in. * @param flags Any flags to pass with the command. */ - public void adjustVolumeBy(int delta, int flags) { + public void adjustVolume(int direction, int flags) { try { - mSessionBinder.adjustVolumeBy(delta, flags); + mSessionBinder.adjustVolume(direction, flags); } catch (RemoteException e) { Log.wtf(TAG, "Error calling adjustVolumeBy.", e); } diff --git a/media/java/android/media/session/MediaSession.java b/media/java/android/media/session/MediaSession.java index cdb61e1..4841360 100644 --- a/media/java/android/media/session/MediaSession.java +++ b/media/java/android/media/session/MediaSession.java @@ -869,11 +869,11 @@ public final class MediaSession { } @Override - public void onAdjustVolumeBy(int delta) { + public void onAdjustVolume(int direction) { MediaSession session = mMediaSession.get(); if (session != null) { if (session.mVolumeProvider != null) { - session.mVolumeProvider.onAdjustVolumeBy(delta); + session.mVolumeProvider.onAdjustVolume(direction); } } } diff --git a/media/java/android/media/session/MediaSessionLegacyHelper.java b/media/java/android/media/session/MediaSessionLegacyHelper.java index 5af793f..da1a6ed 100644 --- a/media/java/android/media/session/MediaSessionLegacyHelper.java +++ b/media/java/android/media/session/MediaSessionLegacyHelper.java @@ -209,13 +209,13 @@ public class MediaSessionLegacyHelper { } } - mSessionManager.dispatchAdjustVolumeBy(AudioManager.USE_DEFAULT_STREAM_TYPE, + mSessionManager.dispatchAdjustVolume(AudioManager.USE_DEFAULT_STREAM_TYPE, direction, flags); } } public void sendAdjustVolumeBy(int suggestedStream, int delta, int flags) { - mSessionManager.dispatchAdjustVolumeBy(suggestedStream, delta, flags); + mSessionManager.dispatchAdjustVolume(suggestedStream, delta, flags); if (DEBUG) { Log.d(TAG, "dispatched volume adjustment"); } diff --git a/media/java/android/media/session/MediaSessionManager.java b/media/java/android/media/session/MediaSessionManager.java index 12013b6..824b397 100644 --- a/media/java/android/media/session/MediaSessionManager.java +++ b/media/java/android/media/session/MediaSessionManager.java @@ -20,6 +20,7 @@ import android.annotation.NonNull; import android.annotation.Nullable; import android.content.ComponentName; import android.content.Context; +import android.media.AudioManager; import android.media.IRemoteVolumeController; import android.media.session.ISessionManager; import android.os.IBinder; @@ -229,17 +230,19 @@ public final class MediaSessionManager { /** * Dispatch an adjust volume request to the system. It will be sent to the - * most relevant audio stream or media session. + * most relevant audio stream or media session. The direction must be one of + * {@link AudioManager#ADJUST_LOWER}, {@link AudioManager#ADJUST_RAISE}, + * {@link AudioManager#ADJUST_SAME}. * * @param suggestedStream The stream to fall back to if there isn't a * relevant stream - * @param delta The amount to adjust the volume by. + * @param direction The direction to adjust volume in. * @param flags Any flags to include with the volume change. * @hide */ - public void dispatchAdjustVolumeBy(int suggestedStream, int delta, int flags) { + public void dispatchAdjustVolume(int suggestedStream, int direction, int flags) { try { - mService.dispatchAdjustVolumeBy(suggestedStream, delta, flags); + mService.dispatchAdjustVolume(suggestedStream, direction, flags); } catch (RemoteException e) { Log.e(TAG, "Failed to send adjust volume.", e); } diff --git a/policy/src/com/android/internal/policy/impl/PhoneWindow.java b/policy/src/com/android/internal/policy/impl/PhoneWindow.java index f431fdb..edeb5b4 100644 --- a/policy/src/com/android/internal/policy/impl/PhoneWindow.java +++ b/policy/src/com/android/internal/policy/impl/PhoneWindow.java @@ -1700,7 +1700,7 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback { // If we have a session send it the volume command, otherwise // use the suggested stream. if (mMediaController != null) { - mMediaController.adjustVolumeBy(direction, AudioManager.FLAG_SHOW_UI); + mMediaController.adjustVolume(direction, AudioManager.FLAG_SHOW_UI); } else { MediaSessionLegacyHelper.getHelper(getContext()).sendAdjustVolumeBy( mVolumeControlStreamType, direction, AudioManager.FLAG_SHOW_UI); @@ -1787,7 +1787,7 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback { // If we have a session send it the volume command, otherwise // use the suggested stream. if (mMediaController != null) { - mMediaController.adjustVolumeBy(0, AudioManager.FLAG_PLAY_SOUND + mMediaController.adjustVolume(0, AudioManager.FLAG_PLAY_SOUND | AudioManager.FLAG_VIBRATE); } else { MediaSessionLegacyHelper.getHelper(getContext()).sendAdjustVolumeBy( diff --git a/services/core/java/com/android/server/media/MediaSessionRecord.java b/services/core/java/com/android/server/media/MediaSessionRecord.java index 01a21f4..ede3dab 100644 --- a/services/core/java/com/android/server/media/MediaSessionRecord.java +++ b/services/core/java/com/android/server/media/MediaSessionRecord.java @@ -203,39 +203,32 @@ public class MediaSessionRecord implements IBinder.DeathRecipient { } /** - * Send a volume adjustment to the session owner. + * Send a volume adjustment to the session owner. Direction must be one of + * {@link AudioManager#ADJUST_LOWER}, {@link AudioManager#ADJUST_RAISE}, + * {@link AudioManager#ADJUST_SAME}. * - * @param delta The amount to adjust the volume by. + * @param direction The direction to adjust volume in. */ - public void adjustVolumeBy(int delta, int flags) { + public void adjustVolume(int direction, int flags) { if (isPlaybackActive(false)) { flags &= ~AudioManager.FLAG_PLAY_SOUND; } + if (direction > 1) { + direction = 1; + } else if (direction < -1) { + direction = -1; + } if (mVolumeType == MediaSession.PLAYBACK_TYPE_LOCAL) { - if (delta == 0) { - mAudioManager.adjustStreamVolume(mAudioStream, delta, flags); - } else { - int direction = 0; - int steps = delta; - if (delta > 0) { - direction = 1; - } else if (delta < 0) { - direction = -1; - steps = -delta; - } - for (int i = 0; i < steps; i++) { - mAudioManager.adjustStreamVolume(mAudioStream, direction, flags); - } - } + mAudioManager.adjustStreamVolume(mAudioStream, direction, flags); } else { if (mVolumeControlType == VolumeProvider.VOLUME_CONTROL_FIXED) { // Nothing to do, the volume cannot be changed return; } - mSessionCb.adjustVolumeBy(delta); + mSessionCb.adjustVolume(direction); int volumeBefore = (mOptimisticVolume < 0 ? mCurrentVolume : mOptimisticVolume); - mOptimisticVolume = volumeBefore + delta; + mOptimisticVolume = volumeBefore + direction; mOptimisticVolume = Math.max(0, Math.min(mOptimisticVolume, mMaxVolume)); mHandler.removeCallbacks(mClearOptimisticVolumeRunnable); mHandler.postDelayed(mClearOptimisticVolumeRunnable, OPTIMISTIC_VOLUME_TIMEOUT); @@ -752,11 +745,11 @@ public class MediaSessionRecord implements IBinder.DeathRecipient { } } - public void adjustVolumeBy(int delta) { + public void adjustVolume(int direction) { try { - mCb.onAdjustVolumeBy(delta); + mCb.onAdjustVolume(direction); } catch (RemoteException e) { - Slog.e(TAG, "Remote failure in adjustVolumeBy.", e); + Slog.e(TAG, "Remote failure in adjustVolume.", e); } } @@ -764,7 +757,7 @@ public class MediaSessionRecord implements IBinder.DeathRecipient { try { mCb.onSetVolumeTo(value); } catch (RemoteException e) { - Slog.e(TAG, "Remote failure in adjustVolumeBy.", e); + Slog.e(TAG, "Remote failure in setVolumeTo.", e); } } } @@ -838,10 +831,10 @@ public class MediaSessionRecord implements IBinder.DeathRecipient { } @Override - public void adjustVolumeBy(int delta, int flags) { + public void adjustVolume(int direction, int flags) { final long token = Binder.clearCallingIdentity(); try { - MediaSessionRecord.this.adjustVolumeBy(delta, flags); + MediaSessionRecord.this.adjustVolume(direction, flags); } finally { Binder.restoreCallingIdentity(token); } diff --git a/services/core/java/com/android/server/media/MediaSessionService.java b/services/core/java/com/android/server/media/MediaSessionService.java index 4c475d9..a2dd15e 100644 --- a/services/core/java/com/android/server/media/MediaSessionService.java +++ b/services/core/java/com/android/server/media/MediaSessionService.java @@ -681,7 +681,7 @@ public class MediaSessionService extends SystemService implements Monitor { } @Override - public void dispatchAdjustVolumeBy(int suggestedStream, int delta, int flags) + public void dispatchAdjustVolume(int suggestedStream, int delta, int flags) throws RemoteException { final int pid = Binder.getCallingPid(); final int uid = Binder.getCallingUid(); @@ -690,7 +690,7 @@ public class MediaSessionService extends SystemService implements Monitor { synchronized (mLock) { MediaSessionRecord session = mPriorityStack .getDefaultVolumeSession(mCurrentUserId); - dispatchAdjustVolumeByLocked(suggestedStream, delta, flags, session); + dispatchAdjustVolumeLocked(suggestedStream, delta, flags, session); } } finally { Binder.restoreCallingIdentity(token); @@ -764,11 +764,11 @@ public class MediaSessionService extends SystemService implements Monitor { return resolvedUserId; } - private void dispatchAdjustVolumeByLocked(int suggestedStream, int delta, int flags, + private void dispatchAdjustVolumeLocked(int suggestedStream, int direction, int flags, MediaSessionRecord session) { if (DEBUG) { String sessionInfo = session == null ? null : session.getSessionInfo().toString(); - Log.d(TAG, "Adjusting session " + sessionInfo + " by " + delta + ". flags=" + flags + Log.d(TAG, "Adjusting session " + sessionInfo + " by " + direction + ". flags=" + flags + ", suggestedStream=" + suggestedStream); } @@ -780,28 +780,13 @@ public class MediaSessionService extends SystemService implements Monitor { } } try { - if (delta == 0) { - mAudioService.adjustSuggestedStreamVolume(delta, suggestedStream, flags, - getContext().getOpPackageName()); - } else { - int direction = 0; - int steps = delta; - if (delta > 0) { - direction = 1; - } else if (delta < 0) { - direction = -1; - steps = -delta; - } - for (int i = 0; i < steps; i++) { - mAudioService.adjustSuggestedStreamVolume(direction, suggestedStream, - flags, getContext().getOpPackageName()); - } - } + mAudioService.adjustSuggestedStreamVolume(direction, suggestedStream, flags, + getContext().getOpPackageName()); } catch (RemoteException e) { Log.e(TAG, "Error adjusting default volume.", e); } } else { - session.adjustVolumeBy(delta, flags); + session.adjustVolume(direction, flags); if (session.getPlaybackType() == MediaSession.PLAYBACK_TYPE_REMOTE && mRvc != null) { try { |