blob: be13499e2c18cc0924907a4b1985b7a5047eed50 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
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
17package com.android.server;
18
Jeff Brown6f357d32014-01-15 20:40:55 -080019import android.app.ActivityThread;
Adam Lesinskief2ea1f2013-12-05 16:48:06 -080020import android.app.INotificationManager;
Adam Lesinski0debc9a2014-07-16 19:09:13 -070021import android.app.usage.UsageStatsManagerInternal;
Joe Onoratof3c3c4f2010-10-21 11:09:02 -040022import android.content.ComponentName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080023import android.content.ContentResolver;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080024import android.content.Context;
Joe Onoratof3c3c4f2010-10-21 11:09:02 -040025import android.content.Intent;
Matthew Xie1dd01eb32013-04-26 12:37:54 -070026import android.content.pm.PackageManager;
Joe Onoratodc565f42010-10-04 15:27:22 -040027import android.content.res.Configuration;
Alan Viverettee54d2452015-05-06 10:41:43 -070028import android.content.res.Resources.Theme;
Jeff Sharkeyd136e512016-03-09 22:30:56 -070029import android.os.BaseBundle;
Jeff Sharkey0a17db12016-11-04 11:23:46 -060030import android.os.Binder;
Jeff Sharkey55687722014-04-09 18:07:19 -070031import android.os.Build;
Jeff Sharkey48749fc2013-04-19 13:25:04 -070032import android.os.Environment;
Jeff Brown6f357d32014-01-15 20:40:55 -080033import android.os.FactoryTest;
Tao Bao4fd6c262016-01-19 14:22:24 -080034import android.os.FileUtils;
Joe Onorato1754d742016-11-21 17:51:35 -080035import android.os.IIncidentManager;
Jeff Hamilton35eef702010-06-09 15:45:18 -050036import android.os.Looper;
Tao Bao4fd6c262016-01-19 14:22:24 -080037import android.os.PowerManager;
Jeff Hamilton35eef702010-06-09 15:45:18 -050038import android.os.RemoteException;
39import android.os.ServiceManager;
Brad Fitzpatrickc74a1b442010-09-10 16:03:29 -070040import android.os.StrictMode;
Jeff Hamilton35eef702010-06-09 15:45:18 -050041import android.os.SystemClock;
42import android.os.SystemProperties;
Yasuhiro Matsuda1ab43d52015-06-30 17:07:32 +090043import android.os.Trace;
Amith Yamasanicd757062012-10-19 18:23:52 -070044import android.os.UserHandle;
Sudheer Shanka2250d562016-11-07 15:41:02 -080045import android.os.storage.IStorageManager;
Fyodor Kupolov3235e0c2016-11-17 11:44:49 -080046import android.util.BootTimingsTraceLog;
Joe Onoratodc565f42010-10-04 15:27:22 -040047import android.util.DisplayMetrics;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080048import android.util.EventLog;
Joe Onorato8a9b2202010-02-26 18:56:32 -080049import android.util.Slog;
Brad Fitzpatrick5fdc0c72010-10-12 13:12:18 -070050import android.view.WindowManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080051
Dan Morrille4d9a012013-03-28 18:10:43 -070052import com.android.internal.R;
Justin Klaassen911e8892016-06-21 18:24:24 -070053import com.android.internal.app.NightDisplayController;
Fyodor Kupolov8d3e82b2016-11-10 17:58:50 -080054import com.android.internal.logging.MetricsLogger;
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -070055import com.android.internal.os.BinderInternal;
56import com.android.internal.os.SamplingProfilerIntegration;
Selim Cinek705442f2016-09-13 16:02:33 -070057import com.android.internal.policy.EmergencyAffordanceManager;
Jeff Sharkeyd136e512016-03-09 22:30:56 -070058import com.android.internal.widget.ILockSettings;
Adam Lesinski6c6cd502014-03-17 12:54:03 -070059import com.android.server.accessibility.AccessibilityManagerService;
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -070060import com.android.server.am.ActivityManagerService;
John Spurlock61560172015-02-06 19:46:04 -050061import com.android.server.audio.AudioService;
Ruben Brunk9d21ee52015-03-20 22:18:55 -070062import com.android.server.camera.CameraService;
Amith Yamasani30f8eb42013-11-06 14:54:50 -080063import com.android.server.clipboard.ClipboardService;
Hugo Benichieab511b2016-09-09 09:23:47 +090064import com.android.server.connectivity.IpConnectivityMetrics;
Pavel Zhamaitsiak02b3e6b2016-02-03 10:39:44 -080065import com.android.server.connectivity.MetricsLoggerService;
Adam Lesinski2c8d67c2014-04-23 13:46:21 -070066import com.android.server.devicepolicy.DevicePolicyManagerService;
Jeff Brownfa25bf52012-07-23 19:26:30 -070067import com.android.server.display.DisplayManagerService;
Justin Klaassen911e8892016-06-21 18:24:24 -070068import com.android.server.display.NightDisplayService;
Jeff Browncef440f2012-09-25 18:58:48 -070069import com.android.server.dreams.DreamManagerService;
Selim Cinek705442f2016-09-13 16:02:33 -070070import com.android.server.emergency.EmergencyAffordanceService;
Jim Millera75961472014-06-06 15:00:49 -070071import com.android.server.fingerprint.FingerprintService;
Jungshik Jang0792d372014-04-23 17:57:26 +090072import com.android.server.hdmi.HdmiControlService;
Jeff Brown6ec6f792012-04-17 16:52:41 -070073import com.android.server.input.InputManagerService;
Christopher Tate7060b042014-06-09 19:50:00 -070074import com.android.server.job.JobSchedulerService;
Adam Lesinskief2ea1f2013-12-05 16:48:06 -080075import com.android.server.lights.LightsService;
Jeff Sharkeyd136e512016-03-09 22:30:56 -070076import com.android.server.media.MediaResourceMonitorService;
Jeff Brown69b07162013-11-07 00:30:16 -080077import com.android.server.media.MediaRouterService;
RoboErik01fe6612014-02-13 14:19:04 -080078import com.android.server.media.MediaSessionService;
Michael Wrightc39d47a2014-07-08 18:07:36 -070079import com.android.server.media.projection.MediaProjectionManagerService;
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -070080import com.android.server.net.NetworkPolicyManagerService;
Jeff Sharkey75279902011-05-24 18:39:45 -070081import com.android.server.net.NetworkStatsService;
Adam Lesinskief2ea1f2013-12-05 16:48:06 -080082import com.android.server.notification.NotificationManagerService;
Svet Ganov37e43272016-09-09 16:01:32 -070083import com.android.server.os.DeviceIdentifiersPolicyService;
Jeff Sharkey7a96c392012-11-15 14:01:46 -080084import com.android.server.os.SchedulingPolicyService;
Brian Carlstrom7395a8a2014-04-28 22:11:01 -070085import com.android.server.pm.BackgroundDexOptService;
Jeff Brownf69c8122012-09-12 17:00:34 -070086import com.android.server.pm.Installer;
Amith Yamasani4f582632014-02-19 14:31:52 -080087import com.android.server.pm.LauncherAppsService;
Andreas Gampea8908752015-11-10 08:58:14 -080088import com.android.server.pm.OtaDexoptService;
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -070089import com.android.server.pm.PackageManagerService;
Makoto Onuki6f7362d92016-03-04 13:39:41 -080090import com.android.server.pm.ShortcutService;
Amith Yamasani258848d2012-08-10 17:06:33 -070091import com.android.server.pm.UserManagerService;
Wale Ogunwaleb699ce02016-07-18 12:05:30 -070092import com.android.server.policy.PhoneWindowManager;
Jeff Brown4f8ecd82012-06-18 18:29:13 -070093import com.android.server.power.PowerManagerService;
94import com.android.server.power.ShutdownThread;
Amith Yamasanif20d6402014-05-24 15:34:37 -070095import com.android.server.restrictions.RestrictionsManagerService;
Suprabh Shukla64725012016-06-15 13:19:28 -070096import com.android.server.retaildemo.RetailDemoModeService;
Janis Danisevskis8ff1e192016-06-03 11:31:55 -070097import com.android.server.security.KeyAttestationApplicationIdProviderService;
Arunesh Mishraa772e5f2016-01-25 10:33:11 -080098import com.android.server.soundtrigger.SoundTriggerService;
Adam Lesinskief2ea1f2013-12-05 16:48:06 -080099import com.android.server.statusbar.StatusBarManagerService;
100import com.android.server.storage.DeviceStorageMonitorService;
Santos Cordon5d2c1e62014-11-21 15:20:15 -0800101import com.android.server.telecom.TelecomLoaderService;
Adrian Roos82142c22014-03-27 14:56:59 +0100102import com.android.server.trust.TrustManagerService;
Jae Seo39570912014-02-20 18:23:25 -0800103import com.android.server.tv.TvInputManagerService;
Fyodor Kupolov3235e0c2016-11-17 11:44:49 -0800104import com.android.server.tv.TvRemoteService;
Adam Lesinskief2ea1f2013-12-05 16:48:06 -0800105import com.android.server.twilight.TwilightService;
Adam Lesinski0debc9a2014-07-16 19:09:13 -0700106import com.android.server.usage.UsageStatsService;
Ruben Brunkdd18a0b2015-12-04 16:16:31 -0800107import com.android.server.vr.VrManagerService;
Torne (Richard Coles)08cfaf62014-05-08 16:07:05 +0100108import com.android.server.webkit.WebViewUpdateService;
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -0700109import com.android.server.wm.WindowManagerService;
110
111import dalvik.system.VMRuntime;
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -0700112
Tao Bao4fd6c262016-01-19 14:22:24 -0800113import java.io.File;
114import java.io.IOException;
Narayan Kamathbf882052015-08-11 15:40:34 +0100115import java.util.Locale;
Bob Leee5408332009-09-04 18:31:17 -0700116import java.util.Timer;
117import java.util.TimerTask;
Fyodor Kupolov311b9fa2016-12-02 16:24:35 -0800118import java.util.concurrent.CountDownLatch;
Bob Leee5408332009-09-04 18:31:17 -0700119
Andrii Kulian5406e7a2016-10-21 11:55:23 -0700120import static android.view.Display.DEFAULT_DISPLAY;
121
Jeff Brown6f357d32014-01-15 20:40:55 -0800122public final class SystemServer {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800123 private static final String TAG = "SystemServer";
Jeff Brown6f357d32014-01-15 20:40:55 -0800124
Fyodor Kupolov3235e0c2016-11-17 11:44:49 -0800125 private static final BootTimingsTraceLog BOOT_TIMINGS_TRACE_LOG
126 = new BootTimingsTraceLog("SystemServerTiming", Trace.TRACE_TAG_SYSTEM_SERVER);
Vitalii Tomkiv4887e672016-07-21 15:58:24 -0700127
Ben Komalo553acf02011-09-19 14:25:28 -0700128 private static final String ENCRYPTING_STATE = "trigger_restart_min_framework";
Ben Komalo3573d402011-09-23 15:08:24 -0700129 private static final String ENCRYPTED_STATE = "1";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800130
Jeff Brown6f357d32014-01-15 20:40:55 -0800131 private static final long SNAPSHOT_INTERVAL = 60 * 60 * 1000; // 1hr
132
133 // The earliest supported time. We pick one day into 1970, to
134 // give any timezone code room without going into negative time.
135 private static final long EARLIEST_SUPPORTED_TIME = 86400 * 1000;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800136
Amith Yamasani817ec492013-12-20 13:27:30 -0800137 /*
138 * Implementation class names. TODO: Move them to a codegen class or load
139 * them from the build system somehow.
140 */
141 private static final String BACKUP_MANAGER_SERVICE_CLASS =
Jeff Brownb880d882014-02-10 19:47:07 -0800142 "com.android.server.backup.BackupManagerService$Lifecycle";
Amith Yamasani817ec492013-12-20 13:27:30 -0800143 private static final String APPWIDGET_SERVICE_CLASS =
144 "com.android.server.appwidget.AppWidgetService";
Dianne Hackborn91097de2014-04-04 18:02:06 -0700145 private static final String VOICE_RECOGNITION_MANAGER_SERVICE_CLASS =
146 "com.android.server.voiceinteraction.VoiceInteractionManagerService";
Amith Yamasani817ec492013-12-20 13:27:30 -0800147 private static final String PRINT_MANAGER_SERVICE_CLASS =
148 "com.android.server.print.PrintManagerService";
Adam Lesinski2cb6c602014-02-14 17:19:56 -0800149 private static final String USB_SERVICE_CLASS =
150 "com.android.server.usb.UsbService$Lifecycle";
Mike Lockwood5781cd52015-03-27 13:23:41 -0700151 private static final String MIDI_SERVICE_CLASS =
152 "com.android.server.midi.MidiService$Lifecycle";
Adam Lesinskif542a332014-02-19 12:29:58 -0800153 private static final String WIFI_SERVICE_CLASS =
154 "com.android.server.wifi.WifiService";
Etan Cohen04133272016-10-26 11:22:06 -0700155 private static final String WIFI_AWARE_SERVICE_CLASS =
156 "com.android.server.wifi.aware.WifiAwareService";
Adam Lesinskif542a332014-02-19 12:29:58 -0800157 private static final String WIFI_P2P_SERVICE_CLASS =
158 "com.android.server.wifi.p2p.WifiP2pService";
Lorenzo Colittif9ff2c92014-05-21 16:32:11 -0700159 private static final String ETHERNET_SERVICE_CLASS =
160 "com.android.server.ethernet.EthernetService";
Christopher Tate7060b042014-06-09 19:50:00 -0700161 private static final String JOB_SCHEDULER_SERVICE_CLASS =
162 "com.android.server.job.JobSchedulerService";
Jim Miller4f93c582016-01-27 19:05:43 -0800163 private static final String LOCK_SETTINGS_SERVICE_CLASS =
164 "com.android.server.LockSettingsService$Lifecycle";
Sudheer Shanka2250d562016-11-07 15:41:02 -0800165 private static final String STORAGE_MANAGER_SERVICE_CLASS =
166 "com.android.server.StorageManagerService$Lifecycle";
Jeff Sharkey4175be22016-01-09 14:57:45 -0700167 private static final String SEARCH_MANAGER_SERVICE_CLASS =
168 "com.android.server.search.SearchManagerService$Lifecycle";
Wei Liud699cf82016-03-25 16:32:10 -0700169 private static final String THERMAL_OBSERVER_CLASS =
170 "com.google.android.clockwork.ThermalObserver";
Wei Liu48d3b632016-03-29 15:26:48 -0700171 private static final String WEAR_BLUETOOTH_SERVICE_CLASS =
172 "com.google.android.clockwork.bluetooth.WearBluetoothService";
Nancy Zhengf3d8b812016-07-08 12:55:48 -0700173 private static final String WEAR_WIFI_MEDIATOR_SERVICE_CLASS =
174 "com.google.android.clockwork.wifi.WearWifiMediatorService";
Damien Bargiacchi2d92eeb2016-04-07 14:01:03 -0700175 private static final String WEAR_TIME_SERVICE_CLASS =
176 "com.google.android.clockwork.time.WearTimeService";
Jeff Sharkey1cab76a2016-04-12 18:23:31 -0600177 private static final String ACCOUNT_SERVICE_CLASS =
178 "com.android.server.accounts.AccountManagerService$Lifecycle";
Jeff Sharkeya3ebfec2016-04-04 08:58:04 -0600179 private static final String CONTENT_SERVICE_CLASS =
180 "com.android.server.content.ContentService$Lifecycle";
Jeff Sharkey1cab76a2016-04-12 18:23:31 -0600181 private static final String WALLPAPER_SERVICE_CLASS =
182 "com.android.server.wallpaper.WallpaperManagerService$Lifecycle";
Felipe Leme5381aa42016-10-13 09:02:32 -0700183 private static final String AUTO_FILL_MANAGER_SERVICE_CLASS =
184 "com.android.server.autofill.AutoFillManagerService";
Jeff Sharkey4175be22016-01-09 14:57:45 -0700185
Andres Morales68d4acd2014-07-01 19:40:41 -0700186 private static final String PERSISTENT_DATA_BLOCK_PROP = "ro.frp.pst";
Amith Yamasani817ec492013-12-20 13:27:30 -0800187
Tao Bao4fd6c262016-01-19 14:22:24 -0800188 private static final String UNCRYPT_PACKAGE_FILE = "/cache/recovery/uncrypt_file";
189 private static final String BLOCK_MAP_FILE = "/cache/recovery/block.map";
190
Tim Murrayeef4a3d2016-04-19 14:14:20 -0700191 // maximum number of binder threads used for system_server
192 // will be higher than the system default
193 private static final int sMaxBinderThreads = 31;
194
Alan Viveretteba398ea2015-12-16 15:28:23 -0500195 /**
196 * Default theme used by the system context. This is used to style
197 * system-provided dialogs, such as the Power Off dialog, and other
198 * visual content.
199 */
200 private static final int DEFAULT_SYSTEM_THEME =
Michael Kwan9c7274c2016-06-13 12:48:55 -0700201 com.android.internal.R.style.Theme_DeviceDefault_System;
Alan Viveretteba398ea2015-12-16 15:28:23 -0500202
Jeff Brown6f357d32014-01-15 20:40:55 -0800203 private final int mFactoryTestMode;
204 private Timer mProfilerSnapshotTimer;
205
206 private Context mSystemContext;
207 private SystemServiceManager mSystemServiceManager;
208
Jeff Brown4ccb8232014-01-16 22:16:42 -0800209 // TODO: remove all of these references by improving dependency resolution and boot phases
Jeff Brown4ccb8232014-01-16 22:16:42 -0800210 private PowerManagerService mPowerManagerService;
211 private ActivityManagerService mActivityManagerService;
Gustav Sennton6258dcd2015-10-30 19:25:37 +0000212 private WebViewUpdateService mWebViewUpdateService;
Jeff Brown4ccb8232014-01-16 22:16:42 -0800213 private DisplayManagerService mDisplayManagerService;
Jeff Brown2c43c332014-06-12 22:38:59 -0700214 private PackageManagerService mPackageManagerService;
215 private PackageManager mPackageManager;
Jeff Brown6f357d32014-01-15 20:40:55 -0800216 private ContentResolver mContentResolver;
Jeff Sharkey1cab76a2016-04-12 18:23:31 -0600217 private EntropyMixer mEntropyMixer;
Jeff Brown6f357d32014-01-15 20:40:55 -0800218
Jeff Brown2c43c332014-06-12 22:38:59 -0700219 private boolean mOnlyCore;
220 private boolean mFirstBoot;
221
Jeff Brown6f357d32014-01-15 20:40:55 -0800222 /**
Svet Ganovb9d71a62015-04-30 10:38:13 -0700223 * Start the sensor service.
Jeff Brown6f357d32014-01-15 20:40:55 -0800224 */
Svet Ganovb9d71a62015-04-30 10:38:13 -0700225 private static native void startSensorService();
Jeff Brown6f357d32014-01-15 20:40:55 -0800226
227 /**
228 * The main entry point from zygote.
229 */
230 public static void main(String[] args) {
231 new SystemServer().run();
232 }
233
234 public SystemServer() {
Jeff Brown2c43c332014-06-12 22:38:59 -0700235 // Check for factory test mode.
Jeff Brown6f357d32014-01-15 20:40:55 -0800236 mFactoryTestMode = FactoryTest.getMode();
237 }
238
239 private void run() {
Yasuhiro Matsuda1ab43d52015-06-30 17:07:32 +0900240 try {
Vitalii Tomkiv4887e672016-07-21 15:58:24 -0700241 traceBeginAndSlog("InitBeforeStartServices");
Yasuhiro Matsuda1ab43d52015-06-30 17:07:32 +0900242 // If a device's clock is before 1970 (before 0), a lot of
243 // APIs crash dealing with negative numbers, notably
244 // java.io.File#setLastModified, so instead we fake it and
245 // hope that time from cell towers or NTP fixes it shortly.
246 if (System.currentTimeMillis() < EARLIEST_SUPPORTED_TIME) {
247 Slog.w(TAG, "System clock is before 1970; setting to 1970.");
248 SystemClock.setCurrentTimeMillis(EARLIEST_SUPPORTED_TIME);
249 }
Jeff Brown6f357d32014-01-15 20:40:55 -0800250
Yasuhiro Matsudaebf94652015-09-02 22:48:13 +0900251 // If the system has "persist.sys.language" and friends set, replace them with
252 // "persist.sys.locale". Note that the default locale at this point is calculated
253 // using the "-Duser.locale" command line flag. That flag is usually populated by
254 // AndroidRuntime using the same set of system properties, but only the system_server
255 // and system apps are allowed to set them.
256 //
257 // NOTE: Most changes made here will need an equivalent change to
258 // core/jni/AndroidRuntime.cpp
259 if (!SystemProperties.get("persist.sys.language").isEmpty()) {
260 final String languageTag = Locale.getDefault().toLanguageTag();
Narayan Kamathbf882052015-08-11 15:40:34 +0100261
Yasuhiro Matsudaebf94652015-09-02 22:48:13 +0900262 SystemProperties.set("persist.sys.locale", languageTag);
263 SystemProperties.set("persist.sys.language", "");
264 SystemProperties.set("persist.sys.country", "");
265 SystemProperties.set("persist.sys.localevar", "");
266 }
Narayan Kamathbf882052015-08-11 15:40:34 +0100267
Jeff Sharkey0a17db12016-11-04 11:23:46 -0600268 // The system server should never make non-oneway calls
269 Binder.setWarnOnBlocking(true);
270
Yasuhiro Matsuda1ab43d52015-06-30 17:07:32 +0900271 // Here we go!
272 Slog.i(TAG, "Entered the Android system server!");
Fyodor Kupolov8d3e82b2016-11-10 17:58:50 -0800273 int uptimeMillis = (int) SystemClock.uptimeMillis();
274 EventLog.writeEvent(EventLogTags.BOOT_PROGRESS_SYSTEM_RUN, uptimeMillis);
275 MetricsLogger.histogram(null, "boot_system_server_init", uptimeMillis);
Fyodor Kupolov3235e0c2016-11-17 11:44:49 -0800276 // Also report when first stage of init has started
Fyodor Kupolov7890c2af2016-12-12 12:41:16 -0800277 long initStartNs = SystemProperties.getLong("ro.boottime.init", -1);
Fyodor Kupolov3235e0c2016-11-17 11:44:49 -0800278 if (initStartNs >= 0) {
279 MetricsLogger.histogram(null, "boot_android_init", (int)(initStartNs / 1000000));
280 }
Jeff Brown6f357d32014-01-15 20:40:55 -0800281
Yasuhiro Matsuda1ab43d52015-06-30 17:07:32 +0900282 // In case the runtime switched since last boot (such as when
283 // the old runtime was removed in an OTA), set the system
284 // property so that it is in sync. We can't do this in
285 // libnativehelper's JniInvocation::Init code where we already
286 // had to fallback to a different runtime because it is
287 // running as root and we need to be the system user to set
288 // the property. http://b/11463182
289 SystemProperties.set("persist.sys.dalvik.vm.lib.2", VMRuntime.getRuntime().vmLibrary());
Jeff Brown6f357d32014-01-15 20:40:55 -0800290
Yasuhiro Matsuda1ab43d52015-06-30 17:07:32 +0900291 // Enable the sampling profiler.
292 if (SamplingProfilerIntegration.isEnabled()) {
293 SamplingProfilerIntegration.start();
294 mProfilerSnapshotTimer = new Timer();
295 mProfilerSnapshotTimer.schedule(new TimerTask() {
296 @Override
297 public void run() {
298 SamplingProfilerIntegration.writeSnapshot("system_server", null);
299 }
300 }, SNAPSHOT_INTERVAL, SNAPSHOT_INTERVAL);
301 }
Jeff Brown6f357d32014-01-15 20:40:55 -0800302
Yasuhiro Matsuda1ab43d52015-06-30 17:07:32 +0900303 // Mmmmmm... more memory!
304 VMRuntime.getRuntime().clearGrowthLimit();
Jeff Brown6f357d32014-01-15 20:40:55 -0800305
Yasuhiro Matsuda1ab43d52015-06-30 17:07:32 +0900306 // The system server has to run all of the time, so it needs to be
307 // as efficient as possible with its memory usage.
308 VMRuntime.getRuntime().setTargetHeapUtilization(0.8f);
Jeff Brown6f357d32014-01-15 20:40:55 -0800309
Yasuhiro Matsuda1ab43d52015-06-30 17:07:32 +0900310 // Some devices rely on runtime fingerprint generation, so make sure
311 // we've defined it before booting further.
312 Build.ensureFingerprintProperty();
Jeff Sharkey55687722014-04-09 18:07:19 -0700313
Yasuhiro Matsuda1ab43d52015-06-30 17:07:32 +0900314 // Within the system server, it is an error to access Environment paths without
315 // explicitly specifying a user.
316 Environment.setUserRequired(true);
Jeff Brown6f357d32014-01-15 20:40:55 -0800317
Jeff Sharkeyd136e512016-03-09 22:30:56 -0700318 // Within the system server, any incoming Bundles should be defused
319 // to avoid throwing BadParcelableException.
320 BaseBundle.setShouldDefuse(true);
321
Yasuhiro Matsuda1ab43d52015-06-30 17:07:32 +0900322 // Ensure binder calls into the system always run at foreground priority.
323 BinderInternal.disableBackgroundScheduling(true);
Jeff Brown6f357d32014-01-15 20:40:55 -0800324
Tim Murrayeef4a3d2016-04-19 14:14:20 -0700325 // Increase the number of binder threads in system_server
326 BinderInternal.setMaxThreads(sMaxBinderThreads);
327
Yasuhiro Matsuda1ab43d52015-06-30 17:07:32 +0900328 // Prepare the main looper thread (this thread).
329 android.os.Process.setThreadPriority(
Jeff Brown6f357d32014-01-15 20:40:55 -0800330 android.os.Process.THREAD_PRIORITY_FOREGROUND);
Yasuhiro Matsuda1ab43d52015-06-30 17:07:32 +0900331 android.os.Process.setCanSelfBackground(false);
332 Looper.prepareMainLooper();
Jeff Brown6f357d32014-01-15 20:40:55 -0800333
Yasuhiro Matsuda1ab43d52015-06-30 17:07:32 +0900334 // Initialize native services.
335 System.loadLibrary("android_servers");
Jeff Brown6f357d32014-01-15 20:40:55 -0800336
Yasuhiro Matsuda1ab43d52015-06-30 17:07:32 +0900337 // Check whether we failed to shut down last time we tried.
338 // This call may not return.
339 performPendingShutdown();
Jeff Brown6f357d32014-01-15 20:40:55 -0800340
Yasuhiro Matsuda1ab43d52015-06-30 17:07:32 +0900341 // Initialize the system context.
342 createSystemContext();
Jeff Brown6f357d32014-01-15 20:40:55 -0800343
Yasuhiro Matsuda1ab43d52015-06-30 17:07:32 +0900344 // Create the system service manager.
345 mSystemServiceManager = new SystemServiceManager(mSystemContext);
346 LocalServices.addService(SystemServiceManager.class, mSystemServiceManager);
347 } finally {
Vitalii Tomkiv4887e672016-07-21 15:58:24 -0700348 traceEnd(); // InitBeforeStartServices
Yasuhiro Matsuda1ab43d52015-06-30 17:07:32 +0900349 }
Jeff Brown6f357d32014-01-15 20:40:55 -0800350
351 // Start services.
352 try {
Vitalii Tomkiv4887e672016-07-21 15:58:24 -0700353 traceBeginAndSlog("StartServices");
Jeff Brown6f357d32014-01-15 20:40:55 -0800354 startBootstrapServices();
Jeff Brown4ccb8232014-01-16 22:16:42 -0800355 startCoreServices();
Jeff Brown6f357d32014-01-15 20:40:55 -0800356 startOtherServices();
Jeff Brown2c43c332014-06-12 22:38:59 -0700357 } catch (Throwable ex) {
Jeff Brown6f357d32014-01-15 20:40:55 -0800358 Slog.e("System", "******************************************");
359 Slog.e("System", "************ Failure starting system services", ex);
360 throw ex;
Yasuhiro Matsuda1ab43d52015-06-30 17:07:32 +0900361 } finally {
Vitalii Tomkiv4887e672016-07-21 15:58:24 -0700362 traceEnd();
Jeff Brown6f357d32014-01-15 20:40:55 -0800363 }
364
365 // For debug builds, log event loop stalls to dropbox for analysis.
366 if (StrictMode.conditionallyEnableDebugLogging()) {
367 Slog.i(TAG, "Enabled StrictMode for system server main thread.");
368 }
Fyodor Kupolov8d3e82b2016-11-10 17:58:50 -0800369 MetricsLogger.histogram(null, "boot_system_server_ready", (int) SystemClock.uptimeMillis());
Jeff Brown6f357d32014-01-15 20:40:55 -0800370
371 // Loop forever.
372 Looper.loop();
373 throw new RuntimeException("Main thread loop unexpectedly exited");
374 }
375
376 private void reportWtf(String msg, Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700377 Slog.w(TAG, "***********************************************");
Dianne Hackborn8d051722014-10-01 14:59:58 -0700378 Slog.wtf(TAG, "BOOT FAILURE " + msg, e);
Dianne Hackborn661cd522011-08-22 00:26:20 -0700379 }
380
Jeff Brown6f357d32014-01-15 20:40:55 -0800381 private void performPendingShutdown() {
382 final String shutdownAction = SystemProperties.get(
383 ShutdownThread.SHUTDOWN_ACTION_PROPERTY, "");
384 if (shutdownAction != null && shutdownAction.length() > 0) {
385 boolean reboot = (shutdownAction.charAt(0) == '1');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800386
Jeff Brown6f357d32014-01-15 20:40:55 -0800387 final String reason;
388 if (shutdownAction.length() > 1) {
389 reason = shutdownAction.substring(1, shutdownAction.length());
390 } else {
391 reason = null;
Kenny Rootf547d672010-09-22 10:36:48 -0700392 }
Jeff Brown6f357d32014-01-15 20:40:55 -0800393
Tao Bao4fd6c262016-01-19 14:22:24 -0800394 // If it's a pending reboot into recovery to apply an update,
395 // always make sure uncrypt gets executed properly when needed.
396 // If '/cache/recovery/block.map' hasn't been created, stop the
397 // reboot which will fail for sure, and get a chance to capture a
Tao Baoe8a403d2015-12-31 07:44:55 -0800398 // bugreport when that's still feasible. (Bug: 26444951)
399 if (PowerManager.REBOOT_RECOVERY_UPDATE.equals(reason)) {
Tao Bao4fd6c262016-01-19 14:22:24 -0800400 File packageFile = new File(UNCRYPT_PACKAGE_FILE);
401 if (packageFile.exists()) {
402 String filename = null;
403 try {
404 filename = FileUtils.readTextFile(packageFile, 0, null);
405 } catch (IOException e) {
406 Slog.e(TAG, "Error reading uncrypt package file", e);
407 }
408
409 if (filename != null && filename.startsWith("/data")) {
410 if (!new File(BLOCK_MAP_FILE).exists()) {
411 Slog.e(TAG, "Can't find block map file, uncrypt failed or " +
412 "unexpected runtime restart?");
413 return;
414 }
415 }
416 }
417 }
riddle_hsud3b37172015-03-19 01:11:55 +0800418 ShutdownThread.rebootOrShutdown(null, reboot, reason);
Kenny Rootf547d672010-09-22 10:36:48 -0700419 }
Jeff Brown6f357d32014-01-15 20:40:55 -0800420 }
Kenny Rootf547d672010-09-22 10:36:48 -0700421
Jeff Brown6f357d32014-01-15 20:40:55 -0800422 private void createSystemContext() {
423 ActivityThread activityThread = ActivityThread.systemMain();
424 mSystemContext = activityThread.getSystemContext();
Alan Viveretteba398ea2015-12-16 15:28:23 -0500425 mSystemContext.setTheme(DEFAULT_SYSTEM_THEME);
Jeff Brown6f357d32014-01-15 20:40:55 -0800426 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800427
Jeff Brown2c43c332014-06-12 22:38:59 -0700428 /**
429 * Starts the small tangle of critical services that are needed to get
430 * the system off the ground. These services have complex mutual dependencies
431 * which is why we initialize them all in one place here. Unless your service
432 * is also entwined in these dependencies, it should be initialized in one of
433 * the other functions.
434 */
Jeff Brown6f357d32014-01-15 20:40:55 -0800435 private void startBootstrapServices() {
436 // Wait for installd to finish starting up so that it has a chance to
437 // create critical directories such as /data/user with the appropriate
438 // permissions. We need this to complete before we initialize other services.
Vitalii Tomkiv4887e672016-07-21 15:58:24 -0700439 traceBeginAndSlog("StartInstaller");
Narayan Kamath76a748e2014-11-10 14:23:41 +0000440 Installer installer = mSystemServiceManager.startService(Installer.class);
Vitalii Tomkiv4887e672016-07-21 15:58:24 -0700441 traceEnd();
Jeff Brown6f357d32014-01-15 20:40:55 -0800442
Svet Ganov37e43272016-09-09 16:01:32 -0700443 // In some cases after launching an app we need to access device identifiers,
444 // therefore register the device identifier policy before the activity manager.
445 traceBeginAndSlog("DeviceIdentifiersPolicyService");
446 mSystemServiceManager.startService(DeviceIdentifiersPolicyService.class);
447 traceEnd();
448
Jeff Brown6f357d32014-01-15 20:40:55 -0800449 // Activity manager runs the show.
Vitalii Tomkiv4887e672016-07-21 15:58:24 -0700450 traceBeginAndSlog("StartActivityManager");
Jeff Brown4ccb8232014-01-16 22:16:42 -0800451 mActivityManagerService = mSystemServiceManager.startService(
452 ActivityManagerService.Lifecycle.class).getService();
Dianne Hackborn91097de2014-04-04 18:02:06 -0700453 mActivityManagerService.setSystemServiceManager(mSystemServiceManager);
Narayan Kamath76a748e2014-11-10 14:23:41 +0000454 mActivityManagerService.setInstaller(installer);
Vitalii Tomkiv4887e672016-07-21 15:58:24 -0700455 traceEnd();
Jeff Brown4ccb8232014-01-16 22:16:42 -0800456
Jeff Brown2c43c332014-06-12 22:38:59 -0700457 // Power manager needs to be started early because other services need it.
458 // Native daemons may be watching for it to be registered so it must be ready
459 // to handle incoming binder calls immediately (including being able to verify
460 // the permissions for those calls).
Vitalii Tomkiv4887e672016-07-21 15:58:24 -0700461 traceBeginAndSlog("StartPowerManager");
Jeff Brown2c43c332014-06-12 22:38:59 -0700462 mPowerManagerService = mSystemServiceManager.startService(PowerManagerService.class);
Vitalii Tomkiv4887e672016-07-21 15:58:24 -0700463 traceEnd();
Jeff Brown2c43c332014-06-12 22:38:59 -0700464
465 // Now that the power manager has been started, let the activity manager
466 // initialize power management features.
Vitalii Tomkiv4887e672016-07-21 15:58:24 -0700467 traceBeginAndSlog("InitPowerManagement");
Jeff Brown2c43c332014-06-12 22:38:59 -0700468 mActivityManagerService.initPowerManagement();
Vitalii Tomkiv4887e672016-07-21 15:58:24 -0700469 traceEnd();
Jeff Brown2c43c332014-06-12 22:38:59 -0700470
Jeff Brown5d6443b2015-04-10 20:15:01 -0700471 // Manages LEDs and display backlight so we need it to bring up the display.
Vitalii Tomkiv4887e672016-07-21 15:58:24 -0700472 traceBeginAndSlog("StartLightsService");
Jeff Brown5d6443b2015-04-10 20:15:01 -0700473 mSystemServiceManager.startService(LightsService.class);
Vitalii Tomkiv4887e672016-07-21 15:58:24 -0700474 traceEnd();
Jeff Brown5d6443b2015-04-10 20:15:01 -0700475
Jeff Brown4ccb8232014-01-16 22:16:42 -0800476 // Display manager is needed to provide display metrics before package manager
477 // starts up.
Vitalii Tomkiv4887e672016-07-21 15:58:24 -0700478 traceBeginAndSlog("StartDisplayManager");
Jeff Brown4ccb8232014-01-16 22:16:42 -0800479 mDisplayManagerService = mSystemServiceManager.startService(DisplayManagerService.class);
Vitalii Tomkiv4887e672016-07-21 15:58:24 -0700480 traceEnd();
Jeff Brown2c43c332014-06-12 22:38:59 -0700481
482 // We need the default display before we can initialize the package manager.
Vitalii Tomkiv4887e672016-07-21 15:58:24 -0700483 traceBeginAndSlog("WaitForDisplay");
Jeff Brown2c43c332014-06-12 22:38:59 -0700484 mSystemServiceManager.startBootPhase(SystemService.PHASE_WAIT_FOR_DEFAULT_DISPLAY);
Vitalii Tomkiv4887e672016-07-21 15:58:24 -0700485 traceEnd();
Jeff Brown2c43c332014-06-12 22:38:59 -0700486
487 // Only run "core" apps if we're encrypting the device.
488 String cryptState = SystemProperties.get("vold.decrypt");
489 if (ENCRYPTING_STATE.equals(cryptState)) {
490 Slog.w(TAG, "Detected encryption in progress - only parsing core apps");
491 mOnlyCore = true;
492 } else if (ENCRYPTED_STATE.equals(cryptState)) {
493 Slog.w(TAG, "Device encrypted - only parsing core apps");
494 mOnlyCore = true;
495 }
496
497 // Start the package manager.
Fyodor Kupolov8d3e82b2016-11-10 17:58:50 -0800498 MetricsLogger.histogram(null, "boot_package_manager_init_start",
499 (int) SystemClock.uptimeMillis());
Yasuhiro Matsuda1ab43d52015-06-30 17:07:32 +0900500 traceBeginAndSlog("StartPackageManagerService");
Narayan Kamath76a748e2014-11-10 14:23:41 +0000501 mPackageManagerService = PackageManagerService.main(mSystemContext, installer,
Jeff Brown2c43c332014-06-12 22:38:59 -0700502 mFactoryTestMode != FactoryTest.FACTORY_TEST_OFF, mOnlyCore);
503 mFirstBoot = mPackageManagerService.isFirstBoot();
504 mPackageManager = mSystemContext.getPackageManager();
Vitalii Tomkiv4887e672016-07-21 15:58:24 -0700505 traceEnd();
Fyodor Kupolov8d3e82b2016-11-10 17:58:50 -0800506 MetricsLogger.histogram(null, "boot_package_manager_init_ready",
507 (int) SystemClock.uptimeMillis());
Andreas Gampeabcbe2f2016-02-26 11:25:36 -0800508 // Manages A/B OTA dexopting. This is a bootstrap service as we need it to rename
509 // A/B artifacts after boot, before anything else might touch/need them.
510 // Note: this isn't needed during decryption (we don't have /data anyways).
511 if (!mOnlyCore) {
512 boolean disableOtaDexopt = SystemProperties.getBoolean("config.disable_otadexopt",
513 false);
514 if (!disableOtaDexopt) {
515 traceBeginAndSlog("StartOtaDexOptService");
516 try {
517 OtaDexoptService.main(mSystemContext, mPackageManagerService);
518 } catch (Throwable e) {
519 reportWtf("starting OtaDexOptService", e);
520 } finally {
Vitalii Tomkiv4887e672016-07-21 15:58:24 -0700521 traceEnd();
Andreas Gampeabcbe2f2016-02-26 11:25:36 -0800522 }
523 }
524 }
525
Yasuhiro Matsuda1ab43d52015-06-30 17:07:32 +0900526 traceBeginAndSlog("StartUserManagerService");
Amith Yamasanid04aaa32016-06-13 12:09:36 -0700527 mSystemServiceManager.startService(UserManagerService.LifeCycle.class);
Vitalii Tomkiv4887e672016-07-21 15:58:24 -0700528 traceEnd();
Adam Lesinski3c153512014-07-23 17:34:34 -0700529
Jeff Brown2c43c332014-06-12 22:38:59 -0700530 // Initialize attribute cache used to cache resources from packages.
Vitalii Tomkiv4887e672016-07-21 15:58:24 -0700531 traceBeginAndSlog("InitAttributerCache");
Jeff Brown2c43c332014-06-12 22:38:59 -0700532 AttributeCache.init(mSystemContext);
Vitalii Tomkiv4887e672016-07-21 15:58:24 -0700533 traceEnd();
Jeff Brown2c43c332014-06-12 22:38:59 -0700534
535 // Set up the Application instance for the system process and get started.
Vitalii Tomkiv4887e672016-07-21 15:58:24 -0700536 traceBeginAndSlog("SetSystemProcess");
Jeff Brown2c43c332014-06-12 22:38:59 -0700537 mActivityManagerService.setSystemProcess();
Vitalii Tomkiv4887e672016-07-21 15:58:24 -0700538 traceEnd();
Svet Ganovb9d71a62015-04-30 10:38:13 -0700539
540 // The sensor service needs access to package manager service, app ops
541 // service, and permissions service, therefore we start it after them.
Vitalii Tomkiv4887e672016-07-21 15:58:24 -0700542 traceBeginAndSlog("StartSensorService");
Svet Ganovb9d71a62015-04-30 10:38:13 -0700543 startSensorService();
Vitalii Tomkiv4887e672016-07-21 15:58:24 -0700544 traceEnd();
Jeff Brown6f357d32014-01-15 20:40:55 -0800545 }
546
Jeff Brown2c43c332014-06-12 22:38:59 -0700547 /**
548 * Starts some essential services that are not tangled up in the bootstrap process.
549 */
550 private void startCoreServices() {
Jeff Sharkeyd79d2032016-08-23 13:39:07 -0600551 // Records errors and logs, for example wtf()
Vitalii Tomkiv4887e672016-07-21 15:58:24 -0700552 traceBeginAndSlog("StartDropBoxManager");
Jeff Sharkeyd79d2032016-08-23 13:39:07 -0600553 mSystemServiceManager.startService(DropBoxManagerService.class);
Vitalii Tomkiv4887e672016-07-21 15:58:24 -0700554 traceEnd();
Jeff Sharkeyd79d2032016-08-23 13:39:07 -0600555
Vitalii Tomkiv4887e672016-07-21 15:58:24 -0700556 traceBeginAndSlog("StartBatteryService");
Jeff Brown21392762014-06-13 19:00:36 -0700557 // Tracks the battery level. Requires LightService.
558 mSystemServiceManager.startService(BatteryService.class);
Vitalii Tomkiv4887e672016-07-21 15:58:24 -0700559 traceEnd();
Adam Lesinski0debc9a2014-07-16 19:09:13 -0700560
561 // Tracks application usage stats.
Vitalii Tomkiv4887e672016-07-21 15:58:24 -0700562 traceBeginAndSlog("StartUsageService");
Adam Lesinski0debc9a2014-07-16 19:09:13 -0700563 mSystemServiceManager.startService(UsageStatsService.class);
564 mActivityManagerService.setUsageStatsManager(
565 LocalServices.getService(UsageStatsManagerInternal.class));
Vitalii Tomkiv4887e672016-07-21 15:58:24 -0700566 traceEnd();
Torne (Richard Coles)4dbeb352014-07-29 19:14:24 +0100567
568 // Tracks whether the updatable WebView is in a ready state and watches for update installs.
Vitalii Tomkiv4887e672016-07-21 15:58:24 -0700569 traceBeginAndSlog("StartWebViewUpdateService");
Gustav Sennton6258dcd2015-10-30 19:25:37 +0000570 mWebViewUpdateService = mSystemServiceManager.startService(WebViewUpdateService.class);
Vitalii Tomkiv4887e672016-07-21 15:58:24 -0700571 traceEnd();
Jeff Brown2c43c332014-06-12 22:38:59 -0700572 }
573
574 /**
575 * Starts a miscellaneous grab bag of stuff that has yet to be refactored
576 * and organized.
577 */
Jeff Brown6f357d32014-01-15 20:40:55 -0800578 private void startOtherServices() {
Jeff Brown6f357d32014-01-15 20:40:55 -0800579 final Context context = mSystemContext;
Jeff Brown7f6c2312012-04-13 20:38:38 -0700580 VibratorService vibrator = null;
Sudheer Shanka2250d562016-11-07 15:41:02 -0800581 IStorageManager storageManager = null;
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -0700582 NetworkManagementService networkManagement = null;
Jeff Sharkey75279902011-05-24 18:39:45 -0700583 NetworkStatsService networkStats = null;
Jeff Sharkeya4620792011-05-20 15:29:23 -0700584 NetworkPolicyManagerService networkPolicy = null;
Mike Lockwood0f79b542009-08-14 14:18:49 -0400585 ConnectivityService connectivity = null;
Jeff Davidson6a4b2202014-04-16 17:29:40 -0700586 NetworkScoreService networkScore = null;
Irfan Sheriff7d024d32012-03-22 17:01:39 -0700587 NsdService serviceDiscovery= null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800588 WindowManagerService wm = null;
Mike Lockwoodb01e8bf2011-08-29 20:11:07 -0400589 SerialService serial = null;
Amith Yamasani6734b9f2010-09-13 16:24:08 -0700590 NetworkTimeUpdateService networkTimeUpdater = null;
John Grossmanc1576732012-02-01 15:23:33 -0800591 CommonTimeManagementService commonTimeMgmtService = null;
Jeff Brown6ec6f792012-04-17 16:52:41 -0700592 InputManagerService inputManager = null;
Wink Savillea12a7b32012-09-20 10:09:45 -0700593 TelephonyRegistry telephonyRegistry = null;
Erik Gilling51e95df2013-06-26 11:06:51 -0700594 ConsumerIrService consumerIr = null;
Ye Wend97e1fd2014-07-24 12:56:45 -0700595 MmsServiceBroker mmsService = null;
Polina Bondarenkof8754ac2016-02-12 20:38:23 +0100596 HardwarePropertiesManagerService hardwarePropertiesService = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800597
Dan Morrille4d9a012013-03-28 18:10:43 -0700598 boolean disableStorage = SystemProperties.getBoolean("config.disable_storage", false);
Dan Morrille4d9a012013-03-28 18:10:43 -0700599 boolean disableBluetooth = SystemProperties.getBoolean("config.disable_bluetooth", false);
Dan Morrille4d9a012013-03-28 18:10:43 -0700600 boolean disableLocation = SystemProperties.getBoolean("config.disable_location", false);
601 boolean disableSystemUI = SystemProperties.getBoolean("config.disable_systemui", false);
602 boolean disableNonCoreServices = SystemProperties.getBoolean("config.disable_noncore", false);
603 boolean disableNetwork = SystemProperties.getBoolean("config.disable_network", false);
Chenjie Luo2cab8822014-10-16 13:31:39 -0700604 boolean disableNetworkTime = SystemProperties.getBoolean("config.disable_networktime", false);
Wei Liu9086b102016-02-03 16:57:31 -0800605 boolean disableRtt = SystemProperties.getBoolean("config.disable_rtt", false);
Wei Liu6aaabae2016-03-04 14:50:16 -0800606 boolean disableMediaProjection = SystemProperties.getBoolean("config.disable_mediaproj",
607 false);
608 boolean disableSerial = SystemProperties.getBoolean("config.disable_serial", false);
609 boolean disableSearchManager = SystemProperties.getBoolean("config.disable_searchmanager",
610 false);
611 boolean disableTrustManager = SystemProperties.getBoolean("config.disable_trustmanager",
612 false);
Ivan Podogov8adaec02016-09-14 18:14:31 +0100613 boolean disableTextServices = SystemProperties.getBoolean("config.disable_textservices",
614 false);
Wei Liu6aaabae2016-03-04 14:50:16 -0800615 boolean disableSamplingProfiler = SystemProperties.getBoolean("config.disable_samplingprof",
616 false);
Wei Liu09de4192016-09-07 13:33:49 -0700617 boolean disableConsumerIr = SystemProperties.getBoolean("config.disable_consumerir", false);
Wei Liuef89d212016-09-19 15:10:33 -0700618 boolean disableVrManager = SystemProperties.getBoolean("config.disable_vrmanager", false);
Ivan Podogov8adaec02016-09-14 18:14:31 +0100619 boolean disableCameraService = SystemProperties.getBoolean("config.disable_cameraservice",
620 false);
Wei Liu09de4192016-09-07 13:33:49 -0700621
Lorenzo Colittibeacf8d2014-06-10 14:51:30 +0900622 boolean isEmulator = SystemProperties.get("ro.kernel.qemu").equals("1");
Dan Morrille4d9a012013-03-28 18:10:43 -0700623
624 try {
Dianne Hackbornbe7c50e2014-06-30 14:43:28 -0700625 Slog.i(TAG, "Reading configuration...");
Vitalii Tomkiv4887e672016-07-21 15:58:24 -0700626 traceBeginAndSlog("ReadingSystemConfig");
Dianne Hackbornbe7c50e2014-06-30 14:43:28 -0700627 SystemConfig.getInstance();
Vitalii Tomkiv4887e672016-07-21 15:58:24 -0700628 traceEnd();
Dianne Hackbornbe7c50e2014-06-30 14:43:28 -0700629
Janis Danisevskis8ff1e192016-06-03 11:31:55 -0700630 traceBeginAndSlog("StartKeyAttestationApplicationIdProviderService");
631 ServiceManager.addService("sec_key_att_app_id_provider",
632 new KeyAttestationApplicationIdProviderService(context));
Vitalii Tomkivca68aca2016-09-23 10:58:43 -0700633 traceEnd();
Janis Danisevskis8ff1e192016-06-03 11:31:55 -0700634
Yasuhiro Matsuda1ab43d52015-06-30 17:07:32 +0900635 traceBeginAndSlog("StartSchedulingPolicyService");
Dianne Hackborn35f72be2013-09-16 10:57:39 -0700636 ServiceManager.addService("scheduling_policy", new SchedulingPolicyService());
Vitalii Tomkiv4887e672016-07-21 15:58:24 -0700637 traceEnd();
Glenn Kasten07b04652012-04-23 15:00:43 -0700638
Vitalii Tomkiv4887e672016-07-21 15:58:24 -0700639 traceBeginAndSlog("StartTelecomLoaderService");
Santos Cordon5d2c1e62014-11-21 15:20:15 -0800640 mSystemServiceManager.startService(TelecomLoaderService.class);
Vitalii Tomkiv4887e672016-07-21 15:58:24 -0700641 traceEnd();
Santos Cordon5d2c1e62014-11-21 15:20:15 -0800642
Yasuhiro Matsuda1ab43d52015-06-30 17:07:32 +0900643 traceBeginAndSlog("StartTelephonyRegistry");
Jeff Brown2c43c332014-06-12 22:38:59 -0700644 telephonyRegistry = new TelephonyRegistry(context);
645 ServiceManager.addService("telephony.registry", telephonyRegistry);
Vitalii Tomkiv4887e672016-07-21 15:58:24 -0700646 traceEnd();
Svetoslavb3038ec2013-02-13 14:39:30 -0800647
Yasuhiro Matsuda1ab43d52015-06-30 17:07:32 +0900648 traceBeginAndSlog("StartEntropyMixer");
Jeff Sharkey1cab76a2016-04-12 18:23:31 -0600649 mEntropyMixer = new EntropyMixer(context);
Vitalii Tomkiv4887e672016-07-21 15:58:24 -0700650 traceEnd();
Nick Kralevich79619dd2013-03-04 13:05:32 -0800651
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800652 mContentResolver = context.getContentResolver();
653
Ivan Podogov8adaec02016-09-14 18:14:31 +0100654 if (!disableCameraService) {
655 Slog.i(TAG, "Camera Service");
Andreas Gampe0dd89592016-09-25 13:38:46 -0700656 traceBeginAndSlog("StartCameraService");
Ivan Podogov8adaec02016-09-14 18:14:31 +0100657 mSystemServiceManager.startService(CameraService.class);
Andreas Gampe0dd89592016-09-25 13:38:46 -0700658 traceEnd();
Ivan Podogov8adaec02016-09-14 18:14:31 +0100659 }
Ruben Brunk9d21ee52015-03-20 22:18:55 -0700660
Fred Quintanae91ebe22009-09-29 20:44:30 -0700661 // The AccountManager must come before the ContentService
Yasuhiro Matsuda1ab43d52015-06-30 17:07:32 +0900662 traceBeginAndSlog("StartAccountManagerService");
Jeff Sharkey1cab76a2016-04-12 18:23:31 -0600663 mSystemServiceManager.startService(ACCOUNT_SERVICE_CLASS);
Vitalii Tomkiv4887e672016-07-21 15:58:24 -0700664 traceEnd();
Fred Quintana60307342009-03-24 22:48:12 -0700665
Yasuhiro Matsuda1ab43d52015-06-30 17:07:32 +0900666 traceBeginAndSlog("StartContentService");
Jeff Sharkeya3ebfec2016-04-04 08:58:04 -0600667 mSystemServiceManager.startService(CONTENT_SERVICE_CLASS);
Vitalii Tomkiv4887e672016-07-21 15:58:24 -0700668 traceEnd();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800669
Yasuhiro Matsuda1ab43d52015-06-30 17:07:32 +0900670 traceBeginAndSlog("InstallSystemProviders");
Jeff Brown4ccb8232014-01-16 22:16:42 -0800671 mActivityManagerService.installSystemProviders();
Vitalii Tomkiv4887e672016-07-21 15:58:24 -0700672 traceEnd();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800673
Yasuhiro Matsuda1ab43d52015-06-30 17:07:32 +0900674 traceBeginAndSlog("StartVibratorService");
Jeff Brown7f6c2312012-04-13 20:38:38 -0700675 vibrator = new VibratorService(context);
676 ServiceManager.addService("vibrator", vibrator);
Vitalii Tomkiv4887e672016-07-21 15:58:24 -0700677 traceEnd();
The Android Open Source Project10592532009-03-18 17:39:46 -0700678
Wei Liu09de4192016-09-07 13:33:49 -0700679 if (!disableConsumerIr) {
680 traceBeginAndSlog("StartConsumerIrService");
681 consumerIr = new ConsumerIrService(context);
682 ServiceManager.addService(Context.CONSUMER_IR_SERVICE, consumerIr);
Colin Cross7af8c2a2016-09-12 21:12:49 -0700683 traceEnd();
Wei Liu09de4192016-09-07 13:33:49 -0700684 }
Erik Gilling51e95df2013-06-26 11:06:51 -0700685
Jeff Sharkey1cab76a2016-04-12 18:23:31 -0600686 traceBeginAndSlog("StartAlarmManagerService");
Jeff Brown6f357d32014-01-15 20:40:55 -0800687 mSystemServiceManager.startService(AlarmManagerService.class);
Vitalii Tomkiv4887e672016-07-21 15:58:24 -0700688 traceEnd();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800689
Yasuhiro Matsuda1ab43d52015-06-30 17:07:32 +0900690 traceBeginAndSlog("InitWatchdog");
Jeff Brown6f357d32014-01-15 20:40:55 -0800691 final Watchdog watchdog = Watchdog.getInstance();
Jeff Brown4ccb8232014-01-16 22:16:42 -0800692 watchdog.init(context, mActivityManagerService);
Vitalii Tomkiv4887e672016-07-21 15:58:24 -0700693 traceEnd();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800694
Yasuhiro Matsuda1ab43d52015-06-30 17:07:32 +0900695 traceBeginAndSlog("StartInputManagerService");
Jeff Brown4ccb8232014-01-16 22:16:42 -0800696 inputManager = new InputManagerService(context);
Vitalii Tomkiv4887e672016-07-21 15:58:24 -0700697 traceEnd();
Jeff Browna9d131c2012-09-20 16:48:17 -0700698
Yasuhiro Matsuda1ab43d52015-06-30 17:07:32 +0900699 traceBeginAndSlog("StartWindowManagerService");
Jeff Brown4ccb8232014-01-16 22:16:42 -0800700 wm = WindowManagerService.main(context, inputManager,
Jeff Brown6f357d32014-01-15 20:40:55 -0800701 mFactoryTestMode != FactoryTest.FACTORY_TEST_LOW_LEVEL,
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700702 !mFirstBoot, mOnlyCore, new PhoneWindowManager());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800703 ServiceManager.addService(Context.WINDOW_SERVICE, wm);
Jeff Brown6ec6f792012-04-17 16:52:41 -0700704 ServiceManager.addService(Context.INPUT_SERVICE, inputManager);
Vitalii Tomkiv4887e672016-07-21 15:58:24 -0700705 traceEnd();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800706
Wei Liuef89d212016-09-19 15:10:33 -0700707 if (!disableVrManager) {
708 traceBeginAndSlog("StartVrManagerService");
709 mSystemServiceManager.startService(VrManagerService.class);
Wei Liu03d0a362016-09-20 10:21:27 -0700710 traceEnd();
Wei Liuef89d212016-09-19 15:10:33 -0700711 }
Ruben Brunkdd18a0b2015-12-04 16:16:31 -0800712
Jeff Brown4ccb8232014-01-16 22:16:42 -0800713 mActivityManagerService.setWindowManager(wm);
Jeff Browna9d131c2012-09-20 16:48:17 -0700714
715 inputManager.setWindowManagerCallbacks(wm.getInputMonitor());
Vitalii Tomkiv4887e672016-07-21 15:58:24 -0700716 traceBeginAndSlog("StartInputManager");
Jeff Browna9d131c2012-09-20 16:48:17 -0700717 inputManager.start();
Vitalii Tomkiv4887e672016-07-21 15:58:24 -0700718 traceEnd();
Jeff Browna9d131c2012-09-20 16:48:17 -0700719
Jeff Brown4ccb8232014-01-16 22:16:42 -0800720 // TODO: Use service dependencies instead.
Vitalii Tomkiv4887e672016-07-21 15:58:24 -0700721 traceBeginAndSlog("DisplayManagerWindowManagerAndInputReady");
Jeff Brown4ccb8232014-01-16 22:16:42 -0800722 mDisplayManagerService.windowManagerAndInputReady();
Vitalii Tomkiv4887e672016-07-21 15:58:24 -0700723 traceEnd();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800724
725 // Skip Bluetooth if we have an emulator kernel
726 // TODO: Use a more reliable check to see if this product should
727 // support Bluetooth - see bug 988521
Lorenzo Colittibeacf8d2014-06-10 14:51:30 +0900728 if (isEmulator) {
Elliott Hughes72716132015-07-06 22:10:36 -0700729 Slog.i(TAG, "No Bluetooth Service (emulator)");
Jeff Brown6f357d32014-01-15 20:40:55 -0800730 } else if (mFactoryTestMode == FactoryTest.FACTORY_TEST_LOW_LEVEL) {
David 'Digit' Turnere2a5e862011-01-17 00:32:33 +0100731 Slog.i(TAG, "No Bluetooth Service (factory test)");
Matthew Xie1dd01eb32013-04-26 12:37:54 -0700732 } else if (!context.getPackageManager().hasSystemFeature
733 (PackageManager.FEATURE_BLUETOOTH)) {
734 Slog.i(TAG, "No Bluetooth Service (Bluetooth Hardware Not Present)");
Dan Morrille4d9a012013-03-28 18:10:43 -0700735 } else if (disableBluetooth) {
736 Slog.i(TAG, "Bluetooth Service disabled by config");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800737 } else {
Vitalii Tomkiv4887e672016-07-21 15:58:24 -0700738 traceBeginAndSlog("StartBluetoothService");
Miao Chou658bf2f2015-06-26 17:14:35 -0700739 mSystemServiceManager.startService(BluetoothService.class);
Vitalii Tomkiv4887e672016-07-21 15:58:24 -0700740 traceEnd();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800741 }
Pavel Zhamaitsiak02b3e6b2016-02-03 10:39:44 -0800742
743 traceBeginAndSlog("ConnectivityMetricsLoggerService");
744 mSystemServiceManager.startService(MetricsLoggerService.class);
Vitalii Tomkiv4887e672016-07-21 15:58:24 -0700745 traceEnd();
Philip Cuadra7bd0fdd2016-04-28 15:26:49 -0700746
Hugo Benichieab511b2016-09-09 09:23:47 +0900747 traceBeginAndSlog("IpConnectivityMetrics");
748 mSystemServiceManager.startService(IpConnectivityMetrics.class);
Keun-young Parkd340d8a2016-10-18 17:52:30 -0700749 traceEnd();
Hugo Benichieab511b2016-09-09 09:23:47 +0900750
Philip Cuadra7bd0fdd2016-04-28 15:26:49 -0700751 traceBeginAndSlog("PinnerService");
752 mSystemServiceManager.startService(PinnerService.class);
Vitalii Tomkiv4887e672016-07-21 15:58:24 -0700753 traceEnd();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800754 } catch (RuntimeException e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700755 Slog.e("System", "******************************************");
756 Slog.e("System", "************ Failure starting core service", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800757 }
758
Joe Onorato089de882010-04-12 08:18:45 -0700759 StatusBarManagerService statusBar = null;
Adam Lesinskief2ea1f2013-12-05 16:48:06 -0800760 INotificationManager notification = null;
Mike Lockwood46db5042010-02-22 16:36:44 -0500761 LocationManagerService location = null;
Bai Taoa58a8752010-07-13 15:32:16 +0800762 CountryDetectorService countryDetector = null;
Jim Miller4f93c582016-01-27 19:05:43 -0800763 ILockSettings lockSettings = null;
Jeff Brown69b07162013-11-07 00:30:16 -0800764 MediaRouterService mediaRouter = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800765
Dianne Hackborn661cd522011-08-22 00:26:20 -0700766 // Bring up services needed for UI.
Jeff Brown6f357d32014-01-15 20:40:55 -0800767 if (mFactoryTestMode != FactoryTest.FACTORY_TEST_LOW_LEVEL) {
Vitalii Tomkiv4887e672016-07-21 15:58:24 -0700768 traceBeginAndSlog("StartInputMethodManagerLifecycle");
Fyodor Kupolov1e33dc82016-01-21 12:02:58 -0800769 mSystemServiceManager.startService(InputMethodManagerService.Lifecycle.class);
Vitalii Tomkiv4887e672016-07-21 15:58:24 -0700770 traceEnd();
Dianne Hackborn661cd522011-08-22 00:26:20 -0700771
Yasuhiro Matsudaebf94652015-09-02 22:48:13 +0900772 traceBeginAndSlog("StartAccessibilityManagerService");
dcashman4e3f5d32014-11-25 15:33:26 -0800773 try {
dcashman4e3f5d32014-11-25 15:33:26 -0800774 ServiceManager.addService(Context.ACCESSIBILITY_SERVICE,
775 new AccessibilityManagerService(context));
776 } catch (Throwable e) {
777 reportWtf("starting Accessibility Manager", e);
Dianne Hackborn661cd522011-08-22 00:26:20 -0700778 }
Vitalii Tomkiv4887e672016-07-21 15:58:24 -0700779 traceEnd();
Dianne Hackborn661cd522011-08-22 00:26:20 -0700780 }
781
Vitalii Tomkiv4887e672016-07-21 15:58:24 -0700782 traceBeginAndSlog("MakeDisplayReady");
Dianne Hackborn661cd522011-08-22 00:26:20 -0700783 try {
784 wm.displayReady();
785 } catch (Throwable e) {
786 reportWtf("making display ready", e);
787 }
Vitalii Tomkiv4887e672016-07-21 15:58:24 -0700788 traceEnd();
Dianne Hackborn8795b602011-08-25 13:30:53 -0700789
Jeff Brown6f357d32014-01-15 20:40:55 -0800790 if (mFactoryTestMode != FactoryTest.FACTORY_TEST_LOW_LEVEL) {
Dan Morrille4d9a012013-03-28 18:10:43 -0700791 if (!disableStorage &&
792 !"0".equals(SystemProperties.get("system_init.startmountservice"))) {
Sudheer Shanka2250d562016-11-07 15:41:02 -0800793 traceBeginAndSlog("StartStorageManagerService");
Kenny Root51a573c2012-05-17 13:30:28 -0700794 try {
795 /*
Sudheer Shanka2250d562016-11-07 15:41:02 -0800796 * NotificationManagerService is dependant on StorageManagerService,
797 * (for media / usb notifications) so we must start StorageManagerService first.
Kenny Root51a573c2012-05-17 13:30:28 -0700798 */
Sudheer Shanka2250d562016-11-07 15:41:02 -0800799 mSystemServiceManager.startService(STORAGE_MANAGER_SERVICE_CLASS);
800 storageManager = IStorageManager.Stub.asInterface(
Jeff Sharkey56e62932015-03-21 20:41:00 -0700801 ServiceManager.getService("mount"));
Kenny Root51a573c2012-05-17 13:30:28 -0700802 } catch (Throwable e) {
Sudheer Shanka2250d562016-11-07 15:41:02 -0800803 reportWtf("starting StorageManager Service", e);
Kenny Root51a573c2012-05-17 13:30:28 -0700804 }
Vitalii Tomkiv4887e672016-07-21 15:58:24 -0700805 traceEnd();
Kenny Root51a573c2012-05-17 13:30:28 -0700806 }
padarshrada45412014-11-05 16:54:50 +0530807 }
Kenny Root51a573c2012-05-17 13:30:28 -0700808
Adam Lesinski05199e82015-03-19 14:37:11 -0700809 // We start this here so that we update our configuration to set watch or television
810 // as appropriate.
Vitalii Tomkiv4887e672016-07-21 15:58:24 -0700811 traceBeginAndSlog("StartUiModeManager");
Adam Lesinski05199e82015-03-19 14:37:11 -0700812 mSystemServiceManager.startService(UiModeManagerService.class);
Vitalii Tomkiv4887e672016-07-21 15:58:24 -0700813 traceEnd();
Adam Lesinski05199e82015-03-19 14:37:11 -0700814
David Brazdil89c80bb2016-06-02 15:31:30 +0100815 if (!mOnlyCore) {
Vitalii Tomkiv4887e672016-07-21 15:58:24 -0700816 traceBeginAndSlog("UpdatePackagesIfNeeded");
David Brazdil89c80bb2016-06-02 15:31:30 +0100817 try {
818 mPackageManagerService.updatePackagesIfNeeded();
819 } catch (Throwable e) {
820 reportWtf("update packages", e);
821 }
Vitalii Tomkiv4887e672016-07-21 15:58:24 -0700822 traceEnd();
David Brazdilf5c444f2016-03-30 11:45:52 +0100823 }
David Brazdilf5c444f2016-03-30 11:45:52 +0100824
Vitalii Tomkiv4887e672016-07-21 15:58:24 -0700825 traceBeginAndSlog("PerformFstrimIfNeeded");
padarshrada45412014-11-05 16:54:50 +0530826 try {
Nicolas Geoffray27c07372015-11-05 16:54:09 +0000827 mPackageManagerService.performFstrimIfNeeded();
padarshrada45412014-11-05 16:54:50 +0530828 } catch (Throwable e) {
Nicolas Geoffray27c07372015-11-05 16:54:09 +0000829 reportWtf("performing fstrim", e);
padarshrada45412014-11-05 16:54:50 +0530830 }
Vitalii Tomkiv4887e672016-07-21 15:58:24 -0700831 traceEnd();
padarshrada45412014-11-05 16:54:50 +0530832
padarshrada45412014-11-05 16:54:50 +0530833 if (mFactoryTestMode != FactoryTest.FACTORY_TEST_LOW_LEVEL) {
Dan Morrille4d9a012013-03-28 18:10:43 -0700834 if (!disableNonCoreServices) {
Yasuhiro Matsuda1ab43d52015-06-30 17:07:32 +0900835 traceBeginAndSlog("StartLockSettingsService");
Dan Morrille4d9a012013-03-28 18:10:43 -0700836 try {
Jim Miller4f93c582016-01-27 19:05:43 -0800837 mSystemServiceManager.startService(LOCK_SETTINGS_SERVICE_CLASS);
838 lockSettings = ILockSettings.Stub.asInterface(
839 ServiceManager.getService("lock_settings"));
Dan Morrille4d9a012013-03-28 18:10:43 -0700840 } catch (Throwable e) {
841 reportWtf("starting LockSettingsService service", e);
842 }
Vitalii Tomkiv4887e672016-07-21 15:58:24 -0700843 traceEnd();
Dan Morrille4d9a012013-03-28 18:10:43 -0700844
Andres Morales68d4acd2014-07-01 19:40:41 -0700845 if (!SystemProperties.get(PERSISTENT_DATA_BLOCK_PROP).equals("")) {
Vitalii Tomkiv4887e672016-07-21 15:58:24 -0700846 traceBeginAndSlog("StartPersistentDataBlock");
Andres Morales68d4acd2014-07-01 19:40:41 -0700847 mSystemServiceManager.startService(PersistentDataBlockService.class);
Vitalii Tomkiv4887e672016-07-21 15:58:24 -0700848 traceEnd();
Andres Morales68d4acd2014-07-01 19:40:41 -0700849 }
850
Vitalii Tomkiv4887e672016-07-21 15:58:24 -0700851 traceBeginAndSlog("StartDeviceIdleController");
Dianne Hackborn0b4daca2015-04-27 09:47:32 -0700852 mSystemServiceManager.startService(DeviceIdleController.class);
Vitalii Tomkiv4887e672016-07-21 15:58:24 -0700853 traceEnd();
Dianne Hackborn0b4daca2015-04-27 09:47:32 -0700854
Jeff Brown2c43c332014-06-12 22:38:59 -0700855 // Always start the Device Policy Manager, so that the API is compatible with
856 // API8.
Vitalii Tomkiv4887e672016-07-21 15:58:24 -0700857 traceBeginAndSlog("StartDevicePolicyManager");
Jeff Brown2c43c332014-06-12 22:38:59 -0700858 mSystemServiceManager.startService(DevicePolicyManagerService.Lifecycle.class);
Vitalii Tomkiv4887e672016-07-21 15:58:24 -0700859 traceEnd();
Amith Yamasani52c489c2012-03-28 11:42:42 -0700860 }
861
Dan Morrille4d9a012013-03-28 18:10:43 -0700862 if (!disableSystemUI) {
Yasuhiro Matsuda1ab43d52015-06-30 17:07:32 +0900863 traceBeginAndSlog("StartStatusBarManagerService");
Dan Morrille4d9a012013-03-28 18:10:43 -0700864 try {
Dan Morrille4d9a012013-03-28 18:10:43 -0700865 statusBar = new StatusBarManagerService(context, wm);
866 ServiceManager.addService(Context.STATUS_BAR_SERVICE, statusBar);
867 } catch (Throwable e) {
868 reportWtf("starting StatusBarManagerService", e);
869 }
Vitalii Tomkiv4887e672016-07-21 15:58:24 -0700870 traceEnd();
Dianne Hackbornd6847842010-01-12 18:14:19 -0800871 }
872
Dan Morrille4d9a012013-03-28 18:10:43 -0700873 if (!disableNonCoreServices) {
Yasuhiro Matsuda1ab43d52015-06-30 17:07:32 +0900874 traceBeginAndSlog("StartClipboardService");
Sudheer Shankaad70bc62016-09-29 12:58:04 -0700875 mSystemServiceManager.startService(ClipboardService.class);
Vitalii Tomkiv4887e672016-07-21 15:58:24 -0700876 traceEnd();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800877 }
878
Dan Morrille4d9a012013-03-28 18:10:43 -0700879 if (!disableNetwork) {
Yasuhiro Matsuda1ab43d52015-06-30 17:07:32 +0900880 traceBeginAndSlog("StartNetworkManagementService");
Dan Morrille4d9a012013-03-28 18:10:43 -0700881 try {
Dan Morrille4d9a012013-03-28 18:10:43 -0700882 networkManagement = NetworkManagementService.create(context);
883 ServiceManager.addService(Context.NETWORKMANAGEMENT_SERVICE, networkManagement);
884 } catch (Throwable e) {
885 reportWtf("starting NetworkManagement Service", e);
886 }
Vitalii Tomkiv4887e672016-07-21 15:58:24 -0700887 traceEnd();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800888 }
889
Wei Liu6aaabae2016-03-04 14:50:16 -0800890 if (!disableNonCoreServices && !disableTextServices) {
Vitalii Tomkiv4887e672016-07-21 15:58:24 -0700891 traceBeginAndSlog("StartTextServicesManager");
Yohei Yukawaa6a152e2016-03-07 13:41:15 -0800892 mSystemServiceManager.startService(TextServicesManagerService.Lifecycle.class);
Vitalii Tomkiv4887e672016-07-21 15:58:24 -0700893 traceEnd();
San Mehatd1df8ac2010-01-26 06:17:26 -0800894 }
895
Dan Morrille4d9a012013-03-28 18:10:43 -0700896 if (!disableNetwork) {
Yasuhiro Matsuda1ab43d52015-06-30 17:07:32 +0900897 traceBeginAndSlog("StartNetworkScoreService");
Dan Morrille4d9a012013-03-28 18:10:43 -0700898 try {
vandwalle7c3606c2014-03-31 19:12:07 -0700899 networkScore = new NetworkScoreService(context);
900 ServiceManager.addService(Context.NETWORK_SCORE_SERVICE, networkScore);
901 } catch (Throwable e) {
902 reportWtf("starting Network Score Service", e);
903 }
Vitalii Tomkiv4887e672016-07-21 15:58:24 -0700904 traceEnd();
vandwalle7c3606c2014-03-31 19:12:07 -0700905
Yasuhiro Matsuda1ab43d52015-06-30 17:07:32 +0900906 traceBeginAndSlog("StartNetworkStatsService");
vandwalle7c3606c2014-03-31 19:12:07 -0700907 try {
Antonio Cansadocd42acd2016-02-17 13:03:38 -0800908 networkStats = NetworkStatsService.create(context, networkManagement);
Dan Morrille4d9a012013-03-28 18:10:43 -0700909 ServiceManager.addService(Context.NETWORK_STATS_SERVICE, networkStats);
910 } catch (Throwable e) {
911 reportWtf("starting NetworkStats Service", e);
912 }
Vitalii Tomkiv4887e672016-07-21 15:58:24 -0700913 traceEnd();
Dan Morrille4d9a012013-03-28 18:10:43 -0700914
Yasuhiro Matsuda1ab43d52015-06-30 17:07:32 +0900915 traceBeginAndSlog("StartNetworkPolicyManagerService");
Dan Morrille4d9a012013-03-28 18:10:43 -0700916 try {
Felipe Leme88f40ad2016-08-10 13:00:32 -0700917 networkPolicy = new NetworkPolicyManagerService(context,
918 mActivityManagerService, networkStats, networkManagement);
Dan Morrille4d9a012013-03-28 18:10:43 -0700919 ServiceManager.addService(Context.NETWORK_POLICY_SERVICE, networkPolicy);
920 } catch (Throwable e) {
921 reportWtf("starting NetworkPolicy Service", e);
922 }
Vitalii Tomkiv4887e672016-07-21 15:58:24 -0700923 traceEnd();
Dan Morrille4d9a012013-03-28 18:10:43 -0700924
Etan Cohen04133272016-10-26 11:22:06 -0700925 if (context.getPackageManager().hasSystemFeature(
926 PackageManager.FEATURE_WIFI_AWARE)) {
927 traceBeginAndSlog("StartWifiAware");
928 mSystemServiceManager.startService(WIFI_AWARE_SERVICE_CLASS);
Vitalii Tomkiv4887e672016-07-21 15:58:24 -0700929 traceEnd();
Etan Cohen20d329b2015-09-29 13:49:02 -0700930 } else {
Etan Cohen04133272016-10-26 11:22:06 -0700931 Slog.i(TAG, "No Wi-Fi Aware Service (Aware support Not Present)");
Etan Cohen20d329b2015-09-29 13:49:02 -0700932 }
Wei Liu4e62ac52016-05-23 15:12:49 -0700933
934 if (context.getPackageManager().hasSystemFeature(
935 PackageManager.FEATURE_WIFI_DIRECT)) {
Vitalii Tomkiv4887e672016-07-21 15:58:24 -0700936 traceBeginAndSlog("StartWifiP2P");
Wei Liu4e62ac52016-05-23 15:12:49 -0700937 mSystemServiceManager.startService(WIFI_P2P_SERVICE_CLASS);
Vitalii Tomkiv4887e672016-07-21 15:58:24 -0700938 traceEnd();
Wei Liu4e62ac52016-05-23 15:12:49 -0700939 }
Vitalii Tomkiv4887e672016-07-21 15:58:24 -0700940 traceBeginAndSlog("StartWifi");
Jeff Brown2c43c332014-06-12 22:38:59 -0700941 mSystemServiceManager.startService(WIFI_SERVICE_CLASS);
Vitalii Tomkiv4887e672016-07-21 15:58:24 -0700942 traceEnd();
943 traceBeginAndSlog("StartWifiScanning");
Jeff Brown2c43c332014-06-12 22:38:59 -0700944 mSystemServiceManager.startService(
Mitchell Willsd0989c92016-02-20 00:09:12 -0800945 "com.android.server.wifi.scanner.WifiScanningService");
Vitalii Tomkiv4887e672016-07-21 15:58:24 -0700946 traceEnd();
Vinit Deshapnde011e1b32014-05-07 21:09:11 -0700947
Wei Liu9086b102016-02-03 16:57:31 -0800948 if (!disableRtt) {
Vitalii Tomkiv4887e672016-07-21 15:58:24 -0700949 traceBeginAndSlog("StartWifiRtt");
Wei Liu9086b102016-02-03 16:57:31 -0800950 mSystemServiceManager.startService("com.android.server.wifi.RttService");
Vitalii Tomkiv4887e672016-07-21 15:58:24 -0700951 traceEnd();
Wei Liu9086b102016-02-03 16:57:31 -0800952 }
Vinit Deshpandec4272f32014-07-25 17:46:14 -0700953
Lorenzo Colitti0ea7b1b2014-11-25 21:52:12 +0900954 if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_ETHERNET) ||
955 mPackageManager.hasSystemFeature(PackageManager.FEATURE_USB_HOST)) {
Vitalii Tomkiv4887e672016-07-21 15:58:24 -0700956 traceBeginAndSlog("StartEthernet");
Jeff Brown2c43c332014-06-12 22:38:59 -0700957 mSystemServiceManager.startService(ETHERNET_SERVICE_CLASS);
Vitalii Tomkiv4887e672016-07-21 15:58:24 -0700958 traceEnd();
Lorenzo Colittif9ff2c92014-05-21 16:32:11 -0700959 }
960
Yasuhiro Matsuda1ab43d52015-06-30 17:07:32 +0900961 traceBeginAndSlog("StartConnectivityService");
Lorenzo Colittif9ff2c92014-05-21 16:32:11 -0700962 try {
Dan Morrille4d9a012013-03-28 18:10:43 -0700963 connectivity = new ConnectivityService(
964 context, networkManagement, networkStats, networkPolicy);
965 ServiceManager.addService(Context.CONNECTIVITY_SERVICE, connectivity);
966 networkStats.bindConnectivityManager(connectivity);
967 networkPolicy.bindConnectivityManager(connectivity);
Dan Morrille4d9a012013-03-28 18:10:43 -0700968 } catch (Throwable e) {
969 reportWtf("starting Connectivity Service", e);
970 }
Vitalii Tomkiv4887e672016-07-21 15:58:24 -0700971 traceEnd();
Dan Morrille4d9a012013-03-28 18:10:43 -0700972
Yasuhiro Matsuda1ab43d52015-06-30 17:07:32 +0900973 traceBeginAndSlog("StartNsdService");
Dan Morrille4d9a012013-03-28 18:10:43 -0700974 try {
Dan Morrille4d9a012013-03-28 18:10:43 -0700975 serviceDiscovery = NsdService.create(context);
976 ServiceManager.addService(
977 Context.NSD_SERVICE, serviceDiscovery);
978 } catch (Throwable e) {
979 reportWtf("starting Service Discovery Service", e);
980 }
Vitalii Tomkiv4887e672016-07-21 15:58:24 -0700981 traceEnd();
satok988323c2011-06-22 16:38:13 +0900982 }
983
Dan Morrille4d9a012013-03-28 18:10:43 -0700984 if (!disableNonCoreServices) {
Yasuhiro Matsuda1ab43d52015-06-30 17:07:32 +0900985 traceBeginAndSlog("StartUpdateLockService");
Dan Morrille4d9a012013-03-28 18:10:43 -0700986 try {
Dan Morrille4d9a012013-03-28 18:10:43 -0700987 ServiceManager.addService(Context.UPDATE_LOCK_SERVICE,
988 new UpdateLockService(context));
989 } catch (Throwable e) {
990 reportWtf("starting UpdateLockService", e);
991 }
Vitalii Tomkiv4887e672016-07-21 15:58:24 -0700992 traceEnd();
Christopher Tate8662cab52012-02-23 14:59:36 -0800993 }
994
Tao Baoe8a403d2015-12-31 07:44:55 -0800995 if (!disableNonCoreServices) {
Vitalii Tomkiv4887e672016-07-21 15:58:24 -0700996 traceBeginAndSlog("StartRecoverSystemService");
Tao Baoe8a403d2015-12-31 07:44:55 -0800997 mSystemServiceManager.startService(RecoverySystemService.class);
Vitalii Tomkiv4887e672016-07-21 15:58:24 -0700998 traceEnd();
Tao Baoe8a403d2015-12-31 07:44:55 -0800999 }
1000
Kenny Root51a573c2012-05-17 13:30:28 -07001001 /*
Sudheer Shanka2250d562016-11-07 15:41:02 -08001002 * StorageManagerService has a few dependencies: Notification Manager and
1003 * AppWidget Provider. Make sure StorageManagerService is completely started
Kenny Root51a573c2012-05-17 13:30:28 -07001004 * first before continuing.
1005 */
Sudheer Shanka2250d562016-11-07 15:41:02 -08001006 if (storageManager != null && !mOnlyCore) {
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001007 traceBeginAndSlog("WaitForAsecScan");
Jeff Sharkey56e62932015-03-21 20:41:00 -07001008 try {
Sudheer Shanka2250d562016-11-07 15:41:02 -08001009 storageManager.waitForAsecScan();
Jeff Sharkey56e62932015-03-21 20:41:00 -07001010 } catch (RemoteException ignored) {
1011 }
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001012 traceEnd();
San Mehat1bf3f8b2010-02-03 14:43:09 -08001013 }
1014
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001015 traceBeginAndSlog("StartNotificationManager");
Jeff Brown6f357d32014-01-15 20:40:55 -08001016 mSystemServiceManager.startService(NotificationManagerService.class);
Adam Lesinskief2ea1f2013-12-05 16:48:06 -08001017 notification = INotificationManager.Stub.asInterface(
1018 ServiceManager.getService(Context.NOTIFICATION_SERVICE));
1019 networkPolicy.bindNotificationManager(notification);
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001020 traceEnd();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001021
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001022 traceBeginAndSlog("StartDeviceMonitor");
Jeff Brown6f357d32014-01-15 20:40:55 -08001023 mSystemServiceManager.startService(DeviceStorageMonitorService.class);
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001024 traceEnd();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001025
Dan Morrille4d9a012013-03-28 18:10:43 -07001026 if (!disableLocation) {
Yasuhiro Matsuda1ab43d52015-06-30 17:07:32 +09001027 traceBeginAndSlog("StartLocationManagerService");
Dan Morrille4d9a012013-03-28 18:10:43 -07001028 try {
Dan Morrille4d9a012013-03-28 18:10:43 -07001029 location = new LocationManagerService(context);
1030 ServiceManager.addService(Context.LOCATION_SERVICE, location);
1031 } catch (Throwable e) {
1032 reportWtf("starting Location Manager", e);
1033 }
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001034 traceEnd();
Dan Morrille4d9a012013-03-28 18:10:43 -07001035
Yasuhiro Matsuda1ab43d52015-06-30 17:07:32 +09001036 traceBeginAndSlog("StartCountryDetectorService");
Dan Morrille4d9a012013-03-28 18:10:43 -07001037 try {
Dan Morrille4d9a012013-03-28 18:10:43 -07001038 countryDetector = new CountryDetectorService(context);
1039 ServiceManager.addService(Context.COUNTRY_DETECTOR, countryDetector);
1040 } catch (Throwable e) {
1041 reportWtf("starting Country Detector", e);
1042 }
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001043 traceEnd();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001044 }
1045
Wei Liu6aaabae2016-03-04 14:50:16 -08001046 if (!disableNonCoreServices && !disableSearchManager) {
Yasuhiro Matsuda1ab43d52015-06-30 17:07:32 +09001047 traceBeginAndSlog("StartSearchManagerService");
Dan Morrille4d9a012013-03-28 18:10:43 -07001048 try {
Jeff Sharkey4175be22016-01-09 14:57:45 -07001049 mSystemServiceManager.startService(SEARCH_MANAGER_SERVICE_CLASS);
Dan Morrille4d9a012013-03-28 18:10:43 -07001050 } catch (Throwable e) {
1051 reportWtf("starting Search Service", e);
1052 }
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001053 traceEnd();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001054 }
1055
Dan Morrille4d9a012013-03-28 18:10:43 -07001056 if (!disableNonCoreServices && context.getResources().getBoolean(
1057 R.bool.config_enableWallpaperService)) {
Yasuhiro Matsuda1ab43d52015-06-30 17:07:32 +09001058 traceBeginAndSlog("StartWallpaperManagerService");
Jeff Sharkey1cab76a2016-04-12 18:23:31 -06001059 mSystemServiceManager.startService(WALLPAPER_SERVICE_CLASS);
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001060 traceEnd();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001061 }
1062
Yasuhiro Matsudaebf94652015-09-02 22:48:13 +09001063 traceBeginAndSlog("StartAudioService");
Makoto Onukie1aef852015-10-15 17:28:35 -07001064 mSystemServiceManager.startService(AudioService.Lifecycle.class);
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001065 traceEnd();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001066
Dan Morrille4d9a012013-03-28 18:10:43 -07001067 if (!disableNonCoreServices) {
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001068 traceBeginAndSlog("StartDockObserver");
Jeff Brown010e5612014-05-29 17:48:33 -07001069 mSystemServiceManager.startService(DockObserver.class);
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001070 traceEnd();
Bryce Leebc58f592015-09-25 16:43:01 -07001071
Wei Liu48d3b632016-03-29 15:26:48 -07001072 if (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_WATCH)) {
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001073 traceBeginAndSlog("StartThermalObserver");
Wei Liud699cf82016-03-25 16:32:10 -07001074 mSystemServiceManager.startService(THERMAL_OBSERVER_CLASS);
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001075 traceEnd();
Bryce Leebc58f592015-09-25 16:43:01 -07001076 }
Dan Murphyc9f4eaf2009-08-12 15:15:43 -05001077 }
1078
Yasuhiro Matsudaebf94652015-09-02 22:48:13 +09001079 traceBeginAndSlog("StartWiredAccessoryManager");
John Spurlockb4f01b92015-03-24 12:40:15 -04001080 try {
John Spurlockb4f01b92015-03-24 12:40:15 -04001081 // Listen for wired headset changes
1082 inputManager.setWiredAccessoryCallbacks(
1083 new WiredAccessoryManager(context, inputManager));
1084 } catch (Throwable e) {
1085 reportWtf("starting WiredAccessoryManager", e);
Praveen Bharathi21e941b2010-10-06 15:23:14 -05001086 }
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001087 traceEnd();
Praveen Bharathi21e941b2010-10-06 15:23:14 -05001088
Dan Morrille4d9a012013-03-28 18:10:43 -07001089 if (!disableNonCoreServices) {
Mike Lockwood5781cd52015-03-27 13:23:41 -07001090 if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_MIDI)) {
1091 // Start MIDI Manager service
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001092 traceBeginAndSlog("StartMidiManager");
Mike Lockwood5781cd52015-03-27 13:23:41 -07001093 mSystemServiceManager.startService(MIDI_SERVICE_CLASS);
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001094 traceEnd();
Mike Lockwood5781cd52015-03-27 13:23:41 -07001095 }
1096
Jeff Brown2c43c332014-06-12 22:38:59 -07001097 if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_USB_HOST)
1098 || mPackageManager.hasSystemFeature(
1099 PackageManager.FEATURE_USB_ACCESSORY)) {
1100 // Manage USB host and device support
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001101 traceBeginAndSlog("StartUsbService");
Jeff Brown2c43c332014-06-12 22:38:59 -07001102 mSystemServiceManager.startService(USB_SERVICE_CLASS);
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001103 traceEnd();
Dan Morrille4d9a012013-03-28 18:10:43 -07001104 }
Mike Lockwood57c798a2010-06-23 17:36:36 -04001105
Wei Liu6aaabae2016-03-04 14:50:16 -08001106 if (!disableSerial) {
1107 traceBeginAndSlog("StartSerialService");
1108 try {
1109 // Serial port support
1110 serial = new SerialService(context);
1111 ServiceManager.addService(Context.SERIAL_SERVICE, serial);
1112 } catch (Throwable e) {
1113 Slog.e(TAG, "Failure starting SerialService", e);
1114 }
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001115 traceEnd();
Dan Morrille4d9a012013-03-28 18:10:43 -07001116 }
Polina Bondarenkof8754ac2016-02-12 20:38:23 +01001117
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001118 traceBeginAndSlog("StartHardwarePropertiesManagerService");
Polina Bondarenkof8754ac2016-02-12 20:38:23 +01001119 try {
1120 hardwarePropertiesService = new HardwarePropertiesManagerService(context);
1121 ServiceManager.addService(Context.HARDWARE_PROPERTIES_SERVICE,
1122 hardwarePropertiesService);
1123 } catch (Throwable e) {
1124 Slog.e(TAG, "Failure starting HardwarePropertiesManagerService", e);
1125 }
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001126 traceEnd();
Mike Lockwoodb01e8bf2011-08-29 20:11:07 -04001127 }
1128
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001129 traceBeginAndSlog("StartTwilightService");
Jeff Brown6f357d32014-01-15 20:40:55 -08001130 mSystemServiceManager.startService(TwilightService.class);
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001131 traceEnd();
Jeff Brown2416e092012-08-21 22:12:20 -07001132
Justin Klaassen911e8892016-06-21 18:24:24 -07001133 if (NightDisplayController.isAvailable(context)) {
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001134 traceBeginAndSlog("StartNightDisplay");
Justin Klaassen911e8892016-06-21 18:24:24 -07001135 mSystemServiceManager.startService(NightDisplayService.class);
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001136 traceEnd();
Justin Klaassen911e8892016-06-21 18:24:24 -07001137 }
1138
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001139 traceBeginAndSlog("StartJobScheduler");
Christopher Tate7060b042014-06-09 19:50:00 -07001140 mSystemServiceManager.startService(JobSchedulerService.class);
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001141 traceEnd();
Christopher Tatefa380e92014-05-19 13:46:29 -07001142
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001143 traceBeginAndSlog("StartSoundTrigger");
Arunesh Mishraa772e5f2016-01-25 10:33:11 -08001144 mSystemServiceManager.startService(SoundTriggerService.class);
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001145 traceEnd();
Arunesh Mishraa772e5f2016-01-25 10:33:11 -08001146
Dan Morrille4d9a012013-03-28 18:10:43 -07001147 if (!disableNonCoreServices) {
Jeff Sharkey73ea0ae2016-08-10 17:30:38 -06001148 if (!disableTrustManager) {
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001149 traceBeginAndSlog("StartTrustManager");
Jeff Sharkey73ea0ae2016-08-10 17:30:38 -06001150 mSystemServiceManager.startService(TrustManagerService.class);
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001151 traceEnd();
Jeff Sharkey73ea0ae2016-08-10 17:30:38 -06001152 }
1153
Jeff Brown2c43c332014-06-12 22:38:59 -07001154 if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_BACKUP)) {
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001155 traceBeginAndSlog("StartBackupManager");
Jeff Brown2c43c332014-06-12 22:38:59 -07001156 mSystemServiceManager.startService(BACKUP_MANAGER_SERVICE_CLASS);
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001157 traceEnd();
Dan Morrille4d9a012013-03-28 18:10:43 -07001158 }
Christopher Tate487529a2009-04-29 14:03:25 -07001159
Dmitri Plotnikov0a3e1732016-03-25 17:24:57 -07001160 if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_APP_WIDGETS)
1161 || context.getResources().getBoolean(R.bool.config_enableAppWidgetService)) {
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001162 traceBeginAndSlog("StartAppWidgerService");
Jeff Brown2c43c332014-06-12 22:38:59 -07001163 mSystemServiceManager.startService(APPWIDGET_SERVICE_CLASS);
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001164 traceEnd();
Dan Morrille4d9a012013-03-28 18:10:43 -07001165 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001166
Jeff Brown2c43c332014-06-12 22:38:59 -07001167 if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_VOICE_RECOGNIZERS)) {
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001168 traceBeginAndSlog("StartVoiceRecognitionManager");
Jeff Brown2c43c332014-06-12 22:38:59 -07001169 mSystemServiceManager.startService(VOICE_RECOGNITION_MANAGER_SERVICE_CLASS);
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001170 traceEnd();
Dianne Hackborn91097de2014-04-04 18:02:06 -07001171 }
Zhentao Sunc6cd1f92015-07-21 17:43:53 -07001172
1173 if (GestureLauncherService.isGestureLauncherEnabled(context.getResources())) {
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001174 traceBeginAndSlog("StartGestureLauncher");
Zhentao Sunc6cd1f92015-07-21 17:43:53 -07001175 mSystemServiceManager.startService(GestureLauncherService.class);
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001176 traceEnd();
Zhentao Sunc6cd1f92015-07-21 17:43:53 -07001177 }
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001178 traceBeginAndSlog("StartSensorNotification");
Peng Xua35b5532016-01-20 00:05:45 -08001179 mSystemServiceManager.startService(SensorNotificationService.class);
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001180 traceEnd();
1181
1182 traceBeginAndSlog("StartContextHubSystemService");
Peng Xu9ff7d222016-02-11 13:02:05 -08001183 mSystemServiceManager.startService(ContextHubSystemService.class);
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001184 traceEnd();
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001185 }
Jaikumar Ganesh7d0548d2010-10-18 15:29:09 -07001186
Yasuhiro Matsuda1ab43d52015-06-30 17:07:32 +09001187 traceBeginAndSlog("StartDiskStatsService");
Nick Pelly038cabe2010-09-23 16:12:11 -07001188 try {
Dan Egnor621bc542010-03-25 16:20:14 -07001189 ServiceManager.addService("diskstats", new DiskStatsService(context));
1190 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -07001191 reportWtf("starting DiskStats Service", e);
Dan Egnor621bc542010-03-25 16:20:14 -07001192 }
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001193 traceEnd();
Sen Hubde75702010-05-28 01:54:03 -07001194
Wei Liu6aaabae2016-03-04 14:50:16 -08001195 if (!disableSamplingProfiler) {
1196 traceBeginAndSlog("StartSamplingProfilerService");
1197 try {
1198 // need to add this service even if SamplingProfilerIntegration.isEnabled()
1199 // is false, because it is this service that detects system property change and
1200 // turns on SamplingProfilerIntegration. Plus, when sampling profiler doesn't work,
1201 // there is little overhead for running this service.
1202 ServiceManager.addService("samplingprofiler",
1203 new SamplingProfilerService(context));
1204 } catch (Throwable e) {
1205 reportWtf("starting SamplingProfiler Service", e);
1206 }
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001207 traceEnd();
Sen Hubde75702010-05-28 01:54:03 -07001208 }
Chung-yih Wang024d5962010-08-06 12:06:04 +08001209
Chenjie Luo2cab8822014-10-16 13:31:39 -07001210 if (!disableNetwork && !disableNetworkTime) {
Yasuhiro Matsuda1ab43d52015-06-30 17:07:32 +09001211 traceBeginAndSlog("StartNetworkTimeUpdateService");
Dan Morrille4d9a012013-03-28 18:10:43 -07001212 try {
Dan Morrille4d9a012013-03-28 18:10:43 -07001213 networkTimeUpdater = new NetworkTimeUpdateService(context);
Fyodor Kupolov32af07a2016-02-26 16:54:25 -08001214 ServiceManager.addService("network_time_update_service", networkTimeUpdater);
Dan Morrille4d9a012013-03-28 18:10:43 -07001215 } catch (Throwable e) {
1216 reportWtf("starting NetworkTimeUpdate service", e);
1217 }
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001218 traceEnd();
Amith Yamasani6734b9f2010-09-13 16:24:08 -07001219 }
John Grossmanc1576732012-02-01 15:23:33 -08001220
Yasuhiro Matsudaebf94652015-09-02 22:48:13 +09001221 traceBeginAndSlog("StartCommonTimeManagementService");
John Spurlockb4f01b92015-03-24 12:40:15 -04001222 try {
John Spurlockb4f01b92015-03-24 12:40:15 -04001223 commonTimeMgmtService = new CommonTimeManagementService(context);
1224 ServiceManager.addService("commontime_management", commonTimeMgmtService);
1225 } catch (Throwable e) {
1226 reportWtf("starting CommonTimeManagementService service", e);
John Grossmanc1576732012-02-01 15:23:33 -08001227 }
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001228 traceEnd();
Geremy Condra3d33c262012-05-06 18:32:19 -07001229
Dan Morrille4d9a012013-03-28 18:10:43 -07001230 if (!disableNetwork) {
Yasuhiro Matsuda1ab43d52015-06-30 17:07:32 +09001231 traceBeginAndSlog("CertBlacklister");
Dan Morrille4d9a012013-03-28 18:10:43 -07001232 try {
Dan Morrille4d9a012013-03-28 18:10:43 -07001233 CertBlacklister blacklister = new CertBlacklister(context);
1234 } catch (Throwable e) {
1235 reportWtf("starting CertBlacklister", e);
1236 }
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001237 traceEnd();
Geremy Condra3d33c262012-05-06 18:32:19 -07001238 }
Jim Miller5ecd8112013-01-09 18:50:26 -08001239
Selim Cinek705442f2016-09-13 16:02:33 -07001240 if (!disableNetwork && !disableNonCoreServices && EmergencyAffordanceManager.ENABLED) {
1241 // EmergencyMode sevice
1242 mSystemServiceManager.startService(EmergencyAffordanceService.class);
1243 }
1244
Jeff Browne0dd3ca82014-02-24 13:57:53 -08001245 if (!disableNonCoreServices) {
1246 // Dreams (interactive idle-time views, a/k/a screen savers, and doze mode)
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001247 traceBeginAndSlog("StartDreamManager");
Jeff Brown567f7ca2014-01-30 23:38:03 -08001248 mSystemServiceManager.startService(DreamManagerService.class);
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001249 traceEnd();
Daniel Sandler7d276c32012-01-30 14:33:52 -05001250 }
Svetoslavb3038ec2013-02-13 14:39:30 -08001251
John Reckedc524c2015-03-18 15:24:33 -07001252 if (!disableNonCoreServices) {
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001253 traceBeginAndSlog("AddGraphicsStatsService");
John Reckedc524c2015-03-18 15:24:33 -07001254 ServiceManager.addService(GraphicsStatsService.GRAPHICS_STATS_SERVICE,
1255 new GraphicsStatsService(context));
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001256 traceEnd();
John Reckedc524c2015-03-18 15:24:33 -07001257 }
1258
Jeff Brown2c43c332014-06-12 22:38:59 -07001259 if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_PRINTING)) {
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001260 traceBeginAndSlog("StartPrintManager");
Jeff Brown2c43c332014-06-12 22:38:59 -07001261 mSystemServiceManager.startService(PRINT_MANAGER_SERVICE_CLASS);
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001262 traceEnd();
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07001263 }
Jeff Brown69b07162013-11-07 00:30:16 -08001264
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001265 traceBeginAndSlog("StartRestrictionManager");
Jeff Brown2c43c332014-06-12 22:38:59 -07001266 mSystemServiceManager.startService(RestrictionsManagerService.class);
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001267 traceEnd();
Amith Yamasanif20d6402014-05-24 15:34:37 -07001268
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001269 traceBeginAndSlog("StartMediaSessionService");
Jeff Brown2c43c332014-06-12 22:38:59 -07001270 mSystemServiceManager.startService(MediaSessionService.class);
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001271 traceEnd();
RoboErik01fe6612014-02-13 14:19:04 -08001272
Yuncheol Heoa0c4a062014-07-10 20:49:27 +09001273 if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_HDMI_CEC)) {
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001274 traceBeginAndSlog("StartHdmiControlService");
Yuncheol Heoa0c4a062014-07-10 20:49:27 +09001275 mSystemServiceManager.startService(HdmiControlService.class);
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001276 traceEnd();
Yuncheol Heoa0c4a062014-07-10 20:49:27 +09001277 }
Jungshik Jang0792d372014-04-23 17:57:26 +09001278
Jae Seo996b5af2014-08-27 23:50:37 -07001279 if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_LIVE_TV)) {
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001280 traceBeginAndSlog("StartTvInputManager");
Dongwon Kang0fdcb742014-07-24 16:28:35 +09001281 mSystemServiceManager.startService(TvInputManagerService.class);
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001282 traceEnd();
Dongwon Kang0fdcb742014-07-24 16:28:35 +09001283 }
Jae Seo39570912014-02-20 18:23:25 -08001284
Dongwon Kangd8b81b32016-03-23 18:04:19 -07001285 if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_PICTURE_IN_PICTURE)) {
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001286 traceBeginAndSlog("StartMediaResourceMonitor");
Dongwon Kangd8b81b32016-03-23 18:04:19 -07001287 mSystemServiceManager.startService(MediaResourceMonitorService.class);
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001288 traceEnd();
Dongwon Kangd8b81b32016-03-23 18:04:19 -07001289 }
Dongwon Kang2034a4c2015-12-14 21:57:34 +09001290
Sujith Ramakrishnanb5b86c12016-01-28 16:53:16 -08001291 if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_LEANBACK)) {
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001292 traceBeginAndSlog("StartTvRemoteService");
Sujith Ramakrishnanb5b86c12016-01-28 16:53:16 -08001293 mSystemServiceManager.startService(TvRemoteService.class);
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001294 traceEnd();
Sujith Ramakrishnanb5b86c12016-01-28 16:53:16 -08001295 }
1296
Jeff Brown69b07162013-11-07 00:30:16 -08001297 if (!disableNonCoreServices) {
Yasuhiro Matsuda1ab43d52015-06-30 17:07:32 +09001298 traceBeginAndSlog("StartMediaRouterService");
Jeff Brown69b07162013-11-07 00:30:16 -08001299 try {
Jeff Brown69b07162013-11-07 00:30:16 -08001300 mediaRouter = new MediaRouterService(context);
1301 ServiceManager.addService(Context.MEDIA_ROUTER_SERVICE, mediaRouter);
1302 } catch (Throwable e) {
1303 reportWtf("starting MediaRouterService", e);
1304 }
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001305 traceEnd();
Adrian Roos82142c22014-03-27 14:56:59 +01001306
Wei Liueac5a802016-02-03 14:31:37 -08001307 if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_FINGERPRINT)) {
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001308 traceBeginAndSlog("StartFingerprintSensor");
Wei Liueac5a802016-02-03 14:31:37 -08001309 mSystemServiceManager.startService(FingerprintService.class);
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001310 traceEnd();
Wei Liueac5a802016-02-03 14:31:37 -08001311 }
Jim Millera75961472014-06-06 15:00:49 -07001312
Yasuhiro Matsuda1ab43d52015-06-30 17:07:32 +09001313 traceBeginAndSlog("StartBackgroundDexOptService");
Jim Millera75961472014-06-06 15:00:49 -07001314 try {
Calin Juravledb4a79a2015-12-23 18:55:08 +02001315 BackgroundDexOptService.schedule(context);
Brian Carlstrom7395a8a2014-04-28 22:11:01 -07001316 } catch (Throwable e) {
1317 reportWtf("starting BackgroundDexOptService", e);
1318 }
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001319 traceEnd();
Jeff Brown69b07162013-11-07 00:30:16 -08001320 }
Makoto Onuki55046222016-03-08 10:49:47 -08001321 // LauncherAppsService uses ShortcutService.
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001322 traceBeginAndSlog("StartShortcutServiceLifecycle");
Makoto Onuki55046222016-03-08 10:49:47 -08001323 mSystemServiceManager.startService(ShortcutService.Lifecycle.class);
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001324 traceEnd();
Amith Yamasani4f582632014-02-19 14:31:52 -08001325
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001326 traceBeginAndSlog("StartLauncherAppsService");
Jeff Brown2c43c332014-06-12 22:38:59 -07001327 mSystemServiceManager.startService(LauncherAppsService.class);
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001328 traceEnd();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001329 }
1330
Wei Liu6aaabae2016-03-04 14:50:16 -08001331 if (!disableNonCoreServices && !disableMediaProjection) {
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001332 traceBeginAndSlog("StartMediaProjectionManager");
Michael Wrightc39d47a2014-07-08 18:07:36 -07001333 mSystemServiceManager.startService(MediaProjectionManagerService.class);
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001334 traceEnd();
Michael Wrightc39d47a2014-07-08 18:07:36 -07001335 }
1336
Wei Liu48d3b632016-03-29 15:26:48 -07001337 if (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_WATCH)) {
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001338 traceBeginAndSlog("StartWearBluetooth");
Wei Liu48d3b632016-03-29 15:26:48 -07001339 mSystemServiceManager.startService(WEAR_BLUETOOTH_SERVICE_CLASS);
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001340 traceEnd();
1341
1342 traceBeginAndSlog("StartWearWifiMediator");
Nancy Zhengf3d8b812016-07-08 12:55:48 -07001343 mSystemServiceManager.startService(WEAR_WIFI_MEDIATOR_SERVICE_CLASS);
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001344 traceEnd();
1345 if (!disableNonCoreServices) {
1346 traceBeginAndSlog("StartWearTimeService");
1347 mSystemServiceManager.startService(WEAR_TIME_SERVICE_CLASS);
1348 traceEnd();
1349 }
Wei Liu48d3b632016-03-29 15:26:48 -07001350 }
1351
Dianne Hackborn6af0d502009-09-28 13:25:46 -07001352 // Before things start rolling, be sure we have decided whether
1353 // we are in safe mode.
Dianne Hackborna34f1ad2009-09-02 13:26:28 -07001354 final boolean safeMode = wm.detectSafeMode();
Dianne Hackborn6af0d502009-09-28 13:25:46 -07001355 if (safeMode) {
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001356 traceBeginAndSlog("EnterSafeModeAndDisableJitCompilation");
Jeff Brown4ccb8232014-01-16 22:16:42 -08001357 mActivityManagerService.enterSafeMode();
Jeff Brownb09abc12011-01-13 21:08:27 -08001358 // Disable the JIT for the system_server process
1359 VMRuntime.getRuntime().disableJitCompilation();
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001360 traceEnd();
Ben Cheng6c0afff2010-02-14 16:18:56 -08001361 } else {
1362 // Enable the JIT for the system_server process
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001363 traceBeginAndSlog("StartJitCompilation");
Ben Cheng6c0afff2010-02-14 16:18:56 -08001364 VMRuntime.getRuntime().startJitCompilation();
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001365 traceEnd();
Dianne Hackborn6af0d502009-09-28 13:25:46 -07001366 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001367
Ye Wend97e1fd2014-07-24 12:56:45 -07001368 // MMS service broker
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001369 traceBeginAndSlog("StartMmsService");
Ye Wend97e1fd2014-07-24 12:56:45 -07001370 mmsService = mSystemServiceManager.startService(MmsServiceBroker.class);
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001371 traceEnd();
Ye Wend97e1fd2014-07-24 12:56:45 -07001372
Sudheer Shanka28537b62016-09-07 11:12:31 -07001373 traceBeginAndSlog("StartRetailDemoModeService");
1374 mSystemServiceManager.startService(RetailDemoModeService.class);
1375 traceEnd();
Suprabh Shuklacc30b0e72016-05-20 14:41:22 -07001376
Felipe Leme5381aa42016-10-13 09:02:32 -07001377 traceBeginAndSlog("StartAutoFillService");
1378 mSystemServiceManager.startService(AUTO_FILL_MANAGER_SERVICE_CLASS);
1379 traceEnd();
1380
Dianne Hackborn6af0d502009-09-28 13:25:46 -07001381 // It is now time to start up the app processes...
Joe Onorato30275482009-07-08 17:09:14 -07001382
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001383 traceBeginAndSlog("MakeVibratorServiceReady");
Jeff Brown7f6c2312012-04-13 20:38:38 -07001384 try {
1385 vibrator.systemReady();
1386 } catch (Throwable e) {
1387 reportWtf("making Vibrator Service ready", e);
1388 }
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001389 traceEnd();
Jeff Brown7f6c2312012-04-13 20:38:38 -07001390
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001391 traceBeginAndSlog("MakeLockSettingsServiceReady");
Dan Morrille4d9a012013-03-28 18:10:43 -07001392 if (lockSettings != null) {
1393 try {
1394 lockSettings.systemReady();
1395 } catch (Throwable e) {
1396 reportWtf("making Lock Settings Service ready", e);
1397 }
Felipe Ramosf35df5b2012-09-18 18:26:27 -03001398 }
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001399 traceEnd();
Felipe Ramosf35df5b2012-09-18 18:26:27 -03001400
Amith Yamasani817ec492013-12-20 13:27:30 -08001401 // Needed by DevicePolicyManager for initialization
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001402 traceBeginAndSlog("StartBootPhaseLockSettingsReady");
Jeff Brown6f357d32014-01-15 20:40:55 -08001403 mSystemServiceManager.startBootPhase(SystemService.PHASE_LOCK_SETTINGS_READY);
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001404 traceEnd();
Dianne Hackbornd6847842010-01-12 18:14:19 -08001405
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001406 traceBeginAndSlog("StartBootPhaseSystemServicesReady");
Jeff Brown6f357d32014-01-15 20:40:55 -08001407 mSystemServiceManager.startBootPhase(SystemService.PHASE_SYSTEM_SERVICES_READY);
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001408 traceEnd();
Joe Onorato30275482009-07-08 17:09:14 -07001409
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001410 traceBeginAndSlog("MakeWindowManagerServiceReady");
Dianne Hackborn661cd522011-08-22 00:26:20 -07001411 try {
1412 wm.systemReady();
1413 } catch (Throwable e) {
1414 reportWtf("making Window Manager Service ready", e);
1415 }
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001416 traceEnd();
Joe Onoratodc565f42010-10-04 15:27:22 -04001417
Jeff Brownb09abc12011-01-13 21:08:27 -08001418 if (safeMode) {
Jeff Brown4ccb8232014-01-16 22:16:42 -08001419 mActivityManagerService.showSafeModeOverlay();
Jeff Brownb09abc12011-01-13 21:08:27 -08001420 }
1421
Joe Onoratodc565f42010-10-04 15:27:22 -04001422 // Update the configuration for this context by hand, because we're going
1423 // to start using it before the config change done in wm.systemReady() will
1424 // propagate to it.
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001425 final Configuration config = wm.computeNewConfiguration(DEFAULT_DISPLAY);
Joe Onoratodc565f42010-10-04 15:27:22 -04001426 DisplayMetrics metrics = new DisplayMetrics();
1427 WindowManager w = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
1428 w.getDefaultDisplay().getMetrics(metrics);
1429 context.getResources().updateConfiguration(config, metrics);
1430
Alan Viverette395cd012015-08-11 17:27:04 -04001431 // The system context's theme may be configuration-dependent.
1432 final Theme systemTheme = context.getTheme();
1433 if (systemTheme.getChangingConfigurations() != 0) {
1434 systemTheme.rebase();
1435 }
1436
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001437 traceBeginAndSlog("MakePowerManagerServiceReady");
Jeff Brownaa202a62012-08-21 22:14:26 -07001438 try {
Jeff Brown6f357d32014-01-15 20:40:55 -08001439 // TODO: use boot phase
Jeff Brown21392762014-06-13 19:00:36 -07001440 mPowerManagerService.systemReady(mActivityManagerService.getAppOpsService());
Jeff Brownaa202a62012-08-21 22:14:26 -07001441 } catch (Throwable e) {
1442 reportWtf("making Power Manager Service ready", e);
1443 }
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001444 traceEnd();
Jeff Brownaa202a62012-08-21 22:14:26 -07001445
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001446 traceBeginAndSlog("MakePackageManagerServiceReady");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001447 try {
Jeff Brown2c43c332014-06-12 22:38:59 -07001448 mPackageManagerService.systemReady();
Dianne Hackborn661cd522011-08-22 00:26:20 -07001449 } catch (Throwable e) {
1450 reportWtf("making Package Manager Service ready", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001451 }
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001452 traceEnd();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001453
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001454 traceBeginAndSlog("MakeDisplayManagerServiceReady");
Jeff Brownbd6e1502012-08-28 03:27:37 -07001455 try {
Jeff Brown4ccb8232014-01-16 22:16:42 -08001456 // TODO: use boot phase and communicate these flags some other way
Jeff Brown2c43c332014-06-12 22:38:59 -07001457 mDisplayManagerService.systemReady(safeMode, mOnlyCore);
Jeff Brownbd6e1502012-08-28 03:27:37 -07001458 } catch (Throwable e) {
1459 reportWtf("making Display Manager Service ready", e);
1460 }
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001461 traceEnd();
Jeff Brownbd6e1502012-08-28 03:27:37 -07001462
joonyoung.cho2f30cc12015-04-08 13:56:34 +09001463 mSystemServiceManager.setSafeMode(safeMode);
1464
Dianne Hackborna34f1ad2009-09-02 13:26:28 -07001465 // These are needed to propagate to the runnable below.
Jeff Sharkey350083e2011-06-29 10:45:16 -07001466 final NetworkManagementService networkManagementF = networkManagement;
Jeff Sharkey75279902011-05-24 18:39:45 -07001467 final NetworkStatsService networkStatsF = networkStats;
Jeff Sharkeya4620792011-05-20 15:29:23 -07001468 final NetworkPolicyManagerService networkPolicyF = networkPolicy;
Dianne Hackborna34f1ad2009-09-02 13:26:28 -07001469 final ConnectivityService connectivityF = connectivity;
Jeff Davidson6a4b2202014-04-16 17:29:40 -07001470 final NetworkScoreService networkScoreF = networkScore;
Mike Lockwood46db5042010-02-22 16:36:44 -05001471 final LocationManagerService locationF = location;
Bai Taoa58a8752010-07-13 15:32:16 +08001472 final CountryDetectorService countryDetectorF = countryDetector;
Amith Yamasani6734b9f2010-09-13 16:24:08 -07001473 final NetworkTimeUpdateService networkTimeUpdaterF = networkTimeUpdater;
John Grossmanc1576732012-02-01 15:23:33 -08001474 final CommonTimeManagementService commonTimeMgmtServiceF = commonTimeMgmtService;
Jeff Brown6ec6f792012-04-17 16:52:41 -07001475 final InputManagerService inputManagerF = inputManager;
Wink Savillea12a7b32012-09-20 10:09:45 -07001476 final TelephonyRegistry telephonyRegistryF = telephonyRegistry;
Jeff Brown69b07162013-11-07 00:30:16 -08001477 final MediaRouterService mediaRouterF = mediaRouter;
Ye Wend97e1fd2014-07-24 12:56:45 -07001478 final MmsServiceBroker mmsServiceF = mmsService;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001479
Dianne Hackborna34f1ad2009-09-02 13:26:28 -07001480 // We now tell the activity manager it is okay to run third party
1481 // code. It will call back into us once it has gotten to the state
1482 // where third party code can really run (but before it has actually
1483 // started launching the initial applications), for us to complete our
1484 // initialization.
Jeff Brown4ccb8232014-01-16 22:16:42 -08001485 mActivityManagerService.systemReady(new Runnable() {
Adam Lesinski2cb6c602014-02-14 17:19:56 -08001486 @Override
Dianne Hackborna34f1ad2009-09-02 13:26:28 -07001487 public void run() {
Adam Lesinski8793dd82014-02-21 14:06:47 -08001488 Slog.i(TAG, "Making services ready");
Fyodor Kupolov68f49ae2016-12-02 17:33:21 -08001489 traceBeginAndSlog("StartActivityManagerReadyPhase");
Adam Lesinski8793dd82014-02-21 14:06:47 -08001490 mSystemServiceManager.startBootPhase(
1491 SystemService.PHASE_ACTIVITY_MANAGER_READY);
Fyodor Kupolov68f49ae2016-12-02 17:33:21 -08001492 traceEnd();
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001493 traceBeginAndSlog("PhaseActivityManagerReady");
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001494
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001495 traceBeginAndSlog("StartObservingNativeCrashes");
Adam Lesinski8793dd82014-02-21 14:06:47 -08001496 try {
1497 mActivityManagerService.startObservingNativeCrashes();
1498 } catch (Throwable e) {
1499 reportWtf("observing native crashes", e);
1500 }
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001501 traceEnd();
Primiano Tucci810c0522014-07-25 18:03:16 +01001502
Gustav Senntonc7db48b2016-02-25 13:42:45 +00001503 if (!mOnlyCore) {
1504 Slog.i(TAG, "WebViewFactory preparation");
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001505 traceBeginAndSlog("WebViewFactoryPreparation");
Gustav Senntonc7db48b2016-02-25 13:42:45 +00001506 mWebViewUpdateService.prepareWebViewInSystemServer();
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001507 traceEnd();
Gustav Senntonc7db48b2016-02-25 13:42:45 +00001508 }
Primiano Tucci810c0522014-07-25 18:03:16 +01001509
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001510 traceBeginAndSlog("StartSystemUI");
Adam Lesinski8793dd82014-02-21 14:06:47 -08001511 try {
1512 startSystemUi(context);
1513 } catch (Throwable e) {
1514 reportWtf("starting System UI", e);
1515 }
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001516 traceEnd();
1517 traceBeginAndSlog("MakeNetworkScoreReady");
Adam Lesinski8793dd82014-02-21 14:06:47 -08001518 try {
Jeff Davidson6a4b2202014-04-16 17:29:40 -07001519 if (networkScoreF != null) networkScoreF.systemReady();
1520 } catch (Throwable e) {
1521 reportWtf("making Network Score Service ready", e);
1522 }
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001523 traceEnd();
1524 traceBeginAndSlog("MakeNetworkManagementServiceReady");
Jeff Davidson6a4b2202014-04-16 17:29:40 -07001525 try {
Adam Lesinski8793dd82014-02-21 14:06:47 -08001526 if (networkManagementF != null) networkManagementF.systemReady();
1527 } catch (Throwable e) {
1528 reportWtf("making Network Managment Service ready", e);
1529 }
Fyodor Kupolov311b9fa2016-12-02 16:24:35 -08001530 CountDownLatch networkPolicyInitReadySignal = null;
1531 if (networkPolicyF != null) {
1532 networkPolicyInitReadySignal = networkPolicyF
1533 .networkScoreAndNetworkManagementServiceReady();
1534 }
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001535 traceEnd();
1536 traceBeginAndSlog("MakeNetworkStatsServiceReady");
Adam Lesinski8793dd82014-02-21 14:06:47 -08001537 try {
1538 if (networkStatsF != null) networkStatsF.systemReady();
1539 } catch (Throwable e) {
1540 reportWtf("making Network Stats Service ready", e);
1541 }
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001542 traceEnd();
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001543 traceBeginAndSlog("MakeConnectivityServiceReady");
Adam Lesinski8793dd82014-02-21 14:06:47 -08001544 try {
1545 if (connectivityF != null) connectivityF.systemReady();
1546 } catch (Throwable e) {
1547 reportWtf("making Connectivity Service ready", e);
1548 }
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001549 traceEnd();
Fyodor Kupolov311b9fa2016-12-02 16:24:35 -08001550 traceBeginAndSlog("MakeNetworkPolicyServiceReady");
1551 try {
1552 if (networkPolicyF != null) {
1553 networkPolicyF.systemReady(networkPolicyInitReadySignal);
1554 }
1555 } catch (Throwable e) {
1556 reportWtf("making Network Policy Service ready", e);
1557 }
1558 traceEnd();
Makoto Onukie1aef852015-10-15 17:28:35 -07001559
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001560 traceBeginAndSlog("StartWatchdog");
Adam Lesinski8793dd82014-02-21 14:06:47 -08001561 Watchdog.getInstance().start();
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001562 traceEnd();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001563
Adam Lesinski8793dd82014-02-21 14:06:47 -08001564 // It is now okay to let the various system services start their
1565 // third party code...
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001566 traceBeginAndSlog("PhaseThirdPartyAppsCanStart");
Adam Lesinski8793dd82014-02-21 14:06:47 -08001567 mSystemServiceManager.startBootPhase(
1568 SystemService.PHASE_THIRD_PARTY_APPS_CAN_START);
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001569 traceEnd();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001570
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001571 traceBeginAndSlog("MakeLocationServiceReady");
Adam Lesinski8793dd82014-02-21 14:06:47 -08001572 try {
Adam Lesinski8793dd82014-02-21 14:06:47 -08001573 if (locationF != null) locationF.systemRunning();
1574 } catch (Throwable e) {
1575 reportWtf("Notifying Location Service running", e);
1576 }
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001577 traceEnd();
1578 traceBeginAndSlog("MakeCountryDetectionServiceReady");
Adam Lesinski8793dd82014-02-21 14:06:47 -08001579 try {
1580 if (countryDetectorF != null) countryDetectorF.systemRunning();
1581 } catch (Throwable e) {
1582 reportWtf("Notifying CountryDetectorService running", e);
1583 }
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001584 traceEnd();
1585 traceBeginAndSlog("MakeNetworkTimeUpdateReady");
Adam Lesinski8793dd82014-02-21 14:06:47 -08001586 try {
1587 if (networkTimeUpdaterF != null) networkTimeUpdaterF.systemRunning();
1588 } catch (Throwable e) {
1589 reportWtf("Notifying NetworkTimeService running", e);
1590 }
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001591 traceEnd();
1592 traceBeginAndSlog("MakeCommonTimeManagementServiceReady");
Adam Lesinski8793dd82014-02-21 14:06:47 -08001593 try {
1594 if (commonTimeMgmtServiceF != null) {
1595 commonTimeMgmtServiceF.systemRunning();
Adam Lesinski2cb6c602014-02-14 17:19:56 -08001596 }
Adam Lesinski8793dd82014-02-21 14:06:47 -08001597 } catch (Throwable e) {
1598 reportWtf("Notifying CommonTimeManagementService running", e);
1599 }
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001600 traceEnd();
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001601 traceBeginAndSlog("MakeInputManagerServiceReady");
Adam Lesinski8793dd82014-02-21 14:06:47 -08001602 try {
1603 // TODO(BT) Pass parameter to input manager
1604 if (inputManagerF != null) inputManagerF.systemRunning();
1605 } catch (Throwable e) {
1606 reportWtf("Notifying InputManagerService running", e);
1607 }
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001608 traceEnd();
1609 traceBeginAndSlog("MakeTelephonyRegistryReady");
Adam Lesinski8793dd82014-02-21 14:06:47 -08001610 try {
1611 if (telephonyRegistryF != null) telephonyRegistryF.systemRunning();
1612 } catch (Throwable e) {
1613 reportWtf("Notifying TelephonyRegistry running", e);
1614 }
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001615 traceEnd();
1616 traceBeginAndSlog("MakeMediaRouterServiceReady");
Adam Lesinski8793dd82014-02-21 14:06:47 -08001617 try {
1618 if (mediaRouterF != null) mediaRouterF.systemRunning();
1619 } catch (Throwable e) {
1620 reportWtf("Notifying MediaRouterService running", e);
1621 }
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001622 traceEnd();
1623 traceBeginAndSlog("MakeMmsServiceReady");
Ye Wend97e1fd2014-07-24 12:56:45 -07001624 try {
1625 if (mmsServiceF != null) mmsServiceF.systemRunning();
1626 } catch (Throwable e) {
1627 reportWtf("Notifying MmsService running", e);
1628 }
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001629 traceEnd();
Jeremy Joslindd251ef2016-03-14 11:17:41 -07001630
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001631 traceBeginAndSlog("MakeNetworkScoreServiceReady");
Jeremy Joslindd251ef2016-03-14 11:17:41 -07001632 try {
1633 if (networkScoreF != null) networkScoreF.systemRunning();
1634 } catch (Throwable e) {
1635 reportWtf("Notifying NetworkScoreService running", e);
1636 }
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001637 traceEnd();
1638
Joe Onorato1754d742016-11-21 17:51:35 -08001639 traceBeginAndSlog("IncidentDaemonReady");
1640 try {
1641 // TODO: Switch from checkService to getService once it's always
1642 // in the build and should reliably be there.
1643 final IIncidentManager incident = IIncidentManager.Stub.asInterface(
1644 ServiceManager.checkService("incident"));
1645 if (incident != null) incident.systemRunning();
1646 } catch (Throwable e) {
1647 reportWtf("Notifying incident daemon running", e);
1648 }
1649 traceEnd();
1650
1651
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001652 traceEnd(); // PhaseActivityManagerReady
Dianne Hackborna34f1ad2009-09-02 13:26:28 -07001653 }
1654 });
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001655 }
Joe Onoratof3c3c4f2010-10-21 11:09:02 -04001656
1657 static final void startSystemUi(Context context) {
1658 Intent intent = new Intent();
1659 intent.setComponent(new ComponentName("com.android.systemui",
1660 "com.android.systemui.SystemUIService"));
Jeff Sharkey2f3e3532015-12-21 14:16:43 -07001661 intent.addFlags(Intent.FLAG_DEBUG_TRIAGED_MISSING);
Dianne Hackborn40e9f292012-11-27 19:12:23 -08001662 //Slog.d(TAG, "Starting service: " + intent);
Xiaohui Chen70f6c382015-04-28 14:21:43 -07001663 context.startServiceAsUser(intent, UserHandle.SYSTEM);
Joe Onoratof3c3c4f2010-10-21 11:09:02 -04001664 }
Yasuhiro Matsuda1ab43d52015-06-30 17:07:32 +09001665
1666 private static void traceBeginAndSlog(String name) {
Yasuhiro Matsuda1ab43d52015-06-30 17:07:32 +09001667 Slog.i(TAG, name);
Fyodor Kupolov3235e0c2016-11-17 11:44:49 -08001668 BOOT_TIMINGS_TRACE_LOG.traceBegin(name);
Vitalii Tomkiv4887e672016-07-21 15:58:24 -07001669 }
1670
1671 private static void traceEnd() {
Fyodor Kupolov3235e0c2016-11-17 11:44:49 -08001672 BOOT_TIMINGS_TRACE_LOG.traceEnd();
Yasuhiro Matsuda1ab43d52015-06-30 17:07:32 +09001673 }
Nicolas Geoffray27c07372015-11-05 16:54:09 +00001674}