blob: 23c7e421516794e2629168e83ceab957a8adb4e2 [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;
Amith Yamasani817ec492013-12-20 13:27:30 -080034import android.os.IBinder;
Jeff Hamilton35eef702010-06-09 15:45:18 -050035import android.os.Looper;
36import android.os.RemoteException;
37import android.os.ServiceManager;
Brad Fitzpatrickc74a1b442010-09-10 16:03:29 -070038import android.os.StrictMode;
Jeff Hamilton35eef702010-06-09 15:45:18 -050039import android.os.SystemClock;
40import android.os.SystemProperties;
Amith Yamasanicd757062012-10-19 18:23:52 -070041import android.os.UserHandle;
Dianne Hackbornbe87e2f2012-09-28 16:31:34 -070042import android.service.dreams.DreamService;
Joe Onoratodc565f42010-10-04 15:27:22 -040043import android.util.DisplayMetrics;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080044import android.util.EventLog;
Dianne Hackborn661cd522011-08-22 00:26:20 -070045import android.util.Log;
Joe Onorato8a9b2202010-02-26 18:56:32 -080046import android.util.Slog;
Brad Fitzpatrick5fdc0c72010-10-12 13:12:18 -070047import android.view.WindowManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080048
Dan Morrille4d9a012013-03-28 18:10:43 -070049import com.android.internal.R;
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -070050import com.android.internal.os.BinderInternal;
51import com.android.internal.os.SamplingProfilerIntegration;
52import com.android.server.accessibility.AccessibilityManagerService;
Jeff Sharkey7a96c392012-11-15 14:01:46 -080053import com.android.server.accounts.AccountManagerService;
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -070054import com.android.server.am.ActivityManagerService;
Jeff Brown96307042012-07-27 15:51:34 -070055import com.android.server.am.BatteryStatsService;
Amith Yamasani30f8eb42013-11-06 14:54:50 -080056import com.android.server.clipboard.ClipboardService;
Jeff Sharkey7a96c392012-11-15 14:01:46 -080057import com.android.server.content.ContentService;
Jeff Brownfa25bf52012-07-23 19:26:30 -070058import com.android.server.display.DisplayManagerService;
Jeff Browncef440f2012-09-25 18:58:48 -070059import com.android.server.dreams.DreamManagerService;
Jeff Brown6ec6f792012-04-17 16:52:41 -070060import com.android.server.input.InputManagerService;
Adam Lesinskief2ea1f2013-12-05 16:48:06 -080061import com.android.server.lights.LightsManager;
62import com.android.server.lights.LightsService;
Jeff Brown69b07162013-11-07 00:30:16 -080063import com.android.server.media.MediaRouterService;
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -070064import com.android.server.net.NetworkPolicyManagerService;
Jeff Sharkey75279902011-05-24 18:39:45 -070065import com.android.server.net.NetworkStatsService;
Adam Lesinskief2ea1f2013-12-05 16:48:06 -080066import com.android.server.notification.NotificationManagerService;
Jeff Sharkey7a96c392012-11-15 14:01:46 -080067import com.android.server.os.SchedulingPolicyService;
Jeff Brownf69c8122012-09-12 17:00:34 -070068import com.android.server.pm.Installer;
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -070069import com.android.server.pm.PackageManagerService;
Amith Yamasani258848d2012-08-10 17:06:33 -070070import com.android.server.pm.UserManagerService;
Jeff Brown4f8ecd82012-06-18 18:29:13 -070071import com.android.server.power.PowerManagerService;
72import com.android.server.power.ShutdownThread;
Jeff Sharkey7a96c392012-11-15 14:01:46 -080073import com.android.server.search.SearchManagerService;
Adam Lesinskief2ea1f2013-12-05 16:48:06 -080074import com.android.server.statusbar.StatusBarManagerService;
75import com.android.server.storage.DeviceStorageMonitorService;
76import com.android.server.twilight.TwilightManager;
77import com.android.server.twilight.TwilightService;
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -070078import com.android.server.usb.UsbService;
Amith Yamasani30f8eb42013-11-06 14:54:50 -080079import com.android.server.wallpaper.WallpaperManagerService;
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -070080import com.android.server.wm.WindowManagerService;
81
82import dalvik.system.VMRuntime;
83import dalvik.system.Zygote;
84
Dan Egnor4410ec82009-09-11 16:40:01 -070085import java.io.File;
Bob Leee5408332009-09-04 18:31:17 -070086import java.util.Timer;
87import java.util.TimerTask;
88
Dianne Hackbornefa92b22013-05-03 14:11:43 -070089class ServerThread {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080090 private static final String TAG = "SystemServer";
Ben Komalo553acf02011-09-19 14:25:28 -070091 private static final String ENCRYPTING_STATE = "trigger_restart_min_framework";
Ben Komalo3573d402011-09-23 15:08:24 -070092 private static final String ENCRYPTED_STATE = "1";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080093
Jeff Hamilton35eef702010-06-09 15:45:18 -050094 ContentResolver mContentResolver;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080095
Amith Yamasani817ec492013-12-20 13:27:30 -080096 /*
97 * Implementation class names. TODO: Move them to a codegen class or load
98 * them from the build system somehow.
99 */
100 private static final String BACKUP_MANAGER_SERVICE_CLASS =
101 "com.android.server.backup.BackupManagerSystemService";
102 private static final String DEVICE_POLICY_MANAGER_SERVICE_CLASS =
103 "com.android.server.devicepolicy.DevicePolicyManagerSystemService";
104 private static final String APPWIDGET_SERVICE_CLASS =
105 "com.android.server.appwidget.AppWidgetService";
106 private static final String PRINT_MANAGER_SERVICE_CLASS =
107 "com.android.server.print.PrintManagerService";
108
Dianne Hackborn661cd522011-08-22 00:26:20 -0700109 void reportWtf(String msg, Throwable e) {
110 Slog.w(TAG, "***********************************************");
111 Log.wtf(TAG, "BOOT FAILURE " + msg, e);
112 }
113
Dianne Hackbornefa92b22013-05-03 14:11:43 -0700114 public void initAndLoop() {
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800115 EventLog.writeEvent(EventLogTags.BOOT_PROGRESS_SYSTEM_RUN,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800116 SystemClock.uptimeMillis());
117
Vairavan Srinivasan04b74ec2012-02-02 22:12:19 -0800118 Looper.prepareMainLooper();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800119
120 android.os.Process.setThreadPriority(
121 android.os.Process.THREAD_PRIORITY_FOREGROUND);
122
Dianne Hackborn887f3552009-12-07 17:59:37 -0800123 BinderInternal.disableBackgroundScheduling(true);
Christopher Tate160edb32010-06-30 17:46:30 -0700124 android.os.Process.setCanSelfBackground(false);
Sen Hubde75702010-05-28 01:54:03 -0700125
Kenny Rootf547d672010-09-22 10:36:48 -0700126 // Check whether we failed to shut down last time we tried.
127 {
128 final String shutdownAction = SystemProperties.get(
129 ShutdownThread.SHUTDOWN_ACTION_PROPERTY, "");
130 if (shutdownAction != null && shutdownAction.length() > 0) {
131 boolean reboot = (shutdownAction.charAt(0) == '1');
132
133 final String reason;
134 if (shutdownAction.length() > 1) {
135 reason = shutdownAction.substring(1, shutdownAction.length());
136 } else {
137 reason = null;
138 }
139
140 ShutdownThread.rebootOrShutdown(reboot, reason);
141 }
142 }
143
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800144 String factoryTestStr = SystemProperties.get("ro.factorytest");
145 int factoryTest = "".equals(factoryTestStr) ? SystemServer.FACTORY_TEST_OFF
146 : Integer.parseInt(factoryTestStr);
147
Jeff Brownf69c8122012-09-12 17:00:34 -0700148 Installer installer = null;
Kenny Root26ff6622012-07-30 12:58:03 -0700149 AccountManagerService accountManager = null;
150 ContentService contentService = null;
Adam Lesinskief2ea1f2013-12-05 16:48:06 -0800151 LightsManager lights = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800152 PowerManagerService power = null;
Jeff Brownfa25bf52012-07-23 19:26:30 -0700153 DisplayManagerService display = null;
Mike Lockwood07a500f2009-08-12 09:56:44 -0400154 BatteryService battery = null;
Jeff Brown7f6c2312012-04-13 20:38:38 -0700155 VibratorService vibrator = null;
Adam Lesinskief2ea1f2013-12-05 16:48:06 -0800156 IAlarmManager alarm = null;
Jeff Sharkeyb049e212012-09-07 23:16:01 -0700157 MountService mountService = null;
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -0700158 NetworkManagementService networkManagement = null;
Jeff Sharkey75279902011-05-24 18:39:45 -0700159 NetworkStatsService networkStats = null;
Jeff Sharkeya4620792011-05-20 15:29:23 -0700160 NetworkPolicyManagerService networkPolicy = null;
Mike Lockwood0f79b542009-08-14 14:18:49 -0400161 ConnectivityService connectivity = null;
Irfan Sheriff7d024d32012-03-22 17:01:39 -0700162 NsdService serviceDiscovery= null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800163 IPackageManager pm = null;
164 Context context = null;
165 WindowManagerService wm = null;
fredc0f420372012-04-12 00:02:00 -0700166 BluetoothManagerService bluetooth = null;
Dan Murphyc9f4eaf2009-08-12 15:15:43 -0500167 DockObserver dock = null;
Mike Lockwood770126a2010-12-09 22:30:37 -0800168 UsbService usb = null;
Mike Lockwoodb01e8bf2011-08-29 20:11:07 -0400169 SerialService serial = null;
Adam Lesinskief2ea1f2013-12-05 16:48:06 -0800170 TwilightManager twilight = null;
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800171 RecognitionManagerService recognition = null;
Amith Yamasani6734b9f2010-09-13 16:24:08 -0700172 NetworkTimeUpdateService networkTimeUpdater = null;
John Grossmanc1576732012-02-01 15:23:33 -0800173 CommonTimeManagementService commonTimeMgmtService = null;
Jeff Brown6ec6f792012-04-17 16:52:41 -0700174 InputManagerService inputManager = null;
Wink Savillea12a7b32012-09-20 10:09:45 -0700175 TelephonyRegistry telephonyRegistry = null;
Erik Gilling51e95df2013-06-26 11:06:51 -0700176 ConsumerIrService consumerIr = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800177
Jeff Brownbd6e1502012-08-28 03:27:37 -0700178 // Create a handler thread just for the window manager to enjoy.
179 HandlerThread wmHandlerThread = new HandlerThread("WindowManager");
180 wmHandlerThread.start();
181 Handler wmHandler = new Handler(wmHandlerThread.getLooper());
182 wmHandler.post(new Runnable() {
183 @Override
184 public void run() {
185 //Looper.myLooper().setMessageLogging(new LogPrinter(
186 // android.util.Log.DEBUG, TAG, android.util.Log.LOG_ID_SYSTEM));
187 android.os.Process.setThreadPriority(
188 android.os.Process.THREAD_PRIORITY_DISPLAY);
189 android.os.Process.setCanSelfBackground(false);
190
191 // For debug builds, log event loop stalls to dropbox for analysis.
192 if (StrictMode.conditionallyEnableDebugLogging()) {
Jeff Brown89d55462012-09-19 11:33:42 -0700193 Slog.i(TAG, "Enabled StrictMode logging for WM Looper");
Jeff Brownbd6e1502012-08-28 03:27:37 -0700194 }
195 }
196 });
197
Dan Morrille4d9a012013-03-28 18:10:43 -0700198 // bootstrap services
Jeff Brownbd6e1502012-08-28 03:27:37 -0700199 boolean onlyCore = false;
Dan Morrille4d9a012013-03-28 18:10:43 -0700200 boolean firstBoot = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800201 try {
Jeff Brownf69c8122012-09-12 17:00:34 -0700202 // Wait for installd to finished starting up so that it has a chance to
203 // create critical directories such as /data/user with the appropriate
204 // permissions. We need this to complete before we initialize other services.
205 Slog.i(TAG, "Waiting for installd to be ready.");
206 installer = new Installer();
207 installer.ping();
208
Joe Onorato8a9b2202010-02-26 18:56:32 -0800209 Slog.i(TAG, "Power Manager");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800210 power = new PowerManagerService();
211 ServiceManager.addService(Context.POWER_SERVICE, power);
212
Joe Onorato8a9b2202010-02-26 18:56:32 -0800213 Slog.i(TAG, "Activity Manager");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800214 context = ActivityManagerService.main(factoryTest);
Dan Morrille4d9a012013-03-28 18:10:43 -0700215 } catch (RuntimeException e) {
216 Slog.e("System", "******************************************");
217 Slog.e("System", "************ Failure starting bootstrap service", e);
218 }
Jeff Brown848c2dc2012-08-19 20:18:08 -0700219
Adam Lesinskief2ea1f2013-12-05 16:48:06 -0800220 final SystemServiceManager systemServiceManager = new SystemServiceManager(context);
221
Dan Morrille4d9a012013-03-28 18:10:43 -0700222 boolean disableStorage = SystemProperties.getBoolean("config.disable_storage", false);
223 boolean disableMedia = SystemProperties.getBoolean("config.disable_media", false);
224 boolean disableBluetooth = SystemProperties.getBoolean("config.disable_bluetooth", false);
225 boolean disableTelephony = SystemProperties.getBoolean("config.disable_telephony", false);
226 boolean disableLocation = SystemProperties.getBoolean("config.disable_location", false);
227 boolean disableSystemUI = SystemProperties.getBoolean("config.disable_systemui", false);
228 boolean disableNonCoreServices = SystemProperties.getBoolean("config.disable_noncore", false);
229 boolean disableNetwork = SystemProperties.getBoolean("config.disable_network", false);
230
231 try {
Jeff Brown848c2dc2012-08-19 20:18:08 -0700232 Slog.i(TAG, "Display Manager");
Dianne Hackborn8d044e82013-04-30 17:24:15 -0700233 display = new DisplayManagerService(context, wmHandler);
Jeff Brown848c2dc2012-08-19 20:18:08 -0700234 ServiceManager.addService(Context.DISPLAY_SERVICE, display, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800235
Joe Onorato8a9b2202010-02-26 18:56:32 -0800236 Slog.i(TAG, "Telephony Registry");
Wink Savillea12a7b32012-09-20 10:09:45 -0700237 telephonyRegistry = new TelephonyRegistry(context);
238 ServiceManager.addService("telephony.registry", telephonyRegistry);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800239
Glenn Kasten07b04652012-04-23 15:00:43 -0700240 Slog.i(TAG, "Scheduling Policy");
Dianne Hackborn35f72be2013-09-16 10:57:39 -0700241 ServiceManager.addService("scheduling_policy", new SchedulingPolicyService());
Glenn Kasten07b04652012-04-23 15:00:43 -0700242
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800243 AttributeCache.init(context);
244
Jeff Brownbd6e1502012-08-28 03:27:37 -0700245 if (!display.waitForDefaultDisplay()) {
246 reportWtf("Timeout waiting for default display to be initialized.",
247 new Throwable());
248 }
249
Joe Onorato8a9b2202010-02-26 18:56:32 -0800250 Slog.i(TAG, "Package Manager");
Ben Komalo553acf02011-09-19 14:25:28 -0700251 // Only run "core" apps if we're encrypting the device.
252 String cryptState = SystemProperties.get("vold.decrypt");
Ben Komalo3573d402011-09-23 15:08:24 -0700253 if (ENCRYPTING_STATE.equals(cryptState)) {
Ben Komalo553acf02011-09-19 14:25:28 -0700254 Slog.w(TAG, "Detected encryption in progress - only parsing core apps");
Ben Komalo3573d402011-09-23 15:08:24 -0700255 onlyCore = true;
256 } else if (ENCRYPTED_STATE.equals(cryptState)) {
257 Slog.w(TAG, "Device encrypted - only parsing core apps");
258 onlyCore = true;
Ben Komalo553acf02011-09-19 14:25:28 -0700259 }
Ben Komalo3573d402011-09-23 15:08:24 -0700260
Jeff Brownf69c8122012-09-12 17:00:34 -0700261 pm = PackageManagerService.main(context, installer,
Dianne Hackbornd2509fd2011-09-12 12:29:43 -0700262 factoryTest != SystemServer.FACTORY_TEST_OFF,
Ben Komalo553acf02011-09-19 14:25:28 -0700263 onlyCore);
Dianne Hackborn58f42a52011-10-10 13:46:34 -0700264 try {
265 firstBoot = pm.isFirstBoot();
266 } catch (RemoteException e) {
267 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800268
269 ActivityManagerService.setSystemProcess();
Svetoslavb3038ec2013-02-13 14:39:30 -0800270
Nick Kralevich79619dd2013-03-04 13:05:32 -0800271 Slog.i(TAG, "Entropy Mixer");
272 ServiceManager.addService("entropy", new EntropyMixer(context));
273
Amith Yamasani258848d2012-08-10 17:06:33 -0700274 Slog.i(TAG, "User Service");
275 ServiceManager.addService(Context.USER_SERVICE,
Dianne Hackborn4428e172012-08-24 17:43:05 -0700276 UserManagerService.getInstance());
Amith Yamasani258848d2012-08-10 17:06:33 -0700277
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800278 mContentResolver = context.getContentResolver();
279
Fred Quintanae91ebe22009-09-29 20:44:30 -0700280 // The AccountManager must come before the ContentService
Fred Quintana60307342009-03-24 22:48:12 -0700281 try {
Dan Morrille4d9a012013-03-28 18:10:43 -0700282 // TODO: seems like this should be disable-able, but req'd by ContentService
Joe Onorato8a9b2202010-02-26 18:56:32 -0800283 Slog.i(TAG, "Account Manager");
Kenny Root26ff6622012-07-30 12:58:03 -0700284 accountManager = new AccountManagerService(context);
285 ServiceManager.addService(Context.ACCOUNT_SERVICE, accountManager);
Fred Quintana60307342009-03-24 22:48:12 -0700286 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800287 Slog.e(TAG, "Failure starting Account Manager", e);
Fred Quintana60307342009-03-24 22:48:12 -0700288 }
289
Joe Onorato8a9b2202010-02-26 18:56:32 -0800290 Slog.i(TAG, "Content Manager");
Kenny Root26ff6622012-07-30 12:58:03 -0700291 contentService = ContentService.main(context,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800292 factoryTest == SystemServer.FACTORY_TEST_LOW_LEVEL);
293
Joe Onorato8a9b2202010-02-26 18:56:32 -0800294 Slog.i(TAG, "System Content Providers");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800295 ActivityManagerService.installSystemProviders();
296
Adam Lesinskief2ea1f2013-12-05 16:48:06 -0800297 systemServiceManager.startService(LightsService.class);
298 lights = LocalServices.getService(LightsManager.class);
Mike Lockwood3a322132009-11-24 00:30:52 -0500299
Joe Onoratode1b3592010-10-25 20:36:47 -0700300 Slog.i(TAG, "Battery Service");
301 battery = new BatteryService(context, lights);
302 ServiceManager.addService("battery", battery);
303
Joe Onorato8a9b2202010-02-26 18:56:32 -0800304 Slog.i(TAG, "Vibrator Service");
Jeff Brown7f6c2312012-04-13 20:38:38 -0700305 vibrator = new VibratorService(context);
306 ServiceManager.addService("vibrator", vibrator);
The Android Open Source Project10592532009-03-18 17:39:46 -0700307
Erik Gilling51e95df2013-06-26 11:06:51 -0700308 Slog.i(TAG, "Consumer IR Service");
309 consumerIr = new ConsumerIrService(context);
310 ServiceManager.addService(Context.CONSUMER_IR_SERVICE, consumerIr);
311
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800312 // only initialize the power service after we have started the
Mike Lockwood3a322132009-11-24 00:30:52 -0500313 // lights service, content providers and the battery service.
Adam Lesinskief2ea1f2013-12-05 16:48:06 -0800314 power.init(context, lights, battery,
Dianne Hackborn713df152013-05-17 11:27:57 -0700315 BatteryStatsService.getService(),
316 ActivityManagerService.self().getAppOpsService(), display);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800317
Adam Lesinskief2ea1f2013-12-05 16:48:06 -0800318 systemServiceManager.startService(AlarmManagerService.class);
319 alarm = IAlarmManager.Stub.asInterface(
320 ServiceManager.getService(Context.ALARM_SERVICE));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800321
Joe Onorato8a9b2202010-02-26 18:56:32 -0800322 Slog.i(TAG, "Init Watchdog");
Adam Lesinskief2ea1f2013-12-05 16:48:06 -0800323 Watchdog.getInstance().init(context, ActivityManagerService.self());
Dianne Hackborn8d044e82013-04-30 17:24:15 -0700324 Watchdog.getInstance().addThread(wmHandler, "WindowManager thread");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800325
Jeff Browna9d131c2012-09-20 16:48:17 -0700326 Slog.i(TAG, "Input Manager");
327 inputManager = new InputManagerService(context, wmHandler);
328
Joe Onorato8a9b2202010-02-26 18:56:32 -0800329 Slog.i(TAG, "Window Manager");
Jeff Browna9d131c2012-09-20 16:48:17 -0700330 wm = WindowManagerService.main(context, power, display, inputManager,
Dianne Hackborn8d044e82013-04-30 17:24:15 -0700331 wmHandler, factoryTest != SystemServer.FACTORY_TEST_LOW_LEVEL,
Jeff Brown780c46f2012-06-24 12:15:38 -0700332 !firstBoot, onlyCore);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800333 ServiceManager.addService(Context.WINDOW_SERVICE, wm);
Jeff Brown6ec6f792012-04-17 16:52:41 -0700334 ServiceManager.addService(Context.INPUT_SERVICE, inputManager);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800335
Dianne Hackborn295e3c22011-08-25 13:19:08 -0700336 ActivityManagerService.self().setWindowManager(wm);
Jeff Browna9d131c2012-09-20 16:48:17 -0700337
338 inputManager.setWindowManagerCallbacks(wm.getInputMonitor());
339 inputManager.start();
340
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700341 display.setWindowManager(wm);
Jeff Brownd728bf52012-09-08 18:05:28 -0700342 display.setInputManager(inputManager);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800343
344 // Skip Bluetooth if we have an emulator kernel
345 // TODO: Use a more reliable check to see if this product should
346 // support Bluetooth - see bug 988521
347 if (SystemProperties.get("ro.kernel.qemu").equals("1")) {
David 'Digit' Turnere2a5e862011-01-17 00:32:33 +0100348 Slog.i(TAG, "No Bluetooh Service (emulator)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800349 } else if (factoryTest == SystemServer.FACTORY_TEST_LOW_LEVEL) {
David 'Digit' Turnere2a5e862011-01-17 00:32:33 +0100350 Slog.i(TAG, "No Bluetooth Service (factory test)");
Matthew Xie1dd01eb32013-04-26 12:37:54 -0700351 } else if (!context.getPackageManager().hasSystemFeature
352 (PackageManager.FEATURE_BLUETOOTH)) {
353 Slog.i(TAG, "No Bluetooth Service (Bluetooth Hardware Not Present)");
Dan Morrille4d9a012013-03-28 18:10:43 -0700354 } else if (disableBluetooth) {
355 Slog.i(TAG, "Bluetooth Service disabled by config");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800356 } else {
fredc0f420372012-04-12 00:02:00 -0700357 Slog.i(TAG, "Bluetooth Manager Service");
358 bluetooth = new BluetoothManagerService(context);
359 ServiceManager.addService(BluetoothAdapter.BLUETOOTH_MANAGER_SERVICE, bluetooth);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800360 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800361 } catch (RuntimeException e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700362 Slog.e("System", "******************************************");
363 Slog.e("System", "************ Failure starting core service", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800364 }
365
Joe Onorato089de882010-04-12 08:18:45 -0700366 StatusBarManagerService statusBar = null;
Adam Lesinskief2ea1f2013-12-05 16:48:06 -0800367 INotificationManager notification = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800368 InputMethodManagerService imm = null;
Dianne Hackbornf21adf62009-08-13 10:20:21 -0700369 WallpaperManagerService wallpaper = null;
Mike Lockwood46db5042010-02-22 16:36:44 -0500370 LocationManagerService location = null;
Bai Taoa58a8752010-07-13 15:32:16 +0800371 CountryDetectorService countryDetector = null;
satok988323c2011-06-22 16:38:13 +0900372 TextServicesManagerService tsms = null;
Amith Yamasani52c489c2012-03-28 11:42:42 -0700373 LockSettingsService lockSettings = null;
Daniel Sandler7d276c32012-01-30 14:33:52 -0500374 DreamManagerService dreamy = null;
Romain Guy3b748a42013-04-17 18:54:38 -0700375 AssetAtlasService atlas = null;
Jeff Brown69b07162013-11-07 00:30:16 -0800376 MediaRouterService mediaRouter = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800377
Dianne Hackborn661cd522011-08-22 00:26:20 -0700378 // Bring up services needed for UI.
379 if (factoryTest != SystemServer.FACTORY_TEST_LOW_LEVEL) {
Dan Morrille4d9a012013-03-28 18:10:43 -0700380 //if (!disableNonCoreServices) { // TODO: View depends on these; mock them?
381 if (true) {
382 try {
383 Slog.i(TAG, "Input Method Service");
384 imm = new InputMethodManagerService(context, wm);
385 ServiceManager.addService(Context.INPUT_METHOD_SERVICE, imm);
386 } catch (Throwable e) {
387 reportWtf("starting Input Manager Service", e);
388 }
Dianne Hackborn661cd522011-08-22 00:26:20 -0700389
Dan Morrille4d9a012013-03-28 18:10:43 -0700390 try {
391 Slog.i(TAG, "Accessibility Manager");
392 ServiceManager.addService(Context.ACCESSIBILITY_SERVICE,
393 new AccessibilityManagerService(context));
394 } catch (Throwable e) {
395 reportWtf("starting Accessibility Manager", e);
396 }
Dianne Hackborn661cd522011-08-22 00:26:20 -0700397 }
398 }
399
400 try {
401 wm.displayReady();
402 } catch (Throwable e) {
403 reportWtf("making display ready", e);
404 }
Dianne Hackborn8795b602011-08-25 13:30:53 -0700405
Dianne Hackborn295e3c22011-08-25 13:19:08 -0700406 try {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700407 pm.performBootDexOpt();
408 } catch (Throwable e) {
409 reportWtf("performing boot dexopt", e);
410 }
411
412 try {
413 ActivityManagerNative.getDefault().showBootMessage(
414 context.getResources().getText(
415 com.android.internal.R.string.android_upgrading_starting_apps),
Adam Lesinskief2ea1f2013-12-05 16:48:06 -0800416 false);
Dianne Hackborn661cd522011-08-22 00:26:20 -0700417 } catch (RemoteException e) {
418 }
419
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800420 if (factoryTest != SystemServer.FACTORY_TEST_LOW_LEVEL) {
Dan Morrille4d9a012013-03-28 18:10:43 -0700421 if (!disableStorage &&
422 !"0".equals(SystemProperties.get("system_init.startmountservice"))) {
Kenny Root51a573c2012-05-17 13:30:28 -0700423 try {
424 /*
425 * NotificationManagerService is dependant on MountService,
426 * (for media / usb notifications) so we must start MountService first.
427 */
428 Slog.i(TAG, "Mount Service");
429 mountService = new MountService(context);
430 ServiceManager.addService("mount", mountService);
431 } catch (Throwable e) {
432 reportWtf("starting Mount Service", e);
433 }
434 }
435
Dan Morrille4d9a012013-03-28 18:10:43 -0700436 if (!disableNonCoreServices) {
437 try {
438 Slog.i(TAG, "LockSettingsService");
439 lockSettings = new LockSettingsService(context);
440 ServiceManager.addService("lock_settings", lockSettings);
441 } catch (Throwable e) {
442 reportWtf("starting LockSettingsService service", e);
443 }
444
445 try {
446 Slog.i(TAG, "Device Policy");
Amith Yamasani817ec492013-12-20 13:27:30 -0800447 systemServiceManager.startService(DEVICE_POLICY_MANAGER_SERVICE_CLASS);
Dan Morrille4d9a012013-03-28 18:10:43 -0700448 } catch (Throwable e) {
449 reportWtf("starting DevicePolicyService", e);
450 }
Amith Yamasani52c489c2012-03-28 11:42:42 -0700451 }
452
Dan Morrille4d9a012013-03-28 18:10:43 -0700453 if (!disableSystemUI) {
454 try {
455 Slog.i(TAG, "Status Bar");
456 statusBar = new StatusBarManagerService(context, wm);
457 ServiceManager.addService(Context.STATUS_BAR_SERVICE, statusBar);
458 } catch (Throwable e) {
459 reportWtf("starting StatusBarManagerService", e);
460 }
Dianne Hackbornd6847842010-01-12 18:14:19 -0800461 }
462
Dan Morrille4d9a012013-03-28 18:10:43 -0700463 if (!disableNonCoreServices) {
464 try {
465 Slog.i(TAG, "Clipboard Service");
466 ServiceManager.addService(Context.CLIPBOARD_SERVICE,
467 new ClipboardService(context));
468 } catch (Throwable e) {
469 reportWtf("starting Clipboard Service", e);
470 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800471 }
472
Dan Morrille4d9a012013-03-28 18:10:43 -0700473 if (!disableNetwork) {
474 try {
475 Slog.i(TAG, "NetworkManagement Service");
476 networkManagement = NetworkManagementService.create(context);
477 ServiceManager.addService(Context.NETWORKMANAGEMENT_SERVICE, networkManagement);
478 } catch (Throwable e) {
479 reportWtf("starting NetworkManagement Service", e);
480 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800481 }
482
Dan Morrille4d9a012013-03-28 18:10:43 -0700483 if (!disableNonCoreServices) {
484 try {
485 Slog.i(TAG, "Text Service Manager Service");
486 tsms = new TextServicesManagerService(context);
487 ServiceManager.addService(Context.TEXT_SERVICES_MANAGER_SERVICE, tsms);
488 } catch (Throwable e) {
489 reportWtf("starting Text Service Manager Service", e);
490 }
San Mehatd1df8ac2010-01-26 06:17:26 -0800491 }
492
Dan Morrille4d9a012013-03-28 18:10:43 -0700493 if (!disableNetwork) {
494 try {
495 Slog.i(TAG, "NetworkStats Service");
496 networkStats = new NetworkStatsService(context, networkManagement, alarm);
497 ServiceManager.addService(Context.NETWORK_STATS_SERVICE, networkStats);
498 } catch (Throwable e) {
499 reportWtf("starting NetworkStats Service", e);
500 }
501
502 try {
503 Slog.i(TAG, "NetworkPolicy Service");
504 networkPolicy = new NetworkPolicyManagerService(
505 context, ActivityManagerService.self(), power,
506 networkStats, networkManagement);
507 ServiceManager.addService(Context.NETWORK_POLICY_SERVICE, networkPolicy);
508 } catch (Throwable e) {
509 reportWtf("starting NetworkPolicy Service", e);
510 }
511
Vinit Deshapnde4a3f9cf2013-12-27 11:10:54 -0800512 try {
Dan Morrille4d9a012013-03-28 18:10:43 -0700513 Slog.i(TAG, "Wi-Fi P2pService");
Vinit Deshapnde4a3f9cf2013-12-27 11:10:54 -0800514 systemServiceManager.startService("com.android.server.wifi.p2p.WifiP2pService");
Dan Morrille4d9a012013-03-28 18:10:43 -0700515 } catch (Throwable e) {
516 reportWtf("starting Wi-Fi P2pService", e);
517 }
518
Vinit Deshapnde4a3f9cf2013-12-27 11:10:54 -0800519 try {
Dan Morrille4d9a012013-03-28 18:10:43 -0700520 Slog.i(TAG, "Wi-Fi Service");
Vinit Deshapnde4a3f9cf2013-12-27 11:10:54 -0800521 systemServiceManager.startService("com.android.server.wifi.WifiService");
Dan Morrille4d9a012013-03-28 18:10:43 -0700522 } 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);
Dan Morrille4d9a012013-03-28 18:10:43 -0700533 } catch (Throwable e) {
534 reportWtf("starting Connectivity Service", e);
535 }
536
537 try {
538 Slog.i(TAG, "Network Service Discovery Service");
539 serviceDiscovery = NsdService.create(context);
540 ServiceManager.addService(
541 Context.NSD_SERVICE, serviceDiscovery);
542 } catch (Throwable e) {
543 reportWtf("starting Service Discovery Service", e);
544 }
satok988323c2011-06-22 16:38:13 +0900545 }
546
Dan Morrille4d9a012013-03-28 18:10:43 -0700547 if (!disableNonCoreServices) {
548 try {
549 Slog.i(TAG, "UpdateLock Service");
550 ServiceManager.addService(Context.UPDATE_LOCK_SERVICE,
551 new UpdateLockService(context));
552 } catch (Throwable e) {
553 reportWtf("starting UpdateLockService", e);
554 }
Christopher Tate8662cab52012-02-23 14:59:36 -0800555 }
556
Kenny Root51a573c2012-05-17 13:30:28 -0700557 /*
558 * MountService has a few dependencies: Notification Manager and
559 * AppWidget Provider. Make sure MountService is completely started
560 * first before continuing.
561 */
Ken Sumrall025adc42013-06-05 22:08:12 -0700562 if (mountService != null && !onlyCore) {
Kenny Root51a573c2012-05-17 13:30:28 -0700563 mountService.waitForAsecScan();
San Mehat1bf3f8b2010-02-03 14:43:09 -0800564 }
565
566 try {
Kenny Root26ff6622012-07-30 12:58:03 -0700567 if (accountManager != null)
568 accountManager.systemReady();
569 } catch (Throwable e) {
570 reportWtf("making Account Manager Service ready", e);
571 }
572
573 try {
574 if (contentService != null)
575 contentService.systemReady();
576 } catch (Throwable e) {
577 reportWtf("making Content Service ready", e);
578 }
579
Adam Lesinskief2ea1f2013-12-05 16:48:06 -0800580 systemServiceManager.startService(NotificationManagerService.class);
581 notification = INotificationManager.Stub.asInterface(
582 ServiceManager.getService(Context.NOTIFICATION_SERVICE));
583 networkPolicy.bindNotificationManager(notification);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800584
Adam Lesinskief2ea1f2013-12-05 16:48:06 -0800585 systemServiceManager.startService(DeviceStorageMonitorService.class);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800586
Dan Morrille4d9a012013-03-28 18:10:43 -0700587 if (!disableLocation) {
588 try {
589 Slog.i(TAG, "Location Manager");
590 location = new LocationManagerService(context);
591 ServiceManager.addService(Context.LOCATION_SERVICE, location);
592 } catch (Throwable e) {
593 reportWtf("starting Location Manager", e);
594 }
595
596 try {
597 Slog.i(TAG, "Country Detector");
598 countryDetector = new CountryDetectorService(context);
599 ServiceManager.addService(Context.COUNTRY_DETECTOR, countryDetector);
600 } catch (Throwable e) {
601 reportWtf("starting Country Detector", e);
602 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800603 }
604
Dan Morrille4d9a012013-03-28 18:10:43 -0700605 if (!disableNonCoreServices) {
606 try {
607 Slog.i(TAG, "Search Service");
608 ServiceManager.addService(Context.SEARCH_SERVICE,
609 new SearchManagerService(context));
610 } catch (Throwable e) {
611 reportWtf("starting Search Service", e);
612 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800613 }
614
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800615 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800616 Slog.i(TAG, "DropBox Service");
Dan Egnor95240272009-10-27 18:23:39 -0700617 ServiceManager.addService(Context.DROPBOX_SERVICE,
Dan Egnorf18a01c2009-11-12 11:32:50 -0800618 new DropBoxManagerService(context, new File("/data/system/dropbox")));
Dan Egnor4410ec82009-09-11 16:40:01 -0700619 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700620 reportWtf("starting DropBoxManagerService", e);
Dan Egnor4410ec82009-09-11 16:40:01 -0700621 }
622
Dan Morrille4d9a012013-03-28 18:10:43 -0700623 if (!disableNonCoreServices && context.getResources().getBoolean(
624 R.bool.config_enableWallpaperService)) {
Mike Lockwoodc067c9c2011-10-31 12:50:12 -0400625 try {
626 Slog.i(TAG, "Wallpaper Service");
Mike Lockwooded8902d2013-11-15 11:01:47 -0800627 wallpaper = new WallpaperManagerService(context);
628 ServiceManager.addService(Context.WALLPAPER_SERVICE, wallpaper);
Mike Lockwoodc067c9c2011-10-31 12:50:12 -0400629 } catch (Throwable e) {
630 reportWtf("starting Wallpaper Service", e);
Mike Lockwood3a74bd32011-08-12 13:55:22 -0700631 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800632 }
633
Dan Morrille4d9a012013-03-28 18:10:43 -0700634 if (!disableMedia && !"0".equals(SystemProperties.get("system_init.startaudioservice"))) {
Mike Lockwoodcba928c2011-08-17 15:58:52 -0700635 try {
636 Slog.i(TAG, "Audio Service");
637 ServiceManager.addService(Context.AUDIO_SERVICE, new AudioService(context));
638 } catch (Throwable e) {
639 reportWtf("starting Audio Service", e);
640 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800641 }
642
Dan Morrille4d9a012013-03-28 18:10:43 -0700643 if (!disableNonCoreServices) {
644 try {
645 Slog.i(TAG, "Dock Observer");
646 // Listen for dock station changes
647 dock = new DockObserver(context);
648 } catch (Throwable e) {
649 reportWtf("starting DockObserver", e);
650 }
Dan Murphyc9f4eaf2009-08-12 15:15:43 -0500651 }
652
Dan Morrille4d9a012013-03-28 18:10:43 -0700653 if (!disableMedia) {
654 try {
655 Slog.i(TAG, "Wired Accessory Manager");
656 // Listen for wired headset changes
657 inputManager.setWiredAccessoryCallbacks(
658 new WiredAccessoryManager(context, inputManager));
659 } catch (Throwable e) {
660 reportWtf("starting WiredAccessoryManager", e);
661 }
Praveen Bharathi21e941b2010-10-06 15:23:14 -0500662 }
663
Dan Morrille4d9a012013-03-28 18:10:43 -0700664 if (!disableNonCoreServices) {
665 try {
666 Slog.i(TAG, "USB Service");
667 // Manage USB host and device support
668 usb = new UsbService(context);
669 ServiceManager.addService(Context.USB_SERVICE, usb);
670 } catch (Throwable e) {
671 reportWtf("starting UsbService", e);
672 }
Mike Lockwood57c798a2010-06-23 17:36:36 -0400673
Dan Morrille4d9a012013-03-28 18:10:43 -0700674 try {
675 Slog.i(TAG, "Serial Service");
676 // Serial port support
677 serial = new SerialService(context);
678 ServiceManager.addService(Context.SERIAL_SERVICE, serial);
679 } catch (Throwable e) {
680 Slog.e(TAG, "Failure starting SerialService", e);
681 }
Mike Lockwoodb01e8bf2011-08-29 20:11:07 -0400682 }
683
Adam Lesinskief2ea1f2013-12-05 16:48:06 -0800684 systemServiceManager.startService(TwilightService.class);
685 twilight = LocalServices.getService(TwilightManager.class);
Jeff Brown2416e092012-08-21 22:12:20 -0700686
Adam Lesinskief2ea1f2013-12-05 16:48:06 -0800687 systemServiceManager.startService(UiModeManagerService.class);
Dianne Hackborn7299c412010-03-04 18:41:49 -0800688
Dan Morrille4d9a012013-03-28 18:10:43 -0700689 if (!disableNonCoreServices) {
690 try {
691 Slog.i(TAG, "Backup Service");
Amith Yamasani817ec492013-12-20 13:27:30 -0800692 systemServiceManager.startService(BACKUP_MANAGER_SERVICE_CLASS);
Dan Morrille4d9a012013-03-28 18:10:43 -0700693 } catch (Throwable e) {
694 Slog.e(TAG, "Failure starting Backup Service", e);
695 }
Christopher Tate487529a2009-04-29 14:03:25 -0700696
Dan Morrille4d9a012013-03-28 18:10:43 -0700697 try {
698 Slog.i(TAG, "AppWidget Service");
Amith Yamasani817ec492013-12-20 13:27:30 -0800699 systemServiceManager.startService(APPWIDGET_SERVICE_CLASS);
Dan Morrille4d9a012013-03-28 18:10:43 -0700700 } catch (Throwable e) {
701 reportWtf("starting AppWidget Service", e);
702 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800703
Dan Morrille4d9a012013-03-28 18:10:43 -0700704 try {
705 Slog.i(TAG, "Recognition Service");
706 recognition = new RecognitionManagerService(context);
707 } catch (Throwable e) {
708 reportWtf("starting Recognition Service", e);
709 }
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800710 }
Jaikumar Ganesh7d0548d2010-10-18 15:29:09 -0700711
Nick Pelly038cabe2010-09-23 16:12:11 -0700712 try {
Dan Egnor621bc542010-03-25 16:20:14 -0700713 Slog.i(TAG, "DiskStats Service");
714 ServiceManager.addService("diskstats", new DiskStatsService(context));
715 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700716 reportWtf("starting DiskStats Service", e);
Dan Egnor621bc542010-03-25 16:20:14 -0700717 }
Sen Hubde75702010-05-28 01:54:03 -0700718
719 try {
720 // need to add this service even if SamplingProfilerIntegration.isEnabled()
721 // is false, because it is this service that detects system property change and
722 // turns on SamplingProfilerIntegration. Plus, when sampling profiler doesn't work,
723 // there is little overhead for running this service.
724 Slog.i(TAG, "SamplingProfiler Service");
725 ServiceManager.addService("samplingprofiler",
726 new SamplingProfilerService(context));
727 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700728 reportWtf("starting SamplingProfiler Service", e);
Sen Hubde75702010-05-28 01:54:03 -0700729 }
Chung-yih Wang024d5962010-08-06 12:06:04 +0800730
Dan Morrille4d9a012013-03-28 18:10:43 -0700731 if (!disableNetwork) {
732 try {
733 Slog.i(TAG, "NetworkTimeUpdateService");
734 networkTimeUpdater = new NetworkTimeUpdateService(context);
735 } catch (Throwable e) {
736 reportWtf("starting NetworkTimeUpdate service", e);
737 }
Amith Yamasani6734b9f2010-09-13 16:24:08 -0700738 }
John Grossmanc1576732012-02-01 15:23:33 -0800739
Dan Morrille4d9a012013-03-28 18:10:43 -0700740 if (!disableMedia) {
741 try {
742 Slog.i(TAG, "CommonTimeManagementService");
743 commonTimeMgmtService = new CommonTimeManagementService(context);
744 ServiceManager.addService("commontime_management", commonTimeMgmtService);
745 } catch (Throwable e) {
746 reportWtf("starting CommonTimeManagementService service", e);
747 }
John Grossmanc1576732012-02-01 15:23:33 -0800748 }
Geremy Condra3d33c262012-05-06 18:32:19 -0700749
Dan Morrille4d9a012013-03-28 18:10:43 -0700750 if (!disableNetwork) {
751 try {
752 Slog.i(TAG, "CertBlacklister");
753 CertBlacklister blacklister = new CertBlacklister(context);
754 } catch (Throwable e) {
755 reportWtf("starting CertBlacklister", e);
756 }
Geremy Condra3d33c262012-05-06 18:32:19 -0700757 }
Jim Miller5ecd8112013-01-09 18:50:26 -0800758
Dan Morrille4d9a012013-03-28 18:10:43 -0700759 if (!disableNonCoreServices &&
760 context.getResources().getBoolean(R.bool.config_dreamsSupported)) {
Daniel Sandler7d276c32012-01-30 14:33:52 -0500761 try {
762 Slog.i(TAG, "Dreams Service");
763 // Dreams (interactive idle-time views, a/k/a screen savers)
Jeff Brown62c82e42012-09-26 01:30:41 -0700764 dreamy = new DreamManagerService(context, wmHandler);
Dianne Hackbornbe87e2f2012-09-28 16:31:34 -0700765 ServiceManager.addService(DreamService.DREAM_SERVICE, dreamy);
Daniel Sandler7d276c32012-01-30 14:33:52 -0500766 } catch (Throwable e) {
767 reportWtf("starting DreamManagerService", e);
768 }
769 }
Svetoslavb3038ec2013-02-13 14:39:30 -0800770
Romain Guy3b748a42013-04-17 18:54:38 -0700771 if (!disableNonCoreServices) {
772 try {
773 Slog.i(TAG, "Assets Atlas Service");
774 atlas = new AssetAtlasService(context);
775 ServiceManager.addService(AssetAtlasService.ASSET_ATLAS_SERVICE, atlas);
776 } catch (Throwable e) {
777 reportWtf("starting AssetAtlasService", e);
778 }
779 }
780
Svetoslavb3038ec2013-02-13 14:39:30 -0800781 try {
782 Slog.i(TAG, "IdleMaintenanceService");
Svetoslav6a08a122013-05-03 11:24:26 -0700783 new IdleMaintenanceService(context, battery);
Svetoslavb3038ec2013-02-13 14:39:30 -0800784 } catch (Throwable e) {
785 reportWtf("starting IdleMaintenanceService", e);
786 }
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -0700787
788 try {
789 Slog.i(TAG, "Print Service");
Amith Yamasani817ec492013-12-20 13:27:30 -0800790 systemServiceManager.startService(PRINT_MANAGER_SERVICE_CLASS);
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -0700791 } catch (Throwable e) {
792 reportWtf("starting Print Service", e);
793 }
Jeff Brown69b07162013-11-07 00:30:16 -0800794
795 if (!disableNonCoreServices) {
796 try {
797 Slog.i(TAG, "Media Router Service");
798 mediaRouter = new MediaRouterService(context);
799 ServiceManager.addService(Context.MEDIA_ROUTER_SERVICE, mediaRouter);
800 } catch (Throwable e) {
801 reportWtf("starting MediaRouterService", e);
802 }
803 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800804 }
805
Dianne Hackborn6af0d502009-09-28 13:25:46 -0700806 // Before things start rolling, be sure we have decided whether
807 // we are in safe mode.
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700808 final boolean safeMode = wm.detectSafeMode();
Dianne Hackborn6af0d502009-09-28 13:25:46 -0700809 if (safeMode) {
Jeff Brownb09abc12011-01-13 21:08:27 -0800810 ActivityManagerService.self().enterSafeMode();
811 // Post the safe mode state in the Zygote class
812 Zygote.systemInSafeMode = true;
813 // Disable the JIT for the system_server process
814 VMRuntime.getRuntime().disableJitCompilation();
Ben Cheng6c0afff2010-02-14 16:18:56 -0800815 } else {
816 // Enable the JIT for the system_server process
817 VMRuntime.getRuntime().startJitCompilation();
Dianne Hackborn6af0d502009-09-28 13:25:46 -0700818 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800819
Dianne Hackborn6af0d502009-09-28 13:25:46 -0700820 // It is now time to start up the app processes...
Joe Onorato30275482009-07-08 17:09:14 -0700821
Jeff Brown7f6c2312012-04-13 20:38:38 -0700822 try {
823 vibrator.systemReady();
824 } catch (Throwable e) {
825 reportWtf("making Vibrator Service ready", e);
826 }
827
Dan Morrille4d9a012013-03-28 18:10:43 -0700828 if (lockSettings != null) {
829 try {
830 lockSettings.systemReady();
831 } catch (Throwable e) {
832 reportWtf("making Lock Settings Service ready", e);
833 }
Felipe Ramosf35df5b2012-09-18 18:26:27 -0300834 }
835
Amith Yamasani817ec492013-12-20 13:27:30 -0800836 // Needed by DevicePolicyManager for initialization
837 systemServiceManager.startBootPhase(SystemService.PHASE_LOCK_SETTINGS_READY);
Dianne Hackbornd6847842010-01-12 18:14:19 -0800838
Adam Lesinskief2ea1f2013-12-05 16:48:06 -0800839 systemServiceManager.startBootPhase(SystemService.PHASE_SYSTEM_SERVICES_READY);
Joe Onorato30275482009-07-08 17:09:14 -0700840
Dianne Hackborn661cd522011-08-22 00:26:20 -0700841 try {
842 wm.systemReady();
843 } catch (Throwable e) {
844 reportWtf("making Window Manager Service ready", e);
845 }
Joe Onoratodc565f42010-10-04 15:27:22 -0400846
Jeff Brownb09abc12011-01-13 21:08:27 -0800847 if (safeMode) {
848 ActivityManagerService.self().showSafeModeOverlay();
849 }
850
Joe Onoratodc565f42010-10-04 15:27:22 -0400851 // Update the configuration for this context by hand, because we're going
852 // to start using it before the config change done in wm.systemReady() will
853 // propagate to it.
854 Configuration config = wm.computeNewConfiguration();
855 DisplayMetrics metrics = new DisplayMetrics();
856 WindowManager w = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
857 w.getDefaultDisplay().getMetrics(metrics);
858 context.getResources().updateConfiguration(config, metrics);
859
Jeff Brownaa202a62012-08-21 22:14:26 -0700860 try {
Jeff Brown62c82e42012-09-26 01:30:41 -0700861 power.systemReady(twilight, dreamy);
Jeff Brownaa202a62012-08-21 22:14:26 -0700862 } catch (Throwable e) {
863 reportWtf("making Power Manager Service ready", e);
864 }
865
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800866 try {
867 pm.systemReady();
Dianne Hackborn661cd522011-08-22 00:26:20 -0700868 } catch (Throwable e) {
869 reportWtf("making Package Manager Service ready", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800870 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800871
Jeff Brownbd6e1502012-08-28 03:27:37 -0700872 try {
873 display.systemReady(safeMode, onlyCore);
874 } catch (Throwable e) {
875 reportWtf("making Display Manager Service ready", e);
876 }
877
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700878 // These are needed to propagate to the runnable below.
Joe Onoratof3c3c4f2010-10-21 11:09:02 -0400879 final Context contextF = context;
Jeff Sharkeyb049e212012-09-07 23:16:01 -0700880 final MountService mountServiceF = mountService;
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700881 final BatteryService batteryF = battery;
Jeff Sharkey350083e2011-06-29 10:45:16 -0700882 final NetworkManagementService networkManagementF = networkManagement;
Jeff Sharkey75279902011-05-24 18:39:45 -0700883 final NetworkStatsService networkStatsF = networkStats;
Jeff Sharkeya4620792011-05-20 15:29:23 -0700884 final NetworkPolicyManagerService networkPolicyF = networkPolicy;
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700885 final ConnectivityService connectivityF = connectivity;
886 final DockObserver dockF = dock;
Mike Lockwood770126a2010-12-09 22:30:37 -0800887 final UsbService usbF = usb;
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700888 final WallpaperManagerService wallpaperF = wallpaper;
889 final InputMethodManagerService immF = imm;
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800890 final RecognitionManagerService recognitionF = recognition;
Mike Lockwood46db5042010-02-22 16:36:44 -0500891 final LocationManagerService locationF = location;
Bai Taoa58a8752010-07-13 15:32:16 +0800892 final CountryDetectorService countryDetectorF = countryDetector;
Amith Yamasani6734b9f2010-09-13 16:24:08 -0700893 final NetworkTimeUpdateService networkTimeUpdaterF = networkTimeUpdater;
John Grossmanc1576732012-02-01 15:23:33 -0800894 final CommonTimeManagementService commonTimeMgmtServiceF = commonTimeMgmtService;
satok988323c2011-06-22 16:38:13 +0900895 final TextServicesManagerService textServiceManagerServiceF = tsms;
Dianne Hackborn661cd522011-08-22 00:26:20 -0700896 final StatusBarManagerService statusBarF = statusBar;
Daniel Sandler7d276c32012-01-30 14:33:52 -0500897 final DreamManagerService dreamyF = dreamy;
Romain Guy3b748a42013-04-17 18:54:38 -0700898 final AssetAtlasService atlasF = atlas;
Jeff Brown6ec6f792012-04-17 16:52:41 -0700899 final InputManagerService inputManagerF = inputManager;
Wink Savillea12a7b32012-09-20 10:09:45 -0700900 final TelephonyRegistry telephonyRegistryF = telephonyRegistry;
Jeff Brown69b07162013-11-07 00:30:16 -0800901 final MediaRouterService mediaRouterF = mediaRouter;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800902
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700903 // We now tell the activity manager it is okay to run third party
904 // code. It will call back into us once it has gotten to the state
905 // where third party code can really run (but before it has actually
906 // started launching the initial applications), for us to complete our
907 // initialization.
Dianne Hackborn295e3c22011-08-25 13:19:08 -0700908 ActivityManagerService.self().systemReady(new Runnable() {
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700909 public void run() {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800910 Slog.i(TAG, "Making services ready");
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800911
Christopher Tate58d380d2013-03-19 13:10:03 -0700912 try {
913 ActivityManagerService.self().startObservingNativeCrashes();
914 } catch (Throwable e) {
915 reportWtf("observing native crashes", e);
916 }
Amith Yamasanib6fda092013-11-14 19:24:44 -0800917 try {
918 startSystemUi(contextF);
919 } catch (Throwable e) {
920 reportWtf("starting System UI", e);
921 }
Dianne Hackborn661cd522011-08-22 00:26:20 -0700922 try {
Jeff Sharkeyb049e212012-09-07 23:16:01 -0700923 if (mountServiceF != null) mountServiceF.systemReady();
924 } catch (Throwable e) {
925 reportWtf("making Mount Service ready", e);
926 }
927 try {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700928 if (batteryF != null) batteryF.systemReady();
929 } catch (Throwable e) {
930 reportWtf("making Battery Service ready", e);
931 }
932 try {
933 if (networkManagementF != null) networkManagementF.systemReady();
934 } catch (Throwable e) {
935 reportWtf("making Network Managment Service ready", e);
936 }
937 try {
938 if (networkStatsF != null) networkStatsF.systemReady();
939 } catch (Throwable e) {
940 reportWtf("making Network Stats Service ready", e);
941 }
942 try {
943 if (networkPolicyF != null) networkPolicyF.systemReady();
944 } catch (Throwable e) {
945 reportWtf("making Network Policy Service ready", e);
946 }
947 try {
948 if (connectivityF != null) connectivityF.systemReady();
949 } catch (Throwable e) {
950 reportWtf("making Connectivity Service ready", e);
951 }
952 try {
953 if (dockF != null) dockF.systemReady();
954 } catch (Throwable e) {
955 reportWtf("making Dock Service ready", e);
956 }
957 try {
958 if (usbF != null) usbF.systemReady();
959 } catch (Throwable e) {
960 reportWtf("making USB Service ready", e);
961 }
962 try {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700963 if (recognitionF != null) recognitionF.systemReady();
964 } catch (Throwable e) {
965 reportWtf("making Recognition Service ready", e);
966 }
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700967 Watchdog.getInstance().start();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800968
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700969 // It is now okay to let the various system services start their
970 // third party code...
Adam Lesinskief2ea1f2013-12-05 16:48:06 -0800971 systemServiceManager.startBootPhase(SystemService.PHASE_THIRD_PARTY_APPS_CAN_START);
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800972
Dianne Hackborn661cd522011-08-22 00:26:20 -0700973 try {
Svetoslav Ganova0027152013-06-25 14:59:53 -0700974 if (wallpaperF != null) wallpaperF.systemRunning();
Dianne Hackborn661cd522011-08-22 00:26:20 -0700975 } catch (Throwable e) {
Svetoslav Ganova0027152013-06-25 14:59:53 -0700976 reportWtf("Notifying WallpaperService running", e);
Dianne Hackborn661cd522011-08-22 00:26:20 -0700977 }
978 try {
Svetoslav Ganova0027152013-06-25 14:59:53 -0700979 if (immF != null) immF.systemRunning(statusBarF);
Dianne Hackborn661cd522011-08-22 00:26:20 -0700980 } catch (Throwable e) {
Svetoslav Ganova0027152013-06-25 14:59:53 -0700981 reportWtf("Notifying InputMethodService running", e);
Dianne Hackborn661cd522011-08-22 00:26:20 -0700982 }
983 try {
Svetoslav Ganova0027152013-06-25 14:59:53 -0700984 if (locationF != null) locationF.systemRunning();
Dianne Hackborn661cd522011-08-22 00:26:20 -0700985 } catch (Throwable e) {
Svetoslav Ganova0027152013-06-25 14:59:53 -0700986 reportWtf("Notifying Location Service running", e);
Dianne Hackborn661cd522011-08-22 00:26:20 -0700987 }
988 try {
Svetoslav Ganova0027152013-06-25 14:59:53 -0700989 if (countryDetectorF != null) countryDetectorF.systemRunning();
Dianne Hackborn661cd522011-08-22 00:26:20 -0700990 } catch (Throwable e) {
Svetoslav Ganova0027152013-06-25 14:59:53 -0700991 reportWtf("Notifying CountryDetectorService running", e);
Dianne Hackborn661cd522011-08-22 00:26:20 -0700992 }
993 try {
Svetoslav Ganova0027152013-06-25 14:59:53 -0700994 if (networkTimeUpdaterF != null) networkTimeUpdaterF.systemRunning();
Dianne Hackborn661cd522011-08-22 00:26:20 -0700995 } catch (Throwable e) {
Svetoslav Ganova0027152013-06-25 14:59:53 -0700996 reportWtf("Notifying NetworkTimeService running", e);
Dianne Hackborn661cd522011-08-22 00:26:20 -0700997 }
998 try {
Svetoslav Ganova0027152013-06-25 14:59:53 -0700999 if (commonTimeMgmtServiceF != null) commonTimeMgmtServiceF.systemRunning();
John Grossmanc1576732012-02-01 15:23:33 -08001000 } catch (Throwable e) {
Svetoslav Ganova0027152013-06-25 14:59:53 -07001001 reportWtf("Notifying CommonTimeManagementService running", e);
John Grossmanc1576732012-02-01 15:23:33 -08001002 }
1003 try {
Svetoslav Ganova0027152013-06-25 14:59:53 -07001004 if (textServiceManagerServiceF != null)
1005 textServiceManagerServiceF.systemRunning();
Dianne Hackborn661cd522011-08-22 00:26:20 -07001006 } catch (Throwable e) {
Svetoslav Ganova0027152013-06-25 14:59:53 -07001007 reportWtf("Notifying TextServicesManagerService running", e);
Dianne Hackborn661cd522011-08-22 00:26:20 -07001008 }
Daniel Sandler7d276c32012-01-30 14:33:52 -05001009 try {
Svetoslav Ganova0027152013-06-25 14:59:53 -07001010 if (dreamyF != null) dreamyF.systemRunning();
Daniel Sandler7d276c32012-01-30 14:33:52 -05001011 } catch (Throwable e) {
Svetoslav Ganova0027152013-06-25 14:59:53 -07001012 reportWtf("Notifying DreamManagerService running", e);
Daniel Sandler7d276c32012-01-30 14:33:52 -05001013 }
Jeff Brown6ec6f792012-04-17 16:52:41 -07001014 try {
Svetoslav Ganova0027152013-06-25 14:59:53 -07001015 if (atlasF != null) atlasF.systemRunning();
Romain Guy3b748a42013-04-17 18:54:38 -07001016 } catch (Throwable e) {
Svetoslav Ganova0027152013-06-25 14:59:53 -07001017 reportWtf("Notifying AssetAtlasService running", e);
Romain Guy3b748a42013-04-17 18:54:38 -07001018 }
1019 try {
Matthew Xie96313142012-06-29 16:57:31 -07001020 // TODO(BT) Pass parameter to input manager
Svetoslav Ganova0027152013-06-25 14:59:53 -07001021 if (inputManagerF != null) inputManagerF.systemRunning();
Jeff Brown6ec6f792012-04-17 16:52:41 -07001022 } catch (Throwable e) {
Svetoslav Ganova0027152013-06-25 14:59:53 -07001023 reportWtf("Notifying InputManagerService running", e);
Jeff Brown6ec6f792012-04-17 16:52:41 -07001024 }
Dan Morrille4d9a012013-03-28 18:10:43 -07001025
Wink Savillea12a7b32012-09-20 10:09:45 -07001026 try {
Svetoslav Ganova0027152013-06-25 14:59:53 -07001027 if (telephonyRegistryF != null) telephonyRegistryF.systemRunning();
Wink Savillea12a7b32012-09-20 10:09:45 -07001028 } catch (Throwable e) {
Svetoslav Ganova0027152013-06-25 14:59:53 -07001029 reportWtf("Notifying TelephonyRegistry running", e);
1030 }
1031
1032 try {
Jeff Brown69b07162013-11-07 00:30:16 -08001033 if (mediaRouterF != null) mediaRouterF.systemRunning();
1034 } catch (Throwable e) {
1035 reportWtf("Notifying MediaRouterService running", e);
1036 }
Adam Lesinskief2ea1f2013-12-05 16:48:06 -08001037
1038 systemServiceManager.startBootPhase(SystemService.PHASE_BOOT_COMPLETE);
Dianne Hackborna34f1ad2009-09-02 13:26:28 -07001039 }
1040 });
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001041
Brad Fitzpatrick1e02d362010-09-10 09:19:50 -07001042 // For debug builds, log event loop stalls to dropbox for analysis.
Brad Fitzpatrick50d66f92010-09-13 21:29:05 -07001043 if (StrictMode.conditionallyEnableDebugLogging()) {
1044 Slog.i(TAG, "Enabled StrictMode for system server main thread.");
Brad Fitzpatrick1e02d362010-09-10 09:19:50 -07001045 }
1046
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001047 Looper.loop();
Joe Onorato8a9b2202010-02-26 18:56:32 -08001048 Slog.d(TAG, "System ServerThread is exiting!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001049 }
Joe Onoratof3c3c4f2010-10-21 11:09:02 -04001050
1051 static final void startSystemUi(Context context) {
1052 Intent intent = new Intent();
1053 intent.setComponent(new ComponentName("com.android.systemui",
1054 "com.android.systemui.SystemUIService"));
Dianne Hackborn40e9f292012-11-27 19:12:23 -08001055 //Slog.d(TAG, "Starting service: " + intent);
Amith Yamasanicd757062012-10-19 18:23:52 -07001056 context.startServiceAsUser(intent, UserHandle.OWNER);
Joe Onoratof3c3c4f2010-10-21 11:09:02 -04001057 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001058}
1059
Jeff Hamilton35eef702010-06-09 15:45:18 -05001060public class SystemServer {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001061 private static final String TAG = "SystemServer";
1062
1063 public static final int FACTORY_TEST_OFF = 0;
1064 public static final int FACTORY_TEST_LOW_LEVEL = 1;
1065 public static final int FACTORY_TEST_HIGH_LEVEL = 2;
Jaikumar Ganeshd5ac1ae2009-05-05 22:26:12 -07001066
Bob Leee5408332009-09-04 18:31:17 -07001067 static Timer timer;
1068 static final long SNAPSHOT_INTERVAL = 60 * 60 * 1000; // 1hr
1069
Brad Fitzpatrick6bb7a4a2010-10-11 13:41:10 -07001070 // The earliest supported time. We pick one day into 1970, to
1071 // give any timezone code room without going into negative time.
1072 private static final long EARLIEST_SUPPORTED_TIME = 86400 * 1000;
1073
Jaikumar Ganeshd5ac1ae2009-05-05 22:26:12 -07001074 /**
Jeff Brownef691172013-07-15 13:22:04 -07001075 * Called to initialize native system services.
Jaikumar Ganeshd5ac1ae2009-05-05 22:26:12 -07001076 */
Jeff Brownef691172013-07-15 13:22:04 -07001077 private static native void nativeInit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001078
1079 public static void main(String[] args) {
Brian Carlstrom5637ffc2013-11-01 14:51:58 -07001080
1081 /*
1082 * In case the runtime switched since last boot (such as when
1083 * the old runtime was removed in an OTA), set the system
1084 * property so that it is in sync. We can't do this in
1085 * libnativehelper's JniInvocation::Init code where we already
1086 * had to fallback to a different runtime because it is
1087 * running as root and we need to be the system user to set
1088 * the property. http://b/11463182
1089 */
1090 SystemProperties.set("persist.sys.dalvik.vm.lib",
1091 VMRuntime.getRuntime().vmLibrary());
1092
Brad Fitzpatrick6bb7a4a2010-10-11 13:41:10 -07001093 if (System.currentTimeMillis() < EARLIEST_SUPPORTED_TIME) {
Brad Fitzpatrick35ca9d82010-10-11 11:52:49 -07001094 // If a device's clock is before 1970 (before 0), a lot of
1095 // APIs crash dealing with negative numbers, notably
1096 // java.io.File#setLastModified, so instead we fake it and
1097 // hope that time from cell towers or NTP fixes it
1098 // shortly.
1099 Slog.w(TAG, "System clock is before 1970; setting to 1970.");
Brad Fitzpatrick6bb7a4a2010-10-11 13:41:10 -07001100 SystemClock.setCurrentTimeMillis(EARLIEST_SUPPORTED_TIME);
Brad Fitzpatrick35ca9d82010-10-11 11:52:49 -07001101 }
1102
Bob Leee5408332009-09-04 18:31:17 -07001103 if (SamplingProfilerIntegration.isEnabled()) {
1104 SamplingProfilerIntegration.start();
1105 timer = new Timer();
1106 timer.schedule(new TimerTask() {
1107 @Override
1108 public void run() {
Sen Hubde75702010-05-28 01:54:03 -07001109 SamplingProfilerIntegration.writeSnapshot("system_server", null);
Bob Leee5408332009-09-04 18:31:17 -07001110 }
1111 }, SNAPSHOT_INTERVAL, SNAPSHOT_INTERVAL);
1112 }
1113
Dianne Hackbornac1471a2011-02-03 13:46:06 -08001114 // Mmmmmm... more memory!
1115 dalvik.system.VMRuntime.getRuntime().clearGrowthLimit();
1116
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001117 // The system server has to run all of the time, so it needs to be
1118 // as efficient as possible with its memory usage.
1119 VMRuntime.getRuntime().setTargetHeapUtilization(0.8f);
Sen Hubde75702010-05-28 01:54:03 -07001120
Jeff Sharkey48749fc2013-04-19 13:25:04 -07001121 Environment.setUserRequired(true);
1122
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001123 System.loadLibrary("android_servers");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001124
Joe Onorato8a9b2202010-02-26 18:56:32 -08001125 Slog.i(TAG, "Entered the Android system server!");
Dianne Hackbornefa92b22013-05-03 14:11:43 -07001126
Jeff Brownef691172013-07-15 13:22:04 -07001127 // Initialize native services.
1128 nativeInit();
1129
Dianne Hackbornefa92b22013-05-03 14:11:43 -07001130 // This used to be its own separate thread, but now it is
1131 // just the loop we run on the main thread.
1132 ServerThread thr = new ServerThread();
1133 thr.initAndLoop();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001134 }
1135}