blob: 8a3bc8841279444779163ccb8baf08c340f580a8 [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;
Nick Pellyf242b7b2009-10-08 00:12:45 +020020import android.bluetooth.BluetoothAdapter;
Joe Onoratof3c3c4f2010-10-21 11:09:02 -040021import android.content.ComponentName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080022import android.content.ContentResolver;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080023import android.content.Context;
Joe Onoratof3c3c4f2010-10-21 11:09:02 -040024import android.content.Intent;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080025import android.content.pm.IPackageManager;
Matthew Xie1dd01eb32013-04-26 12:37:54 -070026import android.content.pm.PackageManager;
Joe Onoratodc565f42010-10-04 15:27:22 -040027import android.content.res.Configuration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080028import android.media.AudioService;
Irfan Sherifff6d09842011-08-03 15:37:08 -070029import android.net.wifi.p2p.WifiP2pService;
Jeff Sharkey48749fc2013-04-19 13:25:04 -070030import android.os.Environment;
Jeff Brownbd6e1502012-08-28 03:27:37 -070031import android.os.Handler;
32import android.os.HandlerThread;
Jeff Hamilton35eef702010-06-09 15:45:18 -050033import android.os.Looper;
34import android.os.RemoteException;
35import android.os.ServiceManager;
Brad Fitzpatrickc74a1b442010-09-10 16:03:29 -070036import android.os.StrictMode;
Jeff Hamilton35eef702010-06-09 15:45:18 -050037import android.os.SystemClock;
38import android.os.SystemProperties;
Amith Yamasanicd757062012-10-19 18:23:52 -070039import android.os.UserHandle;
Dianne Hackbornbe87e2f2012-09-28 16:31:34 -070040import android.service.dreams.DreamService;
Joe Onoratodc565f42010-10-04 15:27:22 -040041import android.util.DisplayMetrics;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080042import android.util.EventLog;
Dianne Hackborn661cd522011-08-22 00:26:20 -070043import android.util.Log;
Joe Onorato8a9b2202010-02-26 18:56:32 -080044import android.util.Slog;
Brad Fitzpatrick5fdc0c72010-10-12 13:12:18 -070045import android.view.WindowManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080046
Dan Morrille4d9a012013-03-28 18:10:43 -070047import com.android.internal.R;
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -070048import com.android.internal.os.BinderInternal;
Narayan Kamath973b4662014-03-31 13:41:26 +010049import com.android.internal.os.Zygote;
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -070050import 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;
Jeff Sharkey7a96c392012-11-15 14:01:46 -080055import com.android.server.content.ContentService;
Jeff Brownfa25bf52012-07-23 19:26:30 -070056import com.android.server.display.DisplayManagerService;
Jeff Browncef440f2012-09-25 18:58:48 -070057import com.android.server.dreams.DreamManagerService;
Jeff Brown6ec6f792012-04-17 16:52:41 -070058import com.android.server.input.InputManagerService;
Jeff Brown69b07162013-11-07 00:30:16 -080059import com.android.server.media.MediaRouterService;
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -070060import com.android.server.net.NetworkPolicyManagerService;
Jeff Sharkey75279902011-05-24 18:39:45 -070061import com.android.server.net.NetworkStatsService;
Jeff Sharkey7a96c392012-11-15 14:01:46 -080062import com.android.server.os.SchedulingPolicyService;
Brian Carlstrom7395a8a2014-04-28 22:11:01 -070063import com.android.server.pm.BackgroundDexOptService;
Jeff Brownf69c8122012-09-12 17:00:34 -070064import com.android.server.pm.Installer;
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -070065import com.android.server.pm.PackageManagerService;
Amith Yamasani258848d2012-08-10 17:06:33 -070066import com.android.server.pm.UserManagerService;
Jeff Brown4f8ecd82012-06-18 18:29:13 -070067import com.android.server.power.PowerManagerService;
68import com.android.server.power.ShutdownThread;
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -070069import com.android.server.print.PrintManagerService;
Jeff Sharkey7a96c392012-11-15 14:01:46 -080070import com.android.server.search.SearchManagerService;
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -070071import com.android.server.usb.UsbService;
Irfan Sheriffd017f352013-02-20 13:30:44 -080072import com.android.server.wifi.WifiService;
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -070073import com.android.server.wm.WindowManagerService;
74
75import dalvik.system.VMRuntime;
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -070076
Dan Egnor4410ec82009-09-11 16:40:01 -070077import java.io.File;
Bob Leee5408332009-09-04 18:31:17 -070078import java.util.Timer;
79import java.util.TimerTask;
80
Dianne Hackbornefa92b22013-05-03 14:11:43 -070081class ServerThread {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080082 private static final String TAG = "SystemServer";
Ben Komalo553acf02011-09-19 14:25:28 -070083 private static final String ENCRYPTING_STATE = "trigger_restart_min_framework";
Ben Komalo3573d402011-09-23 15:08:24 -070084 private static final String ENCRYPTED_STATE = "1";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080085
Jeff Hamilton35eef702010-06-09 15:45:18 -050086 ContentResolver mContentResolver;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080087
Dianne Hackborn661cd522011-08-22 00:26:20 -070088 void reportWtf(String msg, Throwable e) {
89 Slog.w(TAG, "***********************************************");
90 Log.wtf(TAG, "BOOT FAILURE " + msg, e);
91 }
92
Dianne Hackbornefa92b22013-05-03 14:11:43 -070093 public void initAndLoop() {
Doug Zongkerab5c49c2009-12-04 10:31:43 -080094 EventLog.writeEvent(EventLogTags.BOOT_PROGRESS_SYSTEM_RUN,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080095 SystemClock.uptimeMillis());
96
Vairavan Srinivasan04b74ec2012-02-02 22:12:19 -080097 Looper.prepareMainLooper();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080098
99 android.os.Process.setThreadPriority(
100 android.os.Process.THREAD_PRIORITY_FOREGROUND);
101
Dianne Hackborn887f3552009-12-07 17:59:37 -0800102 BinderInternal.disableBackgroundScheduling(true);
Christopher Tate160edb32010-06-30 17:46:30 -0700103 android.os.Process.setCanSelfBackground(false);
Sen Hubde75702010-05-28 01:54:03 -0700104
Kenny Rootf547d672010-09-22 10:36:48 -0700105 // Check whether we failed to shut down last time we tried.
106 {
107 final String shutdownAction = SystemProperties.get(
108 ShutdownThread.SHUTDOWN_ACTION_PROPERTY, "");
109 if (shutdownAction != null && shutdownAction.length() > 0) {
110 boolean reboot = (shutdownAction.charAt(0) == '1');
111
112 final String reason;
113 if (shutdownAction.length() > 1) {
114 reason = shutdownAction.substring(1, shutdownAction.length());
115 } else {
116 reason = null;
117 }
118
119 ShutdownThread.rebootOrShutdown(reboot, reason);
120 }
121 }
122
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800123 String factoryTestStr = SystemProperties.get("ro.factorytest");
124 int factoryTest = "".equals(factoryTestStr) ? SystemServer.FACTORY_TEST_OFF
125 : Integer.parseInt(factoryTestStr);
Mike Lockwood3a74bd32011-08-12 13:55:22 -0700126 final boolean headless = "1".equals(SystemProperties.get("ro.config.headless", "0"));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800127
Jeff Brownf69c8122012-09-12 17:00:34 -0700128 Installer installer = null;
Kenny Root26ff6622012-07-30 12:58:03 -0700129 AccountManagerService accountManager = null;
130 ContentService contentService = null;
Mike Lockwood3a322132009-11-24 00:30:52 -0500131 LightsService lights = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800132 PowerManagerService power = null;
Jeff Brownfa25bf52012-07-23 19:26:30 -0700133 DisplayManagerService display = null;
Mike Lockwood07a500f2009-08-12 09:56:44 -0400134 BatteryService battery = null;
Jeff Brown7f6c2312012-04-13 20:38:38 -0700135 VibratorService vibrator = null;
Jeff Sharkey75279902011-05-24 18:39:45 -0700136 AlarmManagerService alarm = null;
Jeff Sharkeyb049e2122012-09-07 23:16:01 -0700137 MountService mountService = null;
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -0700138 NetworkManagementService networkManagement = null;
Jeff Sharkey75279902011-05-24 18:39:45 -0700139 NetworkStatsService networkStats = null;
Jeff Sharkeya4620792011-05-20 15:29:23 -0700140 NetworkPolicyManagerService networkPolicy = null;
Mike Lockwood0f79b542009-08-14 14:18:49 -0400141 ConnectivityService connectivity = null;
repo sync55bc5f32011-06-24 14:23:07 -0700142 WifiP2pService wifiP2p = null;
repo syncaea743a2011-07-29 23:55:49 -0700143 WifiService wifi = null;
Irfan Sheriff7d024d32012-03-22 17:01:39 -0700144 NsdService serviceDiscovery= null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800145 IPackageManager pm = null;
146 Context context = null;
147 WindowManagerService wm = null;
fredc0f420372012-04-12 00:02:00 -0700148 BluetoothManagerService bluetooth = null;
Dan Murphyc9f4eaf2009-08-12 15:15:43 -0500149 DockObserver dock = null;
Mike Lockwood770126a2010-12-09 22:30:37 -0800150 UsbService usb = null;
Mike Lockwoodb01e8bf2011-08-29 20:11:07 -0400151 SerialService serial = null;
Jeff Brown2416e092012-08-21 22:12:20 -0700152 TwilightService twilight = null;
Dianne Hackborn7299c412010-03-04 18:41:49 -0800153 UiModeManagerService uiMode = null;
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800154 RecognitionManagerService recognition = null;
Amith Yamasani6734b9f62010-09-13 16:24:08 -0700155 NetworkTimeUpdateService networkTimeUpdater = null;
John Grossmanc1576732012-02-01 15:23:33 -0800156 CommonTimeManagementService commonTimeMgmtService = null;
Jeff Brown6ec6f792012-04-17 16:52:41 -0700157 InputManagerService inputManager = null;
Wink Savillea12a7b32012-09-20 10:09:45 -0700158 TelephonyRegistry telephonyRegistry = null;
Erik Gilling51e95df2013-06-26 11:06:51 -0700159 ConsumerIrService consumerIr = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800160
Jeff Brownbd6e1502012-08-28 03:27:37 -0700161 // Create a handler thread just for the window manager to enjoy.
162 HandlerThread wmHandlerThread = new HandlerThread("WindowManager");
163 wmHandlerThread.start();
164 Handler wmHandler = new Handler(wmHandlerThread.getLooper());
165 wmHandler.post(new Runnable() {
166 @Override
167 public void run() {
168 //Looper.myLooper().setMessageLogging(new LogPrinter(
169 // android.util.Log.DEBUG, TAG, android.util.Log.LOG_ID_SYSTEM));
170 android.os.Process.setThreadPriority(
171 android.os.Process.THREAD_PRIORITY_DISPLAY);
172 android.os.Process.setCanSelfBackground(false);
173
174 // For debug builds, log event loop stalls to dropbox for analysis.
175 if (StrictMode.conditionallyEnableDebugLogging()) {
Jeff Brown89d55462012-09-19 11:33:42 -0700176 Slog.i(TAG, "Enabled StrictMode logging for WM Looper");
Jeff Brownbd6e1502012-08-28 03:27:37 -0700177 }
178 }
179 });
180
Dan Morrille4d9a012013-03-28 18:10:43 -0700181 // bootstrap services
Jeff Brownbd6e1502012-08-28 03:27:37 -0700182 boolean onlyCore = false;
Dan Morrille4d9a012013-03-28 18:10:43 -0700183 boolean firstBoot = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800184 try {
Jeff Brownf69c8122012-09-12 17:00:34 -0700185 // Wait for installd to finished starting up so that it has a chance to
186 // create critical directories such as /data/user with the appropriate
187 // permissions. We need this to complete before we initialize other services.
188 Slog.i(TAG, "Waiting for installd to be ready.");
189 installer = new Installer();
190 installer.ping();
191
Joe Onorato8a9b2202010-02-26 18:56:32 -0800192 Slog.i(TAG, "Power Manager");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800193 power = new PowerManagerService();
194 ServiceManager.addService(Context.POWER_SERVICE, power);
195
Joe Onorato8a9b2202010-02-26 18:56:32 -0800196 Slog.i(TAG, "Activity Manager");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800197 context = ActivityManagerService.main(factoryTest);
Dan Morrille4d9a012013-03-28 18:10:43 -0700198 } catch (RuntimeException e) {
199 Slog.e("System", "******************************************");
200 Slog.e("System", "************ Failure starting bootstrap service", e);
201 }
Jeff Brown848c2dc2012-08-19 20:18:08 -0700202
Dan Morrille4d9a012013-03-28 18:10:43 -0700203 boolean disableStorage = SystemProperties.getBoolean("config.disable_storage", false);
204 boolean disableMedia = SystemProperties.getBoolean("config.disable_media", false);
205 boolean disableBluetooth = SystemProperties.getBoolean("config.disable_bluetooth", false);
206 boolean disableTelephony = SystemProperties.getBoolean("config.disable_telephony", false);
207 boolean disableLocation = SystemProperties.getBoolean("config.disable_location", false);
208 boolean disableSystemUI = SystemProperties.getBoolean("config.disable_systemui", false);
209 boolean disableNonCoreServices = SystemProperties.getBoolean("config.disable_noncore", false);
210 boolean disableNetwork = SystemProperties.getBoolean("config.disable_network", false);
211
212 try {
Jeff Brown848c2dc2012-08-19 20:18:08 -0700213 Slog.i(TAG, "Display Manager");
Dianne Hackborn8d044e82013-04-30 17:24:15 -0700214 display = new DisplayManagerService(context, wmHandler);
Jeff Brown848c2dc2012-08-19 20:18:08 -0700215 ServiceManager.addService(Context.DISPLAY_SERVICE, display, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800216
Joe Onorato8a9b2202010-02-26 18:56:32 -0800217 Slog.i(TAG, "Telephony Registry");
Wink Savillea12a7b32012-09-20 10:09:45 -0700218 telephonyRegistry = new TelephonyRegistry(context);
219 ServiceManager.addService("telephony.registry", telephonyRegistry);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800220
Glenn Kasten07b04652012-04-23 15:00:43 -0700221 Slog.i(TAG, "Scheduling Policy");
Dianne Hackborn35f72be2013-09-16 10:57:39 -0700222 ServiceManager.addService("scheduling_policy", new SchedulingPolicyService());
Glenn Kasten07b04652012-04-23 15:00:43 -0700223
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800224 AttributeCache.init(context);
225
Jeff Brownbd6e1502012-08-28 03:27:37 -0700226 if (!display.waitForDefaultDisplay()) {
227 reportWtf("Timeout waiting for default display to be initialized.",
228 new Throwable());
229 }
230
Joe Onorato8a9b2202010-02-26 18:56:32 -0800231 Slog.i(TAG, "Package Manager");
Ben Komalo553acf02011-09-19 14:25:28 -0700232 // Only run "core" apps if we're encrypting the device.
233 String cryptState = SystemProperties.get("vold.decrypt");
Ben Komalo3573d402011-09-23 15:08:24 -0700234 if (ENCRYPTING_STATE.equals(cryptState)) {
Ben Komalo553acf02011-09-19 14:25:28 -0700235 Slog.w(TAG, "Detected encryption in progress - only parsing core apps");
Ben Komalo3573d402011-09-23 15:08:24 -0700236 onlyCore = true;
237 } else if (ENCRYPTED_STATE.equals(cryptState)) {
238 Slog.w(TAG, "Device encrypted - only parsing core apps");
239 onlyCore = true;
Ben Komalo553acf02011-09-19 14:25:28 -0700240 }
Ben Komalo3573d402011-09-23 15:08:24 -0700241
Jeff Brownf69c8122012-09-12 17:00:34 -0700242 pm = PackageManagerService.main(context, installer,
Dianne Hackbornd2509fd2011-09-12 12:29:43 -0700243 factoryTest != SystemServer.FACTORY_TEST_OFF,
Ben Komalo553acf02011-09-19 14:25:28 -0700244 onlyCore);
Dianne Hackborn58f42a52011-10-10 13:46:34 -0700245 try {
246 firstBoot = pm.isFirstBoot();
247 } catch (RemoteException e) {
248 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800249
250 ActivityManagerService.setSystemProcess();
Svetoslavb3038ec2013-02-13 14:39:30 -0800251
Nick Kralevich79619dd2013-03-04 13:05:32 -0800252 Slog.i(TAG, "Entropy Mixer");
253 ServiceManager.addService("entropy", new EntropyMixer(context));
254
Amith Yamasani258848d2012-08-10 17:06:33 -0700255 Slog.i(TAG, "User Service");
256 ServiceManager.addService(Context.USER_SERVICE,
Dianne Hackborn4428e17c2012-08-24 17:43:05 -0700257 UserManagerService.getInstance());
Amith Yamasani258848d2012-08-10 17:06:33 -0700258
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800259 mContentResolver = context.getContentResolver();
260
Fred Quintanae91ebe22009-09-29 20:44:30 -0700261 // The AccountManager must come before the ContentService
Fred Quintana60307342009-03-24 22:48:12 -0700262 try {
Dan Morrille4d9a012013-03-28 18:10:43 -0700263 // TODO: seems like this should be disable-able, but req'd by ContentService
Joe Onorato8a9b2202010-02-26 18:56:32 -0800264 Slog.i(TAG, "Account Manager");
Kenny Root26ff6622012-07-30 12:58:03 -0700265 accountManager = new AccountManagerService(context);
266 ServiceManager.addService(Context.ACCOUNT_SERVICE, accountManager);
Fred Quintana60307342009-03-24 22:48:12 -0700267 } catch (Throwable e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800268 Slog.e(TAG, "Failure starting Account Manager", e);
Fred Quintana60307342009-03-24 22:48:12 -0700269 }
270
Joe Onorato8a9b2202010-02-26 18:56:32 -0800271 Slog.i(TAG, "Content Manager");
Kenny Root26ff6622012-07-30 12:58:03 -0700272 contentService = ContentService.main(context,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800273 factoryTest == SystemServer.FACTORY_TEST_LOW_LEVEL);
274
Joe Onorato8a9b2202010-02-26 18:56:32 -0800275 Slog.i(TAG, "System Content Providers");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800276 ActivityManagerService.installSystemProviders();
277
Joe Onorato8a9b2202010-02-26 18:56:32 -0800278 Slog.i(TAG, "Lights Service");
Mike Lockwood3a322132009-11-24 00:30:52 -0500279 lights = new LightsService(context);
280
Joe Onoratode1b3592010-10-25 20:36:47 -0700281 Slog.i(TAG, "Battery Service");
282 battery = new BatteryService(context, lights);
283 ServiceManager.addService("battery", battery);
284
Joe Onorato8a9b2202010-02-26 18:56:32 -0800285 Slog.i(TAG, "Vibrator Service");
Jeff Brown7f6c2312012-04-13 20:38:38 -0700286 vibrator = new VibratorService(context);
287 ServiceManager.addService("vibrator", vibrator);
The Android Open Source Project10592532009-03-18 17:39:46 -0700288
Erik Gilling51e95df2013-06-26 11:06:51 -0700289 Slog.i(TAG, "Consumer IR Service");
290 consumerIr = new ConsumerIrService(context);
291 ServiceManager.addService(Context.CONSUMER_IR_SERVICE, consumerIr);
292
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800293 // only initialize the power service after we have started the
Mike Lockwood3a322132009-11-24 00:30:52 -0500294 // lights service, content providers and the battery service.
Jeff Brown96307042012-07-27 15:51:34 -0700295 power.init(context, lights, ActivityManagerService.self(), battery,
Dianne Hackborn713df152013-05-17 11:27:57 -0700296 BatteryStatsService.getService(),
297 ActivityManagerService.self().getAppOpsService(), display);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800298
Joe Onorato8a9b2202010-02-26 18:56:32 -0800299 Slog.i(TAG, "Alarm Manager");
Jeff Sharkey75279902011-05-24 18:39:45 -0700300 alarm = new AlarmManagerService(context);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800301 ServiceManager.addService(Context.ALARM_SERVICE, alarm);
302
Joe Onorato8a9b2202010-02-26 18:56:32 -0800303 Slog.i(TAG, "Init Watchdog");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800304 Watchdog.getInstance().init(context, battery, power, alarm,
305 ActivityManagerService.self());
Dianne Hackborn8d044e82013-04-30 17:24:15 -0700306 Watchdog.getInstance().addThread(wmHandler, "WindowManager thread");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800307
Jeff Browna9d131c2012-09-20 16:48:17 -0700308 Slog.i(TAG, "Input Manager");
309 inputManager = new InputManagerService(context, wmHandler);
310
Joe Onorato8a9b2202010-02-26 18:56:32 -0800311 Slog.i(TAG, "Window Manager");
Jeff Browna9d131c2012-09-20 16:48:17 -0700312 wm = WindowManagerService.main(context, power, display, inputManager,
Dianne Hackborn8d044e82013-04-30 17:24:15 -0700313 wmHandler, factoryTest != SystemServer.FACTORY_TEST_LOW_LEVEL,
Jeff Brown780c46f2012-06-24 12:15:38 -0700314 !firstBoot, onlyCore);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800315 ServiceManager.addService(Context.WINDOW_SERVICE, wm);
Jeff Brown6ec6f792012-04-17 16:52:41 -0700316 ServiceManager.addService(Context.INPUT_SERVICE, inputManager);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800317
Dianne Hackborn295e3c22011-08-25 13:19:08 -0700318 ActivityManagerService.self().setWindowManager(wm);
Jeff Browna9d131c2012-09-20 16:48:17 -0700319
320 inputManager.setWindowManagerCallbacks(wm.getInputMonitor());
321 inputManager.start();
322
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700323 display.setWindowManager(wm);
Jeff Brownd728bf52012-09-08 18:05:28 -0700324 display.setInputManager(inputManager);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800325
326 // Skip Bluetooth if we have an emulator kernel
327 // TODO: Use a more reliable check to see if this product should
328 // support Bluetooth - see bug 988521
329 if (SystemProperties.get("ro.kernel.qemu").equals("1")) {
David 'Digit' Turnere2a5e862011-01-17 00:32:33 +0100330 Slog.i(TAG, "No Bluetooh Service (emulator)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800331 } else if (factoryTest == SystemServer.FACTORY_TEST_LOW_LEVEL) {
David 'Digit' Turnere2a5e862011-01-17 00:32:33 +0100332 Slog.i(TAG, "No Bluetooth Service (factory test)");
Matthew Xie1dd01eb32013-04-26 12:37:54 -0700333 } else if (!context.getPackageManager().hasSystemFeature
334 (PackageManager.FEATURE_BLUETOOTH)) {
335 Slog.i(TAG, "No Bluetooth Service (Bluetooth Hardware Not Present)");
Dan Morrille4d9a012013-03-28 18:10:43 -0700336 } else if (disableBluetooth) {
337 Slog.i(TAG, "Bluetooth Service disabled by config");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800338 } else {
fredc0f420372012-04-12 00:02:00 -0700339 Slog.i(TAG, "Bluetooth Manager Service");
340 bluetooth = new BluetoothManagerService(context);
341 ServiceManager.addService(BluetoothAdapter.BLUETOOTH_MANAGER_SERVICE, bluetooth);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800342 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800343 } catch (RuntimeException e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700344 Slog.e("System", "******************************************");
345 Slog.e("System", "************ Failure starting core service", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800346 }
347
Dianne Hackbornd6847842010-01-12 18:14:19 -0800348 DevicePolicyManagerService devicePolicy = null;
Joe Onorato089de882010-04-12 08:18:45 -0700349 StatusBarManagerService statusBar = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800350 InputMethodManagerService imm = null;
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700351 AppWidgetService appWidget = null;
Joe Onorato30275482009-07-08 17:09:14 -0700352 NotificationManagerService notification = null;
Dianne Hackbornf21adf62009-08-13 10:20:21 -0700353 WallpaperManagerService wallpaper = null;
Mike Lockwood46db5042010-02-22 16:36:44 -0500354 LocationManagerService location = null;
Bai Taoa58a8752010-07-13 15:32:16 +0800355 CountryDetectorService countryDetector = null;
satok988323c2011-06-22 16:38:13 +0900356 TextServicesManagerService tsms = null;
Amith Yamasani52c489c2012-03-28 11:42:42 -0700357 LockSettingsService lockSettings = null;
Daniel Sandler7d276c32012-01-30 14:33:52 -0500358 DreamManagerService dreamy = null;
Romain Guy3b748a42013-04-17 18:54:38 -0700359 AssetAtlasService atlas = null;
Svetoslav Ganova0027152013-06-25 14:59:53 -0700360 PrintManagerService printManager = null;
Jeff Brown69b07162013-11-07 00:30:16 -0800361 MediaRouterService mediaRouter = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800362
Dianne Hackborn661cd522011-08-22 00:26:20 -0700363 // Bring up services needed for UI.
364 if (factoryTest != SystemServer.FACTORY_TEST_LOW_LEVEL) {
Dan Morrille4d9a012013-03-28 18:10:43 -0700365 //if (!disableNonCoreServices) { // TODO: View depends on these; mock them?
366 if (true) {
367 try {
368 Slog.i(TAG, "Input Method Service");
369 imm = new InputMethodManagerService(context, wm);
370 ServiceManager.addService(Context.INPUT_METHOD_SERVICE, imm);
371 } catch (Throwable e) {
372 reportWtf("starting Input Manager Service", e);
373 }
Dianne Hackborn661cd522011-08-22 00:26:20 -0700374
Dan Morrille4d9a012013-03-28 18:10:43 -0700375 try {
376 Slog.i(TAG, "Accessibility Manager");
377 ServiceManager.addService(Context.ACCESSIBILITY_SERVICE,
378 new AccessibilityManagerService(context));
379 } catch (Throwable e) {
380 reportWtf("starting Accessibility Manager", e);
381 }
Dianne Hackborn661cd522011-08-22 00:26:20 -0700382 }
383 }
384
385 try {
386 wm.displayReady();
387 } catch (Throwable e) {
388 reportWtf("making display ready", e);
389 }
Dianne Hackborn8795b602011-08-25 13:30:53 -0700390
Dianne Hackborn295e3c22011-08-25 13:19:08 -0700391 try {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700392 pm.performBootDexOpt();
393 } catch (Throwable e) {
394 reportWtf("performing boot dexopt", e);
395 }
396
397 try {
398 ActivityManagerNative.getDefault().showBootMessage(
399 context.getResources().getText(
400 com.android.internal.R.string.android_upgrading_starting_apps),
401 false);
402 } catch (RemoteException e) {
403 }
404
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800405 if (factoryTest != SystemServer.FACTORY_TEST_LOW_LEVEL) {
Dan Morrille4d9a012013-03-28 18:10:43 -0700406 if (!disableStorage &&
407 !"0".equals(SystemProperties.get("system_init.startmountservice"))) {
Kenny Root51a573c2012-05-17 13:30:28 -0700408 try {
409 /*
410 * NotificationManagerService is dependant on MountService,
411 * (for media / usb notifications) so we must start MountService first.
412 */
413 Slog.i(TAG, "Mount Service");
414 mountService = new MountService(context);
415 ServiceManager.addService("mount", mountService);
416 } catch (Throwable e) {
417 reportWtf("starting Mount Service", e);
418 }
419 }
420
Dan Morrille4d9a012013-03-28 18:10:43 -0700421 if (!disableNonCoreServices) {
422 try {
423 Slog.i(TAG, "LockSettingsService");
424 lockSettings = new LockSettingsService(context);
425 ServiceManager.addService("lock_settings", lockSettings);
426 } catch (Throwable e) {
427 reportWtf("starting LockSettingsService service", e);
428 }
429
430 try {
431 Slog.i(TAG, "Device Policy");
432 devicePolicy = new DevicePolicyManagerService(context);
433 ServiceManager.addService(Context.DEVICE_POLICY_SERVICE, devicePolicy);
434 } catch (Throwable e) {
435 reportWtf("starting DevicePolicyService", e);
436 }
Amith Yamasani52c489c2012-03-28 11:42:42 -0700437 }
438
Dan Morrille4d9a012013-03-28 18:10:43 -0700439 if (!disableSystemUI) {
440 try {
441 Slog.i(TAG, "Status Bar");
442 statusBar = new StatusBarManagerService(context, wm);
443 ServiceManager.addService(Context.STATUS_BAR_SERVICE, statusBar);
444 } catch (Throwable e) {
445 reportWtf("starting StatusBarManagerService", e);
446 }
Dianne Hackbornd6847842010-01-12 18:14:19 -0800447 }
448
Dan Morrille4d9a012013-03-28 18:10:43 -0700449 if (!disableNonCoreServices) {
450 try {
451 Slog.i(TAG, "Clipboard Service");
452 ServiceManager.addService(Context.CLIPBOARD_SERVICE,
453 new ClipboardService(context));
454 } catch (Throwable e) {
455 reportWtf("starting Clipboard Service", e);
456 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800457 }
458
Dan Morrille4d9a012013-03-28 18:10:43 -0700459 if (!disableNetwork) {
460 try {
461 Slog.i(TAG, "NetworkManagement Service");
462 networkManagement = NetworkManagementService.create(context);
463 ServiceManager.addService(Context.NETWORKMANAGEMENT_SERVICE, networkManagement);
464 } catch (Throwable e) {
465 reportWtf("starting NetworkManagement Service", e);
466 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800467 }
468
Dan Morrille4d9a012013-03-28 18:10:43 -0700469 if (!disableNonCoreServices) {
470 try {
471 Slog.i(TAG, "Text Service Manager Service");
472 tsms = new TextServicesManagerService(context);
473 ServiceManager.addService(Context.TEXT_SERVICES_MANAGER_SERVICE, tsms);
474 } catch (Throwable e) {
475 reportWtf("starting Text Service Manager Service", e);
476 }
San Mehatd1df8ac2010-01-26 06:17:26 -0800477 }
478
Dan Morrille4d9a012013-03-28 18:10:43 -0700479 if (!disableNetwork) {
480 try {
481 Slog.i(TAG, "NetworkStats Service");
482 networkStats = new NetworkStatsService(context, networkManagement, alarm);
483 ServiceManager.addService(Context.NETWORK_STATS_SERVICE, networkStats);
484 } catch (Throwable e) {
485 reportWtf("starting NetworkStats Service", e);
486 }
487
488 try {
489 Slog.i(TAG, "NetworkPolicy Service");
490 networkPolicy = new NetworkPolicyManagerService(
491 context, ActivityManagerService.self(), power,
492 networkStats, networkManagement);
493 ServiceManager.addService(Context.NETWORK_POLICY_SERVICE, networkPolicy);
494 } catch (Throwable e) {
495 reportWtf("starting NetworkPolicy Service", e);
496 }
497
498 try {
499 Slog.i(TAG, "Wi-Fi P2pService");
500 wifiP2p = new WifiP2pService(context);
501 ServiceManager.addService(Context.WIFI_P2P_SERVICE, wifiP2p);
502 } catch (Throwable e) {
503 reportWtf("starting Wi-Fi P2pService", e);
504 }
505
506 try {
507 Slog.i(TAG, "Wi-Fi Service");
508 wifi = new WifiService(context);
509 ServiceManager.addService(Context.WIFI_SERVICE, wifi);
510 } catch (Throwable e) {
511 reportWtf("starting Wi-Fi Service", e);
512 }
513
514 try {
515 Slog.i(TAG, "Connectivity Service");
516 connectivity = new ConnectivityService(
517 context, networkManagement, networkStats, networkPolicy);
518 ServiceManager.addService(Context.CONNECTIVITY_SERVICE, connectivity);
519 networkStats.bindConnectivityManager(connectivity);
520 networkPolicy.bindConnectivityManager(connectivity);
Vinit Deshapnde04675f62013-10-03 16:18:56 -0700521
Dan Morrille4d9a012013-03-28 18:10:43 -0700522 wifiP2p.connectivityServiceReady();
Vinit Deshapnde04675f62013-10-03 16:18:56 -0700523 wifi.checkAndStartWifi();
Dan Morrille4d9a012013-03-28 18:10:43 -0700524 } catch (Throwable e) {
525 reportWtf("starting Connectivity Service", e);
526 }
527
528 try {
529 Slog.i(TAG, "Network Service Discovery Service");
530 serviceDiscovery = NsdService.create(context);
531 ServiceManager.addService(
532 Context.NSD_SERVICE, serviceDiscovery);
533 } catch (Throwable e) {
534 reportWtf("starting Service Discovery Service", e);
535 }
satok988323c2011-06-22 16:38:13 +0900536 }
537
Dan Morrille4d9a012013-03-28 18:10:43 -0700538 if (!disableNonCoreServices) {
539 try {
540 Slog.i(TAG, "UpdateLock Service");
541 ServiceManager.addService(Context.UPDATE_LOCK_SERVICE,
542 new UpdateLockService(context));
543 } catch (Throwable e) {
544 reportWtf("starting UpdateLockService", e);
545 }
Christopher Tate8662cab52012-02-23 14:59:36 -0800546 }
547
Kenny Root51a573c2012-05-17 13:30:28 -0700548 /*
549 * MountService has a few dependencies: Notification Manager and
550 * AppWidget Provider. Make sure MountService is completely started
551 * first before continuing.
552 */
Ken Sumrall025adc42013-06-05 22:08:12 -0700553 if (mountService != null && !onlyCore) {
Kenny Root51a573c2012-05-17 13:30:28 -0700554 mountService.waitForAsecScan();
San Mehat1bf3f8b2010-02-03 14:43:09 -0800555 }
556
557 try {
Kenny Root26ff6622012-07-30 12:58:03 -0700558 if (accountManager != null)
559 accountManager.systemReady();
560 } catch (Throwable e) {
561 reportWtf("making Account Manager Service ready", e);
562 }
563
564 try {
565 if (contentService != null)
566 contentService.systemReady();
567 } catch (Throwable e) {
568 reportWtf("making Content Service ready", e);
569 }
570
571 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800572 Slog.i(TAG, "Notification Manager");
Mike Lockwood3a322132009-11-24 00:30:52 -0500573 notification = new NotificationManagerService(context, statusBar, lights);
Joe Onorato30275482009-07-08 17:09:14 -0700574 ServiceManager.addService(Context.NOTIFICATION_SERVICE, notification);
Jeff Sharkey497e4432011-06-14 17:27:29 -0700575 networkPolicy.bindNotificationManager(notification);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800576 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700577 reportWtf("starting Notification Manager", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800578 }
579
580 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800581 Slog.i(TAG, "Device Storage Monitor");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800582 ServiceManager.addService(DeviceStorageMonitorService.SERVICE,
583 new DeviceStorageMonitorService(context));
584 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700585 reportWtf("starting DeviceStorageMonitor service", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800586 }
587
Dan Morrille4d9a012013-03-28 18:10:43 -0700588 if (!disableLocation) {
589 try {
590 Slog.i(TAG, "Location Manager");
591 location = new LocationManagerService(context);
592 ServiceManager.addService(Context.LOCATION_SERVICE, location);
593 } catch (Throwable e) {
594 reportWtf("starting Location Manager", e);
595 }
596
597 try {
598 Slog.i(TAG, "Country Detector");
599 countryDetector = new CountryDetectorService(context);
600 ServiceManager.addService(Context.COUNTRY_DETECTOR, countryDetector);
601 } catch (Throwable e) {
602 reportWtf("starting Country Detector", e);
603 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800604 }
605
Dan Morrille4d9a012013-03-28 18:10:43 -0700606 if (!disableNonCoreServices) {
607 try {
608 Slog.i(TAG, "Search Service");
609 ServiceManager.addService(Context.SEARCH_SERVICE,
610 new SearchManagerService(context));
611 } catch (Throwable e) {
612 reportWtf("starting Search Service", e);
613 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800614 }
615
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800616 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800617 Slog.i(TAG, "DropBox Service");
Dan Egnor95240272009-10-27 18:23:39 -0700618 ServiceManager.addService(Context.DROPBOX_SERVICE,
Dan Egnorf18a01c2009-11-12 11:32:50 -0800619 new DropBoxManagerService(context, new File("/data/system/dropbox")));
Dan Egnor4410ec82009-09-11 16:40:01 -0700620 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700621 reportWtf("starting DropBoxManagerService", e);
Dan Egnor4410ec82009-09-11 16:40:01 -0700622 }
623
Dan Morrille4d9a012013-03-28 18:10:43 -0700624 if (!disableNonCoreServices && context.getResources().getBoolean(
625 R.bool.config_enableWallpaperService)) {
Mike Lockwoodc067c9c2011-10-31 12:50:12 -0400626 try {
627 Slog.i(TAG, "Wallpaper Service");
628 if (!headless) {
629 wallpaper = new WallpaperManagerService(context);
630 ServiceManager.addService(Context.WALLPAPER_SERVICE, wallpaper);
631 }
632 } 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
687 try {
Jeff Brown2416e092012-08-21 22:12:20 -0700688 Slog.i(TAG, "Twilight Service");
689 twilight = new TwilightService(context);
690 } catch (Throwable e) {
691 reportWtf("starting TwilightService", e);
692 }
693
694 try {
Dianne Hackborn7299c412010-03-04 18:41:49 -0800695 Slog.i(TAG, "UI Mode Manager Service");
Mike Lockwood57c798a2010-06-23 17:36:36 -0400696 // Listen for UI mode changes
Jeff Brown2416e092012-08-21 22:12:20 -0700697 uiMode = new UiModeManagerService(context, twilight);
Dianne Hackborn7299c412010-03-04 18:41:49 -0800698 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700699 reportWtf("starting UiModeManagerService", e);
Dianne Hackborn7299c412010-03-04 18:41:49 -0800700 }
701
Dan Morrille4d9a012013-03-28 18:10:43 -0700702 if (!disableNonCoreServices) {
703 try {
704 Slog.i(TAG, "Backup Service");
705 ServiceManager.addService(Context.BACKUP_SERVICE,
706 new BackupManagerService(context));
707 } catch (Throwable e) {
708 Slog.e(TAG, "Failure starting Backup Service", e);
709 }
Christopher Tate487529a2009-04-29 14:03:25 -0700710
Dan Morrille4d9a012013-03-28 18:10:43 -0700711 try {
712 Slog.i(TAG, "AppWidget Service");
713 appWidget = new AppWidgetService(context);
714 ServiceManager.addService(Context.APPWIDGET_SERVICE, appWidget);
715 } catch (Throwable e) {
716 reportWtf("starting AppWidget Service", e);
717 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800718
Dan Morrille4d9a012013-03-28 18:10:43 -0700719 try {
720 Slog.i(TAG, "Recognition Service");
721 recognition = new RecognitionManagerService(context);
722 } catch (Throwable e) {
723 reportWtf("starting Recognition Service", e);
724 }
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800725 }
Jaikumar Ganesh7d0548d2010-10-18 15:29:09 -0700726
Nick Pelly038cabe2010-09-23 16:12:11 -0700727 try {
Dan Egnor621bc542010-03-25 16:20:14 -0700728 Slog.i(TAG, "DiskStats Service");
729 ServiceManager.addService("diskstats", new DiskStatsService(context));
730 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700731 reportWtf("starting DiskStats Service", e);
Dan Egnor621bc542010-03-25 16:20:14 -0700732 }
Sen Hubde75702010-05-28 01:54:03 -0700733
734 try {
735 // need to add this service even if SamplingProfilerIntegration.isEnabled()
736 // is false, because it is this service that detects system property change and
737 // turns on SamplingProfilerIntegration. Plus, when sampling profiler doesn't work,
738 // there is little overhead for running this service.
739 Slog.i(TAG, "SamplingProfiler Service");
740 ServiceManager.addService("samplingprofiler",
741 new SamplingProfilerService(context));
742 } catch (Throwable e) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700743 reportWtf("starting SamplingProfiler Service", e);
Sen Hubde75702010-05-28 01:54:03 -0700744 }
Chung-yih Wang024d5962010-08-06 12:06:04 +0800745
Dan Morrille4d9a012013-03-28 18:10:43 -0700746 if (!disableNetwork) {
747 try {
748 Slog.i(TAG, "NetworkTimeUpdateService");
749 networkTimeUpdater = new NetworkTimeUpdateService(context);
750 } catch (Throwable e) {
751 reportWtf("starting NetworkTimeUpdate service", e);
752 }
Amith Yamasani6734b9f62010-09-13 16:24:08 -0700753 }
John Grossmanc1576732012-02-01 15:23:33 -0800754
Dan Morrille4d9a012013-03-28 18:10:43 -0700755 if (!disableMedia) {
756 try {
757 Slog.i(TAG, "CommonTimeManagementService");
758 commonTimeMgmtService = new CommonTimeManagementService(context);
759 ServiceManager.addService("commontime_management", commonTimeMgmtService);
760 } catch (Throwable e) {
761 reportWtf("starting CommonTimeManagementService service", e);
762 }
John Grossmanc1576732012-02-01 15:23:33 -0800763 }
Geremy Condra3d33c262012-05-06 18:32:19 -0700764
Dan Morrille4d9a012013-03-28 18:10:43 -0700765 if (!disableNetwork) {
766 try {
767 Slog.i(TAG, "CertBlacklister");
768 CertBlacklister blacklister = new CertBlacklister(context);
769 } catch (Throwable e) {
770 reportWtf("starting CertBlacklister", e);
771 }
Geremy Condra3d33c262012-05-06 18:32:19 -0700772 }
Jim Miller5ecd8112013-01-09 18:50:26 -0800773
Dan Morrille4d9a012013-03-28 18:10:43 -0700774 if (!disableNonCoreServices &&
775 context.getResources().getBoolean(R.bool.config_dreamsSupported)) {
Daniel Sandler7d276c32012-01-30 14:33:52 -0500776 try {
777 Slog.i(TAG, "Dreams Service");
778 // Dreams (interactive idle-time views, a/k/a screen savers)
Jeff Brown62c82e42012-09-26 01:30:41 -0700779 dreamy = new DreamManagerService(context, wmHandler);
Dianne Hackbornbe87e2f2012-09-28 16:31:34 -0700780 ServiceManager.addService(DreamService.DREAM_SERVICE, dreamy);
Daniel Sandler7d276c32012-01-30 14:33:52 -0500781 } catch (Throwable e) {
782 reportWtf("starting DreamManagerService", e);
783 }
784 }
Svetoslavb3038ec2013-02-13 14:39:30 -0800785
Romain Guy3b748a42013-04-17 18:54:38 -0700786 if (!disableNonCoreServices) {
787 try {
788 Slog.i(TAG, "Assets Atlas Service");
789 atlas = new AssetAtlasService(context);
790 ServiceManager.addService(AssetAtlasService.ASSET_ATLAS_SERVICE, atlas);
791 } catch (Throwable e) {
792 reportWtf("starting AssetAtlasService", e);
793 }
794 }
795
Svetoslavb3038ec2013-02-13 14:39:30 -0800796 try {
797 Slog.i(TAG, "IdleMaintenanceService");
Svetoslav6a08a122013-05-03 11:24:26 -0700798 new IdleMaintenanceService(context, battery);
Svetoslavb3038ec2013-02-13 14:39:30 -0800799 } catch (Throwable e) {
800 reportWtf("starting IdleMaintenanceService", e);
801 }
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -0700802
803 try {
804 Slog.i(TAG, "Print Service");
Svetoslav Ganova0027152013-06-25 14:59:53 -0700805 printManager = new PrintManagerService(context);
806 ServiceManager.addService(Context.PRINT_SERVICE, printManager);
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -0700807 } catch (Throwable e) {
808 reportWtf("starting Print Service", e);
809 }
Jeff Brown69b07162013-11-07 00:30:16 -0800810
811 if (!disableNonCoreServices) {
812 try {
813 Slog.i(TAG, "Media Router Service");
814 mediaRouter = new MediaRouterService(context);
815 ServiceManager.addService(Context.MEDIA_ROUTER_SERVICE, mediaRouter);
816 } catch (Throwable e) {
817 reportWtf("starting MediaRouterService", e);
818 }
Brian Carlstrom7395a8a2014-04-28 22:11:01 -0700819
820 try {
821 Slog.i(TAG, "BackgroundDexOptService");
822 new BackgroundDexOptService(context);
823 } catch (Throwable e) {
824 reportWtf("starting BackgroundDexOptService", e);
825 }
Jeff Brown69b07162013-11-07 00:30:16 -0800826 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800827 }
828
Dianne Hackborn6af0d502009-09-28 13:25:46 -0700829 // Before things start rolling, be sure we have decided whether
830 // we are in safe mode.
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700831 final boolean safeMode = wm.detectSafeMode();
Dianne Hackborn6af0d502009-09-28 13:25:46 -0700832 if (safeMode) {
Jeff Brownb09abc12011-01-13 21:08:27 -0800833 ActivityManagerService.self().enterSafeMode();
834 // Post the safe mode state in the Zygote class
Narayan Kamathd1a8d9f2014-03-28 13:10:41 +0000835 SystemServer.inSafeMode = true;
Jeff Brownb09abc12011-01-13 21:08:27 -0800836 // Disable the JIT for the system_server process
837 VMRuntime.getRuntime().disableJitCompilation();
Ben Cheng6c0afff2010-02-14 16:18:56 -0800838 } else {
839 // Enable the JIT for the system_server process
840 VMRuntime.getRuntime().startJitCompilation();
Dianne Hackborn6af0d502009-09-28 13:25:46 -0700841 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800842
Dianne Hackborn6af0d502009-09-28 13:25:46 -0700843 // It is now time to start up the app processes...
Joe Onorato30275482009-07-08 17:09:14 -0700844
Jeff Brown7f6c2312012-04-13 20:38:38 -0700845 try {
846 vibrator.systemReady();
847 } catch (Throwable e) {
848 reportWtf("making Vibrator Service ready", e);
849 }
850
Dan Morrille4d9a012013-03-28 18:10:43 -0700851 if (lockSettings != null) {
852 try {
853 lockSettings.systemReady();
854 } catch (Throwable e) {
855 reportWtf("making Lock Settings Service ready", e);
856 }
Felipe Ramosf35df5b2012-09-18 18:26:27 -0300857 }
858
Dianne Hackbornd6847842010-01-12 18:14:19 -0800859 if (devicePolicy != null) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700860 try {
861 devicePolicy.systemReady();
862 } catch (Throwable e) {
863 reportWtf("making Device Policy Service ready", e);
864 }
Dianne Hackbornd6847842010-01-12 18:14:19 -0800865 }
866
Joe Onorato30275482009-07-08 17:09:14 -0700867 if (notification != null) {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700868 try {
869 notification.systemReady();
870 } catch (Throwable e) {
871 reportWtf("making Notification Service ready", e);
872 }
Joe Onorato30275482009-07-08 17:09:14 -0700873 }
874
Dianne Hackborn661cd522011-08-22 00:26:20 -0700875 try {
876 wm.systemReady();
877 } catch (Throwable e) {
878 reportWtf("making Window Manager Service ready", e);
879 }
Joe Onoratodc565f42010-10-04 15:27:22 -0400880
Jeff Brownb09abc12011-01-13 21:08:27 -0800881 if (safeMode) {
882 ActivityManagerService.self().showSafeModeOverlay();
883 }
884
Joe Onoratodc565f42010-10-04 15:27:22 -0400885 // Update the configuration for this context by hand, because we're going
886 // to start using it before the config change done in wm.systemReady() will
887 // propagate to it.
888 Configuration config = wm.computeNewConfiguration();
889 DisplayMetrics metrics = new DisplayMetrics();
890 WindowManager w = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
891 w.getDefaultDisplay().getMetrics(metrics);
892 context.getResources().updateConfiguration(config, metrics);
893
Jeff Brownaa202a62012-08-21 22:14:26 -0700894 try {
Jeff Brown62c82e42012-09-26 01:30:41 -0700895 power.systemReady(twilight, dreamy);
Jeff Brownaa202a62012-08-21 22:14:26 -0700896 } catch (Throwable e) {
897 reportWtf("making Power Manager Service ready", e);
898 }
899
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800900 try {
901 pm.systemReady();
Dianne Hackborn661cd522011-08-22 00:26:20 -0700902 } catch (Throwable e) {
903 reportWtf("making Package Manager Service ready", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800904 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800905
Jeff Brownbd6e1502012-08-28 03:27:37 -0700906 try {
907 display.systemReady(safeMode, onlyCore);
908 } catch (Throwable e) {
909 reportWtf("making Display Manager Service ready", e);
910 }
911
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700912 // These are needed to propagate to the runnable below.
Joe Onoratof3c3c4f2010-10-21 11:09:02 -0400913 final Context contextF = context;
Jeff Sharkeyb049e2122012-09-07 23:16:01 -0700914 final MountService mountServiceF = mountService;
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700915 final BatteryService batteryF = battery;
Jeff Sharkey350083e2011-06-29 10:45:16 -0700916 final NetworkManagementService networkManagementF = networkManagement;
Jeff Sharkey75279902011-05-24 18:39:45 -0700917 final NetworkStatsService networkStatsF = networkStats;
Jeff Sharkeya4620792011-05-20 15:29:23 -0700918 final NetworkPolicyManagerService networkPolicyF = networkPolicy;
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700919 final ConnectivityService connectivityF = connectivity;
920 final DockObserver dockF = dock;
Mike Lockwood770126a2010-12-09 22:30:37 -0800921 final UsbService usbF = usb;
Jeff Brown2416e092012-08-21 22:12:20 -0700922 final TwilightService twilightF = twilight;
Dianne Hackborn7299c412010-03-04 18:41:49 -0800923 final UiModeManagerService uiModeF = uiMode;
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700924 final AppWidgetService appWidgetF = appWidget;
925 final WallpaperManagerService wallpaperF = wallpaper;
926 final InputMethodManagerService immF = imm;
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800927 final RecognitionManagerService recognitionF = recognition;
Mike Lockwood46db5042010-02-22 16:36:44 -0500928 final LocationManagerService locationF = location;
Bai Taoa58a8752010-07-13 15:32:16 +0800929 final CountryDetectorService countryDetectorF = countryDetector;
Amith Yamasani6734b9f62010-09-13 16:24:08 -0700930 final NetworkTimeUpdateService networkTimeUpdaterF = networkTimeUpdater;
John Grossmanc1576732012-02-01 15:23:33 -0800931 final CommonTimeManagementService commonTimeMgmtServiceF = commonTimeMgmtService;
satok988323c2011-06-22 16:38:13 +0900932 final TextServicesManagerService textServiceManagerServiceF = tsms;
Dianne Hackborn661cd522011-08-22 00:26:20 -0700933 final StatusBarManagerService statusBarF = statusBar;
Daniel Sandler7d276c32012-01-30 14:33:52 -0500934 final DreamManagerService dreamyF = dreamy;
Romain Guy3b748a42013-04-17 18:54:38 -0700935 final AssetAtlasService atlasF = atlas;
Jeff Brown6ec6f792012-04-17 16:52:41 -0700936 final InputManagerService inputManagerF = inputManager;
Wink Savillea12a7b32012-09-20 10:09:45 -0700937 final TelephonyRegistry telephonyRegistryF = telephonyRegistry;
Svetoslav Ganova0027152013-06-25 14:59:53 -0700938 final PrintManagerService printManagerF = printManager;
Jeff Brown69b07162013-11-07 00:30:16 -0800939 final MediaRouterService mediaRouterF = mediaRouter;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800940
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700941 // We now tell the activity manager it is okay to run third party
942 // code. It will call back into us once it has gotten to the state
943 // where third party code can really run (but before it has actually
944 // started launching the initial applications), for us to complete our
945 // initialization.
Dianne Hackborn295e3c22011-08-25 13:19:08 -0700946 ActivityManagerService.self().systemReady(new Runnable() {
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700947 public void run() {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800948 Slog.i(TAG, "Making services ready");
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800949
Christopher Tate58d380d2013-03-19 13:10:03 -0700950 try {
951 ActivityManagerService.self().startObservingNativeCrashes();
952 } catch (Throwable e) {
953 reportWtf("observing native crashes", e);
954 }
Jim Miller5ecd8112013-01-09 18:50:26 -0800955 if (!headless) {
956 startSystemUi(contextF);
957 }
Dianne Hackborn661cd522011-08-22 00:26:20 -0700958 try {
Jeff Sharkeyb049e2122012-09-07 23:16:01 -0700959 if (mountServiceF != null) mountServiceF.systemReady();
960 } catch (Throwable e) {
961 reportWtf("making Mount Service ready", e);
962 }
963 try {
Dianne Hackborn661cd522011-08-22 00:26:20 -0700964 if (batteryF != null) batteryF.systemReady();
965 } catch (Throwable e) {
966 reportWtf("making Battery Service ready", e);
967 }
968 try {
969 if (networkManagementF != null) networkManagementF.systemReady();
970 } catch (Throwable e) {
971 reportWtf("making Network Managment Service ready", e);
972 }
973 try {
974 if (networkStatsF != null) networkStatsF.systemReady();
975 } catch (Throwable e) {
976 reportWtf("making Network Stats Service ready", e);
977 }
978 try {
979 if (networkPolicyF != null) networkPolicyF.systemReady();
980 } catch (Throwable e) {
981 reportWtf("making Network Policy Service ready", e);
982 }
983 try {
984 if (connectivityF != null) connectivityF.systemReady();
985 } catch (Throwable e) {
986 reportWtf("making Connectivity Service ready", e);
987 }
988 try {
989 if (dockF != null) dockF.systemReady();
990 } catch (Throwable e) {
991 reportWtf("making Dock Service ready", e);
992 }
993 try {
994 if (usbF != null) usbF.systemReady();
995 } catch (Throwable e) {
996 reportWtf("making USB Service ready", e);
997 }
998 try {
Jeff Brown2416e092012-08-21 22:12:20 -0700999 if (twilightF != null) twilightF.systemReady();
1000 } catch (Throwable e) {
1001 reportWtf("makin Twilight Service ready", e);
1002 }
1003 try {
Dianne Hackborn661cd522011-08-22 00:26:20 -07001004 if (uiModeF != null) uiModeF.systemReady();
1005 } catch (Throwable e) {
1006 reportWtf("making UI Mode Service ready", e);
1007 }
1008 try {
1009 if (recognitionF != null) recognitionF.systemReady();
1010 } catch (Throwable e) {
1011 reportWtf("making Recognition Service ready", e);
1012 }
Dianne Hackborna34f1ad2009-09-02 13:26:28 -07001013 Watchdog.getInstance().start();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001014
Dianne Hackborna34f1ad2009-09-02 13:26:28 -07001015 // It is now okay to let the various system services start their
1016 // third party code...
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001017
Dianne Hackborn661cd522011-08-22 00:26:20 -07001018 try {
Svetoslav Ganova0027152013-06-25 14:59:53 -07001019 if (appWidgetF != null) appWidgetF.systemRunning(safeMode);
Dianne Hackborn661cd522011-08-22 00:26:20 -07001020 } catch (Throwable e) {
Svetoslav Ganova0027152013-06-25 14:59:53 -07001021 reportWtf("Notifying AppWidgetService running", e);
Dianne Hackborn661cd522011-08-22 00:26:20 -07001022 }
1023 try {
Svetoslav Ganova0027152013-06-25 14:59:53 -07001024 if (wallpaperF != null) wallpaperF.systemRunning();
Dianne Hackborn661cd522011-08-22 00:26:20 -07001025 } catch (Throwable e) {
Svetoslav Ganova0027152013-06-25 14:59:53 -07001026 reportWtf("Notifying WallpaperService running", e);
Dianne Hackborn661cd522011-08-22 00:26:20 -07001027 }
1028 try {
Svetoslav Ganova0027152013-06-25 14:59:53 -07001029 if (immF != null) immF.systemRunning(statusBarF);
Dianne Hackborn661cd522011-08-22 00:26:20 -07001030 } catch (Throwable e) {
Svetoslav Ganova0027152013-06-25 14:59:53 -07001031 reportWtf("Notifying InputMethodService running", e);
Dianne Hackborn661cd522011-08-22 00:26:20 -07001032 }
1033 try {
Svetoslav Ganova0027152013-06-25 14:59:53 -07001034 if (locationF != null) locationF.systemRunning();
Dianne Hackborn661cd522011-08-22 00:26:20 -07001035 } catch (Throwable e) {
Svetoslav Ganova0027152013-06-25 14:59:53 -07001036 reportWtf("Notifying Location Service running", e);
Dianne Hackborn661cd522011-08-22 00:26:20 -07001037 }
1038 try {
Svetoslav Ganova0027152013-06-25 14:59:53 -07001039 if (countryDetectorF != null) countryDetectorF.systemRunning();
Dianne Hackborn661cd522011-08-22 00:26:20 -07001040 } catch (Throwable e) {
Svetoslav Ganova0027152013-06-25 14:59:53 -07001041 reportWtf("Notifying CountryDetectorService running", e);
Dianne Hackborn661cd522011-08-22 00:26:20 -07001042 }
1043 try {
Svetoslav Ganova0027152013-06-25 14:59:53 -07001044 if (networkTimeUpdaterF != null) networkTimeUpdaterF.systemRunning();
Dianne Hackborn661cd522011-08-22 00:26:20 -07001045 } catch (Throwable e) {
Svetoslav Ganova0027152013-06-25 14:59:53 -07001046 reportWtf("Notifying NetworkTimeService running", e);
Dianne Hackborn661cd522011-08-22 00:26:20 -07001047 }
1048 try {
Svetoslav Ganova0027152013-06-25 14:59:53 -07001049 if (commonTimeMgmtServiceF != null) commonTimeMgmtServiceF.systemRunning();
John Grossmanc1576732012-02-01 15:23:33 -08001050 } catch (Throwable e) {
Svetoslav Ganova0027152013-06-25 14:59:53 -07001051 reportWtf("Notifying CommonTimeManagementService running", e);
John Grossmanc1576732012-02-01 15:23:33 -08001052 }
1053 try {
Svetoslav Ganova0027152013-06-25 14:59:53 -07001054 if (textServiceManagerServiceF != null)
1055 textServiceManagerServiceF.systemRunning();
Dianne Hackborn661cd522011-08-22 00:26:20 -07001056 } catch (Throwable e) {
Svetoslav Ganova0027152013-06-25 14:59:53 -07001057 reportWtf("Notifying TextServicesManagerService running", e);
Dianne Hackborn661cd522011-08-22 00:26:20 -07001058 }
Daniel Sandler7d276c32012-01-30 14:33:52 -05001059 try {
Svetoslav Ganova0027152013-06-25 14:59:53 -07001060 if (dreamyF != null) dreamyF.systemRunning();
Daniel Sandler7d276c32012-01-30 14:33:52 -05001061 } catch (Throwable e) {
Svetoslav Ganova0027152013-06-25 14:59:53 -07001062 reportWtf("Notifying DreamManagerService running", e);
Daniel Sandler7d276c32012-01-30 14:33:52 -05001063 }
Jeff Brown6ec6f792012-04-17 16:52:41 -07001064 try {
Svetoslav Ganova0027152013-06-25 14:59:53 -07001065 if (atlasF != null) atlasF.systemRunning();
Romain Guy3b748a42013-04-17 18:54:38 -07001066 } catch (Throwable e) {
Svetoslav Ganova0027152013-06-25 14:59:53 -07001067 reportWtf("Notifying AssetAtlasService running", e);
Romain Guy3b748a42013-04-17 18:54:38 -07001068 }
1069 try {
Matthew Xie96313142012-06-29 16:57:31 -07001070 // TODO(BT) Pass parameter to input manager
Svetoslav Ganova0027152013-06-25 14:59:53 -07001071 if (inputManagerF != null) inputManagerF.systemRunning();
Jeff Brown6ec6f792012-04-17 16:52:41 -07001072 } catch (Throwable e) {
Svetoslav Ganova0027152013-06-25 14:59:53 -07001073 reportWtf("Notifying InputManagerService running", e);
Jeff Brown6ec6f792012-04-17 16:52:41 -07001074 }
Dan Morrille4d9a012013-03-28 18:10:43 -07001075
Wink Savillea12a7b32012-09-20 10:09:45 -07001076 try {
Svetoslav Ganova0027152013-06-25 14:59:53 -07001077 if (telephonyRegistryF != null) telephonyRegistryF.systemRunning();
Wink Savillea12a7b32012-09-20 10:09:45 -07001078 } catch (Throwable e) {
Svetoslav Ganova0027152013-06-25 14:59:53 -07001079 reportWtf("Notifying TelephonyRegistry running", e);
1080 }
1081
1082 try {
1083 if (printManagerF != null) printManagerF.systemRuning();
1084 } catch (Throwable e) {
1085 reportWtf("Notifying PrintManagerService running", e);
Wink Savillea12a7b32012-09-20 10:09:45 -07001086 }
Jeff Brown69b07162013-11-07 00:30:16 -08001087
1088 try {
1089 if (mediaRouterF != null) mediaRouterF.systemRunning();
1090 } catch (Throwable e) {
1091 reportWtf("Notifying MediaRouterService running", e);
1092 }
Dianne Hackborna34f1ad2009-09-02 13:26:28 -07001093 }
1094 });
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001095
Brad Fitzpatrick1e02d362010-09-10 09:19:50 -07001096 // For debug builds, log event loop stalls to dropbox for analysis.
Brad Fitzpatrick50d66f92010-09-13 21:29:05 -07001097 if (StrictMode.conditionallyEnableDebugLogging()) {
1098 Slog.i(TAG, "Enabled StrictMode for system server main thread.");
Brad Fitzpatrick1e02d362010-09-10 09:19:50 -07001099 }
1100
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001101 Looper.loop();
Joe Onorato8a9b2202010-02-26 18:56:32 -08001102 Slog.d(TAG, "System ServerThread is exiting!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001103 }
Joe Onoratof3c3c4f2010-10-21 11:09:02 -04001104
1105 static final void startSystemUi(Context context) {
1106 Intent intent = new Intent();
1107 intent.setComponent(new ComponentName("com.android.systemui",
1108 "com.android.systemui.SystemUIService"));
Dianne Hackborn40e9f292012-11-27 19:12:23 -08001109 //Slog.d(TAG, "Starting service: " + intent);
Amith Yamasanicd757062012-10-19 18:23:52 -07001110 context.startServiceAsUser(intent, UserHandle.OWNER);
Joe Onoratof3c3c4f2010-10-21 11:09:02 -04001111 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001112}
1113
Jeff Hamilton35eef702010-06-09 15:45:18 -05001114public class SystemServer {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001115 private static final String TAG = "SystemServer";
1116
1117 public static final int FACTORY_TEST_OFF = 0;
1118 public static final int FACTORY_TEST_LOW_LEVEL = 1;
1119 public static final int FACTORY_TEST_HIGH_LEVEL = 2;
Jaikumar Ganeshd5ac1ae2009-05-05 22:26:12 -07001120
Bob Leee5408332009-09-04 18:31:17 -07001121 static Timer timer;
1122 static final long SNAPSHOT_INTERVAL = 60 * 60 * 1000; // 1hr
1123
Brad Fitzpatrick6bb7a4a2010-10-11 13:41:10 -07001124 // The earliest supported time. We pick one day into 1970, to
1125 // give any timezone code room without going into negative time.
1126 private static final long EARLIEST_SUPPORTED_TIME = 86400 * 1000;
1127
Narayan Kamathd1a8d9f2014-03-28 13:10:41 +00001128 /**
1129 * When set, all subsequent apps will be launched in safe mode.
1130 */
1131 public static boolean inSafeMode;
1132
Jaikumar Ganeshd5ac1ae2009-05-05 22:26:12 -07001133 /**
Jeff Brownef691172013-07-15 13:22:04 -07001134 * Called to initialize native system services.
Jaikumar Ganeshd5ac1ae2009-05-05 22:26:12 -07001135 */
Jeff Brownef691172013-07-15 13:22:04 -07001136 private static native void nativeInit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001137
1138 public static void main(String[] args) {
Brian Carlstrom5637ffc2013-11-01 14:51:58 -07001139
1140 /*
1141 * In case the runtime switched since last boot (such as when
1142 * the old runtime was removed in an OTA), set the system
1143 * property so that it is in sync. We can't do this in
1144 * libnativehelper's JniInvocation::Init code where we already
1145 * had to fallback to a different runtime because it is
1146 * running as root and we need to be the system user to set
1147 * the property. http://b/11463182
1148 */
Brian Carlstromc6c63362014-01-30 13:14:01 -08001149 SystemProperties.set("persist.sys.dalvik.vm.lib.1",
Brian Carlstrom5637ffc2013-11-01 14:51:58 -07001150 VMRuntime.getRuntime().vmLibrary());
1151
Brad Fitzpatrick6bb7a4a2010-10-11 13:41:10 -07001152 if (System.currentTimeMillis() < EARLIEST_SUPPORTED_TIME) {
Brad Fitzpatrick35ca9d82010-10-11 11:52:49 -07001153 // If a device's clock is before 1970 (before 0), a lot of
1154 // APIs crash dealing with negative numbers, notably
1155 // java.io.File#setLastModified, so instead we fake it and
1156 // hope that time from cell towers or NTP fixes it
1157 // shortly.
1158 Slog.w(TAG, "System clock is before 1970; setting to 1970.");
Brad Fitzpatrick6bb7a4a2010-10-11 13:41:10 -07001159 SystemClock.setCurrentTimeMillis(EARLIEST_SUPPORTED_TIME);
Brad Fitzpatrick35ca9d82010-10-11 11:52:49 -07001160 }
1161
Bob Leee5408332009-09-04 18:31:17 -07001162 if (SamplingProfilerIntegration.isEnabled()) {
1163 SamplingProfilerIntegration.start();
1164 timer = new Timer();
1165 timer.schedule(new TimerTask() {
1166 @Override
1167 public void run() {
Sen Hubde75702010-05-28 01:54:03 -07001168 SamplingProfilerIntegration.writeSnapshot("system_server", null);
Bob Leee5408332009-09-04 18:31:17 -07001169 }
1170 }, SNAPSHOT_INTERVAL, SNAPSHOT_INTERVAL);
1171 }
1172
Dianne Hackbornac1471a2011-02-03 13:46:06 -08001173 // Mmmmmm... more memory!
1174 dalvik.system.VMRuntime.getRuntime().clearGrowthLimit();
1175
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001176 // The system server has to run all of the time, so it needs to be
1177 // as efficient as possible with its memory usage.
1178 VMRuntime.getRuntime().setTargetHeapUtilization(0.8f);
Sen Hubde75702010-05-28 01:54:03 -07001179
Jeff Sharkey48749fc2013-04-19 13:25:04 -07001180 Environment.setUserRequired(true);
1181
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001182 System.loadLibrary("android_servers");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001183
Joe Onorato8a9b2202010-02-26 18:56:32 -08001184 Slog.i(TAG, "Entered the Android system server!");
Dianne Hackbornefa92b22013-05-03 14:11:43 -07001185
Jeff Brownef691172013-07-15 13:22:04 -07001186 // Initialize native services.
1187 nativeInit();
1188
Dianne Hackbornefa92b22013-05-03 14:11:43 -07001189 // This used to be its own separate thread, but now it is
1190 // just the loop we run on the main thread.
1191 ServerThread thr = new ServerThread();
1192 thr.initAndLoop();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001193 }
1194}