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

Commit 8c65f9b6 authored by Jaewan Kim's avatar Jaewan Kim Committed by android-build-merger
Browse files

Merge "MediaSessionService: Provide caller information for media key events"...

Merge "MediaSessionService: Provide caller information for media key events" into pi-dev am: 183a6347
am: 399a7e99

Change-Id: I7282bf70bfb59ed9d9d81f5780bd49090bb252c6
parents 01beb0ce 399a7e99
Loading
Loading
Loading
Loading
+7 −5
Original line number Diff line number Diff line
@@ -46,6 +46,8 @@ import java.io.PrintStream;
import java.util.List;

public class Media extends BaseCommand {
    // This doesn't belongs to any package. Setting the package name to empty string.
    private static final String PACKAGE_NAME = "";
    private ISessionManager mSessionService;

    /**
@@ -104,7 +106,7 @@ public class Media extends BaseCommand {

    private void sendMediaKey(KeyEvent event) {
        try {
            mSessionService.dispatchMediaKeyEvent(event, false);
            mSessionService.dispatchMediaKeyEvent(PACKAGE_NAME, false, event, false);
        } catch (RemoteException e) {
        }
    }
@@ -264,13 +266,13 @@ public class Media extends BaseCommand {
                    } else if ("q".equals(line) || "quit".equals(line)) {
                        break;
                    } else if ("play".equals(line)) {
                        mController.play("");
                        mController.play(PACKAGE_NAME);
                    } else if ("pause".equals(line)) {
                        mController.pause("");
                        mController.pause(PACKAGE_NAME);
                    } else if ("next".equals(line)) {
                        mController.next("");
                        mController.next(PACKAGE_NAME);
                    } else if ("previous".equals(line)) {
                        mController.previous("");
                        mController.previous(PACKAGE_NAME);
                    } else {
                        System.out.println("Invalid command: " + line);
                    }
+18 −6
Original line number Diff line number Diff line
@@ -23,7 +23,7 @@ import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.media.AudioManager;
import android.media.session.MediaSessionLegacyHelper;
import android.media.session.MediaSessionManager;
import android.os.UserHandle;
import android.provider.Settings;
import android.telephony.TelephonyManager;
@@ -48,6 +48,7 @@ public class PhoneFallbackEventHandler implements FallbackEventHandler {
    KeyguardManager mKeyguardManager;
    SearchManager mSearchManager;
    TelephonyManager mTelephonyManager;
    MediaSessionManager mMediaSessionManager;

    public PhoneFallbackEventHandler(Context context) {
        mContext = context;
@@ -84,8 +85,7 @@ public class PhoneFallbackEventHandler implements FallbackEventHandler {
            case KeyEvent.KEYCODE_VOLUME_UP:
            case KeyEvent.KEYCODE_VOLUME_DOWN:
            case KeyEvent.KEYCODE_VOLUME_MUTE: {
                MediaSessionLegacyHelper.getHelper(mContext).sendVolumeKeyEvent(
                        event, AudioManager.USE_DEFAULT_STREAM_TYPE, false);
                handleVolumeKeyEvent(event);
                return true;
            }

@@ -216,8 +216,7 @@ public class PhoneFallbackEventHandler implements FallbackEventHandler {
            case KeyEvent.KEYCODE_VOLUME_DOWN:
            case KeyEvent.KEYCODE_VOLUME_MUTE: {
                if (!event.isCanceled()) {
                    MediaSessionLegacyHelper.getHelper(mContext).sendVolumeKeyEvent(
                            event, AudioManager.USE_DEFAULT_STREAM_TYPE, false);
                    handleVolumeKeyEvent(event);
                }
                return true;
            }
@@ -306,12 +305,25 @@ public class PhoneFallbackEventHandler implements FallbackEventHandler {
        return mAudioManager;
    }

    MediaSessionManager getMediaSessionManager() {
        if (mMediaSessionManager == null) {
            mMediaSessionManager =
                    (MediaSessionManager) mContext.getSystemService(Context.MEDIA_SESSION_SERVICE);
        }
        return mMediaSessionManager;
    }

    void sendCloseSystemWindows() {
        PhoneWindow.sendCloseSystemWindows(mContext, null);
    }

    private void handleVolumeKeyEvent(KeyEvent keyEvent) {
        getMediaSessionManager().dispatchVolumeKeyEventAsSystemService(keyEvent,
                AudioManager.USE_DEFAULT_STREAM_TYPE);
    }

    private void handleMediaKeyEvent(KeyEvent keyEvent) {
        MediaSessionLegacyHelper.getHelper(mContext).sendMediaButtonEvent(keyEvent, false);
        getMediaSessionManager().dispatchMediaKeyEventAsSystemService(keyEvent);
    }

    private boolean isUserSetupComplete() {
+20 −25
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import static android.view.WindowManager.LayoutParams.*;
import android.annotation.NonNull;
import android.app.ActivityManager;
import android.app.SearchManager;
import android.media.session.MediaSessionManager;
import android.os.UserHandle;

import android.text.TextUtils;
@@ -75,7 +76,6 @@ import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.media.AudioManager;
import android.media.session.MediaController;
import android.media.session.MediaSessionLegacyHelper;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
@@ -251,6 +251,7 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {

    private AudioManager mAudioManager;
    private KeyguardManager mKeyguardManager;
    private MediaSessionManager mMediaSessionManager;

    private int mUiOptions = 0;

@@ -1872,22 +1873,10 @@ 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) {
                    int direction = 0;
                    switch (keyCode) {
                        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;
                    }
                    mMediaController.adjustVolume(direction, AudioManager.FLAG_SHOW_UI);
                    mMediaController.dispatchVolumeButtonEventAsSystemService(event);
                } else {
                    MediaSessionLegacyHelper.getHelper(getContext()).sendVolumeKeyEvent(
                            event, mVolumeControlStreamType, false);
                    getMediaSessionManager().dispatchVolumeKeyEventAsSystemService(event,
                            mVolumeControlStreamType);
                }
                return true;
            }
@@ -1905,7 +1894,7 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
            case KeyEvent.KEYCODE_MEDIA_RECORD:
            case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD: {
                if (mMediaController != null) {
                    if (mMediaController.dispatchMediaButtonEvent(event)) {
                    if (mMediaController.dispatchMediaButtonEventAsSystemService(event)) {
                        return true;
                    }
                }
@@ -1947,6 +1936,14 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
        return mAudioManager;
    }

    private MediaSessionManager getMediaSessionManager() {
        if (mMediaSessionManager == null) {
            mMediaSessionManager = (MediaSessionManager) getContext().getSystemService(
                    Context.MEDIA_SESSION_SERVICE);
        }
        return mMediaSessionManager;
    }

    /**
     * A key was released and not handled by anything else in the window.
     *
@@ -1968,12 +1965,10 @@ 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) {
                    final int flags = AudioManager.FLAG_PLAY_SOUND | AudioManager.FLAG_VIBRATE
                            | AudioManager.FLAG_FROM_KEY;
                    mMediaController.adjustVolume(0, flags);
                    mMediaController.dispatchVolumeButtonEventAsSystemService(event);
                } else {
                    MediaSessionLegacyHelper.getHelper(getContext()).sendVolumeKeyEvent(
                            event, mVolumeControlStreamType, false);
                    getMediaSessionManager().dispatchVolumeKeyEventAsSystemService(
                            event, mVolumeControlStreamType);
                }
                return true;
            }
@@ -1982,8 +1977,8 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
                // doesn't have one of these.  In this case, we execute it here and
                // eat the event instead, because we have mVolumeControlStreamType
                // and they don't.
                MediaSessionLegacyHelper.getHelper(getContext()).sendVolumeKeyEvent(
                        event, AudioManager.USE_DEFAULT_STREAM_TYPE, false);
                getMediaSessionManager().dispatchVolumeKeyEventAsSystemService(
                        event, AudioManager.USE_DEFAULT_STREAM_TYPE);
                return true;
            }
            // These are all the recognized media key codes in
@@ -2000,7 +1995,7 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
            case KeyEvent.KEYCODE_MEDIA_RECORD:
            case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD: {
                if (mMediaController != null) {
                    if (mMediaController.dispatchMediaButtonEvent(event)) {
                    if (mMediaController.dispatchMediaButtonEventAsSystemService(event)) {
                        return true;
                    }
                }
+2 −2
Original line number Diff line number Diff line
@@ -37,7 +37,7 @@ import java.util.List;
 */
interface ISessionController {
    void sendCommand(String packageName, String command, in Bundle args, in ResultReceiver cb);
    boolean sendMediaButton(String packageName, in KeyEvent mediaButton);
    boolean sendMediaButton(String packageName, boolean asSystemService, in KeyEvent mediaButton);
    void registerCallbackListener(in ISessionControllerCallback cb);
    void unregisterCallbackListener(in ISessionControllerCallback cb);
    boolean isTransportControlEnabled();
@@ -46,7 +46,7 @@ interface ISessionController {
    PendingIntent getLaunchPendingIntent();
    long getFlags();
    ParcelableVolumeInfo getVolumeAttributes();
    void adjustVolume(String packageName, int direction, int flags);
    void adjustVolume(String packageName, boolean asSystemService, int direction, int flags);
    void setVolumeTo(String packageName, int value, int flags);

    // These commands are for the TransportControls
+5 −3
Original line number Diff line number Diff line
@@ -34,9 +34,11 @@ import android.view.KeyEvent;
interface ISessionManager {
    ISession createSession(String packageName, in ISessionCallback cb, String tag, int userId);
    List<IBinder> getSessions(in ComponentName compName, int userId);
    void dispatchMediaKeyEvent(in KeyEvent keyEvent, boolean needWakeLock);
    void dispatchVolumeKeyEvent(in KeyEvent keyEvent, int stream, boolean musicOnly);
    void dispatchAdjustVolume(int suggestedStream, int delta, int flags);
    void dispatchMediaKeyEvent(String packageName, boolean asSystemService, in KeyEvent keyEvent,
            boolean needWakeLock);
    void dispatchVolumeKeyEvent(String packageName, boolean asSystemService, in KeyEvent keyEvent,
            int stream, boolean musicOnly);
    void dispatchAdjustVolume(String packageName, int suggestedStream, int delta, int flags);
    void addSessionsListener(in IActiveSessionsListener listener, in ComponentName compName,
            int userId);
    void removeSessionsListener(in IActiveSessionsListener listener);
Loading