mirror of
https://github.com/androidx/media.git
synced 2025-04-30 06:46:50 +08:00

`onConnect_controllerInfo_sameInstanceFromServiceToConnectedControllerManager` was flaky because `onDestroy()` of `MockMediaSessionService` was cleaning up the `TestServiceRegistry`. This includes releasing the session of the service after which no further `MediaSession.Callback` methods are called. This created a race between `Callback.onDisconnected` and the `Mediasession.release()` being called. `onDestroy()` is called unexpectedly early because the controller unbinds as the last controller from the service that never was started (`onStartCommand` never called). In such a case the service is immediately terminated by the system after the last client unbinds from the service, which called `onDestroy()` on the mock service. This change making `MockMediaSessionService` optionally not clean up the registry in `onDestroy()` prevents the session from being released too early. Alternatively, starting playback and hence starting the service into the foreground would prevent the problem as well for the purpose of the test. Another alternative to fix the test would be removing the session from the service before releasing the controller. PiperOrigin-RevId: 730361199
Session test module
Tests cross-process use of the session module. To run the tests:
- Prepare a device (either an emulator or a real device) to run the tests on.
- Run
./gradlew :test-session-current:cAT