Search in sources :

Example 1 with NetworkStatsService

use of com.android.server.net.NetworkStatsService in project platform_frameworks_base by android.

the class SystemServer method startOtherServices.

/**
     * Starts a miscellaneous grab bag of stuff that has yet to be refactored
     * and organized.
     */
private void startOtherServices() {
    final Context context = mSystemContext;
    VibratorService vibrator = null;
    IMountService mountService = null;
    NetworkManagementService networkManagement = null;
    NetworkStatsService networkStats = null;
    NetworkPolicyManagerService networkPolicy = null;
    ConnectivityService connectivity = null;
    NetworkScoreService networkScore = null;
    NsdService serviceDiscovery = null;
    WindowManagerService wm = null;
    SerialService serial = null;
    NetworkTimeUpdateService networkTimeUpdater = null;
    CommonTimeManagementService commonTimeMgmtService = null;
    InputManagerService inputManager = null;
    TelephonyRegistry telephonyRegistry = null;
    ConsumerIrService consumerIr = null;
    MmsServiceBroker mmsService = null;
    HardwarePropertiesManagerService hardwarePropertiesService = null;
    boolean disableStorage = SystemProperties.getBoolean("config.disable_storage", false);
    boolean disableBluetooth = SystemProperties.getBoolean("config.disable_bluetooth", false);
    boolean disableLocation = SystemProperties.getBoolean("config.disable_location", false);
    boolean disableSystemUI = SystemProperties.getBoolean("config.disable_systemui", false);
    boolean disableNonCoreServices = SystemProperties.getBoolean("config.disable_noncore", false);
    boolean disableNetwork = SystemProperties.getBoolean("config.disable_network", false);
    boolean disableNetworkTime = SystemProperties.getBoolean("config.disable_networktime", false);
    boolean disableRtt = SystemProperties.getBoolean("config.disable_rtt", false);
    boolean disableMediaProjection = SystemProperties.getBoolean("config.disable_mediaproj", false);
    boolean disableSerial = SystemProperties.getBoolean("config.disable_serial", false);
    boolean disableSearchManager = SystemProperties.getBoolean("config.disable_searchmanager", false);
    boolean disableTrustManager = SystemProperties.getBoolean("config.disable_trustmanager", false);
    boolean disableTextServices = SystemProperties.getBoolean("config.disable_textservices", false);
    boolean disableSamplingProfiler = SystemProperties.getBoolean("config.disable_samplingprof", false);
    boolean disableConsumerIr = SystemProperties.getBoolean("config.disable_consumerir", false);
    boolean disableVrManager = SystemProperties.getBoolean("config.disable_vrmanager", false);
    boolean disableCameraService = SystemProperties.getBoolean("config.disable_cameraservice", false);
    boolean isEmulator = SystemProperties.get("ro.kernel.qemu").equals("1");
    try {
        Slog.i(TAG, "Reading configuration...");
        SystemConfig.getInstance();
        traceBeginAndSlog("StartSchedulingPolicyService");
        ServiceManager.addService("scheduling_policy", new SchedulingPolicyService());
        Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        mSystemServiceManager.startService(TelecomLoaderService.class);
        traceBeginAndSlog("StartTelephonyRegistry");
        telephonyRegistry = new TelephonyRegistry(context);
        ServiceManager.addService("telephony.registry", telephonyRegistry);
        Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        traceBeginAndSlog("StartEntropyMixer");
        mEntropyMixer = new EntropyMixer(context);
        Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        mContentResolver = context.getContentResolver();
        if (!disableCameraService) {
            Slog.i(TAG, "Camera Service");
            mSystemServiceManager.startService(CameraService.class);
        }
        // The AccountManager must come before the ContentService
        traceBeginAndSlog("StartAccountManagerService");
        mSystemServiceManager.startService(ACCOUNT_SERVICE_CLASS);
        Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        traceBeginAndSlog("StartContentService");
        mSystemServiceManager.startService(CONTENT_SERVICE_CLASS);
        Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        traceBeginAndSlog("InstallSystemProviders");
        mActivityManagerService.installSystemProviders();
        Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        traceBeginAndSlog("StartVibratorService");
        vibrator = new VibratorService(context);
        ServiceManager.addService("vibrator", vibrator);
        Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        if (!disableConsumerIr) {
            traceBeginAndSlog("StartConsumerIrService");
            consumerIr = new ConsumerIrService(context);
            ServiceManager.addService(Context.CONSUMER_IR_SERVICE, consumerIr);
            Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        }
        traceBeginAndSlog("StartAlarmManagerService");
        mSystemServiceManager.startService(AlarmManagerService.class);
        Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        traceBeginAndSlog("InitWatchdog");
        final Watchdog watchdog = Watchdog.getInstance();
        watchdog.init(context, mActivityManagerService);
        Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        traceBeginAndSlog("StartInputManagerService");
        inputManager = new InputManagerService(context);
        Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        traceBeginAndSlog("StartWindowManagerService");
        wm = WindowManagerService.main(context, inputManager, mFactoryTestMode != FactoryTest.FACTORY_TEST_LOW_LEVEL, !mFirstBoot, mOnlyCore);
        ServiceManager.addService(Context.WINDOW_SERVICE, wm);
        ServiceManager.addService(Context.INPUT_SERVICE, inputManager);
        Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        if (!disableVrManager) {
            traceBeginAndSlog("StartVrManagerService");
            mSystemServiceManager.startService(VrManagerService.class);
            Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        }
        mActivityManagerService.setWindowManager(wm);
        inputManager.setWindowManagerCallbacks(wm.getInputMonitor());
        inputManager.start();
        // TODO: Use service dependencies instead.
        mDisplayManagerService.windowManagerAndInputReady();
        // support Bluetooth - see bug 988521
        if (isEmulator) {
            Slog.i(TAG, "No Bluetooth Service (emulator)");
        } else if (mFactoryTestMode == FactoryTest.FACTORY_TEST_LOW_LEVEL) {
            Slog.i(TAG, "No Bluetooth Service (factory test)");
        } else if (!context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH)) {
            Slog.i(TAG, "No Bluetooth Service (Bluetooth Hardware Not Present)");
        } else if (disableBluetooth) {
            Slog.i(TAG, "Bluetooth Service disabled by config");
        } else {
            mSystemServiceManager.startService(BluetoothService.class);
        }
        traceBeginAndSlog("IpConnectivityMetrics");
        mSystemServiceManager.startService(IpConnectivityMetrics.class);
        Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        traceBeginAndSlog("PinnerService");
        mSystemServiceManager.startService(PinnerService.class);
        Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
    } catch (RuntimeException e) {
        Slog.e("System", "******************************************");
        Slog.e("System", "************ Failure starting core service", e);
    }
    StatusBarManagerService statusBar = null;
    INotificationManager notification = null;
    LocationManagerService location = null;
    CountryDetectorService countryDetector = null;
    ILockSettings lockSettings = null;
    AssetAtlasService atlas = null;
    MediaRouterService mediaRouter = null;
    // Bring up services needed for UI.
    if (mFactoryTestMode != FactoryTest.FACTORY_TEST_LOW_LEVEL) {
        mSystemServiceManager.startService(InputMethodManagerService.Lifecycle.class);
        traceBeginAndSlog("StartAccessibilityManagerService");
        try {
            ServiceManager.addService(Context.ACCESSIBILITY_SERVICE, new AccessibilityManagerService(context));
        } catch (Throwable e) {
            reportWtf("starting Accessibility Manager", e);
        }
        Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
    }
    try {
        wm.displayReady();
    } catch (Throwable e) {
        reportWtf("making display ready", e);
    }
    if (mFactoryTestMode != FactoryTest.FACTORY_TEST_LOW_LEVEL) {
        if (!disableStorage && !"0".equals(SystemProperties.get("system_init.startmountservice"))) {
            try {
                /*
                     * NotificationManagerService is dependant on MountService,
                     * (for media / usb notifications) so we must start MountService first.
                     */
                mSystemServiceManager.startService(MOUNT_SERVICE_CLASS);
                mountService = IMountService.Stub.asInterface(ServiceManager.getService("mount"));
            } catch (Throwable e) {
                reportWtf("starting Mount Service", e);
            }
        }
    }
    // We start this here so that we update our configuration to set watch or television
    // as appropriate.
    mSystemServiceManager.startService(UiModeManagerService.class);
    if (!mOnlyCore) {
        Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "UpdatePackagesIfNeeded");
        try {
            mPackageManagerService.updatePackagesIfNeeded();
        } catch (Throwable e) {
            reportWtf("update packages", e);
        }
        Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
    }
    Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "PerformFstrimIfNeeded");
    try {
        mPackageManagerService.performFstrimIfNeeded();
    } catch (Throwable e) {
        reportWtf("performing fstrim", e);
    }
    Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
    if (mFactoryTestMode != FactoryTest.FACTORY_TEST_LOW_LEVEL) {
        if (!disableNonCoreServices) {
            traceBeginAndSlog("StartLockSettingsService");
            try {
                mSystemServiceManager.startService(LOCK_SETTINGS_SERVICE_CLASS);
                lockSettings = ILockSettings.Stub.asInterface(ServiceManager.getService("lock_settings"));
            } catch (Throwable e) {
                reportWtf("starting LockSettingsService service", e);
            }
            Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
            if (!SystemProperties.get(PERSISTENT_DATA_BLOCK_PROP).equals("")) {
                mSystemServiceManager.startService(PersistentDataBlockService.class);
            }
            mSystemServiceManager.startService(DeviceIdleController.class);
            // Always start the Device Policy Manager, so that the API is compatible with
            // API8.
            mSystemServiceManager.startService(DevicePolicyManagerService.Lifecycle.class);
        }
        if (!disableSystemUI) {
            traceBeginAndSlog("StartStatusBarManagerService");
            try {
                statusBar = new StatusBarManagerService(context, wm);
                ServiceManager.addService(Context.STATUS_BAR_SERVICE, statusBar);
            } catch (Throwable e) {
                reportWtf("starting StatusBarManagerService", e);
            }
            Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        }
        if (!disableNonCoreServices) {
            traceBeginAndSlog("StartClipboardService");
            try {
                ServiceManager.addService(Context.CLIPBOARD_SERVICE, new ClipboardService(context));
            } catch (Throwable e) {
                reportWtf("starting Clipboard Service", e);
            }
            Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        }
        if (!disableNetwork) {
            traceBeginAndSlog("StartNetworkManagementService");
            try {
                networkManagement = NetworkManagementService.create(context);
                ServiceManager.addService(Context.NETWORKMANAGEMENT_SERVICE, networkManagement);
            } catch (Throwable e) {
                reportWtf("starting NetworkManagement Service", e);
            }
            Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        }
        if (!disableNonCoreServices && !disableTextServices) {
            mSystemServiceManager.startService(TextServicesManagerService.Lifecycle.class);
        }
        if (!disableNetwork) {
            traceBeginAndSlog("StartNetworkScoreService");
            try {
                networkScore = new NetworkScoreService(context);
                ServiceManager.addService(Context.NETWORK_SCORE_SERVICE, networkScore);
            } catch (Throwable e) {
                reportWtf("starting Network Score Service", e);
            }
            Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
            traceBeginAndSlog("StartNetworkStatsService");
            try {
                networkStats = NetworkStatsService.create(context, networkManagement);
                ServiceManager.addService(Context.NETWORK_STATS_SERVICE, networkStats);
            } catch (Throwable e) {
                reportWtf("starting NetworkStats Service", e);
            }
            Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
            traceBeginAndSlog("StartNetworkPolicyManagerService");
            try {
                networkPolicy = new NetworkPolicyManagerService(context, mActivityManagerService, networkStats, networkManagement);
                ServiceManager.addService(Context.NETWORK_POLICY_SERVICE, networkPolicy);
            } catch (Throwable e) {
                reportWtf("starting NetworkPolicy Service", e);
            }
            Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
            // Wifi Service must be started first for wifi-related services.
            mSystemServiceManager.startService(WIFI_SERVICE_CLASS);
            mSystemServiceManager.startService("com.android.server.wifi.scanner.WifiScanningService");
            if (!disableRtt) {
                mSystemServiceManager.startService("com.android.server.wifi.RttService");
            }
            if (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_WIFI_AWARE)) {
                mSystemServiceManager.startService(WIFI_AWARE_SERVICE_CLASS);
            } else {
                Slog.i(TAG, "No Wi-Fi Aware Service (Aware support Not Present)");
            }
            if (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_WIFI_DIRECT)) {
                mSystemServiceManager.startService(WIFI_P2P_SERVICE_CLASS);
            }
            if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_ETHERNET) || mPackageManager.hasSystemFeature(PackageManager.FEATURE_USB_HOST)) {
                mSystemServiceManager.startService(ETHERNET_SERVICE_CLASS);
            }
            traceBeginAndSlog("StartConnectivityService");
            try {
                connectivity = new ConnectivityService(context, networkManagement, networkStats, networkPolicy);
                ServiceManager.addService(Context.CONNECTIVITY_SERVICE, connectivity);
                networkStats.bindConnectivityManager(connectivity);
                networkPolicy.bindConnectivityManager(connectivity);
            } catch (Throwable e) {
                reportWtf("starting Connectivity Service", e);
            }
            Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
            traceBeginAndSlog("StartNsdService");
            try {
                serviceDiscovery = NsdService.create(context);
                ServiceManager.addService(Context.NSD_SERVICE, serviceDiscovery);
            } catch (Throwable e) {
                reportWtf("starting Service Discovery Service", e);
            }
            Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        }
        if (!disableNonCoreServices) {
            traceBeginAndSlog("StartUpdateLockService");
            try {
                ServiceManager.addService(Context.UPDATE_LOCK_SERVICE, new UpdateLockService(context));
            } catch (Throwable e) {
                reportWtf("starting UpdateLockService", e);
            }
            Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        }
        if (!disableNonCoreServices) {
            mSystemServiceManager.startService(RecoverySystemService.class);
        }
        /*
             * MountService has a few dependencies: Notification Manager and
             * AppWidget Provider. Make sure MountService is completely started
             * first before continuing.
             */
        if (mountService != null && !mOnlyCore) {
            Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "WaitForAsecScan");
            try {
                mountService.waitForAsecScan();
            } catch (RemoteException ignored) {
            }
            Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        }
        mSystemServiceManager.startService(NotificationManagerService.class);
        notification = INotificationManager.Stub.asInterface(ServiceManager.getService(Context.NOTIFICATION_SERVICE));
        networkPolicy.bindNotificationManager(notification);
        mSystemServiceManager.startService(DeviceStorageMonitorService.class);
        if (!disableLocation) {
            traceBeginAndSlog("StartLocationManagerService");
            try {
                location = new LocationManagerService(context);
                ServiceManager.addService(Context.LOCATION_SERVICE, location);
            } catch (Throwable e) {
                reportWtf("starting Location Manager", e);
            }
            Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
            traceBeginAndSlog("StartCountryDetectorService");
            try {
                countryDetector = new CountryDetectorService(context);
                ServiceManager.addService(Context.COUNTRY_DETECTOR, countryDetector);
            } catch (Throwable e) {
                reportWtf("starting Country Detector", e);
            }
            Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        }
        if (!disableNonCoreServices && !disableSearchManager) {
            traceBeginAndSlog("StartSearchManagerService");
            try {
                mSystemServiceManager.startService(SEARCH_MANAGER_SERVICE_CLASS);
            } catch (Throwable e) {
                reportWtf("starting Search Service", e);
            }
            Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        }
        mSystemServiceManager.startService(DropBoxManagerService.class);
        if (!disableNonCoreServices && context.getResources().getBoolean(R.bool.config_enableWallpaperService)) {
            traceBeginAndSlog("StartWallpaperManagerService");
            mSystemServiceManager.startService(WALLPAPER_SERVICE_CLASS);
            Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        }
        traceBeginAndSlog("StartAudioService");
        mSystemServiceManager.startService(AudioService.Lifecycle.class);
        Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        if (!disableNonCoreServices) {
            mSystemServiceManager.startService(DockObserver.class);
            if (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_WATCH)) {
                mSystemServiceManager.startService(THERMAL_OBSERVER_CLASS);
            }
        }
        traceBeginAndSlog("StartWiredAccessoryManager");
        try {
            // Listen for wired headset changes
            inputManager.setWiredAccessoryCallbacks(new WiredAccessoryManager(context, inputManager));
        } catch (Throwable e) {
            reportWtf("starting WiredAccessoryManager", e);
        }
        Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        if (!disableNonCoreServices) {
            if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_MIDI)) {
                // Start MIDI Manager service
                mSystemServiceManager.startService(MIDI_SERVICE_CLASS);
            }
            if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_USB_HOST) || mPackageManager.hasSystemFeature(PackageManager.FEATURE_USB_ACCESSORY)) {
                // Manage USB host and device support
                Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "StartUsbService");
                mSystemServiceManager.startService(USB_SERVICE_CLASS);
                Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
            }
            if (!disableSerial) {
                traceBeginAndSlog("StartSerialService");
                try {
                    // Serial port support
                    serial = new SerialService(context);
                    ServiceManager.addService(Context.SERIAL_SERVICE, serial);
                } catch (Throwable e) {
                    Slog.e(TAG, "Failure starting SerialService", e);
                }
                Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
            }
            Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "StartHardwarePropertiesManagerService");
            try {
                hardwarePropertiesService = new HardwarePropertiesManagerService(context);
                ServiceManager.addService(Context.HARDWARE_PROPERTIES_SERVICE, hardwarePropertiesService);
            } catch (Throwable e) {
                Slog.e(TAG, "Failure starting HardwarePropertiesManagerService", e);
            }
            Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        }
        mSystemServiceManager.startService(TwilightService.class);
        if (NightDisplayController.isAvailable(context)) {
            mSystemServiceManager.startService(NightDisplayService.class);
        }
        mSystemServiceManager.startService(JobSchedulerService.class);
        mSystemServiceManager.startService(SoundTriggerService.class);
        if (!disableNonCoreServices) {
            if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_BACKUP)) {
                mSystemServiceManager.startService(BACKUP_MANAGER_SERVICE_CLASS);
            }
            if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_APP_WIDGETS) || context.getResources().getBoolean(R.bool.config_enableAppWidgetService)) {
                mSystemServiceManager.startService(APPWIDGET_SERVICE_CLASS);
            }
            if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_VOICE_RECOGNIZERS)) {
                mSystemServiceManager.startService(VOICE_RECOGNITION_MANAGER_SERVICE_CLASS);
            }
            if (GestureLauncherService.isGestureLauncherEnabled(context.getResources())) {
                Slog.i(TAG, "Gesture Launcher Service");
                mSystemServiceManager.startService(GestureLauncherService.class);
            }
            mSystemServiceManager.startService(SensorNotificationService.class);
            mSystemServiceManager.startService(ContextHubSystemService.class);
        }
        traceBeginAndSlog("StartDiskStatsService");
        try {
            ServiceManager.addService("diskstats", new DiskStatsService(context));
        } catch (Throwable e) {
            reportWtf("starting DiskStats Service", e);
        }
        Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        if (!disableSamplingProfiler) {
            traceBeginAndSlog("StartSamplingProfilerService");
            try {
                // need to add this service even if SamplingProfilerIntegration.isEnabled()
                // is false, because it is this service that detects system property change and
                // turns on SamplingProfilerIntegration. Plus, when sampling profiler doesn't work,
                // there is little overhead for running this service.
                ServiceManager.addService("samplingprofiler", new SamplingProfilerService(context));
            } catch (Throwable e) {
                reportWtf("starting SamplingProfiler Service", e);
            }
            Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        }
        if (!disableNetwork && !disableNetworkTime) {
            traceBeginAndSlog("StartNetworkTimeUpdateService");
            try {
                networkTimeUpdater = new NetworkTimeUpdateService(context);
                ServiceManager.addService("network_time_update_service", networkTimeUpdater);
            } catch (Throwable e) {
                reportWtf("starting NetworkTimeUpdate service", e);
            }
            Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        }
        traceBeginAndSlog("StartCommonTimeManagementService");
        try {
            commonTimeMgmtService = new CommonTimeManagementService(context);
            ServiceManager.addService("commontime_management", commonTimeMgmtService);
        } catch (Throwable e) {
            reportWtf("starting CommonTimeManagementService service", e);
        }
        Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        if (!disableNetwork) {
            traceBeginAndSlog("CertBlacklister");
            try {
                CertBlacklister blacklister = new CertBlacklister(context);
            } catch (Throwable e) {
                reportWtf("starting CertBlacklister", e);
            }
            Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        }
        if (!disableNetwork && !disableNonCoreServices && EmergencyAffordanceManager.ENABLED) {
            // EmergencyMode sevice
            mSystemServiceManager.startService(EmergencyAffordanceService.class);
        }
        if (!disableNonCoreServices) {
            // Dreams (interactive idle-time views, a/k/a screen savers, and doze mode)
            mSystemServiceManager.startService(DreamManagerService.class);
        }
        if (!disableNonCoreServices && ZygoteInit.PRELOAD_RESOURCES) {
            traceBeginAndSlog("StartAssetAtlasService");
            try {
                atlas = new AssetAtlasService(context);
                ServiceManager.addService(AssetAtlasService.ASSET_ATLAS_SERVICE, atlas);
            } catch (Throwable e) {
                reportWtf("starting AssetAtlasService", e);
            }
            Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        }
        if (!disableNonCoreServices) {
            ServiceManager.addService(GraphicsStatsService.GRAPHICS_STATS_SERVICE, new GraphicsStatsService(context));
        }
        if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_PRINTING)) {
            mSystemServiceManager.startService(PRINT_MANAGER_SERVICE_CLASS);
        }
        mSystemServiceManager.startService(RestrictionsManagerService.class);
        mSystemServiceManager.startService(MediaSessionService.class);
        if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_HDMI_CEC)) {
            mSystemServiceManager.startService(HdmiControlService.class);
        }
        if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_LIVE_TV)) {
            mSystemServiceManager.startService(TvInputManagerService.class);
        }
        if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_PICTURE_IN_PICTURE)) {
            mSystemServiceManager.startService(MediaResourceMonitorService.class);
        }
        if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_LEANBACK)) {
            mSystemServiceManager.startService(TvRemoteService.class);
        }
        if (!disableNonCoreServices) {
            traceBeginAndSlog("StartMediaRouterService");
            try {
                mediaRouter = new MediaRouterService(context);
                ServiceManager.addService(Context.MEDIA_ROUTER_SERVICE, mediaRouter);
            } catch (Throwable e) {
                reportWtf("starting MediaRouterService", e);
            }
            Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
            if (!disableTrustManager) {
                mSystemServiceManager.startService(TrustManagerService.class);
            }
            if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_FINGERPRINT)) {
                mSystemServiceManager.startService(FingerprintService.class);
            }
            traceBeginAndSlog("StartBackgroundDexOptService");
            try {
                BackgroundDexOptService.schedule(context);
            } catch (Throwable e) {
                reportWtf("starting BackgroundDexOptService", e);
            }
            Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        }
        // LauncherAppsService uses ShortcutService.
        mSystemServiceManager.startService(ShortcutService.Lifecycle.class);
        mSystemServiceManager.startService(LauncherAppsService.class);
    }
    if (!disableNonCoreServices && !disableMediaProjection) {
        mSystemServiceManager.startService(MediaProjectionManagerService.class);
    }
    if (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_WATCH)) {
        mSystemServiceManager.startService(WEAR_BLUETOOTH_SERVICE_CLASS);
        mSystemServiceManager.startService(WEAR_WIFI_MEDIATOR_SERVICE_CLASS);
        if (!disableNonCoreServices) {
            mSystemServiceManager.startService(WEAR_TIME_SERVICE_CLASS);
        }
    }
    // Before things start rolling, be sure we have decided whether
    // we are in safe mode.
    final boolean safeMode = wm.detectSafeMode();
    if (safeMode) {
        mActivityManagerService.enterSafeMode();
        // Disable the JIT for the system_server process
        VMRuntime.getRuntime().disableJitCompilation();
    } else {
        // Enable the JIT for the system_server process
        VMRuntime.getRuntime().startJitCompilation();
    }
    // MMS service broker
    mmsService = mSystemServiceManager.startService(MmsServiceBroker.class);
    if (Settings.Global.getInt(mContentResolver, Settings.Global.DEVICE_PROVISIONED, 0) == 0 || UserManager.isDeviceInDemoMode(mSystemContext)) {
        mSystemServiceManager.startService(RetailDemoModeService.class);
    }
    // It is now time to start up the app processes...
    Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "MakeVibratorServiceReady");
    try {
        vibrator.systemReady();
    } catch (Throwable e) {
        reportWtf("making Vibrator Service ready", e);
    }
    Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
    Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "MakeLockSettingsServiceReady");
    if (lockSettings != null) {
        try {
            lockSettings.systemReady();
        } catch (Throwable e) {
            reportWtf("making Lock Settings Service ready", e);
        }
    }
    Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
    // Needed by DevicePolicyManager for initialization
    mSystemServiceManager.startBootPhase(SystemService.PHASE_LOCK_SETTINGS_READY);
    mSystemServiceManager.startBootPhase(SystemService.PHASE_SYSTEM_SERVICES_READY);
    Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "MakeWindowManagerServiceReady");
    try {
        wm.systemReady();
    } catch (Throwable e) {
        reportWtf("making Window Manager Service ready", e);
    }
    Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
    if (safeMode) {
        mActivityManagerService.showSafeModeOverlay();
    }
    // Update the configuration for this context by hand, because we're going
    // to start using it before the config change done in wm.systemReady() will
    // propagate to it.
    Configuration config = wm.computeNewConfiguration();
    DisplayMetrics metrics = new DisplayMetrics();
    WindowManager w = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    w.getDefaultDisplay().getMetrics(metrics);
    context.getResources().updateConfiguration(config, metrics);
    // The system context's theme may be configuration-dependent.
    final Theme systemTheme = context.getTheme();
    if (systemTheme.getChangingConfigurations() != 0) {
        systemTheme.rebase();
    }
    Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "MakePowerManagerServiceReady");
    try {
        // TODO: use boot phase
        mPowerManagerService.systemReady(mActivityManagerService.getAppOpsService());
        Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
    } catch (Throwable e) {
        reportWtf("making Power Manager Service ready", e);
    }
    Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
    Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "MakePackageManagerServiceReady");
    try {
        mPackageManagerService.systemReady();
    } catch (Throwable e) {
        reportWtf("making Package Manager Service ready", e);
    }
    Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
    Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "MakeDisplayManagerServiceReady");
    try {
        // TODO: use boot phase and communicate these flags some other way
        mDisplayManagerService.systemReady(safeMode, mOnlyCore);
    } catch (Throwable e) {
        reportWtf("making Display Manager Service ready", e);
    }
    Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
    mSystemServiceManager.setSafeMode(safeMode);
    // These are needed to propagate to the runnable below.
    final NetworkManagementService networkManagementF = networkManagement;
    final NetworkStatsService networkStatsF = networkStats;
    final NetworkPolicyManagerService networkPolicyF = networkPolicy;
    final ConnectivityService connectivityF = connectivity;
    final NetworkScoreService networkScoreF = networkScore;
    final LocationManagerService locationF = location;
    final CountryDetectorService countryDetectorF = countryDetector;
    final NetworkTimeUpdateService networkTimeUpdaterF = networkTimeUpdater;
    final CommonTimeManagementService commonTimeMgmtServiceF = commonTimeMgmtService;
    final AssetAtlasService atlasF = atlas;
    final InputManagerService inputManagerF = inputManager;
    final TelephonyRegistry telephonyRegistryF = telephonyRegistry;
    final MediaRouterService mediaRouterF = mediaRouter;
    final MmsServiceBroker mmsServiceF = mmsService;
    // We now tell the activity manager it is okay to run third party
    // code.  It will call back into us once it has gotten to the state
    // where third party code can really run (but before it has actually
    // started launching the initial applications), for us to complete our
    // initialization.
    mActivityManagerService.systemReady(new Runnable() {

        @Override
        public void run() {
            Slog.i(TAG, "Making services ready");
            mSystemServiceManager.startBootPhase(SystemService.PHASE_ACTIVITY_MANAGER_READY);
            Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "PhaseActivityManagerReady");
            Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "StartObservingNativeCrashes");
            try {
                mActivityManagerService.startObservingNativeCrashes();
            } catch (Throwable e) {
                reportWtf("observing native crashes", e);
            }
            Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
            if (!mOnlyCore) {
                Slog.i(TAG, "WebViewFactory preparation");
                Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "WebViewFactoryPreparation");
                mWebViewUpdateService.prepareWebViewInSystemServer();
                Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
            }
            Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "StartSystemUI");
            try {
                startSystemUi(context);
            } catch (Throwable e) {
                reportWtf("starting System UI", e);
            }
            Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
            Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "MakeNetworkScoreReady");
            try {
                if (networkScoreF != null)
                    networkScoreF.systemReady();
            } catch (Throwable e) {
                reportWtf("making Network Score Service ready", e);
            }
            Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
            Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "MakeNetworkManagementServiceReady");
            try {
                if (networkManagementF != null)
                    networkManagementF.systemReady();
            } catch (Throwable e) {
                reportWtf("making Network Managment Service ready", e);
            }
            Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
            Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "MakeNetworkStatsServiceReady");
            try {
                if (networkStatsF != null)
                    networkStatsF.systemReady();
            } catch (Throwable e) {
                reportWtf("making Network Stats Service ready", e);
            }
            Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
            Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "MakeNetworkPolicyServiceReady");
            try {
                if (networkPolicyF != null)
                    networkPolicyF.systemReady();
            } catch (Throwable e) {
                reportWtf("making Network Policy Service ready", e);
            }
            Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
            Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "MakeConnectivityServiceReady");
            try {
                if (connectivityF != null)
                    connectivityF.systemReady();
            } catch (Throwable e) {
                reportWtf("making Connectivity Service ready", e);
            }
            Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
            Watchdog.getInstance().start();
            // It is now okay to let the various system services start their
            // third party code...
            Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
            Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "PhaseThirdPartyAppsCanStart");
            mSystemServiceManager.startBootPhase(SystemService.PHASE_THIRD_PARTY_APPS_CAN_START);
            try {
                if (locationF != null)
                    locationF.systemRunning();
            } catch (Throwable e) {
                reportWtf("Notifying Location Service running", e);
            }
            try {
                if (countryDetectorF != null)
                    countryDetectorF.systemRunning();
            } catch (Throwable e) {
                reportWtf("Notifying CountryDetectorService running", e);
            }
            try {
                if (networkTimeUpdaterF != null)
                    networkTimeUpdaterF.systemRunning();
            } catch (Throwable e) {
                reportWtf("Notifying NetworkTimeService running", e);
            }
            try {
                if (commonTimeMgmtServiceF != null) {
                    commonTimeMgmtServiceF.systemRunning();
                }
            } catch (Throwable e) {
                reportWtf("Notifying CommonTimeManagementService running", e);
            }
            try {
                if (atlasF != null)
                    atlasF.systemRunning();
            } catch (Throwable e) {
                reportWtf("Notifying AssetAtlasService running", e);
            }
            try {
                // TODO(BT) Pass parameter to input manager
                if (inputManagerF != null)
                    inputManagerF.systemRunning();
            } catch (Throwable e) {
                reportWtf("Notifying InputManagerService running", e);
            }
            try {
                if (telephonyRegistryF != null)
                    telephonyRegistryF.systemRunning();
            } catch (Throwable e) {
                reportWtf("Notifying TelephonyRegistry running", e);
            }
            try {
                if (mediaRouterF != null)
                    mediaRouterF.systemRunning();
            } catch (Throwable e) {
                reportWtf("Notifying MediaRouterService running", e);
            }
            try {
                if (mmsServiceF != null)
                    mmsServiceF.systemRunning();
            } catch (Throwable e) {
                reportWtf("Notifying MmsService running", e);
            }
            try {
                if (networkScoreF != null)
                    networkScoreF.systemRunning();
            } catch (Throwable e) {
                reportWtf("Notifying NetworkScoreService running", e);
            }
            Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        }
    });
}
Also used : StatusBarManagerService(com.android.server.statusbar.StatusBarManagerService) Configuration(android.content.res.Configuration) AccessibilityManagerService(com.android.server.accessibility.AccessibilityManagerService) ShortcutService(com.android.server.pm.ShortcutService) INotificationManager(android.app.INotificationManager) AudioService(com.android.server.audio.AudioService) ClipboardService(com.android.server.clipboard.ClipboardService) NetworkPolicyManagerService(com.android.server.net.NetworkPolicyManagerService) SchedulingPolicyService(com.android.server.os.SchedulingPolicyService) IMountService(android.os.storage.IMountService) WindowManagerService(com.android.server.wm.WindowManagerService) MediaRouterService(com.android.server.media.MediaRouterService) InputManagerService(com.android.server.input.InputManagerService) TvInputManagerService(com.android.server.tv.TvInputManagerService) DisplayMetrics(android.util.DisplayMetrics) WindowManager(android.view.WindowManager) NetworkStatsService(com.android.server.net.NetworkStatsService) Context(android.content.Context) DevicePolicyManagerService(com.android.server.devicepolicy.DevicePolicyManagerService) ILockSettings(com.android.internal.widget.ILockSettings) Theme(android.content.res.Resources.Theme) RemoteException(android.os.RemoteException)

