blob: b263680ef259462d0fda6cffe4e5b4b870980473 [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 Sharkey48749fc2013-04-19 13:25:04 -070029import android.os.Environment;
Jeff Brownbd6e1502012-08-28 03:27:37 -070030import android.os.Handler;
31import android.os.HandlerThread;
Jeff Hamilton35eef702010-06-09 15:45:18 -050032import android.os.Looper;
33import android.os.RemoteException;
34import android.os.ServiceManager;
Brad Fitzpatrickc74a1b442010-09-10 16:03:29 -070035import android.os.StrictMode;
Jeff Hamilton35eef702010-06-09 15:45:18 -050036import android.os.SystemClock;
37import android.os.SystemProperties;
Amith Yamasanicd757062012-10-19 18:23:52 -070038import android.os.UserHandle;
Dianne Hackbornbe87e2f2012-09-28 16:31:34 -070039import android.service.dreams.DreamService;
Joe Onoratodc565f42010-10-04 15:27:22 -040040import android.util.DisplayMetrics;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080041import android.util.EventLog;
Dianne Hackborn661cd522011-08-22 00:26:20 -070042import android.util.Log;
Joe Onorato8a9b2202010-02-26 18:56:32 -080043import android.util.Slog;
Brad Fitzpatrick5fdc0c72010-10-12 13:12:18 -070044import android.view.WindowManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080045
Dan Morrille4d9a012013-03-28 18:10:43 -070046import com.android.internal.R;
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -070047import com.android.internal.os.BinderInternal;
48import com.android.internal.os.SamplingProfilerIntegration;
49import com.android.server.accessibility.AccessibilityManagerService;
Jeff Sharkey7a96c392012-11-15 14:01:46 -080050import com.android.server.accounts.AccountManagerService;
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -070051import com.android.server.am.ActivityManagerService;
Jeff Brown96307042012-07-27 15:51:34 -070052import com.android.server.am.BatteryStatsService;
Jeff Sharkey7a96c392012-11-15 14:01:46 -080053import com.android.server.content.ContentService;
Jeff Brownfa25bf52012-07-23 19:26:30 -070054import com.android.server.display.DisplayManagerService;
Jeff Browncef440f2012-09-25 18:58:48 -070055import com.android.server.dreams.DreamManagerService;
Jeff Brown6ec6f792012-04-17 16:52:41 -070056import com.android.server.input.InputManagerService;
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -070057import com.android.server.net.NetworkPolicyManagerService;
Jeff Sharkey75279902011-05-24 18:39:45 -070058import com.android.server.net.NetworkStatsService;
Jeff Sharkey7a96c392012-11-15 14:01:46 -080059import com.android.server.os.SchedulingPolicyService;
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 Sharkey7a96c392012-11-15 14:01:46 -080065import com.android.server.search.SearchManagerService;
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -070066import com.android.server.usb.UsbService;
Irfan Sheriffd017f352013-02-20 13:30:44 -080067import com.android.server.wifi.WifiService;
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -070068import com.android.server.wm.WindowManagerService;
69
70import dalvik.system.VMRuntime;
71import dalvik.system.Zygote;
72
Dan Egnor4410ec82009-09-11 16:40:01 -070073import java.io.File;
Bob Leee5408332009-09-04 18:31:17 -070074import java.util.Timer;
75import java.util.TimerTask;
76
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080077class ServerThread extends Thread {
78 private static final String TAG = "SystemServer";
Ben Komalo553acf02011-09-19 14:25:28 -070079 private static final String ENCRYPTING_STATE = "trigger_restart_min_framework";
Ben Komalo3573d402011-09-23 15:08:24 -070080 private static final String ENCRYPTED_STATE = "1";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080081
Jeff Hamilton35eef702010-06-09 15:45:18 -050082 ContentResolver mContentResolver;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080083
Dianne Hackborn661cd522011-08-22 00:26:20 -070084 void reportWtf(String msg, Throwable e) {
85 Slog.w(TAG, "***********************************************");
86 Log.wtf(TAG, "BOOT FAILURE " + msg, e);
87 }
88
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080089 @Override
90 public void run() {
Doug Zongkerab5c49c2009-12-04 10:31:43 -080091 EventLog.writeEvent(EventLogTags.BOOT_PROGRESS_SYSTEM_RUN,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080092 SystemClock.uptimeMillis());
93
Vairavan Srinivasan04b74ec2012-02-02 22:12:19 -080094 Looper.prepareMainLooper();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080095
96 android.os.Process.setThreadPriority(
97 android.os.Process.THREAD_PRIORITY_FOREGROUND);
98
Dianne Hackborn887f3552009-12-07 17:59:37 -080099 BinderInternal.disableBackgroundScheduling(true);
Christopher Tate160edb32010-06-30 17:46:30 -0700100 android.os.Process.setCanSelfBackground(false);
Sen Hubde75702010-05-28 01:54:03 -0700101
Kenny Rootf547d672010-09-22 10:36:48 -0700102 // Check whether we failed to shut down last time we tried.
103 {
104 final String shutdownAction = SystemProperties.get(
105 ShutdownThread.SHUTDOWN_ACTION_PROPERTY, "");
106 if (shutdownAction != null && shutdownAction.length() > 0) {
107 boolean reboot = (shutdownAction.charAt(0) == '1');
108
109 final String reason;
110 if (shutdownAction.length() > 1) {
111 reason = shutdownAction.substring(1, shutdownAction.length());
112 } else {
113 reason = null;
114 }
115
116 ShutdownThread.rebootOrShutdown(reboot, reason);
117 }
118 }
119
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800120 String factoryTestStr = SystemProperties.get("ro.factorytest");
121 int factoryTest = "".equals(factoryTestStr) ? SystemServer.FACTORY_TEST_OFF
122 : Integer.parseInt(factoryTestStr);
Mike Lockwood3a74bd32011-08-12 13:55:22 -0700123 final boolean headless = "1".equals(SystemProperties.get("ro.config.headless", "0"));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800124
Jeff Brownf69c8122012-09-12 17:00:34 -0700125 Installer installer = null;
Kenny Root26ff6622012-07-30 12:58:03 -0700126 AccountManagerService accountManager = null;
127 ContentService contentService = null;
Mike Lockwood3a322132009-11-24 00:30:52 -0500128 LightsService lights = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800129 PowerManagerService power = null;
Jeff Brownfa25bf52012-07-23 19:26:30 -0700130 DisplayManagerService display = null;
Mike Lockwood07a500f2009-08-12 09:56:44 -0400131 BatteryService battery = null;
Jeff Brown7f6c2312012-04-13 20:38:38 -0700132 VibratorService vibrator = null;
Jeff Sharkey75279902011-05-24 18:39:45 -0700133 AlarmManagerService alarm = null;
Jeff Sharkeyb049e2122012-09-07 23:16:01 -0700134 MountService mountService = null;
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -0700135 NetworkManagementService networkManagement = null;
Jeff Sharkey75279902011-05-24 18:39:45 -0700136 NetworkStatsService networkStats = null;
Jeff Sharkeya4620792011-05-20 15:29:23 -0700137 NetworkPolicyManagerService networkPolicy = null;
Mike Lockwood0f79b542009-08-14 14:18:49 -0400138 ConnectivityService connectivity = null;
repo sync55bc5f32011-06-24 14:23:07 -0700139 WifiP2pService wifiP2p = null;
repo syncaea743a2011-07-29 23:55:49 -0700140 WifiService wifi = null;
Irfan Sheriff7d024d32012-03-22 17:01:39 -0700141 NsdService serviceDiscovery= null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800142 IPackageManager pm = null;
143 Context context = null;
144 WindowManagerService wm = null;
fredc0f420372012-04-12 00:02:00 -0700145 BluetoothManagerService bluetooth = null;
Dan Murphyc9f4eaf2009-08-12 15:15:43 -0500146 DockObserver dock = null;
Mike Lockwood770126a2010-12-09 22:30:37 -0800147 UsbService usb = null;
Mike Lockwoodb01e8bf2011-08-29 20:11:07 -0400148 SerialService serial = null;
Jeff Brown2416e092012-08-21 22:12:20 -0700149 TwilightService twilight = null;
Dianne Hackborn7299c412010-03-04 18:41:49 -0800150 UiModeManagerService uiMode = null;
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800151 RecognitionManagerService recognition = null;
Amith Yamasani6734b9f62010-09-13 16:24:08 -0700152 NetworkTimeUpdateService networkTimeUpdater = null;
John Grossmanc1576732012-02-01 15:23:33 -0800153 CommonTimeManagementService commonTimeMgmtService = null;
Jeff Brown6ec6f792012-04-17 16:52:41 -0700154 InputManagerService inputManager = null;
Wink Savillea12a7b32012-09-20 10:09:45 -0700155 TelephonyRegistry telephonyRegistry = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800156
Jeff Brownbd6e1502012-08-28 03:27:37 -0700157 // Create a shared handler thread for UI within the system server.
158 // This thread is used by at least the following components:
159 // - WindowManagerPolicy
160 // - KeyguardViewManager
161 // - DisplayManagerService
162 HandlerThread uiHandlerThread = new HandlerThread("UI");
163 uiHandlerThread.start();
164 Handler uiHandler = new Handler(uiHandlerThread.getLooper());
165 uiHandler.post(new Runnable() {
166 @Override
167 public void run() {
168 //Looper.myLooper().setMessageLogging(new LogPrinter(
169 // Log.VERBOSE, "WindowManagerPolicy", Log.LOG_ID_SYSTEM));
170 android.os.Process.setThreadPriority(
171 android.os.Process.THREAD_PRIORITY_FOREGROUND);
172 android.os.Process.setCanSelfBackground(false);
173
174 // For debug builds, log event loop stalls to dropbox for analysis.
175 if (StrictMode.conditionallyEnableDebugLogging()) {
176 Slog.i(TAG, "Enabled StrictMode logging for UI Looper");
177 }
178 }
179 });
180
181 // Create a handler thread just for the window manager to enjoy.
182 HandlerThread wmHandlerThread = new HandlerThread("WindowManager");
183 wmHandlerThread.start();
184 Handler wmHandler = new Handler(wmHandlerThread.getLooper());
185 wmHandler.post(new Runnable() {
186 @Override
187 public void run() {
188 //Looper.myLooper().setMessageLogging(new LogPrinter(
189 // android.util.Log.DEBUG, TAG, android.util.Log.LOG_ID_SYSTEM));
190 android.os.Process.setThreadPriority(
191 android.os.Process.THREAD_PRIORITY_DISPLAY);
192 android.os.Process.setCanSelfBackground(false);
193
194 // For debug builds, log event loop stalls to dropbox for analysis.
195 if (StrictMode.conditionallyEnableDebugLogging()) {
Jeff Brown89d55462012-09-19 11:33:42 -0700196 Slog.i(TAG, "Enabled StrictMode logging for WM Looper");
Jeff Brownbd6e1502012-08-28 03:27:37 -0700197 }
198 }
199 });
200
Dan Morrille4d9a012013-03-28 18:10:43 -0700201 // bootstrap services
Jeff Brownbd6e1502012-08-28 03:27:37 -0700202 boolean onlyCore = false;
Dan Morrille4d9a012013-03-28 18:10:43 -0700203 boolean firstBoot = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800204 try {
Jeff Brownf69c8122012-09-12 17:00:34 -0700205 // Wait for installd to finished starting up so that it has a chance to
206 // create critical directories such as /data/user with the appropriate
207 // permissions. We need this to complete before we initialize other services.
208 Slog.i(TAG, "Waiting for installd to be ready.");
209 installer = new Installer();
210 installer.ping();
211
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);
Dan Morrille4d9a012013-03-28 18:10:43 -0700218 } catch (RuntimeException e) {
219 Slog.e("System", "******************************************");
220 Slog.e("System", "************ Failure starting bootstrap service", e);
221 }
Jeff Brown848c2dc2012-08-19 20:18:08 -0700222
Dan Morrille4d9a012013-03-28 18:10:43 -0700223 boolean disableStorage = SystemProperties.getBoolean("config.disable_storage", false);
224 boolean disableMedia = SystemProperties.getBoolean("config.disable_media", false);
225 boolean disableBluetooth = SystemProperties.getBoolean("config.disable_bluetooth", false);
226 boolean disableTelephony = SystemProperties.getBoolean("config.disable_telephony", false);
227 boolean disableLocation = SystemProperties.getBoolean("config.disable_location", false);
228 boolean disableSystemUI = SystemProperties.getBoolean("config.disable_systemui", false);
229 boolean disableNonCoreServices = SystemProperties.getBoolean("config.disable_noncore", false);
230 boolean disableNetwork = SystemProperties.getBoolean("config.disable_network", false);
231
232 try {
Jeff Brown848c2dc2012-08-19 20:18:08 -0700233 Slog.i(TAG, "Display Manager");
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700234 display = new DisplayManagerService(context, wmHandler, uiHandler);
Jeff Brown848c2dc2012-08-19 20:18:08 -0700235 ServiceManager.addService(Context.DISPLAY_SERVICE, display, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800236
Joe Onorato8a9b2202010-02-26 18:56:32 -0800237 Slog.i(TAG, "Telephony Registry");
Wink Savillea12a7b32012-09-20 10:09:45 -0700238 telephonyRegistry = new TelephonyRegistry(context);
239 ServiceManager.addService("telephony.registry", telephonyRegistry);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800240
Glenn Kasten07b04652012-04-23 15:00:43 -0700241 Slog.i(TAG, "Scheduling Policy");
242 ServiceManager.addService(Context.SCHEDULING_POLICY_SERVICE,
243 new SchedulingPolicyService());
244
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800245 AttributeCache.init(context);
246
Jeff Brownbd6e1502012-08-28 03:27:37 -0700247 if (!display.waitForDefaultDisplay()) {
248 reportWtf("Timeout waiting for default display to be initialized.",
249 new Throwable());
250 }
251
Joe Onorato8a9b2202010-02-26 18:56:32 -0800252 Slog.i(TAG, "Package Manager");
Ben Komalo553acf02011-09-19 14:25:28 -0700253 // Only run "core" apps if we're encrypting the device.
254 String cryptState = SystemProperties.get("vold.decrypt");
Ben Komalo3573d402011-09-23 15:08:24 -0700255 if (ENCRYPTING_STATE.equals(cryptState)) {
Ben Komalo553acf02011-09-19 14:25:28 -0700256 Slog.w(TAG, "Detected encryption in progress - only parsing core apps");
Ben Komalo3573d402011-09-23 15:08:24 -0700257 onlyCore = true;
258 } else if (ENCRYPTED_STATE.equals(cryptState)) {
259 Slog.w(TAG, "Device encrypted - only parsing core apps");
260 onlyCore = true;
Ben Komalo553acf02011-09-19 14:25:28 -0700261 }
Ben Komalo3573d402011-09-23 15:08:24 -0700262
Jeff Brownf69c8122012-09-12 17:00:34 -0700263 pm = PackageManagerService.main(context, installer,
Dianne Hackbornd2509fd2011-09-12 12:29:43 -0700264 factoryTest != SystemServer.FACTORY_TEST_OFF,
Ben Komalo553acf02011-09-19 14:25:28 -0700265 onlyCore);
Dianne Hackborn58f42a52011-10-10 13:46:34 -0700266 try {
267 firstBoot = pm.isFirstBoot();
268 } catch (RemoteException e) {
269 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800270
271 ActivityManagerService.setSystemProcess();
Svetoslavb3038ec2013-02-13 14:39:30 -0800272
Nick Kralevich79619dd2013-03-04 13:05:32 -0800273 Slog.i(TAG, "Entropy Mixer");
274 ServiceManager.addService("entropy", new EntropyMixer(context));
275
Amith Yamasani258848d2012-08-10 17:06:33 -0700276 Slog.i(TAG, "User Service");
277 ServiceManager.addService(Context.USER_SERVICE,
Dianne Hackborn4428e17c2012-08-24 17:43:05 -0700278 UserManagerService.getInstance());
Amith Yamasani258848d2012-08-10 17:06:33 -0700279
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800280 mContentResolver = context.getContentResolver();
281
Fred Quintanae91ebe22009-09-29 20:44:30 -0700282 // The AccountManager must come before the ContentService
Fred Quintana60307342009-03-24 22:48:12 -0700283 try {
Dan Morrille4d9a012013-03-28 18:10:43 -0700284 // TODO: seems like this should be disable-able, but req'd by ContentService
Joe Onorato8a9b2202010-02-26 18:56:32 -0800285 Slog.i(TAG, "Account Manager");
Kenny Root26ff6622012-07-30 12:58:03 -0700286 accountManager = new AccountManagerService(context);
287 ServiceManager.addService(Context.ACCOUNT_SERVICE, accountManager);
Fred Quintana60307342009-03-24 22:48:12 -0700288 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800289 Slog.e(TAG, "Failure starting Account Manager", e);
Fred Quintana60307342009-03-24 22:48:12 -0700290 }
291
Joe Onorato8a9b2202010-02-26 18:56:32 -0800292 Slog.i(TAG, "Content Manager");
Kenny Root26ff6622012-07-30 12:58:03 -0700293 contentService = ContentService.main(context,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800294 factoryTest == SystemServer.FACTORY_TEST_LOW_LEVEL);
295
Joe Onorato8a9b2202010-02-26 18:56:32 -0800296 Slog.i(TAG, "System Content Providers");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800297 ActivityManagerService.installSystemProviders();
298
Joe Onorato8a9b2202010-02-26 18:56:32 -0800299 Slog.i(TAG, "Lights Service");
Mike Lockwood3a322132009-11-24 00:30:52 -0500300 lights = new LightsService(context);
301
Joe Onoratode1b3592010-10-25 20:36:47 -0700302 Slog.i(TAG, "Battery Service");
303 battery = new BatteryService(context, lights);
304 ServiceManager.addService("battery", battery);
305
Joe Onorato8a9b2202010-02-26 18:56:32 -0800306 Slog.i(TAG, "Vibrator Service");
Jeff Brown7f6c2312012-04-13 20:38:38 -0700307 vibrator = new VibratorService(context);
308 ServiceManager.addService("vibrator", vibrator);
The Android Open Source Project10592532009-03-18 17:39:46 -0700309
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800310 // only initialize the power service after we have started the
Mike Lockwood3a322132009-11-24 00:30:52 -0500311 // lights service, content providers and the battery service.
Jeff Brown96307042012-07-27 15:51:34 -0700312 power.init(context, lights, ActivityManagerService.self(), battery,
313 BatteryStatsService.getService(), display);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800314
Joe Onorato8a9b2202010-02-26 18:56:32 -0800315 Slog.i(TAG, "Alarm Manager");
Jeff Sharkey75279902011-05-24 18:39:45 -0700316 alarm = new AlarmManagerService(context);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800317 ServiceManager.addService(Context.ALARM_SERVICE, alarm);
318
Joe Onorato8a9b2202010-02-26 18:56:32 -0800319 Slog.i(TAG, "Init Watchdog");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800320 Watchdog.getInstance().init(context, battery, power, alarm,
321 ActivityManagerService.self());
322
Jeff Browna9d131c2012-09-20 16:48:17 -0700323 Slog.i(TAG, "Input Manager");
324 inputManager = new InputManagerService(context, wmHandler);
325
Joe Onorato8a9b2202010-02-26 18:56:32 -0800326 Slog.i(TAG, "Window Manager");
Jeff Browna9d131c2012-09-20 16:48:17 -0700327 wm = WindowManagerService.main(context, power, display, inputManager,
Jeff Brownbd6e1502012-08-28 03:27:37 -0700328 uiHandler, wmHandler,
Dianne Hackborn58f42a52011-10-10 13:46:34 -0700329 factoryTest != SystemServer.FACTORY_TEST_LOW_LEVEL,
Jeff Brown780c46f2012-06-24 12:15:38 -0700330 !firstBoot, onlyCore);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800331 ServiceManager.addService(Context.WINDOW_SERVICE, wm);
Jeff Brown6ec6f792012-04-17 16:52:41 -0700332 ServiceManager.addService(Context.INPUT_SERVICE, inputManager);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800333
Dianne Hackborn295e3c22011-08-25 13:19:08 -0700334 ActivityManagerService.self().setWindowManager(wm);
Jeff Browna9d131c2012-09-20 16:48:17 -0700335
336 inputManager.setWindowManagerCallbacks(wm.getInputMonitor());
337 inputManager.start();
338
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700339 display.setWindowManager(wm);
Jeff Brownd728bf52012-09-08 18:05:28 -0700340 display.setInputManager(inputManager);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800341
342 // Skip Bluetooth if we have an emulator kernel
343 // TODO: Use a more reliable check to see if this product should
344 // support Bluetooth - see bug 988521
345 if (SystemProperties.get("ro.kernel.qemu").equals("1")) {
David 'Digit' Turnere2a5e862011-01-17 00:32:33 +0100346 Slog.i(TAG, "No Bluetooh Service (emulator)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800347 } else if (factoryTest == SystemServer.FACTORY_TEST_LOW_LEVEL) {
David 'Digit' Turnere2a5e862011-01-17 00:32:33 +0100348 Slog.i(TAG, "No Bluetooth Service (factory test)");
Dan Morrille4d9a012013-03-28 18:10:43 -0700349 } else if (disableBluetooth) {
350 Slog.i(TAG, "Bluetooth Service disabled by config");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800351 } else {
fredc0f420372012-04-12 00:02:00 -0700352 Slog.i(TAG, "Bluetooth Manager Service");
353 bluetooth = new BluetoothManagerService(context);
354 ServiceManager.addService(BluetoothAdapter.BLUETOOTH_MANAGER_SERVICE, bluetooth);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800355 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800356 } catch (RuntimeException e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700357 Slog.e("System", "******************************************");
358 Slog.e("System", "************ Failure starting core service", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800359 }
360
Dianne Hackbornd6847842010-01-12 18:14:19 -0800361 DevicePolicyManagerService devicePolicy = null;
Joe Onorato089de882010-04-12 08:18:45 -0700362 StatusBarManagerService statusBar = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800363 InputMethodManagerService imm = null;
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700364 AppWidgetService appWidget = null;
Joe Onorato30275482009-07-08 17:09:14 -0700365 NotificationManagerService notification = null;
Dianne Hackbornf21adf62009-08-13 10:20:21 -0700366 WallpaperManagerService wallpaper = null;
Mike Lockwood46db5042010-02-22 16:36:44 -0500367 LocationManagerService location = null;
Bai Taoa58a8752010-07-13 15:32:16 +0800368 CountryDetectorService countryDetector = null;
satok988323c2011-06-22 16:38:13 +0900369 TextServicesManagerService tsms = null;
Amith Yamasani52c489c2012-03-28 11:42:42 -0700370 LockSettingsService lockSettings = null;
Daniel Sandler7d276c32012-01-30 14:33:52 -0500371 DreamManagerService dreamy = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800372
Dianne Hackborn661cd522011-08-22 00:26:20 -0700373 // Bring up services needed for UI.
374 if (factoryTest != SystemServer.FACTORY_TEST_LOW_LEVEL) {
Dan Morrille4d9a012013-03-28 18:10:43 -0700375 //if (!disableNonCoreServices) { // TODO: View depends on these; mock them?
376 if (true) {
377 try {
378 Slog.i(TAG, "Input Method Service");
379 imm = new InputMethodManagerService(context, wm);
380 ServiceManager.addService(Context.INPUT_METHOD_SERVICE, imm);
381 } catch (Throwable e) {
382 reportWtf("starting Input Manager Service", e);
383 }
Dianne Hackborn661cd522011-08-22 00:26:20 -0700384
Dan Morrille4d9a012013-03-28 18:10:43 -0700385 try {
386 Slog.i(TAG, "Accessibility Manager");
387 ServiceManager.addService(Context.ACCESSIBILITY_SERVICE,
388 new AccessibilityManagerService(context));
389 } catch (Throwable e) {
390 reportWtf("starting Accessibility Manager", e);
391 }
Dianne Hackborn661cd522011-08-22 00:26:20 -0700392 }
393 }
394
395 try {
396 wm.displayReady();
397 } catch (Throwable e) {
398 reportWtf("making display ready", e);
399 }
Dianne Hackborn8795b602011-08-25 13:30:53 -0700400
Dianne Hackborn295e3c22011-08-25 13:19:08 -0700401 try {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700402 pm.performBootDexOpt();
403 } catch (Throwable e) {
404 reportWtf("performing boot dexopt", e);
405 }
406
407 try {
408 ActivityManagerNative.getDefault().showBootMessage(
409 context.getResources().getText(
410 com.android.internal.R.string.android_upgrading_starting_apps),
411 false);
412 } catch (RemoteException e) {
413 }
414
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800415 if (factoryTest != SystemServer.FACTORY_TEST_LOW_LEVEL) {
Dan Morrille4d9a012013-03-28 18:10:43 -0700416 if (!disableStorage &&
417 !"0".equals(SystemProperties.get("system_init.startmountservice"))) {
Kenny Root51a573c2012-05-17 13:30:28 -0700418 try {
419 /*
420 * NotificationManagerService is dependant on MountService,
421 * (for media / usb notifications) so we must start MountService first.
422 */
423 Slog.i(TAG, "Mount Service");
424 mountService = new MountService(context);
425 ServiceManager.addService("mount", mountService);
426 } catch (Throwable e) {
427 reportWtf("starting Mount Service", e);
428 }
429 }
430
Dan Morrille4d9a012013-03-28 18:10:43 -0700431 if (!disableNonCoreServices) {
432 try {
433 Slog.i(TAG, "LockSettingsService");
434 lockSettings = new LockSettingsService(context);
435 ServiceManager.addService("lock_settings", lockSettings);
436 } catch (Throwable e) {
437 reportWtf("starting LockSettingsService service", e);
438 }
439
440 try {
441 Slog.i(TAG, "Device Policy");
442 devicePolicy = new DevicePolicyManagerService(context);
443 ServiceManager.addService(Context.DEVICE_POLICY_SERVICE, devicePolicy);
444 } catch (Throwable e) {
445 reportWtf("starting DevicePolicyService", e);
446 }
Amith Yamasani52c489c2012-03-28 11:42:42 -0700447 }
448
Dan Morrille4d9a012013-03-28 18:10:43 -0700449 if (!disableSystemUI) {
450 try {
451 Slog.i(TAG, "Status Bar");
452 statusBar = new StatusBarManagerService(context, wm);
453 ServiceManager.addService(Context.STATUS_BAR_SERVICE, statusBar);
454 } catch (Throwable e) {
455 reportWtf("starting StatusBarManagerService", e);
456 }
Dianne Hackbornd6847842010-01-12 18:14:19 -0800457 }
458
Dan Morrille4d9a012013-03-28 18:10:43 -0700459 if (!disableNonCoreServices) {
460 try {
461 Slog.i(TAG, "Clipboard Service");
462 ServiceManager.addService(Context.CLIPBOARD_SERVICE,
463 new ClipboardService(context));
464 } catch (Throwable e) {
465 reportWtf("starting Clipboard Service", e);
466 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800467 }
468
Dan Morrille4d9a012013-03-28 18:10:43 -0700469 if (!disableNetwork) {
470 try {
471 Slog.i(TAG, "NetworkManagement Service");
472 networkManagement = NetworkManagementService.create(context);
473 ServiceManager.addService(Context.NETWORKMANAGEMENT_SERVICE, networkManagement);
474 } catch (Throwable e) {
475 reportWtf("starting NetworkManagement Service", e);
476 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800477 }
478
Dan Morrille4d9a012013-03-28 18:10:43 -0700479 if (!disableNonCoreServices) {
480 try {
481 Slog.i(TAG, "Text Service Manager Service");
482 tsms = new TextServicesManagerService(context);
483 ServiceManager.addService(Context.TEXT_SERVICES_MANAGER_SERVICE, tsms);
484 } catch (Throwable e) {
485 reportWtf("starting Text Service Manager Service", e);
486 }
San Mehatd1df8ac2010-01-26 06:17:26 -0800487 }
488
Dan Morrille4d9a012013-03-28 18:10:43 -0700489 if (!disableNetwork) {
490 try {
491 Slog.i(TAG, "NetworkStats Service");
492 networkStats = new NetworkStatsService(context, networkManagement, alarm);
493 ServiceManager.addService(Context.NETWORK_STATS_SERVICE, networkStats);
494 } catch (Throwable e) {
495 reportWtf("starting NetworkStats Service", e);
496 }
497
498 try {
499 Slog.i(TAG, "NetworkPolicy Service");
500 networkPolicy = new NetworkPolicyManagerService(
501 context, ActivityManagerService.self(), power,
502 networkStats, networkManagement);
503 ServiceManager.addService(Context.NETWORK_POLICY_SERVICE, networkPolicy);
504 } catch (Throwable e) {
505 reportWtf("starting NetworkPolicy Service", e);
506 }
507
508 try {
509 Slog.i(TAG, "Wi-Fi P2pService");
510 wifiP2p = new WifiP2pService(context);
511 ServiceManager.addService(Context.WIFI_P2P_SERVICE, wifiP2p);
512 } catch (Throwable e) {
513 reportWtf("starting Wi-Fi P2pService", e);
514 }
515
516 try {
517 Slog.i(TAG, "Wi-Fi Service");
518 wifi = new WifiService(context);
519 ServiceManager.addService(Context.WIFI_SERVICE, wifi);
520 } catch (Throwable e) {
521 reportWtf("starting Wi-Fi Service", e);
522 }
523
524 try {
525 Slog.i(TAG, "Connectivity Service");
526 connectivity = new ConnectivityService(
527 context, networkManagement, networkStats, networkPolicy);
528 ServiceManager.addService(Context.CONNECTIVITY_SERVICE, connectivity);
529 networkStats.bindConnectivityManager(connectivity);
530 networkPolicy.bindConnectivityManager(connectivity);
531 wifi.checkAndStartWifi();
532 wifiP2p.connectivityServiceReady();
533 } catch (Throwable e) {
534 reportWtf("starting Connectivity Service", e);
535 }
536
537 try {
538 Slog.i(TAG, "Network Service Discovery Service");
539 serviceDiscovery = NsdService.create(context);
540 ServiceManager.addService(
541 Context.NSD_SERVICE, serviceDiscovery);
542 } catch (Throwable e) {
543 reportWtf("starting Service Discovery Service", e);
544 }
satok988323c2011-06-22 16:38:13 +0900545 }
546
Dan Morrille4d9a012013-03-28 18:10:43 -0700547 if (!disableNonCoreServices) {
548 try {
549 Slog.i(TAG, "UpdateLock Service");
550 ServiceManager.addService(Context.UPDATE_LOCK_SERVICE,
551 new UpdateLockService(context));
552 } catch (Throwable e) {
553 reportWtf("starting UpdateLockService", e);
554 }
Christopher Tate8662cab52012-02-23 14:59:36 -0800555 }
556
Kenny Root51a573c2012-05-17 13:30:28 -0700557 /*
558 * MountService has a few dependencies: Notification Manager and
559 * AppWidget Provider. Make sure MountService is completely started
560 * first before continuing.
561 */
562 if (mountService != null) {
563 mountService.waitForAsecScan();
San Mehat1bf3f8b2010-02-03 14:43:09 -0800564 }
565
566 try {
Kenny Root26ff6622012-07-30 12:58:03 -0700567 if (accountManager != null)
568 accountManager.systemReady();
569 } catch (Throwable e) {
570 reportWtf("making Account Manager Service ready", e);
571 }
572
573 try {
574 if (contentService != null)
575 contentService.systemReady();
576 } catch (Throwable e) {
577 reportWtf("making Content Service ready", e);
578 }
579
580 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800581 Slog.i(TAG, "Notification Manager");
Mike Lockwood3a322132009-11-24 00:30:52 -0500582 notification = new NotificationManagerService(context, statusBar, lights);
Joe Onorato30275482009-07-08 17:09:14 -0700583 ServiceManager.addService(Context.NOTIFICATION_SERVICE, notification);
Jeff Sharkey497e4432011-06-14 17:27:29 -0700584 networkPolicy.bindNotificationManager(notification);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800585 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700586 reportWtf("starting Notification Manager", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800587 }
588
589 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800590 Slog.i(TAG, "Device Storage Monitor");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800591 ServiceManager.addService(DeviceStorageMonitorService.SERVICE,
592 new DeviceStorageMonitorService(context));
593 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700594 reportWtf("starting DeviceStorageMonitor service", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800595 }
596
Dan Morrille4d9a012013-03-28 18:10:43 -0700597 if (!disableLocation) {
598 try {
599 Slog.i(TAG, "Location Manager");
600 location = new LocationManagerService(context);
601 ServiceManager.addService(Context.LOCATION_SERVICE, location);
602 } catch (Throwable e) {
603 reportWtf("starting Location Manager", e);
604 }
605
606 try {
607 Slog.i(TAG, "Country Detector");
608 countryDetector = new CountryDetectorService(context);
609 ServiceManager.addService(Context.COUNTRY_DETECTOR, countryDetector);
610 } catch (Throwable e) {
611 reportWtf("starting Country Detector", e);
612 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800613 }
614
Dan Morrille4d9a012013-03-28 18:10:43 -0700615 if (!disableNonCoreServices) {
616 try {
617 Slog.i(TAG, "Search Service");
618 ServiceManager.addService(Context.SEARCH_SERVICE,
619 new SearchManagerService(context));
620 } catch (Throwable e) {
621 reportWtf("starting Search Service", e);
622 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800623 }
624
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800625 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800626 Slog.i(TAG, "DropBox Service");
Dan Egnor95240272009-10-27 18:23:39 -0700627 ServiceManager.addService(Context.DROPBOX_SERVICE,
Dan Egnorf18a01c2009-11-12 11:32:50 -0800628 new DropBoxManagerService(context, new File("/data/system/dropbox")));
Dan Egnor4410ec82009-09-11 16:40:01 -0700629 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700630 reportWtf("starting DropBoxManagerService", e);
Dan Egnor4410ec82009-09-11 16:40:01 -0700631 }
632
Dan Morrille4d9a012013-03-28 18:10:43 -0700633 if (!disableNonCoreServices && context.getResources().getBoolean(
634 R.bool.config_enableWallpaperService)) {
Mike Lockwoodc067c9c2011-10-31 12:50:12 -0400635 try {
636 Slog.i(TAG, "Wallpaper Service");
637 if (!headless) {
638 wallpaper = new WallpaperManagerService(context);
639 ServiceManager.addService(Context.WALLPAPER_SERVICE, wallpaper);
640 }
641 } catch (Throwable e) {
642 reportWtf("starting Wallpaper Service", e);
Mike Lockwood3a74bd32011-08-12 13:55:22 -0700643 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800644 }
645
Dan Morrille4d9a012013-03-28 18:10:43 -0700646 if (!disableMedia && !"0".equals(SystemProperties.get("system_init.startaudioservice"))) {
Mike Lockwoodcba928c2011-08-17 15:58:52 -0700647 try {
648 Slog.i(TAG, "Audio Service");
649 ServiceManager.addService(Context.AUDIO_SERVICE, new AudioService(context));
650 } catch (Throwable e) {
651 reportWtf("starting Audio Service", e);
652 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800653 }
654
Dan Morrille4d9a012013-03-28 18:10:43 -0700655 if (!disableNonCoreServices) {
656 try {
657 Slog.i(TAG, "Dock Observer");
658 // Listen for dock station changes
659 dock = new DockObserver(context);
660 } catch (Throwable e) {
661 reportWtf("starting DockObserver", e);
662 }
Dan Murphyc9f4eaf2009-08-12 15:15:43 -0500663 }
664
Dan Morrille4d9a012013-03-28 18:10:43 -0700665 if (!disableMedia) {
666 try {
667 Slog.i(TAG, "Wired Accessory Manager");
668 // Listen for wired headset changes
669 inputManager.setWiredAccessoryCallbacks(
670 new WiredAccessoryManager(context, inputManager));
671 } catch (Throwable e) {
672 reportWtf("starting WiredAccessoryManager", e);
673 }
Praveen Bharathi21e941b2010-10-06 15:23:14 -0500674 }
675
Dan Morrille4d9a012013-03-28 18:10:43 -0700676 if (!disableNonCoreServices) {
677 try {
678 Slog.i(TAG, "USB Service");
679 // Manage USB host and device support
680 usb = new UsbService(context);
681 ServiceManager.addService(Context.USB_SERVICE, usb);
682 } catch (Throwable e) {
683 reportWtf("starting UsbService", e);
684 }
Mike Lockwood57c798a2010-06-23 17:36:36 -0400685
Dan Morrille4d9a012013-03-28 18:10:43 -0700686 try {
687 Slog.i(TAG, "Serial Service");
688 // Serial port support
689 serial = new SerialService(context);
690 ServiceManager.addService(Context.SERIAL_SERVICE, serial);
691 } catch (Throwable e) {
692 Slog.e(TAG, "Failure starting SerialService", e);
693 }
Mike Lockwoodb01e8bf2011-08-29 20:11:07 -0400694 }
695
696 try {
Jeff Brown2416e092012-08-21 22:12:20 -0700697 Slog.i(TAG, "Twilight Service");
698 twilight = new TwilightService(context);
699 } catch (Throwable e) {
700 reportWtf("starting TwilightService", e);
701 }
702
703 try {
Dianne Hackborn7299c412010-03-04 18:41:49 -0800704 Slog.i(TAG, "UI Mode Manager Service");
Mike Lockwood57c798a2010-06-23 17:36:36 -0400705 // Listen for UI mode changes
Jeff Brown2416e092012-08-21 22:12:20 -0700706 uiMode = new UiModeManagerService(context, twilight);
Dianne Hackborn7299c412010-03-04 18:41:49 -0800707 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700708 reportWtf("starting UiModeManagerService", e);
Dianne Hackborn7299c412010-03-04 18:41:49 -0800709 }
710
Dan Morrille4d9a012013-03-28 18:10:43 -0700711 if (!disableNonCoreServices) {
712 try {
713 Slog.i(TAG, "Backup Service");
714 ServiceManager.addService(Context.BACKUP_SERVICE,
715 new BackupManagerService(context));
716 } catch (Throwable e) {
717 Slog.e(TAG, "Failure starting Backup Service", e);
718 }
Christopher Tate487529a2009-04-29 14:03:25 -0700719
Dan Morrille4d9a012013-03-28 18:10:43 -0700720 try {
721 Slog.i(TAG, "AppWidget Service");
722 appWidget = new AppWidgetService(context);
723 ServiceManager.addService(Context.APPWIDGET_SERVICE, appWidget);
724 } catch (Throwable e) {
725 reportWtf("starting AppWidget Service", e);
726 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800727
Dan Morrille4d9a012013-03-28 18:10:43 -0700728 try {
729 Slog.i(TAG, "Recognition Service");
730 recognition = new RecognitionManagerService(context);
731 } catch (Throwable e) {
732 reportWtf("starting Recognition Service", e);
733 }
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800734 }
Jaikumar Ganesh7d0548d2010-10-18 15:29:09 -0700735
Nick Pelly038cabe2010-09-23 16:12:11 -0700736 try {
Dan Egnor621bc542010-03-25 16:20:14 -0700737 Slog.i(TAG, "DiskStats Service");
738 ServiceManager.addService("diskstats", new DiskStatsService(context));
739 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700740 reportWtf("starting DiskStats Service", e);
Dan Egnor621bc542010-03-25 16:20:14 -0700741 }
Sen Hubde75702010-05-28 01:54:03 -0700742
743 try {
744 // need to add this service even if SamplingProfilerIntegration.isEnabled()
745 // is false, because it is this service that detects system property change and
746 // turns on SamplingProfilerIntegration. Plus, when sampling profiler doesn't work,
747 // there is little overhead for running this service.
748 Slog.i(TAG, "SamplingProfiler Service");
749 ServiceManager.addService("samplingprofiler",
750 new SamplingProfilerService(context));
751 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700752 reportWtf("starting SamplingProfiler Service", e);
Sen Hubde75702010-05-28 01:54:03 -0700753 }
Chung-yih Wang024d5962010-08-06 12:06:04 +0800754
Dan Morrille4d9a012013-03-28 18:10:43 -0700755 if (!disableNetwork) {
756 try {
757 Slog.i(TAG, "NetworkTimeUpdateService");
758 networkTimeUpdater = new NetworkTimeUpdateService(context);
759 } catch (Throwable e) {
760 reportWtf("starting NetworkTimeUpdate service", e);
761 }
Amith Yamasani6734b9f62010-09-13 16:24:08 -0700762 }
John Grossmanc1576732012-02-01 15:23:33 -0800763
Dan Morrille4d9a012013-03-28 18:10:43 -0700764 if (!disableMedia) {
765 try {
766 Slog.i(TAG, "CommonTimeManagementService");
767 commonTimeMgmtService = new CommonTimeManagementService(context);
768 ServiceManager.addService("commontime_management", commonTimeMgmtService);
769 } catch (Throwable e) {
770 reportWtf("starting CommonTimeManagementService service", e);
771 }
John Grossmanc1576732012-02-01 15:23:33 -0800772 }
Geremy Condra3d33c262012-05-06 18:32:19 -0700773
Dan Morrille4d9a012013-03-28 18:10:43 -0700774 if (!disableNetwork) {
775 try {
776 Slog.i(TAG, "CertBlacklister");
777 CertBlacklister blacklister = new CertBlacklister(context);
778 } catch (Throwable e) {
779 reportWtf("starting CertBlacklister", e);
780 }
Geremy Condra3d33c262012-05-06 18:32:19 -0700781 }
Jim Miller5ecd8112013-01-09 18:50:26 -0800782
Dan Morrille4d9a012013-03-28 18:10:43 -0700783 if (!disableNonCoreServices &&
784 context.getResources().getBoolean(R.bool.config_dreamsSupported)) {
Daniel Sandler7d276c32012-01-30 14:33:52 -0500785 try {
786 Slog.i(TAG, "Dreams Service");
787 // Dreams (interactive idle-time views, a/k/a screen savers)
Jeff Brown62c82e42012-09-26 01:30:41 -0700788 dreamy = new DreamManagerService(context, wmHandler);
Dianne Hackbornbe87e2f2012-09-28 16:31:34 -0700789 ServiceManager.addService(DreamService.DREAM_SERVICE, dreamy);
Daniel Sandler7d276c32012-01-30 14:33:52 -0500790 } catch (Throwable e) {
791 reportWtf("starting DreamManagerService", e);
792 }
793 }
Svetoslavb3038ec2013-02-13 14:39:30 -0800794
795 try {
796 Slog.i(TAG, "IdleMaintenanceService");
797 new IdleMaintenanceService(context);
798 } catch (Throwable e) {
799 reportWtf("starting IdleMaintenanceService", e);
800 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800801 }
802
Dianne Hackborn6af0d502009-09-28 13:25:46 -0700803 // Before things start rolling, be sure we have decided whether
804 // we are in safe mode.
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700805 final boolean safeMode = wm.detectSafeMode();
Dianne Hackborn6af0d502009-09-28 13:25:46 -0700806 if (safeMode) {
Jeff Brownb09abc12011-01-13 21:08:27 -0800807 ActivityManagerService.self().enterSafeMode();
808 // Post the safe mode state in the Zygote class
809 Zygote.systemInSafeMode = true;
810 // Disable the JIT for the system_server process
811 VMRuntime.getRuntime().disableJitCompilation();
Ben Cheng6c0afff2010-02-14 16:18:56 -0800812 } else {
813 // Enable the JIT for the system_server process
814 VMRuntime.getRuntime().startJitCompilation();
Dianne Hackborn6af0d502009-09-28 13:25:46 -0700815 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800816
Dianne Hackborn6af0d502009-09-28 13:25:46 -0700817 // It is now time to start up the app processes...
Joe Onorato30275482009-07-08 17:09:14 -0700818
Jeff Brown7f6c2312012-04-13 20:38:38 -0700819 try {
820 vibrator.systemReady();
821 } catch (Throwable e) {
822 reportWtf("making Vibrator Service ready", e);
823 }
824
Dan Morrille4d9a012013-03-28 18:10:43 -0700825 if (lockSettings != null) {
826 try {
827 lockSettings.systemReady();
828 } catch (Throwable e) {
829 reportWtf("making Lock Settings Service ready", e);
830 }
Felipe Ramosf35df5b2012-09-18 18:26:27 -0300831 }
832
Dianne Hackbornd6847842010-01-12 18:14:19 -0800833 if (devicePolicy != null) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700834 try {
835 devicePolicy.systemReady();
836 } catch (Throwable e) {
837 reportWtf("making Device Policy Service ready", e);
838 }
Dianne Hackbornd6847842010-01-12 18:14:19 -0800839 }
840
Joe Onorato30275482009-07-08 17:09:14 -0700841 if (notification != null) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700842 try {
843 notification.systemReady();
844 } catch (Throwable e) {
845 reportWtf("making Notification Service ready", e);
846 }
Joe Onorato30275482009-07-08 17:09:14 -0700847 }
848
Dianne Hackborn661cd522011-08-22 00:26:20 -0700849 try {
850 wm.systemReady();
851 } catch (Throwable e) {
852 reportWtf("making Window Manager Service ready", e);
853 }
Joe Onoratodc565f42010-10-04 15:27:22 -0400854
Jeff Brownb09abc12011-01-13 21:08:27 -0800855 if (safeMode) {
856 ActivityManagerService.self().showSafeModeOverlay();
857 }
858
Joe Onoratodc565f42010-10-04 15:27:22 -0400859 // Update the configuration for this context by hand, because we're going
860 // to start using it before the config change done in wm.systemReady() will
861 // propagate to it.
862 Configuration config = wm.computeNewConfiguration();
863 DisplayMetrics metrics = new DisplayMetrics();
864 WindowManager w = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
865 w.getDefaultDisplay().getMetrics(metrics);
866 context.getResources().updateConfiguration(config, metrics);
867
Jeff Brownaa202a62012-08-21 22:14:26 -0700868 try {
Jeff Brown62c82e42012-09-26 01:30:41 -0700869 power.systemReady(twilight, dreamy);
Jeff Brownaa202a62012-08-21 22:14:26 -0700870 } catch (Throwable e) {
871 reportWtf("making Power Manager Service ready", e);
872 }
873
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800874 try {
875 pm.systemReady();
Dianne Hackborn661cd522011-08-22 00:26:20 -0700876 } catch (Throwable e) {
877 reportWtf("making Package Manager Service ready", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800878 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800879
Jeff Brownbd6e1502012-08-28 03:27:37 -0700880 try {
881 display.systemReady(safeMode, onlyCore);
882 } catch (Throwable e) {
883 reportWtf("making Display Manager Service ready", e);
884 }
885
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700886 // These are needed to propagate to the runnable below.
Joe Onoratof3c3c4f2010-10-21 11:09:02 -0400887 final Context contextF = context;
Jeff Sharkeyb049e2122012-09-07 23:16:01 -0700888 final MountService mountServiceF = mountService;
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700889 final BatteryService batteryF = battery;
Jeff Sharkey350083e2011-06-29 10:45:16 -0700890 final NetworkManagementService networkManagementF = networkManagement;
Jeff Sharkey75279902011-05-24 18:39:45 -0700891 final NetworkStatsService networkStatsF = networkStats;
Jeff Sharkeya4620792011-05-20 15:29:23 -0700892 final NetworkPolicyManagerService networkPolicyF = networkPolicy;
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700893 final ConnectivityService connectivityF = connectivity;
894 final DockObserver dockF = dock;
Mike Lockwood770126a2010-12-09 22:30:37 -0800895 final UsbService usbF = usb;
Jeff Brown2416e092012-08-21 22:12:20 -0700896 final TwilightService twilightF = twilight;
Dianne Hackborn7299c412010-03-04 18:41:49 -0800897 final UiModeManagerService uiModeF = uiMode;
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700898 final AppWidgetService appWidgetF = appWidget;
899 final WallpaperManagerService wallpaperF = wallpaper;
900 final InputMethodManagerService immF = imm;
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800901 final RecognitionManagerService recognitionF = recognition;
Mike Lockwood46db5042010-02-22 16:36:44 -0500902 final LocationManagerService locationF = location;
Bai Taoa58a8752010-07-13 15:32:16 +0800903 final CountryDetectorService countryDetectorF = countryDetector;
Amith Yamasani6734b9f62010-09-13 16:24:08 -0700904 final NetworkTimeUpdateService networkTimeUpdaterF = networkTimeUpdater;
John Grossmanc1576732012-02-01 15:23:33 -0800905 final CommonTimeManagementService commonTimeMgmtServiceF = commonTimeMgmtService;
satok988323c2011-06-22 16:38:13 +0900906 final TextServicesManagerService textServiceManagerServiceF = tsms;
Dianne Hackborn661cd522011-08-22 00:26:20 -0700907 final StatusBarManagerService statusBarF = statusBar;
Daniel Sandler7d276c32012-01-30 14:33:52 -0500908 final DreamManagerService dreamyF = dreamy;
Jeff Brown6ec6f792012-04-17 16:52:41 -0700909 final InputManagerService inputManagerF = inputManager;
Wink Savillea12a7b32012-09-20 10:09:45 -0700910 final TelephonyRegistry telephonyRegistryF = telephonyRegistry;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800911
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700912 // We now tell the activity manager it is okay to run third party
913 // code. It will call back into us once it has gotten to the state
914 // where third party code can really run (but before it has actually
915 // started launching the initial applications), for us to complete our
916 // initialization.
Dianne Hackborn295e3c22011-08-25 13:19:08 -0700917 ActivityManagerService.self().systemReady(new Runnable() {
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700918 public void run() {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800919 Slog.i(TAG, "Making services ready");
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800920
Christopher Tate58d380d2013-03-19 13:10:03 -0700921 try {
922 ActivityManagerService.self().startObservingNativeCrashes();
923 } catch (Throwable e) {
924 reportWtf("observing native crashes", e);
925 }
Jim Miller5ecd8112013-01-09 18:50:26 -0800926 if (!headless) {
927 startSystemUi(contextF);
928 }
Dianne Hackborn661cd522011-08-22 00:26:20 -0700929 try {
Jeff Sharkeyb049e2122012-09-07 23:16:01 -0700930 if (mountServiceF != null) mountServiceF.systemReady();
931 } catch (Throwable e) {
932 reportWtf("making Mount Service ready", e);
933 }
934 try {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700935 if (batteryF != null) batteryF.systemReady();
936 } catch (Throwable e) {
937 reportWtf("making Battery Service ready", e);
938 }
939 try {
940 if (networkManagementF != null) networkManagementF.systemReady();
941 } catch (Throwable e) {
942 reportWtf("making Network Managment Service ready", e);
943 }
944 try {
945 if (networkStatsF != null) networkStatsF.systemReady();
946 } catch (Throwable e) {
947 reportWtf("making Network Stats Service ready", e);
948 }
949 try {
950 if (networkPolicyF != null) networkPolicyF.systemReady();
951 } catch (Throwable e) {
952 reportWtf("making Network Policy Service ready", e);
953 }
954 try {
955 if (connectivityF != null) connectivityF.systemReady();
956 } catch (Throwable e) {
957 reportWtf("making Connectivity Service ready", e);
958 }
959 try {
960 if (dockF != null) dockF.systemReady();
961 } catch (Throwable e) {
962 reportWtf("making Dock Service ready", e);
963 }
964 try {
965 if (usbF != null) usbF.systemReady();
966 } catch (Throwable e) {
967 reportWtf("making USB Service ready", e);
968 }
969 try {
Jeff Brown2416e092012-08-21 22:12:20 -0700970 if (twilightF != null) twilightF.systemReady();
971 } catch (Throwable e) {
972 reportWtf("makin Twilight Service ready", e);
973 }
974 try {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700975 if (uiModeF != null) uiModeF.systemReady();
976 } catch (Throwable e) {
977 reportWtf("making UI Mode Service ready", e);
978 }
979 try {
980 if (recognitionF != null) recognitionF.systemReady();
981 } catch (Throwable e) {
982 reportWtf("making Recognition Service ready", e);
983 }
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700984 Watchdog.getInstance().start();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800985
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700986 // It is now okay to let the various system services start their
987 // third party code...
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800988
Dianne Hackborn661cd522011-08-22 00:26:20 -0700989 try {
990 if (appWidgetF != null) appWidgetF.systemReady(safeMode);
991 } catch (Throwable e) {
992 reportWtf("making App Widget Service ready", e);
993 }
994 try {
995 if (wallpaperF != null) wallpaperF.systemReady();
996 } catch (Throwable e) {
997 reportWtf("making Wallpaper Service ready", e);
998 }
999 try {
1000 if (immF != null) immF.systemReady(statusBarF);
1001 } catch (Throwable e) {
1002 reportWtf("making Input Method Service ready", e);
1003 }
1004 try {
1005 if (locationF != null) locationF.systemReady();
1006 } catch (Throwable e) {
1007 reportWtf("making Location Service ready", e);
1008 }
1009 try {
1010 if (countryDetectorF != null) countryDetectorF.systemReady();
1011 } catch (Throwable e) {
1012 reportWtf("making Country Detector Service ready", e);
1013 }
1014 try {
Dianne Hackborn661cd522011-08-22 00:26:20 -07001015 if (networkTimeUpdaterF != null) networkTimeUpdaterF.systemReady();
1016 } catch (Throwable e) {
1017 reportWtf("making Network Time Service ready", e);
1018 }
1019 try {
John Grossmanc1576732012-02-01 15:23:33 -08001020 if (commonTimeMgmtServiceF != null) commonTimeMgmtServiceF.systemReady();
1021 } catch (Throwable e) {
1022 reportWtf("making Common time management service ready", e);
1023 }
1024 try {
Dianne Hackborn661cd522011-08-22 00:26:20 -07001025 if (textServiceManagerServiceF != null) textServiceManagerServiceF.systemReady();
1026 } catch (Throwable e) {
1027 reportWtf("making Text Services Manager Service ready", e);
1028 }
Daniel Sandler7d276c32012-01-30 14:33:52 -05001029 try {
1030 if (dreamyF != null) dreamyF.systemReady();
1031 } catch (Throwable e) {
1032 reportWtf("making DreamManagerService ready", e);
1033 }
Jeff Brown6ec6f792012-04-17 16:52:41 -07001034 try {
Matthew Xie96313142012-06-29 16:57:31 -07001035 // TODO(BT) Pass parameter to input manager
1036 if (inputManagerF != null) inputManagerF.systemReady();
Jeff Brown6ec6f792012-04-17 16:52:41 -07001037 } catch (Throwable e) {
1038 reportWtf("making InputManagerService ready", e);
1039 }
Dan Morrille4d9a012013-03-28 18:10:43 -07001040
Wink Savillea12a7b32012-09-20 10:09:45 -07001041 try {
1042 if (telephonyRegistryF != null) telephonyRegistryF.systemReady();
1043 } catch (Throwable e) {
1044 reportWtf("making TelephonyRegistry ready", e);
1045 }
Dianne Hackborna34f1ad2009-09-02 13:26:28 -07001046 }
1047 });
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001048
Brad Fitzpatrick1e02d362010-09-10 09:19:50 -07001049 // For debug builds, log event loop stalls to dropbox for analysis.
Brad Fitzpatrick50d66f92010-09-13 21:29:05 -07001050 if (StrictMode.conditionallyEnableDebugLogging()) {
1051 Slog.i(TAG, "Enabled StrictMode for system server main thread.");
Brad Fitzpatrick1e02d362010-09-10 09:19:50 -07001052 }
1053
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001054 Looper.loop();
Joe Onorato8a9b2202010-02-26 18:56:32 -08001055 Slog.d(TAG, "System ServerThread is exiting!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001056 }
Joe Onoratof3c3c4f2010-10-21 11:09:02 -04001057
1058 static final void startSystemUi(Context context) {
1059 Intent intent = new Intent();
1060 intent.setComponent(new ComponentName("com.android.systemui",
1061 "com.android.systemui.SystemUIService"));
Dianne Hackborn40e9f292012-11-27 19:12:23 -08001062 //Slog.d(TAG, "Starting service: " + intent);
Amith Yamasanicd757062012-10-19 18:23:52 -07001063 context.startServiceAsUser(intent, UserHandle.OWNER);
Joe Onoratof3c3c4f2010-10-21 11:09:02 -04001064 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001065}
1066
Jeff Hamilton35eef702010-06-09 15:45:18 -05001067public class SystemServer {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001068 private static final String TAG = "SystemServer";
1069
1070 public static final int FACTORY_TEST_OFF = 0;
1071 public static final int FACTORY_TEST_LOW_LEVEL = 1;
1072 public static final int FACTORY_TEST_HIGH_LEVEL = 2;
Jaikumar Ganeshd5ac1ae2009-05-05 22:26:12 -07001073
Bob Leee5408332009-09-04 18:31:17 -07001074 static Timer timer;
1075 static final long SNAPSHOT_INTERVAL = 60 * 60 * 1000; // 1hr
1076
Brad Fitzpatrick6bb7a4a2010-10-11 13:41:10 -07001077 // The earliest supported time. We pick one day into 1970, to
1078 // give any timezone code room without going into negative time.
1079 private static final long EARLIEST_SUPPORTED_TIME = 86400 * 1000;
1080
Jaikumar Ganeshd5ac1ae2009-05-05 22:26:12 -07001081 /**
1082 * 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 -08001083 * services (SurfaceFlinger, AudioFlinger, etc..) to be started. After that it will call back
1084 * up into init2() to start the Android services.
Jaikumar Ganeshd5ac1ae2009-05-05 22:26:12 -07001085 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001086 native public static void init1(String[] args);
1087
1088 public static void main(String[] args) {
Brad Fitzpatrick6bb7a4a2010-10-11 13:41:10 -07001089 if (System.currentTimeMillis() < EARLIEST_SUPPORTED_TIME) {
Brad Fitzpatrick35ca9d82010-10-11 11:52:49 -07001090 // If a device's clock is before 1970 (before 0), a lot of
1091 // APIs crash dealing with negative numbers, notably
1092 // java.io.File#setLastModified, so instead we fake it and
1093 // hope that time from cell towers or NTP fixes it
1094 // shortly.
1095 Slog.w(TAG, "System clock is before 1970; setting to 1970.");
Brad Fitzpatrick6bb7a4a2010-10-11 13:41:10 -07001096 SystemClock.setCurrentTimeMillis(EARLIEST_SUPPORTED_TIME);
Brad Fitzpatrick35ca9d82010-10-11 11:52:49 -07001097 }
1098
Bob Leee5408332009-09-04 18:31:17 -07001099 if (SamplingProfilerIntegration.isEnabled()) {
1100 SamplingProfilerIntegration.start();
1101 timer = new Timer();
1102 timer.schedule(new TimerTask() {
1103 @Override
1104 public void run() {
Sen Hubde75702010-05-28 01:54:03 -07001105 SamplingProfilerIntegration.writeSnapshot("system_server", null);
Bob Leee5408332009-09-04 18:31:17 -07001106 }
1107 }, SNAPSHOT_INTERVAL, SNAPSHOT_INTERVAL);
1108 }
1109
Dianne Hackbornac1471a2011-02-03 13:46:06 -08001110 // Mmmmmm... more memory!
1111 dalvik.system.VMRuntime.getRuntime().clearGrowthLimit();
1112
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001113 // The system server has to run all of the time, so it needs to be
1114 // as efficient as possible with its memory usage.
1115 VMRuntime.getRuntime().setTargetHeapUtilization(0.8f);
Sen Hubde75702010-05-28 01:54:03 -07001116
Jeff Sharkey48749fc2013-04-19 13:25:04 -07001117 Environment.setUserRequired(true);
1118
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001119 System.loadLibrary("android_servers");
1120 init1(args);
1121 }
1122
1123 public static final void init2() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001124 Slog.i(TAG, "Entered the Android system server!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001125 Thread thr = new ServerThread();
1126 thr.setName("android.server.ServerThread");
1127 thr.start();
1128 }
1129}