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

Commit 9659c230 authored by Hyundo Moon's avatar Hyundo Moon
Browse files

Send features first and then routes when registering MR2Manager

When a new MediaRouter2Manager is registered, system service first sends
the routes, and then sends the preferred features of all media apps.

This order was not a problem for MediaRouter2Manager, but it is a
problem when creating system MediaRouter2. Here's why:

As a background, system MR2 is for one media app, while MR2Manager is
for all media apps. MR2 creates MR2Manager internally to communicate
with the system media router service, and it 'filters' the information
that are useful for the target app.

When system MR2 is created, the system service sends the routes
and preferred features of all media apps to the internal MR2Manager.

When the routes arrive, system MR2 checks whether the routes match
the media app's features. If there is no matching routes,
the onRoutesAdded() callback is not called.

However, since the features come AFTER the routes, the feature is
yet empty at the point when routes arrive.
This makes the filtered routes also as empty, in turn the
onRoutesAdded() callback is never called for the initial routes.

Bug: 192454011
Test: atest com.android.mediaroutertest.MediaRouter2ManagerTest
      atest android.media.cts.SystemMediaRouter2Test
Change-Id: I2f6101ff86ec6501e8364c75a41b58f2a04ee212
parent 47330ed2
Loading
Loading
Loading
Loading
+6 −3
Original line number Diff line number Diff line
@@ -903,9 +903,9 @@ class MediaRouter2ServiceImpl {
        userRecord.mManagerRecords.add(managerRecord);
        mAllManagerRecords.put(binder, managerRecord);

        userRecord.mHandler.sendMessage(obtainMessage(UserHandler::notifyRoutesToManager,
                userRecord.mHandler, manager));

        // Note: Features should be sent first before the routes. If not, the
        // RouteCallback#onRoutesAdded() for system MR2 will never be called with initial routes
        // due to the lack of features.
        for (RouterRecord routerRecord : userRecord.mRouterRecords) {
            // TODO: UserRecord <-> routerRecord, why do they reference each other?
            // How about removing mUserRecord from routerRecord?
@@ -913,6 +913,9 @@ class MediaRouter2ServiceImpl {
                    obtainMessage(UserHandler::notifyPreferredFeaturesChangedToManager,
                        routerRecord.mUserRecord.mHandler, routerRecord, manager));
        }

        userRecord.mHandler.sendMessage(obtainMessage(UserHandler::notifyRoutesToManager,
                userRecord.mHandler, manager));
    }

    private void unregisterManagerLocked(@NonNull IMediaRouter2Manager manager, boolean died) {