Loading media/java/android/media/session/MediaSession.java +37 −10 Original line number Original line Diff line number Diff line Loading @@ -286,7 +286,9 @@ public final class MediaSession { if (volumeProvider == null) { if (volumeProvider == null) { throw new IllegalArgumentException("volumeProvider may not be null!"); throw new IllegalArgumentException("volumeProvider may not be null!"); } } synchronized (mLock) { mVolumeProvider = volumeProvider; mVolumeProvider = volumeProvider; } volumeProvider.setCallback(new VolumeProvider.Callback() { volumeProvider.setCallback(new VolumeProvider.Callback() { @Override @Override public void onVolumeChanged(VolumeProvider volumeProvider) { public void onVolumeChanged(VolumeProvider volumeProvider) { Loading Loading @@ -491,10 +493,12 @@ public final class MediaSession { * @hide * @hide */ */ public void notifyRemoteVolumeChanged(VolumeProvider provider) { public void notifyRemoteVolumeChanged(VolumeProvider provider) { synchronized (mLock) { if (provider == null || provider != mVolumeProvider) { if (provider == null || provider != mVolumeProvider) { Log.w(TAG, "Received update from stale volume provider"); Log.w(TAG, "Received update from stale volume provider"); return; return; } } } try { try { mBinder.setCurrentVolume(provider.getCurrentVolume()); mBinder.setCurrentVolume(provider.getCurrentVolume()); } catch (RemoteException e) { } catch (RemoteException e) { Loading Loading @@ -558,6 +562,14 @@ public final class MediaSession { postToCallback(CallbackMessageHandler.MSG_MEDIA_BUTTON, mediaButtonIntent); postToCallback(CallbackMessageHandler.MSG_MEDIA_BUTTON, mediaButtonIntent); } } private void dispatchAdjustVolume(int direction) { postToCallback(CallbackMessageHandler.MSG_ADJUST_VOLUME, direction); } private void dispatchSetVolumeTo(int volume) { postToCallback(CallbackMessageHandler.MSG_SET_VOLUME, volume); } private void postToCallback(int what) { private void postToCallback(int what) { postToCallback(what, null); postToCallback(what, null); } } Loading Loading @@ -1009,9 +1021,7 @@ public final class MediaSession { public void onAdjustVolume(int direction) { public void onAdjustVolume(int direction) { MediaSession session = mMediaSession.get(); MediaSession session = mMediaSession.get(); if (session != null) { if (session != null) { if (session.mVolumeProvider != null) { session.dispatchAdjustVolume(direction); session.mVolumeProvider.onAdjustVolume(direction); } } } } } Loading @@ -1019,9 +1029,7 @@ public final class MediaSession { public void onSetVolumeTo(int value) { public void onSetVolumeTo(int value) { MediaSession session = mMediaSession.get(); MediaSession session = mMediaSession.get(); if (session != null) { if (session != null) { if (session.mVolumeProvider != null) { session.dispatchSetVolumeTo(value); session.mVolumeProvider.onSetVolumeTo(value); } } } } } Loading Loading @@ -1138,6 +1146,8 @@ public final class MediaSession { private static final int MSG_CUSTOM_ACTION = 13; private static final int MSG_CUSTOM_ACTION = 13; private static final int MSG_MEDIA_BUTTON = 14; private static final int MSG_MEDIA_BUTTON = 14; private static final int MSG_COMMAND = 15; private static final int MSG_COMMAND = 15; private static final int MSG_ADJUST_VOLUME = 16; private static final int MSG_SET_VOLUME = 17; private MediaSession.Callback mCallback; private MediaSession.Callback mCallback; Loading Loading @@ -1166,6 +1176,7 @@ public final class MediaSession { @Override @Override public void handleMessage(Message msg) { public void handleMessage(Message msg) { VolumeProvider vp; switch (msg.what) { switch (msg.what) { case MSG_PLAY: case MSG_PLAY: mCallback.onPlay(); mCallback.onPlay(); Loading Loading @@ -1213,6 +1224,22 @@ public final class MediaSession { Command cmd = (Command) msg.obj; Command cmd = (Command) msg.obj; mCallback.onCommand(cmd.command, cmd.extras, cmd.stub); mCallback.onCommand(cmd.command, cmd.extras, cmd.stub); break; break; case MSG_ADJUST_VOLUME: synchronized (mLock) { vp = mVolumeProvider; } if (vp != null) { vp.onAdjustVolume((int) msg.obj); } break; case MSG_SET_VOLUME: synchronized (mLock) { vp = mVolumeProvider; } if (vp != null) { vp.onSetVolumeTo((int) msg.obj); } break; } } } } } } Loading Loading
media/java/android/media/session/MediaSession.java +37 −10 Original line number Original line Diff line number Diff line Loading @@ -286,7 +286,9 @@ public final class MediaSession { if (volumeProvider == null) { if (volumeProvider == null) { throw new IllegalArgumentException("volumeProvider may not be null!"); throw new IllegalArgumentException("volumeProvider may not be null!"); } } synchronized (mLock) { mVolumeProvider = volumeProvider; mVolumeProvider = volumeProvider; } volumeProvider.setCallback(new VolumeProvider.Callback() { volumeProvider.setCallback(new VolumeProvider.Callback() { @Override @Override public void onVolumeChanged(VolumeProvider volumeProvider) { public void onVolumeChanged(VolumeProvider volumeProvider) { Loading Loading @@ -491,10 +493,12 @@ public final class MediaSession { * @hide * @hide */ */ public void notifyRemoteVolumeChanged(VolumeProvider provider) { public void notifyRemoteVolumeChanged(VolumeProvider provider) { synchronized (mLock) { if (provider == null || provider != mVolumeProvider) { if (provider == null || provider != mVolumeProvider) { Log.w(TAG, "Received update from stale volume provider"); Log.w(TAG, "Received update from stale volume provider"); return; return; } } } try { try { mBinder.setCurrentVolume(provider.getCurrentVolume()); mBinder.setCurrentVolume(provider.getCurrentVolume()); } catch (RemoteException e) { } catch (RemoteException e) { Loading Loading @@ -558,6 +562,14 @@ public final class MediaSession { postToCallback(CallbackMessageHandler.MSG_MEDIA_BUTTON, mediaButtonIntent); postToCallback(CallbackMessageHandler.MSG_MEDIA_BUTTON, mediaButtonIntent); } } private void dispatchAdjustVolume(int direction) { postToCallback(CallbackMessageHandler.MSG_ADJUST_VOLUME, direction); } private void dispatchSetVolumeTo(int volume) { postToCallback(CallbackMessageHandler.MSG_SET_VOLUME, volume); } private void postToCallback(int what) { private void postToCallback(int what) { postToCallback(what, null); postToCallback(what, null); } } Loading Loading @@ -1009,9 +1021,7 @@ public final class MediaSession { public void onAdjustVolume(int direction) { public void onAdjustVolume(int direction) { MediaSession session = mMediaSession.get(); MediaSession session = mMediaSession.get(); if (session != null) { if (session != null) { if (session.mVolumeProvider != null) { session.dispatchAdjustVolume(direction); session.mVolumeProvider.onAdjustVolume(direction); } } } } } Loading @@ -1019,9 +1029,7 @@ public final class MediaSession { public void onSetVolumeTo(int value) { public void onSetVolumeTo(int value) { MediaSession session = mMediaSession.get(); MediaSession session = mMediaSession.get(); if (session != null) { if (session != null) { if (session.mVolumeProvider != null) { session.dispatchSetVolumeTo(value); session.mVolumeProvider.onSetVolumeTo(value); } } } } } Loading Loading @@ -1138,6 +1146,8 @@ public final class MediaSession { private static final int MSG_CUSTOM_ACTION = 13; private static final int MSG_CUSTOM_ACTION = 13; private static final int MSG_MEDIA_BUTTON = 14; private static final int MSG_MEDIA_BUTTON = 14; private static final int MSG_COMMAND = 15; private static final int MSG_COMMAND = 15; private static final int MSG_ADJUST_VOLUME = 16; private static final int MSG_SET_VOLUME = 17; private MediaSession.Callback mCallback; private MediaSession.Callback mCallback; Loading Loading @@ -1166,6 +1176,7 @@ public final class MediaSession { @Override @Override public void handleMessage(Message msg) { public void handleMessage(Message msg) { VolumeProvider vp; switch (msg.what) { switch (msg.what) { case MSG_PLAY: case MSG_PLAY: mCallback.onPlay(); mCallback.onPlay(); Loading Loading @@ -1213,6 +1224,22 @@ public final class MediaSession { Command cmd = (Command) msg.obj; Command cmd = (Command) msg.obj; mCallback.onCommand(cmd.command, cmd.extras, cmd.stub); mCallback.onCommand(cmd.command, cmd.extras, cmd.stub); break; break; case MSG_ADJUST_VOLUME: synchronized (mLock) { vp = mVolumeProvider; } if (vp != null) { vp.onAdjustVolume((int) msg.obj); } break; case MSG_SET_VOLUME: synchronized (mLock) { vp = mVolumeProvider; } if (vp != null) { vp.onSetVolumeTo((int) msg.obj); } break; } } } } } } Loading