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

Commit 69ab24af authored by Jin Seok Park's avatar Jin Seok Park Committed by Automerger Merge Worker
Browse files

Merge "Add context to customization class constructors" am: ade2da5f am:...

Merge "Add context to customization class constructors" am: ade2da5f am: 7ada26bb am: c3af34c8

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1426657

Change-Id: I57585f182507967596e8abe9e937f517ae4d1739
parents bb6b04ca c3af34c8
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.app.PendingIntent;
import android.content.Context;
import android.media.session.ISessionManager;
import android.media.session.MediaSession;
import android.os.Binder;
@@ -60,7 +61,7 @@ public abstract class MediaKeyDispatcher {

    private Map<Integer, Integer> mOverriddenKeyEvents;

    public MediaKeyDispatcher() {
    public MediaKeyDispatcher(Context context) {
        // Constructor used for reflection
        mOverriddenKeyEvents = new HashMap<>();
        mOverriddenKeyEvents.put(KeyEvent.KEYCODE_MEDIA_PLAY, 0);
+13 −11
Original line number Diff line number Diff line
@@ -94,7 +94,6 @@ import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * System implementation of MediaSessionManager
@@ -149,7 +148,6 @@ public class MediaSessionService extends SystemService implements Monitor {

    private SessionPolicyProvider mCustomSessionPolicyProvider;
    private MediaKeyDispatcher mCustomMediaKeyDispatcher;
    private Map<Integer, Integer> mOverriddenKeyEventsMap;

    public MediaSessionService(Context context) {
        super(context);
@@ -780,7 +778,6 @@ public class MediaSessionService extends SystemService implements Monitor {
    private void instantiateCustomDispatcher(String nameFromTesting) {
        synchronized (mLock) {
            mCustomMediaKeyDispatcher = null;
            mOverriddenKeyEventsMap = null;

            String customDispatcherClassName = (nameFromTesting == null)
                    ? mContext.getResources().getString(R.string.config_customMediaKeyDispatcher)
@@ -788,9 +785,10 @@ public class MediaSessionService extends SystemService implements Monitor {
            try {
                if (!TextUtils.isEmpty(customDispatcherClassName)) {
                    Class customDispatcherClass = Class.forName(customDispatcherClassName);
                    Constructor constructor = customDispatcherClass.getDeclaredConstructor();
                    mCustomMediaKeyDispatcher = (MediaKeyDispatcher) constructor.newInstance();
                    mOverriddenKeyEventsMap = mCustomMediaKeyDispatcher.getOverriddenKeyEvents();
                    Constructor constructor =
                            customDispatcherClass.getDeclaredConstructor(Context.class);
                    mCustomMediaKeyDispatcher =
                            (MediaKeyDispatcher) constructor.newInstance(mContext);
                }
            } catch (ClassNotFoundException | InstantiationException | InvocationTargetException
                    | IllegalAccessException | NoSuchMethodException e) {
@@ -810,9 +808,10 @@ public class MediaSessionService extends SystemService implements Monitor {
            try {
                if (!TextUtils.isEmpty(customProviderClassName)) {
                    Class customProviderClass = Class.forName(customProviderClassName);
                    Constructor constructor = customProviderClass.getDeclaredConstructor();
                    Constructor constructor =
                            customProviderClass.getDeclaredConstructor(Context.class);
                    mCustomSessionPolicyProvider =
                            (SessionPolicyProvider) constructor.newInstance();
                            (SessionPolicyProvider) constructor.newInstance(mContext);
                }
            } catch (ClassNotFoundException | InstantiationException | InvocationTargetException
                    | IllegalAccessException | NoSuchMethodException e) {
@@ -2382,9 +2381,12 @@ public class MediaSessionService extends SystemService implements Monitor {
                    return;
                }

                int overriddenKeyEvents = (mCustomMediaKeyDispatcher == null) ? 0
                        : mCustomMediaKeyDispatcher.getOverriddenKeyEvents()
                int overriddenKeyEvents = 0;
                if (mCustomMediaKeyDispatcher == null
                        && mCustomMediaKeyDispatcher.getOverriddenKeyEvents() != null) {
                    overriddenKeyEvents = mCustomMediaKeyDispatcher.getOverriddenKeyEvents()
                            .get(keyEvent.getKeyCode());
                }
                cancelTrackingIfNeeded(packageName, pid, uid, asSystemService, keyEvent,
                        needWakeLock, opPackageName, stream, musicOnly, overriddenKeyEvents);
                if (!needTracking(keyEvent, overriddenKeyEvents)) {
+2 −1
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.server.media;

import android.annotation.IntDef;
import android.annotation.NonNull;
import android.content.Context;
import android.media.session.MediaSession;

import java.lang.annotation.Retention;
@@ -54,7 +55,7 @@ public abstract class SessionPolicyProvider {
     */
    static final int SESSION_POLICY_IGNORE_BUTTON_SESSION = 1 << 1;

    public SessionPolicyProvider() {
    public SessionPolicyProvider(Context context) {
        // Constructor used for reflection
    }