Example 2 with NetworkStatsService

use of com.android.server.net.NetworkStatsService in project android_frameworks_base by DirtyUnicorns.

the class SystemServer method startOtherServices.

/**
     * Starts a miscellaneous grab bag of stuff that has yet to be refactored
     * and organized.
     */
private void startOtherServices() {
    final Context context = mSystemContext;
    VibratorService vibrator = null;
    IMountService mountService = null;
    NetworkManagementService networkManagement = null;
    NetworkStatsService networkStats = null;
    NetworkPolicyManagerService networkPolicy = null;
    ConnectivityService connectivity = null;
    NetworkScoreService networkScore = null;
    NsdService serviceDiscovery = null;
    WindowManagerService wm = null;
    SerialService serial = null;
    NetworkTimeUpdateService networkTimeUpdater = null;
    CommonTimeManagementService commonTimeMgmtService = null;
    InputManagerService inputManager = null;
    TelephonyRegistry telephonyRegistry = null;
    ConsumerIrService consumerIr = null;
    MmsServiceBroker mmsService = null;
    HardwarePropertiesManagerService hardwarePropertiesService = null;
    boolean disableStorage = SystemProperties.getBoolean("config.disable_storage", false);
    boolean disableBluetooth = SystemProperties.getBoolean("config.disable_bluetooth", false);
    boolean disableLocation = SystemProperties.getBoolean("config.disable_location", false);
    boolean disableSystemUI = SystemProperties.getBoolean("config.disable_systemui", false);
    boolean disableNonCoreServices = SystemProperties.getBoolean("config.disable_noncore", false);
    boolean disableNetwork = SystemProperties.getBoolean("config.disable_network", false);
    boolean disableNetworkTime = SystemProperties.getBoolean("config.disable_networktime", false);
    boolean disableRtt = SystemProperties.getBoolean("config.disable_rtt", false);
    boolean disableMediaProjection = SystemProperties.getBoolean("config.disable_mediaproj", false);
    boolean disableSerial = SystemProperties.getBoolean("config.disable_serial", false);
    boolean disableSearchManager = SystemProperties.getBoolean("config.disable_searchmanager", false);
    boolean disableTrustManager = SystemProperties.getBoolean("config.disable_trustmanager", false);
    boolean disableTextServices = SystemProperties.getBoolean("config.disable_textservices", false);
    boolean disableSamplingProfiler = SystemProperties.getBoolean("config.disable_samplingprof", false);
    boolean disableConsumerIr = SystemProperties.getBoolean("config.disable_consumerir", false);
    boolean disableVrManager = SystemProperties.getBoolean("config.disable_vrmanager", false);
    boolean disableCameraService = SystemProperties.getBoolean("config.disable_cameraservice", false);
    boolean isEmulator = SystemProperties.get("ro.kernel.qemu").equals("1");
    try {
        Slog.i(TAG, "Reading configuration...");
        SystemConfig.getInstance();
        traceBeginAndSlog("StartSchedulingPolicyService");
        ServiceManager.addService("scheduling_policy", new SchedulingPolicyService());
        Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        mSystemServiceManager.startService(TelecomLoaderService.class);
        traceBeginAndSlog("StartTelephonyRegistry");
        telephonyRegistry = new TelephonyRegistry(context);
        ServiceManager.addService("telephony.registry", telephonyRegistry);
        Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        traceBeginAndSlog("StartEntropyMixer");
        mEntropyMixer = new EntropyMixer(context);
        Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        mContentResolver = context.getContentResolver();
        if (!disableCameraService) {
            Slog.i(TAG, "Camera Service");
            mSystemServiceManager.startService(CameraService.class);
        }
        // The AccountManager must come before the ContentService
        traceBeginAndSlog("StartAccountManagerService");
        mSystemServiceManager.startService(ACCOUNT_SERVICE_CLASS);
        Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        traceBeginAndSlog("StartContentService");
        mSystemServiceManager.startService(CONTENT_SERVICE_CLASS);
        Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        traceBeginAndSlog("InstallSystemProviders");
        mActivityManagerService.installSystemProviders();
        Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        traceBeginAndSlog("StartVibratorService");
        vibrator = new VibratorService(context);
        ServiceManager.addService("vibrator", vibrator);
        Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        if (!disableConsumerIr) {
            traceBeginAndSlog("StartConsumerIrService");
            consumerIr = new ConsumerIrService(context);
            ServiceManager.addService(Context.CONSUMER_IR_SERVICE, consumerIr);
            Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        }
        traceBeginAndSlog("StartAlarmManagerService");
        mSystemServiceManager.startService(AlarmManagerService.class);
        Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        traceBeginAndSlog("InitWatchdog");
        final Watchdog watchdog = Watchdog.getInstance();
        watchdog.init(context, mActivityManagerService);
        Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        traceBeginAndSlog("StartInputManagerService");
        inputManager = new InputManagerService(context);
        Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        traceBeginAndSlog("StartWindowManagerService");
        wm = WindowManagerService.main(context, inputManager, mFactoryTestMode != FactoryTest.FACTORY_TEST_LOW_LEVEL, !mFirstBoot, mOnlyCore);
        ServiceManager.addService(Context.WINDOW_SERVICE, wm);
        ServiceManager.addService(Context.INPUT_SERVICE, inputManager);
        Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        if (!disableVrManager) {
            traceBeginAndSlog("StartVrManagerService");
            mSystemServiceManager.startService(VrManagerService.class);
            Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        }
        mActivityManagerService.setWindowManager(wm);
        inputManager.setWindowManagerCallbacks(wm.getInputMonitor());
        inputManager.start();
        // TODO: Use service dependencies instead.
        mDisplayManagerService.windowManagerAndInputReady();
        // support Bluetooth - see bug 988521
        if (isEmulator) {
            Slog.i(TAG, "No Bluetooth Service (emulator)");
        } else if (mFactoryTestMode == FactoryTest.FACTORY_TEST_LOW_LEVEL) {
            Slog.i(TAG, "No Bluetooth Service (factory test)");
        } else if (!context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH)) {
            Slog.i(TAG, "No Bluetooth Service (Bluetooth Hardware Not Present)");
        } else if (disableBluetooth) {
            Slog.i(TAG, "Bluetooth Service disabled by config");
        } else {
            mSystemServiceManager.startService(BluetoothService.class);
        }
        traceBeginAndSlog("ConnectivityMetricsLoggerService");
        mSystemServiceManager.startService(MetricsLoggerService.class);
        Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        traceBeginAndSlog("IpConnectivityMetrics");
        mSystemServiceManager.startService(IpConnectivityMetrics.class);
        Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        traceBeginAndSlog("PinnerService");
        mSystemServiceManager.startService(PinnerService.class);
        Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
    } catch (RuntimeException e) {
        Slog.e("System", "******************************************");
        Slog.e("System", "************ Failure starting core service", e);
    }
    StatusBarManagerService statusBar = null;
    INotificationManager notification = null;
    LocationManagerService location = null;
    CountryDetectorService countryDetector = null;
    ILockSettings lockSettings = null;
    AssetAtlasService atlas = null;
    MediaRouterService mediaRouter = null;
    GestureService gestureService = null;
    // Bring up services needed for UI.
    if (mFactoryTestMode != FactoryTest.FACTORY_TEST_LOW_LEVEL) {
        mSystemServiceManager.startService(InputMethodManagerService.Lifecycle.class);
        traceBeginAndSlog("StartAccessibilityManagerService");
        try {
            ServiceManager.addService(Context.ACCESSIBILITY_SERVICE, new AccessibilityManagerService(context));
        } catch (Throwable e) {
            reportWtf("starting Accessibility Manager", e);
        }
        Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
    }
    try {
        wm.displayReady();
    } catch (Throwable e) {
        reportWtf("making display ready", e);
    }
    if (mFactoryTestMode != FactoryTest.FACTORY_TEST_LOW_LEVEL) {
        if (!disableStorage && !"0".equals(SystemProperties.get("system_init.startmountservice"))) {
            try {
                /*
                     * NotificationManagerService is dependant on MountService,
                     * (for media / usb notifications) so we must start MountService first.
                     */
                mSystemServiceManager.startService(MOUNT_SERVICE_CLASS);
                mountService = IMountService.Stub.asInterface(ServiceManager.getService("mount"));
            } catch (Throwable e) {
                reportWtf("starting Mount Service", e);
            }
        }
    }
    // We start this here so that we update our configuration to set watch or television
    // as appropriate.
    mSystemServiceManager.startService(UiModeManagerService.class);
    if (!mOnlyCore) {
        Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "UpdatePackagesIfNeeded");
        try {
            mPackageManagerService.updatePackagesIfNeeded();
        } catch (Throwable e) {
            reportWtf("update packages", e);
        }
        Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
    }
    Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "PerformFstrimIfNeeded");
    try {
        mPackageManagerService.performFstrimIfNeeded();
    } catch (Throwable e) {
        reportWtf("performing fstrim", e);
    }
    Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
    if (mFactoryTestMode != FactoryTest.FACTORY_TEST_LOW_LEVEL) {
        if (!disableNonCoreServices) {
            traceBeginAndSlog("StartLockSettingsService");
            try {
                mSystemServiceManager.startService(LOCK_SETTINGS_SERVICE_CLASS);
                lockSettings = ILockSettings.Stub.asInterface(ServiceManager.getService("lock_settings"));
            } catch (Throwable e) {
                reportWtf("starting LockSettingsService service", e);
            }
            Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
            if (!SystemProperties.get(PERSISTENT_DATA_BLOCK_PROP).equals("")) {
                mSystemServiceManager.startService(PersistentDataBlockService.class);
            }
            mSystemServiceManager.startService(DeviceIdleController.class);
            // Always start the Device Policy Manager, so that the API is compatible with
            // API8.
            mSystemServiceManager.startService(DevicePolicyManagerService.Lifecycle.class);
        }
        if (!disableSystemUI) {
            traceBeginAndSlog("StartStatusBarManagerService");
            try {
                statusBar = new StatusBarManagerService(context, wm);
                ServiceManager.addService(Context.STATUS_BAR_SERVICE, statusBar);
            } catch (Throwable e) {
                reportWtf("starting StatusBarManagerService", e);
            }
            Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        }
        if (!disableNonCoreServices) {
            traceBeginAndSlog("StartClipboardService");
            try {
                ServiceManager.addService(Context.CLIPBOARD_SERVICE, new ClipboardService(context));
            } catch (Throwable e) {
                reportWtf("starting Clipboard Service", e);
            }
            Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        }
        if (!disableNetwork) {
            traceBeginAndSlog("StartNetworkManagementService");
            try {
                networkManagement = NetworkManagementService.create(context);
                ServiceManager.addService(Context.NETWORKMANAGEMENT_SERVICE, networkManagement);
            } catch (Throwable e) {
                reportWtf("starting NetworkManagement Service", e);
            }
            Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        }
        if (!disableNonCoreServices && !disableTextServices) {
            mSystemServiceManager.startService(TextServicesManagerService.Lifecycle.class);
        }
        if (!disableNetwork) {
            traceBeginAndSlog("StartNetworkScoreService");
            try {
                networkScore = new NetworkScoreService(context);
                ServiceManager.addService(Context.NETWORK_SCORE_SERVICE, networkScore);
            } catch (Throwable e) {
                reportWtf("starting Network Score Service", e);
            }
            Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
            traceBeginAndSlog("StartNetworkStatsService");
            try {
                networkStats = NetworkStatsService.create(context, networkManagement);
                ServiceManager.addService(Context.NETWORK_STATS_SERVICE, networkStats);
            } catch (Throwable e) {
                reportWtf("starting NetworkStats Service", e);
            }
            Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
            traceBeginAndSlog("StartNetworkPolicyManagerService");
            try {
                networkPolicy = new NetworkPolicyManagerService(context, mActivityManagerService, networkStats, networkManagement);
                ServiceManager.addService(Context.NETWORK_POLICY_SERVICE, networkPolicy);
            } catch (Throwable e) {
                reportWtf("starting NetworkPolicy Service", e);
            }
            Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
            if (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_WIFI_NAN)) {
                mSystemServiceManager.startService(WIFI_NAN_SERVICE_CLASS);
            } else {
                Slog.i(TAG, "No Wi-Fi NAN Service (NAN support Not Present)");
            }
            mSystemServiceManager.startService(WIFI_P2P_SERVICE_CLASS);
            mSystemServiceManager.startService(WIFI_SERVICE_CLASS);
            mSystemServiceManager.startService("com.android.server.wifi.scanner.WifiScanningService");
            if (!disableRtt) {
                mSystemServiceManager.startService("com.android.server.wifi.RttService");
            }
            if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_ETHERNET) || mPackageManager.hasSystemFeature(PackageManager.FEATURE_USB_HOST)) {
                mSystemServiceManager.startService(ETHERNET_SERVICE_CLASS);
            }
            traceBeginAndSlog("StartConnectivityService");
            try {
                connectivity = new ConnectivityService(context, networkManagement, networkStats, networkPolicy);
                ServiceManager.addService(Context.CONNECTIVITY_SERVICE, connectivity);
                networkStats.bindConnectivityManager(connectivity);
                networkPolicy.bindConnectivityManager(connectivity);
            } catch (Throwable e) {
                reportWtf("starting Connectivity Service", e);
            }
            Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
            traceBeginAndSlog("StartNsdService");
            try {
                serviceDiscovery = NsdService.create(context);
                ServiceManager.addService(Context.NSD_SERVICE, serviceDiscovery);
            } catch (Throwable e) {
                reportWtf("starting Service Discovery Service", e);
            }
            Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        }
        if (!disableNonCoreServices) {
            traceBeginAndSlog("StartUpdateLockService");
            try {
                ServiceManager.addService(Context.UPDATE_LOCK_SERVICE, new UpdateLockService(context));
            } catch (Throwable e) {
                reportWtf("starting UpdateLockService", e);
            }
            Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        }
        if (!disableNonCoreServices) {
            mSystemServiceManager.startService(RecoverySystemService.class);
        }
        /*
             * MountService has a few dependencies: Notification Manager and
             * AppWidget Provider. Make sure MountService is completely started
             * first before continuing.
             */
        if (mountService != null && !mOnlyCore) {
            Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "WaitForAsecScan");
            try {
                mountService.waitForAsecScan();
            } catch (RemoteException ignored) {
            }
            Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        }
        mSystemServiceManager.startService(NotificationManagerService.class);
        notification = INotificationManager.Stub.asInterface(ServiceManager.getService(Context.NOTIFICATION_SERVICE));
        networkPolicy.bindNotificationManager(notification);
        mSystemServiceManager.startService(DeviceStorageMonitorService.class);
        if (!disableLocation) {
            traceBeginAndSlog("StartLocationManagerService");
            try {
                location = new LocationManagerService(context);
                ServiceManager.addService(Context.LOCATION_SERVICE, location);
            } catch (Throwable e) {
                reportWtf("starting Location Manager", e);
            }
            Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
            traceBeginAndSlog("StartCountryDetectorService");
            try {
                countryDetector = new CountryDetectorService(context);
                ServiceManager.addService(Context.COUNTRY_DETECTOR, countryDetector);
            } catch (Throwable e) {
                reportWtf("starting Country Detector", e);
            }
            Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        }
        if (!disableNonCoreServices && !disableSearchManager) {
            traceBeginAndSlog("StartSearchManagerService");
            try {
                mSystemServiceManager.startService(SEARCH_MANAGER_SERVICE_CLASS);
            } catch (Throwable e) {
                reportWtf("starting Search Service", e);
            }
            Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        }
        mSystemServiceManager.startService(DropBoxManagerService.class);
        if (!disableNonCoreServices && context.getResources().getBoolean(R.bool.config_enableWallpaperService)) {
            traceBeginAndSlog("StartWallpaperManagerService");
            mSystemServiceManager.startService(WALLPAPER_SERVICE_CLASS);
            Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        }
        traceBeginAndSlog("StartAudioService");
        mSystemServiceManager.startService(AudioService.Lifecycle.class);
        Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        if (!disableNonCoreServices) {
            mSystemServiceManager.startService(DockObserver.class);
            if (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_WATCH)) {
                mSystemServiceManager.startService(THERMAL_OBSERVER_CLASS);
            }
        }
        traceBeginAndSlog("StartWiredAccessoryManager");
        try {
            // Listen for wired headset changes
            inputManager.setWiredAccessoryCallbacks(new WiredAccessoryManager(context, inputManager));
        } catch (Throwable e) {
            reportWtf("starting WiredAccessoryManager", e);
        }
        Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        if (!disableNonCoreServices) {
            if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_MIDI)) {
                // Start MIDI Manager service
                mSystemServiceManager.startService(MIDI_SERVICE_CLASS);
            }
            if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_USB_HOST) || mPackageManager.hasSystemFeature(PackageManager.FEATURE_USB_ACCESSORY)) {
                // Manage USB host and device support
                Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "StartUsbService");
                mSystemServiceManager.startService(USB_SERVICE_CLASS);
                Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
            }
            if (!disableSerial) {
                traceBeginAndSlog("StartSerialService");
                try {
                    // Serial port support
                    serial = new SerialService(context);
                    ServiceManager.addService(Context.SERIAL_SERVICE, serial);
                } catch (Throwable e) {
                    Slog.e(TAG, "Failure starting SerialService", e);
                }
                Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
            }
            Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "StartHardwarePropertiesManagerService");
            try {
                hardwarePropertiesService = new HardwarePropertiesManagerService(context);
                ServiceManager.addService(Context.HARDWARE_PROPERTIES_SERVICE, hardwarePropertiesService);
            } catch (Throwable e) {
                Slog.e(TAG, "Failure starting HardwarePropertiesManagerService", e);
            }
            Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        }
        mSystemServiceManager.startService(TwilightService.class);
        if (NightDisplayController.isAvailable(context)) {
            mSystemServiceManager.startService(NightDisplayService.class);
        }
        mSystemServiceManager.startService(JobSchedulerService.class);
        mSystemServiceManager.startService(SoundTriggerService.class);
        if (!disableNonCoreServices) {
            if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_BACKUP)) {
                mSystemServiceManager.startService(BACKUP_MANAGER_SERVICE_CLASS);
            }
            if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_APP_WIDGETS) || context.getResources().getBoolean(R.bool.config_enableAppWidgetService)) {
                mSystemServiceManager.startService(APPWIDGET_SERVICE_CLASS);
            }
            if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_VOICE_RECOGNIZERS)) {
                mSystemServiceManager.startService(VOICE_RECOGNITION_MANAGER_SERVICE_CLASS);
            }
            if (GestureLauncherService.isGestureLauncherEnabled(context.getResources())) {
                Slog.i(TAG, "Gesture Launcher Service");
                mSystemServiceManager.startService(GestureLauncherService.class);
            }
            mSystemServiceManager.startService(SensorNotificationService.class);
            mSystemServiceManager.startService(ContextHubSystemService.class);
        }
        traceBeginAndSlog("StartDiskStatsService");
        try {
            ServiceManager.addService("diskstats", new DiskStatsService(context));
        } catch (Throwable e) {
            reportWtf("starting DiskStats Service", e);
        }
        Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        if (!disableSamplingProfiler) {
            traceBeginAndSlog("StartSamplingProfilerService");
            try {
                // need to add this service even if SamplingProfilerIntegration.isEnabled()
                // is false, because it is this service that detects system property change and
                // turns on SamplingProfilerIntegration. Plus, when sampling profiler doesn't work,
                // there is little overhead for running this service.
                ServiceManager.addService("samplingprofiler", new SamplingProfilerService(context));
            } catch (Throwable e) {
                reportWtf("starting SamplingProfiler Service", e);
            }
            Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        }
        if (!disableNetwork && !disableNetworkTime) {
            traceBeginAndSlog("StartNetworkTimeUpdateService");
            try {
                networkTimeUpdater = new NetworkTimeUpdateService(context);
                ServiceManager.addService("network_time_update_service", networkTimeUpdater);
            } catch (Throwable e) {
                reportWtf("starting NetworkTimeUpdate service", e);
            }
            Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        }
        traceBeginAndSlog("StartCommonTimeManagementService");
        try {
            commonTimeMgmtService = new CommonTimeManagementService(context);
            ServiceManager.addService("commontime_management", commonTimeMgmtService);
        } catch (Throwable e) {
            reportWtf("starting CommonTimeManagementService service", e);
        }
        Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        if (!disableNetwork) {
            traceBeginAndSlog("CertBlacklister");
            try {
                CertBlacklister blacklister = new CertBlacklister(context);
            } catch (Throwable e) {
                reportWtf("starting CertBlacklister", e);
            }
            Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        }
        if (!disableNetwork && !disableNonCoreServices && EmergencyAffordanceManager.ENABLED) {
            // EmergencyMode sevice
            mSystemServiceManager.startService(EmergencyAffordanceService.class);
        }
        if (!disableNonCoreServices) {
            // Dreams (interactive idle-time views, a/k/a screen savers, and doze mode)
            mSystemServiceManager.startService(DreamManagerService.class);
        }
        if (!disableNonCoreServices && ZygoteInit.PRELOAD_RESOURCES) {
            traceBeginAndSlog("StartAssetAtlasService");
            try {
                atlas = new AssetAtlasService(context);
                ServiceManager.addService(AssetAtlasService.ASSET_ATLAS_SERVICE, atlas);
            } catch (Throwable e) {
                reportWtf("starting AssetAtlasService", e);
            }
            Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        }
        if (!disableNonCoreServices) {
            ServiceManager.addService(GraphicsStatsService.GRAPHICS_STATS_SERVICE, new GraphicsStatsService(context));
        }
        if (context.getResources().getBoolean(com.android.internal.R.bool.config_enableGestureService)) {
            try {
                Slog.i(TAG, "Gesture Sensor Service");
                gestureService = new GestureService(context, inputManager);
                ServiceManager.addService("gesture", gestureService);
            } catch (Throwable e) {
                Slog.e(TAG, "Failure starting Gesture Sensor Service", e);
            }
        }
        if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_PRINTING)) {
            mSystemServiceManager.startService(PRINT_MANAGER_SERVICE_CLASS);
        }
        mSystemServiceManager.startService(RestrictionsManagerService.class);
        mSystemServiceManager.startService(MediaSessionService.class);
        if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_HDMI_CEC)) {
            mSystemServiceManager.startService(HdmiControlService.class);
        }
        if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_LIVE_TV)) {
            mSystemServiceManager.startService(TvInputManagerService.class);
        }
        if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_PICTURE_IN_PICTURE)) {
            mSystemServiceManager.startService(MediaResourceMonitorService.class);
        }
        if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_LEANBACK)) {
            mSystemServiceManager.startService(TvRemoteService.class);
        }
        if (!disableNonCoreServices) {
            traceBeginAndSlog("StartMediaRouterService");
            try {
                mediaRouter = new MediaRouterService(context);
                ServiceManager.addService(Context.MEDIA_ROUTER_SERVICE, mediaRouter);
            } catch (Throwable e) {
                reportWtf("starting MediaRouterService", e);
            }
            Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
            if (!disableTrustManager) {
                mSystemServiceManager.startService(TrustManagerService.class);
            }
            if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_FINGERPRINT)) {
                mSystemServiceManager.startService(FingerprintService.class);
            }
            traceBeginAndSlog("StartBackgroundDexOptService");
            try {
                BackgroundDexOptService.schedule(context);
            } catch (Throwable e) {
                reportWtf("starting BackgroundDexOptService", e);
            }
            Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        }
        // LauncherAppsService uses ShortcutService.
        mSystemServiceManager.startService(ShortcutService.Lifecycle.class);
        mSystemServiceManager.startService(LauncherAppsService.class);
    }
    if (!disableNonCoreServices && !disableMediaProjection) {
        mSystemServiceManager.startService(MediaProjectionManagerService.class);
    }
    if (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_WATCH)) {
        mSystemServiceManager.startService(WEAR_BLUETOOTH_SERVICE_CLASS);
        mSystemServiceManager.startService(WEAR_WIFI_MEDIATOR_SERVICE_CLASS);
        if (SystemProperties.getBoolean("config.enable_cellmediator", false)) {
            mSystemServiceManager.startService(WEAR_CELLULAR_MEDIATOR_SERVICE_CLASS);
        }
        if (!disableNonCoreServices) {
            mSystemServiceManager.startService(WEAR_TIME_SERVICE_CLASS);
        }
    }
    // make sure the ADB_ENABLED setting value matches the secure property value
    Settings.Secure.putInt(mContentResolver, Settings.Secure.ADB_PORT, Integer.parseInt(SystemProperties.get("service.adb.tcp.port", "-1")));
    // register observer to listen for settings changes
    mContentResolver.registerContentObserver(Settings.Secure.getUriFor(Settings.Secure.ADB_PORT), false, new AdbPortObserver());
    // Before things start rolling, be sure we have decided whether
    // we are in safe mode.
    final boolean safeMode = wm.detectSafeMode();
    if (safeMode) {
        mActivityManagerService.enterSafeMode();
        // Disable the JIT for the system_server process
        VMRuntime.getRuntime().disableJitCompilation();
    } else {
        // Enable the JIT for the system_server process
        VMRuntime.getRuntime().startJitCompilation();
    }
    // MMS service broker
    mmsService = mSystemServiceManager.startService(MmsServiceBroker.class);
    if (Settings.Global.getInt(mContentResolver, Settings.Global.DEVICE_PROVISIONED, 0) == 0 || UserManager.isDeviceInDemoMode(mSystemContext)) {
        mSystemServiceManager.startService(RetailDemoModeService.class);
    }
    // It is now time to start up the app processes...
    Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "MakeVibratorServiceReady");
    try {
        vibrator.systemReady();
    } catch (Throwable e) {
        reportWtf("making Vibrator Service ready", e);
    }
    Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
    Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "MakeLockSettingsServiceReady");
    if (lockSettings != null) {
        try {
            lockSettings.systemReady();
        } catch (Throwable e) {
            reportWtf("making Lock Settings Service ready", e);
        }
    }
    Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
    // Needed by DevicePolicyManager for initialization
    mSystemServiceManager.startBootPhase(SystemService.PHASE_LOCK_SETTINGS_READY);
    mSystemServiceManager.startBootPhase(SystemService.PHASE_SYSTEM_SERVICES_READY);
    Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "MakeWindowManagerServiceReady");
    try {
        wm.systemReady();
    } catch (Throwable e) {
        reportWtf("making Window Manager Service ready", e);
    }
    Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
    if (safeMode) {
        mActivityManagerService.showSafeModeOverlay();
    }
    // Let's check whether we should disable all theme overlays
    final boolean disableOverlays = wm.detectDisableOverlays();
    if (disableOverlays) {
        mActivityManagerService.disableOverlays();
    }
    // Update the configuration for this context by hand, because we're going
    // to start using it before the config change done in wm.systemReady() will
    // propagate to it.
    Configuration config = wm.computeNewConfiguration();
    DisplayMetrics metrics = new DisplayMetrics();
    WindowManager w = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    w.getDefaultDisplay().getMetrics(metrics);
    context.getResources().updateConfiguration(config, metrics);
    // The system context's theme may be configuration-dependent.
    final Theme systemTheme = context.getTheme();
    if (systemTheme.getChangingConfigurations() != 0) {
        systemTheme.rebase();
    }
    Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "MakePowerManagerServiceReady");
    try {
        // TODO: use boot phase
        mPowerManagerService.systemReady(mActivityManagerService.getAppOpsService());
        Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
    } catch (Throwable e) {
        reportWtf("making Power Manager Service ready", e);
    }
    Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
    Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "MakePackageManagerServiceReady");
    try {
        mPackageManagerService.systemReady();
    } catch (Throwable e) {
        reportWtf("making Package Manager Service ready", e);
    }
    Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
    Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "MakeDisplayManagerServiceReady");
    try {
        // TODO: use boot phase and communicate these flags some other way
        mDisplayManagerService.systemReady(safeMode, mOnlyCore);
    } catch (Throwable e) {
        reportWtf("making Display Manager Service ready", e);
    }
    Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
    if (gestureService != null) {
        try {
            gestureService.systemReady();
        } catch (Throwable e) {
            reportWtf("making Gesture Sensor Service ready", e);
        }
    }
    // These are needed to propagate to the runnable below.
    final NetworkManagementService networkManagementF = networkManagement;
    final NetworkStatsService networkStatsF = networkStats;
    final NetworkPolicyManagerService networkPolicyF = networkPolicy;
    final ConnectivityService connectivityF = connectivity;
    final NetworkScoreService networkScoreF = networkScore;
    final LocationManagerService locationF = location;
    final CountryDetectorService countryDetectorF = countryDetector;
    final NetworkTimeUpdateService networkTimeUpdaterF = networkTimeUpdater;
    final CommonTimeManagementService commonTimeMgmtServiceF = commonTimeMgmtService;
    final AssetAtlasService atlasF = atlas;
    final InputManagerService inputManagerF = inputManager;
    final TelephonyRegistry telephonyRegistryF = telephonyRegistry;
    final MediaRouterService mediaRouterF = mediaRouter;
    final MmsServiceBroker mmsServiceF = mmsService;
    // We now tell the activity manager it is okay to run third party
    // code.  It will call back into us once it has gotten to the state
    // where third party code can really run (but before it has actually
    // started launching the initial applications), for us to complete our
    // initialization.
    mActivityManagerService.systemReady(new Runnable() {

        @Override
        public void run() {
            Slog.i(TAG, "Making services ready");
            mSystemServiceManager.startBootPhase(SystemService.PHASE_ACTIVITY_MANAGER_READY);
            Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "PhaseActivityManagerReady");
            Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "StartObservingNativeCrashes");
            try {
                mActivityManagerService.startObservingNativeCrashes();
            } catch (Throwable e) {
                reportWtf("observing native crashes", e);
            }
            Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
            if (!mOnlyCore) {
                Slog.i(TAG, "WebViewFactory preparation");
                Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "WebViewFactoryPreparation");
                mWebViewUpdateService.prepareWebViewInSystemServer();
                Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
            }
            Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "StartSystemUI");
            try {
                startSystemUi(context);
            } catch (Throwable e) {
                reportWtf("starting System UI", e);
            }
            Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
            Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "MakeNetworkScoreReady");
            try {
                if (networkScoreF != null)
                    networkScoreF.systemReady();
            } catch (Throwable e) {
                reportWtf("making Network Score Service ready", e);
            }
            Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
            Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "MakeNetworkManagementServiceReady");
            try {
                if (networkManagementF != null)
                    networkManagementF.systemReady();
            } catch (Throwable e) {
                reportWtf("making Network Managment Service ready", e);
            }
            Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
            Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "MakeNetworkStatsServiceReady");
            try {
                if (networkStatsF != null)
                    networkStatsF.systemReady();
            } catch (Throwable e) {
                reportWtf("making Network Stats Service ready", e);
            }
            Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
            Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "MakeNetworkPolicyServiceReady");
            try {
                if (networkPolicyF != null)
                    networkPolicyF.systemReady();
            } catch (Throwable e) {
                reportWtf("making Network Policy Service ready", e);
            }
            Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
            Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "MakeConnectivityServiceReady");
            try {
                if (connectivityF != null)
                    connectivityF.systemReady();
            } catch (Throwable e) {
                reportWtf("making Connectivity Service ready", e);
            }
            Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
            Watchdog.getInstance().start();
            // It is now okay to let the various system services start their
            // third party code...
            Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
            Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "PhaseThirdPartyAppsCanStart");
            mSystemServiceManager.startBootPhase(SystemService.PHASE_THIRD_PARTY_APPS_CAN_START);
            try {
                if (locationF != null)
                    locationF.systemRunning();
            } catch (Throwable e) {
                reportWtf("Notifying Location Service running", e);
            }
            try {
                if (countryDetectorF != null)
                    countryDetectorF.systemRunning();
            } catch (Throwable e) {
                reportWtf("Notifying CountryDetectorService running", e);
            }
            try {
                if (networkTimeUpdaterF != null)
                    networkTimeUpdaterF.systemRunning();
            } catch (Throwable e) {
                reportWtf("Notifying NetworkTimeService running", e);
            }
            try {
                if (commonTimeMgmtServiceF != null) {
                    commonTimeMgmtServiceF.systemRunning();
                }
            } catch (Throwable e) {
                reportWtf("Notifying CommonTimeManagementService running", e);
            }
            try {
                if (atlasF != null)
                    atlasF.systemRunning();
            } catch (Throwable e) {
                reportWtf("Notifying AssetAtlasService running", e);
            }
            try {
                // TODO(BT) Pass parameter to input manager
                if (inputManagerF != null)
                    inputManagerF.systemRunning();
            } catch (Throwable e) {
                reportWtf("Notifying InputManagerService running", e);
            }
            try {
                if (telephonyRegistryF != null)
                    telephonyRegistryF.systemRunning();
            } catch (Throwable e) {
                reportWtf("Notifying TelephonyRegistry running", e);
            }
            try {
                if (mediaRouterF != null)
                    mediaRouterF.systemRunning();
            } catch (Throwable e) {
                reportWtf("Notifying MediaRouterService running", e);
            }
            try {
                if (mmsServiceF != null)
                    mmsServiceF.systemRunning();
            } catch (Throwable e) {
                reportWtf("Notifying MmsService running", e);
            }
            try {
                if (networkScoreF != null)
                    networkScoreF.systemRunning();
            } catch (Throwable e) {
                reportWtf("Notifying NetworkScoreService running", e);
            }
            Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        }
    });
}
Also used : StatusBarManagerService(com.android.server.statusbar.StatusBarManagerService) Configuration(android.content.res.Configuration) AccessibilityManagerService(com.android.server.accessibility.AccessibilityManagerService) ShortcutService(com.android.server.pm.ShortcutService) INotificationManager(android.app.INotificationManager) AudioService(com.android.server.audio.AudioService) ClipboardService(com.android.server.clipboard.ClipboardService) NetworkPolicyManagerService(com.android.server.net.NetworkPolicyManagerService) GestureService(com.android.server.gesture.GestureService) SchedulingPolicyService(com.android.server.os.SchedulingPolicyService) IMountService(android.os.storage.IMountService) WindowManagerService(com.android.server.wm.WindowManagerService) MediaRouterService(com.android.server.media.MediaRouterService) InputManagerService(com.android.server.input.InputManagerService) TvInputManagerService(com.android.server.tv.TvInputManagerService) DisplayMetrics(android.util.DisplayMetrics) WindowManager(android.view.WindowManager) NetworkStatsService(com.android.server.net.NetworkStatsService) Context(android.content.Context) DevicePolicyManagerService(com.android.server.devicepolicy.DevicePolicyManagerService) ILockSettings(com.android.internal.widget.ILockSettings) Theme(android.content.res.Resources.Theme) RemoteException(android.os.RemoteException)

