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

Commit 1444690e authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes I1d901692,I3e0bca75

* changes:
  ControllerLink: Remove unused parameter asSystemService
  MediaController: Remove dispatching key event as system service APIs
parents 4607116f da59389f
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -3609,7 +3609,7 @@ package android.media.session {
  public abstract static class ControllerLink.ControllerStub {
    ctor public ControllerLink.ControllerStub();
    method public void adjustVolume(@NonNull String, @NonNull String, @NonNull android.media.session.ControllerCallbackLink, boolean, int, int);
    method public void adjustVolume(@NonNull String, @NonNull String, @NonNull android.media.session.ControllerCallbackLink, int, int);
    method public void fastForward(@NonNull String, @NonNull android.media.session.ControllerCallbackLink);
    method @Nullable public android.os.Bundle getExtras();
    method public long getFlags();
@@ -3639,7 +3639,7 @@ package android.media.session {
    method public void seekTo(@NonNull String, @NonNull android.media.session.ControllerCallbackLink, long);
    method public void sendCommand(@NonNull String, @NonNull android.media.session.ControllerCallbackLink, @NonNull String, @Nullable android.os.Bundle, @Nullable android.os.ResultReceiver);
    method public void sendCustomAction(@NonNull String, @NonNull android.media.session.ControllerCallbackLink, @NonNull String, @Nullable android.os.Bundle);
    method public boolean sendMediaButton(@NonNull String, @NonNull android.media.session.ControllerCallbackLink, boolean, @NonNull android.view.KeyEvent);
    method public boolean sendMediaButton(@NonNull String, @NonNull android.media.session.ControllerCallbackLink, @NonNull android.view.KeyEvent);
    method public void setVolumeTo(@NonNull String, @NonNull String, @NonNull android.media.session.ControllerCallbackLink, int, int);
    method public void skipToQueueItem(@NonNull String, @NonNull android.media.session.ControllerCallbackLink, long);
    method public void stop(@NonNull String, @NonNull android.media.session.ControllerCallbackLink);
+8 −5
Original line number Diff line number Diff line
@@ -41,7 +41,6 @@ import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.content.res.Resources.Theme;
import android.content.res.TypedArray;
import android.graphics.Color;
@@ -1885,7 +1884,8 @@ 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.dispatchVolumeButtonEventAsSystemService(event);
                    getMediaSessionManager().dispatchVolumeKeyEventAsSystemService(
                            mMediaController.getSessionToken(), event);
                } else {
                    getMediaSessionManager().dispatchVolumeKeyEventAsSystemService(event,
                            mVolumeControlStreamType);
@@ -1906,7 +1906,8 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
            case KeyEvent.KEYCODE_MEDIA_RECORD:
            case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD: {
                if (mMediaController != null) {
                    if (mMediaController.dispatchMediaButtonEventAsSystemService(event)) {
                    if (getMediaSessionManager().dispatchMediaKeyEventAsSystemService(
                            mMediaController.getSessionToken(), event)) {
                        return true;
                    }
                }
@@ -1977,7 +1978,8 @@ 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.dispatchVolumeButtonEventAsSystemService(event);
                    getMediaSessionManager().dispatchVolumeKeyEventAsSystemService(
                            mMediaController.getSessionToken(), event);
                } else {
                    getMediaSessionManager().dispatchVolumeKeyEventAsSystemService(
                            event, mVolumeControlStreamType);
@@ -2007,7 +2009,8 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
            case KeyEvent.KEYCODE_MEDIA_RECORD:
            case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD: {
                if (mMediaController != null) {
                    if (mMediaController.dispatchMediaButtonEventAsSystemService(event)) {
                    if (getMediaSessionManager().dispatchMediaKeyEventAsSystemService(
                            mMediaController.getSessionToken(), event)) {
                        return true;
                    }
                }
+28 −20
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ import android.os.ResultReceiver;
import android.view.KeyEvent;

import java.util.List;
import java.util.Objects;

/**
 * Handles incoming commands from {@link MediaController}.
@@ -96,15 +97,12 @@ public final class ControllerLink implements Parcelable {
     *
     * @param packageName the package name of the controller
     * @param caller the {@link ControllerCallbackLink} of the controller
     * @param asSystemService whether this event should be considered as from system service
     * @param mediaButton the media button key event
     */
    boolean sendMediaButton(@NonNull String packageName,
            @NonNull ControllerCallbackLink caller, boolean asSystemService,
            @NonNull KeyEvent mediaButton) {
            @NonNull ControllerCallbackLink caller, @NonNull KeyEvent mediaButton) {
        try {
            return mISessionController.sendMediaButton(packageName, caller, asSystemService,
                    mediaButton);
            return mISessionController.sendMediaButton(packageName, caller, mediaButton);
        } catch (RemoteException e) {
            throw new RuntimeException(e);
        }
@@ -202,16 +200,14 @@ public final class ControllerLink implements Parcelable {
     * @param packageName the package name of the controller
     * @param opPackageName the op package name of this request
     * @param caller the {@link ControllerCallbackLink} of the controller
     * @param asSystemService whether this event should be considered as from system service
     * @param direction the direction to adjust the volume in
     * @param flags the flags with this volume change request
     */
    void adjustVolume(@NonNull String packageName, @NonNull String opPackageName,
            @NonNull ControllerCallbackLink caller, boolean asSystemService, int direction,
            @NonNull ControllerCallbackLink caller, int direction,
            int flags) {
        try {
            mISessionController.adjustVolume(packageName, opPackageName, caller, asSystemService,
                    direction, flags);
            mISessionController.adjustVolume(packageName, opPackageName, caller, direction, flags);
        } catch (RemoteException e) {
            throw new RuntimeException(e);
        }
@@ -603,6 +599,23 @@ public final class ControllerLink implements Parcelable {
        dest.writeStrongBinder(mISessionController.asBinder());
    }

    @Override
    public int hashCode() {
        return mISessionController.asBinder().hashCode();
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (!(obj instanceof ControllerLink)) {
            return false;
        }
        ControllerLink other = (ControllerLink) obj;
        return Objects.equals(getBinder(), other.getBinder());
    }

    /**
     * Class for Stub implementation
     */
@@ -614,8 +627,7 @@ public final class ControllerLink implements Parcelable {

        /** Stub method for ISessionController.sendMediaButton */
        public boolean sendMediaButton(@NonNull String packageName,
                @NonNull ControllerCallbackLink caller, boolean asSystemService,
                @NonNull KeyEvent mediaButton) {
                @NonNull ControllerCallbackLink caller, @NonNull KeyEvent mediaButton) {
            return false;
        }

@@ -659,8 +671,7 @@ public final class ControllerLink implements Parcelable {

        /** Stub method for ISessionController.adjustVolume */
        public void adjustVolume(@NonNull String packageName, @NonNull String opPackageName,
                @NonNull ControllerCallbackLink caller, boolean asSystemService, int direction,
                int flags) {
                @NonNull ControllerCallbackLink caller, int direction, int flags) {
        }

        /** Stub method for ISessionController.setVolumeTo */
@@ -801,9 +812,8 @@ public final class ControllerLink implements Parcelable {

        @Override
        public boolean sendMediaButton(String packageName, ControllerCallbackLink caller,
                boolean asSystemService, KeyEvent mediaButton) {
            return mControllerStub.sendMediaButton(packageName, caller, asSystemService,
                    mediaButton);
                KeyEvent mediaButton) {
            return mControllerStub.sendMediaButton(packageName, caller, mediaButton);
        }

        @Override
@@ -843,10 +853,8 @@ public final class ControllerLink implements Parcelable {

        @Override
        public void adjustVolume(String packageName, String opPackageName,
                ControllerCallbackLink caller, boolean asSystemService, int direction,
                int flags) {
            mControllerStub.adjustVolume(packageName, opPackageName, caller, asSystemService,
                    direction, flags);
                ControllerCallbackLink caller, int direction, int flags) {
            mControllerStub.adjustVolume(packageName, opPackageName, caller, direction, flags);
        }

        @Override
+2 −3
Original line number Diff line number Diff line
@@ -39,7 +39,7 @@ interface ISessionController {
    void sendCommand(String packageName, in ControllerCallbackLink caller,
            String command, in Bundle args, in ResultReceiver cb);
    boolean sendMediaButton(String packageName, in ControllerCallbackLink caller,
            boolean asSystemService, in KeyEvent mediaButton);
            in KeyEvent mediaButton);
    void registerCallback(String packageName, in ControllerCallbackLink cb);
    void unregisterCallback(in ControllerCallbackLink cb);
    String getPackageName();
@@ -48,8 +48,7 @@ interface ISessionController {
    long getFlags();
    MediaController.PlaybackInfo getVolumeAttributes();
    void adjustVolume(String packageName, String opPackageName,
            in ControllerCallbackLink caller, boolean asSystemService, int direction,
            int flags);
            in ControllerCallbackLink caller, int direction, int flags);
    void setVolumeTo(String packageName, String opPackageName, in ControllerCallbackLink caller,
            int value, int flags);

+2 −75
Original line number Diff line number Diff line
@@ -123,25 +123,6 @@ public final class MediaController {
     * @return true if the event was sent to the session, false otherwise.
     */
    public boolean dispatchMediaButtonEvent(@NonNull KeyEvent keyEvent) {
        return dispatchMediaButtonEventInternal(false, keyEvent);
    }

    /**
     * Dispatches the media button event as system service to the session.
     * <p>
     * Should be only called by the {@link com.android.internal.policy.PhoneWindow} when the
     * foreground activity didn't consume the key from the hardware devices.
     *
     * @param keyEvent media key event
     * @return {@code true} if the event was sent to the session, {@code false} otherwise
     * @hide
     */
    public boolean dispatchMediaButtonEventAsSystemService(@NonNull KeyEvent keyEvent) {
        return dispatchMediaButtonEventInternal(true, keyEvent);
    }

    private boolean dispatchMediaButtonEventInternal(boolean asSystemService,
            @NonNull KeyEvent keyEvent) {
        if (keyEvent == null) {
            throw new IllegalArgumentException("KeyEvent may not be null");
        }
@@ -149,67 +130,13 @@ public final class MediaController {
            return false;
        }
        try {
            return mSessionBinder.sendMediaButton(mContext.getPackageName(), mCbStub,
                    asSystemService, keyEvent);
            return mSessionBinder.sendMediaButton(mContext.getPackageName(), mCbStub, keyEvent);
        } catch (RuntimeException e) {
            // System is dead. =(
        }
        return false;
    }

    /**
     * Dispatches the volume button event as system service to the session.
     * <p>
     * Should be only called by the {@link com.android.internal.policy.PhoneWindow} when the
     * foreground activity didn't consume the key from the hardware devices.
     *
     * @param keyEvent volume key event
     * @hide
     */
    public void dispatchVolumeButtonEventAsSystemService(@NonNull KeyEvent keyEvent) {
        switch (keyEvent.getAction()) {
            case KeyEvent.ACTION_DOWN: {
                int direction = 0;
                switch (keyEvent.getKeyCode()) {
                    case KeyEvent.KEYCODE_VOLUME_UP:
                        direction = AudioManager.ADJUST_RAISE;
                        break;
                    case KeyEvent.KEYCODE_VOLUME_DOWN:
                        direction = AudioManager.ADJUST_LOWER;
                        break;
                    case KeyEvent.KEYCODE_VOLUME_MUTE:
                        direction = AudioManager.ADJUST_TOGGLE_MUTE;
                        break;
                }
                try {
                    // Note: Need both package name and OP package name. Package name is used for
                    //       RemoteUserInfo, and OP package name is used for AudioService's internal
                    //       AppOpsManager usages.
                    mSessionBinder.adjustVolume(mContext.getPackageName(),
                            mContext.getOpPackageName(), mCbStub, true, direction,
                            AudioManager.FLAG_SHOW_UI);
                } catch (RuntimeException e) {
                    Log.wtf(TAG, "Error calling adjustVolumeBy", e);
                }
                break;
            }

            case KeyEvent.ACTION_UP: {
                final int flags = AudioManager.FLAG_PLAY_SOUND | AudioManager.FLAG_VIBRATE
                        | AudioManager.FLAG_FROM_KEY;
                try {
                    // Note: Need both package name and OP package name. Package name is used for
                    //       RemoteUserInfo, and OP package name is used for AudioService's internal
                    //       AppOpsManager usages.
                    mSessionBinder.adjustVolume(mContext.getPackageName(),
                            mContext.getOpPackageName(), mCbStub, true, 0, flags);
                } catch (RuntimeException e) {
                    Log.wtf(TAG, "Error calling adjustVolumeBy", e);
                }
            }
        }
    }

    /**
     * Get the current playback state for this session.
     *
@@ -394,7 +321,7 @@ public final class MediaController {
            //       RemoteUserInfo, and OP package name is used for AudioService's internal
            //       AppOpsManager usages.
            mSessionBinder.adjustVolume(mContext.getPackageName(), mContext.getOpPackageName(),
                    mCbStub, false, direction, flags);
                    mCbStub, direction, flags);
        } catch (RuntimeException e) {
            Log.wtf(TAG, "Error calling adjustVolumeBy.", e);
        }
Loading