blob: 9455017dedb8ac7c25150ae62166c5e530c8db64 [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
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -070047import com.android.internal.os.BinderInternal;
48import com.android.internal.os.SamplingProfilerIntegration;
49import com.android.server.accessibility.AccessibilityManagerService;
Jeff Sharkey7a96c392012-11-15 14:01:46 -080050import com.android.server.accounts.AccountManagerService;
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -070051import com.android.server.am.ActivityManagerService;
Jeff Brown96307042012-07-27 15:51:34 -070052import com.android.server.am.BatteryStatsService;
Jeff Sharkey7a96c392012-11-15 14:01:46 -080053import com.android.server.content.ContentService;
Jeff Brownfa25bf52012-07-23 19:26:30 -070054import com.android.server.display.DisplayManagerService;
Jeff Browncef440f2012-09-25 18:58:48 -070055import com.android.server.dreams.DreamManagerService;
Jeff Brown6ec6f792012-04-17 16:52:41 -070056import com.android.server.input.InputManagerService;
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -070057import com.android.server.net.NetworkPolicyManagerService;
Jeff Sharkey75279902011-05-24 18:39:45 -070058import com.android.server.net.NetworkStatsService;
Jeff Sharkey7a96c392012-11-15 14:01:46 -080059import com.android.server.os.SchedulingPolicyService;
Jeff Brownf69c8122012-09-12 17:00:34 -070060import com.android.server.pm.Installer;
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -070061import com.android.server.pm.PackageManagerService;
Amith Yamasani258848d2012-08-10 17:06:33 -070062import com.android.server.pm.UserManagerService;
Jeff Brown4f8ecd82012-06-18 18:29:13 -070063import com.android.server.power.PowerManagerService;
64import com.android.server.power.ShutdownThread;
Jeff Sharkey7a96c392012-11-15 14:01:46 -080065import com.android.server.search.SearchManagerService;
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -070066import com.android.server.usb.UsbService;
Irfan Sheriffd017f352013-02-20 13:30:44 -080067import com.android.server.wifi.WifiService;
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -070068import com.android.server.wm.WindowManagerService;
69
70import dalvik.system.VMRuntime;
71import dalvik.system.Zygote;
72
Dan Egnor4410ec82009-09-11 16:40:01 -070073import java.io.File;
Bob Leee5408332009-09-04 18:31:17 -070074import java.util.Timer;
75import java.util.TimerTask;
76
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080077class ServerThread extends Thread {
78 private static final String TAG = "SystemServer";
Ben Komalo553acf02011-09-19 14:25:28 -070079 private static final String ENCRYPTING_STATE = "trigger_restart_min_framework";
Ben Komalo3573d402011-09-23 15:08:24 -070080 private static final String ENCRYPTED_STATE = "1";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080081
Jeff Hamilton35eef702010-06-09 15:45:18 -050082 ContentResolver mContentResolver;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080083
Dianne Hackborn661cd522011-08-22 00:26:20 -070084 void reportWtf(String msg, Throwable e) {
85 Slog.w(TAG, "***********************************************");
86 Log.wtf(TAG, "BOOT FAILURE " + msg, e);
87 }
88
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080089 @Override
90 public void run() {
Doug Zongkerab5c49c2009-12-04 10:31:43 -080091 EventLog.writeEvent(EventLogTags.BOOT_PROGRESS_SYSTEM_RUN,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080092 SystemClock.uptimeMillis());
93
Vairavan Srinivasan04b74ec2012-02-02 22:12:19 -080094 Looper.prepareMainLooper();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080095
96 android.os.Process.setThreadPriority(
97 android.os.Process.THREAD_PRIORITY_FOREGROUND);
98
Dianne Hackborn887f3552009-12-07 17:59:37 -080099 BinderInternal.disableBackgroundScheduling(true);
Christopher Tate160edb32010-06-30 17:46:30 -0700100 android.os.Process.setCanSelfBackground(false);
Sen Hubde75702010-05-28 01:54:03 -0700101
Kenny Rootf547d672010-09-22 10:36:48 -0700102 // Check whether we failed to shut down last time we tried.
103 {
104 final String shutdownAction = SystemProperties.get(
105 ShutdownThread.SHUTDOWN_ACTION_PROPERTY, "");
106 if (shutdownAction != null && shutdownAction.length() > 0) {
107 boolean reboot = (shutdownAction.charAt(0) == '1');
108
109 final String reason;
110 if (shutdownAction.length() > 1) {
111 reason = shutdownAction.substring(1, shutdownAction.length());
112 } else {
113 reason = null;
114 }
115
116 ShutdownThread.rebootOrShutdown(reboot, reason);
117 }
118 }
119
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800120 String factoryTestStr = SystemProperties.get("ro.factorytest");
121 int factoryTest = "".equals(factoryTestStr) ? SystemServer.FACTORY_TEST_OFF
122 : Integer.parseInt(factoryTestStr);
Mike Lockwood3a74bd32011-08-12 13:55:22 -0700123 final boolean headless = "1".equals(SystemProperties.get("ro.config.headless", "0"));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800124
Jeff Brownf69c8122012-09-12 17:00:34 -0700125 Installer installer = null;
Kenny Root26ff6622012-07-30 12:58:03 -0700126 AccountManagerService accountManager = null;
127 ContentService contentService = null;
Mike Lockwood3a322132009-11-24 00:30:52 -0500128 LightsService lights = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800129 PowerManagerService power = null;
Jeff Brownfa25bf52012-07-23 19:26:30 -0700130 DisplayManagerService display = null;
Mike Lockwood07a500f2009-08-12 09:56:44 -0400131 BatteryService battery = null;
Jeff Brown7f6c2312012-04-13 20:38:38 -0700132 VibratorService vibrator = null;
Jeff Sharkey75279902011-05-24 18:39:45 -0700133 AlarmManagerService alarm = null;
Jeff Sharkeyb049e212012-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 Yamasani6734b9f2010-09-13 16:24:08 -0700152 NetworkTimeUpdateService networkTimeUpdater = null;
John Grossmanc1576732012-02-01 15:23:33 -0800153 CommonTimeManagementService commonTimeMgmtService = null;
Jeff Brown6ec6f792012-04-17 16:52:41 -0700154 InputManagerService inputManager = null;
Wink Savillea12a7b32012-09-20 10:09:45 -0700155 TelephonyRegistry telephonyRegistry = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800156
Jeff Brownbd6e1502012-08-28 03:27:37 -0700157 // Create a shared handler thread for UI within the system server.
158 // This thread is used by at least the following components:
159 // - WindowManagerPolicy
160 // - KeyguardViewManager
161 // - DisplayManagerService
162 HandlerThread uiHandlerThread = new HandlerThread("UI");
163 uiHandlerThread.start();
164 Handler uiHandler = new Handler(uiHandlerThread.getLooper());
165 uiHandler.post(new Runnable() {
166 @Override
167 public void run() {
168 //Looper.myLooper().setMessageLogging(new LogPrinter(
169 // Log.VERBOSE, "WindowManagerPolicy", Log.LOG_ID_SYSTEM));
170 android.os.Process.setThreadPriority(
171 android.os.Process.THREAD_PRIORITY_FOREGROUND);
172 android.os.Process.setCanSelfBackground(false);
173
174 // For debug builds, log event loop stalls to dropbox for analysis.
175 if (StrictMode.conditionallyEnableDebugLogging()) {
176 Slog.i(TAG, "Enabled StrictMode logging for UI Looper");
177 }
178 }
179 });
180
181 // Create a handler thread just for the window manager to enjoy.
182 HandlerThread wmHandlerThread = new HandlerThread("WindowManager");
183 wmHandlerThread.start();
184 Handler wmHandler = new Handler(wmHandlerThread.getLooper());
185 wmHandler.post(new Runnable() {
186 @Override
187 public void run() {
188 //Looper.myLooper().setMessageLogging(new LogPrinter(
189 // android.util.Log.DEBUG, TAG, android.util.Log.LOG_ID_SYSTEM));
190 android.os.Process.setThreadPriority(
191 android.os.Process.THREAD_PRIORITY_DISPLAY);
192 android.os.Process.setCanSelfBackground(false);
193
194 // For debug builds, log event loop stalls to dropbox for analysis.
195 if (StrictMode.conditionallyEnableDebugLogging()) {
Jeff Brown89d55462012-09-19 11:33:42 -0700196 Slog.i(TAG, "Enabled StrictMode logging for WM Looper");
Jeff Brownbd6e1502012-08-28 03:27:37 -0700197 }
198 }
199 });
200
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800201 // Critical services...
Jeff Brownbd6e1502012-08-28 03:27:37 -0700202 boolean onlyCore = 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);
Jeff Brown848c2dc2012-08-19 20:18:08 -0700217
218 Slog.i(TAG, "Display Manager");
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700219 display = new DisplayManagerService(context, wmHandler, uiHandler);
Jeff Brown848c2dc2012-08-19 20:18:08 -0700220 ServiceManager.addService(Context.DISPLAY_SERVICE, display, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800221
Joe Onorato8a9b2202010-02-26 18:56:32 -0800222 Slog.i(TAG, "Telephony Registry");
Wink Savillea12a7b32012-09-20 10:09:45 -0700223 telephonyRegistry = new TelephonyRegistry(context);
224 ServiceManager.addService("telephony.registry", telephonyRegistry);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800225
Glenn Kasten07b04652012-04-23 15:00:43 -0700226 Slog.i(TAG, "Scheduling Policy");
227 ServiceManager.addService(Context.SCHEDULING_POLICY_SERVICE,
228 new SchedulingPolicyService());
229
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800230 AttributeCache.init(context);
231
Jeff Brownbd6e1502012-08-28 03:27:37 -0700232 if (!display.waitForDefaultDisplay()) {
233 reportWtf("Timeout waiting for default display to be initialized.",
234 new Throwable());
235 }
236
Joe Onorato8a9b2202010-02-26 18:56:32 -0800237 Slog.i(TAG, "Package Manager");
Ben Komalo553acf02011-09-19 14:25:28 -0700238 // Only run "core" apps if we're encrypting the device.
239 String cryptState = SystemProperties.get("vold.decrypt");
Ben Komalo3573d402011-09-23 15:08:24 -0700240 if (ENCRYPTING_STATE.equals(cryptState)) {
Ben Komalo553acf02011-09-19 14:25:28 -0700241 Slog.w(TAG, "Detected encryption in progress - only parsing core apps");
Ben Komalo3573d402011-09-23 15:08:24 -0700242 onlyCore = true;
243 } else if (ENCRYPTED_STATE.equals(cryptState)) {
244 Slog.w(TAG, "Device encrypted - only parsing core apps");
245 onlyCore = true;
Ben Komalo553acf02011-09-19 14:25:28 -0700246 }
Ben Komalo3573d402011-09-23 15:08:24 -0700247
Jeff Brownf69c8122012-09-12 17:00:34 -0700248 pm = PackageManagerService.main(context, installer,
Dianne Hackbornd2509fd2011-09-12 12:29:43 -0700249 factoryTest != SystemServer.FACTORY_TEST_OFF,
Ben Komalo553acf02011-09-19 14:25:28 -0700250 onlyCore);
Dianne Hackborn58f42a52011-10-10 13:46:34 -0700251 boolean firstBoot = false;
252 try {
253 firstBoot = pm.isFirstBoot();
254 } catch (RemoteException e) {
255 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800256
257 ActivityManagerService.setSystemProcess();
Svetoslavb3038ec2013-02-13 14:39:30 -0800258
Nick Kralevich79619dd2013-03-04 13:05:32 -0800259 Slog.i(TAG, "Entropy Mixer");
260 ServiceManager.addService("entropy", new EntropyMixer(context));
261
Amith Yamasani258848d2012-08-10 17:06:33 -0700262 Slog.i(TAG, "User Service");
263 ServiceManager.addService(Context.USER_SERVICE,
Dianne Hackborn4428e172012-08-24 17:43:05 -0700264 UserManagerService.getInstance());
Amith Yamasani258848d2012-08-10 17:06:33 -0700265
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800266 mContentResolver = context.getContentResolver();
267
Fred Quintanae91ebe22009-09-29 20:44:30 -0700268 // The AccountManager must come before the ContentService
Fred Quintana60307342009-03-24 22:48:12 -0700269 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800270 Slog.i(TAG, "Account Manager");
Kenny Root26ff6622012-07-30 12:58:03 -0700271 accountManager = new AccountManagerService(context);
272 ServiceManager.addService(Context.ACCOUNT_SERVICE, accountManager);
Fred Quintana60307342009-03-24 22:48:12 -0700273 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800274 Slog.e(TAG, "Failure starting Account Manager", e);
Fred Quintana60307342009-03-24 22:48:12 -0700275 }
276
Joe Onorato8a9b2202010-02-26 18:56:32 -0800277 Slog.i(TAG, "Content Manager");
Kenny Root26ff6622012-07-30 12:58:03 -0700278 contentService = ContentService.main(context,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800279 factoryTest == SystemServer.FACTORY_TEST_LOW_LEVEL);
280
Joe Onorato8a9b2202010-02-26 18:56:32 -0800281 Slog.i(TAG, "System Content Providers");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800282 ActivityManagerService.installSystemProviders();
283
Joe Onorato8a9b2202010-02-26 18:56:32 -0800284 Slog.i(TAG, "Lights Service");
Mike Lockwood3a322132009-11-24 00:30:52 -0500285 lights = new LightsService(context);
286
Joe Onoratode1b3592010-10-25 20:36:47 -0700287 Slog.i(TAG, "Battery Service");
288 battery = new BatteryService(context, lights);
289 ServiceManager.addService("battery", battery);
290
Joe Onorato8a9b2202010-02-26 18:56:32 -0800291 Slog.i(TAG, "Vibrator Service");
Jeff Brown7f6c2312012-04-13 20:38:38 -0700292 vibrator = new VibratorService(context);
293 ServiceManager.addService("vibrator", vibrator);
The Android Open Source Project10592532009-03-18 17:39:46 -0700294
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800295 // only initialize the power service after we have started the
Mike Lockwood3a322132009-11-24 00:30:52 -0500296 // lights service, content providers and the battery service.
Jeff Brown96307042012-07-27 15:51:34 -0700297 power.init(context, lights, ActivityManagerService.self(), battery,
298 BatteryStatsService.getService(), display);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800299
Joe Onorato8a9b2202010-02-26 18:56:32 -0800300 Slog.i(TAG, "Alarm Manager");
Jeff Sharkey75279902011-05-24 18:39:45 -0700301 alarm = new AlarmManagerService(context);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800302 ServiceManager.addService(Context.ALARM_SERVICE, alarm);
303
Joe Onorato8a9b2202010-02-26 18:56:32 -0800304 Slog.i(TAG, "Init Watchdog");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800305 Watchdog.getInstance().init(context, battery, power, alarm,
306 ActivityManagerService.self());
307
Jeff Browna9d131c2012-09-20 16:48:17 -0700308 Slog.i(TAG, "Input Manager");
309 inputManager = new InputManagerService(context, wmHandler);
310
Joe Onorato8a9b2202010-02-26 18:56:32 -0800311 Slog.i(TAG, "Window Manager");
Jeff Browna9d131c2012-09-20 16:48:17 -0700312 wm = WindowManagerService.main(context, power, display, inputManager,
Jeff Brownbd6e1502012-08-28 03:27:37 -0700313 uiHandler, wmHandler,
Dianne Hackborn58f42a52011-10-10 13:46:34 -0700314 factoryTest != SystemServer.FACTORY_TEST_LOW_LEVEL,
Jeff Brown780c46f2012-06-24 12:15:38 -0700315 !firstBoot, onlyCore);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800316 ServiceManager.addService(Context.WINDOW_SERVICE, wm);
Jeff Brown6ec6f792012-04-17 16:52:41 -0700317 ServiceManager.addService(Context.INPUT_SERVICE, inputManager);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800318
Dianne Hackborn295e3c22011-08-25 13:19:08 -0700319 ActivityManagerService.self().setWindowManager(wm);
Jeff Browna9d131c2012-09-20 16:48:17 -0700320
321 inputManager.setWindowManagerCallbacks(wm.getInputMonitor());
322 inputManager.start();
323
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700324 display.setWindowManager(wm);
Jeff Brownd728bf52012-09-08 18:05:28 -0700325 display.setInputManager(inputManager);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800326
327 // Skip Bluetooth if we have an emulator kernel
328 // TODO: Use a more reliable check to see if this product should
329 // support Bluetooth - see bug 988521
330 if (SystemProperties.get("ro.kernel.qemu").equals("1")) {
David 'Digit' Turnere2a5e862011-01-17 00:32:33 +0100331 Slog.i(TAG, "No Bluetooh Service (emulator)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800332 } else if (factoryTest == SystemServer.FACTORY_TEST_LOW_LEVEL) {
David 'Digit' Turnere2a5e862011-01-17 00:32:33 +0100333 Slog.i(TAG, "No Bluetooth Service (factory test)");
Matthew Xie1dd01eb32013-04-26 12:37:54 -0700334 } else if (!context.getPackageManager().hasSystemFeature
335 (PackageManager.FEATURE_BLUETOOTH)) {
336 Slog.i(TAG, "No Bluetooth Service (Bluetooth Hardware Not Present)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800337 } else {
fredc0f420372012-04-12 00:02:00 -0700338 Slog.i(TAG, "Bluetooth Manager Service");
339 bluetooth = new BluetoothManagerService(context);
340 ServiceManager.addService(BluetoothAdapter.BLUETOOTH_MANAGER_SERVICE, bluetooth);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800341 }
342
343 } catch (RuntimeException e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700344 Slog.e("System", "******************************************");
345 Slog.e("System", "************ Failure starting core service", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800346 }
347
Dianne Hackbornd6847842010-01-12 18:14:19 -0800348 DevicePolicyManagerService devicePolicy = null;
Joe Onorato089de882010-04-12 08:18:45 -0700349 StatusBarManagerService statusBar = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800350 InputMethodManagerService imm = null;
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700351 AppWidgetService appWidget = null;
Joe Onorato30275482009-07-08 17:09:14 -0700352 NotificationManagerService notification = null;
Dianne Hackbornf21adf62009-08-13 10:20:21 -0700353 WallpaperManagerService wallpaper = null;
Mike Lockwood46db5042010-02-22 16:36:44 -0500354 LocationManagerService location = null;
Bai Taoa58a8752010-07-13 15:32:16 +0800355 CountryDetectorService countryDetector = null;
satok988323c2011-06-22 16:38:13 +0900356 TextServicesManagerService tsms = null;
Amith Yamasani52c489c2012-03-28 11:42:42 -0700357 LockSettingsService lockSettings = null;
Daniel Sandler7d276c32012-01-30 14:33:52 -0500358 DreamManagerService dreamy = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800359
Dianne Hackborn661cd522011-08-22 00:26:20 -0700360 // Bring up services needed for UI.
361 if (factoryTest != SystemServer.FACTORY_TEST_LOW_LEVEL) {
362 try {
363 Slog.i(TAG, "Input Method Service");
satok01038492012-04-09 21:08:27 +0900364 imm = new InputMethodManagerService(context, wm);
Dianne Hackborn661cd522011-08-22 00:26:20 -0700365 ServiceManager.addService(Context.INPUT_METHOD_SERVICE, imm);
366 } catch (Throwable e) {
367 reportWtf("starting Input Manager Service", e);
368 }
369
370 try {
371 Slog.i(TAG, "Accessibility Manager");
372 ServiceManager.addService(Context.ACCESSIBILITY_SERVICE,
373 new AccessibilityManagerService(context));
374 } catch (Throwable e) {
375 reportWtf("starting Accessibility Manager", e);
376 }
377 }
378
379 try {
380 wm.displayReady();
381 } catch (Throwable e) {
382 reportWtf("making display ready", e);
383 }
Dianne Hackborn8795b602011-08-25 13:30:53 -0700384
Dianne Hackborn295e3c22011-08-25 13:19:08 -0700385 try {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700386 pm.performBootDexOpt();
387 } catch (Throwable e) {
388 reportWtf("performing boot dexopt", e);
389 }
390
391 try {
392 ActivityManagerNative.getDefault().showBootMessage(
393 context.getResources().getText(
394 com.android.internal.R.string.android_upgrading_starting_apps),
395 false);
396 } catch (RemoteException e) {
397 }
398
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800399 if (factoryTest != SystemServer.FACTORY_TEST_LOW_LEVEL) {
Kenny Root51a573c2012-05-17 13:30:28 -0700400 if (!"0".equals(SystemProperties.get("system_init.startmountservice"))) {
401 try {
402 /*
403 * NotificationManagerService is dependant on MountService,
404 * (for media / usb notifications) so we must start MountService first.
405 */
406 Slog.i(TAG, "Mount Service");
407 mountService = new MountService(context);
408 ServiceManager.addService("mount", mountService);
409 } catch (Throwable e) {
410 reportWtf("starting Mount Service", e);
411 }
412 }
413
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800414 try {
Amith Yamasani52c489c2012-03-28 11:42:42 -0700415 Slog.i(TAG, "LockSettingsService");
416 lockSettings = new LockSettingsService(context);
417 ServiceManager.addService("lock_settings", lockSettings);
418 } catch (Throwable e) {
419 reportWtf("starting LockSettingsService service", e);
420 }
421
422 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800423 Slog.i(TAG, "Device Policy");
Dianne Hackbornd6847842010-01-12 18:14:19 -0800424 devicePolicy = new DevicePolicyManagerService(context);
425 ServiceManager.addService(Context.DEVICE_POLICY_SERVICE, devicePolicy);
426 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700427 reportWtf("starting DevicePolicyService", e);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800428 }
429
430 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800431 Slog.i(TAG, "Status Bar");
Jeff Brown2992ea72011-01-28 22:04:14 -0800432 statusBar = new StatusBarManagerService(context, wm);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800433 ServiceManager.addService(Context.STATUS_BAR_SERVICE, statusBar);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800434 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700435 reportWtf("starting StatusBarManagerService", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800436 }
437
438 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800439 Slog.i(TAG, "Clipboard Service");
Dianne Hackbornd6847842010-01-12 18:14:19 -0800440 ServiceManager.addService(Context.CLIPBOARD_SERVICE,
441 new ClipboardService(context));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800442 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700443 reportWtf("starting Clipboard Service", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800444 }
445
446 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800447 Slog.i(TAG, "NetworkManagement Service");
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -0700448 networkManagement = NetworkManagementService.create(context);
449 ServiceManager.addService(Context.NETWORKMANAGEMENT_SERVICE, networkManagement);
San Mehatd1df8ac2010-01-26 06:17:26 -0800450 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700451 reportWtf("starting NetworkManagement Service", e);
San Mehatd1df8ac2010-01-26 06:17:26 -0800452 }
453
454 try {
satok988323c2011-06-22 16:38:13 +0900455 Slog.i(TAG, "Text Service Manager Service");
456 tsms = new TextServicesManagerService(context);
457 ServiceManager.addService(Context.TEXT_SERVICES_MANAGER_SERVICE, tsms);
458 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700459 reportWtf("starting Text Service Manager Service", e);
satok988323c2011-06-22 16:38:13 +0900460 }
461
462 try {
Jeff Sharkey75279902011-05-24 18:39:45 -0700463 Slog.i(TAG, "NetworkStats Service");
464 networkStats = new NetworkStatsService(context, networkManagement, alarm);
465 ServiceManager.addService(Context.NETWORK_STATS_SERVICE, networkStats);
466 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700467 reportWtf("starting NetworkStats Service", e);
Jeff Sharkey75279902011-05-24 18:39:45 -0700468 }
469
470 try {
471 Slog.i(TAG, "NetworkPolicy Service");
472 networkPolicy = new NetworkPolicyManagerService(
Ashish Sharma50fd36d2011-06-15 19:34:53 -0700473 context, ActivityManagerService.self(), power,
474 networkStats, networkManagement);
Jeff Sharkey75279902011-05-24 18:39:45 -0700475 ServiceManager.addService(Context.NETWORK_POLICY_SERVICE, networkPolicy);
476 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700477 reportWtf("starting NetworkPolicy Service", e);
Jeff Sharkey75279902011-05-24 18:39:45 -0700478 }
479
repo sync55bc5f32011-06-24 14:23:07 -0700480 try {
481 Slog.i(TAG, "Wi-Fi P2pService");
482 wifiP2p = new WifiP2pService(context);
483 ServiceManager.addService(Context.WIFI_P2P_SERVICE, wifiP2p);
484 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700485 reportWtf("starting Wi-Fi P2pService", e);
repo sync55bc5f32011-06-24 14:23:07 -0700486 }
487
repo syncaea743a2011-07-29 23:55:49 -0700488 try {
489 Slog.i(TAG, "Wi-Fi Service");
490 wifi = new WifiService(context);
491 ServiceManager.addService(Context.WIFI_SERVICE, wifi);
repo syncaea743a2011-07-29 23:55:49 -0700492 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700493 reportWtf("starting Wi-Fi Service", e);
repo syncaea743a2011-07-29 23:55:49 -0700494 }
495
Jeff Sharkey75279902011-05-24 18:39:45 -0700496 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800497 Slog.i(TAG, "Connectivity Service");
Jeff Sharkey367d15a2011-09-22 14:59:51 -0700498 connectivity = new ConnectivityService(
499 context, networkManagement, networkStats, networkPolicy);
Mike Lockwood0f79b542009-08-14 14:18:49 -0400500 ServiceManager.addService(Context.CONNECTIVITY_SERVICE, connectivity);
Jeff Sharkeyd2a45872011-05-28 20:56:34 -0700501 networkStats.bindConnectivityManager(connectivity);
Jeff Sharkey21c9c452011-06-07 12:26:43 -0700502 networkPolicy.bindConnectivityManager(connectivity);
Robert Greenwalt9b2886e2011-08-31 11:46:42 -0700503 wifi.checkAndStartWifi();
Irfan Sheriffcb30b222011-07-29 20:54:52 -0700504 wifiP2p.connectivityServiceReady();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800505 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700506 reportWtf("starting Connectivity Service", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800507 }
508
509 try {
Irfan Sheriff7d024d32012-03-22 17:01:39 -0700510 Slog.i(TAG, "Network Service Discovery Service");
511 serviceDiscovery = NsdService.create(context);
512 ServiceManager.addService(
513 Context.NSD_SERVICE, serviceDiscovery);
514 } catch (Throwable e) {
515 reportWtf("starting Service Discovery Service", e);
516 }
517
518 try {
Christopher Tate8662cab52012-02-23 14:59:36 -0800519 Slog.i(TAG, "UpdateLock Service");
520 ServiceManager.addService(Context.UPDATE_LOCK_SERVICE,
521 new UpdateLockService(context));
522 } catch (Throwable e) {
523 reportWtf("starting UpdateLockService", e);
524 }
525
Kenny Root51a573c2012-05-17 13:30:28 -0700526 /*
527 * MountService has a few dependencies: Notification Manager and
528 * AppWidget Provider. Make sure MountService is completely started
529 * first before continuing.
530 */
531 if (mountService != null) {
532 mountService.waitForAsecScan();
San Mehat1bf3f8b2010-02-03 14:43:09 -0800533 }
534
535 try {
Kenny Root26ff6622012-07-30 12:58:03 -0700536 if (accountManager != null)
537 accountManager.systemReady();
538 } catch (Throwable e) {
539 reportWtf("making Account Manager Service ready", e);
540 }
541
542 try {
543 if (contentService != null)
544 contentService.systemReady();
545 } catch (Throwable e) {
546 reportWtf("making Content Service ready", e);
547 }
548
549 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800550 Slog.i(TAG, "Notification Manager");
Mike Lockwood3a322132009-11-24 00:30:52 -0500551 notification = new NotificationManagerService(context, statusBar, lights);
Joe Onorato30275482009-07-08 17:09:14 -0700552 ServiceManager.addService(Context.NOTIFICATION_SERVICE, notification);
Jeff Sharkey497e4432011-06-14 17:27:29 -0700553 networkPolicy.bindNotificationManager(notification);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800554 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700555 reportWtf("starting Notification Manager", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800556 }
557
558 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800559 Slog.i(TAG, "Device Storage Monitor");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800560 ServiceManager.addService(DeviceStorageMonitorService.SERVICE,
561 new DeviceStorageMonitorService(context));
562 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700563 reportWtf("starting DeviceStorageMonitor service", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800564 }
565
566 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800567 Slog.i(TAG, "Location Manager");
Mike Lockwood46db5042010-02-22 16:36:44 -0500568 location = new LocationManagerService(context);
569 ServiceManager.addService(Context.LOCATION_SERVICE, location);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800570 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700571 reportWtf("starting Location Manager", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800572 }
573
574 try {
Bai Taoa58a8752010-07-13 15:32:16 +0800575 Slog.i(TAG, "Country Detector");
576 countryDetector = new CountryDetectorService(context);
577 ServiceManager.addService(Context.COUNTRY_DETECTOR, countryDetector);
578 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700579 reportWtf("starting Country Detector", e);
Bai Taoa58a8752010-07-13 15:32:16 +0800580 }
581
582 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800583 Slog.i(TAG, "Search Service");
Dianne Hackbornd6847842010-01-12 18:14:19 -0800584 ServiceManager.addService(Context.SEARCH_SERVICE,
585 new SearchManagerService(context));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800586 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700587 reportWtf("starting Search Service", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800588 }
589
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800590 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800591 Slog.i(TAG, "DropBox Service");
Dan Egnor95240272009-10-27 18:23:39 -0700592 ServiceManager.addService(Context.DROPBOX_SERVICE,
Dan Egnorf18a01c2009-11-12 11:32:50 -0800593 new DropBoxManagerService(context, new File("/data/system/dropbox")));
Dan Egnor4410ec82009-09-11 16:40:01 -0700594 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700595 reportWtf("starting DropBoxManagerService", e);
Dan Egnor4410ec82009-09-11 16:40:01 -0700596 }
597
Mike Lockwoodc067c9c2011-10-31 12:50:12 -0400598 if (context.getResources().getBoolean(
599 com.android.internal.R.bool.config_enableWallpaperService)) {
600 try {
601 Slog.i(TAG, "Wallpaper Service");
602 if (!headless) {
603 wallpaper = new WallpaperManagerService(context);
604 ServiceManager.addService(Context.WALLPAPER_SERVICE, wallpaper);
605 }
606 } catch (Throwable e) {
607 reportWtf("starting Wallpaper Service", e);
Mike Lockwood3a74bd32011-08-12 13:55:22 -0700608 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800609 }
610
Mike Lockwoodcba928c2011-08-17 15:58:52 -0700611 if (!"0".equals(SystemProperties.get("system_init.startaudioservice"))) {
612 try {
613 Slog.i(TAG, "Audio Service");
614 ServiceManager.addService(Context.AUDIO_SERVICE, new AudioService(context));
615 } catch (Throwable e) {
616 reportWtf("starting Audio Service", e);
617 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800618 }
619
620 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800621 Slog.i(TAG, "Dock Observer");
Dan Murphyc9f4eaf2009-08-12 15:15:43 -0500622 // Listen for dock station changes
Jeff Brown96307042012-07-27 15:51:34 -0700623 dock = new DockObserver(context);
Dan Murphyc9f4eaf2009-08-12 15:15:43 -0500624 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700625 reportWtf("starting DockObserver", e);
Dan Murphyc9f4eaf2009-08-12 15:15:43 -0500626 }
627
628 try {
Craig Mautner2f39e9f2012-09-21 11:39:54 -0700629 Slog.i(TAG, "Wired Accessory Manager");
Praveen Bharathi21e941b2010-10-06 15:23:14 -0500630 // Listen for wired headset changes
Craig Mautner2f39e9f2012-09-21 11:39:54 -0700631 inputManager.setWiredAccessoryCallbacks(
632 new WiredAccessoryManager(context, inputManager));
Praveen Bharathi21e941b2010-10-06 15:23:14 -0500633 } catch (Throwable e) {
Craig Mautner2f39e9f2012-09-21 11:39:54 -0700634 reportWtf("starting WiredAccessoryManager", e);
Praveen Bharathi21e941b2010-10-06 15:23:14 -0500635 }
636
637 try {
Mike Lockwood02e45692011-06-14 15:43:51 -0400638 Slog.i(TAG, "USB Service");
639 // Manage USB host and device support
Mike Lockwood770126a2010-12-09 22:30:37 -0800640 usb = new UsbService(context);
Mike Lockwoode7d511e2010-12-30 13:39:37 -0500641 ServiceManager.addService(Context.USB_SERVICE, usb);
Mike Lockwood57c798a2010-06-23 17:36:36 -0400642 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700643 reportWtf("starting UsbService", e);
Mike Lockwood57c798a2010-06-23 17:36:36 -0400644 }
645
646 try {
Mike Lockwoodb01e8bf2011-08-29 20:11:07 -0400647 Slog.i(TAG, "Serial Service");
648 // Serial port support
649 serial = new SerialService(context);
650 ServiceManager.addService(Context.SERIAL_SERVICE, serial);
651 } catch (Throwable e) {
652 Slog.e(TAG, "Failure starting SerialService", e);
653 }
654
655 try {
Jeff Brown2416e092012-08-21 22:12:20 -0700656 Slog.i(TAG, "Twilight Service");
657 twilight = new TwilightService(context);
658 } catch (Throwable e) {
659 reportWtf("starting TwilightService", e);
660 }
661
662 try {
Dianne Hackborn7299c412010-03-04 18:41:49 -0800663 Slog.i(TAG, "UI Mode Manager Service");
Mike Lockwood57c798a2010-06-23 17:36:36 -0400664 // Listen for UI mode changes
Jeff Brown2416e092012-08-21 22:12:20 -0700665 uiMode = new UiModeManagerService(context, twilight);
Dianne Hackborn7299c412010-03-04 18:41:49 -0800666 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700667 reportWtf("starting UiModeManagerService", e);
Dianne Hackborn7299c412010-03-04 18:41:49 -0800668 }
669
670 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800671 Slog.i(TAG, "Backup Service");
Dianne Hackbornd6847842010-01-12 18:14:19 -0800672 ServiceManager.addService(Context.BACKUP_SERVICE,
673 new BackupManagerService(context));
Christopher Tate487529a2009-04-29 14:03:25 -0700674 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800675 Slog.e(TAG, "Failure starting Backup Service", e);
Christopher Tate487529a2009-04-29 14:03:25 -0700676 }
677
678 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800679 Slog.i(TAG, "AppWidget Service");
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700680 appWidget = new AppWidgetService(context);
681 ServiceManager.addService(Context.APPWIDGET_SERVICE, appWidget);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800682 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700683 reportWtf("starting AppWidget Service", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800684 }
685
686 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800687 Slog.i(TAG, "Recognition Service");
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800688 recognition = new RecognitionManagerService(context);
689 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700690 reportWtf("starting Recognition Service", e);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800691 }
Jaikumar Ganesh7d0548d2010-10-18 15:29:09 -0700692
Nick Pelly038cabe2010-09-23 16:12:11 -0700693 try {
Dan Egnor621bc542010-03-25 16:20:14 -0700694 Slog.i(TAG, "DiskStats Service");
695 ServiceManager.addService("diskstats", new DiskStatsService(context));
696 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700697 reportWtf("starting DiskStats Service", e);
Dan Egnor621bc542010-03-25 16:20:14 -0700698 }
Sen Hubde75702010-05-28 01:54:03 -0700699
700 try {
701 // need to add this service even if SamplingProfilerIntegration.isEnabled()
702 // is false, because it is this service that detects system property change and
703 // turns on SamplingProfilerIntegration. Plus, when sampling profiler doesn't work,
704 // there is little overhead for running this service.
705 Slog.i(TAG, "SamplingProfiler Service");
706 ServiceManager.addService("samplingprofiler",
707 new SamplingProfilerService(context));
708 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700709 reportWtf("starting SamplingProfiler Service", e);
Sen Hubde75702010-05-28 01:54:03 -0700710 }
Chung-yih Wang024d5962010-08-06 12:06:04 +0800711
712 try {
Amith Yamasani6734b9f2010-09-13 16:24:08 -0700713 Slog.i(TAG, "NetworkTimeUpdateService");
714 networkTimeUpdater = new NetworkTimeUpdateService(context);
715 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700716 reportWtf("starting NetworkTimeUpdate service", e);
Amith Yamasani6734b9f2010-09-13 16:24:08 -0700717 }
John Grossmanc1576732012-02-01 15:23:33 -0800718
719 try {
720 Slog.i(TAG, "CommonTimeManagementService");
721 commonTimeMgmtService = new CommonTimeManagementService(context);
722 ServiceManager.addService("commontime_management", commonTimeMgmtService);
723 } catch (Throwable e) {
724 reportWtf("starting CommonTimeManagementService service", e);
725 }
Geremy Condra3d33c262012-05-06 18:32:19 -0700726
727 try {
728 Slog.i(TAG, "CertBlacklister");
729 CertBlacklister blacklister = new CertBlacklister(context);
730 } catch (Throwable e) {
731 reportWtf("starting CertBlacklister", e);
732 }
Daniel Sandler7d276c32012-01-30 14:33:52 -0500733
734 if (context.getResources().getBoolean(
John Spurlocked108f32012-10-18 16:49:24 -0400735 com.android.internal.R.bool.config_dreamsSupported)) {
Daniel Sandler7d276c32012-01-30 14:33:52 -0500736 try {
737 Slog.i(TAG, "Dreams Service");
738 // Dreams (interactive idle-time views, a/k/a screen savers)
Jeff Brown62c82e42012-09-26 01:30:41 -0700739 dreamy = new DreamManagerService(context, wmHandler);
Dianne Hackbornbe87e2f2012-09-28 16:31:34 -0700740 ServiceManager.addService(DreamService.DREAM_SERVICE, dreamy);
Daniel Sandler7d276c32012-01-30 14:33:52 -0500741 } catch (Throwable e) {
742 reportWtf("starting DreamManagerService", e);
743 }
744 }
Svetoslavb3038ec2013-02-13 14:39:30 -0800745
746 try {
747 Slog.i(TAG, "IdleMaintenanceService");
Svetoslav6a08a122013-05-03 11:24:26 -0700748 new IdleMaintenanceService(context, battery);
Svetoslavb3038ec2013-02-13 14:39:30 -0800749 } catch (Throwable e) {
750 reportWtf("starting IdleMaintenanceService", e);
751 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800752 }
753
Dianne Hackborn6af0d502009-09-28 13:25:46 -0700754 // Before things start rolling, be sure we have decided whether
755 // we are in safe mode.
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700756 final boolean safeMode = wm.detectSafeMode();
Dianne Hackborn6af0d502009-09-28 13:25:46 -0700757 if (safeMode) {
Jeff Brownb09abc12011-01-13 21:08:27 -0800758 ActivityManagerService.self().enterSafeMode();
759 // Post the safe mode state in the Zygote class
760 Zygote.systemInSafeMode = true;
761 // Disable the JIT for the system_server process
762 VMRuntime.getRuntime().disableJitCompilation();
Ben Cheng6c0afff2010-02-14 16:18:56 -0800763 } else {
764 // Enable the JIT for the system_server process
765 VMRuntime.getRuntime().startJitCompilation();
Dianne Hackborn6af0d502009-09-28 13:25:46 -0700766 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800767
Dianne Hackborn6af0d502009-09-28 13:25:46 -0700768 // It is now time to start up the app processes...
Joe Onorato30275482009-07-08 17:09:14 -0700769
Jeff Brown7f6c2312012-04-13 20:38:38 -0700770 try {
771 vibrator.systemReady();
772 } catch (Throwable e) {
773 reportWtf("making Vibrator Service ready", e);
774 }
775
Felipe Ramosf35df5b2012-09-18 18:26:27 -0300776 try {
777 lockSettings.systemReady();
778 } catch (Throwable e) {
779 reportWtf("making Lock Settings Service ready", e);
780 }
781
Dianne Hackbornd6847842010-01-12 18:14:19 -0800782 if (devicePolicy != null) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700783 try {
784 devicePolicy.systemReady();
785 } catch (Throwable e) {
786 reportWtf("making Device Policy Service ready", e);
787 }
Dianne Hackbornd6847842010-01-12 18:14:19 -0800788 }
789
Joe Onorato30275482009-07-08 17:09:14 -0700790 if (notification != null) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700791 try {
792 notification.systemReady();
793 } catch (Throwable e) {
794 reportWtf("making Notification Service ready", e);
795 }
Joe Onorato30275482009-07-08 17:09:14 -0700796 }
797
Dianne Hackborn661cd522011-08-22 00:26:20 -0700798 try {
799 wm.systemReady();
800 } catch (Throwable e) {
801 reportWtf("making Window Manager Service ready", e);
802 }
Joe Onoratodc565f42010-10-04 15:27:22 -0400803
Jeff Brownb09abc12011-01-13 21:08:27 -0800804 if (safeMode) {
805 ActivityManagerService.self().showSafeModeOverlay();
806 }
807
Joe Onoratodc565f42010-10-04 15:27:22 -0400808 // Update the configuration for this context by hand, because we're going
809 // to start using it before the config change done in wm.systemReady() will
810 // propagate to it.
811 Configuration config = wm.computeNewConfiguration();
812 DisplayMetrics metrics = new DisplayMetrics();
813 WindowManager w = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
814 w.getDefaultDisplay().getMetrics(metrics);
815 context.getResources().updateConfiguration(config, metrics);
816
Jeff Brownaa202a62012-08-21 22:14:26 -0700817 try {
Jeff Brown62c82e42012-09-26 01:30:41 -0700818 power.systemReady(twilight, dreamy);
Jeff Brownaa202a62012-08-21 22:14:26 -0700819 } catch (Throwable e) {
820 reportWtf("making Power Manager Service ready", e);
821 }
822
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800823 try {
824 pm.systemReady();
Dianne Hackborn661cd522011-08-22 00:26:20 -0700825 } catch (Throwable e) {
826 reportWtf("making Package Manager Service ready", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800827 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800828
Jeff Brownbd6e1502012-08-28 03:27:37 -0700829 try {
830 display.systemReady(safeMode, onlyCore);
831 } catch (Throwable e) {
832 reportWtf("making Display Manager Service ready", e);
833 }
834
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700835 // These are needed to propagate to the runnable below.
Joe Onoratof3c3c4f2010-10-21 11:09:02 -0400836 final Context contextF = context;
Jeff Sharkeyb049e212012-09-07 23:16:01 -0700837 final MountService mountServiceF = mountService;
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700838 final BatteryService batteryF = battery;
Jeff Sharkey350083e2011-06-29 10:45:16 -0700839 final NetworkManagementService networkManagementF = networkManagement;
Jeff Sharkey75279902011-05-24 18:39:45 -0700840 final NetworkStatsService networkStatsF = networkStats;
Jeff Sharkeya4620792011-05-20 15:29:23 -0700841 final NetworkPolicyManagerService networkPolicyF = networkPolicy;
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700842 final ConnectivityService connectivityF = connectivity;
843 final DockObserver dockF = dock;
Mike Lockwood770126a2010-12-09 22:30:37 -0800844 final UsbService usbF = usb;
Jeff Brown2416e092012-08-21 22:12:20 -0700845 final TwilightService twilightF = twilight;
Dianne Hackborn7299c412010-03-04 18:41:49 -0800846 final UiModeManagerService uiModeF = uiMode;
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700847 final AppWidgetService appWidgetF = appWidget;
848 final WallpaperManagerService wallpaperF = wallpaper;
849 final InputMethodManagerService immF = imm;
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800850 final RecognitionManagerService recognitionF = recognition;
Mike Lockwood46db5042010-02-22 16:36:44 -0500851 final LocationManagerService locationF = location;
Bai Taoa58a8752010-07-13 15:32:16 +0800852 final CountryDetectorService countryDetectorF = countryDetector;
Amith Yamasani6734b9f2010-09-13 16:24:08 -0700853 final NetworkTimeUpdateService networkTimeUpdaterF = networkTimeUpdater;
John Grossmanc1576732012-02-01 15:23:33 -0800854 final CommonTimeManagementService commonTimeMgmtServiceF = commonTimeMgmtService;
satok988323c2011-06-22 16:38:13 +0900855 final TextServicesManagerService textServiceManagerServiceF = tsms;
Dianne Hackborn661cd522011-08-22 00:26:20 -0700856 final StatusBarManagerService statusBarF = statusBar;
Daniel Sandler7d276c32012-01-30 14:33:52 -0500857 final DreamManagerService dreamyF = dreamy;
Jeff Brown6ec6f792012-04-17 16:52:41 -0700858 final InputManagerService inputManagerF = inputManager;
Wink Savillea12a7b32012-09-20 10:09:45 -0700859 final TelephonyRegistry telephonyRegistryF = telephonyRegistry;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800860
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700861 // We now tell the activity manager it is okay to run third party
862 // code. It will call back into us once it has gotten to the state
863 // where third party code can really run (but before it has actually
864 // started launching the initial applications), for us to complete our
865 // initialization.
Dianne Hackborn295e3c22011-08-25 13:19:08 -0700866 ActivityManagerService.self().systemReady(new Runnable() {
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700867 public void run() {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800868 Slog.i(TAG, "Making services ready");
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800869
Christopher Tate58d380d2013-03-19 13:10:03 -0700870 try {
871 ActivityManagerService.self().startObservingNativeCrashes();
872 } catch (Throwable e) {
873 reportWtf("observing native crashes", e);
874 }
Mike Lockwood3a74bd32011-08-12 13:55:22 -0700875 if (!headless) startSystemUi(contextF);
Dianne Hackborn661cd522011-08-22 00:26:20 -0700876 try {
Jeff Sharkeyb049e212012-09-07 23:16:01 -0700877 if (mountServiceF != null) mountServiceF.systemReady();
878 } catch (Throwable e) {
879 reportWtf("making Mount Service ready", e);
880 }
881 try {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700882 if (batteryF != null) batteryF.systemReady();
883 } catch (Throwable e) {
884 reportWtf("making Battery Service ready", e);
885 }
886 try {
887 if (networkManagementF != null) networkManagementF.systemReady();
888 } catch (Throwable e) {
889 reportWtf("making Network Managment Service ready", e);
890 }
891 try {
892 if (networkStatsF != null) networkStatsF.systemReady();
893 } catch (Throwable e) {
894 reportWtf("making Network Stats Service ready", e);
895 }
896 try {
897 if (networkPolicyF != null) networkPolicyF.systemReady();
898 } catch (Throwable e) {
899 reportWtf("making Network Policy Service ready", e);
900 }
901 try {
902 if (connectivityF != null) connectivityF.systemReady();
903 } catch (Throwable e) {
904 reportWtf("making Connectivity Service ready", e);
905 }
906 try {
907 if (dockF != null) dockF.systemReady();
908 } catch (Throwable e) {
909 reportWtf("making Dock Service ready", e);
910 }
911 try {
912 if (usbF != null) usbF.systemReady();
913 } catch (Throwable e) {
914 reportWtf("making USB Service ready", e);
915 }
916 try {
Jeff Brown2416e092012-08-21 22:12:20 -0700917 if (twilightF != null) twilightF.systemReady();
918 } catch (Throwable e) {
919 reportWtf("makin Twilight Service ready", e);
920 }
921 try {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700922 if (uiModeF != null) uiModeF.systemReady();
923 } catch (Throwable e) {
924 reportWtf("making UI Mode Service ready", e);
925 }
926 try {
927 if (recognitionF != null) recognitionF.systemReady();
928 } catch (Throwable e) {
929 reportWtf("making Recognition Service ready", e);
930 }
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700931 Watchdog.getInstance().start();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800932
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700933 // It is now okay to let the various system services start their
934 // third party code...
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800935
Dianne Hackborn661cd522011-08-22 00:26:20 -0700936 try {
937 if (appWidgetF != null) appWidgetF.systemReady(safeMode);
938 } catch (Throwable e) {
939 reportWtf("making App Widget Service ready", e);
940 }
941 try {
942 if (wallpaperF != null) wallpaperF.systemReady();
943 } catch (Throwable e) {
944 reportWtf("making Wallpaper Service ready", e);
945 }
946 try {
947 if (immF != null) immF.systemReady(statusBarF);
948 } catch (Throwable e) {
949 reportWtf("making Input Method Service ready", e);
950 }
951 try {
952 if (locationF != null) locationF.systemReady();
953 } catch (Throwable e) {
954 reportWtf("making Location Service ready", e);
955 }
956 try {
957 if (countryDetectorF != null) countryDetectorF.systemReady();
958 } catch (Throwable e) {
959 reportWtf("making Country Detector Service ready", e);
960 }
961 try {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700962 if (networkTimeUpdaterF != null) networkTimeUpdaterF.systemReady();
963 } catch (Throwable e) {
964 reportWtf("making Network Time Service ready", e);
965 }
966 try {
John Grossmanc1576732012-02-01 15:23:33 -0800967 if (commonTimeMgmtServiceF != null) commonTimeMgmtServiceF.systemReady();
968 } catch (Throwable e) {
969 reportWtf("making Common time management service ready", e);
970 }
971 try {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700972 if (textServiceManagerServiceF != null) textServiceManagerServiceF.systemReady();
973 } catch (Throwable e) {
974 reportWtf("making Text Services Manager Service ready", e);
975 }
Daniel Sandler7d276c32012-01-30 14:33:52 -0500976 try {
977 if (dreamyF != null) dreamyF.systemReady();
978 } catch (Throwable e) {
979 reportWtf("making DreamManagerService ready", e);
980 }
Jeff Brown6ec6f792012-04-17 16:52:41 -0700981 try {
Matthew Xie96313142012-06-29 16:57:31 -0700982 // TODO(BT) Pass parameter to input manager
983 if (inputManagerF != null) inputManagerF.systemReady();
Jeff Brown6ec6f792012-04-17 16:52:41 -0700984 } catch (Throwable e) {
985 reportWtf("making InputManagerService ready", e);
986 }
Wink Savillea12a7b32012-09-20 10:09:45 -0700987 try {
988 if (telephonyRegistryF != null) telephonyRegistryF.systemReady();
989 } catch (Throwable e) {
990 reportWtf("making TelephonyRegistry ready", e);
991 }
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700992 }
993 });
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800994
Brad Fitzpatrick1e02d362010-09-10 09:19:50 -0700995 // For debug builds, log event loop stalls to dropbox for analysis.
Brad Fitzpatrick50d66f92010-09-13 21:29:05 -0700996 if (StrictMode.conditionallyEnableDebugLogging()) {
997 Slog.i(TAG, "Enabled StrictMode for system server main thread.");
Brad Fitzpatrick1e02d362010-09-10 09:19:50 -0700998 }
999
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001000 Looper.loop();
Joe Onorato8a9b2202010-02-26 18:56:32 -08001001 Slog.d(TAG, "System ServerThread is exiting!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001002 }
Joe Onoratof3c3c4f2010-10-21 11:09:02 -04001003
1004 static final void startSystemUi(Context context) {
1005 Intent intent = new Intent();
1006 intent.setComponent(new ComponentName("com.android.systemui",
1007 "com.android.systemui.SystemUIService"));
Dianne Hackborn40e9f292012-11-27 19:12:23 -08001008 //Slog.d(TAG, "Starting service: " + intent);
Amith Yamasanicd757062012-10-19 18:23:52 -07001009 context.startServiceAsUser(intent, UserHandle.OWNER);
Joe Onoratof3c3c4f2010-10-21 11:09:02 -04001010 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001011}
1012
Jeff Hamilton35eef702010-06-09 15:45:18 -05001013public class SystemServer {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001014 private static final String TAG = "SystemServer";
1015
1016 public static final int FACTORY_TEST_OFF = 0;
1017 public static final int FACTORY_TEST_LOW_LEVEL = 1;
1018 public static final int FACTORY_TEST_HIGH_LEVEL = 2;
Jaikumar Ganeshd5ac1ae2009-05-05 22:26:12 -07001019
Bob Leee5408332009-09-04 18:31:17 -07001020 static Timer timer;
1021 static final long SNAPSHOT_INTERVAL = 60 * 60 * 1000; // 1hr
1022
Brad Fitzpatrick6bb7a4a2010-10-11 13:41:10 -07001023 // The earliest supported time. We pick one day into 1970, to
1024 // give any timezone code room without going into negative time.
1025 private static final long EARLIEST_SUPPORTED_TIME = 86400 * 1000;
1026
Jaikumar Ganeshd5ac1ae2009-05-05 22:26:12 -07001027 /**
1028 * 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 -08001029 * services (SurfaceFlinger, AudioFlinger, etc..) to be started. After that it will call back
1030 * up into init2() to start the Android services.
Jaikumar Ganeshd5ac1ae2009-05-05 22:26:12 -07001031 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001032 native public static void init1(String[] args);
1033
1034 public static void main(String[] args) {
Brad Fitzpatrick6bb7a4a2010-10-11 13:41:10 -07001035 if (System.currentTimeMillis() < EARLIEST_SUPPORTED_TIME) {
Brad Fitzpatrick35ca9d82010-10-11 11:52:49 -07001036 // If a device's clock is before 1970 (before 0), a lot of
1037 // APIs crash dealing with negative numbers, notably
1038 // java.io.File#setLastModified, so instead we fake it and
1039 // hope that time from cell towers or NTP fixes it
1040 // shortly.
1041 Slog.w(TAG, "System clock is before 1970; setting to 1970.");
Brad Fitzpatrick6bb7a4a2010-10-11 13:41:10 -07001042 SystemClock.setCurrentTimeMillis(EARLIEST_SUPPORTED_TIME);
Brad Fitzpatrick35ca9d82010-10-11 11:52:49 -07001043 }
1044
Bob Leee5408332009-09-04 18:31:17 -07001045 if (SamplingProfilerIntegration.isEnabled()) {
1046 SamplingProfilerIntegration.start();
1047 timer = new Timer();
1048 timer.schedule(new TimerTask() {
1049 @Override
1050 public void run() {
Sen Hubde75702010-05-28 01:54:03 -07001051 SamplingProfilerIntegration.writeSnapshot("system_server", null);
Bob Leee5408332009-09-04 18:31:17 -07001052 }
1053 }, SNAPSHOT_INTERVAL, SNAPSHOT_INTERVAL);
1054 }
1055
Dianne Hackbornac1471a2011-02-03 13:46:06 -08001056 // Mmmmmm... more memory!
1057 dalvik.system.VMRuntime.getRuntime().clearGrowthLimit();
1058
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001059 // The system server has to run all of the time, so it needs to be
1060 // as efficient as possible with its memory usage.
1061 VMRuntime.getRuntime().setTargetHeapUtilization(0.8f);
Sen Hubde75702010-05-28 01:54:03 -07001062
Jeff Sharkey48749fc2013-04-19 13:25:04 -07001063 Environment.setUserRequired(true);
1064
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001065 System.loadLibrary("android_servers");
1066 init1(args);
1067 }
1068
1069 public static final void init2() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001070 Slog.i(TAG, "Entered the Android system server!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001071 Thread thr = new ServerThread();
1072 thr.setName("android.server.ServerThread");
1073 thr.start();
1074 }
1075}