mirror of
https://github.com/androidx/media.git
synced 2025-04-30 06:46:50 +08:00
Add sessionImpl to PostSessionTask
In some cases it's helpful to have access to the session (e.g. to get the PlayerWrapper) from within the PostSessionTask implementations. This change forwards the existing sessionImpl instance to all these callbacks. PiperOrigin-RevId: 451857191
This commit is contained in:
parent
6d776a5ae4
commit
c814f791d7
@ -116,12 +116,13 @@ import java.util.concurrent.ExecutionException;
|
|||||||
return connectedControllersManager;
|
return connectedControllersManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void sendSessionResult(
|
private static <K extends MediaSessionImpl> void sendSessionResult(
|
||||||
ControllerInfo controller, int seq, @SessionResult.Code int resultCode) {
|
K sessionImpl, ControllerInfo controller, int seq, @SessionResult.Code int resultCode) {
|
||||||
sendSessionResult(controller, seq, new SessionResult(resultCode));
|
sendSessionResult(sessionImpl, controller, seq, new SessionResult(resultCode));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void sendSessionResult(ControllerInfo controller, int seq, SessionResult result) {
|
private static <K extends MediaSessionImpl> void sendSessionResult(
|
||||||
|
K sessionImpl, ControllerInfo controller, int seq, SessionResult result) {
|
||||||
try {
|
try {
|
||||||
checkStateNotNull(controller.getControllerCb()).onSessionResult(seq, result);
|
checkStateNotNull(controller.getControllerCb()).onSessionResult(seq, result);
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
@ -129,8 +130,8 @@ import java.util.concurrent.ExecutionException;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void sendSessionResultWhenReady(
|
private static <K extends MediaSessionImpl> void sendSessionResultWhenReady(
|
||||||
ControllerInfo controller, int seq, ListenableFuture<SessionResult> future) {
|
K sessionImpl, ControllerInfo controller, int seq, ListenableFuture<SessionResult> future) {
|
||||||
future.addListener(
|
future.addListener(
|
||||||
() -> {
|
() -> {
|
||||||
SessionResult result;
|
SessionResult result;
|
||||||
@ -141,7 +142,7 @@ import java.util.concurrent.ExecutionException;
|
|||||||
} catch (ExecutionException | InterruptedException unused) {
|
} catch (ExecutionException | InterruptedException unused) {
|
||||||
result = new SessionResult(SessionResult.RESULT_ERROR_UNKNOWN);
|
result = new SessionResult(SessionResult.RESULT_ERROR_UNKNOWN);
|
||||||
}
|
}
|
||||||
sendSessionResult(controller, seq, result);
|
sendSessionResult(sessionImpl, controller, seq, result);
|
||||||
},
|
},
|
||||||
MoreExecutors.directExecutor());
|
MoreExecutors.directExecutor());
|
||||||
}
|
}
|
||||||
@ -155,8 +156,11 @@ import java.util.concurrent.ExecutionException;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static <V> void sendLibraryResultWhenReady(
|
private static <V, K extends MediaSessionImpl> void sendLibraryResultWhenReady(
|
||||||
ControllerInfo controller, int seq, ListenableFuture<LibraryResult<V>> future) {
|
K sessionImpl,
|
||||||
|
ControllerInfo controller,
|
||||||
|
int seq,
|
||||||
|
ListenableFuture<LibraryResult<V>> future) {
|
||||||
future.addListener(
|
future.addListener(
|
||||||
() -> {
|
() -> {
|
||||||
LibraryResult<V> result;
|
LibraryResult<V> result;
|
||||||
@ -177,7 +181,7 @@ import java.util.concurrent.ExecutionException;
|
|||||||
int seq,
|
int seq,
|
||||||
@Player.Command int command,
|
@Player.Command int command,
|
||||||
SessionTask<T, K> task,
|
SessionTask<T, K> task,
|
||||||
PostSessionTask<T> postTask) {
|
PostSessionTask<T, K> postTask) {
|
||||||
long token = Binder.clearCallingIdentity();
|
long token = Binder.clearCallingIdentity();
|
||||||
try {
|
try {
|
||||||
@SuppressWarnings({"unchecked", "cast.unsafe"})
|
@SuppressWarnings({"unchecked", "cast.unsafe"})
|
||||||
@ -213,22 +217,25 @@ import java.util.concurrent.ExecutionException;
|
|||||||
@Player.Command int command,
|
@Player.Command int command,
|
||||||
K sessionImpl,
|
K sessionImpl,
|
||||||
SessionTask<T, K> task,
|
SessionTask<T, K> task,
|
||||||
PostSessionTask<T> postTask) {
|
PostSessionTask<T, K> postTask) {
|
||||||
return () -> {
|
return () -> {
|
||||||
if (!connectedControllersManager.isPlayerCommandAvailable(controller, command)) {
|
if (!connectedControllersManager.isPlayerCommandAvailable(controller, command)) {
|
||||||
sendSessionResult(
|
sendSessionResult(
|
||||||
controller, seq, new SessionResult(SessionResult.RESULT_ERROR_PERMISSION_DENIED));
|
sessionImpl,
|
||||||
|
controller,
|
||||||
|
seq,
|
||||||
|
new SessionResult(SessionResult.RESULT_ERROR_PERMISSION_DENIED));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@SessionResult.Code
|
@SessionResult.Code
|
||||||
int resultCode = sessionImpl.onPlayerCommandRequestOnHandler(controller, command);
|
int resultCode = sessionImpl.onPlayerCommandRequestOnHandler(controller, command);
|
||||||
if (resultCode != SessionResult.RESULT_SUCCESS) {
|
if (resultCode != SessionResult.RESULT_SUCCESS) {
|
||||||
// Don't run rejected command.
|
// Don't run rejected command.
|
||||||
sendSessionResult(controller, seq, new SessionResult(resultCode));
|
sendSessionResult(sessionImpl, controller, seq, new SessionResult(resultCode));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
T result = task.run(sessionImpl, controller);
|
T result = task.run(sessionImpl, controller);
|
||||||
postTask.run(controller, seq, result);
|
postTask.run(sessionImpl, controller, seq, result);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -237,7 +244,7 @@ import java.util.concurrent.ExecutionException;
|
|||||||
int seq,
|
int seq,
|
||||||
@CommandCode int commandCode,
|
@CommandCode int commandCode,
|
||||||
SessionTask<T, MediaLibrarySessionImpl> task,
|
SessionTask<T, MediaLibrarySessionImpl> task,
|
||||||
PostSessionTask<T> postTask) {
|
PostSessionTask<T, MediaLibrarySessionImpl> postTask) {
|
||||||
dispatchSessionTaskWithSessionCommandInternal(
|
dispatchSessionTaskWithSessionCommandInternal(
|
||||||
caller, seq, /* sessionCommand= */ null, commandCode, task, postTask);
|
caller, seq, /* sessionCommand= */ null, commandCode, task, postTask);
|
||||||
}
|
}
|
||||||
@ -247,7 +254,7 @@ import java.util.concurrent.ExecutionException;
|
|||||||
int seq,
|
int seq,
|
||||||
@CommandCode int commandCode,
|
@CommandCode int commandCode,
|
||||||
SessionTask<T, K> task,
|
SessionTask<T, K> task,
|
||||||
PostSessionTask<T> postTask) {
|
PostSessionTask<T, K> postTask) {
|
||||||
dispatchSessionTaskWithSessionCommandInternal(
|
dispatchSessionTaskWithSessionCommandInternal(
|
||||||
caller, seq, /* sessionCommand= */ null, commandCode, task, postTask);
|
caller, seq, /* sessionCommand= */ null, commandCode, task, postTask);
|
||||||
}
|
}
|
||||||
@ -257,7 +264,7 @@ import java.util.concurrent.ExecutionException;
|
|||||||
int seq,
|
int seq,
|
||||||
SessionCommand sessionCommand,
|
SessionCommand sessionCommand,
|
||||||
SessionTask<T, K> task,
|
SessionTask<T, K> task,
|
||||||
PostSessionTask<T> postTask) {
|
PostSessionTask<T, K> postTask) {
|
||||||
dispatchSessionTaskWithSessionCommandInternal(
|
dispatchSessionTaskWithSessionCommandInternal(
|
||||||
caller, seq, sessionCommand, COMMAND_CODE_CUSTOM, task, postTask);
|
caller, seq, sessionCommand, COMMAND_CODE_CUSTOM, task, postTask);
|
||||||
}
|
}
|
||||||
@ -268,7 +275,7 @@ import java.util.concurrent.ExecutionException;
|
|||||||
@Nullable SessionCommand sessionCommand,
|
@Nullable SessionCommand sessionCommand,
|
||||||
@CommandCode int commandCode,
|
@CommandCode int commandCode,
|
||||||
SessionTask<T, K> task,
|
SessionTask<T, K> task,
|
||||||
PostSessionTask<T> postTask) {
|
PostSessionTask<T, K> postTask) {
|
||||||
long token = Binder.clearCallingIdentity();
|
long token = Binder.clearCallingIdentity();
|
||||||
try {
|
try {
|
||||||
@SuppressWarnings({"unchecked", "cast.unsafe"})
|
@SuppressWarnings({"unchecked", "cast.unsafe"})
|
||||||
@ -292,6 +299,7 @@ import java.util.concurrent.ExecutionException;
|
|||||||
if (!connectedControllersManager.isSessionCommandAvailable(
|
if (!connectedControllersManager.isSessionCommandAvailable(
|
||||||
controller, sessionCommand)) {
|
controller, sessionCommand)) {
|
||||||
sendSessionResult(
|
sendSessionResult(
|
||||||
|
sessionImpl,
|
||||||
controller,
|
controller,
|
||||||
seq,
|
seq,
|
||||||
new SessionResult(SessionResult.RESULT_ERROR_PERMISSION_DENIED));
|
new SessionResult(SessionResult.RESULT_ERROR_PERMISSION_DENIED));
|
||||||
@ -300,6 +308,7 @@ import java.util.concurrent.ExecutionException;
|
|||||||
} else {
|
} else {
|
||||||
if (!connectedControllersManager.isSessionCommandAvailable(controller, commandCode)) {
|
if (!connectedControllersManager.isSessionCommandAvailable(controller, commandCode)) {
|
||||||
sendSessionResult(
|
sendSessionResult(
|
||||||
|
sessionImpl,
|
||||||
controller,
|
controller,
|
||||||
seq,
|
seq,
|
||||||
new SessionResult(SessionResult.RESULT_ERROR_PERMISSION_DENIED));
|
new SessionResult(SessionResult.RESULT_ERROR_PERMISSION_DENIED));
|
||||||
@ -307,7 +316,7 @@ import java.util.concurrent.ExecutionException;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
T result = task.run(sessionImpl, controller);
|
T result = task.run(sessionImpl, controller);
|
||||||
postTask.run(controller, seq, result);
|
postTask.run(sessionImpl, controller, seq, result);
|
||||||
});
|
});
|
||||||
} finally {
|
} finally {
|
||||||
Binder.restoreCallingIdentity(token);
|
Binder.restoreCallingIdentity(token);
|
||||||
@ -1696,8 +1705,8 @@ import java.util.concurrent.ExecutionException;
|
|||||||
T run(K sessionImpl, ControllerInfo controller);
|
T run(K sessionImpl, ControllerInfo controller);
|
||||||
}
|
}
|
||||||
|
|
||||||
private interface PostSessionTask<T> {
|
private interface PostSessionTask<T, K extends MediaSessionImpl> {
|
||||||
void run(ControllerInfo controller, int seq, T result);
|
void run(K sessionImpl, ControllerInfo controller, int seq, T result);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* package */ static final class Controller2Cb implements ControllerCb {
|
/* package */ static final class Controller2Cb implements ControllerCb {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user