blob: a7b502ae97dd185108c7d48c2b466bfd1e1011e7 [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
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080019import android.app.ActivityManagerNative;
Nick Pellyf242b7b2009-10-08 00:12:45 +020020import android.bluetooth.BluetoothAdapter;
Joe Onoratof3c3c4f2010-10-21 11:09:02 -040021import android.content.ComponentName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080022import android.content.ContentResolver;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080023import android.content.Context;
Joe Onoratof3c3c4f2010-10-21 11:09:02 -040024import android.content.Intent;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080025import android.content.pm.IPackageManager;
Joe Onoratodc565f42010-10-04 15:27:22 -040026import android.content.res.Configuration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080027import android.media.AudioService;
Irfan Sherifff6d09842011-08-03 15:37:08 -070028import android.net.wifi.p2p.WifiP2pService;
Jeff Brownbd6e1502012-08-28 03:27:37 -070029import android.os.Handler;
30import android.os.HandlerThread;
Jeff Hamilton35eef702010-06-09 15:45:18 -050031import android.os.Looper;
32import android.os.RemoteException;
33import android.os.ServiceManager;
Brad Fitzpatrickc74a1b442010-09-10 16:03:29 -070034import android.os.StrictMode;
Jeff Hamilton35eef702010-06-09 15:45:18 -050035import android.os.SystemClock;
36import android.os.SystemProperties;
Amith Yamasanicd757062012-10-19 18:23:52 -070037import android.os.UserHandle;
Dianne Hackbornbe87e2f2012-09-28 16:31:34 -070038import android.service.dreams.DreamService;
Joe Onoratodc565f42010-10-04 15:27:22 -040039import android.util.DisplayMetrics;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080040import android.util.EventLog;
Dianne Hackborn661cd522011-08-22 00:26:20 -070041import android.util.Log;
Joe Onorato8a9b2202010-02-26 18:56:32 -080042import android.util.Slog;
Brad Fitzpatrick5fdc0c72010-10-12 13:12:18 -070043import android.view.WindowManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080044
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -070045import com.android.internal.os.BinderInternal;
46import com.android.internal.os.SamplingProfilerIntegration;
47import com.android.server.accessibility.AccessibilityManagerService;
Jeff Sharkey7a96c392012-11-15 14:01:46 -080048import com.android.server.accounts.AccountManagerService;
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -070049import com.android.server.am.ActivityManagerService;
Jeff Brown96307042012-07-27 15:51:34 -070050import com.android.server.am.BatteryStatsService;
Jeff Sharkey7a96c392012-11-15 14:01:46 -080051import com.android.server.content.ContentService;
Jeff Brownfa25bf52012-07-23 19:26:30 -070052import com.android.server.display.DisplayManagerService;
Jeff Browncef440f2012-09-25 18:58:48 -070053import com.android.server.dreams.DreamManagerService;
Jeff Brown6ec6f792012-04-17 16:52:41 -070054import com.android.server.input.InputManagerService;
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -070055import com.android.server.net.NetworkPolicyManagerService;
Jeff Sharkey75279902011-05-24 18:39:45 -070056import com.android.server.net.NetworkStatsService;
Jeff Sharkey7a96c392012-11-15 14:01:46 -080057import com.android.server.os.SchedulingPolicyService;
Jeff Brownf69c8122012-09-12 17:00:34 -070058import com.android.server.pm.Installer;
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -070059import com.android.server.pm.PackageManagerService;
Amith Yamasani258848d2012-08-10 17:06:33 -070060import com.android.server.pm.UserManagerService;
Jeff Brown4f8ecd82012-06-18 18:29:13 -070061import com.android.server.power.PowerManagerService;
62import com.android.server.power.ShutdownThread;
Jeff Sharkey7a96c392012-11-15 14:01:46 -080063import com.android.server.search.SearchManagerService;
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -070064import com.android.server.usb.UsbService;
65import com.android.server.wm.WindowManagerService;
66
67import dalvik.system.VMRuntime;
68import dalvik.system.Zygote;
69
Dan Egnor4410ec82009-09-11 16:40:01 -070070import java.io.File;
Bob Leee5408332009-09-04 18:31:17 -070071import java.util.Timer;
72import java.util.TimerTask;
73
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080074class ServerThread extends Thread {
75 private static final String TAG = "SystemServer";
Ben Komalo553acf02011-09-19 14:25:28 -070076 private static final String ENCRYPTING_STATE = "trigger_restart_min_framework";
Ben Komalo3573d402011-09-23 15:08:24 -070077 private static final String ENCRYPTED_STATE = "1";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080078
Jeff Hamilton35eef702010-06-09 15:45:18 -050079 ContentResolver mContentResolver;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080080
Dianne Hackborn661cd522011-08-22 00:26:20 -070081 void reportWtf(String msg, Throwable e) {
82 Slog.w(TAG, "***********************************************");
83 Log.wtf(TAG, "BOOT FAILURE " + msg, e);
84 }
85
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080086 @Override
87 public void run() {
Doug Zongkerab5c49c2009-12-04 10:31:43 -080088 EventLog.writeEvent(EventLogTags.BOOT_PROGRESS_SYSTEM_RUN,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080089 SystemClock.uptimeMillis());
90
Vairavan Srinivasan04b74ec2012-02-02 22:12:19 -080091 Looper.prepareMainLooper();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080092
93 android.os.Process.setThreadPriority(
94 android.os.Process.THREAD_PRIORITY_FOREGROUND);
95
Dianne Hackborn887f3552009-12-07 17:59:37 -080096 BinderInternal.disableBackgroundScheduling(true);
Christopher Tate160edb32010-06-30 17:46:30 -070097 android.os.Process.setCanSelfBackground(false);
Sen Hubde75702010-05-28 01:54:03 -070098
Kenny Rootf547d672010-09-22 10:36:48 -070099 // Check whether we failed to shut down last time we tried.
100 {
101 final String shutdownAction = SystemProperties.get(
102 ShutdownThread.SHUTDOWN_ACTION_PROPERTY, "");
103 if (shutdownAction != null && shutdownAction.length() > 0) {
104 boolean reboot = (shutdownAction.charAt(0) == '1');
105
106 final String reason;
107 if (shutdownAction.length() > 1) {
108 reason = shutdownAction.substring(1, shutdownAction.length());
109 } else {
110 reason = null;
111 }
112
113 ShutdownThread.rebootOrShutdown(reboot, reason);
114 }
115 }
116
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800117 String factoryTestStr = SystemProperties.get("ro.factorytest");
118 int factoryTest = "".equals(factoryTestStr) ? SystemServer.FACTORY_TEST_OFF
119 : Integer.parseInt(factoryTestStr);
Mike Lockwood3a74bd32011-08-12 13:55:22 -0700120 final boolean headless = "1".equals(SystemProperties.get("ro.config.headless", "0"));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800121
Jeff Brownf69c8122012-09-12 17:00:34 -0700122 Installer installer = null;
Kenny Root26ff6622012-07-30 12:58:03 -0700123 AccountManagerService accountManager = null;
124 ContentService contentService = null;
Mike Lockwood3a322132009-11-24 00:30:52 -0500125 LightsService lights = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800126 PowerManagerService power = null;
Jeff Brownfa25bf52012-07-23 19:26:30 -0700127 DisplayManagerService display = null;
Mike Lockwood07a500f2009-08-12 09:56:44 -0400128 BatteryService battery = null;
Jeff Brown7f6c2312012-04-13 20:38:38 -0700129 VibratorService vibrator = null;
Jeff Sharkey75279902011-05-24 18:39:45 -0700130 AlarmManagerService alarm = null;
Jeff Sharkeyb049e212012-09-07 23:16:01 -0700131 MountService mountService = null;
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -0700132 NetworkManagementService networkManagement = null;
Jeff Sharkey75279902011-05-24 18:39:45 -0700133 NetworkStatsService networkStats = null;
Jeff Sharkeya4620792011-05-20 15:29:23 -0700134 NetworkPolicyManagerService networkPolicy = null;
Mike Lockwood0f79b542009-08-14 14:18:49 -0400135 ConnectivityService connectivity = null;
repo sync55bc5f32011-06-24 14:23:07 -0700136 WifiP2pService wifiP2p = null;
repo syncaea743a2011-07-29 23:55:49 -0700137 WifiService wifi = null;
Irfan Sheriff7d024d32012-03-22 17:01:39 -0700138 NsdService serviceDiscovery= null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800139 IPackageManager pm = null;
140 Context context = null;
141 WindowManagerService wm = null;
fredc0f420372012-04-12 00:02:00 -0700142 BluetoothManagerService bluetooth = null;
Dan Murphyc9f4eaf2009-08-12 15:15:43 -0500143 DockObserver dock = null;
Mike Lockwood770126a2010-12-09 22:30:37 -0800144 UsbService usb = null;
Mike Lockwoodb01e8bf2011-08-29 20:11:07 -0400145 SerialService serial = null;
Jeff Brown2416e092012-08-21 22:12:20 -0700146 TwilightService twilight = null;
Dianne Hackborn7299c412010-03-04 18:41:49 -0800147 UiModeManagerService uiMode = null;
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800148 RecognitionManagerService recognition = null;
Robert Greenwalt9e696c22010-04-01 14:45:18 -0700149 ThrottleService throttle = null;
Amith Yamasani6734b9f2010-09-13 16:24:08 -0700150 NetworkTimeUpdateService networkTimeUpdater = null;
John Grossmanc1576732012-02-01 15:23:33 -0800151 CommonTimeManagementService commonTimeMgmtService = null;
Jeff Brown6ec6f792012-04-17 16:52:41 -0700152 InputManagerService inputManager = null;
Wink Savillea12a7b32012-09-20 10:09:45 -0700153 TelephonyRegistry telephonyRegistry = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800154
Jeff Brownbd6e1502012-08-28 03:27:37 -0700155 // Create a shared handler thread for UI within the system server.
156 // This thread is used by at least the following components:
157 // - WindowManagerPolicy
158 // - KeyguardViewManager
159 // - DisplayManagerService
160 HandlerThread uiHandlerThread = new HandlerThread("UI");
161 uiHandlerThread.start();
162 Handler uiHandler = new Handler(uiHandlerThread.getLooper());
163 uiHandler.post(new Runnable() {
164 @Override
165 public void run() {
166 //Looper.myLooper().setMessageLogging(new LogPrinter(
167 // Log.VERBOSE, "WindowManagerPolicy", Log.LOG_ID_SYSTEM));
168 android.os.Process.setThreadPriority(
169 android.os.Process.THREAD_PRIORITY_FOREGROUND);
170 android.os.Process.setCanSelfBackground(false);
171
172 // For debug builds, log event loop stalls to dropbox for analysis.
173 if (StrictMode.conditionallyEnableDebugLogging()) {
174 Slog.i(TAG, "Enabled StrictMode logging for UI Looper");
175 }
176 }
177 });
178
179 // Create a handler thread just for the window manager to enjoy.
180 HandlerThread wmHandlerThread = new HandlerThread("WindowManager");
181 wmHandlerThread.start();
182 Handler wmHandler = new Handler(wmHandlerThread.getLooper());
183 wmHandler.post(new Runnable() {
184 @Override
185 public void run() {
186 //Looper.myLooper().setMessageLogging(new LogPrinter(
187 // android.util.Log.DEBUG, TAG, android.util.Log.LOG_ID_SYSTEM));
188 android.os.Process.setThreadPriority(
189 android.os.Process.THREAD_PRIORITY_DISPLAY);
190 android.os.Process.setCanSelfBackground(false);
191
192 // For debug builds, log event loop stalls to dropbox for analysis.
193 if (StrictMode.conditionallyEnableDebugLogging()) {
Jeff Brown89d55462012-09-19 11:33:42 -0700194 Slog.i(TAG, "Enabled StrictMode logging for WM Looper");
Jeff Brownbd6e1502012-08-28 03:27:37 -0700195 }
196 }
197 });
198
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800199 // Critical services...
Jeff Brownbd6e1502012-08-28 03:27:37 -0700200 boolean onlyCore = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800201 try {
Jeff Brownf69c8122012-09-12 17:00:34 -0700202 // Wait for installd to finished starting up so that it has a chance to
203 // create critical directories such as /data/user with the appropriate
204 // permissions. We need this to complete before we initialize other services.
205 Slog.i(TAG, "Waiting for installd to be ready.");
206 installer = new Installer();
207 installer.ping();
208
Nick Kralevich6967cbc2011-11-17 13:24:32 -0800209 Slog.i(TAG, "Entropy Mixer");
210 ServiceManager.addService("entropy", new EntropyMixer());
Nick Kralevich4fb25612009-06-17 16:03:22 -0700211
Joe Onorato8a9b2202010-02-26 18:56:32 -0800212 Slog.i(TAG, "Power Manager");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800213 power = new PowerManagerService();
214 ServiceManager.addService(Context.POWER_SERVICE, power);
215
Joe Onorato8a9b2202010-02-26 18:56:32 -0800216 Slog.i(TAG, "Activity Manager");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800217 context = ActivityManagerService.main(factoryTest);
Jeff Brown848c2dc2012-08-19 20:18:08 -0700218
219 Slog.i(TAG, "Display Manager");
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700220 display = new DisplayManagerService(context, wmHandler, uiHandler);
Jeff Brown848c2dc2012-08-19 20:18:08 -0700221 ServiceManager.addService(Context.DISPLAY_SERVICE, display, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800222
Joe Onorato8a9b2202010-02-26 18:56:32 -0800223 Slog.i(TAG, "Telephony Registry");
Wink Savillea12a7b32012-09-20 10:09:45 -0700224 telephonyRegistry = new TelephonyRegistry(context);
225 ServiceManager.addService("telephony.registry", telephonyRegistry);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800226
Glenn Kasten07b04652012-04-23 15:00:43 -0700227 Slog.i(TAG, "Scheduling Policy");
228 ServiceManager.addService(Context.SCHEDULING_POLICY_SERVICE,
229 new SchedulingPolicyService());
230
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800231 AttributeCache.init(context);
232
Jeff Brownbd6e1502012-08-28 03:27:37 -0700233 if (!display.waitForDefaultDisplay()) {
234 reportWtf("Timeout waiting for default display to be initialized.",
235 new Throwable());
236 }
237
Joe Onorato8a9b2202010-02-26 18:56:32 -0800238 Slog.i(TAG, "Package Manager");
Ben Komalo553acf02011-09-19 14:25:28 -0700239 // Only run "core" apps if we're encrypting the device.
240 String cryptState = SystemProperties.get("vold.decrypt");
Ben Komalo3573d402011-09-23 15:08:24 -0700241 if (ENCRYPTING_STATE.equals(cryptState)) {
Ben Komalo553acf02011-09-19 14:25:28 -0700242 Slog.w(TAG, "Detected encryption in progress - only parsing core apps");
Ben Komalo3573d402011-09-23 15:08:24 -0700243 onlyCore = true;
244 } else if (ENCRYPTED_STATE.equals(cryptState)) {
245 Slog.w(TAG, "Device encrypted - only parsing core apps");
246 onlyCore = true;
Ben Komalo553acf02011-09-19 14:25:28 -0700247 }
Ben Komalo3573d402011-09-23 15:08:24 -0700248
Jeff Brownf69c8122012-09-12 17:00:34 -0700249 pm = PackageManagerService.main(context, installer,
Dianne Hackbornd2509fd2011-09-12 12:29:43 -0700250 factoryTest != SystemServer.FACTORY_TEST_OFF,
Ben Komalo553acf02011-09-19 14:25:28 -0700251 onlyCore);
Dianne Hackborn58f42a52011-10-10 13:46:34 -0700252 boolean firstBoot = false;
253 try {
254 firstBoot = pm.isFirstBoot();
255 } catch (RemoteException e) {
256 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800257
258 ActivityManagerService.setSystemProcess();
Amith Yamasani258848d2012-08-10 17:06:33 -0700259
260 Slog.i(TAG, "User Service");
261 ServiceManager.addService(Context.USER_SERVICE,
Dianne Hackborn4428e172012-08-24 17:43:05 -0700262 UserManagerService.getInstance());
Amith Yamasani258848d2012-08-10 17:06:33 -0700263
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800264
265 mContentResolver = context.getContentResolver();
266
Fred Quintanae91ebe22009-09-29 20:44:30 -0700267 // The AccountManager must come before the ContentService
Fred Quintana60307342009-03-24 22:48:12 -0700268 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800269 Slog.i(TAG, "Account Manager");
Kenny Root26ff6622012-07-30 12:58:03 -0700270 accountManager = new AccountManagerService(context);
271 ServiceManager.addService(Context.ACCOUNT_SERVICE, accountManager);
Fred Quintana60307342009-03-24 22:48:12 -0700272 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800273 Slog.e(TAG, "Failure starting Account Manager", e);
Fred Quintana60307342009-03-24 22:48:12 -0700274 }
275
Joe Onorato8a9b2202010-02-26 18:56:32 -0800276 Slog.i(TAG, "Content Manager");
Kenny Root26ff6622012-07-30 12:58:03 -0700277 contentService = ContentService.main(context,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800278 factoryTest == SystemServer.FACTORY_TEST_LOW_LEVEL);
279
Joe Onorato8a9b2202010-02-26 18:56:32 -0800280 Slog.i(TAG, "System Content Providers");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800281 ActivityManagerService.installSystemProviders();
282
Joe Onorato8a9b2202010-02-26 18:56:32 -0800283 Slog.i(TAG, "Lights Service");
Mike Lockwood3a322132009-11-24 00:30:52 -0500284 lights = new LightsService(context);
285
Joe Onoratode1b3592010-10-25 20:36:47 -0700286 Slog.i(TAG, "Battery Service");
287 battery = new BatteryService(context, lights);
288 ServiceManager.addService("battery", battery);
289
Joe Onorato8a9b2202010-02-26 18:56:32 -0800290 Slog.i(TAG, "Vibrator Service");
Jeff Brown7f6c2312012-04-13 20:38:38 -0700291 vibrator = new VibratorService(context);
292 ServiceManager.addService("vibrator", vibrator);
The Android Open Source Project10592532009-03-18 17:39:46 -0700293
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800294 // only initialize the power service after we have started the
Mike Lockwood3a322132009-11-24 00:30:52 -0500295 // lights service, content providers and the battery service.
Jeff Brown96307042012-07-27 15:51:34 -0700296 power.init(context, lights, ActivityManagerService.self(), battery,
297 BatteryStatsService.getService(), display);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800298
Joe Onorato8a9b2202010-02-26 18:56:32 -0800299 Slog.i(TAG, "Alarm Manager");
Jeff Sharkey75279902011-05-24 18:39:45 -0700300 alarm = new AlarmManagerService(context);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800301 ServiceManager.addService(Context.ALARM_SERVICE, alarm);
302
Joe Onorato8a9b2202010-02-26 18:56:32 -0800303 Slog.i(TAG, "Init Watchdog");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800304 Watchdog.getInstance().init(context, battery, power, alarm,
305 ActivityManagerService.self());
306
Jeff Browna9d131c2012-09-20 16:48:17 -0700307 Slog.i(TAG, "Input Manager");
308 inputManager = new InputManagerService(context, wmHandler);
309
Joe Onorato8a9b2202010-02-26 18:56:32 -0800310 Slog.i(TAG, "Window Manager");
Jeff Browna9d131c2012-09-20 16:48:17 -0700311 wm = WindowManagerService.main(context, power, display, inputManager,
Jeff Brownbd6e1502012-08-28 03:27:37 -0700312 uiHandler, wmHandler,
Dianne Hackborn58f42a52011-10-10 13:46:34 -0700313 factoryTest != SystemServer.FACTORY_TEST_LOW_LEVEL,
Jeff Brown780c46f2012-06-24 12:15:38 -0700314 !firstBoot, onlyCore);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800315 ServiceManager.addService(Context.WINDOW_SERVICE, wm);
Jeff Brown6ec6f792012-04-17 16:52:41 -0700316 ServiceManager.addService(Context.INPUT_SERVICE, inputManager);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800317
Dianne Hackborn295e3c22011-08-25 13:19:08 -0700318 ActivityManagerService.self().setWindowManager(wm);
Jeff Browna9d131c2012-09-20 16:48:17 -0700319
320 inputManager.setWindowManagerCallbacks(wm.getInputMonitor());
321 inputManager.start();
322
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700323 display.setWindowManager(wm);
Jeff Brownd728bf52012-09-08 18:05:28 -0700324 display.setInputManager(inputManager);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800325
326 // Skip Bluetooth if we have an emulator kernel
327 // TODO: Use a more reliable check to see if this product should
328 // support Bluetooth - see bug 988521
329 if (SystemProperties.get("ro.kernel.qemu").equals("1")) {
David 'Digit' Turnere2a5e862011-01-17 00:32:33 +0100330 Slog.i(TAG, "No Bluetooh Service (emulator)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800331 } else if (factoryTest == SystemServer.FACTORY_TEST_LOW_LEVEL) {
David 'Digit' Turnere2a5e862011-01-17 00:32:33 +0100332 Slog.i(TAG, "No Bluetooth Service (factory test)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800333 } else {
fredc0f420372012-04-12 00:02:00 -0700334 Slog.i(TAG, "Bluetooth Manager Service");
335 bluetooth = new BluetoothManagerService(context);
336 ServiceManager.addService(BluetoothAdapter.BLUETOOTH_MANAGER_SERVICE, bluetooth);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800337 }
338
339 } catch (RuntimeException e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700340 Slog.e("System", "******************************************");
341 Slog.e("System", "************ Failure starting core service", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800342 }
343
Dianne Hackbornd6847842010-01-12 18:14:19 -0800344 DevicePolicyManagerService devicePolicy = null;
Joe Onorato089de882010-04-12 08:18:45 -0700345 StatusBarManagerService statusBar = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800346 InputMethodManagerService imm = null;
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700347 AppWidgetService appWidget = null;
Joe Onorato30275482009-07-08 17:09:14 -0700348 NotificationManagerService notification = null;
Dianne Hackbornf21adf62009-08-13 10:20:21 -0700349 WallpaperManagerService wallpaper = null;
Mike Lockwood46db5042010-02-22 16:36:44 -0500350 LocationManagerService location = null;
Bai Taoa58a8752010-07-13 15:32:16 +0800351 CountryDetectorService countryDetector = null;
satok988323c2011-06-22 16:38:13 +0900352 TextServicesManagerService tsms = null;
Amith Yamasani52c489c2012-03-28 11:42:42 -0700353 LockSettingsService lockSettings = null;
Daniel Sandler7d276c32012-01-30 14:33:52 -0500354 DreamManagerService dreamy = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800355
Dianne Hackborn661cd522011-08-22 00:26:20 -0700356 // Bring up services needed for UI.
357 if (factoryTest != SystemServer.FACTORY_TEST_LOW_LEVEL) {
358 try {
359 Slog.i(TAG, "Input Method Service");
satok01038492012-04-09 21:08:27 +0900360 imm = new InputMethodManagerService(context, wm);
Dianne Hackborn661cd522011-08-22 00:26:20 -0700361 ServiceManager.addService(Context.INPUT_METHOD_SERVICE, imm);
362 } catch (Throwable e) {
363 reportWtf("starting Input Manager Service", e);
364 }
365
366 try {
367 Slog.i(TAG, "Accessibility Manager");
368 ServiceManager.addService(Context.ACCESSIBILITY_SERVICE,
369 new AccessibilityManagerService(context));
370 } catch (Throwable e) {
371 reportWtf("starting Accessibility Manager", e);
372 }
373 }
374
375 try {
376 wm.displayReady();
377 } catch (Throwable e) {
378 reportWtf("making display ready", e);
379 }
Dianne Hackborn8795b602011-08-25 13:30:53 -0700380
Dianne Hackborn295e3c22011-08-25 13:19:08 -0700381 try {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700382 pm.performBootDexOpt();
383 } catch (Throwable e) {
384 reportWtf("performing boot dexopt", e);
385 }
386
387 try {
388 ActivityManagerNative.getDefault().showBootMessage(
389 context.getResources().getText(
390 com.android.internal.R.string.android_upgrading_starting_apps),
391 false);
392 } catch (RemoteException e) {
393 }
394
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800395 if (factoryTest != SystemServer.FACTORY_TEST_LOW_LEVEL) {
Kenny Root51a573c2012-05-17 13:30:28 -0700396 if (!"0".equals(SystemProperties.get("system_init.startmountservice"))) {
397 try {
398 /*
399 * NotificationManagerService is dependant on MountService,
400 * (for media / usb notifications) so we must start MountService first.
401 */
402 Slog.i(TAG, "Mount Service");
403 mountService = new MountService(context);
404 ServiceManager.addService("mount", mountService);
405 } catch (Throwable e) {
406 reportWtf("starting Mount Service", e);
407 }
408 }
409
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800410 try {
Amith Yamasani52c489c2012-03-28 11:42:42 -0700411 Slog.i(TAG, "LockSettingsService");
412 lockSettings = new LockSettingsService(context);
413 ServiceManager.addService("lock_settings", lockSettings);
414 } catch (Throwable e) {
415 reportWtf("starting LockSettingsService service", e);
416 }
417
418 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800419 Slog.i(TAG, "Device Policy");
Dianne Hackbornd6847842010-01-12 18:14:19 -0800420 devicePolicy = new DevicePolicyManagerService(context);
421 ServiceManager.addService(Context.DEVICE_POLICY_SERVICE, devicePolicy);
422 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700423 reportWtf("starting DevicePolicyService", e);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800424 }
425
426 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800427 Slog.i(TAG, "Status Bar");
Jeff Brown2992ea72011-01-28 22:04:14 -0800428 statusBar = new StatusBarManagerService(context, wm);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800429 ServiceManager.addService(Context.STATUS_BAR_SERVICE, statusBar);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800430 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700431 reportWtf("starting StatusBarManagerService", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800432 }
433
434 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800435 Slog.i(TAG, "Clipboard Service");
Dianne Hackbornd6847842010-01-12 18:14:19 -0800436 ServiceManager.addService(Context.CLIPBOARD_SERVICE,
437 new ClipboardService(context));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800438 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700439 reportWtf("starting Clipboard Service", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800440 }
441
442 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800443 Slog.i(TAG, "NetworkManagement Service");
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -0700444 networkManagement = NetworkManagementService.create(context);
445 ServiceManager.addService(Context.NETWORKMANAGEMENT_SERVICE, networkManagement);
San Mehatd1df8ac2010-01-26 06:17:26 -0800446 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700447 reportWtf("starting NetworkManagement Service", e);
San Mehatd1df8ac2010-01-26 06:17:26 -0800448 }
449
450 try {
satok988323c2011-06-22 16:38:13 +0900451 Slog.i(TAG, "Text Service Manager Service");
452 tsms = new TextServicesManagerService(context);
453 ServiceManager.addService(Context.TEXT_SERVICES_MANAGER_SERVICE, tsms);
454 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700455 reportWtf("starting Text Service Manager Service", e);
satok988323c2011-06-22 16:38:13 +0900456 }
457
458 try {
Jeff Sharkey75279902011-05-24 18:39:45 -0700459 Slog.i(TAG, "NetworkStats Service");
460 networkStats = new NetworkStatsService(context, networkManagement, alarm);
461 ServiceManager.addService(Context.NETWORK_STATS_SERVICE, networkStats);
462 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700463 reportWtf("starting NetworkStats Service", e);
Jeff Sharkey75279902011-05-24 18:39:45 -0700464 }
465
466 try {
467 Slog.i(TAG, "NetworkPolicy Service");
468 networkPolicy = new NetworkPolicyManagerService(
Ashish Sharma50fd36d2011-06-15 19:34:53 -0700469 context, ActivityManagerService.self(), power,
470 networkStats, networkManagement);
Jeff Sharkey75279902011-05-24 18:39:45 -0700471 ServiceManager.addService(Context.NETWORK_POLICY_SERVICE, networkPolicy);
472 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700473 reportWtf("starting NetworkPolicy Service", e);
Jeff Sharkey75279902011-05-24 18:39:45 -0700474 }
475
repo sync55bc5f32011-06-24 14:23:07 -0700476 try {
477 Slog.i(TAG, "Wi-Fi P2pService");
478 wifiP2p = new WifiP2pService(context);
479 ServiceManager.addService(Context.WIFI_P2P_SERVICE, wifiP2p);
480 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700481 reportWtf("starting Wi-Fi P2pService", e);
repo sync55bc5f32011-06-24 14:23:07 -0700482 }
483
repo syncaea743a2011-07-29 23:55:49 -0700484 try {
485 Slog.i(TAG, "Wi-Fi Service");
486 wifi = new WifiService(context);
487 ServiceManager.addService(Context.WIFI_SERVICE, wifi);
repo syncaea743a2011-07-29 23:55:49 -0700488 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700489 reportWtf("starting Wi-Fi Service", e);
repo syncaea743a2011-07-29 23:55:49 -0700490 }
491
Jeff Sharkey75279902011-05-24 18:39:45 -0700492 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800493 Slog.i(TAG, "Connectivity Service");
Jeff Sharkey367d15a2011-09-22 14:59:51 -0700494 connectivity = new ConnectivityService(
495 context, networkManagement, networkStats, networkPolicy);
Mike Lockwood0f79b542009-08-14 14:18:49 -0400496 ServiceManager.addService(Context.CONNECTIVITY_SERVICE, connectivity);
Jeff Sharkeyd2a45872011-05-28 20:56:34 -0700497 networkStats.bindConnectivityManager(connectivity);
Jeff Sharkey21c9c452011-06-07 12:26:43 -0700498 networkPolicy.bindConnectivityManager(connectivity);
Robert Greenwalt9b2886e2011-08-31 11:46:42 -0700499 wifi.checkAndStartWifi();
Irfan Sheriffcb30b222011-07-29 20:54:52 -0700500 wifiP2p.connectivityServiceReady();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800501 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700502 reportWtf("starting Connectivity Service", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800503 }
504
505 try {
Irfan Sheriff7d024d32012-03-22 17:01:39 -0700506 Slog.i(TAG, "Network Service Discovery Service");
507 serviceDiscovery = NsdService.create(context);
508 ServiceManager.addService(
509 Context.NSD_SERVICE, serviceDiscovery);
510 } catch (Throwable e) {
511 reportWtf("starting Service Discovery Service", e);
512 }
513
514 try {
Robert Greenwalt9e696c22010-04-01 14:45:18 -0700515 Slog.i(TAG, "Throttle Service");
516 throttle = new ThrottleService(context);
517 ServiceManager.addService(
518 Context.THROTTLE_SERVICE, throttle);
519 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700520 reportWtf("starting ThrottleService", e);
svetoslavganov75986cf2009-05-14 22:28:01 -0700521 }
522
Christopher Tate8662cab52012-02-23 14:59:36 -0800523 try {
524 Slog.i(TAG, "UpdateLock Service");
525 ServiceManager.addService(Context.UPDATE_LOCK_SERVICE,
526 new UpdateLockService(context));
527 } catch (Throwable e) {
528 reportWtf("starting UpdateLockService", e);
529 }
530
Kenny Root51a573c2012-05-17 13:30:28 -0700531 /*
532 * MountService has a few dependencies: Notification Manager and
533 * AppWidget Provider. Make sure MountService is completely started
534 * first before continuing.
535 */
536 if (mountService != null) {
537 mountService.waitForAsecScan();
San Mehat1bf3f8b2010-02-03 14:43:09 -0800538 }
539
540 try {
Kenny Root26ff6622012-07-30 12:58:03 -0700541 if (accountManager != null)
542 accountManager.systemReady();
543 } catch (Throwable e) {
544 reportWtf("making Account Manager Service ready", e);
545 }
546
547 try {
548 if (contentService != null)
549 contentService.systemReady();
550 } catch (Throwable e) {
551 reportWtf("making Content Service ready", e);
552 }
553
554 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800555 Slog.i(TAG, "Notification Manager");
Mike Lockwood3a322132009-11-24 00:30:52 -0500556 notification = new NotificationManagerService(context, statusBar, lights);
Joe Onorato30275482009-07-08 17:09:14 -0700557 ServiceManager.addService(Context.NOTIFICATION_SERVICE, notification);
Jeff Sharkey497e4432011-06-14 17:27:29 -0700558 networkPolicy.bindNotificationManager(notification);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800559 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700560 reportWtf("starting Notification Manager", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800561 }
562
563 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800564 Slog.i(TAG, "Device Storage Monitor");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800565 ServiceManager.addService(DeviceStorageMonitorService.SERVICE,
566 new DeviceStorageMonitorService(context));
567 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700568 reportWtf("starting DeviceStorageMonitor service", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800569 }
570
571 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800572 Slog.i(TAG, "Location Manager");
Mike Lockwood46db5042010-02-22 16:36:44 -0500573 location = new LocationManagerService(context);
574 ServiceManager.addService(Context.LOCATION_SERVICE, location);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800575 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700576 reportWtf("starting Location Manager", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800577 }
578
579 try {
Bai Taoa58a8752010-07-13 15:32:16 +0800580 Slog.i(TAG, "Country Detector");
581 countryDetector = new CountryDetectorService(context);
582 ServiceManager.addService(Context.COUNTRY_DETECTOR, countryDetector);
583 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700584 reportWtf("starting Country Detector", e);
Bai Taoa58a8752010-07-13 15:32:16 +0800585 }
586
587 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800588 Slog.i(TAG, "Search Service");
Dianne Hackbornd6847842010-01-12 18:14:19 -0800589 ServiceManager.addService(Context.SEARCH_SERVICE,
590 new SearchManagerService(context));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800591 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700592 reportWtf("starting Search Service", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800593 }
594
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800595 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800596 Slog.i(TAG, "DropBox Service");
Dan Egnor95240272009-10-27 18:23:39 -0700597 ServiceManager.addService(Context.DROPBOX_SERVICE,
Dan Egnorf18a01c2009-11-12 11:32:50 -0800598 new DropBoxManagerService(context, new File("/data/system/dropbox")));
Dan Egnor4410ec82009-09-11 16:40:01 -0700599 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700600 reportWtf("starting DropBoxManagerService", e);
Dan Egnor4410ec82009-09-11 16:40:01 -0700601 }
602
Mike Lockwoodc067c9c2011-10-31 12:50:12 -0400603 if (context.getResources().getBoolean(
604 com.android.internal.R.bool.config_enableWallpaperService)) {
605 try {
606 Slog.i(TAG, "Wallpaper Service");
607 if (!headless) {
608 wallpaper = new WallpaperManagerService(context);
609 ServiceManager.addService(Context.WALLPAPER_SERVICE, wallpaper);
610 }
611 } catch (Throwable e) {
612 reportWtf("starting Wallpaper Service", e);
Mike Lockwood3a74bd32011-08-12 13:55:22 -0700613 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800614 }
615
Mike Lockwoodcba928c2011-08-17 15:58:52 -0700616 if (!"0".equals(SystemProperties.get("system_init.startaudioservice"))) {
617 try {
618 Slog.i(TAG, "Audio Service");
619 ServiceManager.addService(Context.AUDIO_SERVICE, new AudioService(context));
620 } catch (Throwable e) {
621 reportWtf("starting Audio Service", e);
622 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800623 }
624
625 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800626 Slog.i(TAG, "Dock Observer");
Dan Murphyc9f4eaf2009-08-12 15:15:43 -0500627 // Listen for dock station changes
Jeff Brown96307042012-07-27 15:51:34 -0700628 dock = new DockObserver(context);
Dan Murphyc9f4eaf2009-08-12 15:15:43 -0500629 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700630 reportWtf("starting DockObserver", e);
Dan Murphyc9f4eaf2009-08-12 15:15:43 -0500631 }
632
633 try {
Craig Mautner2f39e9f2012-09-21 11:39:54 -0700634 Slog.i(TAG, "Wired Accessory Manager");
Praveen Bharathi21e941b2010-10-06 15:23:14 -0500635 // Listen for wired headset changes
Craig Mautner2f39e9f2012-09-21 11:39:54 -0700636 inputManager.setWiredAccessoryCallbacks(
637 new WiredAccessoryManager(context, inputManager));
Praveen Bharathi21e941b2010-10-06 15:23:14 -0500638 } catch (Throwable e) {
Craig Mautner2f39e9f2012-09-21 11:39:54 -0700639 reportWtf("starting WiredAccessoryManager", e);
Praveen Bharathi21e941b2010-10-06 15:23:14 -0500640 }
641
642 try {
Mike Lockwood02e45692011-06-14 15:43:51 -0400643 Slog.i(TAG, "USB Service");
644 // Manage USB host and device support
Mike Lockwood770126a2010-12-09 22:30:37 -0800645 usb = new UsbService(context);
Mike Lockwoode7d511e2010-12-30 13:39:37 -0500646 ServiceManager.addService(Context.USB_SERVICE, usb);
Mike Lockwood57c798a2010-06-23 17:36:36 -0400647 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700648 reportWtf("starting UsbService", e);
Mike Lockwood57c798a2010-06-23 17:36:36 -0400649 }
650
651 try {
Mike Lockwoodb01e8bf2011-08-29 20:11:07 -0400652 Slog.i(TAG, "Serial Service");
653 // Serial port support
654 serial = new SerialService(context);
655 ServiceManager.addService(Context.SERIAL_SERVICE, serial);
656 } catch (Throwable e) {
657 Slog.e(TAG, "Failure starting SerialService", e);
658 }
659
660 try {
Jeff Brown2416e092012-08-21 22:12:20 -0700661 Slog.i(TAG, "Twilight Service");
662 twilight = new TwilightService(context);
663 } catch (Throwable e) {
664 reportWtf("starting TwilightService", e);
665 }
666
667 try {
Dianne Hackborn7299c412010-03-04 18:41:49 -0800668 Slog.i(TAG, "UI Mode Manager Service");
Mike Lockwood57c798a2010-06-23 17:36:36 -0400669 // Listen for UI mode changes
Jeff Brown2416e092012-08-21 22:12:20 -0700670 uiMode = new UiModeManagerService(context, twilight);
Dianne Hackborn7299c412010-03-04 18:41:49 -0800671 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700672 reportWtf("starting UiModeManagerService", e);
Dianne Hackborn7299c412010-03-04 18:41:49 -0800673 }
674
675 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800676 Slog.i(TAG, "Backup Service");
Dianne Hackbornd6847842010-01-12 18:14:19 -0800677 ServiceManager.addService(Context.BACKUP_SERVICE,
678 new BackupManagerService(context));
Christopher Tate487529a2009-04-29 14:03:25 -0700679 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800680 Slog.e(TAG, "Failure starting Backup Service", e);
Christopher Tate487529a2009-04-29 14:03:25 -0700681 }
682
683 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800684 Slog.i(TAG, "AppWidget Service");
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700685 appWidget = new AppWidgetService(context);
686 ServiceManager.addService(Context.APPWIDGET_SERVICE, appWidget);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800687 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700688 reportWtf("starting AppWidget Service", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800689 }
690
691 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800692 Slog.i(TAG, "Recognition Service");
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800693 recognition = new RecognitionManagerService(context);
694 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700695 reportWtf("starting Recognition Service", e);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800696 }
Jaikumar Ganesh7d0548d2010-10-18 15:29:09 -0700697
Nick Pelly038cabe2010-09-23 16:12:11 -0700698 try {
Dan Egnor621bc542010-03-25 16:20:14 -0700699 Slog.i(TAG, "DiskStats Service");
700 ServiceManager.addService("diskstats", new DiskStatsService(context));
701 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700702 reportWtf("starting DiskStats Service", e);
Dan Egnor621bc542010-03-25 16:20:14 -0700703 }
Sen Hubde75702010-05-28 01:54:03 -0700704
705 try {
706 // need to add this service even if SamplingProfilerIntegration.isEnabled()
707 // is false, because it is this service that detects system property change and
708 // turns on SamplingProfilerIntegration. Plus, when sampling profiler doesn't work,
709 // there is little overhead for running this service.
710 Slog.i(TAG, "SamplingProfiler Service");
711 ServiceManager.addService("samplingprofiler",
712 new SamplingProfilerService(context));
713 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700714 reportWtf("starting SamplingProfiler Service", e);
Sen Hubde75702010-05-28 01:54:03 -0700715 }
Chung-yih Wang024d5962010-08-06 12:06:04 +0800716
717 try {
Amith Yamasani6734b9f2010-09-13 16:24:08 -0700718 Slog.i(TAG, "NetworkTimeUpdateService");
719 networkTimeUpdater = new NetworkTimeUpdateService(context);
720 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700721 reportWtf("starting NetworkTimeUpdate service", e);
Amith Yamasani6734b9f2010-09-13 16:24:08 -0700722 }
John Grossmanc1576732012-02-01 15:23:33 -0800723
724 try {
725 Slog.i(TAG, "CommonTimeManagementService");
726 commonTimeMgmtService = new CommonTimeManagementService(context);
727 ServiceManager.addService("commontime_management", commonTimeMgmtService);
728 } catch (Throwable e) {
729 reportWtf("starting CommonTimeManagementService service", e);
730 }
Geremy Condra3d33c262012-05-06 18:32:19 -0700731
732 try {
733 Slog.i(TAG, "CertBlacklister");
734 CertBlacklister blacklister = new CertBlacklister(context);
735 } catch (Throwable e) {
736 reportWtf("starting CertBlacklister", e);
737 }
Daniel Sandler7d276c32012-01-30 14:33:52 -0500738
739 if (context.getResources().getBoolean(
John Spurlocked108f32012-10-18 16:49:24 -0400740 com.android.internal.R.bool.config_dreamsSupported)) {
Daniel Sandler7d276c32012-01-30 14:33:52 -0500741 try {
742 Slog.i(TAG, "Dreams Service");
743 // Dreams (interactive idle-time views, a/k/a screen savers)
Jeff Brown62c82e42012-09-26 01:30:41 -0700744 dreamy = new DreamManagerService(context, wmHandler);
Dianne Hackbornbe87e2f2012-09-28 16:31:34 -0700745 ServiceManager.addService(DreamService.DREAM_SERVICE, dreamy);
Daniel Sandler7d276c32012-01-30 14:33:52 -0500746 } catch (Throwable e) {
747 reportWtf("starting DreamManagerService", e);
748 }
749 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800750 }
751
Dianne Hackborn6af0d502009-09-28 13:25:46 -0700752 // Before things start rolling, be sure we have decided whether
753 // we are in safe mode.
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700754 final boolean safeMode = wm.detectSafeMode();
Dianne Hackborn6af0d502009-09-28 13:25:46 -0700755 if (safeMode) {
Jeff Brownb09abc12011-01-13 21:08:27 -0800756 ActivityManagerService.self().enterSafeMode();
757 // Post the safe mode state in the Zygote class
758 Zygote.systemInSafeMode = true;
759 // Disable the JIT for the system_server process
760 VMRuntime.getRuntime().disableJitCompilation();
Ben Cheng6c0afff2010-02-14 16:18:56 -0800761 } else {
762 // Enable the JIT for the system_server process
763 VMRuntime.getRuntime().startJitCompilation();
Dianne Hackborn6af0d502009-09-28 13:25:46 -0700764 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800765
Dianne Hackborn6af0d502009-09-28 13:25:46 -0700766 // It is now time to start up the app processes...
Joe Onorato30275482009-07-08 17:09:14 -0700767
Jeff Brown7f6c2312012-04-13 20:38:38 -0700768 try {
769 vibrator.systemReady();
770 } catch (Throwable e) {
771 reportWtf("making Vibrator Service ready", e);
772 }
773
Felipe Ramosf35df5b2012-09-18 18:26:27 -0300774 try {
775 lockSettings.systemReady();
776 } catch (Throwable e) {
777 reportWtf("making Lock Settings Service ready", e);
778 }
779
Dianne Hackbornd6847842010-01-12 18:14:19 -0800780 if (devicePolicy != null) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700781 try {
782 devicePolicy.systemReady();
783 } catch (Throwable e) {
784 reportWtf("making Device Policy Service ready", e);
785 }
Dianne Hackbornd6847842010-01-12 18:14:19 -0800786 }
787
Joe Onorato30275482009-07-08 17:09:14 -0700788 if (notification != null) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700789 try {
790 notification.systemReady();
791 } catch (Throwable e) {
792 reportWtf("making Notification Service ready", e);
793 }
Joe Onorato30275482009-07-08 17:09:14 -0700794 }
795
Dianne Hackborn661cd522011-08-22 00:26:20 -0700796 try {
797 wm.systemReady();
798 } catch (Throwable e) {
799 reportWtf("making Window Manager Service ready", e);
800 }
Joe Onoratodc565f42010-10-04 15:27:22 -0400801
Jeff Brownb09abc12011-01-13 21:08:27 -0800802 if (safeMode) {
803 ActivityManagerService.self().showSafeModeOverlay();
804 }
805
Joe Onoratodc565f42010-10-04 15:27:22 -0400806 // Update the configuration for this context by hand, because we're going
807 // to start using it before the config change done in wm.systemReady() will
808 // propagate to it.
809 Configuration config = wm.computeNewConfiguration();
810 DisplayMetrics metrics = new DisplayMetrics();
811 WindowManager w = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
812 w.getDefaultDisplay().getMetrics(metrics);
813 context.getResources().updateConfiguration(config, metrics);
814
Jeff Brownaa202a62012-08-21 22:14:26 -0700815 try {
Jeff Brown62c82e42012-09-26 01:30:41 -0700816 power.systemReady(twilight, dreamy);
Jeff Brownaa202a62012-08-21 22:14:26 -0700817 } catch (Throwable e) {
818 reportWtf("making Power Manager Service ready", e);
819 }
820
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800821 try {
822 pm.systemReady();
Dianne Hackborn661cd522011-08-22 00:26:20 -0700823 } catch (Throwable e) {
824 reportWtf("making Package Manager Service ready", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800825 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800826
Jeff Brownbd6e1502012-08-28 03:27:37 -0700827 try {
828 display.systemReady(safeMode, onlyCore);
829 } catch (Throwable e) {
830 reportWtf("making Display Manager Service ready", e);
831 }
832
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700833 // These are needed to propagate to the runnable below.
Joe Onoratof3c3c4f2010-10-21 11:09:02 -0400834 final Context contextF = context;
Jeff Sharkeyb049e212012-09-07 23:16:01 -0700835 final MountService mountServiceF = mountService;
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700836 final BatteryService batteryF = battery;
Jeff Sharkey350083e2011-06-29 10:45:16 -0700837 final NetworkManagementService networkManagementF = networkManagement;
Jeff Sharkey75279902011-05-24 18:39:45 -0700838 final NetworkStatsService networkStatsF = networkStats;
Jeff Sharkeya4620792011-05-20 15:29:23 -0700839 final NetworkPolicyManagerService networkPolicyF = networkPolicy;
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700840 final ConnectivityService connectivityF = connectivity;
841 final DockObserver dockF = dock;
Mike Lockwood770126a2010-12-09 22:30:37 -0800842 final UsbService usbF = usb;
Robert Greenwalt9e696c22010-04-01 14:45:18 -0700843 final ThrottleService throttleF = throttle;
Jeff Brown2416e092012-08-21 22:12:20 -0700844 final TwilightService twilightF = twilight;
Dianne Hackborn7299c412010-03-04 18:41:49 -0800845 final UiModeManagerService uiModeF = uiMode;
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700846 final AppWidgetService appWidgetF = appWidget;
847 final WallpaperManagerService wallpaperF = wallpaper;
848 final InputMethodManagerService immF = imm;
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800849 final RecognitionManagerService recognitionF = recognition;
Mike Lockwood46db5042010-02-22 16:36:44 -0500850 final LocationManagerService locationF = location;
Bai Taoa58a8752010-07-13 15:32:16 +0800851 final CountryDetectorService countryDetectorF = countryDetector;
Amith Yamasani6734b9f2010-09-13 16:24:08 -0700852 final NetworkTimeUpdateService networkTimeUpdaterF = networkTimeUpdater;
John Grossmanc1576732012-02-01 15:23:33 -0800853 final CommonTimeManagementService commonTimeMgmtServiceF = commonTimeMgmtService;
satok988323c2011-06-22 16:38:13 +0900854 final TextServicesManagerService textServiceManagerServiceF = tsms;
Dianne Hackborn661cd522011-08-22 00:26:20 -0700855 final StatusBarManagerService statusBarF = statusBar;
Daniel Sandler7d276c32012-01-30 14:33:52 -0500856 final DreamManagerService dreamyF = dreamy;
Jeff Brown6ec6f792012-04-17 16:52:41 -0700857 final InputManagerService inputManagerF = inputManager;
Wink Savillea12a7b32012-09-20 10:09:45 -0700858 final TelephonyRegistry telephonyRegistryF = telephonyRegistry;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800859
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700860 // We now tell the activity manager it is okay to run third party
861 // code. It will call back into us once it has gotten to the state
862 // where third party code can really run (but before it has actually
863 // started launching the initial applications), for us to complete our
864 // initialization.
Dianne Hackborn295e3c22011-08-25 13:19:08 -0700865 ActivityManagerService.self().systemReady(new Runnable() {
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700866 public void run() {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800867 Slog.i(TAG, "Making services ready");
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800868
Mike Lockwood3a74bd32011-08-12 13:55:22 -0700869 if (!headless) startSystemUi(contextF);
Dianne Hackborn661cd522011-08-22 00:26:20 -0700870 try {
Jeff Sharkeyb049e212012-09-07 23:16:01 -0700871 if (mountServiceF != null) mountServiceF.systemReady();
872 } catch (Throwable e) {
873 reportWtf("making Mount Service ready", e);
874 }
875 try {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700876 if (batteryF != null) batteryF.systemReady();
877 } catch (Throwable e) {
878 reportWtf("making Battery Service ready", e);
879 }
880 try {
881 if (networkManagementF != null) networkManagementF.systemReady();
882 } catch (Throwable e) {
883 reportWtf("making Network Managment Service ready", e);
884 }
885 try {
886 if (networkStatsF != null) networkStatsF.systemReady();
887 } catch (Throwable e) {
888 reportWtf("making Network Stats Service ready", e);
889 }
890 try {
891 if (networkPolicyF != null) networkPolicyF.systemReady();
892 } catch (Throwable e) {
893 reportWtf("making Network Policy Service ready", e);
894 }
895 try {
896 if (connectivityF != null) connectivityF.systemReady();
897 } catch (Throwable e) {
898 reportWtf("making Connectivity Service ready", e);
899 }
900 try {
901 if (dockF != null) dockF.systemReady();
902 } catch (Throwable e) {
903 reportWtf("making Dock Service ready", e);
904 }
905 try {
906 if (usbF != null) usbF.systemReady();
907 } catch (Throwable e) {
908 reportWtf("making USB Service ready", e);
909 }
910 try {
Jeff Brown2416e092012-08-21 22:12:20 -0700911 if (twilightF != null) twilightF.systemReady();
912 } catch (Throwable e) {
913 reportWtf("makin Twilight Service ready", e);
914 }
915 try {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700916 if (uiModeF != null) uiModeF.systemReady();
917 } catch (Throwable e) {
918 reportWtf("making UI Mode Service ready", e);
919 }
920 try {
921 if (recognitionF != null) recognitionF.systemReady();
922 } catch (Throwable e) {
923 reportWtf("making Recognition Service ready", e);
924 }
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700925 Watchdog.getInstance().start();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800926
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700927 // It is now okay to let the various system services start their
928 // third party code...
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800929
Dianne Hackborn661cd522011-08-22 00:26:20 -0700930 try {
931 if (appWidgetF != null) appWidgetF.systemReady(safeMode);
932 } catch (Throwable e) {
933 reportWtf("making App Widget Service ready", e);
934 }
935 try {
936 if (wallpaperF != null) wallpaperF.systemReady();
937 } catch (Throwable e) {
938 reportWtf("making Wallpaper Service ready", e);
939 }
940 try {
941 if (immF != null) immF.systemReady(statusBarF);
942 } catch (Throwable e) {
943 reportWtf("making Input Method Service ready", e);
944 }
945 try {
946 if (locationF != null) locationF.systemReady();
947 } catch (Throwable e) {
948 reportWtf("making Location Service ready", e);
949 }
950 try {
951 if (countryDetectorF != null) countryDetectorF.systemReady();
952 } catch (Throwable e) {
953 reportWtf("making Country Detector Service ready", e);
954 }
955 try {
956 if (throttleF != null) throttleF.systemReady();
957 } catch (Throwable e) {
958 reportWtf("making Throttle Service ready", e);
959 }
960 try {
961 if (networkTimeUpdaterF != null) networkTimeUpdaterF.systemReady();
962 } catch (Throwable e) {
963 reportWtf("making Network Time Service ready", e);
964 }
965 try {
John Grossmanc1576732012-02-01 15:23:33 -0800966 if (commonTimeMgmtServiceF != null) commonTimeMgmtServiceF.systemReady();
967 } catch (Throwable e) {
968 reportWtf("making Common time management service ready", e);
969 }
970 try {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700971 if (textServiceManagerServiceF != null) textServiceManagerServiceF.systemReady();
972 } catch (Throwable e) {
973 reportWtf("making Text Services Manager Service ready", e);
974 }
Daniel Sandler7d276c32012-01-30 14:33:52 -0500975 try {
976 if (dreamyF != null) dreamyF.systemReady();
977 } catch (Throwable e) {
978 reportWtf("making DreamManagerService ready", e);
979 }
Jeff Brown6ec6f792012-04-17 16:52:41 -0700980 try {
Matthew Xie96313142012-06-29 16:57:31 -0700981 // TODO(BT) Pass parameter to input manager
982 if (inputManagerF != null) inputManagerF.systemReady();
Jeff Brown6ec6f792012-04-17 16:52:41 -0700983 } catch (Throwable e) {
984 reportWtf("making InputManagerService ready", e);
985 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700986 try {
987 if (telephonyRegistryF != null) telephonyRegistryF.systemReady();
988 } catch (Throwable e) {
989 reportWtf("making TelephonyRegistry ready", e);
990 }
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700991 }
992 });
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800993
Brad Fitzpatrick1e02d362010-09-10 09:19:50 -0700994 // For debug builds, log event loop stalls to dropbox for analysis.
Brad Fitzpatrick50d66f92010-09-13 21:29:05 -0700995 if (StrictMode.conditionallyEnableDebugLogging()) {
996 Slog.i(TAG, "Enabled StrictMode for system server main thread.");
Brad Fitzpatrick1e02d362010-09-10 09:19:50 -0700997 }
998
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800999 Looper.loop();
Joe Onorato8a9b2202010-02-26 18:56:32 -08001000 Slog.d(TAG, "System ServerThread is exiting!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001001 }
Joe Onoratof3c3c4f2010-10-21 11:09:02 -04001002
1003 static final void startSystemUi(Context context) {
1004 Intent intent = new Intent();
1005 intent.setComponent(new ComponentName("com.android.systemui",
1006 "com.android.systemui.SystemUIService"));
Dianne Hackborn40e9f292012-11-27 19:12:23 -08001007 //Slog.d(TAG, "Starting service: " + intent);
Amith Yamasanicd757062012-10-19 18:23:52 -07001008 context.startServiceAsUser(intent, UserHandle.OWNER);
Joe Onoratof3c3c4f2010-10-21 11:09:02 -04001009 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001010}
1011
Jeff Hamilton35eef702010-06-09 15:45:18 -05001012public class SystemServer {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001013 private static final String TAG = "SystemServer";
1014
1015 public static final int FACTORY_TEST_OFF = 0;
1016 public static final int FACTORY_TEST_LOW_LEVEL = 1;
1017 public static final int FACTORY_TEST_HIGH_LEVEL = 2;
Jaikumar Ganeshd5ac1ae2009-05-05 22:26:12 -07001018
Bob Leee5408332009-09-04 18:31:17 -07001019 static Timer timer;
1020 static final long SNAPSHOT_INTERVAL = 60 * 60 * 1000; // 1hr
1021
Brad Fitzpatrick6bb7a4a2010-10-11 13:41:10 -07001022 // The earliest supported time. We pick one day into 1970, to
1023 // give any timezone code room without going into negative time.
1024 private static final long EARLIEST_SUPPORTED_TIME = 86400 * 1000;
1025
Jaikumar Ganeshd5ac1ae2009-05-05 22:26:12 -07001026 /**
1027 * 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 -08001028 * services (SurfaceFlinger, AudioFlinger, etc..) to be started. After that it will call back
1029 * up into init2() to start the Android services.
Jaikumar Ganeshd5ac1ae2009-05-05 22:26:12 -07001030 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001031 native public static void init1(String[] args);
1032
1033 public static void main(String[] args) {
Brad Fitzpatrick6bb7a4a2010-10-11 13:41:10 -07001034 if (System.currentTimeMillis() < EARLIEST_SUPPORTED_TIME) {
Brad Fitzpatrick35ca9d82010-10-11 11:52:49 -07001035 // If a device's clock is before 1970 (before 0), a lot of
1036 // APIs crash dealing with negative numbers, notably
1037 // java.io.File#setLastModified, so instead we fake it and
1038 // hope that time from cell towers or NTP fixes it
1039 // shortly.
1040 Slog.w(TAG, "System clock is before 1970; setting to 1970.");
Brad Fitzpatrick6bb7a4a2010-10-11 13:41:10 -07001041 SystemClock.setCurrentTimeMillis(EARLIEST_SUPPORTED_TIME);
Brad Fitzpatrick35ca9d82010-10-11 11:52:49 -07001042 }
1043
Bob Leee5408332009-09-04 18:31:17 -07001044 if (SamplingProfilerIntegration.isEnabled()) {
1045 SamplingProfilerIntegration.start();
1046 timer = new Timer();
1047 timer.schedule(new TimerTask() {
1048 @Override
1049 public void run() {
Sen Hubde75702010-05-28 01:54:03 -07001050 SamplingProfilerIntegration.writeSnapshot("system_server", null);
Bob Leee5408332009-09-04 18:31:17 -07001051 }
1052 }, SNAPSHOT_INTERVAL, SNAPSHOT_INTERVAL);
1053 }
1054
Dianne Hackbornac1471a2011-02-03 13:46:06 -08001055 // Mmmmmm... more memory!
1056 dalvik.system.VMRuntime.getRuntime().clearGrowthLimit();
1057
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001058 // The system server has to run all of the time, so it needs to be
1059 // as efficient as possible with its memory usage.
1060 VMRuntime.getRuntime().setTargetHeapUtilization(0.8f);
Sen Hubde75702010-05-28 01:54:03 -07001061
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001062 System.loadLibrary("android_servers");
1063 init1(args);
1064 }
1065
1066 public static final void init2() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001067 Slog.i(TAG, "Entered the Android system server!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001068 Thread thr = new ServerThread();
1069 thr.setName("android.server.ServerThread");
1070 thr.start();
1071 }
1072}