Merge "Add context to customization class constructors"
This commit is contained in:
@@ -20,6 +20,7 @@ import android.annotation.IntDef;
|
|||||||
import android.annotation.NonNull;
|
import android.annotation.NonNull;
|
||||||
import android.annotation.Nullable;
|
import android.annotation.Nullable;
|
||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
|
import android.content.Context;
|
||||||
import android.media.session.ISessionManager;
|
import android.media.session.ISessionManager;
|
||||||
import android.media.session.MediaSession;
|
import android.media.session.MediaSession;
|
||||||
import android.os.Binder;
|
import android.os.Binder;
|
||||||
@@ -60,7 +61,7 @@ public abstract class MediaKeyDispatcher {
|
|||||||
|
|
||||||
private Map<Integer, Integer> mOverriddenKeyEvents;
|
private Map<Integer, Integer> mOverriddenKeyEvents;
|
||||||
|
|
||||||
public MediaKeyDispatcher() {
|
public MediaKeyDispatcher(Context context) {
|
||||||
// Constructor used for reflection
|
// Constructor used for reflection
|
||||||
mOverriddenKeyEvents = new HashMap<>();
|
mOverriddenKeyEvents = new HashMap<>();
|
||||||
mOverriddenKeyEvents.put(KeyEvent.KEYCODE_MEDIA_PLAY, 0);
|
mOverriddenKeyEvents.put(KeyEvent.KEYCODE_MEDIA_PLAY, 0);
|
||||||
|
|||||||
@@ -96,7 +96,6 @@ import java.lang.reflect.InvocationTargetException;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* System implementation of MediaSessionManager
|
* System implementation of MediaSessionManager
|
||||||
@@ -152,7 +151,6 @@ public class MediaSessionService extends SystemService implements Monitor {
|
|||||||
|
|
||||||
private SessionPolicyProvider mCustomSessionPolicyProvider;
|
private SessionPolicyProvider mCustomSessionPolicyProvider;
|
||||||
private MediaKeyDispatcher mCustomMediaKeyDispatcher;
|
private MediaKeyDispatcher mCustomMediaKeyDispatcher;
|
||||||
private Map<Integer, Integer> mOverriddenKeyEventsMap;
|
|
||||||
|
|
||||||
public MediaSessionService(Context context) {
|
public MediaSessionService(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
@@ -771,7 +769,6 @@ public class MediaSessionService extends SystemService implements Monitor {
|
|||||||
private void instantiateCustomDispatcher(String nameFromTesting) {
|
private void instantiateCustomDispatcher(String nameFromTesting) {
|
||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
mCustomMediaKeyDispatcher = null;
|
mCustomMediaKeyDispatcher = null;
|
||||||
mOverriddenKeyEventsMap = null;
|
|
||||||
|
|
||||||
String customDispatcherClassName = (nameFromTesting == null)
|
String customDispatcherClassName = (nameFromTesting == null)
|
||||||
? mContext.getResources().getString(R.string.config_customMediaKeyDispatcher)
|
? mContext.getResources().getString(R.string.config_customMediaKeyDispatcher)
|
||||||
@@ -779,9 +776,10 @@ public class MediaSessionService extends SystemService implements Monitor {
|
|||||||
try {
|
try {
|
||||||
if (!TextUtils.isEmpty(customDispatcherClassName)) {
|
if (!TextUtils.isEmpty(customDispatcherClassName)) {
|
||||||
Class customDispatcherClass = Class.forName(customDispatcherClassName);
|
Class customDispatcherClass = Class.forName(customDispatcherClassName);
|
||||||
Constructor constructor = customDispatcherClass.getDeclaredConstructor();
|
Constructor constructor =
|
||||||
mCustomMediaKeyDispatcher = (MediaKeyDispatcher) constructor.newInstance();
|
customDispatcherClass.getDeclaredConstructor(Context.class);
|
||||||
mOverriddenKeyEventsMap = mCustomMediaKeyDispatcher.getOverriddenKeyEvents();
|
mCustomMediaKeyDispatcher =
|
||||||
|
(MediaKeyDispatcher) constructor.newInstance(mContext);
|
||||||
}
|
}
|
||||||
} catch (ClassNotFoundException | InstantiationException | InvocationTargetException
|
} catch (ClassNotFoundException | InstantiationException | InvocationTargetException
|
||||||
| IllegalAccessException | NoSuchMethodException e) {
|
| IllegalAccessException | NoSuchMethodException e) {
|
||||||
@@ -801,9 +799,10 @@ public class MediaSessionService extends SystemService implements Monitor {
|
|||||||
try {
|
try {
|
||||||
if (!TextUtils.isEmpty(customProviderClassName)) {
|
if (!TextUtils.isEmpty(customProviderClassName)) {
|
||||||
Class customProviderClass = Class.forName(customProviderClassName);
|
Class customProviderClass = Class.forName(customProviderClassName);
|
||||||
Constructor constructor = customProviderClass.getDeclaredConstructor();
|
Constructor constructor =
|
||||||
|
customProviderClass.getDeclaredConstructor(Context.class);
|
||||||
mCustomSessionPolicyProvider =
|
mCustomSessionPolicyProvider =
|
||||||
(SessionPolicyProvider) constructor.newInstance();
|
(SessionPolicyProvider) constructor.newInstance(mContext);
|
||||||
}
|
}
|
||||||
} catch (ClassNotFoundException | InstantiationException | InvocationTargetException
|
} catch (ClassNotFoundException | InstantiationException | InvocationTargetException
|
||||||
| IllegalAccessException | NoSuchMethodException e) {
|
| IllegalAccessException | NoSuchMethodException e) {
|
||||||
@@ -2398,9 +2397,12 @@ public class MediaSessionService extends SystemService implements Monitor {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int overriddenKeyEvents = (mCustomMediaKeyDispatcher == null) ? 0
|
int overriddenKeyEvents = 0;
|
||||||
: mCustomMediaKeyDispatcher.getOverriddenKeyEvents()
|
if (mCustomMediaKeyDispatcher != null
|
||||||
.get(keyEvent.getKeyCode());
|
&& mCustomMediaKeyDispatcher.getOverriddenKeyEvents() != null) {
|
||||||
|
overriddenKeyEvents = mCustomMediaKeyDispatcher.getOverriddenKeyEvents()
|
||||||
|
.get(keyEvent.getKeyCode());
|
||||||
|
}
|
||||||
cancelTrackingIfNeeded(packageName, pid, uid, asSystemService, keyEvent,
|
cancelTrackingIfNeeded(packageName, pid, uid, asSystemService, keyEvent,
|
||||||
needWakeLock, opPackageName, stream, musicOnly, overriddenKeyEvents);
|
needWakeLock, opPackageName, stream, musicOnly, overriddenKeyEvents);
|
||||||
if (!needTracking(keyEvent, overriddenKeyEvents)) {
|
if (!needTracking(keyEvent, overriddenKeyEvents)) {
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ package com.android.server.media;
|
|||||||
|
|
||||||
import android.annotation.IntDef;
|
import android.annotation.IntDef;
|
||||||
import android.annotation.NonNull;
|
import android.annotation.NonNull;
|
||||||
|
import android.content.Context;
|
||||||
import android.media.session.MediaSession;
|
import android.media.session.MediaSession;
|
||||||
|
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
||||||
@@ -54,7 +55,7 @@ public abstract class SessionPolicyProvider {
|
|||||||
*/
|
*/
|
||||||
static final int SESSION_POLICY_IGNORE_BUTTON_SESSION = 1 << 1;
|
static final int SESSION_POLICY_IGNORE_BUTTON_SESSION = 1 << 1;
|
||||||
|
|
||||||
public SessionPolicyProvider() {
|
public SessionPolicyProvider(Context context) {
|
||||||
// Constructor used for reflection
|
// Constructor used for reflection
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user