blob: 55885e6ed37fcbca732ed95b9cbe421d93a91416 [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 Hamilton35eef702010-06-09 15:45:18 -050019import android.accounts.AccountManagerService;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080020import android.app.ActivityManagerNative;
Nick Pellyf242b7b2009-10-08 00:12:45 +020021import android.bluetooth.BluetoothAdapter;
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;
24import android.content.ContentService;
25import android.content.Context;
Joe Onoratof3c3c4f2010-10-21 11:09:02 -040026import android.content.Intent;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080027import android.content.pm.IPackageManager;
Joe Onoratodc565f42010-10-04 15:27:22 -040028import android.content.res.Configuration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080029import android.media.AudioService;
Irfan Sherifff6d09842011-08-03 15:37:08 -070030import android.net.wifi.p2p.WifiP2pService;
Jeff Brownbd6e1502012-08-28 03:27:37 -070031import android.os.Handler;
32import android.os.HandlerThread;
Jeff Hamilton35eef702010-06-09 15:45:18 -050033import android.os.Looper;
34import android.os.RemoteException;
Glenn Kasten07b04652012-04-23 15:00:43 -070035import android.os.SchedulingPolicyService;
Jeff Hamilton35eef702010-06-09 15:45:18 -050036import android.os.ServiceManager;
Brad Fitzpatrickc74a1b442010-09-10 16:03:29 -070037import android.os.StrictMode;
Jeff Hamilton35eef702010-06-09 15:45:18 -050038import android.os.SystemClock;
39import android.os.SystemProperties;
Amith Yamasanicd757062012-10-19 18:23:52 -070040import android.os.UserHandle;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080041import android.server.search.SearchManagerService;
Dianne Hackbornbe87e2f2012-09-28 16:31:34 -070042import android.service.dreams.DreamService;
Joe Onoratodc565f42010-10-04 15:27:22 -040043import android.util.DisplayMetrics;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080044import android.util.EventLog;
Dianne Hackborn661cd522011-08-22 00:26:20 -070045import android.util.Log;
Joe Onorato8a9b2202010-02-26 18:56:32 -080046import android.util.Slog;
Brad Fitzpatrick5fdc0c72010-10-12 13:12:18 -070047import android.view.WindowManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080048
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -070049import com.android.internal.os.BinderInternal;
50import com.android.internal.os.SamplingProfilerIntegration;
Amith Yamasani52c489c2012-03-28 11:42:42 -070051import com.android.internal.widget.LockSettingsService;
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -070052import com.android.server.accessibility.AccessibilityManagerService;
53import com.android.server.am.ActivityManagerService;
Jeff Brown96307042012-07-27 15:51:34 -070054import com.android.server.am.BatteryStatsService;
Jeff Brownfa25bf52012-07-23 19:26:30 -070055import com.android.server.display.DisplayManagerService;
Jeff Browncef440f2012-09-25 18:58:48 -070056import com.android.server.dreams.DreamManagerService;
Jeff Brown6ec6f792012-04-17 16:52:41 -070057import com.android.server.input.InputManagerService;
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -070058import com.android.server.net.NetworkPolicyManagerService;
Jeff Sharkey75279902011-05-24 18:39:45 -070059import com.android.server.net.NetworkStatsService;
Jeff Brownf69c8122012-09-12 17:00:34 -070060import com.android.server.pm.Installer;
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -070061import com.android.server.pm.PackageManagerService;
Amith Yamasani258848d2012-08-10 17:06:33 -070062import com.android.server.pm.UserManagerService;
Jeff Brown4f8ecd82012-06-18 18:29:13 -070063import com.android.server.power.PowerManagerService;
64import com.android.server.power.ShutdownThread;
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -070065import com.android.server.usb.UsbService;
66import com.android.server.wm.WindowManagerService;
67
68import dalvik.system.VMRuntime;
69import dalvik.system.Zygote;
70
Dan Egnor4410ec82009-09-11 16:40:01 -070071import java.io.File;
Bob Leee5408332009-09-04 18:31:17 -070072import java.util.Timer;
73import java.util.TimerTask;
74
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080075class ServerThread extends Thread {
76 private static final String TAG = "SystemServer";
Ben Komalo553acf02011-09-19 14:25:28 -070077 private static final String ENCRYPTING_STATE = "trigger_restart_min_framework";
Ben Komalo3573d402011-09-23 15:08:24 -070078 private static final String ENCRYPTED_STATE = "1";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080079
Jeff Hamilton35eef702010-06-09 15:45:18 -050080 ContentResolver mContentResolver;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080081
Dianne Hackborn661cd522011-08-22 00:26:20 -070082 void reportWtf(String msg, Throwable e) {
83 Slog.w(TAG, "***********************************************");
84 Log.wtf(TAG, "BOOT FAILURE " + msg, e);
85 }
86
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080087 @Override
88 public void run() {
Doug Zongkerab5c49c2009-12-04 10:31:43 -080089 EventLog.writeEvent(EventLogTags.BOOT_PROGRESS_SYSTEM_RUN,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080090 SystemClock.uptimeMillis());
91
Vairavan Srinivasan04b74ec2012-02-02 22:12:19 -080092 Looper.prepareMainLooper();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080093
94 android.os.Process.setThreadPriority(
95 android.os.Process.THREAD_PRIORITY_FOREGROUND);
96
Dianne Hackborn887f3552009-12-07 17:59:37 -080097 BinderInternal.disableBackgroundScheduling(true);
Christopher Tate160edb32010-06-30 17:46:30 -070098 android.os.Process.setCanSelfBackground(false);
Sen Hubde75702010-05-28 01:54:03 -070099
Kenny Rootf547d672010-09-22 10:36:48 -0700100 // Check whether we failed to shut down last time we tried.
101 {
102 final String shutdownAction = SystemProperties.get(
103 ShutdownThread.SHUTDOWN_ACTION_PROPERTY, "");
104 if (shutdownAction != null && shutdownAction.length() > 0) {
105 boolean reboot = (shutdownAction.charAt(0) == '1');
106
107 final String reason;
108 if (shutdownAction.length() > 1) {
109 reason = shutdownAction.substring(1, shutdownAction.length());
110 } else {
111 reason = null;
112 }
113
114 ShutdownThread.rebootOrShutdown(reboot, reason);
115 }
116 }
117
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800118 String factoryTestStr = SystemProperties.get("ro.factorytest");
119 int factoryTest = "".equals(factoryTestStr) ? SystemServer.FACTORY_TEST_OFF
120 : Integer.parseInt(factoryTestStr);
Mike Lockwood3a74bd32011-08-12 13:55:22 -0700121 final boolean headless = "1".equals(SystemProperties.get("ro.config.headless", "0"));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800122
Jeff Brownf69c8122012-09-12 17:00:34 -0700123 Installer installer = null;
Kenny Root26ff6622012-07-30 12:58:03 -0700124 AccountManagerService accountManager = null;
125 ContentService contentService = null;
Mike Lockwood3a322132009-11-24 00:30:52 -0500126 LightsService lights = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800127 PowerManagerService power = null;
Jeff Brownfa25bf52012-07-23 19:26:30 -0700128 DisplayManagerService display = null;
Mike Lockwood07a500f2009-08-12 09:56:44 -0400129 BatteryService battery = null;
Jeff Brown7f6c2312012-04-13 20:38:38 -0700130 VibratorService vibrator = null;
Jeff Sharkey75279902011-05-24 18:39:45 -0700131 AlarmManagerService alarm = null;
Jeff Sharkeyb049e212012-09-07 23:16:01 -0700132 MountService mountService = null;
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -0700133 NetworkManagementService networkManagement = null;
Jeff Sharkey75279902011-05-24 18:39:45 -0700134 NetworkStatsService networkStats = null;
Jeff Sharkeya4620792011-05-20 15:29:23 -0700135 NetworkPolicyManagerService networkPolicy = null;
Mike Lockwood0f79b542009-08-14 14:18:49 -0400136 ConnectivityService connectivity = null;
repo sync55bc5f32011-06-24 14:23:07 -0700137 WifiP2pService wifiP2p = null;
repo syncaea743a2011-07-29 23:55:49 -0700138 WifiService wifi = null;
Irfan Sheriff7d024d32012-03-22 17:01:39 -0700139 NsdService serviceDiscovery= null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800140 IPackageManager pm = null;
141 Context context = null;
142 WindowManagerService wm = null;
fredc0f420372012-04-12 00:02:00 -0700143 BluetoothManagerService bluetooth = null;
Dan Murphyc9f4eaf2009-08-12 15:15:43 -0500144 DockObserver dock = null;
Mike Lockwood770126a2010-12-09 22:30:37 -0800145 UsbService usb = null;
Mike Lockwoodb01e8bf2011-08-29 20:11:07 -0400146 SerialService serial = null;
Jeff Brown2416e092012-08-21 22:12:20 -0700147 TwilightService twilight = null;
Dianne Hackborn7299c412010-03-04 18:41:49 -0800148 UiModeManagerService uiMode = null;
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800149 RecognitionManagerService recognition = null;
Robert Greenwalt9e696c22010-04-01 14:45:18 -0700150 ThrottleService throttle = null;
Amith Yamasani6734b9f2010-09-13 16:24:08 -0700151 NetworkTimeUpdateService networkTimeUpdater = null;
John Grossmanc1576732012-02-01 15:23:33 -0800152 CommonTimeManagementService commonTimeMgmtService = null;
Jeff Brown6ec6f792012-04-17 16:52:41 -0700153 InputManagerService inputManager = null;
Wink Savillea12a7b32012-09-20 10:09:45 -0700154 TelephonyRegistry telephonyRegistry = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800155
Jeff Brownbd6e1502012-08-28 03:27:37 -0700156 // Create a shared handler thread for UI within the system server.
157 // This thread is used by at least the following components:
158 // - WindowManagerPolicy
159 // - KeyguardViewManager
160 // - DisplayManagerService
161 HandlerThread uiHandlerThread = new HandlerThread("UI");
162 uiHandlerThread.start();
163 Handler uiHandler = new Handler(uiHandlerThread.getLooper());
164 uiHandler.post(new Runnable() {
165 @Override
166 public void run() {
167 //Looper.myLooper().setMessageLogging(new LogPrinter(
168 // Log.VERBOSE, "WindowManagerPolicy", Log.LOG_ID_SYSTEM));
169 android.os.Process.setThreadPriority(
170 android.os.Process.THREAD_PRIORITY_FOREGROUND);
171 android.os.Process.setCanSelfBackground(false);
172
173 // For debug builds, log event loop stalls to dropbox for analysis.
174 if (StrictMode.conditionallyEnableDebugLogging()) {
175 Slog.i(TAG, "Enabled StrictMode logging for UI Looper");
176 }
177 }
178 });
179
180 // Create a handler thread just for the window manager to enjoy.
181 HandlerThread wmHandlerThread = new HandlerThread("WindowManager");
182 wmHandlerThread.start();
183 Handler wmHandler = new Handler(wmHandlerThread.getLooper());
184 wmHandler.post(new Runnable() {
185 @Override
186 public void run() {
187 //Looper.myLooper().setMessageLogging(new LogPrinter(
188 // android.util.Log.DEBUG, TAG, android.util.Log.LOG_ID_SYSTEM));
189 android.os.Process.setThreadPriority(
190 android.os.Process.THREAD_PRIORITY_DISPLAY);
191 android.os.Process.setCanSelfBackground(false);
192
193 // For debug builds, log event loop stalls to dropbox for analysis.
194 if (StrictMode.conditionallyEnableDebugLogging()) {
Jeff Brown89d55462012-09-19 11:33:42 -0700195 Slog.i(TAG, "Enabled StrictMode logging for WM Looper");
Jeff Brownbd6e1502012-08-28 03:27:37 -0700196 }
197 }
198 });
199
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800200 // Critical services...
Jeff Brownbd6e1502012-08-28 03:27:37 -0700201 boolean onlyCore = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800202 try {
Jeff Brownf69c8122012-09-12 17:00:34 -0700203 // Wait for installd to finished starting up so that it has a chance to
204 // create critical directories such as /data/user with the appropriate
205 // permissions. We need this to complete before we initialize other services.
206 Slog.i(TAG, "Waiting for installd to be ready.");
207 installer = new Installer();
208 installer.ping();
209
Nick Kralevich6967cbc2011-11-17 13:24:32 -0800210 Slog.i(TAG, "Entropy Mixer");
211 ServiceManager.addService("entropy", new EntropyMixer());
Nick Kralevich4fb25612009-06-17 16:03:22 -0700212
Joe Onorato8a9b2202010-02-26 18:56:32 -0800213 Slog.i(TAG, "Power Manager");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800214 power = new PowerManagerService();
215 ServiceManager.addService(Context.POWER_SERVICE, power);
216
Joe Onorato8a9b2202010-02-26 18:56:32 -0800217 Slog.i(TAG, "Activity Manager");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800218 context = ActivityManagerService.main(factoryTest);
Jeff Brown848c2dc2012-08-19 20:18:08 -0700219
220 Slog.i(TAG, "Display Manager");
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700221 display = new DisplayManagerService(context, wmHandler, uiHandler);
Jeff Brown848c2dc2012-08-19 20:18:08 -0700222 ServiceManager.addService(Context.DISPLAY_SERVICE, display, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800223
Joe Onorato8a9b2202010-02-26 18:56:32 -0800224 Slog.i(TAG, "Telephony Registry");
Wink Savillea12a7b32012-09-20 10:09:45 -0700225 telephonyRegistry = new TelephonyRegistry(context);
226 ServiceManager.addService("telephony.registry", telephonyRegistry);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800227
Glenn Kasten07b04652012-04-23 15:00:43 -0700228 Slog.i(TAG, "Scheduling Policy");
229 ServiceManager.addService(Context.SCHEDULING_POLICY_SERVICE,
230 new SchedulingPolicyService());
231
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800232 AttributeCache.init(context);
233
Jeff Brownbd6e1502012-08-28 03:27:37 -0700234 if (!display.waitForDefaultDisplay()) {
235 reportWtf("Timeout waiting for default display to be initialized.",
236 new Throwable());
237 }
238
Joe Onorato8a9b2202010-02-26 18:56:32 -0800239 Slog.i(TAG, "Package Manager");
Ben Komalo553acf02011-09-19 14:25:28 -0700240 // Only run "core" apps if we're encrypting the device.
241 String cryptState = SystemProperties.get("vold.decrypt");
Ben Komalo3573d402011-09-23 15:08:24 -0700242 if (ENCRYPTING_STATE.equals(cryptState)) {
Ben Komalo553acf02011-09-19 14:25:28 -0700243 Slog.w(TAG, "Detected encryption in progress - only parsing core apps");
Ben Komalo3573d402011-09-23 15:08:24 -0700244 onlyCore = true;
245 } else if (ENCRYPTED_STATE.equals(cryptState)) {
246 Slog.w(TAG, "Device encrypted - only parsing core apps");
247 onlyCore = true;
Ben Komalo553acf02011-09-19 14:25:28 -0700248 }
Ben Komalo3573d402011-09-23 15:08:24 -0700249
Jeff Brownf69c8122012-09-12 17:00:34 -0700250 pm = PackageManagerService.main(context, installer,
Dianne Hackbornd2509fd2011-09-12 12:29:43 -0700251 factoryTest != SystemServer.FACTORY_TEST_OFF,
Ben Komalo553acf02011-09-19 14:25:28 -0700252 onlyCore);
Dianne Hackborn58f42a52011-10-10 13:46:34 -0700253 boolean firstBoot = false;
254 try {
255 firstBoot = pm.isFirstBoot();
256 } catch (RemoteException e) {
257 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800258
259 ActivityManagerService.setSystemProcess();
Amith Yamasani258848d2012-08-10 17:06:33 -0700260
261 Slog.i(TAG, "User Service");
262 ServiceManager.addService(Context.USER_SERVICE,
Dianne Hackborn4428e172012-08-24 17:43:05 -0700263 UserManagerService.getInstance());
Amith Yamasani258848d2012-08-10 17:06:33 -0700264
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800265
266 mContentResolver = context.getContentResolver();
267
Fred Quintanae91ebe22009-09-29 20:44:30 -0700268 // The AccountManager must come before the ContentService
Fred Quintana60307342009-03-24 22:48:12 -0700269 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800270 Slog.i(TAG, "Account Manager");
Kenny Root26ff6622012-07-30 12:58:03 -0700271 accountManager = new AccountManagerService(context);
272 ServiceManager.addService(Context.ACCOUNT_SERVICE, accountManager);
Fred Quintana60307342009-03-24 22:48:12 -0700273 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800274 Slog.e(TAG, "Failure starting Account Manager", e);
Fred Quintana60307342009-03-24 22:48:12 -0700275 }
276
Joe Onorato8a9b2202010-02-26 18:56:32 -0800277 Slog.i(TAG, "Content Manager");
Kenny Root26ff6622012-07-30 12:58:03 -0700278 contentService = ContentService.main(context,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800279 factoryTest == SystemServer.FACTORY_TEST_LOW_LEVEL);
280
Joe Onorato8a9b2202010-02-26 18:56:32 -0800281 Slog.i(TAG, "System Content Providers");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800282 ActivityManagerService.installSystemProviders();
283
Joe Onorato8a9b2202010-02-26 18:56:32 -0800284 Slog.i(TAG, "Lights Service");
Mike Lockwood3a322132009-11-24 00:30:52 -0500285 lights = new LightsService(context);
286
Joe Onoratode1b3592010-10-25 20:36:47 -0700287 Slog.i(TAG, "Battery Service");
288 battery = new BatteryService(context, lights);
289 ServiceManager.addService("battery", battery);
290
Joe Onorato8a9b2202010-02-26 18:56:32 -0800291 Slog.i(TAG, "Vibrator Service");
Jeff Brown7f6c2312012-04-13 20:38:38 -0700292 vibrator = new VibratorService(context);
293 ServiceManager.addService("vibrator", vibrator);
The Android Open Source Project10592532009-03-18 17:39:46 -0700294
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800295 // only initialize the power service after we have started the
Mike Lockwood3a322132009-11-24 00:30:52 -0500296 // lights service, content providers and the battery service.
Jeff Brown96307042012-07-27 15:51:34 -0700297 power.init(context, lights, ActivityManagerService.self(), battery,
298 BatteryStatsService.getService(), display);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800299
Joe Onorato8a9b2202010-02-26 18:56:32 -0800300 Slog.i(TAG, "Alarm Manager");
Jeff Sharkey75279902011-05-24 18:39:45 -0700301 alarm = new AlarmManagerService(context);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800302 ServiceManager.addService(Context.ALARM_SERVICE, alarm);
303
Joe Onorato8a9b2202010-02-26 18:56:32 -0800304 Slog.i(TAG, "Init Watchdog");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800305 Watchdog.getInstance().init(context, battery, power, alarm,
306 ActivityManagerService.self());
307
Jeff Browna9d131c2012-09-20 16:48:17 -0700308 Slog.i(TAG, "Input Manager");
309 inputManager = new InputManagerService(context, wmHandler);
310
Joe Onorato8a9b2202010-02-26 18:56:32 -0800311 Slog.i(TAG, "Window Manager");
Jeff Browna9d131c2012-09-20 16:48:17 -0700312 wm = WindowManagerService.main(context, power, display, inputManager,
Jeff Brownbd6e1502012-08-28 03:27:37 -0700313 uiHandler, wmHandler,
Dianne Hackborn58f42a52011-10-10 13:46:34 -0700314 factoryTest != SystemServer.FACTORY_TEST_LOW_LEVEL,
Jeff Brown780c46f2012-06-24 12:15:38 -0700315 !firstBoot, onlyCore);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800316 ServiceManager.addService(Context.WINDOW_SERVICE, wm);
Jeff Brown6ec6f792012-04-17 16:52:41 -0700317 ServiceManager.addService(Context.INPUT_SERVICE, inputManager);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800318
Dianne Hackborn295e3c22011-08-25 13:19:08 -0700319 ActivityManagerService.self().setWindowManager(wm);
Jeff Browna9d131c2012-09-20 16:48:17 -0700320
321 inputManager.setWindowManagerCallbacks(wm.getInputMonitor());
322 inputManager.start();
323
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700324 display.setWindowManager(wm);
Jeff Brownd728bf52012-09-08 18:05:28 -0700325 display.setInputManager(inputManager);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800326
327 // Skip Bluetooth if we have an emulator kernel
328 // TODO: Use a more reliable check to see if this product should
329 // support Bluetooth - see bug 988521
330 if (SystemProperties.get("ro.kernel.qemu").equals("1")) {
David 'Digit' Turnere2a5e862011-01-17 00:32:33 +0100331 Slog.i(TAG, "No Bluetooh Service (emulator)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800332 } else if (factoryTest == SystemServer.FACTORY_TEST_LOW_LEVEL) {
David 'Digit' Turnere2a5e862011-01-17 00:32:33 +0100333 Slog.i(TAG, "No Bluetooth Service (factory test)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800334 } else {
fredc0f420372012-04-12 00:02:00 -0700335 Slog.i(TAG, "Bluetooth Manager Service");
336 bluetooth = new BluetoothManagerService(context);
337 ServiceManager.addService(BluetoothAdapter.BLUETOOTH_MANAGER_SERVICE, bluetooth);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800338 }
339
340 } catch (RuntimeException e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700341 Slog.e("System", "******************************************");
342 Slog.e("System", "************ Failure starting core service", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800343 }
344
Dianne Hackbornd6847842010-01-12 18:14:19 -0800345 DevicePolicyManagerService devicePolicy = null;
Joe Onorato089de882010-04-12 08:18:45 -0700346 StatusBarManagerService statusBar = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800347 InputMethodManagerService imm = null;
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700348 AppWidgetService appWidget = null;
Joe Onorato30275482009-07-08 17:09:14 -0700349 NotificationManagerService notification = null;
Dianne Hackbornf21adf62009-08-13 10:20:21 -0700350 WallpaperManagerService wallpaper = null;
Mike Lockwood46db5042010-02-22 16:36:44 -0500351 LocationManagerService location = null;
Bai Taoa58a8752010-07-13 15:32:16 +0800352 CountryDetectorService countryDetector = null;
satok988323c2011-06-22 16:38:13 +0900353 TextServicesManagerService tsms = null;
Amith Yamasani52c489c2012-03-28 11:42:42 -0700354 LockSettingsService lockSettings = null;
Daniel Sandler7d276c32012-01-30 14:33:52 -0500355 DreamManagerService dreamy = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800356
Dianne Hackborn661cd522011-08-22 00:26:20 -0700357 // Bring up services needed for UI.
358 if (factoryTest != SystemServer.FACTORY_TEST_LOW_LEVEL) {
359 try {
360 Slog.i(TAG, "Input Method Service");
satok01038492012-04-09 21:08:27 +0900361 imm = new InputMethodManagerService(context, wm);
Dianne Hackborn661cd522011-08-22 00:26:20 -0700362 ServiceManager.addService(Context.INPUT_METHOD_SERVICE, imm);
363 } catch (Throwable e) {
364 reportWtf("starting Input Manager Service", e);
365 }
366
367 try {
368 Slog.i(TAG, "Accessibility Manager");
369 ServiceManager.addService(Context.ACCESSIBILITY_SERVICE,
370 new AccessibilityManagerService(context));
371 } catch (Throwable e) {
372 reportWtf("starting Accessibility Manager", e);
373 }
374 }
375
376 try {
377 wm.displayReady();
378 } catch (Throwable e) {
379 reportWtf("making display ready", e);
380 }
Dianne Hackborn8795b602011-08-25 13:30:53 -0700381
Dianne Hackborn295e3c22011-08-25 13:19:08 -0700382 try {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700383 pm.performBootDexOpt();
384 } catch (Throwable e) {
385 reportWtf("performing boot dexopt", e);
386 }
387
388 try {
389 ActivityManagerNative.getDefault().showBootMessage(
390 context.getResources().getText(
391 com.android.internal.R.string.android_upgrading_starting_apps),
392 false);
393 } catch (RemoteException e) {
394 }
395
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800396 if (factoryTest != SystemServer.FACTORY_TEST_LOW_LEVEL) {
Kenny Root51a573c2012-05-17 13:30:28 -0700397 if (!"0".equals(SystemProperties.get("system_init.startmountservice"))) {
398 try {
399 /*
400 * NotificationManagerService is dependant on MountService,
401 * (for media / usb notifications) so we must start MountService first.
402 */
403 Slog.i(TAG, "Mount Service");
404 mountService = new MountService(context);
405 ServiceManager.addService("mount", mountService);
406 } catch (Throwable e) {
407 reportWtf("starting Mount Service", e);
408 }
409 }
410
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800411 try {
Amith Yamasani52c489c2012-03-28 11:42:42 -0700412 Slog.i(TAG, "LockSettingsService");
413 lockSettings = new LockSettingsService(context);
414 ServiceManager.addService("lock_settings", lockSettings);
415 } catch (Throwable e) {
416 reportWtf("starting LockSettingsService service", e);
417 }
418
419 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800420 Slog.i(TAG, "Device Policy");
Dianne Hackbornd6847842010-01-12 18:14:19 -0800421 devicePolicy = new DevicePolicyManagerService(context);
422 ServiceManager.addService(Context.DEVICE_POLICY_SERVICE, devicePolicy);
423 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700424 reportWtf("starting DevicePolicyService", e);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800425 }
426
427 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800428 Slog.i(TAG, "Status Bar");
Jeff Brown2992ea72011-01-28 22:04:14 -0800429 statusBar = new StatusBarManagerService(context, wm);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800430 ServiceManager.addService(Context.STATUS_BAR_SERVICE, statusBar);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800431 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700432 reportWtf("starting StatusBarManagerService", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800433 }
434
435 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800436 Slog.i(TAG, "Clipboard Service");
Dianne Hackbornd6847842010-01-12 18:14:19 -0800437 ServiceManager.addService(Context.CLIPBOARD_SERVICE,
438 new ClipboardService(context));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800439 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700440 reportWtf("starting Clipboard Service", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800441 }
442
443 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800444 Slog.i(TAG, "NetworkManagement Service");
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -0700445 networkManagement = NetworkManagementService.create(context);
446 ServiceManager.addService(Context.NETWORKMANAGEMENT_SERVICE, networkManagement);
San Mehatd1df8ac2010-01-26 06:17:26 -0800447 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700448 reportWtf("starting NetworkManagement Service", e);
San Mehatd1df8ac2010-01-26 06:17:26 -0800449 }
450
451 try {
satok988323c2011-06-22 16:38:13 +0900452 Slog.i(TAG, "Text Service Manager Service");
453 tsms = new TextServicesManagerService(context);
454 ServiceManager.addService(Context.TEXT_SERVICES_MANAGER_SERVICE, tsms);
455 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700456 reportWtf("starting Text Service Manager Service", e);
satok988323c2011-06-22 16:38:13 +0900457 }
458
459 try {
Jeff Sharkey75279902011-05-24 18:39:45 -0700460 Slog.i(TAG, "NetworkStats Service");
461 networkStats = new NetworkStatsService(context, networkManagement, alarm);
462 ServiceManager.addService(Context.NETWORK_STATS_SERVICE, networkStats);
463 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700464 reportWtf("starting NetworkStats Service", e);
Jeff Sharkey75279902011-05-24 18:39:45 -0700465 }
466
467 try {
468 Slog.i(TAG, "NetworkPolicy Service");
469 networkPolicy = new NetworkPolicyManagerService(
Ashish Sharma50fd36d2011-06-15 19:34:53 -0700470 context, ActivityManagerService.self(), power,
471 networkStats, networkManagement);
Jeff Sharkey75279902011-05-24 18:39:45 -0700472 ServiceManager.addService(Context.NETWORK_POLICY_SERVICE, networkPolicy);
473 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700474 reportWtf("starting NetworkPolicy Service", e);
Jeff Sharkey75279902011-05-24 18:39:45 -0700475 }
476
repo sync55bc5f32011-06-24 14:23:07 -0700477 try {
478 Slog.i(TAG, "Wi-Fi P2pService");
479 wifiP2p = new WifiP2pService(context);
480 ServiceManager.addService(Context.WIFI_P2P_SERVICE, wifiP2p);
481 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700482 reportWtf("starting Wi-Fi P2pService", e);
repo sync55bc5f32011-06-24 14:23:07 -0700483 }
484
repo syncaea743a2011-07-29 23:55:49 -0700485 try {
486 Slog.i(TAG, "Wi-Fi Service");
487 wifi = new WifiService(context);
488 ServiceManager.addService(Context.WIFI_SERVICE, wifi);
repo syncaea743a2011-07-29 23:55:49 -0700489 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700490 reportWtf("starting Wi-Fi Service", e);
repo syncaea743a2011-07-29 23:55:49 -0700491 }
492
Jeff Sharkey75279902011-05-24 18:39:45 -0700493 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800494 Slog.i(TAG, "Connectivity Service");
Jeff Sharkey367d15a2011-09-22 14:59:51 -0700495 connectivity = new ConnectivityService(
496 context, networkManagement, networkStats, networkPolicy);
Mike Lockwood0f79b542009-08-14 14:18:49 -0400497 ServiceManager.addService(Context.CONNECTIVITY_SERVICE, connectivity);
Jeff Sharkeyd2a45872011-05-28 20:56:34 -0700498 networkStats.bindConnectivityManager(connectivity);
Jeff Sharkey21c9c452011-06-07 12:26:43 -0700499 networkPolicy.bindConnectivityManager(connectivity);
Robert Greenwalt9b2886e2011-08-31 11:46:42 -0700500 wifi.checkAndStartWifi();
Irfan Sheriffcb30b222011-07-29 20:54:52 -0700501 wifiP2p.connectivityServiceReady();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800502 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700503 reportWtf("starting Connectivity Service", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800504 }
505
506 try {
Irfan Sheriff7d024d32012-03-22 17:01:39 -0700507 Slog.i(TAG, "Network Service Discovery Service");
508 serviceDiscovery = NsdService.create(context);
509 ServiceManager.addService(
510 Context.NSD_SERVICE, serviceDiscovery);
511 } catch (Throwable e) {
512 reportWtf("starting Service Discovery Service", e);
513 }
514
515 try {
Robert Greenwalt9e696c22010-04-01 14:45:18 -0700516 Slog.i(TAG, "Throttle Service");
517 throttle = new ThrottleService(context);
518 ServiceManager.addService(
519 Context.THROTTLE_SERVICE, throttle);
520 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700521 reportWtf("starting ThrottleService", e);
svetoslavganov75986cf2009-05-14 22:28:01 -0700522 }
523
Christopher Tate8662cab52012-02-23 14:59:36 -0800524 try {
525 Slog.i(TAG, "UpdateLock Service");
526 ServiceManager.addService(Context.UPDATE_LOCK_SERVICE,
527 new UpdateLockService(context));
528 } catch (Throwable e) {
529 reportWtf("starting UpdateLockService", e);
530 }
531
Kenny Root51a573c2012-05-17 13:30:28 -0700532 /*
533 * MountService has a few dependencies: Notification Manager and
534 * AppWidget Provider. Make sure MountService is completely started
535 * first before continuing.
536 */
537 if (mountService != null) {
538 mountService.waitForAsecScan();
San Mehat1bf3f8b2010-02-03 14:43:09 -0800539 }
540
541 try {
Kenny Root26ff6622012-07-30 12:58:03 -0700542 if (accountManager != null)
543 accountManager.systemReady();
544 } catch (Throwable e) {
545 reportWtf("making Account Manager Service ready", e);
546 }
547
548 try {
549 if (contentService != null)
550 contentService.systemReady();
551 } catch (Throwable e) {
552 reportWtf("making Content Service ready", e);
553 }
554
555 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800556 Slog.i(TAG, "Notification Manager");
Mike Lockwood3a322132009-11-24 00:30:52 -0500557 notification = new NotificationManagerService(context, statusBar, lights);
Joe Onorato30275482009-07-08 17:09:14 -0700558 ServiceManager.addService(Context.NOTIFICATION_SERVICE, notification);
Jeff Sharkey497e4432011-06-14 17:27:29 -0700559 networkPolicy.bindNotificationManager(notification);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800560 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700561 reportWtf("starting Notification Manager", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800562 }
563
564 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800565 Slog.i(TAG, "Device Storage Monitor");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800566 ServiceManager.addService(DeviceStorageMonitorService.SERVICE,
567 new DeviceStorageMonitorService(context));
568 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700569 reportWtf("starting DeviceStorageMonitor service", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800570 }
571
572 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800573 Slog.i(TAG, "Location Manager");
Mike Lockwood46db5042010-02-22 16:36:44 -0500574 location = new LocationManagerService(context);
575 ServiceManager.addService(Context.LOCATION_SERVICE, location);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800576 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700577 reportWtf("starting Location Manager", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800578 }
579
580 try {
Bai Taoa58a8752010-07-13 15:32:16 +0800581 Slog.i(TAG, "Country Detector");
582 countryDetector = new CountryDetectorService(context);
583 ServiceManager.addService(Context.COUNTRY_DETECTOR, countryDetector);
584 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700585 reportWtf("starting Country Detector", e);
Bai Taoa58a8752010-07-13 15:32:16 +0800586 }
587
588 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800589 Slog.i(TAG, "Search Service");
Dianne Hackbornd6847842010-01-12 18:14:19 -0800590 ServiceManager.addService(Context.SEARCH_SERVICE,
591 new SearchManagerService(context));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800592 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700593 reportWtf("starting Search Service", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800594 }
595
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800596 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800597 Slog.i(TAG, "DropBox Service");
Dan Egnor95240272009-10-27 18:23:39 -0700598 ServiceManager.addService(Context.DROPBOX_SERVICE,
Dan Egnorf18a01c2009-11-12 11:32:50 -0800599 new DropBoxManagerService(context, new File("/data/system/dropbox")));
Dan Egnor4410ec82009-09-11 16:40:01 -0700600 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700601 reportWtf("starting DropBoxManagerService", e);
Dan Egnor4410ec82009-09-11 16:40:01 -0700602 }
603
Mike Lockwoodc067c9c2011-10-31 12:50:12 -0400604 if (context.getResources().getBoolean(
605 com.android.internal.R.bool.config_enableWallpaperService)) {
606 try {
607 Slog.i(TAG, "Wallpaper Service");
608 if (!headless) {
609 wallpaper = new WallpaperManagerService(context);
610 ServiceManager.addService(Context.WALLPAPER_SERVICE, wallpaper);
611 }
612 } catch (Throwable e) {
613 reportWtf("starting Wallpaper Service", e);
Mike Lockwood3a74bd32011-08-12 13:55:22 -0700614 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800615 }
616
Mike Lockwoodcba928c2011-08-17 15:58:52 -0700617 if (!"0".equals(SystemProperties.get("system_init.startaudioservice"))) {
618 try {
619 Slog.i(TAG, "Audio Service");
620 ServiceManager.addService(Context.AUDIO_SERVICE, new AudioService(context));
621 } catch (Throwable e) {
622 reportWtf("starting Audio Service", e);
623 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800624 }
625
626 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800627 Slog.i(TAG, "Dock Observer");
Dan Murphyc9f4eaf2009-08-12 15:15:43 -0500628 // Listen for dock station changes
Jeff Brown96307042012-07-27 15:51:34 -0700629 dock = new DockObserver(context);
Dan Murphyc9f4eaf2009-08-12 15:15:43 -0500630 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700631 reportWtf("starting DockObserver", e);
Dan Murphyc9f4eaf2009-08-12 15:15:43 -0500632 }
633
634 try {
Craig Mautner2f39e9f2012-09-21 11:39:54 -0700635 Slog.i(TAG, "Wired Accessory Manager");
Praveen Bharathi21e941b2010-10-06 15:23:14 -0500636 // Listen for wired headset changes
Craig Mautner2f39e9f2012-09-21 11:39:54 -0700637 inputManager.setWiredAccessoryCallbacks(
638 new WiredAccessoryManager(context, inputManager));
Praveen Bharathi21e941b2010-10-06 15:23:14 -0500639 } catch (Throwable e) {
Craig Mautner2f39e9f2012-09-21 11:39:54 -0700640 reportWtf("starting WiredAccessoryManager", e);
Praveen Bharathi21e941b2010-10-06 15:23:14 -0500641 }
642
643 try {
Mike Lockwood02e45692011-06-14 15:43:51 -0400644 Slog.i(TAG, "USB Service");
645 // Manage USB host and device support
Mike Lockwood770126a2010-12-09 22:30:37 -0800646 usb = new UsbService(context);
Mike Lockwoode7d511e2010-12-30 13:39:37 -0500647 ServiceManager.addService(Context.USB_SERVICE, usb);
Mike Lockwood57c798a2010-06-23 17:36:36 -0400648 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700649 reportWtf("starting UsbService", e);
Mike Lockwood57c798a2010-06-23 17:36:36 -0400650 }
651
652 try {
Mike Lockwoodb01e8bf2011-08-29 20:11:07 -0400653 Slog.i(TAG, "Serial Service");
654 // Serial port support
655 serial = new SerialService(context);
656 ServiceManager.addService(Context.SERIAL_SERVICE, serial);
657 } catch (Throwable e) {
658 Slog.e(TAG, "Failure starting SerialService", e);
659 }
660
661 try {
Jeff Brown2416e092012-08-21 22:12:20 -0700662 Slog.i(TAG, "Twilight Service");
663 twilight = new TwilightService(context);
664 } catch (Throwable e) {
665 reportWtf("starting TwilightService", e);
666 }
667
668 try {
Dianne Hackborn7299c412010-03-04 18:41:49 -0800669 Slog.i(TAG, "UI Mode Manager Service");
Mike Lockwood57c798a2010-06-23 17:36:36 -0400670 // Listen for UI mode changes
Jeff Brown2416e092012-08-21 22:12:20 -0700671 uiMode = new UiModeManagerService(context, twilight);
Dianne Hackborn7299c412010-03-04 18:41:49 -0800672 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700673 reportWtf("starting UiModeManagerService", e);
Dianne Hackborn7299c412010-03-04 18:41:49 -0800674 }
675
676 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800677 Slog.i(TAG, "Backup Service");
Dianne Hackbornd6847842010-01-12 18:14:19 -0800678 ServiceManager.addService(Context.BACKUP_SERVICE,
679 new BackupManagerService(context));
Christopher Tate487529a2009-04-29 14:03:25 -0700680 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800681 Slog.e(TAG, "Failure starting Backup Service", e);
Christopher Tate487529a2009-04-29 14:03:25 -0700682 }
683
684 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800685 Slog.i(TAG, "AppWidget Service");
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700686 appWidget = new AppWidgetService(context);
687 ServiceManager.addService(Context.APPWIDGET_SERVICE, appWidget);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800688 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700689 reportWtf("starting AppWidget Service", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800690 }
691
692 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800693 Slog.i(TAG, "Recognition Service");
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800694 recognition = new RecognitionManagerService(context);
695 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700696 reportWtf("starting Recognition Service", e);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800697 }
Jaikumar Ganesh7d0548d2010-10-18 15:29:09 -0700698
Nick Pelly038cabe2010-09-23 16:12:11 -0700699 try {
Dan Egnor621bc542010-03-25 16:20:14 -0700700 Slog.i(TAG, "DiskStats Service");
701 ServiceManager.addService("diskstats", new DiskStatsService(context));
702 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700703 reportWtf("starting DiskStats Service", e);
Dan Egnor621bc542010-03-25 16:20:14 -0700704 }
Sen Hubde75702010-05-28 01:54:03 -0700705
706 try {
707 // need to add this service even if SamplingProfilerIntegration.isEnabled()
708 // is false, because it is this service that detects system property change and
709 // turns on SamplingProfilerIntegration. Plus, when sampling profiler doesn't work,
710 // there is little overhead for running this service.
711 Slog.i(TAG, "SamplingProfiler Service");
712 ServiceManager.addService("samplingprofiler",
713 new SamplingProfilerService(context));
714 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700715 reportWtf("starting SamplingProfiler Service", e);
Sen Hubde75702010-05-28 01:54:03 -0700716 }
Chung-yih Wang024d5962010-08-06 12:06:04 +0800717
718 try {
Amith Yamasani6734b9f2010-09-13 16:24:08 -0700719 Slog.i(TAG, "NetworkTimeUpdateService");
720 networkTimeUpdater = new NetworkTimeUpdateService(context);
721 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700722 reportWtf("starting NetworkTimeUpdate service", e);
Amith Yamasani6734b9f2010-09-13 16:24:08 -0700723 }
John Grossmanc1576732012-02-01 15:23:33 -0800724
725 try {
726 Slog.i(TAG, "CommonTimeManagementService");
727 commonTimeMgmtService = new CommonTimeManagementService(context);
728 ServiceManager.addService("commontime_management", commonTimeMgmtService);
729 } catch (Throwable e) {
730 reportWtf("starting CommonTimeManagementService service", e);
731 }
Geremy Condra3d33c262012-05-06 18:32:19 -0700732
733 try {
734 Slog.i(TAG, "CertBlacklister");
735 CertBlacklister blacklister = new CertBlacklister(context);
736 } catch (Throwable e) {
737 reportWtf("starting CertBlacklister", e);
738 }
Daniel Sandler7d276c32012-01-30 14:33:52 -0500739
740 if (context.getResources().getBoolean(
John Spurlocked108f32012-10-18 16:49:24 -0400741 com.android.internal.R.bool.config_dreamsSupported)) {
Daniel Sandler7d276c32012-01-30 14:33:52 -0500742 try {
743 Slog.i(TAG, "Dreams Service");
744 // Dreams (interactive idle-time views, a/k/a screen savers)
Jeff Brown62c82e42012-09-26 01:30:41 -0700745 dreamy = new DreamManagerService(context, wmHandler);
Dianne Hackbornbe87e2f2012-09-28 16:31:34 -0700746 ServiceManager.addService(DreamService.DREAM_SERVICE, dreamy);
Daniel Sandler7d276c32012-01-30 14:33:52 -0500747 } catch (Throwable e) {
748 reportWtf("starting DreamManagerService", e);
749 }
750 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800751 }
752
Dianne Hackborn6af0d502009-09-28 13:25:46 -0700753 // Before things start rolling, be sure we have decided whether
754 // we are in safe mode.
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700755 final boolean safeMode = wm.detectSafeMode();
Dianne Hackborn6af0d502009-09-28 13:25:46 -0700756 if (safeMode) {
Jeff Brownb09abc12011-01-13 21:08:27 -0800757 ActivityManagerService.self().enterSafeMode();
758 // Post the safe mode state in the Zygote class
759 Zygote.systemInSafeMode = true;
760 // Disable the JIT for the system_server process
761 VMRuntime.getRuntime().disableJitCompilation();
Ben Cheng6c0afff2010-02-14 16:18:56 -0800762 } else {
763 // Enable the JIT for the system_server process
764 VMRuntime.getRuntime().startJitCompilation();
Dianne Hackborn6af0d502009-09-28 13:25:46 -0700765 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800766
Dianne Hackborn6af0d502009-09-28 13:25:46 -0700767 // It is now time to start up the app processes...
Joe Onorato30275482009-07-08 17:09:14 -0700768
Jeff Brown7f6c2312012-04-13 20:38:38 -0700769 try {
770 vibrator.systemReady();
771 } catch (Throwable e) {
772 reportWtf("making Vibrator Service ready", e);
773 }
774
Felipe Ramosf35df5b2012-09-18 18:26:27 -0300775 try {
776 lockSettings.systemReady();
777 } catch (Throwable e) {
778 reportWtf("making Lock Settings Service ready", e);
779 }
780
Dianne Hackbornd6847842010-01-12 18:14:19 -0800781 if (devicePolicy != null) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700782 try {
783 devicePolicy.systemReady();
784 } catch (Throwable e) {
785 reportWtf("making Device Policy Service ready", e);
786 }
Dianne Hackbornd6847842010-01-12 18:14:19 -0800787 }
788
Joe Onorato30275482009-07-08 17:09:14 -0700789 if (notification != null) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700790 try {
791 notification.systemReady();
792 } catch (Throwable e) {
793 reportWtf("making Notification Service ready", e);
794 }
Joe Onorato30275482009-07-08 17:09:14 -0700795 }
796
Dianne Hackborn661cd522011-08-22 00:26:20 -0700797 try {
798 wm.systemReady();
799 } catch (Throwable e) {
800 reportWtf("making Window Manager Service ready", e);
801 }
Joe Onoratodc565f42010-10-04 15:27:22 -0400802
Jeff Brownb09abc12011-01-13 21:08:27 -0800803 if (safeMode) {
804 ActivityManagerService.self().showSafeModeOverlay();
805 }
806
Joe Onoratodc565f42010-10-04 15:27:22 -0400807 // Update the configuration for this context by hand, because we're going
808 // to start using it before the config change done in wm.systemReady() will
809 // propagate to it.
810 Configuration config = wm.computeNewConfiguration();
811 DisplayMetrics metrics = new DisplayMetrics();
812 WindowManager w = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
813 w.getDefaultDisplay().getMetrics(metrics);
814 context.getResources().updateConfiguration(config, metrics);
815
Jeff Brownaa202a62012-08-21 22:14:26 -0700816 try {
Jeff Brown62c82e42012-09-26 01:30:41 -0700817 power.systemReady(twilight, dreamy);
Jeff Brownaa202a62012-08-21 22:14:26 -0700818 } catch (Throwable e) {
819 reportWtf("making Power Manager Service ready", e);
820 }
821
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800822 try {
823 pm.systemReady();
Dianne Hackborn661cd522011-08-22 00:26:20 -0700824 } catch (Throwable e) {
825 reportWtf("making Package Manager Service ready", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800826 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800827
Jeff Brownbd6e1502012-08-28 03:27:37 -0700828 try {
829 display.systemReady(safeMode, onlyCore);
830 } catch (Throwable e) {
831 reportWtf("making Display Manager Service ready", e);
832 }
833
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700834 // These are needed to propagate to the runnable below.
Joe Onoratof3c3c4f2010-10-21 11:09:02 -0400835 final Context contextF = context;
Jeff Sharkeyb049e212012-09-07 23:16:01 -0700836 final MountService mountServiceF = mountService;
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700837 final BatteryService batteryF = battery;
Jeff Sharkey350083e2011-06-29 10:45:16 -0700838 final NetworkManagementService networkManagementF = networkManagement;
Jeff Sharkey75279902011-05-24 18:39:45 -0700839 final NetworkStatsService networkStatsF = networkStats;
Jeff Sharkeya4620792011-05-20 15:29:23 -0700840 final NetworkPolicyManagerService networkPolicyF = networkPolicy;
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700841 final ConnectivityService connectivityF = connectivity;
842 final DockObserver dockF = dock;
Mike Lockwood770126a2010-12-09 22:30:37 -0800843 final UsbService usbF = usb;
Robert Greenwalt9e696c22010-04-01 14:45:18 -0700844 final ThrottleService throttleF = throttle;
Jeff Brown2416e092012-08-21 22:12:20 -0700845 final TwilightService twilightF = twilight;
Dianne Hackborn7299c412010-03-04 18:41:49 -0800846 final UiModeManagerService uiModeF = uiMode;
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700847 final AppWidgetService appWidgetF = appWidget;
848 final WallpaperManagerService wallpaperF = wallpaper;
849 final InputMethodManagerService immF = imm;
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800850 final RecognitionManagerService recognitionF = recognition;
Mike Lockwood46db5042010-02-22 16:36:44 -0500851 final LocationManagerService locationF = location;
Bai Taoa58a8752010-07-13 15:32:16 +0800852 final CountryDetectorService countryDetectorF = countryDetector;
Amith Yamasani6734b9f2010-09-13 16:24:08 -0700853 final NetworkTimeUpdateService networkTimeUpdaterF = networkTimeUpdater;
John Grossmanc1576732012-02-01 15:23:33 -0800854 final CommonTimeManagementService commonTimeMgmtServiceF = commonTimeMgmtService;
satok988323c2011-06-22 16:38:13 +0900855 final TextServicesManagerService textServiceManagerServiceF = tsms;
Dianne Hackborn661cd522011-08-22 00:26:20 -0700856 final StatusBarManagerService statusBarF = statusBar;
Daniel Sandler7d276c32012-01-30 14:33:52 -0500857 final DreamManagerService dreamyF = dreamy;
Jeff Brown6ec6f792012-04-17 16:52:41 -0700858 final InputManagerService inputManagerF = inputManager;
Wink Savillea12a7b32012-09-20 10:09:45 -0700859 final TelephonyRegistry telephonyRegistryF = telephonyRegistry;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800860
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700861 // We now tell the activity manager it is okay to run third party
862 // code. It will call back into us once it has gotten to the state
863 // where third party code can really run (but before it has actually
864 // started launching the initial applications), for us to complete our
865 // initialization.
Dianne Hackborn295e3c22011-08-25 13:19:08 -0700866 ActivityManagerService.self().systemReady(new Runnable() {
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700867 public void run() {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800868 Slog.i(TAG, "Making services ready");
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800869
Mike Lockwood3a74bd32011-08-12 13:55:22 -0700870 if (!headless) startSystemUi(contextF);
Dianne Hackborn661cd522011-08-22 00:26:20 -0700871 try {
Jeff Sharkeyb049e212012-09-07 23:16:01 -0700872 if (mountServiceF != null) mountServiceF.systemReady();
873 } catch (Throwable e) {
874 reportWtf("making Mount Service ready", e);
875 }
876 try {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700877 if (batteryF != null) batteryF.systemReady();
878 } catch (Throwable e) {
879 reportWtf("making Battery Service ready", e);
880 }
881 try {
882 if (networkManagementF != null) networkManagementF.systemReady();
883 } catch (Throwable e) {
884 reportWtf("making Network Managment Service ready", e);
885 }
886 try {
887 if (networkStatsF != null) networkStatsF.systemReady();
888 } catch (Throwable e) {
889 reportWtf("making Network Stats Service ready", e);
890 }
891 try {
892 if (networkPolicyF != null) networkPolicyF.systemReady();
893 } catch (Throwable e) {
894 reportWtf("making Network Policy Service ready", e);
895 }
896 try {
897 if (connectivityF != null) connectivityF.systemReady();
898 } catch (Throwable e) {
899 reportWtf("making Connectivity Service ready", e);
900 }
901 try {
902 if (dockF != null) dockF.systemReady();
903 } catch (Throwable e) {
904 reportWtf("making Dock Service ready", e);
905 }
906 try {
907 if (usbF != null) usbF.systemReady();
908 } catch (Throwable e) {
909 reportWtf("making USB Service ready", e);
910 }
911 try {
Jeff Brown2416e092012-08-21 22:12:20 -0700912 if (twilightF != null) twilightF.systemReady();
913 } catch (Throwable e) {
914 reportWtf("makin Twilight Service ready", e);
915 }
916 try {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700917 if (uiModeF != null) uiModeF.systemReady();
918 } catch (Throwable e) {
919 reportWtf("making UI Mode Service ready", e);
920 }
921 try {
922 if (recognitionF != null) recognitionF.systemReady();
923 } catch (Throwable e) {
924 reportWtf("making Recognition Service ready", e);
925 }
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700926 Watchdog.getInstance().start();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800927
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700928 // It is now okay to let the various system services start their
929 // third party code...
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800930
Dianne Hackborn661cd522011-08-22 00:26:20 -0700931 try {
932 if (appWidgetF != null) appWidgetF.systemReady(safeMode);
933 } catch (Throwable e) {
934 reportWtf("making App Widget Service ready", e);
935 }
936 try {
937 if (wallpaperF != null) wallpaperF.systemReady();
938 } catch (Throwable e) {
939 reportWtf("making Wallpaper Service ready", e);
940 }
941 try {
942 if (immF != null) immF.systemReady(statusBarF);
943 } catch (Throwable e) {
944 reportWtf("making Input Method Service ready", e);
945 }
946 try {
947 if (locationF != null) locationF.systemReady();
948 } catch (Throwable e) {
949 reportWtf("making Location Service ready", e);
950 }
951 try {
952 if (countryDetectorF != null) countryDetectorF.systemReady();
953 } catch (Throwable e) {
954 reportWtf("making Country Detector Service ready", e);
955 }
956 try {
957 if (throttleF != null) throttleF.systemReady();
958 } catch (Throwable e) {
959 reportWtf("making Throttle Service ready", e);
960 }
961 try {
962 if (networkTimeUpdaterF != null) networkTimeUpdaterF.systemReady();
963 } catch (Throwable e) {
964 reportWtf("making Network Time Service ready", e);
965 }
966 try {
John Grossmanc1576732012-02-01 15:23:33 -0800967 if (commonTimeMgmtServiceF != null) commonTimeMgmtServiceF.systemReady();
968 } catch (Throwable e) {
969 reportWtf("making Common time management service ready", e);
970 }
971 try {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700972 if (textServiceManagerServiceF != null) textServiceManagerServiceF.systemReady();
973 } catch (Throwable e) {
974 reportWtf("making Text Services Manager Service ready", e);
975 }
Daniel Sandler7d276c32012-01-30 14:33:52 -0500976 try {
977 if (dreamyF != null) dreamyF.systemReady();
978 } catch (Throwable e) {
979 reportWtf("making DreamManagerService ready", e);
980 }
Jeff Brown6ec6f792012-04-17 16:52:41 -0700981 try {
Matthew Xie96313142012-06-29 16:57:31 -0700982 // TODO(BT) Pass parameter to input manager
983 if (inputManagerF != null) inputManagerF.systemReady();
Jeff Brown6ec6f792012-04-17 16:52:41 -0700984 } catch (Throwable e) {
985 reportWtf("making InputManagerService ready", e);
986 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700987 try {
988 if (telephonyRegistryF != null) telephonyRegistryF.systemReady();
989 } catch (Throwable e) {
990 reportWtf("making TelephonyRegistry ready", e);
991 }
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700992 }
993 });
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800994
Brad Fitzpatrick1e02d362010-09-10 09:19:50 -0700995 // For debug builds, log event loop stalls to dropbox for analysis.
Brad Fitzpatrick50d66f92010-09-13 21:29:05 -0700996 if (StrictMode.conditionallyEnableDebugLogging()) {
997 Slog.i(TAG, "Enabled StrictMode for system server main thread.");
Brad Fitzpatrick1e02d362010-09-10 09:19:50 -0700998 }
999
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001000 Looper.loop();
Joe Onorato8a9b2202010-02-26 18:56:32 -08001001 Slog.d(TAG, "System ServerThread is exiting!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001002 }
Joe Onoratof3c3c4f2010-10-21 11:09:02 -04001003
1004 static final void startSystemUi(Context context) {
1005 Intent intent = new Intent();
1006 intent.setComponent(new ComponentName("com.android.systemui",
1007 "com.android.systemui.SystemUIService"));
Dianne Hackborn40e9f292012-11-27 19:12:23 -08001008 //Slog.d(TAG, "Starting service: " + intent);
Amith Yamasanicd757062012-10-19 18:23:52 -07001009 context.startServiceAsUser(intent, UserHandle.OWNER);
Joe Onoratof3c3c4f2010-10-21 11:09:02 -04001010 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001011}
1012
Jeff Hamilton35eef702010-06-09 15:45:18 -05001013public class SystemServer {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001014 private static final String TAG = "SystemServer";
1015
1016 public static final int FACTORY_TEST_OFF = 0;
1017 public static final int FACTORY_TEST_LOW_LEVEL = 1;
1018 public static final int FACTORY_TEST_HIGH_LEVEL = 2;
Jaikumar Ganeshd5ac1ae2009-05-05 22:26:12 -07001019
Bob Leee5408332009-09-04 18:31:17 -07001020 static Timer timer;
1021 static final long SNAPSHOT_INTERVAL = 60 * 60 * 1000; // 1hr
1022
Brad Fitzpatrick6bb7a4a2010-10-11 13:41:10 -07001023 // The earliest supported time. We pick one day into 1970, to
1024 // give any timezone code room without going into negative time.
1025 private static final long EARLIEST_SUPPORTED_TIME = 86400 * 1000;
1026
Jaikumar Ganeshd5ac1ae2009-05-05 22:26:12 -07001027 /**
1028 * This method is called from Zygote to initialize the system. This will cause the native
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001029 * services (SurfaceFlinger, AudioFlinger, etc..) to be started. After that it will call back
1030 * up into init2() to start the Android services.
Jaikumar Ganeshd5ac1ae2009-05-05 22:26:12 -07001031 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001032 native public static void init1(String[] args);
1033
1034 public static void main(String[] args) {
Brad Fitzpatrick6bb7a4a2010-10-11 13:41:10 -07001035 if (System.currentTimeMillis() < EARLIEST_SUPPORTED_TIME) {
Brad Fitzpatrick35ca9d82010-10-11 11:52:49 -07001036 // If a device's clock is before 1970 (before 0), a lot of
1037 // APIs crash dealing with negative numbers, notably
1038 // java.io.File#setLastModified, so instead we fake it and
1039 // hope that time from cell towers or NTP fixes it
1040 // shortly.
1041 Slog.w(TAG, "System clock is before 1970; setting to 1970.");
Brad Fitzpatrick6bb7a4a2010-10-11 13:41:10 -07001042 SystemClock.setCurrentTimeMillis(EARLIEST_SUPPORTED_TIME);
Brad Fitzpatrick35ca9d82010-10-11 11:52:49 -07001043 }
1044
Bob Leee5408332009-09-04 18:31:17 -07001045 if (SamplingProfilerIntegration.isEnabled()) {
1046 SamplingProfilerIntegration.start();
1047 timer = new Timer();
1048 timer.schedule(new TimerTask() {
1049 @Override
1050 public void run() {
Sen Hubde75702010-05-28 01:54:03 -07001051 SamplingProfilerIntegration.writeSnapshot("system_server", null);
Bob Leee5408332009-09-04 18:31:17 -07001052 }
1053 }, SNAPSHOT_INTERVAL, SNAPSHOT_INTERVAL);
1054 }
1055
Dianne Hackbornac1471a2011-02-03 13:46:06 -08001056 // Mmmmmm... more memory!
1057 dalvik.system.VMRuntime.getRuntime().clearGrowthLimit();
1058
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001059 // The system server has to run all of the time, so it needs to be
1060 // as efficient as possible with its memory usage.
1061 VMRuntime.getRuntime().setTargetHeapUtilization(0.8f);
Sen Hubde75702010-05-28 01:54:03 -07001062
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001063 System.loadLibrary("android_servers");
1064 init1(args);
1065 }
1066
1067 public static final void init2() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001068 Slog.i(TAG, "Entered the Android system server!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001069 Thread thr = new ServerThread();
1070 thr.setName("android.server.ServerThread");
1071 thr.start();
1072 }
1073}