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