Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c83a248b authored by Hyundo Moon's avatar Hyundo Moon Committed by Android (Google) Code Review
Browse files

Merge "MediaSession2: Implement setAllowedCommands()" into pi-dev

parents 44da223a e0e20717
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@ oneway interface IMediaSession2Callback {
    void onDisconnected();

    void onCustomLayoutChanged(in List<Bundle> commandButtonlist);
    void onAllowedCommandsChanged(in Bundle commands);

    void onCustomCommand(in Bundle command, in Bundle args, in ResultReceiver receiver);

+6 −0
Original line number Diff line number Diff line
@@ -776,6 +776,12 @@ public class MediaController2Impl implements MediaController2Provider {
        });
    }

    void onAllowedCommandsChanged(final CommandGroup commands) {
        mCallbackExecutor.execute(() -> {
            mCallback.onAllowedCommandsChanged(mInstance, commands);
        });
    }

    void onCustomLayoutChanged(final List<CommandButton> layout) {
        mCallbackExecutor.execute(() -> {
            mCallback.onCustomLayoutChanged(mInstance, layout);
+21 −0
Original line number Diff line number Diff line
@@ -214,6 +214,27 @@ public class MediaSession2CallbackStub extends IMediaSession2Callback.Stub {
        controller.onCustomLayoutChanged(layout);
    }

    @Override
    public void onAllowedCommandsChanged(Bundle commandsBundle) {
        final MediaController2Impl controller;
        try {
            controller = getController();
        } catch (IllegalStateException e) {
            Log.w(TAG, "Don't fail silently here. Highly likely a bug");
            return;
        }
        if (controller == null) {
            // TODO(jaewan): Revisit here. Could be a bug
            return;
        }
        CommandGroup commands = CommandGroup.fromBundle(controller.getContext(), commandsBundle);
        if (commands == null) {
            Log.w(TAG, "onAllowedCommandsChanged(): Ignoring null commands");
            return;
        }
        controller.onAllowedCommandsChanged(commands);
    }

    @Override
    public void onCustomCommand(Bundle commandBundle, Bundle args, ResultReceiver receiver) {
        final MediaController2Impl controller;
+7 −1
Original line number Diff line number Diff line
@@ -429,7 +429,13 @@ public class MediaSession2Impl implements MediaSession2Provider {

    @Override
    public void setAllowedCommands_impl(ControllerInfo controller, CommandGroup commands) {
        // TODO(jaewan): Implement
        if (controller == null) {
            throw new IllegalArgumentException("controller shouldn't be null");
        }
        if (commands == null) {
            throw new IllegalArgumentException("commands shouldn't be null");
        }
        mSessionStub.setAllowedCommands(controller, commands);
    }

    @Override
+16 −0
Original line number Diff line number Diff line
@@ -958,6 +958,22 @@ public class MediaSession2Stub extends IMediaSession2.Stub {
        }
    }

    public void setAllowedCommands(ControllerInfo controller, CommandGroup commands) {
        synchronized (mLock) {
            mAllowedCommandGroupMap.put(controller, commands);
        }
        final IMediaSession2Callback controllerBinder = getControllerBinderIfAble(controller);
        if (controllerBinder == null) {
            return;
        }
        try {
            controllerBinder.onAllowedCommandsChanged(commands.toBundle());
        } catch (RemoteException e) {
            Log.w(TAG, "Controller is gone", e);
            // TODO(jaewan): What to do when the controller is gone?
        }
    }

    public void sendCustomCommand(ControllerInfo controller, Command command, Bundle args,
            ResultReceiver receiver) {
        if (receiver != null && controller == null) {
Loading