Post initial media button preferences update

Controller and browsers are typically obtained with
Futures.addCallback(future, getMainExecutor()), which triggers
the onSuccess callback with a message post. We currently send
the initial media button preferences inline, causing the callback
in MediaController.Listener.onMediaButtonPreferencesChanged to
arrive before the FutureCallback.onSuccess callback.

In the test controller app, which causes crashed when
connecting to existing sessions for example. We can make this
more robust by also posting the initial update of the media button
preferences.

PiperOrigin-RevId: 726923498
(cherry picked from commit d5df227b3ae4d87ec4876cc19ecca814c91c5fd7)
This commit is contained in:
tonihei 2025-02-14 07:37:52 -08:00
parent 22e5f25648
commit 2a3e733161

View File

@ -1646,6 +1646,10 @@ import org.checkerframework.checker.initialization.qual.UnderInitialization;
getInstance().notifyAccepted();
if (!oldControllerInfo.mediaButtonPreferences.equals(
newControllerInfo.mediaButtonPreferences)) {
getInstance()
.applicationHandler
.post(
() ->
getInstance()
.notifyControllerListener(
listener -> {
@ -1656,7 +1660,7 @@ import org.checkerframework.checker.initialization.qual.UnderInitialization;
getInstance(), newControllerInfo.mediaButtonPreferences);
listener.onMediaButtonPreferencesChanged(
getInstance(), newControllerInfo.mediaButtonPreferences);
});
}));
}
return;
}