blob: a6de8ed534222cad93bc33b33b7b9ca73f9d57e7 [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
19import com.android.server.am.ActivityManagerService;
Kenny Rootf547d672010-09-22 10:36:48 -070020import com.android.internal.app.ShutdownThread;
Dianne Hackborn887f3552009-12-07 17:59:37 -080021import com.android.internal.os.BinderInternal;
Bob Leee5408332009-09-04 18:31:17 -070022import com.android.internal.os.SamplingProfilerIntegration;
Nick Pelly038cabe2010-09-23 16:12:11 -070023import com.trustedlogic.trustednfc.android.server.NfcService;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080024
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080025import dalvik.system.VMRuntime;
Ben Cheng6c0afff2010-02-14 16:18:56 -080026import dalvik.system.Zygote;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080027
Jeff Hamilton35eef702010-06-09 15:45:18 -050028import android.accounts.AccountManagerService;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080029import android.app.ActivityManagerNative;
Nick Pellyf242b7b2009-10-08 00:12:45 +020030import android.bluetooth.BluetoothAdapter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031import android.content.ContentResolver;
32import android.content.ContentService;
33import android.content.Context;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080034import android.content.pm.IPackageManager;
Joe Onoratodc565f42010-10-04 15:27:22 -040035import android.content.res.Configuration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080036import android.database.ContentObserver;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080037import android.media.AudioService;
Brad Fitzpatrickc74a1b442010-09-10 16:03:29 -070038import android.os.Build;
Jeff Hamilton35eef702010-06-09 15:45:18 -050039import android.os.Looper;
40import android.os.RemoteException;
41import android.os.ServiceManager;
Brad Fitzpatrickc74a1b442010-09-10 16:03:29 -070042import android.os.StrictMode;
Jeff Hamilton35eef702010-06-09 15:45:18 -050043import android.os.SystemClock;
44import android.os.SystemProperties;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080045import android.provider.Contacts.People;
46import android.provider.Settings;
47import android.server.BluetoothA2dpService;
Nick Pellybd022f42009-08-14 18:33:38 -070048import android.server.BluetoothService;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080049import android.server.search.SearchManagerService;
Joe Onoratodc565f42010-10-04 15:27:22 -040050import android.util.DisplayMetrics;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080051import android.util.EventLog;
Nick Pelly038cabe2010-09-23 16:12:11 -070052import android.util.Log;
Joe Onorato8a9b2202010-02-26 18:56:32 -080053import android.util.Slog;
Brad Fitzpatrick5fdc0c72010-10-12 13:12:18 -070054import android.view.Display;
55import android.view.WindowManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080056
Dan Egnor4410ec82009-09-11 16:40:01 -070057import java.io.File;
Bob Leee5408332009-09-04 18:31:17 -070058import java.util.Timer;
59import java.util.TimerTask;
60
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080061class ServerThread extends Thread {
62 private static final String TAG = "SystemServer";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080063
Jeff Hamilton35eef702010-06-09 15:45:18 -050064 ContentResolver mContentResolver;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080065
66 private class AdbSettingsObserver extends ContentObserver {
67 public AdbSettingsObserver() {
68 super(null);
69 }
70 @Override
71 public void onChange(boolean selfChange) {
72 boolean enableAdb = (Settings.Secure.getInt(mContentResolver,
73 Settings.Secure.ADB_ENABLED, 0) > 0);
74 // setting this secure property will start or stop adbd
75 SystemProperties.set("persist.service.adb.enable", enableAdb ? "1" : "0");
76 }
77 }
78
79 @Override
80 public void run() {
Doug Zongkerab5c49c2009-12-04 10:31:43 -080081 EventLog.writeEvent(EventLogTags.BOOT_PROGRESS_SYSTEM_RUN,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080082 SystemClock.uptimeMillis());
83
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080084 Looper.prepare();
85
86 android.os.Process.setThreadPriority(
87 android.os.Process.THREAD_PRIORITY_FOREGROUND);
88
Dianne Hackborn887f3552009-12-07 17:59:37 -080089 BinderInternal.disableBackgroundScheduling(true);
Christopher Tate160edb32010-06-30 17:46:30 -070090 android.os.Process.setCanSelfBackground(false);
Sen Hubde75702010-05-28 01:54:03 -070091
Kenny Rootf547d672010-09-22 10:36:48 -070092 // Check whether we failed to shut down last time we tried.
93 {
94 final String shutdownAction = SystemProperties.get(
95 ShutdownThread.SHUTDOWN_ACTION_PROPERTY, "");
96 if (shutdownAction != null && shutdownAction.length() > 0) {
97 boolean reboot = (shutdownAction.charAt(0) == '1');
98
99 final String reason;
100 if (shutdownAction.length() > 1) {
101 reason = shutdownAction.substring(1, shutdownAction.length());
102 } else {
103 reason = null;
104 }
105
106 ShutdownThread.rebootOrShutdown(reboot, reason);
107 }
108 }
109
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800110 String factoryTestStr = SystemProperties.get("ro.factorytest");
111 int factoryTest = "".equals(factoryTestStr) ? SystemServer.FACTORY_TEST_OFF
112 : Integer.parseInt(factoryTestStr);
113
Mike Lockwood3a322132009-11-24 00:30:52 -0500114 LightsService lights = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800115 PowerManagerService power = null;
Mike Lockwood07a500f2009-08-12 09:56:44 -0400116 BatteryService battery = null;
Mike Lockwood0f79b542009-08-14 14:18:49 -0400117 ConnectivityService connectivity = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800118 IPackageManager pm = null;
119 Context context = null;
120 WindowManagerService wm = null;
Nick Pellybd022f42009-08-14 18:33:38 -0700121 BluetoothService bluetooth = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800122 BluetoothA2dpService bluetoothA2dp = null;
123 HeadsetObserver headset = null;
Dan Murphyc9f4eaf2009-08-12 15:15:43 -0500124 DockObserver dock = null;
Mike Lockwood57c798a2010-06-23 17:36:36 -0400125 UsbObserver usb = null;
Dianne Hackborn7299c412010-03-04 18:41:49 -0800126 UiModeManagerService uiMode = null;
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800127 RecognitionManagerService recognition = null;
Robert Greenwalt9e696c22010-04-01 14:45:18 -0700128 ThrottleService throttle = null;
Amith Yamasani6734b9f62010-09-13 16:24:08 -0700129 NetworkTimeUpdateService networkTimeUpdater = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800130
131 // Critical services...
132 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800133 Slog.i(TAG, "Entropy Service");
Nick Kralevich4fb25612009-06-17 16:03:22 -0700134 ServiceManager.addService("entropy", new EntropyService());
135
Joe Onorato8a9b2202010-02-26 18:56:32 -0800136 Slog.i(TAG, "Power Manager");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800137 power = new PowerManagerService();
138 ServiceManager.addService(Context.POWER_SERVICE, power);
139
Joe Onorato8a9b2202010-02-26 18:56:32 -0800140 Slog.i(TAG, "Activity Manager");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800141 context = ActivityManagerService.main(factoryTest);
142
Joe Onorato8a9b2202010-02-26 18:56:32 -0800143 Slog.i(TAG, "Telephony Registry");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800144 ServiceManager.addService("telephony.registry", new TelephonyRegistry(context));
145
146 AttributeCache.init(context);
147
Joe Onorato8a9b2202010-02-26 18:56:32 -0800148 Slog.i(TAG, "Package Manager");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800149 pm = PackageManagerService.main(context,
150 factoryTest != SystemServer.FACTORY_TEST_OFF);
151
152 ActivityManagerService.setSystemProcess();
153
154 mContentResolver = context.getContentResolver();
155
Fred Quintanae91ebe22009-09-29 20:44:30 -0700156 // The AccountManager must come before the ContentService
Fred Quintana60307342009-03-24 22:48:12 -0700157 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800158 Slog.i(TAG, "Account Manager");
Fred Quintana60307342009-03-24 22:48:12 -0700159 ServiceManager.addService(Context.ACCOUNT_SERVICE,
160 new AccountManagerService(context));
161 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800162 Slog.e(TAG, "Failure starting Account Manager", e);
Fred Quintana60307342009-03-24 22:48:12 -0700163 }
164
Joe Onorato8a9b2202010-02-26 18:56:32 -0800165 Slog.i(TAG, "Content Manager");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800166 ContentService.main(context,
167 factoryTest == SystemServer.FACTORY_TEST_LOW_LEVEL);
168
Joe Onorato8a9b2202010-02-26 18:56:32 -0800169 Slog.i(TAG, "System Content Providers");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800170 ActivityManagerService.installSystemProviders();
171
Joe Onorato8a9b2202010-02-26 18:56:32 -0800172 Slog.i(TAG, "Battery Service");
Mike Lockwood07a500f2009-08-12 09:56:44 -0400173 battery = new BatteryService(context);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800174 ServiceManager.addService("battery", battery);
175
Joe Onorato8a9b2202010-02-26 18:56:32 -0800176 Slog.i(TAG, "Lights Service");
Mike Lockwood3a322132009-11-24 00:30:52 -0500177 lights = new LightsService(context);
178
Joe Onorato8a9b2202010-02-26 18:56:32 -0800179 Slog.i(TAG, "Vibrator Service");
Mike Lockwood3a322132009-11-24 00:30:52 -0500180 ServiceManager.addService("vibrator", new VibratorService(context));
The Android Open Source Project10592532009-03-18 17:39:46 -0700181
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800182 // only initialize the power service after we have started the
Mike Lockwood3a322132009-11-24 00:30:52 -0500183 // lights service, content providers and the battery service.
184 power.init(context, lights, ActivityManagerService.getDefault(), battery);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800185
Joe Onorato8a9b2202010-02-26 18:56:32 -0800186 Slog.i(TAG, "Alarm Manager");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800187 AlarmManagerService alarm = new AlarmManagerService(context);
188 ServiceManager.addService(Context.ALARM_SERVICE, alarm);
189
Joe Onorato8a9b2202010-02-26 18:56:32 -0800190 Slog.i(TAG, "Init Watchdog");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800191 Watchdog.getInstance().init(context, battery, power, alarm,
192 ActivityManagerService.self());
193
Joe Onorato8a9b2202010-02-26 18:56:32 -0800194 Slog.i(TAG, "Window Manager");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800195 wm = WindowManagerService.main(context, power,
196 factoryTest != SystemServer.FACTORY_TEST_LOW_LEVEL);
197 ServiceManager.addService(Context.WINDOW_SERVICE, wm);
198
199 ((ActivityManagerService)ServiceManager.getService("activity"))
200 .setWindowManager(wm);
201
202 // Skip Bluetooth if we have an emulator kernel
203 // TODO: Use a more reliable check to see if this product should
204 // support Bluetooth - see bug 988521
205 if (SystemProperties.get("ro.kernel.qemu").equals("1")) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800206 Slog.i(TAG, "Registering null Bluetooth Service (emulator)");
Nick Pellyf242b7b2009-10-08 00:12:45 +0200207 ServiceManager.addService(BluetoothAdapter.BLUETOOTH_SERVICE, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800208 } else if (factoryTest == SystemServer.FACTORY_TEST_LOW_LEVEL) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800209 Slog.i(TAG, "Registering null Bluetooth Service (factory test)");
Nick Pellyf242b7b2009-10-08 00:12:45 +0200210 ServiceManager.addService(BluetoothAdapter.BLUETOOTH_SERVICE, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800211 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800212 Slog.i(TAG, "Bluetooth Service");
Nick Pellybd022f42009-08-14 18:33:38 -0700213 bluetooth = new BluetoothService(context);
Nick Pellyf242b7b2009-10-08 00:12:45 +0200214 ServiceManager.addService(BluetoothAdapter.BLUETOOTH_SERVICE, bluetooth);
Nick Pellybd022f42009-08-14 18:33:38 -0700215 bluetooth.initAfterRegistration();
Jaikumar Ganeshd5ac1ae2009-05-05 22:26:12 -0700216 bluetoothA2dp = new BluetoothA2dpService(context, bluetooth);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800217 ServiceManager.addService(BluetoothA2dpService.BLUETOOTH_A2DP_SERVICE,
218 bluetoothA2dp);
219
220 int bluetoothOn = Settings.Secure.getInt(mContentResolver,
221 Settings.Secure.BLUETOOTH_ON, 0);
222 if (bluetoothOn > 0) {
The Android Open Source Project10592532009-03-18 17:39:46 -0700223 bluetooth.enable();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800224 }
225 }
226
227 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800228 Slog.e("System", "Failure starting core service", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800229 }
230
Dianne Hackbornd6847842010-01-12 18:14:19 -0800231 DevicePolicyManagerService devicePolicy = null;
Joe Onorato089de882010-04-12 08:18:45 -0700232 StatusBarManagerService statusBar = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800233 InputMethodManagerService imm = null;
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700234 AppWidgetService appWidget = null;
Joe Onorato30275482009-07-08 17:09:14 -0700235 NotificationManagerService notification = null;
Dianne Hackbornf21adf62009-08-13 10:20:21 -0700236 WallpaperManagerService wallpaper = null;
Mike Lockwood46db5042010-02-22 16:36:44 -0500237 LocationManagerService location = null;
Bai Taoa58a8752010-07-13 15:32:16 +0800238 CountryDetectorService countryDetector = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800239
240 if (factoryTest != SystemServer.FACTORY_TEST_LOW_LEVEL) {
241 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800242 Slog.i(TAG, "Device Policy");
Dianne Hackbornd6847842010-01-12 18:14:19 -0800243 devicePolicy = new DevicePolicyManagerService(context);
244 ServiceManager.addService(Context.DEVICE_POLICY_SERVICE, devicePolicy);
245 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800246 Slog.e(TAG, "Failure starting DevicePolicyService", e);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800247 }
248
249 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800250 Slog.i(TAG, "Status Bar");
Joe Onorato089de882010-04-12 08:18:45 -0700251 statusBar = new StatusBarManagerService(context);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800252 ServiceManager.addService(Context.STATUS_BAR_SERVICE, statusBar);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800253 } catch (Throwable e) {
Joe Onorato089de882010-04-12 08:18:45 -0700254 Slog.e(TAG, "Failure starting StatusBarManagerService", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800255 }
256
257 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800258 Slog.i(TAG, "Clipboard Service");
Dianne Hackbornd6847842010-01-12 18:14:19 -0800259 ServiceManager.addService(Context.CLIPBOARD_SERVICE,
260 new ClipboardService(context));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800261 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800262 Slog.e(TAG, "Failure starting Clipboard Service", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800263 }
264
265 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800266 Slog.i(TAG, "Input Method Service");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800267 imm = new InputMethodManagerService(context, statusBar);
268 ServiceManager.addService(Context.INPUT_METHOD_SERVICE, imm);
269 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800270 Slog.e(TAG, "Failure starting Input Manager Service", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800271 }
272
273 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800274 Slog.i(TAG, "NetStat Service");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800275 ServiceManager.addService("netstat", new NetStatService(context));
276 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800277 Slog.e(TAG, "Failure starting NetStat Service", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800278 }
279
280 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800281 Slog.i(TAG, "NetworkManagement Service");
San Mehatd1df8ac2010-01-26 06:17:26 -0800282 ServiceManager.addService(
Robert Greenwalte5c3afb2010-09-22 14:32:35 -0700283 Context.NETWORKMANAGEMENT_SERVICE,
284 NetworkManagementService.create(context));
San Mehatd1df8ac2010-01-26 06:17:26 -0800285 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800286 Slog.e(TAG, "Failure starting NetworkManagement Service", e);
San Mehatd1df8ac2010-01-26 06:17:26 -0800287 }
288
289 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800290 Slog.i(TAG, "Connectivity Service");
Mike Lockwood0f79b542009-08-14 14:18:49 -0400291 connectivity = ConnectivityService.getInstance(context);
292 ServiceManager.addService(Context.CONNECTIVITY_SERVICE, connectivity);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800293 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800294 Slog.e(TAG, "Failure starting Connectivity Service", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800295 }
296
297 try {
Robert Greenwalt9e696c22010-04-01 14:45:18 -0700298 Slog.i(TAG, "Throttle Service");
299 throttle = new ThrottleService(context);
300 ServiceManager.addService(
301 Context.THROTTLE_SERVICE, throttle);
302 } catch (Throwable e) {
303 Slog.e(TAG, "Failure starting ThrottleService", e);
304 }
305
306 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800307 Slog.i(TAG, "Accessibility Manager");
svetoslavganov75986cf2009-05-14 22:28:01 -0700308 ServiceManager.addService(Context.ACCESSIBILITY_SERVICE,
309 new AccessibilityManagerService(context));
310 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800311 Slog.e(TAG, "Failure starting Accessibility Manager", e);
svetoslavganov75986cf2009-05-14 22:28:01 -0700312 }
313
314 try {
San Mehat1bf3f8b2010-02-03 14:43:09 -0800315 /*
316 * NotificationManagerService is dependant on MountService,
317 * (for media / usb notifications) so we must start MountService first.
318 */
Joe Onorato8a9b2202010-02-26 18:56:32 -0800319 Slog.i(TAG, "Mount Service");
San Mehat1bf3f8b2010-02-03 14:43:09 -0800320 ServiceManager.addService("mount", new MountService(context));
321 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800322 Slog.e(TAG, "Failure starting Mount Service", e);
San Mehat1bf3f8b2010-02-03 14:43:09 -0800323 }
324
325 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800326 Slog.i(TAG, "Notification Manager");
Mike Lockwood3a322132009-11-24 00:30:52 -0500327 notification = new NotificationManagerService(context, statusBar, lights);
Joe Onorato30275482009-07-08 17:09:14 -0700328 ServiceManager.addService(Context.NOTIFICATION_SERVICE, notification);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800329 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800330 Slog.e(TAG, "Failure starting Notification Manager", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800331 }
332
333 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800334 Slog.i(TAG, "Device Storage Monitor");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800335 ServiceManager.addService(DeviceStorageMonitorService.SERVICE,
336 new DeviceStorageMonitorService(context));
337 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800338 Slog.e(TAG, "Failure starting DeviceStorageMonitor service", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800339 }
340
341 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800342 Slog.i(TAG, "Location Manager");
Mike Lockwood46db5042010-02-22 16:36:44 -0500343 location = new LocationManagerService(context);
344 ServiceManager.addService(Context.LOCATION_SERVICE, location);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800345 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800346 Slog.e(TAG, "Failure starting Location Manager", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800347 }
348
349 try {
Bai Taoa58a8752010-07-13 15:32:16 +0800350 Slog.i(TAG, "Country Detector");
351 countryDetector = new CountryDetectorService(context);
352 ServiceManager.addService(Context.COUNTRY_DETECTOR, countryDetector);
353 } catch (Throwable e) {
354 Slog.e(TAG, "Failure starting Country Detector", e);
355 }
356
357 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800358 Slog.i(TAG, "Search Service");
Dianne Hackbornd6847842010-01-12 18:14:19 -0800359 ServiceManager.addService(Context.SEARCH_SERVICE,
360 new SearchManagerService(context));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800361 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800362 Slog.e(TAG, "Failure starting Search Service", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800363 }
364
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800365 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800366 Slog.i(TAG, "DropBox Service");
Dan Egnor95240272009-10-27 18:23:39 -0700367 ServiceManager.addService(Context.DROPBOX_SERVICE,
Dan Egnorf18a01c2009-11-12 11:32:50 -0800368 new DropBoxManagerService(context, new File("/data/system/dropbox")));
Dan Egnor4410ec82009-09-11 16:40:01 -0700369 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800370 Slog.e(TAG, "Failure starting DropBoxManagerService", e);
Dan Egnor4410ec82009-09-11 16:40:01 -0700371 }
372
373 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800374 Slog.i(TAG, "Wallpaper Service");
Dianne Hackbornf21adf62009-08-13 10:20:21 -0700375 wallpaper = new WallpaperManagerService(context);
376 ServiceManager.addService(Context.WALLPAPER_SERVICE, wallpaper);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800377 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800378 Slog.e(TAG, "Failure starting Wallpaper Service", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800379 }
380
381 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800382 Slog.i(TAG, "Audio Service");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800383 ServiceManager.addService(Context.AUDIO_SERVICE, new AudioService(context));
384 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800385 Slog.e(TAG, "Failure starting Audio Service", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800386 }
387
388 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800389 Slog.i(TAG, "Headset Observer");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800390 // Listen for wired headset changes
391 headset = new HeadsetObserver(context);
392 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800393 Slog.e(TAG, "Failure starting HeadsetObserver", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800394 }
395
396 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800397 Slog.i(TAG, "Dock Observer");
Dan Murphyc9f4eaf2009-08-12 15:15:43 -0500398 // Listen for dock station changes
Ken Schultzf02c0742009-09-10 18:37:37 -0500399 dock = new DockObserver(context, power);
Dan Murphyc9f4eaf2009-08-12 15:15:43 -0500400 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800401 Slog.e(TAG, "Failure starting DockObserver", e);
Dan Murphyc9f4eaf2009-08-12 15:15:43 -0500402 }
403
404 try {
Mike Lockwood57c798a2010-06-23 17:36:36 -0400405 Slog.i(TAG, "USB Observer");
406 // Listen for USB changes
407 usb = new UsbObserver(context);
408 } catch (Throwable e) {
409 Slog.e(TAG, "Failure starting UsbObserver", e);
410 }
411
412 try {
Dianne Hackborn7299c412010-03-04 18:41:49 -0800413 Slog.i(TAG, "UI Mode Manager Service");
Mike Lockwood57c798a2010-06-23 17:36:36 -0400414 // Listen for UI mode changes
Dianne Hackborn7299c412010-03-04 18:41:49 -0800415 uiMode = new UiModeManagerService(context);
416 } catch (Throwable e) {
417 Slog.e(TAG, "Failure starting UiModeManagerService", e);
418 }
419
420 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800421 Slog.i(TAG, "Backup Service");
Dianne Hackbornd6847842010-01-12 18:14:19 -0800422 ServiceManager.addService(Context.BACKUP_SERVICE,
423 new BackupManagerService(context));
Christopher Tate487529a2009-04-29 14:03:25 -0700424 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800425 Slog.e(TAG, "Failure starting Backup Service", e);
Christopher Tate487529a2009-04-29 14:03:25 -0700426 }
427
428 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800429 Slog.i(TAG, "AppWidget Service");
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700430 appWidget = new AppWidgetService(context);
431 ServiceManager.addService(Context.APPWIDGET_SERVICE, appWidget);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800432 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800433 Slog.e(TAG, "Failure starting AppWidget Service", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800434 }
435
436 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800437 Slog.i(TAG, "Recognition Service");
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800438 recognition = new RecognitionManagerService(context);
439 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800440 Slog.e(TAG, "Failure starting Recognition Service", e);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800441 }
Nick Pelly038cabe2010-09-23 16:12:11 -0700442
443 try {
444 Slog.i(TAG, "Nfc Service");
445 NfcService nfc;
446 try {
447 nfc = new NfcService(context);
448 } catch (UnsatisfiedLinkError e) { // gross hack to detect NFC
449 nfc = null;
450 Slog.w(TAG, "No NFC support");
451 }
452 ServiceManager.addService(Context.NFC_SERVICE, nfc);
453 } catch (Throwable e) {
454 Slog.e(TAG, "Failure starting NFC Service", e);
455 }
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800456
457 try {
Dan Egnor621bc542010-03-25 16:20:14 -0700458 Slog.i(TAG, "DiskStats Service");
459 ServiceManager.addService("diskstats", new DiskStatsService(context));
460 } catch (Throwable e) {
461 Slog.e(TAG, "Failure starting DiskStats Service", e);
462 }
Sen Hubde75702010-05-28 01:54:03 -0700463
464 try {
465 // need to add this service even if SamplingProfilerIntegration.isEnabled()
466 // is false, because it is this service that detects system property change and
467 // turns on SamplingProfilerIntegration. Plus, when sampling profiler doesn't work,
468 // there is little overhead for running this service.
469 Slog.i(TAG, "SamplingProfiler Service");
470 ServiceManager.addService("samplingprofiler",
471 new SamplingProfilerService(context));
472 } catch (Throwable e) {
473 Slog.e(TAG, "Failure starting SamplingProfiler Service", e);
474 }
Chung-yih Wang024d5962010-08-06 12:06:04 +0800475
476 try {
Amith Yamasani6734b9f62010-09-13 16:24:08 -0700477 Slog.i(TAG, "NetworkTimeUpdateService");
478 networkTimeUpdater = new NetworkTimeUpdateService(context);
479 } catch (Throwable e) {
480 Slog.e(TAG, "Failure starting NetworkTimeUpdate service");
481 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800482 }
483
484 // make sure the ADB_ENABLED setting value matches the secure property value
485 Settings.Secure.putInt(mContentResolver, Settings.Secure.ADB_ENABLED,
486 "1".equals(SystemProperties.get("persist.service.adb.enable")) ? 1 : 0);
487
488 // register observer to listen for settings changes
489 mContentResolver.registerContentObserver(Settings.Secure.getUriFor(Settings.Secure.ADB_ENABLED),
490 false, new AdbSettingsObserver());
491
Dianne Hackborn6af0d502009-09-28 13:25:46 -0700492 // Before things start rolling, be sure we have decided whether
493 // we are in safe mode.
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700494 final boolean safeMode = wm.detectSafeMode();
Dianne Hackborn6af0d502009-09-28 13:25:46 -0700495 if (safeMode) {
496 try {
497 ActivityManagerNative.getDefault().enterSafeMode();
Ben Cheng6c0afff2010-02-14 16:18:56 -0800498 // Post the safe mode state in the Zygote class
499 Zygote.systemInSafeMode = true;
500 // Disable the JIT for the system_server process
501 VMRuntime.getRuntime().disableJitCompilation();
Dianne Hackborn6af0d502009-09-28 13:25:46 -0700502 } catch (RemoteException e) {
503 }
Ben Cheng6c0afff2010-02-14 16:18:56 -0800504 } else {
505 // Enable the JIT for the system_server process
506 VMRuntime.getRuntime().startJitCompilation();
Dianne Hackborn6af0d502009-09-28 13:25:46 -0700507 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800508
Dianne Hackborn6af0d502009-09-28 13:25:46 -0700509 // It is now time to start up the app processes...
Joe Onorato30275482009-07-08 17:09:14 -0700510
Dianne Hackbornd6847842010-01-12 18:14:19 -0800511 if (devicePolicy != null) {
512 devicePolicy.systemReady();
513 }
514
Joe Onorato30275482009-07-08 17:09:14 -0700515 if (notification != null) {
516 notification.systemReady();
517 }
518
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800519 if (statusBar != null) {
520 statusBar.systemReady();
521 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800522 wm.systemReady();
Joe Onoratodc565f42010-10-04 15:27:22 -0400523
524 // Update the configuration for this context by hand, because we're going
525 // to start using it before the config change done in wm.systemReady() will
526 // propagate to it.
527 Configuration config = wm.computeNewConfiguration();
528 DisplayMetrics metrics = new DisplayMetrics();
529 WindowManager w = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
530 w.getDefaultDisplay().getMetrics(metrics);
531 context.getResources().updateConfiguration(config, metrics);
532
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800533 power.systemReady();
534 try {
535 pm.systemReady();
536 } catch (RemoteException e) {
537 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800538
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700539 // These are needed to propagate to the runnable below.
Joe Onorato089de882010-04-12 08:18:45 -0700540 final StatusBarManagerService statusBarF = statusBar;
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700541 final BatteryService batteryF = battery;
542 final ConnectivityService connectivityF = connectivity;
543 final DockObserver dockF = dock;
Mike Lockwood57c798a2010-06-23 17:36:36 -0400544 final UsbObserver usbF = usb;
Robert Greenwalt9e696c22010-04-01 14:45:18 -0700545 final ThrottleService throttleF = throttle;
Dianne Hackborn7299c412010-03-04 18:41:49 -0800546 final UiModeManagerService uiModeF = uiMode;
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700547 final AppWidgetService appWidgetF = appWidget;
548 final WallpaperManagerService wallpaperF = wallpaper;
549 final InputMethodManagerService immF = imm;
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800550 final RecognitionManagerService recognitionF = recognition;
Mike Lockwood46db5042010-02-22 16:36:44 -0500551 final LocationManagerService locationF = location;
Bai Taoa58a8752010-07-13 15:32:16 +0800552 final CountryDetectorService countryDetectorF = countryDetector;
Amith Yamasani6734b9f62010-09-13 16:24:08 -0700553 final NetworkTimeUpdateService networkTimeUpdaterF = networkTimeUpdater;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800554
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700555 // We now tell the activity manager it is okay to run third party
556 // code. It will call back into us once it has gotten to the state
557 // where third party code can really run (but before it has actually
558 // started launching the initial applications), for us to complete our
559 // initialization.
560 ((ActivityManagerService)ActivityManagerNative.getDefault())
561 .systemReady(new Runnable() {
562 public void run() {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800563 Slog.i(TAG, "Making services ready");
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800564
Joe Onorato2314aab2010-04-08 16:41:23 -0500565 if (statusBarF != null) statusBarF.systemReady2();
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700566 if (batteryF != null) batteryF.systemReady();
567 if (connectivityF != null) connectivityF.systemReady();
568 if (dockF != null) dockF.systemReady();
Mike Lockwood57c798a2010-06-23 17:36:36 -0400569 if (usbF != null) usbF.systemReady();
Dianne Hackborn7299c412010-03-04 18:41:49 -0800570 if (uiModeF != null) uiModeF.systemReady();
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800571 if (recognitionF != null) recognitionF.systemReady();
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700572 Watchdog.getInstance().start();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800573
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700574 // It is now okay to let the various system services start their
575 // third party code...
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800576
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700577 if (appWidgetF != null) appWidgetF.systemReady(safeMode);
578 if (wallpaperF != null) wallpaperF.systemReady();
579 if (immF != null) immF.systemReady();
Mike Lockwood46db5042010-02-22 16:36:44 -0500580 if (locationF != null) locationF.systemReady();
Bai Taoa58a8752010-07-13 15:32:16 +0800581 if (countryDetectorF != null) countryDetectorF.systemReady();
Robert Greenwalt9e696c22010-04-01 14:45:18 -0700582 if (throttleF != null) throttleF.systemReady();
Amith Yamasani6734b9f62010-09-13 16:24:08 -0700583 if (networkTimeUpdaterF != null) networkTimeUpdaterF.systemReady();
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700584 }
585 });
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800586
Brad Fitzpatrick1e02d362010-09-10 09:19:50 -0700587 // For debug builds, log event loop stalls to dropbox for analysis.
Brad Fitzpatrick50d66f92010-09-13 21:29:05 -0700588 if (StrictMode.conditionallyEnableDebugLogging()) {
589 Slog.i(TAG, "Enabled StrictMode for system server main thread.");
Brad Fitzpatrick1e02d362010-09-10 09:19:50 -0700590 }
591
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800592 Looper.loop();
Joe Onorato8a9b2202010-02-26 18:56:32 -0800593 Slog.d(TAG, "System ServerThread is exiting!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800594 }
595}
596
Jeff Hamilton35eef702010-06-09 15:45:18 -0500597public class SystemServer {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800598 private static final String TAG = "SystemServer";
599
600 public static final int FACTORY_TEST_OFF = 0;
601 public static final int FACTORY_TEST_LOW_LEVEL = 1;
602 public static final int FACTORY_TEST_HIGH_LEVEL = 2;
Jaikumar Ganeshd5ac1ae2009-05-05 22:26:12 -0700603
Bob Leee5408332009-09-04 18:31:17 -0700604 static Timer timer;
605 static final long SNAPSHOT_INTERVAL = 60 * 60 * 1000; // 1hr
606
Brad Fitzpatrick6bb7a4a2010-10-11 13:41:10 -0700607 // The earliest supported time. We pick one day into 1970, to
608 // give any timezone code room without going into negative time.
609 private static final long EARLIEST_SUPPORTED_TIME = 86400 * 1000;
610
Jaikumar Ganeshd5ac1ae2009-05-05 22:26:12 -0700611 /**
612 * 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 -0800613 * services (SurfaceFlinger, AudioFlinger, etc..) to be started. After that it will call back
614 * up into init2() to start the Android services.
Jaikumar Ganeshd5ac1ae2009-05-05 22:26:12 -0700615 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800616 native public static void init1(String[] args);
617
618 public static void main(String[] args) {
Brad Fitzpatrick6bb7a4a2010-10-11 13:41:10 -0700619 if (System.currentTimeMillis() < EARLIEST_SUPPORTED_TIME) {
Brad Fitzpatrick35ca9d82010-10-11 11:52:49 -0700620 // If a device's clock is before 1970 (before 0), a lot of
621 // APIs crash dealing with negative numbers, notably
622 // java.io.File#setLastModified, so instead we fake it and
623 // hope that time from cell towers or NTP fixes it
624 // shortly.
625 Slog.w(TAG, "System clock is before 1970; setting to 1970.");
Brad Fitzpatrick6bb7a4a2010-10-11 13:41:10 -0700626 SystemClock.setCurrentTimeMillis(EARLIEST_SUPPORTED_TIME);
Brad Fitzpatrick35ca9d82010-10-11 11:52:49 -0700627 }
628
Bob Leee5408332009-09-04 18:31:17 -0700629 if (SamplingProfilerIntegration.isEnabled()) {
630 SamplingProfilerIntegration.start();
631 timer = new Timer();
632 timer.schedule(new TimerTask() {
633 @Override
634 public void run() {
Sen Hubde75702010-05-28 01:54:03 -0700635 SamplingProfilerIntegration.writeSnapshot("system_server", null);
Bob Leee5408332009-09-04 18:31:17 -0700636 }
637 }, SNAPSHOT_INTERVAL, SNAPSHOT_INTERVAL);
638 }
639
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800640 // The system server has to run all of the time, so it needs to be
641 // as efficient as possible with its memory usage.
642 VMRuntime.getRuntime().setTargetHeapUtilization(0.8f);
Sen Hubde75702010-05-28 01:54:03 -0700643
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800644 System.loadLibrary("android_servers");
645 init1(args);
646 }
647
648 public static final void init2() {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800649 Slog.i(TAG, "Entered the Android system server!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800650 Thread thr = new ServerThread();
651 thr.setName("android.server.ServerThread");
652 thr.start();
653 }
654}