1 /* 2 * Copyright (C) 2006 The Android Open Source Project 3 * 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 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 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. 15 */ 16 17 package com.android.server; 18 19 import android.app.ActivityManagerNative; 20 import android.app.ActivityThread; 21 import android.app.INotificationManager; 22 import android.app.usage.UsageStatsManagerInternal; 23 import android.content.ComponentName; 24 import android.content.ContentResolver; 25 import android.content.Context; 26 import android.content.Intent; 27 import android.content.pm.PackageManager; 28 import android.content.res.Configuration; 29 import android.content.res.Resources.Theme; 30 import android.os.BaseBundle; 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.RemoteException; 39 import android.os.ServiceManager; 40 import android.os.StrictMode; 41 import android.os.SystemClock; 42 import android.os.SystemProperties; 43 import android.os.Trace; 44 import android.os.UserHandle; 45 import android.os.storage.IMountService; 46 import android.util.DisplayMetrics; 47 import android.util.EventLog; 48 import android.util.Slog; 49 import android.view.WindowManager; 50 51 import com.android.internal.R; 52 import com.android.internal.os.BinderInternal; 53 import com.android.internal.os.SamplingProfilerIntegration; 54 import com.android.internal.os.ZygoteInit; 55 import com.android.internal.widget.ILockSettings; 56 import com.android.server.accessibility.AccessibilityManagerService; 57 import com.android.server.am.ActivityManagerService; 58 import com.android.server.audio.AudioService; 59 import com.android.server.camera.CameraService; 60 import com.android.server.clipboard.ClipboardService; 61 import com.android.server.connectivity.MetricsLoggerService; 62 import com.android.server.devicepolicy.DevicePolicyManagerService; 63 import com.android.server.display.DisplayManagerService; 64 import com.android.server.dreams.DreamManagerService; 65 import com.android.server.fingerprint.FingerprintService; 66 import com.android.server.hdmi.HdmiControlService; 67 import com.android.server.input.InputManagerService; 68 import com.android.server.job.JobSchedulerService; 69 import com.android.server.lights.LightsService; 70 import com.android.server.media.MediaResourceMonitorService; 71 import com.android.server.media.MediaRouterService; 72 import com.android.server.media.MediaSessionService; 73 import com.android.server.media.projection.MediaProjectionManagerService; 74 import com.android.server.net.NetworkPolicyManagerService; 75 import com.android.server.net.NetworkStatsService; 76 import com.android.server.notification.NotificationManagerService; 77 import com.android.server.os.SchedulingPolicyService; 78 import com.android.server.pm.BackgroundDexOptService; 79 import com.android.server.pm.Installer; 80 import com.android.server.pm.LauncherAppsService; 81 import com.android.server.pm.OtaDexoptService; 82 import com.android.server.pm.PackageManagerService; 83 import com.android.server.pm.ShortcutService; 84 import com.android.server.pm.UserManagerService; 85 import com.android.server.power.PowerManagerService; 86 import com.android.server.power.ShutdownThread; 87 import com.android.server.restrictions.RestrictionsManagerService; 88 import com.android.server.soundtrigger.SoundTriggerService; 89 import com.android.server.statusbar.StatusBarManagerService; 90 import com.android.server.storage.DeviceStorageMonitorService; 91 import com.android.server.telecom.TelecomLoaderService; 92 import com.android.server.trust.TrustManagerService; 93 import com.android.server.tv.TvRemoteService; 94 import com.android.server.tv.TvInputManagerService; 95 import com.android.server.twilight.TwilightService; 96 import com.android.server.usage.UsageStatsService; 97 import com.android.server.vr.VrManagerService; 98 import com.android.server.webkit.WebViewUpdateService; 99 import com.android.server.wm.WindowManagerService; 100 101 import dalvik.system.VMRuntime; 102 103 import java.io.File; 104 import java.io.IOException; 105 import java.util.Locale; 106 import java.util.Timer; 107 import java.util.TimerTask; 108 109 public final class SystemServer { 110 private static final String TAG = "SystemServer"; 111 112 private static final String ENCRYPTING_STATE = "trigger_restart_min_framework"; 113 private static final String ENCRYPTED_STATE = "1"; 114 115 private static final long SNAPSHOT_INTERVAL = 60 * 60 * 1000; // 1hr 116 117 // The earliest supported time. We pick one day into 1970, to 118 // give any timezone code room without going into negative time. 119 private static final long EARLIEST_SUPPORTED_TIME = 86400 * 1000; 120 121 /* 122 * Implementation class names. TODO: Move them to a codegen class or load 123 * them from the build system somehow. 124 */ 125 private static final String BACKUP_MANAGER_SERVICE_CLASS = 126 "com.android.server.backup.BackupManagerService$Lifecycle"; 127 private static final String APPWIDGET_SERVICE_CLASS = 128 "com.android.server.appwidget.AppWidgetService"; 129 private static final String VOICE_RECOGNITION_MANAGER_SERVICE_CLASS = 130 "com.android.server.voiceinteraction.VoiceInteractionManagerService"; 131 private static final String PRINT_MANAGER_SERVICE_CLASS = 132 "com.android.server.print.PrintManagerService"; 133 private static final String USB_SERVICE_CLASS = 134 "com.android.server.usb.UsbService$Lifecycle"; 135 private static final String MIDI_SERVICE_CLASS = 136 "com.android.server.midi.MidiService$Lifecycle"; 137 private static final String WIFI_SERVICE_CLASS = 138 "com.android.server.wifi.WifiService"; 139 private static final String WIFI_NAN_SERVICE_CLASS = 140 "com.android.server.wifi.nan.WifiNanService"; 141 private static final String WIFI_P2P_SERVICE_CLASS = 142 "com.android.server.wifi.p2p.WifiP2pService"; 143 private static final String ETHERNET_SERVICE_CLASS = 144 "com.android.server.ethernet.EthernetService"; 145 private static final String JOB_SCHEDULER_SERVICE_CLASS = 146 "com.android.server.job.JobSchedulerService"; 147 private static final String LOCK_SETTINGS_SERVICE_CLASS = 148 "com.android.server.LockSettingsService$Lifecycle"; 149 private static final String MOUNT_SERVICE_CLASS = 150 "com.android.server.MountService$Lifecycle"; 151 private static final String SEARCH_MANAGER_SERVICE_CLASS = 152 "com.android.server.search.SearchManagerService$Lifecycle"; 153 private static final String THERMAL_OBSERVER_CLASS = 154 "com.google.android.clockwork.ThermalObserver"; 155 private static final String WEAR_BLUETOOTH_SERVICE_CLASS = 156 "com.google.android.clockwork.bluetooth.WearBluetoothService"; 157 private static final String ACCOUNT_SERVICE_CLASS = 158 "com.android.server.accounts.AccountManagerService$Lifecycle"; 159 private static final String CONTENT_SERVICE_CLASS = 160 "com.android.server.content.ContentService$Lifecycle"; 161 private static final String WALLPAPER_SERVICE_CLASS = 162 "com.android.server.wallpaper.WallpaperManagerService$Lifecycle"; 163 164 private static final String PERSISTENT_DATA_BLOCK_PROP = "ro.frp.pst"; 165 166 private static final String UNCRYPT_PACKAGE_FILE = "/cache/recovery/uncrypt_file"; 167 private static final String BLOCK_MAP_FILE = "/cache/recovery/block.map"; 168 169 // maximum number of binder threads used for system_server 170 // will be higher than the system default 171 private static final int sMaxBinderThreads = 31; 172 173 /** 174 * Default theme used by the system context. This is used to style 175 * system-provided dialogs, such as the Power Off dialog, and other 176 * visual content. 177 */ 178 private static final int DEFAULT_SYSTEM_THEME = 179 com.android.internal.R.style.Theme_DeviceDefault_Light_DarkActionBar; 180 181 private final int mFactoryTestMode; 182 private Timer mProfilerSnapshotTimer; 183 184 private Context mSystemContext; 185 private SystemServiceManager mSystemServiceManager; 186 187 // TODO: remove all of these references by improving dependency resolution and boot phases 188 private PowerManagerService mPowerManagerService; 189 private ActivityManagerService mActivityManagerService; 190 private WebViewUpdateService mWebViewUpdateService; 191 private DisplayManagerService mDisplayManagerService; 192 private PackageManagerService mPackageManagerService; 193 private PackageManager mPackageManager; 194 private ContentResolver mContentResolver; 195 private EntropyMixer mEntropyMixer; 196 197 private boolean mOnlyCore; 198 private boolean mFirstBoot; 199 200 /** 201 * Start the sensor service. 202 */ startSensorService()203 private static native void startSensorService(); 204 205 /** 206 * The main entry point from zygote. 207 */ main(String[] args)208 public static void main(String[] args) { 209 new SystemServer().run(); 210 } 211 SystemServer()212 public SystemServer() { 213 // Check for factory test mode. 214 mFactoryTestMode = FactoryTest.getMode(); 215 } 216 run()217 private void run() { 218 try { 219 Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "InitBeforeStartServices"); 220 // If a device's clock is before 1970 (before 0), a lot of 221 // APIs crash dealing with negative numbers, notably 222 // java.io.File#setLastModified, so instead we fake it and 223 // hope that time from cell towers or NTP fixes it shortly. 224 if (System.currentTimeMillis() < EARLIEST_SUPPORTED_TIME) { 225 Slog.w(TAG, "System clock is before 1970; setting to 1970."); 226 SystemClock.setCurrentTimeMillis(EARLIEST_SUPPORTED_TIME); 227 } 228 229 // If the system has "persist.sys.language" and friends set, replace them with 230 // "persist.sys.locale". Note that the default locale at this point is calculated 231 // using the "-Duser.locale" command line flag. That flag is usually populated by 232 // AndroidRuntime using the same set of system properties, but only the system_server 233 // and system apps are allowed to set them. 234 // 235 // NOTE: Most changes made here will need an equivalent change to 236 // core/jni/AndroidRuntime.cpp 237 if (!SystemProperties.get("persist.sys.language").isEmpty()) { 238 final String languageTag = Locale.getDefault().toLanguageTag(); 239 240 SystemProperties.set("persist.sys.locale", languageTag); 241 SystemProperties.set("persist.sys.language", ""); 242 SystemProperties.set("persist.sys.country", ""); 243 SystemProperties.set("persist.sys.localevar", ""); 244 } 245 246 // Here we go! 247 Slog.i(TAG, "Entered the Android system server!"); 248 EventLog.writeEvent(EventLogTags.BOOT_PROGRESS_SYSTEM_RUN, SystemClock.uptimeMillis()); 249 250 // In case the runtime switched since last boot (such as when 251 // the old runtime was removed in an OTA), set the system 252 // property so that it is in sync. We can't do this in 253 // libnativehelper's JniInvocation::Init code where we already 254 // had to fallback to a different runtime because it is 255 // running as root and we need to be the system user to set 256 // the property. http://b/11463182 257 SystemProperties.set("persist.sys.dalvik.vm.lib.2", VMRuntime.getRuntime().vmLibrary()); 258 259 // Enable the sampling profiler. 260 if (SamplingProfilerIntegration.isEnabled()) { 261 SamplingProfilerIntegration.start(); 262 mProfilerSnapshotTimer = new Timer(); 263 mProfilerSnapshotTimer.schedule(new TimerTask() { 264 @Override 265 public void run() { 266 SamplingProfilerIntegration.writeSnapshot("system_server", null); 267 } 268 }, SNAPSHOT_INTERVAL, SNAPSHOT_INTERVAL); 269 } 270 271 // Mmmmmm... more memory! 272 VMRuntime.getRuntime().clearGrowthLimit(); 273 274 // The system server has to run all of the time, so it needs to be 275 // as efficient as possible with its memory usage. 276 VMRuntime.getRuntime().setTargetHeapUtilization(0.8f); 277 278 // Some devices rely on runtime fingerprint generation, so make sure 279 // we've defined it before booting further. 280 Build.ensureFingerprintProperty(); 281 282 // Within the system server, it is an error to access Environment paths without 283 // explicitly specifying a user. 284 Environment.setUserRequired(true); 285 286 // Within the system server, any incoming Bundles should be defused 287 // to avoid throwing BadParcelableException. 288 BaseBundle.setShouldDefuse(true); 289 290 // Ensure binder calls into the system always run at foreground priority. 291 BinderInternal.disableBackgroundScheduling(true); 292 293 // Increase the number of binder threads in system_server 294 BinderInternal.setMaxThreads(sMaxBinderThreads); 295 296 // Prepare the main looper thread (this thread). 297 android.os.Process.setThreadPriority( 298 android.os.Process.THREAD_PRIORITY_FOREGROUND); 299 android.os.Process.setCanSelfBackground(false); 300 Looper.prepareMainLooper(); 301 302 // Initialize native services. 303 System.loadLibrary("android_servers"); 304 305 // Check whether we failed to shut down last time we tried. 306 // This call may not return. 307 performPendingShutdown(); 308 309 // Initialize the system context. 310 createSystemContext(); 311 312 // Create the system service manager. 313 mSystemServiceManager = new SystemServiceManager(mSystemContext); 314 LocalServices.addService(SystemServiceManager.class, mSystemServiceManager); 315 } finally { 316 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER); 317 } 318 319 // Start services. 320 try { 321 Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "StartServices"); 322 startBootstrapServices(); 323 startCoreServices(); 324 startOtherServices(); 325 } catch (Throwable ex) { 326 Slog.e("System", "******************************************"); 327 Slog.e("System", "************ Failure starting system services", ex); 328 throw ex; 329 } finally { 330 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER); 331 } 332 333 // For debug builds, log event loop stalls to dropbox for analysis. 334 if (StrictMode.conditionallyEnableDebugLogging()) { 335 Slog.i(TAG, "Enabled StrictMode for system server main thread."); 336 } 337 338 // Loop forever. 339 Looper.loop(); 340 throw new RuntimeException("Main thread loop unexpectedly exited"); 341 } 342 reportWtf(String msg, Throwable e)343 private void reportWtf(String msg, Throwable e) { 344 Slog.w(TAG, "***********************************************"); 345 Slog.wtf(TAG, "BOOT FAILURE " + msg, e); 346 } 347 performPendingShutdown()348 private void performPendingShutdown() { 349 final String shutdownAction = SystemProperties.get( 350 ShutdownThread.SHUTDOWN_ACTION_PROPERTY, ""); 351 if (shutdownAction != null && shutdownAction.length() > 0) { 352 boolean reboot = (shutdownAction.charAt(0) == '1'); 353 354 final String reason; 355 if (shutdownAction.length() > 1) { 356 reason = shutdownAction.substring(1, shutdownAction.length()); 357 } else { 358 reason = null; 359 } 360 361 // If it's a pending reboot into recovery to apply an update, 362 // always make sure uncrypt gets executed properly when needed. 363 // If '/cache/recovery/block.map' hasn't been created, stop the 364 // reboot which will fail for sure, and get a chance to capture a 365 // bugreport when that's still feasible. (Bug: 26444951) 366 if (PowerManager.REBOOT_RECOVERY_UPDATE.equals(reason)) { 367 File packageFile = new File(UNCRYPT_PACKAGE_FILE); 368 if (packageFile.exists()) { 369 String filename = null; 370 try { 371 filename = FileUtils.readTextFile(packageFile, 0, null); 372 } catch (IOException e) { 373 Slog.e(TAG, "Error reading uncrypt package file", e); 374 } 375 376 if (filename != null && filename.startsWith("/data")) { 377 if (!new File(BLOCK_MAP_FILE).exists()) { 378 Slog.e(TAG, "Can't find block map file, uncrypt failed or " + 379 "unexpected runtime restart?"); 380 return; 381 } 382 } 383 } 384 } 385 ShutdownThread.rebootOrShutdown(null, reboot, reason); 386 } 387 } 388 createSystemContext()389 private void createSystemContext() { 390 ActivityThread activityThread = ActivityThread.systemMain(); 391 mSystemContext = activityThread.getSystemContext(); 392 mSystemContext.setTheme(DEFAULT_SYSTEM_THEME); 393 } 394 395 /** 396 * Starts the small tangle of critical services that are needed to get 397 * the system off the ground. These services have complex mutual dependencies 398 * which is why we initialize them all in one place here. Unless your service 399 * is also entwined in these dependencies, it should be initialized in one of 400 * the other functions. 401 */ startBootstrapServices()402 private void startBootstrapServices() { 403 // Wait for installd to finish starting up so that it has a chance to 404 // create critical directories such as /data/user with the appropriate 405 // permissions. We need this to complete before we initialize other services. 406 Installer installer = mSystemServiceManager.startService(Installer.class); 407 408 // Activity manager runs the show. 409 mActivityManagerService = mSystemServiceManager.startService( 410 ActivityManagerService.Lifecycle.class).getService(); 411 mActivityManagerService.setSystemServiceManager(mSystemServiceManager); 412 mActivityManagerService.setInstaller(installer); 413 414 // Power manager needs to be started early because other services need it. 415 // Native daemons may be watching for it to be registered so it must be ready 416 // to handle incoming binder calls immediately (including being able to verify 417 // the permissions for those calls). 418 mPowerManagerService = mSystemServiceManager.startService(PowerManagerService.class); 419 420 // Now that the power manager has been started, let the activity manager 421 // initialize power management features. 422 Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "InitPowerManagement"); 423 mActivityManagerService.initPowerManagement(); 424 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER); 425 426 // Manages LEDs and display backlight so we need it to bring up the display. 427 mSystemServiceManager.startService(LightsService.class); 428 429 // Display manager is needed to provide display metrics before package manager 430 // starts up. 431 mDisplayManagerService = mSystemServiceManager.startService(DisplayManagerService.class); 432 433 // We need the default display before we can initialize the package manager. 434 mSystemServiceManager.startBootPhase(SystemService.PHASE_WAIT_FOR_DEFAULT_DISPLAY); 435 436 // Only run "core" apps if we're encrypting the device. 437 String cryptState = SystemProperties.get("vold.decrypt"); 438 if (ENCRYPTING_STATE.equals(cryptState)) { 439 Slog.w(TAG, "Detected encryption in progress - only parsing core apps"); 440 mOnlyCore = true; 441 } else if (ENCRYPTED_STATE.equals(cryptState)) { 442 Slog.w(TAG, "Device encrypted - only parsing core apps"); 443 mOnlyCore = true; 444 } 445 446 // Start the package manager. 447 traceBeginAndSlog("StartPackageManagerService"); 448 mPackageManagerService = PackageManagerService.main(mSystemContext, installer, 449 mFactoryTestMode != FactoryTest.FACTORY_TEST_OFF, mOnlyCore); 450 mFirstBoot = mPackageManagerService.isFirstBoot(); 451 mPackageManager = mSystemContext.getPackageManager(); 452 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER); 453 454 // Manages A/B OTA dexopting. This is a bootstrap service as we need it to rename 455 // A/B artifacts after boot, before anything else might touch/need them. 456 // Note: this isn't needed during decryption (we don't have /data anyways). 457 if (!mOnlyCore) { 458 boolean disableOtaDexopt = SystemProperties.getBoolean("config.disable_otadexopt", 459 false); 460 if (!disableOtaDexopt) { 461 traceBeginAndSlog("StartOtaDexOptService"); 462 try { 463 OtaDexoptService.main(mSystemContext, mPackageManagerService); 464 } catch (Throwable e) { 465 reportWtf("starting OtaDexOptService", e); 466 } finally { 467 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER); 468 } 469 } 470 } 471 472 traceBeginAndSlog("StartUserManagerService"); 473 mSystemServiceManager.startService(UserManagerService.LifeCycle.class); 474 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER); 475 476 // Initialize attribute cache used to cache resources from packages. 477 AttributeCache.init(mSystemContext); 478 479 // Set up the Application instance for the system process and get started. 480 mActivityManagerService.setSystemProcess(); 481 482 // The sensor service needs access to package manager service, app ops 483 // service, and permissions service, therefore we start it after them. 484 startSensorService(); 485 } 486 487 /** 488 * Starts some essential services that are not tangled up in the bootstrap process. 489 */ startCoreServices()490 private void startCoreServices() { 491 // Tracks the battery level. Requires LightService. 492 mSystemServiceManager.startService(BatteryService.class); 493 494 // Tracks application usage stats. 495 mSystemServiceManager.startService(UsageStatsService.class); 496 mActivityManagerService.setUsageStatsManager( 497 LocalServices.getService(UsageStatsManagerInternal.class)); 498 499 // Tracks whether the updatable WebView is in a ready state and watches for update installs. 500 mWebViewUpdateService = mSystemServiceManager.startService(WebViewUpdateService.class); 501 } 502 503 /** 504 * Starts a miscellaneous grab bag of stuff that has yet to be refactored 505 * and organized. 506 */ startOtherServices()507 private void startOtherServices() { 508 final Context context = mSystemContext; 509 VibratorService vibrator = null; 510 IMountService mountService = null; 511 NetworkManagementService networkManagement = null; 512 NetworkStatsService networkStats = null; 513 NetworkPolicyManagerService networkPolicy = null; 514 ConnectivityService connectivity = null; 515 NetworkScoreService networkScore = null; 516 NsdService serviceDiscovery= null; 517 WindowManagerService wm = null; 518 SerialService serial = null; 519 NetworkTimeUpdateService networkTimeUpdater = null; 520 CommonTimeManagementService commonTimeMgmtService = null; 521 InputManagerService inputManager = null; 522 TelephonyRegistry telephonyRegistry = null; 523 ConsumerIrService consumerIr = null; 524 MmsServiceBroker mmsService = null; 525 HardwarePropertiesManagerService hardwarePropertiesService = null; 526 527 boolean disableStorage = SystemProperties.getBoolean("config.disable_storage", false); 528 boolean disableBluetooth = SystemProperties.getBoolean("config.disable_bluetooth", false); 529 boolean disableLocation = SystemProperties.getBoolean("config.disable_location", false); 530 boolean disableSystemUI = SystemProperties.getBoolean("config.disable_systemui", false); 531 boolean disableNonCoreServices = SystemProperties.getBoolean("config.disable_noncore", false); 532 boolean disableNetwork = SystemProperties.getBoolean("config.disable_network", false); 533 boolean disableNetworkTime = SystemProperties.getBoolean("config.disable_networktime", false); 534 boolean disableRtt = SystemProperties.getBoolean("config.disable_rtt", false); 535 boolean disableMediaProjection = SystemProperties.getBoolean("config.disable_mediaproj", 536 false); 537 boolean disableSerial = SystemProperties.getBoolean("config.disable_serial", false); 538 boolean disableSearchManager = SystemProperties.getBoolean("config.disable_searchmanager", 539 false); 540 boolean disableTrustManager = SystemProperties.getBoolean("config.disable_trustmanager", 541 false); 542 boolean disableTextServices = SystemProperties.getBoolean("config.disable_textservices", false); 543 boolean disableSamplingProfiler = SystemProperties.getBoolean("config.disable_samplingprof", 544 false); 545 boolean isEmulator = SystemProperties.get("ro.kernel.qemu").equals("1"); 546 547 try { 548 Slog.i(TAG, "Reading configuration..."); 549 SystemConfig.getInstance(); 550 551 traceBeginAndSlog("StartSchedulingPolicyService"); 552 ServiceManager.addService("scheduling_policy", new SchedulingPolicyService()); 553 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER); 554 555 mSystemServiceManager.startService(TelecomLoaderService.class); 556 557 traceBeginAndSlog("StartTelephonyRegistry"); 558 telephonyRegistry = new TelephonyRegistry(context); 559 ServiceManager.addService("telephony.registry", telephonyRegistry); 560 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER); 561 562 traceBeginAndSlog("StartEntropyMixer"); 563 mEntropyMixer = new EntropyMixer(context); 564 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER); 565 566 mContentResolver = context.getContentResolver(); 567 568 Slog.i(TAG, "Camera Service"); 569 mSystemServiceManager.startService(CameraService.class); 570 571 // The AccountManager must come before the ContentService 572 traceBeginAndSlog("StartAccountManagerService"); 573 mSystemServiceManager.startService(ACCOUNT_SERVICE_CLASS); 574 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER); 575 576 traceBeginAndSlog("StartContentService"); 577 mSystemServiceManager.startService(CONTENT_SERVICE_CLASS); 578 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER); 579 580 traceBeginAndSlog("InstallSystemProviders"); 581 mActivityManagerService.installSystemProviders(); 582 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER); 583 584 traceBeginAndSlog("StartVibratorService"); 585 vibrator = new VibratorService(context); 586 ServiceManager.addService("vibrator", vibrator); 587 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER); 588 589 traceBeginAndSlog("StartConsumerIrService"); 590 consumerIr = new ConsumerIrService(context); 591 ServiceManager.addService(Context.CONSUMER_IR_SERVICE, consumerIr); 592 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER); 593 594 traceBeginAndSlog("StartAlarmManagerService"); 595 mSystemServiceManager.startService(AlarmManagerService.class); 596 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER); 597 598 traceBeginAndSlog("InitWatchdog"); 599 final Watchdog watchdog = Watchdog.getInstance(); 600 watchdog.init(context, mActivityManagerService); 601 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER); 602 603 traceBeginAndSlog("StartInputManagerService"); 604 inputManager = new InputManagerService(context); 605 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER); 606 607 traceBeginAndSlog("StartWindowManagerService"); 608 wm = WindowManagerService.main(context, inputManager, 609 mFactoryTestMode != FactoryTest.FACTORY_TEST_LOW_LEVEL, 610 !mFirstBoot, mOnlyCore); 611 ServiceManager.addService(Context.WINDOW_SERVICE, wm); 612 ServiceManager.addService(Context.INPUT_SERVICE, inputManager); 613 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER); 614 615 traceBeginAndSlog("StartVrManagerService"); 616 mSystemServiceManager.startService(VrManagerService.class); 617 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER); 618 619 mActivityManagerService.setWindowManager(wm); 620 621 inputManager.setWindowManagerCallbacks(wm.getInputMonitor()); 622 inputManager.start(); 623 624 // TODO: Use service dependencies instead. 625 mDisplayManagerService.windowManagerAndInputReady(); 626 627 // Skip Bluetooth if we have an emulator kernel 628 // TODO: Use a more reliable check to see if this product should 629 // support Bluetooth - see bug 988521 630 if (isEmulator) { 631 Slog.i(TAG, "No Bluetooth Service (emulator)"); 632 } else if (mFactoryTestMode == FactoryTest.FACTORY_TEST_LOW_LEVEL) { 633 Slog.i(TAG, "No Bluetooth Service (factory test)"); 634 } else if (!context.getPackageManager().hasSystemFeature 635 (PackageManager.FEATURE_BLUETOOTH)) { 636 Slog.i(TAG, "No Bluetooth Service (Bluetooth Hardware Not Present)"); 637 } else if (disableBluetooth) { 638 Slog.i(TAG, "Bluetooth Service disabled by config"); 639 } else { 640 mSystemServiceManager.startService(BluetoothService.class); 641 } 642 643 traceBeginAndSlog("ConnectivityMetricsLoggerService"); 644 mSystemServiceManager.startService(MetricsLoggerService.class); 645 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER); 646 647 traceBeginAndSlog("PinnerService"); 648 mSystemServiceManager.startService(PinnerService.class); 649 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER); 650 } catch (RuntimeException e) { 651 Slog.e("System", "******************************************"); 652 Slog.e("System", "************ Failure starting core service", e); 653 } 654 655 StatusBarManagerService statusBar = null; 656 INotificationManager notification = null; 657 LocationManagerService location = null; 658 CountryDetectorService countryDetector = null; 659 ILockSettings lockSettings = null; 660 AssetAtlasService atlas = null; 661 MediaRouterService mediaRouter = null; 662 663 // Bring up services needed for UI. 664 if (mFactoryTestMode != FactoryTest.FACTORY_TEST_LOW_LEVEL) { 665 mSystemServiceManager.startService(InputMethodManagerService.Lifecycle.class); 666 667 traceBeginAndSlog("StartAccessibilityManagerService"); 668 try { 669 ServiceManager.addService(Context.ACCESSIBILITY_SERVICE, 670 new AccessibilityManagerService(context)); 671 } catch (Throwable e) { 672 reportWtf("starting Accessibility Manager", e); 673 } 674 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER); 675 } 676 677 try { 678 wm.displayReady(); 679 } catch (Throwable e) { 680 reportWtf("making display ready", e); 681 } 682 683 if (mFactoryTestMode != FactoryTest.FACTORY_TEST_LOW_LEVEL) { 684 if (!disableStorage && 685 !"0".equals(SystemProperties.get("system_init.startmountservice"))) { 686 try { 687 /* 688 * NotificationManagerService is dependant on MountService, 689 * (for media / usb notifications) so we must start MountService first. 690 */ 691 mSystemServiceManager.startService(MOUNT_SERVICE_CLASS); 692 mountService = IMountService.Stub.asInterface( 693 ServiceManager.getService("mount")); 694 } catch (Throwable e) { 695 reportWtf("starting Mount Service", e); 696 } 697 } 698 } 699 700 // We start this here so that we update our configuration to set watch or television 701 // as appropriate. 702 mSystemServiceManager.startService(UiModeManagerService.class); 703 704 if (!mOnlyCore) { 705 Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "UpdatePackagesIfNeeded"); 706 try { 707 mPackageManagerService.updatePackagesIfNeeded(); 708 } catch (Throwable e) { 709 reportWtf("update packages", e); 710 } 711 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER); 712 } 713 714 Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "PerformFstrimIfNeeded"); 715 try { 716 mPackageManagerService.performFstrimIfNeeded(); 717 } catch (Throwable e) { 718 reportWtf("performing fstrim", e); 719 } 720 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER); 721 722 try { 723 ActivityManagerNative.getDefault().showBootMessage( 724 context.getResources().getText( 725 com.android.internal.R.string.android_upgrading_starting_apps), 726 false); 727 } catch (RemoteException e) { 728 } 729 730 if (mFactoryTestMode != FactoryTest.FACTORY_TEST_LOW_LEVEL) { 731 if (!disableNonCoreServices) { 732 traceBeginAndSlog("StartLockSettingsService"); 733 try { 734 mSystemServiceManager.startService(LOCK_SETTINGS_SERVICE_CLASS); 735 lockSettings = ILockSettings.Stub.asInterface( 736 ServiceManager.getService("lock_settings")); 737 } catch (Throwable e) { 738 reportWtf("starting LockSettingsService service", e); 739 } 740 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER); 741 742 if (!SystemProperties.get(PERSISTENT_DATA_BLOCK_PROP).equals("")) { 743 mSystemServiceManager.startService(PersistentDataBlockService.class); 744 } 745 746 mSystemServiceManager.startService(DeviceIdleController.class); 747 748 // Always start the Device Policy Manager, so that the API is compatible with 749 // API8. 750 mSystemServiceManager.startService(DevicePolicyManagerService.Lifecycle.class); 751 } 752 753 if (!disableSystemUI) { 754 traceBeginAndSlog("StartStatusBarManagerService"); 755 try { 756 statusBar = new StatusBarManagerService(context, wm); 757 ServiceManager.addService(Context.STATUS_BAR_SERVICE, statusBar); 758 } catch (Throwable e) { 759 reportWtf("starting StatusBarManagerService", e); 760 } 761 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER); 762 } 763 764 if (!disableNonCoreServices) { 765 traceBeginAndSlog("StartClipboardService"); 766 try { 767 ServiceManager.addService(Context.CLIPBOARD_SERVICE, 768 new ClipboardService(context)); 769 } catch (Throwable e) { 770 reportWtf("starting Clipboard Service", e); 771 } 772 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER); 773 } 774 775 if (!disableNetwork) { 776 traceBeginAndSlog("StartNetworkManagementService"); 777 try { 778 networkManagement = NetworkManagementService.create(context); 779 ServiceManager.addService(Context.NETWORKMANAGEMENT_SERVICE, networkManagement); 780 } catch (Throwable e) { 781 reportWtf("starting NetworkManagement Service", e); 782 } 783 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER); 784 } 785 786 if (!disableNonCoreServices && !disableTextServices) { 787 mSystemServiceManager.startService(TextServicesManagerService.Lifecycle.class); 788 } 789 790 if (!disableNetwork) { 791 traceBeginAndSlog("StartNetworkScoreService"); 792 try { 793 networkScore = new NetworkScoreService(context); 794 ServiceManager.addService(Context.NETWORK_SCORE_SERVICE, networkScore); 795 } catch (Throwable e) { 796 reportWtf("starting Network Score Service", e); 797 } 798 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER); 799 800 traceBeginAndSlog("StartNetworkStatsService"); 801 try { 802 networkStats = NetworkStatsService.create(context, networkManagement); 803 ServiceManager.addService(Context.NETWORK_STATS_SERVICE, networkStats); 804 } catch (Throwable e) { 805 reportWtf("starting NetworkStats Service", e); 806 } 807 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER); 808 809 traceBeginAndSlog("StartNetworkPolicyManagerService"); 810 try { 811 networkPolicy = new NetworkPolicyManagerService( 812 context, mActivityManagerService, 813 (IPowerManager)ServiceManager.getService(Context.POWER_SERVICE), 814 networkStats, networkManagement); 815 ServiceManager.addService(Context.NETWORK_POLICY_SERVICE, networkPolicy); 816 } catch (Throwable e) { 817 reportWtf("starting NetworkPolicy Service", e); 818 } 819 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER); 820 821 if (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_WIFI_NAN)) { 822 mSystemServiceManager.startService(WIFI_NAN_SERVICE_CLASS); 823 } else { 824 Slog.i(TAG, "No Wi-Fi NAN Service (NAN support Not Present)"); 825 } 826 mSystemServiceManager.startService(WIFI_P2P_SERVICE_CLASS); 827 mSystemServiceManager.startService(WIFI_SERVICE_CLASS); 828 mSystemServiceManager.startService( 829 "com.android.server.wifi.scanner.WifiScanningService"); 830 831 if (!disableRtt) { 832 mSystemServiceManager.startService("com.android.server.wifi.RttService"); 833 } 834 835 if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_ETHERNET) || 836 mPackageManager.hasSystemFeature(PackageManager.FEATURE_USB_HOST)) { 837 mSystemServiceManager.startService(ETHERNET_SERVICE_CLASS); 838 } 839 840 traceBeginAndSlog("StartConnectivityService"); 841 try { 842 connectivity = new ConnectivityService( 843 context, networkManagement, networkStats, networkPolicy); 844 ServiceManager.addService(Context.CONNECTIVITY_SERVICE, connectivity); 845 networkStats.bindConnectivityManager(connectivity); 846 networkPolicy.bindConnectivityManager(connectivity); 847 } catch (Throwable e) { 848 reportWtf("starting Connectivity Service", e); 849 } 850 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER); 851 852 traceBeginAndSlog("StartNsdService"); 853 try { 854 serviceDiscovery = NsdService.create(context); 855 ServiceManager.addService( 856 Context.NSD_SERVICE, serviceDiscovery); 857 } catch (Throwable e) { 858 reportWtf("starting Service Discovery Service", e); 859 } 860 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER); 861 } 862 863 if (!disableNonCoreServices) { 864 traceBeginAndSlog("StartUpdateLockService"); 865 try { 866 ServiceManager.addService(Context.UPDATE_LOCK_SERVICE, 867 new UpdateLockService(context)); 868 } catch (Throwable e) { 869 reportWtf("starting UpdateLockService", e); 870 } 871 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER); 872 } 873 874 if (!disableNonCoreServices) { 875 mSystemServiceManager.startService(RecoverySystemService.class); 876 } 877 878 /* 879 * MountService has a few dependencies: Notification Manager and 880 * AppWidget Provider. Make sure MountService is completely started 881 * first before continuing. 882 */ 883 if (mountService != null && !mOnlyCore) { 884 Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "WaitForAsecScan"); 885 try { 886 mountService.waitForAsecScan(); 887 } catch (RemoteException ignored) { 888 } 889 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER); 890 } 891 892 mSystemServiceManager.startService(NotificationManagerService.class); 893 notification = INotificationManager.Stub.asInterface( 894 ServiceManager.getService(Context.NOTIFICATION_SERVICE)); 895 networkPolicy.bindNotificationManager(notification); 896 897 mSystemServiceManager.startService(DeviceStorageMonitorService.class); 898 899 if (!disableLocation) { 900 traceBeginAndSlog("StartLocationManagerService"); 901 try { 902 location = new LocationManagerService(context); 903 ServiceManager.addService(Context.LOCATION_SERVICE, location); 904 } catch (Throwable e) { 905 reportWtf("starting Location Manager", e); 906 } 907 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER); 908 909 traceBeginAndSlog("StartCountryDetectorService"); 910 try { 911 countryDetector = new CountryDetectorService(context); 912 ServiceManager.addService(Context.COUNTRY_DETECTOR, countryDetector); 913 } catch (Throwable e) { 914 reportWtf("starting Country Detector", e); 915 } 916 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER); 917 } 918 919 if (!disableNonCoreServices && !disableSearchManager) { 920 traceBeginAndSlog("StartSearchManagerService"); 921 try { 922 mSystemServiceManager.startService(SEARCH_MANAGER_SERVICE_CLASS); 923 } catch (Throwable e) { 924 reportWtf("starting Search Service", e); 925 } 926 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER); 927 } 928 929 mSystemServiceManager.startService(DropBoxManagerService.class); 930 931 if (!disableNonCoreServices && context.getResources().getBoolean( 932 R.bool.config_enableWallpaperService)) { 933 traceBeginAndSlog("StartWallpaperManagerService"); 934 mSystemServiceManager.startService(WALLPAPER_SERVICE_CLASS); 935 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER); 936 } 937 938 traceBeginAndSlog("StartAudioService"); 939 mSystemServiceManager.startService(AudioService.Lifecycle.class); 940 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER); 941 942 if (!disableNonCoreServices) { 943 mSystemServiceManager.startService(DockObserver.class); 944 945 if (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_WATCH)) { 946 mSystemServiceManager.startService(THERMAL_OBSERVER_CLASS); 947 } 948 } 949 950 traceBeginAndSlog("StartWiredAccessoryManager"); 951 try { 952 // Listen for wired headset changes 953 inputManager.setWiredAccessoryCallbacks( 954 new WiredAccessoryManager(context, inputManager)); 955 } catch (Throwable e) { 956 reportWtf("starting WiredAccessoryManager", e); 957 } 958 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER); 959 960 if (!disableNonCoreServices) { 961 if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_MIDI)) { 962 // Start MIDI Manager service 963 mSystemServiceManager.startService(MIDI_SERVICE_CLASS); 964 } 965 966 if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_USB_HOST) 967 || mPackageManager.hasSystemFeature( 968 PackageManager.FEATURE_USB_ACCESSORY)) { 969 // Manage USB host and device support 970 Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "StartUsbService"); 971 mSystemServiceManager.startService(USB_SERVICE_CLASS); 972 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER); 973 } 974 975 if (!disableSerial) { 976 traceBeginAndSlog("StartSerialService"); 977 try { 978 // Serial port support 979 serial = new SerialService(context); 980 ServiceManager.addService(Context.SERIAL_SERVICE, serial); 981 } catch (Throwable e) { 982 Slog.e(TAG, "Failure starting SerialService", e); 983 } 984 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER); 985 } 986 987 Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, 988 "StartHardwarePropertiesManagerService"); 989 try { 990 hardwarePropertiesService = new HardwarePropertiesManagerService(context); 991 ServiceManager.addService(Context.HARDWARE_PROPERTIES_SERVICE, 992 hardwarePropertiesService); 993 } catch (Throwable e) { 994 Slog.e(TAG, "Failure starting HardwarePropertiesManagerService", e); 995 } 996 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER); 997 } 998 999 mSystemServiceManager.startService(TwilightService.class); 1000 1001 mSystemServiceManager.startService(JobSchedulerService.class); 1002 1003 mSystemServiceManager.startService(SoundTriggerService.class); 1004 1005 if (!disableNonCoreServices) { 1006 if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_BACKUP)) { 1007 mSystemServiceManager.startService(BACKUP_MANAGER_SERVICE_CLASS); 1008 } 1009 1010 if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_APP_WIDGETS) 1011 || context.getResources().getBoolean(R.bool.config_enableAppWidgetService)) { 1012 mSystemServiceManager.startService(APPWIDGET_SERVICE_CLASS); 1013 } 1014 1015 if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_VOICE_RECOGNIZERS)) { 1016 mSystemServiceManager.startService(VOICE_RECOGNITION_MANAGER_SERVICE_CLASS); 1017 } 1018 1019 if (GestureLauncherService.isGestureLauncherEnabled(context.getResources())) { 1020 Slog.i(TAG, "Gesture Launcher Service"); 1021 mSystemServiceManager.startService(GestureLauncherService.class); 1022 } 1023 mSystemServiceManager.startService(SensorNotificationService.class); 1024 mSystemServiceManager.startService(ContextHubSystemService.class); 1025 } 1026 1027 traceBeginAndSlog("StartDiskStatsService"); 1028 try { 1029 ServiceManager.addService("diskstats", new DiskStatsService(context)); 1030 } catch (Throwable e) { 1031 reportWtf("starting DiskStats Service", e); 1032 } 1033 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER); 1034 1035 if (!disableSamplingProfiler) { 1036 traceBeginAndSlog("StartSamplingProfilerService"); 1037 try { 1038 // need to add this service even if SamplingProfilerIntegration.isEnabled() 1039 // is false, because it is this service that detects system property change and 1040 // turns on SamplingProfilerIntegration. Plus, when sampling profiler doesn't work, 1041 // there is little overhead for running this service. 1042 ServiceManager.addService("samplingprofiler", 1043 new SamplingProfilerService(context)); 1044 } catch (Throwable e) { 1045 reportWtf("starting SamplingProfiler Service", e); 1046 } 1047 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER); 1048 } 1049 1050 if (!disableNetwork && !disableNetworkTime) { 1051 traceBeginAndSlog("StartNetworkTimeUpdateService"); 1052 try { 1053 networkTimeUpdater = new NetworkTimeUpdateService(context); 1054 ServiceManager.addService("network_time_update_service", networkTimeUpdater); 1055 } catch (Throwable e) { 1056 reportWtf("starting NetworkTimeUpdate service", e); 1057 } 1058 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER); 1059 } 1060 1061 traceBeginAndSlog("StartCommonTimeManagementService"); 1062 try { 1063 commonTimeMgmtService = new CommonTimeManagementService(context); 1064 ServiceManager.addService("commontime_management", commonTimeMgmtService); 1065 } catch (Throwable e) { 1066 reportWtf("starting CommonTimeManagementService service", e); 1067 } 1068 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER); 1069 1070 if (!disableNetwork) { 1071 traceBeginAndSlog("CertBlacklister"); 1072 try { 1073 CertBlacklister blacklister = new CertBlacklister(context); 1074 } catch (Throwable e) { 1075 reportWtf("starting CertBlacklister", e); 1076 } 1077 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER); 1078 } 1079 1080 if (!disableNonCoreServices) { 1081 // Dreams (interactive idle-time views, a/k/a screen savers, and doze mode) 1082 mSystemServiceManager.startService(DreamManagerService.class); 1083 } 1084 1085 if (!disableNonCoreServices && ZygoteInit.PRELOAD_RESOURCES) { 1086 traceBeginAndSlog("StartAssetAtlasService"); 1087 try { 1088 atlas = new AssetAtlasService(context); 1089 ServiceManager.addService(AssetAtlasService.ASSET_ATLAS_SERVICE, atlas); 1090 } catch (Throwable e) { 1091 reportWtf("starting AssetAtlasService", e); 1092 } 1093 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER); 1094 } 1095 1096 if (!disableNonCoreServices) { 1097 ServiceManager.addService(GraphicsStatsService.GRAPHICS_STATS_SERVICE, 1098 new GraphicsStatsService(context)); 1099 } 1100 1101 if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_PRINTING)) { 1102 mSystemServiceManager.startService(PRINT_MANAGER_SERVICE_CLASS); 1103 } 1104 1105 mSystemServiceManager.startService(RestrictionsManagerService.class); 1106 1107 mSystemServiceManager.startService(MediaSessionService.class); 1108 1109 if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_HDMI_CEC)) { 1110 mSystemServiceManager.startService(HdmiControlService.class); 1111 } 1112 1113 if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_LIVE_TV)) { 1114 mSystemServiceManager.startService(TvInputManagerService.class); 1115 } 1116 1117 if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_PICTURE_IN_PICTURE)) { 1118 mSystemServiceManager.startService(MediaResourceMonitorService.class); 1119 } 1120 1121 if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_LEANBACK)) { 1122 mSystemServiceManager.startService(TvRemoteService.class); 1123 } 1124 1125 if (!disableNonCoreServices) { 1126 traceBeginAndSlog("StartMediaRouterService"); 1127 try { 1128 mediaRouter = new MediaRouterService(context); 1129 ServiceManager.addService(Context.MEDIA_ROUTER_SERVICE, mediaRouter); 1130 } catch (Throwable e) { 1131 reportWtf("starting MediaRouterService", e); 1132 } 1133 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER); 1134 1135 if (!disableTrustManager) { 1136 mSystemServiceManager.startService(TrustManagerService.class); 1137 } 1138 1139 if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_FINGERPRINT)) { 1140 mSystemServiceManager.startService(FingerprintService.class); 1141 } 1142 1143 traceBeginAndSlog("StartBackgroundDexOptService"); 1144 try { 1145 BackgroundDexOptService.schedule(context); 1146 } catch (Throwable e) { 1147 reportWtf("starting BackgroundDexOptService", e); 1148 } 1149 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER); 1150 } 1151 // LauncherAppsService uses ShortcutService. 1152 mSystemServiceManager.startService(ShortcutService.Lifecycle.class); 1153 1154 mSystemServiceManager.startService(LauncherAppsService.class); 1155 } 1156 1157 if (!disableNonCoreServices && !disableMediaProjection) { 1158 mSystemServiceManager.startService(MediaProjectionManagerService.class); 1159 } 1160 1161 if (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_WATCH)) { 1162 mSystemServiceManager.startService(WEAR_BLUETOOTH_SERVICE_CLASS); 1163 } 1164 1165 // Before things start rolling, be sure we have decided whether 1166 // we are in safe mode. 1167 final boolean safeMode = wm.detectSafeMode(); 1168 if (safeMode) { 1169 mActivityManagerService.enterSafeMode(); 1170 // Disable the JIT for the system_server process 1171 VMRuntime.getRuntime().disableJitCompilation(); 1172 } else { 1173 // Enable the JIT for the system_server process 1174 VMRuntime.getRuntime().startJitCompilation(); 1175 } 1176 1177 // MMS service broker 1178 mmsService = mSystemServiceManager.startService(MmsServiceBroker.class); 1179 1180 // It is now time to start up the app processes... 1181 1182 Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "MakeVibratorServiceReady"); 1183 try { 1184 vibrator.systemReady(); 1185 } catch (Throwable e) { 1186 reportWtf("making Vibrator Service ready", e); 1187 } 1188 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER); 1189 1190 Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "MakeLockSettingsServiceReady"); 1191 if (lockSettings != null) { 1192 try { 1193 lockSettings.systemReady(); 1194 } catch (Throwable e) { 1195 reportWtf("making Lock Settings Service ready", e); 1196 } 1197 } 1198 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER); 1199 1200 // Needed by DevicePolicyManager for initialization 1201 mSystemServiceManager.startBootPhase(SystemService.PHASE_LOCK_SETTINGS_READY); 1202 1203 mSystemServiceManager.startBootPhase(SystemService.PHASE_SYSTEM_SERVICES_READY); 1204 1205 Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "MakeWindowManagerServiceReady"); 1206 try { 1207 wm.systemReady(); 1208 } catch (Throwable e) { 1209 reportWtf("making Window Manager Service ready", e); 1210 } 1211 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER); 1212 1213 if (safeMode) { 1214 mActivityManagerService.showSafeModeOverlay(); 1215 } 1216 1217 // Update the configuration for this context by hand, because we're going 1218 // to start using it before the config change done in wm.systemReady() will 1219 // propagate to it. 1220 Configuration config = wm.computeNewConfiguration(); 1221 DisplayMetrics metrics = new DisplayMetrics(); 1222 WindowManager w = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE); 1223 w.getDefaultDisplay().getMetrics(metrics); 1224 context.getResources().updateConfiguration(config, metrics); 1225 1226 // The system context's theme may be configuration-dependent. 1227 final Theme systemTheme = context.getTheme(); 1228 if (systemTheme.getChangingConfigurations() != 0) { 1229 systemTheme.rebase(); 1230 } 1231 1232 Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "MakePowerManagerServiceReady"); 1233 try { 1234 // TODO: use boot phase 1235 mPowerManagerService.systemReady(mActivityManagerService.getAppOpsService()); 1236 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER); 1237 } catch (Throwable e) { 1238 reportWtf("making Power Manager Service ready", e); 1239 } 1240 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER); 1241 1242 Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "MakePackageManagerServiceReady"); 1243 try { 1244 mPackageManagerService.systemReady(); 1245 } catch (Throwable e) { 1246 reportWtf("making Package Manager Service ready", e); 1247 } 1248 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER); 1249 1250 Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "MakeDisplayManagerServiceReady"); 1251 try { 1252 // TODO: use boot phase and communicate these flags some other way 1253 mDisplayManagerService.systemReady(safeMode, mOnlyCore); 1254 } catch (Throwable e) { 1255 reportWtf("making Display Manager Service ready", e); 1256 } 1257 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER); 1258 1259 // These are needed to propagate to the runnable below. 1260 final NetworkManagementService networkManagementF = networkManagement; 1261 final NetworkStatsService networkStatsF = networkStats; 1262 final NetworkPolicyManagerService networkPolicyF = networkPolicy; 1263 final ConnectivityService connectivityF = connectivity; 1264 final NetworkScoreService networkScoreF = networkScore; 1265 final LocationManagerService locationF = location; 1266 final CountryDetectorService countryDetectorF = countryDetector; 1267 final NetworkTimeUpdateService networkTimeUpdaterF = networkTimeUpdater; 1268 final CommonTimeManagementService commonTimeMgmtServiceF = commonTimeMgmtService; 1269 final AssetAtlasService atlasF = atlas; 1270 final InputManagerService inputManagerF = inputManager; 1271 final TelephonyRegistry telephonyRegistryF = telephonyRegistry; 1272 final MediaRouterService mediaRouterF = mediaRouter; 1273 final MmsServiceBroker mmsServiceF = mmsService; 1274 1275 // We now tell the activity manager it is okay to run third party 1276 // code. It will call back into us once it has gotten to the state 1277 // where third party code can really run (but before it has actually 1278 // started launching the initial applications), for us to complete our 1279 // initialization. 1280 mActivityManagerService.systemReady(new Runnable() { 1281 @Override 1282 public void run() { 1283 Slog.i(TAG, "Making services ready"); 1284 mSystemServiceManager.startBootPhase( 1285 SystemService.PHASE_ACTIVITY_MANAGER_READY); 1286 Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "PhaseActivityManagerReady"); 1287 1288 Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "StartObservingNativeCrashes"); 1289 try { 1290 mActivityManagerService.startObservingNativeCrashes(); 1291 } catch (Throwable e) { 1292 reportWtf("observing native crashes", e); 1293 } 1294 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER); 1295 1296 if (!mOnlyCore) { 1297 Slog.i(TAG, "WebViewFactory preparation"); 1298 Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "WebViewFactoryPreparation"); 1299 mWebViewUpdateService.prepareWebViewInSystemServer(); 1300 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER); 1301 } 1302 1303 Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "StartSystemUI"); 1304 try { 1305 startSystemUi(context); 1306 } catch (Throwable e) { 1307 reportWtf("starting System UI", e); 1308 } 1309 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER); 1310 Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "MakeNetworkScoreReady"); 1311 try { 1312 if (networkScoreF != null) networkScoreF.systemReady(); 1313 } catch (Throwable e) { 1314 reportWtf("making Network Score Service ready", e); 1315 } 1316 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER); 1317 Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "MakeNetworkManagementServiceReady"); 1318 try { 1319 if (networkManagementF != null) networkManagementF.systemReady(); 1320 } catch (Throwable e) { 1321 reportWtf("making Network Managment Service ready", e); 1322 } 1323 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER); 1324 Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "MakeNetworkStatsServiceReady"); 1325 try { 1326 if (networkStatsF != null) networkStatsF.systemReady(); 1327 } catch (Throwable e) { 1328 reportWtf("making Network Stats Service ready", e); 1329 } 1330 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER); 1331 Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "MakeNetworkPolicyServiceReady"); 1332 try { 1333 if (networkPolicyF != null) networkPolicyF.systemReady(); 1334 } catch (Throwable e) { 1335 reportWtf("making Network Policy Service ready", e); 1336 } 1337 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER); 1338 Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "MakeConnectivityServiceReady"); 1339 try { 1340 if (connectivityF != null) connectivityF.systemReady(); 1341 } catch (Throwable e) { 1342 reportWtf("making Connectivity Service ready", e); 1343 } 1344 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER); 1345 1346 Watchdog.getInstance().start(); 1347 1348 // It is now okay to let the various system services start their 1349 // third party code... 1350 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER); 1351 Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "PhaseThirdPartyAppsCanStart"); 1352 mSystemServiceManager.startBootPhase( 1353 SystemService.PHASE_THIRD_PARTY_APPS_CAN_START); 1354 1355 try { 1356 if (locationF != null) locationF.systemRunning(); 1357 } catch (Throwable e) { 1358 reportWtf("Notifying Location Service running", e); 1359 } 1360 try { 1361 if (countryDetectorF != null) countryDetectorF.systemRunning(); 1362 } catch (Throwable e) { 1363 reportWtf("Notifying CountryDetectorService running", e); 1364 } 1365 try { 1366 if (networkTimeUpdaterF != null) networkTimeUpdaterF.systemRunning(); 1367 } catch (Throwable e) { 1368 reportWtf("Notifying NetworkTimeService running", e); 1369 } 1370 try { 1371 if (commonTimeMgmtServiceF != null) { 1372 commonTimeMgmtServiceF.systemRunning(); 1373 } 1374 } catch (Throwable e) { 1375 reportWtf("Notifying CommonTimeManagementService running", e); 1376 } 1377 try { 1378 if (atlasF != null) atlasF.systemRunning(); 1379 } catch (Throwable e) { 1380 reportWtf("Notifying AssetAtlasService running", e); 1381 } 1382 try { 1383 // TODO(BT) Pass parameter to input manager 1384 if (inputManagerF != null) inputManagerF.systemRunning(); 1385 } catch (Throwable e) { 1386 reportWtf("Notifying InputManagerService running", e); 1387 } 1388 try { 1389 if (telephonyRegistryF != null) telephonyRegistryF.systemRunning(); 1390 } catch (Throwable e) { 1391 reportWtf("Notifying TelephonyRegistry running", e); 1392 } 1393 try { 1394 if (mediaRouterF != null) mediaRouterF.systemRunning(); 1395 } catch (Throwable e) { 1396 reportWtf("Notifying MediaRouterService running", e); 1397 } 1398 1399 try { 1400 if (mmsServiceF != null) mmsServiceF.systemRunning(); 1401 } catch (Throwable e) { 1402 reportWtf("Notifying MmsService running", e); 1403 } 1404 1405 try { 1406 if (networkScoreF != null) networkScoreF.systemRunning(); 1407 } catch (Throwable e) { 1408 reportWtf("Notifying NetworkScoreService running", e); 1409 } 1410 Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER); 1411 } 1412 }); 1413 } 1414 startSystemUi(Context context)1415 static final void startSystemUi(Context context) { 1416 Intent intent = new Intent(); 1417 intent.setComponent(new ComponentName("com.android.systemui", 1418 "com.android.systemui.SystemUIService")); 1419 intent.addFlags(Intent.FLAG_DEBUG_TRIAGED_MISSING); 1420 //Slog.d(TAG, "Starting service: " + intent); 1421 context.startServiceAsUser(intent, UserHandle.SYSTEM); 1422 } 1423 traceBeginAndSlog(String name)1424 private static void traceBeginAndSlog(String name) { 1425 Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, name); 1426 Slog.i(TAG, name); 1427 } 1428 } 1429