blob: 7d7aeec55deaa499ed9cfe23ee94d6fe412f2543 [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;
Matthew Xie1dd01eb32013-04-26 12:37:54 -070026import android.content.pm.PackageManager;
Joe Onoratodc565f42010-10-04 15:27:22 -040027import android.content.res.Configuration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080028import android.media.AudioService;
Irfan Sherifff6d09842011-08-03 15:37:08 -070029import android.net.wifi.p2p.WifiP2pService;
Jeff Sharkey48749fc2013-04-19 13:25:04 -070030import android.os.Environment;
Jeff Brownbd6e1502012-08-28 03:27:37 -070031import android.os.Handler;
32import android.os.HandlerThread;
Jeff Hamilton35eef702010-06-09 15:45:18 -050033import android.os.Looper;
34import android.os.RemoteException;
35import android.os.ServiceManager;
Brad Fitzpatrickc74a1b442010-09-10 16:03:29 -070036import android.os.StrictMode;
Jeff Hamilton35eef702010-06-09 15:45:18 -050037import android.os.SystemClock;
38import android.os.SystemProperties;
Amith Yamasanicd757062012-10-19 18:23:52 -070039import android.os.UserHandle;
Dianne Hackbornbe87e2f2012-09-28 16:31:34 -070040import android.service.dreams.DreamService;
Joe Onoratodc565f42010-10-04 15:27:22 -040041import android.util.DisplayMetrics;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080042import android.util.EventLog;
Dianne Hackborn661cd522011-08-22 00:26:20 -070043import android.util.Log;
Joe Onorato8a9b2202010-02-26 18:56:32 -080044import android.util.Slog;
Brad Fitzpatrick5fdc0c72010-10-12 13:12:18 -070045import android.view.WindowManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080046
Dan Morrille4d9a012013-03-28 18:10:43 -070047import com.android.internal.R;
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -070048import com.android.internal.os.BinderInternal;
49import com.android.internal.os.SamplingProfilerIntegration;
50import com.android.server.accessibility.AccessibilityManagerService;
Jeff Sharkey7a96c392012-11-15 14:01:46 -080051import com.android.server.accounts.AccountManagerService;
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -070052import com.android.server.am.ActivityManagerService;
Jeff Brown96307042012-07-27 15:51:34 -070053import com.android.server.am.BatteryStatsService;
Jeff Sharkey7a96c392012-11-15 14:01:46 -080054import com.android.server.content.ContentService;
Jeff Brownfa25bf52012-07-23 19:26:30 -070055import com.android.server.display.DisplayManagerService;
Jeff Browncef440f2012-09-25 18:58:48 -070056import com.android.server.dreams.DreamManagerService;
Jeff Brown6ec6f792012-04-17 16:52:41 -070057import com.android.server.input.InputManagerService;
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -070058import com.android.server.net.NetworkPolicyManagerService;
Jeff Sharkey75279902011-05-24 18:39:45 -070059import com.android.server.net.NetworkStatsService;
Jeff Sharkey7a96c392012-11-15 14:01:46 -080060import com.android.server.os.SchedulingPolicyService;
Jeff Brownf69c8122012-09-12 17:00:34 -070061import com.android.server.pm.Installer;
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -070062import com.android.server.pm.PackageManagerService;
Amith Yamasani258848d2012-08-10 17:06:33 -070063import com.android.server.pm.UserManagerService;
Jeff Brown4f8ecd82012-06-18 18:29:13 -070064import com.android.server.power.PowerManagerService;
65import com.android.server.power.ShutdownThread;
Jeff Sharkey7a96c392012-11-15 14:01:46 -080066import com.android.server.search.SearchManagerService;
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -070067import com.android.server.usb.UsbService;
Irfan Sheriffd017f352013-02-20 13:30:44 -080068import com.android.server.wifi.WifiService;
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -070069import com.android.server.wm.WindowManagerService;
70
71import dalvik.system.VMRuntime;
72import dalvik.system.Zygote;
73
Dan Egnor4410ec82009-09-11 16:40:01 -070074import java.io.File;
Bob Leee5408332009-09-04 18:31:17 -070075import java.util.Timer;
76import java.util.TimerTask;
77
Dianne Hackbornefa92b22013-05-03 14:11:43 -070078class ServerThread {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080079 private static final String TAG = "SystemServer";
Ben Komalo553acf02011-09-19 14:25:28 -070080 private static final String ENCRYPTING_STATE = "trigger_restart_min_framework";
Ben Komalo3573d402011-09-23 15:08:24 -070081 private static final String ENCRYPTED_STATE = "1";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080082
Jeff Hamilton35eef702010-06-09 15:45:18 -050083 ContentResolver mContentResolver;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080084
Dianne Hackborn661cd522011-08-22 00:26:20 -070085 void reportWtf(String msg, Throwable e) {
86 Slog.w(TAG, "***********************************************");
87 Log.wtf(TAG, "BOOT FAILURE " + msg, e);
88 }
89
Dianne Hackbornefa92b22013-05-03 14:11:43 -070090 public void initAndLoop() {
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 handler thread just for the window manager to enjoy.
158 HandlerThread wmHandlerThread = new HandlerThread("WindowManager");
159 wmHandlerThread.start();
160 Handler wmHandler = new Handler(wmHandlerThread.getLooper());
161 wmHandler.post(new Runnable() {
162 @Override
163 public void run() {
164 //Looper.myLooper().setMessageLogging(new LogPrinter(
165 // android.util.Log.DEBUG, TAG, android.util.Log.LOG_ID_SYSTEM));
166 android.os.Process.setThreadPriority(
167 android.os.Process.THREAD_PRIORITY_DISPLAY);
168 android.os.Process.setCanSelfBackground(false);
169
170 // For debug builds, log event loop stalls to dropbox for analysis.
171 if (StrictMode.conditionallyEnableDebugLogging()) {
Jeff Brown89d55462012-09-19 11:33:42 -0700172 Slog.i(TAG, "Enabled StrictMode logging for WM Looper");
Jeff Brownbd6e1502012-08-28 03:27:37 -0700173 }
174 }
175 });
176
Dan Morrille4d9a012013-03-28 18:10:43 -0700177 // bootstrap services
Jeff Brownbd6e1502012-08-28 03:27:37 -0700178 boolean onlyCore = false;
Dan Morrille4d9a012013-03-28 18:10:43 -0700179 boolean firstBoot = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800180 try {
Jeff Brownf69c8122012-09-12 17:00:34 -0700181 // Wait for installd to finished starting up so that it has a chance to
182 // create critical directories such as /data/user with the appropriate
183 // permissions. We need this to complete before we initialize other services.
184 Slog.i(TAG, "Waiting for installd to be ready.");
185 installer = new Installer();
186 installer.ping();
187
Joe Onorato8a9b2202010-02-26 18:56:32 -0800188 Slog.i(TAG, "Power Manager");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800189 power = new PowerManagerService();
190 ServiceManager.addService(Context.POWER_SERVICE, power);
191
Joe Onorato8a9b2202010-02-26 18:56:32 -0800192 Slog.i(TAG, "Activity Manager");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800193 context = ActivityManagerService.main(factoryTest);
Dan Morrille4d9a012013-03-28 18:10:43 -0700194 } catch (RuntimeException e) {
195 Slog.e("System", "******************************************");
196 Slog.e("System", "************ Failure starting bootstrap service", e);
197 }
Jeff Brown848c2dc2012-08-19 20:18:08 -0700198
Dan Morrille4d9a012013-03-28 18:10:43 -0700199 boolean disableStorage = SystemProperties.getBoolean("config.disable_storage", false);
200 boolean disableMedia = SystemProperties.getBoolean("config.disable_media", false);
201 boolean disableBluetooth = SystemProperties.getBoolean("config.disable_bluetooth", false);
202 boolean disableTelephony = SystemProperties.getBoolean("config.disable_telephony", false);
203 boolean disableLocation = SystemProperties.getBoolean("config.disable_location", false);
204 boolean disableSystemUI = SystemProperties.getBoolean("config.disable_systemui", false);
205 boolean disableNonCoreServices = SystemProperties.getBoolean("config.disable_noncore", false);
206 boolean disableNetwork = SystemProperties.getBoolean("config.disable_network", false);
207
208 try {
Jeff Brown848c2dc2012-08-19 20:18:08 -0700209 Slog.i(TAG, "Display Manager");
Dianne Hackborn8d044e82013-04-30 17:24:15 -0700210 display = new DisplayManagerService(context, wmHandler);
Jeff Brown848c2dc2012-08-19 20:18:08 -0700211 ServiceManager.addService(Context.DISPLAY_SERVICE, display, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800212
Joe Onorato8a9b2202010-02-26 18:56:32 -0800213 Slog.i(TAG, "Telephony Registry");
Wink Savillea12a7b32012-09-20 10:09:45 -0700214 telephonyRegistry = new TelephonyRegistry(context);
215 ServiceManager.addService("telephony.registry", telephonyRegistry);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800216
Glenn Kasten07b04652012-04-23 15:00:43 -0700217 Slog.i(TAG, "Scheduling Policy");
218 ServiceManager.addService(Context.SCHEDULING_POLICY_SERVICE,
219 new SchedulingPolicyService());
220
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800221 AttributeCache.init(context);
222
Jeff Brownbd6e1502012-08-28 03:27:37 -0700223 if (!display.waitForDefaultDisplay()) {
224 reportWtf("Timeout waiting for default display to be initialized.",
225 new Throwable());
226 }
227
Joe Onorato8a9b2202010-02-26 18:56:32 -0800228 Slog.i(TAG, "Package Manager");
Ben Komalo553acf02011-09-19 14:25:28 -0700229 // Only run "core" apps if we're encrypting the device.
230 String cryptState = SystemProperties.get("vold.decrypt");
Ben Komalo3573d402011-09-23 15:08:24 -0700231 if (ENCRYPTING_STATE.equals(cryptState)) {
Ben Komalo553acf02011-09-19 14:25:28 -0700232 Slog.w(TAG, "Detected encryption in progress - only parsing core apps");
Ben Komalo3573d402011-09-23 15:08:24 -0700233 onlyCore = true;
234 } else if (ENCRYPTED_STATE.equals(cryptState)) {
235 Slog.w(TAG, "Device encrypted - only parsing core apps");
236 onlyCore = true;
Ben Komalo553acf02011-09-19 14:25:28 -0700237 }
Ben Komalo3573d402011-09-23 15:08:24 -0700238
Jeff Brownf69c8122012-09-12 17:00:34 -0700239 pm = PackageManagerService.main(context, installer,
Dianne Hackbornd2509fd2011-09-12 12:29:43 -0700240 factoryTest != SystemServer.FACTORY_TEST_OFF,
Ben Komalo553acf02011-09-19 14:25:28 -0700241 onlyCore);
Dianne Hackborn58f42a52011-10-10 13:46:34 -0700242 try {
243 firstBoot = pm.isFirstBoot();
244 } catch (RemoteException e) {
245 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800246
247 ActivityManagerService.setSystemProcess();
Svetoslavb3038ec2013-02-13 14:39:30 -0800248
Nick Kralevich79619dd2013-03-04 13:05:32 -0800249 Slog.i(TAG, "Entropy Mixer");
250 ServiceManager.addService("entropy", new EntropyMixer(context));
251
Amith Yamasani258848d2012-08-10 17:06:33 -0700252 Slog.i(TAG, "User Service");
253 ServiceManager.addService(Context.USER_SERVICE,
Dianne Hackborn4428e17c2012-08-24 17:43:05 -0700254 UserManagerService.getInstance());
Amith Yamasani258848d2012-08-10 17:06:33 -0700255
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800256 mContentResolver = context.getContentResolver();
257
Fred Quintanae91ebe22009-09-29 20:44:30 -0700258 // The AccountManager must come before the ContentService
Fred Quintana60307342009-03-24 22:48:12 -0700259 try {
Dan Morrille4d9a012013-03-28 18:10:43 -0700260 // TODO: seems like this should be disable-able, but req'd by ContentService
Joe Onorato8a9b2202010-02-26 18:56:32 -0800261 Slog.i(TAG, "Account Manager");
Kenny Root26ff6622012-07-30 12:58:03 -0700262 accountManager = new AccountManagerService(context);
263 ServiceManager.addService(Context.ACCOUNT_SERVICE, accountManager);
Fred Quintana60307342009-03-24 22:48:12 -0700264 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800265 Slog.e(TAG, "Failure starting Account Manager", e);
Fred Quintana60307342009-03-24 22:48:12 -0700266 }
267
Joe Onorato8a9b2202010-02-26 18:56:32 -0800268 Slog.i(TAG, "Content Manager");
Kenny Root26ff6622012-07-30 12:58:03 -0700269 contentService = ContentService.main(context,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800270 factoryTest == SystemServer.FACTORY_TEST_LOW_LEVEL);
271
Joe Onorato8a9b2202010-02-26 18:56:32 -0800272 Slog.i(TAG, "System Content Providers");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800273 ActivityManagerService.installSystemProviders();
274
Joe Onorato8a9b2202010-02-26 18:56:32 -0800275 Slog.i(TAG, "Lights Service");
Mike Lockwood3a322132009-11-24 00:30:52 -0500276 lights = new LightsService(context);
277
Joe Onoratode1b3592010-10-25 20:36:47 -0700278 Slog.i(TAG, "Battery Service");
279 battery = new BatteryService(context, lights);
280 ServiceManager.addService("battery", battery);
281
Joe Onorato8a9b2202010-02-26 18:56:32 -0800282 Slog.i(TAG, "Vibrator Service");
Jeff Brown7f6c2312012-04-13 20:38:38 -0700283 vibrator = new VibratorService(context);
284 ServiceManager.addService("vibrator", vibrator);
The Android Open Source Project10592532009-03-18 17:39:46 -0700285
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800286 // only initialize the power service after we have started the
Mike Lockwood3a322132009-11-24 00:30:52 -0500287 // lights service, content providers and the battery service.
Jeff Brown96307042012-07-27 15:51:34 -0700288 power.init(context, lights, ActivityManagerService.self(), battery,
289 BatteryStatsService.getService(), display);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800290
Joe Onorato8a9b2202010-02-26 18:56:32 -0800291 Slog.i(TAG, "Alarm Manager");
Jeff Sharkey75279902011-05-24 18:39:45 -0700292 alarm = new AlarmManagerService(context);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800293 ServiceManager.addService(Context.ALARM_SERVICE, alarm);
294
Joe Onorato8a9b2202010-02-26 18:56:32 -0800295 Slog.i(TAG, "Init Watchdog");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800296 Watchdog.getInstance().init(context, battery, power, alarm,
297 ActivityManagerService.self());
Dianne Hackborn8d044e82013-04-30 17:24:15 -0700298 Watchdog.getInstance().addThread(wmHandler, "WindowManager thread");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800299
Jeff Browna9d131c2012-09-20 16:48:17 -0700300 Slog.i(TAG, "Input Manager");
301 inputManager = new InputManagerService(context, wmHandler);
302
Joe Onorato8a9b2202010-02-26 18:56:32 -0800303 Slog.i(TAG, "Window Manager");
Jeff Browna9d131c2012-09-20 16:48:17 -0700304 wm = WindowManagerService.main(context, power, display, inputManager,
Dianne Hackborn8d044e82013-04-30 17:24:15 -0700305 wmHandler, factoryTest != SystemServer.FACTORY_TEST_LOW_LEVEL,
Jeff Brown780c46f2012-06-24 12:15:38 -0700306 !firstBoot, onlyCore);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800307 ServiceManager.addService(Context.WINDOW_SERVICE, wm);
Jeff Brown6ec6f792012-04-17 16:52:41 -0700308 ServiceManager.addService(Context.INPUT_SERVICE, inputManager);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800309
Dianne Hackborn295e3c22011-08-25 13:19:08 -0700310 ActivityManagerService.self().setWindowManager(wm);
Jeff Browna9d131c2012-09-20 16:48:17 -0700311
312 inputManager.setWindowManagerCallbacks(wm.getInputMonitor());
313 inputManager.start();
314
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700315 display.setWindowManager(wm);
Jeff Brownd728bf52012-09-08 18:05:28 -0700316 display.setInputManager(inputManager);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800317
318 // Skip Bluetooth if we have an emulator kernel
319 // TODO: Use a more reliable check to see if this product should
320 // support Bluetooth - see bug 988521
321 if (SystemProperties.get("ro.kernel.qemu").equals("1")) {
David 'Digit' Turnere2a5e862011-01-17 00:32:33 +0100322 Slog.i(TAG, "No Bluetooh Service (emulator)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800323 } else if (factoryTest == SystemServer.FACTORY_TEST_LOW_LEVEL) {
David 'Digit' Turnere2a5e862011-01-17 00:32:33 +0100324 Slog.i(TAG, "No Bluetooth Service (factory test)");
Matthew Xie1dd01eb32013-04-26 12:37:54 -0700325 } else if (!context.getPackageManager().hasSystemFeature
326 (PackageManager.FEATURE_BLUETOOTH)) {
327 Slog.i(TAG, "No Bluetooth Service (Bluetooth Hardware Not Present)");
Dan Morrille4d9a012013-03-28 18:10:43 -0700328 } else if (disableBluetooth) {
329 Slog.i(TAG, "Bluetooth Service disabled by config");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800330 } else {
fredc0f420372012-04-12 00:02:00 -0700331 Slog.i(TAG, "Bluetooth Manager Service");
332 bluetooth = new BluetoothManagerService(context);
333 ServiceManager.addService(BluetoothAdapter.BLUETOOTH_MANAGER_SERVICE, bluetooth);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800334 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800335 } catch (RuntimeException e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700336 Slog.e("System", "******************************************");
337 Slog.e("System", "************ Failure starting core service", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800338 }
339
Dianne Hackbornd6847842010-01-12 18:14:19 -0800340 DevicePolicyManagerService devicePolicy = null;
Joe Onorato089de882010-04-12 08:18:45 -0700341 StatusBarManagerService statusBar = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800342 InputMethodManagerService imm = null;
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700343 AppWidgetService appWidget = null;
Joe Onorato30275482009-07-08 17:09:14 -0700344 NotificationManagerService notification = null;
Dianne Hackbornf21adf62009-08-13 10:20:21 -0700345 WallpaperManagerService wallpaper = null;
Mike Lockwood46db5042010-02-22 16:36:44 -0500346 LocationManagerService location = null;
Bai Taoa58a8752010-07-13 15:32:16 +0800347 CountryDetectorService countryDetector = null;
satok988323c2011-06-22 16:38:13 +0900348 TextServicesManagerService tsms = null;
Amith Yamasani52c489c2012-03-28 11:42:42 -0700349 LockSettingsService lockSettings = null;
Daniel Sandler7d276c32012-01-30 14:33:52 -0500350 DreamManagerService dreamy = null;
Romain Guy3b748a42013-04-17 18:54:38 -0700351 AssetAtlasService atlas = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800352
Dianne Hackborn661cd522011-08-22 00:26:20 -0700353 // Bring up services needed for UI.
354 if (factoryTest != SystemServer.FACTORY_TEST_LOW_LEVEL) {
Dan Morrille4d9a012013-03-28 18:10:43 -0700355 //if (!disableNonCoreServices) { // TODO: View depends on these; mock them?
356 if (true) {
357 try {
358 Slog.i(TAG, "Input Method Service");
359 imm = new InputMethodManagerService(context, wm);
360 ServiceManager.addService(Context.INPUT_METHOD_SERVICE, imm);
361 } catch (Throwable e) {
362 reportWtf("starting Input Manager Service", e);
363 }
Dianne Hackborn661cd522011-08-22 00:26:20 -0700364
Dan Morrille4d9a012013-03-28 18:10:43 -0700365 try {
366 Slog.i(TAG, "Accessibility Manager");
367 ServiceManager.addService(Context.ACCESSIBILITY_SERVICE,
368 new AccessibilityManagerService(context));
369 } catch (Throwable e) {
370 reportWtf("starting Accessibility Manager", e);
371 }
Dianne Hackborn661cd522011-08-22 00:26:20 -0700372 }
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) {
Dan Morrille4d9a012013-03-28 18:10:43 -0700396 if (!disableStorage &&
397 !"0".equals(SystemProperties.get("system_init.startmountservice"))) {
Kenny Root51a573c2012-05-17 13:30:28 -0700398 try {
399 /*
400 * NotificationManagerService is dependant on MountService,
401 * (for media / usb notifications) so we must start MountService first.
402 */
403 Slog.i(TAG, "Mount Service");
404 mountService = new MountService(context);
405 ServiceManager.addService("mount", mountService);
406 } catch (Throwable e) {
407 reportWtf("starting Mount Service", e);
408 }
409 }
410
Dan Morrille4d9a012013-03-28 18:10:43 -0700411 if (!disableNonCoreServices) {
412 try {
413 Slog.i(TAG, "LockSettingsService");
414 lockSettings = new LockSettingsService(context);
415 ServiceManager.addService("lock_settings", lockSettings);
416 } catch (Throwable e) {
417 reportWtf("starting LockSettingsService service", e);
418 }
419
420 try {
421 Slog.i(TAG, "Device Policy");
422 devicePolicy = new DevicePolicyManagerService(context);
423 ServiceManager.addService(Context.DEVICE_POLICY_SERVICE, devicePolicy);
424 } catch (Throwable e) {
425 reportWtf("starting DevicePolicyService", e);
426 }
Amith Yamasani52c489c2012-03-28 11:42:42 -0700427 }
428
Dan Morrille4d9a012013-03-28 18:10:43 -0700429 if (!disableSystemUI) {
430 try {
431 Slog.i(TAG, "Status Bar");
432 statusBar = new StatusBarManagerService(context, wm);
433 ServiceManager.addService(Context.STATUS_BAR_SERVICE, statusBar);
434 } catch (Throwable e) {
435 reportWtf("starting StatusBarManagerService", e);
436 }
Dianne Hackbornd6847842010-01-12 18:14:19 -0800437 }
438
Dan Morrille4d9a012013-03-28 18:10:43 -0700439 if (!disableNonCoreServices) {
440 try {
441 Slog.i(TAG, "Clipboard Service");
442 ServiceManager.addService(Context.CLIPBOARD_SERVICE,
443 new ClipboardService(context));
444 } catch (Throwable e) {
445 reportWtf("starting Clipboard Service", e);
446 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800447 }
448
Dan Morrille4d9a012013-03-28 18:10:43 -0700449 if (!disableNetwork) {
450 try {
451 Slog.i(TAG, "NetworkManagement Service");
452 networkManagement = NetworkManagementService.create(context);
453 ServiceManager.addService(Context.NETWORKMANAGEMENT_SERVICE, networkManagement);
454 } catch (Throwable e) {
455 reportWtf("starting NetworkManagement Service", e);
456 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800457 }
458
Dan Morrille4d9a012013-03-28 18:10:43 -0700459 if (!disableNonCoreServices) {
460 try {
461 Slog.i(TAG, "Text Service Manager Service");
462 tsms = new TextServicesManagerService(context);
463 ServiceManager.addService(Context.TEXT_SERVICES_MANAGER_SERVICE, tsms);
464 } catch (Throwable e) {
465 reportWtf("starting Text Service Manager Service", e);
466 }
San Mehatd1df8ac2010-01-26 06:17:26 -0800467 }
468
Dan Morrille4d9a012013-03-28 18:10:43 -0700469 if (!disableNetwork) {
470 try {
471 Slog.i(TAG, "NetworkStats Service");
472 networkStats = new NetworkStatsService(context, networkManagement, alarm);
473 ServiceManager.addService(Context.NETWORK_STATS_SERVICE, networkStats);
474 } catch (Throwable e) {
475 reportWtf("starting NetworkStats Service", e);
476 }
477
478 try {
479 Slog.i(TAG, "NetworkPolicy Service");
480 networkPolicy = new NetworkPolicyManagerService(
481 context, ActivityManagerService.self(), power,
482 networkStats, networkManagement);
483 ServiceManager.addService(Context.NETWORK_POLICY_SERVICE, networkPolicy);
484 } catch (Throwable e) {
485 reportWtf("starting NetworkPolicy Service", e);
486 }
487
488 try {
489 Slog.i(TAG, "Wi-Fi P2pService");
490 wifiP2p = new WifiP2pService(context);
491 ServiceManager.addService(Context.WIFI_P2P_SERVICE, wifiP2p);
492 } catch (Throwable e) {
493 reportWtf("starting Wi-Fi P2pService", e);
494 }
495
496 try {
497 Slog.i(TAG, "Wi-Fi Service");
498 wifi = new WifiService(context);
499 ServiceManager.addService(Context.WIFI_SERVICE, wifi);
500 } catch (Throwable e) {
501 reportWtf("starting Wi-Fi Service", e);
502 }
503
504 try {
505 Slog.i(TAG, "Connectivity Service");
506 connectivity = new ConnectivityService(
507 context, networkManagement, networkStats, networkPolicy);
508 ServiceManager.addService(Context.CONNECTIVITY_SERVICE, connectivity);
509 networkStats.bindConnectivityManager(connectivity);
510 networkPolicy.bindConnectivityManager(connectivity);
511 wifi.checkAndStartWifi();
512 wifiP2p.connectivityServiceReady();
513 } catch (Throwable e) {
514 reportWtf("starting Connectivity Service", e);
515 }
516
517 try {
518 Slog.i(TAG, "Network Service Discovery Service");
519 serviceDiscovery = NsdService.create(context);
520 ServiceManager.addService(
521 Context.NSD_SERVICE, serviceDiscovery);
522 } catch (Throwable e) {
523 reportWtf("starting Service Discovery Service", e);
524 }
satok988323c2011-06-22 16:38:13 +0900525 }
526
Dan Morrille4d9a012013-03-28 18:10:43 -0700527 if (!disableNonCoreServices) {
528 try {
529 Slog.i(TAG, "UpdateLock Service");
530 ServiceManager.addService(Context.UPDATE_LOCK_SERVICE,
531 new UpdateLockService(context));
532 } catch (Throwable e) {
533 reportWtf("starting UpdateLockService", e);
534 }
Christopher Tate8662cab52012-02-23 14:59:36 -0800535 }
536
Kenny Root51a573c2012-05-17 13:30:28 -0700537 /*
538 * MountService has a few dependencies: Notification Manager and
539 * AppWidget Provider. Make sure MountService is completely started
540 * first before continuing.
541 */
542 if (mountService != null) {
543 mountService.waitForAsecScan();
San Mehat1bf3f8b2010-02-03 14:43:09 -0800544 }
545
546 try {
Kenny Root26ff6622012-07-30 12:58:03 -0700547 if (accountManager != null)
548 accountManager.systemReady();
549 } catch (Throwable e) {
550 reportWtf("making Account Manager Service ready", e);
551 }
552
553 try {
554 if (contentService != null)
555 contentService.systemReady();
556 } catch (Throwable e) {
557 reportWtf("making Content Service ready", e);
558 }
559
560 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800561 Slog.i(TAG, "Notification Manager");
Mike Lockwood3a322132009-11-24 00:30:52 -0500562 notification = new NotificationManagerService(context, statusBar, lights);
Joe Onorato30275482009-07-08 17:09:14 -0700563 ServiceManager.addService(Context.NOTIFICATION_SERVICE, notification);
Jeff Sharkey497e4432011-06-14 17:27:29 -0700564 networkPolicy.bindNotificationManager(notification);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800565 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700566 reportWtf("starting Notification Manager", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800567 }
568
569 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800570 Slog.i(TAG, "Device Storage Monitor");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800571 ServiceManager.addService(DeviceStorageMonitorService.SERVICE,
572 new DeviceStorageMonitorService(context));
573 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700574 reportWtf("starting DeviceStorageMonitor service", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800575 }
576
Dan Morrille4d9a012013-03-28 18:10:43 -0700577 if (!disableLocation) {
578 try {
579 Slog.i(TAG, "Location Manager");
580 location = new LocationManagerService(context);
581 ServiceManager.addService(Context.LOCATION_SERVICE, location);
582 } catch (Throwable e) {
583 reportWtf("starting Location Manager", e);
584 }
585
586 try {
587 Slog.i(TAG, "Country Detector");
588 countryDetector = new CountryDetectorService(context);
589 ServiceManager.addService(Context.COUNTRY_DETECTOR, countryDetector);
590 } catch (Throwable e) {
591 reportWtf("starting Country Detector", e);
592 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800593 }
594
Dan Morrille4d9a012013-03-28 18:10:43 -0700595 if (!disableNonCoreServices) {
596 try {
597 Slog.i(TAG, "Search Service");
598 ServiceManager.addService(Context.SEARCH_SERVICE,
599 new SearchManagerService(context));
600 } catch (Throwable e) {
601 reportWtf("starting Search Service", e);
602 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800603 }
604
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800605 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800606 Slog.i(TAG, "DropBox Service");
Dan Egnor95240272009-10-27 18:23:39 -0700607 ServiceManager.addService(Context.DROPBOX_SERVICE,
Dan Egnorf18a01c2009-11-12 11:32:50 -0800608 new DropBoxManagerService(context, new File("/data/system/dropbox")));
Dan Egnor4410ec82009-09-11 16:40:01 -0700609 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700610 reportWtf("starting DropBoxManagerService", e);
Dan Egnor4410ec82009-09-11 16:40:01 -0700611 }
612
Dan Morrille4d9a012013-03-28 18:10:43 -0700613 if (!disableNonCoreServices && context.getResources().getBoolean(
614 R.bool.config_enableWallpaperService)) {
Mike Lockwoodc067c9c2011-10-31 12:50:12 -0400615 try {
616 Slog.i(TAG, "Wallpaper Service");
617 if (!headless) {
618 wallpaper = new WallpaperManagerService(context);
619 ServiceManager.addService(Context.WALLPAPER_SERVICE, wallpaper);
620 }
621 } catch (Throwable e) {
622 reportWtf("starting Wallpaper Service", e);
Mike Lockwood3a74bd32011-08-12 13:55:22 -0700623 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800624 }
625
Dan Morrille4d9a012013-03-28 18:10:43 -0700626 if (!disableMedia && !"0".equals(SystemProperties.get("system_init.startaudioservice"))) {
Mike Lockwoodcba928c2011-08-17 15:58:52 -0700627 try {
628 Slog.i(TAG, "Audio Service");
629 ServiceManager.addService(Context.AUDIO_SERVICE, new AudioService(context));
630 } catch (Throwable e) {
631 reportWtf("starting Audio Service", e);
632 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800633 }
634
Dan Morrille4d9a012013-03-28 18:10:43 -0700635 if (!disableNonCoreServices) {
636 try {
637 Slog.i(TAG, "Dock Observer");
638 // Listen for dock station changes
639 dock = new DockObserver(context);
640 } catch (Throwable e) {
641 reportWtf("starting DockObserver", e);
642 }
Dan Murphyc9f4eaf2009-08-12 15:15:43 -0500643 }
644
Dan Morrille4d9a012013-03-28 18:10:43 -0700645 if (!disableMedia) {
646 try {
647 Slog.i(TAG, "Wired Accessory Manager");
648 // Listen for wired headset changes
649 inputManager.setWiredAccessoryCallbacks(
650 new WiredAccessoryManager(context, inputManager));
651 } catch (Throwable e) {
652 reportWtf("starting WiredAccessoryManager", e);
653 }
Praveen Bharathi21e941b2010-10-06 15:23:14 -0500654 }
655
Dan Morrille4d9a012013-03-28 18:10:43 -0700656 if (!disableNonCoreServices) {
657 try {
658 Slog.i(TAG, "USB Service");
659 // Manage USB host and device support
660 usb = new UsbService(context);
661 ServiceManager.addService(Context.USB_SERVICE, usb);
662 } catch (Throwable e) {
663 reportWtf("starting UsbService", e);
664 }
Mike Lockwood57c798a2010-06-23 17:36:36 -0400665
Dan Morrille4d9a012013-03-28 18:10:43 -0700666 try {
667 Slog.i(TAG, "Serial Service");
668 // Serial port support
669 serial = new SerialService(context);
670 ServiceManager.addService(Context.SERIAL_SERVICE, serial);
671 } catch (Throwable e) {
672 Slog.e(TAG, "Failure starting SerialService", e);
673 }
Mike Lockwoodb01e8bf2011-08-29 20:11:07 -0400674 }
675
676 try {
Jeff Brown2416e092012-08-21 22:12:20 -0700677 Slog.i(TAG, "Twilight Service");
678 twilight = new TwilightService(context);
679 } catch (Throwable e) {
680 reportWtf("starting TwilightService", e);
681 }
682
683 try {
Dianne Hackborn7299c412010-03-04 18:41:49 -0800684 Slog.i(TAG, "UI Mode Manager Service");
Mike Lockwood57c798a2010-06-23 17:36:36 -0400685 // Listen for UI mode changes
Jeff Brown2416e092012-08-21 22:12:20 -0700686 uiMode = new UiModeManagerService(context, twilight);
Dianne Hackborn7299c412010-03-04 18:41:49 -0800687 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700688 reportWtf("starting UiModeManagerService", e);
Dianne Hackborn7299c412010-03-04 18:41:49 -0800689 }
690
Dan Morrille4d9a012013-03-28 18:10:43 -0700691 if (!disableNonCoreServices) {
692 try {
693 Slog.i(TAG, "Backup Service");
694 ServiceManager.addService(Context.BACKUP_SERVICE,
695 new BackupManagerService(context));
696 } catch (Throwable e) {
697 Slog.e(TAG, "Failure starting Backup Service", e);
698 }
Christopher Tate487529a2009-04-29 14:03:25 -0700699
Dan Morrille4d9a012013-03-28 18:10:43 -0700700 try {
701 Slog.i(TAG, "AppWidget Service");
702 appWidget = new AppWidgetService(context);
703 ServiceManager.addService(Context.APPWIDGET_SERVICE, appWidget);
704 } catch (Throwable e) {
705 reportWtf("starting AppWidget Service", e);
706 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800707
Dan Morrille4d9a012013-03-28 18:10:43 -0700708 try {
709 Slog.i(TAG, "Recognition Service");
710 recognition = new RecognitionManagerService(context);
711 } catch (Throwable e) {
712 reportWtf("starting Recognition Service", e);
713 }
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800714 }
Jaikumar Ganesh7d0548d2010-10-18 15:29:09 -0700715
Nick Pelly038cabe2010-09-23 16:12:11 -0700716 try {
Dan Egnor621bc542010-03-25 16:20:14 -0700717 Slog.i(TAG, "DiskStats Service");
718 ServiceManager.addService("diskstats", new DiskStatsService(context));
719 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700720 reportWtf("starting DiskStats Service", e);
Dan Egnor621bc542010-03-25 16:20:14 -0700721 }
Sen Hubde75702010-05-28 01:54:03 -0700722
723 try {
724 // need to add this service even if SamplingProfilerIntegration.isEnabled()
725 // is false, because it is this service that detects system property change and
726 // turns on SamplingProfilerIntegration. Plus, when sampling profiler doesn't work,
727 // there is little overhead for running this service.
728 Slog.i(TAG, "SamplingProfiler Service");
729 ServiceManager.addService("samplingprofiler",
730 new SamplingProfilerService(context));
731 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700732 reportWtf("starting SamplingProfiler Service", e);
Sen Hubde75702010-05-28 01:54:03 -0700733 }
Chung-yih Wang024d5962010-08-06 12:06:04 +0800734
Dan Morrille4d9a012013-03-28 18:10:43 -0700735 if (!disableNetwork) {
736 try {
737 Slog.i(TAG, "NetworkTimeUpdateService");
738 networkTimeUpdater = new NetworkTimeUpdateService(context);
739 } catch (Throwable e) {
740 reportWtf("starting NetworkTimeUpdate service", e);
741 }
Amith Yamasani6734b9f62010-09-13 16:24:08 -0700742 }
John Grossmanc1576732012-02-01 15:23:33 -0800743
Dan Morrille4d9a012013-03-28 18:10:43 -0700744 if (!disableMedia) {
745 try {
746 Slog.i(TAG, "CommonTimeManagementService");
747 commonTimeMgmtService = new CommonTimeManagementService(context);
748 ServiceManager.addService("commontime_management", commonTimeMgmtService);
749 } catch (Throwable e) {
750 reportWtf("starting CommonTimeManagementService service", e);
751 }
John Grossmanc1576732012-02-01 15:23:33 -0800752 }
Geremy Condra3d33c262012-05-06 18:32:19 -0700753
Dan Morrille4d9a012013-03-28 18:10:43 -0700754 if (!disableNetwork) {
755 try {
756 Slog.i(TAG, "CertBlacklister");
757 CertBlacklister blacklister = new CertBlacklister(context);
758 } catch (Throwable e) {
759 reportWtf("starting CertBlacklister", e);
760 }
Geremy Condra3d33c262012-05-06 18:32:19 -0700761 }
Jim Miller5ecd8112013-01-09 18:50:26 -0800762
Dan Morrille4d9a012013-03-28 18:10:43 -0700763 if (!disableNonCoreServices &&
764 context.getResources().getBoolean(R.bool.config_dreamsSupported)) {
Daniel Sandler7d276c32012-01-30 14:33:52 -0500765 try {
766 Slog.i(TAG, "Dreams Service");
767 // Dreams (interactive idle-time views, a/k/a screen savers)
Jeff Brown62c82e42012-09-26 01:30:41 -0700768 dreamy = new DreamManagerService(context, wmHandler);
Dianne Hackbornbe87e2f2012-09-28 16:31:34 -0700769 ServiceManager.addService(DreamService.DREAM_SERVICE, dreamy);
Daniel Sandler7d276c32012-01-30 14:33:52 -0500770 } catch (Throwable e) {
771 reportWtf("starting DreamManagerService", e);
772 }
773 }
Svetoslavb3038ec2013-02-13 14:39:30 -0800774
Romain Guy3b748a42013-04-17 18:54:38 -0700775 if (!disableNonCoreServices) {
776 try {
777 Slog.i(TAG, "Assets Atlas Service");
778 atlas = new AssetAtlasService(context);
779 ServiceManager.addService(AssetAtlasService.ASSET_ATLAS_SERVICE, atlas);
780 } catch (Throwable e) {
781 reportWtf("starting AssetAtlasService", e);
782 }
783 }
784
Svetoslavb3038ec2013-02-13 14:39:30 -0800785 try {
786 Slog.i(TAG, "IdleMaintenanceService");
Svetoslav6a08a122013-05-03 11:24:26 -0700787 new IdleMaintenanceService(context, battery);
Svetoslavb3038ec2013-02-13 14:39:30 -0800788 } catch (Throwable e) {
789 reportWtf("starting IdleMaintenanceService", e);
790 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800791 }
792
Dianne Hackborn6af0d502009-09-28 13:25:46 -0700793 // Before things start rolling, be sure we have decided whether
794 // we are in safe mode.
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700795 final boolean safeMode = wm.detectSafeMode();
Dianne Hackborn6af0d502009-09-28 13:25:46 -0700796 if (safeMode) {
Jeff Brownb09abc12011-01-13 21:08:27 -0800797 ActivityManagerService.self().enterSafeMode();
798 // Post the safe mode state in the Zygote class
799 Zygote.systemInSafeMode = true;
800 // Disable the JIT for the system_server process
801 VMRuntime.getRuntime().disableJitCompilation();
Ben Cheng6c0afff2010-02-14 16:18:56 -0800802 } else {
803 // Enable the JIT for the system_server process
804 VMRuntime.getRuntime().startJitCompilation();
Dianne Hackborn6af0d502009-09-28 13:25:46 -0700805 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800806
Dianne Hackborn6af0d502009-09-28 13:25:46 -0700807 // It is now time to start up the app processes...
Joe Onorato30275482009-07-08 17:09:14 -0700808
Jeff Brown7f6c2312012-04-13 20:38:38 -0700809 try {
810 vibrator.systemReady();
811 } catch (Throwable e) {
812 reportWtf("making Vibrator Service ready", e);
813 }
814
Dan Morrille4d9a012013-03-28 18:10:43 -0700815 if (lockSettings != null) {
816 try {
817 lockSettings.systemReady();
818 } catch (Throwable e) {
819 reportWtf("making Lock Settings Service ready", e);
820 }
Felipe Ramosf35df5b2012-09-18 18:26:27 -0300821 }
822
Dianne Hackbornd6847842010-01-12 18:14:19 -0800823 if (devicePolicy != null) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700824 try {
825 devicePolicy.systemReady();
826 } catch (Throwable e) {
827 reportWtf("making Device Policy Service ready", e);
828 }
Dianne Hackbornd6847842010-01-12 18:14:19 -0800829 }
830
Joe Onorato30275482009-07-08 17:09:14 -0700831 if (notification != null) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700832 try {
833 notification.systemReady();
834 } catch (Throwable e) {
835 reportWtf("making Notification Service ready", e);
836 }
Joe Onorato30275482009-07-08 17:09:14 -0700837 }
838
Dianne Hackborn661cd522011-08-22 00:26:20 -0700839 try {
840 wm.systemReady();
841 } catch (Throwable e) {
842 reportWtf("making Window Manager Service ready", e);
843 }
Joe Onoratodc565f42010-10-04 15:27:22 -0400844
Jeff Brownb09abc12011-01-13 21:08:27 -0800845 if (safeMode) {
846 ActivityManagerService.self().showSafeModeOverlay();
847 }
848
Joe Onoratodc565f42010-10-04 15:27:22 -0400849 // Update the configuration for this context by hand, because we're going
850 // to start using it before the config change done in wm.systemReady() will
851 // propagate to it.
852 Configuration config = wm.computeNewConfiguration();
853 DisplayMetrics metrics = new DisplayMetrics();
854 WindowManager w = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
855 w.getDefaultDisplay().getMetrics(metrics);
856 context.getResources().updateConfiguration(config, metrics);
857
Jeff Brownaa202a62012-08-21 22:14:26 -0700858 try {
Jeff Brown62c82e42012-09-26 01:30:41 -0700859 power.systemReady(twilight, dreamy);
Jeff Brownaa202a62012-08-21 22:14:26 -0700860 } catch (Throwable e) {
861 reportWtf("making Power Manager Service ready", e);
862 }
863
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800864 try {
865 pm.systemReady();
Dianne Hackborn661cd522011-08-22 00:26:20 -0700866 } catch (Throwable e) {
867 reportWtf("making Package Manager Service ready", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800868 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800869
Jeff Brownbd6e1502012-08-28 03:27:37 -0700870 try {
871 display.systemReady(safeMode, onlyCore);
872 } catch (Throwable e) {
873 reportWtf("making Display Manager Service ready", e);
874 }
875
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700876 // These are needed to propagate to the runnable below.
Joe Onoratof3c3c4f2010-10-21 11:09:02 -0400877 final Context contextF = context;
Jeff Sharkeyb049e2122012-09-07 23:16:01 -0700878 final MountService mountServiceF = mountService;
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700879 final BatteryService batteryF = battery;
Jeff Sharkey350083e2011-06-29 10:45:16 -0700880 final NetworkManagementService networkManagementF = networkManagement;
Jeff Sharkey75279902011-05-24 18:39:45 -0700881 final NetworkStatsService networkStatsF = networkStats;
Jeff Sharkeya4620792011-05-20 15:29:23 -0700882 final NetworkPolicyManagerService networkPolicyF = networkPolicy;
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700883 final ConnectivityService connectivityF = connectivity;
884 final DockObserver dockF = dock;
Mike Lockwood770126a2010-12-09 22:30:37 -0800885 final UsbService usbF = usb;
Jeff Brown2416e092012-08-21 22:12:20 -0700886 final TwilightService twilightF = twilight;
Dianne Hackborn7299c412010-03-04 18:41:49 -0800887 final UiModeManagerService uiModeF = uiMode;
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700888 final AppWidgetService appWidgetF = appWidget;
889 final WallpaperManagerService wallpaperF = wallpaper;
890 final InputMethodManagerService immF = imm;
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800891 final RecognitionManagerService recognitionF = recognition;
Mike Lockwood46db5042010-02-22 16:36:44 -0500892 final LocationManagerService locationF = location;
Bai Taoa58a8752010-07-13 15:32:16 +0800893 final CountryDetectorService countryDetectorF = countryDetector;
Amith Yamasani6734b9f62010-09-13 16:24:08 -0700894 final NetworkTimeUpdateService networkTimeUpdaterF = networkTimeUpdater;
John Grossmanc1576732012-02-01 15:23:33 -0800895 final CommonTimeManagementService commonTimeMgmtServiceF = commonTimeMgmtService;
satok988323c2011-06-22 16:38:13 +0900896 final TextServicesManagerService textServiceManagerServiceF = tsms;
Dianne Hackborn661cd522011-08-22 00:26:20 -0700897 final StatusBarManagerService statusBarF = statusBar;
Daniel Sandler7d276c32012-01-30 14:33:52 -0500898 final DreamManagerService dreamyF = dreamy;
Romain Guy3b748a42013-04-17 18:54:38 -0700899 final AssetAtlasService atlasF = atlas;
Jeff Brown6ec6f792012-04-17 16:52:41 -0700900 final InputManagerService inputManagerF = inputManager;
Wink Savillea12a7b32012-09-20 10:09:45 -0700901 final TelephonyRegistry telephonyRegistryF = telephonyRegistry;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800902
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700903 // We now tell the activity manager it is okay to run third party
904 // code. It will call back into us once it has gotten to the state
905 // where third party code can really run (but before it has actually
906 // started launching the initial applications), for us to complete our
907 // initialization.
Dianne Hackborn295e3c22011-08-25 13:19:08 -0700908 ActivityManagerService.self().systemReady(new Runnable() {
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700909 public void run() {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800910 Slog.i(TAG, "Making services ready");
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800911
Christopher Tate58d380d2013-03-19 13:10:03 -0700912 try {
913 ActivityManagerService.self().startObservingNativeCrashes();
914 } catch (Throwable e) {
915 reportWtf("observing native crashes", e);
916 }
Jim Miller5ecd8112013-01-09 18:50:26 -0800917 if (!headless) {
918 startSystemUi(contextF);
919 }
Dianne Hackborn661cd522011-08-22 00:26:20 -0700920 try {
Jeff Sharkeyb049e2122012-09-07 23:16:01 -0700921 if (mountServiceF != null) mountServiceF.systemReady();
922 } catch (Throwable e) {
923 reportWtf("making Mount Service ready", e);
924 }
925 try {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700926 if (batteryF != null) batteryF.systemReady();
927 } catch (Throwable e) {
928 reportWtf("making Battery Service ready", e);
929 }
930 try {
931 if (networkManagementF != null) networkManagementF.systemReady();
932 } catch (Throwable e) {
933 reportWtf("making Network Managment Service ready", e);
934 }
935 try {
936 if (networkStatsF != null) networkStatsF.systemReady();
937 } catch (Throwable e) {
938 reportWtf("making Network Stats Service ready", e);
939 }
940 try {
941 if (networkPolicyF != null) networkPolicyF.systemReady();
942 } catch (Throwable e) {
943 reportWtf("making Network Policy Service ready", e);
944 }
945 try {
946 if (connectivityF != null) connectivityF.systemReady();
947 } catch (Throwable e) {
948 reportWtf("making Connectivity Service ready", e);
949 }
950 try {
951 if (dockF != null) dockF.systemReady();
952 } catch (Throwable e) {
953 reportWtf("making Dock Service ready", e);
954 }
955 try {
956 if (usbF != null) usbF.systemReady();
957 } catch (Throwable e) {
958 reportWtf("making USB Service ready", e);
959 }
960 try {
Jeff Brown2416e092012-08-21 22:12:20 -0700961 if (twilightF != null) twilightF.systemReady();
962 } catch (Throwable e) {
963 reportWtf("makin Twilight Service ready", e);
964 }
965 try {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700966 if (uiModeF != null) uiModeF.systemReady();
967 } catch (Throwable e) {
968 reportWtf("making UI Mode Service ready", e);
969 }
970 try {
971 if (recognitionF != null) recognitionF.systemReady();
972 } catch (Throwable e) {
973 reportWtf("making Recognition Service ready", e);
974 }
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700975 Watchdog.getInstance().start();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800976
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700977 // It is now okay to let the various system services start their
978 // third party code...
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800979
Dianne Hackborn661cd522011-08-22 00:26:20 -0700980 try {
981 if (appWidgetF != null) appWidgetF.systemReady(safeMode);
982 } catch (Throwable e) {
983 reportWtf("making App Widget Service ready", e);
984 }
985 try {
986 if (wallpaperF != null) wallpaperF.systemReady();
987 } catch (Throwable e) {
988 reportWtf("making Wallpaper Service ready", e);
989 }
990 try {
991 if (immF != null) immF.systemReady(statusBarF);
992 } catch (Throwable e) {
993 reportWtf("making Input Method Service ready", e);
994 }
995 try {
996 if (locationF != null) locationF.systemReady();
997 } catch (Throwable e) {
998 reportWtf("making Location Service ready", e);
999 }
1000 try {
1001 if (countryDetectorF != null) countryDetectorF.systemReady();
1002 } catch (Throwable e) {
1003 reportWtf("making Country Detector Service ready", e);
1004 }
1005 try {
Dianne Hackborn661cd522011-08-22 00:26:20 -07001006 if (networkTimeUpdaterF != null) networkTimeUpdaterF.systemReady();
1007 } catch (Throwable e) {
1008 reportWtf("making Network Time Service ready", e);
1009 }
1010 try {
John Grossmanc1576732012-02-01 15:23:33 -08001011 if (commonTimeMgmtServiceF != null) commonTimeMgmtServiceF.systemReady();
1012 } catch (Throwable e) {
1013 reportWtf("making Common time management service ready", e);
1014 }
1015 try {
Dianne Hackborn661cd522011-08-22 00:26:20 -07001016 if (textServiceManagerServiceF != null) textServiceManagerServiceF.systemReady();
1017 } catch (Throwable e) {
1018 reportWtf("making Text Services Manager Service ready", e);
1019 }
Daniel Sandler7d276c32012-01-30 14:33:52 -05001020 try {
1021 if (dreamyF != null) dreamyF.systemReady();
1022 } catch (Throwable e) {
1023 reportWtf("making DreamManagerService ready", e);
1024 }
Jeff Brown6ec6f792012-04-17 16:52:41 -07001025 try {
Romain Guy3b748a42013-04-17 18:54:38 -07001026 if (atlasF != null) atlasF.systemReady();
1027 } catch (Throwable e) {
1028 reportWtf("making AssetAtlasService ready", e);
1029 }
1030 try {
Matthew Xie96313142012-06-29 16:57:31 -07001031 // TODO(BT) Pass parameter to input manager
1032 if (inputManagerF != null) inputManagerF.systemReady();
Jeff Brown6ec6f792012-04-17 16:52:41 -07001033 } catch (Throwable e) {
1034 reportWtf("making InputManagerService ready", e);
1035 }
Dan Morrille4d9a012013-03-28 18:10:43 -07001036
Wink Savillea12a7b32012-09-20 10:09:45 -07001037 try {
1038 if (telephonyRegistryF != null) telephonyRegistryF.systemReady();
1039 } catch (Throwable e) {
1040 reportWtf("making TelephonyRegistry ready", e);
1041 }
Dianne Hackborna34f1ad2009-09-02 13:26:28 -07001042 }
1043 });
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001044
Brad Fitzpatrick1e02d362010-09-10 09:19:50 -07001045 // For debug builds, log event loop stalls to dropbox for analysis.
Brad Fitzpatrick50d66f92010-09-13 21:29:05 -07001046 if (StrictMode.conditionallyEnableDebugLogging()) {
1047 Slog.i(TAG, "Enabled StrictMode for system server main thread.");
Brad Fitzpatrick1e02d362010-09-10 09:19:50 -07001048 }
1049
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001050 Looper.loop();
Joe Onorato8a9b2202010-02-26 18:56:32 -08001051 Slog.d(TAG, "System ServerThread is exiting!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001052 }
Joe Onoratof3c3c4f2010-10-21 11:09:02 -04001053
1054 static final void startSystemUi(Context context) {
1055 Intent intent = new Intent();
1056 intent.setComponent(new ComponentName("com.android.systemui",
1057 "com.android.systemui.SystemUIService"));
Dianne Hackborn40e9f292012-11-27 19:12:23 -08001058 //Slog.d(TAG, "Starting service: " + intent);
Amith Yamasanicd757062012-10-19 18:23:52 -07001059 context.startServiceAsUser(intent, UserHandle.OWNER);
Joe Onoratof3c3c4f2010-10-21 11:09:02 -04001060 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001061}
1062
Jeff Hamilton35eef702010-06-09 15:45:18 -05001063public class SystemServer {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001064 private static final String TAG = "SystemServer";
1065
1066 public static final int FACTORY_TEST_OFF = 0;
1067 public static final int FACTORY_TEST_LOW_LEVEL = 1;
1068 public static final int FACTORY_TEST_HIGH_LEVEL = 2;
Jaikumar Ganeshd5ac1ae2009-05-05 22:26:12 -07001069
Bob Leee5408332009-09-04 18:31:17 -07001070 static Timer timer;
1071 static final long SNAPSHOT_INTERVAL = 60 * 60 * 1000; // 1hr
1072
Brad Fitzpatrick6bb7a4a2010-10-11 13:41:10 -07001073 // The earliest supported time. We pick one day into 1970, to
1074 // give any timezone code room without going into negative time.
1075 private static final long EARLIEST_SUPPORTED_TIME = 86400 * 1000;
1076
Jaikumar Ganeshd5ac1ae2009-05-05 22:26:12 -07001077 /**
1078 * 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 -08001079 * services (SurfaceFlinger, AudioFlinger, etc..) to be started. After that it will call back
1080 * up into init2() to start the Android services.
Jaikumar Ganeshd5ac1ae2009-05-05 22:26:12 -07001081 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001082 native public static void init1(String[] args);
1083
1084 public static void main(String[] args) {
Brad Fitzpatrick6bb7a4a2010-10-11 13:41:10 -07001085 if (System.currentTimeMillis() < EARLIEST_SUPPORTED_TIME) {
Brad Fitzpatrick35ca9d82010-10-11 11:52:49 -07001086 // If a device's clock is before 1970 (before 0), a lot of
1087 // APIs crash dealing with negative numbers, notably
1088 // java.io.File#setLastModified, so instead we fake it and
1089 // hope that time from cell towers or NTP fixes it
1090 // shortly.
1091 Slog.w(TAG, "System clock is before 1970; setting to 1970.");
Brad Fitzpatrick6bb7a4a2010-10-11 13:41:10 -07001092 SystemClock.setCurrentTimeMillis(EARLIEST_SUPPORTED_TIME);
Brad Fitzpatrick35ca9d82010-10-11 11:52:49 -07001093 }
1094
Bob Leee5408332009-09-04 18:31:17 -07001095 if (SamplingProfilerIntegration.isEnabled()) {
1096 SamplingProfilerIntegration.start();
1097 timer = new Timer();
1098 timer.schedule(new TimerTask() {
1099 @Override
1100 public void run() {
Sen Hubde75702010-05-28 01:54:03 -07001101 SamplingProfilerIntegration.writeSnapshot("system_server", null);
Bob Leee5408332009-09-04 18:31:17 -07001102 }
1103 }, SNAPSHOT_INTERVAL, SNAPSHOT_INTERVAL);
1104 }
1105
Dianne Hackbornac1471a2011-02-03 13:46:06 -08001106 // Mmmmmm... more memory!
1107 dalvik.system.VMRuntime.getRuntime().clearGrowthLimit();
1108
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001109 // The system server has to run all of the time, so it needs to be
1110 // as efficient as possible with its memory usage.
1111 VMRuntime.getRuntime().setTargetHeapUtilization(0.8f);
Sen Hubde75702010-05-28 01:54:03 -07001112
Jeff Sharkey48749fc2013-04-19 13:25:04 -07001113 Environment.setUserRequired(true);
1114
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001115 System.loadLibrary("android_servers");
1116 init1(args);
1117 }
1118
1119 public static final void init2() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001120 Slog.i(TAG, "Entered the Android system server!");
Dianne Hackbornefa92b22013-05-03 14:11:43 -07001121
1122 // This used to be its own separate thread, but now it is
1123 // just the loop we run on the main thread.
1124 ServerThread thr = new ServerThread();
1125 thr.initAndLoop();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001126 }
1127}