diff options
author | RoboErik <epastern@google.com> | 2014-07-15 17:23:18 -0700 |
---|---|---|
committer | RoboErik <epastern@google.com> | 2014-07-16 12:03:45 -0700 |
commit | 1ff5b1648a051e9650614f0c0f1b3f449777db81 (patch) | |
tree | f24d5542c8532a4db1331b1c02c77d76ab6e3948 /services/core/java/com/android/server/media | |
parent | 8b4bffcac996b4083e720310a09d315ca1c4a000 (diff) | |
download | frameworks_base-1ff5b1648a051e9650614f0c0f1b3f449777db81.zip frameworks_base-1ff5b1648a051e9650614f0c0f1b3f449777db81.tar.gz frameworks_base-1ff5b1648a051e9650614f0c0f1b3f449777db81.tar.bz2 |
Change adjustVolumeBy to adjustVolume
This makes volume adjustments take a direction instead of a number of
steps and renames the API appropriately.
Change-Id: I6a31cbc42d889a38aa63446686a424cb2b8b2270
Diffstat (limited to 'services/core/java/com/android/server/media')
-rw-r--r-- | services/core/java/com/android/server/media/MediaSessionRecord.java | 45 | ||||
-rw-r--r-- | services/core/java/com/android/server/media/MediaSessionService.java | 29 |
2 files changed, 26 insertions, 48 deletions
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 { |