Example 3 with NetworkStatsService

use of com.android.server.net.NetworkStatsService in project android_frameworks_base by DirtyUnicorns.

the class NetworkStatsServiceTest method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    mServiceContext = new BroadcastInterceptingContext(getContext());
    mStatsDir = getContext().getFilesDir();
    if (mStatsDir.exists()) {
        IoUtils.deleteContents(mStatsDir);
    }
    mNetManager = createMock(INetworkManagementService.class);
    // TODO: Mock AlarmManager when migrating this test to Mockito.
    AlarmManager alarmManager = (AlarmManager) mServiceContext.getSystemService(Context.ALARM_SERVICE);
    mTime = createMock(TrustedTime.class);
    mSettings = createMock(NetworkStatsSettings.class);
    mConnManager = createMock(IConnectivityManager.class);
    PowerManager powerManager = (PowerManager) mServiceContext.getSystemService(Context.POWER_SERVICE);
    PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
    mService = new NetworkStatsService(mServiceContext, mNetManager, alarmManager, wakeLock, mTime, TelephonyManager.getDefault(), mSettings, new NetworkStatsObservers(), mStatsDir, getBaseDir(mStatsDir));
    mHandlerThread = new IdleableHandlerThread("HandlerThread");
    mHandlerThread.start();
    Handler.Callback callback = new NetworkStatsService.HandlerCallback(mService);
    mHandler = new Handler(mHandlerThread.getLooper(), callback);
    mService.setHandler(mHandler, callback);
    mService.bindConnectivityManager(mConnManager);
    mElapsedRealtime = 0L;
    expectCurrentTime();
    expectDefaultSettings();
    expectNetworkStatsUidDetail(buildEmptyStats());
    expectSystemReady();
    // catch INetworkManagementEventObserver during systemReady()
    final Capture<INetworkManagementEventObserver> networkObserver = new Capture<INetworkManagementEventObserver>();
    mNetManager.registerObserver(capture(networkObserver));
    expectLastCall().atLeastOnce();
    replay();
    mService.systemReady();
    mSession = mService.openSession();
    verifyAndReset();
    mNetworkObserver = networkObserver.getValue();
}
Also used : TrustedTime(android.util.TrustedTime) INetworkManagementService(android.os.INetworkManagementService) BroadcastInterceptingContext(com.android.server.BroadcastInterceptingContext) Handler(android.os.Handler) IdleHandler(android.os.MessageQueue.IdleHandler) Capture(org.easymock.Capture) NetworkStatsSettings(com.android.server.net.NetworkStatsService.NetworkStatsSettings) PowerManager(android.os.PowerManager) NetworkStatsService(com.android.server.net.NetworkStatsService) IAlarmManager(android.app.IAlarmManager) AlarmManager(android.app.AlarmManager) INetworkManagementEventObserver(android.net.INetworkManagementEventObserver) IConnectivityManager(android.net.IConnectivityManager)

