blob: ab98249a8a70782047bf70481e10391c5c1d6fb3 [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
Jeff Hamilton35eef702010-06-09 15:45:18 -050027import android.accounts.AccountManagerService;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080028import android.app.ActivityManagerNative;
Nick Pellyf242b7b2009-10-08 00:12:45 +020029import android.bluetooth.BluetoothAdapter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080030import android.content.ContentResolver;
31import android.content.ContentService;
32import android.content.Context;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080033import android.content.pm.IPackageManager;
Joe Onoratodc565f42010-10-04 15:27:22 -040034import android.content.res.Configuration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080035import android.database.ContentObserver;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080036import android.media.AudioService;
Brad Fitzpatrickc74a1b442010-09-10 16:03:29 -070037import android.os.Build;
Jeff Hamilton35eef702010-06-09 15:45:18 -050038import android.os.Looper;
39import android.os.RemoteException;
40import android.os.ServiceManager;
Brad Fitzpatrickc74a1b442010-09-10 16:03:29 -070041import android.os.StrictMode;
Jeff Hamilton35eef702010-06-09 15:45:18 -050042import 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;
Joe Onoratodc565f42010-10-04 15:27:22 -040049import android.util.DisplayMetrics;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080050import android.util.EventLog;
Nick Pelly038cabe2010-09-23 16:12:11 -070051import android.util.Log;
Joe Onorato8a9b2202010-02-26 18:56:32 -080052import android.util.Slog;
Brad Fitzpatrick5fdc0c72010-10-12 13:12:18 -070053import android.view.Display;
54import android.view.WindowManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080055
Dan Egnor4410ec82009-09-11 16:40:01 -070056import java.io.File;
Bob Leee5408332009-09-04 18:31:17 -070057import java.util.Timer;
58import java.util.TimerTask;
59
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080060class ServerThread extends Thread {
61 private static final String TAG = "SystemServer";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080062
Jeff Hamilton35eef702010-06-09 15:45:18 -050063 ContentResolver mContentResolver;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080064
65 private class AdbSettingsObserver extends ContentObserver {
66 public AdbSettingsObserver() {
67 super(null);
68 }
69 @Override
70 public void onChange(boolean selfChange) {
71 boolean enableAdb = (Settings.Secure.getInt(mContentResolver,
72 Settings.Secure.ADB_ENABLED, 0) > 0);
73 // setting this secure property will start or stop adbd
74 SystemProperties.set("persist.service.adb.enable", enableAdb ? "1" : "0");
75 }
76 }
77
78 @Override
79 public void run() {
Doug Zongkerab5c49c2009-12-04 10:31:43 -080080 EventLog.writeEvent(EventLogTags.BOOT_PROGRESS_SYSTEM_RUN,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080081 SystemClock.uptimeMillis());
82
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080083 Looper.prepare();
84
85 android.os.Process.setThreadPriority(
86 android.os.Process.THREAD_PRIORITY_FOREGROUND);
87
Dianne Hackborn887f3552009-12-07 17:59:37 -080088 BinderInternal.disableBackgroundScheduling(true);
Christopher Tate160edb32010-06-30 17:46:30 -070089 android.os.Process.setCanSelfBackground(false);
Sen Hubde75702010-05-28 01:54:03 -070090
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080091 String factoryTestStr = SystemProperties.get("ro.factorytest");
92 int factoryTest = "".equals(factoryTestStr) ? SystemServer.FACTORY_TEST_OFF
93 : Integer.parseInt(factoryTestStr);
94
Mike Lockwood3a322132009-11-24 00:30:52 -050095 LightsService lights = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080096 PowerManagerService power = null;
Mike Lockwood07a500f2009-08-12 09:56:44 -040097 BatteryService battery = null;
Mike Lockwood0f79b542009-08-14 14:18:49 -040098 ConnectivityService connectivity = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080099 IPackageManager pm = null;
100 Context context = null;
101 WindowManagerService wm = null;
Nick Pellybd022f42009-08-14 18:33:38 -0700102 BluetoothService bluetooth = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800103 BluetoothA2dpService bluetoothA2dp = null;
104 HeadsetObserver headset = null;
Dan Murphyc9f4eaf2009-08-12 15:15:43 -0500105 DockObserver dock = null;
Mike Lockwood57c798a2010-06-23 17:36:36 -0400106 UsbObserver usb = null;
Dianne Hackborn7299c412010-03-04 18:41:49 -0800107 UiModeManagerService uiMode = null;
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800108 RecognitionManagerService recognition = null;
Robert Greenwalt9e696c22010-04-01 14:45:18 -0700109 ThrottleService throttle = null;
Amith Yamasani6734b9f2010-09-13 16:24:08 -0700110 NetworkTimeUpdateService networkTimeUpdater = 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;
Bai Taoa58a8752010-07-13 15:32:16 +0800219 CountryDetectorService countryDetector = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800220
221 if (factoryTest != SystemServer.FACTORY_TEST_LOW_LEVEL) {
222 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800223 Slog.i(TAG, "Device Policy");
Dianne Hackbornd6847842010-01-12 18:14:19 -0800224 devicePolicy = new DevicePolicyManagerService(context);
225 ServiceManager.addService(Context.DEVICE_POLICY_SERVICE, devicePolicy);
226 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800227 Slog.e(TAG, "Failure starting DevicePolicyService", e);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800228 }
229
230 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800231 Slog.i(TAG, "Status Bar");
Joe Onorato089de882010-04-12 08:18:45 -0700232 statusBar = new StatusBarManagerService(context);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800233 ServiceManager.addService(Context.STATUS_BAR_SERVICE, statusBar);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800234 } catch (Throwable e) {
Joe Onorato089de882010-04-12 08:18:45 -0700235 Slog.e(TAG, "Failure starting StatusBarManagerService", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800236 }
237
238 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800239 Slog.i(TAG, "Clipboard Service");
Dianne Hackbornd6847842010-01-12 18:14:19 -0800240 ServiceManager.addService(Context.CLIPBOARD_SERVICE,
241 new ClipboardService(context));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800242 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800243 Slog.e(TAG, "Failure starting Clipboard Service", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800244 }
245
246 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800247 Slog.i(TAG, "Input Method Service");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800248 imm = new InputMethodManagerService(context, statusBar);
249 ServiceManager.addService(Context.INPUT_METHOD_SERVICE, imm);
250 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800251 Slog.e(TAG, "Failure starting Input Manager Service", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800252 }
253
254 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800255 Slog.i(TAG, "NetStat Service");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800256 ServiceManager.addService("netstat", new NetStatService(context));
257 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800258 Slog.e(TAG, "Failure starting NetStat Service", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800259 }
260
261 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800262 Slog.i(TAG, "NetworkManagement Service");
San Mehatd1df8ac2010-01-26 06:17:26 -0800263 ServiceManager.addService(
Robert Greenwalte5c3afb2010-09-22 14:32:35 -0700264 Context.NETWORKMANAGEMENT_SERVICE,
265 NetworkManagementService.create(context));
San Mehatd1df8ac2010-01-26 06:17:26 -0800266 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800267 Slog.e(TAG, "Failure starting NetworkManagement Service", e);
San Mehatd1df8ac2010-01-26 06:17:26 -0800268 }
269
270 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800271 Slog.i(TAG, "Connectivity Service");
Mike Lockwood0f79b542009-08-14 14:18:49 -0400272 connectivity = ConnectivityService.getInstance(context);
273 ServiceManager.addService(Context.CONNECTIVITY_SERVICE, connectivity);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800274 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800275 Slog.e(TAG, "Failure starting Connectivity Service", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800276 }
277
278 try {
Robert Greenwalt9e696c22010-04-01 14:45:18 -0700279 Slog.i(TAG, "Throttle Service");
280 throttle = new ThrottleService(context);
281 ServiceManager.addService(
282 Context.THROTTLE_SERVICE, throttle);
283 } catch (Throwable e) {
284 Slog.e(TAG, "Failure starting ThrottleService", e);
285 }
286
287 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800288 Slog.i(TAG, "Accessibility Manager");
svetoslavganov75986cf2009-05-14 22:28:01 -0700289 ServiceManager.addService(Context.ACCESSIBILITY_SERVICE,
290 new AccessibilityManagerService(context));
291 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800292 Slog.e(TAG, "Failure starting Accessibility Manager", e);
svetoslavganov75986cf2009-05-14 22:28:01 -0700293 }
294
295 try {
San Mehat1bf3f8b2010-02-03 14:43:09 -0800296 /*
297 * NotificationManagerService is dependant on MountService,
298 * (for media / usb notifications) so we must start MountService first.
299 */
Joe Onorato8a9b2202010-02-26 18:56:32 -0800300 Slog.i(TAG, "Mount Service");
San Mehat1bf3f8b2010-02-03 14:43:09 -0800301 ServiceManager.addService("mount", new MountService(context));
302 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800303 Slog.e(TAG, "Failure starting Mount Service", e);
San Mehat1bf3f8b2010-02-03 14:43:09 -0800304 }
305
306 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800307 Slog.i(TAG, "Notification Manager");
Mike Lockwood3a322132009-11-24 00:30:52 -0500308 notification = new NotificationManagerService(context, statusBar, lights);
Joe Onorato30275482009-07-08 17:09:14 -0700309 ServiceManager.addService(Context.NOTIFICATION_SERVICE, notification);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800310 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800311 Slog.e(TAG, "Failure starting Notification Manager", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800312 }
313
314 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800315 Slog.i(TAG, "Device Storage Monitor");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800316 ServiceManager.addService(DeviceStorageMonitorService.SERVICE,
317 new DeviceStorageMonitorService(context));
318 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800319 Slog.e(TAG, "Failure starting DeviceStorageMonitor service", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800320 }
321
322 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800323 Slog.i(TAG, "Location Manager");
Mike Lockwood46db5042010-02-22 16:36:44 -0500324 location = new LocationManagerService(context);
325 ServiceManager.addService(Context.LOCATION_SERVICE, location);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800326 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800327 Slog.e(TAG, "Failure starting Location Manager", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800328 }
329
330 try {
Bai Taoa58a8752010-07-13 15:32:16 +0800331 Slog.i(TAG, "Country Detector");
332 countryDetector = new CountryDetectorService(context);
333 ServiceManager.addService(Context.COUNTRY_DETECTOR, countryDetector);
334 } catch (Throwable e) {
335 Slog.e(TAG, "Failure starting Country Detector", e);
336 }
337
338 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800339 Slog.i(TAG, "Search Service");
Dianne Hackbornd6847842010-01-12 18:14:19 -0800340 ServiceManager.addService(Context.SEARCH_SERVICE,
341 new SearchManagerService(context));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800342 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800343 Slog.e(TAG, "Failure starting Search Service", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800344 }
345
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800346 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800347 Slog.i(TAG, "DropBox Service");
Dan Egnor95240272009-10-27 18:23:39 -0700348 ServiceManager.addService(Context.DROPBOX_SERVICE,
Dan Egnorf18a01c2009-11-12 11:32:50 -0800349 new DropBoxManagerService(context, new File("/data/system/dropbox")));
Dan Egnor4410ec82009-09-11 16:40:01 -0700350 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800351 Slog.e(TAG, "Failure starting DropBoxManagerService", e);
Dan Egnor4410ec82009-09-11 16:40:01 -0700352 }
353
354 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800355 Slog.i(TAG, "Wallpaper Service");
Dianne Hackbornf21adf62009-08-13 10:20:21 -0700356 wallpaper = new WallpaperManagerService(context);
357 ServiceManager.addService(Context.WALLPAPER_SERVICE, wallpaper);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800358 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800359 Slog.e(TAG, "Failure starting Wallpaper Service", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800360 }
361
362 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800363 Slog.i(TAG, "Audio Service");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800364 ServiceManager.addService(Context.AUDIO_SERVICE, new AudioService(context));
365 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800366 Slog.e(TAG, "Failure starting Audio Service", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800367 }
368
369 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800370 Slog.i(TAG, "Headset Observer");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800371 // Listen for wired headset changes
372 headset = new HeadsetObserver(context);
373 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800374 Slog.e(TAG, "Failure starting HeadsetObserver", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800375 }
376
377 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800378 Slog.i(TAG, "Dock Observer");
Dan Murphyc9f4eaf2009-08-12 15:15:43 -0500379 // Listen for dock station changes
Ken Schultzf02c0742009-09-10 18:37:37 -0500380 dock = new DockObserver(context, power);
Dan Murphyc9f4eaf2009-08-12 15:15:43 -0500381 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800382 Slog.e(TAG, "Failure starting DockObserver", e);
Dan Murphyc9f4eaf2009-08-12 15:15:43 -0500383 }
384
385 try {
Mike Lockwood57c798a2010-06-23 17:36:36 -0400386 Slog.i(TAG, "USB Observer");
387 // Listen for USB changes
388 usb = new UsbObserver(context);
389 } catch (Throwable e) {
390 Slog.e(TAG, "Failure starting UsbObserver", e);
391 }
392
393 try {
Dianne Hackborn7299c412010-03-04 18:41:49 -0800394 Slog.i(TAG, "UI Mode Manager Service");
Mike Lockwood57c798a2010-06-23 17:36:36 -0400395 // Listen for UI mode changes
Dianne Hackborn7299c412010-03-04 18:41:49 -0800396 uiMode = new UiModeManagerService(context);
397 } catch (Throwable e) {
398 Slog.e(TAG, "Failure starting UiModeManagerService", e);
399 }
400
401 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800402 Slog.i(TAG, "Backup Service");
Dianne Hackbornd6847842010-01-12 18:14:19 -0800403 ServiceManager.addService(Context.BACKUP_SERVICE,
404 new BackupManagerService(context));
Christopher Tate487529a2009-04-29 14:03:25 -0700405 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800406 Slog.e(TAG, "Failure starting Backup Service", e);
Christopher Tate487529a2009-04-29 14:03:25 -0700407 }
408
409 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800410 Slog.i(TAG, "AppWidget Service");
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700411 appWidget = new AppWidgetService(context);
412 ServiceManager.addService(Context.APPWIDGET_SERVICE, appWidget);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800413 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800414 Slog.e(TAG, "Failure starting AppWidget Service", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800415 }
416
417 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800418 Slog.i(TAG, "Recognition Service");
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800419 recognition = new RecognitionManagerService(context);
420 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800421 Slog.e(TAG, "Failure starting Recognition Service", e);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800422 }
Nick Pelly038cabe2010-09-23 16:12:11 -0700423
424 try {
425 Slog.i(TAG, "Nfc Service");
426 NfcService nfc;
427 try {
428 nfc = new NfcService(context);
429 } catch (UnsatisfiedLinkError e) { // gross hack to detect NFC
430 nfc = null;
431 Slog.w(TAG, "No NFC support");
432 }
433 ServiceManager.addService(Context.NFC_SERVICE, nfc);
434 } catch (Throwable e) {
435 Slog.e(TAG, "Failure starting NFC Service", e);
436 }
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800437
438 try {
Dan Egnor621bc542010-03-25 16:20:14 -0700439 Slog.i(TAG, "DiskStats Service");
440 ServiceManager.addService("diskstats", new DiskStatsService(context));
441 } catch (Throwable e) {
442 Slog.e(TAG, "Failure starting DiskStats Service", e);
443 }
Sen Hubde75702010-05-28 01:54:03 -0700444
445 try {
446 // need to add this service even if SamplingProfilerIntegration.isEnabled()
447 // is false, because it is this service that detects system property change and
448 // turns on SamplingProfilerIntegration. Plus, when sampling profiler doesn't work,
449 // there is little overhead for running this service.
450 Slog.i(TAG, "SamplingProfiler Service");
451 ServiceManager.addService("samplingprofiler",
452 new SamplingProfilerService(context));
453 } catch (Throwable e) {
454 Slog.e(TAG, "Failure starting SamplingProfiler Service", e);
455 }
Chung-yih Wang024d5962010-08-06 12:06:04 +0800456
457 try {
Amith Yamasani6734b9f2010-09-13 16:24:08 -0700458 Slog.i(TAG, "NetworkTimeUpdateService");
459 networkTimeUpdater = new NetworkTimeUpdateService(context);
460 } catch (Throwable e) {
461 Slog.e(TAG, "Failure starting NetworkTimeUpdate service");
462 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800463 }
464
465 // make sure the ADB_ENABLED setting value matches the secure property value
466 Settings.Secure.putInt(mContentResolver, Settings.Secure.ADB_ENABLED,
467 "1".equals(SystemProperties.get("persist.service.adb.enable")) ? 1 : 0);
468
469 // register observer to listen for settings changes
470 mContentResolver.registerContentObserver(Settings.Secure.getUriFor(Settings.Secure.ADB_ENABLED),
471 false, new AdbSettingsObserver());
472
Dianne Hackborn6af0d502009-09-28 13:25:46 -0700473 // Before things start rolling, be sure we have decided whether
474 // we are in safe mode.
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700475 final boolean safeMode = wm.detectSafeMode();
Dianne Hackborn6af0d502009-09-28 13:25:46 -0700476 if (safeMode) {
477 try {
478 ActivityManagerNative.getDefault().enterSafeMode();
Ben Cheng6c0afff2010-02-14 16:18:56 -0800479 // Post the safe mode state in the Zygote class
480 Zygote.systemInSafeMode = true;
481 // Disable the JIT for the system_server process
482 VMRuntime.getRuntime().disableJitCompilation();
Dianne Hackborn6af0d502009-09-28 13:25:46 -0700483 } catch (RemoteException e) {
484 }
Ben Cheng6c0afff2010-02-14 16:18:56 -0800485 } else {
486 // Enable the JIT for the system_server process
487 VMRuntime.getRuntime().startJitCompilation();
Dianne Hackborn6af0d502009-09-28 13:25:46 -0700488 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800489
Dianne Hackborn6af0d502009-09-28 13:25:46 -0700490 // It is now time to start up the app processes...
Joe Onorato30275482009-07-08 17:09:14 -0700491
Dianne Hackbornd6847842010-01-12 18:14:19 -0800492 if (devicePolicy != null) {
493 devicePolicy.systemReady();
494 }
495
Joe Onorato30275482009-07-08 17:09:14 -0700496 if (notification != null) {
497 notification.systemReady();
498 }
499
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800500 if (statusBar != null) {
501 statusBar.systemReady();
502 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800503 wm.systemReady();
Joe Onoratodc565f42010-10-04 15:27:22 -0400504
505 // Update the configuration for this context by hand, because we're going
506 // to start using it before the config change done in wm.systemReady() will
507 // propagate to it.
508 Configuration config = wm.computeNewConfiguration();
509 DisplayMetrics metrics = new DisplayMetrics();
510 WindowManager w = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
511 w.getDefaultDisplay().getMetrics(metrics);
512 context.getResources().updateConfiguration(config, metrics);
513
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800514 power.systemReady();
515 try {
516 pm.systemReady();
517 } catch (RemoteException e) {
518 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800519
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700520 // These are needed to propagate to the runnable below.
Joe Onorato089de882010-04-12 08:18:45 -0700521 final StatusBarManagerService statusBarF = statusBar;
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700522 final BatteryService batteryF = battery;
523 final ConnectivityService connectivityF = connectivity;
524 final DockObserver dockF = dock;
Mike Lockwood57c798a2010-06-23 17:36:36 -0400525 final UsbObserver usbF = usb;
Robert Greenwalt9e696c22010-04-01 14:45:18 -0700526 final ThrottleService throttleF = throttle;
Dianne Hackborn7299c412010-03-04 18:41:49 -0800527 final UiModeManagerService uiModeF = uiMode;
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700528 final AppWidgetService appWidgetF = appWidget;
529 final WallpaperManagerService wallpaperF = wallpaper;
530 final InputMethodManagerService immF = imm;
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800531 final RecognitionManagerService recognitionF = recognition;
Mike Lockwood46db5042010-02-22 16:36:44 -0500532 final LocationManagerService locationF = location;
Bai Taoa58a8752010-07-13 15:32:16 +0800533 final CountryDetectorService countryDetectorF = countryDetector;
Amith Yamasani6734b9f2010-09-13 16:24:08 -0700534 final NetworkTimeUpdateService networkTimeUpdaterF = networkTimeUpdater;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800535
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700536 // We now tell the activity manager it is okay to run third party
537 // code. It will call back into us once it has gotten to the state
538 // where third party code can really run (but before it has actually
539 // started launching the initial applications), for us to complete our
540 // initialization.
541 ((ActivityManagerService)ActivityManagerNative.getDefault())
542 .systemReady(new Runnable() {
543 public void run() {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800544 Slog.i(TAG, "Making services ready");
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800545
Joe Onorato2314aab2010-04-08 16:41:23 -0500546 if (statusBarF != null) statusBarF.systemReady2();
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700547 if (batteryF != null) batteryF.systemReady();
548 if (connectivityF != null) connectivityF.systemReady();
549 if (dockF != null) dockF.systemReady();
Mike Lockwood57c798a2010-06-23 17:36:36 -0400550 if (usbF != null) usbF.systemReady();
Dianne Hackborn7299c412010-03-04 18:41:49 -0800551 if (uiModeF != null) uiModeF.systemReady();
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800552 if (recognitionF != null) recognitionF.systemReady();
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700553 Watchdog.getInstance().start();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800554
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700555 // It is now okay to let the various system services start their
556 // third party code...
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800557
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700558 if (appWidgetF != null) appWidgetF.systemReady(safeMode);
559 if (wallpaperF != null) wallpaperF.systemReady();
560 if (immF != null) immF.systemReady();
Mike Lockwood46db5042010-02-22 16:36:44 -0500561 if (locationF != null) locationF.systemReady();
Bai Taoa58a8752010-07-13 15:32:16 +0800562 if (countryDetectorF != null) countryDetectorF.systemReady();
Robert Greenwalt9e696c22010-04-01 14:45:18 -0700563 if (throttleF != null) throttleF.systemReady();
Amith Yamasani6734b9f2010-09-13 16:24:08 -0700564 if (networkTimeUpdaterF != null) networkTimeUpdaterF.systemReady();
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700565 }
566 });
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800567
Brad Fitzpatrick1e02d362010-09-10 09:19:50 -0700568 // For debug builds, log event loop stalls to dropbox for analysis.
Brad Fitzpatrick50d66f92010-09-13 21:29:05 -0700569 if (StrictMode.conditionallyEnableDebugLogging()) {
570 Slog.i(TAG, "Enabled StrictMode for system server main thread.");
Brad Fitzpatrick1e02d362010-09-10 09:19:50 -0700571 }
572
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800573 Looper.loop();
Joe Onorato8a9b2202010-02-26 18:56:32 -0800574 Slog.d(TAG, "System ServerThread is exiting!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800575 }
576}
577
Jeff Hamilton35eef702010-06-09 15:45:18 -0500578public class SystemServer {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800579 private static final String TAG = "SystemServer";
580
581 public static final int FACTORY_TEST_OFF = 0;
582 public static final int FACTORY_TEST_LOW_LEVEL = 1;
583 public static final int FACTORY_TEST_HIGH_LEVEL = 2;
Jaikumar Ganeshd5ac1ae2009-05-05 22:26:12 -0700584
Bob Leee5408332009-09-04 18:31:17 -0700585 static Timer timer;
586 static final long SNAPSHOT_INTERVAL = 60 * 60 * 1000; // 1hr
587
Jaikumar Ganeshd5ac1ae2009-05-05 22:26:12 -0700588 /**
589 * 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 -0800590 * services (SurfaceFlinger, AudioFlinger, etc..) to be started. After that it will call back
591 * up into init2() to start the Android services.
Jaikumar Ganeshd5ac1ae2009-05-05 22:26:12 -0700592 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800593 native public static void init1(String[] args);
594
595 public static void main(String[] args) {
Brad Fitzpatrick35ca9d82010-10-11 11:52:49 -0700596 if (System.currentTimeMillis() < 0) {
597 // If a device's clock is before 1970 (before 0), a lot of
598 // APIs crash dealing with negative numbers, notably
599 // java.io.File#setLastModified, so instead we fake it and
600 // hope that time from cell towers or NTP fixes it
601 // shortly.
602 Slog.w(TAG, "System clock is before 1970; setting to 1970.");
603 SystemClock.setCurrentTimeMillis(1); // 0 isn't allowed
604 }
605
Bob Leee5408332009-09-04 18:31:17 -0700606 if (SamplingProfilerIntegration.isEnabled()) {
607 SamplingProfilerIntegration.start();
608 timer = new Timer();
609 timer.schedule(new TimerTask() {
610 @Override
611 public void run() {
Sen Hubde75702010-05-28 01:54:03 -0700612 SamplingProfilerIntegration.writeSnapshot("system_server", null);
Bob Leee5408332009-09-04 18:31:17 -0700613 }
614 }, SNAPSHOT_INTERVAL, SNAPSHOT_INTERVAL);
615 }
616
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800617 // The system server has to run all of the time, so it needs to be
618 // as efficient as possible with its memory usage.
619 VMRuntime.getRuntime().setTargetHeapUtilization(0.8f);
Sen Hubde75702010-05-28 01:54:03 -0700620
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800621 System.loadLibrary("android_servers");
622 init1(args);
623 }
624
625 public static final void init2() {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800626 Slog.i(TAG, "Entered the Android system server!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800627 Thread thr = new ServerThread();
628 thr.setName("android.server.ServerThread");
629 thr.start();
630 }
631}