Merge "[Media ML] Expose config values for OEMs to set custom classes" into sc-dev am: ee9b56d9bc
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/13451717 MUST ONLY BE SUBMITTED BY AUTOMERGER Change-Id: I43d291af1e44bff31b62f3a03db0344f072a3968
This commit is contained in:
@@ -333,6 +333,8 @@ package android {
|
||||
}
|
||||
|
||||
public static final class R.string {
|
||||
field public static final int config_customMediaKeyDispatcher = 17039404; // 0x104002c
|
||||
field public static final int config_customMediaSessionPolicyProvider = 17039405; // 0x104002d
|
||||
field public static final int config_defaultAssistant = 17039393; // 0x1040021
|
||||
field public static final int config_defaultBrowser = 17039394; // 0x1040022
|
||||
field public static final int config_defaultCallRedirection = 17039397; // 0x1040025
|
||||
|
||||
@@ -4592,11 +4592,12 @@
|
||||
<item>com.android.systemui</item>
|
||||
</string-array>
|
||||
|
||||
<!-- Package name of custom media key dispatcher class used by MediaSessionService. -->
|
||||
<!-- Component name of custom media key dispatcher class used by MediaSessionService. -->
|
||||
<string name="config_customMediaKeyDispatcher"></string>
|
||||
|
||||
<!-- Package name of custom session policy provider class used by MediaSessionService. -->
|
||||
<string name="config_customSessionPolicyProvider"></string>
|
||||
<!-- Component name of custom media session policy provider class used by
|
||||
MediaSessionService. -->
|
||||
<string name="config_customMediaSessionPolicyProvider"></string>
|
||||
|
||||
<!-- The max scale for the wallpaper when it's zoomed in -->
|
||||
<item name="config_wallpaperMaxScale" format="float" type="dimen">1.10</item>
|
||||
|
||||
@@ -3153,6 +3153,10 @@
|
||||
<public name="config_systemShell" />
|
||||
<!-- @hide @SystemApi -->
|
||||
<public name="config_systemContacts" />
|
||||
<!-- @hide @SystemApi -->
|
||||
<public name="config_customMediaKeyDispatcher" />
|
||||
<!-- @hide @SystemApi -->
|
||||
<public name="config_customMediaSessionPolicyProvider" />
|
||||
</public-group>
|
||||
|
||||
<public-group type="id" first-id="0x01020055">
|
||||
|
||||
@@ -4115,8 +4115,6 @@
|
||||
|
||||
<java-symbol type="string" name="notification_history_title_placeholder" />
|
||||
|
||||
<java-symbol type="string" name="config_customMediaKeyDispatcher" />
|
||||
<java-symbol type="string" name="config_customSessionPolicyProvider" />
|
||||
<!-- The max scale for the wallpaper when it's zoomed in -->
|
||||
<java-symbol type="dimen" name="config_wallpaperMaxScale"/>
|
||||
|
||||
|
||||
@@ -73,8 +73,10 @@ interface ISessionManager {
|
||||
void setOnMediaKeyListener(in IOnMediaKeyListener listener);
|
||||
|
||||
boolean isTrusted(String controllerPackageName, int controllerPid, int controllerUid);
|
||||
void setCustomMediaKeyDispatcherForTesting(String name);
|
||||
void setCustomSessionPolicyProviderForTesting(String name);
|
||||
void setCustomMediaKeyDispatcher(String name);
|
||||
void setCustomMediaSessionPolicyProvider(String name);
|
||||
boolean hasCustomMediaKeyDispatcher(String componentName);
|
||||
boolean hasCustomMediaSessionPolicyProvider(String componentName);
|
||||
int getSessionPolicies(in MediaSession.Token token);
|
||||
void setSessionPolicies(in MediaSession.Token token, int policies);
|
||||
}
|
||||
|
||||
@@ -958,9 +958,9 @@ public final class MediaSessionManager {
|
||||
* @hide
|
||||
*/
|
||||
@VisibleForTesting
|
||||
public void setCustomMediaKeyDispatcherForTesting(@Nullable String name) {
|
||||
public void setCustomMediaKeyDispatcher(@Nullable String name) {
|
||||
try {
|
||||
mService.setCustomMediaKeyDispatcherForTesting(name);
|
||||
mService.setCustomMediaKeyDispatcher(name);
|
||||
} catch (RemoteException e) {
|
||||
Log.e(TAG, "Failed to set custom media key dispatcher name", e);
|
||||
}
|
||||
@@ -968,21 +968,57 @@ public final class MediaSessionManager {
|
||||
|
||||
/**
|
||||
* Set the component name for the custom
|
||||
* {@link com.android.server.media.SessionPolicyProvider} class. Set to null to restore to the
|
||||
* custom {@link com.android.server.media.SessionPolicyProvider} class name retrieved from the
|
||||
* config value.
|
||||
* {@link com.android.server.media.MediaSessionPolicyProvider} class. Set to null to restore to
|
||||
* the custom {@link com.android.server.media.MediaSessionPolicyProvider} class name retrieved
|
||||
* from the config value.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
@VisibleForTesting
|
||||
public void setCustomSessionPolicyProviderForTesting(@Nullable String name) {
|
||||
public void setCustomMediaSessionPolicyProvider(@Nullable String name) {
|
||||
try {
|
||||
mService.setCustomSessionPolicyProviderForTesting(name);
|
||||
mService.setCustomMediaSessionPolicyProvider(name);
|
||||
} catch (RemoteException e) {
|
||||
Log.e(TAG, "Failed to set custom session policy provider name", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the component name for the custom {@link com.android.server.media.MediaKeyDispatcher}
|
||||
* class.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
@VisibleForTesting
|
||||
public boolean hasCustomMediaKeyDispatcher(@NonNull String componentName) {
|
||||
Objects.requireNonNull(componentName, "componentName shouldn't be null");
|
||||
try {
|
||||
return mService.hasCustomMediaKeyDispatcher(componentName);
|
||||
} catch (RemoteException e) {
|
||||
Log.e(TAG, "Failed to check if custom media key dispatcher with given component"
|
||||
+ " name exists", e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the component name for the custom
|
||||
* {@link com.android.server.media.MediaSessionPolicyProvider} class.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
@VisibleForTesting
|
||||
public boolean hasCustomMediaSessionPolicyProvider(@NonNull String componentName) {
|
||||
Objects.requireNonNull(componentName, "componentName shouldn't be null");
|
||||
try {
|
||||
return mService.hasCustomMediaSessionPolicyProvider(componentName);
|
||||
} catch (RemoteException e) {
|
||||
Log.e(TAG, "Failed to check if custom media session policy provider with given"
|
||||
+ " component name exists", e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get session policies of the specified {@link MediaSession.Token}.
|
||||
*
|
||||
|
||||
@@ -77,7 +77,7 @@ public abstract class MediaKeyDispatcher {
|
||||
mOverriddenKeyEvents.put(KeyEvent.KEYCODE_VOLUME_MUTE, 0);
|
||||
}
|
||||
|
||||
// TODO: Move this method into SessionPolicyProvider.java for better readability.
|
||||
// TODO: Move this method into MediaSessionPolicyProvider.java for better readability.
|
||||
/**
|
||||
* Implement this to customize the logic for which MediaSession should consume which key event.
|
||||
*
|
||||
|
||||
@@ -31,7 +31,7 @@ import java.lang.annotation.RetentionPolicy;
|
||||
* without any parameters.
|
||||
*/
|
||||
// TODO: Move this class to apex/media/
|
||||
public abstract class SessionPolicyProvider {
|
||||
public abstract class MediaSessionPolicyProvider {
|
||||
@IntDef(value = {
|
||||
SESSION_POLICY_IGNORE_BUTTON_RECEIVER,
|
||||
SESSION_POLICY_IGNORE_BUTTON_SESSION
|
||||
@@ -55,7 +55,7 @@ public abstract class SessionPolicyProvider {
|
||||
*/
|
||||
static final int SESSION_POLICY_IGNORE_BUTTON_SESSION = 1 << 1;
|
||||
|
||||
public SessionPolicyProvider(Context context) {
|
||||
public MediaSessionPolicyProvider(Context context) {
|
||||
// Constructor used for reflection
|
||||
}
|
||||
|
||||
@@ -895,7 +895,7 @@ public class MediaSessionRecord implements IBinder.DeathRecipient, MediaSessionR
|
||||
throws RemoteException {
|
||||
final long token = Binder.clearCallingIdentity();
|
||||
try {
|
||||
if ((mPolicies & SessionPolicyProvider.SESSION_POLICY_IGNORE_BUTTON_RECEIVER)
|
||||
if ((mPolicies & MediaSessionPolicyProvider.SESSION_POLICY_IGNORE_BUTTON_RECEIVER)
|
||||
!= 0) {
|
||||
return;
|
||||
}
|
||||
@@ -911,7 +911,7 @@ public class MediaSessionRecord implements IBinder.DeathRecipient, MediaSessionR
|
||||
public void setMediaButtonBroadcastReceiver(ComponentName receiver) throws RemoteException {
|
||||
final long token = Binder.clearCallingIdentity();
|
||||
try {
|
||||
if ((mPolicies & SessionPolicyProvider.SESSION_POLICY_IGNORE_BUTTON_RECEIVER)
|
||||
if ((mPolicies & MediaSessionPolicyProvider.SESSION_POLICY_IGNORE_BUTTON_RECEIVER)
|
||||
!= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ import android.media.AudioManager;
|
||||
import android.os.ResultReceiver;
|
||||
import android.view.KeyEvent;
|
||||
|
||||
import com.android.server.media.SessionPolicyProvider.SessionPolicy;
|
||||
import com.android.server.media.MediaSessionPolicyProvider.SessionPolicy;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
|
||||
|
||||
@@ -148,7 +148,7 @@ public class MediaSessionService extends SystemService implements Monitor {
|
||||
final RemoteCallbackList<IRemoteSessionCallback> mRemoteVolumeControllers =
|
||||
new RemoteCallbackList<>();
|
||||
|
||||
private SessionPolicyProvider mCustomSessionPolicyProvider;
|
||||
private MediaSessionPolicyProvider mCustomMediaSessionPolicyProvider;
|
||||
private MediaKeyDispatcher mCustomMediaKeyDispatcher;
|
||||
|
||||
public MediaSessionService(Context context) {
|
||||
@@ -191,8 +191,10 @@ public class MediaSessionService extends SystemService implements Monitor {
|
||||
|
||||
updateUser();
|
||||
|
||||
instantiateCustomProvider(null);
|
||||
instantiateCustomDispatcher(null);
|
||||
instantiateCustomProvider(mContext.getResources().getString(
|
||||
R.string.config_customMediaSessionPolicyProvider));
|
||||
instantiateCustomDispatcher(mContext.getResources().getString(
|
||||
R.string.config_customMediaKeyDispatcher));
|
||||
mRecordThread.start();
|
||||
|
||||
final IntentFilter filter = new IntentFilter(
|
||||
@@ -589,8 +591,8 @@ public class MediaSessionService extends SystemService implements Monitor {
|
||||
String callerPackageName, ISessionCallback cb, String tag, Bundle sessionInfo) {
|
||||
synchronized (mLock) {
|
||||
int policies = 0;
|
||||
if (mCustomSessionPolicyProvider != null) {
|
||||
policies = mCustomSessionPolicyProvider.getSessionPoliciesForApplication(
|
||||
if (mCustomMediaSessionPolicyProvider != null) {
|
||||
policies = mCustomMediaSessionPolicyProvider.getSessionPoliciesForApplication(
|
||||
callerUid, callerPackageName);
|
||||
}
|
||||
|
||||
@@ -778,16 +780,13 @@ public class MediaSessionService extends SystemService implements Monitor {
|
||||
return null;
|
||||
}
|
||||
|
||||
private void instantiateCustomDispatcher(String nameFromTesting) {
|
||||
private void instantiateCustomDispatcher(String componentName) {
|
||||
synchronized (mLock) {
|
||||
mCustomMediaKeyDispatcher = null;
|
||||
|
||||
String customDispatcherClassName = (nameFromTesting == null)
|
||||
? mContext.getResources().getString(R.string.config_customMediaKeyDispatcher)
|
||||
: nameFromTesting;
|
||||
try {
|
||||
if (!TextUtils.isEmpty(customDispatcherClassName)) {
|
||||
Class customDispatcherClass = Class.forName(customDispatcherClassName);
|
||||
if (componentName != null && !TextUtils.isEmpty(componentName)) {
|
||||
Class customDispatcherClass = Class.forName(componentName);
|
||||
Constructor constructor =
|
||||
customDispatcherClass.getDeclaredConstructor(Context.class);
|
||||
mCustomMediaKeyDispatcher =
|
||||
@@ -801,20 +800,17 @@ public class MediaSessionService extends SystemService implements Monitor {
|
||||
}
|
||||
}
|
||||
|
||||
private void instantiateCustomProvider(String nameFromTesting) {
|
||||
private void instantiateCustomProvider(String componentName) {
|
||||
synchronized (mLock) {
|
||||
mCustomSessionPolicyProvider = null;
|
||||
mCustomMediaSessionPolicyProvider = null;
|
||||
|
||||
String customProviderClassName = (nameFromTesting == null)
|
||||
? mContext.getResources().getString(R.string.config_customSessionPolicyProvider)
|
||||
: nameFromTesting;
|
||||
try {
|
||||
if (!TextUtils.isEmpty(customProviderClassName)) {
|
||||
Class customProviderClass = Class.forName(customProviderClassName);
|
||||
if (componentName != null && !TextUtils.isEmpty(componentName)) {
|
||||
Class customProviderClass = Class.forName(componentName);
|
||||
Constructor constructor =
|
||||
customProviderClass.getDeclaredConstructor(Context.class);
|
||||
mCustomSessionPolicyProvider =
|
||||
(SessionPolicyProvider) constructor.newInstance(mContext);
|
||||
mCustomMediaSessionPolicyProvider =
|
||||
(MediaSessionPolicyProvider) constructor.newInstance(mContext);
|
||||
}
|
||||
} catch (ClassNotFoundException | InstantiationException | InvocationTargetException
|
||||
| IllegalAccessException | NoSuchMethodException e) {
|
||||
@@ -1933,15 +1929,29 @@ public class MediaSessionService extends SystemService implements Monitor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCustomMediaKeyDispatcherForTesting(String name) {
|
||||
public void setCustomMediaKeyDispatcher(String name) {
|
||||
instantiateCustomDispatcher(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCustomSessionPolicyProviderForTesting(String name) {
|
||||
public void setCustomMediaSessionPolicyProvider(String name) {
|
||||
instantiateCustomProvider(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomMediaKeyDispatcher(String componentName) {
|
||||
return mCustomMediaKeyDispatcher == null ? false
|
||||
: TextUtils.equals(componentName,
|
||||
mCustomMediaKeyDispatcher.getClass().getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomMediaSessionPolicyProvider(String componentName) {
|
||||
return mCustomMediaSessionPolicyProvider == null ? false
|
||||
: TextUtils.equals(componentName,
|
||||
mCustomMediaSessionPolicyProvider.getClass().getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSessionPolicies(MediaSession.Token token) {
|
||||
synchronized (mLock) {
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
package com.android.server.media;
|
||||
|
||||
import static com.android.server.media.SessionPolicyProvider.SESSION_POLICY_IGNORE_BUTTON_SESSION;
|
||||
import static com.android.server.media.MediaSessionPolicyProvider.SESSION_POLICY_IGNORE_BUTTON_SESSION;
|
||||
|
||||
import android.media.Session2Token;
|
||||
import android.media.session.MediaSession;
|
||||
|
||||
Reference in New Issue
Block a user