Example 4 with NetworkStatsService

use of com.android.server.net.NetworkStatsService in project android_frameworks_base by ResurrectionRemix.

the class SystemServer method startOtherServices.

/**
     * Starts a miscellaneous grab bag of stuff that has yet to be refactored
     * and organized.
     */
private void startOtherServices() {
    final Context context = mSystemContext;
    VibratorService vibrator = null;
    IMountService mountService = null;
    NetworkManagementService networkManagement = null;
    NetworkStatsService networkStats = null;
    NetworkPolicyManagerService networkPolicy = null;
    ConnectivityService connectivity = null;
    NetworkScoreService networkScore = null;
    NsdService serviceDiscovery = null;
    WindowManagerService wm = null;
    SerialService serial = null;
    NetworkTimeUpdateService networkTimeUpdater = null;
    CommonTimeManagementService commonTimeMgmtService = null;
    InputManagerService inputManager = null;
    TelephonyRegistry telephonyRegistry = null;
    ConsumerIrService consumerIr = null;
    MmsServiceBroker mmsService = null;
    HardwarePropertiesManagerService hardwarePropertiesService = null;
    Object wigigP2pService = null;
    Object wigigService = null;
    boolean disableStorage = SystemProperties.getBoolean("config.disable_storage", false);
    boolean disableBluetooth = SystemProperties.getBoolean("config.disable_bluetooth", false);
    boolean disableLocation = SystemProperties.getBoolean("config.disable_location", false);
    boolean disableSystemUI = SystemProperties.getBoolean("config.disable_systemui", false);
    boolean disableNonCoreServices = SystemProperties.getBoolean("config.disable_noncore", false);
    boolean disableNetwork = SystemProperties.getBoolean("config.disable_network", false);
    boolean disableNetworkTime = SystemProperties.getBoolean("config.disable_networktime", false);
    boolean disableRtt = SystemProperties.getBoolean("config.disable_rtt", false);
    boolean disableMediaProjection = SystemProperties.getBoolean("config.disable_mediaproj", false);
    boolean disableSerial = SystemProperties.getBoolean("config.disable_serial", false);
    boolean disableSearchManager = SystemProperties.getBoolean("config.disable_searchmanager", false);
    boolean disableTrustManager = SystemProperties.getBoolean("config.disable_trustmanager", false);
    boolean disableTextServices = SystemProperties.getBoolean("config.disable_textservices", false);
    boolean disableSamplingProfiler = SystemProperties.getBoolean("config.disable_samplingprof", false);
    boolean disableConsumerIr = SystemProperties.getBoolean("config.disable_consumerir", false);
    boolean disableVrManager = SystemProperties.getBoolean("config.disable_vrmanager", false);
    boolean disableCameraService = SystemProperties.getBoolean("config.disable_cameraservice", false);
    boolean isEmulator = SystemProperties.get("ro.kernel.qemu").equals("1");
    boolean enableWigig = SystemProperties.getBoolean("persist.wigig.enable", false);
    String externalServer = context.getResources().getString(org.cyanogenmod.platform.internal.R.string.config_externalSystemServer);
    boolean disableAtlas = SystemProperties.getBoolean("config.disable_atlas", false);
    try {
        Slog.i(TAG, "Reading configuration...");
        SystemConfig.getInstance();
        traceBeginAndSlog("StartSchedulingPolicyService");
        ServiceManager.addService("scheduling_policy", new SchedulingPolicyService());
        Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        mSystemServiceManager.startService(TelecomLoaderService.class);
        traceBeginAndSlog("StartTelephonyRegistry");
        telephonyRegistry = new TelephonyRegistry(context);
        ServiceManager.addService("telephony.registry", telephonyRegistry);
        Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        traceBeginAndSlog("StartEntropyMixer");
        mEntropyMixer = new EntropyMixer(context);
        Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        mContentResolver = context.getContentResolver();
        if (!disableCameraService) {
            Slog.i(TAG, "Camera Service");
            mSystemServiceManager.startService(CameraService.class);
        }
        // The AccountManager must come before the ContentService
        traceBeginAndSlog("StartAccountManagerService");
        mSystemServiceManager.startService(ACCOUNT_SERVICE_CLASS);
        Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        traceBeginAndSlog("StartContentService");
        mSystemServiceManager.startService(CONTENT_SERVICE_CLASS);
        Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        traceBeginAndSlog("InstallSystemProviders");
        mActivityManagerService.installSystemProviders();
        Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        traceBeginAndSlog("StartVibratorService");
        vibrator = new VibratorService(context);
        ServiceManager.addService("vibrator", vibrator);
        Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        if (!disableConsumerIr) {
            traceBeginAndSlog("StartConsumerIrService");
            consumerIr = new ConsumerIrService(context);
            ServiceManager.addService(Context.CONSUMER_IR_SERVICE, consumerIr);
            Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        }
        traceBeginAndSlog("StartAlarmManagerService");
        mSystemServiceManager.startService(AlarmManagerService.class);
        Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        traceBeginAndSlog("InitWatchdog");
        final Watchdog watchdog = Watchdog.getInstance();
        watchdog.init(context, mActivityManagerService);
        Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        traceBeginAndSlog("StartInputManagerService");
        inputManager = new InputManagerService(context);
        Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        traceBeginAndSlog("StartWindowManagerService");
        wm = WindowManagerService.main(context, inputManager, mFactoryTestMode != FactoryTest.FACTORY_TEST_LOW_LEVEL, !mFirstBoot, mOnlyCore);
        ServiceManager.addService(Context.WINDOW_SERVICE, wm);
        ServiceManager.addService(Context.INPUT_SERVICE, inputManager);
        Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        if (!disableVrManager) {
            traceBeginAndSlog("StartVrManagerService");
            mSystemServiceManager.startService(VrManagerService.class);
            Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        }
        mActivityManagerService.setWindowManager(wm);
        inputManager.setWindowManagerCallbacks(wm.getInputMonitor());
        inputManager.start();
        // TODO: Use service dependencies instead.
        mDisplayManagerService.windowManagerAndInputReady();
        // support Bluetooth - see bug 988521
        if (isEmulator) {
            Slog.i(TAG, "No Bluetooth Service (emulator)");
        } else if (mFactoryTestMode == FactoryTest.FACTORY_TEST_LOW_LEVEL) {
            Slog.i(TAG, "No Bluetooth Service (factory test)");
        } else if (!context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH)) {
            Slog.i(TAG, "No Bluetooth Service (Bluetooth Hardware Not Present)");
        } else if (disableBluetooth) {
            Slog.i(TAG, "Bluetooth Service disabled by config");
        } else {
            mSystemServiceManager.startService(BluetoothService.class);
        }
        traceBeginAndSlog("ConnectivityMetricsLoggerService");
        mSystemServiceManager.startService(MetricsLoggerService.class);
        Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        traceBeginAndSlog("IpConnectivityMetrics");
        mSystemServiceManager.startService(IpConnectivityMetrics.class);
        Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        traceBeginAndSlog("PinnerService");
        mSystemServiceManager.startService(PinnerService.class);
        Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
    } catch (RuntimeException e) {
        Slog.e("System", "******************************************");
        Slog.e("System", "************ Failure starting core service", e);
    }
    StatusBarManagerService statusBar = null;
    INotificationManager notification = null;
    LocationManagerService location = null;
    CountryDetectorService countryDetector = null;
    ILockSettings lockSettings = null;
    AssetAtlasService atlas = null;
    MediaRouterService mediaRouter = null;
    GestureService gestureService = null;
    EdgeGestureService edgeGestureService = null;
    // Bring up services needed for UI.
    if (mFactoryTestMode != FactoryTest.FACTORY_TEST_LOW_LEVEL) {
        mSystemServiceManager.startService(InputMethodManagerService.Lifecycle.class);
        traceBeginAndSlog("StartAccessibilityManagerService");
        try {
            ServiceManager.addService(Context.ACCESSIBILITY_SERVICE, new AccessibilityManagerService(context));
        } catch (Throwable e) {
            reportWtf("starting Accessibility Manager", e);
        }
        Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
    }
    try {
        wm.displayReady();
    } catch (Throwable e) {
        reportWtf("making display ready", e);
    }
    if (mFactoryTestMode != FactoryTest.FACTORY_TEST_LOW_LEVEL) {
        if (!disableStorage && !"0".equals(SystemProperties.get("system_init.startmountservice"))) {
            try {
                /*
                     * NotificationManagerService is dependant on MountService,
                     * (for media / usb notifications) so we must start MountService first.
                     */
                mSystemServiceManager.startService(MOUNT_SERVICE_CLASS);
                mountService = IMountService.Stub.asInterface(ServiceManager.getService("mount"));
            } catch (Throwable e) {
                reportWtf("starting Mount Service", e);
            }
        }
    }
    // We start this here so that we update our configuration to set watch or television
    // as appropriate.
    mSystemServiceManager.startService(UiModeManagerService.class);
    if (!mOnlyCore) {
        Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "UpdatePackagesIfNeeded");
        try {
            mPackageManagerService.updatePackagesIfNeeded();
        } catch (Throwable e) {
            reportWtf("update packages", e);
        }
        Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
    }
    Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "PerformFstrimIfNeeded");
    try {
        mPackageManagerService.performFstrimIfNeeded();
    } catch (Throwable e) {
        reportWtf("performing fstrim", e);
    }
    Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
    if (mFactoryTestMode != FactoryTest.FACTORY_TEST_LOW_LEVEL) {
        if (!disableNonCoreServices) {
            traceBeginAndSlog("StartLockSettingsService");
            try {
                mSystemServiceManager.startService(LOCK_SETTINGS_SERVICE_CLASS);
                lockSettings = ILockSettings.Stub.asInterface(ServiceManager.getService("lock_settings"));
            } catch (Throwable e) {
                reportWtf("starting LockSettingsService service", e);
            }
            Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
            if (!SystemProperties.get(PERSISTENT_DATA_BLOCK_PROP).equals("")) {
                mSystemServiceManager.startService(PersistentDataBlockService.class);
            }
            mSystemServiceManager.startService(DeviceIdleController.class);
            // Always start the Device Policy Manager, so that the API is compatible with
            // API8.
            mSystemServiceManager.startService(DevicePolicyManagerService.Lifecycle.class);
        }
        if (!disableSystemUI) {
            traceBeginAndSlog("StartStatusBarManagerService");
            try {
                statusBar = new StatusBarManagerService(context, wm);
                ServiceManager.addService(Context.STATUS_BAR_SERVICE, statusBar);
            } catch (Throwable e) {
                reportWtf("starting StatusBarManagerService", e);
            }
            Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        }
        if (!disableNonCoreServices) {
            traceBeginAndSlog("StartClipboardService");
            try {
                ServiceManager.addService(Context.CLIPBOARD_SERVICE, new ClipboardService(context));
            } catch (Throwable e) {
                reportWtf("starting Clipboard Service", e);
            }
            Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        }
        if (!disableNetwork) {
            traceBeginAndSlog("StartNetworkManagementService");
            try {
                networkManagement = NetworkManagementService.create(context);
                ServiceManager.addService(Context.NETWORKMANAGEMENT_SERVICE, networkManagement);
            } catch (Throwable e) {
                reportWtf("starting NetworkManagement Service", e);
            }
            Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        }
        if (!disableNonCoreServices && !disableTextServices) {
            mSystemServiceManager.startService(TextServicesManagerService.Lifecycle.class);
        }
        if (!disableNetwork) {
            traceBeginAndSlog("StartNetworkScoreService");
            try {
                networkScore = new NetworkScoreService(context);
                ServiceManager.addService(Context.NETWORK_SCORE_SERVICE, networkScore);
            } catch (Throwable e) {
                reportWtf("starting Network Score Service", e);
            }
            Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
            traceBeginAndSlog("StartNetworkStatsService");
            try {
                networkStats = NetworkStatsService.create(context, networkManagement);
                ServiceManager.addService(Context.NETWORK_STATS_SERVICE, networkStats);
            } catch (Throwable e) {
                reportWtf("starting NetworkStats Service", e);
            }
            Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
            traceBeginAndSlog("StartNetworkPolicyManagerService");
            try {
                networkPolicy = new NetworkPolicyManagerService(context, mActivityManagerService, networkStats, networkManagement);
                ServiceManager.addService(Context.NETWORK_POLICY_SERVICE, networkPolicy);
            } catch (Throwable e) {
                reportWtf("starting NetworkPolicy Service", e);
            }
            Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
            if (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_WIFI_NAN)) {
                mSystemServiceManager.startService(WIFI_NAN_SERVICE_CLASS);
            } else {
                Slog.i(TAG, "No Wi-Fi NAN Service (NAN support Not Present)");
            }
            mSystemServiceManager.startService(WIFI_P2P_SERVICE_CLASS);
            mSystemServiceManager.startService(WIFI_SERVICE_CLASS);
            mSystemServiceManager.startService("com.android.server.wifi.scanner.WifiScanningService");
            if (!disableRtt) {
                mSystemServiceManager.startService("com.android.server.wifi.RttService");
            }
            if (enableWigig) {
                try {
                    Slog.i(TAG, "Wigig Service");
                    PathClassLoader wigigClassLoader = new PathClassLoader("/system/framework/wigig-service.jar", "/system/lib64:/system/vendor/lib64", getClass().getClassLoader());
                    Class wigigP2pClass = wigigClassLoader.loadClass("com.qualcomm.qti.server.wigig.p2p.WigigP2pServiceImpl");
                    Constructor<Class> ctor = wigigP2pClass.getConstructor(Context.class);
                    wigigP2pService = ctor.newInstance(context);
                    Slog.i(TAG, "Successfully loaded WigigP2pServiceImpl class");
                    ServiceManager.addService("wigigp2p", (IBinder) wigigP2pService);
                    Class wigigClass = wigigClassLoader.loadClass("com.qualcomm.qti.server.wigig.WigigService");
                    ctor = wigigClass.getConstructor(Context.class);
                    wigigService = ctor.newInstance(context);
                    Slog.i(TAG, "Successfully loaded WigigService class");
                    ServiceManager.addService("wigig", (IBinder) wigigService);
                } catch (Throwable e) {
                    reportWtf("starting WigigService", e);
                }
            }
            if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_ETHERNET) || mPackageManager.hasSystemFeature(PackageManager.FEATURE_USB_HOST)) {
                mSystemServiceManager.startService(ETHERNET_SERVICE_CLASS);
            }
            traceBeginAndSlog("StartConnectivityService");
            try {
                connectivity = new ConnectivityService(context, networkManagement, networkStats, networkPolicy);
                ServiceManager.addService(Context.CONNECTIVITY_SERVICE, connectivity);
                networkStats.bindConnectivityManager(connectivity);
                networkPolicy.bindConnectivityManager(connectivity);
            } catch (Throwable e) {
                reportWtf("starting Connectivity Service", e);
            }
            Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
            traceBeginAndSlog("StartNsdService");
            try {
                serviceDiscovery = NsdService.create(context);
                ServiceManager.addService(Context.NSD_SERVICE, serviceDiscovery);
            } catch (Throwable e) {
                reportWtf("starting Service Discovery Service", e);
            }
            Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        }
        if (!disableNonCoreServices) {
            traceBeginAndSlog("StartUpdateLockService");
            try {
                ServiceManager.addService(Context.UPDATE_LOCK_SERVICE, new UpdateLockService(context));
            } catch (Throwable e) {
                reportWtf("starting UpdateLockService", e);
            }
            Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        }
        if (!disableNonCoreServices) {
            mSystemServiceManager.startService(RecoverySystemService.class);
        }
        /*
             * MountService has a few dependencies: Notification Manager and
             * AppWidget Provider. Make sure MountService is completely started
             * first before continuing.
             */
        if (mountService != null && !mOnlyCore) {
            Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "WaitForAsecScan");
            try {
                mountService.waitForAsecScan();
            } catch (RemoteException ignored) {
            }
            Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        }
        mSystemServiceManager.startService(NotificationManagerService.class);
        notification = INotificationManager.Stub.asInterface(ServiceManager.getService(Context.NOTIFICATION_SERVICE));
        networkPolicy.bindNotificationManager(notification);
        mSystemServiceManager.startService(DeviceStorageMonitorService.class);
        if (!disableLocation) {
            traceBeginAndSlog("StartLocationManagerService");
            try {
                location = new LocationManagerService(context);
                ServiceManager.addService(Context.LOCATION_SERVICE, location);
            } catch (Throwable e) {
                reportWtf("starting Location Manager", e);
            }
            Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
            traceBeginAndSlog("StartCountryDetectorService");
            try {
                countryDetector = new CountryDetectorService(context);
                ServiceManager.addService(Context.COUNTRY_DETECTOR, countryDetector);
            } catch (Throwable e) {
                reportWtf("starting Country Detector", e);
            }
            Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        }
        if (!disableNonCoreServices && !disableSearchManager) {
            traceBeginAndSlog("StartSearchManagerService");
            try {
                mSystemServiceManager.startService(SEARCH_MANAGER_SERVICE_CLASS);
            } catch (Throwable e) {
                reportWtf("starting Search Service", e);
            }
            Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        }
        mSystemServiceManager.startService(DropBoxManagerService.class);
        if (!disableNonCoreServices && context.getResources().getBoolean(R.bool.config_enableWallpaperService) && !mIsAlarmBoot) {
            traceBeginAndSlog("StartWallpaperManagerService");
            mSystemServiceManager.startService(WALLPAPER_SERVICE_CLASS);
            Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        }
        traceBeginAndSlog("StartAudioService");
        mSystemServiceManager.startService(AudioService.Lifecycle.class);
        Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        if (!disableNonCoreServices) {
            mSystemServiceManager.startService(DockObserver.class);
            if (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_WATCH)) {
            //#Fixme:mSystemServiceManager.startService(THERMAL_OBSERVER_CLASS);
            }
        }
        traceBeginAndSlog("StartWiredAccessoryManager");
        try {
            // Listen for wired headset changes
            inputManager.setWiredAccessoryCallbacks(new WiredAccessoryManager(context, inputManager));
        } catch (Throwable e) {
            reportWtf("starting WiredAccessoryManager", e);
        }
        Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        if (!disableNonCoreServices) {
            if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_MIDI)) {
                // Start MIDI Manager service
                mSystemServiceManager.startService(MIDI_SERVICE_CLASS);
            }
            if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_USB_HOST) || mPackageManager.hasSystemFeature(PackageManager.FEATURE_USB_ACCESSORY)) {
                // Manage USB host and device support
                Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "StartUsbService");
                mSystemServiceManager.startService(USB_SERVICE_CLASS);
                Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
            }
            if (!disableSerial) {
                traceBeginAndSlog("StartSerialService");
                try {
                    // Serial port support
                    serial = new SerialService(context);
                    ServiceManager.addService(Context.SERIAL_SERVICE, serial);
                } catch (Throwable e) {
                    Slog.e(TAG, "Failure starting SerialService", e);
                }
                Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
            }
            Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "StartHardwarePropertiesManagerService");
            try {
                hardwarePropertiesService = new HardwarePropertiesManagerService(context);
                ServiceManager.addService(Context.HARDWARE_PROPERTIES_SERVICE, hardwarePropertiesService);
            } catch (Throwable e) {
                Slog.e(TAG, "Failure starting HardwarePropertiesManagerService", e);
            }
            Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        }
        mSystemServiceManager.startService(TwilightService.class);
        if (NightDisplayController.isAvailable(context)) {
            mSystemServiceManager.startService(NightDisplayService.class);
        }
        mSystemServiceManager.startService(JobSchedulerService.class);
        mSystemServiceManager.startService(SoundTriggerService.class);
        if (!disableNonCoreServices) {
            if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_BACKUP)) {
                mSystemServiceManager.startService(BACKUP_MANAGER_SERVICE_CLASS);
            }
            if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_APP_WIDGETS) || context.getResources().getBoolean(R.bool.config_enableAppWidgetService)) {
                mSystemServiceManager.startService(APPWIDGET_SERVICE_CLASS);
            }
            if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_VOICE_RECOGNIZERS)) {
                mSystemServiceManager.startService(VOICE_RECOGNITION_MANAGER_SERVICE_CLASS);
            }
            if (GestureLauncherService.isGestureLauncherEnabled(context.getResources())) {
                Slog.i(TAG, "Gesture Launcher Service");
                mSystemServiceManager.startService(GestureLauncherService.class);
            }
            mSystemServiceManager.startService(SensorNotificationService.class);
            mSystemServiceManager.startService(ContextHubSystemService.class);
        }
        traceBeginAndSlog("StartDiskStatsService");
        try {
            ServiceManager.addService("diskstats", new DiskStatsService(context));
        } catch (Throwable e) {
            reportWtf("starting DiskStats Service", e);
        }
        Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        if (!disableSamplingProfiler) {
            traceBeginAndSlog("StartSamplingProfilerService");
            try {
                // need to add this service even if SamplingProfilerIntegration.isEnabled()
                // is false, because it is this service that detects system property change and
                // turns on SamplingProfilerIntegration. Plus, when sampling profiler doesn't work,
                // there is little overhead for running this service.
                ServiceManager.addService("samplingprofiler", new SamplingProfilerService(context));
            } catch (Throwable e) {
                reportWtf("starting SamplingProfiler Service", e);
            }
            Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        }
        if (!disableNetwork && !disableNetworkTime) {
            traceBeginAndSlog("StartNetworkTimeUpdateService");
            try {
                networkTimeUpdater = new NetworkTimeUpdateService(context);
                ServiceManager.addService("network_time_update_service", networkTimeUpdater);
            } catch (Throwable e) {
                reportWtf("starting NetworkTimeUpdate service", e);
            }
            Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        }
        traceBeginAndSlog("StartCommonTimeManagementService");
        try {
            commonTimeMgmtService = new CommonTimeManagementService(context);
            ServiceManager.addService("commontime_management", commonTimeMgmtService);
        } catch (Throwable e) {
            reportWtf("starting CommonTimeManagementService service", e);
        }
        Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        if (!disableNetwork) {
            traceBeginAndSlog("CertBlacklister");
            try {
                CertBlacklister blacklister = new CertBlacklister(context);
            } catch (Throwable e) {
                reportWtf("starting CertBlacklister", e);
            }
            Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        }
        if (!disableNetwork && !disableNonCoreServices && EmergencyAffordanceManager.ENABLED) {
            // EmergencyMode sevice
            mSystemServiceManager.startService(EmergencyAffordanceService.class);
        }
        if (!disableNonCoreServices) {
            // Dreams (interactive idle-time views, a/k/a screen savers, and doze mode)
            mSystemServiceManager.startService(DreamManagerService.class);
        }
        if (!disableNonCoreServices && ZygoteInit.PRELOAD_RESOURCES && !disableAtlas) {
            traceBeginAndSlog("StartAssetAtlasService");
            try {
                atlas = new AssetAtlasService(context);
                ServiceManager.addService(AssetAtlasService.ASSET_ATLAS_SERVICE, atlas);
            } catch (Throwable e) {
                reportWtf("starting AssetAtlasService", e);
            }
            Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        }
        if (!disableNonCoreServices) {
            ServiceManager.addService(GraphicsStatsService.GRAPHICS_STATS_SERVICE, new GraphicsStatsService(context));
        }
        if (context.getResources().getBoolean(com.android.internal.R.bool.config_enableGestureService)) {
            try {
                Slog.i(TAG, "Gesture Sensor Service");
                gestureService = new GestureService(context, inputManager);
                ServiceManager.addService("gesture", gestureService);
            } catch (Throwable e) {
                Slog.e(TAG, "Failure starting Gesture Sensor Service", e);
            }
        }
        if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_PRINTING)) {
            mSystemServiceManager.startService(PRINT_MANAGER_SERVICE_CLASS);
        }
        mSystemServiceManager.startService(RestrictionsManagerService.class);
        mSystemServiceManager.startService(MediaSessionService.class);
        if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_HDMI_CEC)) {
            mSystemServiceManager.startService(HdmiControlService.class);
        }
        if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_LIVE_TV)) {
            mSystemServiceManager.startService(TvInputManagerService.class);
        }
        if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_PICTURE_IN_PICTURE)) {
            mSystemServiceManager.startService(MediaResourceMonitorService.class);
        }
        if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_LEANBACK)) {
            mSystemServiceManager.startService(TvRemoteService.class);
        }
        if (!disableNonCoreServices) {
            traceBeginAndSlog("StartMediaRouterService");
            try {
                mediaRouter = new MediaRouterService(context);
                ServiceManager.addService(Context.MEDIA_ROUTER_SERVICE, mediaRouter);
            } catch (Throwable e) {
                reportWtf("starting MediaRouterService", e);
            }
            Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
            if (!disableTrustManager) {
                mSystemServiceManager.startService(TrustManagerService.class);
            }
            if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_FINGERPRINT)) {
                mSystemServiceManager.startService(FingerprintService.class);
            }
            traceBeginAndSlog("StartBackgroundDexOptService");
            try {
                BackgroundDexOptService.schedule(context);
            } catch (Throwable e) {
                reportWtf("starting BackgroundDexOptService", e);
            }
            Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        }
        // LauncherAppsService uses ShortcutService.
        mSystemServiceManager.startService(ShortcutService.Lifecycle.class);
        mSystemServiceManager.startService(LauncherAppsService.class);
        try {
            Slog.i(TAG, "EdgeGesture service");
            edgeGestureService = new EdgeGestureService(context, inputManager);
            ServiceManager.addService("edgegestureservice", edgeGestureService);
        } catch (Throwable e) {
            Slog.e(TAG, "Failure starting EdgeGesture service", e);
        }
    }
    if (!disableNonCoreServices && !disableMediaProjection) {
        mSystemServiceManager.startService(MediaProjectionManagerService.class);
    }
    if (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_WATCH)) {
        //#Fixme:mSystemServiceManager.startService(WEAR_BLUETOOTH_SERVICE_CLASS);
        mSystemServiceManager.startService(WEAR_BLUETOOTH_SERVICE_CLASS);
        mSystemServiceManager.startService(WEAR_WIFI_MEDIATOR_SERVICE_CLASS);
        if (SystemProperties.getBoolean("config.enable_cellmediator", false)) {
            mSystemServiceManager.startService(WEAR_CELLULAR_MEDIATOR_SERVICE_CLASS);
        }
        if (!disableNonCoreServices) {
            mSystemServiceManager.startService(WEAR_TIME_SERVICE_CLASS);
        }
    }
    // make sure the ADB_ENABLED setting value matches the secure property value
    CMSettings.Secure.putInt(mContentResolver, CMSettings.Secure.ADB_PORT, Integer.parseInt(SystemProperties.get("service.adb.tcp.port", "-1")));
    // register observer to listen for settings changes
    mContentResolver.registerContentObserver(CMSettings.Secure.getUriFor(CMSettings.Secure.ADB_PORT), false, new AdbPortObserver());
    // Before things start rolling, be sure we have decided whether
    // we are in safe mode.
    final boolean safeMode = wm.detectSafeMode();
    if (safeMode) {
        mActivityManagerService.enterSafeMode();
        // Disable the JIT for the system_server process
        VMRuntime.getRuntime().disableJitCompilation();
    } else {
        // Enable the JIT for the system_server process
        VMRuntime.getRuntime().startJitCompilation();
    }
    // MMS service broker
    mmsService = mSystemServiceManager.startService(MmsServiceBroker.class);
    final Class<?> serverClazz;
    try {
        serverClazz = Class.forName(externalServer);
        final Constructor<?> constructor = serverClazz.getDeclaredConstructor(Context.class);
        constructor.setAccessible(true);
        final Object baseObject = constructor.newInstance(mSystemContext);
        final Method method = baseObject.getClass().getDeclaredMethod("run");
        method.setAccessible(true);
        method.invoke(baseObject);
    } catch (ClassNotFoundException | IllegalAccessException | InvocationTargetException | InstantiationException | NoSuchMethodException e) {
        Slog.wtf(TAG, "Unable to start  " + externalServer);
        Slog.wtf(TAG, e);
    }
    if (Settings.Global.getInt(mContentResolver, Settings.Global.DEVICE_PROVISIONED, 0) == 0 || UserManager.isDeviceInDemoMode(mSystemContext)) {
        mSystemServiceManager.startService(RetailDemoModeService.class);
    }
    // It is now time to start up the app processes...
    Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "MakeVibratorServiceReady");
    try {
        vibrator.systemReady();
    } catch (Throwable e) {
        reportWtf("making Vibrator Service ready", e);
    }
    Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
    Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "MakeLockSettingsServiceReady");
    if (lockSettings != null) {
        try {
            lockSettings.systemReady();
        } catch (Throwable e) {
            reportWtf("making Lock Settings Service ready", e);
        }
    }
    Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
    // Needed by DevicePolicyManager for initialization
    mSystemServiceManager.startBootPhase(SystemService.PHASE_LOCK_SETTINGS_READY);
    mSystemServiceManager.startBootPhase(SystemService.PHASE_SYSTEM_SERVICES_READY);
    Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "MakeWindowManagerServiceReady");
    // limitations, send boot phase notification separately
    if (enableWigig) {
        try {
            Slog.i(TAG, "calling onBootPhase for Wigig Services");
            Class wigigP2pClass = wigigP2pService.getClass();
            Method m = wigigP2pClass.getMethod("onBootPhase", int.class);
            m.invoke(wigigP2pService, new Integer(SystemService.PHASE_SYSTEM_SERVICES_READY));
            Class wigigClass = wigigService.getClass();
            m = wigigClass.getMethod("onBootPhase", int.class);
            m.invoke(wigigService, new Integer(SystemService.PHASE_SYSTEM_SERVICES_READY));
        } catch (Throwable e) {
            reportWtf("Wigig services ready", e);
        }
    }
    try {
        wm.systemReady();
    } catch (Throwable e) {
        reportWtf("making Window Manager Service ready", e);
    }
    Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
    if (safeMode) {
        mActivityManagerService.showSafeModeOverlay();
    }
    // Let's check whether we should disable all theme overlays
    final boolean disableOverlays = wm.detectDisableOverlays();
    if (disableOverlays) {
        mActivityManagerService.disableOverlays();
    }
    // Update the configuration for this context by hand, because we're going
    // to start using it before the config change done in wm.systemReady() will
    // propagate to it.
    Configuration config = wm.computeNewConfiguration();
    DisplayMetrics metrics = new DisplayMetrics();
    WindowManager w = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    w.getDefaultDisplay().getMetrics(metrics);
    context.getResources().updateConfiguration(config, metrics);
    // The system context's theme may be configuration-dependent.
    final Theme systemTheme = context.getTheme();
    if (systemTheme.getChangingConfigurations() != 0) {
        systemTheme.rebase();
    }
    Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "MakePowerManagerServiceReady");
    try {
        // TODO: use boot phase
        mPowerManagerService.systemReady(mActivityManagerService.getAppOpsService());
        Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
    } catch (Throwable e) {
        reportWtf("making Power Manager Service ready", e);
    }
    Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
    Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "MakePackageManagerServiceReady");
    try {
        mPackageManagerService.systemReady();
    } catch (Throwable e) {
        reportWtf("making Package Manager Service ready", e);
    }
    Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
    Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "MakeDisplayManagerServiceReady");
    try {
        // TODO: use boot phase and communicate these flags some other way
        mDisplayManagerService.systemReady(safeMode, mOnlyCore);
    } catch (Throwable e) {
        reportWtf("making Display Manager Service ready", e);
    }
    Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
    if (gestureService != null) {
        try {
            gestureService.systemReady();
        } catch (Throwable e) {
            reportWtf("making Gesture Sensor Service ready", e);
        }
    }
    if (edgeGestureService != null) {
        try {
            edgeGestureService.systemReady();
        } catch (Throwable e) {
            reportWtf("making EdgeGesture service ready", e);
        }
    }
    // These are needed to propagate to the runnable below.
    final NetworkManagementService networkManagementF = networkManagement;
    final NetworkStatsService networkStatsF = networkStats;
    final NetworkPolicyManagerService networkPolicyF = networkPolicy;
    final ConnectivityService connectivityF = connectivity;
    final NetworkScoreService networkScoreF = networkScore;
    final LocationManagerService locationF = location;
    final CountryDetectorService countryDetectorF = countryDetector;
    final NetworkTimeUpdateService networkTimeUpdaterF = networkTimeUpdater;
    final CommonTimeManagementService commonTimeMgmtServiceF = commonTimeMgmtService;
    final AssetAtlasService atlasF = atlas;
    final InputManagerService inputManagerF = inputManager;
    final TelephonyRegistry telephonyRegistryF = telephonyRegistry;
    final MediaRouterService mediaRouterF = mediaRouter;
    final MmsServiceBroker mmsServiceF = mmsService;
    // We now tell the activity manager it is okay to run third party
    // code.  It will call back into us once it has gotten to the state
    // where third party code can really run (but before it has actually
    // started launching the initial applications), for us to complete our
    // initialization.
    mActivityManagerService.systemReady(new Runnable() {

        @Override
        public void run() {
            Slog.i(TAG, "Making services ready");
            mSystemServiceManager.startBootPhase(SystemService.PHASE_ACTIVITY_MANAGER_READY);
            Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "PhaseActivityManagerReady");
            Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "StartObservingNativeCrashes");
            try {
                mActivityManagerService.startObservingNativeCrashes();
            } catch (Throwable e) {
                reportWtf("observing native crashes", e);
            }
            Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
            if (!mOnlyCore) {
                Slog.i(TAG, "WebViewFactory preparation");
                Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "WebViewFactoryPreparation");
                mWebViewUpdateService.prepareWebViewInSystemServer();
                Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
            }
            Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "StartSystemUI");
            try {
                startSystemUi(context);
            } catch (Throwable e) {
                reportWtf("starting System UI", e);
            }
            Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
            Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "MakeNetworkScoreReady");
            try {
                if (networkScoreF != null)
                    networkScoreF.systemReady();
            } catch (Throwable e) {
                reportWtf("making Network Score Service ready", e);
            }
            Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
            Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "MakeNetworkManagementServiceReady");
            try {
                if (networkManagementF != null)
                    networkManagementF.systemReady();
            } catch (Throwable e) {
                reportWtf("making Network Managment Service ready", e);
            }
            Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
            Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "MakeNetworkStatsServiceReady");
            try {
                if (networkStatsF != null)
                    networkStatsF.systemReady();
            } catch (Throwable e) {
                reportWtf("making Network Stats Service ready", e);
            }
            Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
            Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "MakeNetworkPolicyServiceReady");
            try {
                if (networkPolicyF != null)
                    networkPolicyF.systemReady();
            } catch (Throwable e) {
                reportWtf("making Network Policy Service ready", e);
            }
            Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
            Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "MakeConnectivityServiceReady");
            try {
                if (connectivityF != null)
                    connectivityF.systemReady();
            } catch (Throwable e) {
                reportWtf("making Connectivity Service ready", e);
            }
            Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
            Watchdog.getInstance().start();
            // It is now okay to let the various system services start their
            // third party code...
            Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
            Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "PhaseThirdPartyAppsCanStart");
            mSystemServiceManager.startBootPhase(SystemService.PHASE_THIRD_PARTY_APPS_CAN_START);
            try {
                if (locationF != null)
                    locationF.systemRunning();
            } catch (Throwable e) {
                reportWtf("Notifying Location Service running", e);
            }
            try {
                if (countryDetectorF != null)
                    countryDetectorF.systemRunning();
            } catch (Throwable e) {
                reportWtf("Notifying CountryDetectorService running", e);
            }
            try {
                if (networkTimeUpdaterF != null)
                    networkTimeUpdaterF.systemRunning();
            } catch (Throwable e) {
                reportWtf("Notifying NetworkTimeService running", e);
            }
            try {
                if (commonTimeMgmtServiceF != null) {
                    commonTimeMgmtServiceF.systemRunning();
                }
            } catch (Throwable e) {
                reportWtf("Notifying CommonTimeManagementService running", e);
            }
            try {
                if (atlasF != null)
                    atlasF.systemRunning();
            } catch (Throwable e) {
                reportWtf("Notifying AssetAtlasService running", e);
            }
            try {
                // TODO(BT) Pass parameter to input manager
                if (inputManagerF != null)
                    inputManagerF.systemRunning();
            } catch (Throwable e) {
                reportWtf("Notifying InputManagerService running", e);
            }
            try {
                if (telephonyRegistryF != null)
                    telephonyRegistryF.systemRunning();
            } catch (Throwable e) {
                reportWtf("Notifying TelephonyRegistry running", e);
            }
            try {
                if (mediaRouterF != null)
                    mediaRouterF.systemRunning();
            } catch (Throwable e) {
                reportWtf("Notifying MediaRouterService running", e);
            }
            try {
                if (mmsServiceF != null)
                    mmsServiceF.systemRunning();
            } catch (Throwable e) {
                reportWtf("Notifying MmsService running", e);
            }
            try {
                if (networkScoreF != null)
                    networkScoreF.systemRunning();
            } catch (Throwable e) {
                reportWtf("Notifying NetworkScoreService running", e);
            }
            Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
        }
    });
}
Also used : StatusBarManagerService(com.android.server.statusbar.StatusBarManagerService) EdgeGestureService(com.android.server.gesture.EdgeGestureService) Configuration(android.content.res.Configuration) AccessibilityManagerService(com.android.server.accessibility.AccessibilityManagerService) ShortcutService(com.android.server.pm.ShortcutService) INotificationManager(android.app.INotificationManager) AudioService(com.android.server.audio.AudioService) Method(java.lang.reflect.Method) ClipboardService(com.android.server.clipboard.ClipboardService) InvocationTargetException(java.lang.reflect.InvocationTargetException) NetworkPolicyManagerService(com.android.server.net.NetworkPolicyManagerService) GestureService(com.android.server.gesture.GestureService) EdgeGestureService(com.android.server.gesture.EdgeGestureService) SchedulingPolicyService(com.android.server.os.SchedulingPolicyService) IMountService(android.os.storage.IMountService) WindowManagerService(com.android.server.wm.WindowManagerService) MediaRouterService(com.android.server.media.MediaRouterService) InputManagerService(com.android.server.input.InputManagerService) TvInputManagerService(com.android.server.tv.TvInputManagerService) DisplayMetrics(android.util.DisplayMetrics) WindowManager(android.view.WindowManager) PathClassLoader(dalvik.system.PathClassLoader) NetworkStatsService(com.android.server.net.NetworkStatsService) Context(android.content.Context) DevicePolicyManagerService(com.android.server.devicepolicy.DevicePolicyManagerService) ILockSettings(com.android.internal.widget.ILockSettings) Theme(android.content.res.Resources.Theme) RemoteException(android.os.RemoteException)

