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

Commit 937076ef authored by Junyu Lai's avatar Junyu Lai Committed by Remi NGUYEN VAN
Browse files

[MS62.1] Start NetworkStatsService from the module

NetworkStatsService is going to be moved into Connectivity mainlne
module and it will be not visible to SystemServiceResistry after
migration done. Thus:
1. Register service in NetworkStatsServiceInitialalizer, a separate
   initializer is needed because the service needs to be created
   before NetworkPolicyManagerService's initialization.
2. Call SystemReady at PHASE_ACTIVITY_MANAGER_READY phase where
   it needs to be ready before StatsPullAtomService pulls at
   PHASE_THIRD_PARTY_APPS_CAN_START.
3. Register manager in ConnectivityFrameworkInitializerTiramisu
   instead of SystemServiceRegistery.

Test: atest FrameworksNetTests CtsNetTestCases NetworkUsageStatsTest
Bug: 204830222
Change-Id: I95020d816ed613ce3480a0720a5b71dcdc7fab72
parent e839e63d
Loading
Loading
Loading
Loading
+0 −13
Original line number Diff line number Diff line
@@ -48,7 +48,6 @@ import android.app.timezonedetector.TimeZoneDetectorImpl;
import android.app.trust.TrustManager;
import android.app.usage.IStorageStatsManager;
import android.app.usage.IUsageStatsManager;
import android.app.usage.NetworkStatsManager;
import android.app.usage.StorageStatsManager;
import android.app.usage.UsageStatsManager;
import android.app.wallpapereffectsgeneration.IWallpaperEffectsGenerationManager;
@@ -140,7 +139,6 @@ import android.net.ConnectivityFrameworkInitializerTiramisu;
import android.net.EthernetManager;
import android.net.IEthernetManager;
import android.net.INetworkPolicyManager;
import android.net.INetworkStatsService;
import android.net.IPacProxyManager;
import android.net.IVpnManager;
import android.net.NetworkPolicyManager;
@@ -1013,17 +1011,6 @@ public final class SystemServiceRegistry {
                return new UsageStatsManager(ctx.getOuterContext(), service);
            }});

        registerService(Context.NETWORK_STATS_SERVICE, NetworkStatsManager.class,
                new CachedServiceFetcher<NetworkStatsManager>() {
            @Override
            public NetworkStatsManager createService(ContextImpl ctx) throws ServiceNotFoundException {
                // TODO: Replace with an initializer in the module, see
                //  {@code ConnectivityFrameworkInitializer}.
                final INetworkStatsService service = INetworkStatsService.Stub.asInterface(
                        ServiceManager.getServiceOrThrow(Context.NETWORK_STATS_SERVICE));
                return new NetworkStatsManager(ctx.getOuterContext(), service);
            }});

        registerService(Context.PERSISTENT_DATA_BLOCK_SERVICE, PersistentDataBlockManager.class,
                new StaticServiceFetcher<PersistentDataBlockManager>() {
            @Override
+11 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package android.net;

import android.annotation.SystemApi;
import android.app.SystemServiceRegistry;
import android.app.usage.NetworkStatsManager;
import android.content.Context;
import android.net.nsd.INsdManager;
import android.net.nsd.NsdManager;
@@ -57,5 +58,15 @@ public final class ConnectivityFrameworkInitializerTiramisu {
                    return new IpSecManager(context, service);
                }
        );

        SystemServiceRegistry.registerContextAwareService(
                Context.NETWORK_STATS_SERVICE,
                NetworkStatsManager.class,
                (context, serviceBinder) -> {
                    INetworkStatsService service =
                            INetworkStatsService.Stub.asInterface(serviceBinder);
                    return new NetworkStatsManager(context, service);
                }
        );
    }
}
+6 −20
Original line number Diff line number Diff line
@@ -54,7 +54,6 @@ import android.hardware.display.DisplayManagerInternal;
import android.net.ConnectivityManager;
import android.net.ConnectivityModuleConnector;
import android.net.NetworkStackClient;
import android.net.TrafficStats;
import android.os.BaseBundle;
import android.os.Binder;
import android.os.Build;
@@ -143,7 +142,6 @@ import com.android.server.media.MediaRouterService;
import com.android.server.media.metrics.MediaMetricsManagerService;
import com.android.server.media.projection.MediaProjectionManagerService;
import com.android.server.net.NetworkPolicyManagerService;
import com.android.server.net.NetworkStatsService;
import com.android.server.net.watchlist.NetworkWatchlistService;
import com.android.server.notification.NotificationManagerService;
import com.android.server.oemlock.OemLockService;
@@ -397,6 +395,8 @@ public final class SystemServer implements Dumpable {
            "com.android.server.media.MediaResourceMonitorService";
    private static final String CONNECTIVITY_SERVICE_INITIALIZER_CLASS =
            "com.android.server.ConnectivityServiceInitializer";
    private static final String NETWORK_STATS_SERVICE_INITIALIZER_CLASS =
            "com.android.server.NetworkStatsServiceInitializer";
    private static final String IP_CONNECTIVITY_METRICS_CLASS =
            "com.android.server.connectivity.IpConnectivityMetrics";
    private static final String MEDIA_COMMUNICATION_SERVICE_CLASS =
@@ -1395,7 +1395,6 @@ public final class SystemServer implements Dumpable {
        NetworkManagementService networkManagement = null;
        VpnManagerService vpnManager = null;
        VcnManagementService vcnManagement = null;
        NetworkStatsService networkStats = null;
        NetworkPolicyManagerService networkPolicy = null;
        WindowManagerService wm = null;
        SerialService serial = null;
@@ -1917,13 +1916,10 @@ public final class SystemServer implements Dumpable {
            t.traceEnd();

            t.traceBegin("StartNetworkStatsService");
            try {
                networkStats = NetworkStatsService.create(context);
                ServiceManager.addService(Context.NETWORK_STATS_SERVICE, networkStats);
                TrafficStats.init(context);
            } catch (Throwable e) {
                reportWtf("starting NetworkStats Service", e);
            }
            // This has to be called before NetworkPolicyManager because NetworkPolicyManager
            // needs to take NetworkStatsService to initialize.
            mSystemServiceManager.startServiceFromJar(NETWORK_STATS_SERVICE_INITIALIZER_CLASS,
                    CONNECTIVITY_SERVICE_APEX_PATH);
            t.traceEnd();

            t.traceBegin("StartNetworkPolicyManagerService");
@@ -2775,7 +2771,6 @@ public final class SystemServer implements Dumpable {

        // These are needed to propagate to the runnable below.
        final NetworkManagementService networkManagementF = networkManagement;
        final NetworkStatsService networkStatsF = networkStats;
        final NetworkPolicyManagerService networkPolicyF = networkPolicy;
        final CountryDetectorService countryDetectorF = countryDetector;
        final NetworkTimeUpdateService networkTimeUpdaterF = networkTimeUpdater;
@@ -2874,15 +2869,6 @@ public final class SystemServer implements Dumpable {
                        .networkScoreAndNetworkManagementServiceReady();
            }
            t.traceEnd();
            t.traceBegin("MakeNetworkStatsServiceReady");
            try {
                if (networkStatsF != null) {
                    networkStatsF.systemReady();
                }
            } catch (Throwable e) {
                reportWtf("making Network Stats Service ready", e);
            }
            t.traceEnd();
            t.traceBegin("MakeConnectivityServiceReady");
            try {
                if (connectivityF != null) {