blob: 38f4c78db3edc69497209946f79a54f8a48ff25b [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
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080019import android.app.ActivityManagerNative;
Adam Lesinskief2ea1f2013-12-05 16:48:06 -080020import android.app.IAlarmManager;
21import android.app.INotificationManager;
Nick Pellyf242b7b2009-10-08 00:12:45 +020022import android.bluetooth.BluetoothAdapter;
Joe Onoratof3c3c4f2010-10-21 11:09:02 -040023import android.content.ComponentName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080024import android.content.ContentResolver;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080025import 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;
Matthew Xie1dd01eb32013-04-26 12:37:54 -070028import android.content.pm.PackageManager;
Joe Onoratodc565f42010-10-04 15:27:22 -040029import android.content.res.Configuration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080030import android.media.AudioService;
Jeff Sharkey48749fc2013-04-19 13:25:04 -070031import android.os.Environment;
Jeff Brownbd6e1502012-08-28 03:27:37 -070032import android.os.Handler;
33import android.os.HandlerThread;
Jeff Hamilton35eef702010-06-09 15:45:18 -050034import android.os.Looper;
35import android.os.RemoteException;
36import android.os.ServiceManager;
Brad Fitzpatrickc74a1b442010-09-10 16:03:29 -070037import android.os.StrictMode;
Jeff Hamilton35eef702010-06-09 15:45:18 -050038import android.os.SystemClock;
39import android.os.SystemProperties;
Amith Yamasanicd757062012-10-19 18:23:52 -070040import android.os.UserHandle;
Dianne Hackbornbe87e2f2012-09-28 16:31:34 -070041import android.service.dreams.DreamService;
Joe Onoratodc565f42010-10-04 15:27:22 -040042import android.util.DisplayMetrics;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080043import android.util.EventLog;
Dianne Hackborn661cd522011-08-22 00:26:20 -070044import android.util.Log;
Joe Onorato8a9b2202010-02-26 18:56:32 -080045import android.util.Slog;
Brad Fitzpatrick5fdc0c72010-10-12 13:12:18 -070046import android.view.WindowManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080047
Dan Morrille4d9a012013-03-28 18:10:43 -070048import com.android.internal.R;
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -070049import com.android.internal.os.BinderInternal;
50import com.android.internal.os.SamplingProfilerIntegration;
51import com.android.server.accessibility.AccessibilityManagerService;
Jeff Sharkey7a96c392012-11-15 14:01:46 -080052import com.android.server.accounts.AccountManagerService;
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -070053import com.android.server.am.ActivityManagerService;
Jeff Brown96307042012-07-27 15:51:34 -070054import com.android.server.am.BatteryStatsService;
Amith Yamasani30f8eb42013-11-06 14:54:50 -080055import com.android.server.appwidget.AppWidgetService;
56import com.android.server.backup.BackupManagerService;
57import com.android.server.clipboard.ClipboardService;
Jeff Sharkey7a96c392012-11-15 14:01:46 -080058import com.android.server.content.ContentService;
Amith Yamasani30f8eb42013-11-06 14:54:50 -080059import com.android.server.devicepolicy.DevicePolicyManagerService;
Jeff Brownfa25bf52012-07-23 19:26:30 -070060import com.android.server.display.DisplayManagerService;
Jeff Browncef440f2012-09-25 18:58:48 -070061import com.android.server.dreams.DreamManagerService;
Jeff Brown6ec6f792012-04-17 16:52:41 -070062import com.android.server.input.InputManagerService;
Adam Lesinskief2ea1f2013-12-05 16:48:06 -080063import com.android.server.lights.LightsManager;
64import com.android.server.lights.LightsService;
Jeff Brown69b07162013-11-07 00:30:16 -080065import com.android.server.media.MediaRouterService;
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -070066import com.android.server.net.NetworkPolicyManagerService;
Jeff Sharkey75279902011-05-24 18:39:45 -070067import com.android.server.net.NetworkStatsService;
Adam Lesinskief2ea1f2013-12-05 16:48:06 -080068import com.android.server.notification.NotificationManagerService;
Jeff Sharkey7a96c392012-11-15 14:01:46 -080069import com.android.server.os.SchedulingPolicyService;
Jeff Brownf69c8122012-09-12 17:00:34 -070070import com.android.server.pm.Installer;
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -070071import com.android.server.pm.PackageManagerService;
Amith Yamasani258848d2012-08-10 17:06:33 -070072import com.android.server.pm.UserManagerService;
Jeff Brown4f8ecd82012-06-18 18:29:13 -070073import com.android.server.power.PowerManagerService;
74import com.android.server.power.ShutdownThread;
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -070075import com.android.server.print.PrintManagerService;
Jeff Sharkey7a96c392012-11-15 14:01:46 -080076import com.android.server.search.SearchManagerService;
Adam Lesinskief2ea1f2013-12-05 16:48:06 -080077import com.android.server.statusbar.StatusBarManagerService;
78import com.android.server.storage.DeviceStorageMonitorService;
79import com.android.server.twilight.TwilightManager;
80import com.android.server.twilight.TwilightService;
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -070081import com.android.server.usb.UsbService;
Amith Yamasani30f8eb42013-11-06 14:54:50 -080082import com.android.server.wallpaper.WallpaperManagerService;
Irfan Sheriffd017f352013-02-20 13:30:44 -080083import com.android.server.wifi.WifiService;
Vinit Deshapndeffadfb92013-12-06 15:12:41 -080084import com.android.server.wifi.p2p.WifiP2pService;
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -070085import com.android.server.wm.WindowManagerService;
86
87import dalvik.system.VMRuntime;
88import dalvik.system.Zygote;
89
Dan Egnor4410ec82009-09-11 16:40:01 -070090import java.io.File;
Bob Leee5408332009-09-04 18:31:17 -070091import java.util.Timer;
92import java.util.TimerTask;
93
Dianne Hackbornefa92b22013-05-03 14:11:43 -070094class ServerThread {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080095 private static final String TAG = "SystemServer";
Ben Komalo553acf02011-09-19 14:25:28 -070096 private static final String ENCRYPTING_STATE = "trigger_restart_min_framework";
Ben Komalo3573d402011-09-23 15:08:24 -070097 private static final String ENCRYPTED_STATE = "1";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080098
Jeff Hamilton35eef702010-06-09 15:45:18 -050099 ContentResolver mContentResolver;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800100
Dianne Hackborn661cd522011-08-22 00:26:20 -0700101 void reportWtf(String msg, Throwable e) {
102 Slog.w(TAG, "***********************************************");
103 Log.wtf(TAG, "BOOT FAILURE " + msg, e);
104 }
105
Dianne Hackbornefa92b22013-05-03 14:11:43 -0700106 public void initAndLoop() {
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800107 EventLog.writeEvent(EventLogTags.BOOT_PROGRESS_SYSTEM_RUN,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800108 SystemClock.uptimeMillis());
109
Vairavan Srinivasan04b74ec2012-02-02 22:12:19 -0800110 Looper.prepareMainLooper();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800111
112 android.os.Process.setThreadPriority(
113 android.os.Process.THREAD_PRIORITY_FOREGROUND);
114
Dianne Hackborn887f3552009-12-07 17:59:37 -0800115 BinderInternal.disableBackgroundScheduling(true);
Christopher Tate160edb32010-06-30 17:46:30 -0700116 android.os.Process.setCanSelfBackground(false);
Sen Hubde75702010-05-28 01:54:03 -0700117
Kenny Rootf547d672010-09-22 10:36:48 -0700118 // Check whether we failed to shut down last time we tried.
119 {
120 final String shutdownAction = SystemProperties.get(
121 ShutdownThread.SHUTDOWN_ACTION_PROPERTY, "");
122 if (shutdownAction != null && shutdownAction.length() > 0) {
123 boolean reboot = (shutdownAction.charAt(0) == '1');
124
125 final String reason;
126 if (shutdownAction.length() > 1) {
127 reason = shutdownAction.substring(1, shutdownAction.length());
128 } else {
129 reason = null;
130 }
131
132 ShutdownThread.rebootOrShutdown(reboot, reason);
133 }
134 }
135
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800136 String factoryTestStr = SystemProperties.get("ro.factorytest");
137 int factoryTest = "".equals(factoryTestStr) ? SystemServer.FACTORY_TEST_OFF
138 : Integer.parseInt(factoryTestStr);
139
Jeff Brownf69c8122012-09-12 17:00:34 -0700140 Installer installer = null;
Kenny Root26ff6622012-07-30 12:58:03 -0700141 AccountManagerService accountManager = null;
142 ContentService contentService = null;
Adam Lesinskief2ea1f2013-12-05 16:48:06 -0800143 LightsManager lights = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800144 PowerManagerService power = null;
Jeff Brownfa25bf52012-07-23 19:26:30 -0700145 DisplayManagerService display = null;
Mike Lockwood07a500f2009-08-12 09:56:44 -0400146 BatteryService battery = null;
Jeff Brown7f6c2312012-04-13 20:38:38 -0700147 VibratorService vibrator = null;
Adam Lesinskief2ea1f2013-12-05 16:48:06 -0800148 IAlarmManager alarm = null;
Jeff Sharkeyb049e212012-09-07 23:16:01 -0700149 MountService mountService = null;
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -0700150 NetworkManagementService networkManagement = null;
Jeff Sharkey75279902011-05-24 18:39:45 -0700151 NetworkStatsService networkStats = null;
Jeff Sharkeya4620792011-05-20 15:29:23 -0700152 NetworkPolicyManagerService networkPolicy = null;
Mike Lockwood0f79b542009-08-14 14:18:49 -0400153 ConnectivityService connectivity = null;
repo sync55bc5f32011-06-24 14:23:07 -0700154 WifiP2pService wifiP2p = null;
repo syncaea743a2011-07-29 23:55:49 -0700155 WifiService wifi = null;
Irfan Sheriff7d024d32012-03-22 17:01:39 -0700156 NsdService serviceDiscovery= null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800157 IPackageManager pm = null;
158 Context context = null;
159 WindowManagerService wm = null;
fredc0f420372012-04-12 00:02:00 -0700160 BluetoothManagerService bluetooth = null;
Dan Murphyc9f4eaf2009-08-12 15:15:43 -0500161 DockObserver dock = null;
Mike Lockwood770126a2010-12-09 22:30:37 -0800162 UsbService usb = null;
Mike Lockwoodb01e8bf2011-08-29 20:11:07 -0400163 SerialService serial = null;
Adam Lesinskief2ea1f2013-12-05 16:48:06 -0800164 TwilightManager twilight = null;
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800165 RecognitionManagerService recognition = null;
Amith Yamasani6734b9f2010-09-13 16:24:08 -0700166 NetworkTimeUpdateService networkTimeUpdater = null;
John Grossmanc1576732012-02-01 15:23:33 -0800167 CommonTimeManagementService commonTimeMgmtService = null;
Jeff Brown6ec6f792012-04-17 16:52:41 -0700168 InputManagerService inputManager = null;
Wink Savillea12a7b32012-09-20 10:09:45 -0700169 TelephonyRegistry telephonyRegistry = null;
Erik Gilling51e95df2013-06-26 11:06:51 -0700170 ConsumerIrService consumerIr = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800171
Jeff Brownbd6e1502012-08-28 03:27:37 -0700172 // Create a handler thread just for the window manager to enjoy.
173 HandlerThread wmHandlerThread = new HandlerThread("WindowManager");
174 wmHandlerThread.start();
175 Handler wmHandler = new Handler(wmHandlerThread.getLooper());
176 wmHandler.post(new Runnable() {
177 @Override
178 public void run() {
179 //Looper.myLooper().setMessageLogging(new LogPrinter(
180 // android.util.Log.DEBUG, TAG, android.util.Log.LOG_ID_SYSTEM));
181 android.os.Process.setThreadPriority(
182 android.os.Process.THREAD_PRIORITY_DISPLAY);
183 android.os.Process.setCanSelfBackground(false);
184
185 // For debug builds, log event loop stalls to dropbox for analysis.
186 if (StrictMode.conditionallyEnableDebugLogging()) {
Jeff Brown89d55462012-09-19 11:33:42 -0700187 Slog.i(TAG, "Enabled StrictMode logging for WM Looper");
Jeff Brownbd6e1502012-08-28 03:27:37 -0700188 }
189 }
190 });
191
Dan Morrille4d9a012013-03-28 18:10:43 -0700192 // bootstrap services
Jeff Brownbd6e1502012-08-28 03:27:37 -0700193 boolean onlyCore = false;
Dan Morrille4d9a012013-03-28 18:10:43 -0700194 boolean firstBoot = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800195 try {
Jeff Brownf69c8122012-09-12 17:00:34 -0700196 // Wait for installd to finished starting up so that it has a chance to
197 // create critical directories such as /data/user with the appropriate
198 // permissions. We need this to complete before we initialize other services.
199 Slog.i(TAG, "Waiting for installd to be ready.");
200 installer = new Installer();
201 installer.ping();
202
Joe Onorato8a9b2202010-02-26 18:56:32 -0800203 Slog.i(TAG, "Power Manager");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800204 power = new PowerManagerService();
205 ServiceManager.addService(Context.POWER_SERVICE, power);
206
Joe Onorato8a9b2202010-02-26 18:56:32 -0800207 Slog.i(TAG, "Activity Manager");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800208 context = ActivityManagerService.main(factoryTest);
Dan Morrille4d9a012013-03-28 18:10:43 -0700209 } catch (RuntimeException e) {
210 Slog.e("System", "******************************************");
211 Slog.e("System", "************ Failure starting bootstrap service", e);
212 }
Jeff Brown848c2dc2012-08-19 20:18:08 -0700213
Adam Lesinskief2ea1f2013-12-05 16:48:06 -0800214 final SystemServiceManager systemServiceManager = new SystemServiceManager(context);
215
Dan Morrille4d9a012013-03-28 18:10:43 -0700216 boolean disableStorage = SystemProperties.getBoolean("config.disable_storage", false);
217 boolean disableMedia = SystemProperties.getBoolean("config.disable_media", false);
218 boolean disableBluetooth = SystemProperties.getBoolean("config.disable_bluetooth", false);
219 boolean disableTelephony = SystemProperties.getBoolean("config.disable_telephony", false);
220 boolean disableLocation = SystemProperties.getBoolean("config.disable_location", false);
221 boolean disableSystemUI = SystemProperties.getBoolean("config.disable_systemui", false);
222 boolean disableNonCoreServices = SystemProperties.getBoolean("config.disable_noncore", false);
223 boolean disableNetwork = SystemProperties.getBoolean("config.disable_network", false);
224
225 try {
Jeff Brown848c2dc2012-08-19 20:18:08 -0700226 Slog.i(TAG, "Display Manager");
Dianne Hackborn8d044e82013-04-30 17:24:15 -0700227 display = new DisplayManagerService(context, wmHandler);
Jeff Brown848c2dc2012-08-19 20:18:08 -0700228 ServiceManager.addService(Context.DISPLAY_SERVICE, display, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800229
Joe Onorato8a9b2202010-02-26 18:56:32 -0800230 Slog.i(TAG, "Telephony Registry");
Wink Savillea12a7b32012-09-20 10:09:45 -0700231 telephonyRegistry = new TelephonyRegistry(context);
232 ServiceManager.addService("telephony.registry", telephonyRegistry);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800233
Glenn Kasten07b04652012-04-23 15:00:43 -0700234 Slog.i(TAG, "Scheduling Policy");
Dianne Hackborn35f72be2013-09-16 10:57:39 -0700235 ServiceManager.addService("scheduling_policy", new SchedulingPolicyService());
Glenn Kasten07b04652012-04-23 15:00:43 -0700236
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800237 AttributeCache.init(context);
238
Jeff Brownbd6e1502012-08-28 03:27:37 -0700239 if (!display.waitForDefaultDisplay()) {
240 reportWtf("Timeout waiting for default display to be initialized.",
241 new Throwable());
242 }
243
Joe Onorato8a9b2202010-02-26 18:56:32 -0800244 Slog.i(TAG, "Package Manager");
Ben Komalo553acf02011-09-19 14:25:28 -0700245 // Only run "core" apps if we're encrypting the device.
246 String cryptState = SystemProperties.get("vold.decrypt");
Ben Komalo3573d402011-09-23 15:08:24 -0700247 if (ENCRYPTING_STATE.equals(cryptState)) {
Ben Komalo553acf02011-09-19 14:25:28 -0700248 Slog.w(TAG, "Detected encryption in progress - only parsing core apps");
Ben Komalo3573d402011-09-23 15:08:24 -0700249 onlyCore = true;
250 } else if (ENCRYPTED_STATE.equals(cryptState)) {
251 Slog.w(TAG, "Device encrypted - only parsing core apps");
252 onlyCore = true;
Ben Komalo553acf02011-09-19 14:25:28 -0700253 }
Ben Komalo3573d402011-09-23 15:08:24 -0700254
Jeff Brownf69c8122012-09-12 17:00:34 -0700255 pm = PackageManagerService.main(context, installer,
Dianne Hackbornd2509fd2011-09-12 12:29:43 -0700256 factoryTest != SystemServer.FACTORY_TEST_OFF,
Ben Komalo553acf02011-09-19 14:25:28 -0700257 onlyCore);
Dianne Hackborn58f42a52011-10-10 13:46:34 -0700258 try {
259 firstBoot = pm.isFirstBoot();
260 } catch (RemoteException e) {
261 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800262
263 ActivityManagerService.setSystemProcess();
Svetoslavb3038ec2013-02-13 14:39:30 -0800264
Nick Kralevich79619dd2013-03-04 13:05:32 -0800265 Slog.i(TAG, "Entropy Mixer");
266 ServiceManager.addService("entropy", new EntropyMixer(context));
267
Amith Yamasani258848d2012-08-10 17:06:33 -0700268 Slog.i(TAG, "User Service");
269 ServiceManager.addService(Context.USER_SERVICE,
Dianne Hackborn4428e172012-08-24 17:43:05 -0700270 UserManagerService.getInstance());
Amith Yamasani258848d2012-08-10 17:06:33 -0700271
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800272 mContentResolver = context.getContentResolver();
273
Fred Quintanae91ebe22009-09-29 20:44:30 -0700274 // The AccountManager must come before the ContentService
Fred Quintana60307342009-03-24 22:48:12 -0700275 try {
Dan Morrille4d9a012013-03-28 18:10:43 -0700276 // TODO: seems like this should be disable-able, but req'd by ContentService
Joe Onorato8a9b2202010-02-26 18:56:32 -0800277 Slog.i(TAG, "Account Manager");
Kenny Root26ff6622012-07-30 12:58:03 -0700278 accountManager = new AccountManagerService(context);
279 ServiceManager.addService(Context.ACCOUNT_SERVICE, accountManager);
Fred Quintana60307342009-03-24 22:48:12 -0700280 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800281 Slog.e(TAG, "Failure starting Account Manager", e);
Fred Quintana60307342009-03-24 22:48:12 -0700282 }
283
Joe Onorato8a9b2202010-02-26 18:56:32 -0800284 Slog.i(TAG, "Content Manager");
Kenny Root26ff6622012-07-30 12:58:03 -0700285 contentService = ContentService.main(context,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800286 factoryTest == SystemServer.FACTORY_TEST_LOW_LEVEL);
287
Joe Onorato8a9b2202010-02-26 18:56:32 -0800288 Slog.i(TAG, "System Content Providers");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800289 ActivityManagerService.installSystemProviders();
290
Adam Lesinskief2ea1f2013-12-05 16:48:06 -0800291 systemServiceManager.startService(LightsService.class);
292 lights = LocalServices.getService(LightsManager.class);
Mike Lockwood3a322132009-11-24 00:30:52 -0500293
Joe Onoratode1b3592010-10-25 20:36:47 -0700294 Slog.i(TAG, "Battery Service");
295 battery = new BatteryService(context, lights);
296 ServiceManager.addService("battery", battery);
297
Joe Onorato8a9b2202010-02-26 18:56:32 -0800298 Slog.i(TAG, "Vibrator Service");
Jeff Brown7f6c2312012-04-13 20:38:38 -0700299 vibrator = new VibratorService(context);
300 ServiceManager.addService("vibrator", vibrator);
The Android Open Source Project10592532009-03-18 17:39:46 -0700301
Erik Gilling51e95df2013-06-26 11:06:51 -0700302 Slog.i(TAG, "Consumer IR Service");
303 consumerIr = new ConsumerIrService(context);
304 ServiceManager.addService(Context.CONSUMER_IR_SERVICE, consumerIr);
305
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800306 // only initialize the power service after we have started the
Mike Lockwood3a322132009-11-24 00:30:52 -0500307 // lights service, content providers and the battery service.
Adam Lesinskief2ea1f2013-12-05 16:48:06 -0800308 power.init(context, lights, battery,
Dianne Hackborn713df152013-05-17 11:27:57 -0700309 BatteryStatsService.getService(),
310 ActivityManagerService.self().getAppOpsService(), display);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800311
Adam Lesinskief2ea1f2013-12-05 16:48:06 -0800312 systemServiceManager.startService(AlarmManagerService.class);
313 alarm = IAlarmManager.Stub.asInterface(
314 ServiceManager.getService(Context.ALARM_SERVICE));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800315
Joe Onorato8a9b2202010-02-26 18:56:32 -0800316 Slog.i(TAG, "Init Watchdog");
Adam Lesinskief2ea1f2013-12-05 16:48:06 -0800317 Watchdog.getInstance().init(context, ActivityManagerService.self());
Dianne Hackborn8d044e82013-04-30 17:24:15 -0700318 Watchdog.getInstance().addThread(wmHandler, "WindowManager thread");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800319
Jeff Browna9d131c2012-09-20 16:48:17 -0700320 Slog.i(TAG, "Input Manager");
321 inputManager = new InputManagerService(context, wmHandler);
322
Joe Onorato8a9b2202010-02-26 18:56:32 -0800323 Slog.i(TAG, "Window Manager");
Jeff Browna9d131c2012-09-20 16:48:17 -0700324 wm = WindowManagerService.main(context, power, display, inputManager,
Dianne Hackborn8d044e82013-04-30 17:24:15 -0700325 wmHandler, factoryTest != SystemServer.FACTORY_TEST_LOW_LEVEL,
Jeff Brown780c46f2012-06-24 12:15:38 -0700326 !firstBoot, onlyCore);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800327 ServiceManager.addService(Context.WINDOW_SERVICE, wm);
Jeff Brown6ec6f792012-04-17 16:52:41 -0700328 ServiceManager.addService(Context.INPUT_SERVICE, inputManager);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800329
Dianne Hackborn295e3c22011-08-25 13:19:08 -0700330 ActivityManagerService.self().setWindowManager(wm);
Jeff Browna9d131c2012-09-20 16:48:17 -0700331
332 inputManager.setWindowManagerCallbacks(wm.getInputMonitor());
333 inputManager.start();
334
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700335 display.setWindowManager(wm);
Jeff Brownd728bf52012-09-08 18:05:28 -0700336 display.setInputManager(inputManager);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800337
338 // Skip Bluetooth if we have an emulator kernel
339 // TODO: Use a more reliable check to see if this product should
340 // support Bluetooth - see bug 988521
341 if (SystemProperties.get("ro.kernel.qemu").equals("1")) {
David 'Digit' Turnere2a5e862011-01-17 00:32:33 +0100342 Slog.i(TAG, "No Bluetooh Service (emulator)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800343 } else if (factoryTest == SystemServer.FACTORY_TEST_LOW_LEVEL) {
David 'Digit' Turnere2a5e862011-01-17 00:32:33 +0100344 Slog.i(TAG, "No Bluetooth Service (factory test)");
Matthew Xie1dd01eb32013-04-26 12:37:54 -0700345 } else if (!context.getPackageManager().hasSystemFeature
346 (PackageManager.FEATURE_BLUETOOTH)) {
347 Slog.i(TAG, "No Bluetooth Service (Bluetooth Hardware Not Present)");
Dan Morrille4d9a012013-03-28 18:10:43 -0700348 } else if (disableBluetooth) {
349 Slog.i(TAG, "Bluetooth Service disabled by config");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800350 } else {
fredc0f420372012-04-12 00:02:00 -0700351 Slog.i(TAG, "Bluetooth Manager Service");
352 bluetooth = new BluetoothManagerService(context);
353 ServiceManager.addService(BluetoothAdapter.BLUETOOTH_MANAGER_SERVICE, bluetooth);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800354 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800355 } catch (RuntimeException e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700356 Slog.e("System", "******************************************");
357 Slog.e("System", "************ Failure starting core service", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800358 }
359
Dianne Hackbornd6847842010-01-12 18:14:19 -0800360 DevicePolicyManagerService devicePolicy = null;
Joe Onorato089de882010-04-12 08:18:45 -0700361 StatusBarManagerService statusBar = null;
Adam Lesinskief2ea1f2013-12-05 16:48:06 -0800362 INotificationManager notification = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800363 InputMethodManagerService imm = null;
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700364 AppWidgetService appWidget = null;
Dianne Hackbornf21adf62009-08-13 10:20:21 -0700365 WallpaperManagerService wallpaper = null;
Mike Lockwood46db5042010-02-22 16:36:44 -0500366 LocationManagerService location = null;
Bai Taoa58a8752010-07-13 15:32:16 +0800367 CountryDetectorService countryDetector = null;
satok988323c2011-06-22 16:38:13 +0900368 TextServicesManagerService tsms = null;
Amith Yamasani52c489c2012-03-28 11:42:42 -0700369 LockSettingsService lockSettings = null;
Daniel Sandler7d276c32012-01-30 14:33:52 -0500370 DreamManagerService dreamy = null;
Romain Guy3b748a42013-04-17 18:54:38 -0700371 AssetAtlasService atlas = null;
Svetoslav Ganova0027152013-06-25 14:59:53 -0700372 PrintManagerService printManager = null;
Jeff Brown69b07162013-11-07 00:30:16 -0800373 MediaRouterService mediaRouter = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800374
Dianne Hackborn661cd522011-08-22 00:26:20 -0700375 // Bring up services needed for UI.
376 if (factoryTest != SystemServer.FACTORY_TEST_LOW_LEVEL) {
Dan Morrille4d9a012013-03-28 18:10:43 -0700377 //if (!disableNonCoreServices) { // TODO: View depends on these; mock them?
378 if (true) {
379 try {
380 Slog.i(TAG, "Input Method Service");
381 imm = new InputMethodManagerService(context, wm);
382 ServiceManager.addService(Context.INPUT_METHOD_SERVICE, imm);
383 } catch (Throwable e) {
384 reportWtf("starting Input Manager Service", e);
385 }
Dianne Hackborn661cd522011-08-22 00:26:20 -0700386
Dan Morrille4d9a012013-03-28 18:10:43 -0700387 try {
388 Slog.i(TAG, "Accessibility Manager");
389 ServiceManager.addService(Context.ACCESSIBILITY_SERVICE,
390 new AccessibilityManagerService(context));
391 } catch (Throwable e) {
392 reportWtf("starting Accessibility Manager", e);
393 }
Dianne Hackborn661cd522011-08-22 00:26:20 -0700394 }
395 }
396
397 try {
398 wm.displayReady();
399 } catch (Throwable e) {
400 reportWtf("making display ready", e);
401 }
Dianne Hackborn8795b602011-08-25 13:30:53 -0700402
Dianne Hackborn295e3c22011-08-25 13:19:08 -0700403 try {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700404 pm.performBootDexOpt();
405 } catch (Throwable e) {
406 reportWtf("performing boot dexopt", e);
407 }
408
409 try {
410 ActivityManagerNative.getDefault().showBootMessage(
411 context.getResources().getText(
412 com.android.internal.R.string.android_upgrading_starting_apps),
Adam Lesinskief2ea1f2013-12-05 16:48:06 -0800413 false);
Dianne Hackborn661cd522011-08-22 00:26:20 -0700414 } catch (RemoteException e) {
415 }
416
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800417 if (factoryTest != SystemServer.FACTORY_TEST_LOW_LEVEL) {
Dan Morrille4d9a012013-03-28 18:10:43 -0700418 if (!disableStorage &&
419 !"0".equals(SystemProperties.get("system_init.startmountservice"))) {
Kenny Root51a573c2012-05-17 13:30:28 -0700420 try {
421 /*
422 * NotificationManagerService is dependant on MountService,
423 * (for media / usb notifications) so we must start MountService first.
424 */
425 Slog.i(TAG, "Mount Service");
426 mountService = new MountService(context);
427 ServiceManager.addService("mount", mountService);
428 } catch (Throwable e) {
429 reportWtf("starting Mount Service", e);
430 }
431 }
432
Dan Morrille4d9a012013-03-28 18:10:43 -0700433 if (!disableNonCoreServices) {
434 try {
435 Slog.i(TAG, "LockSettingsService");
436 lockSettings = new LockSettingsService(context);
437 ServiceManager.addService("lock_settings", lockSettings);
438 } catch (Throwable e) {
439 reportWtf("starting LockSettingsService service", e);
440 }
441
442 try {
443 Slog.i(TAG, "Device Policy");
444 devicePolicy = new DevicePolicyManagerService(context);
445 ServiceManager.addService(Context.DEVICE_POLICY_SERVICE, devicePolicy);
446 } catch (Throwable e) {
447 reportWtf("starting DevicePolicyService", e);
448 }
Amith Yamasani52c489c2012-03-28 11:42:42 -0700449 }
450
Dan Morrille4d9a012013-03-28 18:10:43 -0700451 if (!disableSystemUI) {
452 try {
453 Slog.i(TAG, "Status Bar");
454 statusBar = new StatusBarManagerService(context, wm);
455 ServiceManager.addService(Context.STATUS_BAR_SERVICE, statusBar);
456 } catch (Throwable e) {
457 reportWtf("starting StatusBarManagerService", e);
458 }
Dianne Hackbornd6847842010-01-12 18:14:19 -0800459 }
460
Dan Morrille4d9a012013-03-28 18:10:43 -0700461 if (!disableNonCoreServices) {
462 try {
463 Slog.i(TAG, "Clipboard Service");
464 ServiceManager.addService(Context.CLIPBOARD_SERVICE,
465 new ClipboardService(context));
466 } catch (Throwable e) {
467 reportWtf("starting Clipboard Service", e);
468 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800469 }
470
Dan Morrille4d9a012013-03-28 18:10:43 -0700471 if (!disableNetwork) {
472 try {
473 Slog.i(TAG, "NetworkManagement Service");
474 networkManagement = NetworkManagementService.create(context);
475 ServiceManager.addService(Context.NETWORKMANAGEMENT_SERVICE, networkManagement);
476 } catch (Throwable e) {
477 reportWtf("starting NetworkManagement Service", e);
478 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800479 }
480
Dan Morrille4d9a012013-03-28 18:10:43 -0700481 if (!disableNonCoreServices) {
482 try {
483 Slog.i(TAG, "Text Service Manager Service");
484 tsms = new TextServicesManagerService(context);
485 ServiceManager.addService(Context.TEXT_SERVICES_MANAGER_SERVICE, tsms);
486 } catch (Throwable e) {
487 reportWtf("starting Text Service Manager Service", e);
488 }
San Mehatd1df8ac2010-01-26 06:17:26 -0800489 }
490
Dan Morrille4d9a012013-03-28 18:10:43 -0700491 if (!disableNetwork) {
492 try {
493 Slog.i(TAG, "NetworkStats Service");
494 networkStats = new NetworkStatsService(context, networkManagement, alarm);
495 ServiceManager.addService(Context.NETWORK_STATS_SERVICE, networkStats);
496 } catch (Throwable e) {
497 reportWtf("starting NetworkStats Service", e);
498 }
499
500 try {
501 Slog.i(TAG, "NetworkPolicy Service");
502 networkPolicy = new NetworkPolicyManagerService(
503 context, ActivityManagerService.self(), power,
504 networkStats, networkManagement);
505 ServiceManager.addService(Context.NETWORK_POLICY_SERVICE, networkPolicy);
506 } catch (Throwable e) {
507 reportWtf("starting NetworkPolicy Service", e);
508 }
509
510 try {
511 Slog.i(TAG, "Wi-Fi P2pService");
512 wifiP2p = new WifiP2pService(context);
513 ServiceManager.addService(Context.WIFI_P2P_SERVICE, wifiP2p);
514 } catch (Throwable e) {
515 reportWtf("starting Wi-Fi P2pService", e);
516 }
517
518 try {
519 Slog.i(TAG, "Wi-Fi Service");
520 wifi = new WifiService(context);
521 ServiceManager.addService(Context.WIFI_SERVICE, wifi);
522 } catch (Throwable e) {
523 reportWtf("starting Wi-Fi Service", e);
524 }
525
526 try {
527 Slog.i(TAG, "Connectivity Service");
528 connectivity = new ConnectivityService(
529 context, networkManagement, networkStats, networkPolicy);
530 ServiceManager.addService(Context.CONNECTIVITY_SERVICE, connectivity);
531 networkStats.bindConnectivityManager(connectivity);
532 networkPolicy.bindConnectivityManager(connectivity);
Vinit Deshapnde04675f62013-10-03 16:18:56 -0700533
Dan Morrille4d9a012013-03-28 18:10:43 -0700534 wifiP2p.connectivityServiceReady();
Vinit Deshapnde04675f62013-10-03 16:18:56 -0700535 wifi.checkAndStartWifi();
Dan Morrille4d9a012013-03-28 18:10:43 -0700536 } catch (Throwable e) {
537 reportWtf("starting Connectivity Service", e);
538 }
539
540 try {
541 Slog.i(TAG, "Network Service Discovery Service");
542 serviceDiscovery = NsdService.create(context);
543 ServiceManager.addService(
544 Context.NSD_SERVICE, serviceDiscovery);
545 } catch (Throwable e) {
546 reportWtf("starting Service Discovery Service", e);
547 }
satok988323c2011-06-22 16:38:13 +0900548 }
549
Dan Morrille4d9a012013-03-28 18:10:43 -0700550 if (!disableNonCoreServices) {
551 try {
552 Slog.i(TAG, "UpdateLock Service");
553 ServiceManager.addService(Context.UPDATE_LOCK_SERVICE,
554 new UpdateLockService(context));
555 } catch (Throwable e) {
556 reportWtf("starting UpdateLockService", e);
557 }
Christopher Tate8662cab52012-02-23 14:59:36 -0800558 }
559
Kenny Root51a573c2012-05-17 13:30:28 -0700560 /*
561 * MountService has a few dependencies: Notification Manager and
562 * AppWidget Provider. Make sure MountService is completely started
563 * first before continuing.
564 */
Ken Sumrall025adc42013-06-05 22:08:12 -0700565 if (mountService != null && !onlyCore) {
Kenny Root51a573c2012-05-17 13:30:28 -0700566 mountService.waitForAsecScan();
San Mehat1bf3f8b2010-02-03 14:43:09 -0800567 }
568
569 try {
Kenny Root26ff6622012-07-30 12:58:03 -0700570 if (accountManager != null)
571 accountManager.systemReady();
572 } catch (Throwable e) {
573 reportWtf("making Account Manager Service ready", e);
574 }
575
576 try {
577 if (contentService != null)
578 contentService.systemReady();
579 } catch (Throwable e) {
580 reportWtf("making Content Service ready", e);
581 }
582
Adam Lesinskief2ea1f2013-12-05 16:48:06 -0800583 systemServiceManager.startService(NotificationManagerService.class);
584 notification = INotificationManager.Stub.asInterface(
585 ServiceManager.getService(Context.NOTIFICATION_SERVICE));
586 networkPolicy.bindNotificationManager(notification);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800587
Adam Lesinskief2ea1f2013-12-05 16:48:06 -0800588 systemServiceManager.startService(DeviceStorageMonitorService.class);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800589
Dan Morrille4d9a012013-03-28 18:10:43 -0700590 if (!disableLocation) {
591 try {
592 Slog.i(TAG, "Location Manager");
593 location = new LocationManagerService(context);
594 ServiceManager.addService(Context.LOCATION_SERVICE, location);
595 } catch (Throwable e) {
596 reportWtf("starting Location Manager", e);
597 }
598
599 try {
600 Slog.i(TAG, "Country Detector");
601 countryDetector = new CountryDetectorService(context);
602 ServiceManager.addService(Context.COUNTRY_DETECTOR, countryDetector);
603 } catch (Throwable e) {
604 reportWtf("starting Country Detector", e);
605 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800606 }
607
Dan Morrille4d9a012013-03-28 18:10:43 -0700608 if (!disableNonCoreServices) {
609 try {
610 Slog.i(TAG, "Search Service");
611 ServiceManager.addService(Context.SEARCH_SERVICE,
612 new SearchManagerService(context));
613 } catch (Throwable e) {
614 reportWtf("starting Search Service", e);
615 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800616 }
617
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800618 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800619 Slog.i(TAG, "DropBox Service");
Dan Egnor95240272009-10-27 18:23:39 -0700620 ServiceManager.addService(Context.DROPBOX_SERVICE,
Dan Egnorf18a01c2009-11-12 11:32:50 -0800621 new DropBoxManagerService(context, new File("/data/system/dropbox")));
Dan Egnor4410ec82009-09-11 16:40:01 -0700622 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700623 reportWtf("starting DropBoxManagerService", e);
Dan Egnor4410ec82009-09-11 16:40:01 -0700624 }
625
Dan Morrille4d9a012013-03-28 18:10:43 -0700626 if (!disableNonCoreServices && context.getResources().getBoolean(
627 R.bool.config_enableWallpaperService)) {
Mike Lockwoodc067c9c2011-10-31 12:50:12 -0400628 try {
629 Slog.i(TAG, "Wallpaper Service");
Mike Lockwooded8902d2013-11-15 11:01:47 -0800630 wallpaper = new WallpaperManagerService(context);
631 ServiceManager.addService(Context.WALLPAPER_SERVICE, wallpaper);
Mike Lockwoodc067c9c2011-10-31 12:50:12 -0400632 } catch (Throwable e) {
633 reportWtf("starting Wallpaper Service", e);
Mike Lockwood3a74bd32011-08-12 13:55:22 -0700634 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800635 }
636
Dan Morrille4d9a012013-03-28 18:10:43 -0700637 if (!disableMedia && !"0".equals(SystemProperties.get("system_init.startaudioservice"))) {
Mike Lockwoodcba928c2011-08-17 15:58:52 -0700638 try {
639 Slog.i(TAG, "Audio Service");
640 ServiceManager.addService(Context.AUDIO_SERVICE, new AudioService(context));
641 } catch (Throwable e) {
642 reportWtf("starting Audio Service", e);
643 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800644 }
645
Dan Morrille4d9a012013-03-28 18:10:43 -0700646 if (!disableNonCoreServices) {
647 try {
648 Slog.i(TAG, "Dock Observer");
649 // Listen for dock station changes
650 dock = new DockObserver(context);
651 } catch (Throwable e) {
652 reportWtf("starting DockObserver", e);
653 }
Dan Murphyc9f4eaf2009-08-12 15:15:43 -0500654 }
655
Dan Morrille4d9a012013-03-28 18:10:43 -0700656 if (!disableMedia) {
657 try {
658 Slog.i(TAG, "Wired Accessory Manager");
659 // Listen for wired headset changes
660 inputManager.setWiredAccessoryCallbacks(
661 new WiredAccessoryManager(context, inputManager));
662 } catch (Throwable e) {
663 reportWtf("starting WiredAccessoryManager", e);
664 }
Praveen Bharathi21e941b2010-10-06 15:23:14 -0500665 }
666
Dan Morrille4d9a012013-03-28 18:10:43 -0700667 if (!disableNonCoreServices) {
668 try {
669 Slog.i(TAG, "USB Service");
670 // Manage USB host and device support
671 usb = new UsbService(context);
672 ServiceManager.addService(Context.USB_SERVICE, usb);
673 } catch (Throwable e) {
674 reportWtf("starting UsbService", e);
675 }
Mike Lockwood57c798a2010-06-23 17:36:36 -0400676
Dan Morrille4d9a012013-03-28 18:10:43 -0700677 try {
678 Slog.i(TAG, "Serial Service");
679 // Serial port support
680 serial = new SerialService(context);
681 ServiceManager.addService(Context.SERIAL_SERVICE, serial);
682 } catch (Throwable e) {
683 Slog.e(TAG, "Failure starting SerialService", e);
684 }
Mike Lockwoodb01e8bf2011-08-29 20:11:07 -0400685 }
686
Adam Lesinskief2ea1f2013-12-05 16:48:06 -0800687 systemServiceManager.startService(TwilightService.class);
688 twilight = LocalServices.getService(TwilightManager.class);
Jeff Brown2416e092012-08-21 22:12:20 -0700689
Adam Lesinskief2ea1f2013-12-05 16:48:06 -0800690 systemServiceManager.startService(UiModeManagerService.class);
Dianne Hackborn7299c412010-03-04 18:41:49 -0800691
Dan Morrille4d9a012013-03-28 18:10:43 -0700692 if (!disableNonCoreServices) {
693 try {
694 Slog.i(TAG, "Backup Service");
695 ServiceManager.addService(Context.BACKUP_SERVICE,
696 new BackupManagerService(context));
697 } catch (Throwable e) {
698 Slog.e(TAG, "Failure starting Backup Service", e);
699 }
Christopher Tate487529a2009-04-29 14:03:25 -0700700
Dan Morrille4d9a012013-03-28 18:10:43 -0700701 try {
702 Slog.i(TAG, "AppWidget Service");
703 appWidget = new AppWidgetService(context);
704 ServiceManager.addService(Context.APPWIDGET_SERVICE, appWidget);
705 } catch (Throwable e) {
706 reportWtf("starting AppWidget Service", e);
707 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800708
Dan Morrille4d9a012013-03-28 18:10:43 -0700709 try {
710 Slog.i(TAG, "Recognition Service");
711 recognition = new RecognitionManagerService(context);
712 } catch (Throwable e) {
713 reportWtf("starting Recognition Service", e);
714 }
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800715 }
Jaikumar Ganesh7d0548d2010-10-18 15:29:09 -0700716
Nick Pelly038cabe2010-09-23 16:12:11 -0700717 try {
Dan Egnor621bc542010-03-25 16:20:14 -0700718 Slog.i(TAG, "DiskStats Service");
719 ServiceManager.addService("diskstats", new DiskStatsService(context));
720 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700721 reportWtf("starting DiskStats Service", e);
Dan Egnor621bc542010-03-25 16:20:14 -0700722 }
Sen Hubde75702010-05-28 01:54:03 -0700723
724 try {
725 // need to add this service even if SamplingProfilerIntegration.isEnabled()
726 // is false, because it is this service that detects system property change and
727 // turns on SamplingProfilerIntegration. Plus, when sampling profiler doesn't work,
728 // there is little overhead for running this service.
729 Slog.i(TAG, "SamplingProfiler Service");
730 ServiceManager.addService("samplingprofiler",
731 new SamplingProfilerService(context));
732 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700733 reportWtf("starting SamplingProfiler Service", e);
Sen Hubde75702010-05-28 01:54:03 -0700734 }
Chung-yih Wang024d5962010-08-06 12:06:04 +0800735
Dan Morrille4d9a012013-03-28 18:10:43 -0700736 if (!disableNetwork) {
737 try {
738 Slog.i(TAG, "NetworkTimeUpdateService");
739 networkTimeUpdater = new NetworkTimeUpdateService(context);
740 } catch (Throwable e) {
741 reportWtf("starting NetworkTimeUpdate service", e);
742 }
Amith Yamasani6734b9f2010-09-13 16:24:08 -0700743 }
John Grossmanc1576732012-02-01 15:23:33 -0800744
Dan Morrille4d9a012013-03-28 18:10:43 -0700745 if (!disableMedia) {
746 try {
747 Slog.i(TAG, "CommonTimeManagementService");
748 commonTimeMgmtService = new CommonTimeManagementService(context);
749 ServiceManager.addService("commontime_management", commonTimeMgmtService);
750 } catch (Throwable e) {
751 reportWtf("starting CommonTimeManagementService service", e);
752 }
John Grossmanc1576732012-02-01 15:23:33 -0800753 }
Geremy Condra3d33c262012-05-06 18:32:19 -0700754
Dan Morrille4d9a012013-03-28 18:10:43 -0700755 if (!disableNetwork) {
756 try {
757 Slog.i(TAG, "CertBlacklister");
758 CertBlacklister blacklister = new CertBlacklister(context);
759 } catch (Throwable e) {
760 reportWtf("starting CertBlacklister", e);
761 }
Geremy Condra3d33c262012-05-06 18:32:19 -0700762 }
Jim Miller5ecd8112013-01-09 18:50:26 -0800763
Dan Morrille4d9a012013-03-28 18:10:43 -0700764 if (!disableNonCoreServices &&
765 context.getResources().getBoolean(R.bool.config_dreamsSupported)) {
Daniel Sandler7d276c32012-01-30 14:33:52 -0500766 try {
767 Slog.i(TAG, "Dreams Service");
768 // Dreams (interactive idle-time views, a/k/a screen savers)
Jeff Brown62c82e42012-09-26 01:30:41 -0700769 dreamy = new DreamManagerService(context, wmHandler);
Dianne Hackbornbe87e2f2012-09-28 16:31:34 -0700770 ServiceManager.addService(DreamService.DREAM_SERVICE, dreamy);
Daniel Sandler7d276c32012-01-30 14:33:52 -0500771 } catch (Throwable e) {
772 reportWtf("starting DreamManagerService", e);
773 }
774 }
Svetoslavb3038ec2013-02-13 14:39:30 -0800775
Romain Guy3b748a42013-04-17 18:54:38 -0700776 if (!disableNonCoreServices) {
777 try {
778 Slog.i(TAG, "Assets Atlas Service");
779 atlas = new AssetAtlasService(context);
780 ServiceManager.addService(AssetAtlasService.ASSET_ATLAS_SERVICE, atlas);
781 } catch (Throwable e) {
782 reportWtf("starting AssetAtlasService", e);
783 }
784 }
785
Svetoslavb3038ec2013-02-13 14:39:30 -0800786 try {
787 Slog.i(TAG, "IdleMaintenanceService");
Svetoslav6a08a122013-05-03 11:24:26 -0700788 new IdleMaintenanceService(context, battery);
Svetoslavb3038ec2013-02-13 14:39:30 -0800789 } catch (Throwable e) {
790 reportWtf("starting IdleMaintenanceService", e);
791 }
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -0700792
793 try {
794 Slog.i(TAG, "Print Service");
Svetoslav Ganova0027152013-06-25 14:59:53 -0700795 printManager = new PrintManagerService(context);
796 ServiceManager.addService(Context.PRINT_SERVICE, printManager);
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -0700797 } catch (Throwable e) {
798 reportWtf("starting Print Service", e);
799 }
Jeff Brown69b07162013-11-07 00:30:16 -0800800
801 if (!disableNonCoreServices) {
802 try {
803 Slog.i(TAG, "Media Router Service");
804 mediaRouter = new MediaRouterService(context);
805 ServiceManager.addService(Context.MEDIA_ROUTER_SERVICE, mediaRouter);
806 } catch (Throwable e) {
807 reportWtf("starting MediaRouterService", e);
808 }
809 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800810 }
811
Dianne Hackborn6af0d502009-09-28 13:25:46 -0700812 // Before things start rolling, be sure we have decided whether
813 // we are in safe mode.
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700814 final boolean safeMode = wm.detectSafeMode();
Dianne Hackborn6af0d502009-09-28 13:25:46 -0700815 if (safeMode) {
Jeff Brownb09abc12011-01-13 21:08:27 -0800816 ActivityManagerService.self().enterSafeMode();
817 // Post the safe mode state in the Zygote class
818 Zygote.systemInSafeMode = true;
819 // Disable the JIT for the system_server process
820 VMRuntime.getRuntime().disableJitCompilation();
Ben Cheng6c0afff2010-02-14 16:18:56 -0800821 } else {
822 // Enable the JIT for the system_server process
823 VMRuntime.getRuntime().startJitCompilation();
Dianne Hackborn6af0d502009-09-28 13:25:46 -0700824 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800825
Dianne Hackborn6af0d502009-09-28 13:25:46 -0700826 // It is now time to start up the app processes...
Joe Onorato30275482009-07-08 17:09:14 -0700827
Jeff Brown7f6c2312012-04-13 20:38:38 -0700828 try {
829 vibrator.systemReady();
830 } catch (Throwable e) {
831 reportWtf("making Vibrator Service ready", e);
832 }
833
Dan Morrille4d9a012013-03-28 18:10:43 -0700834 if (lockSettings != null) {
835 try {
836 lockSettings.systemReady();
837 } catch (Throwable e) {
838 reportWtf("making Lock Settings Service ready", e);
839 }
Felipe Ramosf35df5b2012-09-18 18:26:27 -0300840 }
841
Dianne Hackbornd6847842010-01-12 18:14:19 -0800842 if (devicePolicy != null) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700843 try {
844 devicePolicy.systemReady();
845 } catch (Throwable e) {
846 reportWtf("making Device Policy Service ready", e);
847 }
Dianne Hackbornd6847842010-01-12 18:14:19 -0800848 }
849
Adam Lesinskief2ea1f2013-12-05 16:48:06 -0800850 systemServiceManager.startBootPhase(SystemService.PHASE_SYSTEM_SERVICES_READY);
Joe Onorato30275482009-07-08 17:09:14 -0700851
Dianne Hackborn661cd522011-08-22 00:26:20 -0700852 try {
853 wm.systemReady();
854 } catch (Throwable e) {
855 reportWtf("making Window Manager Service ready", e);
856 }
Joe Onoratodc565f42010-10-04 15:27:22 -0400857
Jeff Brownb09abc12011-01-13 21:08:27 -0800858 if (safeMode) {
859 ActivityManagerService.self().showSafeModeOverlay();
860 }
861
Joe Onoratodc565f42010-10-04 15:27:22 -0400862 // Update the configuration for this context by hand, because we're going
863 // to start using it before the config change done in wm.systemReady() will
864 // propagate to it.
865 Configuration config = wm.computeNewConfiguration();
866 DisplayMetrics metrics = new DisplayMetrics();
867 WindowManager w = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
868 w.getDefaultDisplay().getMetrics(metrics);
869 context.getResources().updateConfiguration(config, metrics);
870
Jeff Brownaa202a62012-08-21 22:14:26 -0700871 try {
Jeff Brown62c82e42012-09-26 01:30:41 -0700872 power.systemReady(twilight, dreamy);
Jeff Brownaa202a62012-08-21 22:14:26 -0700873 } catch (Throwable e) {
874 reportWtf("making Power Manager Service ready", e);
875 }
876
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800877 try {
878 pm.systemReady();
Dianne Hackborn661cd522011-08-22 00:26:20 -0700879 } catch (Throwable e) {
880 reportWtf("making Package Manager Service ready", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800881 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800882
Jeff Brownbd6e1502012-08-28 03:27:37 -0700883 try {
884 display.systemReady(safeMode, onlyCore);
885 } catch (Throwable e) {
886 reportWtf("making Display Manager Service ready", e);
887 }
888
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700889 // These are needed to propagate to the runnable below.
Joe Onoratof3c3c4f2010-10-21 11:09:02 -0400890 final Context contextF = context;
Jeff Sharkeyb049e212012-09-07 23:16:01 -0700891 final MountService mountServiceF = mountService;
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700892 final BatteryService batteryF = battery;
Jeff Sharkey350083e2011-06-29 10:45:16 -0700893 final NetworkManagementService networkManagementF = networkManagement;
Jeff Sharkey75279902011-05-24 18:39:45 -0700894 final NetworkStatsService networkStatsF = networkStats;
Jeff Sharkeya4620792011-05-20 15:29:23 -0700895 final NetworkPolicyManagerService networkPolicyF = networkPolicy;
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700896 final ConnectivityService connectivityF = connectivity;
897 final DockObserver dockF = dock;
Mike Lockwood770126a2010-12-09 22:30:37 -0800898 final UsbService usbF = usb;
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700899 final AppWidgetService appWidgetF = appWidget;
900 final WallpaperManagerService wallpaperF = wallpaper;
901 final InputMethodManagerService immF = imm;
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800902 final RecognitionManagerService recognitionF = recognition;
Mike Lockwood46db5042010-02-22 16:36:44 -0500903 final LocationManagerService locationF = location;
Bai Taoa58a8752010-07-13 15:32:16 +0800904 final CountryDetectorService countryDetectorF = countryDetector;
Amith Yamasani6734b9f2010-09-13 16:24:08 -0700905 final NetworkTimeUpdateService networkTimeUpdaterF = networkTimeUpdater;
John Grossmanc1576732012-02-01 15:23:33 -0800906 final CommonTimeManagementService commonTimeMgmtServiceF = commonTimeMgmtService;
satok988323c2011-06-22 16:38:13 +0900907 final TextServicesManagerService textServiceManagerServiceF = tsms;
Dianne Hackborn661cd522011-08-22 00:26:20 -0700908 final StatusBarManagerService statusBarF = statusBar;
Daniel Sandler7d276c32012-01-30 14:33:52 -0500909 final DreamManagerService dreamyF = dreamy;
Romain Guy3b748a42013-04-17 18:54:38 -0700910 final AssetAtlasService atlasF = atlas;
Jeff Brown6ec6f792012-04-17 16:52:41 -0700911 final InputManagerService inputManagerF = inputManager;
Wink Savillea12a7b32012-09-20 10:09:45 -0700912 final TelephonyRegistry telephonyRegistryF = telephonyRegistry;
Svetoslav Ganova0027152013-06-25 14:59:53 -0700913 final PrintManagerService printManagerF = printManager;
Jeff Brown69b07162013-11-07 00:30:16 -0800914 final MediaRouterService mediaRouterF = mediaRouter;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800915
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700916 // We now tell the activity manager it is okay to run third party
917 // code. It will call back into us once it has gotten to the state
918 // where third party code can really run (but before it has actually
919 // started launching the initial applications), for us to complete our
920 // initialization.
Dianne Hackborn295e3c22011-08-25 13:19:08 -0700921 ActivityManagerService.self().systemReady(new Runnable() {
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700922 public void run() {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800923 Slog.i(TAG, "Making services ready");
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800924
Christopher Tate58d380d2013-03-19 13:10:03 -0700925 try {
926 ActivityManagerService.self().startObservingNativeCrashes();
927 } catch (Throwable e) {
928 reportWtf("observing native crashes", e);
929 }
Amith Yamasanib6fda092013-11-14 19:24:44 -0800930 try {
931 startSystemUi(contextF);
932 } catch (Throwable e) {
933 reportWtf("starting System UI", e);
934 }
Dianne Hackborn661cd522011-08-22 00:26:20 -0700935 try {
Jeff Sharkeyb049e212012-09-07 23:16:01 -0700936 if (mountServiceF != null) mountServiceF.systemReady();
937 } catch (Throwable e) {
938 reportWtf("making Mount Service ready", e);
939 }
940 try {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700941 if (batteryF != null) batteryF.systemReady();
942 } catch (Throwable e) {
943 reportWtf("making Battery Service ready", e);
944 }
945 try {
946 if (networkManagementF != null) networkManagementF.systemReady();
947 } catch (Throwable e) {
948 reportWtf("making Network Managment Service ready", e);
949 }
950 try {
951 if (networkStatsF != null) networkStatsF.systemReady();
952 } catch (Throwable e) {
953 reportWtf("making Network Stats Service ready", e);
954 }
955 try {
956 if (networkPolicyF != null) networkPolicyF.systemReady();
957 } catch (Throwable e) {
958 reportWtf("making Network Policy Service ready", e);
959 }
960 try {
961 if (connectivityF != null) connectivityF.systemReady();
962 } catch (Throwable e) {
963 reportWtf("making Connectivity Service ready", e);
964 }
965 try {
966 if (dockF != null) dockF.systemReady();
967 } catch (Throwable e) {
968 reportWtf("making Dock Service ready", e);
969 }
970 try {
971 if (usbF != null) usbF.systemReady();
972 } catch (Throwable e) {
973 reportWtf("making USB Service ready", e);
974 }
975 try {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700976 if (recognitionF != null) recognitionF.systemReady();
977 } catch (Throwable e) {
978 reportWtf("making Recognition Service ready", e);
979 }
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700980 Watchdog.getInstance().start();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800981
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700982 // It is now okay to let the various system services start their
983 // third party code...
Adam Lesinskief2ea1f2013-12-05 16:48:06 -0800984 systemServiceManager.startBootPhase(SystemService.PHASE_THIRD_PARTY_APPS_CAN_START);
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800985
Dianne Hackborn661cd522011-08-22 00:26:20 -0700986 try {
Svetoslav Ganova0027152013-06-25 14:59:53 -0700987 if (appWidgetF != null) appWidgetF.systemRunning(safeMode);
Dianne Hackborn661cd522011-08-22 00:26:20 -0700988 } catch (Throwable e) {
Svetoslav Ganova0027152013-06-25 14:59:53 -0700989 reportWtf("Notifying AppWidgetService running", e);
Dianne Hackborn661cd522011-08-22 00:26:20 -0700990 }
991 try {
Svetoslav Ganova0027152013-06-25 14:59:53 -0700992 if (wallpaperF != null) wallpaperF.systemRunning();
Dianne Hackborn661cd522011-08-22 00:26:20 -0700993 } catch (Throwable e) {
Svetoslav Ganova0027152013-06-25 14:59:53 -0700994 reportWtf("Notifying WallpaperService running", e);
Dianne Hackborn661cd522011-08-22 00:26:20 -0700995 }
996 try {
Svetoslav Ganova0027152013-06-25 14:59:53 -0700997 if (immF != null) immF.systemRunning(statusBarF);
Dianne Hackborn661cd522011-08-22 00:26:20 -0700998 } catch (Throwable e) {
Svetoslav Ganova0027152013-06-25 14:59:53 -0700999 reportWtf("Notifying InputMethodService running", e);
Dianne Hackborn661cd522011-08-22 00:26:20 -07001000 }
1001 try {
Svetoslav Ganova0027152013-06-25 14:59:53 -07001002 if (locationF != null) locationF.systemRunning();
Dianne Hackborn661cd522011-08-22 00:26:20 -07001003 } catch (Throwable e) {
Svetoslav Ganova0027152013-06-25 14:59:53 -07001004 reportWtf("Notifying Location Service running", e);
Dianne Hackborn661cd522011-08-22 00:26:20 -07001005 }
1006 try {
Svetoslav Ganova0027152013-06-25 14:59:53 -07001007 if (countryDetectorF != null) countryDetectorF.systemRunning();
Dianne Hackborn661cd522011-08-22 00:26:20 -07001008 } catch (Throwable e) {
Svetoslav Ganova0027152013-06-25 14:59:53 -07001009 reportWtf("Notifying CountryDetectorService running", e);
Dianne Hackborn661cd522011-08-22 00:26:20 -07001010 }
1011 try {
Svetoslav Ganova0027152013-06-25 14:59:53 -07001012 if (networkTimeUpdaterF != null) networkTimeUpdaterF.systemRunning();
Dianne Hackborn661cd522011-08-22 00:26:20 -07001013 } catch (Throwable e) {
Svetoslav Ganova0027152013-06-25 14:59:53 -07001014 reportWtf("Notifying NetworkTimeService running", e);
Dianne Hackborn661cd522011-08-22 00:26:20 -07001015 }
1016 try {
Svetoslav Ganova0027152013-06-25 14:59:53 -07001017 if (commonTimeMgmtServiceF != null) commonTimeMgmtServiceF.systemRunning();
John Grossmanc1576732012-02-01 15:23:33 -08001018 } catch (Throwable e) {
Svetoslav Ganova0027152013-06-25 14:59:53 -07001019 reportWtf("Notifying CommonTimeManagementService running", e);
John Grossmanc1576732012-02-01 15:23:33 -08001020 }
1021 try {
Svetoslav Ganova0027152013-06-25 14:59:53 -07001022 if (textServiceManagerServiceF != null)
1023 textServiceManagerServiceF.systemRunning();
Dianne Hackborn661cd522011-08-22 00:26:20 -07001024 } catch (Throwable e) {
Svetoslav Ganova0027152013-06-25 14:59:53 -07001025 reportWtf("Notifying TextServicesManagerService running", e);
Dianne Hackborn661cd522011-08-22 00:26:20 -07001026 }
Daniel Sandler7d276c32012-01-30 14:33:52 -05001027 try {
Svetoslav Ganova0027152013-06-25 14:59:53 -07001028 if (dreamyF != null) dreamyF.systemRunning();
Daniel Sandler7d276c32012-01-30 14:33:52 -05001029 } catch (Throwable e) {
Svetoslav Ganova0027152013-06-25 14:59:53 -07001030 reportWtf("Notifying DreamManagerService running", e);
Daniel Sandler7d276c32012-01-30 14:33:52 -05001031 }
Jeff Brown6ec6f792012-04-17 16:52:41 -07001032 try {
Svetoslav Ganova0027152013-06-25 14:59:53 -07001033 if (atlasF != null) atlasF.systemRunning();
Romain Guy3b748a42013-04-17 18:54:38 -07001034 } catch (Throwable e) {
Svetoslav Ganova0027152013-06-25 14:59:53 -07001035 reportWtf("Notifying AssetAtlasService running", e);
Romain Guy3b748a42013-04-17 18:54:38 -07001036 }
1037 try {
Matthew Xie96313142012-06-29 16:57:31 -07001038 // TODO(BT) Pass parameter to input manager
Svetoslav Ganova0027152013-06-25 14:59:53 -07001039 if (inputManagerF != null) inputManagerF.systemRunning();
Jeff Brown6ec6f792012-04-17 16:52:41 -07001040 } catch (Throwable e) {
Svetoslav Ganova0027152013-06-25 14:59:53 -07001041 reportWtf("Notifying InputManagerService running", e);
Jeff Brown6ec6f792012-04-17 16:52:41 -07001042 }
Dan Morrille4d9a012013-03-28 18:10:43 -07001043
Wink Savillea12a7b32012-09-20 10:09:45 -07001044 try {
Svetoslav Ganova0027152013-06-25 14:59:53 -07001045 if (telephonyRegistryF != null) telephonyRegistryF.systemRunning();
Wink Savillea12a7b32012-09-20 10:09:45 -07001046 } catch (Throwable e) {
Svetoslav Ganova0027152013-06-25 14:59:53 -07001047 reportWtf("Notifying TelephonyRegistry running", e);
1048 }
1049
1050 try {
1051 if (printManagerF != null) printManagerF.systemRuning();
1052 } catch (Throwable e) {
1053 reportWtf("Notifying PrintManagerService running", e);
Wink Savillea12a7b32012-09-20 10:09:45 -07001054 }
Jeff Brown69b07162013-11-07 00:30:16 -08001055
1056 try {
1057 if (mediaRouterF != null) mediaRouterF.systemRunning();
1058 } catch (Throwable e) {
1059 reportWtf("Notifying MediaRouterService running", e);
1060 }
Adam Lesinskief2ea1f2013-12-05 16:48:06 -08001061
1062 systemServiceManager.startBootPhase(SystemService.PHASE_BOOT_COMPLETE);
Dianne Hackborna34f1ad2009-09-02 13:26:28 -07001063 }
1064 });
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001065
Brad Fitzpatrick1e02d362010-09-10 09:19:50 -07001066 // For debug builds, log event loop stalls to dropbox for analysis.
Brad Fitzpatrick50d66f92010-09-13 21:29:05 -07001067 if (StrictMode.conditionallyEnableDebugLogging()) {
1068 Slog.i(TAG, "Enabled StrictMode for system server main thread.");
Brad Fitzpatrick1e02d362010-09-10 09:19:50 -07001069 }
1070
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001071 Looper.loop();
Joe Onorato8a9b2202010-02-26 18:56:32 -08001072 Slog.d(TAG, "System ServerThread is exiting!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001073 }
Joe Onoratof3c3c4f2010-10-21 11:09:02 -04001074
1075 static final void startSystemUi(Context context) {
1076 Intent intent = new Intent();
1077 intent.setComponent(new ComponentName("com.android.systemui",
1078 "com.android.systemui.SystemUIService"));
Dianne Hackborn40e9f292012-11-27 19:12:23 -08001079 //Slog.d(TAG, "Starting service: " + intent);
Amith Yamasanicd757062012-10-19 18:23:52 -07001080 context.startServiceAsUser(intent, UserHandle.OWNER);
Joe Onoratof3c3c4f2010-10-21 11:09:02 -04001081 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001082}
1083
Jeff Hamilton35eef702010-06-09 15:45:18 -05001084public class SystemServer {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001085 private static final String TAG = "SystemServer";
1086
1087 public static final int FACTORY_TEST_OFF = 0;
1088 public static final int FACTORY_TEST_LOW_LEVEL = 1;
1089 public static final int FACTORY_TEST_HIGH_LEVEL = 2;
Jaikumar Ganeshd5ac1ae2009-05-05 22:26:12 -07001090
Bob Leee5408332009-09-04 18:31:17 -07001091 static Timer timer;
1092 static final long SNAPSHOT_INTERVAL = 60 * 60 * 1000; // 1hr
1093
Brad Fitzpatrick6bb7a4a2010-10-11 13:41:10 -07001094 // The earliest supported time. We pick one day into 1970, to
1095 // give any timezone code room without going into negative time.
1096 private static final long EARLIEST_SUPPORTED_TIME = 86400 * 1000;
1097
Jaikumar Ganeshd5ac1ae2009-05-05 22:26:12 -07001098 /**
Jeff Brownef691172013-07-15 13:22:04 -07001099 * Called to initialize native system services.
Jaikumar Ganeshd5ac1ae2009-05-05 22:26:12 -07001100 */
Jeff Brownef691172013-07-15 13:22:04 -07001101 private static native void nativeInit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001102
1103 public static void main(String[] args) {
Brian Carlstrom5637ffc2013-11-01 14:51:58 -07001104
1105 /*
1106 * In case the runtime switched since last boot (such as when
1107 * the old runtime was removed in an OTA), set the system
1108 * property so that it is in sync. We can't do this in
1109 * libnativehelper's JniInvocation::Init code where we already
1110 * had to fallback to a different runtime because it is
1111 * running as root and we need to be the system user to set
1112 * the property. http://b/11463182
1113 */
1114 SystemProperties.set("persist.sys.dalvik.vm.lib",
1115 VMRuntime.getRuntime().vmLibrary());
1116
Brad Fitzpatrick6bb7a4a2010-10-11 13:41:10 -07001117 if (System.currentTimeMillis() < EARLIEST_SUPPORTED_TIME) {
Brad Fitzpatrick35ca9d82010-10-11 11:52:49 -07001118 // If a device's clock is before 1970 (before 0), a lot of
1119 // APIs crash dealing with negative numbers, notably
1120 // java.io.File#setLastModified, so instead we fake it and
1121 // hope that time from cell towers or NTP fixes it
1122 // shortly.
1123 Slog.w(TAG, "System clock is before 1970; setting to 1970.");
Brad Fitzpatrick6bb7a4a2010-10-11 13:41:10 -07001124 SystemClock.setCurrentTimeMillis(EARLIEST_SUPPORTED_TIME);
Brad Fitzpatrick35ca9d82010-10-11 11:52:49 -07001125 }
1126
Bob Leee5408332009-09-04 18:31:17 -07001127 if (SamplingProfilerIntegration.isEnabled()) {
1128 SamplingProfilerIntegration.start();
1129 timer = new Timer();
1130 timer.schedule(new TimerTask() {
1131 @Override
1132 public void run() {
Sen Hubde75702010-05-28 01:54:03 -07001133 SamplingProfilerIntegration.writeSnapshot("system_server", null);
Bob Leee5408332009-09-04 18:31:17 -07001134 }
1135 }, SNAPSHOT_INTERVAL, SNAPSHOT_INTERVAL);
1136 }
1137
Dianne Hackbornac1471a2011-02-03 13:46:06 -08001138 // Mmmmmm... more memory!
1139 dalvik.system.VMRuntime.getRuntime().clearGrowthLimit();
1140
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001141 // The system server has to run all of the time, so it needs to be
1142 // as efficient as possible with its memory usage.
1143 VMRuntime.getRuntime().setTargetHeapUtilization(0.8f);
Sen Hubde75702010-05-28 01:54:03 -07001144
Jeff Sharkey48749fc2013-04-19 13:25:04 -07001145 Environment.setUserRequired(true);
1146
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001147 System.loadLibrary("android_servers");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001148
Joe Onorato8a9b2202010-02-26 18:56:32 -08001149 Slog.i(TAG, "Entered the Android system server!");
Dianne Hackbornefa92b22013-05-03 14:11:43 -07001150
Jeff Brownef691172013-07-15 13:22:04 -07001151 // Initialize native services.
1152 nativeInit();
1153
Dianne Hackbornefa92b22013-05-03 14:11:43 -07001154 // This used to be its own separate thread, but now it is
1155 // just the loop we run on the main thread.
1156 ServerThread thr = new ServerThread();
1157 thr.initAndLoop();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001158 }
1159}