Merge "[Media ML] Add get/setSessionPolicies APIs" into rvc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
02e59dd951
@@ -75,4 +75,6 @@ interface ISessionManager {
|
||||
boolean isTrusted(String controllerPackageName, int controllerPid, int controllerUid);
|
||||
void setCustomMediaKeyDispatcherForTesting(String name);
|
||||
void setCustomSessionPolicyProviderForTesting(String name);
|
||||
int getSessionPolicies(in MediaSession.Token token);
|
||||
void setSessionPolicies(in MediaSession.Token token, int policies);
|
||||
}
|
||||
|
||||
@@ -912,6 +912,34 @@ public final class MediaSessionManager {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get session policies of the specified {@link MediaSession.Token}.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
@Nullable
|
||||
public int getSessionPolicies(@NonNull MediaSession.Token token) {
|
||||
try {
|
||||
return mService.getSessionPolicies(token);
|
||||
} catch (RemoteException e) {
|
||||
Log.e(TAG, "Failed to get session policies", e);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set new session policies to the specified {@link MediaSession.Token}.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
public void setSessionPolicies(@NonNull MediaSession.Token token, @Nullable int policies) {
|
||||
try {
|
||||
mService.setSessionPolicies(token, policies);
|
||||
} catch (RemoteException e) {
|
||||
Log.e(TAG, "Failed to set session policies", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Listens for changes to the list of active sessions. This can be added
|
||||
* using {@link #addOnActiveSessionsChangedListener}.
|
||||
|
||||
@@ -166,7 +166,7 @@ class AudioPlayerStateMonitor {
|
||||
* Cleans up the sorted list of audio playback client UIDs with given {@param
|
||||
* mediaButtonSessionUid}.
|
||||
* <p>UIDs whose audio playback are inactive and have started before the media button session's
|
||||
* audio playback cannot be the lastly played media app. So they won't needed anymore.
|
||||
* audio playback cannot be the lastly played media app. So they won't be needed anymore.
|
||||
*
|
||||
* @param mediaButtonSessionUid UID of the media button session.
|
||||
*/
|
||||
|
||||
@@ -1973,6 +1973,34 @@ public class MediaSessionService extends SystemService implements Monitor {
|
||||
instantiateCustomProvider(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSessionPolicies(MediaSession.Token token) {
|
||||
synchronized (mLock) {
|
||||
MediaSessionRecord record = getMediaSessionRecordLocked(token);
|
||||
if (record != null) {
|
||||
return record.getSessionPolicies();
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSessionPolicies(MediaSession.Token token, int policies) {
|
||||
final long callingIdentityToken = Binder.clearCallingIdentity();
|
||||
try {
|
||||
synchronized (mLock) {
|
||||
MediaSessionRecord record = getMediaSessionRecordLocked(token);
|
||||
FullUserRecord user = getFullUserRecordLocked(record.getUserId());
|
||||
if (record != null && user != null) {
|
||||
record.setSessionPolicies(policies);
|
||||
user.mPriorityStack.updateMediaButtonSessionIfNeeded();
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
Binder.restoreCallingIdentity(callingIdentityToken);
|
||||
}
|
||||
}
|
||||
|
||||
// For MediaSession
|
||||
private int verifySessionsRequest(ComponentName componentName, int userId, final int pid,
|
||||
final int uid) {
|
||||
|
||||
@@ -156,7 +156,11 @@ class MediaSessionStack {
|
||||
if (mMediaButtonSession != null && mMediaButtonSession.getUid() == record.getUid()) {
|
||||
MediaSessionRecordImpl newMediaButtonSession =
|
||||
findMediaButtonSession(mMediaButtonSession.getUid());
|
||||
if (newMediaButtonSession != mMediaButtonSession) {
|
||||
if (newMediaButtonSession != mMediaButtonSession
|
||||
&& (newMediaButtonSession.getSessionPolicies()
|
||||
& SessionPolicyProvider.SESSION_POLICY_IGNORE_BUTTON_SESSION) == 0) {
|
||||
// Check if the policy states that this session should not be updated as a media
|
||||
// button session.
|
||||
updateMediaButtonSession(newMediaButtonSession);
|
||||
}
|
||||
}
|
||||
@@ -187,14 +191,15 @@ class MediaSessionStack {
|
||||
for (int i = 0; i < audioPlaybackUids.size(); i++) {
|
||||
MediaSessionRecordImpl mediaButtonSession =
|
||||
findMediaButtonSession(audioPlaybackUids.get(i));
|
||||
if (mediaButtonSession != null
|
||||
&& (mediaButtonSession.getSessionPolicies()
|
||||
& SessionPolicyProvider.SESSION_POLICY_IGNORE_BUTTON_SESSION) == 0) {
|
||||
// Found the media button session.
|
||||
mAudioPlayerStateMonitor.cleanUpAudioPlaybackUids(mediaButtonSession.getUid());
|
||||
if (mMediaButtonSession != mediaButtonSession) {
|
||||
updateMediaButtonSession(mediaButtonSession);
|
||||
}
|
||||
if (mediaButtonSession == null) continue;
|
||||
boolean ignoreButtonSession = (mediaButtonSession.getSessionPolicies()
|
||||
& SessionPolicyProvider.SESSION_POLICY_IGNORE_BUTTON_SESSION) != 0;
|
||||
if (mediaButtonSession == mMediaButtonSession && ignoreButtonSession) {
|
||||
updateMediaButtonSession(null);
|
||||
return;
|
||||
}
|
||||
if (mediaButtonSession != mMediaButtonSession && !ignoreButtonSession) {
|
||||
updateMediaButtonSession(mediaButtonSession);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -276,15 +281,6 @@ class MediaSessionStack {
|
||||
}
|
||||
|
||||
private void updateMediaButtonSession(MediaSessionRecordImpl newMediaButtonSession) {
|
||||
// Check if the policy states that this session should not be updated as a media button
|
||||
// session.
|
||||
if (newMediaButtonSession != null) {
|
||||
int policies = newMediaButtonSession.getSessionPolicies();
|
||||
if ((policies & SessionPolicyProvider.SESSION_POLICY_IGNORE_BUTTON_SESSION) != 0) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
MediaSessionRecordImpl oldMediaButtonSession = mMediaButtonSession;
|
||||
mMediaButtonSession = newMediaButtonSession;
|
||||
mOnMediaButtonSessionChangedListener.onMediaButtonSessionChanged(
|
||||
|
||||
Reference in New Issue
Block a user