Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7e9e4d99 authored by Jaewan Kim's avatar Jaewan Kim
Browse files

MediaSessionService: Document necessity of onSessionDestroyed()

Test: Build
Change-Id: I7b370b31e502a2f863d9b029426d8dc4690e27ec
parent 02a72280
Loading
Loading
Loading
Loading
+24 −0
Original line number Diff line number Diff line
@@ -1427,6 +1427,17 @@ public class MediaSessionService extends SystemService implements Monitor {
            }
        }

        /**
         * Called when a {@link android.media.MediaSession2} instance is created.
         * <p>
         * This does two things.
         *   1. Keep the newly created session in the service
         *   2. Do sanity check to ensure unique id per package, and return result
         *
         * @param sessionToken SessionToken2 object in bundled form
         * @return {@code true} if the session's id isn't used by the package now. {@code false}
         *     otherwise.
         */
        @Override
        public boolean onSessionCreated(Bundle sessionToken) {
            final int uid = Binder.getCallingUid();
@@ -1453,6 +1464,19 @@ public class MediaSessionService extends SystemService implements Monitor {
            }
        }

        /**
         * Called when a {@link android.media.MediaSession2} instance is closed. (i.e. destroyed)
         * <p>
         * Ideally service should know that a session is destroyed through the
         * {@link android.media.MediaController2.ControllerCallback#onDisconnected()}, which is
         * asynchronous call. However, we also need synchronous way together to address timing
         * issue. If the package recreates the session almost immediately, which happens commonly
         * for tests, service will reject the creation through {@link #onSessionCreated(Bundle)}
         * if the service hasn't notified previous destroy yet. This synchronous API will address
         * the issue.
         *
         * @param sessionToken SessionToken2 object in bundled form
         */
        @Override
        public void onSessionDestroyed(Bundle sessionToken) {
            final int uid = Binder.getCallingUid();