diff options
Diffstat (limited to 'services/java/com')
-rw-r--r-- | services/java/com/android/server/SystemServer.java | 296 |
1 files changed, 109 insertions, 187 deletions
diff --git a/services/java/com/android/server/SystemServer.java b/services/java/com/android/server/SystemServer.java index 54be537..0d05c5f 100644 --- a/services/java/com/android/server/SystemServer.java +++ b/services/java/com/android/server/SystemServer.java @@ -63,6 +63,7 @@ import com.android.server.content.ContentService; import com.android.server.devicepolicy.DevicePolicyManagerService; import com.android.server.display.DisplayManagerService; import com.android.server.dreams.DreamManagerService; +import com.android.server.fingerprint.FingerprintService; import com.android.server.hdmi.HdmiControlService; import com.android.server.input.InputManagerService; import com.android.server.job.JobSchedulerService; @@ -81,6 +82,7 @@ import com.android.server.pm.PackageManagerService; import com.android.server.pm.UserManagerService; import com.android.server.power.PowerManagerService; import com.android.server.power.ShutdownThread; +import com.android.server.restrictions.RestrictionsManagerService; import com.android.server.search.SearchManagerService; import com.android.server.statusbar.StatusBarManagerService; import com.android.server.storage.DeviceStorageMonitorService; @@ -126,7 +128,7 @@ public final class SystemServer { private static final String WIFI_SERVICE_CLASS = "com.android.server.wifi.WifiService"; private static final String WIFI_PASSPOINT_SERVICE_CLASS = - "com.android.server.wifi.passpoint.PasspointService"; + "com.android.server.wifi.passpoint.WifiPasspointService"; private static final String WIFI_P2P_SERVICE_CLASS = "com.android.server.wifi.p2p.WifiP2pService"; private static final String ETHERNET_SERVICE_CLASS = @@ -145,8 +147,13 @@ public final class SystemServer { private PowerManagerService mPowerManagerService; private ActivityManagerService mActivityManagerService; private DisplayManagerService mDisplayManagerService; + private PackageManagerService mPackageManagerService; + private PackageManager mPackageManager; private ContentResolver mContentResolver; + private boolean mOnlyCore; + private boolean mFirstBoot; + /** * Called to initialize native system services. */ @@ -160,6 +167,7 @@ public final class SystemServer { } public SystemServer() { + // Check for factory test mode. mFactoryTestMode = FactoryTest.getMode(); } @@ -242,7 +250,7 @@ public final class SystemServer { startBootstrapServices(); startCoreServices(); startOtherServices(); - } catch (RuntimeException ex) { + } catch (Throwable ex) { Slog.e("System", "******************************************"); Slog.e("System", "************ Failure starting system services", ex); throw ex; @@ -286,36 +294,84 @@ public final class SystemServer { mSystemContext.setTheme(android.R.style.Theme_DeviceDefault_Light_DarkActionBar); } + /** + * Starts the small tangle of critical services that are needed to get + * the system off the ground. These services have complex mutual dependencies + * which is why we initialize them all in one place here. Unless your service + * is also entwined in these dependencies, it should be initialized in one of + * the other functions. + */ private void startBootstrapServices() { // Wait for installd to finish starting up so that it has a chance to // create critical directories such as /data/user with the appropriate // permissions. We need this to complete before we initialize other services. mInstaller = mSystemServiceManager.startService(Installer.class); - // Power manager needs to be started early because other services need it. - // TODO: The conversion to the new pattern is incomplete. We need to switch - // the power manager's dependencies over then we can use boot phases to arrange - // initialization order and remove the mPowerManagerService field. - mPowerManagerService = mSystemServiceManager.startService(PowerManagerService.class); - // Activity manager runs the show. mActivityManagerService = mSystemServiceManager.startService( ActivityManagerService.Lifecycle.class).getService(); mActivityManagerService.setSystemServiceManager(mSystemServiceManager); - } - private void startCoreServices() { + // Power manager needs to be started early because other services need it. + // Native daemons may be watching for it to be registered so it must be ready + // to handle incoming binder calls immediately (including being able to verify + // the permissions for those calls). + mPowerManagerService = mSystemServiceManager.startService(PowerManagerService.class); + + // Now that the power manager has been started, let the activity manager + // initialize power management features. + mActivityManagerService.initPowerManagement(); + // Display manager is needed to provide display metrics before package manager // starts up. mDisplayManagerService = mSystemServiceManager.startService(DisplayManagerService.class); + + // We need the default display before we can initialize the package manager. + mSystemServiceManager.startBootPhase(SystemService.PHASE_WAIT_FOR_DEFAULT_DISPLAY); + + // Only run "core" apps if we're encrypting the device. + String cryptState = SystemProperties.get("vold.decrypt"); + if (ENCRYPTING_STATE.equals(cryptState)) { + Slog.w(TAG, "Detected encryption in progress - only parsing core apps"); + mOnlyCore = true; + } else if (ENCRYPTED_STATE.equals(cryptState)) { + Slog.w(TAG, "Device encrypted - only parsing core apps"); + mOnlyCore = true; + } + + // Start the package manager. + Slog.i(TAG, "Package Manager"); + mPackageManagerService = PackageManagerService.main(mSystemContext, mInstaller, + mFactoryTestMode != FactoryTest.FACTORY_TEST_OFF, mOnlyCore); + mFirstBoot = mPackageManagerService.isFirstBoot(); + mPackageManager = mSystemContext.getPackageManager(); + + // Initialize attribute cache used to cache resources from packages. + AttributeCache.init(mSystemContext); + + // Set up the Application instance for the system process and get started. + mActivityManagerService.setSystemProcess(); } + /** + * Starts some essential services that are not tangled up in the bootstrap process. + */ + private void startCoreServices() { + // Manages LEDs and display backlight. + mSystemServiceManager.startService(LightsService.class); + + // Tracks the battery level. Requires LightService. + mSystemServiceManager.startService(BatteryService.class); + } + + /** + * Starts a miscellaneous grab bag of stuff that has yet to be refactored + * and organized. + */ private void startOtherServices() { final Context context = mSystemContext; AccountManagerService accountManager = null; ContentService contentService = null; - LightsManager lights = null; - BatteryService battery = null; VibratorService vibrator = null; IAlarmManager alarm = null; MountService mountService = null; @@ -325,10 +381,8 @@ public final class SystemServer { ConnectivityService connectivity = null; NetworkScoreService networkScore = null; NsdService serviceDiscovery= null; - IPackageManager pm = null; WindowManagerService wm = null; BluetoothManagerService bluetooth = null; - DockObserver dock = null; UsbService usb = null; SerialService serial = null; RecognitionManagerService recognition = null; @@ -339,8 +393,6 @@ public final class SystemServer { ConsumerIrService consumerIr = null; AudioService audioService = null; - boolean onlyCore = false; - boolean firstBoot = false; boolean disableStorage = SystemProperties.getBoolean("config.disable_storage", false); boolean disableMedia = SystemProperties.getBoolean("config.disable_media", false); boolean disableBluetooth = SystemProperties.getBoolean("config.disable_bluetooth", false); @@ -352,38 +404,12 @@ public final class SystemServer { boolean isEmulator = SystemProperties.get("ro.kernel.qemu").equals("1"); try { - Slog.i(TAG, "Telephony Registry"); - telephonyRegistry = new TelephonyRegistry(context); - ServiceManager.addService("telephony.registry", telephonyRegistry); - Slog.i(TAG, "Scheduling Policy"); ServiceManager.addService("scheduling_policy", new SchedulingPolicyService()); - AttributeCache.init(context); - - // We need the default display before we can initialize the package manager. - mSystemServiceManager.startBootPhase(SystemService.PHASE_WAIT_FOR_DEFAULT_DISPLAY); - - Slog.i(TAG, "Package Manager"); - // Only run "core" apps if we're encrypting the device. - String cryptState = SystemProperties.get("vold.decrypt"); - if (ENCRYPTING_STATE.equals(cryptState)) { - Slog.w(TAG, "Detected encryption in progress - only parsing core apps"); - onlyCore = true; - } else if (ENCRYPTED_STATE.equals(cryptState)) { - Slog.w(TAG, "Device encrypted - only parsing core apps"); - onlyCore = true; - } - - pm = PackageManagerService.main(context, mInstaller, - mFactoryTestMode != FactoryTest.FACTORY_TEST_OFF, - onlyCore); - try { - firstBoot = pm.isFirstBoot(); - } catch (RemoteException e) { - } - - mActivityManagerService.setSystemProcess(); + Slog.i(TAG, "Telephony Registry"); + telephonyRegistry = new TelephonyRegistry(context); + ServiceManager.addService("telephony.registry", telephonyRegistry); Slog.i(TAG, "Entropy Mixer"); ServiceManager.addService("entropy", new EntropyMixer(context)); @@ -411,24 +437,10 @@ public final class SystemServer { Slog.i(TAG, "System Content Providers"); mActivityManagerService.installSystemProviders(); - mSystemServiceManager.startService(LightsService.class); - lights = LocalServices.getService(LightsManager.class); - - Slog.i(TAG, "Battery Service"); - battery = new BatteryService(context, lights); - ServiceManager.addService("battery", battery); - Slog.i(TAG, "Vibrator Service"); vibrator = new VibratorService(context); ServiceManager.addService("vibrator", vibrator); - // TODO: use boot phase - // only initialize the power service after we have started the - // lights service, content providers and the battery service. - mPowerManagerService.init(lights, battery, - BatteryStatsService.getService(), - mActivityManagerService.getAppOpsService()); - Slog.i(TAG, "Consumer IR Service"); consumerIr = new ConsumerIrService(context); ServiceManager.addService(Context.CONSUMER_IR_SERVICE, consumerIr); @@ -447,7 +459,7 @@ public final class SystemServer { Slog.i(TAG, "Window Manager"); wm = WindowManagerService.main(context, inputManager, mFactoryTestMode != FactoryTest.FACTORY_TEST_LOW_LEVEL, - !firstBoot, onlyCore); + !mFirstBoot, mOnlyCore); ServiceManager.addService(Context.WINDOW_SERVICE, wm); ServiceManager.addService(Context.INPUT_SERVICE, inputManager); @@ -521,7 +533,7 @@ public final class SystemServer { } try { - pm.performBootDexOpt(); + mPackageManagerService.performBootDexOpt(); } catch (Throwable e) { reportWtf("performing boot dexopt", e); } @@ -559,13 +571,9 @@ public final class SystemServer { reportWtf("starting LockSettingsService service", e); } - try { - // Always start the Device Policy Manager, so that the API is compatible with - // API8. - mSystemServiceManager.startService(DevicePolicyManagerService.Lifecycle.class); - } catch (Throwable e) { - reportWtf("starting DevicePolicyService", e); - } + // Always start the Device Policy Manager, so that the API is compatible with + // API8. + mSystemServiceManager.startService(DevicePolicyManagerService.Lifecycle.class); } if (!disableSystemUI) { @@ -636,39 +644,17 @@ public final class SystemServer { reportWtf("starting NetworkPolicy Service", e); } - try { - mSystemServiceManager.startService(WIFI_P2P_SERVICE_CLASS); - } catch (Throwable e) { - reportWtf("starting Wi-Fi P2pService", e); - } + mSystemServiceManager.startService(WIFI_P2P_SERVICE_CLASS); - try { - mSystemServiceManager.startService(WIFI_SERVICE_CLASS); - } catch (Throwable e) { - reportWtf("starting Wi-Fi Service", e); - } + mSystemServiceManager.startService(WIFI_PASSPOINT_SERVICE_CLASS); - try { - mSystemServiceManager.startService(WIFI_PASSPOINT_SERVICE_CLASS); - } catch (Throwable e) { - reportWtf("starting Wi-Fi PasspointService", e); - } + mSystemServiceManager.startService(WIFI_SERVICE_CLASS); - try { - Slog.i(TAG, "Wi-Fi Scanning Service"); - mSystemServiceManager.startService( + mSystemServiceManager.startService( "com.android.server.wifi.WifiScanningService"); - } catch (Throwable e) { - reportWtf("starting Wi-Fi Scanning Service", e); - } - if (!isEmulator) { - try { - mSystemServiceManager.startService(ETHERNET_SERVICE_CLASS); - } catch (Throwable e) { - reportWtf("starting Ethernet Service", e); - } + mSystemServiceManager.startService(ETHERNET_SERVICE_CLASS); } else { // Don't start the Ethernet service on the emulator because // it interferes with qemu's SLIRP emulation, which uses @@ -712,7 +698,7 @@ public final class SystemServer { * AppWidget Provider. Make sure MountService is completely started * first before continuing. */ - if (mountService != null && !onlyCore) { + if (mountService != null && !mOnlyCore) { mountService.waitForAsecScan(); } @@ -795,13 +781,7 @@ public final class SystemServer { } if (!disableNonCoreServices) { - try { - Slog.i(TAG, "Dock Observer"); - // Listen for dock station changes - dock = new DockObserver(context); - } catch (Throwable e) { - reportWtf("starting DockObserver", e); - } + mSystemServiceManager.startService(DockObserver.class); } if (!disableMedia) { @@ -816,14 +796,11 @@ public final class SystemServer { } if (!disableNonCoreServices) { - try { - if (pm.hasSystemFeature(PackageManager.FEATURE_USB_HOST) || - pm.hasSystemFeature(PackageManager.FEATURE_USB_ACCESSORY)) { - // Manage USB host and device support - mSystemServiceManager.startService(USB_SERVICE_CLASS); - } - } catch (Throwable e) { - reportWtf("starting UsbService", e); + if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_USB_HOST) + || mPackageManager.hasSystemFeature( + PackageManager.FEATURE_USB_ACCESSORY)) { + // Manage USB host and device support + mSystemServiceManager.startService(USB_SERVICE_CLASS); } try { @@ -843,20 +820,12 @@ public final class SystemServer { mSystemServiceManager.startService(JobSchedulerService.class); if (!disableNonCoreServices) { - try { - if (pm.hasSystemFeature(PackageManager.FEATURE_BACKUP)) { - mSystemServiceManager.startService(BACKUP_MANAGER_SERVICE_CLASS); - } - } catch (Throwable e) { - Slog.e(TAG, "Failure starting Backup Service", e); + if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_BACKUP)) { + mSystemServiceManager.startService(BACKUP_MANAGER_SERVICE_CLASS); } - try { - if (pm.hasSystemFeature(PackageManager.FEATURE_APP_WIDGETS)) { - mSystemServiceManager.startService(APPWIDGET_SERVICE_CLASS); - } - } catch (Throwable e) { - reportWtf("starting AppWidget Service", e); + if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_APP_WIDGETS)) { + mSystemServiceManager.startService(APPWIDGET_SERVICE_CLASS); } try { @@ -866,13 +835,8 @@ public final class SystemServer { reportWtf("starting Recognition Service", e); } - try { - if (pm.hasSystemFeature(PackageManager.FEATURE_VOICE_RECOGNIZERS)) { - Slog.i(TAG, "Voice Recognition Service"); - mSystemServiceManager.startService(VOICE_RECOGNITION_MANAGER_SERVICE_CLASS); - } - } catch (Throwable e) { - reportWtf("starting Voice Recognition Service", e); + if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_VOICE_RECOGNIZERS)) { + mSystemServiceManager.startService(VOICE_RECOGNITION_MANAGER_SERVICE_CLASS); } } @@ -938,39 +902,17 @@ public final class SystemServer { } } - try { - Slog.i(TAG, "IdleMaintenanceService"); - new IdleMaintenanceService(context, battery); - } catch (Throwable e) { - reportWtf("starting IdleMaintenanceService", e); + if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_PRINTING)) { + mSystemServiceManager.startService(PRINT_MANAGER_SERVICE_CLASS); } - try { - if (pm.hasSystemFeature(PackageManager.FEATURE_PRINTING)) { - mSystemServiceManager.startService(PRINT_MANAGER_SERVICE_CLASS); - } - } catch (Throwable e) { - reportWtf("starting Print Service", e); - } + mSystemServiceManager.startService(RestrictionsManagerService.class); - try { - mSystemServiceManager.startService(MediaSessionService.class); - } catch (Throwable e) { - reportWtf("starting MediaSessionService", e); - } + mSystemServiceManager.startService(MediaSessionService.class); - try { - mSystemServiceManager.startService(HdmiControlService.class); - } catch (Throwable e) { - reportWtf("starting HdmiControlService", e); - } + mSystemServiceManager.startService(HdmiControlService.class); - try { - Slog.i(TAG, "TvInputManagerService"); - mSystemServiceManager.startService(TvInputManagerService.class); - } catch (Throwable e) { - reportWtf("starting TvInputManagerService", e); - } + mSystemServiceManager.startService(TvInputManagerService.class); if (!disableNonCoreServices) { try { @@ -981,28 +923,20 @@ public final class SystemServer { reportWtf("starting MediaRouterService", e); } - try { - Slog.i(TAG, "Trust Manager"); - mSystemServiceManager.startService(TrustManagerService.class); - } catch (Throwable e) { - Slog.e(TAG, "Failure starting TrustManagerService", e); - } + mSystemServiceManager.startService(TrustManagerService.class); + + mSystemServiceManager.startService(FingerprintService.class); try { Slog.i(TAG, "BackgroundDexOptService"); - new BackgroundDexOptService(context); + BackgroundDexOptService.schedule(context); } catch (Throwable e) { reportWtf("starting BackgroundDexOptService", e); } - } - try { - Slog.i(TAG, "LauncherAppsService"); - LauncherAppsService las = new LauncherAppsService(context); - ServiceManager.addService(Context.LAUNCHER_APPS_SERVICE, las); - } catch (Throwable t) { - reportWtf("starting LauncherAppsService", t); } + + mSystemServiceManager.startService(LauncherAppsService.class); } // Before things start rolling, be sure we have decided whether @@ -1059,33 +993,31 @@ public final class SystemServer { try { // TODO: use boot phase - mPowerManagerService.systemReady(); + mPowerManagerService.systemReady(mActivityManagerService.getAppOpsService()); } catch (Throwable e) { reportWtf("making Power Manager Service ready", e); } try { - pm.systemReady(); + mPackageManagerService.systemReady(); } catch (Throwable e) { reportWtf("making Package Manager Service ready", e); } try { // TODO: use boot phase and communicate these flags some other way - mDisplayManagerService.systemReady(safeMode, onlyCore); + mDisplayManagerService.systemReady(safeMode, mOnlyCore); } catch (Throwable e) { reportWtf("making Display Manager Service ready", e); } // These are needed to propagate to the runnable below. final MountService mountServiceF = mountService; - final BatteryService batteryF = battery; final NetworkManagementService networkManagementF = networkManagement; final NetworkStatsService networkStatsF = networkStats; final NetworkPolicyManagerService networkPolicyF = networkPolicy; final ConnectivityService connectivityF = connectivity; final NetworkScoreService networkScoreF = networkScore; - final DockObserver dockF = dock; final WallpaperManagerService wallpaperF = wallpaper; final InputMethodManagerService immF = imm; final RecognitionManagerService recognitionF = recognition; @@ -1129,11 +1061,6 @@ public final class SystemServer { reportWtf("making Mount Service ready", e); } try { - if (batteryF != null) batteryF.systemReady(); - } catch (Throwable e) { - reportWtf("making Battery Service ready", e); - } - try { if (networkScoreF != null) networkScoreF.systemReady(); } catch (Throwable e) { reportWtf("making Network Score Service ready", e); @@ -1159,11 +1086,6 @@ public final class SystemServer { reportWtf("making Connectivity Service ready", e); } try { - if (dockF != null) dockF.systemReady(); - } catch (Throwable e) { - reportWtf("making Dock Service ready", e); - } - try { if (recognitionF != null) recognitionF.systemReady(); } catch (Throwable e) { reportWtf("making Recognition Service ready", e); |