blob: 3f9d666486a206c3960adcac8793b922f05aab4f [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 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)");
Dan Morrille4d9a012013-03-28 18:10:43 -0700325 } else if (disableBluetooth) {
326 Slog.i(TAG, "Bluetooth Service disabled by config");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800327 } else {
fredc0f420372012-04-12 00:02:00 -0700328 Slog.i(TAG, "Bluetooth Manager Service");
329 bluetooth = new BluetoothManagerService(context);
330 ServiceManager.addService(BluetoothAdapter.BLUETOOTH_MANAGER_SERVICE, bluetooth);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800331 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800332 } catch (RuntimeException e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700333 Slog.e("System", "******************************************");
334 Slog.e("System", "************ Failure starting core service", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800335 }
336
Dianne Hackbornd6847842010-01-12 18:14:19 -0800337 DevicePolicyManagerService devicePolicy = null;
Joe Onorato089de882010-04-12 08:18:45 -0700338 StatusBarManagerService statusBar = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800339 InputMethodManagerService imm = null;
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700340 AppWidgetService appWidget = null;
Joe Onorato30275482009-07-08 17:09:14 -0700341 NotificationManagerService notification = null;
Dianne Hackbornf21adf62009-08-13 10:20:21 -0700342 WallpaperManagerService wallpaper = null;
Mike Lockwood46db5042010-02-22 16:36:44 -0500343 LocationManagerService location = null;
Bai Taoa58a8752010-07-13 15:32:16 +0800344 CountryDetectorService countryDetector = null;
satok988323c2011-06-22 16:38:13 +0900345 TextServicesManagerService tsms = null;
Amith Yamasani52c489c2012-03-28 11:42:42 -0700346 LockSettingsService lockSettings = null;
Daniel Sandler7d276c32012-01-30 14:33:52 -0500347 DreamManagerService dreamy = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800348
Dianne Hackborn661cd522011-08-22 00:26:20 -0700349 // Bring up services needed for UI.
350 if (factoryTest != SystemServer.FACTORY_TEST_LOW_LEVEL) {
Dan Morrille4d9a012013-03-28 18:10:43 -0700351 //if (!disableNonCoreServices) { // TODO: View depends on these; mock them?
352 if (true) {
353 try {
354 Slog.i(TAG, "Input Method Service");
355 imm = new InputMethodManagerService(context, wm);
356 ServiceManager.addService(Context.INPUT_METHOD_SERVICE, imm);
357 } catch (Throwable e) {
358 reportWtf("starting Input Manager Service", e);
359 }
Dianne Hackborn661cd522011-08-22 00:26:20 -0700360
Dan Morrille4d9a012013-03-28 18:10:43 -0700361 try {
362 Slog.i(TAG, "Accessibility Manager");
363 ServiceManager.addService(Context.ACCESSIBILITY_SERVICE,
364 new AccessibilityManagerService(context));
365 } catch (Throwable e) {
366 reportWtf("starting Accessibility Manager", e);
367 }
Dianne Hackborn661cd522011-08-22 00:26:20 -0700368 }
369 }
370
371 try {
372 wm.displayReady();
373 } catch (Throwable e) {
374 reportWtf("making display ready", e);
375 }
Dianne Hackborn8795b602011-08-25 13:30:53 -0700376
Dianne Hackborn295e3c22011-08-25 13:19:08 -0700377 try {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700378 pm.performBootDexOpt();
379 } catch (Throwable e) {
380 reportWtf("performing boot dexopt", e);
381 }
382
383 try {
384 ActivityManagerNative.getDefault().showBootMessage(
385 context.getResources().getText(
386 com.android.internal.R.string.android_upgrading_starting_apps),
387 false);
388 } catch (RemoteException e) {
389 }
390
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800391 if (factoryTest != SystemServer.FACTORY_TEST_LOW_LEVEL) {
Dan Morrille4d9a012013-03-28 18:10:43 -0700392 if (!disableStorage &&
393 !"0".equals(SystemProperties.get("system_init.startmountservice"))) {
Kenny Root51a573c2012-05-17 13:30:28 -0700394 try {
395 /*
396 * NotificationManagerService is dependant on MountService,
397 * (for media / usb notifications) so we must start MountService first.
398 */
399 Slog.i(TAG, "Mount Service");
400 mountService = new MountService(context);
401 ServiceManager.addService("mount", mountService);
402 } catch (Throwable e) {
403 reportWtf("starting Mount Service", e);
404 }
405 }
406
Dan Morrille4d9a012013-03-28 18:10:43 -0700407 if (!disableNonCoreServices) {
408 try {
409 Slog.i(TAG, "LockSettingsService");
410 lockSettings = new LockSettingsService(context);
411 ServiceManager.addService("lock_settings", lockSettings);
412 } catch (Throwable e) {
413 reportWtf("starting LockSettingsService service", e);
414 }
415
416 try {
417 Slog.i(TAG, "Device Policy");
418 devicePolicy = new DevicePolicyManagerService(context);
419 ServiceManager.addService(Context.DEVICE_POLICY_SERVICE, devicePolicy);
420 } catch (Throwable e) {
421 reportWtf("starting DevicePolicyService", e);
422 }
Amith Yamasani52c489c2012-03-28 11:42:42 -0700423 }
424
Dan Morrille4d9a012013-03-28 18:10:43 -0700425 if (!disableSystemUI) {
426 try {
427 Slog.i(TAG, "Status Bar");
428 statusBar = new StatusBarManagerService(context, wm);
429 ServiceManager.addService(Context.STATUS_BAR_SERVICE, statusBar);
430 } catch (Throwable e) {
431 reportWtf("starting StatusBarManagerService", e);
432 }
Dianne Hackbornd6847842010-01-12 18:14:19 -0800433 }
434
Dan Morrille4d9a012013-03-28 18:10:43 -0700435 if (!disableNonCoreServices) {
436 try {
437 Slog.i(TAG, "Clipboard Service");
438 ServiceManager.addService(Context.CLIPBOARD_SERVICE,
439 new ClipboardService(context));
440 } catch (Throwable e) {
441 reportWtf("starting Clipboard Service", e);
442 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800443 }
444
Dan Morrille4d9a012013-03-28 18:10:43 -0700445 if (!disableNetwork) {
446 try {
447 Slog.i(TAG, "NetworkManagement Service");
448 networkManagement = NetworkManagementService.create(context);
449 ServiceManager.addService(Context.NETWORKMANAGEMENT_SERVICE, networkManagement);
450 } catch (Throwable e) {
451 reportWtf("starting NetworkManagement Service", e);
452 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800453 }
454
Dan Morrille4d9a012013-03-28 18:10:43 -0700455 if (!disableNonCoreServices) {
456 try {
457 Slog.i(TAG, "Text Service Manager Service");
458 tsms = new TextServicesManagerService(context);
459 ServiceManager.addService(Context.TEXT_SERVICES_MANAGER_SERVICE, tsms);
460 } catch (Throwable e) {
461 reportWtf("starting Text Service Manager Service", e);
462 }
San Mehatd1df8ac2010-01-26 06:17:26 -0800463 }
464
Dan Morrille4d9a012013-03-28 18:10:43 -0700465 if (!disableNetwork) {
466 try {
467 Slog.i(TAG, "NetworkStats Service");
468 networkStats = new NetworkStatsService(context, networkManagement, alarm);
469 ServiceManager.addService(Context.NETWORK_STATS_SERVICE, networkStats);
470 } catch (Throwable e) {
471 reportWtf("starting NetworkStats Service", e);
472 }
473
474 try {
475 Slog.i(TAG, "NetworkPolicy Service");
476 networkPolicy = new NetworkPolicyManagerService(
477 context, ActivityManagerService.self(), power,
478 networkStats, networkManagement);
479 ServiceManager.addService(Context.NETWORK_POLICY_SERVICE, networkPolicy);
480 } catch (Throwable e) {
481 reportWtf("starting NetworkPolicy Service", e);
482 }
483
484 try {
485 Slog.i(TAG, "Wi-Fi P2pService");
486 wifiP2p = new WifiP2pService(context);
487 ServiceManager.addService(Context.WIFI_P2P_SERVICE, wifiP2p);
488 } catch (Throwable e) {
489 reportWtf("starting Wi-Fi P2pService", e);
490 }
491
492 try {
493 Slog.i(TAG, "Wi-Fi Service");
494 wifi = new WifiService(context);
495 ServiceManager.addService(Context.WIFI_SERVICE, wifi);
496 } catch (Throwable e) {
497 reportWtf("starting Wi-Fi Service", e);
498 }
499
500 try {
501 Slog.i(TAG, "Connectivity Service");
502 connectivity = new ConnectivityService(
503 context, networkManagement, networkStats, networkPolicy);
504 ServiceManager.addService(Context.CONNECTIVITY_SERVICE, connectivity);
505 networkStats.bindConnectivityManager(connectivity);
506 networkPolicy.bindConnectivityManager(connectivity);
507 wifi.checkAndStartWifi();
508 wifiP2p.connectivityServiceReady();
509 } catch (Throwable e) {
510 reportWtf("starting Connectivity Service", e);
511 }
512
513 try {
514 Slog.i(TAG, "Network Service Discovery Service");
515 serviceDiscovery = NsdService.create(context);
516 ServiceManager.addService(
517 Context.NSD_SERVICE, serviceDiscovery);
518 } catch (Throwable e) {
519 reportWtf("starting Service Discovery Service", e);
520 }
satok988323c2011-06-22 16:38:13 +0900521 }
522
Dan Morrille4d9a012013-03-28 18:10:43 -0700523 if (!disableNonCoreServices) {
524 try {
525 Slog.i(TAG, "UpdateLock Service");
526 ServiceManager.addService(Context.UPDATE_LOCK_SERVICE,
527 new UpdateLockService(context));
528 } catch (Throwable e) {
529 reportWtf("starting UpdateLockService", e);
530 }
Christopher Tate8662cab52012-02-23 14:59:36 -0800531 }
532
Kenny Root51a573c2012-05-17 13:30:28 -0700533 /*
534 * MountService has a few dependencies: Notification Manager and
535 * AppWidget Provider. Make sure MountService is completely started
536 * first before continuing.
537 */
538 if (mountService != null) {
539 mountService.waitForAsecScan();
San Mehat1bf3f8b2010-02-03 14:43:09 -0800540 }
541
542 try {
Kenny Root26ff6622012-07-30 12:58:03 -0700543 if (accountManager != null)
544 accountManager.systemReady();
545 } catch (Throwable e) {
546 reportWtf("making Account Manager Service ready", e);
547 }
548
549 try {
550 if (contentService != null)
551 contentService.systemReady();
552 } catch (Throwable e) {
553 reportWtf("making Content Service ready", e);
554 }
555
556 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800557 Slog.i(TAG, "Notification Manager");
Mike Lockwood3a322132009-11-24 00:30:52 -0500558 notification = new NotificationManagerService(context, statusBar, lights);
Joe Onorato30275482009-07-08 17:09:14 -0700559 ServiceManager.addService(Context.NOTIFICATION_SERVICE, notification);
Jeff Sharkey497e4432011-06-14 17:27:29 -0700560 networkPolicy.bindNotificationManager(notification);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800561 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700562 reportWtf("starting Notification Manager", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800563 }
564
565 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800566 Slog.i(TAG, "Device Storage Monitor");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800567 ServiceManager.addService(DeviceStorageMonitorService.SERVICE,
568 new DeviceStorageMonitorService(context));
569 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700570 reportWtf("starting DeviceStorageMonitor service", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800571 }
572
Dan Morrille4d9a012013-03-28 18:10:43 -0700573 if (!disableLocation) {
574 try {
575 Slog.i(TAG, "Location Manager");
576 location = new LocationManagerService(context);
577 ServiceManager.addService(Context.LOCATION_SERVICE, location);
578 } catch (Throwable e) {
579 reportWtf("starting Location Manager", e);
580 }
581
582 try {
583 Slog.i(TAG, "Country Detector");
584 countryDetector = new CountryDetectorService(context);
585 ServiceManager.addService(Context.COUNTRY_DETECTOR, countryDetector);
586 } catch (Throwable e) {
587 reportWtf("starting Country Detector", e);
588 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800589 }
590
Dan Morrille4d9a012013-03-28 18:10:43 -0700591 if (!disableNonCoreServices) {
592 try {
593 Slog.i(TAG, "Search Service");
594 ServiceManager.addService(Context.SEARCH_SERVICE,
595 new SearchManagerService(context));
596 } catch (Throwable e) {
597 reportWtf("starting Search Service", e);
598 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800599 }
600
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800601 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800602 Slog.i(TAG, "DropBox Service");
Dan Egnor95240272009-10-27 18:23:39 -0700603 ServiceManager.addService(Context.DROPBOX_SERVICE,
Dan Egnorf18a01c2009-11-12 11:32:50 -0800604 new DropBoxManagerService(context, new File("/data/system/dropbox")));
Dan Egnor4410ec82009-09-11 16:40:01 -0700605 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700606 reportWtf("starting DropBoxManagerService", e);
Dan Egnor4410ec82009-09-11 16:40:01 -0700607 }
608
Dan Morrille4d9a012013-03-28 18:10:43 -0700609 if (!disableNonCoreServices && context.getResources().getBoolean(
610 R.bool.config_enableWallpaperService)) {
Mike Lockwoodc067c9c2011-10-31 12:50:12 -0400611 try {
612 Slog.i(TAG, "Wallpaper Service");
613 if (!headless) {
614 wallpaper = new WallpaperManagerService(context);
615 ServiceManager.addService(Context.WALLPAPER_SERVICE, wallpaper);
616 }
617 } catch (Throwable e) {
618 reportWtf("starting Wallpaper Service", e);
Mike Lockwood3a74bd32011-08-12 13:55:22 -0700619 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800620 }
621
Dan Morrille4d9a012013-03-28 18:10:43 -0700622 if (!disableMedia && !"0".equals(SystemProperties.get("system_init.startaudioservice"))) {
Mike Lockwoodcba928c2011-08-17 15:58:52 -0700623 try {
624 Slog.i(TAG, "Audio Service");
625 ServiceManager.addService(Context.AUDIO_SERVICE, new AudioService(context));
626 } catch (Throwable e) {
627 reportWtf("starting Audio Service", e);
628 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800629 }
630
Dan Morrille4d9a012013-03-28 18:10:43 -0700631 if (!disableNonCoreServices) {
632 try {
633 Slog.i(TAG, "Dock Observer");
634 // Listen for dock station changes
635 dock = new DockObserver(context);
636 } catch (Throwable e) {
637 reportWtf("starting DockObserver", e);
638 }
Dan Murphyc9f4eaf2009-08-12 15:15:43 -0500639 }
640
Dan Morrille4d9a012013-03-28 18:10:43 -0700641 if (!disableMedia) {
642 try {
643 Slog.i(TAG, "Wired Accessory Manager");
644 // Listen for wired headset changes
645 inputManager.setWiredAccessoryCallbacks(
646 new WiredAccessoryManager(context, inputManager));
647 } catch (Throwable e) {
648 reportWtf("starting WiredAccessoryManager", e);
649 }
Praveen Bharathi21e941b2010-10-06 15:23:14 -0500650 }
651
Dan Morrille4d9a012013-03-28 18:10:43 -0700652 if (!disableNonCoreServices) {
653 try {
654 Slog.i(TAG, "USB Service");
655 // Manage USB host and device support
656 usb = new UsbService(context);
657 ServiceManager.addService(Context.USB_SERVICE, usb);
658 } catch (Throwable e) {
659 reportWtf("starting UsbService", e);
660 }
Mike Lockwood57c798a2010-06-23 17:36:36 -0400661
Dan Morrille4d9a012013-03-28 18:10:43 -0700662 try {
663 Slog.i(TAG, "Serial Service");
664 // Serial port support
665 serial = new SerialService(context);
666 ServiceManager.addService(Context.SERIAL_SERVICE, serial);
667 } catch (Throwable e) {
668 Slog.e(TAG, "Failure starting SerialService", e);
669 }
Mike Lockwoodb01e8bf2011-08-29 20:11:07 -0400670 }
671
672 try {
Jeff Brown2416e092012-08-21 22:12:20 -0700673 Slog.i(TAG, "Twilight Service");
674 twilight = new TwilightService(context);
675 } catch (Throwable e) {
676 reportWtf("starting TwilightService", e);
677 }
678
679 try {
Dianne Hackborn7299c412010-03-04 18:41:49 -0800680 Slog.i(TAG, "UI Mode Manager Service");
Mike Lockwood57c798a2010-06-23 17:36:36 -0400681 // Listen for UI mode changes
Jeff Brown2416e092012-08-21 22:12:20 -0700682 uiMode = new UiModeManagerService(context, twilight);
Dianne Hackborn7299c412010-03-04 18:41:49 -0800683 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700684 reportWtf("starting UiModeManagerService", e);
Dianne Hackborn7299c412010-03-04 18:41:49 -0800685 }
686
Dan Morrille4d9a012013-03-28 18:10:43 -0700687 if (!disableNonCoreServices) {
688 try {
689 Slog.i(TAG, "Backup Service");
690 ServiceManager.addService(Context.BACKUP_SERVICE,
691 new BackupManagerService(context));
692 } catch (Throwable e) {
693 Slog.e(TAG, "Failure starting Backup Service", e);
694 }
Christopher Tate487529a2009-04-29 14:03:25 -0700695
Dan Morrille4d9a012013-03-28 18:10:43 -0700696 try {
697 Slog.i(TAG, "AppWidget Service");
698 appWidget = new AppWidgetService(context);
699 ServiceManager.addService(Context.APPWIDGET_SERVICE, appWidget);
700 } catch (Throwable e) {
701 reportWtf("starting AppWidget Service", e);
702 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800703
Dan Morrille4d9a012013-03-28 18:10:43 -0700704 try {
705 Slog.i(TAG, "Recognition Service");
706 recognition = new RecognitionManagerService(context);
707 } catch (Throwable e) {
708 reportWtf("starting Recognition Service", e);
709 }
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800710 }
Jaikumar Ganesh7d0548d2010-10-18 15:29:09 -0700711
Nick Pelly038cabe2010-09-23 16:12:11 -0700712 try {
Dan Egnor621bc542010-03-25 16:20:14 -0700713 Slog.i(TAG, "DiskStats Service");
714 ServiceManager.addService("diskstats", new DiskStatsService(context));
715 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700716 reportWtf("starting DiskStats Service", e);
Dan Egnor621bc542010-03-25 16:20:14 -0700717 }
Sen Hubde75702010-05-28 01:54:03 -0700718
719 try {
720 // need to add this service even if SamplingProfilerIntegration.isEnabled()
721 // is false, because it is this service that detects system property change and
722 // turns on SamplingProfilerIntegration. Plus, when sampling profiler doesn't work,
723 // there is little overhead for running this service.
724 Slog.i(TAG, "SamplingProfiler Service");
725 ServiceManager.addService("samplingprofiler",
726 new SamplingProfilerService(context));
727 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700728 reportWtf("starting SamplingProfiler Service", e);
Sen Hubde75702010-05-28 01:54:03 -0700729 }
Chung-yih Wang024d5962010-08-06 12:06:04 +0800730
Dan Morrille4d9a012013-03-28 18:10:43 -0700731 if (!disableNetwork) {
732 try {
733 Slog.i(TAG, "NetworkTimeUpdateService");
734 networkTimeUpdater = new NetworkTimeUpdateService(context);
735 } catch (Throwable e) {
736 reportWtf("starting NetworkTimeUpdate service", e);
737 }
Amith Yamasani6734b9f62010-09-13 16:24:08 -0700738 }
John Grossmanc1576732012-02-01 15:23:33 -0800739
Dan Morrille4d9a012013-03-28 18:10:43 -0700740 if (!disableMedia) {
741 try {
742 Slog.i(TAG, "CommonTimeManagementService");
743 commonTimeMgmtService = new CommonTimeManagementService(context);
744 ServiceManager.addService("commontime_management", commonTimeMgmtService);
745 } catch (Throwable e) {
746 reportWtf("starting CommonTimeManagementService service", e);
747 }
John Grossmanc1576732012-02-01 15:23:33 -0800748 }
Geremy Condra3d33c262012-05-06 18:32:19 -0700749
Dan Morrille4d9a012013-03-28 18:10:43 -0700750 if (!disableNetwork) {
751 try {
752 Slog.i(TAG, "CertBlacklister");
753 CertBlacklister blacklister = new CertBlacklister(context);
754 } catch (Throwable e) {
755 reportWtf("starting CertBlacklister", e);
756 }
Geremy Condra3d33c262012-05-06 18:32:19 -0700757 }
Jim Miller5ecd8112013-01-09 18:50:26 -0800758
Dan Morrille4d9a012013-03-28 18:10:43 -0700759 if (!disableNonCoreServices &&
760 context.getResources().getBoolean(R.bool.config_dreamsSupported)) {
Daniel Sandler7d276c32012-01-30 14:33:52 -0500761 try {
762 Slog.i(TAG, "Dreams Service");
763 // Dreams (interactive idle-time views, a/k/a screen savers)
Jeff Brown62c82e42012-09-26 01:30:41 -0700764 dreamy = new DreamManagerService(context, wmHandler);
Dianne Hackbornbe87e2f2012-09-28 16:31:34 -0700765 ServiceManager.addService(DreamService.DREAM_SERVICE, dreamy);
Daniel Sandler7d276c32012-01-30 14:33:52 -0500766 } catch (Throwable e) {
767 reportWtf("starting DreamManagerService", e);
768 }
769 }
Svetoslavb3038ec2013-02-13 14:39:30 -0800770
771 try {
772 Slog.i(TAG, "IdleMaintenanceService");
773 new IdleMaintenanceService(context);
774 } catch (Throwable e) {
775 reportWtf("starting IdleMaintenanceService", e);
776 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800777 }
778
Dianne Hackborn6af0d502009-09-28 13:25:46 -0700779 // Before things start rolling, be sure we have decided whether
780 // we are in safe mode.
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700781 final boolean safeMode = wm.detectSafeMode();
Dianne Hackborn6af0d502009-09-28 13:25:46 -0700782 if (safeMode) {
Jeff Brownb09abc12011-01-13 21:08:27 -0800783 ActivityManagerService.self().enterSafeMode();
784 // Post the safe mode state in the Zygote class
785 Zygote.systemInSafeMode = true;
786 // Disable the JIT for the system_server process
787 VMRuntime.getRuntime().disableJitCompilation();
Ben Cheng6c0afff2010-02-14 16:18:56 -0800788 } else {
789 // Enable the JIT for the system_server process
790 VMRuntime.getRuntime().startJitCompilation();
Dianne Hackborn6af0d502009-09-28 13:25:46 -0700791 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800792
Dianne Hackborn6af0d502009-09-28 13:25:46 -0700793 // It is now time to start up the app processes...
Joe Onorato30275482009-07-08 17:09:14 -0700794
Jeff Brown7f6c2312012-04-13 20:38:38 -0700795 try {
796 vibrator.systemReady();
797 } catch (Throwable e) {
798 reportWtf("making Vibrator Service ready", e);
799 }
800
Dan Morrille4d9a012013-03-28 18:10:43 -0700801 if (lockSettings != null) {
802 try {
803 lockSettings.systemReady();
804 } catch (Throwable e) {
805 reportWtf("making Lock Settings Service ready", e);
806 }
Felipe Ramosf35df5b2012-09-18 18:26:27 -0300807 }
808
Dianne Hackbornd6847842010-01-12 18:14:19 -0800809 if (devicePolicy != null) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700810 try {
811 devicePolicy.systemReady();
812 } catch (Throwable e) {
813 reportWtf("making Device Policy Service ready", e);
814 }
Dianne Hackbornd6847842010-01-12 18:14:19 -0800815 }
816
Joe Onorato30275482009-07-08 17:09:14 -0700817 if (notification != null) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700818 try {
819 notification.systemReady();
820 } catch (Throwable e) {
821 reportWtf("making Notification Service ready", e);
822 }
Joe Onorato30275482009-07-08 17:09:14 -0700823 }
824
Dianne Hackborn661cd522011-08-22 00:26:20 -0700825 try {
826 wm.systemReady();
827 } catch (Throwable e) {
828 reportWtf("making Window Manager Service ready", e);
829 }
Joe Onoratodc565f42010-10-04 15:27:22 -0400830
Jeff Brownb09abc12011-01-13 21:08:27 -0800831 if (safeMode) {
832 ActivityManagerService.self().showSafeModeOverlay();
833 }
834
Joe Onoratodc565f42010-10-04 15:27:22 -0400835 // Update the configuration for this context by hand, because we're going
836 // to start using it before the config change done in wm.systemReady() will
837 // propagate to it.
838 Configuration config = wm.computeNewConfiguration();
839 DisplayMetrics metrics = new DisplayMetrics();
840 WindowManager w = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
841 w.getDefaultDisplay().getMetrics(metrics);
842 context.getResources().updateConfiguration(config, metrics);
843
Jeff Brownaa202a62012-08-21 22:14:26 -0700844 try {
Jeff Brown62c82e42012-09-26 01:30:41 -0700845 power.systemReady(twilight, dreamy);
Jeff Brownaa202a62012-08-21 22:14:26 -0700846 } catch (Throwable e) {
847 reportWtf("making Power Manager Service ready", e);
848 }
849
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800850 try {
851 pm.systemReady();
Dianne Hackborn661cd522011-08-22 00:26:20 -0700852 } catch (Throwable e) {
853 reportWtf("making Package Manager Service ready", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800854 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800855
Jeff Brownbd6e1502012-08-28 03:27:37 -0700856 try {
857 display.systemReady(safeMode, onlyCore);
858 } catch (Throwable e) {
859 reportWtf("making Display Manager Service ready", e);
860 }
861
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700862 // These are needed to propagate to the runnable below.
Joe Onoratof3c3c4f2010-10-21 11:09:02 -0400863 final Context contextF = context;
Jeff Sharkeyb049e2122012-09-07 23:16:01 -0700864 final MountService mountServiceF = mountService;
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700865 final BatteryService batteryF = battery;
Jeff Sharkey350083e2011-06-29 10:45:16 -0700866 final NetworkManagementService networkManagementF = networkManagement;
Jeff Sharkey75279902011-05-24 18:39:45 -0700867 final NetworkStatsService networkStatsF = networkStats;
Jeff Sharkeya4620792011-05-20 15:29:23 -0700868 final NetworkPolicyManagerService networkPolicyF = networkPolicy;
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700869 final ConnectivityService connectivityF = connectivity;
870 final DockObserver dockF = dock;
Mike Lockwood770126a2010-12-09 22:30:37 -0800871 final UsbService usbF = usb;
Jeff Brown2416e092012-08-21 22:12:20 -0700872 final TwilightService twilightF = twilight;
Dianne Hackborn7299c412010-03-04 18:41:49 -0800873 final UiModeManagerService uiModeF = uiMode;
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700874 final AppWidgetService appWidgetF = appWidget;
875 final WallpaperManagerService wallpaperF = wallpaper;
876 final InputMethodManagerService immF = imm;
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800877 final RecognitionManagerService recognitionF = recognition;
Mike Lockwood46db5042010-02-22 16:36:44 -0500878 final LocationManagerService locationF = location;
Bai Taoa58a8752010-07-13 15:32:16 +0800879 final CountryDetectorService countryDetectorF = countryDetector;
Amith Yamasani6734b9f62010-09-13 16:24:08 -0700880 final NetworkTimeUpdateService networkTimeUpdaterF = networkTimeUpdater;
John Grossmanc1576732012-02-01 15:23:33 -0800881 final CommonTimeManagementService commonTimeMgmtServiceF = commonTimeMgmtService;
satok988323c2011-06-22 16:38:13 +0900882 final TextServicesManagerService textServiceManagerServiceF = tsms;
Dianne Hackborn661cd522011-08-22 00:26:20 -0700883 final StatusBarManagerService statusBarF = statusBar;
Daniel Sandler7d276c32012-01-30 14:33:52 -0500884 final DreamManagerService dreamyF = dreamy;
Jeff Brown6ec6f792012-04-17 16:52:41 -0700885 final InputManagerService inputManagerF = inputManager;
Wink Savillea12a7b32012-09-20 10:09:45 -0700886 final TelephonyRegistry telephonyRegistryF = telephonyRegistry;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800887
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700888 // We now tell the activity manager it is okay to run third party
889 // code. It will call back into us once it has gotten to the state
890 // where third party code can really run (but before it has actually
891 // started launching the initial applications), for us to complete our
892 // initialization.
Dianne Hackborn295e3c22011-08-25 13:19:08 -0700893 ActivityManagerService.self().systemReady(new Runnable() {
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700894 public void run() {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800895 Slog.i(TAG, "Making services ready");
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800896
Christopher Tate58d380d2013-03-19 13:10:03 -0700897 try {
898 ActivityManagerService.self().startObservingNativeCrashes();
899 } catch (Throwable e) {
900 reportWtf("observing native crashes", e);
901 }
Jim Miller5ecd8112013-01-09 18:50:26 -0800902 if (!headless) {
903 startSystemUi(contextF);
904 }
Dianne Hackborn661cd522011-08-22 00:26:20 -0700905 try {
Jeff Sharkeyb049e2122012-09-07 23:16:01 -0700906 if (mountServiceF != null) mountServiceF.systemReady();
907 } catch (Throwable e) {
908 reportWtf("making Mount Service ready", e);
909 }
910 try {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700911 if (batteryF != null) batteryF.systemReady();
912 } catch (Throwable e) {
913 reportWtf("making Battery Service ready", e);
914 }
915 try {
916 if (networkManagementF != null) networkManagementF.systemReady();
917 } catch (Throwable e) {
918 reportWtf("making Network Managment Service ready", e);
919 }
920 try {
921 if (networkStatsF != null) networkStatsF.systemReady();
922 } catch (Throwable e) {
923 reportWtf("making Network Stats Service ready", e);
924 }
925 try {
926 if (networkPolicyF != null) networkPolicyF.systemReady();
927 } catch (Throwable e) {
928 reportWtf("making Network Policy Service ready", e);
929 }
930 try {
931 if (connectivityF != null) connectivityF.systemReady();
932 } catch (Throwable e) {
933 reportWtf("making Connectivity Service ready", e);
934 }
935 try {
936 if (dockF != null) dockF.systemReady();
937 } catch (Throwable e) {
938 reportWtf("making Dock Service ready", e);
939 }
940 try {
941 if (usbF != null) usbF.systemReady();
942 } catch (Throwable e) {
943 reportWtf("making USB Service ready", e);
944 }
945 try {
Jeff Brown2416e092012-08-21 22:12:20 -0700946 if (twilightF != null) twilightF.systemReady();
947 } catch (Throwable e) {
948 reportWtf("makin Twilight Service ready", e);
949 }
950 try {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700951 if (uiModeF != null) uiModeF.systemReady();
952 } catch (Throwable e) {
953 reportWtf("making UI Mode Service ready", e);
954 }
955 try {
956 if (recognitionF != null) recognitionF.systemReady();
957 } catch (Throwable e) {
958 reportWtf("making Recognition Service ready", e);
959 }
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700960 Watchdog.getInstance().start();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800961
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700962 // It is now okay to let the various system services start their
963 // third party code...
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800964
Dianne Hackborn661cd522011-08-22 00:26:20 -0700965 try {
966 if (appWidgetF != null) appWidgetF.systemReady(safeMode);
967 } catch (Throwable e) {
968 reportWtf("making App Widget Service ready", e);
969 }
970 try {
971 if (wallpaperF != null) wallpaperF.systemReady();
972 } catch (Throwable e) {
973 reportWtf("making Wallpaper Service ready", e);
974 }
975 try {
976 if (immF != null) immF.systemReady(statusBarF);
977 } catch (Throwable e) {
978 reportWtf("making Input Method Service ready", e);
979 }
980 try {
981 if (locationF != null) locationF.systemReady();
982 } catch (Throwable e) {
983 reportWtf("making Location Service ready", e);
984 }
985 try {
986 if (countryDetectorF != null) countryDetectorF.systemReady();
987 } catch (Throwable e) {
988 reportWtf("making Country Detector Service ready", e);
989 }
990 try {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700991 if (networkTimeUpdaterF != null) networkTimeUpdaterF.systemReady();
992 } catch (Throwable e) {
993 reportWtf("making Network Time Service ready", e);
994 }
995 try {
John Grossmanc1576732012-02-01 15:23:33 -0800996 if (commonTimeMgmtServiceF != null) commonTimeMgmtServiceF.systemReady();
997 } catch (Throwable e) {
998 reportWtf("making Common time management service ready", e);
999 }
1000 try {
Dianne Hackborn661cd522011-08-22 00:26:20 -07001001 if (textServiceManagerServiceF != null) textServiceManagerServiceF.systemReady();
1002 } catch (Throwable e) {
1003 reportWtf("making Text Services Manager Service ready", e);
1004 }
Daniel Sandler7d276c32012-01-30 14:33:52 -05001005 try {
1006 if (dreamyF != null) dreamyF.systemReady();
1007 } catch (Throwable e) {
1008 reportWtf("making DreamManagerService ready", e);
1009 }
Jeff Brown6ec6f792012-04-17 16:52:41 -07001010 try {
Matthew Xie96313142012-06-29 16:57:31 -07001011 // TODO(BT) Pass parameter to input manager
1012 if (inputManagerF != null) inputManagerF.systemReady();
Jeff Brown6ec6f792012-04-17 16:52:41 -07001013 } catch (Throwable e) {
1014 reportWtf("making InputManagerService ready", e);
1015 }
Dan Morrille4d9a012013-03-28 18:10:43 -07001016
Wink Savillea12a7b32012-09-20 10:09:45 -07001017 try {
1018 if (telephonyRegistryF != null) telephonyRegistryF.systemReady();
1019 } catch (Throwable e) {
1020 reportWtf("making TelephonyRegistry ready", e);
1021 }
Dianne Hackborna34f1ad2009-09-02 13:26:28 -07001022 }
1023 });
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001024
Brad Fitzpatrick1e02d362010-09-10 09:19:50 -07001025 // For debug builds, log event loop stalls to dropbox for analysis.
Brad Fitzpatrick50d66f92010-09-13 21:29:05 -07001026 if (StrictMode.conditionallyEnableDebugLogging()) {
1027 Slog.i(TAG, "Enabled StrictMode for system server main thread.");
Brad Fitzpatrick1e02d362010-09-10 09:19:50 -07001028 }
1029
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001030 Looper.loop();
Joe Onorato8a9b2202010-02-26 18:56:32 -08001031 Slog.d(TAG, "System ServerThread is exiting!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001032 }
Joe Onoratof3c3c4f2010-10-21 11:09:02 -04001033
1034 static final void startSystemUi(Context context) {
1035 Intent intent = new Intent();
1036 intent.setComponent(new ComponentName("com.android.systemui",
1037 "com.android.systemui.SystemUIService"));
Dianne Hackborn40e9f292012-11-27 19:12:23 -08001038 //Slog.d(TAG, "Starting service: " + intent);
Amith Yamasanicd757062012-10-19 18:23:52 -07001039 context.startServiceAsUser(intent, UserHandle.OWNER);
Joe Onoratof3c3c4f2010-10-21 11:09:02 -04001040 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001041}
1042
Jeff Hamilton35eef702010-06-09 15:45:18 -05001043public class SystemServer {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001044 private static final String TAG = "SystemServer";
1045
1046 public static final int FACTORY_TEST_OFF = 0;
1047 public static final int FACTORY_TEST_LOW_LEVEL = 1;
1048 public static final int FACTORY_TEST_HIGH_LEVEL = 2;
Jaikumar Ganeshd5ac1ae2009-05-05 22:26:12 -07001049
Bob Leee5408332009-09-04 18:31:17 -07001050 static Timer timer;
1051 static final long SNAPSHOT_INTERVAL = 60 * 60 * 1000; // 1hr
1052
Brad Fitzpatrick6bb7a4a2010-10-11 13:41:10 -07001053 // The earliest supported time. We pick one day into 1970, to
1054 // give any timezone code room without going into negative time.
1055 private static final long EARLIEST_SUPPORTED_TIME = 86400 * 1000;
1056
Jaikumar Ganeshd5ac1ae2009-05-05 22:26:12 -07001057 /**
1058 * 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 -08001059 * services (SurfaceFlinger, AudioFlinger, etc..) to be started. After that it will call back
1060 * up into init2() to start the Android services.
Jaikumar Ganeshd5ac1ae2009-05-05 22:26:12 -07001061 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001062 native public static void init1(String[] args);
1063
1064 public static void main(String[] args) {
Brad Fitzpatrick6bb7a4a2010-10-11 13:41:10 -07001065 if (System.currentTimeMillis() < EARLIEST_SUPPORTED_TIME) {
Brad Fitzpatrick35ca9d82010-10-11 11:52:49 -07001066 // If a device's clock is before 1970 (before 0), a lot of
1067 // APIs crash dealing with negative numbers, notably
1068 // java.io.File#setLastModified, so instead we fake it and
1069 // hope that time from cell towers or NTP fixes it
1070 // shortly.
1071 Slog.w(TAG, "System clock is before 1970; setting to 1970.");
Brad Fitzpatrick6bb7a4a2010-10-11 13:41:10 -07001072 SystemClock.setCurrentTimeMillis(EARLIEST_SUPPORTED_TIME);
Brad Fitzpatrick35ca9d82010-10-11 11:52:49 -07001073 }
1074
Bob Leee5408332009-09-04 18:31:17 -07001075 if (SamplingProfilerIntegration.isEnabled()) {
1076 SamplingProfilerIntegration.start();
1077 timer = new Timer();
1078 timer.schedule(new TimerTask() {
1079 @Override
1080 public void run() {
Sen Hubde75702010-05-28 01:54:03 -07001081 SamplingProfilerIntegration.writeSnapshot("system_server", null);
Bob Leee5408332009-09-04 18:31:17 -07001082 }
1083 }, SNAPSHOT_INTERVAL, SNAPSHOT_INTERVAL);
1084 }
1085
Dianne Hackbornac1471a2011-02-03 13:46:06 -08001086 // Mmmmmm... more memory!
1087 dalvik.system.VMRuntime.getRuntime().clearGrowthLimit();
1088
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001089 // The system server has to run all of the time, so it needs to be
1090 // as efficient as possible with its memory usage.
1091 VMRuntime.getRuntime().setTargetHeapUtilization(0.8f);
Sen Hubde75702010-05-28 01:54:03 -07001092
Jeff Sharkey48749fc2013-04-19 13:25:04 -07001093 Environment.setUserRequired(true);
1094
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001095 System.loadLibrary("android_servers");
1096 init1(args);
1097 }
1098
1099 public static final void init2() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001100 Slog.i(TAG, "Entered the Android system server!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001101 Thread thr = new ServerThread();
1102 thr.setName("android.server.ServerThread");
1103 thr.start();
1104 }
1105}