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

Commit 01f07725 authored by Santiago Seifert's avatar Santiago Seifert Committed by Android (Google) Code Review
Browse files

Merge "Log route additions and removals to dumpsys"

parents 113e5cbc 06da1daa
Loading
Loading
Loading
Loading
+39 −2
Original line number Diff line number Diff line
@@ -1742,6 +1742,9 @@ class MediaRouter2ServiceImpl {
                    indexOfRouteProviderInfoByUniqueId(provider.getUniqueId(), mLastProviderInfos);
            MediaRoute2ProviderInfo oldInfo =
                    providerInfoIndex == -1 ? null : mLastProviderInfos.get(providerInfoIndex);
            MediaRouter2ServiceImpl mediaRouter2Service = mServiceRef.get();
            EventLogger eventLogger =
                    mediaRouter2Service != null ? mediaRouter2Service.mEventLogger : null;
            if (oldInfo == newInfo) {
                // Nothing to do.
                return;
@@ -1767,6 +1770,7 @@ class MediaRouter2ServiceImpl {
            }

            // Add new routes to the maps.
            ArrayList<MediaRoute2Info> addedRoutes = new ArrayList<>();
            boolean hasAddedOrModifiedRoutes = false;
            for (MediaRoute2Info newRouteInfo : newRoutes) {
                if (!newRouteInfo.isValid()) {
@@ -1781,11 +1785,14 @@ class MediaRouter2ServiceImpl {
                MediaRoute2Info oldRouteInfo =
                        mLastNotifiedRoutesToPrivilegedRouters.put(
                                newRouteInfo.getId(), newRouteInfo);
                hasAddedOrModifiedRoutes |=
                        oldRouteInfo == null || !oldRouteInfo.equals(newRouteInfo);
                hasAddedOrModifiedRoutes |= !newRouteInfo.equals(oldRouteInfo);
                if (oldRouteInfo == null) {
                    addedRoutes.add(newRouteInfo);
                }
            }

            // Remove stale routes from the maps.
            ArrayList<MediaRoute2Info> removedRoutes = new ArrayList<>();
            Collection<MediaRoute2Info> oldRoutes =
                    oldInfo == null ? Collections.emptyList() : oldInfo.getRoutes();
            boolean hasRemovedRoutes = false;
@@ -1795,6 +1802,26 @@ class MediaRouter2ServiceImpl {
                    hasRemovedRoutes = true;
                    mLastNotifiedRoutesToPrivilegedRouters.remove(oldRouteId);
                    mLastNotifiedRoutesToNonPrivilegedRouters.remove(oldRouteId);
                    removedRoutes.add(oldRoute);
                }
            }

            if (eventLogger != null) {
                if (!addedRoutes.isEmpty()) {
                    // If routes were added, newInfo cannot be null.
                    eventLogger.enqueue(
                            toLoggingEvent(
                                    /* source= */ "addProviderRoutes",
                                    newInfo.getUniqueId(),
                                    addedRoutes));
                }
                if (!removedRoutes.isEmpty()) {
                    // If routes were removed, oldInfo cannot be null.
                    eventLogger.enqueue(
                            toLoggingEvent(
                                    /* source= */ "removeProviderRoutes",
                                    oldInfo.getUniqueId(),
                                    removedRoutes));
                }
            }

@@ -1805,6 +1832,16 @@ class MediaRouter2ServiceImpl {
                    mSystemProvider.getDefaultRoute());
        }

        private static EventLogger.Event toLoggingEvent(
                String source, String providerId, ArrayList<MediaRoute2Info> routes) {
            String routesString =
                    routes.stream()
                            .map(it -> String.format("%s | %s", it.getOriginalId(), it.getName()))
                            .collect(Collectors.joining(/* delimiter= */ ", "));
            return EventLogger.StringEvent.from(
                    source, "provider: %s, routes: [%s]", providerId, routesString);
        }

        /**
         * Dispatches the latest route updates in {@link #mLastNotifiedRoutesToPrivilegedRouters}
         * and {@link #mLastNotifiedRoutesToNonPrivilegedRouters} to registered {@link