blob: def65a85eaeaca8e0e6eb87420764f95ed31fb35 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.server;
18
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080019import android.app.ActivityManagerNative;
Nick Pellyf242b7b2009-10-08 00:12:45 +020020import android.bluetooth.BluetoothAdapter;
Joe Onoratof3c3c4f2010-10-21 11:09:02 -040021import android.content.ComponentName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080022import android.content.ContentResolver;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080023import android.content.Context;
Joe Onoratof3c3c4f2010-10-21 11:09:02 -040024import android.content.Intent;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080025import android.content.pm.IPackageManager;
Joe Onoratodc565f42010-10-04 15:27:22 -040026import android.content.res.Configuration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080027import android.media.AudioService;
Irfan Sherifff6d09842011-08-03 15:37:08 -070028import android.net.wifi.p2p.WifiP2pService;
Jeff Brownbd6e1502012-08-28 03:27:37 -070029import android.os.Handler;
30import android.os.HandlerThread;
Jeff Hamilton35eef702010-06-09 15:45:18 -050031import android.os.Looper;
32import android.os.RemoteException;
33import android.os.ServiceManager;
Brad Fitzpatrickc74a1b442010-09-10 16:03:29 -070034import android.os.StrictMode;
Jeff Hamilton35eef702010-06-09 15:45:18 -050035import android.os.SystemClock;
36import android.os.SystemProperties;
Amith Yamasanicd757062012-10-19 18:23:52 -070037import android.os.UserHandle;
Dianne Hackbornbe87e2f2012-09-28 16:31:34 -070038import android.service.dreams.DreamService;
Joe Onoratodc565f42010-10-04 15:27:22 -040039import android.util.DisplayMetrics;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080040import android.util.EventLog;
Dianne Hackborn661cd522011-08-22 00:26:20 -070041import android.util.Log;
Joe Onorato8a9b2202010-02-26 18:56:32 -080042import android.util.Slog;
Brad Fitzpatrick5fdc0c72010-10-12 13:12:18 -070043import android.view.WindowManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080044
Dan Morrille4d9a012013-03-28 18:10:43 -070045import com.android.internal.R;
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -070046import com.android.internal.os.BinderInternal;
47import com.android.internal.os.SamplingProfilerIntegration;
48import com.android.server.accessibility.AccessibilityManagerService;
Jeff Sharkey7a96c392012-11-15 14:01:46 -080049import com.android.server.accounts.AccountManagerService;
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -070050import com.android.server.am.ActivityManagerService;
Jeff Brown96307042012-07-27 15:51:34 -070051import com.android.server.am.BatteryStatsService;
Jeff Sharkey7a96c392012-11-15 14:01:46 -080052import com.android.server.content.ContentService;
Jeff Brownfa25bf52012-07-23 19:26:30 -070053import com.android.server.display.DisplayManagerService;
Jeff Browncef440f2012-09-25 18:58:48 -070054import com.android.server.dreams.DreamManagerService;
Jeff Brown6ec6f792012-04-17 16:52:41 -070055import com.android.server.input.InputManagerService;
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -070056import com.android.server.net.NetworkPolicyManagerService;
Jeff Sharkey75279902011-05-24 18:39:45 -070057import com.android.server.net.NetworkStatsService;
Jeff Sharkey7a96c392012-11-15 14:01:46 -080058import com.android.server.os.SchedulingPolicyService;
Jeff Brownf69c8122012-09-12 17:00:34 -070059import com.android.server.pm.Installer;
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -070060import com.android.server.pm.PackageManagerService;
Amith Yamasani258848d2012-08-10 17:06:33 -070061import com.android.server.pm.UserManagerService;
Jeff Brown4f8ecd82012-06-18 18:29:13 -070062import com.android.server.power.PowerManagerService;
63import com.android.server.power.ShutdownThread;
Jeff Sharkey7a96c392012-11-15 14:01:46 -080064import com.android.server.search.SearchManagerService;
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -070065import com.android.server.usb.UsbService;
Irfan Sheriffd017f352013-02-20 13:30:44 -080066import com.android.server.wifi.WifiService;
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -070067import com.android.server.wm.WindowManagerService;
68
69import dalvik.system.VMRuntime;
70import dalvik.system.Zygote;
71
Dan Egnor4410ec82009-09-11 16:40:01 -070072import java.io.File;
Bob Leee5408332009-09-04 18:31:17 -070073import java.util.Timer;
74import java.util.TimerTask;
75
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080076class ServerThread extends Thread {
77 private static final String TAG = "SystemServer";
Ben Komalo553acf02011-09-19 14:25:28 -070078 private static final String ENCRYPTING_STATE = "trigger_restart_min_framework";
Ben Komalo3573d402011-09-23 15:08:24 -070079 private static final String ENCRYPTED_STATE = "1";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080080
Jeff Hamilton35eef702010-06-09 15:45:18 -050081 ContentResolver mContentResolver;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080082
Dianne Hackborn661cd522011-08-22 00:26:20 -070083 void reportWtf(String msg, Throwable e) {
84 Slog.w(TAG, "***********************************************");
85 Log.wtf(TAG, "BOOT FAILURE " + msg, e);
86 }
87
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080088 @Override
89 public void run() {
Doug Zongkerab5c49c2009-12-04 10:31:43 -080090 EventLog.writeEvent(EventLogTags.BOOT_PROGRESS_SYSTEM_RUN,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080091 SystemClock.uptimeMillis());
92
Vairavan Srinivasan04b74ec2012-02-02 22:12:19 -080093 Looper.prepareMainLooper();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080094
95 android.os.Process.setThreadPriority(
96 android.os.Process.THREAD_PRIORITY_FOREGROUND);
97
Dianne Hackborn887f3552009-12-07 17:59:37 -080098 BinderInternal.disableBackgroundScheduling(true);
Christopher Tate160edb32010-06-30 17:46:30 -070099 android.os.Process.setCanSelfBackground(false);
Sen Hubde75702010-05-28 01:54:03 -0700100
Kenny Rootf547d672010-09-22 10:36:48 -0700101 // Check whether we failed to shut down last time we tried.
102 {
103 final String shutdownAction = SystemProperties.get(
104 ShutdownThread.SHUTDOWN_ACTION_PROPERTY, "");
105 if (shutdownAction != null && shutdownAction.length() > 0) {
106 boolean reboot = (shutdownAction.charAt(0) == '1');
107
108 final String reason;
109 if (shutdownAction.length() > 1) {
110 reason = shutdownAction.substring(1, shutdownAction.length());
111 } else {
112 reason = null;
113 }
114
115 ShutdownThread.rebootOrShutdown(reboot, reason);
116 }
117 }
118
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800119 String factoryTestStr = SystemProperties.get("ro.factorytest");
120 int factoryTest = "".equals(factoryTestStr) ? SystemServer.FACTORY_TEST_OFF
121 : Integer.parseInt(factoryTestStr);
Mike Lockwood3a74bd32011-08-12 13:55:22 -0700122 final boolean headless = "1".equals(SystemProperties.get("ro.config.headless", "0"));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800123
Jeff Brownf69c8122012-09-12 17:00:34 -0700124 Installer installer = null;
Kenny Root26ff6622012-07-30 12:58:03 -0700125 AccountManagerService accountManager = null;
126 ContentService contentService = null;
Mike Lockwood3a322132009-11-24 00:30:52 -0500127 LightsService lights = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800128 PowerManagerService power = null;
Jeff Brownfa25bf52012-07-23 19:26:30 -0700129 DisplayManagerService display = null;
Mike Lockwood07a500f2009-08-12 09:56:44 -0400130 BatteryService battery = null;
Jeff Brown7f6c2312012-04-13 20:38:38 -0700131 VibratorService vibrator = null;
Jeff Sharkey75279902011-05-24 18:39:45 -0700132 AlarmManagerService alarm = null;
Jeff Sharkeyb049e212012-09-07 23:16:01 -0700133 MountService mountService = null;
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -0700134 NetworkManagementService networkManagement = null;
Jeff Sharkey75279902011-05-24 18:39:45 -0700135 NetworkStatsService networkStats = null;
Jeff Sharkeya4620792011-05-20 15:29:23 -0700136 NetworkPolicyManagerService networkPolicy = null;
Mike Lockwood0f79b542009-08-14 14:18:49 -0400137 ConnectivityService connectivity = null;
repo sync55bc5f32011-06-24 14:23:07 -0700138 WifiP2pService wifiP2p = null;
repo syncaea743a2011-07-29 23:55:49 -0700139 WifiService wifi = null;
Irfan Sheriff7d024d32012-03-22 17:01:39 -0700140 NsdService serviceDiscovery= null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800141 IPackageManager pm = null;
142 Context context = null;
143 WindowManagerService wm = null;
fredc0f420372012-04-12 00:02:00 -0700144 BluetoothManagerService bluetooth = null;
Dan Murphyc9f4eaf2009-08-12 15:15:43 -0500145 DockObserver dock = null;
Mike Lockwood770126a2010-12-09 22:30:37 -0800146 UsbService usb = null;
Mike Lockwoodb01e8bf2011-08-29 20:11:07 -0400147 SerialService serial = null;
Jeff Brown2416e092012-08-21 22:12:20 -0700148 TwilightService twilight = null;
Dianne Hackborn7299c412010-03-04 18:41:49 -0800149 UiModeManagerService uiMode = null;
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800150 RecognitionManagerService recognition = null;
Amith Yamasani6734b9f2010-09-13 16:24:08 -0700151 NetworkTimeUpdateService networkTimeUpdater = null;
John Grossmanc1576732012-02-01 15:23:33 -0800152 CommonTimeManagementService commonTimeMgmtService = null;
Jeff Brown6ec6f792012-04-17 16:52:41 -0700153 InputManagerService inputManager = null;
Wink Savillea12a7b32012-09-20 10:09:45 -0700154 TelephonyRegistry telephonyRegistry = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800155
Jeff Brownbd6e1502012-08-28 03:27:37 -0700156 // Create a shared handler thread for UI within the system server.
157 // This thread is used by at least the following components:
158 // - WindowManagerPolicy
159 // - KeyguardViewManager
160 // - DisplayManagerService
161 HandlerThread uiHandlerThread = new HandlerThread("UI");
162 uiHandlerThread.start();
163 Handler uiHandler = new Handler(uiHandlerThread.getLooper());
164 uiHandler.post(new Runnable() {
165 @Override
166 public void run() {
167 //Looper.myLooper().setMessageLogging(new LogPrinter(
168 // Log.VERBOSE, "WindowManagerPolicy", Log.LOG_ID_SYSTEM));
169 android.os.Process.setThreadPriority(
170 android.os.Process.THREAD_PRIORITY_FOREGROUND);
171 android.os.Process.setCanSelfBackground(false);
172
173 // For debug builds, log event loop stalls to dropbox for analysis.
174 if (StrictMode.conditionallyEnableDebugLogging()) {
175 Slog.i(TAG, "Enabled StrictMode logging for UI Looper");
176 }
177 }
178 });
179
180 // Create a handler thread just for the window manager to enjoy.
181 HandlerThread wmHandlerThread = new HandlerThread("WindowManager");
182 wmHandlerThread.start();
183 Handler wmHandler = new Handler(wmHandlerThread.getLooper());
184 wmHandler.post(new Runnable() {
185 @Override
186 public void run() {
187 //Looper.myLooper().setMessageLogging(new LogPrinter(
188 // android.util.Log.DEBUG, TAG, android.util.Log.LOG_ID_SYSTEM));
189 android.os.Process.setThreadPriority(
190 android.os.Process.THREAD_PRIORITY_DISPLAY);
191 android.os.Process.setCanSelfBackground(false);
192
193 // For debug builds, log event loop stalls to dropbox for analysis.
194 if (StrictMode.conditionallyEnableDebugLogging()) {
Jeff Brown89d55462012-09-19 11:33:42 -0700195 Slog.i(TAG, "Enabled StrictMode logging for WM Looper");
Jeff Brownbd6e1502012-08-28 03:27:37 -0700196 }
197 }
198 });
199
Dan Morrille4d9a012013-03-28 18:10:43 -0700200 // bootstrap services
Jeff Brownbd6e1502012-08-28 03:27:37 -0700201 boolean onlyCore = false;
Dan Morrille4d9a012013-03-28 18:10:43 -0700202 boolean firstBoot = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800203 try {
Jeff Brownf69c8122012-09-12 17:00:34 -0700204 // Wait for installd to finished starting up so that it has a chance to
205 // create critical directories such as /data/user with the appropriate
206 // permissions. We need this to complete before we initialize other services.
207 Slog.i(TAG, "Waiting for installd to be ready.");
208 installer = new Installer();
209 installer.ping();
210
Joe Onorato8a9b2202010-02-26 18:56:32 -0800211 Slog.i(TAG, "Power Manager");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800212 power = new PowerManagerService();
213 ServiceManager.addService(Context.POWER_SERVICE, power);
214
Joe Onorato8a9b2202010-02-26 18:56:32 -0800215 Slog.i(TAG, "Activity Manager");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800216 context = ActivityManagerService.main(factoryTest);
Dan Morrille4d9a012013-03-28 18:10:43 -0700217 } catch (RuntimeException e) {
218 Slog.e("System", "******************************************");
219 Slog.e("System", "************ Failure starting bootstrap service", e);
220 }
Jeff Brown848c2dc2012-08-19 20:18:08 -0700221
Dan Morrille4d9a012013-03-28 18:10:43 -0700222 boolean disableStorage = SystemProperties.getBoolean("config.disable_storage", false);
223 boolean disableMedia = SystemProperties.getBoolean("config.disable_media", false);
224 boolean disableBluetooth = SystemProperties.getBoolean("config.disable_bluetooth", false);
225 boolean disableTelephony = SystemProperties.getBoolean("config.disable_telephony", false);
226 boolean disableLocation = SystemProperties.getBoolean("config.disable_location", false);
227 boolean disableSystemUI = SystemProperties.getBoolean("config.disable_systemui", false);
228 boolean disableNonCoreServices = SystemProperties.getBoolean("config.disable_noncore", false);
229 boolean disableNetwork = SystemProperties.getBoolean("config.disable_network", false);
230
231 try {
Jeff Brown848c2dc2012-08-19 20:18:08 -0700232 Slog.i(TAG, "Display Manager");
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700233 display = new DisplayManagerService(context, wmHandler, uiHandler);
Jeff Brown848c2dc2012-08-19 20:18:08 -0700234 ServiceManager.addService(Context.DISPLAY_SERVICE, display, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800235
Joe Onorato8a9b2202010-02-26 18:56:32 -0800236 Slog.i(TAG, "Telephony Registry");
Wink Savillea12a7b32012-09-20 10:09:45 -0700237 telephonyRegistry = new TelephonyRegistry(context);
238 ServiceManager.addService("telephony.registry", telephonyRegistry);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800239
Glenn Kasten07b04652012-04-23 15:00:43 -0700240 Slog.i(TAG, "Scheduling Policy");
241 ServiceManager.addService(Context.SCHEDULING_POLICY_SERVICE,
242 new SchedulingPolicyService());
243
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800244 AttributeCache.init(context);
245
Jeff Brownbd6e1502012-08-28 03:27:37 -0700246 if (!display.waitForDefaultDisplay()) {
247 reportWtf("Timeout waiting for default display to be initialized.",
248 new Throwable());
249 }
250
Joe Onorato8a9b2202010-02-26 18:56:32 -0800251 Slog.i(TAG, "Package Manager");
Ben Komalo553acf02011-09-19 14:25:28 -0700252 // Only run "core" apps if we're encrypting the device.
253 String cryptState = SystemProperties.get("vold.decrypt");
Ben Komalo3573d402011-09-23 15:08:24 -0700254 if (ENCRYPTING_STATE.equals(cryptState)) {
Ben Komalo553acf02011-09-19 14:25:28 -0700255 Slog.w(TAG, "Detected encryption in progress - only parsing core apps");
Ben Komalo3573d402011-09-23 15:08:24 -0700256 onlyCore = true;
257 } else if (ENCRYPTED_STATE.equals(cryptState)) {
258 Slog.w(TAG, "Device encrypted - only parsing core apps");
259 onlyCore = true;
Ben Komalo553acf02011-09-19 14:25:28 -0700260 }
Ben Komalo3573d402011-09-23 15:08:24 -0700261
Jeff Brownf69c8122012-09-12 17:00:34 -0700262 pm = PackageManagerService.main(context, installer,
Dianne Hackbornd2509fd2011-09-12 12:29:43 -0700263 factoryTest != SystemServer.FACTORY_TEST_OFF,
Ben Komalo553acf02011-09-19 14:25:28 -0700264 onlyCore);
Dianne Hackborn58f42a52011-10-10 13:46:34 -0700265 try {
266 firstBoot = pm.isFirstBoot();
267 } catch (RemoteException e) {
268 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800269
270 ActivityManagerService.setSystemProcess();
Svetoslavb3038ec2013-02-13 14:39:30 -0800271
Nick Kralevich79619dd2013-03-04 13:05:32 -0800272 Slog.i(TAG, "Entropy Mixer");
273 ServiceManager.addService("entropy", new EntropyMixer(context));
274
Amith Yamasani258848d2012-08-10 17:06:33 -0700275 Slog.i(TAG, "User Service");
276 ServiceManager.addService(Context.USER_SERVICE,
Dianne Hackborn4428e172012-08-24 17:43:05 -0700277 UserManagerService.getInstance());
Amith Yamasani258848d2012-08-10 17:06:33 -0700278
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800279 mContentResolver = context.getContentResolver();
280
Fred Quintanae91ebe22009-09-29 20:44:30 -0700281 // The AccountManager must come before the ContentService
Fred Quintana60307342009-03-24 22:48:12 -0700282 try {
Dan Morrille4d9a012013-03-28 18:10:43 -0700283 // TODO: seems like this should be disable-able, but req'd by ContentService
Joe Onorato8a9b2202010-02-26 18:56:32 -0800284 Slog.i(TAG, "Account Manager");
Kenny Root26ff6622012-07-30 12:58:03 -0700285 accountManager = new AccountManagerService(context);
286 ServiceManager.addService(Context.ACCOUNT_SERVICE, accountManager);
Fred Quintana60307342009-03-24 22:48:12 -0700287 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800288 Slog.e(TAG, "Failure starting Account Manager", e);
Fred Quintana60307342009-03-24 22:48:12 -0700289 }
290
Joe Onorato8a9b2202010-02-26 18:56:32 -0800291 Slog.i(TAG, "Content Manager");
Kenny Root26ff6622012-07-30 12:58:03 -0700292 contentService = ContentService.main(context,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800293 factoryTest == SystemServer.FACTORY_TEST_LOW_LEVEL);
294
Joe Onorato8a9b2202010-02-26 18:56:32 -0800295 Slog.i(TAG, "System Content Providers");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800296 ActivityManagerService.installSystemProviders();
297
Joe Onorato8a9b2202010-02-26 18:56:32 -0800298 Slog.i(TAG, "Lights Service");
Mike Lockwood3a322132009-11-24 00:30:52 -0500299 lights = new LightsService(context);
300
Joe Onoratode1b3592010-10-25 20:36:47 -0700301 Slog.i(TAG, "Battery Service");
302 battery = new BatteryService(context, lights);
303 ServiceManager.addService("battery", battery);
304
Joe Onorato8a9b2202010-02-26 18:56:32 -0800305 Slog.i(TAG, "Vibrator Service");
Jeff Brown7f6c2312012-04-13 20:38:38 -0700306 vibrator = new VibratorService(context);
307 ServiceManager.addService("vibrator", vibrator);
The Android Open Source Project10592532009-03-18 17:39:46 -0700308
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800309 // only initialize the power service after we have started the
Mike Lockwood3a322132009-11-24 00:30:52 -0500310 // lights service, content providers and the battery service.
Jeff Brown96307042012-07-27 15:51:34 -0700311 power.init(context, lights, ActivityManagerService.self(), battery,
312 BatteryStatsService.getService(), display);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800313
Joe Onorato8a9b2202010-02-26 18:56:32 -0800314 Slog.i(TAG, "Alarm Manager");
Jeff Sharkey75279902011-05-24 18:39:45 -0700315 alarm = new AlarmManagerService(context);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800316 ServiceManager.addService(Context.ALARM_SERVICE, alarm);
317
Joe Onorato8a9b2202010-02-26 18:56:32 -0800318 Slog.i(TAG, "Init Watchdog");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800319 Watchdog.getInstance().init(context, battery, power, alarm,
320 ActivityManagerService.self());
321
Jeff Browna9d131c2012-09-20 16:48:17 -0700322 Slog.i(TAG, "Input Manager");
323 inputManager = new InputManagerService(context, wmHandler);
324
Joe Onorato8a9b2202010-02-26 18:56:32 -0800325 Slog.i(TAG, "Window Manager");
Jeff Browna9d131c2012-09-20 16:48:17 -0700326 wm = WindowManagerService.main(context, power, display, inputManager,
Jeff Brownbd6e1502012-08-28 03:27:37 -0700327 uiHandler, wmHandler,
Dianne Hackborn58f42a52011-10-10 13:46:34 -0700328 factoryTest != SystemServer.FACTORY_TEST_LOW_LEVEL,
Jeff Brown780c46f2012-06-24 12:15:38 -0700329 !firstBoot, onlyCore);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800330 ServiceManager.addService(Context.WINDOW_SERVICE, wm);
Jeff Brown6ec6f792012-04-17 16:52:41 -0700331 ServiceManager.addService(Context.INPUT_SERVICE, inputManager);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800332
Dianne Hackborn295e3c22011-08-25 13:19:08 -0700333 ActivityManagerService.self().setWindowManager(wm);
Jeff Browna9d131c2012-09-20 16:48:17 -0700334
335 inputManager.setWindowManagerCallbacks(wm.getInputMonitor());
336 inputManager.start();
337
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700338 display.setWindowManager(wm);
Jeff Brownd728bf52012-09-08 18:05:28 -0700339 display.setInputManager(inputManager);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800340
341 // Skip Bluetooth if we have an emulator kernel
342 // TODO: Use a more reliable check to see if this product should
343 // support Bluetooth - see bug 988521
344 if (SystemProperties.get("ro.kernel.qemu").equals("1")) {
David 'Digit' Turnere2a5e862011-01-17 00:32:33 +0100345 Slog.i(TAG, "No Bluetooh Service (emulator)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800346 } else if (factoryTest == SystemServer.FACTORY_TEST_LOW_LEVEL) {
David 'Digit' Turnere2a5e862011-01-17 00:32:33 +0100347 Slog.i(TAG, "No Bluetooth Service (factory test)");
Dan Morrille4d9a012013-03-28 18:10:43 -0700348 } else if (disableBluetooth) {
349 Slog.i(TAG, "Bluetooth Service disabled by config");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800350 } else {
fredc0f420372012-04-12 00:02:00 -0700351 Slog.i(TAG, "Bluetooth Manager Service");
352 bluetooth = new BluetoothManagerService(context);
353 ServiceManager.addService(BluetoothAdapter.BLUETOOTH_MANAGER_SERVICE, bluetooth);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800354 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800355 } catch (RuntimeException e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700356 Slog.e("System", "******************************************");
357 Slog.e("System", "************ Failure starting core service", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800358 }
359
Dianne Hackbornd6847842010-01-12 18:14:19 -0800360 DevicePolicyManagerService devicePolicy = null;
Joe Onorato089de882010-04-12 08:18:45 -0700361 StatusBarManagerService statusBar = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800362 InputMethodManagerService imm = null;
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700363 AppWidgetService appWidget = null;
Joe Onorato30275482009-07-08 17:09:14 -0700364 NotificationManagerService notification = null;
Dianne Hackbornf21adf62009-08-13 10:20:21 -0700365 WallpaperManagerService wallpaper = null;
Mike Lockwood46db5042010-02-22 16:36:44 -0500366 LocationManagerService location = null;
Bai Taoa58a8752010-07-13 15:32:16 +0800367 CountryDetectorService countryDetector = null;
satok988323c2011-06-22 16:38:13 +0900368 TextServicesManagerService tsms = null;
Amith Yamasani52c489c2012-03-28 11:42:42 -0700369 LockSettingsService lockSettings = null;
Daniel Sandler7d276c32012-01-30 14:33:52 -0500370 DreamManagerService dreamy = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800371
Dianne Hackborn661cd522011-08-22 00:26:20 -0700372 // Bring up services needed for UI.
373 if (factoryTest != SystemServer.FACTORY_TEST_LOW_LEVEL) {
Dan Morrille4d9a012013-03-28 18:10:43 -0700374 //if (!disableNonCoreServices) { // TODO: View depends on these; mock them?
375 if (true) {
376 try {
377 Slog.i(TAG, "Input Method Service");
378 imm = new InputMethodManagerService(context, wm);
379 ServiceManager.addService(Context.INPUT_METHOD_SERVICE, imm);
380 } catch (Throwable e) {
381 reportWtf("starting Input Manager Service", e);
382 }
Dianne Hackborn661cd522011-08-22 00:26:20 -0700383
Dan Morrille4d9a012013-03-28 18:10:43 -0700384 try {
385 Slog.i(TAG, "Accessibility Manager");
386 ServiceManager.addService(Context.ACCESSIBILITY_SERVICE,
387 new AccessibilityManagerService(context));
388 } catch (Throwable e) {
389 reportWtf("starting Accessibility Manager", e);
390 }
Dianne Hackborn661cd522011-08-22 00:26:20 -0700391 }
392 }
393
394 try {
395 wm.displayReady();
396 } catch (Throwable e) {
397 reportWtf("making display ready", e);
398 }
Dianne Hackborn8795b602011-08-25 13:30:53 -0700399
Dianne Hackborn295e3c22011-08-25 13:19:08 -0700400 try {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700401 pm.performBootDexOpt();
402 } catch (Throwable e) {
403 reportWtf("performing boot dexopt", e);
404 }
405
406 try {
407 ActivityManagerNative.getDefault().showBootMessage(
408 context.getResources().getText(
409 com.android.internal.R.string.android_upgrading_starting_apps),
410 false);
411 } catch (RemoteException e) {
412 }
413
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800414 if (factoryTest != SystemServer.FACTORY_TEST_LOW_LEVEL) {
Dan Morrille4d9a012013-03-28 18:10:43 -0700415 if (!disableStorage &&
416 !"0".equals(SystemProperties.get("system_init.startmountservice"))) {
Kenny Root51a573c2012-05-17 13:30:28 -0700417 try {
418 /*
419 * NotificationManagerService is dependant on MountService,
420 * (for media / usb notifications) so we must start MountService first.
421 */
422 Slog.i(TAG, "Mount Service");
423 mountService = new MountService(context);
424 ServiceManager.addService("mount", mountService);
425 } catch (Throwable e) {
426 reportWtf("starting Mount Service", e);
427 }
428 }
429
Dan Morrille4d9a012013-03-28 18:10:43 -0700430 if (!disableNonCoreServices) {
431 try {
432 Slog.i(TAG, "LockSettingsService");
433 lockSettings = new LockSettingsService(context);
434 ServiceManager.addService("lock_settings", lockSettings);
435 } catch (Throwable e) {
436 reportWtf("starting LockSettingsService service", e);
437 }
438
439 try {
440 Slog.i(TAG, "Device Policy");
441 devicePolicy = new DevicePolicyManagerService(context);
442 ServiceManager.addService(Context.DEVICE_POLICY_SERVICE, devicePolicy);
443 } catch (Throwable e) {
444 reportWtf("starting DevicePolicyService", e);
445 }
Amith Yamasani52c489c2012-03-28 11:42:42 -0700446 }
447
Dan Morrille4d9a012013-03-28 18:10:43 -0700448 if (!disableSystemUI) {
449 try {
450 Slog.i(TAG, "Status Bar");
451 statusBar = new StatusBarManagerService(context, wm);
452 ServiceManager.addService(Context.STATUS_BAR_SERVICE, statusBar);
453 } catch (Throwable e) {
454 reportWtf("starting StatusBarManagerService", e);
455 }
Dianne Hackbornd6847842010-01-12 18:14:19 -0800456 }
457
Dan Morrille4d9a012013-03-28 18:10:43 -0700458 if (!disableNonCoreServices) {
459 try {
460 Slog.i(TAG, "Clipboard Service");
461 ServiceManager.addService(Context.CLIPBOARD_SERVICE,
462 new ClipboardService(context));
463 } catch (Throwable e) {
464 reportWtf("starting Clipboard Service", e);
465 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800466 }
467
Dan Morrille4d9a012013-03-28 18:10:43 -0700468 if (!disableNetwork) {
469 try {
470 Slog.i(TAG, "NetworkManagement Service");
471 networkManagement = NetworkManagementService.create(context);
472 ServiceManager.addService(Context.NETWORKMANAGEMENT_SERVICE, networkManagement);
473 } catch (Throwable e) {
474 reportWtf("starting NetworkManagement Service", e);
475 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800476 }
477
Dan Morrille4d9a012013-03-28 18:10:43 -0700478 if (!disableNonCoreServices) {
479 try {
480 Slog.i(TAG, "Text Service Manager Service");
481 tsms = new TextServicesManagerService(context);
482 ServiceManager.addService(Context.TEXT_SERVICES_MANAGER_SERVICE, tsms);
483 } catch (Throwable e) {
484 reportWtf("starting Text Service Manager Service", e);
485 }
San Mehatd1df8ac2010-01-26 06:17:26 -0800486 }
487
Dan Morrille4d9a012013-03-28 18:10:43 -0700488 if (!disableNetwork) {
489 try {
490 Slog.i(TAG, "NetworkStats Service");
491 networkStats = new NetworkStatsService(context, networkManagement, alarm);
492 ServiceManager.addService(Context.NETWORK_STATS_SERVICE, networkStats);
493 } catch (Throwable e) {
494 reportWtf("starting NetworkStats Service", e);
495 }
496
497 try {
498 Slog.i(TAG, "NetworkPolicy Service");
499 networkPolicy = new NetworkPolicyManagerService(
500 context, ActivityManagerService.self(), power,
501 networkStats, networkManagement);
502 ServiceManager.addService(Context.NETWORK_POLICY_SERVICE, networkPolicy);
503 } catch (Throwable e) {
504 reportWtf("starting NetworkPolicy Service", e);
505 }
506
507 try {
508 Slog.i(TAG, "Wi-Fi P2pService");
509 wifiP2p = new WifiP2pService(context);
510 ServiceManager.addService(Context.WIFI_P2P_SERVICE, wifiP2p);
511 } catch (Throwable e) {
512 reportWtf("starting Wi-Fi P2pService", e);
513 }
514
515 try {
516 Slog.i(TAG, "Wi-Fi Service");
517 wifi = new WifiService(context);
518 ServiceManager.addService(Context.WIFI_SERVICE, wifi);
519 } catch (Throwable e) {
520 reportWtf("starting Wi-Fi Service", e);
521 }
522
523 try {
524 Slog.i(TAG, "Connectivity Service");
525 connectivity = new ConnectivityService(
526 context, networkManagement, networkStats, networkPolicy);
527 ServiceManager.addService(Context.CONNECTIVITY_SERVICE, connectivity);
528 networkStats.bindConnectivityManager(connectivity);
529 networkPolicy.bindConnectivityManager(connectivity);
530 wifi.checkAndStartWifi();
531 wifiP2p.connectivityServiceReady();
532 } catch (Throwable e) {
533 reportWtf("starting Connectivity Service", e);
534 }
535
536 try {
537 Slog.i(TAG, "Network Service Discovery Service");
538 serviceDiscovery = NsdService.create(context);
539 ServiceManager.addService(
540 Context.NSD_SERVICE, serviceDiscovery);
541 } catch (Throwable e) {
542 reportWtf("starting Service Discovery Service", e);
543 }
satok988323c2011-06-22 16:38:13 +0900544 }
545
Dan Morrille4d9a012013-03-28 18:10:43 -0700546 if (!disableNonCoreServices) {
547 try {
548 Slog.i(TAG, "UpdateLock Service");
549 ServiceManager.addService(Context.UPDATE_LOCK_SERVICE,
550 new UpdateLockService(context));
551 } catch (Throwable e) {
552 reportWtf("starting UpdateLockService", e);
553 }
Christopher Tate8662cab52012-02-23 14:59:36 -0800554 }
555
Kenny Root51a573c2012-05-17 13:30:28 -0700556 /*
557 * MountService has a few dependencies: Notification Manager and
558 * AppWidget Provider. Make sure MountService is completely started
559 * first before continuing.
560 */
561 if (mountService != null) {
562 mountService.waitForAsecScan();
San Mehat1bf3f8b2010-02-03 14:43:09 -0800563 }
564
565 try {
Kenny Root26ff6622012-07-30 12:58:03 -0700566 if (accountManager != null)
567 accountManager.systemReady();
568 } catch (Throwable e) {
569 reportWtf("making Account Manager Service ready", e);
570 }
571
572 try {
573 if (contentService != null)
574 contentService.systemReady();
575 } catch (Throwable e) {
576 reportWtf("making Content Service ready", e);
577 }
578
579 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800580 Slog.i(TAG, "Notification Manager");
Mike Lockwood3a322132009-11-24 00:30:52 -0500581 notification = new NotificationManagerService(context, statusBar, lights);
Joe Onorato30275482009-07-08 17:09:14 -0700582 ServiceManager.addService(Context.NOTIFICATION_SERVICE, notification);
Jeff Sharkey497e4432011-06-14 17:27:29 -0700583 networkPolicy.bindNotificationManager(notification);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800584 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700585 reportWtf("starting Notification Manager", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800586 }
587
588 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800589 Slog.i(TAG, "Device Storage Monitor");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800590 ServiceManager.addService(DeviceStorageMonitorService.SERVICE,
591 new DeviceStorageMonitorService(context));
592 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700593 reportWtf("starting DeviceStorageMonitor service", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800594 }
595
Dan Morrille4d9a012013-03-28 18:10:43 -0700596 if (!disableLocation) {
597 try {
598 Slog.i(TAG, "Location Manager");
599 location = new LocationManagerService(context);
600 ServiceManager.addService(Context.LOCATION_SERVICE, location);
601 } catch (Throwable e) {
602 reportWtf("starting Location Manager", e);
603 }
604
605 try {
606 Slog.i(TAG, "Country Detector");
607 countryDetector = new CountryDetectorService(context);
608 ServiceManager.addService(Context.COUNTRY_DETECTOR, countryDetector);
609 } catch (Throwable e) {
610 reportWtf("starting Country Detector", e);
611 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800612 }
613
Dan Morrille4d9a012013-03-28 18:10:43 -0700614 if (!disableNonCoreServices) {
615 try {
616 Slog.i(TAG, "Search Service");
617 ServiceManager.addService(Context.SEARCH_SERVICE,
618 new SearchManagerService(context));
619 } catch (Throwable e) {
620 reportWtf("starting Search Service", e);
621 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800622 }
623
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800624 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800625 Slog.i(TAG, "DropBox Service");
Dan Egnor95240272009-10-27 18:23:39 -0700626 ServiceManager.addService(Context.DROPBOX_SERVICE,
Dan Egnorf18a01c2009-11-12 11:32:50 -0800627 new DropBoxManagerService(context, new File("/data/system/dropbox")));
Dan Egnor4410ec82009-09-11 16:40:01 -0700628 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700629 reportWtf("starting DropBoxManagerService", e);
Dan Egnor4410ec82009-09-11 16:40:01 -0700630 }
631
Dan Morrille4d9a012013-03-28 18:10:43 -0700632 if (!disableNonCoreServices && context.getResources().getBoolean(
633 R.bool.config_enableWallpaperService)) {
Mike Lockwoodc067c9c2011-10-31 12:50:12 -0400634 try {
635 Slog.i(TAG, "Wallpaper Service");
636 if (!headless) {
637 wallpaper = new WallpaperManagerService(context);
638 ServiceManager.addService(Context.WALLPAPER_SERVICE, wallpaper);
639 }
640 } catch (Throwable e) {
641 reportWtf("starting Wallpaper Service", e);
Mike Lockwood3a74bd32011-08-12 13:55:22 -0700642 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800643 }
644
Dan Morrille4d9a012013-03-28 18:10:43 -0700645 if (!disableMedia && !"0".equals(SystemProperties.get("system_init.startaudioservice"))) {
Mike Lockwoodcba928c2011-08-17 15:58:52 -0700646 try {
647 Slog.i(TAG, "Audio Service");
648 ServiceManager.addService(Context.AUDIO_SERVICE, new AudioService(context));
649 } catch (Throwable e) {
650 reportWtf("starting Audio Service", e);
651 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800652 }
653
Dan Morrille4d9a012013-03-28 18:10:43 -0700654 if (!disableNonCoreServices) {
655 try {
656 Slog.i(TAG, "Dock Observer");
657 // Listen for dock station changes
658 dock = new DockObserver(context);
659 } catch (Throwable e) {
660 reportWtf("starting DockObserver", e);
661 }
Dan Murphyc9f4eaf2009-08-12 15:15:43 -0500662 }
663
Dan Morrille4d9a012013-03-28 18:10:43 -0700664 if (!disableMedia) {
665 try {
666 Slog.i(TAG, "Wired Accessory Manager");
667 // Listen for wired headset changes
668 inputManager.setWiredAccessoryCallbacks(
669 new WiredAccessoryManager(context, inputManager));
670 } catch (Throwable e) {
671 reportWtf("starting WiredAccessoryManager", e);
672 }
Praveen Bharathi21e941b2010-10-06 15:23:14 -0500673 }
674
Dan Morrille4d9a012013-03-28 18:10:43 -0700675 if (!disableNonCoreServices) {
676 try {
677 Slog.i(TAG, "USB Service");
678 // Manage USB host and device support
679 usb = new UsbService(context);
680 ServiceManager.addService(Context.USB_SERVICE, usb);
681 } catch (Throwable e) {
682 reportWtf("starting UsbService", e);
683 }
Mike Lockwood57c798a2010-06-23 17:36:36 -0400684
Dan Morrille4d9a012013-03-28 18:10:43 -0700685 try {
686 Slog.i(TAG, "Serial Service");
687 // Serial port support
688 serial = new SerialService(context);
689 ServiceManager.addService(Context.SERIAL_SERVICE, serial);
690 } catch (Throwable e) {
691 Slog.e(TAG, "Failure starting SerialService", e);
692 }
Mike Lockwoodb01e8bf2011-08-29 20:11:07 -0400693 }
694
695 try {
Jeff Brown2416e092012-08-21 22:12:20 -0700696 Slog.i(TAG, "Twilight Service");
697 twilight = new TwilightService(context);
698 } catch (Throwable e) {
699 reportWtf("starting TwilightService", e);
700 }
701
702 try {
Dianne Hackborn7299c412010-03-04 18:41:49 -0800703 Slog.i(TAG, "UI Mode Manager Service");
Mike Lockwood57c798a2010-06-23 17:36:36 -0400704 // Listen for UI mode changes
Jeff Brown2416e092012-08-21 22:12:20 -0700705 uiMode = new UiModeManagerService(context, twilight);
Dianne Hackborn7299c412010-03-04 18:41:49 -0800706 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700707 reportWtf("starting UiModeManagerService", e);
Dianne Hackborn7299c412010-03-04 18:41:49 -0800708 }
709
Dan Morrille4d9a012013-03-28 18:10:43 -0700710 if (!disableNonCoreServices) {
711 try {
712 Slog.i(TAG, "Backup Service");
713 ServiceManager.addService(Context.BACKUP_SERVICE,
714 new BackupManagerService(context));
715 } catch (Throwable e) {
716 Slog.e(TAG, "Failure starting Backup Service", e);
717 }
Christopher Tate487529a2009-04-29 14:03:25 -0700718
Dan Morrille4d9a012013-03-28 18:10:43 -0700719 try {
720 Slog.i(TAG, "AppWidget Service");
721 appWidget = new AppWidgetService(context);
722 ServiceManager.addService(Context.APPWIDGET_SERVICE, appWidget);
723 } catch (Throwable e) {
724 reportWtf("starting AppWidget Service", e);
725 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800726
Dan Morrille4d9a012013-03-28 18:10:43 -0700727 try {
728 Slog.i(TAG, "Recognition Service");
729 recognition = new RecognitionManagerService(context);
730 } catch (Throwable e) {
731 reportWtf("starting Recognition Service", e);
732 }
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800733 }
Jaikumar Ganesh7d0548d2010-10-18 15:29:09 -0700734
Nick Pelly038cabe2010-09-23 16:12:11 -0700735 try {
Dan Egnor621bc542010-03-25 16:20:14 -0700736 Slog.i(TAG, "DiskStats Service");
737 ServiceManager.addService("diskstats", new DiskStatsService(context));
738 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700739 reportWtf("starting DiskStats Service", e);
Dan Egnor621bc542010-03-25 16:20:14 -0700740 }
Sen Hubde75702010-05-28 01:54:03 -0700741
742 try {
743 // need to add this service even if SamplingProfilerIntegration.isEnabled()
744 // is false, because it is this service that detects system property change and
745 // turns on SamplingProfilerIntegration. Plus, when sampling profiler doesn't work,
746 // there is little overhead for running this service.
747 Slog.i(TAG, "SamplingProfiler Service");
748 ServiceManager.addService("samplingprofiler",
749 new SamplingProfilerService(context));
750 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700751 reportWtf("starting SamplingProfiler Service", e);
Sen Hubde75702010-05-28 01:54:03 -0700752 }
Chung-yih Wang024d5962010-08-06 12:06:04 +0800753
Dan Morrille4d9a012013-03-28 18:10:43 -0700754 if (!disableNetwork) {
755 try {
756 Slog.i(TAG, "NetworkTimeUpdateService");
757 networkTimeUpdater = new NetworkTimeUpdateService(context);
758 } catch (Throwable e) {
759 reportWtf("starting NetworkTimeUpdate service", e);
760 }
Amith Yamasani6734b9f2010-09-13 16:24:08 -0700761 }
John Grossmanc1576732012-02-01 15:23:33 -0800762
Dan Morrille4d9a012013-03-28 18:10:43 -0700763 if (!disableMedia) {
764 try {
765 Slog.i(TAG, "CommonTimeManagementService");
766 commonTimeMgmtService = new CommonTimeManagementService(context);
767 ServiceManager.addService("commontime_management", commonTimeMgmtService);
768 } catch (Throwable e) {
769 reportWtf("starting CommonTimeManagementService service", e);
770 }
John Grossmanc1576732012-02-01 15:23:33 -0800771 }
Geremy Condra3d33c262012-05-06 18:32:19 -0700772
Dan Morrille4d9a012013-03-28 18:10:43 -0700773 if (!disableNetwork) {
774 try {
775 Slog.i(TAG, "CertBlacklister");
776 CertBlacklister blacklister = new CertBlacklister(context);
777 } catch (Throwable e) {
778 reportWtf("starting CertBlacklister", e);
779 }
Geremy Condra3d33c262012-05-06 18:32:19 -0700780 }
Jim Miller5ecd8112013-01-09 18:50:26 -0800781
Dan Morrille4d9a012013-03-28 18:10:43 -0700782 if (!disableNonCoreServices &&
783 context.getResources().getBoolean(R.bool.config_dreamsSupported)) {
Daniel Sandler7d276c32012-01-30 14:33:52 -0500784 try {
785 Slog.i(TAG, "Dreams Service");
786 // Dreams (interactive idle-time views, a/k/a screen savers)
Jeff Brown62c82e42012-09-26 01:30:41 -0700787 dreamy = new DreamManagerService(context, wmHandler);
Dianne Hackbornbe87e2f2012-09-28 16:31:34 -0700788 ServiceManager.addService(DreamService.DREAM_SERVICE, dreamy);
Daniel Sandler7d276c32012-01-30 14:33:52 -0500789 } catch (Throwable e) {
790 reportWtf("starting DreamManagerService", e);
791 }
792 }
Svetoslavb3038ec2013-02-13 14:39:30 -0800793
794 try {
795 Slog.i(TAG, "IdleMaintenanceService");
796 new IdleMaintenanceService(context);
797 } catch (Throwable e) {
798 reportWtf("starting IdleMaintenanceService", e);
799 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800800 }
801
Dianne Hackborn6af0d502009-09-28 13:25:46 -0700802 // Before things start rolling, be sure we have decided whether
803 // we are in safe mode.
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700804 final boolean safeMode = wm.detectSafeMode();
Dianne Hackborn6af0d502009-09-28 13:25:46 -0700805 if (safeMode) {
Jeff Brownb09abc12011-01-13 21:08:27 -0800806 ActivityManagerService.self().enterSafeMode();
807 // Post the safe mode state in the Zygote class
808 Zygote.systemInSafeMode = true;
809 // Disable the JIT for the system_server process
810 VMRuntime.getRuntime().disableJitCompilation();
Ben Cheng6c0afff2010-02-14 16:18:56 -0800811 } else {
812 // Enable the JIT for the system_server process
813 VMRuntime.getRuntime().startJitCompilation();
Dianne Hackborn6af0d502009-09-28 13:25:46 -0700814 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800815
Dianne Hackborn6af0d502009-09-28 13:25:46 -0700816 // It is now time to start up the app processes...
Joe Onorato30275482009-07-08 17:09:14 -0700817
Jeff Brown7f6c2312012-04-13 20:38:38 -0700818 try {
819 vibrator.systemReady();
820 } catch (Throwable e) {
821 reportWtf("making Vibrator Service ready", e);
822 }
823
Dan Morrille4d9a012013-03-28 18:10:43 -0700824 if (lockSettings != null) {
825 try {
826 lockSettings.systemReady();
827 } catch (Throwable e) {
828 reportWtf("making Lock Settings Service ready", e);
829 }
Felipe Ramosf35df5b2012-09-18 18:26:27 -0300830 }
831
Dianne Hackbornd6847842010-01-12 18:14:19 -0800832 if (devicePolicy != null) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700833 try {
834 devicePolicy.systemReady();
835 } catch (Throwable e) {
836 reportWtf("making Device Policy Service ready", e);
837 }
Dianne Hackbornd6847842010-01-12 18:14:19 -0800838 }
839
Joe Onorato30275482009-07-08 17:09:14 -0700840 if (notification != null) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700841 try {
842 notification.systemReady();
843 } catch (Throwable e) {
844 reportWtf("making Notification Service ready", e);
845 }
Joe Onorato30275482009-07-08 17:09:14 -0700846 }
847
Dianne Hackborn661cd522011-08-22 00:26:20 -0700848 try {
849 wm.systemReady();
850 } catch (Throwable e) {
851 reportWtf("making Window Manager Service ready", e);
852 }
Joe Onoratodc565f42010-10-04 15:27:22 -0400853
Jeff Brownb09abc12011-01-13 21:08:27 -0800854 if (safeMode) {
855 ActivityManagerService.self().showSafeModeOverlay();
856 }
857
Joe Onoratodc565f42010-10-04 15:27:22 -0400858 // Update the configuration for this context by hand, because we're going
859 // to start using it before the config change done in wm.systemReady() will
860 // propagate to it.
861 Configuration config = wm.computeNewConfiguration();
862 DisplayMetrics metrics = new DisplayMetrics();
863 WindowManager w = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
864 w.getDefaultDisplay().getMetrics(metrics);
865 context.getResources().updateConfiguration(config, metrics);
866
Jeff Brownaa202a62012-08-21 22:14:26 -0700867 try {
Jeff Brown62c82e42012-09-26 01:30:41 -0700868 power.systemReady(twilight, dreamy);
Jeff Brownaa202a62012-08-21 22:14:26 -0700869 } catch (Throwable e) {
870 reportWtf("making Power Manager Service ready", e);
871 }
872
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800873 try {
874 pm.systemReady();
Dianne Hackborn661cd522011-08-22 00:26:20 -0700875 } catch (Throwable e) {
876 reportWtf("making Package Manager Service ready", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800877 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800878
Jeff Brownbd6e1502012-08-28 03:27:37 -0700879 try {
880 display.systemReady(safeMode, onlyCore);
881 } catch (Throwable e) {
882 reportWtf("making Display Manager Service ready", e);
883 }
884
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700885 // These are needed to propagate to the runnable below.
Joe Onoratof3c3c4f2010-10-21 11:09:02 -0400886 final Context contextF = context;
Jeff Sharkeyb049e212012-09-07 23:16:01 -0700887 final MountService mountServiceF = mountService;
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700888 final BatteryService batteryF = battery;
Jeff Sharkey350083e2011-06-29 10:45:16 -0700889 final NetworkManagementService networkManagementF = networkManagement;
Jeff Sharkey75279902011-05-24 18:39:45 -0700890 final NetworkStatsService networkStatsF = networkStats;
Jeff Sharkeya4620792011-05-20 15:29:23 -0700891 final NetworkPolicyManagerService networkPolicyF = networkPolicy;
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700892 final ConnectivityService connectivityF = connectivity;
893 final DockObserver dockF = dock;
Mike Lockwood770126a2010-12-09 22:30:37 -0800894 final UsbService usbF = usb;
Jeff Brown2416e092012-08-21 22:12:20 -0700895 final TwilightService twilightF = twilight;
Dianne Hackborn7299c412010-03-04 18:41:49 -0800896 final UiModeManagerService uiModeF = uiMode;
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700897 final AppWidgetService appWidgetF = appWidget;
898 final WallpaperManagerService wallpaperF = wallpaper;
899 final InputMethodManagerService immF = imm;
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800900 final RecognitionManagerService recognitionF = recognition;
Mike Lockwood46db5042010-02-22 16:36:44 -0500901 final LocationManagerService locationF = location;
Bai Taoa58a8752010-07-13 15:32:16 +0800902 final CountryDetectorService countryDetectorF = countryDetector;
Amith Yamasani6734b9f2010-09-13 16:24:08 -0700903 final NetworkTimeUpdateService networkTimeUpdaterF = networkTimeUpdater;
John Grossmanc1576732012-02-01 15:23:33 -0800904 final CommonTimeManagementService commonTimeMgmtServiceF = commonTimeMgmtService;
satok988323c2011-06-22 16:38:13 +0900905 final TextServicesManagerService textServiceManagerServiceF = tsms;
Dianne Hackborn661cd522011-08-22 00:26:20 -0700906 final StatusBarManagerService statusBarF = statusBar;
Daniel Sandler7d276c32012-01-30 14:33:52 -0500907 final DreamManagerService dreamyF = dreamy;
Jeff Brown6ec6f792012-04-17 16:52:41 -0700908 final InputManagerService inputManagerF = inputManager;
Wink Savillea12a7b32012-09-20 10:09:45 -0700909 final TelephonyRegistry telephonyRegistryF = telephonyRegistry;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800910
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700911 // We now tell the activity manager it is okay to run third party
912 // code. It will call back into us once it has gotten to the state
913 // where third party code can really run (but before it has actually
914 // started launching the initial applications), for us to complete our
915 // initialization.
Dianne Hackborn295e3c22011-08-25 13:19:08 -0700916 ActivityManagerService.self().systemReady(new Runnable() {
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700917 public void run() {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800918 Slog.i(TAG, "Making services ready");
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800919
Christopher Tate58d380d2013-03-19 13:10:03 -0700920 try {
921 ActivityManagerService.self().startObservingNativeCrashes();
922 } catch (Throwable e) {
923 reportWtf("observing native crashes", e);
924 }
Jim Miller5ecd8112013-01-09 18:50:26 -0800925 if (!headless) {
926 startSystemUi(contextF);
927 }
Dianne Hackborn661cd522011-08-22 00:26:20 -0700928 try {
Jeff Sharkeyb049e212012-09-07 23:16:01 -0700929 if (mountServiceF != null) mountServiceF.systemReady();
930 } catch (Throwable e) {
931 reportWtf("making Mount Service ready", e);
932 }
933 try {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700934 if (batteryF != null) batteryF.systemReady();
935 } catch (Throwable e) {
936 reportWtf("making Battery Service ready", e);
937 }
938 try {
939 if (networkManagementF != null) networkManagementF.systemReady();
940 } catch (Throwable e) {
941 reportWtf("making Network Managment Service ready", e);
942 }
943 try {
944 if (networkStatsF != null) networkStatsF.systemReady();
945 } catch (Throwable e) {
946 reportWtf("making Network Stats Service ready", e);
947 }
948 try {
949 if (networkPolicyF != null) networkPolicyF.systemReady();
950 } catch (Throwable e) {
951 reportWtf("making Network Policy Service ready", e);
952 }
953 try {
954 if (connectivityF != null) connectivityF.systemReady();
955 } catch (Throwable e) {
956 reportWtf("making Connectivity Service ready", e);
957 }
958 try {
959 if (dockF != null) dockF.systemReady();
960 } catch (Throwable e) {
961 reportWtf("making Dock Service ready", e);
962 }
963 try {
964 if (usbF != null) usbF.systemReady();
965 } catch (Throwable e) {
966 reportWtf("making USB Service ready", e);
967 }
968 try {
Jeff Brown2416e092012-08-21 22:12:20 -0700969 if (twilightF != null) twilightF.systemReady();
970 } catch (Throwable e) {
971 reportWtf("makin Twilight Service ready", e);
972 }
973 try {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700974 if (uiModeF != null) uiModeF.systemReady();
975 } catch (Throwable e) {
976 reportWtf("making UI Mode Service ready", e);
977 }
978 try {
979 if (recognitionF != null) recognitionF.systemReady();
980 } catch (Throwable e) {
981 reportWtf("making Recognition Service ready", e);
982 }
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700983 Watchdog.getInstance().start();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800984
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700985 // It is now okay to let the various system services start their
986 // third party code...
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800987
Dianne Hackborn661cd522011-08-22 00:26:20 -0700988 try {
989 if (appWidgetF != null) appWidgetF.systemReady(safeMode);
990 } catch (Throwable e) {
991 reportWtf("making App Widget Service ready", e);
992 }
993 try {
994 if (wallpaperF != null) wallpaperF.systemReady();
995 } catch (Throwable e) {
996 reportWtf("making Wallpaper Service ready", e);
997 }
998 try {
999 if (immF != null) immF.systemReady(statusBarF);
1000 } catch (Throwable e) {
1001 reportWtf("making Input Method Service ready", e);
1002 }
1003 try {
1004 if (locationF != null) locationF.systemReady();
1005 } catch (Throwable e) {
1006 reportWtf("making Location Service ready", e);
1007 }
1008 try {
1009 if (countryDetectorF != null) countryDetectorF.systemReady();
1010 } catch (Throwable e) {
1011 reportWtf("making Country Detector Service ready", e);
1012 }
1013 try {
Dianne Hackborn661cd522011-08-22 00:26:20 -07001014 if (networkTimeUpdaterF != null) networkTimeUpdaterF.systemReady();
1015 } catch (Throwable e) {
1016 reportWtf("making Network Time Service ready", e);
1017 }
1018 try {
John Grossmanc1576732012-02-01 15:23:33 -08001019 if (commonTimeMgmtServiceF != null) commonTimeMgmtServiceF.systemReady();
1020 } catch (Throwable e) {
1021 reportWtf("making Common time management service ready", e);
1022 }
1023 try {
Dianne Hackborn661cd522011-08-22 00:26:20 -07001024 if (textServiceManagerServiceF != null) textServiceManagerServiceF.systemReady();
1025 } catch (Throwable e) {
1026 reportWtf("making Text Services Manager Service ready", e);
1027 }
Daniel Sandler7d276c32012-01-30 14:33:52 -05001028 try {
1029 if (dreamyF != null) dreamyF.systemReady();
1030 } catch (Throwable e) {
1031 reportWtf("making DreamManagerService ready", e);
1032 }
Jeff Brown6ec6f792012-04-17 16:52:41 -07001033 try {
Matthew Xie96313142012-06-29 16:57:31 -07001034 // TODO(BT) Pass parameter to input manager
1035 if (inputManagerF != null) inputManagerF.systemReady();
Jeff Brown6ec6f792012-04-17 16:52:41 -07001036 } catch (Throwable e) {
1037 reportWtf("making InputManagerService ready", e);
1038 }
Dan Morrille4d9a012013-03-28 18:10:43 -07001039
Wink Savillea12a7b32012-09-20 10:09:45 -07001040 try {
1041 if (telephonyRegistryF != null) telephonyRegistryF.systemReady();
1042 } catch (Throwable e) {
1043 reportWtf("making TelephonyRegistry ready", e);
1044 }
Dianne Hackborna34f1ad2009-09-02 13:26:28 -07001045 }
1046 });
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001047
Brad Fitzpatrick1e02d362010-09-10 09:19:50 -07001048 // For debug builds, log event loop stalls to dropbox for analysis.
Brad Fitzpatrick50d66f92010-09-13 21:29:05 -07001049 if (StrictMode.conditionallyEnableDebugLogging()) {
1050 Slog.i(TAG, "Enabled StrictMode for system server main thread.");
Brad Fitzpatrick1e02d362010-09-10 09:19:50 -07001051 }
1052
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001053 Looper.loop();
Joe Onorato8a9b2202010-02-26 18:56:32 -08001054 Slog.d(TAG, "System ServerThread is exiting!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001055 }
Joe Onoratof3c3c4f2010-10-21 11:09:02 -04001056
1057 static final void startSystemUi(Context context) {
1058 Intent intent = new Intent();
1059 intent.setComponent(new ComponentName("com.android.systemui",
1060 "com.android.systemui.SystemUIService"));
Dianne Hackborn40e9f292012-11-27 19:12:23 -08001061 //Slog.d(TAG, "Starting service: " + intent);
Amith Yamasanicd757062012-10-19 18:23:52 -07001062 context.startServiceAsUser(intent, UserHandle.OWNER);
Joe Onoratof3c3c4f2010-10-21 11:09:02 -04001063 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001064}
1065
Jeff Hamilton35eef702010-06-09 15:45:18 -05001066public class SystemServer {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001067 private static final String TAG = "SystemServer";
1068
1069 public static final int FACTORY_TEST_OFF = 0;
1070 public static final int FACTORY_TEST_LOW_LEVEL = 1;
1071 public static final int FACTORY_TEST_HIGH_LEVEL = 2;
Jaikumar Ganeshd5ac1ae2009-05-05 22:26:12 -07001072
Bob Leee5408332009-09-04 18:31:17 -07001073 static Timer timer;
1074 static final long SNAPSHOT_INTERVAL = 60 * 60 * 1000; // 1hr
1075
Brad Fitzpatrick6bb7a4a2010-10-11 13:41:10 -07001076 // The earliest supported time. We pick one day into 1970, to
1077 // give any timezone code room without going into negative time.
1078 private static final long EARLIEST_SUPPORTED_TIME = 86400 * 1000;
1079
Jaikumar Ganeshd5ac1ae2009-05-05 22:26:12 -07001080 /**
1081 * 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 -08001082 * services (SurfaceFlinger, AudioFlinger, etc..) to be started. After that it will call back
1083 * up into init2() to start the Android services.
Jaikumar Ganeshd5ac1ae2009-05-05 22:26:12 -07001084 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001085 native public static void init1(String[] args);
1086
1087 public static void main(String[] args) {
Brad Fitzpatrick6bb7a4a2010-10-11 13:41:10 -07001088 if (System.currentTimeMillis() < EARLIEST_SUPPORTED_TIME) {
Brad Fitzpatrick35ca9d82010-10-11 11:52:49 -07001089 // If a device's clock is before 1970 (before 0), a lot of
1090 // APIs crash dealing with negative numbers, notably
1091 // java.io.File#setLastModified, so instead we fake it and
1092 // hope that time from cell towers or NTP fixes it
1093 // shortly.
1094 Slog.w(TAG, "System clock is before 1970; setting to 1970.");
Brad Fitzpatrick6bb7a4a2010-10-11 13:41:10 -07001095 SystemClock.setCurrentTimeMillis(EARLIEST_SUPPORTED_TIME);
Brad Fitzpatrick35ca9d82010-10-11 11:52:49 -07001096 }
1097
Bob Leee5408332009-09-04 18:31:17 -07001098 if (SamplingProfilerIntegration.isEnabled()) {
1099 SamplingProfilerIntegration.start();
1100 timer = new Timer();
1101 timer.schedule(new TimerTask() {
1102 @Override
1103 public void run() {
Sen Hubde75702010-05-28 01:54:03 -07001104 SamplingProfilerIntegration.writeSnapshot("system_server", null);
Bob Leee5408332009-09-04 18:31:17 -07001105 }
1106 }, SNAPSHOT_INTERVAL, SNAPSHOT_INTERVAL);
1107 }
1108
Dianne Hackbornac1471a2011-02-03 13:46:06 -08001109 // Mmmmmm... more memory!
1110 dalvik.system.VMRuntime.getRuntime().clearGrowthLimit();
1111
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001112 // The system server has to run all of the time, so it needs to be
1113 // as efficient as possible with its memory usage.
1114 VMRuntime.getRuntime().setTargetHeapUtilization(0.8f);
Sen Hubde75702010-05-28 01:54:03 -07001115
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!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001122 Thread thr = new ServerThread();
1123 thr.setName("android.server.ServerThread");
1124 thr.start();
1125 }
1126}