blob: c9567efc8cea1520ff97c6581da913e8aeca0d84 [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
Dianne Hackborn887f3552009-12-07 17:59:37 -080019import com.android.internal.os.BinderInternal;
Bob Leee5408332009-09-04 18:31:17 -070020import com.android.internal.os.SamplingProfilerIntegration;
Jeff Hamilton35eef702010-06-09 15:45:18 -050021import com.android.server.am.ActivityManagerService;
22import com.android.server.status.StatusBarService;
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;
34import android.database.ContentObserver;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080035import android.media.AudioService;
Jeff Hamilton35eef702010-06-09 15:45:18 -050036import android.os.Looper;
37import android.os.RemoteException;
38import android.os.ServiceManager;
39import android.os.SystemClock;
40import android.os.SystemProperties;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080041import android.provider.Settings;
42import android.server.BluetoothA2dpService;
Nick Pellybd022f42009-08-14 18:33:38 -070043import android.server.BluetoothService;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080044import android.server.search.SearchManagerService;
45import android.util.EventLog;
Joe Onorato8a9b2202010-02-26 18:56:32 -080046import android.util.Slog;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080047
Dan Egnor4410ec82009-09-11 16:40:01 -070048import java.io.File;
Bob Leee5408332009-09-04 18:31:17 -070049import java.util.Timer;
50import java.util.TimerTask;
51
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080052class ServerThread extends Thread {
53 private static final String TAG = "SystemServer";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080054
Jeff Hamilton35eef702010-06-09 15:45:18 -050055 ContentResolver mContentResolver;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080056
57 private class AdbSettingsObserver extends ContentObserver {
58 public AdbSettingsObserver() {
59 super(null);
60 }
61 @Override
62 public void onChange(boolean selfChange) {
63 boolean enableAdb = (Settings.Secure.getInt(mContentResolver,
64 Settings.Secure.ADB_ENABLED, 0) > 0);
65 // setting this secure property will start or stop adbd
66 SystemProperties.set("persist.service.adb.enable", enableAdb ? "1" : "0");
67 }
68 }
69
70 @Override
71 public void run() {
Doug Zongkerab5c49c2009-12-04 10:31:43 -080072 EventLog.writeEvent(EventLogTags.BOOT_PROGRESS_SYSTEM_RUN,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080073 SystemClock.uptimeMillis());
74
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080075 Looper.prepare();
76
77 android.os.Process.setThreadPriority(
78 android.os.Process.THREAD_PRIORITY_FOREGROUND);
79
Dianne Hackborn887f3552009-12-07 17:59:37 -080080 BinderInternal.disableBackgroundScheduling(true);
81
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080082 String factoryTestStr = SystemProperties.get("ro.factorytest");
83 int factoryTest = "".equals(factoryTestStr) ? SystemServer.FACTORY_TEST_OFF
84 : Integer.parseInt(factoryTestStr);
85
Mike Lockwood3a322132009-11-24 00:30:52 -050086 LightsService lights = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080087 PowerManagerService power = null;
Mike Lockwood07a500f2009-08-12 09:56:44 -040088 BatteryService battery = null;
Mike Lockwood0f79b542009-08-14 14:18:49 -040089 ConnectivityService connectivity = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080090 IPackageManager pm = null;
91 Context context = null;
92 WindowManagerService wm = null;
Nick Pellybd022f42009-08-14 18:33:38 -070093 BluetoothService bluetooth = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080094 BluetoothA2dpService bluetoothA2dp = null;
95 HeadsetObserver headset = null;
Dan Murphyc9f4eaf2009-08-12 15:15:43 -050096 DockObserver dock = null;
Dianne Hackborn7299c412010-03-04 18:41:49 -080097 UiModeManagerService uiMode = null;
Dianne Hackborn21f1bd12010-02-19 17:02:21 -080098 RecognitionManagerService recognition = null;
Robert Greenwalt9e696c22010-04-01 14:45:18 -070099 ThrottleService throttle = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800100
101 // Critical services...
102 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800103 Slog.i(TAG, "Entropy Service");
Nick Kralevich4fb25612009-06-17 16:03:22 -0700104 ServiceManager.addService("entropy", new EntropyService());
105
Joe Onorato8a9b2202010-02-26 18:56:32 -0800106 Slog.i(TAG, "Power Manager");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800107 power = new PowerManagerService();
108 ServiceManager.addService(Context.POWER_SERVICE, power);
109
Joe Onorato8a9b2202010-02-26 18:56:32 -0800110 Slog.i(TAG, "Activity Manager");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800111 context = ActivityManagerService.main(factoryTest);
112
Joe Onorato8a9b2202010-02-26 18:56:32 -0800113 Slog.i(TAG, "Telephony Registry");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800114 ServiceManager.addService("telephony.registry", new TelephonyRegistry(context));
115
116 AttributeCache.init(context);
117
Joe Onorato8a9b2202010-02-26 18:56:32 -0800118 Slog.i(TAG, "Package Manager");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800119 pm = PackageManagerService.main(context,
120 factoryTest != SystemServer.FACTORY_TEST_OFF);
121
122 ActivityManagerService.setSystemProcess();
123
124 mContentResolver = context.getContentResolver();
125
Fred Quintanae91ebe22009-09-29 20:44:30 -0700126 // The AccountManager must come before the ContentService
Fred Quintana60307342009-03-24 22:48:12 -0700127 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800128 Slog.i(TAG, "Account Manager");
Fred Quintana60307342009-03-24 22:48:12 -0700129 ServiceManager.addService(Context.ACCOUNT_SERVICE,
130 new AccountManagerService(context));
131 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800132 Slog.e(TAG, "Failure starting Account Manager", e);
Fred Quintana60307342009-03-24 22:48:12 -0700133 }
134
Joe Onorato8a9b2202010-02-26 18:56:32 -0800135 Slog.i(TAG, "Content Manager");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800136 ContentService.main(context,
137 factoryTest == SystemServer.FACTORY_TEST_LOW_LEVEL);
138
Joe Onorato8a9b2202010-02-26 18:56:32 -0800139 Slog.i(TAG, "System Content Providers");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800140 ActivityManagerService.installSystemProviders();
141
Joe Onorato8a9b2202010-02-26 18:56:32 -0800142 Slog.i(TAG, "Battery Service");
Mike Lockwood07a500f2009-08-12 09:56:44 -0400143 battery = new BatteryService(context);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800144 ServiceManager.addService("battery", battery);
145
Joe Onorato8a9b2202010-02-26 18:56:32 -0800146 Slog.i(TAG, "Lights Service");
Mike Lockwood3a322132009-11-24 00:30:52 -0500147 lights = new LightsService(context);
148
Joe Onorato8a9b2202010-02-26 18:56:32 -0800149 Slog.i(TAG, "Vibrator Service");
Mike Lockwood3a322132009-11-24 00:30:52 -0500150 ServiceManager.addService("vibrator", new VibratorService(context));
The Android Open Source Project10592532009-03-18 17:39:46 -0700151
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800152 // only initialize the power service after we have started the
Mike Lockwood3a322132009-11-24 00:30:52 -0500153 // lights service, content providers and the battery service.
154 power.init(context, lights, ActivityManagerService.getDefault(), battery);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800155
Joe Onorato8a9b2202010-02-26 18:56:32 -0800156 Slog.i(TAG, "Alarm Manager");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800157 AlarmManagerService alarm = new AlarmManagerService(context);
158 ServiceManager.addService(Context.ALARM_SERVICE, alarm);
159
Joe Onorato8a9b2202010-02-26 18:56:32 -0800160 Slog.i(TAG, "Init Watchdog");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800161 Watchdog.getInstance().init(context, battery, power, alarm,
162 ActivityManagerService.self());
163
164 // Sensor Service is needed by Window Manager, so this goes first
Joe Onorato8a9b2202010-02-26 18:56:32 -0800165 Slog.i(TAG, "Sensor Service");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800166 ServiceManager.addService(Context.SENSOR_SERVICE, new SensorService(context));
167
Joe Onorato8a9b2202010-02-26 18:56:32 -0800168 Slog.i(TAG, "Window Manager");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800169 wm = WindowManagerService.main(context, power,
170 factoryTest != SystemServer.FACTORY_TEST_LOW_LEVEL);
171 ServiceManager.addService(Context.WINDOW_SERVICE, wm);
172
173 ((ActivityManagerService)ServiceManager.getService("activity"))
174 .setWindowManager(wm);
175
176 // Skip Bluetooth if we have an emulator kernel
177 // TODO: Use a more reliable check to see if this product should
178 // support Bluetooth - see bug 988521
179 if (SystemProperties.get("ro.kernel.qemu").equals("1")) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800180 Slog.i(TAG, "Registering null Bluetooth Service (emulator)");
Nick Pellyf242b7b2009-10-08 00:12:45 +0200181 ServiceManager.addService(BluetoothAdapter.BLUETOOTH_SERVICE, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800182 } else if (factoryTest == SystemServer.FACTORY_TEST_LOW_LEVEL) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800183 Slog.i(TAG, "Registering null Bluetooth Service (factory test)");
Nick Pellyf242b7b2009-10-08 00:12:45 +0200184 ServiceManager.addService(BluetoothAdapter.BLUETOOTH_SERVICE, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800185 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800186 Slog.i(TAG, "Bluetooth Service");
Nick Pellybd022f42009-08-14 18:33:38 -0700187 bluetooth = new BluetoothService(context);
Nick Pellyf242b7b2009-10-08 00:12:45 +0200188 ServiceManager.addService(BluetoothAdapter.BLUETOOTH_SERVICE, bluetooth);
Nick Pellybd022f42009-08-14 18:33:38 -0700189 bluetooth.initAfterRegistration();
Jaikumar Ganeshd5ac1ae2009-05-05 22:26:12 -0700190 bluetoothA2dp = new BluetoothA2dpService(context, bluetooth);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800191 ServiceManager.addService(BluetoothA2dpService.BLUETOOTH_A2DP_SERVICE,
192 bluetoothA2dp);
193
194 int bluetoothOn = Settings.Secure.getInt(mContentResolver,
195 Settings.Secure.BLUETOOTH_ON, 0);
196 if (bluetoothOn > 0) {
The Android Open Source Project10592532009-03-18 17:39:46 -0700197 bluetooth.enable();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800198 }
199 }
200
201 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800202 Slog.e("System", "Failure starting core service", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800203 }
204
Dianne Hackbornd6847842010-01-12 18:14:19 -0800205 DevicePolicyManagerService devicePolicy = null;
Joe Onorato089de882010-04-12 08:18:45 -0700206 StatusBarManagerService statusBar = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800207 InputMethodManagerService imm = null;
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700208 AppWidgetService appWidget = null;
Joe Onorato30275482009-07-08 17:09:14 -0700209 NotificationManagerService notification = null;
Dianne Hackbornf21adf62009-08-13 10:20:21 -0700210 WallpaperManagerService wallpaper = null;
Mike Lockwood46db5042010-02-22 16:36:44 -0500211 LocationManagerService location = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800212
213 if (factoryTest != SystemServer.FACTORY_TEST_LOW_LEVEL) {
214 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800215 Slog.i(TAG, "Device Policy");
Dianne Hackbornd6847842010-01-12 18:14:19 -0800216 devicePolicy = new DevicePolicyManagerService(context);
217 ServiceManager.addService(Context.DEVICE_POLICY_SERVICE, devicePolicy);
218 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800219 Slog.e(TAG, "Failure starting DevicePolicyService", e);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800220 }
221
222 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800223 Slog.i(TAG, "Status Bar");
Joe Onorato089de882010-04-12 08:18:45 -0700224 statusBar = new StatusBarManagerService(context);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800225 ServiceManager.addService(Context.STATUS_BAR_SERVICE, statusBar);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800226 } catch (Throwable e) {
Joe Onorato089de882010-04-12 08:18:45 -0700227 Slog.e(TAG, "Failure starting StatusBarManagerService", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800228 }
229
230 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800231 Slog.i(TAG, "Clipboard Service");
Dianne Hackbornd6847842010-01-12 18:14:19 -0800232 ServiceManager.addService(Context.CLIPBOARD_SERVICE,
233 new ClipboardService(context));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800234 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800235 Slog.e(TAG, "Failure starting Clipboard Service", 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, "Input Method Service");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800240 imm = new InputMethodManagerService(context, statusBar);
241 ServiceManager.addService(Context.INPUT_METHOD_SERVICE, imm);
242 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800243 Slog.e(TAG, "Failure starting Input Manager 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, "NetStat Service");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800248 ServiceManager.addService("netstat", new NetStatService(context));
249 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800250 Slog.e(TAG, "Failure starting NetStat 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, "NetworkManagement Service");
San Mehatd1df8ac2010-01-26 06:17:26 -0800255 ServiceManager.addService(
256 Context.NETWORKMANAGEMENT_SERVICE, new NetworkManagementService(context));
257 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800258 Slog.e(TAG, "Failure starting NetworkManagement Service", e);
San Mehatd1df8ac2010-01-26 06:17:26 -0800259 }
260
261 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800262 Slog.i(TAG, "Connectivity Service");
Mike Lockwood0f79b542009-08-14 14:18:49 -0400263 connectivity = ConnectivityService.getInstance(context);
264 ServiceManager.addService(Context.CONNECTIVITY_SERVICE, connectivity);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800265 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800266 Slog.e(TAG, "Failure starting Connectivity Service", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800267 }
268
269 try {
Robert Greenwalt9e696c22010-04-01 14:45:18 -0700270 Slog.i(TAG, "Throttle Service");
271 throttle = new ThrottleService(context);
272 ServiceManager.addService(
273 Context.THROTTLE_SERVICE, throttle);
274 } catch (Throwable e) {
275 Slog.e(TAG, "Failure starting ThrottleService", e);
276 }
277
278 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800279 Slog.i(TAG, "Accessibility Manager");
svetoslavganov75986cf2009-05-14 22:28:01 -0700280 ServiceManager.addService(Context.ACCESSIBILITY_SERVICE,
281 new AccessibilityManagerService(context));
282 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800283 Slog.e(TAG, "Failure starting Accessibility Manager", e);
svetoslavganov75986cf2009-05-14 22:28:01 -0700284 }
285
286 try {
San Mehat1bf3f8b2010-02-03 14:43:09 -0800287 /*
288 * NotificationManagerService is dependant on MountService,
289 * (for media / usb notifications) so we must start MountService first.
290 */
Joe Onorato8a9b2202010-02-26 18:56:32 -0800291 Slog.i(TAG, "Mount Service");
San Mehat1bf3f8b2010-02-03 14:43:09 -0800292 ServiceManager.addService("mount", new MountService(context));
293 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800294 Slog.e(TAG, "Failure starting Mount Service", e);
San Mehat1bf3f8b2010-02-03 14:43:09 -0800295 }
296
297 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800298 Slog.i(TAG, "Notification Manager");
Mike Lockwood3a322132009-11-24 00:30:52 -0500299 notification = new NotificationManagerService(context, statusBar, lights);
Joe Onorato30275482009-07-08 17:09:14 -0700300 ServiceManager.addService(Context.NOTIFICATION_SERVICE, notification);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800301 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800302 Slog.e(TAG, "Failure starting Notification Manager", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800303 }
304
305 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800306 Slog.i(TAG, "Device Storage Monitor");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800307 ServiceManager.addService(DeviceStorageMonitorService.SERVICE,
308 new DeviceStorageMonitorService(context));
309 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800310 Slog.e(TAG, "Failure starting DeviceStorageMonitor service", 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, "Location Manager");
Mike Lockwood46db5042010-02-22 16:36:44 -0500315 location = new LocationManagerService(context);
316 ServiceManager.addService(Context.LOCATION_SERVICE, location);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800317 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800318 Slog.e(TAG, "Failure starting Location Manager", 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, "Search Service");
Dianne Hackbornd6847842010-01-12 18:14:19 -0800323 ServiceManager.addService(Context.SEARCH_SERVICE,
324 new SearchManagerService(context));
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 Search Service", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800327 }
328
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800329 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800330 Slog.i(TAG, "DropBox Service");
Dan Egnor95240272009-10-27 18:23:39 -0700331 ServiceManager.addService(Context.DROPBOX_SERVICE,
Dan Egnorf18a01c2009-11-12 11:32:50 -0800332 new DropBoxManagerService(context, new File("/data/system/dropbox")));
Dan Egnor4410ec82009-09-11 16:40:01 -0700333 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800334 Slog.e(TAG, "Failure starting DropBoxManagerService", e);
Dan Egnor4410ec82009-09-11 16:40:01 -0700335 }
336
337 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800338 Slog.i(TAG, "Wallpaper Service");
Dianne Hackbornf21adf62009-08-13 10:20:21 -0700339 wallpaper = new WallpaperManagerService(context);
340 ServiceManager.addService(Context.WALLPAPER_SERVICE, wallpaper);
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 Wallpaper Service", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800343 }
344
345 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800346 Slog.i(TAG, "Audio Service");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800347 ServiceManager.addService(Context.AUDIO_SERVICE, new AudioService(context));
348 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800349 Slog.e(TAG, "Failure starting Audio Service", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800350 }
351
352 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800353 Slog.i(TAG, "Headset Observer");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800354 // Listen for wired headset changes
355 headset = new HeadsetObserver(context);
356 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800357 Slog.e(TAG, "Failure starting HeadsetObserver", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800358 }
359
360 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800361 Slog.i(TAG, "Dock Observer");
Dan Murphyc9f4eaf2009-08-12 15:15:43 -0500362 // Listen for dock station changes
Ken Schultzf02c0742009-09-10 18:37:37 -0500363 dock = new DockObserver(context, power);
Dan Murphyc9f4eaf2009-08-12 15:15:43 -0500364 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800365 Slog.e(TAG, "Failure starting DockObserver", e);
Dan Murphyc9f4eaf2009-08-12 15:15:43 -0500366 }
367
368 try {
Dianne Hackborn7299c412010-03-04 18:41:49 -0800369 Slog.i(TAG, "UI Mode Manager Service");
370 // Listen for dock station changes
371 uiMode = new UiModeManagerService(context);
372 } catch (Throwable e) {
373 Slog.e(TAG, "Failure starting UiModeManagerService", e);
374 }
375
376 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800377 Slog.i(TAG, "Backup Service");
Dianne Hackbornd6847842010-01-12 18:14:19 -0800378 ServiceManager.addService(Context.BACKUP_SERVICE,
379 new BackupManagerService(context));
Christopher Tate487529a2009-04-29 14:03:25 -0700380 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800381 Slog.e(TAG, "Failure starting Backup Service", e);
Christopher Tate487529a2009-04-29 14:03:25 -0700382 }
383
384 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800385 Slog.i(TAG, "AppWidget Service");
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700386 appWidget = new AppWidgetService(context);
387 ServiceManager.addService(Context.APPWIDGET_SERVICE, appWidget);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800388 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800389 Slog.e(TAG, "Failure starting AppWidget Service", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800390 }
391
392 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800393 Slog.i(TAG, "Recognition Service");
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800394 recognition = new RecognitionManagerService(context);
395 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800396 Slog.e(TAG, "Failure starting Recognition Service", e);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800397 }
398
399 try {
Dan Egnor621bc542010-03-25 16:20:14 -0700400 Slog.i(TAG, "DiskStats Service");
401 ServiceManager.addService("diskstats", new DiskStatsService(context));
402 } catch (Throwable e) {
403 Slog.e(TAG, "Failure starting DiskStats Service", e);
404 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800405 }
406
407 // make sure the ADB_ENABLED setting value matches the secure property value
408 Settings.Secure.putInt(mContentResolver, Settings.Secure.ADB_ENABLED,
409 "1".equals(SystemProperties.get("persist.service.adb.enable")) ? 1 : 0);
410
411 // register observer to listen for settings changes
412 mContentResolver.registerContentObserver(Settings.Secure.getUriFor(Settings.Secure.ADB_ENABLED),
413 false, new AdbSettingsObserver());
414
Dianne Hackborn6af0d502009-09-28 13:25:46 -0700415 // Before things start rolling, be sure we have decided whether
416 // we are in safe mode.
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700417 final boolean safeMode = wm.detectSafeMode();
Dianne Hackborn6af0d502009-09-28 13:25:46 -0700418 if (safeMode) {
419 try {
420 ActivityManagerNative.getDefault().enterSafeMode();
Ben Cheng6c0afff2010-02-14 16:18:56 -0800421 // Post the safe mode state in the Zygote class
422 Zygote.systemInSafeMode = true;
423 // Disable the JIT for the system_server process
424 VMRuntime.getRuntime().disableJitCompilation();
Dianne Hackborn6af0d502009-09-28 13:25:46 -0700425 } catch (RemoteException e) {
426 }
Ben Cheng6c0afff2010-02-14 16:18:56 -0800427 } else {
428 // Enable the JIT for the system_server process
429 VMRuntime.getRuntime().startJitCompilation();
Dianne Hackborn6af0d502009-09-28 13:25:46 -0700430 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800431
Dianne Hackborn6af0d502009-09-28 13:25:46 -0700432 // It is now time to start up the app processes...
Joe Onorato30275482009-07-08 17:09:14 -0700433
Dianne Hackbornd6847842010-01-12 18:14:19 -0800434 if (devicePolicy != null) {
435 devicePolicy.systemReady();
436 }
437
Joe Onorato30275482009-07-08 17:09:14 -0700438 if (notification != null) {
439 notification.systemReady();
440 }
441
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800442 if (statusBar != null) {
443 statusBar.systemReady();
444 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800445 wm.systemReady();
446 power.systemReady();
447 try {
448 pm.systemReady();
449 } catch (RemoteException e) {
450 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800451
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700452 // These are needed to propagate to the runnable below.
Joe Onorato089de882010-04-12 08:18:45 -0700453 final StatusBarManagerService statusBarF = statusBar;
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700454 final BatteryService batteryF = battery;
455 final ConnectivityService connectivityF = connectivity;
456 final DockObserver dockF = dock;
Robert Greenwalt9e696c22010-04-01 14:45:18 -0700457 final ThrottleService throttleF = throttle;
Dianne Hackborn7299c412010-03-04 18:41:49 -0800458 final UiModeManagerService uiModeF = uiMode;
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700459 final AppWidgetService appWidgetF = appWidget;
460 final WallpaperManagerService wallpaperF = wallpaper;
461 final InputMethodManagerService immF = imm;
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800462 final RecognitionManagerService recognitionF = recognition;
Mike Lockwood46db5042010-02-22 16:36:44 -0500463 final LocationManagerService locationF = location;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800464
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700465 // We now tell the activity manager it is okay to run third party
466 // code. It will call back into us once it has gotten to the state
467 // where third party code can really run (but before it has actually
468 // started launching the initial applications), for us to complete our
469 // initialization.
470 ((ActivityManagerService)ActivityManagerNative.getDefault())
471 .systemReady(new Runnable() {
472 public void run() {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800473 Slog.i(TAG, "Making services ready");
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800474
Joe Onorato2314aab2010-04-08 16:41:23 -0500475 if (statusBarF != null) statusBarF.systemReady2();
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700476 if (batteryF != null) batteryF.systemReady();
477 if (connectivityF != null) connectivityF.systemReady();
478 if (dockF != null) dockF.systemReady();
Dianne Hackborn7299c412010-03-04 18:41:49 -0800479 if (uiModeF != null) uiModeF.systemReady();
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800480 if (recognitionF != null) recognitionF.systemReady();
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700481 Watchdog.getInstance().start();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800482
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700483 // It is now okay to let the various system services start their
484 // third party code...
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800485
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700486 if (appWidgetF != null) appWidgetF.systemReady(safeMode);
487 if (wallpaperF != null) wallpaperF.systemReady();
488 if (immF != null) immF.systemReady();
Mike Lockwood46db5042010-02-22 16:36:44 -0500489 if (locationF != null) locationF.systemReady();
Robert Greenwalt9e696c22010-04-01 14:45:18 -0700490 if (throttleF != null) throttleF.systemReady();
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700491 }
492 });
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800493
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800494 Looper.loop();
Joe Onorato8a9b2202010-02-26 18:56:32 -0800495 Slog.d(TAG, "System ServerThread is exiting!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800496 }
497}
498
Jeff Hamilton35eef702010-06-09 15:45:18 -0500499public class SystemServer {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800500 private static final String TAG = "SystemServer";
501
502 public static final int FACTORY_TEST_OFF = 0;
503 public static final int FACTORY_TEST_LOW_LEVEL = 1;
504 public static final int FACTORY_TEST_HIGH_LEVEL = 2;
Jaikumar Ganeshd5ac1ae2009-05-05 22:26:12 -0700505
Bob Leee5408332009-09-04 18:31:17 -0700506 static Timer timer;
507 static final long SNAPSHOT_INTERVAL = 60 * 60 * 1000; // 1hr
508
Jaikumar Ganeshd5ac1ae2009-05-05 22:26:12 -0700509 /**
510 * 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 -0800511 * services (SurfaceFlinger, AudioFlinger, etc..) to be started. After that it will call back
512 * up into init2() to start the Android services.
Jaikumar Ganeshd5ac1ae2009-05-05 22:26:12 -0700513 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800514 native public static void init1(String[] args);
515
516 public static void main(String[] args) {
Bob Leee5408332009-09-04 18:31:17 -0700517 if (SamplingProfilerIntegration.isEnabled()) {
518 SamplingProfilerIntegration.start();
519 timer = new Timer();
520 timer.schedule(new TimerTask() {
521 @Override
522 public void run() {
523 SamplingProfilerIntegration.writeSnapshot("system_server");
524 }
525 }, SNAPSHOT_INTERVAL, SNAPSHOT_INTERVAL);
526 }
527
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800528 // The system server has to run all of the time, so it needs to be
529 // as efficient as possible with its memory usage.
530 VMRuntime.getRuntime().setTargetHeapUtilization(0.8f);
Dianne Hackborn2a9094d2010-02-03 19:20:09 -0800531
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800532 System.loadLibrary("android_servers");
533 init1(args);
534 }
535
536 public static final void init2() {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800537 Slog.i(TAG, "Entered the Android system server!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800538 Thread thr = new ServerThread();
539 thr.setName("android.server.ServerThread");
540 thr.start();
541 }
542}