Loading services/core/java/com/android/server/media/MediaRouter2ServiceImpl.java +39 −2 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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()) { Loading @@ -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; Loading @@ -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)); } } Loading @@ -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 Loading Loading
services/core/java/com/android/server/media/MediaRouter2ServiceImpl.java +39 −2 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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()) { Loading @@ -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; Loading @@ -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)); } } Loading @@ -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 Loading