Example 5 with NetworkStatsService

use of com.android.server.net.NetworkStatsService in project android_frameworks_base by ResurrectionRemix.

the class NetworkStatsServiceTest method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    mServiceContext = new BroadcastInterceptingContext(getContext());
    mStatsDir = getContext().getFilesDir();
    if (mStatsDir.exists()) {
        IoUtils.deleteContents(mStatsDir);
    }
    mNetManager = createMock(INetworkManagementService.class);
    // TODO: Mock AlarmManager when migrating this test to Mockito.
    AlarmManager alarmManager = (AlarmManager) mServiceContext.getSystemService(Context.ALARM_SERVICE);
    mTime = createMock(TrustedTime.class);
    mSettings = createMock(NetworkStatsSettings.class);
    mConnManager = createMock(IConnectivityManager.class);
    PowerManager powerManager = (PowerManager) mServiceContext.getSystemService(Context.POWER_SERVICE);
    PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
    mService = new NetworkStatsService(mServiceContext, mNetManager, alarmManager, wakeLock, mTime, TelephonyManager.getDefault(), mSettings, new NetworkStatsObservers(), mStatsDir, getBaseDir(mStatsDir));
    mHandlerThread = new IdleableHandlerThread("HandlerThread");
    mHandlerThread.start();
    Handler.Callback callback = new NetworkStatsService.HandlerCallback(mService);
    mHandler = new Handler(mHandlerThread.getLooper(), callback);
    mService.setHandler(mHandler, callback);
    mService.bindConnectivityManager(mConnManager);
    mElapsedRealtime = 0L;
    expectCurrentTime();
    expectDefaultSettings();
    expectNetworkStatsUidDetail(buildEmptyStats());
    expectSystemReady();
    // catch INetworkManagementEventObserver during systemReady()
    final Capture<INetworkManagementEventObserver> networkObserver = new Capture<INetworkManagementEventObserver>();
    mNetManager.registerObserver(capture(networkObserver));
    expectLastCall().atLeastOnce();
    replay();
    mService.systemReady();
    mSession = mService.openSession();
    verifyAndReset();
    mNetworkObserver = networkObserver.getValue();
}
Also used : TrustedTime(android.util.TrustedTime) INetworkManagementService(android.os.INetworkManagementService) BroadcastInterceptingContext(com.android.server.BroadcastInterceptingContext) Handler(android.os.Handler) IdleHandler(android.os.MessageQueue.IdleHandler) Capture(org.easymock.Capture) NetworkStatsSettings(com.android.server.net.NetworkStatsService.NetworkStatsSettings) PowerManager(android.os.PowerManager) NetworkStatsService(com.android.server.net.NetworkStatsService) IAlarmManager(android.app.IAlarmManager) AlarmManager(android.app.AlarmManager) INetworkManagementEventObserver(android.net.INetworkManagementEventObserver) IConnectivityManager(android.net.IConnectivityManager)

Aggregations

NetworkStatsService (com.android.server.net.NetworkStatsService)10 Context (android.content.Context)6 Configuration (android.content.res.Configuration)5 INetworkManagementEventObserver (android.net.INetworkManagementEventObserver)5 Handler (android.os.Handler)5 RemoteException (android.os.RemoteException)5 DisplayMetrics (android.util.DisplayMetrics)5 WindowManager (android.view.WindowManager)5 AccessibilityManagerService (com.android.server.accessibility.AccessibilityManagerService)5 InputManagerService (com.android.server.input.InputManagerService)5 NetworkPolicyManagerService (com.android.server.net.NetworkPolicyManagerService)5 SchedulingPolicyService (com.android.server.os.SchedulingPolicyService)5 WindowManagerService (com.android.server.wm.WindowManagerService)5 IAlarmManager (android.app.IAlarmManager)4 INotificationManager (android.app.INotificationManager)4 Theme (android.content.res.Resources.Theme)4 IConnectivityManager (android.net.IConnectivityManager)4 INetworkManagementService (android.os.INetworkManagementService)4 IdleHandler (android.os.MessageQueue.IdleHandler)4 PowerManager (android.os.PowerManager)4