Loading packages/MediaComponents/src/com/android/media/MediaBrowser2Impl.java +8 −0 Original line number Diff line number Diff line Loading @@ -20,12 +20,14 @@ import android.content.Context; import android.media.IMediaSession2; import android.media.MediaBrowser2; import android.media.MediaBrowser2.BrowserCallback; import android.media.MediaSession2.CommandButton; import android.media.SessionToken; import android.media.update.MediaBrowser2Provider; import android.os.Bundle; import android.os.RemoteException; import android.util.Log; import java.util.List; import java.util.concurrent.Executor; public class MediaBrowser2Impl extends MediaController2Impl implements MediaBrowser2Provider { Loading Loading @@ -65,4 +67,10 @@ public class MediaBrowser2Impl extends MediaController2Impl implements MediaBrow mCallback.onGetRootResult(rootHints, rootMediaId, rootExtra); }); } public void onCustomLayoutChanged(final List<CommandButton> layout) { getCallbackExecutor().execute(() -> { mCallback.onCustomLayoutChanged(layout); }); } } packages/MediaComponents/src/com/android/media/MediaController2Impl.java +32 −0 Original line number Diff line number Diff line Loading @@ -24,6 +24,7 @@ import android.media.IMediaSession2; import android.media.IMediaSession2Callback; import android.media.MediaSession2; import android.media.MediaSession2.Command; import android.media.MediaSession2.CommandButton; import android.media.MediaSession2.CommandGroup; import android.media.MediaController2; import android.media.MediaController2.ControllerCallback; Loading Loading @@ -461,8 +462,39 @@ public class MediaController2Impl implements MediaController2Provider { Log.w(TAG, "Don't fail silently here. Highly likely a bug"); return; } if (browser == null) { // TODO(jaewan): Revisit here. Could be a bug return; } browser.onGetRootResult(rootHints, rootMediaId, rootExtra); } @Override public void onCustomLayoutChanged(List<Bundle> commandButtonlist) { if (commandButtonlist == null) { // Illegal call. Ignore return; } final MediaBrowser2Impl browser; try { browser = getBrowser(); } catch (IllegalStateException e) { Log.w(TAG, "Don't fail silently here. Highly likely a bug"); return; } if (browser == null) { // TODO(jaewan): Revisit here. Could be a bug return; } List<CommandButton> layout = new ArrayList<>(); for (int i = 0; i < commandButtonlist.size(); i++) { CommandButton button = CommandButton.fromBundle(commandButtonlist.get(i)); if (button != null) { layout.add(button); } } browser.onCustomLayoutChanged(layout); } } // This will be called on the main thread. Loading packages/MediaComponents/src/com/android/media/MediaSession2Impl.java +13 −0 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ import android.media.MediaController2; import android.media.MediaPlayerBase; import android.media.MediaSession2; import android.media.MediaSession2.Builder; import android.media.MediaSession2.CommandButton; import android.media.MediaSession2.ControllerInfo; import android.media.MediaSession2.SessionCallback; import android.media.SessionToken; Loading Loading @@ -230,6 +231,18 @@ public class MediaSession2Impl implements MediaSession2Provider { } } @Override public void setCustomLayout_impl(ControllerInfo controller, List<CommandButton> layout) { ensureCallingThread(); if (controller == null) { throw new IllegalArgumentException("controller shouldn't be null"); } if (layout == null) { throw new IllegalArgumentException("layout shouldn't be null"); } mSessionStub.notifyCustomLayoutNotLocked(controller, layout); } /////////////////////////////////////////////////// // Protected or private methods /////////////////////////////////////////////////// Loading packages/MediaComponents/src/com/android/media/MediaSession2Stub.java +21 −0 Original line number Diff line number Diff line Loading @@ -24,6 +24,7 @@ import android.media.IMediaSession2Callback; import android.media.MediaLibraryService2.MediaLibrarySessionCallback; import android.media.MediaSession2; import android.media.MediaSession2.Command; import android.media.MediaSession2.CommandButton; import android.media.MediaSession2.CommandGroup; import android.media.MediaSession2.ControllerInfo; import android.media.MediaSession2.SessionCallback; Loading Loading @@ -229,6 +230,26 @@ public class MediaSession2Stub extends IMediaSession2.Stub { } } public void notifyCustomLayoutNotLocked(ControllerInfo controller, List<CommandButton> layout) { // TODO(jaewan): It's OK to be called while it's connecting, but not OK if the connection // is rejected. Handle the case. IMediaSession2Callback callbackBinder = ControllerInfoImpl.from(controller).getControllerBinder(); try { List<Bundle> layoutBundles = new ArrayList<>(); for (int i = 0; i < layout.size(); i++) { Bundle bundle = layout.get(i).toBundle(); if (bundle != null) { layoutBundles.add(bundle); } } callbackBinder.onCustomLayoutChanged(layoutBundles); } catch (RemoteException e) { Log.w(TAG, "Controller is gone", e); // TODO(jaewan): What to do when the controller is gone? } } // TODO(jaewan): Remove this. We should use Executor given by the session builder. private class CommandHandler extends Handler { public static final int MSG_CONNECT = 1000; Loading Loading
packages/MediaComponents/src/com/android/media/MediaBrowser2Impl.java +8 −0 Original line number Diff line number Diff line Loading @@ -20,12 +20,14 @@ import android.content.Context; import android.media.IMediaSession2; import android.media.MediaBrowser2; import android.media.MediaBrowser2.BrowserCallback; import android.media.MediaSession2.CommandButton; import android.media.SessionToken; import android.media.update.MediaBrowser2Provider; import android.os.Bundle; import android.os.RemoteException; import android.util.Log; import java.util.List; import java.util.concurrent.Executor; public class MediaBrowser2Impl extends MediaController2Impl implements MediaBrowser2Provider { Loading Loading @@ -65,4 +67,10 @@ public class MediaBrowser2Impl extends MediaController2Impl implements MediaBrow mCallback.onGetRootResult(rootHints, rootMediaId, rootExtra); }); } public void onCustomLayoutChanged(final List<CommandButton> layout) { getCallbackExecutor().execute(() -> { mCallback.onCustomLayoutChanged(layout); }); } }
packages/MediaComponents/src/com/android/media/MediaController2Impl.java +32 −0 Original line number Diff line number Diff line Loading @@ -24,6 +24,7 @@ import android.media.IMediaSession2; import android.media.IMediaSession2Callback; import android.media.MediaSession2; import android.media.MediaSession2.Command; import android.media.MediaSession2.CommandButton; import android.media.MediaSession2.CommandGroup; import android.media.MediaController2; import android.media.MediaController2.ControllerCallback; Loading Loading @@ -461,8 +462,39 @@ public class MediaController2Impl implements MediaController2Provider { Log.w(TAG, "Don't fail silently here. Highly likely a bug"); return; } if (browser == null) { // TODO(jaewan): Revisit here. Could be a bug return; } browser.onGetRootResult(rootHints, rootMediaId, rootExtra); } @Override public void onCustomLayoutChanged(List<Bundle> commandButtonlist) { if (commandButtonlist == null) { // Illegal call. Ignore return; } final MediaBrowser2Impl browser; try { browser = getBrowser(); } catch (IllegalStateException e) { Log.w(TAG, "Don't fail silently here. Highly likely a bug"); return; } if (browser == null) { // TODO(jaewan): Revisit here. Could be a bug return; } List<CommandButton> layout = new ArrayList<>(); for (int i = 0; i < commandButtonlist.size(); i++) { CommandButton button = CommandButton.fromBundle(commandButtonlist.get(i)); if (button != null) { layout.add(button); } } browser.onCustomLayoutChanged(layout); } } // This will be called on the main thread. Loading
packages/MediaComponents/src/com/android/media/MediaSession2Impl.java +13 −0 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ import android.media.MediaController2; import android.media.MediaPlayerBase; import android.media.MediaSession2; import android.media.MediaSession2.Builder; import android.media.MediaSession2.CommandButton; import android.media.MediaSession2.ControllerInfo; import android.media.MediaSession2.SessionCallback; import android.media.SessionToken; Loading Loading @@ -230,6 +231,18 @@ public class MediaSession2Impl implements MediaSession2Provider { } } @Override public void setCustomLayout_impl(ControllerInfo controller, List<CommandButton> layout) { ensureCallingThread(); if (controller == null) { throw new IllegalArgumentException("controller shouldn't be null"); } if (layout == null) { throw new IllegalArgumentException("layout shouldn't be null"); } mSessionStub.notifyCustomLayoutNotLocked(controller, layout); } /////////////////////////////////////////////////// // Protected or private methods /////////////////////////////////////////////////// Loading
packages/MediaComponents/src/com/android/media/MediaSession2Stub.java +21 −0 Original line number Diff line number Diff line Loading @@ -24,6 +24,7 @@ import android.media.IMediaSession2Callback; import android.media.MediaLibraryService2.MediaLibrarySessionCallback; import android.media.MediaSession2; import android.media.MediaSession2.Command; import android.media.MediaSession2.CommandButton; import android.media.MediaSession2.CommandGroup; import android.media.MediaSession2.ControllerInfo; import android.media.MediaSession2.SessionCallback; Loading Loading @@ -229,6 +230,26 @@ public class MediaSession2Stub extends IMediaSession2.Stub { } } public void notifyCustomLayoutNotLocked(ControllerInfo controller, List<CommandButton> layout) { // TODO(jaewan): It's OK to be called while it's connecting, but not OK if the connection // is rejected. Handle the case. IMediaSession2Callback callbackBinder = ControllerInfoImpl.from(controller).getControllerBinder(); try { List<Bundle> layoutBundles = new ArrayList<>(); for (int i = 0; i < layout.size(); i++) { Bundle bundle = layout.get(i).toBundle(); if (bundle != null) { layoutBundles.add(bundle); } } callbackBinder.onCustomLayoutChanged(layoutBundles); } catch (RemoteException e) { Log.w(TAG, "Controller is gone", e); // TODO(jaewan): What to do when the controller is gone? } } // TODO(jaewan): Remove this. We should use Executor given by the session builder. private class CommandHandler extends Handler { public static final int MSG_CONNECT = 1000; Loading