2 * Copyright (C) 2006 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com.android.server;
19 import android.app.ActivityManagerNative;
20 import android.app.ActivityThread;
21 import android.app.IAlarmManager;
22 import android.app.INotificationManager;
23 import android.app.usage.UsageStatsManagerInternal;
24 import android.content.ComponentName;
25 import android.content.ContentResolver;
26 import android.content.Context;
27 import android.content.Intent;
28 import android.content.pm.PackageManager;
29 import android.content.res.Configuration;
30 import android.content.res.Resources.Theme;
31 import android.os.Build;
32 import android.os.Environment;
33 import android.os.FactoryTest;
34 import android.os.FileUtils;
35 import android.os.IPowerManager;
36 import android.os.Looper;
37 import android.os.PowerManager;
38 import android.os.RecoverySystem;
39 import android.os.RemoteException;
40 import android.os.ServiceManager;
41 import android.os.StrictMode;
42 import android.os.SystemClock;
43 import android.os.SystemProperties;
44 import android.os.Trace;
45 import android.os.UserHandle;
46 import android.os.storage.IMountService;
47 import android.util.DisplayMetrics;
48 import android.util.EventLog;
49 import android.util.Slog;
50 import android.view.WindowManager;
52 import com.android.internal.R;
53 import com.android.internal.os.BinderInternal;
54 import com.android.internal.os.SamplingProfilerIntegration;
55 import com.android.internal.os.ZygoteInit;
56 import com.android.server.accessibility.AccessibilityManagerService;
57 import com.android.server.accounts.AccountManagerService;
58 import com.android.server.am.ActivityManagerService;
59 import com.android.server.audio.AudioService;
60 import com.android.server.camera.CameraService;
61 import com.android.server.clipboard.ClipboardService;
62 import com.android.server.connectivity.MetricsLoggerService;
63 import com.android.server.content.ContentService;
64 import com.android.server.devicepolicy.DevicePolicyManagerService;
65 import com.android.server.display.DisplayManagerService;
66 import com.android.server.dreams.DreamManagerService;
67 import com.android.server.fingerprint.FingerprintService;
68 import com.android.server.hdmi.HdmiControlService;
69 import com.android.server.input.InputManagerService;
70 import com.android.server.job.JobSchedulerService;
71 import com.android.server.lights.LightsService;
72 import com.android.internal.widget.ILockSettings;
73 import com.android.server.media.MediaRouterService;
74 import com.android.server.media.MediaSessionService;
75 import com.android.server.media.MediaResourceMonitorService;
76 import com.android.server.media.projection.MediaProjectionManagerService;
77 import com.android.server.net.NetworkPolicyManagerService;
78 import com.android.server.net.NetworkStatsService;
79 import com.android.server.notification.NotificationManagerService;
80 import com.android.server.os.SchedulingPolicyService;
81 import com.android.server.pm.BackgroundDexOptService;
82 import com.android.server.pm.Installer;
83 import com.android.server.pm.LauncherAppsService;
84 import com.android.server.pm.OtaDexoptService;
85 import com.android.server.pm.PackageManagerService;
86 import com.android.server.pm.ShortcutService;
87 import com.android.server.pm.UserManagerService;
88 import com.android.server.power.PowerManagerService;
89 import com.android.server.power.ShutdownThread;
90 import com.android.server.restrictions.RestrictionsManagerService;
91 import com.android.server.soundtrigger.SoundTriggerService;
92 import com.android.server.statusbar.StatusBarManagerService;
93 import com.android.server.storage.DeviceStorageMonitorService;
94 import com.android.server.telecom.TelecomLoaderService;
95 import com.android.server.trust.TrustManagerService;
96 import com.android.server.tv.TvInputManagerService;
97 import com.android.server.twilight.TwilightService;
98 import com.android.server.usage.UsageStatsService;
99 import com.android.server.vr.VrManagerService;
100 import com.android.server.wallpaper.WallpaperManagerService;
101 import com.android.server.webkit.WebViewUpdateService;
102 import com.android.server.wm.WindowManagerService;
104 import dalvik.system.VMRuntime;
107 import java.io.IOException;
108 import java.util.Locale;
109 import java.util.Timer;
110 import java.util.TimerTask;
112 public final class SystemServer {
113 private static final String TAG = "SystemServer";
115 private static final String ENCRYPTING_STATE = "trigger_restart_min_framework";
116 private static final String ENCRYPTED_STATE = "1";
118 private static final long SNAPSHOT_INTERVAL = 60 * 60 * 1000; // 1hr
120 // The earliest supported time. We pick one day into 1970, to
121 // give any timezone code room without going into negative time.
122 private static final long EARLIEST_SUPPORTED_TIME = 86400 * 1000;
125 * Implementation class names. TODO: Move them to a codegen class or load
126 * them from the build system somehow.
128 private static final String BACKUP_MANAGER_SERVICE_CLASS =
129 "com.android.server.backup.BackupManagerService$Lifecycle";
130 private static final String APPWIDGET_SERVICE_CLASS =
131 "com.android.server.appwidget.AppWidgetService";
132 private static final String VOICE_RECOGNITION_MANAGER_SERVICE_CLASS =
133 "com.android.server.voiceinteraction.VoiceInteractionManagerService";
134 private static final String PRINT_MANAGER_SERVICE_CLASS =
135 "com.android.server.print.PrintManagerService";
136 private static final String USB_SERVICE_CLASS =
137 "com.android.server.usb.UsbService$Lifecycle";
138 private static final String MIDI_SERVICE_CLASS =
139 "com.android.server.midi.MidiService$Lifecycle";
140 private static final String WIFI_SERVICE_CLASS =
141 "com.android.server.wifi.WifiService";
142 private static final String WIFI_NAN_SERVICE_CLASS =
143 "com.android.server.wifi.nan.WifiNanService";
144 private static final String WIFI_P2P_SERVICE_CLASS =
145 "com.android.server.wifi.p2p.WifiP2pService";
146 private static final String ETHERNET_SERVICE_CLASS =
147 "com.android.server.ethernet.EthernetService";
148 private static final String JOB_SCHEDULER_SERVICE_CLASS =
149 "com.android.server.job.JobSchedulerService";
150 private static final String LOCK_SETTINGS_SERVICE_CLASS =
151 "com.android.server.LockSettingsService$Lifecycle";
152 private static final String MOUNT_SERVICE_CLASS =
153 "com.android.server.MountService$Lifecycle";
154 private static final String SEARCH_MANAGER_SERVICE_CLASS =
155 "com.android.server.search.SearchManagerService$Lifecycle";
157 private static final String PERSISTENT_DATA_BLOCK_PROP = "ro.frp.pst";
159 private static final String UNCRYPT_PACKAGE_FILE = "/cache/recovery/uncrypt_file";
160 private static final String BLOCK_MAP_FILE = "/cache/recovery/block.map";
163 * Default theme used by the system context. This is used to style
164 * system-provided dialogs, such as the Power Off dialog, and other
167 private static final int DEFAULT_SYSTEM_THEME =
168 com.android.internal.R.style.Theme_Material_DayNight_DarkActionBar;
170 private final int mFactoryTestMode;
171 private Timer mProfilerSnapshotTimer;
173 private Context mSystemContext;
174 private SystemServiceManager mSystemServiceManager;
176 // TODO: remove all of these references by improving dependency resolution and boot phases
177 private PowerManagerService mPowerManagerService;
178 private ActivityManagerService mActivityManagerService;
179 private WebViewUpdateService mWebViewUpdateService;
180 private DisplayManagerService mDisplayManagerService;
181 private PackageManagerService mPackageManagerService;
182 private PackageManager mPackageManager;
183 private ContentResolver mContentResolver;
185 private boolean mOnlyCore;
186 private boolean mFirstBoot;
189 * Start the sensor service.
191 private static native void startSensorService();
194 * The main entry point from zygote.
196 public static void main(String[] args) {
197 new SystemServer().run();
200 public SystemServer() {
201 // Check for factory test mode.
202 mFactoryTestMode = FactoryTest.getMode();
207 Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "InitBeforeStartServices");
208 // If a device's clock is before 1970 (before 0), a lot of
209 // APIs crash dealing with negative numbers, notably
210 // java.io.File#setLastModified, so instead we fake it and
211 // hope that time from cell towers or NTP fixes it shortly.
212 if (System.currentTimeMillis() < EARLIEST_SUPPORTED_TIME) {
213 Slog.w(TAG, "System clock is before 1970; setting to 1970.");
214 SystemClock.setCurrentTimeMillis(EARLIEST_SUPPORTED_TIME);
217 // If the system has "persist.sys.language" and friends set, replace them with
218 // "persist.sys.locale". Note that the default locale at this point is calculated
219 // using the "-Duser.locale" command line flag. That flag is usually populated by
220 // AndroidRuntime using the same set of system properties, but only the system_server
221 // and system apps are allowed to set them.
223 // NOTE: Most changes made here will need an equivalent change to
224 // core/jni/AndroidRuntime.cpp
225 if (!SystemProperties.get("persist.sys.language").isEmpty()) {
226 final String languageTag = Locale.getDefault().toLanguageTag();
228 SystemProperties.set("persist.sys.locale", languageTag);
229 SystemProperties.set("persist.sys.language", "");
230 SystemProperties.set("persist.sys.country", "");
231 SystemProperties.set("persist.sys.localevar", "");
235 Slog.i(TAG, "Entered the Android system server!");
236 EventLog.writeEvent(EventLogTags.BOOT_PROGRESS_SYSTEM_RUN, SystemClock.uptimeMillis());
238 // In case the runtime switched since last boot (such as when
239 // the old runtime was removed in an OTA), set the system
240 // property so that it is in sync. We can't do this in
241 // libnativehelper's JniInvocation::Init code where we already
242 // had to fallback to a different runtime because it is
243 // running as root and we need to be the system user to set
244 // the property. http://b/11463182
245 SystemProperties.set("persist.sys.dalvik.vm.lib.2", VMRuntime.getRuntime().vmLibrary());
247 // Enable the sampling profiler.
248 if (SamplingProfilerIntegration.isEnabled()) {
249 SamplingProfilerIntegration.start();
250 mProfilerSnapshotTimer = new Timer();
251 mProfilerSnapshotTimer.schedule(new TimerTask() {
254 SamplingProfilerIntegration.writeSnapshot("system_server", null);
256 }, SNAPSHOT_INTERVAL, SNAPSHOT_INTERVAL);
259 // Mmmmmm... more memory!
260 VMRuntime.getRuntime().clearGrowthLimit();
262 // The system server has to run all of the time, so it needs to be
263 // as efficient as possible with its memory usage.
264 VMRuntime.getRuntime().setTargetHeapUtilization(0.8f);
266 // Some devices rely on runtime fingerprint generation, so make sure
267 // we've defined it before booting further.
268 Build.ensureFingerprintProperty();
270 // Within the system server, it is an error to access Environment paths without
271 // explicitly specifying a user.
272 Environment.setUserRequired(true);
274 // Ensure binder calls into the system always run at foreground priority.
275 BinderInternal.disableBackgroundScheduling(true);
277 // Prepare the main looper thread (this thread).
278 android.os.Process.setThreadPriority(
279 android.os.Process.THREAD_PRIORITY_FOREGROUND);
280 android.os.Process.setCanSelfBackground(false);
281 Looper.prepareMainLooper();
283 // Initialize native services.
284 System.loadLibrary("android_servers");
286 // Check whether we failed to shut down last time we tried.
287 // This call may not return.
288 performPendingShutdown();
290 // Initialize the system context.
291 createSystemContext();
293 // Create the system service manager.
294 mSystemServiceManager = new SystemServiceManager(mSystemContext);
295 LocalServices.addService(SystemServiceManager.class, mSystemServiceManager);
297 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
302 Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "StartServices");
303 startBootstrapServices();
305 startOtherServices();
306 } catch (Throwable ex) {
307 Slog.e("System", "******************************************");
308 Slog.e("System", "************ Failure starting system services", ex);
311 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
314 // For debug builds, log event loop stalls to dropbox for analysis.
315 if (StrictMode.conditionallyEnableDebugLogging()) {
316 Slog.i(TAG, "Enabled StrictMode for system server main thread.");
321 throw new RuntimeException("Main thread loop unexpectedly exited");
324 private void reportWtf(String msg, Throwable e) {
325 Slog.w(TAG, "***********************************************");
326 Slog.wtf(TAG, "BOOT FAILURE " + msg, e);
329 private void performPendingShutdown() {
330 final String shutdownAction = SystemProperties.get(
331 ShutdownThread.SHUTDOWN_ACTION_PROPERTY, "");
332 if (shutdownAction != null && shutdownAction.length() > 0) {
333 boolean reboot = (shutdownAction.charAt(0) == '1');
336 if (shutdownAction.length() > 1) {
337 reason = shutdownAction.substring(1, shutdownAction.length());
342 // If it's a pending reboot into recovery to apply an update,
343 // always make sure uncrypt gets executed properly when needed.
344 // If '/cache/recovery/block.map' hasn't been created, stop the
345 // reboot which will fail for sure, and get a chance to capture a
346 // bugreport when that's still feasible. (Bug: 26444951)
347 if (PowerManager.REBOOT_RECOVERY_UPDATE.equals(reason)) {
348 File packageFile = new File(UNCRYPT_PACKAGE_FILE);
349 if (packageFile.exists()) {
350 String filename = null;
352 filename = FileUtils.readTextFile(packageFile, 0, null);
353 } catch (IOException e) {
354 Slog.e(TAG, "Error reading uncrypt package file", e);
357 if (filename != null && filename.startsWith("/data")) {
358 if (!new File(BLOCK_MAP_FILE).exists()) {
359 Slog.e(TAG, "Can't find block map file, uncrypt failed or " +
360 "unexpected runtime restart?");
366 ShutdownThread.rebootOrShutdown(null, reboot, reason);
370 private void createSystemContext() {
371 ActivityThread activityThread = ActivityThread.systemMain();
372 mSystemContext = activityThread.getSystemContext();
373 mSystemContext.setTheme(DEFAULT_SYSTEM_THEME);
377 * Starts the small tangle of critical services that are needed to get
378 * the system off the ground. These services have complex mutual dependencies
379 * which is why we initialize them all in one place here. Unless your service
380 * is also entwined in these dependencies, it should be initialized in one of
381 * the other functions.
383 private void startBootstrapServices() {
384 // Wait for installd to finish starting up so that it has a chance to
385 // create critical directories such as /data/user with the appropriate
386 // permissions. We need this to complete before we initialize other services.
387 Installer installer = mSystemServiceManager.startService(Installer.class);
389 // Activity manager runs the show.
390 mActivityManagerService = mSystemServiceManager.startService(
391 ActivityManagerService.Lifecycle.class).getService();
392 mActivityManagerService.setSystemServiceManager(mSystemServiceManager);
393 mActivityManagerService.setInstaller(installer);
395 // Power manager needs to be started early because other services need it.
396 // Native daemons may be watching for it to be registered so it must be ready
397 // to handle incoming binder calls immediately (including being able to verify
398 // the permissions for those calls).
399 mPowerManagerService = mSystemServiceManager.startService(PowerManagerService.class);
401 // Now that the power manager has been started, let the activity manager
402 // initialize power management features.
403 Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "InitPowerManagement");
404 mActivityManagerService.initPowerManagement();
405 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
407 // Manages LEDs and display backlight so we need it to bring up the display.
408 mSystemServiceManager.startService(LightsService.class);
410 // Display manager is needed to provide display metrics before package manager
412 mDisplayManagerService = mSystemServiceManager.startService(DisplayManagerService.class);
414 // We need the default display before we can initialize the package manager.
415 mSystemServiceManager.startBootPhase(SystemService.PHASE_WAIT_FOR_DEFAULT_DISPLAY);
417 // Only run "core" apps if we're encrypting the device.
418 String cryptState = SystemProperties.get("vold.decrypt");
419 if (ENCRYPTING_STATE.equals(cryptState)) {
420 Slog.w(TAG, "Detected encryption in progress - only parsing core apps");
422 } else if (ENCRYPTED_STATE.equals(cryptState)) {
423 Slog.w(TAG, "Device encrypted - only parsing core apps");
427 // Start the package manager.
428 traceBeginAndSlog("StartPackageManagerService");
429 mPackageManagerService = PackageManagerService.main(mSystemContext, installer,
430 mFactoryTestMode != FactoryTest.FACTORY_TEST_OFF, mOnlyCore);
431 mFirstBoot = mPackageManagerService.isFirstBoot();
432 mPackageManager = mSystemContext.getPackageManager();
433 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
435 // Manages A/B OTA dexopting. This is a bootstrap service as we need it to rename
436 // A/B artifacts after boot, before anything else might touch/need them.
437 // Note: this isn't needed during decryption (we don't have /data anyways).
439 boolean disableOtaDexopt = SystemProperties.getBoolean("config.disable_otadexopt",
441 if (!disableOtaDexopt) {
442 traceBeginAndSlog("StartOtaDexOptService");
444 OtaDexoptService.main(mSystemContext, mPackageManagerService);
445 } catch (Throwable e) {
446 reportWtf("starting OtaDexOptService", e);
448 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
453 traceBeginAndSlog("StartUserManagerService");
454 ServiceManager.addService(Context.USER_SERVICE, UserManagerService.getInstance());
455 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
457 // Initialize attribute cache used to cache resources from packages.
458 AttributeCache.init(mSystemContext);
460 // Set up the Application instance for the system process and get started.
461 mActivityManagerService.setSystemProcess();
463 // The sensor service needs access to package manager service, app ops
464 // service, and permissions service, therefore we start it after them.
465 startSensorService();
469 * Starts some essential services that are not tangled up in the bootstrap process.
471 private void startCoreServices() {
472 // Tracks the battery level. Requires LightService.
473 mSystemServiceManager.startService(BatteryService.class);
475 // Tracks application usage stats.
476 mSystemServiceManager.startService(UsageStatsService.class);
477 mActivityManagerService.setUsageStatsManager(
478 LocalServices.getService(UsageStatsManagerInternal.class));
480 // Tracks whether the updatable WebView is in a ready state and watches for update installs.
481 mWebViewUpdateService = mSystemServiceManager.startService(WebViewUpdateService.class);
485 * Starts a miscellaneous grab bag of stuff that has yet to be refactored
488 private void startOtherServices() {
489 final Context context = mSystemContext;
490 AccountManagerService accountManager = null;
491 ContentService contentService = null;
492 VibratorService vibrator = null;
493 IAlarmManager alarm = null;
494 IMountService mountService = null;
495 NetworkManagementService networkManagement = null;
496 NetworkStatsService networkStats = null;
497 NetworkPolicyManagerService networkPolicy = null;
498 ConnectivityService connectivity = null;
499 NetworkScoreService networkScore = null;
500 NsdService serviceDiscovery= null;
501 WindowManagerService wm = null;
502 SerialService serial = null;
503 NetworkTimeUpdateService networkTimeUpdater = null;
504 CommonTimeManagementService commonTimeMgmtService = null;
505 InputManagerService inputManager = null;
506 TelephonyRegistry telephonyRegistry = null;
507 ConsumerIrService consumerIr = null;
508 MmsServiceBroker mmsService = null;
509 EntropyMixer entropyMixer = null;
510 VrManagerService vrManagerService = null;
511 HardwarePropertiesManagerService hardwarePropertiesService = null;
513 boolean disableStorage = SystemProperties.getBoolean("config.disable_storage", false);
514 boolean disableBluetooth = SystemProperties.getBoolean("config.disable_bluetooth", false);
515 boolean disableLocation = SystemProperties.getBoolean("config.disable_location", false);
516 boolean disableSystemUI = SystemProperties.getBoolean("config.disable_systemui", false);
517 boolean disableNonCoreServices = SystemProperties.getBoolean("config.disable_noncore", false);
518 boolean disableNetwork = SystemProperties.getBoolean("config.disable_network", false);
519 boolean disableNetworkTime = SystemProperties.getBoolean("config.disable_networktime", false);
520 boolean disableRtt = SystemProperties.getBoolean("config.disable_rtt", false);
521 boolean disableMediaProjection = SystemProperties.getBoolean("config.disable_mediaproj",
523 boolean disableSerial = SystemProperties.getBoolean("config.disable_serial", false);
524 boolean disableSearchManager = SystemProperties.getBoolean("config.disable_searchmanager",
526 boolean disableTrustManager = SystemProperties.getBoolean("config.disable_trustmanager",
528 boolean disableTextServices = SystemProperties.getBoolean("config.disable_textservices", false);
529 boolean disableSamplingProfiler = SystemProperties.getBoolean("config.disable_samplingprof",
531 boolean isEmulator = SystemProperties.get("ro.kernel.qemu").equals("1");
534 Slog.i(TAG, "Reading configuration...");
535 SystemConfig.getInstance();
537 traceBeginAndSlog("StartSchedulingPolicyService");
538 ServiceManager.addService("scheduling_policy", new SchedulingPolicyService());
539 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
541 mSystemServiceManager.startService(TelecomLoaderService.class);
543 traceBeginAndSlog("StartTelephonyRegistry");
544 telephonyRegistry = new TelephonyRegistry(context);
545 ServiceManager.addService("telephony.registry", telephonyRegistry);
546 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
548 traceBeginAndSlog("StartEntropyMixer");
549 entropyMixer = new EntropyMixer(context);
550 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
552 mContentResolver = context.getContentResolver();
554 Slog.i(TAG, "Camera Service");
555 mSystemServiceManager.startService(CameraService.class);
557 // The AccountManager must come before the ContentService
558 traceBeginAndSlog("StartAccountManagerService");
560 // TODO: seems like this should be disable-able, but req'd by ContentService
561 accountManager = new AccountManagerService(context);
562 ServiceManager.addService(Context.ACCOUNT_SERVICE, accountManager);
563 } catch (Throwable e) {
564 Slog.e(TAG, "Failure starting Account Manager", e);
566 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
568 traceBeginAndSlog("StartContentService");
569 contentService = ContentService.main(context,
570 mFactoryTestMode == FactoryTest.FACTORY_TEST_LOW_LEVEL);
571 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
573 traceBeginAndSlog("InstallSystemProviders");
574 mActivityManagerService.installSystemProviders();
575 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
577 traceBeginAndSlog("StartVibratorService");
578 vibrator = new VibratorService(context);
579 ServiceManager.addService("vibrator", vibrator);
580 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
582 traceBeginAndSlog("StartConsumerIrService");
583 consumerIr = new ConsumerIrService(context);
584 ServiceManager.addService(Context.CONSUMER_IR_SERVICE, consumerIr);
585 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
587 mSystemServiceManager.startService(AlarmManagerService.class);
588 alarm = IAlarmManager.Stub.asInterface(
589 ServiceManager.getService(Context.ALARM_SERVICE));
591 traceBeginAndSlog("InitWatchdog");
592 final Watchdog watchdog = Watchdog.getInstance();
593 watchdog.init(context, mActivityManagerService);
594 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
596 traceBeginAndSlog("StartInputManagerService");
597 inputManager = new InputManagerService(context);
598 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
600 traceBeginAndSlog("StartWindowManagerService");
601 wm = WindowManagerService.main(context, inputManager,
602 mFactoryTestMode != FactoryTest.FACTORY_TEST_LOW_LEVEL,
603 !mFirstBoot, mOnlyCore);
604 ServiceManager.addService(Context.WINDOW_SERVICE, wm);
605 ServiceManager.addService(Context.INPUT_SERVICE, inputManager);
606 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
608 traceBeginAndSlog("StartVrManagerService");
609 mSystemServiceManager.startService(VrManagerService.class);
610 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
612 mActivityManagerService.setWindowManager(wm);
614 inputManager.setWindowManagerCallbacks(wm.getInputMonitor());
615 inputManager.start();
617 // TODO: Use service dependencies instead.
618 mDisplayManagerService.windowManagerAndInputReady();
620 // Skip Bluetooth if we have an emulator kernel
621 // TODO: Use a more reliable check to see if this product should
622 // support Bluetooth - see bug 988521
624 Slog.i(TAG, "No Bluetooth Service (emulator)");
625 } else if (mFactoryTestMode == FactoryTest.FACTORY_TEST_LOW_LEVEL) {
626 Slog.i(TAG, "No Bluetooth Service (factory test)");
627 } else if (!context.getPackageManager().hasSystemFeature
628 (PackageManager.FEATURE_BLUETOOTH)) {
629 Slog.i(TAG, "No Bluetooth Service (Bluetooth Hardware Not Present)");
630 } else if (disableBluetooth) {
631 Slog.i(TAG, "Bluetooth Service disabled by config");
633 mSystemServiceManager.startService(BluetoothService.class);
636 traceBeginAndSlog("ConnectivityMetricsLoggerService");
637 mSystemServiceManager.startService(MetricsLoggerService.class);
638 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
639 } catch (RuntimeException e) {
640 Slog.e("System", "******************************************");
641 Slog.e("System", "************ Failure starting core service", e);
644 StatusBarManagerService statusBar = null;
645 INotificationManager notification = null;
646 WallpaperManagerService wallpaper = null;
647 LocationManagerService location = null;
648 CountryDetectorService countryDetector = null;
649 ILockSettings lockSettings = null;
650 AssetAtlasService atlas = null;
651 MediaRouterService mediaRouter = null;
653 // Bring up services needed for UI.
654 if (mFactoryTestMode != FactoryTest.FACTORY_TEST_LOW_LEVEL) {
655 mSystemServiceManager.startService(InputMethodManagerService.Lifecycle.class);
657 traceBeginAndSlog("StartAccessibilityManagerService");
659 ServiceManager.addService(Context.ACCESSIBILITY_SERVICE,
660 new AccessibilityManagerService(context));
661 } catch (Throwable e) {
662 reportWtf("starting Accessibility Manager", e);
664 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
669 } catch (Throwable e) {
670 reportWtf("making display ready", e);
673 if (mFactoryTestMode != FactoryTest.FACTORY_TEST_LOW_LEVEL) {
674 if (!disableStorage &&
675 !"0".equals(SystemProperties.get("system_init.startmountservice"))) {
678 * NotificationManagerService is dependant on MountService,
679 * (for media / usb notifications) so we must start MountService first.
681 mSystemServiceManager.startService(MOUNT_SERVICE_CLASS);
682 mountService = IMountService.Stub.asInterface(
683 ServiceManager.getService("mount"));
684 } catch (Throwable e) {
685 reportWtf("starting Mount Service", e);
690 // We start this here so that we update our configuration to set watch or television
692 mSystemServiceManager.startService(UiModeManagerService.class);
694 Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "PerformFstrimIfNeeded");
696 mPackageManagerService.performFstrimIfNeeded();
697 } catch (Throwable e) {
698 reportWtf("performing fstrim", e);
700 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
702 Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "ExtractPackagesIfNeeded");
704 mPackageManagerService.extractPackagesIfNeeded();
705 } catch (Throwable e) {
706 reportWtf("extract packages", e);
708 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
711 ActivityManagerNative.getDefault().showBootMessage(
712 context.getResources().getText(
713 com.android.internal.R.string.android_upgrading_starting_apps),
715 } catch (RemoteException e) {
718 if (mFactoryTestMode != FactoryTest.FACTORY_TEST_LOW_LEVEL) {
719 if (!disableNonCoreServices) {
720 traceBeginAndSlog("StartLockSettingsService");
722 mSystemServiceManager.startService(LOCK_SETTINGS_SERVICE_CLASS);
723 lockSettings = ILockSettings.Stub.asInterface(
724 ServiceManager.getService("lock_settings"));
725 } catch (Throwable e) {
726 reportWtf("starting LockSettingsService service", e);
728 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
730 if (!SystemProperties.get(PERSISTENT_DATA_BLOCK_PROP).equals("")) {
731 mSystemServiceManager.startService(PersistentDataBlockService.class);
734 mSystemServiceManager.startService(DeviceIdleController.class);
736 // Always start the Device Policy Manager, so that the API is compatible with
738 mSystemServiceManager.startService(DevicePolicyManagerService.Lifecycle.class);
741 if (!disableSystemUI) {
742 traceBeginAndSlog("StartStatusBarManagerService");
744 statusBar = new StatusBarManagerService(context, wm);
745 ServiceManager.addService(Context.STATUS_BAR_SERVICE, statusBar);
746 } catch (Throwable e) {
747 reportWtf("starting StatusBarManagerService", e);
749 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
752 if (!disableNonCoreServices) {
753 traceBeginAndSlog("StartClipboardService");
755 ServiceManager.addService(Context.CLIPBOARD_SERVICE,
756 new ClipboardService(context));
757 } catch (Throwable e) {
758 reportWtf("starting Clipboard Service", e);
760 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
763 if (!disableNetwork) {
764 traceBeginAndSlog("StartNetworkManagementService");
766 networkManagement = NetworkManagementService.create(context);
767 ServiceManager.addService(Context.NETWORKMANAGEMENT_SERVICE, networkManagement);
768 } catch (Throwable e) {
769 reportWtf("starting NetworkManagement Service", e);
771 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
774 if (!disableNonCoreServices && !disableTextServices) {
775 mSystemServiceManager.startService(TextServicesManagerService.Lifecycle.class);
778 if (!disableNetwork) {
779 traceBeginAndSlog("StartNetworkScoreService");
781 networkScore = new NetworkScoreService(context);
782 ServiceManager.addService(Context.NETWORK_SCORE_SERVICE, networkScore);
783 } catch (Throwable e) {
784 reportWtf("starting Network Score Service", e);
786 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
788 traceBeginAndSlog("StartNetworkStatsService");
790 networkStats = NetworkStatsService.create(context, networkManagement);
791 ServiceManager.addService(Context.NETWORK_STATS_SERVICE, networkStats);
792 } catch (Throwable e) {
793 reportWtf("starting NetworkStats Service", e);
795 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
797 traceBeginAndSlog("StartNetworkPolicyManagerService");
799 networkPolicy = new NetworkPolicyManagerService(
800 context, mActivityManagerService,
801 (IPowerManager)ServiceManager.getService(Context.POWER_SERVICE),
802 networkStats, networkManagement);
803 ServiceManager.addService(Context.NETWORK_POLICY_SERVICE, networkPolicy);
804 } catch (Throwable e) {
805 reportWtf("starting NetworkPolicy Service", e);
807 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
809 if (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_WIFI_NAN)) {
810 mSystemServiceManager.startService(WIFI_NAN_SERVICE_CLASS);
812 Slog.i(TAG, "No Wi-Fi NAN Service (NAN support Not Present)");
814 mSystemServiceManager.startService(WIFI_P2P_SERVICE_CLASS);
815 mSystemServiceManager.startService(WIFI_SERVICE_CLASS);
816 mSystemServiceManager.startService(
817 "com.android.server.wifi.WifiScanningService");
820 mSystemServiceManager.startService("com.android.server.wifi.RttService");
823 if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_ETHERNET) ||
824 mPackageManager.hasSystemFeature(PackageManager.FEATURE_USB_HOST)) {
825 mSystemServiceManager.startService(ETHERNET_SERVICE_CLASS);
828 traceBeginAndSlog("StartConnectivityService");
830 connectivity = new ConnectivityService(
831 context, networkManagement, networkStats, networkPolicy);
832 ServiceManager.addService(Context.CONNECTIVITY_SERVICE, connectivity);
833 networkStats.bindConnectivityManager(connectivity);
834 networkPolicy.bindConnectivityManager(connectivity);
835 } catch (Throwable e) {
836 reportWtf("starting Connectivity Service", e);
838 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
840 traceBeginAndSlog("StartNsdService");
842 serviceDiscovery = NsdService.create(context);
843 ServiceManager.addService(
844 Context.NSD_SERVICE, serviceDiscovery);
845 } catch (Throwable e) {
846 reportWtf("starting Service Discovery Service", e);
848 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
851 if (!disableNonCoreServices) {
852 traceBeginAndSlog("StartUpdateLockService");
854 ServiceManager.addService(Context.UPDATE_LOCK_SERVICE,
855 new UpdateLockService(context));
856 } catch (Throwable e) {
857 reportWtf("starting UpdateLockService", e);
859 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
862 if (!disableNonCoreServices) {
863 mSystemServiceManager.startService(RecoverySystemService.class);
867 * MountService has a few dependencies: Notification Manager and
868 * AppWidget Provider. Make sure MountService is completely started
869 * first before continuing.
871 if (mountService != null && !mOnlyCore) {
872 Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "WaitForAsecScan");
874 mountService.waitForAsecScan();
875 } catch (RemoteException ignored) {
877 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
880 Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "MakeAccountManagerServiceReady");
882 if (accountManager != null)
883 accountManager.systemReady();
884 } catch (Throwable e) {
885 reportWtf("making Account Manager Service ready", e);
887 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
889 Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "MakeContentServiceReady");
891 if (contentService != null)
892 contentService.systemReady();
893 } catch (Throwable e) {
894 reportWtf("making Content Service ready", e);
896 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
898 mSystemServiceManager.startService(NotificationManagerService.class);
899 notification = INotificationManager.Stub.asInterface(
900 ServiceManager.getService(Context.NOTIFICATION_SERVICE));
901 networkPolicy.bindNotificationManager(notification);
903 mSystemServiceManager.startService(DeviceStorageMonitorService.class);
905 if (!disableLocation) {
906 traceBeginAndSlog("StartLocationManagerService");
908 location = new LocationManagerService(context);
909 ServiceManager.addService(Context.LOCATION_SERVICE, location);
910 } catch (Throwable e) {
911 reportWtf("starting Location Manager", e);
913 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
915 traceBeginAndSlog("StartCountryDetectorService");
917 countryDetector = new CountryDetectorService(context);
918 ServiceManager.addService(Context.COUNTRY_DETECTOR, countryDetector);
919 } catch (Throwable e) {
920 reportWtf("starting Country Detector", e);
922 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
925 if (!disableNonCoreServices && !disableSearchManager) {
926 traceBeginAndSlog("StartSearchManagerService");
928 mSystemServiceManager.startService(SEARCH_MANAGER_SERVICE_CLASS);
929 } catch (Throwable e) {
930 reportWtf("starting Search Service", e);
932 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
935 mSystemServiceManager.startService(DropBoxManagerService.class);
937 if (!disableNonCoreServices && context.getResources().getBoolean(
938 R.bool.config_enableWallpaperService)) {
939 traceBeginAndSlog("StartWallpaperManagerService");
941 wallpaper = new WallpaperManagerService(context);
942 ServiceManager.addService(Context.WALLPAPER_SERVICE, wallpaper);
943 } catch (Throwable e) {
944 reportWtf("starting Wallpaper Service", e);
946 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
949 traceBeginAndSlog("StartAudioService");
950 mSystemServiceManager.startService(AudioService.Lifecycle.class);
951 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
953 if (!disableNonCoreServices) {
954 mSystemServiceManager.startService(DockObserver.class);
956 if (context.getPackageManager().hasSystemFeature
957 (PackageManager.FEATURE_WATCH)) {
958 mSystemServiceManager.startService(ThermalObserver.class);
962 traceBeginAndSlog("StartWiredAccessoryManager");
964 // Listen for wired headset changes
965 inputManager.setWiredAccessoryCallbacks(
966 new WiredAccessoryManager(context, inputManager));
967 } catch (Throwable e) {
968 reportWtf("starting WiredAccessoryManager", e);
970 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
972 if (!disableNonCoreServices) {
973 if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_MIDI)) {
974 // Start MIDI Manager service
975 mSystemServiceManager.startService(MIDI_SERVICE_CLASS);
978 if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_USB_HOST)
979 || mPackageManager.hasSystemFeature(
980 PackageManager.FEATURE_USB_ACCESSORY)) {
981 // Manage USB host and device support
982 Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "StartUsbService");
983 mSystemServiceManager.startService(USB_SERVICE_CLASS);
984 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
987 if (!disableSerial) {
988 traceBeginAndSlog("StartSerialService");
990 // Serial port support
991 serial = new SerialService(context);
992 ServiceManager.addService(Context.SERIAL_SERVICE, serial);
993 } catch (Throwable e) {
994 Slog.e(TAG, "Failure starting SerialService", e);
996 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
999 Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER,
1000 "StartHardwarePropertiesManagerService");
1002 hardwarePropertiesService = new HardwarePropertiesManagerService(context);
1003 ServiceManager.addService(Context.HARDWARE_PROPERTIES_SERVICE,
1004 hardwarePropertiesService);
1005 } catch (Throwable e) {
1006 Slog.e(TAG, "Failure starting HardwarePropertiesManagerService", e);
1008 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
1011 mSystemServiceManager.startService(TwilightService.class);
1013 mSystemServiceManager.startService(JobSchedulerService.class);
1015 mSystemServiceManager.startService(SoundTriggerService.class);
1017 if (!disableNonCoreServices) {
1018 if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_BACKUP)) {
1019 mSystemServiceManager.startService(BACKUP_MANAGER_SERVICE_CLASS);
1022 if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_APP_WIDGETS)) {
1023 mSystemServiceManager.startService(APPWIDGET_SERVICE_CLASS);
1026 if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_VOICE_RECOGNIZERS)) {
1027 mSystemServiceManager.startService(VOICE_RECOGNITION_MANAGER_SERVICE_CLASS);
1030 if (GestureLauncherService.isGestureLauncherEnabled(context.getResources())) {
1031 Slog.i(TAG, "Gesture Launcher Service");
1032 mSystemServiceManager.startService(GestureLauncherService.class);
1034 mSystemServiceManager.startService(SensorNotificationService.class);
1035 mSystemServiceManager.startService(ContextHubSystemService.class);
1038 traceBeginAndSlog("StartDiskStatsService");
1040 ServiceManager.addService("diskstats", new DiskStatsService(context));
1041 } catch (Throwable e) {
1042 reportWtf("starting DiskStats Service", e);
1044 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
1046 if (!disableSamplingProfiler) {
1047 traceBeginAndSlog("StartSamplingProfilerService");
1049 // need to add this service even if SamplingProfilerIntegration.isEnabled()
1050 // is false, because it is this service that detects system property change and
1051 // turns on SamplingProfilerIntegration. Plus, when sampling profiler doesn't work,
1052 // there is little overhead for running this service.
1053 ServiceManager.addService("samplingprofiler",
1054 new SamplingProfilerService(context));
1055 } catch (Throwable e) {
1056 reportWtf("starting SamplingProfiler Service", e);
1058 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
1061 if (!disableNetwork && !disableNetworkTime) {
1062 traceBeginAndSlog("StartNetworkTimeUpdateService");
1064 networkTimeUpdater = new NetworkTimeUpdateService(context);
1065 ServiceManager.addService("network_time_update_service", networkTimeUpdater);
1066 } catch (Throwable e) {
1067 reportWtf("starting NetworkTimeUpdate service", e);
1069 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
1072 traceBeginAndSlog("StartCommonTimeManagementService");
1074 commonTimeMgmtService = new CommonTimeManagementService(context);
1075 ServiceManager.addService("commontime_management", commonTimeMgmtService);
1076 } catch (Throwable e) {
1077 reportWtf("starting CommonTimeManagementService service", e);
1079 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
1081 if (!disableNetwork) {
1082 traceBeginAndSlog("CertBlacklister");
1084 CertBlacklister blacklister = new CertBlacklister(context);
1085 } catch (Throwable e) {
1086 reportWtf("starting CertBlacklister", e);
1088 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
1091 if (!disableNonCoreServices) {
1092 // Dreams (interactive idle-time views, a/k/a screen savers, and doze mode)
1093 mSystemServiceManager.startService(DreamManagerService.class);
1096 if (!disableNonCoreServices && ZygoteInit.PRELOAD_RESOURCES) {
1097 traceBeginAndSlog("StartAssetAtlasService");
1099 atlas = new AssetAtlasService(context);
1100 ServiceManager.addService(AssetAtlasService.ASSET_ATLAS_SERVICE, atlas);
1101 } catch (Throwable e) {
1102 reportWtf("starting AssetAtlasService", e);
1104 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
1107 if (!disableNonCoreServices) {
1108 ServiceManager.addService(GraphicsStatsService.GRAPHICS_STATS_SERVICE,
1109 new GraphicsStatsService(context));
1112 if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_PRINTING)) {
1113 mSystemServiceManager.startService(PRINT_MANAGER_SERVICE_CLASS);
1116 mSystemServiceManager.startService(RestrictionsManagerService.class);
1118 mSystemServiceManager.startService(MediaSessionService.class);
1120 if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_HDMI_CEC)) {
1121 mSystemServiceManager.startService(HdmiControlService.class);
1124 if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_LIVE_TV)) {
1125 mSystemServiceManager.startService(TvInputManagerService.class);
1128 mSystemServiceManager.startService(MediaResourceMonitorService.class);
1130 if (!disableNonCoreServices) {
1131 traceBeginAndSlog("StartMediaRouterService");
1133 mediaRouter = new MediaRouterService(context);
1134 ServiceManager.addService(Context.MEDIA_ROUTER_SERVICE, mediaRouter);
1135 } catch (Throwable e) {
1136 reportWtf("starting MediaRouterService", e);
1138 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
1140 if (!disableTrustManager) {
1141 mSystemServiceManager.startService(TrustManagerService.class);
1144 if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_FINGERPRINT)) {
1145 mSystemServiceManager.startService(FingerprintService.class);
1148 traceBeginAndSlog("StartBackgroundDexOptService");
1150 BackgroundDexOptService.schedule(context);
1151 } catch (Throwable e) {
1152 reportWtf("starting BackgroundDexOptService", e);
1154 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
1156 // LauncherAppsService uses ShortcutService.
1157 mSystemServiceManager.startService(ShortcutService.Lifecycle.class);
1159 mSystemServiceManager.startService(LauncherAppsService.class);
1162 if (!disableNonCoreServices && !disableMediaProjection) {
1163 mSystemServiceManager.startService(MediaProjectionManagerService.class);
1166 // Before things start rolling, be sure we have decided whether
1167 // we are in safe mode.
1168 final boolean safeMode = wm.detectSafeMode();
1170 mActivityManagerService.enterSafeMode();
1171 // Disable the JIT for the system_server process
1172 VMRuntime.getRuntime().disableJitCompilation();
1174 // Enable the JIT for the system_server process
1175 VMRuntime.getRuntime().startJitCompilation();
1178 // MMS service broker
1179 mmsService = mSystemServiceManager.startService(MmsServiceBroker.class);
1181 // It is now time to start up the app processes...
1183 Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "MakeVibratorServiceReady");
1185 vibrator.systemReady();
1186 } catch (Throwable e) {
1187 reportWtf("making Vibrator Service ready", e);
1189 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
1191 Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "MakeLockSettingsServiceReady");
1192 if (lockSettings != null) {
1194 lockSettings.systemReady();
1195 } catch (Throwable e) {
1196 reportWtf("making Lock Settings Service ready", e);
1199 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
1201 // Needed by DevicePolicyManager for initialization
1202 mSystemServiceManager.startBootPhase(SystemService.PHASE_LOCK_SETTINGS_READY);
1204 mSystemServiceManager.startBootPhase(SystemService.PHASE_SYSTEM_SERVICES_READY);
1206 Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "MakeWindowManagerServiceReady");
1209 } catch (Throwable e) {
1210 reportWtf("making Window Manager Service ready", e);
1212 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
1215 mActivityManagerService.showSafeModeOverlay();
1218 // Update the configuration for this context by hand, because we're going
1219 // to start using it before the config change done in wm.systemReady() will
1221 Configuration config = wm.computeNewConfiguration();
1222 DisplayMetrics metrics = new DisplayMetrics();
1223 WindowManager w = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
1224 w.getDefaultDisplay().getMetrics(metrics);
1225 context.getResources().updateConfiguration(config, metrics);
1227 // The system context's theme may be configuration-dependent.
1228 final Theme systemTheme = context.getTheme();
1229 if (systemTheme.getChangingConfigurations() != 0) {
1230 systemTheme.rebase();
1233 Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "MakePowerManagerServiceReady");
1235 // TODO: use boot phase
1236 mPowerManagerService.systemReady(mActivityManagerService.getAppOpsService());
1237 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
1238 } catch (Throwable e) {
1239 reportWtf("making Power Manager Service ready", e);
1241 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
1243 Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "MakePackageManagerServiceReady");
1245 mPackageManagerService.systemReady();
1246 } catch (Throwable e) {
1247 reportWtf("making Package Manager Service ready", e);
1249 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
1251 Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "MakeDisplayManagerServiceReady");
1253 // TODO: use boot phase and communicate these flags some other way
1254 mDisplayManagerService.systemReady(safeMode, mOnlyCore);
1255 } catch (Throwable e) {
1256 reportWtf("making Display Manager Service ready", e);
1258 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
1260 // These are needed to propagate to the runnable below.
1261 final NetworkManagementService networkManagementF = networkManagement;
1262 final NetworkStatsService networkStatsF = networkStats;
1263 final NetworkPolicyManagerService networkPolicyF = networkPolicy;
1264 final ConnectivityService connectivityF = connectivity;
1265 final NetworkScoreService networkScoreF = networkScore;
1266 final WallpaperManagerService wallpaperF = wallpaper;
1267 final LocationManagerService locationF = location;
1268 final CountryDetectorService countryDetectorF = countryDetector;
1269 final NetworkTimeUpdateService networkTimeUpdaterF = networkTimeUpdater;
1270 final CommonTimeManagementService commonTimeMgmtServiceF = commonTimeMgmtService;
1271 final StatusBarManagerService statusBarF = statusBar;
1272 final AssetAtlasService atlasF = atlas;
1273 final InputManagerService inputManagerF = inputManager;
1274 final TelephonyRegistry telephonyRegistryF = telephonyRegistry;
1275 final MediaRouterService mediaRouterF = mediaRouter;
1276 final MmsServiceBroker mmsServiceF = mmsService;
1278 // We now tell the activity manager it is okay to run third party
1279 // code. It will call back into us once it has gotten to the state
1280 // where third party code can really run (but before it has actually
1281 // started launching the initial applications), for us to complete our
1283 mActivityManagerService.systemReady(new Runnable() {
1286 Slog.i(TAG, "Making services ready");
1287 mSystemServiceManager.startBootPhase(
1288 SystemService.PHASE_ACTIVITY_MANAGER_READY);
1289 Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "PhaseActivityManagerReady");
1291 Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "StartObservingNativeCrashes");
1293 mActivityManagerService.startObservingNativeCrashes();
1294 } catch (Throwable e) {
1295 reportWtf("observing native crashes", e);
1297 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
1300 Slog.i(TAG, "WebViewFactory preparation");
1301 Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "WebViewFactoryPreparation");
1302 mWebViewUpdateService.prepareWebViewInSystemServer();
1303 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
1306 Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "StartSystemUI");
1308 startSystemUi(context);
1309 } catch (Throwable e) {
1310 reportWtf("starting System UI", e);
1312 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
1313 Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "MakeMountServiceReady");
1315 if (networkScoreF != null) networkScoreF.systemReady();
1316 } catch (Throwable e) {
1317 reportWtf("making Network Score Service ready", e);
1319 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
1320 Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "MakeNetworkManagementServiceReady");
1322 if (networkManagementF != null) networkManagementF.systemReady();
1323 } catch (Throwable e) {
1324 reportWtf("making Network Managment Service ready", e);
1326 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
1327 Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "MakeNetworkStatsServiceReady");
1329 if (networkStatsF != null) networkStatsF.systemReady();
1330 } catch (Throwable e) {
1331 reportWtf("making Network Stats Service ready", e);
1333 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
1334 Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "MakeNetworkPolicyServiceReady");
1336 if (networkPolicyF != null) networkPolicyF.systemReady();
1337 } catch (Throwable e) {
1338 reportWtf("making Network Policy Service ready", e);
1340 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
1341 Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "MakeConnectivityServiceReady");
1343 if (connectivityF != null) connectivityF.systemReady();
1344 } catch (Throwable e) {
1345 reportWtf("making Connectivity Service ready", e);
1347 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
1349 Watchdog.getInstance().start();
1351 // It is now okay to let the various system services start their
1352 // third party code...
1353 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
1354 Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "PhaseThirdPartyAppsCanStart");
1355 mSystemServiceManager.startBootPhase(
1356 SystemService.PHASE_THIRD_PARTY_APPS_CAN_START);
1359 if (wallpaperF != null) wallpaperF.systemRunning();
1360 } catch (Throwable e) {
1361 reportWtf("Notifying WallpaperService running", e);
1364 if (locationF != null) locationF.systemRunning();
1365 } catch (Throwable e) {
1366 reportWtf("Notifying Location Service running", e);
1369 if (countryDetectorF != null) countryDetectorF.systemRunning();
1370 } catch (Throwable e) {
1371 reportWtf("Notifying CountryDetectorService running", e);
1374 if (networkTimeUpdaterF != null) networkTimeUpdaterF.systemRunning();
1375 } catch (Throwable e) {
1376 reportWtf("Notifying NetworkTimeService running", e);
1379 if (commonTimeMgmtServiceF != null) {
1380 commonTimeMgmtServiceF.systemRunning();
1382 } catch (Throwable e) {
1383 reportWtf("Notifying CommonTimeManagementService running", e);
1386 if (atlasF != null) atlasF.systemRunning();
1387 } catch (Throwable e) {
1388 reportWtf("Notifying AssetAtlasService running", e);
1391 // TODO(BT) Pass parameter to input manager
1392 if (inputManagerF != null) inputManagerF.systemRunning();
1393 } catch (Throwable e) {
1394 reportWtf("Notifying InputManagerService running", e);
1397 if (telephonyRegistryF != null) telephonyRegistryF.systemRunning();
1398 } catch (Throwable e) {
1399 reportWtf("Notifying TelephonyRegistry running", e);
1402 if (mediaRouterF != null) mediaRouterF.systemRunning();
1403 } catch (Throwable e) {
1404 reportWtf("Notifying MediaRouterService running", e);
1408 if (mmsServiceF != null) mmsServiceF.systemRunning();
1409 } catch (Throwable e) {
1410 reportWtf("Notifying MmsService running", e);
1412 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
1417 static final void startSystemUi(Context context) {
1418 Intent intent = new Intent();
1419 intent.setComponent(new ComponentName("com.android.systemui",
1420 "com.android.systemui.SystemUIService"));
1421 intent.addFlags(Intent.FLAG_DEBUG_TRIAGED_MISSING);
1422 //Slog.d(TAG, "Starting service: " + intent);
1423 context.startServiceAsUser(intent, UserHandle.SYSTEM);
1426 private static void traceBeginAndSlog(String name) {
1427 Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, name);