blob: a7785e2fdf308897a4d1464ed4f45ee405217a63 [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;
Dianne Hackborn887f3552009-12-07 17:59:37 -080020import com.android.internal.os.BinderInternal;
Bob Leee5408332009-09-04 18:31:17 -070021import com.android.internal.os.SamplingProfilerIntegration;
Nick Pelly038cabe2010-09-23 16:12:11 -070022import com.trustedlogic.trustednfc.android.server.NfcService;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080023
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080024import dalvik.system.VMRuntime;
Ben Cheng6c0afff2010-02-14 16:18:56 -080025import dalvik.system.Zygote;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080026
27import android.app.ActivityManagerNative;
Nick Pellyf242b7b2009-10-08 00:12:45 +020028import android.bluetooth.BluetoothAdapter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080029import android.content.ComponentName;
30import android.content.ContentResolver;
31import android.content.ContentService;
32import android.content.Context;
33import android.content.Intent;
34import android.content.pm.IPackageManager;
35import android.database.ContentObserver;
36import android.database.Cursor;
37import android.media.AudioService;
Brad Fitzpatrick35ca9d82010-10-11 11:52:49 -070038import android.os.Looper;
39import android.os.RemoteException;
40import android.os.ServiceManager;
41import android.os.StrictMode;
42import android.os.SystemClock;
43import android.os.SystemProperties;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080044import android.provider.Contacts.People;
45import android.provider.Settings;
46import android.server.BluetoothA2dpService;
Nick Pellybd022f42009-08-14 18:33:38 -070047import android.server.BluetoothService;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080048import android.server.search.SearchManagerService;
49import android.util.EventLog;
Nick Pelly038cabe2010-09-23 16:12:11 -070050import android.util.Log;
Joe Onorato8a9b2202010-02-26 18:56:32 -080051import android.util.Slog;
Fred Quintana60307342009-03-24 22:48:12 -070052import android.accounts.AccountManagerService;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080053
Dan Egnor4410ec82009-09-11 16:40:01 -070054import java.io.File;
Bob Leee5408332009-09-04 18:31:17 -070055import java.util.Timer;
56import java.util.TimerTask;
57
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080058class ServerThread extends Thread {
59 private static final String TAG = "SystemServer";
60 private final static boolean INCLUDE_DEMO = false;
61
62 private static final int LOG_BOOT_PROGRESS_SYSTEM_RUN = 3010;
63
64 private ContentResolver mContentResolver;
65
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);
91
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080092 String factoryTestStr = SystemProperties.get("ro.factorytest");
93 int factoryTest = "".equals(factoryTestStr) ? SystemServer.FACTORY_TEST_OFF
94 : Integer.parseInt(factoryTestStr);
95
Mike Lockwood3a322132009-11-24 00:30:52 -050096 LightsService lights = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080097 PowerManagerService power = null;
Mike Lockwood07a500f2009-08-12 09:56:44 -040098 BatteryService battery = null;
Mike Lockwood0f79b542009-08-14 14:18:49 -040099 ConnectivityService connectivity = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800100 IPackageManager pm = null;
101 Context context = null;
102 WindowManagerService wm = null;
Nick Pellybd022f42009-08-14 18:33:38 -0700103 BluetoothService bluetooth = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800104 BluetoothA2dpService bluetoothA2dp = null;
105 HeadsetObserver headset = null;
Dan Murphyc9f4eaf2009-08-12 15:15:43 -0500106 DockObserver dock = null;
Mike Lockwood24236072010-06-23 17:36:36 -0400107 UsbObserver usb = null;
Dianne Hackborn7299c412010-03-04 18:41:49 -0800108 UiModeManagerService uiMode = null;
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800109 RecognitionManagerService recognition = null;
Robert Greenwalt9e696c22010-04-01 14:45:18 -0700110 ThrottleService throttle = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800111
112 // Critical services...
113 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800114 Slog.i(TAG, "Entropy Service");
Nick Kralevich4fb25612009-06-17 16:03:22 -0700115 ServiceManager.addService("entropy", new EntropyService());
116
Joe Onorato8a9b2202010-02-26 18:56:32 -0800117 Slog.i(TAG, "Power Manager");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800118 power = new PowerManagerService();
119 ServiceManager.addService(Context.POWER_SERVICE, power);
120
Joe Onorato8a9b2202010-02-26 18:56:32 -0800121 Slog.i(TAG, "Activity Manager");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800122 context = ActivityManagerService.main(factoryTest);
123
Joe Onorato8a9b2202010-02-26 18:56:32 -0800124 Slog.i(TAG, "Telephony Registry");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800125 ServiceManager.addService("telephony.registry", new TelephonyRegistry(context));
126
127 AttributeCache.init(context);
128
Joe Onorato8a9b2202010-02-26 18:56:32 -0800129 Slog.i(TAG, "Package Manager");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800130 pm = PackageManagerService.main(context,
131 factoryTest != SystemServer.FACTORY_TEST_OFF);
132
133 ActivityManagerService.setSystemProcess();
134
135 mContentResolver = context.getContentResolver();
136
Fred Quintanae91ebe22009-09-29 20:44:30 -0700137 // The AccountManager must come before the ContentService
Fred Quintana60307342009-03-24 22:48:12 -0700138 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800139 Slog.i(TAG, "Account Manager");
Fred Quintana60307342009-03-24 22:48:12 -0700140 ServiceManager.addService(Context.ACCOUNT_SERVICE,
141 new AccountManagerService(context));
142 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800143 Slog.e(TAG, "Failure starting Account Manager", e);
Fred Quintana60307342009-03-24 22:48:12 -0700144 }
145
Joe Onorato8a9b2202010-02-26 18:56:32 -0800146 Slog.i(TAG, "Content Manager");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800147 ContentService.main(context,
148 factoryTest == SystemServer.FACTORY_TEST_LOW_LEVEL);
149
Joe Onorato8a9b2202010-02-26 18:56:32 -0800150 Slog.i(TAG, "System Content Providers");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800151 ActivityManagerService.installSystemProviders();
152
Joe Onorato8a9b2202010-02-26 18:56:32 -0800153 Slog.i(TAG, "Battery Service");
Mike Lockwood07a500f2009-08-12 09:56:44 -0400154 battery = new BatteryService(context);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800155 ServiceManager.addService("battery", battery);
156
Joe Onorato8a9b2202010-02-26 18:56:32 -0800157 Slog.i(TAG, "Lights Service");
Mike Lockwood3a322132009-11-24 00:30:52 -0500158 lights = new LightsService(context);
159
Joe Onorato8a9b2202010-02-26 18:56:32 -0800160 Slog.i(TAG, "Vibrator Service");
Mike Lockwood3a322132009-11-24 00:30:52 -0500161 ServiceManager.addService("vibrator", new VibratorService(context));
The Android Open Source Project10592532009-03-18 17:39:46 -0700162
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800163 // only initialize the power service after we have started the
Mike Lockwood3a322132009-11-24 00:30:52 -0500164 // lights service, content providers and the battery service.
165 power.init(context, lights, ActivityManagerService.getDefault(), battery);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800166
Joe Onorato8a9b2202010-02-26 18:56:32 -0800167 Slog.i(TAG, "Alarm Manager");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800168 AlarmManagerService alarm = new AlarmManagerService(context);
169 ServiceManager.addService(Context.ALARM_SERVICE, alarm);
170
Joe Onorato8a9b2202010-02-26 18:56:32 -0800171 Slog.i(TAG, "Init Watchdog");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800172 Watchdog.getInstance().init(context, battery, power, alarm,
173 ActivityManagerService.self());
174
Joe Onorato8a9b2202010-02-26 18:56:32 -0800175 Slog.i(TAG, "Window Manager");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800176 wm = WindowManagerService.main(context, power,
177 factoryTest != SystemServer.FACTORY_TEST_LOW_LEVEL);
178 ServiceManager.addService(Context.WINDOW_SERVICE, wm);
179
180 ((ActivityManagerService)ServiceManager.getService("activity"))
181 .setWindowManager(wm);
182
183 // Skip Bluetooth if we have an emulator kernel
184 // TODO: Use a more reliable check to see if this product should
185 // support Bluetooth - see bug 988521
186 if (SystemProperties.get("ro.kernel.qemu").equals("1")) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800187 Slog.i(TAG, "Registering null Bluetooth Service (emulator)");
Nick Pellyf242b7b2009-10-08 00:12:45 +0200188 ServiceManager.addService(BluetoothAdapter.BLUETOOTH_SERVICE, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800189 } else if (factoryTest == SystemServer.FACTORY_TEST_LOW_LEVEL) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800190 Slog.i(TAG, "Registering null Bluetooth Service (factory test)");
Nick Pellyf242b7b2009-10-08 00:12:45 +0200191 ServiceManager.addService(BluetoothAdapter.BLUETOOTH_SERVICE, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800192 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800193 Slog.i(TAG, "Bluetooth Service");
Nick Pellybd022f42009-08-14 18:33:38 -0700194 bluetooth = new BluetoothService(context);
Nick Pellyf242b7b2009-10-08 00:12:45 +0200195 ServiceManager.addService(BluetoothAdapter.BLUETOOTH_SERVICE, bluetooth);
Nick Pellybd022f42009-08-14 18:33:38 -0700196 bluetooth.initAfterRegistration();
Jaikumar Ganeshd5ac1ae2009-05-05 22:26:12 -0700197 bluetoothA2dp = new BluetoothA2dpService(context, bluetooth);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800198 ServiceManager.addService(BluetoothA2dpService.BLUETOOTH_A2DP_SERVICE,
199 bluetoothA2dp);
200
201 int bluetoothOn = Settings.Secure.getInt(mContentResolver,
202 Settings.Secure.BLUETOOTH_ON, 0);
203 if (bluetoothOn > 0) {
The Android Open Source Project10592532009-03-18 17:39:46 -0700204 bluetooth.enable();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800205 }
206 }
207
208 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800209 Slog.e("System", "Failure starting core service", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800210 }
211
Dianne Hackbornd6847842010-01-12 18:14:19 -0800212 DevicePolicyManagerService devicePolicy = null;
Joe Onorato089de882010-04-12 08:18:45 -0700213 StatusBarManagerService statusBar = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800214 InputMethodManagerService imm = null;
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700215 AppWidgetService appWidget = null;
Joe Onorato30275482009-07-08 17:09:14 -0700216 NotificationManagerService notification = null;
Dianne Hackbornf21adf62009-08-13 10:20:21 -0700217 WallpaperManagerService wallpaper = null;
Mike Lockwood46db5042010-02-22 16:36:44 -0500218 LocationManagerService location = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800219
220 if (factoryTest != SystemServer.FACTORY_TEST_LOW_LEVEL) {
221 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800222 Slog.i(TAG, "Device Policy");
Dianne Hackbornd6847842010-01-12 18:14:19 -0800223 devicePolicy = new DevicePolicyManagerService(context);
224 ServiceManager.addService(Context.DEVICE_POLICY_SERVICE, devicePolicy);
225 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800226 Slog.e(TAG, "Failure starting DevicePolicyService", e);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800227 }
228
229 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800230 Slog.i(TAG, "Status Bar");
Joe Onorato089de882010-04-12 08:18:45 -0700231 statusBar = new StatusBarManagerService(context);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800232 ServiceManager.addService(Context.STATUS_BAR_SERVICE, statusBar);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800233 } catch (Throwable e) {
Joe Onorato089de882010-04-12 08:18:45 -0700234 Slog.e(TAG, "Failure starting StatusBarManagerService", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800235 }
236
237 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800238 Slog.i(TAG, "Clipboard Service");
Dianne Hackbornd6847842010-01-12 18:14:19 -0800239 ServiceManager.addService(Context.CLIPBOARD_SERVICE,
240 new ClipboardService(context));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800241 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800242 Slog.e(TAG, "Failure starting Clipboard Service", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800243 }
244
245 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800246 Slog.i(TAG, "Input Method Service");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800247 imm = new InputMethodManagerService(context, statusBar);
248 ServiceManager.addService(Context.INPUT_METHOD_SERVICE, imm);
249 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800250 Slog.e(TAG, "Failure starting Input Manager Service", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800251 }
252
253 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800254 Slog.i(TAG, "NetStat Service");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800255 ServiceManager.addService("netstat", new NetStatService(context));
256 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800257 Slog.e(TAG, "Failure starting NetStat Service", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800258 }
259
260 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800261 Slog.i(TAG, "NetworkManagement Service");
San Mehatd1df8ac2010-01-26 06:17:26 -0800262 ServiceManager.addService(
Robert Greenwalte5c3afb2010-09-22 14:32:35 -0700263 Context.NETWORKMANAGEMENT_SERVICE,
264 NetworkManagementService.create(context));
San Mehatd1df8ac2010-01-26 06:17:26 -0800265 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800266 Slog.e(TAG, "Failure starting NetworkManagement Service", e);
San Mehatd1df8ac2010-01-26 06:17:26 -0800267 }
268
269 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800270 Slog.i(TAG, "Connectivity Service");
Mike Lockwood0f79b542009-08-14 14:18:49 -0400271 connectivity = ConnectivityService.getInstance(context);
272 ServiceManager.addService(Context.CONNECTIVITY_SERVICE, connectivity);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800273 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800274 Slog.e(TAG, "Failure starting Connectivity Service", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800275 }
276
277 try {
Robert Greenwalt9e696c22010-04-01 14:45:18 -0700278 Slog.i(TAG, "Throttle Service");
279 throttle = new ThrottleService(context);
280 ServiceManager.addService(
281 Context.THROTTLE_SERVICE, throttle);
282 } catch (Throwable e) {
283 Slog.e(TAG, "Failure starting ThrottleService", e);
284 }
285
286 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800287 Slog.i(TAG, "Accessibility Manager");
svetoslavganov75986cf2009-05-14 22:28:01 -0700288 ServiceManager.addService(Context.ACCESSIBILITY_SERVICE,
289 new AccessibilityManagerService(context));
290 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800291 Slog.e(TAG, "Failure starting Accessibility Manager", e);
svetoslavganov75986cf2009-05-14 22:28:01 -0700292 }
293
294 try {
San Mehat1bf3f8b2010-02-03 14:43:09 -0800295 /*
296 * NotificationManagerService is dependant on MountService,
297 * (for media / usb notifications) so we must start MountService first.
298 */
Joe Onorato8a9b2202010-02-26 18:56:32 -0800299 Slog.i(TAG, "Mount Service");
San Mehat1bf3f8b2010-02-03 14:43:09 -0800300 ServiceManager.addService("mount", new MountService(context));
301 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800302 Slog.e(TAG, "Failure starting Mount Service", e);
San Mehat1bf3f8b2010-02-03 14:43:09 -0800303 }
304
305 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800306 Slog.i(TAG, "Notification Manager");
Mike Lockwood3a322132009-11-24 00:30:52 -0500307 notification = new NotificationManagerService(context, statusBar, lights);
Joe Onorato30275482009-07-08 17:09:14 -0700308 ServiceManager.addService(Context.NOTIFICATION_SERVICE, notification);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800309 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800310 Slog.e(TAG, "Failure starting Notification Manager", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800311 }
312
313 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800314 Slog.i(TAG, "Device Storage Monitor");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800315 ServiceManager.addService(DeviceStorageMonitorService.SERVICE,
316 new DeviceStorageMonitorService(context));
317 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800318 Slog.e(TAG, "Failure starting DeviceStorageMonitor service", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800319 }
320
321 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800322 Slog.i(TAG, "Location Manager");
Mike Lockwood46db5042010-02-22 16:36:44 -0500323 location = new LocationManagerService(context);
324 ServiceManager.addService(Context.LOCATION_SERVICE, location);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800325 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800326 Slog.e(TAG, "Failure starting Location Manager", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800327 }
328
329 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800330 Slog.i(TAG, "Search Service");
Dianne Hackbornd6847842010-01-12 18:14:19 -0800331 ServiceManager.addService(Context.SEARCH_SERVICE,
332 new SearchManagerService(context));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800333 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800334 Slog.e(TAG, "Failure starting Search Service", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800335 }
336
337 if (INCLUDE_DEMO) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800338 Slog.i(TAG, "Installing demo data...");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800339 (new DemoThread(context)).start();
340 }
341
342 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800343 Slog.i(TAG, "DropBox Service");
Dan Egnor95240272009-10-27 18:23:39 -0700344 ServiceManager.addService(Context.DROPBOX_SERVICE,
Dan Egnorf18a01c2009-11-12 11:32:50 -0800345 new DropBoxManagerService(context, new File("/data/system/dropbox")));
Dan Egnor4410ec82009-09-11 16:40:01 -0700346 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800347 Slog.e(TAG, "Failure starting DropBoxManagerService", e);
Dan Egnor4410ec82009-09-11 16:40:01 -0700348 }
349
350 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800351 Slog.i(TAG, "Wallpaper Service");
Dianne Hackbornf21adf62009-08-13 10:20:21 -0700352 wallpaper = new WallpaperManagerService(context);
353 ServiceManager.addService(Context.WALLPAPER_SERVICE, wallpaper);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800354 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800355 Slog.e(TAG, "Failure starting Wallpaper Service", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800356 }
357
358 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800359 Slog.i(TAG, "Audio Service");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800360 ServiceManager.addService(Context.AUDIO_SERVICE, new AudioService(context));
361 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800362 Slog.e(TAG, "Failure starting Audio Service", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800363 }
364
365 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800366 Slog.i(TAG, "Headset Observer");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800367 // Listen for wired headset changes
368 headset = new HeadsetObserver(context);
369 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800370 Slog.e(TAG, "Failure starting HeadsetObserver", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800371 }
372
373 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800374 Slog.i(TAG, "Dock Observer");
Dan Murphyc9f4eaf2009-08-12 15:15:43 -0500375 // Listen for dock station changes
Ken Schultzf02c0742009-09-10 18:37:37 -0500376 dock = new DockObserver(context, power);
Dan Murphyc9f4eaf2009-08-12 15:15:43 -0500377 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800378 Slog.e(TAG, "Failure starting DockObserver", e);
Dan Murphyc9f4eaf2009-08-12 15:15:43 -0500379 }
380
381 try {
Mike Lockwood24236072010-06-23 17:36:36 -0400382 Slog.i(TAG, "USB Observer");
383 // Listen for USB changes
384 usb = new UsbObserver(context);
385 } catch (Throwable e) {
386 Slog.e(TAG, "Failure starting UsbObserver", e);
387 }
388
389 try {
Dianne Hackborn7299c412010-03-04 18:41:49 -0800390 Slog.i(TAG, "UI Mode Manager Service");
Mike Lockwood24236072010-06-23 17:36:36 -0400391 // Listen for UI mode changes
Dianne Hackborn7299c412010-03-04 18:41:49 -0800392 uiMode = new UiModeManagerService(context);
393 } catch (Throwable e) {
394 Slog.e(TAG, "Failure starting UiModeManagerService", e);
395 }
396
397 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800398 Slog.i(TAG, "Backup Service");
Dianne Hackbornd6847842010-01-12 18:14:19 -0800399 ServiceManager.addService(Context.BACKUP_SERVICE,
400 new BackupManagerService(context));
Christopher Tate487529a2009-04-29 14:03:25 -0700401 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800402 Slog.e(TAG, "Failure starting Backup Service", e);
Christopher Tate487529a2009-04-29 14:03:25 -0700403 }
404
405 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800406 Slog.i(TAG, "AppWidget Service");
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700407 appWidget = new AppWidgetService(context);
408 ServiceManager.addService(Context.APPWIDGET_SERVICE, appWidget);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800409 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800410 Slog.e(TAG, "Failure starting AppWidget Service", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800411 }
412
413 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800414 Slog.i(TAG, "Recognition Service");
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800415 recognition = new RecognitionManagerService(context);
416 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800417 Slog.e(TAG, "Failure starting Recognition Service", e);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800418 }
Nick Pelly038cabe2010-09-23 16:12:11 -0700419
420 try {
421 Slog.i(TAG, "Nfc Service");
422 NfcService nfc;
423 try {
424 nfc = new NfcService(context);
425 } catch (UnsatisfiedLinkError e) { // gross hack to detect NFC
426 nfc = null;
427 Slog.w(TAG, "No NFC support");
428 }
429 ServiceManager.addService(Context.NFC_SERVICE, nfc);
430 } catch (Throwable e) {
431 Slog.e(TAG, "Failure starting NFC Service", e);
432 }
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800433
434 try {
Dan Egnor621bc542010-03-25 16:20:14 -0700435 Slog.i(TAG, "DiskStats Service");
436 ServiceManager.addService("diskstats", new DiskStatsService(context));
437 } catch (Throwable e) {
438 Slog.e(TAG, "Failure starting DiskStats Service", e);
439 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800440 }
441
442 // make sure the ADB_ENABLED setting value matches the secure property value
443 Settings.Secure.putInt(mContentResolver, Settings.Secure.ADB_ENABLED,
444 "1".equals(SystemProperties.get("persist.service.adb.enable")) ? 1 : 0);
445
446 // register observer to listen for settings changes
447 mContentResolver.registerContentObserver(Settings.Secure.getUriFor(Settings.Secure.ADB_ENABLED),
448 false, new AdbSettingsObserver());
449
Dianne Hackborn6af0d502009-09-28 13:25:46 -0700450 // Before things start rolling, be sure we have decided whether
451 // we are in safe mode.
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700452 final boolean safeMode = wm.detectSafeMode();
Dianne Hackborn6af0d502009-09-28 13:25:46 -0700453 if (safeMode) {
454 try {
455 ActivityManagerNative.getDefault().enterSafeMode();
Ben Cheng6c0afff2010-02-14 16:18:56 -0800456 // Post the safe mode state in the Zygote class
457 Zygote.systemInSafeMode = true;
458 // Disable the JIT for the system_server process
459 VMRuntime.getRuntime().disableJitCompilation();
Dianne Hackborn6af0d502009-09-28 13:25:46 -0700460 } catch (RemoteException e) {
461 }
Ben Cheng6c0afff2010-02-14 16:18:56 -0800462 } else {
463 // Enable the JIT for the system_server process
464 VMRuntime.getRuntime().startJitCompilation();
Dianne Hackborn6af0d502009-09-28 13:25:46 -0700465 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800466
Dianne Hackborn6af0d502009-09-28 13:25:46 -0700467 // It is now time to start up the app processes...
Joe Onorato30275482009-07-08 17:09:14 -0700468
Dianne Hackbornd6847842010-01-12 18:14:19 -0800469 if (devicePolicy != null) {
470 devicePolicy.systemReady();
471 }
472
Joe Onorato30275482009-07-08 17:09:14 -0700473 if (notification != null) {
474 notification.systemReady();
475 }
476
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800477 if (statusBar != null) {
478 statusBar.systemReady();
479 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800480 wm.systemReady();
481 power.systemReady();
482 try {
483 pm.systemReady();
484 } catch (RemoteException e) {
485 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800486
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700487 // These are needed to propagate to the runnable below.
Joe Onorato089de882010-04-12 08:18:45 -0700488 final StatusBarManagerService statusBarF = statusBar;
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700489 final BatteryService batteryF = battery;
490 final ConnectivityService connectivityF = connectivity;
491 final DockObserver dockF = dock;
Mike Lockwood24236072010-06-23 17:36:36 -0400492 final UsbObserver usbF = usb;
Robert Greenwalt9e696c22010-04-01 14:45:18 -0700493 final ThrottleService throttleF = throttle;
Dianne Hackborn7299c412010-03-04 18:41:49 -0800494 final UiModeManagerService uiModeF = uiMode;
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700495 final AppWidgetService appWidgetF = appWidget;
496 final WallpaperManagerService wallpaperF = wallpaper;
497 final InputMethodManagerService immF = imm;
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800498 final RecognitionManagerService recognitionF = recognition;
Mike Lockwood46db5042010-02-22 16:36:44 -0500499 final LocationManagerService locationF = location;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800500
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700501 // We now tell the activity manager it is okay to run third party
502 // code. It will call back into us once it has gotten to the state
503 // where third party code can really run (but before it has actually
504 // started launching the initial applications), for us to complete our
505 // initialization.
506 ((ActivityManagerService)ActivityManagerNative.getDefault())
507 .systemReady(new Runnable() {
508 public void run() {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800509 Slog.i(TAG, "Making services ready");
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800510
Joe Onorato2314aab2010-04-08 16:41:23 -0500511 if (statusBarF != null) statusBarF.systemReady2();
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700512 if (batteryF != null) batteryF.systemReady();
513 if (connectivityF != null) connectivityF.systemReady();
514 if (dockF != null) dockF.systemReady();
Mike Lockwood24236072010-06-23 17:36:36 -0400515 if (usbF != null) usbF.systemReady();
Dianne Hackborn7299c412010-03-04 18:41:49 -0800516 if (uiModeF != null) uiModeF.systemReady();
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800517 if (recognitionF != null) recognitionF.systemReady();
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700518 Watchdog.getInstance().start();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800519
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700520 // It is now okay to let the various system services start their
521 // third party code...
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800522
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700523 if (appWidgetF != null) appWidgetF.systemReady(safeMode);
524 if (wallpaperF != null) wallpaperF.systemReady();
525 if (immF != null) immF.systemReady();
Mike Lockwood46db5042010-02-22 16:36:44 -0500526 if (locationF != null) locationF.systemReady();
Robert Greenwalt9e696c22010-04-01 14:45:18 -0700527 if (throttleF != null) throttleF.systemReady();
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700528 }
529 });
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800530
Brad Fitzpatrick1e02d362010-09-10 09:19:50 -0700531 // For debug builds, log event loop stalls to dropbox for analysis.
Brad Fitzpatrick50d66f92010-09-13 21:29:05 -0700532 if (StrictMode.conditionallyEnableDebugLogging()) {
533 Slog.i(TAG, "Enabled StrictMode for system server main thread.");
Brad Fitzpatrick1e02d362010-09-10 09:19:50 -0700534 }
535
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800536 Looper.loop();
Joe Onorato8a9b2202010-02-26 18:56:32 -0800537 Slog.d(TAG, "System ServerThread is exiting!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800538 }
539}
540
541class DemoThread extends Thread
542{
543 DemoThread(Context context)
544 {
545 mContext = context;
546 }
547
548 @Override
549 public void run()
550 {
551 try {
552 Cursor c = mContext.getContentResolver().query(People.CONTENT_URI, null, null, null, null);
553 boolean hasData = c != null && c.moveToFirst();
554 if (c != null) {
555 c.deactivate();
556 }
557 if (!hasData) {
558 DemoDataSet dataset = new DemoDataSet();
559 dataset.add(mContext);
560 }
561 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800562 Slog.e("SystemServer", "Failure installing demo data", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800563 }
564
565 }
566
567 Context mContext;
568}
569
570public class SystemServer
571{
572 private static final String TAG = "SystemServer";
573
574 public static final int FACTORY_TEST_OFF = 0;
575 public static final int FACTORY_TEST_LOW_LEVEL = 1;
576 public static final int FACTORY_TEST_HIGH_LEVEL = 2;
Jaikumar Ganeshd5ac1ae2009-05-05 22:26:12 -0700577
Bob Leee5408332009-09-04 18:31:17 -0700578 static Timer timer;
579 static final long SNAPSHOT_INTERVAL = 60 * 60 * 1000; // 1hr
580
Jaikumar Ganeshd5ac1ae2009-05-05 22:26:12 -0700581 /**
582 * 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 -0800583 * services (SurfaceFlinger, AudioFlinger, etc..) to be started. After that it will call back
584 * up into init2() to start the Android services.
Jaikumar Ganeshd5ac1ae2009-05-05 22:26:12 -0700585 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800586 native public static void init1(String[] args);
587
588 public static void main(String[] args) {
Brad Fitzpatrick35ca9d82010-10-11 11:52:49 -0700589 if (System.currentTimeMillis() < 0) {
590 // If a device's clock is before 1970 (before 0), a lot of
591 // APIs crash dealing with negative numbers, notably
592 // java.io.File#setLastModified, so instead we fake it and
593 // hope that time from cell towers or NTP fixes it
594 // shortly.
595 Slog.w(TAG, "System clock is before 1970; setting to 1970.");
596 SystemClock.setCurrentTimeMillis(1); // 0 isn't allowed
597 }
598
Bob Leee5408332009-09-04 18:31:17 -0700599 if (SamplingProfilerIntegration.isEnabled()) {
600 SamplingProfilerIntegration.start();
601 timer = new Timer();
602 timer.schedule(new TimerTask() {
603 @Override
604 public void run() {
605 SamplingProfilerIntegration.writeSnapshot("system_server");
606 }
607 }, SNAPSHOT_INTERVAL, SNAPSHOT_INTERVAL);
608 }
609
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800610 // The system server has to run all of the time, so it needs to be
611 // as efficient as possible with its memory usage.
612 VMRuntime.getRuntime().setTargetHeapUtilization(0.8f);
Dianne Hackborn2a9094d2010-02-03 19:20:09 -0800613
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800614 System.loadLibrary("android_servers");
615 init1(args);
616 }
617
618 public static final void init2() {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800619 Slog.i(TAG, "Entered the Android system server!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800620 Thread thr = new ServerThread();
621 thr.setName("android.server.ServerThread");
622 thr.start();
623 }
624}