blob: 4a0dcdfd3b685c27516ec3e8078ca2e2134153cc [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
Jeff Hamilton35eef702010-06-09 15:45:18 -050019import android.accounts.AccountManagerService;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080020import android.app.ActivityManagerNative;
Nick Pellyf242b7b2009-10-08 00:12:45 +020021import android.bluetooth.BluetoothAdapter;
Joe Onoratof3c3c4f2010-10-21 11:09:02 -040022import android.content.ComponentName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080023import android.content.ContentResolver;
24import android.content.ContentService;
25import android.content.Context;
Joe Onoratof3c3c4f2010-10-21 11:09:02 -040026import android.content.Intent;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080027import android.content.pm.IPackageManager;
Joe Onoratodc565f42010-10-04 15:27:22 -040028import android.content.res.Configuration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080029import android.media.AudioService;
Irfan Sherifff6d09842011-08-03 15:37:08 -070030import android.net.wifi.p2p.WifiP2pService;
Jeff Hamilton35eef702010-06-09 15:45:18 -050031import android.os.Looper;
32import android.os.RemoteException;
33import android.os.ServiceManager;
Brad Fitzpatrickc74a1b442010-09-10 16:03:29 -070034import android.os.StrictMode;
Jeff Hamilton35eef702010-06-09 15:45:18 -050035import android.os.SystemClock;
36import android.os.SystemProperties;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080037import android.provider.Settings;
38import android.server.BluetoothA2dpService;
Nick Pellybd022f42009-08-14 18:33:38 -070039import android.server.BluetoothService;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080040import android.server.search.SearchManagerService;
Joe Onoratodc565f42010-10-04 15:27:22 -040041import android.util.DisplayMetrics;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080042import android.util.EventLog;
Joe Onorato8a9b2202010-02-26 18:56:32 -080043import android.util.Slog;
Brad Fitzpatrick5fdc0c72010-10-12 13:12:18 -070044import android.view.WindowManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080045
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -070046import com.android.internal.app.ShutdownThread;
47import com.android.internal.os.BinderInternal;
48import com.android.internal.os.SamplingProfilerIntegration;
49import com.android.server.accessibility.AccessibilityManagerService;
50import com.android.server.am.ActivityManagerService;
51import com.android.server.net.NetworkPolicyManagerService;
Jeff Sharkey75279902011-05-24 18:39:45 -070052import com.android.server.net.NetworkStatsService;
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -070053import com.android.server.pm.PackageManagerService;
54import com.android.server.usb.UsbService;
55import com.android.server.wm.WindowManagerService;
56
57import dalvik.system.VMRuntime;
58import dalvik.system.Zygote;
59
Dan Egnor4410ec82009-09-11 16:40:01 -070060import java.io.File;
Bob Leee5408332009-09-04 18:31:17 -070061import java.util.Timer;
62import java.util.TimerTask;
63
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080064class ServerThread extends Thread {
65 private static final String TAG = "SystemServer";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080066
Jeff Hamilton35eef702010-06-09 15:45:18 -050067 ContentResolver mContentResolver;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080068
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080069 @Override
70 public void run() {
Doug Zongkerab5c49c2009-12-04 10:31:43 -080071 EventLog.writeEvent(EventLogTags.BOOT_PROGRESS_SYSTEM_RUN,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080072 SystemClock.uptimeMillis());
73
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080074 Looper.prepare();
75
76 android.os.Process.setThreadPriority(
77 android.os.Process.THREAD_PRIORITY_FOREGROUND);
78
Dianne Hackborn887f3552009-12-07 17:59:37 -080079 BinderInternal.disableBackgroundScheduling(true);
Christopher Tate160edb32010-06-30 17:46:30 -070080 android.os.Process.setCanSelfBackground(false);
Sen Hubde75702010-05-28 01:54:03 -070081
Kenny Rootf547d672010-09-22 10:36:48 -070082 // Check whether we failed to shut down last time we tried.
83 {
84 final String shutdownAction = SystemProperties.get(
85 ShutdownThread.SHUTDOWN_ACTION_PROPERTY, "");
86 if (shutdownAction != null && shutdownAction.length() > 0) {
87 boolean reboot = (shutdownAction.charAt(0) == '1');
88
89 final String reason;
90 if (shutdownAction.length() > 1) {
91 reason = shutdownAction.substring(1, shutdownAction.length());
92 } else {
93 reason = null;
94 }
95
96 ShutdownThread.rebootOrShutdown(reboot, reason);
97 }
98 }
99
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800100 String factoryTestStr = SystemProperties.get("ro.factorytest");
101 int factoryTest = "".equals(factoryTestStr) ? SystemServer.FACTORY_TEST_OFF
102 : Integer.parseInt(factoryTestStr);
103
Mike Lockwood3a322132009-11-24 00:30:52 -0500104 LightsService lights = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800105 PowerManagerService power = null;
Mike Lockwood07a500f2009-08-12 09:56:44 -0400106 BatteryService battery = null;
Jeff Sharkey75279902011-05-24 18:39:45 -0700107 AlarmManagerService alarm = null;
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -0700108 NetworkManagementService networkManagement = null;
Jeff Sharkey75279902011-05-24 18:39:45 -0700109 NetworkStatsService networkStats = null;
Jeff Sharkeya4620792011-05-20 15:29:23 -0700110 NetworkPolicyManagerService networkPolicy = null;
Mike Lockwood0f79b542009-08-14 14:18:49 -0400111 ConnectivityService connectivity = null;
repo sync55bc5f32011-06-24 14:23:07 -0700112 WifiP2pService wifiP2p = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800113 IPackageManager pm = null;
114 Context context = null;
115 WindowManagerService wm = null;
Nick Pellybd022f42009-08-14 18:33:38 -0700116 BluetoothService bluetooth = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800117 BluetoothA2dpService bluetoothA2dp = null;
Praveen Bharathi21e941b2010-10-06 15:23:14 -0500118 WiredAccessoryObserver wiredAccessory = null;
Dan Murphyc9f4eaf2009-08-12 15:15:43 -0500119 DockObserver dock = null;
Mike Lockwood770126a2010-12-09 22:30:37 -0800120 UsbService usb = null;
Dianne Hackborn7299c412010-03-04 18:41:49 -0800121 UiModeManagerService uiMode = null;
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800122 RecognitionManagerService recognition = null;
Robert Greenwalt9e696c22010-04-01 14:45:18 -0700123 ThrottleService throttle = null;
Amith Yamasani6734b9f62010-09-13 16:24:08 -0700124 NetworkTimeUpdateService networkTimeUpdater = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800125
126 // Critical services...
127 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800128 Slog.i(TAG, "Entropy Service");
Nick Kralevich4fb25612009-06-17 16:03:22 -0700129 ServiceManager.addService("entropy", new EntropyService());
130
Joe Onorato8a9b2202010-02-26 18:56:32 -0800131 Slog.i(TAG, "Power Manager");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800132 power = new PowerManagerService();
133 ServiceManager.addService(Context.POWER_SERVICE, power);
134
Joe Onorato8a9b2202010-02-26 18:56:32 -0800135 Slog.i(TAG, "Activity Manager");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800136 context = ActivityManagerService.main(factoryTest);
137
Joe Onorato8a9b2202010-02-26 18:56:32 -0800138 Slog.i(TAG, "Telephony Registry");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800139 ServiceManager.addService("telephony.registry", new TelephonyRegistry(context));
140
141 AttributeCache.init(context);
142
Joe Onorato8a9b2202010-02-26 18:56:32 -0800143 Slog.i(TAG, "Package Manager");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800144 pm = PackageManagerService.main(context,
145 factoryTest != SystemServer.FACTORY_TEST_OFF);
146
147 ActivityManagerService.setSystemProcess();
148
149 mContentResolver = context.getContentResolver();
150
Fred Quintanae91ebe22009-09-29 20:44:30 -0700151 // The AccountManager must come before the ContentService
Fred Quintana60307342009-03-24 22:48:12 -0700152 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800153 Slog.i(TAG, "Account Manager");
Fred Quintana60307342009-03-24 22:48:12 -0700154 ServiceManager.addService(Context.ACCOUNT_SERVICE,
155 new AccountManagerService(context));
156 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800157 Slog.e(TAG, "Failure starting Account Manager", e);
Fred Quintana60307342009-03-24 22:48:12 -0700158 }
159
Joe Onorato8a9b2202010-02-26 18:56:32 -0800160 Slog.i(TAG, "Content Manager");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800161 ContentService.main(context,
162 factoryTest == SystemServer.FACTORY_TEST_LOW_LEVEL);
163
Joe Onorato8a9b2202010-02-26 18:56:32 -0800164 Slog.i(TAG, "System Content Providers");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800165 ActivityManagerService.installSystemProviders();
166
Joe Onorato8a9b2202010-02-26 18:56:32 -0800167 Slog.i(TAG, "Lights Service");
Mike Lockwood3a322132009-11-24 00:30:52 -0500168 lights = new LightsService(context);
169
Joe Onoratode1b3592010-10-25 20:36:47 -0700170 Slog.i(TAG, "Battery Service");
171 battery = new BatteryService(context, lights);
172 ServiceManager.addService("battery", battery);
173
Joe Onorato8a9b2202010-02-26 18:56:32 -0800174 Slog.i(TAG, "Vibrator Service");
Mike Lockwood3a322132009-11-24 00:30:52 -0500175 ServiceManager.addService("vibrator", new VibratorService(context));
The Android Open Source Project10592532009-03-18 17:39:46 -0700176
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800177 // only initialize the power service after we have started the
Mike Lockwood3a322132009-11-24 00:30:52 -0500178 // lights service, content providers and the battery service.
179 power.init(context, lights, ActivityManagerService.getDefault(), battery);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800180
Joe Onorato8a9b2202010-02-26 18:56:32 -0800181 Slog.i(TAG, "Alarm Manager");
Jeff Sharkey75279902011-05-24 18:39:45 -0700182 alarm = new AlarmManagerService(context);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800183 ServiceManager.addService(Context.ALARM_SERVICE, alarm);
184
Joe Onorato8a9b2202010-02-26 18:56:32 -0800185 Slog.i(TAG, "Init Watchdog");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800186 Watchdog.getInstance().init(context, battery, power, alarm,
187 ActivityManagerService.self());
188
Joe Onorato8a9b2202010-02-26 18:56:32 -0800189 Slog.i(TAG, "Window Manager");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800190 wm = WindowManagerService.main(context, power,
191 factoryTest != SystemServer.FACTORY_TEST_LOW_LEVEL);
192 ServiceManager.addService(Context.WINDOW_SERVICE, wm);
193
194 ((ActivityManagerService)ServiceManager.getService("activity"))
195 .setWindowManager(wm);
196
197 // Skip Bluetooth if we have an emulator kernel
198 // TODO: Use a more reliable check to see if this product should
199 // support Bluetooth - see bug 988521
200 if (SystemProperties.get("ro.kernel.qemu").equals("1")) {
David 'Digit' Turnere2a5e862011-01-17 00:32:33 +0100201 Slog.i(TAG, "No Bluetooh Service (emulator)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800202 } else if (factoryTest == SystemServer.FACTORY_TEST_LOW_LEVEL) {
David 'Digit' Turnere2a5e862011-01-17 00:32:33 +0100203 Slog.i(TAG, "No Bluetooth Service (factory test)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800204 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800205 Slog.i(TAG, "Bluetooth Service");
Nick Pellybd022f42009-08-14 18:33:38 -0700206 bluetooth = new BluetoothService(context);
Nick Pellyf242b7b2009-10-08 00:12:45 +0200207 ServiceManager.addService(BluetoothAdapter.BLUETOOTH_SERVICE, bluetooth);
Nick Pellybd022f42009-08-14 18:33:38 -0700208 bluetooth.initAfterRegistration();
Jaikumar Ganeshd5ac1ae2009-05-05 22:26:12 -0700209 bluetoothA2dp = new BluetoothA2dpService(context, bluetooth);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800210 ServiceManager.addService(BluetoothA2dpService.BLUETOOTH_A2DP_SERVICE,
211 bluetoothA2dp);
Jaikumar Ganesh7d0548d2010-10-18 15:29:09 -0700212 bluetooth.initAfterA2dpRegistration();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800213
Jake Hambyaa6bd942011-06-27 16:32:37 -0700214 int airplaneModeOn = Settings.System.getInt(mContentResolver,
215 Settings.System.AIRPLANE_MODE_ON, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800216 int bluetoothOn = Settings.Secure.getInt(mContentResolver,
217 Settings.Secure.BLUETOOTH_ON, 0);
Jake Hambyaa6bd942011-06-27 16:32:37 -0700218 if (airplaneModeOn == 0 && bluetoothOn != 0) {
The Android Open Source Project10592532009-03-18 17:39:46 -0700219 bluetooth.enable();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800220 }
221 }
222
223 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800224 Slog.e("System", "Failure starting core service", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800225 }
226
Dianne Hackbornd6847842010-01-12 18:14:19 -0800227 DevicePolicyManagerService devicePolicy = null;
Joe Onorato089de882010-04-12 08:18:45 -0700228 StatusBarManagerService statusBar = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800229 InputMethodManagerService imm = null;
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700230 AppWidgetService appWidget = null;
Joe Onorato30275482009-07-08 17:09:14 -0700231 NotificationManagerService notification = null;
Dianne Hackbornf21adf62009-08-13 10:20:21 -0700232 WallpaperManagerService wallpaper = null;
Mike Lockwood46db5042010-02-22 16:36:44 -0500233 LocationManagerService location = null;
Bai Taoa58a8752010-07-13 15:32:16 +0800234 CountryDetectorService countryDetector = null;
satok988323c2011-06-22 16:38:13 +0900235 TextServicesManagerService tsms = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800236
237 if (factoryTest != SystemServer.FACTORY_TEST_LOW_LEVEL) {
238 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800239 Slog.i(TAG, "Device Policy");
Dianne Hackbornd6847842010-01-12 18:14:19 -0800240 devicePolicy = new DevicePolicyManagerService(context);
241 ServiceManager.addService(Context.DEVICE_POLICY_SERVICE, devicePolicy);
242 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800243 Slog.e(TAG, "Failure starting DevicePolicyService", e);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800244 }
245
246 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800247 Slog.i(TAG, "Status Bar");
Jeff Brown2992ea72011-01-28 22:04:14 -0800248 statusBar = new StatusBarManagerService(context, wm);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800249 ServiceManager.addService(Context.STATUS_BAR_SERVICE, statusBar);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800250 } catch (Throwable e) {
Joe Onorato089de882010-04-12 08:18:45 -0700251 Slog.e(TAG, "Failure starting StatusBarManagerService", 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, "Clipboard Service");
Dianne Hackbornd6847842010-01-12 18:14:19 -0800256 ServiceManager.addService(Context.CLIPBOARD_SERVICE,
257 new ClipboardService(context));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800258 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800259 Slog.e(TAG, "Failure starting Clipboard Service", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800260 }
261
262 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800263 Slog.i(TAG, "Input Method Service");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800264 imm = new InputMethodManagerService(context, statusBar);
265 ServiceManager.addService(Context.INPUT_METHOD_SERVICE, imm);
266 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800267 Slog.e(TAG, "Failure starting Input Manager Service", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800268 }
269
270 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800271 Slog.i(TAG, "NetworkManagement Service");
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -0700272 networkManagement = NetworkManagementService.create(context);
273 ServiceManager.addService(Context.NETWORKMANAGEMENT_SERVICE, networkManagement);
San Mehatd1df8ac2010-01-26 06:17:26 -0800274 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800275 Slog.e(TAG, "Failure starting NetworkManagement Service", e);
San Mehatd1df8ac2010-01-26 06:17:26 -0800276 }
277
278 try {
satok988323c2011-06-22 16:38:13 +0900279 Slog.i(TAG, "Text Service Manager Service");
280 tsms = new TextServicesManagerService(context);
281 ServiceManager.addService(Context.TEXT_SERVICES_MANAGER_SERVICE, tsms);
282 } catch (Throwable e) {
283 Slog.e(TAG, "Failure starting Text Service Manager Service", e);
284 }
285
286 try {
Jeff Sharkey75279902011-05-24 18:39:45 -0700287 Slog.i(TAG, "NetworkStats Service");
288 networkStats = new NetworkStatsService(context, networkManagement, alarm);
289 ServiceManager.addService(Context.NETWORK_STATS_SERVICE, networkStats);
290 } catch (Throwable e) {
291 Slog.e(TAG, "Failure starting NetworkStats Service", e);
292 }
293
294 try {
295 Slog.i(TAG, "NetworkPolicy Service");
296 networkPolicy = new NetworkPolicyManagerService(
Ashish Sharma50fd36d2011-06-15 19:34:53 -0700297 context, ActivityManagerService.self(), power,
298 networkStats, networkManagement);
Jeff Sharkey75279902011-05-24 18:39:45 -0700299 ServiceManager.addService(Context.NETWORK_POLICY_SERVICE, networkPolicy);
300 } catch (Throwable e) {
301 Slog.e(TAG, "Failure starting NetworkPolicy Service", e);
302 }
303
repo sync55bc5f32011-06-24 14:23:07 -0700304 try {
305 Slog.i(TAG, "Wi-Fi P2pService");
306 wifiP2p = new WifiP2pService(context);
307 ServiceManager.addService(Context.WIFI_P2P_SERVICE, wifiP2p);
308 } catch (Throwable e) {
309 Slog.e(TAG, "Failure starting Wi-Fi P2pService", e);
310 }
311
Jeff Sharkey75279902011-05-24 18:39:45 -0700312 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800313 Slog.i(TAG, "Connectivity Service");
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -0700314 connectivity = new ConnectivityService(context, networkManagement, networkPolicy);
Mike Lockwood0f79b542009-08-14 14:18:49 -0400315 ServiceManager.addService(Context.CONNECTIVITY_SERVICE, connectivity);
Jeff Sharkeyd2a45872011-05-28 20:56:34 -0700316 networkStats.bindConnectivityManager(connectivity);
Jeff Sharkey21c9c452011-06-07 12:26:43 -0700317 networkPolicy.bindConnectivityManager(connectivity);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800318 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800319 Slog.e(TAG, "Failure starting Connectivity Service", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800320 }
321
322 try {
Robert Greenwalt9e696c22010-04-01 14:45:18 -0700323 Slog.i(TAG, "Throttle Service");
324 throttle = new ThrottleService(context);
325 ServiceManager.addService(
326 Context.THROTTLE_SERVICE, throttle);
327 } catch (Throwable e) {
328 Slog.e(TAG, "Failure starting ThrottleService", e);
329 }
330
331 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800332 Slog.i(TAG, "Accessibility Manager");
svetoslavganov75986cf2009-05-14 22:28:01 -0700333 ServiceManager.addService(Context.ACCESSIBILITY_SERVICE,
334 new AccessibilityManagerService(context));
335 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800336 Slog.e(TAG, "Failure starting Accessibility Manager", e);
svetoslavganov75986cf2009-05-14 22:28:01 -0700337 }
338
339 try {
San Mehat1bf3f8b2010-02-03 14:43:09 -0800340 /*
341 * NotificationManagerService is dependant on MountService,
342 * (for media / usb notifications) so we must start MountService first.
343 */
Joe Onorato8a9b2202010-02-26 18:56:32 -0800344 Slog.i(TAG, "Mount Service");
San Mehat1bf3f8b2010-02-03 14:43:09 -0800345 ServiceManager.addService("mount", new MountService(context));
346 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800347 Slog.e(TAG, "Failure starting Mount Service", e);
San Mehat1bf3f8b2010-02-03 14:43:09 -0800348 }
349
350 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800351 Slog.i(TAG, "Notification Manager");
Mike Lockwood3a322132009-11-24 00:30:52 -0500352 notification = new NotificationManagerService(context, statusBar, lights);
Joe Onorato30275482009-07-08 17:09:14 -0700353 ServiceManager.addService(Context.NOTIFICATION_SERVICE, notification);
Jeff Sharkey497e4432011-06-14 17:27:29 -0700354 networkPolicy.bindNotificationManager(notification);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800355 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800356 Slog.e(TAG, "Failure starting Notification Manager", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800357 }
358
359 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800360 Slog.i(TAG, "Device Storage Monitor");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800361 ServiceManager.addService(DeviceStorageMonitorService.SERVICE,
362 new DeviceStorageMonitorService(context));
363 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800364 Slog.e(TAG, "Failure starting DeviceStorageMonitor service", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800365 }
366
367 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800368 Slog.i(TAG, "Location Manager");
Mike Lockwood46db5042010-02-22 16:36:44 -0500369 location = new LocationManagerService(context);
370 ServiceManager.addService(Context.LOCATION_SERVICE, location);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800371 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800372 Slog.e(TAG, "Failure starting Location Manager", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800373 }
374
375 try {
Bai Taoa58a8752010-07-13 15:32:16 +0800376 Slog.i(TAG, "Country Detector");
377 countryDetector = new CountryDetectorService(context);
378 ServiceManager.addService(Context.COUNTRY_DETECTOR, countryDetector);
379 } catch (Throwable e) {
380 Slog.e(TAG, "Failure starting Country Detector", e);
381 }
382
383 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800384 Slog.i(TAG, "Search Service");
Dianne Hackbornd6847842010-01-12 18:14:19 -0800385 ServiceManager.addService(Context.SEARCH_SERVICE,
386 new SearchManagerService(context));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800387 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800388 Slog.e(TAG, "Failure starting Search Service", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800389 }
390
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800391 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800392 Slog.i(TAG, "DropBox Service");
Dan Egnor95240272009-10-27 18:23:39 -0700393 ServiceManager.addService(Context.DROPBOX_SERVICE,
Dan Egnorf18a01c2009-11-12 11:32:50 -0800394 new DropBoxManagerService(context, new File("/data/system/dropbox")));
Dan Egnor4410ec82009-09-11 16:40:01 -0700395 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800396 Slog.e(TAG, "Failure starting DropBoxManagerService", e);
Dan Egnor4410ec82009-09-11 16:40:01 -0700397 }
398
399 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800400 Slog.i(TAG, "Wallpaper Service");
Dianne Hackbornf21adf62009-08-13 10:20:21 -0700401 wallpaper = new WallpaperManagerService(context);
402 ServiceManager.addService(Context.WALLPAPER_SERVICE, wallpaper);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800403 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800404 Slog.e(TAG, "Failure starting Wallpaper Service", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800405 }
406
407 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800408 Slog.i(TAG, "Audio Service");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800409 ServiceManager.addService(Context.AUDIO_SERVICE, new AudioService(context));
410 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800411 Slog.e(TAG, "Failure starting Audio Service", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800412 }
413
414 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800415 Slog.i(TAG, "Dock Observer");
Dan Murphyc9f4eaf2009-08-12 15:15:43 -0500416 // Listen for dock station changes
Ken Schultzf02c0742009-09-10 18:37:37 -0500417 dock = new DockObserver(context, power);
Dan Murphyc9f4eaf2009-08-12 15:15:43 -0500418 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800419 Slog.e(TAG, "Failure starting DockObserver", e);
Dan Murphyc9f4eaf2009-08-12 15:15:43 -0500420 }
421
422 try {
Praveen Bharathi21e941b2010-10-06 15:23:14 -0500423 Slog.i(TAG, "Wired Accessory Observer");
424 // Listen for wired headset changes
425 wiredAccessory = new WiredAccessoryObserver(context);
426 } catch (Throwable e) {
427 Slog.e(TAG, "Failure starting WiredAccessoryObserver", e);
428 }
429
430 try {
Mike Lockwood02e45692011-06-14 15:43:51 -0400431 Slog.i(TAG, "USB Service");
432 // Manage USB host and device support
Mike Lockwood770126a2010-12-09 22:30:37 -0800433 usb = new UsbService(context);
Mike Lockwoode7d511e2010-12-30 13:39:37 -0500434 ServiceManager.addService(Context.USB_SERVICE, usb);
Mike Lockwood57c798a2010-06-23 17:36:36 -0400435 } catch (Throwable e) {
Mike Lockwood770126a2010-12-09 22:30:37 -0800436 Slog.e(TAG, "Failure starting UsbService", e);
Mike Lockwood57c798a2010-06-23 17:36:36 -0400437 }
438
439 try {
Dianne Hackborn7299c412010-03-04 18:41:49 -0800440 Slog.i(TAG, "UI Mode Manager Service");
Mike Lockwood57c798a2010-06-23 17:36:36 -0400441 // Listen for UI mode changes
Dianne Hackborn7299c412010-03-04 18:41:49 -0800442 uiMode = new UiModeManagerService(context);
443 } catch (Throwable e) {
444 Slog.e(TAG, "Failure starting UiModeManagerService", e);
445 }
446
447 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800448 Slog.i(TAG, "Backup Service");
Dianne Hackbornd6847842010-01-12 18:14:19 -0800449 ServiceManager.addService(Context.BACKUP_SERVICE,
450 new BackupManagerService(context));
Christopher Tate487529a2009-04-29 14:03:25 -0700451 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800452 Slog.e(TAG, "Failure starting Backup Service", e);
Christopher Tate487529a2009-04-29 14:03:25 -0700453 }
454
455 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800456 Slog.i(TAG, "AppWidget Service");
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700457 appWidget = new AppWidgetService(context);
458 ServiceManager.addService(Context.APPWIDGET_SERVICE, appWidget);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800459 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800460 Slog.e(TAG, "Failure starting AppWidget Service", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800461 }
462
463 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800464 Slog.i(TAG, "Recognition Service");
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800465 recognition = new RecognitionManagerService(context);
466 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800467 Slog.e(TAG, "Failure starting Recognition Service", e);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800468 }
Jaikumar Ganesh7d0548d2010-10-18 15:29:09 -0700469
Nick Pelly038cabe2010-09-23 16:12:11 -0700470 try {
Dan Egnor621bc542010-03-25 16:20:14 -0700471 Slog.i(TAG, "DiskStats Service");
472 ServiceManager.addService("diskstats", new DiskStatsService(context));
473 } catch (Throwable e) {
474 Slog.e(TAG, "Failure starting DiskStats Service", e);
475 }
Sen Hubde75702010-05-28 01:54:03 -0700476
477 try {
478 // need to add this service even if SamplingProfilerIntegration.isEnabled()
479 // is false, because it is this service that detects system property change and
480 // turns on SamplingProfilerIntegration. Plus, when sampling profiler doesn't work,
481 // there is little overhead for running this service.
482 Slog.i(TAG, "SamplingProfiler Service");
483 ServiceManager.addService("samplingprofiler",
484 new SamplingProfilerService(context));
485 } catch (Throwable e) {
486 Slog.e(TAG, "Failure starting SamplingProfiler Service", e);
487 }
Chung-yih Wang024d5962010-08-06 12:06:04 +0800488
489 try {
Amith Yamasani6734b9f62010-09-13 16:24:08 -0700490 Slog.i(TAG, "NetworkTimeUpdateService");
491 networkTimeUpdater = new NetworkTimeUpdateService(context);
492 } catch (Throwable e) {
493 Slog.e(TAG, "Failure starting NetworkTimeUpdate service");
494 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800495 }
496
Dianne Hackborn6af0d502009-09-28 13:25:46 -0700497 // Before things start rolling, be sure we have decided whether
498 // we are in safe mode.
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700499 final boolean safeMode = wm.detectSafeMode();
Dianne Hackborn6af0d502009-09-28 13:25:46 -0700500 if (safeMode) {
Jeff Brownb09abc12011-01-13 21:08:27 -0800501 ActivityManagerService.self().enterSafeMode();
502 // Post the safe mode state in the Zygote class
503 Zygote.systemInSafeMode = true;
504 // Disable the JIT for the system_server process
505 VMRuntime.getRuntime().disableJitCompilation();
Ben Cheng6c0afff2010-02-14 16:18:56 -0800506 } else {
507 // Enable the JIT for the system_server process
508 VMRuntime.getRuntime().startJitCompilation();
Dianne Hackborn6af0d502009-09-28 13:25:46 -0700509 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800510
Dianne Hackborn6af0d502009-09-28 13:25:46 -0700511 // It is now time to start up the app processes...
Joe Onorato30275482009-07-08 17:09:14 -0700512
Dianne Hackbornd6847842010-01-12 18:14:19 -0800513 if (devicePolicy != null) {
514 devicePolicy.systemReady();
515 }
516
Joe Onorato30275482009-07-08 17:09:14 -0700517 if (notification != null) {
518 notification.systemReady();
519 }
520
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800521 wm.systemReady();
Joe Onoratodc565f42010-10-04 15:27:22 -0400522
Jeff Brownb09abc12011-01-13 21:08:27 -0800523 if (safeMode) {
524 ActivityManagerService.self().showSafeModeOverlay();
525 }
526
Joe Onoratodc565f42010-10-04 15:27:22 -0400527 // Update the configuration for this context by hand, because we're going
528 // to start using it before the config change done in wm.systemReady() will
529 // propagate to it.
530 Configuration config = wm.computeNewConfiguration();
531 DisplayMetrics metrics = new DisplayMetrics();
532 WindowManager w = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
533 w.getDefaultDisplay().getMetrics(metrics);
534 context.getResources().updateConfiguration(config, metrics);
535
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800536 power.systemReady();
537 try {
538 pm.systemReady();
539 } catch (RemoteException e) {
540 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800541
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700542 // These are needed to propagate to the runnable below.
Joe Onoratof3c3c4f2010-10-21 11:09:02 -0400543 final Context contextF = context;
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700544 final BatteryService batteryF = battery;
Jeff Sharkey350083e2011-06-29 10:45:16 -0700545 final NetworkManagementService networkManagementF = networkManagement;
Jeff Sharkey75279902011-05-24 18:39:45 -0700546 final NetworkStatsService networkStatsF = networkStats;
Jeff Sharkeya4620792011-05-20 15:29:23 -0700547 final NetworkPolicyManagerService networkPolicyF = networkPolicy;
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700548 final ConnectivityService connectivityF = connectivity;
549 final DockObserver dockF = dock;
Mike Lockwood770126a2010-12-09 22:30:37 -0800550 final UsbService usbF = usb;
Robert Greenwalt9e696c22010-04-01 14:45:18 -0700551 final ThrottleService throttleF = throttle;
Dianne Hackborn7299c412010-03-04 18:41:49 -0800552 final UiModeManagerService uiModeF = uiMode;
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700553 final AppWidgetService appWidgetF = appWidget;
554 final WallpaperManagerService wallpaperF = wallpaper;
555 final InputMethodManagerService immF = imm;
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800556 final RecognitionManagerService recognitionF = recognition;
Mike Lockwood46db5042010-02-22 16:36:44 -0500557 final LocationManagerService locationF = location;
Bai Taoa58a8752010-07-13 15:32:16 +0800558 final CountryDetectorService countryDetectorF = countryDetector;
Amith Yamasani6734b9f62010-09-13 16:24:08 -0700559 final NetworkTimeUpdateService networkTimeUpdaterF = networkTimeUpdater;
satok988323c2011-06-22 16:38:13 +0900560 final TextServicesManagerService textServiceManagerServiceF = tsms;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800561
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700562 // We now tell the activity manager it is okay to run third party
563 // code. It will call back into us once it has gotten to the state
564 // where third party code can really run (but before it has actually
565 // started launching the initial applications), for us to complete our
566 // initialization.
567 ((ActivityManagerService)ActivityManagerNative.getDefault())
568 .systemReady(new Runnable() {
569 public void run() {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800570 Slog.i(TAG, "Making services ready");
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800571
Joe Onoratof3c3c4f2010-10-21 11:09:02 -0400572 startSystemUi(contextF);
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700573 if (batteryF != null) batteryF.systemReady();
Jeff Sharkey350083e2011-06-29 10:45:16 -0700574 if (networkManagementF != null) networkManagementF.systemReady();
Jeff Sharkey75279902011-05-24 18:39:45 -0700575 if (networkStatsF != null) networkStatsF.systemReady();
Jeff Sharkeya4620792011-05-20 15:29:23 -0700576 if (networkPolicyF != null) networkPolicyF.systemReady();
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700577 if (connectivityF != null) connectivityF.systemReady();
578 if (dockF != null) dockF.systemReady();
Mike Lockwood57c798a2010-06-23 17:36:36 -0400579 if (usbF != null) usbF.systemReady();
Dianne Hackborn7299c412010-03-04 18:41:49 -0800580 if (uiModeF != null) uiModeF.systemReady();
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800581 if (recognitionF != null) recognitionF.systemReady();
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700582 Watchdog.getInstance().start();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800583
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700584 // It is now okay to let the various system services start their
585 // third party code...
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800586
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700587 if (appWidgetF != null) appWidgetF.systemReady(safeMode);
588 if (wallpaperF != null) wallpaperF.systemReady();
589 if (immF != null) immF.systemReady();
Mike Lockwood46db5042010-02-22 16:36:44 -0500590 if (locationF != null) locationF.systemReady();
Bai Taoa58a8752010-07-13 15:32:16 +0800591 if (countryDetectorF != null) countryDetectorF.systemReady();
Robert Greenwalt9e696c22010-04-01 14:45:18 -0700592 if (throttleF != null) throttleF.systemReady();
Amith Yamasani6734b9f62010-09-13 16:24:08 -0700593 if (networkTimeUpdaterF != null) networkTimeUpdaterF.systemReady();
satok988323c2011-06-22 16:38:13 +0900594 if (textServiceManagerServiceF != null) textServiceManagerServiceF.systemReady();
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700595 }
596 });
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800597
Brad Fitzpatrick1e02d362010-09-10 09:19:50 -0700598 // For debug builds, log event loop stalls to dropbox for analysis.
Brad Fitzpatrick50d66f92010-09-13 21:29:05 -0700599 if (StrictMode.conditionallyEnableDebugLogging()) {
600 Slog.i(TAG, "Enabled StrictMode for system server main thread.");
Brad Fitzpatrick1e02d362010-09-10 09:19:50 -0700601 }
602
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800603 Looper.loop();
Joe Onorato8a9b2202010-02-26 18:56:32 -0800604 Slog.d(TAG, "System ServerThread is exiting!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800605 }
Joe Onoratof3c3c4f2010-10-21 11:09:02 -0400606
607 static final void startSystemUi(Context context) {
608 Intent intent = new Intent();
609 intent.setComponent(new ComponentName("com.android.systemui",
610 "com.android.systemui.SystemUIService"));
611 Slog.d(TAG, "Starting service: " + intent);
612 context.startService(intent);
613 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800614}
615
Jeff Hamilton35eef702010-06-09 15:45:18 -0500616public class SystemServer {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800617 private static final String TAG = "SystemServer";
618
619 public static final int FACTORY_TEST_OFF = 0;
620 public static final int FACTORY_TEST_LOW_LEVEL = 1;
621 public static final int FACTORY_TEST_HIGH_LEVEL = 2;
Jaikumar Ganeshd5ac1ae2009-05-05 22:26:12 -0700622
Bob Leee5408332009-09-04 18:31:17 -0700623 static Timer timer;
624 static final long SNAPSHOT_INTERVAL = 60 * 60 * 1000; // 1hr
625
Brad Fitzpatrick6bb7a4a2010-10-11 13:41:10 -0700626 // The earliest supported time. We pick one day into 1970, to
627 // give any timezone code room without going into negative time.
628 private static final long EARLIEST_SUPPORTED_TIME = 86400 * 1000;
629
Jaikumar Ganeshd5ac1ae2009-05-05 22:26:12 -0700630 /**
631 * 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 -0800632 * services (SurfaceFlinger, AudioFlinger, etc..) to be started. After that it will call back
633 * up into init2() to start the Android services.
Jaikumar Ganeshd5ac1ae2009-05-05 22:26:12 -0700634 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800635 native public static void init1(String[] args);
636
637 public static void main(String[] args) {
Brad Fitzpatrick6bb7a4a2010-10-11 13:41:10 -0700638 if (System.currentTimeMillis() < EARLIEST_SUPPORTED_TIME) {
Brad Fitzpatrick35ca9d82010-10-11 11:52:49 -0700639 // If a device's clock is before 1970 (before 0), a lot of
640 // APIs crash dealing with negative numbers, notably
641 // java.io.File#setLastModified, so instead we fake it and
642 // hope that time from cell towers or NTP fixes it
643 // shortly.
644 Slog.w(TAG, "System clock is before 1970; setting to 1970.");
Brad Fitzpatrick6bb7a4a2010-10-11 13:41:10 -0700645 SystemClock.setCurrentTimeMillis(EARLIEST_SUPPORTED_TIME);
Brad Fitzpatrick35ca9d82010-10-11 11:52:49 -0700646 }
647
Bob Leee5408332009-09-04 18:31:17 -0700648 if (SamplingProfilerIntegration.isEnabled()) {
649 SamplingProfilerIntegration.start();
650 timer = new Timer();
651 timer.schedule(new TimerTask() {
652 @Override
653 public void run() {
Sen Hubde75702010-05-28 01:54:03 -0700654 SamplingProfilerIntegration.writeSnapshot("system_server", null);
Bob Leee5408332009-09-04 18:31:17 -0700655 }
656 }, SNAPSHOT_INTERVAL, SNAPSHOT_INTERVAL);
657 }
658
Dianne Hackbornac1471a2011-02-03 13:46:06 -0800659 // Mmmmmm... more memory!
660 dalvik.system.VMRuntime.getRuntime().clearGrowthLimit();
661
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800662 // The system server has to run all of the time, so it needs to be
663 // as efficient as possible with its memory usage.
664 VMRuntime.getRuntime().setTargetHeapUtilization(0.8f);
Sen Hubde75702010-05-28 01:54:03 -0700665
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800666 System.loadLibrary("android_servers");
667 init1(args);
668 }
669
670 public static final void init2() {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800671 Slog.i(TAG, "Entered the Android system server!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800672 Thread thr = new ServerThread();
673 thr.setName("android.server.ServerThread");
674 thr.start();
675 }
676}