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 static android.os.IServiceManager.DUMP_FLAG_PRIORITY_CRITICAL; 20 import static android.os.IServiceManager.DUMP_FLAG_PRIORITY_HIGH; 21 import static android.os.IServiceManager.DUMP_FLAG_PRIORITY_NORMAL; 22 import static android.os.IServiceManager.DUMP_FLAG_PROTO; 23 import static android.view.Display.DEFAULT_DISPLAY; 24 25 import android.annotation.NonNull; 26 import android.app.ActivityThread; 27 import android.app.INotificationManager; 28 import android.app.usage.UsageStatsManagerInternal; 29 import android.content.ComponentName; 30 import android.content.ContentResolver; 31 import android.content.Context; 32 import android.content.Intent; 33 import android.content.pm.PackageItemInfo; 34 import android.content.pm.PackageManager; 35 import android.content.res.Configuration; 36 import android.content.res.Resources.Theme; 37 import android.database.sqlite.SQLiteCompatibilityWalFlags; 38 import android.database.sqlite.SQLiteGlobal; 39 import android.hardware.display.DisplayManagerInternal; 40 import android.net.NetworkStackClient; 41 import android.os.BaseBundle; 42 import android.os.Binder; 43 import android.os.Build; 44 import android.os.Environment; 45 import android.os.FactoryTest; 46 import android.os.FileUtils; 47 import android.os.IIncidentManager; 48 import android.os.Looper; 49 import android.os.Message; 50 import android.os.Parcel; 51 import android.os.PowerManager; 52 import android.os.Process; 53 import android.os.ServiceManager; 54 import android.os.StrictMode; 55 import android.os.SystemClock; 56 import android.os.SystemProperties; 57 import android.os.Trace; 58 import android.os.UserHandle; 59 import android.os.storage.IStorageManager; 60 import android.provider.DeviceConfig; 61 import android.provider.Settings; 62 import android.sysprop.VoldProperties; 63 import android.text.TextUtils; 64 import android.util.DisplayMetrics; 65 import android.util.EventLog; 66 import android.util.Slog; 67 import android.util.TimingsTraceLog; 68 import android.view.WindowManager; 69 import android.view.contentcapture.ContentCaptureManager; 70 import android.view.inputmethod.InputMethodSystemProperty; 71 72 import com.android.internal.R; 73 import com.android.internal.logging.MetricsLogger; 74 import com.android.internal.notification.SystemNotificationChannels; 75 import com.android.internal.os.BinderInternal; 76 import com.android.internal.util.ConcurrentUtils; 77 import com.android.internal.util.EmergencyAffordanceManager; 78 import com.android.internal.widget.ILockSettings; 79 import com.android.server.am.ActivityManagerService; 80 import com.android.server.appbinding.AppBindingService; 81 import com.android.server.attention.AttentionManagerService; 82 import com.android.server.audio.AudioService; 83 import com.android.server.biometrics.BiometricService; 84 import com.android.server.biometrics.face.FaceService; 85 import com.android.server.biometrics.fingerprint.FingerprintService; 86 import com.android.server.biometrics.iris.IrisService; 87 import com.android.server.broadcastradio.BroadcastRadioService; 88 import com.android.server.camera.CameraServiceProxy; 89 import com.android.server.clipboard.ClipboardService; 90 import com.android.server.connectivity.IpConnectivityMetrics; 91 import com.android.server.contentcapture.ContentCaptureManagerInternal; 92 import com.android.server.coverage.CoverageService; 93 import com.android.server.devicepolicy.DevicePolicyManagerService; 94 import com.android.server.display.DisplayManagerService; 95 import com.android.server.display.color.ColorDisplayService; 96 import com.android.server.dreams.DreamManagerService; 97 import com.android.server.emergency.EmergencyAffordanceService; 98 import com.android.server.gpu.GpuService; 99 import com.android.server.hdmi.HdmiControlService; 100 import com.android.server.incident.IncidentCompanionService; 101 import com.android.server.input.InputManagerService; 102 import com.android.server.inputmethod.InputMethodManagerService; 103 import com.android.server.inputmethod.MultiClientInputMethodManagerService; 104 import com.android.server.job.JobSchedulerService; 105 import com.android.server.lights.LightsService; 106 import com.android.server.media.MediaResourceMonitorService; 107 import com.android.server.media.MediaRouterService; 108 import com.android.server.media.MediaSessionService; 109 import com.android.server.media.projection.MediaProjectionManagerService; 110 import com.android.server.net.NetworkPolicyManagerService; 111 import com.android.server.net.NetworkStatsService; 112 import com.android.server.net.watchlist.NetworkWatchlistService; 113 import com.android.server.notification.NotificationManagerService; 114 import com.android.server.oemlock.OemLockService; 115 import com.android.server.om.OverlayManagerService; 116 import com.android.server.os.BugreportManagerService; 117 import com.android.server.os.DeviceIdentifiersPolicyService; 118 import com.android.server.os.SchedulingPolicyService; 119 import com.android.server.pm.BackgroundDexOptService; 120 import com.android.server.pm.CrossProfileAppsService; 121 import com.android.server.pm.DynamicCodeLoggingService; 122 import com.android.server.pm.Installer; 123 import com.android.server.pm.LauncherAppsService; 124 import com.android.server.pm.OtaDexoptService; 125 import com.android.server.pm.PackageManagerService; 126 import com.android.server.pm.ShortcutService; 127 import com.android.server.pm.UserManagerService; 128 import com.android.server.policy.PermissionPolicyService; 129 import com.android.server.policy.PhoneWindowManager; 130 import com.android.server.policy.role.LegacyRoleResolutionPolicy; 131 import com.android.server.power.PowerManagerService; 132 import com.android.server.power.ShutdownThread; 133 import com.android.server.power.ThermalManagerService; 134 import com.android.server.restrictions.RestrictionsManagerService; 135 import com.android.server.role.RoleManagerService; 136 import com.android.server.rollback.RollbackManagerService; 137 import com.android.server.security.KeyAttestationApplicationIdProviderService; 138 import com.android.server.security.KeyChainSystemService; 139 import com.android.server.signedconfig.SignedConfigService; 140 import com.android.server.soundtrigger.SoundTriggerService; 141 import com.android.server.stats.StatsCompanionService; 142 import com.android.server.statusbar.StatusBarManagerService; 143 import com.android.server.storage.DeviceStorageMonitorService; 144 import com.android.server.telecom.TelecomLoaderService; 145 import com.android.server.testharness.TestHarnessModeService; 146 import com.android.server.textclassifier.TextClassificationManagerService; 147 import com.android.server.textservices.TextServicesManagerService; 148 import com.android.server.trust.TrustManagerService; 149 import com.android.server.tv.TvInputManagerService; 150 import com.android.server.tv.TvRemoteService; 151 import com.android.server.twilight.TwilightService; 152 import com.android.server.uri.UriGrantsManagerService; 153 import com.android.server.usage.UsageStatsService; 154 import com.android.server.vr.VrManagerService; 155 import com.android.server.webkit.WebViewUpdateService; 156 import com.android.server.wm.ActivityTaskManagerService; 157 import com.android.server.wm.WindowManagerGlobalLock; 158 import com.android.server.wm.WindowManagerService; 159 160 import dalvik.system.VMRuntime; 161 162 import java.io.File; 163 import java.io.IOException; 164 import java.util.Locale; 165 import java.util.Timer; 166 import java.util.concurrent.CountDownLatch; 167 import java.util.concurrent.Future; 168 169 public final class SystemServer { 170 171 private static final String TAG = "SystemServer"; 172 173 // Tag for timing measurement of main thread. 174 private static final String SYSTEM_SERVER_TIMING_TAG = "SystemServerTiming"; 175 // Tag for timing measurement of non-main asynchronous operations. 176 private static final String SYSTEM_SERVER_TIMING_ASYNC_TAG = SYSTEM_SERVER_TIMING_TAG + "Async"; 177 178 private static final TimingsTraceLog BOOT_TIMINGS_TRACE_LOG 179 = new TimingsTraceLog(SYSTEM_SERVER_TIMING_TAG, Trace.TRACE_TAG_SYSTEM_SERVER); 180 181 private static final String ENCRYPTING_STATE = "trigger_restart_min_framework"; 182 private static final String ENCRYPTED_STATE = "1"; 183 184 private static final long SNAPSHOT_INTERVAL = 60 * 60 * 1000; // 1hr 185 186 // The earliest supported time. We pick one day into 1970, to 187 // give any timezone code room without going into negative time. 188 private static final long EARLIEST_SUPPORTED_TIME = 86400 * 1000; 189 190 private static final long SLOW_DISPATCH_THRESHOLD_MS = 100; 191 private static final long SLOW_DELIVERY_THRESHOLD_MS = 200; 192 193 /* 194 * Implementation class names. TODO: Move them to a codegen class or load 195 * them from the build system somehow. 196 */ 197 private static final String BACKUP_MANAGER_SERVICE_CLASS = 198 "com.android.server.backup.BackupManagerService$Lifecycle"; 199 private static final String APPWIDGET_SERVICE_CLASS = 200 "com.android.server.appwidget.AppWidgetService"; 201 private static final String VOICE_RECOGNITION_MANAGER_SERVICE_CLASS = 202 "com.android.server.voiceinteraction.VoiceInteractionManagerService"; 203 private static final String PRINT_MANAGER_SERVICE_CLASS = 204 "com.android.server.print.PrintManagerService"; 205 private static final String COMPANION_DEVICE_MANAGER_SERVICE_CLASS = 206 "com.android.server.companion.CompanionDeviceManagerService"; 207 private static final String USB_SERVICE_CLASS = 208 "com.android.server.usb.UsbService$Lifecycle"; 209 private static final String MIDI_SERVICE_CLASS = 210 "com.android.server.midi.MidiService$Lifecycle"; 211 private static final String WIFI_SERVICE_CLASS = 212 "com.android.server.wifi.WifiService"; 213 private static final String WIFI_AWARE_SERVICE_CLASS = 214 "com.android.server.wifi.aware.WifiAwareService"; 215 private static final String WIFI_P2P_SERVICE_CLASS = 216 "com.android.server.wifi.p2p.WifiP2pService"; 217 private static final String LOWPAN_SERVICE_CLASS = 218 "com.android.server.lowpan.LowpanService"; 219 private static final String ETHERNET_SERVICE_CLASS = 220 "com.android.server.ethernet.EthernetService"; 221 private static final String JOB_SCHEDULER_SERVICE_CLASS = 222 "com.android.server.job.JobSchedulerService"; 223 private static final String LOCK_SETTINGS_SERVICE_CLASS = 224 "com.android.server.locksettings.LockSettingsService$Lifecycle"; 225 private static final String STORAGE_MANAGER_SERVICE_CLASS = 226 "com.android.server.StorageManagerService$Lifecycle"; 227 private static final String STORAGE_STATS_SERVICE_CLASS = 228 "com.android.server.usage.StorageStatsService$Lifecycle"; 229 private static final String SEARCH_MANAGER_SERVICE_CLASS = 230 "com.android.server.search.SearchManagerService$Lifecycle"; 231 private static final String THERMAL_OBSERVER_CLASS = 232 "com.google.android.clockwork.ThermalObserver"; 233 private static final String WEAR_CONNECTIVITY_SERVICE_CLASS = 234 "com.android.clockwork.connectivity.WearConnectivityService"; 235 private static final String WEAR_POWER_SERVICE_CLASS = 236 "com.android.clockwork.power.WearPowerService"; 237 private static final String WEAR_SIDEKICK_SERVICE_CLASS = 238 "com.google.android.clockwork.sidekick.SidekickService"; 239 private static final String WEAR_DISPLAY_SERVICE_CLASS = 240 "com.google.android.clockwork.display.WearDisplayService"; 241 private static final String WEAR_LEFTY_SERVICE_CLASS = 242 "com.google.android.clockwork.lefty.WearLeftyService"; 243 private static final String WEAR_TIME_SERVICE_CLASS = 244 "com.google.android.clockwork.time.WearTimeService"; 245 private static final String WEAR_GLOBAL_ACTIONS_SERVICE_CLASS = 246 "com.android.clockwork.globalactions.GlobalActionsService"; 247 private static final String ACCOUNT_SERVICE_CLASS = 248 "com.android.server.accounts.AccountManagerService$Lifecycle"; 249 private static final String CONTENT_SERVICE_CLASS = 250 "com.android.server.content.ContentService$Lifecycle"; 251 private static final String WALLPAPER_SERVICE_CLASS = 252 "com.android.server.wallpaper.WallpaperManagerService$Lifecycle"; 253 private static final String AUTO_FILL_MANAGER_SERVICE_CLASS = 254 "com.android.server.autofill.AutofillManagerService"; 255 private static final String CONTENT_CAPTURE_MANAGER_SERVICE_CLASS = 256 "com.android.server.contentcapture.ContentCaptureManagerService"; 257 private static final String SYSTEM_CAPTIONS_MANAGER_SERVICE_CLASS = 258 "com.android.server.systemcaptions.SystemCaptionsManagerService"; 259 private static final String TIME_ZONE_RULES_MANAGER_SERVICE_CLASS = 260 "com.android.server.timezone.RulesManagerService$Lifecycle"; 261 private static final String IOT_SERVICE_CLASS = 262 "com.android.things.server.IoTSystemService"; 263 private static final String SLICE_MANAGER_SERVICE_CLASS = 264 "com.android.server.slice.SliceManagerService$Lifecycle"; 265 private static final String CAR_SERVICE_HELPER_SERVICE_CLASS = 266 "com.android.internal.car.CarServiceHelperService"; 267 private static final String TIME_DETECTOR_SERVICE_CLASS = 268 "com.android.server.timedetector.TimeDetectorService$Lifecycle"; 269 private static final String ACCESSIBILITY_MANAGER_SERVICE_CLASS = 270 "com.android.server.accessibility.AccessibilityManagerService$Lifecycle"; 271 private static final String ADB_SERVICE_CLASS = 272 "com.android.server.adb.AdbService$Lifecycle"; 273 private static final String APP_PREDICTION_MANAGER_SERVICE_CLASS = 274 "com.android.server.appprediction.AppPredictionManagerService"; 275 private static final String CONTENT_SUGGESTIONS_SERVICE_CLASS = 276 "com.android.server.contentsuggestions.ContentSuggestionsManagerService"; 277 278 private static final String PERSISTENT_DATA_BLOCK_PROP = "ro.frp.pst"; 279 280 private static final String UNCRYPT_PACKAGE_FILE = "/cache/recovery/uncrypt_file"; 281 private static final String BLOCK_MAP_FILE = "/cache/recovery/block.map"; 282 283 private static final String GSI_RUNNING_PROP = "ro.gsid.image_running"; 284 285 // maximum number of binder threads used for system_server 286 // will be higher than the system default 287 private static final int sMaxBinderThreads = 31; 288 289 /** 290 * Default theme used by the system context. This is used to style system-provided dialogs, such 291 * as the Power Off dialog, and other visual content. 292 */ 293 private static final int DEFAULT_SYSTEM_THEME = 294 com.android.internal.R.style.Theme_DeviceDefault_System; 295 296 private final int mFactoryTestMode; 297 private Timer mProfilerSnapshotTimer; 298 299 private Context mSystemContext; 300 private SystemServiceManager mSystemServiceManager; 301 302 // TODO: remove all of these references by improving dependency resolution and boot phases 303 private PowerManagerService mPowerManagerService; 304 private ActivityManagerService mActivityManagerService; 305 private WindowManagerGlobalLock mWindowManagerGlobalLock; 306 private WebViewUpdateService mWebViewUpdateService; 307 private DisplayManagerService mDisplayManagerService; 308 private PackageManagerService mPackageManagerService; 309 private PackageManager mPackageManager; 310 private ContentResolver mContentResolver; 311 private EntropyMixer mEntropyMixer; 312 313 private boolean mOnlyCore; 314 private boolean mFirstBoot; 315 private final int mStartCount; 316 private final boolean mRuntimeRestart; 317 private final long mRuntimeStartElapsedTime; 318 private final long mRuntimeStartUptime; 319 320 private static final String START_SENSOR_SERVICE = "StartSensorService"; 321 private static final String START_HIDL_SERVICES = "StartHidlServices"; 322 323 private static final String SYSPROP_START_COUNT = "sys.system_server.start_count"; 324 private static final String SYSPROP_START_ELAPSED = "sys.system_server.start_elapsed"; 325 private static final String SYSPROP_START_UPTIME = "sys.system_server.start_uptime"; 326 327 private Future<?> mSensorServiceStart; 328 private Future<?> mZygotePreload; 329 330 /** 331 * Start the sensor service. This is a blocking call and can take time. 332 */ startSensorService()333 private static native void startSensorService(); 334 335 /** 336 * Start all HIDL services that are run inside the system server. This may take some time. 337 */ startHidlServices()338 private static native void startHidlServices(); 339 340 /** 341 * Mark this process' heap as profileable. Only for debug builds. 342 */ initZygoteChildHeapProfiling()343 private static native void initZygoteChildHeapProfiling(); 344 345 /** 346 * The main entry point from zygote. 347 */ main(String[] args)348 public static void main(String[] args) { 349 new SystemServer().run(); 350 } 351 SystemServer()352 public SystemServer() { 353 // Check for factory test mode. 354 mFactoryTestMode = FactoryTest.getMode(); 355 356 // Record process start information. 357 // Note SYSPROP_START_COUNT will increment by *2* on a FDE device when it fully boots; 358 // one for the password screen, second for the actual boot. 359 mStartCount = SystemProperties.getInt(SYSPROP_START_COUNT, 0) + 1; 360 mRuntimeStartElapsedTime = SystemClock.elapsedRealtime(); 361 mRuntimeStartUptime = SystemClock.uptimeMillis(); 362 363 // Remember if it's runtime restart(when sys.boot_completed is already set) or reboot 364 // We don't use "mStartCount > 1" here because it'll be wrong on a FDE device. 365 // TODO: mRuntimeRestart will *not* be set to true if the proccess crashes before 366 // sys.boot_completed is set. Fix it. 367 mRuntimeRestart = "1".equals(SystemProperties.get("sys.boot_completed")); 368 } 369 run()370 private void run() { 371 try { 372 traceBeginAndSlog("InitBeforeStartServices"); 373 374 // Record the process start information in sys props. 375 SystemProperties.set(SYSPROP_START_COUNT, String.valueOf(mStartCount)); 376 SystemProperties.set(SYSPROP_START_ELAPSED, String.valueOf(mRuntimeStartElapsedTime)); 377 SystemProperties.set(SYSPROP_START_UPTIME, String.valueOf(mRuntimeStartUptime)); 378 379 EventLog.writeEvent(EventLogTags.SYSTEM_SERVER_START, 380 mStartCount, mRuntimeStartUptime, mRuntimeStartElapsedTime); 381 382 // If a device's clock is before 1970 (before 0), a lot of 383 // APIs crash dealing with negative numbers, notably 384 // java.io.File#setLastModified, so instead we fake it and 385 // hope that time from cell towers or NTP fixes it shortly. 386 if (System.currentTimeMillis() < EARLIEST_SUPPORTED_TIME) { 387 Slog.w(TAG, "System clock is before 1970; setting to 1970."); 388 SystemClock.setCurrentTimeMillis(EARLIEST_SUPPORTED_TIME); 389 } 390 391 // 392 // Default the timezone property to GMT if not set. 393 // 394 String timezoneProperty = SystemProperties.get("persist.sys.timezone"); 395 if (timezoneProperty == null || timezoneProperty.isEmpty()) { 396 Slog.w(TAG, "Timezone not set; setting to GMT."); 397 SystemProperties.set("persist.sys.timezone", "GMT"); 398 } 399 400 // If the system has "persist.sys.language" and friends set, replace them with 401 // "persist.sys.locale". Note that the default locale at this point is calculated 402 // using the "-Duser.locale" command line flag. That flag is usually populated by 403 // AndroidRuntime using the same set of system properties, but only the system_server 404 // and system apps are allowed to set them. 405 // 406 // NOTE: Most changes made here will need an equivalent change to 407 // core/jni/AndroidRuntime.cpp 408 if (!SystemProperties.get("persist.sys.language").isEmpty()) { 409 final String languageTag = Locale.getDefault().toLanguageTag(); 410 411 SystemProperties.set("persist.sys.locale", languageTag); 412 SystemProperties.set("persist.sys.language", ""); 413 SystemProperties.set("persist.sys.country", ""); 414 SystemProperties.set("persist.sys.localevar", ""); 415 } 416 417 // The system server should never make non-oneway calls 418 Binder.setWarnOnBlocking(true); 419 // The system server should always load safe labels 420 PackageItemInfo.forceSafeLabels(); 421 422 // Default to FULL within the system server. 423 SQLiteGlobal.sDefaultSyncMode = SQLiteGlobal.SYNC_MODE_FULL; 424 425 // Deactivate SQLiteCompatibilityWalFlags until settings provider is initialized 426 SQLiteCompatibilityWalFlags.init(null); 427 428 // Here we go! 429 Slog.i(TAG, "Entered the Android system server!"); 430 int uptimeMillis = (int) SystemClock.elapsedRealtime(); 431 EventLog.writeEvent(EventLogTags.BOOT_PROGRESS_SYSTEM_RUN, uptimeMillis); 432 if (!mRuntimeRestart) { 433 MetricsLogger.histogram(null, "boot_system_server_init", uptimeMillis); 434 } 435 436 // In case the runtime switched since last boot (such as when 437 // the old runtime was removed in an OTA), set the system 438 // property so that it is in sync. We can | xq oqi't do this in 439 // libnativehelper's JniInvocation::Init code where we already 440 // had to fallback to a different runtime because it is 441 // running as root and we need to be the system user to set 442 // the property. http://b/11463182 443 SystemProperties.set("persist.sys.dalvik.vm.lib.2", VMRuntime.getRuntime().vmLibrary()); 444 445 // Mmmmmm... more memory! 446 VMRuntime.getRuntime().clearGrowthLimit(); 447 448 // The system server has to run all of the time, so it needs to be 449 // as efficient as possible with its memory usage. 450 VMRuntime.getRuntime().setTargetHeapUtilization(0.8f); 451 452 // Some devices rely on runtime fingerprint generation, so make sure 453 // we've defined it before booting further. 454 Build.ensureFingerprintProperty(); 455 456 // Within the system server, it is an error to access Environment paths without 457 // explicitly specifying a user. 458 Environment.setUserRequired(true); 459 460 // Within the system server, any incoming Bundles should be defused 461 // to avoid throwing BadParcelableException. 462 BaseBundle.setShouldDefuse(true); 463 464 // Within the system server, when parceling exceptions, include the stack trace 465 Parcel.setStackTraceParceling(true); 466 467 // Ensure binder calls into the system always run at foreground priority. 468 BinderInternal.disableBackgroundScheduling(true); 469 470 // Increase the number of binder threads in system_server 471 BinderInternal.setMaxThreads(sMaxBinderThreads); 472 473 // Prepare the main looper thread (this thread). 474 android.os.Process.setThreadPriority( 475 android.os.Process.THREAD_PRIORITY_FOREGROUND); 476 android.os.Process.setCanSelfBackground(false); 477 Looper.prepareMainLooper(); 478 Looper.getMainLooper().setSlowLogThresholdMs( 479 SLOW_DISPATCH_THRESHOLD_MS, SLOW_DELIVERY_THRESHOLD_MS); 480 481 // Initialize native services. 482 System.loadLibrary("android_servers"); 483 484 // Debug builds - allow heap profiling. 485 if (Build.IS_DEBUGGABLE) { 486 initZygoteChildHeapProfiling(); 487 } 488 489 // Check whether we failed to shut down last time we tried. 490 // This call may not return. 491 performPendingShutdown(); 492 493 // Initialize the system context. 494 createSystemContext(); 495 496 // Create the system service manager. 497 mSystemServiceManager = new SystemServiceManager(mSystemContext); 498 mSystemServiceManager.setStartInfo(mRuntimeRestart, 499 mRuntimeStartElapsedTime, mRuntimeStartUptime); 500 LocalServices.addService(SystemServiceManager.class, mSystemServiceManager); 501 // Prepare the thread pool for init tasks that can be parallelized 502 SystemServerInitThreadPool.get(); 503 } finally { 504 traceEnd(); // InitBeforeStartServices 505 } 506 507 // Start services. 508 try { 509 traceBeginAndSlog("StartServices"); 510 startBootstrapServices(); 511 startCoreServices(); 512 startOtherServices(); 513 SystemServerInitThreadPool.shutdown(); 514 } catch (Throwable ex) { 515 Slog.e("System", "******************************************"); 516 Slog.e("System", "************ Failure starting system services", ex); 517 throw ex; 518 } finally { 519 traceEnd(); 520 } 521 522 StrictMode.initVmDefaults(null); 523 524 if (!mRuntimeRestart && !isFirstBootOrUpgrade()) { 525 int uptimeMillis = (int) SystemClock.elapsedRealtime(); 526 MetricsLogger.histogram(null, "boot_system_server_ready", uptimeMillis); 527 final int MAX_UPTIME_MILLIS = 60 * 1000; 528 if (uptimeMillis > MAX_UPTIME_MILLIS) { 529 Slog.wtf(SYSTEM_SERVER_TIMING_TAG, 530 "SystemServer init took too long. uptimeMillis=" + uptimeMillis); 531 } 532 } 533 534 // Diagnostic to ensure that the system is in a base healthy state. Done here as a common 535 // non-zygote process. 536 if (!VMRuntime.hasBootImageSpaces()) { 537 Slog.wtf(TAG, "Runtime is not running with a boot image!"); 538 } 539 540 // Loop forever. 541 Looper.loop(); 542 throw new RuntimeException("Main thread loop unexpectedly exited"); 543 } 544 isFirstBootOrUpgrade()545 private boolean isFirstBootOrUpgrade() { 546 return mPackageManagerService.isFirstBoot() || mPackageManagerService.isDeviceUpgrading(); 547 } 548 reportWtf(String msg, Throwable e)549 private void reportWtf(String msg, Throwable e) { 550 Slog.w(TAG, "***********************************************"); 551 Slog.wtf(TAG, "BOOT FAILURE " + msg, e); 552 } 553 performPendingShutdown()554 private void performPendingShutdown() { 555 final String shutdownAction = SystemProperties.get( 556 ShutdownThread.SHUTDOWN_ACTION_PROPERTY, ""); 557 if (shutdownAction != null && shutdownAction.length() > 0) { 558 boolean reboot = (shutdownAction.charAt(0) == '1'); 559 560 final String reason; 561 if (shutdownAction.length() > 1) { 562 reason = shutdownAction.substring(1, shutdownAction.length()); 563 } else { 564 reason = null; 565 } 566 567 // If it's a pending reboot into recovery to apply an update, 568 // always make sure uncrypt gets executed properly when needed. 569 // If '/cache/recovery/block.map' hasn't been created, stop the 570 // reboot which will fail for sure, and get a chance to capture a 571 // bugreport when that's still feasible. (Bug: 26444951) 572 if (reason != null && reason.startsWith(PowerManager.REBOOT_RECOVERY_UPDATE)) { 573 File packageFile = new File(UNCRYPT_PACKAGE_FILE); 574 if (packageFile.exists()) { 575 String filename = null; 576 try { 577 filename = FileUtils.readTextFile(packageFile, 0, null); 578 } catch (IOException e) { 579 Slog.e(TAG, "Error reading uncrypt package file", e); 580 } 581 582 if (filename != null && filename.startsWith("/data")) { 583 if (!new File(BLOCK_MAP_FILE).exists()) { 584 Slog.e(TAG, "Can't find block map file, uncrypt failed or " + 585 "unexpected runtime restart?"); 586 return; 587 } 588 } 589 } 590 } 591 Runnable runnable = new Runnable() { 592 @Override 593 public void run() { 594 synchronized (this) { 595 ShutdownThread.rebootOrShutdown(null, reboot, reason); 596 } 597 } 598 }; 599 600 // ShutdownThread must run on a looper capable of displaying the UI. 601 Message msg = Message.obtain(UiThread.getHandler(), runnable); 602 msg.setAsynchronous(true); 603 UiThread.getHandler().sendMessage(msg); 604 605 } 606 } 607 createSystemContext()608 private void createSystemContext() { 609 ActivityThread activityThread = ActivityThread.systemMain(); 610 mSystemContext = activityThread.getSystemContext(); 611 mSystemContext.setTheme(DEFAULT_SYSTEM_THEME); 612 613 final Context systemUiContext = activityThread.getSystemUiContext(); 614 systemUiContext.setTheme(DEFAULT_SYSTEM_THEME); 615 } 616 617 /** 618 * Starts the small tangle of critical services that are needed to get the system off the 619 * ground. These services have complex mutual dependencies which is why we initialize them all 620 * in one place here. Unless your service is also entwined in these dependencies, it should be 621 * initialized in one of the other functions. 622 */ startBootstrapServices()623 private void startBootstrapServices() { 624 // Start the watchdog as early as possible so we can crash the system server 625 // if we deadlock during early boot 626 traceBeginAndSlog("StartWatchdog"); 627 final Watchdog watchdog = Watchdog.getInstance(); 628 watchdog.start(); 629 traceEnd(); 630 631 Slog.i(TAG, "Reading configuration..."); 632 final String TAG_SYSTEM_CONFIG = "ReadingSystemConfig"; 633 traceBeginAndSlog(TAG_SYSTEM_CONFIG); 634 SystemServerInitThreadPool.get().submit(SystemConfig::getInstance, TAG_SYSTEM_CONFIG); 635 traceEnd(); 636 637 // Wait for installd to finish starting up so that it has a chance to 638 // create critical directories such as /data/user with the appropriate 639 // permissions. We need this to complete before we initialize other services. 640 traceBeginAndSlog("StartInstaller"); 641 Installer installer = mSystemServiceManager.startService(Installer.class); 642 traceEnd(); 643 644 // In some cases after launching an app we need to access device identifiers, 645 // therefore register the device identifier policy before the activity manager. 646 traceBeginAndSlog("DeviceIdentifiersPolicyService"); 647 mSystemServiceManager.startService(DeviceIdentifiersPolicyService.class); 648 traceEnd(); 649 650 // Uri Grants Manager. 651 traceBeginAndSlog("UriGrantsManagerService"); 652 mSystemServiceManager.startService(UriGrantsManagerService.Lifecycle.class); 653 traceEnd(); 654 655 // Activity manager runs the show. 656 traceBeginAndSlog("StartActivityManager"); 657 // TODO: Might need to move after migration to WM. 658 ActivityTaskManagerService atm = mSystemServiceManager.startService( 659 ActivityTaskManagerService.Lifecycle.class).getService(); 660 mActivityManagerService = ActivityManagerService.Lifecycle.startService( 661 mSystemServiceManager, atm); 662 mActivityManagerService.setSystemServiceManager(mSystemServiceManager); 663 mActivityManagerService.setInstaller(installer); 664 mWindowManagerGlobalLock = atm.getGlobalLock(); 665 traceEnd(); 666 667 // Power manager needs to be started early because other services need it. 668 // Native daemons may be watching for it to be registered so it must be ready 669 // to handle incoming binder calls immediately (including being able to verify 670 // the permissions for those calls). 671 traceBeginAndSlog("StartPowerManager"); 672 mPowerManagerService = mSystemServiceManager.startService(PowerManagerService.class); 673 traceEnd(); 674 675 traceBeginAndSlog("StartThermalManager"); 676 mSystemServiceManager.startService(ThermalManagerService.class); 677 traceEnd(); 678 679 // Now that the power manager has been started, let the activity manager 680 // initialize power management features. 681 traceBeginAndSlog("InitPowerManagement"); 682 mActivityManagerService.initPowerManagement(); 683 traceEnd(); 684 685 // Bring up recovery system in case a rescue party needs a reboot 686 traceBeginAndSlog("StartRecoverySystemService"); 687 mSystemServiceManager.startService(RecoverySystemService.class); 688 traceEnd(); 689 690 // Now that we have the bare essentials of the OS up and running, take 691 // note that we just booted, which might send out a rescue party if 692 // we're stuck in a runtime restart loop. 693 RescueParty.noteBoot(mSystemContext); 694 695 // Manages LEDs and display backlight so we need it to bring up the display. 696 traceBeginAndSlog("StartLightsService"); 697 mSystemServiceManager.startService(LightsService.class); 698 traceEnd(); 699 700 traceBeginAndSlog("StartSidekickService"); 701 // Package manager isn't started yet; need to use SysProp not hardware feature 702 if (SystemProperties.getBoolean("config.enable_sidekick_graphics", false)) { 703 mSystemServiceManager.startService(WEAR_SIDEKICK_SERVICE_CLASS); 704 } 705 traceEnd(); 706 707 // Display manager is needed to provide display metrics before package manager 708 // starts up. 709 traceBeginAndSlog("StartDisplayManager"); 710 mDisplayManagerService = mSystemServiceManager.startService(DisplayManagerService.class); 711 traceEnd(); 712 713 // We need the default display before we can initialize the package manager. 714 traceBeginAndSlog("WaitForDisplay"); 715 mSystemServiceManager.startBootPhase(SystemService.PHASE_WAIT_FOR_DEFAULT_DISPLAY); 716 traceEnd(); 717 718 // Only run "core" apps if we're encrypting the device. 719 String cryptState = VoldProperties.decrypt().orElse(""); 720 if (ENCRYPTING_STATE.equals(cryptState)) { 721 Slog.w(TAG, "Detected encryption in progress - only parsing core apps"); 722 mOnlyCore = true; 723 } else if (ENCRYPTED_STATE.equals(cryptState)) { 724 Slog.w(TAG, "Device encrypted - only parsing core apps"); 725 mOnlyCore = true; 726 } 727 728 // Start the package manager. 729 if (!mRuntimeRestart) { 730 MetricsLogger.histogram(null, "boot_package_manager_init_start", 731 (int) SystemClock.elapsedRealtime()); 732 } 733 traceBeginAndSlog("StartPackageManagerService"); 734 try { 735 Watchdog.getInstance().pauseWatchingCurrentThread("packagemanagermain"); 736 mPackageManagerService = PackageManagerService.main(mSystemContext, installer, 737 mFactoryTestMode != FactoryTest.FACTORY_TEST_OFF, mOnlyCore); 738 } finally { 739 Watchdog.getInstance().resumeWatchingCurrentThread("packagemanagermain"); 740 } 741 mFirstBoot = mPackageManagerService.isFirstBoot(); 742 mPackageManager = mSystemContext.getPackageManager(); 743 traceEnd(); 744 if (!mRuntimeRestart && !isFirstBootOrUpgrade()) { 745 MetricsLogger.histogram(null, "boot_package_manager_init_ready", 746 (int) SystemClock.elapsedRealtime()); 747 } 748 // Manages A/B OTA dexopting. This is a bootstrap service as we need it to rename 749 // A/B artifacts after boot, before anything else might touch/need them. 750 // Note: this isn't needed during decryption (we don't have /data anyways). 751 if (!mOnlyCore) { 752 boolean disableOtaDexopt = SystemProperties.getBoolean("config.disable_otadexopt", 753 false); 754 if (!disableOtaDexopt) { 755 traceBeginAndSlog("StartOtaDexOptService"); 756 try { 757 Watchdog.getInstance().pauseWatchingCurrentThread("moveab"); 758 OtaDexoptService.main(mSystemContext, mPackageManagerService); 759 } catch (Throwable e) { 760 reportWtf("starting OtaDexOptService", e); 761 } finally { 762 Watchdog.getInstance().resumeWatchingCurrentThread("moveab"); 763 traceEnd(); 764 } 765 } 766 } 767 768 traceBeginAndSlog("StartUserManagerService"); 769 mSystemServiceManager.startService(UserManagerService.LifeCycle.class); 770 traceEnd(); 771 772 // Initialize attribute cache used to cache resources from packages. 773 traceBeginAndSlog("InitAttributerCache"); 774 AttributeCache.init(mSystemContext); 775 traceEnd(); 776 777 // Set up the Application instance for the system process and get started. 778 traceBeginAndSlog("SetSystemProcess"); 779 mActivityManagerService.setSystemProcess(); 780 traceEnd(); 781 782 // Complete the watchdog setup with an ActivityManager instance and listen for reboots 783 // Do this only after the ActivityManagerService is properly started as a system process 784 traceBeginAndSlog("InitWatchdog"); 785 watchdog.init(mSystemContext, mActivityManagerService); 786 traceEnd(); 787 788 // DisplayManagerService needs to setup android.display scheduling related policies 789 // since setSystemProcess() would have overridden policies due to setProcessGroup 790 mDisplayManagerService.setupSchedulerPolicies(); 791 792 // Manages Overlay packages 793 traceBeginAndSlog("StartOverlayManagerService"); 794 mSystemServiceManager.startService(new OverlayManagerService(mSystemContext, installer)); 795 traceEnd(); 796 797 traceBeginAndSlog("StartSensorPrivacyService"); 798 mSystemServiceManager.startService(new SensorPrivacyService(mSystemContext)); 799 traceEnd(); 800 801 if (SystemProperties.getInt("persist.sys.displayinset.top", 0) > 0) { 802 // DisplayManager needs the overlay immediately. 803 mActivityManagerService.updateSystemUiContext(); 804 LocalServices.getService(DisplayManagerInternal.class).onOverlayChanged(); 805 } 806 807 // The sensor service needs access to package manager service, app ops 808 // service, and permissions service, therefore we start it after them. 809 // Start sensor service in a separate thread. Completion should be checked 810 // before using it. 811 mSensorServiceStart = SystemServerInitThreadPool.get().submit(() -> { 812 TimingsTraceLog traceLog = new TimingsTraceLog( 813 SYSTEM_SERVER_TIMING_ASYNC_TAG, Trace.TRACE_TAG_SYSTEM_SERVER); 814 traceLog.traceBegin(START_SENSOR_SERVICE); 815 startSensorService(); 816 traceLog.traceEnd(); 817 }, START_SENSOR_SERVICE); 818 } 819 820 /** 821 * Starts some essential services that are not tangled up in the bootstrap process. 822 */ startCoreServices()823 private void startCoreServices() { 824 traceBeginAndSlog("StartBatteryService"); 825 // Tracks the battery level. Requires LightService. 826 mSystemServiceManager.startService(BatteryService.class); 827 traceEnd(); 828 829 // Tracks application usage stats. 830 traceBeginAndSlog("StartUsageService"); 831 mSystemServiceManager.startService(UsageStatsService.class); 832 mActivityManagerService.setUsageStatsManager( 833 LocalServices.getService(UsageStatsManagerInternal.class)); 834 traceEnd(); 835 836 // Tracks whether the updatable WebView is in a ready state and watches for update installs. 837 if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_WEBVIEW)) { 838 traceBeginAndSlog("StartWebViewUpdateService"); 839 mWebViewUpdateService = mSystemServiceManager.startService(WebViewUpdateService.class); 840 traceEnd(); 841 } 842 843 // Tracks and caches the device state. 844 traceBeginAndSlog("StartCachedDeviceStateService"); 845 mSystemServiceManager.startService(CachedDeviceStateService.class); 846 traceEnd(); 847 848 // Tracks cpu time spent in binder calls 849 traceBeginAndSlog("StartBinderCallsStatsService"); 850 mSystemServiceManager.startService(BinderCallsStatsService.LifeCycle.class); 851 traceEnd(); 852 853 // Tracks time spent in handling messages in handlers. 854 traceBeginAndSlog("StartLooperStatsService"); 855 mSystemServiceManager.startService(LooperStatsService.Lifecycle.class); 856 traceEnd(); 857 858 // Manages apk rollbacks. 859 traceBeginAndSlog("StartRollbackManagerService"); 860 mSystemServiceManager.startService(RollbackManagerService.class); 861 traceEnd(); 862 863 // Service to capture bugreports. 864 traceBeginAndSlog("StartBugreportManagerService"); 865 mSystemServiceManager.startService(BugreportManagerService.class); 866 traceEnd(); 867 868 // Serivce for GPU and GPU driver. 869 traceBeginAndSlog("GpuService"); 870 mSystemServiceManager.startService(GpuService.class); 871 traceEnd(); 872 } 873 874 /** 875 * Starts a miscellaneous grab bag of stuff that has yet to be refactored and organized. 876 */ startOtherServices()877 private void startOtherServices() { 878 final Context context = mSystemContext; 879 VibratorService vibrator = null; 880 DynamicSystemService dynamicSystem = null; 881 IStorageManager storageManager = null; 882 NetworkManagementService networkManagement = null; 883 IpSecService ipSecService = null; 884 NetworkStatsService networkStats = null; 885 NetworkPolicyManagerService networkPolicy = null; 886 ConnectivityService connectivity = null; 887 NsdService serviceDiscovery = null; 888 WindowManagerService wm = null; 889 SerialService serial = null; 890 NetworkTimeUpdateService networkTimeUpdater = null; 891 InputManagerService inputManager = null; 892 TelephonyRegistry telephonyRegistry = null; 893 ConsumerIrService consumerIr = null; 894 MmsServiceBroker mmsService = null; 895 HardwarePropertiesManagerService hardwarePropertiesService = null; 896 897 boolean disableSystemTextClassifier = SystemProperties.getBoolean( 898 "config.disable_systemtextclassifier", false); 899 900 boolean disableNetworkTime = SystemProperties.getBoolean("config.disable_networktime", 901 false); 902 boolean disableCameraService = SystemProperties.getBoolean("config.disable_cameraservice", 903 false); 904 boolean disableSlices = SystemProperties.getBoolean("config.disable_slices", false); 905 boolean enableLeftyService = SystemProperties.getBoolean("config.enable_lefty", false); 906 907 boolean isEmulator = SystemProperties.get("ro.kernel.qemu").equals("1"); 908 909 boolean isWatch = context.getPackageManager().hasSystemFeature( 910 PackageManager.FEATURE_WATCH); 911 912 boolean isArc = context.getPackageManager().hasSystemFeature( 913 "org.chromium.arc"); 914 915 boolean enableVrService = context.getPackageManager().hasSystemFeature( 916 PackageManager.FEATURE_VR_MODE_HIGH_PERFORMANCE); 917 918 // For debugging RescueParty 919 if (Build.IS_DEBUGGABLE && SystemProperties.getBoolean("debug.crash_system", false)) { 920 throw new RuntimeException(); 921 } 922 923 try { 924 final String SECONDARY_ZYGOTE_PRELOAD = "SecondaryZygotePreload"; 925 // We start the preload ~1s before the webview factory preparation, to 926 // ensure that it completes before the 32 bit relro process is forked 927 // from the zygote. In the event that it takes too long, the webview 928 // RELRO process will block, but it will do so without holding any locks. 929 mZygotePreload = SystemServerInitThreadPool.get().submit(() -> { 930 try { 931 Slog.i(TAG, SECONDARY_ZYGOTE_PRELOAD); 932 TimingsTraceLog traceLog = new TimingsTraceLog( 933 SYSTEM_SERVER_TIMING_ASYNC_TAG, Trace.TRACE_TAG_SYSTEM_SERVER); 934 traceLog.traceBegin(SECONDARY_ZYGOTE_PRELOAD); 935 if (!Process.ZYGOTE_PROCESS.preloadDefault(Build.SUPPORTED_32_BIT_ABIS[0])) { 936 Slog.e(TAG, "Unable to preload default resources"); 937 } 938 traceLog.traceEnd(); 939 } catch (Exception ex) { 940 Slog.e(TAG, "Exception preloading default resources", ex); 941 } 942 }, SECONDARY_ZYGOTE_PRELOAD); 943 944 traceBeginAndSlog("StartKeyAttestationApplicationIdProviderService"); 945 ServiceManager.addService("sec_key_att_app_id_provider", 946 new KeyAttestationApplicationIdProviderService(context)); 947 traceEnd(); 948 949 traceBeginAndSlog("StartKeyChainSystemService"); 950 mSystemServiceManager.startService(KeyChainSystemService.class); 951 traceEnd(); 952 953 traceBeginAndSlog("StartSchedulingPolicyService"); 954 ServiceManager.addService("scheduling_policy", new SchedulingPolicyService()); 955 traceEnd(); 956 957 traceBeginAndSlog("StartTelecomLoaderService"); 958 mSystemServiceManager.startService(TelecomLoaderService.class); 959 traceEnd(); 960 961 traceBeginAndSlog("StartTelephonyRegistry"); 962 telephonyRegistry = new TelephonyRegistry(context); 963 ServiceManager.addService("telephony.registry", telephonyRegistry); 964 traceEnd(); 965 966 traceBeginAndSlog("StartEntropyMixer"); 967 mEntropyMixer = new EntropyMixer(context); 968 traceEnd(); 969 970 mContentResolver = context.getContentResolver(); 971 972 // The AccountManager must come before the ContentService 973 traceBeginAndSlog("StartAccountManagerService"); 974 mSystemServiceManager.startService(ACCOUNT_SERVICE_CLASS); 975 traceEnd(); 976 977 traceBeginAndSlog("StartContentService"); 978 mSystemServiceManager.startService(CONTENT_SERVICE_CLASS); 979 traceEnd(); 980 981 traceBeginAndSlog("InstallSystemProviders"); 982 mActivityManagerService.installSystemProviders(); 983 // Now that SettingsProvider is ready, reactivate SQLiteCompatibilityWalFlags 984 SQLiteCompatibilityWalFlags.reset(); 985 traceEnd(); 986 987 // Records errors and logs, for example wtf() 988 // Currently this service indirectly depends on SettingsProvider so do this after 989 // InstallSystemProviders. 990 traceBeginAndSlog("StartDropBoxManager"); 991 mSystemServiceManager.startService(DropBoxManagerService.class); 992 traceEnd(); 993 994 traceBeginAndSlog("StartVibratorService"); 995 vibrator = new VibratorService(context); 996 ServiceManager.addService("vibrator", vibrator); 997 traceEnd(); 998 999 traceBeginAndSlog("StartDynamicSystemService"); 1000 dynamicSystem = new DynamicSystemService(context); 1001 ServiceManager.addService("dynamic_system", dynamicSystem); 1002 traceEnd(); 1003 1004 if (!isWatch) { 1005 traceBeginAndSlog("StartConsumerIrService"); 1006 consumerIr = new ConsumerIrService(context); 1007 ServiceManager.addService(Context.CONSUMER_IR_SERVICE, consumerIr); 1008 traceEnd(); 1009 } 1010 1011 traceBeginAndSlog("StartAlarmManagerService"); 1012 mSystemServiceManager.startService(new AlarmManagerService(context)); 1013 traceEnd(); 1014 1015 traceBeginAndSlog("StartInputManagerService"); 1016 inputManager = new InputManagerService(context); 1017 traceEnd(); 1018 1019 traceBeginAndSlog("StartWindowManagerService"); 1020 // WMS needs sensor service ready 1021 ConcurrentUtils.waitForFutureNoInterrupt(mSensorServiceStart, START_SENSOR_SERVICE); 1022 mSensorServiceStart = null; 1023 wm = WindowManagerService.main(context, inputManager, !mFirstBoot, mOnlyCore, 1024 new PhoneWindowManager(), mActivityManagerService.mActivityTaskManager); 1025 ServiceManager.addService(Context.WINDOW_SERVICE, wm, /* allowIsolated= */ false, 1026 DUMP_FLAG_PRIORITY_CRITICAL | DUMP_FLAG_PROTO); 1027 ServiceManager.addService(Context.INPUT_SERVICE, inputManager, 1028 /* allowIsolated= */ false, DUMP_FLAG_PRIORITY_CRITICAL); 1029 traceEnd(); 1030 1031 traceBeginAndSlog("SetWindowManagerService"); 1032 mActivityManagerService.setWindowManager(wm); 1033 traceEnd(); 1034 1035 traceBeginAndSlog("WindowManagerServiceOnInitReady"); 1036 wm.onInitReady(); 1037 traceEnd(); 1038 1039 // Start receiving calls from HIDL services. Start in in a separate thread 1040 // because it need to connect to SensorManager. This have to start 1041 // after START_SENSOR_SERVICE is done. 1042 SystemServerInitThreadPool.get().submit(() -> { 1043 TimingsTraceLog traceLog = new TimingsTraceLog( 1044 SYSTEM_SERVER_TIMING_ASYNC_TAG, Trace.TRACE_TAG_SYSTEM_SERVER); 1045 traceLog.traceBegin(START_HIDL_SERVICES); 1046 startHidlServices(); 1047 traceLog.traceEnd(); 1048 }, START_HIDL_SERVICES); 1049 1050 if (!isWatch && enableVrService) { 1051 traceBeginAndSlog("StartVrManagerService"); 1052 mSystemServiceManager.startService(VrManagerService.class); 1053 traceEnd(); 1054 } 1055 1056 traceBeginAndSlog("StartInputManager"); 1057 inputManager.setWindowManagerCallbacks(wm.getInputManagerCallback()); 1058 inputManager.start(); 1059 traceEnd(); 1060 1061 // TODO: Use service dependencies instead. 1062 traceBeginAndSlog("DisplayManagerWindowManagerAndInputReady"); 1063 mDisplayManagerService.windowManagerAndInputReady(); 1064 traceEnd(); 1065 1066 if (mFactoryTestMode == FactoryTest.FACTORY_TEST_LOW_LEVEL) { 1067 Slog.i(TAG, "No Bluetooth Service (factory test)"); 1068 } else if (!context.getPackageManager().hasSystemFeature 1069 (PackageManager.FEATURE_BLUETOOTH)) { 1070 Slog.i(TAG, "No Bluetooth Service (Bluetooth Hardware Not Present)"); 1071 } else { 1072 traceBeginAndSlog("StartBluetoothService"); 1073 mSystemServiceManager.startService(BluetoothService.class); 1074 traceEnd(); 1075 } 1076 1077 traceBeginAndSlog("IpConnectivityMetrics"); 1078 mSystemServiceManager.startService(IpConnectivityMetrics.class); 1079 traceEnd(); 1080 1081 traceBeginAndSlog("NetworkWatchlistService"); 1082 mSystemServiceManager.startService(NetworkWatchlistService.Lifecycle.class); 1083 traceEnd(); 1084 1085 traceBeginAndSlog("PinnerService"); 1086 mSystemServiceManager.startService(PinnerService.class); 1087 traceEnd(); 1088 1089 traceBeginAndSlog("SignedConfigService"); 1090 SignedConfigService.registerUpdateReceiver(mSystemContext); 1091 traceEnd(); 1092 } catch (RuntimeException e) { 1093 Slog.e("System", "******************************************"); 1094 Slog.e("System", "************ Failure starting core service", e); 1095 } 1096 1097 // Before things start rolling, be sure we have decided whether 1098 // we are in safe mode. 1099 final boolean safeMode = wm.detectSafeMode(); 1100 if (safeMode) { 1101 // If yes, immediately turn on the global setting for airplane mode. 1102 // Note that this does not send broadcasts at this stage because 1103 // subsystems are not yet up. We will send broadcasts later to ensure 1104 // all listeners have the chance to react with special handling. 1105 Settings.Global.putInt(context.getContentResolver(), 1106 Settings.Global.AIRPLANE_MODE_ON, 1); 1107 } 1108 1109 StatusBarManagerService statusBar = null; 1110 INotificationManager notification = null; 1111 LocationManagerService location = null; 1112 CountryDetectorService countryDetector = null; 1113 ILockSettings lockSettings = null; 1114 MediaRouterService mediaRouter = null; 1115 1116 // Bring up services needed for UI. 1117 if (mFactoryTestMode != FactoryTest.FACTORY_TEST_LOW_LEVEL) { 1118 traceBeginAndSlog("StartInputMethodManagerLifecycle"); 1119 if (InputMethodSystemProperty.MULTI_CLIENT_IME_ENABLED) { 1120 mSystemServiceManager.startService( 1121 MultiClientInputMethodManagerService.Lifecycle.class); 1122 } else { 1123 mSystemServiceManager.startService(InputMethodManagerService.Lifecycle.class); 1124 } 1125 traceEnd(); 1126 1127 traceBeginAndSlog("StartAccessibilityManagerService"); 1128 try { 1129 mSystemServiceManager.startService(ACCESSIBILITY_MANAGER_SERVICE_CLASS); 1130 } catch (Throwable e) { 1131 reportWtf("starting Accessibility Manager", e); 1132 } 1133 traceEnd(); 1134 } 1135 1136 traceBeginAndSlog("MakeDisplayReady"); 1137 try { 1138 wm.displayReady(); 1139 } catch (Throwable e) { 1140 reportWtf("making display ready", e); 1141 } 1142 traceEnd(); 1143 1144 if (mFactoryTestMode != FactoryTest.FACTORY_TEST_LOW_LEVEL) { 1145 if (!"0".equals(SystemProperties.get("system_init.startmountservice"))) { 1146 traceBeginAndSlog("StartStorageManagerService"); 1147 try { 1148 /* 1149 * NotificationManagerService is dependant on StorageManagerService, 1150 * (for media / usb notifications) so we must start StorageManagerService first. 1151 */ 1152 mSystemServiceManager.startService(STORAGE_MANAGER_SERVICE_CLASS); 1153 storageManager = IStorageManager.Stub.asInterface( 1154 ServiceManager.getService("mount")); 1155 } catch (Throwable e) { 1156 reportWtf("starting StorageManagerService", e); 1157 } 1158 traceEnd(); 1159 1160 traceBeginAndSlog("StartStorageStatsService"); 1161 try { 1162 mSystemServiceManager.startService(STORAGE_STATS_SERVICE_CLASS); 1163 } catch (Throwable e) { 1164 reportWtf("starting StorageStatsService", e); 1165 } 1166 traceEnd(); 1167 } 1168 } 1169 1170 // We start this here so that we update our configuration to set watch or television 1171 // as appropriate. 1172 traceBeginAndSlog("StartUiModeManager"); 1173 mSystemServiceManager.startService(UiModeManagerService.class); 1174 traceEnd(); 1175 1176 if (!mOnlyCore) { 1177 traceBeginAndSlog("UpdatePackagesIfNeeded"); 1178 try { 1179 Watchdog.getInstance().pauseWatchingCurrentThread("dexopt"); 1180 mPackageManagerService.updatePackagesIfNeeded(); 1181 } catch (Throwable e) { 1182 reportWtf("update packages", e); 1183 } finally { 1184 Watchdog.getInstance().resumeWatchingCurrentThread("dexopt"); 1185 } 1186 traceEnd(); 1187 } 1188 1189 traceBeginAndSlog("PerformFstrimIfNeeded"); 1190 try { 1191 mPackageManagerService.performFstrimIfNeeded(); 1192 } catch (Throwable e) { 1193 reportWtf("performing fstrim", e); 1194 } 1195 traceEnd(); 1196 1197 if (mFactoryTestMode != FactoryTest.FACTORY_TEST_LOW_LEVEL) { 1198 traceBeginAndSlog("StartLockSettingsService"); 1199 try { 1200 mSystemServiceManager.startService(LOCK_SETTINGS_SERVICE_CLASS); 1201 lockSettings = ILockSettings.Stub.asInterface( 1202 ServiceManager.getService("lock_settings")); 1203 } catch (Throwable e) { 1204 reportWtf("starting LockSettingsService service", e); 1205 } 1206 traceEnd(); 1207 1208 final boolean hasPdb = !SystemProperties.get(PERSISTENT_DATA_BLOCK_PROP).equals(""); 1209 final boolean hasGsi = SystemProperties.getInt(GSI_RUNNING_PROP, 0) > 0; 1210 if (hasPdb && !hasGsi) { 1211 traceBeginAndSlog("StartPersistentDataBlock"); 1212 mSystemServiceManager.startService(PersistentDataBlockService.class); 1213 traceEnd(); 1214 } 1215 1216 traceBeginAndSlog("StartTestHarnessMode"); 1217 mSystemServiceManager.startService(TestHarnessModeService.class); 1218 traceEnd(); 1219 1220 if (hasPdb || OemLockService.isHalPresent()) { 1221 // Implementation depends on pdb or the OemLock HAL 1222 traceBeginAndSlog("StartOemLockService"); 1223 mSystemServiceManager.startService(OemLockService.class); 1224 traceEnd(); 1225 } 1226 1227 traceBeginAndSlog("StartDeviceIdleController"); 1228 mSystemServiceManager.startService(DeviceIdleController.class); 1229 traceEnd(); 1230 1231 // Always start the Device Policy Manager, so that the API is compatible with 1232 // API8. 1233 traceBeginAndSlog("StartDevicePolicyManager"); 1234 mSystemServiceManager.startService(DevicePolicyManagerService.Lifecycle.class); 1235 traceEnd(); 1236 1237 if (!isWatch) { 1238 traceBeginAndSlog("StartStatusBarManagerService"); 1239 try { 1240 statusBar = new StatusBarManagerService(context, wm); 1241 ServiceManager.addService(Context.STATUS_BAR_SERVICE, statusBar); 1242 } catch (Throwable e) { 1243 reportWtf("starting StatusBarManagerService", e); 1244 } 1245 traceEnd(); 1246 } 1247 1248 startContentCaptureService(context); 1249 startAttentionService(context); 1250 1251 startSystemCaptionsManagerService(context); 1252 1253 // App prediction manager service 1254 traceBeginAndSlog("StartAppPredictionService"); 1255 mSystemServiceManager.startService(APP_PREDICTION_MANAGER_SERVICE_CLASS); 1256 traceEnd(); 1257 1258 // Content suggestions manager service 1259 traceBeginAndSlog("StartContentSuggestionsService"); 1260 mSystemServiceManager.startService(CONTENT_SUGGESTIONS_SERVICE_CLASS); 1261 traceEnd(); 1262 1263 traceBeginAndSlog("InitNetworkStackClient"); 1264 try { 1265 NetworkStackClient.getInstance().init(); 1266 } catch (Throwable e) { 1267 reportWtf("initializing NetworkStackClient", e); 1268 } 1269 traceEnd(); 1270 1271 traceBeginAndSlog("StartNetworkManagementService"); 1272 try { 1273 networkManagement = NetworkManagementService.create(context); 1274 ServiceManager.addService(Context.NETWORKMANAGEMENT_SERVICE, networkManagement); 1275 } catch (Throwable e) { 1276 reportWtf("starting NetworkManagement Service", e); 1277 } 1278 traceEnd(); 1279 1280 1281 traceBeginAndSlog("StartIpSecService"); 1282 try { 1283 ipSecService = IpSecService.create(context); 1284 ServiceManager.addService(Context.IPSEC_SERVICE, ipSecService); 1285 } catch (Throwable e) { 1286 reportWtf("starting IpSec Service", e); 1287 } 1288 traceEnd(); 1289 1290 traceBeginAndSlog("StartTextServicesManager"); 1291 mSystemServiceManager.startService(TextServicesManagerService.Lifecycle.class); 1292 traceEnd(); 1293 1294 if (!disableSystemTextClassifier) { 1295 traceBeginAndSlog("StartTextClassificationManagerService"); 1296 mSystemServiceManager 1297 .startService(TextClassificationManagerService.Lifecycle.class); 1298 traceEnd(); 1299 } 1300 1301 traceBeginAndSlog("StartNetworkScoreService"); 1302 mSystemServiceManager.startService(NetworkScoreService.Lifecycle.class); 1303 traceEnd(); 1304 1305 traceBeginAndSlog("StartNetworkStatsService"); 1306 try { 1307 networkStats = NetworkStatsService.create(context, networkManagement); 1308 ServiceManager.addService(Context.NETWORK_STATS_SERVICE, networkStats); 1309 } catch (Throwable e) { 1310 reportWtf("starting NetworkStats Service", e); 1311 } 1312 traceEnd(); 1313 1314 traceBeginAndSlog("StartNetworkPolicyManagerService"); 1315 try { 1316 networkPolicy = new NetworkPolicyManagerService(context, mActivityManagerService, 1317 networkManagement); 1318 ServiceManager.addService(Context.NETWORK_POLICY_SERVICE, networkPolicy); 1319 } catch (Throwable e) { 1320 reportWtf("starting NetworkPolicy Service", e); 1321 } 1322 traceEnd(); 1323 1324 if (context.getPackageManager().hasSystemFeature( 1325 PackageManager.FEATURE_WIFI)) { 1326 // Wifi Service must be started first for wifi-related services. 1327 traceBeginAndSlog("StartWifi"); 1328 mSystemServiceManager.startService(WIFI_SERVICE_CLASS); 1329 traceEnd(); 1330 traceBeginAndSlog("StartWifiScanning"); 1331 mSystemServiceManager.startService( 1332 "com.android.server.wifi.scanner.WifiScanningService"); 1333 traceEnd(); 1334 } 1335 1336 if (context.getPackageManager().hasSystemFeature( 1337 PackageManager.FEATURE_WIFI_RTT)) { 1338 traceBeginAndSlog("StartRttService"); 1339 mSystemServiceManager.startService( 1340 "com.android.server.wifi.rtt.RttService"); 1341 traceEnd(); 1342 } 1343 1344 if (context.getPackageManager().hasSystemFeature( 1345 PackageManager.FEATURE_WIFI_AWARE)) { 1346 traceBeginAndSlog("StartWifiAware"); 1347 mSystemServiceManager.startService(WIFI_AWARE_SERVICE_CLASS); 1348 traceEnd(); 1349 } 1350 1351 if (context.getPackageManager().hasSystemFeature( 1352 PackageManager.FEATURE_WIFI_DIRECT)) { 1353 traceBeginAndSlog("StartWifiP2P"); 1354 mSystemServiceManager.startService(WIFI_P2P_SERVICE_CLASS); 1355 traceEnd(); 1356 } 1357 1358 if (context.getPackageManager().hasSystemFeature( 1359 PackageManager.FEATURE_LOWPAN)) { 1360 traceBeginAndSlog("StartLowpan"); 1361 mSystemServiceManager.startService(LOWPAN_SERVICE_CLASS); 1362 traceEnd(); 1363 } 1364 1365 if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_ETHERNET) || 1366 mPackageManager.hasSystemFeature(PackageManager.FEATURE_USB_HOST)) { 1367 traceBeginAndSlog("StartEthernet"); 1368 mSystemServiceManager.startService(ETHERNET_SERVICE_CLASS); 1369 traceEnd(); 1370 } 1371 1372 traceBeginAndSlog("StartConnectivityService"); 1373 try { 1374 connectivity = new ConnectivityService( 1375 context, networkManagement, networkStats, networkPolicy); 1376 ServiceManager.addService(Context.CONNECTIVITY_SERVICE, connectivity, 1377 /* allowIsolated= */ false, 1378 DUMP_FLAG_PRIORITY_HIGH | DUMP_FLAG_PRIORITY_NORMAL); 1379 networkPolicy.bindConnectivityManager(connectivity); 1380 } catch (Throwable e) { 1381 reportWtf("starting Connectivity Service", e); 1382 } 1383 traceEnd(); 1384 1385 traceBeginAndSlog("StartNsdService"); 1386 try { 1387 serviceDiscovery = NsdService.create(context); 1388 ServiceManager.addService( 1389 Context.NSD_SERVICE, serviceDiscovery); 1390 } catch (Throwable e) { 1391 reportWtf("starting Service Discovery Service", e); 1392 } 1393 traceEnd(); 1394 1395 traceBeginAndSlog("StartSystemUpdateManagerService"); 1396 try { 1397 ServiceManager.addService(Context.SYSTEM_UPDATE_SERVICE, 1398 new SystemUpdateManagerService(context)); 1399 } catch (Throwable e) { 1400 reportWtf("starting SystemUpdateManagerService", e); 1401 } 1402 traceEnd(); 1403 1404 traceBeginAndSlog("StartUpdateLockService"); 1405 try { 1406 ServiceManager.addService(Context.UPDATE_LOCK_SERVICE, 1407 new UpdateLockService(context)); 1408 } catch (Throwable e) { 1409 reportWtf("starting UpdateLockService", e); 1410 } 1411 traceEnd(); 1412 1413 traceBeginAndSlog("StartNotificationManager"); 1414 mSystemServiceManager.startService(NotificationManagerService.class); 1415 SystemNotificationChannels.removeDeprecated(context); 1416 SystemNotificationChannels.createAll(context); 1417 notification = INotificationManager.Stub.asInterface( 1418 ServiceManager.getService(Context.NOTIFICATION_SERVICE)); 1419 traceEnd(); 1420 1421 traceBeginAndSlog("StartDeviceMonitor"); 1422 mSystemServiceManager.startService(DeviceStorageMonitorService.class); 1423 traceEnd(); 1424 1425 traceBeginAndSlog("StartLocationManagerService"); 1426 try { 1427 location = new LocationManagerService(context); 1428 ServiceManager.addService(Context.LOCATION_SERVICE, location); 1429 } catch (Throwable e) { 1430 reportWtf("starting Location Manager", e); 1431 } 1432 traceEnd(); 1433 1434 traceBeginAndSlog("StartCountryDetectorService"); 1435 try { 1436 countryDetector = new CountryDetectorService(context); 1437 ServiceManager.addService(Context.COUNTRY_DETECTOR, countryDetector); 1438 } catch (Throwable e) { 1439 reportWtf("starting Country Detector", e); 1440 } 1441 traceEnd(); 1442 1443 final boolean useNewTimeServices = true; 1444 if (useNewTimeServices) { 1445 traceBeginAndSlog("StartTimeDetectorService"); 1446 try { 1447 mSystemServiceManager.startService(TIME_DETECTOR_SERVICE_CLASS); 1448 } catch (Throwable e) { 1449 reportWtf("starting StartTimeDetectorService service", e); 1450 } 1451 traceEnd(); 1452 } 1453 1454 if (!isWatch) { 1455 traceBeginAndSlog("StartSearchManagerService"); 1456 try { 1457 mSystemServiceManager.startService(SEARCH_MANAGER_SERVICE_CLASS); 1458 } catch (Throwable e) { 1459 reportWtf("starting Search Service", e); 1460 } 1461 traceEnd(); 1462 } 1463 1464 if (context.getResources().getBoolean(R.bool.config_enableWallpaperService)) { 1465 traceBeginAndSlog("StartWallpaperManagerService"); 1466 mSystemServiceManager.startService(WALLPAPER_SERVICE_CLASS); 1467 traceEnd(); 1468 } 1469 1470 traceBeginAndSlog("StartAudioService"); 1471 if (!isArc) { 1472 mSystemServiceManager.startService(AudioService.Lifecycle.class); 1473 } else { 1474 String className = context.getResources() 1475 .getString(R.string.config_deviceSpecificAudioService); 1476 try { 1477 mSystemServiceManager.startService(className + "$Lifecycle"); 1478 } catch (Throwable e) { 1479 reportWtf("starting " + className, e); 1480 } 1481 } 1482 traceEnd(); 1483 1484 if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_BROADCAST_RADIO)) { 1485 traceBeginAndSlog("StartBroadcastRadioService"); 1486 mSystemServiceManager.startService(BroadcastRadioService.class); 1487 traceEnd(); 1488 } 1489 1490 traceBeginAndSlog("StartDockObserver"); 1491 mSystemServiceManager.startService(DockObserver.class); 1492 traceEnd(); 1493 1494 if (isWatch) { 1495 traceBeginAndSlog("StartThermalObserver"); 1496 mSystemServiceManager.startService(THERMAL_OBSERVER_CLASS); 1497 traceEnd(); 1498 } 1499 1500 traceBeginAndSlog("StartWiredAccessoryManager"); 1501 try { 1502 // Listen for wired headset changes 1503 inputManager.setWiredAccessoryCallbacks( 1504 new WiredAccessoryManager(context, inputManager)); 1505 } catch (Throwable e) { 1506 reportWtf("starting WiredAccessoryManager", e); 1507 } 1508 traceEnd(); 1509 1510 if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_MIDI)) { 1511 // Start MIDI Manager service 1512 traceBeginAndSlog("StartMidiManager"); 1513 mSystemServiceManager.startService(MIDI_SERVICE_CLASS); 1514 traceEnd(); 1515 } 1516 1517 // Start ADB Debugging Service 1518 traceBeginAndSlog("StartAdbService"); 1519 try { 1520 mSystemServiceManager.startService(ADB_SERVICE_CLASS); 1521 } catch (Throwable e) { 1522 Slog.e(TAG, "Failure starting AdbService"); 1523 } 1524 traceEnd(); 1525 1526 if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_USB_HOST) 1527 || mPackageManager.hasSystemFeature( 1528 PackageManager.FEATURE_USB_ACCESSORY) 1529 || isEmulator) { 1530 // Manage USB host and device support 1531 traceBeginAndSlog("StartUsbService"); 1532 mSystemServiceManager.startService(USB_SERVICE_CLASS); 1533 traceEnd(); 1534 } 1535 1536 if (!isWatch) { 1537 traceBeginAndSlog("StartSerialService"); 1538 try { 1539 // Serial port support 1540 serial = new SerialService(context); 1541 ServiceManager.addService(Context.SERIAL_SERVICE, serial); 1542 } catch (Throwable e) { 1543 Slog.e(TAG, "Failure starting SerialService", e); 1544 } 1545 traceEnd(); 1546 } 1547 1548 traceBeginAndSlog("StartHardwarePropertiesManagerService"); 1549 try { 1550 hardwarePropertiesService = new HardwarePropertiesManagerService(context); 1551 ServiceManager.addService(Context.HARDWARE_PROPERTIES_SERVICE, 1552 hardwarePropertiesService); 1553 } catch (Throwable e) { 1554 Slog.e(TAG, "Failure starting HardwarePropertiesManagerService", e); 1555 } 1556 traceEnd(); 1557 1558 traceBeginAndSlog("StartTwilightService"); 1559 mSystemServiceManager.startService(TwilightService.class); 1560 traceEnd(); 1561 1562 traceBeginAndSlog("StartColorDisplay"); 1563 mSystemServiceManager.startService(ColorDisplayService.class); 1564 traceEnd(); 1565 1566 traceBeginAndSlog("StartJobScheduler"); 1567 mSystemServiceManager.startService(JobSchedulerService.class); 1568 traceEnd(); 1569 1570 traceBeginAndSlog("StartSoundTrigger"); 1571 mSystemServiceManager.startService(SoundTriggerService.class); 1572 traceEnd(); 1573 1574 traceBeginAndSlog("StartTrustManager"); 1575 mSystemServiceManager.startService(TrustManagerService.class); 1576 traceEnd(); 1577 1578 if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_BACKUP)) { 1579 traceBeginAndSlog("StartBackupManager"); 1580 mSystemServiceManager.startService(BACKUP_MANAGER_SERVICE_CLASS); 1581 traceEnd(); 1582 } 1583 1584 if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_APP_WIDGETS) 1585 || context.getResources().getBoolean(R.bool.config_enableAppWidgetService)) { 1586 traceBeginAndSlog("StartAppWidgetService"); 1587 mSystemServiceManager.startService(APPWIDGET_SERVICE_CLASS); 1588 traceEnd(); 1589 } 1590 1591 // Grants default permissions and defines roles 1592 traceBeginAndSlog("StartRoleManagerService"); 1593 mSystemServiceManager.startService(new RoleManagerService( 1594 mSystemContext, new LegacyRoleResolutionPolicy(mSystemContext))); 1595 traceEnd(); 1596 1597 // We need to always start this service, regardless of whether the 1598 // FEATURE_VOICE_RECOGNIZERS feature is set, because it needs to take care 1599 // of initializing various settings. It will internally modify its behavior 1600 // based on that feature. 1601 traceBeginAndSlog("StartVoiceRecognitionManager"); 1602 mSystemServiceManager.startService(VOICE_RECOGNITION_MANAGER_SERVICE_CLASS); 1603 traceEnd(); 1604 1605 if (GestureLauncherService.isGestureLauncherEnabled(context.getResources())) { 1606 traceBeginAndSlog("StartGestureLauncher"); 1607 mSystemServiceManager.startService(GestureLauncherService.class); 1608 traceEnd(); 1609 } 1610 traceBeginAndSlog("StartSensorNotification"); 1611 mSystemServiceManager.startService(SensorNotificationService.class); 1612 traceEnd(); 1613 1614 traceBeginAndSlog("StartContextHubSystemService"); 1615 mSystemServiceManager.startService(ContextHubSystemService.class); 1616 traceEnd(); 1617 1618 traceBeginAndSlog("StartDiskStatsService"); 1619 try { 1620 ServiceManager.addService("diskstats", new DiskStatsService(context)); 1621 } catch (Throwable e) { 1622 reportWtf("starting DiskStats Service", e); 1623 } 1624 traceEnd(); 1625 1626 traceBeginAndSlog("RuntimeService"); 1627 try { 1628 ServiceManager.addService("runtime", new RuntimeService(context)); 1629 } catch (Throwable e) { 1630 reportWtf("starting RuntimeService", e); 1631 } 1632 traceEnd(); 1633 1634 // timezone.RulesManagerService will prevent a device starting up if the chain of trust 1635 // required for safe time zone updates might be broken. RuleManagerService cannot do 1636 // this check when mOnlyCore == true, so we don't enable the service in this case. 1637 // This service requires that JobSchedulerService is already started when it starts. 1638 final boolean startRulesManagerService = 1639 !mOnlyCore && context.getResources().getBoolean( 1640 R.bool.config_enableUpdateableTimeZoneRules); 1641 if (startRulesManagerService) { 1642 traceBeginAndSlog("StartTimeZoneRulesManagerService"); 1643 mSystemServiceManager.startService(TIME_ZONE_RULES_MANAGER_SERVICE_CLASS); 1644 traceEnd(); 1645 } 1646 1647 if (!isWatch && !disableNetworkTime) { 1648 traceBeginAndSlog("StartNetworkTimeUpdateService"); 1649 try { 1650 if (useNewTimeServices) { 1651 networkTimeUpdater = new NewNetworkTimeUpdateService(context); 1652 } else { 1653 networkTimeUpdater = new OldNetworkTimeUpdateService(context); 1654 } 1655 Slog.d(TAG, "Using networkTimeUpdater class=" + networkTimeUpdater.getClass()); 1656 ServiceManager.addService("network_time_update_service", networkTimeUpdater); 1657 } catch (Throwable e) { 1658 reportWtf("starting NetworkTimeUpdate service", e); 1659 } 1660 traceEnd(); 1661 } 1662 1663 traceBeginAndSlog("CertBlacklister"); 1664 try { 1665 CertBlacklister blacklister = new CertBlacklister(context); 1666 } catch (Throwable e) { 1667 reportWtf("starting CertBlacklister", e); 1668 } 1669 traceEnd(); 1670 1671 if (EmergencyAffordanceManager.ENABLED) { 1672 // EmergencyMode service 1673 traceBeginAndSlog("StartEmergencyAffordanceService"); 1674 mSystemServiceManager.startService(EmergencyAffordanceService.class); 1675 traceEnd(); 1676 } 1677 1678 // Dreams (interactive idle-time views, a/k/a screen savers, and doze mode) 1679 traceBeginAndSlog("StartDreamManager"); 1680 mSystemServiceManager.startService(DreamManagerService.class); 1681 traceEnd(); 1682 1683 traceBeginAndSlog("AddGraphicsStatsService"); 1684 ServiceManager.addService(GraphicsStatsService.GRAPHICS_STATS_SERVICE, 1685 new GraphicsStatsService(context)); 1686 traceEnd(); 1687 1688 if (CoverageService.ENABLED) { 1689 traceBeginAndSlog("AddCoverageService"); 1690 ServiceManager.addService(CoverageService.COVERAGE_SERVICE, new CoverageService()); 1691 traceEnd(); 1692 } 1693 1694 if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_PRINTING)) { 1695 traceBeginAndSlog("StartPrintManager"); 1696 mSystemServiceManager.startService(PRINT_MANAGER_SERVICE_CLASS); 1697 traceEnd(); 1698 } 1699 1700 if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_COMPANION_DEVICE_SETUP)) { 1701 traceBeginAndSlog("StartCompanionDeviceManager"); 1702 mSystemServiceManager.startService(COMPANION_DEVICE_MANAGER_SERVICE_CLASS); 1703 traceEnd(); 1704 } 1705 1706 traceBeginAndSlog("StartRestrictionManager"); 1707 mSystemServiceManager.startService(RestrictionsManagerService.class); 1708 traceEnd(); 1709 1710 traceBeginAndSlog("StartMediaSessionService"); 1711 mSystemServiceManager.startService(MediaSessionService.class); 1712 traceEnd(); 1713 1714 if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_HDMI_CEC)) { 1715 traceBeginAndSlog("StartHdmiControlService"); 1716 mSystemServiceManager.startService(HdmiControlService.class); 1717 traceEnd(); 1718 } 1719 1720 if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_LIVE_TV) 1721 || mPackageManager.hasSystemFeature(PackageManager.FEATURE_LEANBACK)) { 1722 traceBeginAndSlog("StartTvInputManager"); 1723 mSystemServiceManager.startService(TvInputManagerService.class); 1724 traceEnd(); 1725 } 1726 1727 if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_PICTURE_IN_PICTURE)) { 1728 traceBeginAndSlog("StartMediaResourceMonitor"); 1729 mSystemServiceManager.startService(MediaResourceMonitorService.class); 1730 traceEnd(); 1731 } 1732 1733 if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_LEANBACK)) { 1734 traceBeginAndSlog("StartTvRemoteService"); 1735 mSystemServiceManager.startService(TvRemoteService.class); 1736 traceEnd(); 1737 } 1738 1739 traceBeginAndSlog("StartMediaRouterService"); 1740 try { 1741 mediaRouter = new MediaRouterService(context); 1742 ServiceManager.addService(Context.MEDIA_ROUTER_SERVICE, mediaRouter); 1743 } catch (Throwable e) { 1744 reportWtf("starting MediaRouterService", e); 1745 } 1746 traceEnd(); 1747 1748 final boolean hasFeatureFace 1749 = mPackageManager.hasSystemFeature(PackageManager.FEATURE_FACE); 1750 final boolean hasFeatureIris 1751 = mPackageManager.hasSystemFeature(PackageManager.FEATURE_IRIS); 1752 final boolean hasFeatureFingerprint 1753 = mPackageManager.hasSystemFeature(PackageManager.FEATURE_FINGERPRINT); 1754 1755 if (hasFeatureFace) { 1756 traceBeginAndSlog("StartFaceSensor"); 1757 mSystemServiceManager.startService(FaceService.class); 1758 traceEnd(); 1759 } 1760 1761 if (hasFeatureIris) { 1762 traceBeginAndSlog("StartIrisSensor"); 1763 mSystemServiceManager.startService(IrisService.class); 1764 traceEnd(); 1765 } 1766 1767 if (hasFeatureFingerprint) { 1768 traceBeginAndSlog("StartFingerprintSensor"); 1769 mSystemServiceManager.startService(FingerprintService.class); 1770 traceEnd(); 1771 } 1772 1773 if (hasFeatureFace || hasFeatureIris || hasFeatureFingerprint) { 1774 // Start this service after all biometric services. 1775 traceBeginAndSlog("StartBiometricService"); 1776 mSystemServiceManager.startService(BiometricService.class); 1777 traceEnd(); 1778 } 1779 1780 traceBeginAndSlog("StartBackgroundDexOptService"); 1781 try { 1782 BackgroundDexOptService.schedule(context); 1783 } catch (Throwable e) { 1784 reportWtf("starting StartBackgroundDexOptService", e); 1785 } 1786 traceEnd(); 1787 1788 if (!isWatch) { 1789 // We don't run this on watches as there are no plans to use the data logged 1790 // on watch devices. 1791 traceBeginAndSlog("StartDynamicCodeLoggingService"); 1792 try { 1793 DynamicCodeLoggingService.schedule(context); 1794 } catch (Throwable e) { 1795 reportWtf("starting DynamicCodeLoggingService", e); 1796 } 1797 traceEnd(); 1798 } 1799 1800 if (!isWatch) { 1801 traceBeginAndSlog("StartPruneInstantAppsJobService"); 1802 try { 1803 PruneInstantAppsJobService.schedule(context); 1804 } catch (Throwable e) { 1805 reportWtf("StartPruneInstantAppsJobService", e); 1806 } 1807 traceEnd(); 1808 } 1809 1810 // LauncherAppsService uses ShortcutService. 1811 traceBeginAndSlog("StartShortcutServiceLifecycle"); 1812 mSystemServiceManager.startService(ShortcutService.Lifecycle.class); 1813 traceEnd(); 1814 1815 traceBeginAndSlog("StartLauncherAppsService"); 1816 mSystemServiceManager.startService(LauncherAppsService.class); 1817 traceEnd(); 1818 1819 traceBeginAndSlog("StartCrossProfileAppsService"); 1820 mSystemServiceManager.startService(CrossProfileAppsService.class); 1821 traceEnd(); 1822 } 1823 1824 if (!isWatch) { 1825 traceBeginAndSlog("StartMediaProjectionManager"); 1826 mSystemServiceManager.startService(MediaProjectionManagerService.class); 1827 traceEnd(); 1828 } 1829 1830 if (isWatch) { 1831 // Must be started before services that depend it, e.g. WearConnectivityService 1832 traceBeginAndSlog("StartWearPowerService"); 1833 mSystemServiceManager.startService(WEAR_POWER_SERVICE_CLASS); 1834 traceEnd(); 1835 1836 traceBeginAndSlog("StartWearConnectivityService"); 1837 mSystemServiceManager.startService(WEAR_CONNECTIVITY_SERVICE_CLASS); 1838 traceEnd(); 1839 1840 traceBeginAndSlog("StartWearDisplayService"); 1841 mSystemServiceManager.startService(WEAR_DISPLAY_SERVICE_CLASS); 1842 traceEnd(); 1843 1844 traceBeginAndSlog("StartWearTimeService"); 1845 mSystemServiceManager.startService(WEAR_TIME_SERVICE_CLASS); 1846 traceEnd(); 1847 1848 if (enableLeftyService) { 1849 traceBeginAndSlog("StartWearLeftyService"); 1850 mSystemServiceManager.startService(WEAR_LEFTY_SERVICE_CLASS); 1851 traceEnd(); 1852 } 1853 1854 traceBeginAndSlog("StartWearGlobalActionsService"); 1855 mSystemServiceManager.startService(WEAR_GLOBAL_ACTIONS_SERVICE_CLASS); 1856 traceEnd(); 1857 } 1858 1859 if (!disableSlices) { 1860 traceBeginAndSlog("StartSliceManagerService"); 1861 mSystemServiceManager.startService(SLICE_MANAGER_SERVICE_CLASS); 1862 traceEnd(); 1863 } 1864 1865 if (!disableCameraService) { 1866 traceBeginAndSlog("StartCameraServiceProxy"); 1867 mSystemServiceManager.startService(CameraServiceProxy.class); 1868 traceEnd(); 1869 } 1870 1871 if (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_EMBEDDED)) { 1872 traceBeginAndSlog("StartIoTSystemService"); 1873 mSystemServiceManager.startService(IOT_SERVICE_CLASS); 1874 traceEnd(); 1875 } 1876 1877 // Statsd helper 1878 traceBeginAndSlog("StartStatsCompanionService"); 1879 mSystemServiceManager.startService(StatsCompanionService.Lifecycle.class); 1880 traceEnd(); 1881 1882 // Incidentd and dumpstated helper 1883 traceBeginAndSlog("StartIncidentCompanionService"); 1884 mSystemServiceManager.startService(IncidentCompanionService.class); 1885 traceEnd(); 1886 1887 if (safeMode) { 1888 mActivityManagerService.enterSafeMode(); 1889 } 1890 1891 // MMS service broker 1892 traceBeginAndSlog("StartMmsService"); 1893 mmsService = mSystemServiceManager.startService(MmsServiceBroker.class); 1894 traceEnd(); 1895 1896 if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_AUTOFILL)) { 1897 traceBeginAndSlog("StartAutoFillService"); 1898 mSystemServiceManager.startService(AUTO_FILL_MANAGER_SERVICE_CLASS); 1899 traceEnd(); 1900 } 1901 1902 // NOTE: ClipboardService depends on ContentCapture and Autofill 1903 traceBeginAndSlog("StartClipboardService"); 1904 mSystemServiceManager.startService(ClipboardService.class); 1905 traceEnd(); 1906 1907 traceBeginAndSlog("AppServiceManager"); 1908 mSystemServiceManager.startService(AppBindingService.Lifecycle.class); 1909 traceEnd(); 1910 1911 // It is now time to start up the app processes... 1912 1913 traceBeginAndSlog("MakeVibratorServiceReady"); 1914 try { 1915 vibrator.systemReady(); 1916 } catch (Throwable e) { 1917 reportWtf("making Vibrator Service ready", e); 1918 } 1919 traceEnd(); 1920 1921 traceBeginAndSlog("MakeLockSettingsServiceReady"); 1922 if (lockSettings != null) { 1923 try { 1924 lockSettings.systemReady(); 1925 } catch (Throwable e) { 1926 reportWtf("making Lock Settings Service ready", e); 1927 } 1928 } 1929 traceEnd(); 1930 1931 // Needed by DevicePolicyManager for initialization 1932 traceBeginAndSlog("StartBootPhaseLockSettingsReady"); 1933 mSystemServiceManager.startBootPhase(SystemService.PHASE_LOCK_SETTINGS_READY); 1934 traceEnd(); 1935 1936 traceBeginAndSlog("StartBootPhaseSystemServicesReady"); 1937 mSystemServiceManager.startBootPhase(SystemService.PHASE_SYSTEM_SERVICES_READY); 1938 traceEnd(); 1939 1940 traceBeginAndSlog("MakeWindowManagerServiceReady"); 1941 try { 1942 wm.systemReady(); 1943 } catch (Throwable e) { 1944 reportWtf("making Window Manager Service ready", e); 1945 } 1946 traceEnd(); 1947 1948 if (safeMode) { 1949 mActivityManagerService.showSafeModeOverlay(); 1950 } 1951 1952 // Update the configuration for this context by hand, because we're going 1953 // to start using it before the config change done in wm.systemReady() will 1954 // propagate to it. 1955 final Configuration config = wm.computeNewConfiguration(DEFAULT_DISPLAY); 1956 DisplayMetrics metrics = new DisplayMetrics(); 1957 WindowManager w = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); 1958 w.getDefaultDisplay().getMetrics(metrics); 1959 context.getResources().updateConfiguration(config, metrics); 1960 1961 // The system context's theme may be configuration-dependent. 1962 final Theme systemTheme = context.getTheme(); 1963 if (systemTheme.getChangingConfigurations() != 0) { 1964 systemTheme.rebase(); 1965 } 1966 1967 traceBeginAndSlog("MakePowerManagerServiceReady"); 1968 try { 1969 // TODO: use boot phase 1970 mPowerManagerService.systemReady(mActivityManagerService.getAppOpsService()); 1971 } catch (Throwable e) { 1972 reportWtf("making Power Manager Service ready", e); 1973 } 1974 traceEnd(); 1975 1976 // Permission policy service 1977 traceBeginAndSlog("StartPermissionPolicyService"); 1978 mSystemServiceManager.startService(PermissionPolicyService.class); 1979 traceEnd(); 1980 1981 traceBeginAndSlog("MakePackageManagerServiceReady"); 1982 mPackageManagerService.systemReady(); 1983 traceEnd(); 1984 1985 traceBeginAndSlog("MakeDisplayManagerServiceReady"); 1986 try { 1987 // TODO: use boot phase and communicate these flags some other way 1988 mDisplayManagerService.systemReady(safeMode, mOnlyCore); 1989 } catch (Throwable e) { 1990 reportWtf("making Display Manager Service ready", e); 1991 } 1992 traceEnd(); 1993 1994 mSystemServiceManager.setSafeMode(safeMode); 1995 1996 // Start device specific services 1997 traceBeginAndSlog("StartDeviceSpecificServices"); 1998 final String[] classes = mSystemContext.getResources().getStringArray( 1999 R.array.config_deviceSpecificSystemServices); 2000 for (final String className : classes) { 2001 traceBeginAndSlog("StartDeviceSpecificServices " + className); 2002 try { 2003 mSystemServiceManager.startService(className); 2004 } catch (Throwable e) { 2005 reportWtf("starting " + className, e); 2006 } 2007 traceEnd(); 2008 } 2009 traceEnd(); 2010 2011 traceBeginAndSlog("StartBootPhaseDeviceSpecificServicesReady"); 2012 mSystemServiceManager.startBootPhase(SystemService.PHASE_DEVICE_SPECIFIC_SERVICES_READY); 2013 traceEnd(); 2014 2015 // These are needed to propagate to the runnable below. 2016 final NetworkManagementService networkManagementF = networkManagement; 2017 final NetworkStatsService networkStatsF = networkStats; 2018 final NetworkPolicyManagerService networkPolicyF = networkPolicy; 2019 final ConnectivityService connectivityF = connectivity; 2020 final LocationManagerService locationF = location; 2021 final CountryDetectorService countryDetectorF = countryDetector; 2022 final NetworkTimeUpdateService networkTimeUpdaterF = networkTimeUpdater; 2023 final InputManagerService inputManagerF = inputManager; 2024 final TelephonyRegistry telephonyRegistryF = telephonyRegistry; 2025 final MediaRouterService mediaRouterF = mediaRouter; 2026 final MmsServiceBroker mmsServiceF = mmsService; 2027 final IpSecService ipSecServiceF = ipSecService; 2028 final WindowManagerService windowManagerF = wm; 2029 2030 // We now tell the activity manager it is okay to run third party 2031 // code. It will call back into us once it has gotten to the state 2032 // where third party code can really run (but before it has actually 2033 // started launching the initial applications), for us to complete our 2034 // initialization. 2035 mActivityManagerService.systemReady(() -> { 2036 Slog.i(TAG, "Making services ready"); 2037 traceBeginAndSlog("StartActivityManagerReadyPhase"); 2038 mSystemServiceManager.startBootPhase( 2039 SystemService.PHASE_ACTIVITY_MANAGER_READY); 2040 traceEnd(); 2041 traceBeginAndSlog("StartObservingNativeCrashes"); 2042 try { 2043 mActivityManagerService.startObservingNativeCrashes(); 2044 } catch (Throwable e) { 2045 reportWtf("observing native crashes", e); 2046 } 2047 traceEnd(); 2048 2049 // No dependency on Webview preparation in system server. But this should 2050 // be completed before allowing 3rd party 2051 final String WEBVIEW_PREPARATION = "WebViewFactoryPreparation"; 2052 Future<?> webviewPrep = null; 2053 if (!mOnlyCore && mWebViewUpdateService != null) { 2054 webviewPrep = SystemServerInitThreadPool.get().submit(() -> { 2055 Slog.i(TAG, WEBVIEW_PREPARATION); 2056 TimingsTraceLog traceLog = new TimingsTraceLog( 2057 SYSTEM_SERVER_TIMING_ASYNC_TAG, Trace.TRACE_TAG_SYSTEM_SERVER); 2058 traceLog.traceBegin(WEBVIEW_PREPARATION); 2059 ConcurrentUtils.waitForFutureNoInterrupt(mZygotePreload, "Zygote preload"); 2060 mZygotePreload = null; 2061 mWebViewUpdateService.prepareWebViewInSystemServer(); 2062 traceLog.traceEnd(); 2063 }, WEBVIEW_PREPARATION); 2064 } 2065 2066 if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_AUTOMOTIVE)) { 2067 traceBeginAndSlog("StartCarServiceHelperService"); 2068 mSystemServiceManager.startService(CAR_SERVICE_HELPER_SERVICE_CLASS); 2069 traceEnd(); 2070 } 2071 2072 traceBeginAndSlog("StartSystemUI"); 2073 try { 2074 startSystemUi(context, windowManagerF); 2075 } catch (Throwable e) { 2076 reportWtf("starting System UI", e); 2077 } 2078 traceEnd(); 2079 // Enable airplane mode in safe mode. setAirplaneMode() cannot be called 2080 // earlier as it sends broadcasts to other services. 2081 // TODO: This may actually be too late if radio firmware already started leaking 2082 // RF before the respective services start. However, fixing this requires changes 2083 // to radio firmware and interfaces. 2084 if (safeMode) { 2085 traceBeginAndSlog("EnableAirplaneModeInSafeMode"); 2086 try { 2087 connectivityF.setAirplaneMode(true); 2088 } catch (Throwable e) { 2089 reportWtf("enabling Airplane Mode during Safe Mode bootup", e); 2090 } 2091 traceEnd(); 2092 } 2093 traceBeginAndSlog("MakeNetworkManagementServiceReady"); 2094 try { 2095 if (networkManagementF != null) { 2096 networkManagementF.systemReady(); 2097 } 2098 } catch (Throwable e) { 2099 reportWtf("making Network Managment Service ready", e); 2100 } 2101 CountDownLatch networkPolicyInitReadySignal = null; 2102 if (networkPolicyF != null) { 2103 networkPolicyInitReadySignal = networkPolicyF 2104 .networkScoreAndNetworkManagementServiceReady(); 2105 } 2106 traceEnd(); 2107 traceBeginAndSlog("MakeIpSecServiceReady"); 2108 try { 2109 if (ipSecServiceF != null) { 2110 ipSecServiceF.systemReady(); 2111 } 2112 } catch (Throwable e) { 2113 reportWtf("making IpSec Service ready", e); 2114 } 2115 traceEnd(); 2116 traceBeginAndSlog("MakeNetworkStatsServiceReady"); 2117 try { 2118 if (networkStatsF != null) { 2119 networkStatsF.systemReady(); 2120 } 2121 } catch (Throwable e) { 2122 reportWtf("making Network Stats Service ready", e); 2123 } 2124 traceEnd(); 2125 traceBeginAndSlog("MakeConnectivityServiceReady"); 2126 try { 2127 if (connectivityF != null) { 2128 connectivityF.systemReady(); 2129 } 2130 } catch (Throwable e) { 2131 reportWtf("making Connectivity Service ready", e); 2132 } 2133 traceEnd(); 2134 traceBeginAndSlog("MakeNetworkPolicyServiceReady"); 2135 try { 2136 if (networkPolicyF != null) { 2137 networkPolicyF.systemReady(networkPolicyInitReadySignal); 2138 } 2139 } catch (Throwable e) { 2140 reportWtf("making Network Policy Service ready", e); 2141 } 2142 traceEnd(); 2143 2144 // Wait for all packages to be prepared 2145 mPackageManagerService.waitForAppDataPrepared(); 2146 2147 // It is now okay to let the various system services start their 2148 // third party code... 2149 traceBeginAndSlog("PhaseThirdPartyAppsCanStart"); 2150 // confirm webview completion before starting 3rd party 2151 if (webviewPrep != null) { 2152 ConcurrentUtils.waitForFutureNoInterrupt(webviewPrep, WEBVIEW_PREPARATION); 2153 } 2154 mSystemServiceManager.startBootPhase( 2155 SystemService.PHASE_THIRD_PARTY_APPS_CAN_START); 2156 traceEnd(); 2157 2158 traceBeginAndSlog("StartNetworkStack"); 2159 try { 2160 // Note : the network stack is creating on-demand objects that need to send 2161 // broadcasts, which means it currently depends on being started after 2162 // ActivityManagerService.mSystemReady and ActivityManagerService.mProcessesReady 2163 // are set to true. Be careful if moving this to a different place in the 2164 // startup sequence. 2165 NetworkStackClient.getInstance().start(context); 2166 } catch (Throwable e) { 2167 reportWtf("starting Network Stack", e); 2168 } 2169 traceEnd(); 2170 2171 traceBeginAndSlog("MakeLocationServiceReady"); 2172 try { 2173 if (locationF != null) { 2174 locationF.systemRunning(); 2175 } 2176 } catch (Throwable e) { 2177 reportWtf("Notifying Location Service running", e); 2178 } 2179 traceEnd(); 2180 traceBeginAndSlog("MakeCountryDetectionServiceReady"); 2181 try { 2182 if (countryDetectorF != null) { 2183 countryDetectorF.systemRunning(); 2184 } 2185 } catch (Throwable e) { 2186 reportWtf("Notifying CountryDetectorService running", e); 2187 } 2188 traceEnd(); 2189 traceBeginAndSlog("MakeNetworkTimeUpdateReady"); 2190 try { 2191 if (networkTimeUpdaterF != null) { 2192 networkTimeUpdaterF.systemRunning(); 2193 } 2194 } catch (Throwable e) { 2195 reportWtf("Notifying NetworkTimeService running", e); 2196 } 2197 traceEnd(); 2198 traceBeginAndSlog("MakeInputManagerServiceReady"); 2199 try { 2200 // TODO(BT) Pass parameter to input manager 2201 if (inputManagerF != null) { 2202 inputManagerF.systemRunning(); 2203 } 2204 } catch (Throwable e) { 2205 reportWtf("Notifying InputManagerService running", e); 2206 } 2207 traceEnd(); 2208 traceBeginAndSlog("MakeTelephonyRegistryReady"); 2209 try { 2210 if (telephonyRegistryF != null) { 2211 telephonyRegistryF.systemRunning(); 2212 } 2213 } catch (Throwable e) { 2214 reportWtf("Notifying TelephonyRegistry running", e); 2215 } 2216 traceEnd(); 2217 traceBeginAndSlog("MakeMediaRouterServiceReady"); 2218 try { 2219 if (mediaRouterF != null) { 2220 mediaRouterF.systemRunning(); 2221 } 2222 } catch (Throwable e) { 2223 reportWtf("Notifying MediaRouterService running", e); 2224 } 2225 traceEnd(); 2226 traceBeginAndSlog("MakeMmsServiceReady"); 2227 try { 2228 if (mmsServiceF != null) { 2229 mmsServiceF.systemRunning(); 2230 } 2231 } catch (Throwable e) { 2232 reportWtf("Notifying MmsService running", e); 2233 } 2234 traceEnd(); 2235 2236 traceBeginAndSlog("IncidentDaemonReady"); 2237 try { 2238 // TODO: Switch from checkService to getService once it's always 2239 // in the build and should reliably be there. 2240 final IIncidentManager incident = IIncidentManager.Stub.asInterface( 2241 ServiceManager.getService(Context.INCIDENT_SERVICE)); 2242 if (incident != null) { 2243 incident.systemRunning(); 2244 } 2245 } catch (Throwable e) { 2246 reportWtf("Notifying incident daemon running", e); 2247 } 2248 traceEnd(); 2249 }, BOOT_TIMINGS_TRACE_LOG); 2250 } 2251 startSystemCaptionsManagerService(@onNull Context context)2252 private void startSystemCaptionsManagerService(@NonNull Context context) { 2253 String serviceName = context.getString( 2254 com.android.internal.R.string.config_defaultSystemCaptionsManagerService); 2255 if (TextUtils.isEmpty(serviceName)) { 2256 Slog.d(TAG, "SystemCaptionsManagerService disabled because resource is not overlaid"); 2257 return; 2258 } 2259 2260 traceBeginAndSlog("StartSystemCaptionsManagerService"); 2261 mSystemServiceManager.startService(SYSTEM_CAPTIONS_MANAGER_SERVICE_CLASS); 2262 traceEnd(); 2263 } 2264 startContentCaptureService(@onNull Context context)2265 private void startContentCaptureService(@NonNull Context context) { 2266 // First check if it was explicitly enabled by DeviceConfig 2267 boolean explicitlyEnabled = false; 2268 String settings = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_CONTENT_CAPTURE, 2269 ContentCaptureManager.DEVICE_CONFIG_PROPERTY_SERVICE_EXPLICITLY_ENABLED); 2270 if (settings != null && !settings.equalsIgnoreCase("default")) { 2271 explicitlyEnabled = Boolean.parseBoolean(settings); 2272 if (explicitlyEnabled) { 2273 Slog.d(TAG, "ContentCaptureService explicitly enabled by DeviceConfig"); 2274 } else { 2275 Slog.d(TAG, "ContentCaptureService explicitly disabled by DeviceConfig"); 2276 return; 2277 } 2278 } 2279 2280 // Then check if OEM overlaid the resource that defines the service. 2281 if (!explicitlyEnabled) { 2282 final String serviceName = context 2283 .getString(com.android.internal.R.string.config_defaultContentCaptureService); 2284 if (TextUtils.isEmpty(serviceName)) { 2285 Slog.d(TAG, "ContentCaptureService disabled because resource is not overlaid"); 2286 return; 2287 } 2288 } 2289 2290 traceBeginAndSlog("StartContentCaptureService"); 2291 mSystemServiceManager.startService(CONTENT_CAPTURE_MANAGER_SERVICE_CLASS); 2292 2293 ContentCaptureManagerInternal ccmi = 2294 LocalServices.getService(ContentCaptureManagerInternal.class); 2295 if (ccmi != null && mActivityManagerService != null) { 2296 mActivityManagerService.setContentCaptureManager(ccmi); 2297 } 2298 2299 traceEnd(); 2300 } 2301 startAttentionService(@onNull Context context)2302 private void startAttentionService(@NonNull Context context) { 2303 if (!AttentionManagerService.isServiceConfigured(context)) { 2304 Slog.d(TAG, "AttentionService is not configured on this device"); 2305 return; 2306 } 2307 2308 traceBeginAndSlog("StartAttentionManagerService"); 2309 mSystemServiceManager.startService(AttentionManagerService.class); 2310 traceEnd(); 2311 } 2312 startSystemUi(Context context, WindowManagerService windowManager)2313 private static void startSystemUi(Context context, WindowManagerService windowManager) { 2314 Intent intent = new Intent(); 2315 intent.setComponent(new ComponentName("com.android.systemui", 2316 "com.android.systemui.SystemUIService")); 2317 intent.addFlags(Intent.FLAG_DEBUG_TRIAGED_MISSING); 2318 //Slog.d(TAG, "Starting service: " + intent); 2319 context.startServiceAsUser(intent, UserHandle.SYSTEM); 2320 windowManager.onSystemUiStarted(); 2321 } 2322 traceBeginAndSlog(@onNull String name)2323 private static void traceBeginAndSlog(@NonNull String name) { 2324 Slog.i(TAG, name); 2325 BOOT_TIMINGS_TRACE_LOG.traceBegin(name); 2326 } 2327 traceEnd()2328 private static void traceEnd() { 2329 BOOT_TIMINGS_TRACE_LOG.traceEnd(); 2330 } 2331 } 2332