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.net.NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK; 20 import static android.os.IServiceManager.DUMP_FLAG_PRIORITY_CRITICAL; 21 import static android.os.IServiceManager.DUMP_FLAG_PRIORITY_HIGH; 22 import static android.os.IServiceManager.DUMP_FLAG_PRIORITY_NORMAL; 23 import static android.os.IServiceManager.DUMP_FLAG_PROTO; 24 import static android.os.Process.SYSTEM_UID; 25 import static android.os.Process.myPid; 26 import static android.system.OsConstants.O_CLOEXEC; 27 import static android.system.OsConstants.O_RDONLY; 28 import static android.view.Display.DEFAULT_DISPLAY; 29 30 import static com.android.server.utils.TimingsTraceAndSlog.SYSTEM_SERVER_TIMING_TAG; 31 32 import android.annotation.NonNull; 33 import android.annotation.StringRes; 34 import android.app.ActivityThread; 35 import android.app.AppCompatCallbacks; 36 import android.app.ApplicationErrorReport; 37 import android.app.INotificationManager; 38 import android.app.SystemServiceRegistry; 39 import android.app.admin.DevicePolicySafetyChecker; 40 import android.app.usage.UsageStatsManagerInternal; 41 import android.content.ComponentName; 42 import android.content.ContentResolver; 43 import android.content.Context; 44 import android.content.Intent; 45 import android.content.pm.PackageItemInfo; 46 import android.content.pm.PackageManager; 47 import android.content.pm.PackageManagerInternal; 48 import android.content.res.Configuration; 49 import android.content.res.Resources.Theme; 50 import android.crashrecovery.flags.Flags; 51 import android.credentials.CredentialManager; 52 import android.database.sqlite.SQLiteCompatibilityWalFlags; 53 import android.database.sqlite.SQLiteGlobal; 54 import android.graphics.GraphicsStatsService; 55 import android.graphics.Typeface; 56 import android.hardware.display.DisplayManagerInternal; 57 import android.net.ConnectivityManager; 58 import android.net.ConnectivityModuleConnector; 59 import android.net.NetworkStackClient; 60 import android.os.ArtModuleServiceManager; 61 import android.os.BaseBundle; 62 import android.os.Binder; 63 import android.os.Build; 64 import android.os.Debug; 65 import android.os.Environment; 66 import android.os.FactoryTest; 67 import android.os.FileUtils; 68 import android.os.IBinder; 69 import android.os.IBinderCallback; 70 import android.os.IIncidentManager; 71 import android.os.Looper; 72 import android.os.Message; 73 import android.os.Parcel; 74 import android.os.PowerManager; 75 import android.os.Process; 76 import android.os.ServiceManager; 77 import android.os.StrictMode; 78 import android.os.SystemClock; 79 import android.os.SystemProperties; 80 import android.os.Trace; 81 import android.os.UserHandle; 82 import android.os.UserManager; 83 import android.os.storage.IStorageManager; 84 import android.provider.DeviceConfig; 85 import android.provider.Settings; 86 import android.server.ServerProtoEnums; 87 import android.system.ErrnoException; 88 import android.system.Os; 89 import android.text.TextUtils; 90 import android.util.ArrayMap; 91 import android.util.DisplayMetrics; 92 import android.util.Dumpable; 93 import android.util.EventLog; 94 import android.util.IndentingPrintWriter; 95 import android.util.Log; 96 import android.util.Pair; 97 import android.util.Slog; 98 import android.util.TimeUtils; 99 import android.view.contentcapture.ContentCaptureManager; 100 101 import com.android.i18n.timezone.ZoneInfoDb; 102 import com.android.internal.R; 103 import com.android.internal.annotations.GuardedBy; 104 import com.android.internal.notification.SystemNotificationChannels; 105 import com.android.internal.os.BinderInternal; 106 import com.android.internal.os.RuntimeInit; 107 import com.android.internal.policy.AttributeCache; 108 import com.android.internal.util.ConcurrentUtils; 109 import com.android.internal.util.EmergencyAffordanceManager; 110 import com.android.internal.util.FrameworkStatsLog; 111 import com.android.internal.widget.ILockSettings; 112 import com.android.internal.widget.LockSettingsInternal; 113 import com.android.server.accessibility.AccessibilityManagerService; 114 import com.android.server.accounts.AccountManagerService; 115 import com.android.server.adaptiveauth.AdaptiveAuthService; 116 import com.android.server.adb.AdbService; 117 import com.android.server.alarm.AlarmManagerService; 118 import com.android.server.am.ActivityManagerService; 119 import com.android.server.ambientcontext.AmbientContextManagerService; 120 import com.android.server.app.GameManagerService; 121 import com.android.server.appbinding.AppBindingService; 122 import com.android.server.apphibernation.AppHibernationService; 123 import com.android.server.appop.AppOpMigrationHelper; 124 import com.android.server.appop.AppOpMigrationHelperImpl; 125 import com.android.server.appprediction.AppPredictionManagerService; 126 import com.android.server.appwidget.AppWidgetService; 127 import com.android.server.art.ArtModuleServiceInitializer; 128 import com.android.server.art.DexUseManagerLocal; 129 import com.android.server.attention.AttentionManagerService; 130 import com.android.server.audio.AudioService; 131 import com.android.server.autofill.AutofillManagerService; 132 import com.android.server.backup.BackupManagerService; 133 import com.android.server.biometrics.AuthService; 134 import com.android.server.biometrics.BiometricService; 135 import com.android.server.biometrics.sensors.face.FaceService; 136 import com.android.server.biometrics.sensors.fingerprint.FingerprintService; 137 import com.android.server.biometrics.sensors.iris.IrisService; 138 import com.android.server.blob.BlobStoreManagerService; 139 import com.android.server.broadcastradio.BroadcastRadioService; 140 import com.android.server.camera.CameraServiceProxy; 141 import com.android.server.clipboard.ClipboardService; 142 import com.android.server.companion.CompanionDeviceManagerService; 143 import com.android.server.companion.virtual.VirtualDeviceManagerService; 144 import com.android.server.compat.PlatformCompat; 145 import com.android.server.compat.PlatformCompatNative; 146 import com.android.server.compat.overrides.AppCompatOverridesService; 147 import com.android.server.connectivity.IpConnectivityMetrics; 148 import com.android.server.connectivity.PacProxyService; 149 import com.android.server.content.ContentService; 150 import com.android.server.contentcapture.ContentCaptureManagerInternal; 151 import com.android.server.contentcapture.ContentCaptureManagerService; 152 import com.android.server.contentsuggestions.ContentSuggestionsManagerService; 153 import com.android.server.contextualsearch.ContextualSearchManagerService; 154 import com.android.server.coverage.CoverageService; 155 import com.android.server.cpu.CpuMonitorService; 156 import com.android.server.credentials.CredentialManagerService; 157 import com.android.server.criticalevents.CriticalEventLog; 158 import com.android.server.devicepolicy.DevicePolicyManagerService; 159 import com.android.server.devicestate.DeviceStateManagerService; 160 import com.android.server.display.DisplayManagerService; 161 import com.android.server.display.color.ColorDisplayService; 162 import com.android.server.dreams.DreamManagerService; 163 import com.android.server.emergency.EmergencyAffordanceService; 164 import com.android.server.flags.FeatureFlagsService; 165 import com.android.server.gpu.GpuService; 166 import com.android.server.grammaticalinflection.GrammaticalInflectionService; 167 import com.android.server.graphics.fonts.FontManagerService; 168 import com.android.server.hdmi.HdmiControlService; 169 import com.android.server.incident.IncidentCompanionService; 170 import com.android.server.input.InputManagerService; 171 import com.android.server.inputmethod.InputMethodManagerService; 172 import com.android.server.integrity.AppIntegrityManagerService; 173 import com.android.server.job.JobSchedulerService; 174 import com.android.server.lights.LightsService; 175 import com.android.server.locales.LocaleManagerService; 176 import com.android.server.location.LocationManagerService; 177 import com.android.server.location.altitude.AltitudeService; 178 import com.android.server.locksettings.LockSettingsService; 179 import com.android.server.logcat.LogcatManagerService; 180 import com.android.server.media.MediaResourceMonitorService; 181 import com.android.server.media.MediaRouterService; 182 import com.android.server.media.MediaSessionService; 183 import com.android.server.media.metrics.MediaMetricsManagerService; 184 import com.android.server.media.projection.MediaProjectionManagerService; 185 import com.android.server.midi.MidiService; 186 import com.android.server.musicrecognition.MusicRecognitionManagerService; 187 import com.android.server.net.NetworkManagementService; 188 import com.android.server.net.NetworkPolicyManagerService; 189 import com.android.server.net.watchlist.NetworkWatchlistService; 190 import com.android.server.notification.NotificationManagerService; 191 import com.android.server.oemlock.OemLockService; 192 import com.android.server.om.OverlayManagerService; 193 import com.android.server.ondeviceintelligence.OnDeviceIntelligenceManagerService; 194 import com.android.server.os.BugreportManagerService; 195 import com.android.server.os.DeviceIdentifiersPolicyService; 196 import com.android.server.os.NativeTombstoneManagerService; 197 import com.android.server.os.SchedulingPolicyService; 198 import com.android.server.pdb.PersistentDataBlockService; 199 import com.android.server.people.PeopleService; 200 import com.android.server.permission.access.AccessCheckingService; 201 import com.android.server.pm.ApexManager; 202 import com.android.server.pm.ApexSystemServiceInfo; 203 import com.android.server.pm.BackgroundInstallControlService; 204 import com.android.server.pm.CrossProfileAppsService; 205 import com.android.server.pm.DataLoaderManagerService; 206 import com.android.server.pm.DexOptHelper; 207 import com.android.server.pm.DynamicCodeLoggingService; 208 import com.android.server.pm.Installer; 209 import com.android.server.pm.LauncherAppsService; 210 import com.android.server.pm.OtaDexoptService; 211 import com.android.server.pm.PackageManagerService; 212 import com.android.server.pm.ShortcutService; 213 import com.android.server.pm.UserManagerService; 214 import com.android.server.pm.dex.OdsignStatsLogger; 215 import com.android.server.pm.permission.PermissionMigrationHelper; 216 import com.android.server.pm.permission.PermissionMigrationHelperImpl; 217 import com.android.server.pm.verify.domain.DomainVerificationService; 218 import com.android.server.policy.AppOpsPolicy; 219 import com.android.server.policy.PermissionPolicyService; 220 import com.android.server.policy.PhoneWindowManager; 221 import com.android.server.policy.role.RoleServicePlatformHelperImpl; 222 import com.android.server.power.PowerManagerService; 223 import com.android.server.power.ShutdownThread; 224 import com.android.server.power.ThermalManagerService; 225 import com.android.server.power.hint.HintManagerService; 226 import com.android.server.powerstats.PowerStatsService; 227 import com.android.server.print.PrintManagerService; 228 import com.android.server.profcollect.ProfcollectForwardingService; 229 import com.android.server.recoverysystem.RecoverySystemService; 230 import com.android.server.resources.ResourcesManagerService; 231 import com.android.server.restrictions.RestrictionsManagerService; 232 import com.android.server.role.RoleServicePlatformHelper; 233 import com.android.server.rollback.RollbackManagerService; 234 import com.android.server.rotationresolver.RotationResolverManagerService; 235 import com.android.server.search.SearchManagerService; 236 import com.android.server.searchui.SearchUiManagerService; 237 import com.android.server.security.AttestationVerificationManagerService; 238 import com.android.server.security.FileIntegrityService; 239 import com.android.server.security.KeyAttestationApplicationIdProviderService; 240 import com.android.server.security.KeyChainSystemService; 241 import com.android.server.security.rkp.RemoteProvisioningService; 242 import com.android.server.selinux.SelinuxAuditLogsService; 243 import com.android.server.sensorprivacy.SensorPrivacyService; 244 import com.android.server.sensors.SensorService; 245 import com.android.server.signedconfig.SignedConfigService; 246 import com.android.server.slice.SliceManagerService; 247 import com.android.server.smartspace.SmartspaceManagerService; 248 import com.android.server.soundtrigger.SoundTriggerService; 249 import com.android.server.soundtrigger_middleware.SoundTriggerMiddlewareService; 250 import com.android.server.speech.SpeechRecognitionManagerService; 251 import com.android.server.stats.bootstrap.StatsBootstrapAtomService; 252 import com.android.server.stats.pull.StatsPullAtomService; 253 import com.android.server.statusbar.StatusBarManagerService; 254 import com.android.server.storage.DeviceStorageMonitorService; 255 import com.android.server.systemcaptions.SystemCaptionsManagerService; 256 import com.android.server.telecom.TelecomLoaderService; 257 import com.android.server.testharness.TestHarnessModeService; 258 import com.android.server.textclassifier.TextClassificationManagerService; 259 import com.android.server.textservices.TextServicesManagerService; 260 import com.android.server.texttospeech.TextToSpeechManagerService; 261 import com.android.server.timedetector.GnssTimeUpdateService; 262 import com.android.server.timedetector.NetworkTimeUpdateService; 263 import com.android.server.timedetector.TimeDetectorService; 264 import com.android.server.timezonedetector.TimeZoneDetectorService; 265 import com.android.server.timezonedetector.location.LocationTimeZoneManagerService; 266 import com.android.server.tracing.TracingServiceProxy; 267 import com.android.server.translation.TranslationManagerService; 268 import com.android.server.trust.TrustManagerService; 269 import com.android.server.tv.TvInputManagerService; 270 import com.android.server.tv.TvRemoteService; 271 import com.android.server.tv.interactive.TvInteractiveAppManagerService; 272 import com.android.server.tv.tunerresourcemanager.TunerResourceManagerService; 273 import com.android.server.twilight.TwilightService; 274 import com.android.server.uri.UriGrantsManagerService; 275 import com.android.server.usage.StorageStatsService; 276 import com.android.server.usage.UsageStatsService; 277 import com.android.server.usb.UsbService; 278 import com.android.server.utils.TimingsTraceAndSlog; 279 import com.android.server.vibrator.VibratorManagerService; 280 import com.android.server.voiceinteraction.VoiceInteractionManagerService; 281 import com.android.server.vr.VrManagerService; 282 import com.android.server.wallpaper.WallpaperManagerService; 283 import com.android.server.wallpapereffectsgeneration.WallpaperEffectsGenerationManagerService; 284 import com.android.server.wearable.WearableSensingManagerService; 285 import com.android.server.webkit.WebViewUpdateService; 286 import com.android.server.wm.ActivityTaskManagerService; 287 import com.android.server.wm.WindowManagerGlobalLock; 288 import com.android.server.wm.WindowManagerService; 289 290 import dalvik.system.VMRuntime; 291 292 import java.io.File; 293 import java.io.FileDescriptor; 294 import java.io.IOException; 295 import java.io.PrintWriter; 296 import java.text.SimpleDateFormat; 297 import java.util.Arrays; 298 import java.util.Date; 299 import java.util.LinkedList; 300 import java.util.List; 301 import java.util.Locale; 302 import java.util.Timer; 303 import java.util.TreeSet; 304 import java.util.concurrent.CountDownLatch; 305 import java.util.concurrent.Future; 306 307 /** 308 * Entry point to {@code system_server}. 309 */ 310 public final class SystemServer implements Dumpable { 311 312 private static final String TAG = "SystemServer"; 313 314 private static final long SLOW_DISPATCH_THRESHOLD_MS = 100; 315 private static final long SLOW_DELIVERY_THRESHOLD_MS = 200; 316 317 /* 318 * Implementation class names for services in the {@code SYSTEMSERVERCLASSPATH} 319 * from {@code PRODUCT_SYSTEM_SERVER_JARS} that are *not* in {@code services.jar}. 320 */ 321 private static final String ARC_NETWORK_SERVICE_CLASS = 322 "com.android.server.arc.net.ArcNetworkService"; 323 private static final String ARC_PERSISTENT_DATA_BLOCK_SERVICE_CLASS = 324 "com.android.server.arc.persistent_data_block.ArcPersistentDataBlockService"; 325 private static final String ARC_SYSTEM_HEALTH_SERVICE = 326 "com.android.server.arc.health.ArcSystemHealthService"; 327 private static final String LOWPAN_SERVICE_CLASS = 328 "com.android.server.lowpan.LowpanService"; 329 private static final String THERMAL_OBSERVER_CLASS = 330 "com.android.clockwork.ThermalObserver"; 331 private static final String WEAR_CONNECTIVITY_SERVICE_CLASS = 332 "com.android.clockwork.connectivity.WearConnectivityService"; 333 private static final String WEAR_POWER_SERVICE_CLASS = 334 "com.android.clockwork.power.WearPowerService"; 335 private static final String HEALTH_SERVICE_CLASS = 336 "com.android.clockwork.healthservices.HealthService"; 337 private static final String SYSTEM_STATE_DISPLAY_SERVICE_CLASS = 338 "com.android.clockwork.systemstatedisplay.SystemStateDisplayService"; 339 private static final String WEAR_DISPLAYOFFLOAD_SERVICE_CLASS = 340 "com.android.clockwork.displayoffload.DisplayOffloadService"; 341 private static final String WEAR_MODE_SERVICE_CLASS = 342 "com.android.clockwork.modes.ModeManagerService"; 343 private static final String WEAR_DISPLAY_SERVICE_CLASS = 344 "com.android.clockwork.display.WearDisplayService"; 345 private static final String WEAR_DEBUG_SERVICE_CLASS = 346 "com.android.clockwork.debug.WearDebugService"; 347 private static final String WEAR_TIME_SERVICE_CLASS = 348 "com.android.clockwork.time.WearTimeService"; 349 private static final String WEAR_SETTINGS_SERVICE_CLASS = 350 "com.android.clockwork.settings.WearSettingsService"; 351 private static final String WRIST_ORIENTATION_SERVICE_CLASS = 352 "com.android.clockwork.wristorientation.WristOrientationService"; 353 private static final String IOT_SERVICE_CLASS = 354 "com.android.things.server.IoTSystemService"; 355 private static final String CAR_SERVICE_HELPER_SERVICE_CLASS = 356 "com.android.internal.car.CarServiceHelperService"; 357 358 /* 359 * Implementation class names for services in the {@code SYSTEMSERVERCLASSPATH} 360 * from {@code PRODUCT_APEX_SYSTEM_SERVER_JARS}. 361 */ 362 private static final String APPSEARCH_MODULE_LIFECYCLE_CLASS = 363 "com.android.server.appsearch.AppSearchModule$Lifecycle"; 364 private static final String ISOLATED_COMPILATION_SERVICE_CLASS = 365 "com.android.server.compos.IsolatedCompilationService"; 366 private static final String MEDIA_COMMUNICATION_SERVICE_CLASS = 367 "com.android.server.media.MediaCommunicationService"; 368 private static final String HEALTHCONNECT_MANAGER_SERVICE_CLASS = 369 "com.android.server.healthconnect.HealthConnectManagerService"; 370 private static final String ROLE_SERVICE_CLASS = "com.android.role.RoleService"; 371 private static final String ENHANCED_CONFIRMATION_SERVICE_CLASS = 372 "com.android.ecm.EnhancedConfirmationService"; 373 private static final String SAFETY_CENTER_SERVICE_CLASS = 374 "com.android.safetycenter.SafetyCenterService"; 375 private static final String SDK_SANDBOX_MANAGER_SERVICE_CLASS = 376 "com.android.server.sdksandbox.SdkSandboxManagerService$Lifecycle"; 377 private static final String AD_SERVICES_MANAGER_SERVICE_CLASS = 378 "com.android.server.adservices.AdServicesManagerService$Lifecycle"; 379 private static final String ON_DEVICE_PERSONALIZATION_SYSTEM_SERVICE_CLASS = 380 "com.android.server.ondevicepersonalization." 381 + "OnDevicePersonalizationSystemService$Lifecycle"; 382 private static final String UPDATABLE_DEVICE_CONFIG_SERVICE_CLASS = 383 "com.android.server.deviceconfig.DeviceConfigInit$Lifecycle"; 384 385 /* 386 * Implementation class names and jar locations for services in 387 * {@code STANDALONE_SYSTEMSERVER_JARS}. 388 */ 389 private static final String STATS_COMPANION_APEX_PATH = 390 "/apex/com.android.os.statsd/javalib/service-statsd.jar"; 391 private static final String STATS_COMPANION_LIFECYCLE_CLASS = 392 "com.android.server.stats.StatsCompanion$Lifecycle"; 393 private static final String SCHEDULING_APEX_PATH = 394 "/apex/com.android.scheduling/javalib/service-scheduling.jar"; 395 private static final String REBOOT_READINESS_LIFECYCLE_CLASS = 396 "com.android.server.scheduling.RebootReadinessManagerService$Lifecycle"; 397 private static final String WIFI_APEX_SERVICE_JAR_PATH = 398 "/apex/com.android.wifi/javalib/service-wifi.jar"; 399 private static final String WIFI_SERVICE_CLASS = 400 "com.android.server.wifi.WifiService"; 401 private static final String WIFI_SCANNING_SERVICE_CLASS = 402 "com.android.server.wifi.scanner.WifiScanningService"; 403 private static final String WIFI_RTT_SERVICE_CLASS = 404 "com.android.server.wifi.rtt.RttService"; 405 private static final String WIFI_AWARE_SERVICE_CLASS = 406 "com.android.server.wifi.aware.WifiAwareService"; 407 private static final String WIFI_P2P_SERVICE_CLASS = 408 "com.android.server.wifi.p2p.WifiP2pService"; 409 private static final String CONNECTIVITY_SERVICE_APEX_PATH = 410 "/apex/com.android.tethering/javalib/service-connectivity.jar"; 411 private static final String CONNECTIVITY_SERVICE_INITIALIZER_CLASS = 412 "com.android.server.ConnectivityServiceInitializer"; 413 private static final String NETWORK_STATS_SERVICE_INITIALIZER_CLASS = 414 "com.android.server.NetworkStatsServiceInitializer"; 415 private static final String UWB_APEX_SERVICE_JAR_PATH = 416 "/apex/com.android.uwb/javalib/service-uwb.jar"; 417 private static final String UWB_SERVICE_CLASS = "com.android.server.uwb.UwbService"; 418 private static final String BLUETOOTH_APEX_SERVICE_JAR_PATH = 419 "/apex/com.android.btservices/javalib/service-bluetooth.jar"; 420 private static final String BLUETOOTH_SERVICE_CLASS = 421 "com.android.server.bluetooth.BluetoothService"; 422 private static final String DEVICE_LOCK_SERVICE_CLASS = 423 "com.android.server.devicelock.DeviceLockService"; 424 private static final String DEVICE_LOCK_APEX_PATH = 425 "/apex/com.android.devicelock/javalib/service-devicelock.jar"; 426 private static final String PROFILING_SERVICE_LIFECYCLE_CLASS = 427 "android.os.profiling.ProfilingService$Lifecycle"; 428 private static final String PROFILING_SERVICE_JAR_PATH = 429 "/apex/com.android.profiling/javalib/service-profiling.jar"; 430 431 private static final String TETHERING_CONNECTOR_CLASS = "android.net.ITetheringConnector"; 432 433 private static final String PERSISTENT_DATA_BLOCK_PROP = "ro.frp.pst"; 434 435 private static final String UNCRYPT_PACKAGE_FILE = "/cache/recovery/uncrypt_file"; 436 private static final String BLOCK_MAP_FILE = "/cache/recovery/block.map"; 437 438 // maximum number of binder threads used for system_server 439 // will be higher than the system default 440 private static final int sMaxBinderThreads = 31; 441 442 /** 443 * Default theme used by the system context. This is used to style system-provided dialogs, such 444 * as the Power Off dialog, and other visual content. 445 */ 446 private static final int DEFAULT_SYSTEM_THEME = 447 com.android.internal.R.style.Theme_DeviceDefault_System; 448 449 private final int mFactoryTestMode; 450 private Timer mProfilerSnapshotTimer; 451 452 private Context mSystemContext; 453 private SystemServiceManager mSystemServiceManager; 454 455 // TODO: remove all of these references by improving dependency resolution and boot phases 456 private PowerManagerService mPowerManagerService; 457 private ActivityManagerService mActivityManagerService; 458 private WindowManagerGlobalLock mWindowManagerGlobalLock; 459 private WebViewUpdateService mWebViewUpdateService; 460 private DisplayManagerService mDisplayManagerService; 461 private PackageManagerService mPackageManagerService; 462 private PackageManager mPackageManager; 463 private ContentResolver mContentResolver; 464 private EntropyMixer mEntropyMixer; 465 private DataLoaderManagerService mDataLoaderManagerService; 466 private long mIncrementalServiceHandle = 0; 467 468 private boolean mFirstBoot; 469 private final int mStartCount; 470 private final boolean mRuntimeRestart; 471 private final long mRuntimeStartElapsedTime; 472 private final long mRuntimeStartUptime; 473 474 private static final String START_HIDL_SERVICES = "StartHidlServices"; 475 private static final String START_SENSOR_MANAGER_SERVICE = "StartISensorManagerService"; 476 private static final String START_BLOB_STORE_SERVICE = "startBlobStoreManagerService"; 477 478 private static final String SYSPROP_START_COUNT = "sys.system_server.start_count"; 479 private static final String SYSPROP_START_ELAPSED = "sys.system_server.start_elapsed"; 480 private static final String SYSPROP_START_UPTIME = "sys.system_server.start_uptime"; 481 482 private Future<?> mZygotePreload; 483 484 private final SystemServerDumper mDumper = new SystemServerDumper(); 485 486 /** 487 * The pending WTF to be logged into dropbox. 488 */ 489 private static LinkedList<Pair<String, ApplicationErrorReport.CrashInfo>> sPendingWtfs; 490 491 /** Start the IStats services. This is a blocking call and can take time. */ startIStatsService()492 private static native void startIStatsService(); 493 494 /** Start the ISensorManager service. This is a blocking call and can take time. */ startISensorManagerService()495 private static native void startISensorManagerService(); 496 497 /** 498 * Start the memtrack proxy service. 499 */ startMemtrackProxyService()500 private static native void startMemtrackProxyService(); 501 502 /** 503 * Start all HIDL services that are run inside the system server. This may take some time. 504 */ startHidlServices()505 private static native void startHidlServices(); 506 507 /** 508 * Mark this process' heap as profileable. Only for debug builds. 509 */ initZygoteChildHeapProfiling()510 private static native void initZygoteChildHeapProfiling(); 511 512 private static final String SYSPROP_FDTRACK_ENABLE_THRESHOLD = 513 "persist.sys.debug.fdtrack_enable_threshold"; 514 private static final String SYSPROP_FDTRACK_ABORT_THRESHOLD = 515 "persist.sys.debug.fdtrack_abort_threshold"; 516 private static final String SYSPROP_FDTRACK_INTERVAL = 517 "persist.sys.debug.fdtrack_interval"; 518 getMaxFd()519 private static int getMaxFd() { 520 FileDescriptor fd = null; 521 try { 522 fd = Os.open("/dev/null", O_RDONLY | O_CLOEXEC, 0); 523 return fd.getInt$(); 524 } catch (ErrnoException ex) { 525 Slog.e("System", "Failed to get maximum fd: " + ex); 526 } finally { 527 if (fd != null) { 528 try { 529 Os.close(fd); 530 } catch (ErrnoException ex) { 531 // If Os.close threw, something went horribly wrong. 532 throw new RuntimeException(ex); 533 } 534 } 535 } 536 537 return Integer.MAX_VALUE; 538 } 539 fdtrackAbort()540 private static native void fdtrackAbort(); 541 542 private static final File HEAP_DUMP_PATH = new File("/data/system/heapdump/"); 543 private static final int MAX_HEAP_DUMPS = 2; 544 545 /** 546 * Dump system_server's heap. 547 * 548 * For privacy reasons, these aren't automatically pulled into bugreports: 549 * they must be manually pulled by the user. 550 */ dumpHprof()551 private static void dumpHprof() { 552 // hprof dumps are rather large, so ensure we don't fill the disk by generating 553 // hundreds of these that will live forever. 554 TreeSet<File> existingTombstones = new TreeSet<>(); 555 for (File file : HEAP_DUMP_PATH.listFiles()) { 556 if (!file.isFile()) { 557 continue; 558 } 559 if (!file.getName().startsWith("fdtrack-")) { 560 continue; 561 } 562 existingTombstones.add(file); 563 } 564 if (existingTombstones.size() >= MAX_HEAP_DUMPS) { 565 for (int i = 0; i < MAX_HEAP_DUMPS - 1; ++i) { 566 // Leave the newest `MAX_HEAP_DUMPS - 1` tombstones in place. 567 existingTombstones.pollLast(); 568 } 569 for (File file : existingTombstones) { 570 if (!file.delete()) { 571 Slog.w("System", "Failed to clean up hprof " + file); 572 } 573 } 574 } 575 576 try { 577 String date = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss").format(new Date()); 578 String filename = "/data/system/heapdump/fdtrack-" + date + ".hprof"; 579 Debug.dumpHprofData(filename); 580 } catch (IOException ex) { 581 Slog.e("System", "Failed to dump fdtrack hprof", ex); 582 } 583 } 584 585 /** 586 * Spawn a thread that monitors for fd leaks. 587 */ spawnFdLeakCheckThread()588 private static void spawnFdLeakCheckThread() { 589 final int enableThreshold = SystemProperties.getInt(SYSPROP_FDTRACK_ENABLE_THRESHOLD, 1600); 590 final int abortThreshold = SystemProperties.getInt(SYSPROP_FDTRACK_ABORT_THRESHOLD, 3000); 591 final int checkInterval = SystemProperties.getInt(SYSPROP_FDTRACK_INTERVAL, 120); 592 593 new Thread(() -> { 594 boolean enabled = false; 595 long nextWrite = 0; 596 597 while (true) { 598 int maxFd = getMaxFd(); 599 if (maxFd > enableThreshold) { 600 // Do a manual GC to clean up fds that are hanging around as garbage. 601 System.gc(); 602 System.runFinalization(); 603 maxFd = getMaxFd(); 604 } 605 606 if (maxFd > enableThreshold && !enabled) { 607 Slog.i("System", "fdtrack enable threshold reached, enabling"); 608 FrameworkStatsLog.write(FrameworkStatsLog.FDTRACK_EVENT_OCCURRED, 609 FrameworkStatsLog.FDTRACK_EVENT_OCCURRED__EVENT__ENABLED, 610 maxFd); 611 612 System.loadLibrary("fdtrack"); 613 enabled = true; 614 } else if (maxFd > abortThreshold) { 615 Slog.i("System", "fdtrack abort threshold reached, dumping and aborting"); 616 FrameworkStatsLog.write(FrameworkStatsLog.FDTRACK_EVENT_OCCURRED, 617 FrameworkStatsLog.FDTRACK_EVENT_OCCURRED__EVENT__ABORTING, 618 maxFd); 619 620 dumpHprof(); 621 fdtrackAbort(); 622 } else { 623 // Limit this to once per hour. 624 long now = SystemClock.elapsedRealtime(); 625 if (now > nextWrite) { 626 nextWrite = now + 60 * 60 * 1000; 627 FrameworkStatsLog.write(FrameworkStatsLog.FDTRACK_EVENT_OCCURRED, 628 enabled ? FrameworkStatsLog.FDTRACK_EVENT_OCCURRED__EVENT__ENABLED 629 : FrameworkStatsLog.FDTRACK_EVENT_OCCURRED__EVENT__DISABLED, 630 maxFd); 631 } 632 } 633 634 try { 635 Thread.sleep(checkInterval * 1000); 636 } catch (InterruptedException ex) { 637 continue; 638 } 639 } 640 }).start(); 641 } 642 643 /** 644 * Start native Incremental Service and get its handle. 645 */ startIncrementalService()646 private static native long startIncrementalService(); 647 648 /** 649 * Inform Incremental Service that system is ready. 650 */ setIncrementalServiceSystemReady(long incrementalServiceHandle)651 private static native void setIncrementalServiceSystemReady(long incrementalServiceHandle); 652 653 /** 654 * The main entry point from zygote. 655 */ main(String[] args)656 public static void main(String[] args) { 657 new SystemServer().run(); 658 } 659 SystemServer()660 public SystemServer() { 661 // Check for factory test mode. 662 mFactoryTestMode = FactoryTest.getMode(); 663 664 // Record process start information. 665 mStartCount = SystemProperties.getInt(SYSPROP_START_COUNT, 0) + 1; 666 mRuntimeStartElapsedTime = SystemClock.elapsedRealtime(); 667 mRuntimeStartUptime = SystemClock.uptimeMillis(); 668 Process.setStartTimes(mRuntimeStartElapsedTime, mRuntimeStartUptime, 669 mRuntimeStartElapsedTime, mRuntimeStartUptime); 670 671 // Remember if it's runtime restart or reboot. 672 mRuntimeRestart = mStartCount > 1; 673 } 674 675 @Override getDumpableName()676 public String getDumpableName() { 677 return SystemServer.class.getSimpleName(); 678 } 679 680 @Override dump(PrintWriter pw, String[] args)681 public void dump(PrintWriter pw, String[] args) { 682 pw.printf("Runtime restart: %b\n", mRuntimeRestart); 683 pw.printf("Start count: %d\n", mStartCount); 684 pw.print("Runtime start-up time: "); 685 TimeUtils.formatDuration(mRuntimeStartUptime, pw); pw.println(); 686 pw.print("Runtime start-elapsed time: "); 687 TimeUtils.formatDuration(mRuntimeStartElapsedTime, pw); pw.println(); 688 } 689 690 /** 691 * Service used to dump {@link SystemServer} state that is not associated with any service. 692 * 693 * <p>To dump all services: 694 * 695 * <pre><code>adb shell dumpsys system_server_dumper</code></pre> 696 * 697 * <p>To get a list of all services: 698 * 699 * <pre><code>adb shell dumpsys system_server_dumper --list</code></pre> 700 * 701 * <p>To dump a specific service (use {@code --list} above to get service names): 702 * 703 * <pre><code>adb shell dumpsys system_server_dumper --name NAME</code></pre> 704 */ 705 private final class SystemServerDumper extends Binder { 706 707 @GuardedBy("mDumpables") 708 private final ArrayMap<String, Dumpable> mDumpables = new ArrayMap<>(4); 709 710 @Override dump(FileDescriptor fd, PrintWriter pw, String[] args)711 protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) { 712 final boolean hasArgs = args != null && args.length > 0; 713 714 synchronized (mDumpables) { 715 if (hasArgs && "--list".equals(args[0])) { 716 final int dumpablesSize = mDumpables.size(); 717 for (int i = 0; i < dumpablesSize; i++) { 718 pw.println(mDumpables.keyAt(i)); 719 } 720 return; 721 } 722 723 if (hasArgs && "--name".equals(args[0])) { 724 if (args.length < 2) { 725 pw.println("Must pass at least one argument to --name"); 726 return; 727 } 728 final String name = args[1]; 729 final Dumpable dumpable = mDumpables.get(name); 730 if (dumpable == null) { 731 pw.printf("No dumpable named %s\n", name); 732 return; 733 } 734 735 try (IndentingPrintWriter ipw = new IndentingPrintWriter(pw, " ")) { 736 // Strip --name DUMPABLE from args 737 final String[] actualArgs = Arrays.copyOfRange(args, 2, args.length); 738 dumpable.dump(ipw, actualArgs); 739 } 740 return; 741 } 742 743 final int dumpablesSize = mDumpables.size(); 744 try (IndentingPrintWriter ipw = new IndentingPrintWriter(pw, " ")) { 745 for (int i = 0; i < dumpablesSize; i++) { 746 final Dumpable dumpable = mDumpables.valueAt(i); 747 ipw.printf("%s:\n", dumpable.getDumpableName()); 748 ipw.increaseIndent(); 749 dumpable.dump(ipw, args); 750 ipw.decreaseIndent(); 751 ipw.println(); 752 } 753 } 754 } 755 } 756 addDumpable(@onNull Dumpable dumpable)757 private void addDumpable(@NonNull Dumpable dumpable) { 758 synchronized (mDumpables) { 759 mDumpables.put(dumpable.getDumpableName(), dumpable); 760 } 761 } 762 } 763 run()764 private void run() { 765 TimingsTraceAndSlog t = new TimingsTraceAndSlog(); 766 try { 767 t.traceBegin("InitBeforeStartServices"); 768 769 // Record the process start information in sys props. 770 SystemProperties.set(SYSPROP_START_COUNT, String.valueOf(mStartCount)); 771 SystemProperties.set(SYSPROP_START_ELAPSED, String.valueOf(mRuntimeStartElapsedTime)); 772 SystemProperties.set(SYSPROP_START_UPTIME, String.valueOf(mRuntimeStartUptime)); 773 774 EventLog.writeEvent(EventLogTags.SYSTEM_SERVER_START, 775 mStartCount, mRuntimeStartUptime, mRuntimeStartElapsedTime); 776 777 // Set the device's time zone (a system property) if it is not set or is invalid. 778 SystemTimeZone.initializeTimeZoneSettingsIfRequired(); 779 780 // If the system has "persist.sys.language" and friends set, replace them with 781 // "persist.sys.locale". Note that the default locale at this point is calculated 782 // using the "-Duser.locale" command line flag. That flag is usually populated by 783 // AndroidRuntime using the same set of system properties, but only the system_server 784 // and system apps are allowed to set them. 785 // 786 // NOTE: Most changes made here will need an equivalent change to 787 // core/jni/AndroidRuntime.cpp 788 if (!SystemProperties.get("persist.sys.language").isEmpty()) { 789 final String languageTag = Locale.getDefault().toLanguageTag(); 790 791 SystemProperties.set("persist.sys.locale", languageTag); 792 SystemProperties.set("persist.sys.language", ""); 793 SystemProperties.set("persist.sys.country", ""); 794 SystemProperties.set("persist.sys.localevar", ""); 795 } 796 797 // The system server should never make non-oneway calls 798 Binder.setWarnOnBlocking(true); 799 // The system server should always load safe labels 800 PackageItemInfo.forceSafeLabels(); 801 802 // Default to FULL within the system server. 803 SQLiteGlobal.sDefaultSyncMode = SQLiteGlobal.SYNC_MODE_FULL; 804 805 // Deactivate SQLiteCompatibilityWalFlags until settings provider is initialized 806 SQLiteCompatibilityWalFlags.init(null); 807 808 // Here we go! 809 Slog.i(TAG, "Entered the Android system server!"); 810 final long uptimeMillis = SystemClock.elapsedRealtime(); 811 EventLog.writeEvent(EventLogTags.BOOT_PROGRESS_SYSTEM_RUN, uptimeMillis); 812 if (!mRuntimeRestart) { 813 FrameworkStatsLog.write(FrameworkStatsLog.BOOT_TIME_EVENT_ELAPSED_TIME_REPORTED, 814 FrameworkStatsLog 815 .BOOT_TIME_EVENT_ELAPSED_TIME__EVENT__SYSTEM_SERVER_INIT_START, 816 uptimeMillis); 817 } 818 819 // In case the runtime switched since last boot (such as when 820 // the old runtime was removed in an OTA), set the system 821 // property so that it is in sync. We can't do this in 822 // libnativehelper's JniInvocation::Init code where we already 823 // had to fallback to a different runtime because it is 824 // running as root and we need to be the system user to set 825 // the property. http://b/11463182 826 SystemProperties.set("persist.sys.dalvik.vm.lib.2", VMRuntime.getRuntime().vmLibrary()); 827 828 // Mmmmmm... more memory! 829 VMRuntime.getRuntime().clearGrowthLimit(); 830 831 // Some devices rely on runtime fingerprint generation, so make sure 832 // we've defined it before booting further. 833 Build.ensureFingerprintProperty(); 834 835 // Within the system server, it is an error to access Environment paths without 836 // explicitly specifying a user. 837 Environment.setUserRequired(true); 838 839 // Within the system server, any incoming Bundles should be defused 840 // to avoid throwing BadParcelableException. 841 BaseBundle.setShouldDefuse(true); 842 843 // Within the system server, when parceling exceptions, include the stack trace 844 Parcel.setStackTraceParceling(true); 845 846 // Ensure binder calls into the system always run at foreground priority. 847 BinderInternal.disableBackgroundScheduling(true); 848 849 // Increase the number of binder threads in system_server 850 BinderInternal.setMaxThreads(sMaxBinderThreads); 851 852 // Prepare the main looper thread (this thread). 853 android.os.Process.setThreadPriority( 854 android.os.Process.THREAD_PRIORITY_FOREGROUND); 855 android.os.Process.setCanSelfBackground(false); 856 Looper.prepareMainLooper(); 857 Looper.getMainLooper().setSlowLogThresholdMs( 858 SLOW_DISPATCH_THRESHOLD_MS, SLOW_DELIVERY_THRESHOLD_MS); 859 860 SystemServiceRegistry.sEnableServiceNotFoundWtf = true; 861 862 // Initialize native services. 863 System.loadLibrary("android_servers"); 864 865 // Allow heap / perf profiling. 866 initZygoteChildHeapProfiling(); 867 868 // Debug builds - spawn a thread to monitor for fd leaks. 869 if (Build.IS_DEBUGGABLE) { 870 spawnFdLeakCheckThread(); 871 } 872 873 // Check whether we failed to shut down last time we tried. 874 // This call may not return. 875 performPendingShutdown(); 876 877 // Initialize the system context. 878 createSystemContext(); 879 880 // Call per-process mainline module initialization. 881 ActivityThread.initializeMainlineModules(); 882 883 // Sets the dumper service 884 ServiceManager.addService("system_server_dumper", mDumper); 885 mDumper.addDumpable(this); 886 887 // Create the system service manager. 888 mSystemServiceManager = new SystemServiceManager(mSystemContext); 889 mSystemServiceManager.setStartInfo(mRuntimeRestart, 890 mRuntimeStartElapsedTime, mRuntimeStartUptime); 891 mDumper.addDumpable(mSystemServiceManager); 892 893 LocalServices.addService(SystemServiceManager.class, mSystemServiceManager); 894 // Prepare the thread pool for init tasks that can be parallelized 895 SystemServerInitThreadPool tp = SystemServerInitThreadPool.start(); 896 mDumper.addDumpable(tp); 897 898 // Lazily load the pre-installed system font map in SystemServer only if we're not doing 899 // the optimized font loading in the FontManagerService. 900 if (!com.android.text.flags.Flags.useOptimizedBoottimeFontLoading() 901 && Typeface.ENABLE_LAZY_TYPEFACE_INITIALIZATION) { 902 Slog.i(TAG, "Loading pre-installed system font map."); 903 Typeface.loadPreinstalledSystemFontMap(); 904 } 905 906 // Attach JVMTI agent if this is a debuggable build and the system property is set. 907 if (Build.IS_DEBUGGABLE) { 908 // Property is of the form "library_path=parameters". 909 String jvmtiAgent = SystemProperties.get("persist.sys.dalvik.jvmtiagent"); 910 if (!jvmtiAgent.isEmpty()) { 911 int equalIndex = jvmtiAgent.indexOf('='); 912 String libraryPath = jvmtiAgent.substring(0, equalIndex); 913 String parameterList = 914 jvmtiAgent.substring(equalIndex + 1, jvmtiAgent.length()); 915 // Attach the agent. 916 try { 917 Debug.attachJvmtiAgent(libraryPath, parameterList, null); 918 } catch (Exception e) { 919 Slog.e("System", "*************************************************"); 920 Slog.e("System", "********** Failed to load jvmti plugin: " + jvmtiAgent); 921 } 922 } 923 } 924 } finally { 925 t.traceEnd(); // InitBeforeStartServices 926 } 927 928 // Setup the default WTF handler 929 RuntimeInit.setDefaultApplicationWtfHandler(SystemServer::handleEarlySystemWtf); 930 931 // Start services. 932 try { 933 t.traceBegin("StartServices"); 934 startBootstrapServices(t); 935 startCoreServices(t); 936 startOtherServices(t); 937 startApexServices(t); 938 // Only update the timeout after starting all the services so that we use 939 // the default timeout to start system server. 940 updateWatchdogTimeout(t); 941 CriticalEventLog.getInstance().logSystemServerStarted(); 942 } catch (Throwable ex) { 943 Slog.e("System", "******************************************"); 944 Slog.e("System", "************ Failure starting system services", ex); 945 throw ex; 946 } finally { 947 t.traceEnd(); // StartServices 948 } 949 950 StrictMode.initVmDefaults(null); 951 952 if (!mRuntimeRestart && !isFirstBootOrUpgrade()) { 953 final long uptimeMillis = SystemClock.elapsedRealtime(); 954 FrameworkStatsLog.write(FrameworkStatsLog.BOOT_TIME_EVENT_ELAPSED_TIME_REPORTED, 955 FrameworkStatsLog.BOOT_TIME_EVENT_ELAPSED_TIME__EVENT__SYSTEM_SERVER_READY, 956 uptimeMillis); 957 final long maxUptimeMillis = 60 * 1000; 958 if (uptimeMillis > maxUptimeMillis) { 959 Slog.wtf(SYSTEM_SERVER_TIMING_TAG, 960 "SystemServer init took too long. uptimeMillis=" + uptimeMillis); 961 } 962 } 963 964 // Set binder transaction callback after starting system services 965 Binder.setTransactionCallback(new IBinderCallback() { 966 @Override 967 public void onTransactionError(int pid, int code, int flags, int err) { 968 mActivityManagerService.frozenBinderTransactionDetected(pid, code, flags, err); 969 } 970 }); 971 972 // Loop forever. 973 Looper.loop(); 974 throw new RuntimeException("Main thread loop unexpectedly exited"); 975 } 976 isValidTimeZoneId(String timezoneProperty)977 private static boolean isValidTimeZoneId(String timezoneProperty) { 978 return timezoneProperty != null 979 && !timezoneProperty.isEmpty() 980 && ZoneInfoDb.getInstance().hasTimeZone(timezoneProperty); 981 } 982 isFirstBootOrUpgrade()983 private boolean isFirstBootOrUpgrade() { 984 return mPackageManagerService.isFirstBoot() || mPackageManagerService.isDeviceUpgrading(); 985 } 986 reportWtf(String msg, Throwable e)987 private void reportWtf(String msg, Throwable e) { 988 Slog.w(TAG, "***********************************************"); 989 Slog.wtf(TAG, "BOOT FAILURE " + msg, e); 990 } 991 performPendingShutdown()992 private void performPendingShutdown() { 993 final String shutdownAction = SystemProperties.get( 994 ShutdownThread.SHUTDOWN_ACTION_PROPERTY, ""); 995 if (shutdownAction != null && shutdownAction.length() > 0) { 996 boolean reboot = (shutdownAction.charAt(0) == '1'); 997 998 final String reason; 999 if (shutdownAction.length() > 1) { 1000 reason = shutdownAction.substring(1, shutdownAction.length()); 1001 } else { 1002 reason = null; 1003 } 1004 1005 // If it's a pending reboot into recovery to apply an update, 1006 // always make sure uncrypt gets executed properly when needed. 1007 // If '/cache/recovery/block.map' hasn't been created, stop the 1008 // reboot which will fail for sure, and get a chance to capture a 1009 // bugreport when that's still feasible. (Bug: 26444951) 1010 if (reason != null && reason.startsWith(PowerManager.REBOOT_RECOVERY_UPDATE)) { 1011 File packageFile = new File(UNCRYPT_PACKAGE_FILE); 1012 if (packageFile.exists()) { 1013 String filename = null; 1014 try { 1015 filename = FileUtils.readTextFile(packageFile, 0, null); 1016 } catch (IOException e) { 1017 Slog.e(TAG, "Error reading uncrypt package file", e); 1018 } 1019 1020 if (filename != null && filename.startsWith("/data")) { 1021 if (!new File(BLOCK_MAP_FILE).exists()) { 1022 Slog.e(TAG, "Can't find block map file, uncrypt failed or " + 1023 "unexpected runtime restart?"); 1024 return; 1025 } 1026 } 1027 } 1028 } 1029 Runnable runnable = new Runnable() { 1030 @Override 1031 public void run() { 1032 ShutdownThread.rebootOrShutdown(null, reboot, reason); 1033 } 1034 }; 1035 1036 // ShutdownThread must run on a looper capable of displaying the UI. 1037 Message msg = Message.obtain(UiThread.getHandler(), runnable); 1038 msg.setAsynchronous(true); 1039 UiThread.getHandler().sendMessage(msg); 1040 1041 } 1042 } 1043 createSystemContext()1044 private void createSystemContext() { 1045 ActivityThread activityThread = ActivityThread.systemMain(); 1046 mSystemContext = activityThread.getSystemContext(); 1047 mSystemContext.setTheme(DEFAULT_SYSTEM_THEME); 1048 1049 final Context systemUiContext = activityThread.getSystemUiContext(); 1050 systemUiContext.setTheme(DEFAULT_SYSTEM_THEME); 1051 Trace.registerWithPerfetto(); 1052 } 1053 1054 /** 1055 * Starts the small tangle of critical services that are needed to get the system off the 1056 * ground. These services have complex mutual dependencies which is why we initialize them all 1057 * in one place here. Unless your service is also entwined in these dependencies, it should be 1058 * initialized in one of the other functions. 1059 */ startBootstrapServices(@onNull TimingsTraceAndSlog t)1060 private void startBootstrapServices(@NonNull TimingsTraceAndSlog t) { 1061 t.traceBegin("startBootstrapServices"); 1062 1063 t.traceBegin("ArtModuleServiceInitializer"); 1064 // This needs to happen before DexUseManagerLocal init. We do it here to avoid colliding 1065 // with a GC. ArtModuleServiceInitializer is a class from a separate dex file 1066 // "service-art.jar", so referencing it involves the class linker. The class linker and the 1067 // GC are mutually exclusive (b/263486535). Therefore, we do this here to force trigger the 1068 // class linker earlier. If we did this later, especially after PackageManagerService init, 1069 // the class linker would be consistently blocked by a GC because PackageManagerService 1070 // allocates a lot of memory and almost certainly triggers a GC. 1071 ArtModuleServiceInitializer.setArtModuleServiceManager(new ArtModuleServiceManager()); 1072 t.traceEnd(); 1073 1074 // Start the watchdog as early as possible so we can crash the system server 1075 // if we deadlock during early boot 1076 t.traceBegin("StartWatchdog"); 1077 final Watchdog watchdog = Watchdog.getInstance(); 1078 watchdog.start(); 1079 mDumper.addDumpable(watchdog); 1080 t.traceEnd(); 1081 1082 Slog.i(TAG, "Reading configuration..."); 1083 final String TAG_SYSTEM_CONFIG = "ReadingSystemConfig"; 1084 t.traceBegin(TAG_SYSTEM_CONFIG); 1085 SystemServerInitThreadPool.submit(SystemConfig::getInstance, TAG_SYSTEM_CONFIG); 1086 t.traceEnd(); 1087 1088 // Platform compat service is used by ActivityManagerService, PackageManagerService, and 1089 // possibly others in the future. b/135010838. 1090 t.traceBegin("PlatformCompat"); 1091 PlatformCompat platformCompat = new PlatformCompat(mSystemContext); 1092 ServiceManager.addService(Context.PLATFORM_COMPAT_SERVICE, platformCompat); 1093 ServiceManager.addService(Context.PLATFORM_COMPAT_NATIVE_SERVICE, 1094 new PlatformCompatNative(platformCompat)); 1095 AppCompatCallbacks.install(new long[0], new long[0]); 1096 t.traceEnd(); 1097 1098 // FileIntegrityService responds to requests from apps and the system. It needs to run after 1099 // the source (i.e. keystore) is ready, and before the apps (or the first customer in the 1100 // system) run. 1101 t.traceBegin("StartFileIntegrityService"); 1102 mSystemServiceManager.startService(FileIntegrityService.class); 1103 t.traceEnd(); 1104 1105 // Wait for installd to finish starting up so that it has a chance to 1106 // create critical directories such as /data/user with the appropriate 1107 // permissions. We need this to complete before we initialize other services. 1108 t.traceBegin("StartInstaller"); 1109 Installer installer = mSystemServiceManager.startService(Installer.class); 1110 t.traceEnd(); 1111 1112 // In some cases after launching an app we need to access device identifiers, 1113 // therefore register the device identifier policy before the activity manager. 1114 t.traceBegin("DeviceIdentifiersPolicyService"); 1115 mSystemServiceManager.startService(DeviceIdentifiersPolicyService.class); 1116 t.traceEnd(); 1117 1118 // Starts a service for reading runtime flag overrides, and keeping processes 1119 // in sync with one another. 1120 t.traceBegin("StartFeatureFlagsService"); 1121 mSystemServiceManager.startService(FeatureFlagsService.class); 1122 t.traceEnd(); 1123 1124 // Uri Grants Manager. 1125 t.traceBegin("UriGrantsManagerService"); 1126 mSystemServiceManager.startService(UriGrantsManagerService.Lifecycle.class); 1127 t.traceEnd(); 1128 1129 t.traceBegin("StartPowerStatsService"); 1130 // Tracks rail data to be used for power statistics. 1131 mSystemServiceManager.startService(PowerStatsService.class); 1132 t.traceEnd(); 1133 1134 t.traceBegin("StartIStatsService"); 1135 startIStatsService(); 1136 t.traceEnd(); 1137 1138 // Start MemtrackProxyService before ActivityManager, so that early calls 1139 // to Memtrack::getMemory() don't fail. 1140 t.traceBegin("MemtrackProxyService"); 1141 startMemtrackProxyService(); 1142 t.traceEnd(); 1143 1144 // Start AccessCheckingService which provides new implementation for permission and app op. 1145 t.traceBegin("StartAccessCheckingService"); 1146 LocalServices.addService(PermissionMigrationHelper.class, 1147 new PermissionMigrationHelperImpl()); 1148 LocalServices.addService(AppOpMigrationHelper.class, 1149 new AppOpMigrationHelperImpl()); 1150 mSystemServiceManager.startService(AccessCheckingService.class); 1151 t.traceEnd(); 1152 1153 // Activity manager runs the show. 1154 t.traceBegin("StartActivityManager"); 1155 // TODO: Might need to move after migration to WM. 1156 ActivityTaskManagerService atm = mSystemServiceManager.startService( 1157 ActivityTaskManagerService.Lifecycle.class).getService(); 1158 mActivityManagerService = ActivityManagerService.Lifecycle.startService( 1159 mSystemServiceManager, atm); 1160 mActivityManagerService.setSystemServiceManager(mSystemServiceManager); 1161 mActivityManagerService.setInstaller(installer); 1162 mWindowManagerGlobalLock = atm.getGlobalLock(); 1163 t.traceEnd(); 1164 1165 // Data loader manager service needs to be started before package manager 1166 t.traceBegin("StartDataLoaderManagerService"); 1167 mDataLoaderManagerService = mSystemServiceManager.startService( 1168 DataLoaderManagerService.class); 1169 t.traceEnd(); 1170 1171 // Incremental service needs to be started before package manager 1172 t.traceBegin("StartIncrementalService"); 1173 mIncrementalServiceHandle = startIncrementalService(); 1174 t.traceEnd(); 1175 1176 // Power manager needs to be started early because other services need it. 1177 // Native daemons may be watching for it to be registered so it must be ready 1178 // to handle incoming binder calls immediately (including being able to verify 1179 // the permissions for those calls). 1180 t.traceBegin("StartPowerManager"); 1181 mPowerManagerService = mSystemServiceManager.startService(PowerManagerService.class); 1182 t.traceEnd(); 1183 1184 t.traceBegin("StartThermalManager"); 1185 mSystemServiceManager.startService(ThermalManagerService.class); 1186 t.traceEnd(); 1187 1188 // Now that the power manager has been started, let the activity manager 1189 // initialize power management features. 1190 t.traceBegin("InitPowerManagement"); 1191 mActivityManagerService.initPowerManagement(); 1192 t.traceEnd(); 1193 1194 // Bring up recovery system in case a rescue party needs a reboot 1195 t.traceBegin("StartRecoverySystemService"); 1196 mSystemServiceManager.startService(RecoverySystemService.Lifecycle.class); 1197 t.traceEnd(); 1198 1199 // Initialize RescueParty. 1200 RescueParty.registerHealthObserver(mSystemContext); 1201 if (!Flags.recoverabilityDetection()) { 1202 // Now that we have the bare essentials of the OS up and running, take 1203 // note that we just booted, which might send out a rescue party if 1204 // we're stuck in a runtime restart loop. 1205 PackageWatchdog.getInstance(mSystemContext).noteBoot(); 1206 } 1207 1208 // Manages LEDs and display backlight so we need it to bring up the display. 1209 t.traceBegin("StartLightsService"); 1210 mSystemServiceManager.startService(LightsService.class); 1211 t.traceEnd(); 1212 1213 t.traceBegin("StartDisplayOffloadService"); 1214 // Package manager isn't started yet; need to use SysProp not hardware feature 1215 if (SystemProperties.getBoolean("config.enable_display_offload", false)) { 1216 mSystemServiceManager.startService(WEAR_DISPLAYOFFLOAD_SERVICE_CLASS); 1217 } 1218 t.traceEnd(); 1219 1220 // Display manager is needed to provide display metrics before package manager 1221 // starts up. 1222 t.traceBegin("StartDisplayManager"); 1223 mDisplayManagerService = mSystemServiceManager.startService(DisplayManagerService.class); 1224 t.traceEnd(); 1225 1226 // We need the default display before we can initialize the package manager. 1227 t.traceBegin("WaitForDisplay"); 1228 mSystemServiceManager.startBootPhase(t, SystemService.PHASE_WAIT_FOR_DEFAULT_DISPLAY); 1229 t.traceEnd(); 1230 1231 // Start the package manager. 1232 if (!mRuntimeRestart) { 1233 FrameworkStatsLog.write(FrameworkStatsLog.BOOT_TIME_EVENT_ELAPSED_TIME_REPORTED, 1234 FrameworkStatsLog 1235 .BOOT_TIME_EVENT_ELAPSED_TIME__EVENT__PACKAGE_MANAGER_INIT_START, 1236 SystemClock.elapsedRealtime()); 1237 } 1238 1239 t.traceBegin("StartDomainVerificationService"); 1240 DomainVerificationService domainVerificationService = new DomainVerificationService( 1241 mSystemContext, SystemConfig.getInstance(), platformCompat); 1242 mSystemServiceManager.startService(domainVerificationService); 1243 t.traceEnd(); 1244 1245 t.traceBegin("StartPackageManagerService"); 1246 try { 1247 Watchdog.getInstance().pauseWatchingCurrentThread("packagemanagermain"); 1248 mPackageManagerService = PackageManagerService.main( 1249 mSystemContext, installer, domainVerificationService, 1250 mFactoryTestMode != FactoryTest.FACTORY_TEST_OFF); 1251 } finally { 1252 Watchdog.getInstance().resumeWatchingCurrentThread("packagemanagermain"); 1253 } 1254 1255 mFirstBoot = mPackageManagerService.isFirstBoot(); 1256 mPackageManager = mSystemContext.getPackageManager(); 1257 t.traceEnd(); 1258 1259 t.traceBegin("DexUseManagerLocal"); 1260 // DexUseManagerLocal needs to be loaded after PackageManagerLocal has been registered, but 1261 // before PackageManagerService starts processing binder calls to notifyDexLoad. 1262 LocalManagerRegistry.addManager( 1263 DexUseManagerLocal.class, DexUseManagerLocal.createInstance(mSystemContext)); 1264 t.traceEnd(); 1265 1266 if (!mRuntimeRestart && !isFirstBootOrUpgrade()) { 1267 FrameworkStatsLog.write(FrameworkStatsLog.BOOT_TIME_EVENT_ELAPSED_TIME_REPORTED, 1268 FrameworkStatsLog 1269 .BOOT_TIME_EVENT_ELAPSED_TIME__EVENT__PACKAGE_MANAGER_INIT_READY, 1270 SystemClock.elapsedRealtime()); 1271 } 1272 // Manages A/B OTA dexopting. This is a bootstrap service as we need it to rename 1273 // A/B artifacts after boot, before anything else might touch/need them. 1274 boolean disableOtaDexopt = SystemProperties.getBoolean("config.disable_otadexopt", false); 1275 if (!disableOtaDexopt) { 1276 t.traceBegin("StartOtaDexOptService"); 1277 try { 1278 Watchdog.getInstance().pauseWatchingCurrentThread("moveab"); 1279 OtaDexoptService.main(mSystemContext, mPackageManagerService); 1280 } catch (Throwable e) { 1281 reportWtf("starting OtaDexOptService", e); 1282 } finally { 1283 Watchdog.getInstance().resumeWatchingCurrentThread("moveab"); 1284 t.traceEnd(); 1285 } 1286 } 1287 1288 if (Build.IS_ARC) { 1289 t.traceBegin("StartArcSystemHealthService"); 1290 mSystemServiceManager.startService(ARC_SYSTEM_HEALTH_SERVICE); 1291 t.traceEnd(); 1292 } 1293 1294 t.traceBegin("StartUserManagerService"); 1295 mSystemServiceManager.startService(UserManagerService.LifeCycle.class); 1296 t.traceEnd(); 1297 1298 // Initialize attribute cache used to cache resources from packages. 1299 t.traceBegin("InitAttributerCache"); 1300 AttributeCache.init(mSystemContext); 1301 t.traceEnd(); 1302 1303 // Set up the Application instance for the system process and get started. 1304 t.traceBegin("SetSystemProcess"); 1305 mActivityManagerService.setSystemProcess(); 1306 t.traceEnd(); 1307 1308 // The package receiver depends on the activity service in order to get registered. 1309 platformCompat.registerPackageReceiver(mSystemContext); 1310 1311 // Complete the watchdog setup with an ActivityManager instance and listen for reboots 1312 // Do this only after the ActivityManagerService is properly started as a system process 1313 t.traceBegin("InitWatchdog"); 1314 watchdog.init(mSystemContext, mActivityManagerService); 1315 t.traceEnd(); 1316 1317 // DisplayManagerService needs to setup android.display scheduling related policies 1318 // since setSystemProcess() would have overridden policies due to setProcessGroup 1319 mDisplayManagerService.setupSchedulerPolicies(); 1320 1321 // Manages Overlay packages 1322 t.traceBegin("StartOverlayManagerService"); 1323 mSystemServiceManager.startService(new OverlayManagerService(mSystemContext)); 1324 t.traceEnd(); 1325 1326 // Manages Resources packages 1327 t.traceBegin("StartResourcesManagerService"); 1328 ResourcesManagerService resourcesService = new ResourcesManagerService(mSystemContext); 1329 resourcesService.setActivityManagerService(mActivityManagerService); 1330 mSystemServiceManager.startService(resourcesService); 1331 t.traceEnd(); 1332 1333 t.traceBegin("StartSensorPrivacyService"); 1334 mSystemServiceManager.startService(new SensorPrivacyService(mSystemContext)); 1335 t.traceEnd(); 1336 1337 if (SystemProperties.getInt("persist.sys.displayinset.top", 0) > 0) { 1338 // DisplayManager needs the overlay immediately. 1339 mActivityManagerService.updateSystemUiContext(); 1340 LocalServices.getService(DisplayManagerInternal.class).onOverlayChanged(); 1341 } 1342 1343 // The sensor service needs access to package manager service, app ops 1344 // service, and permissions service, therefore we start it after them. 1345 t.traceBegin("StartSensorService"); 1346 mSystemServiceManager.startService(SensorService.class); 1347 t.traceEnd(); 1348 t.traceEnd(); // startBootstrapServices 1349 } 1350 1351 /** 1352 * Starts some essential services that are not tangled up in the bootstrap process. 1353 */ startCoreServices(@onNull TimingsTraceAndSlog t)1354 private void startCoreServices(@NonNull TimingsTraceAndSlog t) { 1355 t.traceBegin("startCoreServices"); 1356 1357 // Service for system config 1358 t.traceBegin("StartSystemConfigService"); 1359 mSystemServiceManager.startService(SystemConfigService.class); 1360 t.traceEnd(); 1361 1362 t.traceBegin("StartBatteryService"); 1363 // Tracks the battery level. Requires LightService. 1364 mSystemServiceManager.startService(BatteryService.class); 1365 t.traceEnd(); 1366 1367 // Tracks application usage stats. 1368 t.traceBegin("StartUsageService"); 1369 mSystemServiceManager.startService(UsageStatsService.class); 1370 mActivityManagerService.setUsageStatsManager( 1371 LocalServices.getService(UsageStatsManagerInternal.class)); 1372 t.traceEnd(); 1373 1374 // Tracks whether the updatable WebView is in a ready state and watches for update installs. 1375 if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_WEBVIEW)) { 1376 t.traceBegin("StartWebViewUpdateService"); 1377 mWebViewUpdateService = mSystemServiceManager.startService(WebViewUpdateService.class); 1378 t.traceEnd(); 1379 } 1380 1381 // Tracks and caches the device state. 1382 t.traceBegin("StartCachedDeviceStateService"); 1383 mSystemServiceManager.startService(CachedDeviceStateService.class); 1384 t.traceEnd(); 1385 1386 // Tracks cpu time spent in binder calls 1387 t.traceBegin("StartBinderCallsStatsService"); 1388 mSystemServiceManager.startService(BinderCallsStatsService.LifeCycle.class); 1389 t.traceEnd(); 1390 1391 // Tracks time spent in handling messages in handlers. 1392 t.traceBegin("StartLooperStatsService"); 1393 mSystemServiceManager.startService(LooperStatsService.Lifecycle.class); 1394 t.traceEnd(); 1395 1396 // Manages apk rollbacks. 1397 t.traceBegin("StartRollbackManagerService"); 1398 mSystemServiceManager.startService(RollbackManagerService.class); 1399 t.traceEnd(); 1400 1401 // Tracks native tombstones. 1402 t.traceBegin("StartNativeTombstoneManagerService"); 1403 mSystemServiceManager.startService(NativeTombstoneManagerService.class); 1404 t.traceEnd(); 1405 1406 // Service to capture bugreports. 1407 t.traceBegin("StartBugreportManagerService"); 1408 mSystemServiceManager.startService(BugreportManagerService.class); 1409 t.traceEnd(); 1410 1411 // Service for GPU and GPU driver. 1412 t.traceBegin("GpuService"); 1413 mSystemServiceManager.startService(GpuService.class); 1414 t.traceEnd(); 1415 1416 // Handles system process requests for remotely provisioned keys & data. 1417 t.traceBegin("StartRemoteProvisioningService"); 1418 mSystemServiceManager.startService(RemoteProvisioningService.class); 1419 t.traceEnd(); 1420 1421 // TODO(b/277600174): Start CpuMonitorService on all builds and not just on debuggable 1422 // builds once the Android JobScheduler starts using this service. 1423 if (Build.IS_DEBUGGABLE || Build.IS_ENG) { 1424 // Service for CPU monitor. 1425 t.traceBegin("CpuMonitorService"); 1426 mSystemServiceManager.startService(CpuMonitorService.class); 1427 t.traceEnd(); 1428 } 1429 1430 t.traceEnd(); // startCoreServices 1431 } 1432 1433 /** 1434 * Starts a miscellaneous grab bag of stuff that has yet to be refactored and organized. 1435 */ startOtherServices(@onNull TimingsTraceAndSlog t)1436 private void startOtherServices(@NonNull TimingsTraceAndSlog t) { 1437 t.traceBegin("startOtherServices"); 1438 mSystemServiceManager.updateOtherServicesStartIndex(); 1439 1440 final Context context = mSystemContext; 1441 DynamicSystemService dynamicSystem = null; 1442 IStorageManager storageManager = null; 1443 NetworkManagementService networkManagement = null; 1444 VpnManagerService vpnManager = null; 1445 VcnManagementService vcnManagement = null; 1446 NetworkPolicyManagerService networkPolicy = null; 1447 WindowManagerService wm = null; 1448 NetworkTimeUpdateService networkTimeUpdater = null; 1449 InputManagerService inputManager = null; 1450 TelephonyRegistry telephonyRegistry = null; 1451 ConsumerIrService consumerIr = null; 1452 MmsServiceBroker mmsService = null; 1453 HardwarePropertiesManagerService hardwarePropertiesService = null; 1454 PacProxyService pacProxyService = null; 1455 1456 boolean disableSystemTextClassifier = SystemProperties.getBoolean( 1457 "config.disable_systemtextclassifier", false); 1458 1459 boolean disableNetworkTime = SystemProperties.getBoolean("config.disable_networktime", 1460 false); 1461 boolean disableCameraService = SystemProperties.getBoolean("config.disable_cameraservice", 1462 false); 1463 1464 boolean isWatch = context.getPackageManager().hasSystemFeature( 1465 PackageManager.FEATURE_WATCH); 1466 1467 boolean isArc = context.getPackageManager().hasSystemFeature( 1468 "org.chromium.arc"); 1469 1470 boolean isTv = context.getPackageManager().hasSystemFeature( 1471 PackageManager.FEATURE_LEANBACK); 1472 1473 boolean enableVrService = context.getPackageManager().hasSystemFeature( 1474 PackageManager.FEATURE_VR_MODE_HIGH_PERFORMANCE); 1475 1476 if (!Flags.recoverabilityDetection()) { 1477 // For debugging RescueParty 1478 if (Build.IS_DEBUGGABLE 1479 && SystemProperties.getBoolean("debug.crash_system", false)) { 1480 throw new RuntimeException(); 1481 } 1482 } 1483 1484 try { 1485 final String SECONDARY_ZYGOTE_PRELOAD = "SecondaryZygotePreload"; 1486 // We start the preload ~1s before the webview factory preparation, to 1487 // ensure that it completes before the 32 bit relro process is forked 1488 // from the zygote. In the event that it takes too long, the webview 1489 // RELRO process will block, but it will do so without holding any locks. 1490 mZygotePreload = SystemServerInitThreadPool.submit(() -> { 1491 try { 1492 Slog.i(TAG, SECONDARY_ZYGOTE_PRELOAD); 1493 TimingsTraceAndSlog traceLog = TimingsTraceAndSlog.newAsyncLog(); 1494 traceLog.traceBegin(SECONDARY_ZYGOTE_PRELOAD); 1495 String[] abis32 = Build.SUPPORTED_32_BIT_ABIS; 1496 if (abis32.length > 0 && !Process.ZYGOTE_PROCESS.preloadDefault(abis32[0])) { 1497 Slog.e(TAG, "Unable to preload default resources for secondary"); 1498 } 1499 traceLog.traceEnd(); 1500 } catch (Exception ex) { 1501 Slog.e(TAG, "Exception preloading default resources", ex); 1502 } 1503 }, SECONDARY_ZYGOTE_PRELOAD); 1504 1505 t.traceBegin("StartKeyAttestationApplicationIdProviderService"); 1506 ServiceManager.addService("sec_key_att_app_id_provider", 1507 new KeyAttestationApplicationIdProviderService(context)); 1508 t.traceEnd(); 1509 1510 t.traceBegin("StartKeyChainSystemService"); 1511 mSystemServiceManager.startService(KeyChainSystemService.class); 1512 t.traceEnd(); 1513 1514 t.traceBegin("StartBinaryTransparencyService"); 1515 mSystemServiceManager.startService(BinaryTransparencyService.class); 1516 t.traceEnd(); 1517 1518 t.traceBegin("StartSchedulingPolicyService"); 1519 ServiceManager.addService("scheduling_policy", new SchedulingPolicyService()); 1520 t.traceEnd(); 1521 1522 // TelecomLoader hooks into classes with defined HFP logic, 1523 // so check for either telephony or microphone. 1524 if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_MICROPHONE) 1525 || mPackageManager.hasSystemFeature(PackageManager.FEATURE_TELECOM) 1526 || mPackageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY)) { 1527 t.traceBegin("StartTelecomLoaderService"); 1528 mSystemServiceManager.startService(TelecomLoaderService.class); 1529 t.traceEnd(); 1530 } 1531 1532 t.traceBegin("StartTelephonyRegistry"); 1533 telephonyRegistry = new TelephonyRegistry( 1534 context, new TelephonyRegistry.ConfigurationProvider()); 1535 ServiceManager.addService("telephony.registry", telephonyRegistry); 1536 t.traceEnd(); 1537 1538 t.traceBegin("StartEntropyMixer"); 1539 mEntropyMixer = new EntropyMixer(context); 1540 t.traceEnd(); 1541 1542 mContentResolver = context.getContentResolver(); 1543 1544 // The AccountManager must come before the ContentService 1545 t.traceBegin("StartAccountManagerService"); 1546 mSystemServiceManager.startService(AccountManagerService.Lifecycle.class); 1547 t.traceEnd(); 1548 1549 t.traceBegin("StartContentService"); 1550 mSystemServiceManager.startService(ContentService.Lifecycle.class); 1551 t.traceEnd(); 1552 1553 t.traceBegin("InstallSystemProviders"); 1554 mActivityManagerService.getContentProviderHelper().installSystemProviders(); 1555 // Device configuration used to be part of System providers 1556 mSystemServiceManager.startService(UPDATABLE_DEVICE_CONFIG_SERVICE_CLASS); 1557 // Now that SettingsProvider is ready, reactivate SQLiteCompatibilityWalFlags 1558 SQLiteCompatibilityWalFlags.reset(); 1559 t.traceEnd(); 1560 1561 // Records errors and logs, for example wtf() 1562 // Currently this service indirectly depends on SettingsProvider so do this after 1563 // InstallSystemProviders. 1564 t.traceBegin("StartDropBoxManager"); 1565 mSystemServiceManager.startService(DropBoxManagerService.class); 1566 t.traceEnd(); 1567 1568 if (android.permission.flags.Flags.enhancedConfirmationModeApisEnabled()) { 1569 t.traceBegin("StartEnhancedConfirmationService"); 1570 mSystemServiceManager.startService(ENHANCED_CONFIRMATION_SERVICE_CLASS); 1571 t.traceEnd(); 1572 } 1573 1574 t.traceBegin("StartHintManager"); 1575 mSystemServiceManager.startService(HintManagerService.class); 1576 t.traceEnd(); 1577 1578 // Grants default permissions and defines roles 1579 t.traceBegin("StartRoleManagerService"); 1580 LocalManagerRegistry.addManager(RoleServicePlatformHelper.class, 1581 new RoleServicePlatformHelperImpl(mSystemContext)); 1582 mSystemServiceManager.startService(ROLE_SERVICE_CLASS); 1583 t.traceEnd(); 1584 1585 if (!isTv) { 1586 t.traceBegin("StartVibratorManagerService"); 1587 mSystemServiceManager.startService(VibratorManagerService.Lifecycle.class); 1588 t.traceEnd(); 1589 } 1590 1591 t.traceBegin("StartDynamicSystemService"); 1592 dynamicSystem = new DynamicSystemService(context); 1593 ServiceManager.addService("dynamic_system", dynamicSystem); 1594 t.traceEnd(); 1595 1596 if (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CONSUMER_IR)) { 1597 t.traceBegin("StartConsumerIrService"); 1598 consumerIr = new ConsumerIrService(context); 1599 ServiceManager.addService(Context.CONSUMER_IR_SERVICE, consumerIr); 1600 t.traceEnd(); 1601 } 1602 1603 // TODO(aml-jobscheduler): Think about how to do it properly. 1604 t.traceBegin("StartAlarmManagerService"); 1605 mSystemServiceManager.startService(AlarmManagerService.class); 1606 t.traceEnd(); 1607 1608 t.traceBegin("StartInputManagerService"); 1609 inputManager = new InputManagerService(context); 1610 t.traceEnd(); 1611 1612 t.traceBegin("DeviceStateManagerService"); 1613 mSystemServiceManager.startService(DeviceStateManagerService.class); 1614 t.traceEnd(); 1615 1616 if (!disableCameraService) { 1617 t.traceBegin("StartCameraServiceProxy"); 1618 mSystemServiceManager.startService(CameraServiceProxy.class); 1619 t.traceEnd(); 1620 } 1621 1622 t.traceBegin("StartWindowManagerService"); 1623 // WMS needs sensor service ready 1624 mSystemServiceManager.startBootPhase(t, SystemService.PHASE_WAIT_FOR_SENSOR_SERVICE); 1625 wm = WindowManagerService.main(context, inputManager, !mFirstBoot, 1626 new PhoneWindowManager(), mActivityManagerService.mActivityTaskManager); 1627 ServiceManager.addService(Context.WINDOW_SERVICE, wm, /* allowIsolated= */ false, 1628 DUMP_FLAG_PRIORITY_CRITICAL | DUMP_FLAG_PRIORITY_HIGH 1629 | DUMP_FLAG_PROTO); 1630 ServiceManager.addService(Context.INPUT_SERVICE, inputManager, 1631 /* allowIsolated= */ false, DUMP_FLAG_PRIORITY_CRITICAL); 1632 t.traceEnd(); 1633 1634 t.traceBegin("SetWindowManagerService"); 1635 mActivityManagerService.setWindowManager(wm); 1636 t.traceEnd(); 1637 1638 t.traceBegin("WindowManagerServiceOnInitReady"); 1639 wm.onInitReady(); 1640 t.traceEnd(); 1641 1642 // Start receiving calls from SensorManager services. Start in a separate thread 1643 // because it need to connect to SensorManager. This has to start 1644 // after PHASE_WAIT_FOR_SENSOR_SERVICE is done. 1645 SystemServerInitThreadPool.submit(() -> { 1646 TimingsTraceAndSlog traceLog = TimingsTraceAndSlog.newAsyncLog(); 1647 traceLog.traceBegin(START_SENSOR_MANAGER_SERVICE); 1648 startISensorManagerService(); 1649 traceLog.traceEnd(); 1650 }, START_SENSOR_MANAGER_SERVICE); 1651 1652 SystemServerInitThreadPool.submit(() -> { 1653 TimingsTraceAndSlog traceLog = TimingsTraceAndSlog.newAsyncLog(); 1654 traceLog.traceBegin(START_HIDL_SERVICES); 1655 startHidlServices(); 1656 traceLog.traceEnd(); 1657 }, START_HIDL_SERVICES); 1658 1659 if (!isWatch && enableVrService) { 1660 t.traceBegin("StartVrManagerService"); 1661 mSystemServiceManager.startService(VrManagerService.class); 1662 t.traceEnd(); 1663 } 1664 1665 t.traceBegin("StartInputManager"); 1666 inputManager.setWindowManagerCallbacks(wm.getInputManagerCallback()); 1667 inputManager.start(); 1668 t.traceEnd(); 1669 1670 // TODO: Use service dependencies instead. 1671 t.traceBegin("DisplayManagerWindowManagerAndInputReady"); 1672 mDisplayManagerService.windowManagerAndInputReady(); 1673 t.traceEnd(); 1674 1675 if (mFactoryTestMode == FactoryTest.FACTORY_TEST_LOW_LEVEL) { 1676 Slog.i(TAG, "No Bluetooth Service (factory test)"); 1677 } else if (!context.getPackageManager().hasSystemFeature 1678 (PackageManager.FEATURE_BLUETOOTH)) { 1679 Slog.i(TAG, "No Bluetooth Service (Bluetooth Hardware Not Present)"); 1680 } else { 1681 t.traceBegin("StartBluetoothService"); 1682 mSystemServiceManager.startServiceFromJar(BLUETOOTH_SERVICE_CLASS, 1683 BLUETOOTH_APEX_SERVICE_JAR_PATH); 1684 t.traceEnd(); 1685 } 1686 1687 t.traceBegin("IpConnectivityMetrics"); 1688 mSystemServiceManager.startService(IpConnectivityMetrics.class); 1689 t.traceEnd(); 1690 1691 t.traceBegin("NetworkWatchlistService"); 1692 mSystemServiceManager.startService(NetworkWatchlistService.Lifecycle.class); 1693 t.traceEnd(); 1694 1695 t.traceBegin("PinnerService"); 1696 mSystemServiceManager.startService(PinnerService.class); 1697 t.traceEnd(); 1698 1699 if (Build.IS_DEBUGGABLE && ProfcollectForwardingService.enabled()) { 1700 t.traceBegin("ProfcollectForwardingService"); 1701 mSystemServiceManager.startService(ProfcollectForwardingService.class); 1702 t.traceEnd(); 1703 } 1704 1705 t.traceBegin("SignedConfigService"); 1706 SignedConfigService.registerUpdateReceiver(mSystemContext); 1707 t.traceEnd(); 1708 1709 t.traceBegin("AppIntegrityService"); 1710 mSystemServiceManager.startService(AppIntegrityManagerService.class); 1711 t.traceEnd(); 1712 1713 t.traceBegin("StartLogcatManager"); 1714 mSystemServiceManager.startService(LogcatManagerService.class); 1715 t.traceEnd(); 1716 1717 } catch (Throwable e) { 1718 Slog.e("System", "******************************************"); 1719 Slog.e("System", "************ Failure starting core service"); 1720 throw e; 1721 } 1722 1723 // Before things start rolling, be sure we have decided whether 1724 // we are in safe mode. 1725 final boolean safeMode = wm.detectSafeMode(); 1726 if (safeMode) { 1727 // If yes, immediately turn on the global setting for airplane mode. 1728 // Note that this does not send broadcasts at this stage because 1729 // subsystems are not yet up. We will send broadcasts later to ensure 1730 // all listeners have the chance to react with special handling. 1731 Settings.Global.putInt(context.getContentResolver(), 1732 Settings.Global.AIRPLANE_MODE_ON, 1); 1733 } else if (context.getResources().getBoolean(R.bool.config_autoResetAirplaneMode)) { 1734 Settings.Global.putInt(context.getContentResolver(), 1735 Settings.Global.AIRPLANE_MODE_ON, 0); 1736 } 1737 1738 StatusBarManagerService statusBar = null; 1739 INotificationManager notification = null; 1740 CountryDetectorService countryDetector = null; 1741 ILockSettings lockSettings = null; 1742 MediaRouterService mediaRouter = null; 1743 1744 // Bring up services needed for UI. 1745 if (mFactoryTestMode != FactoryTest.FACTORY_TEST_LOW_LEVEL) { 1746 t.traceBegin("StartInputMethodManagerLifecycle"); 1747 String immsClassName = context.getResources().getString( 1748 R.string.config_deviceSpecificInputMethodManagerService); 1749 if (immsClassName.isEmpty()) { 1750 mSystemServiceManager.startService(InputMethodManagerService.Lifecycle.class); 1751 } else { 1752 try { 1753 Slog.i(TAG, "Starting custom IMMS: " + immsClassName); 1754 mSystemServiceManager.startService(immsClassName); 1755 } catch (Throwable e) { 1756 reportWtf("starting " + immsClassName, e); 1757 } 1758 } 1759 t.traceEnd(); 1760 1761 t.traceBegin("StartAccessibilityManagerService"); 1762 try { 1763 mSystemServiceManager.startService(AccessibilityManagerService.Lifecycle.class); 1764 } catch (Throwable e) { 1765 reportWtf("starting Accessibility Manager", e); 1766 } 1767 t.traceEnd(); 1768 } 1769 1770 t.traceBegin("MakeDisplayReady"); 1771 try { 1772 wm.displayReady(); 1773 } catch (Throwable e) { 1774 reportWtf("making display ready", e); 1775 } 1776 t.traceEnd(); 1777 1778 if (mFactoryTestMode != FactoryTest.FACTORY_TEST_LOW_LEVEL) { 1779 if (!"0".equals(SystemProperties.get("system_init.startmountservice"))) { 1780 t.traceBegin("StartStorageManagerService"); 1781 try { 1782 /* 1783 * NotificationManagerService is dependant on StorageManagerService, 1784 * (for media / usb notifications) so we must start StorageManagerService first. 1785 */ 1786 mSystemServiceManager.startService(StorageManagerService.Lifecycle.class); 1787 storageManager = IStorageManager.Stub.asInterface( 1788 ServiceManager.getService("mount")); 1789 } catch (Throwable e) { 1790 reportWtf("starting StorageManagerService", e); 1791 } 1792 t.traceEnd(); 1793 1794 t.traceBegin("StartStorageStatsService"); 1795 try { 1796 mSystemServiceManager.startService(StorageStatsService.Lifecycle.class); 1797 } catch (Throwable e) { 1798 reportWtf("starting StorageStatsService", e); 1799 } 1800 t.traceEnd(); 1801 } 1802 } 1803 1804 // We start this here so that we update our configuration to set watch or television 1805 // as appropriate. 1806 t.traceBegin("StartUiModeManager"); 1807 mSystemServiceManager.startService(UiModeManagerService.class); 1808 t.traceEnd(); 1809 1810 t.traceBegin("StartLocaleManagerService"); 1811 try { 1812 mSystemServiceManager.startService(LocaleManagerService.class); 1813 } catch (Throwable e) { 1814 reportWtf("starting LocaleManagerService service", e); 1815 } 1816 t.traceEnd(); 1817 1818 t.traceBegin("StartGrammarInflectionService"); 1819 try { 1820 mSystemServiceManager.startService(GrammaticalInflectionService.class); 1821 } catch (Throwable e) { 1822 reportWtf("starting GrammarInflectionService service", e); 1823 } 1824 t.traceEnd(); 1825 1826 t.traceBegin("StartAppHibernationService"); 1827 mSystemServiceManager.startService(AppHibernationService.class); 1828 t.traceEnd(); 1829 1830 t.traceBegin("ArtManagerLocal"); 1831 DexOptHelper.initializeArtManagerLocal(context, mPackageManagerService); 1832 t.traceEnd(); 1833 1834 t.traceBegin("UpdatePackagesIfNeeded"); 1835 try { 1836 Watchdog.getInstance().pauseWatchingCurrentThread("dexopt"); 1837 mPackageManagerService.updatePackagesIfNeeded(); 1838 } catch (Throwable e) { 1839 reportWtf("update packages", e); 1840 } finally { 1841 Watchdog.getInstance().resumeWatchingCurrentThread("dexopt"); 1842 } 1843 t.traceEnd(); 1844 1845 t.traceBegin("PerformFstrimIfNeeded"); 1846 try { 1847 mPackageManagerService.performFstrimIfNeeded(); 1848 } catch (Throwable e) { 1849 reportWtf("performing fstrim", e); 1850 } 1851 t.traceEnd(); 1852 1853 final DevicePolicyManagerService.Lifecycle dpms; 1854 if (mFactoryTestMode == FactoryTest.FACTORY_TEST_LOW_LEVEL) { 1855 dpms = null; 1856 } else { 1857 t.traceBegin("StartLockSettingsService"); 1858 try { 1859 mSystemServiceManager.startService(LockSettingsService.Lifecycle.class); 1860 lockSettings = ILockSettings.Stub.asInterface( 1861 ServiceManager.getService("lock_settings")); 1862 } catch (Throwable e) { 1863 reportWtf("starting LockSettingsService service", e); 1864 } 1865 t.traceEnd(); 1866 1867 final boolean hasPdb = !SystemProperties.get(PERSISTENT_DATA_BLOCK_PROP).equals(""); 1868 if (hasPdb) { 1869 t.traceBegin("StartPersistentDataBlock"); 1870 mSystemServiceManager.startService(PersistentDataBlockService.class); 1871 t.traceEnd(); 1872 } 1873 1874 if (Build.IS_ARC && SystemProperties.getInt("ro.boot.dev_mode", 0) == 1) { 1875 t.traceBegin("StartArcPersistentDataBlock"); 1876 mSystemServiceManager.startService(ARC_PERSISTENT_DATA_BLOCK_SERVICE_CLASS); 1877 t.traceEnd(); 1878 } 1879 1880 t.traceBegin("StartTestHarnessMode"); 1881 mSystemServiceManager.startService(TestHarnessModeService.class); 1882 t.traceEnd(); 1883 1884 if (hasPdb || OemLockService.isHalPresent()) { 1885 // Implementation depends on pdb or the OemLock HAL 1886 t.traceBegin("StartOemLockService"); 1887 mSystemServiceManager.startService(OemLockService.class); 1888 t.traceEnd(); 1889 } 1890 1891 t.traceBegin("StartDeviceIdleController"); 1892 mSystemServiceManager.startService(DeviceIdleController.class); 1893 t.traceEnd(); 1894 1895 // Always start the Device Policy Manager, so that the API is compatible with 1896 // API8. 1897 t.traceBegin("StartDevicePolicyManager"); 1898 dpms = mSystemServiceManager.startService(DevicePolicyManagerService.Lifecycle.class); 1899 t.traceEnd(); 1900 1901 t.traceBegin("StartStatusBarManagerService"); 1902 try { 1903 statusBar = new StatusBarManagerService(context); 1904 statusBar.publishGlobalActionsProvider(); 1905 ServiceManager.addService(Context.STATUS_BAR_SERVICE, statusBar, false, 1906 DUMP_FLAG_PRIORITY_NORMAL | DUMP_FLAG_PROTO); 1907 } catch (Throwable e) { 1908 reportWtf("starting StatusBarManagerService", e); 1909 } 1910 t.traceEnd(); 1911 1912 if (deviceHasConfigString(context, 1913 R.string.config_defaultMusicRecognitionService)) { 1914 t.traceBegin("StartMusicRecognitionManagerService"); 1915 mSystemServiceManager.startService(MusicRecognitionManagerService.class); 1916 t.traceEnd(); 1917 } else { 1918 Slog.d(TAG, 1919 "MusicRecognitionManagerService not defined by OEM or disabled by flag"); 1920 } 1921 1922 startContentCaptureService(context, t); 1923 startAttentionService(context, t); 1924 startRotationResolverService(context, t); 1925 startSystemCaptionsManagerService(context, t); 1926 startTextToSpeechManagerService(context, t); 1927 startWearableSensingService(t); 1928 startOnDeviceIntelligenceService(t); 1929 1930 if (deviceHasConfigString( 1931 context, R.string.config_defaultAmbientContextDetectionService)) { 1932 t.traceBegin("StartAmbientContextService"); 1933 mSystemServiceManager.startService(AmbientContextManagerService.class); 1934 t.traceEnd(); 1935 } else { 1936 Slog.d(TAG, "AmbientContextManagerService not defined by OEM or disabled by flag"); 1937 } 1938 1939 // System Speech Recognition Service 1940 t.traceBegin("StartSpeechRecognitionManagerService"); 1941 mSystemServiceManager.startService(SpeechRecognitionManagerService.class); 1942 t.traceEnd(); 1943 1944 // App prediction manager service 1945 if (deviceHasConfigString(context, R.string.config_defaultAppPredictionService)) { 1946 t.traceBegin("StartAppPredictionService"); 1947 mSystemServiceManager.startService(AppPredictionManagerService.class); 1948 t.traceEnd(); 1949 } else { 1950 Slog.d(TAG, "AppPredictionService not defined by OEM"); 1951 } 1952 1953 // Content suggestions manager service 1954 if (deviceHasConfigString(context, R.string.config_defaultContentSuggestionsService)) { 1955 t.traceBegin("StartContentSuggestionsService"); 1956 mSystemServiceManager.startService(ContentSuggestionsManagerService.class); 1957 t.traceEnd(); 1958 } else { 1959 Slog.d(TAG, "ContentSuggestionsService not defined by OEM"); 1960 } 1961 1962 // Search UI manager service 1963 if (deviceHasConfigString(context, R.string.config_defaultSearchUiService)) { 1964 t.traceBegin("StartSearchUiService"); 1965 mSystemServiceManager.startService(SearchUiManagerService.class); 1966 t.traceEnd(); 1967 } 1968 1969 // Smartspace manager service 1970 if (deviceHasConfigString(context, R.string.config_defaultSmartspaceService)) { 1971 t.traceBegin("StartSmartspaceService"); 1972 mSystemServiceManager.startService(SmartspaceManagerService.class); 1973 t.traceEnd(); 1974 } else { 1975 Slog.d(TAG, "SmartspaceManagerService not defined by OEM or disabled by flag"); 1976 } 1977 1978 // Contextual search manager service 1979 if (deviceHasConfigString(context, 1980 R.string.config_defaultContextualSearchPackageName)) { 1981 t.traceBegin("StartContextualSearchService"); 1982 mSystemServiceManager.startService(ContextualSearchManagerService.class); 1983 t.traceEnd(); 1984 } else { 1985 Slog.d(TAG, "ContextualSearchManagerService not defined or disabled by flag"); 1986 } 1987 1988 t.traceBegin("InitConnectivityModuleConnector"); 1989 try { 1990 ConnectivityModuleConnector.getInstance().init(context); 1991 } catch (Throwable e) { 1992 reportWtf("initializing ConnectivityModuleConnector", e); 1993 } 1994 t.traceEnd(); 1995 1996 t.traceBegin("InitNetworkStackClient"); 1997 try { 1998 NetworkStackClient.getInstance().init(); 1999 } catch (Throwable e) { 2000 reportWtf("initializing NetworkStackClient", e); 2001 } 2002 t.traceEnd(); 2003 2004 t.traceBegin("StartNetworkManagementService"); 2005 try { 2006 networkManagement = NetworkManagementService.create(context); 2007 ServiceManager.addService(Context.NETWORKMANAGEMENT_SERVICE, networkManagement); 2008 } catch (Throwable e) { 2009 reportWtf("starting NetworkManagement Service", e); 2010 } 2011 t.traceEnd(); 2012 2013 t.traceBegin("StartFontManagerService"); 2014 mSystemServiceManager.startService(new FontManagerService.Lifecycle(context, safeMode)); 2015 t.traceEnd(); 2016 2017 if (!isWatch || !android.server.Flags.removeTextService()) { 2018 t.traceBegin("StartTextServicesManager"); 2019 mSystemServiceManager.startService(TextServicesManagerService.Lifecycle.class); 2020 t.traceEnd(); 2021 } 2022 2023 if (!disableSystemTextClassifier) { 2024 t.traceBegin("StartTextClassificationManagerService"); 2025 mSystemServiceManager 2026 .startService(TextClassificationManagerService.Lifecycle.class); 2027 t.traceEnd(); 2028 } 2029 2030 t.traceBegin("StartNetworkScoreService"); 2031 mSystemServiceManager.startService(NetworkScoreService.Lifecycle.class); 2032 t.traceEnd(); 2033 2034 t.traceBegin("StartNetworkStatsService"); 2035 // This has to be called before NetworkPolicyManager because NetworkPolicyManager 2036 // needs to take NetworkStatsService to initialize. 2037 mSystemServiceManager.startServiceFromJar(NETWORK_STATS_SERVICE_INITIALIZER_CLASS, 2038 CONNECTIVITY_SERVICE_APEX_PATH); 2039 t.traceEnd(); 2040 2041 t.traceBegin("StartNetworkPolicyManagerService"); 2042 try { 2043 networkPolicy = new NetworkPolicyManagerService(context, mActivityManagerService, 2044 networkManagement); 2045 ServiceManager.addService(Context.NETWORK_POLICY_SERVICE, networkPolicy); 2046 } catch (Throwable e) { 2047 reportWtf("starting NetworkPolicy Service", e); 2048 } 2049 t.traceEnd(); 2050 2051 if (context.getPackageManager().hasSystemFeature( 2052 PackageManager.FEATURE_WIFI)) { 2053 // Wifi Service must be started first for wifi-related services. 2054 if (!isArc) { 2055 t.traceBegin("StartWifi"); 2056 mSystemServiceManager.startServiceFromJar( 2057 WIFI_SERVICE_CLASS, WIFI_APEX_SERVICE_JAR_PATH); 2058 t.traceEnd(); 2059 t.traceBegin("StartWifiScanning"); 2060 mSystemServiceManager.startServiceFromJar( 2061 WIFI_SCANNING_SERVICE_CLASS, WIFI_APEX_SERVICE_JAR_PATH); 2062 t.traceEnd(); 2063 } 2064 } 2065 2066 // ARC - ArcNetworkService registers the ARC network stack and replaces the 2067 // stock WiFi service in both ARC++ container and ARCVM. Always starts the ARC network 2068 // stack regardless of whether FEATURE_WIFI is enabled/disabled (b/254755875). 2069 if (isArc) { 2070 t.traceBegin("StartArcNetworking"); 2071 mSystemServiceManager.startService(ARC_NETWORK_SERVICE_CLASS); 2072 t.traceEnd(); 2073 } 2074 2075 if (context.getPackageManager().hasSystemFeature( 2076 PackageManager.FEATURE_WIFI_RTT)) { 2077 t.traceBegin("StartRttService"); 2078 mSystemServiceManager.startServiceFromJar( 2079 WIFI_RTT_SERVICE_CLASS, WIFI_APEX_SERVICE_JAR_PATH); 2080 t.traceEnd(); 2081 } 2082 2083 if (context.getPackageManager().hasSystemFeature( 2084 PackageManager.FEATURE_WIFI_AWARE)) { 2085 t.traceBegin("StartWifiAware"); 2086 mSystemServiceManager.startServiceFromJar( 2087 WIFI_AWARE_SERVICE_CLASS, WIFI_APEX_SERVICE_JAR_PATH); 2088 t.traceEnd(); 2089 } 2090 2091 if (context.getPackageManager().hasSystemFeature( 2092 PackageManager.FEATURE_WIFI_DIRECT)) { 2093 t.traceBegin("StartWifiP2P"); 2094 mSystemServiceManager.startServiceFromJar( 2095 WIFI_P2P_SERVICE_CLASS, WIFI_APEX_SERVICE_JAR_PATH); 2096 t.traceEnd(); 2097 } 2098 2099 if (context.getPackageManager().hasSystemFeature( 2100 PackageManager.FEATURE_LOWPAN)) { 2101 t.traceBegin("StartLowpan"); 2102 mSystemServiceManager.startService(LOWPAN_SERVICE_CLASS); 2103 t.traceEnd(); 2104 } 2105 2106 t.traceBegin("StartPacProxyService"); 2107 try { 2108 pacProxyService = new PacProxyService(context); 2109 ServiceManager.addService(Context.PAC_PROXY_SERVICE, pacProxyService); 2110 } catch (Throwable e) { 2111 reportWtf("starting PacProxyService", e); 2112 } 2113 t.traceEnd(); 2114 2115 t.traceBegin("StartConnectivityService"); 2116 // This has to be called after NetworkManagementService, NetworkStatsService 2117 // and NetworkPolicyManager because ConnectivityService needs to take these 2118 // services to initialize. 2119 mSystemServiceManager.startServiceFromJar(CONNECTIVITY_SERVICE_INITIALIZER_CLASS, 2120 CONNECTIVITY_SERVICE_APEX_PATH); 2121 networkPolicy.bindConnectivityManager(); 2122 t.traceEnd(); 2123 2124 t.traceBegin("StartSecurityStateManagerService"); 2125 try { 2126 ServiceManager.addService(Context.SECURITY_STATE_SERVICE, 2127 new SecurityStateManagerService(context)); 2128 } catch (Throwable e) { 2129 reportWtf("starting SecurityStateManagerService", e); 2130 } 2131 t.traceEnd(); 2132 2133 t.traceBegin("StartVpnManagerService"); 2134 try { 2135 vpnManager = VpnManagerService.create(context); 2136 ServiceManager.addService(Context.VPN_MANAGEMENT_SERVICE, vpnManager); 2137 } catch (Throwable e) { 2138 reportWtf("starting VPN Manager Service", e); 2139 } 2140 t.traceEnd(); 2141 2142 t.traceBegin("StartVcnManagementService"); 2143 try { 2144 vcnManagement = VcnManagementService.create(context); 2145 ServiceManager.addService(Context.VCN_MANAGEMENT_SERVICE, vcnManagement); 2146 } catch (Throwable e) { 2147 reportWtf("starting VCN Management Service", e); 2148 } 2149 t.traceEnd(); 2150 2151 t.traceBegin("StartSystemUpdateManagerService"); 2152 try { 2153 ServiceManager.addService(Context.SYSTEM_UPDATE_SERVICE, 2154 new SystemUpdateManagerService(context)); 2155 } catch (Throwable e) { 2156 reportWtf("starting SystemUpdateManagerService", e); 2157 } 2158 t.traceEnd(); 2159 2160 t.traceBegin("StartUpdateLockService"); 2161 try { 2162 ServiceManager.addService(Context.UPDATE_LOCK_SERVICE, 2163 new UpdateLockService(context)); 2164 } catch (Throwable e) { 2165 reportWtf("starting UpdateLockService", e); 2166 } 2167 t.traceEnd(); 2168 2169 t.traceBegin("StartNotificationManager"); 2170 mSystemServiceManager.startService(NotificationManagerService.class); 2171 SystemNotificationChannels.removeDeprecated(context); 2172 SystemNotificationChannels.createAll(context); 2173 notification = INotificationManager.Stub.asInterface( 2174 ServiceManager.getService(Context.NOTIFICATION_SERVICE)); 2175 t.traceEnd(); 2176 2177 t.traceBegin("StartDeviceMonitor"); 2178 mSystemServiceManager.startService(DeviceStorageMonitorService.class); 2179 t.traceEnd(); 2180 2181 t.traceBegin("StartTimeDetectorService"); 2182 try { 2183 mSystemServiceManager.startService(TimeDetectorService.Lifecycle.class); 2184 } catch (Throwable e) { 2185 reportWtf("starting TimeDetectorService service", e); 2186 } 2187 t.traceEnd(); 2188 2189 t.traceBegin("StartLocationManagerService"); 2190 mSystemServiceManager.startService(LocationManagerService.Lifecycle.class); 2191 t.traceEnd(); 2192 2193 t.traceBegin("StartCountryDetectorService"); 2194 try { 2195 countryDetector = new CountryDetectorService(context); 2196 ServiceManager.addService(Context.COUNTRY_DETECTOR, countryDetector); 2197 } catch (Throwable e) { 2198 reportWtf("starting Country Detector", e); 2199 } 2200 t.traceEnd(); 2201 2202 t.traceBegin("StartTimeZoneDetectorService"); 2203 try { 2204 mSystemServiceManager.startService(TimeZoneDetectorService.Lifecycle.class); 2205 } catch (Throwable e) { 2206 reportWtf("starting TimeZoneDetectorService service", e); 2207 } 2208 t.traceEnd(); 2209 2210 t.traceBegin("StartAltitudeService"); 2211 try { 2212 mSystemServiceManager.startService(AltitudeService.Lifecycle.class); 2213 } catch (Throwable e) { 2214 reportWtf("starting AltitudeService service", e); 2215 } 2216 t.traceEnd(); 2217 2218 t.traceBegin("StartLocationTimeZoneManagerService"); 2219 try { 2220 mSystemServiceManager.startService(LocationTimeZoneManagerService.Lifecycle.class); 2221 } catch (Throwable e) { 2222 reportWtf("starting LocationTimeZoneManagerService service", e); 2223 } 2224 t.traceEnd(); 2225 2226 if (context.getResources().getBoolean(R.bool.config_enableGnssTimeUpdateService)) { 2227 t.traceBegin("StartGnssTimeUpdateService"); 2228 try { 2229 mSystemServiceManager.startService(GnssTimeUpdateService.Lifecycle.class); 2230 } catch (Throwable e) { 2231 reportWtf("starting GnssTimeUpdateService service", e); 2232 } 2233 t.traceEnd(); 2234 } 2235 2236 if (!isWatch) { 2237 t.traceBegin("StartSearchManagerService"); 2238 try { 2239 mSystemServiceManager.startService(SearchManagerService.Lifecycle.class); 2240 } catch (Throwable e) { 2241 reportWtf("starting Search Service", e); 2242 } 2243 t.traceEnd(); 2244 } 2245 2246 if (context.getResources().getBoolean(R.bool.config_enableWallpaperService)) { 2247 t.traceBegin("StartWallpaperManagerService"); 2248 mSystemServiceManager.startService(WallpaperManagerService.Lifecycle.class); 2249 t.traceEnd(); 2250 } else { 2251 Slog.i(TAG, "Wallpaper service disabled by config"); 2252 } 2253 2254 // WallpaperEffectsGeneration manager service 2255 if (deviceHasConfigString(context, 2256 R.string.config_defaultWallpaperEffectsGenerationService)) { 2257 t.traceBegin("StartWallpaperEffectsGenerationService"); 2258 mSystemServiceManager.startService(WallpaperEffectsGenerationManagerService.class); 2259 t.traceEnd(); 2260 } 2261 2262 t.traceBegin("StartAudioService"); 2263 if (!isArc) { 2264 mSystemServiceManager.startService(AudioService.Lifecycle.class); 2265 } else { 2266 String className = context.getResources() 2267 .getString(R.string.config_deviceSpecificAudioService); 2268 try { 2269 mSystemServiceManager.startService(className + "$Lifecycle"); 2270 } catch (Throwable e) { 2271 reportWtf("starting " + className, e); 2272 } 2273 } 2274 t.traceEnd(); 2275 2276 t.traceBegin("StartSoundTriggerMiddlewareService"); 2277 mSystemServiceManager.startService(SoundTriggerMiddlewareService.Lifecycle.class); 2278 t.traceEnd(); 2279 2280 if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_BROADCAST_RADIO)) { 2281 t.traceBegin("StartBroadcastRadioService"); 2282 mSystemServiceManager.startService(BroadcastRadioService.class); 2283 t.traceEnd(); 2284 } 2285 2286 if (!isTv) { 2287 t.traceBegin("StartDockObserver"); 2288 mSystemServiceManager.startService(DockObserver.class); 2289 t.traceEnd(); 2290 } 2291 2292 if (isWatch) { 2293 t.traceBegin("StartThermalObserver"); 2294 mSystemServiceManager.startService(THERMAL_OBSERVER_CLASS); 2295 t.traceEnd(); 2296 } 2297 2298 if (!isWatch) { 2299 t.traceBegin("StartWiredAccessoryManager"); 2300 try { 2301 // Listen for wired headset changes 2302 inputManager.setWiredAccessoryCallbacks( 2303 new WiredAccessoryManager(context, inputManager)); 2304 } catch (Throwable e) { 2305 reportWtf("starting WiredAccessoryManager", e); 2306 } 2307 t.traceEnd(); 2308 } 2309 2310 if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_MIDI)) { 2311 // Start MIDI Manager service 2312 t.traceBegin("StartMidiManager"); 2313 mSystemServiceManager.startService(MidiService.Lifecycle.class); 2314 t.traceEnd(); 2315 } 2316 2317 // Start ADB Debugging Service 2318 t.traceBegin("StartAdbService"); 2319 try { 2320 mSystemServiceManager.startService(AdbService.Lifecycle.class); 2321 } catch (Throwable e) { 2322 Slog.e(TAG, "Failure starting AdbService"); 2323 } 2324 t.traceEnd(); 2325 2326 if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_USB_HOST) 2327 || mPackageManager.hasSystemFeature( 2328 PackageManager.FEATURE_USB_ACCESSORY) 2329 || Build.IS_EMULATOR) { 2330 // Manage USB host and device support 2331 t.traceBegin("StartUsbService"); 2332 mSystemServiceManager.startService(UsbService.Lifecycle.class); 2333 t.traceEnd(); 2334 } 2335 2336 if (!isWatch) { 2337 t.traceBegin("StartSerialService"); 2338 mSystemServiceManager.startService(SerialService.Lifecycle.class); 2339 t.traceEnd(); 2340 } 2341 2342 t.traceBegin("StartHardwarePropertiesManagerService"); 2343 try { 2344 hardwarePropertiesService = new HardwarePropertiesManagerService(context); 2345 ServiceManager.addService(Context.HARDWARE_PROPERTIES_SERVICE, 2346 hardwarePropertiesService); 2347 } catch (Throwable e) { 2348 Slog.e(TAG, "Failure starting HardwarePropertiesManagerService", e); 2349 } 2350 t.traceEnd(); 2351 2352 if (!isWatch) { 2353 t.traceBegin("StartTwilightService"); 2354 mSystemServiceManager.startService(TwilightService.class); 2355 t.traceEnd(); 2356 } 2357 2358 t.traceBegin("StartColorDisplay"); 2359 mSystemServiceManager.startService(ColorDisplayService.class); 2360 t.traceEnd(); 2361 2362 // TODO(aml-jobscheduler): Think about how to do it properly. 2363 t.traceBegin("StartJobScheduler"); 2364 mSystemServiceManager.startService(JobSchedulerService.class); 2365 t.traceEnd(); 2366 2367 t.traceBegin("StartSoundTrigger"); 2368 mSystemServiceManager.startService(SoundTriggerService.class); 2369 t.traceEnd(); 2370 2371 t.traceBegin("StartTrustManager"); 2372 mSystemServiceManager.startService(TrustManagerService.class); 2373 t.traceEnd(); 2374 2375 if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_BACKUP)) { 2376 t.traceBegin("StartBackupManager"); 2377 mSystemServiceManager.startService(BackupManagerService.Lifecycle.class); 2378 t.traceEnd(); 2379 } 2380 2381 if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_APP_WIDGETS) 2382 || context.getResources().getBoolean(R.bool.config_enableAppWidgetService)) { 2383 t.traceBegin("StartAppWidgetService"); 2384 mSystemServiceManager.startService(AppWidgetService.class); 2385 t.traceEnd(); 2386 } 2387 2388 // We need to always start this service, regardless of whether the 2389 // FEATURE_VOICE_RECOGNIZERS feature is set, because it needs to take care 2390 // of initializing various settings. It will internally modify its behavior 2391 // based on that feature. 2392 t.traceBegin("StartVoiceRecognitionManager"); 2393 mSystemServiceManager.startService(VoiceInteractionManagerService.class); 2394 t.traceEnd(); 2395 2396 if (GestureLauncherService.isGestureLauncherEnabled(context.getResources())) { 2397 t.traceBegin("StartGestureLauncher"); 2398 mSystemServiceManager.startService(GestureLauncherService.class); 2399 t.traceEnd(); 2400 } 2401 t.traceBegin("StartSensorNotification"); 2402 mSystemServiceManager.startService(SensorNotificationService.class); 2403 t.traceEnd(); 2404 2405 if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_CONTEXT_HUB)) { 2406 t.traceBegin("StartContextHubSystemService"); 2407 mSystemServiceManager.startService(ContextHubSystemService.class); 2408 t.traceEnd(); 2409 } 2410 2411 t.traceBegin("StartDiskStatsService"); 2412 try { 2413 ServiceManager.addService("diskstats", new DiskStatsService(context)); 2414 } catch (Throwable e) { 2415 reportWtf("starting DiskStats Service", e); 2416 } 2417 t.traceEnd(); 2418 2419 t.traceBegin("RuntimeService"); 2420 try { 2421 ServiceManager.addService("runtime", new RuntimeService(context)); 2422 } catch (Throwable e) { 2423 reportWtf("starting RuntimeService", e); 2424 } 2425 t.traceEnd(); 2426 2427 if (!isWatch && !disableNetworkTime) { 2428 t.traceBegin("StartNetworkTimeUpdateService"); 2429 try { 2430 networkTimeUpdater = new NetworkTimeUpdateService(context); 2431 ServiceManager.addService("network_time_update_service", networkTimeUpdater); 2432 } catch (Throwable e) { 2433 reportWtf("starting NetworkTimeUpdate service", e); 2434 } 2435 t.traceEnd(); 2436 } 2437 2438 t.traceBegin("CertBlacklister"); 2439 try { 2440 CertBlacklister blacklister = new CertBlacklister(context); 2441 } catch (Throwable e) { 2442 reportWtf("starting CertBlacklister", e); 2443 } 2444 t.traceEnd(); 2445 2446 if (EmergencyAffordanceManager.ENABLED) { 2447 // EmergencyMode service 2448 t.traceBegin("StartEmergencyAffordanceService"); 2449 mSystemServiceManager.startService(EmergencyAffordanceService.class); 2450 t.traceEnd(); 2451 } 2452 2453 t.traceBegin(START_BLOB_STORE_SERVICE); 2454 mSystemServiceManager.startService(BlobStoreManagerService.class); 2455 t.traceEnd(); 2456 2457 // Dreams (interactive idle-time views, a/k/a screen savers, and doze mode) 2458 t.traceBegin("StartDreamManager"); 2459 mSystemServiceManager.startService(DreamManagerService.class); 2460 t.traceEnd(); 2461 2462 t.traceBegin("AddGraphicsStatsService"); 2463 ServiceManager.addService(GraphicsStatsService.GRAPHICS_STATS_SERVICE, 2464 new GraphicsStatsService(context)); 2465 t.traceEnd(); 2466 2467 if (CoverageService.ENABLED) { 2468 t.traceBegin("AddCoverageService"); 2469 ServiceManager.addService(CoverageService.COVERAGE_SERVICE, new CoverageService()); 2470 t.traceEnd(); 2471 } 2472 2473 if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_PRINTING)) { 2474 t.traceBegin("StartPrintManager"); 2475 mSystemServiceManager.startService(PrintManagerService.class); 2476 t.traceEnd(); 2477 } 2478 2479 t.traceBegin("StartAttestationVerificationService"); 2480 mSystemServiceManager.startService(AttestationVerificationManagerService.class); 2481 t.traceEnd(); 2482 2483 if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_COMPANION_DEVICE_SETUP)) { 2484 t.traceBegin("StartCompanionDeviceManager"); 2485 mSystemServiceManager.startService(CompanionDeviceManagerService.class); 2486 t.traceEnd(); 2487 } 2488 2489 if (context.getResources().getBoolean(R.bool.config_enableVirtualDeviceManager)) { 2490 t.traceBegin("StartVirtualDeviceManager"); 2491 mSystemServiceManager.startService(VirtualDeviceManagerService.class); 2492 t.traceEnd(); 2493 } 2494 2495 t.traceBegin("StartRestrictionManager"); 2496 mSystemServiceManager.startService(RestrictionsManagerService.class); 2497 t.traceEnd(); 2498 2499 t.traceBegin("StartMediaSessionService"); 2500 mSystemServiceManager.startService(MediaSessionService.class); 2501 t.traceEnd(); 2502 2503 if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_HDMI_CEC)) { 2504 t.traceBegin("StartHdmiControlService"); 2505 mSystemServiceManager.startService(HdmiControlService.class); 2506 t.traceEnd(); 2507 } 2508 2509 if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_LIVE_TV) 2510 || mPackageManager.hasSystemFeature(PackageManager.FEATURE_LEANBACK)) { 2511 t.traceBegin("StartTvInteractiveAppManager"); 2512 mSystemServiceManager.startService(TvInteractiveAppManagerService.class); 2513 t.traceEnd(); 2514 } 2515 2516 if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_LIVE_TV) 2517 || mPackageManager.hasSystemFeature(PackageManager.FEATURE_LEANBACK)) { 2518 t.traceBegin("StartTvInputManager"); 2519 mSystemServiceManager.startService(TvInputManagerService.class); 2520 t.traceEnd(); 2521 } 2522 2523 if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_TUNER)) { 2524 t.traceBegin("StartTunerResourceManager"); 2525 mSystemServiceManager.startService(TunerResourceManagerService.class); 2526 t.traceEnd(); 2527 } 2528 2529 if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_PICTURE_IN_PICTURE)) { 2530 t.traceBegin("StartMediaResourceMonitor"); 2531 mSystemServiceManager.startService(MediaResourceMonitorService.class); 2532 t.traceEnd(); 2533 } 2534 2535 if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_LEANBACK)) { 2536 t.traceBegin("StartTvRemoteService"); 2537 mSystemServiceManager.startService(TvRemoteService.class); 2538 t.traceEnd(); 2539 } 2540 2541 t.traceBegin("StartMediaRouterService"); 2542 try { 2543 mediaRouter = new MediaRouterService(context); 2544 ServiceManager.addService(Context.MEDIA_ROUTER_SERVICE, mediaRouter); 2545 } catch (Throwable e) { 2546 reportWtf("starting MediaRouterService", e); 2547 } 2548 t.traceEnd(); 2549 2550 final boolean hasFeatureFace 2551 = mPackageManager.hasSystemFeature(PackageManager.FEATURE_FACE); 2552 final boolean hasFeatureIris 2553 = mPackageManager.hasSystemFeature(PackageManager.FEATURE_IRIS); 2554 final boolean hasFeatureFingerprint 2555 = mPackageManager.hasSystemFeature(PackageManager.FEATURE_FINGERPRINT); 2556 2557 if (hasFeatureFace) { 2558 t.traceBegin("StartFaceSensor"); 2559 final FaceService faceService = 2560 mSystemServiceManager.startService(FaceService.class); 2561 t.traceEnd(); 2562 } 2563 2564 if (hasFeatureIris) { 2565 t.traceBegin("StartIrisSensor"); 2566 mSystemServiceManager.startService(IrisService.class); 2567 t.traceEnd(); 2568 } 2569 2570 if (hasFeatureFingerprint) { 2571 t.traceBegin("StartFingerprintSensor"); 2572 final FingerprintService fingerprintService = 2573 mSystemServiceManager.startService(FingerprintService.class); 2574 t.traceEnd(); 2575 } 2576 2577 // Start this service after all biometric sensor services are started. 2578 t.traceBegin("StartBiometricService"); 2579 mSystemServiceManager.startService(BiometricService.class); 2580 t.traceEnd(); 2581 2582 t.traceBegin("StartAuthService"); 2583 mSystemServiceManager.startService(AuthService.class); 2584 t.traceEnd(); 2585 2586 if (android.adaptiveauth.Flags.enableAdaptiveAuth()) { 2587 t.traceBegin("StartAdaptiveAuthService"); 2588 mSystemServiceManager.startService(AdaptiveAuthService.class); 2589 t.traceEnd(); 2590 } 2591 2592 if (!isWatch) { 2593 // We don't run this on watches as there are no plans to use the data logged 2594 // on watch devices. 2595 t.traceBegin("StartDynamicCodeLoggingService"); 2596 try { 2597 DynamicCodeLoggingService.schedule(context); 2598 } catch (Throwable e) { 2599 reportWtf("starting DynamicCodeLoggingService", e); 2600 } 2601 t.traceEnd(); 2602 } 2603 2604 if (!isWatch) { 2605 t.traceBegin("StartPruneInstantAppsJobService"); 2606 try { 2607 PruneInstantAppsJobService.schedule(context); 2608 } catch (Throwable e) { 2609 reportWtf("StartPruneInstantAppsJobService", e); 2610 } 2611 t.traceEnd(); 2612 } 2613 2614 t.traceBegin("StartSelinuxAuditLogsService"); 2615 try { 2616 SelinuxAuditLogsService.schedule(context); 2617 } catch (Throwable e) { 2618 reportWtf("starting SelinuxAuditLogsService", e); 2619 } 2620 t.traceEnd(); 2621 2622 // LauncherAppsService uses ShortcutService. 2623 t.traceBegin("StartShortcutServiceLifecycle"); 2624 mSystemServiceManager.startService(ShortcutService.Lifecycle.class); 2625 t.traceEnd(); 2626 2627 t.traceBegin("StartLauncherAppsService"); 2628 mSystemServiceManager.startService(LauncherAppsService.class); 2629 t.traceEnd(); 2630 2631 t.traceBegin("StartCrossProfileAppsService"); 2632 mSystemServiceManager.startService(CrossProfileAppsService.class); 2633 t.traceEnd(); 2634 2635 t.traceBegin("StartPeopleService"); 2636 mSystemServiceManager.startService(PeopleService.class); 2637 t.traceEnd(); 2638 2639 t.traceBegin("StartMediaMetricsManager"); 2640 mSystemServiceManager.startService(MediaMetricsManagerService.class); 2641 t.traceEnd(); 2642 2643 t.traceBegin("StartBackgroundInstallControlService"); 2644 mSystemServiceManager.startService(BackgroundInstallControlService.class); 2645 t.traceEnd(); 2646 } 2647 2648 t.traceBegin("StartMediaProjectionManager"); 2649 mSystemServiceManager.startService(MediaProjectionManagerService.class); 2650 t.traceEnd(); 2651 2652 if (isWatch) { 2653 // Must be started before services that depend it, e.g. WearConnectivityService 2654 t.traceBegin("StartWearPowerService"); 2655 mSystemServiceManager.startService(WEAR_POWER_SERVICE_CLASS); 2656 t.traceEnd(); 2657 2658 t.traceBegin("StartHealthService"); 2659 mSystemServiceManager.startService(HEALTH_SERVICE_CLASS); 2660 t.traceEnd(); 2661 2662 t.traceBegin("StartSystemStateDisplayService"); 2663 mSystemServiceManager.startService(SYSTEM_STATE_DISPLAY_SERVICE_CLASS); 2664 t.traceEnd(); 2665 2666 t.traceBegin("StartWearConnectivityService"); 2667 mSystemServiceManager.startService(WEAR_CONNECTIVITY_SERVICE_CLASS); 2668 t.traceEnd(); 2669 2670 t.traceBegin("StartWearDisplayService"); 2671 mSystemServiceManager.startService(WEAR_DISPLAY_SERVICE_CLASS); 2672 t.traceEnd(); 2673 2674 if (Build.IS_DEBUGGABLE) { 2675 t.traceBegin("StartWearDebugService"); 2676 mSystemServiceManager.startService(WEAR_DEBUG_SERVICE_CLASS); 2677 t.traceEnd(); 2678 } 2679 2680 t.traceBegin("StartWearTimeService"); 2681 mSystemServiceManager.startService(WEAR_TIME_SERVICE_CLASS); 2682 t.traceEnd(); 2683 2684 t.traceBegin("StartWearSettingsService"); 2685 mSystemServiceManager.startService(WEAR_SETTINGS_SERVICE_CLASS); 2686 t.traceEnd(); 2687 2688 t.traceBegin("StartWearModeService"); 2689 mSystemServiceManager.startService(WEAR_MODE_SERVICE_CLASS); 2690 t.traceEnd(); 2691 2692 boolean enableWristOrientationService = SystemProperties.getBoolean( 2693 "config.enable_wristorientation", false); 2694 if (enableWristOrientationService) { 2695 t.traceBegin("StartWristOrientationService"); 2696 mSystemServiceManager.startService(WRIST_ORIENTATION_SERVICE_CLASS); 2697 t.traceEnd(); 2698 } 2699 } 2700 2701 if (!mPackageManager.hasSystemFeature(PackageManager.FEATURE_SLICES_DISABLED)) { 2702 t.traceBegin("StartSliceManagerService"); 2703 mSystemServiceManager.startService(SliceManagerService.Lifecycle.class); 2704 t.traceEnd(); 2705 } 2706 2707 if (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_EMBEDDED)) { 2708 t.traceBegin("StartIoTSystemService"); 2709 mSystemServiceManager.startService(IOT_SERVICE_CLASS); 2710 t.traceEnd(); 2711 } 2712 2713 // Statsd helper 2714 t.traceBegin("StartStatsCompanion"); 2715 mSystemServiceManager.startServiceFromJar( 2716 STATS_COMPANION_LIFECYCLE_CLASS, STATS_COMPANION_APEX_PATH); 2717 t.traceEnd(); 2718 2719 // Reboot Readiness 2720 t.traceBegin("StartRebootReadinessManagerService"); 2721 mSystemServiceManager.startServiceFromJar( 2722 REBOOT_READINESS_LIFECYCLE_CLASS, SCHEDULING_APEX_PATH); 2723 t.traceEnd(); 2724 2725 // Statsd pulled atoms 2726 t.traceBegin("StartStatsPullAtomService"); 2727 mSystemServiceManager.startService(StatsPullAtomService.class); 2728 t.traceEnd(); 2729 2730 // Log atoms to statsd from bootstrap processes. 2731 t.traceBegin("StatsBootstrapAtomService"); 2732 mSystemServiceManager.startService(StatsBootstrapAtomService.Lifecycle.class); 2733 t.traceEnd(); 2734 2735 // Incidentd and dumpstated helper 2736 t.traceBegin("StartIncidentCompanionService"); 2737 mSystemServiceManager.startService(IncidentCompanionService.class); 2738 t.traceEnd(); 2739 2740 // SdkSandboxManagerService 2741 t.traceBegin("StarSdkSandboxManagerService"); 2742 mSystemServiceManager.startService(SDK_SANDBOX_MANAGER_SERVICE_CLASS); 2743 t.traceEnd(); 2744 2745 // AdServicesManagerService (PP API service) 2746 t.traceBegin("StartAdServicesManagerService"); 2747 mSystemServiceManager.startService(AD_SERVICES_MANAGER_SERVICE_CLASS); 2748 t.traceEnd(); 2749 2750 // OnDevicePersonalizationSystemService 2751 if (!com.android.server.flags.Flags.enableOdpFeatureGuard() 2752 || SystemProperties.getBoolean("ro.system_settings.service.odp_enabled", true)) { 2753 t.traceBegin("StartOnDevicePersonalizationSystemService"); 2754 mSystemServiceManager.startService(ON_DEVICE_PERSONALIZATION_SYSTEM_SERVICE_CLASS); 2755 t.traceEnd(); 2756 } 2757 2758 // Profiling 2759 if (android.server.Flags.telemetryApisService()) { 2760 t.traceBegin("StartProfilingCompanion"); 2761 mSystemServiceManager.startServiceFromJar(PROFILING_SERVICE_LIFECYCLE_CLASS, 2762 PROFILING_SERVICE_JAR_PATH); 2763 t.traceEnd(); 2764 } 2765 2766 if (safeMode) { 2767 mActivityManagerService.enterSafeMode(); 2768 } 2769 2770 if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY)) { 2771 // MMS service broker 2772 t.traceBegin("StartMmsService"); 2773 mmsService = mSystemServiceManager.startService(MmsServiceBroker.class); 2774 t.traceEnd(); 2775 } 2776 2777 if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_AUTOFILL)) { 2778 t.traceBegin("StartAutoFillService"); 2779 mSystemServiceManager.startService(AutofillManagerService.class); 2780 t.traceEnd(); 2781 } 2782 2783 if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_CREDENTIALS)) { 2784 boolean credentialManagerEnabled = 2785 DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_CREDENTIAL, 2786 CredentialManager.DEVICE_CONFIG_ENABLE_CREDENTIAL_MANAGER, true); 2787 if (credentialManagerEnabled) { 2788 if (isWatch && !android.credentials.flags.Flags.wearCredentialManagerEnabled()) { 2789 Slog.d(TAG, "CredentialManager disabled on wear."); 2790 } else { 2791 t.traceBegin("StartCredentialManagerService"); 2792 mSystemServiceManager.startService(CredentialManagerService.class); 2793 t.traceEnd(); 2794 } 2795 } else { 2796 Slog.d(TAG, "CredentialManager disabled."); 2797 } 2798 } 2799 2800 // Translation manager service 2801 if (deviceHasConfigString(context, R.string.config_defaultTranslationService)) { 2802 t.traceBegin("StartTranslationManagerService"); 2803 mSystemServiceManager.startService(TranslationManagerService.class); 2804 t.traceEnd(); 2805 } else { 2806 Slog.d(TAG, "TranslationService not defined by OEM"); 2807 } 2808 2809 // NOTE: ClipboardService depends on ContentCapture and Autofill 2810 t.traceBegin("StartClipboardService"); 2811 mSystemServiceManager.startService(ClipboardService.class); 2812 t.traceEnd(); 2813 2814 t.traceBegin("AppServiceManager"); 2815 mSystemServiceManager.startService(AppBindingService.Lifecycle.class); 2816 t.traceEnd(); 2817 2818 // Perfetto TracingServiceProxy 2819 t.traceBegin("startTracingServiceProxy"); 2820 mSystemServiceManager.startService(TracingServiceProxy.class); 2821 t.traceEnd(); 2822 2823 // It is now time to start up the app processes... 2824 2825 t.traceBegin("MakeLockSettingsServiceReady"); 2826 if (lockSettings != null) { 2827 try { 2828 lockSettings.systemReady(); 2829 } catch (Throwable e) { 2830 reportWtf("making Lock Settings Service ready", e); 2831 } 2832 } 2833 t.traceEnd(); 2834 2835 // Needed by DevicePolicyManager for initialization 2836 t.traceBegin("StartBootPhaseLockSettingsReady"); 2837 mSystemServiceManager.startBootPhase(t, SystemService.PHASE_LOCK_SETTINGS_READY); 2838 t.traceEnd(); 2839 2840 // Create initial user if needed, which should be done early since some system services rely 2841 // on it in their setup, but likely needs to be done after LockSettingsService is ready. 2842 final HsumBootUserInitializer hsumBootUserInitializer = 2843 HsumBootUserInitializer.createInstance( 2844 mActivityManagerService, mPackageManagerService, mContentResolver, 2845 context.getResources().getBoolean(R.bool.config_isMainUserPermanentAdmin)); 2846 if (hsumBootUserInitializer != null) { 2847 t.traceBegin("HsumBootUserInitializer.init"); 2848 hsumBootUserInitializer.init(t); 2849 t.traceEnd(); 2850 } 2851 2852 CommunalProfileInitializer communalProfileInitializer = null; 2853 if (UserManager.isCommunalProfileEnabled()) { 2854 t.traceBegin("CommunalProfileInitializer.init"); 2855 communalProfileInitializer = 2856 new CommunalProfileInitializer(mActivityManagerService); 2857 communalProfileInitializer.init(t); 2858 t.traceEnd(); 2859 } else { 2860 t.traceBegin("CommunalProfileInitializer.removeCommunalProfileIfPresent"); 2861 CommunalProfileInitializer.removeCommunalProfileIfPresent(); 2862 t.traceEnd(); 2863 } 2864 2865 t.traceBegin("StartBootPhaseSystemServicesReady"); 2866 mSystemServiceManager.startBootPhase(t, SystemService.PHASE_SYSTEM_SERVICES_READY); 2867 t.traceEnd(); 2868 2869 t.traceBegin("MakeWindowManagerServiceReady"); 2870 try { 2871 wm.systemReady(); 2872 } catch (Throwable e) { 2873 reportWtf("making Window Manager Service ready", e); 2874 } 2875 t.traceEnd(); 2876 2877 t.traceBegin("RegisterLogMteState"); 2878 try { 2879 LogMteState.register(context); 2880 } catch (Throwable e) { 2881 reportWtf("RegisterLogMteState", e); 2882 } 2883 t.traceEnd(); 2884 2885 // Emit any pending system_server WTFs 2886 synchronized (SystemService.class) { 2887 if (sPendingWtfs != null) { 2888 mActivityManagerService.schedulePendingSystemServerWtfs(sPendingWtfs); 2889 sPendingWtfs = null; 2890 } 2891 } 2892 2893 if (safeMode) { 2894 mActivityManagerService.showSafeModeOverlay(); 2895 } 2896 2897 // Update the configuration for this context by hand, because we're going 2898 // to start using it before the config change done in wm.systemReady() will 2899 // propagate to it. 2900 final Configuration config = wm.computeNewConfiguration(DEFAULT_DISPLAY); 2901 DisplayMetrics metrics = new DisplayMetrics(); 2902 context.getDisplay().getMetrics(metrics); 2903 context.getResources().updateConfiguration(config, metrics); 2904 2905 // The system context's theme may be configuration-dependent. 2906 final Theme systemTheme = context.getTheme(); 2907 if (systemTheme.getChangingConfigurations() != 0) { 2908 systemTheme.rebase(); 2909 } 2910 2911 // Permission policy service 2912 t.traceBegin("StartPermissionPolicyService"); 2913 mSystemServiceManager.startService(PermissionPolicyService.class); 2914 t.traceEnd(); 2915 2916 t.traceBegin("MakePackageManagerServiceReady"); 2917 mPackageManagerService.systemReady(); 2918 t.traceEnd(); 2919 2920 if (Flags.recoverabilityDetection()) { 2921 // Now that we have the essential services needed for mitigations, register the boot 2922 // with package watchdog. 2923 // Note that we just booted, which might send out a rescue party if we're stuck in a 2924 // runtime restart loop. 2925 PackageWatchdog.getInstance(mSystemContext).noteBoot(); 2926 } 2927 2928 t.traceBegin("MakeDisplayManagerServiceReady"); 2929 try { 2930 // TODO: use boot phase and communicate this flag some other way 2931 mDisplayManagerService.systemReady(safeMode); 2932 } catch (Throwable e) { 2933 reportWtf("making Display Manager Service ready", e); 2934 } 2935 t.traceEnd(); 2936 2937 mSystemServiceManager.setSafeMode(safeMode); 2938 2939 // Start device specific services 2940 t.traceBegin("StartDeviceSpecificServices"); 2941 final String[] classes = mSystemContext.getResources().getStringArray( 2942 R.array.config_deviceSpecificSystemServices); 2943 for (final String className : classes) { 2944 t.traceBegin("StartDeviceSpecificServices " + className); 2945 try { 2946 mSystemServiceManager.startService(className); 2947 } catch (Throwable e) { 2948 reportWtf("starting " + className, e); 2949 } 2950 t.traceEnd(); 2951 } 2952 t.traceEnd(); 2953 2954 t.traceBegin("GameManagerService"); 2955 mSystemServiceManager.startService(GameManagerService.Lifecycle.class); 2956 t.traceEnd(); 2957 2958 if (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_UWB)) { 2959 t.traceBegin("UwbService"); 2960 mSystemServiceManager.startServiceFromJar(UWB_SERVICE_CLASS, UWB_APEX_SERVICE_JAR_PATH); 2961 t.traceEnd(); 2962 } 2963 2964 t.traceBegin("StartBootPhaseDeviceSpecificServicesReady"); 2965 mSystemServiceManager.startBootPhase(t, SystemService.PHASE_DEVICE_SPECIFIC_SERVICES_READY); 2966 t.traceEnd(); 2967 2968 t.traceBegin("StartSafetyCenterService"); 2969 mSystemServiceManager.startService(SAFETY_CENTER_SERVICE_CLASS); 2970 t.traceEnd(); 2971 2972 t.traceBegin("AppSearchModule"); 2973 mSystemServiceManager.startService(APPSEARCH_MODULE_LIFECYCLE_CLASS); 2974 t.traceEnd(); 2975 2976 if (SystemProperties.getBoolean("ro.config.isolated_compilation_enabled", false)) { 2977 t.traceBegin("IsolatedCompilationService"); 2978 mSystemServiceManager.startService(ISOLATED_COMPILATION_SERVICE_CLASS); 2979 t.traceEnd(); 2980 } 2981 2982 t.traceBegin("StartMediaCommunicationService"); 2983 mSystemServiceManager.startService(MEDIA_COMMUNICATION_SERVICE_CLASS); 2984 t.traceEnd(); 2985 2986 t.traceBegin("AppCompatOverridesService"); 2987 mSystemServiceManager.startService(AppCompatOverridesService.Lifecycle.class); 2988 t.traceEnd(); 2989 2990 t.traceBegin("HealthConnectManagerService"); 2991 mSystemServiceManager.startService(HEALTHCONNECT_MANAGER_SERVICE_CLASS); 2992 t.traceEnd(); 2993 2994 if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_DEVICE_LOCK)) { 2995 t.traceBegin("DeviceLockService"); 2996 mSystemServiceManager.startServiceFromJar(DEVICE_LOCK_SERVICE_CLASS, 2997 DEVICE_LOCK_APEX_PATH); 2998 t.traceEnd(); 2999 } 3000 3001 if (android.permission.flags.Flags.sensitiveNotificationAppProtection() 3002 || android.view.flags.Flags.sensitiveContentAppProtection()) { 3003 t.traceBegin("StartSensitiveContentProtectionManager"); 3004 mSystemServiceManager.startService(SensitiveContentProtectionManagerService.class); 3005 t.traceEnd(); 3006 } 3007 3008 // These are needed to propagate to the runnable below. 3009 final NetworkManagementService networkManagementF = networkManagement; 3010 final NetworkPolicyManagerService networkPolicyF = networkPolicy; 3011 final CountryDetectorService countryDetectorF = countryDetector; 3012 final NetworkTimeUpdateService networkTimeUpdaterF = networkTimeUpdater; 3013 final InputManagerService inputManagerF = inputManager; 3014 final TelephonyRegistry telephonyRegistryF = telephonyRegistry; 3015 final MediaRouterService mediaRouterF = mediaRouter; 3016 final MmsServiceBroker mmsServiceF = mmsService; 3017 final VpnManagerService vpnManagerF = vpnManager; 3018 final VcnManagementService vcnManagementF = vcnManagement; 3019 final WindowManagerService windowManagerF = wm; 3020 final ConnectivityManager connectivityF = (ConnectivityManager) 3021 context.getSystemService(Context.CONNECTIVITY_SERVICE); 3022 3023 // We now tell the activity manager it is okay to run third party 3024 // code. It will call back into us once it has gotten to the state 3025 // where third party code can really run (but before it has actually 3026 // started launching the initial applications), for us to complete our 3027 // initialization. 3028 mActivityManagerService.systemReady(() -> { 3029 Slog.i(TAG, "Making services ready"); 3030 t.traceBegin("StartActivityManagerReadyPhase"); 3031 mSystemServiceManager.startBootPhase(t, SystemService.PHASE_ACTIVITY_MANAGER_READY); 3032 t.traceEnd(); 3033 t.traceBegin("StartObservingNativeCrashes"); 3034 try { 3035 mActivityManagerService.startObservingNativeCrashes(); 3036 } catch (Throwable e) { 3037 reportWtf("observing native crashes", e); 3038 } 3039 t.traceEnd(); 3040 3041 t.traceBegin("RegisterAppOpsPolicy"); 3042 try { 3043 mActivityManagerService.setAppOpsPolicy(new AppOpsPolicy(mSystemContext)); 3044 } catch (Throwable e) { 3045 reportWtf("registering app ops policy", e); 3046 } 3047 t.traceEnd(); 3048 3049 // No dependency on Webview preparation in system server. But this should 3050 // be completed before allowing 3rd party 3051 final String WEBVIEW_PREPARATION = "WebViewFactoryPreparation"; 3052 Future<?> webviewPrep = null; 3053 if (mWebViewUpdateService != null) { 3054 webviewPrep = SystemServerInitThreadPool.submit(() -> { 3055 Slog.i(TAG, WEBVIEW_PREPARATION); 3056 TimingsTraceAndSlog traceLog = TimingsTraceAndSlog.newAsyncLog(); 3057 traceLog.traceBegin(WEBVIEW_PREPARATION); 3058 ConcurrentUtils.waitForFutureNoInterrupt(mZygotePreload, "Zygote preload"); 3059 mZygotePreload = null; 3060 mWebViewUpdateService.prepareWebViewInSystemServer(); 3061 traceLog.traceEnd(); 3062 }, WEBVIEW_PREPARATION); 3063 } 3064 3065 boolean isAutomotive = mPackageManager 3066 .hasSystemFeature(PackageManager.FEATURE_AUTOMOTIVE); 3067 if (isAutomotive) { 3068 t.traceBegin("StartCarServiceHelperService"); 3069 final SystemService cshs = mSystemServiceManager 3070 .startService(CAR_SERVICE_HELPER_SERVICE_CLASS); 3071 if (cshs instanceof Dumpable) { 3072 mDumper.addDumpable((Dumpable) cshs); 3073 } 3074 if (cshs instanceof DevicePolicySafetyChecker) { 3075 dpms.setDevicePolicySafetyChecker((DevicePolicySafetyChecker) cshs); 3076 } 3077 t.traceEnd(); 3078 } 3079 3080 if (isWatch) { 3081 t.traceBegin("StartWearService"); 3082 String wearServiceComponentNameString = 3083 context.getString(R.string.config_wearServiceComponent); 3084 3085 if (!TextUtils.isEmpty(wearServiceComponentNameString)) { 3086 ComponentName wearServiceComponentName = ComponentName.unflattenFromString( 3087 wearServiceComponentNameString); 3088 3089 if (wearServiceComponentName != null) { 3090 Intent intent = new Intent(); 3091 intent.setComponent(wearServiceComponentName); 3092 intent.addFlags(Intent.FLAG_DIRECT_BOOT_AUTO); 3093 context.startServiceAsUser(intent, UserHandle.SYSTEM); 3094 } else { 3095 Slog.d(TAG, "Null wear service component name."); 3096 } 3097 } 3098 t.traceEnd(); 3099 } 3100 3101 // Enable airplane mode in safe mode. setAirplaneMode() cannot be called 3102 // earlier as it sends broadcasts to other services. 3103 // TODO: This may actually be too late if radio firmware already started leaking 3104 // RF before the respective services start. However, fixing this requires changes 3105 // to radio firmware and interfaces. 3106 if (safeMode) { 3107 t.traceBegin("EnableAirplaneModeInSafeMode"); 3108 try { 3109 connectivityF.setAirplaneMode(true); 3110 } catch (Throwable e) { 3111 reportWtf("enabling Airplane Mode during Safe Mode bootup", e); 3112 } 3113 t.traceEnd(); 3114 } 3115 t.traceBegin("MakeNetworkManagementServiceReady"); 3116 try { 3117 if (networkManagementF != null) { 3118 networkManagementF.systemReady(); 3119 } 3120 } catch (Throwable e) { 3121 reportWtf("making Network Managment Service ready", e); 3122 } 3123 CountDownLatch networkPolicyInitReadySignal = null; 3124 if (networkPolicyF != null) { 3125 networkPolicyInitReadySignal = networkPolicyF 3126 .networkScoreAndNetworkManagementServiceReady(); 3127 } 3128 t.traceEnd(); 3129 t.traceBegin("MakeConnectivityServiceReady"); 3130 try { 3131 if (connectivityF != null) { 3132 connectivityF.systemReady(); 3133 } 3134 } catch (Throwable e) { 3135 reportWtf("making Connectivity Service ready", e); 3136 } 3137 t.traceEnd(); 3138 t.traceBegin("MakeVpnManagerServiceReady"); 3139 try { 3140 if (vpnManagerF != null) { 3141 vpnManagerF.systemReady(); 3142 } 3143 } catch (Throwable e) { 3144 reportWtf("making VpnManagerService ready", e); 3145 } 3146 t.traceEnd(); 3147 t.traceBegin("MakeVcnManagementServiceReady"); 3148 try { 3149 if (vcnManagementF != null) { 3150 vcnManagementF.systemReady(); 3151 } 3152 } catch (Throwable e) { 3153 reportWtf("making VcnManagementService ready", e); 3154 } 3155 t.traceEnd(); 3156 t.traceBegin("MakeNetworkPolicyServiceReady"); 3157 try { 3158 if (networkPolicyF != null) { 3159 networkPolicyF.systemReady(networkPolicyInitReadySignal); 3160 } 3161 } catch (Throwable e) { 3162 reportWtf("making Network Policy Service ready", e); 3163 } 3164 t.traceEnd(); 3165 3166 // Wait for all packages to be prepared 3167 mPackageManagerService.waitForAppDataPrepared(); 3168 3169 // It is now okay to let the various system services start their 3170 // third party code... 3171 t.traceBegin("PhaseThirdPartyAppsCanStart"); 3172 // confirm webview completion before starting 3rd party 3173 if (webviewPrep != null) { 3174 ConcurrentUtils.waitForFutureNoInterrupt(webviewPrep, WEBVIEW_PREPARATION); 3175 } 3176 mSystemServiceManager.startBootPhase(t, SystemService.PHASE_THIRD_PARTY_APPS_CAN_START); 3177 t.traceEnd(); 3178 3179 if (hsumBootUserInitializer != null) { 3180 t.traceBegin("HsumBootUserInitializer.systemRunning"); 3181 hsumBootUserInitializer.systemRunning(t); 3182 t.traceEnd(); 3183 } 3184 3185 t.traceBegin("StartNetworkStack"); 3186 try { 3187 // Note : the network stack is creating on-demand objects that need to send 3188 // broadcasts, which means it currently depends on being started after 3189 // ActivityManagerService.mSystemReady and ActivityManagerService.mProcessesReady 3190 // are set to true. Be careful if moving this to a different place in the 3191 // startup sequence. 3192 NetworkStackClient.getInstance().start(); 3193 } catch (Throwable e) { 3194 reportWtf("starting Network Stack", e); 3195 } 3196 t.traceEnd(); 3197 3198 t.traceBegin("StartTethering"); 3199 try { 3200 // TODO: hide implementation details, b/146312721. 3201 ConnectivityModuleConnector.getInstance().startModuleService( 3202 TETHERING_CONNECTOR_CLASS, 3203 PERMISSION_MAINLINE_NETWORK_STACK, service -> { 3204 ServiceManager.addService(Context.TETHERING_SERVICE, service, 3205 false /* allowIsolated */, 3206 DUMP_FLAG_PRIORITY_HIGH | DUMP_FLAG_PRIORITY_NORMAL); 3207 }); 3208 } catch (Throwable e) { 3209 reportWtf("starting Tethering", e); 3210 } 3211 t.traceEnd(); 3212 3213 t.traceBegin("MakeCountryDetectionServiceReady"); 3214 try { 3215 if (countryDetectorF != null) { 3216 countryDetectorF.systemRunning(); 3217 } 3218 } catch (Throwable e) { 3219 reportWtf("Notifying CountryDetectorService running", e); 3220 } 3221 t.traceEnd(); 3222 t.traceBegin("MakeNetworkTimeUpdateReady"); 3223 try { 3224 if (networkTimeUpdaterF != null) { 3225 networkTimeUpdaterF.systemRunning(); 3226 } 3227 } catch (Throwable e) { 3228 reportWtf("Notifying NetworkTimeService running", e); 3229 } 3230 t.traceEnd(); 3231 t.traceBegin("MakeInputManagerServiceReady"); 3232 try { 3233 // TODO(BT) Pass parameter to input manager 3234 if (inputManagerF != null) { 3235 inputManagerF.systemRunning(); 3236 } 3237 } catch (Throwable e) { 3238 reportWtf("Notifying InputManagerService running", e); 3239 } 3240 t.traceEnd(); 3241 t.traceBegin("MakeTelephonyRegistryReady"); 3242 try { 3243 if (telephonyRegistryF != null) { 3244 telephonyRegistryF.systemRunning(); 3245 } 3246 } catch (Throwable e) { 3247 reportWtf("Notifying TelephonyRegistry running", e); 3248 } 3249 t.traceEnd(); 3250 t.traceBegin("MakeMediaRouterServiceReady"); 3251 try { 3252 if (mediaRouterF != null) { 3253 mediaRouterF.systemRunning(); 3254 } 3255 } catch (Throwable e) { 3256 reportWtf("Notifying MediaRouterService running", e); 3257 } 3258 t.traceEnd(); 3259 if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY)) { 3260 t.traceBegin("MakeMmsServiceReady"); 3261 try { 3262 if (mmsServiceF != null) mmsServiceF.systemRunning(); 3263 } catch (Throwable e) { 3264 reportWtf("Notifying MmsService running", e); 3265 } 3266 t.traceEnd(); 3267 } 3268 3269 t.traceBegin("IncidentDaemonReady"); 3270 try { 3271 // TODO: Switch from checkService to getService once it's always 3272 // in the build and should reliably be there. 3273 final IIncidentManager incident = IIncidentManager.Stub.asInterface( 3274 ServiceManager.getService(Context.INCIDENT_SERVICE)); 3275 if (incident != null) { 3276 incident.systemRunning(); 3277 } 3278 } catch (Throwable e) { 3279 reportWtf("Notifying incident daemon running", e); 3280 } 3281 t.traceEnd(); 3282 3283 if (mIncrementalServiceHandle != 0) { 3284 t.traceBegin("MakeIncrementalServiceReady"); 3285 setIncrementalServiceSystemReady(mIncrementalServiceHandle); 3286 t.traceEnd(); 3287 } 3288 3289 t.traceBegin("OdsignStatsLogger"); 3290 try { 3291 OdsignStatsLogger.triggerStatsWrite(); 3292 } catch (Throwable e) { 3293 reportWtf("Triggering OdsignStatsLogger", e); 3294 } 3295 t.traceEnd(); 3296 }, t); 3297 3298 t.traceBegin("LockSettingsThirdPartyAppsStarted"); 3299 LockSettingsInternal lockSettingsInternal = 3300 LocalServices.getService(LockSettingsInternal.class); 3301 if (lockSettingsInternal != null) { 3302 lockSettingsInternal.onThirdPartyAppsStarted(); 3303 } 3304 t.traceEnd(); 3305 3306 t.traceBegin("StartSystemUI"); 3307 try { 3308 startSystemUi(context, windowManagerF); 3309 } catch (Throwable e) { 3310 reportWtf("starting System UI", e); 3311 } 3312 t.traceEnd(); 3313 3314 t.traceEnd(); // startOtherServices 3315 } 3316 startOnDeviceIntelligenceService(TimingsTraceAndSlog t)3317 private void startOnDeviceIntelligenceService(TimingsTraceAndSlog t) { 3318 t.traceBegin("startOnDeviceIntelligenceManagerService"); 3319 mSystemServiceManager.startService(OnDeviceIntelligenceManagerService.class); 3320 t.traceEnd(); 3321 } 3322 3323 /** 3324 * Starts system services defined in apexes. 3325 * 3326 * <p>Apex services must be the last category of services to start. No other service must be 3327 * starting after this point. This is to prevent unnecessary stability issues when these apexes 3328 * are updated outside of OTA; and to avoid breaking dependencies from system into apexes. 3329 */ startApexServices(@onNull TimingsTraceAndSlog t)3330 private void startApexServices(@NonNull TimingsTraceAndSlog t) { 3331 if (Flags.recoverabilityDetection()) { 3332 // For debugging RescueParty 3333 if (Build.IS_DEBUGGABLE 3334 && SystemProperties.getBoolean("debug.crash_system", false)) { 3335 throw new RuntimeException(); 3336 } 3337 } 3338 3339 t.traceBegin("startApexServices"); 3340 // TODO(b/192880996): get the list from "android" package, once the manifest entries 3341 // are migrated to system manifest. 3342 List<ApexSystemServiceInfo> services = ApexManager.getInstance().getApexSystemServices(); 3343 for (ApexSystemServiceInfo info : services) { 3344 String name = info.getName(); 3345 String jarPath = info.getJarPath(); 3346 t.traceBegin("starting " + name); 3347 if (TextUtils.isEmpty(jarPath)) { 3348 mSystemServiceManager.startService(name); 3349 } else { 3350 mSystemServiceManager.startServiceFromJar(name, jarPath); 3351 } 3352 t.traceEnd(); 3353 } 3354 3355 // make sure no other services are started after this point 3356 mSystemServiceManager.sealStartedServices(); 3357 3358 t.traceEnd(); // startApexServices 3359 } 3360 updateWatchdogTimeout(@onNull TimingsTraceAndSlog t)3361 private void updateWatchdogTimeout(@NonNull TimingsTraceAndSlog t) { 3362 t.traceBegin("UpdateWatchdogTimeout"); 3363 Watchdog.getInstance().registerSettingsObserver(mSystemContext); 3364 t.traceEnd(); 3365 } 3366 deviceHasConfigString(@onNull Context context, @StringRes int resId)3367 private boolean deviceHasConfigString(@NonNull Context context, @StringRes int resId) { 3368 String serviceName = context.getString(resId); 3369 return !TextUtils.isEmpty(serviceName); 3370 } 3371 startSystemCaptionsManagerService(@onNull Context context, @NonNull TimingsTraceAndSlog t)3372 private void startSystemCaptionsManagerService(@NonNull Context context, 3373 @NonNull TimingsTraceAndSlog t) { 3374 if (!deviceHasConfigString(context, R.string.config_defaultSystemCaptionsManagerService)) { 3375 Slog.d(TAG, "SystemCaptionsManagerService disabled because resource is not overlaid"); 3376 return; 3377 } 3378 3379 t.traceBegin("StartSystemCaptionsManagerService"); 3380 mSystemServiceManager.startService(SystemCaptionsManagerService.class); 3381 t.traceEnd(); 3382 } 3383 startTextToSpeechManagerService(@onNull Context context, @NonNull TimingsTraceAndSlog t)3384 private void startTextToSpeechManagerService(@NonNull Context context, 3385 @NonNull TimingsTraceAndSlog t) { 3386 t.traceBegin("StartTextToSpeechManagerService"); 3387 mSystemServiceManager.startService(TextToSpeechManagerService.class); 3388 t.traceEnd(); 3389 } 3390 startContentCaptureService(@onNull Context context, @NonNull TimingsTraceAndSlog t)3391 private void startContentCaptureService(@NonNull Context context, 3392 @NonNull TimingsTraceAndSlog t) { 3393 // First check if it was explicitly enabled by DeviceConfig 3394 boolean explicitlyEnabled = false; 3395 String settings = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_CONTENT_CAPTURE, 3396 ContentCaptureManager.DEVICE_CONFIG_PROPERTY_SERVICE_EXPLICITLY_ENABLED); 3397 if (settings != null && !settings.equalsIgnoreCase("default")) { 3398 explicitlyEnabled = Boolean.parseBoolean(settings); 3399 if (explicitlyEnabled) { 3400 Slog.d(TAG, "ContentCaptureService explicitly enabled by DeviceConfig"); 3401 } else { 3402 Slog.d(TAG, "ContentCaptureService explicitly disabled by DeviceConfig"); 3403 return; 3404 } 3405 } 3406 3407 // Then check if OEM overlaid the resource that defines the service. 3408 if (!explicitlyEnabled) { 3409 if (!deviceHasConfigString(context, R.string.config_defaultContentCaptureService)) { 3410 Slog.d(TAG, "ContentCaptureService disabled because resource is not overlaid"); 3411 return; 3412 } 3413 if (!deviceHasConfigString(context, R.string.config_defaultContentProtectionService)) { 3414 Slog.d( 3415 TAG, 3416 "ContentProtectionService disabled because resource is not overlaid," 3417 + " ContentCaptureService still enabled"); 3418 } 3419 } 3420 3421 t.traceBegin("StartContentCaptureService"); 3422 mSystemServiceManager.startService(ContentCaptureManagerService.class); 3423 3424 ContentCaptureManagerInternal ccmi = 3425 LocalServices.getService(ContentCaptureManagerInternal.class); 3426 if (ccmi != null && mActivityManagerService != null) { 3427 mActivityManagerService.setContentCaptureManager(ccmi); 3428 } 3429 3430 t.traceEnd(); 3431 } 3432 startAttentionService(@onNull Context context, @NonNull TimingsTraceAndSlog t)3433 private void startAttentionService(@NonNull Context context, @NonNull TimingsTraceAndSlog t) { 3434 if (!AttentionManagerService.isServiceConfigured(context)) { 3435 Slog.d(TAG, "AttentionService is not configured on this device"); 3436 return; 3437 } 3438 3439 t.traceBegin("StartAttentionManagerService"); 3440 mSystemServiceManager.startService(AttentionManagerService.class); 3441 t.traceEnd(); 3442 } 3443 startRotationResolverService(@onNull Context context, @NonNull TimingsTraceAndSlog t)3444 private void startRotationResolverService(@NonNull Context context, 3445 @NonNull TimingsTraceAndSlog t) { 3446 if (!RotationResolverManagerService.isServiceConfigured(context)) { 3447 Slog.d(TAG, "RotationResolverService is not configured on this device"); 3448 return; 3449 } 3450 3451 t.traceBegin("StartRotationResolverService"); 3452 mSystemServiceManager.startService(RotationResolverManagerService.class); 3453 t.traceEnd(); 3454 3455 } 3456 startWearableSensingService(@onNull TimingsTraceAndSlog t)3457 private void startWearableSensingService(@NonNull TimingsTraceAndSlog t) { 3458 t.traceBegin("startWearableSensingService"); 3459 mSystemServiceManager.startService(WearableSensingManagerService.class); 3460 t.traceEnd(); 3461 } 3462 startSystemUi(Context context, WindowManagerService windowManager)3463 private static void startSystemUi(Context context, WindowManagerService windowManager) { 3464 PackageManagerInternal pm = LocalServices.getService(PackageManagerInternal.class); 3465 Intent intent = new Intent(); 3466 intent.setComponent(pm.getSystemUiServiceComponent()); 3467 intent.addFlags(Intent.FLAG_DEBUG_TRIAGED_MISSING); 3468 //Slog.d(TAG, "Starting service: " + intent); 3469 context.startServiceAsUser(intent, UserHandle.SYSTEM); 3470 windowManager.onSystemUiStarted(); 3471 } 3472 3473 /** 3474 * Handle the serious errors during early system boot, used by {@link Log} via 3475 * {@link com.android.internal.os.RuntimeInit}. 3476 */ handleEarlySystemWtf(final IBinder app, final String tag, boolean system, final ApplicationErrorReport.ParcelableCrashInfo crashInfo, int immediateCallerPid)3477 private static boolean handleEarlySystemWtf(final IBinder app, final String tag, boolean system, 3478 final ApplicationErrorReport.ParcelableCrashInfo crashInfo, int immediateCallerPid) { 3479 final String processName = "system_server"; 3480 final int myPid = myPid(); 3481 3482 com.android.server.am.EventLogTags.writeAmWtf(UserHandle.getUserId(SYSTEM_UID), myPid, 3483 processName, -1, tag, crashInfo.exceptionMessage); 3484 3485 FrameworkStatsLog.write(FrameworkStatsLog.WTF_OCCURRED, SYSTEM_UID, tag, processName, 3486 myPid, ServerProtoEnums.SYSTEM_SERVER); 3487 3488 synchronized (SystemServer.class) { 3489 if (sPendingWtfs == null) { 3490 sPendingWtfs = new LinkedList<>(); 3491 } 3492 sPendingWtfs.add(new Pair<>(tag, crashInfo)); 3493 } 3494 return false; 3495 } 3496 3497 } 3498