blob: 7c5959dbd08a09550efa9cb2366f8e9d7129e9a7 [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,
Dianne Hackborn713df152013-05-17 11:27:57 -0700289 BatteryStatsService.getService(),
290 ActivityManagerService.self().getAppOpsService(), display);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800291
Joe Onorato8a9b2202010-02-26 18:56:32 -0800292 Slog.i(TAG, "Alarm Manager");
Jeff Sharkey75279902011-05-24 18:39:45 -0700293 alarm = new AlarmManagerService(context);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800294 ServiceManager.addService(Context.ALARM_SERVICE, alarm);
295
Joe Onorato8a9b2202010-02-26 18:56:32 -0800296 Slog.i(TAG, "Init Watchdog");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800297 Watchdog.getInstance().init(context, battery, power, alarm,
298 ActivityManagerService.self());
Dianne Hackborn8d044e82013-04-30 17:24:15 -0700299 Watchdog.getInstance().addThread(wmHandler, "WindowManager thread");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800300
Jeff Browna9d131c2012-09-20 16:48:17 -0700301 Slog.i(TAG, "Input Manager");
302 inputManager = new InputManagerService(context, wmHandler);
303
Joe Onorato8a9b2202010-02-26 18:56:32 -0800304 Slog.i(TAG, "Window Manager");
Jeff Browna9d131c2012-09-20 16:48:17 -0700305 wm = WindowManagerService.main(context, power, display, inputManager,
Dianne Hackborn8d044e82013-04-30 17:24:15 -0700306 wmHandler, factoryTest != SystemServer.FACTORY_TEST_LOW_LEVEL,
Jeff Brown780c46f2012-06-24 12:15:38 -0700307 !firstBoot, onlyCore);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800308 ServiceManager.addService(Context.WINDOW_SERVICE, wm);
Jeff Brown6ec6f792012-04-17 16:52:41 -0700309 ServiceManager.addService(Context.INPUT_SERVICE, inputManager);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800310
Dianne Hackborn295e3c22011-08-25 13:19:08 -0700311 ActivityManagerService.self().setWindowManager(wm);
Jeff Browna9d131c2012-09-20 16:48:17 -0700312
313 inputManager.setWindowManagerCallbacks(wm.getInputMonitor());
314 inputManager.start();
315
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700316 display.setWindowManager(wm);
Jeff Brownd728bf52012-09-08 18:05:28 -0700317 display.setInputManager(inputManager);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800318
319 // Skip Bluetooth if we have an emulator kernel
320 // TODO: Use a more reliable check to see if this product should
321 // support Bluetooth - see bug 988521
322 if (SystemProperties.get("ro.kernel.qemu").equals("1")) {
David 'Digit' Turnere2a5e862011-01-17 00:32:33 +0100323 Slog.i(TAG, "No Bluetooh Service (emulator)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800324 } else if (factoryTest == SystemServer.FACTORY_TEST_LOW_LEVEL) {
David 'Digit' Turnere2a5e862011-01-17 00:32:33 +0100325 Slog.i(TAG, "No Bluetooth Service (factory test)");
Matthew Xie1dd01eb32013-04-26 12:37:54 -0700326 } else if (!context.getPackageManager().hasSystemFeature
327 (PackageManager.FEATURE_BLUETOOTH)) {
328 Slog.i(TAG, "No Bluetooth Service (Bluetooth Hardware Not Present)");
Dan Morrille4d9a012013-03-28 18:10:43 -0700329 } else if (disableBluetooth) {
330 Slog.i(TAG, "Bluetooth Service disabled by config");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800331 } else {
fredc0f420372012-04-12 00:02:00 -0700332 Slog.i(TAG, "Bluetooth Manager Service");
333 bluetooth = new BluetoothManagerService(context);
334 ServiceManager.addService(BluetoothAdapter.BLUETOOTH_MANAGER_SERVICE, bluetooth);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800335 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800336 } catch (RuntimeException e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700337 Slog.e("System", "******************************************");
338 Slog.e("System", "************ Failure starting core service", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800339 }
340
Dianne Hackbornd6847842010-01-12 18:14:19 -0800341 DevicePolicyManagerService devicePolicy = null;
Joe Onorato089de882010-04-12 08:18:45 -0700342 StatusBarManagerService statusBar = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800343 InputMethodManagerService imm = null;
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700344 AppWidgetService appWidget = null;
Joe Onorato30275482009-07-08 17:09:14 -0700345 NotificationManagerService notification = null;
Dianne Hackbornf21adf62009-08-13 10:20:21 -0700346 WallpaperManagerService wallpaper = null;
Mike Lockwood46db5042010-02-22 16:36:44 -0500347 LocationManagerService location = null;
Bai Taoa58a8752010-07-13 15:32:16 +0800348 CountryDetectorService countryDetector = null;
satok988323c2011-06-22 16:38:13 +0900349 TextServicesManagerService tsms = null;
Amith Yamasani52c489c2012-03-28 11:42:42 -0700350 LockSettingsService lockSettings = null;
Daniel Sandler7d276c32012-01-30 14:33:52 -0500351 DreamManagerService dreamy = null;
Romain Guy3b748a42013-04-17 18:54:38 -0700352 AssetAtlasService atlas = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800353
Dianne Hackborn661cd522011-08-22 00:26:20 -0700354 // Bring up services needed for UI.
355 if (factoryTest != SystemServer.FACTORY_TEST_LOW_LEVEL) {
Dan Morrille4d9a012013-03-28 18:10:43 -0700356 //if (!disableNonCoreServices) { // TODO: View depends on these; mock them?
357 if (true) {
358 try {
359 Slog.i(TAG, "Input Method Service");
360 imm = new InputMethodManagerService(context, wm);
361 ServiceManager.addService(Context.INPUT_METHOD_SERVICE, imm);
362 } catch (Throwable e) {
363 reportWtf("starting Input Manager Service", e);
364 }
Dianne Hackborn661cd522011-08-22 00:26:20 -0700365
Dan Morrille4d9a012013-03-28 18:10:43 -0700366 try {
367 Slog.i(TAG, "Accessibility Manager");
368 ServiceManager.addService(Context.ACCESSIBILITY_SERVICE,
369 new AccessibilityManagerService(context));
370 } catch (Throwable e) {
371 reportWtf("starting Accessibility Manager", e);
372 }
Dianne Hackborn661cd522011-08-22 00:26:20 -0700373 }
374 }
375
376 try {
377 wm.displayReady();
378 } catch (Throwable e) {
379 reportWtf("making display ready", e);
380 }
Dianne Hackborn8795b602011-08-25 13:30:53 -0700381
Dianne Hackborn295e3c22011-08-25 13:19:08 -0700382 try {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700383 pm.performBootDexOpt();
384 } catch (Throwable e) {
385 reportWtf("performing boot dexopt", e);
386 }
387
388 try {
389 ActivityManagerNative.getDefault().showBootMessage(
390 context.getResources().getText(
391 com.android.internal.R.string.android_upgrading_starting_apps),
392 false);
393 } catch (RemoteException e) {
394 }
395
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800396 if (factoryTest != SystemServer.FACTORY_TEST_LOW_LEVEL) {
Dan Morrille4d9a012013-03-28 18:10:43 -0700397 if (!disableStorage &&
398 !"0".equals(SystemProperties.get("system_init.startmountservice"))) {
Kenny Root51a573c2012-05-17 13:30:28 -0700399 try {
400 /*
401 * NotificationManagerService is dependant on MountService,
402 * (for media / usb notifications) so we must start MountService first.
403 */
404 Slog.i(TAG, "Mount Service");
405 mountService = new MountService(context);
406 ServiceManager.addService("mount", mountService);
407 } catch (Throwable e) {
408 reportWtf("starting Mount Service", e);
409 }
410 }
411
Dan Morrille4d9a012013-03-28 18:10:43 -0700412 if (!disableNonCoreServices) {
413 try {
414 Slog.i(TAG, "LockSettingsService");
415 lockSettings = new LockSettingsService(context);
416 ServiceManager.addService("lock_settings", lockSettings);
417 } catch (Throwable e) {
418 reportWtf("starting LockSettingsService service", e);
419 }
420
421 try {
422 Slog.i(TAG, "Device Policy");
423 devicePolicy = new DevicePolicyManagerService(context);
424 ServiceManager.addService(Context.DEVICE_POLICY_SERVICE, devicePolicy);
425 } catch (Throwable e) {
426 reportWtf("starting DevicePolicyService", e);
427 }
Amith Yamasani52c489c2012-03-28 11:42:42 -0700428 }
429
Dan Morrille4d9a012013-03-28 18:10:43 -0700430 if (!disableSystemUI) {
431 try {
432 Slog.i(TAG, "Status Bar");
433 statusBar = new StatusBarManagerService(context, wm);
434 ServiceManager.addService(Context.STATUS_BAR_SERVICE, statusBar);
435 } catch (Throwable e) {
436 reportWtf("starting StatusBarManagerService", e);
437 }
Dianne Hackbornd6847842010-01-12 18:14:19 -0800438 }
439
Dan Morrille4d9a012013-03-28 18:10:43 -0700440 if (!disableNonCoreServices) {
441 try {
442 Slog.i(TAG, "Clipboard Service");
443 ServiceManager.addService(Context.CLIPBOARD_SERVICE,
444 new ClipboardService(context));
445 } catch (Throwable e) {
446 reportWtf("starting Clipboard Service", e);
447 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800448 }
449
Dan Morrille4d9a012013-03-28 18:10:43 -0700450 if (!disableNetwork) {
451 try {
452 Slog.i(TAG, "NetworkManagement Service");
453 networkManagement = NetworkManagementService.create(context);
454 ServiceManager.addService(Context.NETWORKMANAGEMENT_SERVICE, networkManagement);
455 } catch (Throwable e) {
456 reportWtf("starting NetworkManagement Service", e);
457 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800458 }
459
Dan Morrille4d9a012013-03-28 18:10:43 -0700460 if (!disableNonCoreServices) {
461 try {
462 Slog.i(TAG, "Text Service Manager Service");
463 tsms = new TextServicesManagerService(context);
464 ServiceManager.addService(Context.TEXT_SERVICES_MANAGER_SERVICE, tsms);
465 } catch (Throwable e) {
466 reportWtf("starting Text Service Manager Service", e);
467 }
San Mehatd1df8ac2010-01-26 06:17:26 -0800468 }
469
Dan Morrille4d9a012013-03-28 18:10:43 -0700470 if (!disableNetwork) {
471 try {
472 Slog.i(TAG, "NetworkStats Service");
473 networkStats = new NetworkStatsService(context, networkManagement, alarm);
474 ServiceManager.addService(Context.NETWORK_STATS_SERVICE, networkStats);
475 } catch (Throwable e) {
476 reportWtf("starting NetworkStats Service", e);
477 }
478
479 try {
480 Slog.i(TAG, "NetworkPolicy Service");
481 networkPolicy = new NetworkPolicyManagerService(
482 context, ActivityManagerService.self(), power,
483 networkStats, networkManagement);
484 ServiceManager.addService(Context.NETWORK_POLICY_SERVICE, networkPolicy);
485 } catch (Throwable e) {
486 reportWtf("starting NetworkPolicy Service", e);
487 }
488
489 try {
490 Slog.i(TAG, "Wi-Fi P2pService");
491 wifiP2p = new WifiP2pService(context);
492 ServiceManager.addService(Context.WIFI_P2P_SERVICE, wifiP2p);
493 } catch (Throwable e) {
494 reportWtf("starting Wi-Fi P2pService", e);
495 }
496
497 try {
498 Slog.i(TAG, "Wi-Fi Service");
499 wifi = new WifiService(context);
500 ServiceManager.addService(Context.WIFI_SERVICE, wifi);
501 } catch (Throwable e) {
502 reportWtf("starting Wi-Fi Service", e);
503 }
504
505 try {
506 Slog.i(TAG, "Connectivity Service");
507 connectivity = new ConnectivityService(
508 context, networkManagement, networkStats, networkPolicy);
509 ServiceManager.addService(Context.CONNECTIVITY_SERVICE, connectivity);
510 networkStats.bindConnectivityManager(connectivity);
511 networkPolicy.bindConnectivityManager(connectivity);
512 wifi.checkAndStartWifi();
513 wifiP2p.connectivityServiceReady();
514 } catch (Throwable e) {
515 reportWtf("starting Connectivity Service", e);
516 }
517
518 try {
519 Slog.i(TAG, "Network Service Discovery Service");
520 serviceDiscovery = NsdService.create(context);
521 ServiceManager.addService(
522 Context.NSD_SERVICE, serviceDiscovery);
523 } catch (Throwable e) {
524 reportWtf("starting Service Discovery Service", e);
525 }
satok988323c2011-06-22 16:38:13 +0900526 }
527
Dan Morrille4d9a012013-03-28 18:10:43 -0700528 if (!disableNonCoreServices) {
529 try {
530 Slog.i(TAG, "UpdateLock Service");
531 ServiceManager.addService(Context.UPDATE_LOCK_SERVICE,
532 new UpdateLockService(context));
533 } catch (Throwable e) {
534 reportWtf("starting UpdateLockService", e);
535 }
Christopher Tate8662cab52012-02-23 14:59:36 -0800536 }
537
Kenny Root51a573c2012-05-17 13:30:28 -0700538 /*
539 * MountService has a few dependencies: Notification Manager and
540 * AppWidget Provider. Make sure MountService is completely started
541 * first before continuing.
542 */
543 if (mountService != null) {
544 mountService.waitForAsecScan();
San Mehat1bf3f8b2010-02-03 14:43:09 -0800545 }
546
547 try {
Kenny Root26ff6622012-07-30 12:58:03 -0700548 if (accountManager != null)
549 accountManager.systemReady();
550 } catch (Throwable e) {
551 reportWtf("making Account Manager Service ready", e);
552 }
553
554 try {
555 if (contentService != null)
556 contentService.systemReady();
557 } catch (Throwable e) {
558 reportWtf("making Content Service ready", e);
559 }
560
561 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800562 Slog.i(TAG, "Notification Manager");
Mike Lockwood3a322132009-11-24 00:30:52 -0500563 notification = new NotificationManagerService(context, statusBar, lights);
Joe Onorato30275482009-07-08 17:09:14 -0700564 ServiceManager.addService(Context.NOTIFICATION_SERVICE, notification);
Jeff Sharkey497e4432011-06-14 17:27:29 -0700565 networkPolicy.bindNotificationManager(notification);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800566 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700567 reportWtf("starting Notification Manager", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800568 }
569
570 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800571 Slog.i(TAG, "Device Storage Monitor");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800572 ServiceManager.addService(DeviceStorageMonitorService.SERVICE,
573 new DeviceStorageMonitorService(context));
574 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700575 reportWtf("starting DeviceStorageMonitor service", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800576 }
577
Dan Morrille4d9a012013-03-28 18:10:43 -0700578 if (!disableLocation) {
579 try {
580 Slog.i(TAG, "Location Manager");
581 location = new LocationManagerService(context);
582 ServiceManager.addService(Context.LOCATION_SERVICE, location);
583 } catch (Throwable e) {
584 reportWtf("starting Location Manager", e);
585 }
586
587 try {
588 Slog.i(TAG, "Country Detector");
589 countryDetector = new CountryDetectorService(context);
590 ServiceManager.addService(Context.COUNTRY_DETECTOR, countryDetector);
591 } catch (Throwable e) {
592 reportWtf("starting Country Detector", e);
593 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800594 }
595
Dan Morrille4d9a012013-03-28 18:10:43 -0700596 if (!disableNonCoreServices) {
597 try {
598 Slog.i(TAG, "Search Service");
599 ServiceManager.addService(Context.SEARCH_SERVICE,
600 new SearchManagerService(context));
601 } catch (Throwable e) {
602 reportWtf("starting Search Service", e);
603 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800604 }
605
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800606 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800607 Slog.i(TAG, "DropBox Service");
Dan Egnor95240272009-10-27 18:23:39 -0700608 ServiceManager.addService(Context.DROPBOX_SERVICE,
Dan Egnorf18a01c2009-11-12 11:32:50 -0800609 new DropBoxManagerService(context, new File("/data/system/dropbox")));
Dan Egnor4410ec82009-09-11 16:40:01 -0700610 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700611 reportWtf("starting DropBoxManagerService", e);
Dan Egnor4410ec82009-09-11 16:40:01 -0700612 }
613
Dan Morrille4d9a012013-03-28 18:10:43 -0700614 if (!disableNonCoreServices && context.getResources().getBoolean(
615 R.bool.config_enableWallpaperService)) {
Mike Lockwoodc067c9c2011-10-31 12:50:12 -0400616 try {
617 Slog.i(TAG, "Wallpaper Service");
618 if (!headless) {
619 wallpaper = new WallpaperManagerService(context);
620 ServiceManager.addService(Context.WALLPAPER_SERVICE, wallpaper);
621 }
622 } catch (Throwable e) {
623 reportWtf("starting Wallpaper Service", e);
Mike Lockwood3a74bd32011-08-12 13:55:22 -0700624 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800625 }
626
Dan Morrille4d9a012013-03-28 18:10:43 -0700627 if (!disableMedia && !"0".equals(SystemProperties.get("system_init.startaudioservice"))) {
Mike Lockwoodcba928c2011-08-17 15:58:52 -0700628 try {
629 Slog.i(TAG, "Audio Service");
630 ServiceManager.addService(Context.AUDIO_SERVICE, new AudioService(context));
631 } catch (Throwable e) {
632 reportWtf("starting Audio Service", e);
633 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800634 }
635
Dan Morrille4d9a012013-03-28 18:10:43 -0700636 if (!disableNonCoreServices) {
637 try {
638 Slog.i(TAG, "Dock Observer");
639 // Listen for dock station changes
640 dock = new DockObserver(context);
641 } catch (Throwable e) {
642 reportWtf("starting DockObserver", e);
643 }
Dan Murphyc9f4eaf2009-08-12 15:15:43 -0500644 }
645
Dan Morrille4d9a012013-03-28 18:10:43 -0700646 if (!disableMedia) {
647 try {
648 Slog.i(TAG, "Wired Accessory Manager");
649 // Listen for wired headset changes
650 inputManager.setWiredAccessoryCallbacks(
651 new WiredAccessoryManager(context, inputManager));
652 } catch (Throwable e) {
653 reportWtf("starting WiredAccessoryManager", e);
654 }
Praveen Bharathi21e941b2010-10-06 15:23:14 -0500655 }
656
Dan Morrille4d9a012013-03-28 18:10:43 -0700657 if (!disableNonCoreServices) {
658 try {
659 Slog.i(TAG, "USB Service");
660 // Manage USB host and device support
661 usb = new UsbService(context);
662 ServiceManager.addService(Context.USB_SERVICE, usb);
663 } catch (Throwable e) {
664 reportWtf("starting UsbService", e);
665 }
Mike Lockwood57c798a2010-06-23 17:36:36 -0400666
Dan Morrille4d9a012013-03-28 18:10:43 -0700667 try {
668 Slog.i(TAG, "Serial Service");
669 // Serial port support
670 serial = new SerialService(context);
671 ServiceManager.addService(Context.SERIAL_SERVICE, serial);
672 } catch (Throwable e) {
673 Slog.e(TAG, "Failure starting SerialService", e);
674 }
Mike Lockwoodb01e8bf2011-08-29 20:11:07 -0400675 }
676
677 try {
Jeff Brown2416e092012-08-21 22:12:20 -0700678 Slog.i(TAG, "Twilight Service");
679 twilight = new TwilightService(context);
680 } catch (Throwable e) {
681 reportWtf("starting TwilightService", e);
682 }
683
684 try {
Dianne Hackborn7299c412010-03-04 18:41:49 -0800685 Slog.i(TAG, "UI Mode Manager Service");
Mike Lockwood57c798a2010-06-23 17:36:36 -0400686 // Listen for UI mode changes
Jeff Brown2416e092012-08-21 22:12:20 -0700687 uiMode = new UiModeManagerService(context, twilight);
Dianne Hackborn7299c412010-03-04 18:41:49 -0800688 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700689 reportWtf("starting UiModeManagerService", e);
Dianne Hackborn7299c412010-03-04 18:41:49 -0800690 }
691
Dan Morrille4d9a012013-03-28 18:10:43 -0700692 if (!disableNonCoreServices) {
693 try {
694 Slog.i(TAG, "Backup Service");
695 ServiceManager.addService(Context.BACKUP_SERVICE,
696 new BackupManagerService(context));
697 } catch (Throwable e) {
698 Slog.e(TAG, "Failure starting Backup Service", e);
699 }
Christopher Tate487529a2009-04-29 14:03:25 -0700700
Dan Morrille4d9a012013-03-28 18:10:43 -0700701 try {
702 Slog.i(TAG, "AppWidget Service");
703 appWidget = new AppWidgetService(context);
704 ServiceManager.addService(Context.APPWIDGET_SERVICE, appWidget);
705 } catch (Throwable e) {
706 reportWtf("starting AppWidget Service", e);
707 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800708
Dan Morrille4d9a012013-03-28 18:10:43 -0700709 try {
710 Slog.i(TAG, "Recognition Service");
711 recognition = new RecognitionManagerService(context);
712 } catch (Throwable e) {
713 reportWtf("starting Recognition Service", e);
714 }
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800715 }
Jaikumar Ganesh7d0548d2010-10-18 15:29:09 -0700716
Nick Pelly038cabe2010-09-23 16:12:11 -0700717 try {
Dan Egnor621bc542010-03-25 16:20:14 -0700718 Slog.i(TAG, "DiskStats Service");
719 ServiceManager.addService("diskstats", new DiskStatsService(context));
720 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700721 reportWtf("starting DiskStats Service", e);
Dan Egnor621bc542010-03-25 16:20:14 -0700722 }
Sen Hubde75702010-05-28 01:54:03 -0700723
724 try {
725 // need to add this service even if SamplingProfilerIntegration.isEnabled()
726 // is false, because it is this service that detects system property change and
727 // turns on SamplingProfilerIntegration. Plus, when sampling profiler doesn't work,
728 // there is little overhead for running this service.
729 Slog.i(TAG, "SamplingProfiler Service");
730 ServiceManager.addService("samplingprofiler",
731 new SamplingProfilerService(context));
732 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700733 reportWtf("starting SamplingProfiler Service", e);
Sen Hubde75702010-05-28 01:54:03 -0700734 }
Chung-yih Wang024d5962010-08-06 12:06:04 +0800735
Dan Morrille4d9a012013-03-28 18:10:43 -0700736 if (!disableNetwork) {
737 try {
738 Slog.i(TAG, "NetworkTimeUpdateService");
739 networkTimeUpdater = new NetworkTimeUpdateService(context);
740 } catch (Throwable e) {
741 reportWtf("starting NetworkTimeUpdate service", e);
742 }
Amith Yamasani6734b9f62010-09-13 16:24:08 -0700743 }
John Grossmanc1576732012-02-01 15:23:33 -0800744
Dan Morrille4d9a012013-03-28 18:10:43 -0700745 if (!disableMedia) {
746 try {
747 Slog.i(TAG, "CommonTimeManagementService");
748 commonTimeMgmtService = new CommonTimeManagementService(context);
749 ServiceManager.addService("commontime_management", commonTimeMgmtService);
750 } catch (Throwable e) {
751 reportWtf("starting CommonTimeManagementService service", e);
752 }
John Grossmanc1576732012-02-01 15:23:33 -0800753 }
Geremy Condra3d33c262012-05-06 18:32:19 -0700754
Dan Morrille4d9a012013-03-28 18:10:43 -0700755 if (!disableNetwork) {
756 try {
757 Slog.i(TAG, "CertBlacklister");
758 CertBlacklister blacklister = new CertBlacklister(context);
759 } catch (Throwable e) {
760 reportWtf("starting CertBlacklister", e);
761 }
Geremy Condra3d33c262012-05-06 18:32:19 -0700762 }
Jim Miller5ecd8112013-01-09 18:50:26 -0800763
Dan Morrille4d9a012013-03-28 18:10:43 -0700764 if (!disableNonCoreServices &&
765 context.getResources().getBoolean(R.bool.config_dreamsSupported)) {
Daniel Sandler7d276c32012-01-30 14:33:52 -0500766 try {
767 Slog.i(TAG, "Dreams Service");
768 // Dreams (interactive idle-time views, a/k/a screen savers)
Jeff Brown62c82e42012-09-26 01:30:41 -0700769 dreamy = new DreamManagerService(context, wmHandler);
Dianne Hackbornbe87e2f2012-09-28 16:31:34 -0700770 ServiceManager.addService(DreamService.DREAM_SERVICE, dreamy);
Daniel Sandler7d276c32012-01-30 14:33:52 -0500771 } catch (Throwable e) {
772 reportWtf("starting DreamManagerService", e);
773 }
774 }
Svetoslavb3038ec2013-02-13 14:39:30 -0800775
Romain Guy3b748a42013-04-17 18:54:38 -0700776 if (!disableNonCoreServices) {
777 try {
778 Slog.i(TAG, "Assets Atlas Service");
779 atlas = new AssetAtlasService(context);
780 ServiceManager.addService(AssetAtlasService.ASSET_ATLAS_SERVICE, atlas);
781 } catch (Throwable e) {
782 reportWtf("starting AssetAtlasService", e);
783 }
784 }
785
Svetoslavb3038ec2013-02-13 14:39:30 -0800786 try {
787 Slog.i(TAG, "IdleMaintenanceService");
Svetoslav6a08a122013-05-03 11:24:26 -0700788 new IdleMaintenanceService(context, battery);
Svetoslavb3038ec2013-02-13 14:39:30 -0800789 } catch (Throwable e) {
790 reportWtf("starting IdleMaintenanceService", e);
791 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800792 }
793
Dianne Hackborn6af0d502009-09-28 13:25:46 -0700794 // Before things start rolling, be sure we have decided whether
795 // we are in safe mode.
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700796 final boolean safeMode = wm.detectSafeMode();
Dianne Hackborn6af0d502009-09-28 13:25:46 -0700797 if (safeMode) {
Jeff Brownb09abc12011-01-13 21:08:27 -0800798 ActivityManagerService.self().enterSafeMode();
799 // Post the safe mode state in the Zygote class
800 Zygote.systemInSafeMode = true;
801 // Disable the JIT for the system_server process
802 VMRuntime.getRuntime().disableJitCompilation();
Ben Cheng6c0afff2010-02-14 16:18:56 -0800803 } else {
804 // Enable the JIT for the system_server process
805 VMRuntime.getRuntime().startJitCompilation();
Dianne Hackborn6af0d502009-09-28 13:25:46 -0700806 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800807
Dianne Hackborn6af0d502009-09-28 13:25:46 -0700808 // It is now time to start up the app processes...
Joe Onorato30275482009-07-08 17:09:14 -0700809
Jeff Brown7f6c2312012-04-13 20:38:38 -0700810 try {
811 vibrator.systemReady();
812 } catch (Throwable e) {
813 reportWtf("making Vibrator Service ready", e);
814 }
815
Dan Morrille4d9a012013-03-28 18:10:43 -0700816 if (lockSettings != null) {
817 try {
818 lockSettings.systemReady();
819 } catch (Throwable e) {
820 reportWtf("making Lock Settings Service ready", e);
821 }
Felipe Ramosf35df5b2012-09-18 18:26:27 -0300822 }
823
Dianne Hackbornd6847842010-01-12 18:14:19 -0800824 if (devicePolicy != null) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700825 try {
826 devicePolicy.systemReady();
827 } catch (Throwable e) {
828 reportWtf("making Device Policy Service ready", e);
829 }
Dianne Hackbornd6847842010-01-12 18:14:19 -0800830 }
831
Joe Onorato30275482009-07-08 17:09:14 -0700832 if (notification != null) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700833 try {
834 notification.systemReady();
835 } catch (Throwable e) {
836 reportWtf("making Notification Service ready", e);
837 }
Joe Onorato30275482009-07-08 17:09:14 -0700838 }
839
Dianne Hackborn661cd522011-08-22 00:26:20 -0700840 try {
841 wm.systemReady();
842 } catch (Throwable e) {
843 reportWtf("making Window Manager Service ready", e);
844 }
Joe Onoratodc565f42010-10-04 15:27:22 -0400845
Jeff Brownb09abc12011-01-13 21:08:27 -0800846 if (safeMode) {
847 ActivityManagerService.self().showSafeModeOverlay();
848 }
849
Joe Onoratodc565f42010-10-04 15:27:22 -0400850 // Update the configuration for this context by hand, because we're going
851 // to start using it before the config change done in wm.systemReady() will
852 // propagate to it.
853 Configuration config = wm.computeNewConfiguration();
854 DisplayMetrics metrics = new DisplayMetrics();
855 WindowManager w = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
856 w.getDefaultDisplay().getMetrics(metrics);
857 context.getResources().updateConfiguration(config, metrics);
858
Jeff Brownaa202a62012-08-21 22:14:26 -0700859 try {
Jeff Brown62c82e42012-09-26 01:30:41 -0700860 power.systemReady(twilight, dreamy);
Jeff Brownaa202a62012-08-21 22:14:26 -0700861 } catch (Throwable e) {
862 reportWtf("making Power Manager Service ready", e);
863 }
864
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800865 try {
866 pm.systemReady();
Dianne Hackborn661cd522011-08-22 00:26:20 -0700867 } catch (Throwable e) {
868 reportWtf("making Package Manager Service ready", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800869 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800870
Jeff Brownbd6e1502012-08-28 03:27:37 -0700871 try {
872 display.systemReady(safeMode, onlyCore);
873 } catch (Throwable e) {
874 reportWtf("making Display Manager Service ready", e);
875 }
876
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700877 // These are needed to propagate to the runnable below.
Joe Onoratof3c3c4f2010-10-21 11:09:02 -0400878 final Context contextF = context;
Jeff Sharkeyb049e2122012-09-07 23:16:01 -0700879 final MountService mountServiceF = mountService;
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700880 final BatteryService batteryF = battery;
Jeff Sharkey350083e2011-06-29 10:45:16 -0700881 final NetworkManagementService networkManagementF = networkManagement;
Jeff Sharkey75279902011-05-24 18:39:45 -0700882 final NetworkStatsService networkStatsF = networkStats;
Jeff Sharkeya4620792011-05-20 15:29:23 -0700883 final NetworkPolicyManagerService networkPolicyF = networkPolicy;
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700884 final ConnectivityService connectivityF = connectivity;
885 final DockObserver dockF = dock;
Mike Lockwood770126a2010-12-09 22:30:37 -0800886 final UsbService usbF = usb;
Jeff Brown2416e092012-08-21 22:12:20 -0700887 final TwilightService twilightF = twilight;
Dianne Hackborn7299c412010-03-04 18:41:49 -0800888 final UiModeManagerService uiModeF = uiMode;
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700889 final AppWidgetService appWidgetF = appWidget;
890 final WallpaperManagerService wallpaperF = wallpaper;
891 final InputMethodManagerService immF = imm;
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800892 final RecognitionManagerService recognitionF = recognition;
Mike Lockwood46db5042010-02-22 16:36:44 -0500893 final LocationManagerService locationF = location;
Bai Taoa58a8752010-07-13 15:32:16 +0800894 final CountryDetectorService countryDetectorF = countryDetector;
Amith Yamasani6734b9f62010-09-13 16:24:08 -0700895 final NetworkTimeUpdateService networkTimeUpdaterF = networkTimeUpdater;
John Grossmanc1576732012-02-01 15:23:33 -0800896 final CommonTimeManagementService commonTimeMgmtServiceF = commonTimeMgmtService;
satok988323c2011-06-22 16:38:13 +0900897 final TextServicesManagerService textServiceManagerServiceF = tsms;
Dianne Hackborn661cd522011-08-22 00:26:20 -0700898 final StatusBarManagerService statusBarF = statusBar;
Daniel Sandler7d276c32012-01-30 14:33:52 -0500899 final DreamManagerService dreamyF = dreamy;
Romain Guy3b748a42013-04-17 18:54:38 -0700900 final AssetAtlasService atlasF = atlas;
Jeff Brown6ec6f792012-04-17 16:52:41 -0700901 final InputManagerService inputManagerF = inputManager;
Wink Savillea12a7b32012-09-20 10:09:45 -0700902 final TelephonyRegistry telephonyRegistryF = telephonyRegistry;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800903
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700904 // We now tell the activity manager it is okay to run third party
905 // code. It will call back into us once it has gotten to the state
906 // where third party code can really run (but before it has actually
907 // started launching the initial applications), for us to complete our
908 // initialization.
Dianne Hackborn295e3c22011-08-25 13:19:08 -0700909 ActivityManagerService.self().systemReady(new Runnable() {
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700910 public void run() {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800911 Slog.i(TAG, "Making services ready");
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800912
Christopher Tate58d380d2013-03-19 13:10:03 -0700913 try {
914 ActivityManagerService.self().startObservingNativeCrashes();
915 } catch (Throwable e) {
916 reportWtf("observing native crashes", e);
917 }
Jim Miller5ecd8112013-01-09 18:50:26 -0800918 if (!headless) {
919 startSystemUi(contextF);
920 }
Dianne Hackborn661cd522011-08-22 00:26:20 -0700921 try {
Jeff Sharkeyb049e2122012-09-07 23:16:01 -0700922 if (mountServiceF != null) mountServiceF.systemReady();
923 } catch (Throwable e) {
924 reportWtf("making Mount Service ready", e);
925 }
926 try {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700927 if (batteryF != null) batteryF.systemReady();
928 } catch (Throwable e) {
929 reportWtf("making Battery Service ready", e);
930 }
931 try {
932 if (networkManagementF != null) networkManagementF.systemReady();
933 } catch (Throwable e) {
934 reportWtf("making Network Managment Service ready", e);
935 }
936 try {
937 if (networkStatsF != null) networkStatsF.systemReady();
938 } catch (Throwable e) {
939 reportWtf("making Network Stats Service ready", e);
940 }
941 try {
942 if (networkPolicyF != null) networkPolicyF.systemReady();
943 } catch (Throwable e) {
944 reportWtf("making Network Policy Service ready", e);
945 }
946 try {
947 if (connectivityF != null) connectivityF.systemReady();
948 } catch (Throwable e) {
949 reportWtf("making Connectivity Service ready", e);
950 }
951 try {
952 if (dockF != null) dockF.systemReady();
953 } catch (Throwable e) {
954 reportWtf("making Dock Service ready", e);
955 }
956 try {
957 if (usbF != null) usbF.systemReady();
958 } catch (Throwable e) {
959 reportWtf("making USB Service ready", e);
960 }
961 try {
Jeff Brown2416e092012-08-21 22:12:20 -0700962 if (twilightF != null) twilightF.systemReady();
963 } catch (Throwable e) {
964 reportWtf("makin Twilight Service ready", e);
965 }
966 try {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700967 if (uiModeF != null) uiModeF.systemReady();
968 } catch (Throwable e) {
969 reportWtf("making UI Mode Service ready", e);
970 }
971 try {
972 if (recognitionF != null) recognitionF.systemReady();
973 } catch (Throwable e) {
974 reportWtf("making Recognition Service ready", e);
975 }
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700976 Watchdog.getInstance().start();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800977
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700978 // It is now okay to let the various system services start their
979 // third party code...
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800980
Dianne Hackborn661cd522011-08-22 00:26:20 -0700981 try {
982 if (appWidgetF != null) appWidgetF.systemReady(safeMode);
983 } catch (Throwable e) {
984 reportWtf("making App Widget Service ready", e);
985 }
986 try {
987 if (wallpaperF != null) wallpaperF.systemReady();
988 } catch (Throwable e) {
989 reportWtf("making Wallpaper Service ready", e);
990 }
991 try {
992 if (immF != null) immF.systemReady(statusBarF);
993 } catch (Throwable e) {
994 reportWtf("making Input Method Service ready", e);
995 }
996 try {
997 if (locationF != null) locationF.systemReady();
998 } catch (Throwable e) {
999 reportWtf("making Location Service ready", e);
1000 }
1001 try {
1002 if (countryDetectorF != null) countryDetectorF.systemReady();
1003 } catch (Throwable e) {
1004 reportWtf("making Country Detector Service ready", e);
1005 }
1006 try {
Dianne Hackborn661cd522011-08-22 00:26:20 -07001007 if (networkTimeUpdaterF != null) networkTimeUpdaterF.systemReady();
1008 } catch (Throwable e) {
1009 reportWtf("making Network Time Service ready", e);
1010 }
1011 try {
John Grossmanc1576732012-02-01 15:23:33 -08001012 if (commonTimeMgmtServiceF != null) commonTimeMgmtServiceF.systemReady();
1013 } catch (Throwable e) {
1014 reportWtf("making Common time management service ready", e);
1015 }
1016 try {
Dianne Hackborn661cd522011-08-22 00:26:20 -07001017 if (textServiceManagerServiceF != null) textServiceManagerServiceF.systemReady();
1018 } catch (Throwable e) {
1019 reportWtf("making Text Services Manager Service ready", e);
1020 }
Daniel Sandler7d276c32012-01-30 14:33:52 -05001021 try {
1022 if (dreamyF != null) dreamyF.systemReady();
1023 } catch (Throwable e) {
1024 reportWtf("making DreamManagerService ready", e);
1025 }
Jeff Brown6ec6f792012-04-17 16:52:41 -07001026 try {
Romain Guy3b748a42013-04-17 18:54:38 -07001027 if (atlasF != null) atlasF.systemReady();
1028 } catch (Throwable e) {
1029 reportWtf("making AssetAtlasService ready", e);
1030 }
1031 try {
Matthew Xie96313142012-06-29 16:57:31 -07001032 // TODO(BT) Pass parameter to input manager
1033 if (inputManagerF != null) inputManagerF.systemReady();
Jeff Brown6ec6f792012-04-17 16:52:41 -07001034 } catch (Throwable e) {
1035 reportWtf("making InputManagerService ready", e);
1036 }
Dan Morrille4d9a012013-03-28 18:10:43 -07001037
Wink Savillea12a7b32012-09-20 10:09:45 -07001038 try {
1039 if (telephonyRegistryF != null) telephonyRegistryF.systemReady();
1040 } catch (Throwable e) {
1041 reportWtf("making TelephonyRegistry ready", e);
1042 }
Dianne Hackborna34f1ad2009-09-02 13:26:28 -07001043 }
1044 });
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001045
Brad Fitzpatrick1e02d362010-09-10 09:19:50 -07001046 // For debug builds, log event loop stalls to dropbox for analysis.
Brad Fitzpatrick50d66f92010-09-13 21:29:05 -07001047 if (StrictMode.conditionallyEnableDebugLogging()) {
1048 Slog.i(TAG, "Enabled StrictMode for system server main thread.");
Brad Fitzpatrick1e02d362010-09-10 09:19:50 -07001049 }
1050
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001051 Looper.loop();
Joe Onorato8a9b2202010-02-26 18:56:32 -08001052 Slog.d(TAG, "System ServerThread is exiting!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001053 }
Joe Onoratof3c3c4f2010-10-21 11:09:02 -04001054
1055 static final void startSystemUi(Context context) {
1056 Intent intent = new Intent();
1057 intent.setComponent(new ComponentName("com.android.systemui",
1058 "com.android.systemui.SystemUIService"));
Dianne Hackborn40e9f292012-11-27 19:12:23 -08001059 //Slog.d(TAG, "Starting service: " + intent);
Amith Yamasanicd757062012-10-19 18:23:52 -07001060 context.startServiceAsUser(intent, UserHandle.OWNER);
Joe Onoratof3c3c4f2010-10-21 11:09:02 -04001061 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001062}
1063
Jeff Hamilton35eef702010-06-09 15:45:18 -05001064public class SystemServer {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001065 private static final String TAG = "SystemServer";
1066
1067 public static final int FACTORY_TEST_OFF = 0;
1068 public static final int FACTORY_TEST_LOW_LEVEL = 1;
1069 public static final int FACTORY_TEST_HIGH_LEVEL = 2;
Jaikumar Ganeshd5ac1ae2009-05-05 22:26:12 -07001070
Bob Leee5408332009-09-04 18:31:17 -07001071 static Timer timer;
1072 static final long SNAPSHOT_INTERVAL = 60 * 60 * 1000; // 1hr
1073
Brad Fitzpatrick6bb7a4a2010-10-11 13:41:10 -07001074 // The earliest supported time. We pick one day into 1970, to
1075 // give any timezone code room without going into negative time.
1076 private static final long EARLIEST_SUPPORTED_TIME = 86400 * 1000;
1077
Jaikumar Ganeshd5ac1ae2009-05-05 22:26:12 -07001078 /**
1079 * 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 -08001080 * services (SurfaceFlinger, AudioFlinger, etc..) to be started. After that it will call back
1081 * up into init2() to start the Android services.
Jaikumar Ganeshd5ac1ae2009-05-05 22:26:12 -07001082 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001083 native public static void init1(String[] args);
1084
1085 public static void main(String[] args) {
Brad Fitzpatrick6bb7a4a2010-10-11 13:41:10 -07001086 if (System.currentTimeMillis() < EARLIEST_SUPPORTED_TIME) {
Brad Fitzpatrick35ca9d82010-10-11 11:52:49 -07001087 // If a device's clock is before 1970 (before 0), a lot of
1088 // APIs crash dealing with negative numbers, notably
1089 // java.io.File#setLastModified, so instead we fake it and
1090 // hope that time from cell towers or NTP fixes it
1091 // shortly.
1092 Slog.w(TAG, "System clock is before 1970; setting to 1970.");
Brad Fitzpatrick6bb7a4a2010-10-11 13:41:10 -07001093 SystemClock.setCurrentTimeMillis(EARLIEST_SUPPORTED_TIME);
Brad Fitzpatrick35ca9d82010-10-11 11:52:49 -07001094 }
1095
Bob Leee5408332009-09-04 18:31:17 -07001096 if (SamplingProfilerIntegration.isEnabled()) {
1097 SamplingProfilerIntegration.start();
1098 timer = new Timer();
1099 timer.schedule(new TimerTask() {
1100 @Override
1101 public void run() {
Sen Hubde75702010-05-28 01:54:03 -07001102 SamplingProfilerIntegration.writeSnapshot("system_server", null);
Bob Leee5408332009-09-04 18:31:17 -07001103 }
1104 }, SNAPSHOT_INTERVAL, SNAPSHOT_INTERVAL);
1105 }
1106
Dianne Hackbornac1471a2011-02-03 13:46:06 -08001107 // Mmmmmm... more memory!
1108 dalvik.system.VMRuntime.getRuntime().clearGrowthLimit();
1109
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001110 // The system server has to run all of the time, so it needs to be
1111 // as efficient as possible with its memory usage.
1112 VMRuntime.getRuntime().setTargetHeapUtilization(0.8f);
Sen Hubde75702010-05-28 01:54:03 -07001113
Jeff Sharkey48749fc2013-04-19 13:25:04 -07001114 Environment.setUserRequired(true);
1115
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001116 System.loadLibrary("android_servers");
1117 init1(args);
1118 }
1119
1120 public static final void init2() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001121 Slog.i(TAG, "Entered the Android system server!");
Dianne Hackbornefa92b22013-05-03 14:11:43 -07001122
1123 // This used to be its own separate thread, but now it is
1124 // just the loop we run on the main thread.
1125 ServerThread thr = new ServerThread();
1126 thr.initAndLoop();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001127 }
1128}