Fix flaky media key event related CTS tests

Media key events had been incorrectly dispatched to the
MediaSession2, which is closed from the app side, but
MediaSessionService didn't get the notification for it.

It may happen if MediaController2 from the MediaSession2 was
connecting and also MediaSession2 was closing. This fix ensures
that closing session is always propagated to the controller in
onConnect().

Test: Run following tests 10 times (previously flaky ~50%)
   $ atest CtsMediaTestCases:android.media.cts.MediaSessionTest
Bug: 159865360
Change-Id: If16f8c665214614961f28f9406225af19fdad1a8
This commit is contained in:
Jaewan Kim
2020-06-27 04:37:46 +09:00
parent 9c71148852
commit 5a6696991f

View File

@@ -404,7 +404,7 @@ public class MediaSession2 implements AutoCloseable {
mCallback.onPostConnect(MediaSession2.this, controllerInfo);
connected = true;
} finally {
if (!connected) {
if (!connected || isClosed()) {
if (DEBUG) {
Log.d(TAG, "Rejecting connection or notifying that session is closed"
+ ", controllerInfo=" + controllerInfo);