blob: 80dcc98d2792d2111423f78ba7b3bb411c3dc063 [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.Settings;
45import android.server.BluetoothA2dpService;
Nick Pellybd022f42009-08-14 18:33:38 -070046import android.server.BluetoothService;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080047import android.server.search.SearchManagerService;
Joe Onoratodc565f42010-10-04 15:27:22 -040048import android.view.Display;
49import android.view.WindowManager;
50import 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;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080054
Dan Egnor4410ec82009-09-11 16:40:01 -070055import java.io.File;
Bob Leee5408332009-09-04 18:31:17 -070056import java.util.Timer;
57import java.util.TimerTask;
58
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080059class ServerThread extends Thread {
60 private static final String TAG = "SystemServer";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080061
Jeff Hamilton35eef702010-06-09 15:45:18 -050062 ContentResolver mContentResolver;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080063
64 private class AdbSettingsObserver extends ContentObserver {
65 public AdbSettingsObserver() {
66 super(null);
67 }
68 @Override
69 public void onChange(boolean selfChange) {
70 boolean enableAdb = (Settings.Secure.getInt(mContentResolver,
71 Settings.Secure.ADB_ENABLED, 0) > 0);
72 // setting this secure property will start or stop adbd
73 SystemProperties.set("persist.service.adb.enable", enableAdb ? "1" : "0");
74 }
75 }
76
77 @Override
78 public void run() {
Doug Zongkerab5c49c2009-12-04 10:31:43 -080079 EventLog.writeEvent(EventLogTags.BOOT_PROGRESS_SYSTEM_RUN,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080080 SystemClock.uptimeMillis());
81
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080082 Looper.prepare();
83
84 android.os.Process.setThreadPriority(
85 android.os.Process.THREAD_PRIORITY_FOREGROUND);
86
Dianne Hackborn887f3552009-12-07 17:59:37 -080087 BinderInternal.disableBackgroundScheduling(true);
Christopher Tate160edb32010-06-30 17:46:30 -070088 android.os.Process.setCanSelfBackground(false);
Sen Hubde75702010-05-28 01:54:03 -070089
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080090 String factoryTestStr = SystemProperties.get("ro.factorytest");
91 int factoryTest = "".equals(factoryTestStr) ? SystemServer.FACTORY_TEST_OFF
92 : Integer.parseInt(factoryTestStr);
93
Mike Lockwood3a322132009-11-24 00:30:52 -050094 LightsService lights = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080095 PowerManagerService power = null;
Mike Lockwood07a500f2009-08-12 09:56:44 -040096 BatteryService battery = null;
Mike Lockwood0f79b542009-08-14 14:18:49 -040097 ConnectivityService connectivity = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080098 IPackageManager pm = null;
99 Context context = null;
100 WindowManagerService wm = null;
Nick Pellybd022f42009-08-14 18:33:38 -0700101 BluetoothService bluetooth = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800102 BluetoothA2dpService bluetoothA2dp = null;
103 HeadsetObserver headset = null;
Dan Murphyc9f4eaf2009-08-12 15:15:43 -0500104 DockObserver dock = null;
Mike Lockwood57c798a2010-06-23 17:36:36 -0400105 UsbObserver usb = null;
Dianne Hackborn7299c412010-03-04 18:41:49 -0800106 UiModeManagerService uiMode = null;
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800107 RecognitionManagerService recognition = null;
Robert Greenwalt9e696c22010-04-01 14:45:18 -0700108 ThrottleService throttle = null;
Amith Yamasani6734b9f2010-09-13 16:24:08 -0700109 NetworkTimeUpdateService networkTimeUpdater = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800110
111 // Critical services...
112 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800113 Slog.i(TAG, "Entropy Service");
Nick Kralevich4fb25612009-06-17 16:03:22 -0700114 ServiceManager.addService("entropy", new EntropyService());
115
Joe Onorato8a9b2202010-02-26 18:56:32 -0800116 Slog.i(TAG, "Power Manager");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800117 power = new PowerManagerService();
118 ServiceManager.addService(Context.POWER_SERVICE, power);
119
Joe Onorato8a9b2202010-02-26 18:56:32 -0800120 Slog.i(TAG, "Activity Manager");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800121 context = ActivityManagerService.main(factoryTest);
122
Joe Onorato8a9b2202010-02-26 18:56:32 -0800123 Slog.i(TAG, "Telephony Registry");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800124 ServiceManager.addService("telephony.registry", new TelephonyRegistry(context));
125
126 AttributeCache.init(context);
127
Joe Onorato8a9b2202010-02-26 18:56:32 -0800128 Slog.i(TAG, "Package Manager");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800129 pm = PackageManagerService.main(context,
130 factoryTest != SystemServer.FACTORY_TEST_OFF);
131
132 ActivityManagerService.setSystemProcess();
133
134 mContentResolver = context.getContentResolver();
135
Fred Quintanae91ebe22009-09-29 20:44:30 -0700136 // The AccountManager must come before the ContentService
Fred Quintana60307342009-03-24 22:48:12 -0700137 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800138 Slog.i(TAG, "Account Manager");
Fred Quintana60307342009-03-24 22:48:12 -0700139 ServiceManager.addService(Context.ACCOUNT_SERVICE,
140 new AccountManagerService(context));
141 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800142 Slog.e(TAG, "Failure starting Account Manager", e);
Fred Quintana60307342009-03-24 22:48:12 -0700143 }
144
Joe Onorato8a9b2202010-02-26 18:56:32 -0800145 Slog.i(TAG, "Content Manager");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800146 ContentService.main(context,
147 factoryTest == SystemServer.FACTORY_TEST_LOW_LEVEL);
148
Joe Onorato8a9b2202010-02-26 18:56:32 -0800149 Slog.i(TAG, "System Content Providers");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800150 ActivityManagerService.installSystemProviders();
151
Joe Onorato8a9b2202010-02-26 18:56:32 -0800152 Slog.i(TAG, "Battery Service");
Mike Lockwood07a500f2009-08-12 09:56:44 -0400153 battery = new BatteryService(context);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800154 ServiceManager.addService("battery", battery);
155
Joe Onorato8a9b2202010-02-26 18:56:32 -0800156 Slog.i(TAG, "Lights Service");
Mike Lockwood3a322132009-11-24 00:30:52 -0500157 lights = new LightsService(context);
158
Joe Onorato8a9b2202010-02-26 18:56:32 -0800159 Slog.i(TAG, "Vibrator Service");
Mike Lockwood3a322132009-11-24 00:30:52 -0500160 ServiceManager.addService("vibrator", new VibratorService(context));
The Android Open Source Project10592532009-03-18 17:39:46 -0700161
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800162 // only initialize the power service after we have started the
Mike Lockwood3a322132009-11-24 00:30:52 -0500163 // lights service, content providers and the battery service.
164 power.init(context, lights, ActivityManagerService.getDefault(), battery);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800165
Joe Onorato8a9b2202010-02-26 18:56:32 -0800166 Slog.i(TAG, "Alarm Manager");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800167 AlarmManagerService alarm = new AlarmManagerService(context);
168 ServiceManager.addService(Context.ALARM_SERVICE, alarm);
169
Joe Onorato8a9b2202010-02-26 18:56:32 -0800170 Slog.i(TAG, "Init Watchdog");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800171 Watchdog.getInstance().init(context, battery, power, alarm,
172 ActivityManagerService.self());
173
Joe Onorato8a9b2202010-02-26 18:56:32 -0800174 Slog.i(TAG, "Window Manager");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800175 wm = WindowManagerService.main(context, power,
176 factoryTest != SystemServer.FACTORY_TEST_LOW_LEVEL);
177 ServiceManager.addService(Context.WINDOW_SERVICE, wm);
178
179 ((ActivityManagerService)ServiceManager.getService("activity"))
180 .setWindowManager(wm);
181
182 // Skip Bluetooth if we have an emulator kernel
183 // TODO: Use a more reliable check to see if this product should
184 // support Bluetooth - see bug 988521
185 if (SystemProperties.get("ro.kernel.qemu").equals("1")) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800186 Slog.i(TAG, "Registering null Bluetooth Service (emulator)");
Nick Pellyf242b7b2009-10-08 00:12:45 +0200187 ServiceManager.addService(BluetoothAdapter.BLUETOOTH_SERVICE, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800188 } else if (factoryTest == SystemServer.FACTORY_TEST_LOW_LEVEL) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800189 Slog.i(TAG, "Registering null Bluetooth Service (factory test)");
Nick Pellyf242b7b2009-10-08 00:12:45 +0200190 ServiceManager.addService(BluetoothAdapter.BLUETOOTH_SERVICE, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800191 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800192 Slog.i(TAG, "Bluetooth Service");
Nick Pellybd022f42009-08-14 18:33:38 -0700193 bluetooth = new BluetoothService(context);
Nick Pellyf242b7b2009-10-08 00:12:45 +0200194 ServiceManager.addService(BluetoothAdapter.BLUETOOTH_SERVICE, bluetooth);
Nick Pellybd022f42009-08-14 18:33:38 -0700195 bluetooth.initAfterRegistration();
Jaikumar Ganeshd5ac1ae2009-05-05 22:26:12 -0700196 bluetoothA2dp = new BluetoothA2dpService(context, bluetooth);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800197 ServiceManager.addService(BluetoothA2dpService.BLUETOOTH_A2DP_SERVICE,
198 bluetoothA2dp);
199
200 int bluetoothOn = Settings.Secure.getInt(mContentResolver,
201 Settings.Secure.BLUETOOTH_ON, 0);
202 if (bluetoothOn > 0) {
The Android Open Source Project10592532009-03-18 17:39:46 -0700203 bluetooth.enable();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800204 }
205 }
206
207 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800208 Slog.e("System", "Failure starting core service", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800209 }
210
Dianne Hackbornd6847842010-01-12 18:14:19 -0800211 DevicePolicyManagerService devicePolicy = null;
Joe Onorato089de882010-04-12 08:18:45 -0700212 StatusBarManagerService statusBar = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800213 InputMethodManagerService imm = null;
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700214 AppWidgetService appWidget = null;
Joe Onorato30275482009-07-08 17:09:14 -0700215 NotificationManagerService notification = null;
Dianne Hackbornf21adf62009-08-13 10:20:21 -0700216 WallpaperManagerService wallpaper = null;
Mike Lockwood46db5042010-02-22 16:36:44 -0500217 LocationManagerService location = null;
Bai Taoa58a8752010-07-13 15:32:16 +0800218 CountryDetectorService countryDetector = 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 {
Bai Taoa58a8752010-07-13 15:32:16 +0800330 Slog.i(TAG, "Country Detector");
331 countryDetector = new CountryDetectorService(context);
332 ServiceManager.addService(Context.COUNTRY_DETECTOR, countryDetector);
333 } catch (Throwable e) {
334 Slog.e(TAG, "Failure starting Country Detector", e);
335 }
336
337 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800338 Slog.i(TAG, "Search Service");
Dianne Hackbornd6847842010-01-12 18:14:19 -0800339 ServiceManager.addService(Context.SEARCH_SERVICE,
340 new SearchManagerService(context));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800341 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800342 Slog.e(TAG, "Failure starting Search Service", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800343 }
344
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800345 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800346 Slog.i(TAG, "DropBox Service");
Dan Egnor95240272009-10-27 18:23:39 -0700347 ServiceManager.addService(Context.DROPBOX_SERVICE,
Dan Egnorf18a01c2009-11-12 11:32:50 -0800348 new DropBoxManagerService(context, new File("/data/system/dropbox")));
Dan Egnor4410ec82009-09-11 16:40:01 -0700349 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800350 Slog.e(TAG, "Failure starting DropBoxManagerService", e);
Dan Egnor4410ec82009-09-11 16:40:01 -0700351 }
352
353 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800354 Slog.i(TAG, "Wallpaper Service");
Dianne Hackbornf21adf62009-08-13 10:20:21 -0700355 wallpaper = new WallpaperManagerService(context);
356 ServiceManager.addService(Context.WALLPAPER_SERVICE, wallpaper);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800357 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800358 Slog.e(TAG, "Failure starting Wallpaper Service", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800359 }
360
361 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800362 Slog.i(TAG, "Audio Service");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800363 ServiceManager.addService(Context.AUDIO_SERVICE, new AudioService(context));
364 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800365 Slog.e(TAG, "Failure starting Audio Service", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800366 }
367
368 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800369 Slog.i(TAG, "Headset Observer");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800370 // Listen for wired headset changes
371 headset = new HeadsetObserver(context);
372 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800373 Slog.e(TAG, "Failure starting HeadsetObserver", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800374 }
375
376 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800377 Slog.i(TAG, "Dock Observer");
Dan Murphyc9f4eaf2009-08-12 15:15:43 -0500378 // Listen for dock station changes
Ken Schultzf02c0742009-09-10 18:37:37 -0500379 dock = new DockObserver(context, power);
Dan Murphyc9f4eaf2009-08-12 15:15:43 -0500380 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800381 Slog.e(TAG, "Failure starting DockObserver", e);
Dan Murphyc9f4eaf2009-08-12 15:15:43 -0500382 }
383
384 try {
Mike Lockwood57c798a2010-06-23 17:36:36 -0400385 Slog.i(TAG, "USB Observer");
386 // Listen for USB changes
387 usb = new UsbObserver(context);
388 } catch (Throwable e) {
389 Slog.e(TAG, "Failure starting UsbObserver", e);
390 }
391
392 try {
Dianne Hackborn7299c412010-03-04 18:41:49 -0800393 Slog.i(TAG, "UI Mode Manager Service");
Mike Lockwood57c798a2010-06-23 17:36:36 -0400394 // Listen for UI mode changes
Dianne Hackborn7299c412010-03-04 18:41:49 -0800395 uiMode = new UiModeManagerService(context);
396 } catch (Throwable e) {
397 Slog.e(TAG, "Failure starting UiModeManagerService", e);
398 }
399
400 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800401 Slog.i(TAG, "Backup Service");
Dianne Hackbornd6847842010-01-12 18:14:19 -0800402 ServiceManager.addService(Context.BACKUP_SERVICE,
403 new BackupManagerService(context));
Christopher Tate487529a2009-04-29 14:03:25 -0700404 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800405 Slog.e(TAG, "Failure starting Backup Service", e);
Christopher Tate487529a2009-04-29 14:03:25 -0700406 }
407
408 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800409 Slog.i(TAG, "AppWidget Service");
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700410 appWidget = new AppWidgetService(context);
411 ServiceManager.addService(Context.APPWIDGET_SERVICE, appWidget);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800412 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800413 Slog.e(TAG, "Failure starting AppWidget Service", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800414 }
415
416 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800417 Slog.i(TAG, "Recognition Service");
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800418 recognition = new RecognitionManagerService(context);
419 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800420 Slog.e(TAG, "Failure starting Recognition Service", e);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800421 }
Nick Pelly038cabe2010-09-23 16:12:11 -0700422
423 try {
424 Slog.i(TAG, "Nfc Service");
425 NfcService nfc;
426 try {
427 nfc = new NfcService(context);
428 } catch (UnsatisfiedLinkError e) { // gross hack to detect NFC
429 nfc = null;
430 Slog.w(TAG, "No NFC support");
431 }
432 ServiceManager.addService(Context.NFC_SERVICE, nfc);
433 } catch (Throwable e) {
434 Slog.e(TAG, "Failure starting NFC Service", e);
435 }
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800436
437 try {
Dan Egnor621bc542010-03-25 16:20:14 -0700438 Slog.i(TAG, "DiskStats Service");
439 ServiceManager.addService("diskstats", new DiskStatsService(context));
440 } catch (Throwable e) {
441 Slog.e(TAG, "Failure starting DiskStats Service", e);
442 }
Sen Hubde75702010-05-28 01:54:03 -0700443
444 try {
445 // need to add this service even if SamplingProfilerIntegration.isEnabled()
446 // is false, because it is this service that detects system property change and
447 // turns on SamplingProfilerIntegration. Plus, when sampling profiler doesn't work,
448 // there is little overhead for running this service.
449 Slog.i(TAG, "SamplingProfiler Service");
450 ServiceManager.addService("samplingprofiler",
451 new SamplingProfilerService(context));
452 } catch (Throwable e) {
453 Slog.e(TAG, "Failure starting SamplingProfiler Service", e);
454 }
Chung-yih Wang024d5962010-08-06 12:06:04 +0800455
456 try {
Amith Yamasani6734b9f2010-09-13 16:24:08 -0700457 Slog.i(TAG, "NetworkTimeUpdateService");
458 networkTimeUpdater = new NetworkTimeUpdateService(context);
459 } catch (Throwable e) {
460 Slog.e(TAG, "Failure starting NetworkTimeUpdate service");
461 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800462 }
463
464 // make sure the ADB_ENABLED setting value matches the secure property value
465 Settings.Secure.putInt(mContentResolver, Settings.Secure.ADB_ENABLED,
466 "1".equals(SystemProperties.get("persist.service.adb.enable")) ? 1 : 0);
467
468 // register observer to listen for settings changes
469 mContentResolver.registerContentObserver(Settings.Secure.getUriFor(Settings.Secure.ADB_ENABLED),
470 false, new AdbSettingsObserver());
471
Dianne Hackborn6af0d502009-09-28 13:25:46 -0700472 // Before things start rolling, be sure we have decided whether
473 // we are in safe mode.
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700474 final boolean safeMode = wm.detectSafeMode();
Dianne Hackborn6af0d502009-09-28 13:25:46 -0700475 if (safeMode) {
476 try {
477 ActivityManagerNative.getDefault().enterSafeMode();
Ben Cheng6c0afff2010-02-14 16:18:56 -0800478 // Post the safe mode state in the Zygote class
479 Zygote.systemInSafeMode = true;
480 // Disable the JIT for the system_server process
481 VMRuntime.getRuntime().disableJitCompilation();
Dianne Hackborn6af0d502009-09-28 13:25:46 -0700482 } catch (RemoteException e) {
483 }
Ben Cheng6c0afff2010-02-14 16:18:56 -0800484 } else {
485 // Enable the JIT for the system_server process
486 VMRuntime.getRuntime().startJitCompilation();
Dianne Hackborn6af0d502009-09-28 13:25:46 -0700487 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800488
Dianne Hackborn6af0d502009-09-28 13:25:46 -0700489 // It is now time to start up the app processes...
Joe Onorato30275482009-07-08 17:09:14 -0700490
Dianne Hackbornd6847842010-01-12 18:14:19 -0800491 if (devicePolicy != null) {
492 devicePolicy.systemReady();
493 }
494
Joe Onorato30275482009-07-08 17:09:14 -0700495 if (notification != null) {
496 notification.systemReady();
497 }
498
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800499 if (statusBar != null) {
500 statusBar.systemReady();
501 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800502 wm.systemReady();
Joe Onoratodc565f42010-10-04 15:27:22 -0400503
504 // Update the configuration for this context by hand, because we're going
505 // to start using it before the config change done in wm.systemReady() will
506 // propagate to it.
507 Configuration config = wm.computeNewConfiguration();
508 DisplayMetrics metrics = new DisplayMetrics();
509 WindowManager w = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
510 w.getDefaultDisplay().getMetrics(metrics);
511 context.getResources().updateConfiguration(config, metrics);
512
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800513 power.systemReady();
514 try {
515 pm.systemReady();
516 } catch (RemoteException e) {
517 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800518
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700519 // These are needed to propagate to the runnable below.
Joe Onorato089de882010-04-12 08:18:45 -0700520 final StatusBarManagerService statusBarF = statusBar;
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700521 final BatteryService batteryF = battery;
522 final ConnectivityService connectivityF = connectivity;
523 final DockObserver dockF = dock;
Mike Lockwood57c798a2010-06-23 17:36:36 -0400524 final UsbObserver usbF = usb;
Robert Greenwalt9e696c22010-04-01 14:45:18 -0700525 final ThrottleService throttleF = throttle;
Dianne Hackborn7299c412010-03-04 18:41:49 -0800526 final UiModeManagerService uiModeF = uiMode;
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700527 final AppWidgetService appWidgetF = appWidget;
528 final WallpaperManagerService wallpaperF = wallpaper;
529 final InputMethodManagerService immF = imm;
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800530 final RecognitionManagerService recognitionF = recognition;
Mike Lockwood46db5042010-02-22 16:36:44 -0500531 final LocationManagerService locationF = location;
Bai Taoa58a8752010-07-13 15:32:16 +0800532 final CountryDetectorService countryDetectorF = countryDetector;
Amith Yamasani6734b9f2010-09-13 16:24:08 -0700533 final NetworkTimeUpdateService networkTimeUpdaterF = networkTimeUpdater;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800534
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700535 // We now tell the activity manager it is okay to run third party
536 // code. It will call back into us once it has gotten to the state
537 // where third party code can really run (but before it has actually
538 // started launching the initial applications), for us to complete our
539 // initialization.
540 ((ActivityManagerService)ActivityManagerNative.getDefault())
541 .systemReady(new Runnable() {
542 public void run() {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800543 Slog.i(TAG, "Making services ready");
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800544
Joe Onorato2314aab2010-04-08 16:41:23 -0500545 if (statusBarF != null) statusBarF.systemReady2();
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700546 if (batteryF != null) batteryF.systemReady();
547 if (connectivityF != null) connectivityF.systemReady();
548 if (dockF != null) dockF.systemReady();
Mike Lockwood57c798a2010-06-23 17:36:36 -0400549 if (usbF != null) usbF.systemReady();
Dianne Hackborn7299c412010-03-04 18:41:49 -0800550 if (uiModeF != null) uiModeF.systemReady();
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800551 if (recognitionF != null) recognitionF.systemReady();
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700552 Watchdog.getInstance().start();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800553
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700554 // It is now okay to let the various system services start their
555 // third party code...
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800556
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700557 if (appWidgetF != null) appWidgetF.systemReady(safeMode);
558 if (wallpaperF != null) wallpaperF.systemReady();
559 if (immF != null) immF.systemReady();
Mike Lockwood46db5042010-02-22 16:36:44 -0500560 if (locationF != null) locationF.systemReady();
Bai Taoa58a8752010-07-13 15:32:16 +0800561 if (countryDetectorF != null) countryDetectorF.systemReady();
Robert Greenwalt9e696c22010-04-01 14:45:18 -0700562 if (throttleF != null) throttleF.systemReady();
Amith Yamasani6734b9f2010-09-13 16:24:08 -0700563 if (networkTimeUpdaterF != null) networkTimeUpdaterF.systemReady();
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700564 }
565 });
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800566
Brad Fitzpatrick1e02d362010-09-10 09:19:50 -0700567 // For debug builds, log event loop stalls to dropbox for analysis.
Brad Fitzpatrick50d66f92010-09-13 21:29:05 -0700568 if (StrictMode.conditionallyEnableDebugLogging()) {
569 Slog.i(TAG, "Enabled StrictMode for system server main thread.");
Brad Fitzpatrick1e02d362010-09-10 09:19:50 -0700570 }
571
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800572 Looper.loop();
Joe Onorato8a9b2202010-02-26 18:56:32 -0800573 Slog.d(TAG, "System ServerThread is exiting!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800574 }
575}
576
Jeff Hamilton35eef702010-06-09 15:45:18 -0500577public class SystemServer {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800578 private static final String TAG = "SystemServer";
579
580 public static final int FACTORY_TEST_OFF = 0;
581 public static final int FACTORY_TEST_LOW_LEVEL = 1;
582 public static final int FACTORY_TEST_HIGH_LEVEL = 2;
Jaikumar Ganeshd5ac1ae2009-05-05 22:26:12 -0700583
Bob Leee5408332009-09-04 18:31:17 -0700584 static Timer timer;
585 static final long SNAPSHOT_INTERVAL = 60 * 60 * 1000; // 1hr
586
Jaikumar Ganeshd5ac1ae2009-05-05 22:26:12 -0700587 /**
588 * 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 -0800589 * services (SurfaceFlinger, AudioFlinger, etc..) to be started. After that it will call back
590 * up into init2() to start the Android services.
Jaikumar Ganeshd5ac1ae2009-05-05 22:26:12 -0700591 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800592 native public static void init1(String[] args);
593
594 public static void main(String[] args) {
Bob Leee5408332009-09-04 18:31:17 -0700595 if (SamplingProfilerIntegration.isEnabled()) {
596 SamplingProfilerIntegration.start();
597 timer = new Timer();
598 timer.schedule(new TimerTask() {
599 @Override
600 public void run() {
Sen Hubde75702010-05-28 01:54:03 -0700601 SamplingProfilerIntegration.writeSnapshot("system_server", null);
Bob Leee5408332009-09-04 18:31:17 -0700602 }
603 }, SNAPSHOT_INTERVAL, SNAPSHOT_INTERVAL);
604 }
605
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800606 // The system server has to run all of the time, so it needs to be
607 // as efficient as possible with its memory usage.
608 VMRuntime.getRuntime().setTargetHeapUtilization(0.8f);
Sen Hubde75702010-05-28 01:54:03 -0700609
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800610 System.loadLibrary("android_servers");
611 init1(args);
612 }
613
614 public static final void init2() {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800615 Slog.i(TAG, "Entered the Android system server!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800616 Thread thr = new ServerThread();
617 thr.setName("android.server.ServerThread");
618 thr.start();
619 }
620}