Skip to content

Commit 047d489

Browse files
committed
Move legacy session calls to a new thread
Issue: #2577 Test: add Thread.sleep(5000) to setMetadata(), app stays responsive
1 parent 2e30212 commit 047d489

File tree

3 files changed

+167
-110
lines changed

3 files changed

+167
-110
lines changed

libraries/session/src/main/java/androidx/media3/session/MediaSessionImpl.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,6 @@ public MediaSessionImpl(
236236
new MediaSessionLegacyStub(
237237
/* session= */ thisRef,
238238
sessionUri,
239-
applicationHandler,
240239
tokenExtras,
241240
playIfSuppressed,
242241
customLayout,
@@ -245,7 +244,7 @@ public MediaSessionImpl(
245244
connectionResult.availablePlayerCommands,
246245
sessionExtras);
247246

248-
Token platformToken = sessionLegacyStub.getSessionCompat().getSessionToken().getToken();
247+
Token platformToken = sessionLegacyStub.getSessionToken().getToken();
249248
sessionToken =
250249
new SessionToken(
251250
Process.myUid(),
@@ -985,7 +984,7 @@ public void connectFromService(IMediaController caller, ControllerInfo controlle
985984

986985
@SuppressWarnings("UnnecessarilyFullyQualified") // Avoiding confusion by just using "Token"
987986
public android.media.session.MediaSession.Token getPlatformToken() {
988-
return sessionLegacyStub.getSessionCompat().getSessionToken().getToken();
987+
return sessionLegacyStub.getSessionToken().getToken();
989988
}
990989

991990
public void setLegacyControllerConnectionTimeoutMs(long timeoutMs) {
@@ -1054,8 +1053,7 @@ protected IBinder getLegacyBrowserServiceBinder() {
10541053
MediaSessionServiceLegacyStub legacyStub;
10551054
synchronized (lock) {
10561055
if (browserServiceLegacyStub == null) {
1057-
browserServiceLegacyStub =
1058-
createLegacyBrowserService(sessionLegacyStub.getSessionCompat().getSessionToken());
1056+
browserServiceLegacyStub = createLegacyBrowserService(sessionLegacyStub.getSessionToken());
10591057
}
10601058
legacyStub = browserServiceLegacyStub;
10611059
}
@@ -1485,7 +1483,7 @@ private void handleAvailablePlayerCommandsChanged(Player.Commands availableComma
14851483
sessionLegacyStub.onSkipToNext();
14861484
return true;
14871485
} else if (callerInfo.getControllerVersion() != ControllerInfo.LEGACY_CONTROLLER_VERSION) {
1488-
sessionLegacyStub.getSessionCompat().getController().dispatchMediaButtonEvent(keyEvent);
1486+
sessionLegacyStub.getControllerCompat().dispatchMediaButtonEvent(keyEvent);
14891487
return true;
14901488
}
14911489
// This is an unhandled framework event. Return false to let the framework resolve by calling

0 commit comments

Comments
 (0)