blob: b8cf844edaeed64a44cfa395569756b2d9e4f7c7 [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
19import com.android.server.am.ActivityManagerService;
20import com.android.server.status.StatusBarService;
Bob Leee5408332009-09-04 18:31:17 -070021import com.android.internal.os.SamplingProfilerIntegration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080022
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080023import dalvik.system.VMRuntime;
24
25import android.app.ActivityManagerNative;
Nick Pellyf242b7b2009-10-08 00:12:45 +020026import android.bluetooth.BluetoothAdapter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080027import android.content.ComponentName;
28import android.content.ContentResolver;
29import android.content.ContentService;
30import android.content.Context;
31import android.content.Intent;
32import android.content.pm.IPackageManager;
33import android.database.ContentObserver;
34import android.database.Cursor;
35import android.media.AudioService;
Fred Quintana60307342009-03-24 22:48:12 -070036import android.os.*;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080037import android.provider.Contacts.People;
38import android.provider.Settings;
39import android.server.BluetoothA2dpService;
Nick Pellybd022f42009-08-14 18:33:38 -070040import android.server.BluetoothService;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080041import android.server.search.SearchManagerService;
42import android.util.EventLog;
43import android.util.Log;
Fred Quintana60307342009-03-24 22:48:12 -070044import android.accounts.AccountManagerService;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080045
Bob Leee5408332009-09-04 18:31:17 -070046import java.util.Timer;
47import java.util.TimerTask;
48
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080049class ServerThread extends Thread {
50 private static final String TAG = "SystemServer";
51 private final static boolean INCLUDE_DEMO = false;
52
53 private static final int LOG_BOOT_PROGRESS_SYSTEM_RUN = 3010;
54
55 private ContentResolver mContentResolver;
56
57 private class AdbSettingsObserver extends ContentObserver {
58 public AdbSettingsObserver() {
59 super(null);
60 }
61 @Override
62 public void onChange(boolean selfChange) {
63 boolean enableAdb = (Settings.Secure.getInt(mContentResolver,
64 Settings.Secure.ADB_ENABLED, 0) > 0);
65 // setting this secure property will start or stop adbd
66 SystemProperties.set("persist.service.adb.enable", enableAdb ? "1" : "0");
67 }
68 }
69
70 @Override
71 public void run() {
72 EventLog.writeEvent(LOG_BOOT_PROGRESS_SYSTEM_RUN,
73 SystemClock.uptimeMillis());
74
75 ActivityManagerService.prepareTraceFile(false); // create dir
76
77 Looper.prepare();
78
79 android.os.Process.setThreadPriority(
80 android.os.Process.THREAD_PRIORITY_FOREGROUND);
81
82 String factoryTestStr = SystemProperties.get("ro.factorytest");
83 int factoryTest = "".equals(factoryTestStr) ? SystemServer.FACTORY_TEST_OFF
84 : Integer.parseInt(factoryTestStr);
85
The Android Open Source Project10592532009-03-18 17:39:46 -070086 HardwareService hardware = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080087 PowerManagerService power = null;
Mike Lockwood07a500f2009-08-12 09:56:44 -040088 BatteryService battery = null;
Mike Lockwood0f79b542009-08-14 14:18:49 -040089 ConnectivityService connectivity = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080090 IPackageManager pm = null;
91 Context context = null;
92 WindowManagerService wm = null;
Nick Pellybd022f42009-08-14 18:33:38 -070093 BluetoothService bluetooth = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080094 BluetoothA2dpService bluetoothA2dp = null;
95 HeadsetObserver headset = null;
Dan Murphyc9f4eaf2009-08-12 15:15:43 -050096 DockObserver dock = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080097
98 // Critical services...
99 try {
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700100 Log.i(TAG, "Entropy Service");
Nick Kralevich4fb25612009-06-17 16:03:22 -0700101 ServiceManager.addService("entropy", new EntropyService());
102
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700103 Log.i(TAG, "Power Manager");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800104 power = new PowerManagerService();
105 ServiceManager.addService(Context.POWER_SERVICE, power);
106
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700107 Log.i(TAG, "Activity Manager");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800108 context = ActivityManagerService.main(factoryTest);
109
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700110 Log.i(TAG, "Telephony Registry");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800111 ServiceManager.addService("telephony.registry", new TelephonyRegistry(context));
112
113 AttributeCache.init(context);
114
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700115 Log.i(TAG, "Package Manager");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800116 pm = PackageManagerService.main(context,
117 factoryTest != SystemServer.FACTORY_TEST_OFF);
118
119 ActivityManagerService.setSystemProcess();
120
121 mContentResolver = context.getContentResolver();
122
Fred Quintanae91ebe22009-09-29 20:44:30 -0700123 // The AccountManager must come before the ContentService
Fred Quintana60307342009-03-24 22:48:12 -0700124 try {
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700125 Log.i(TAG, "Account Manager");
Fred Quintana60307342009-03-24 22:48:12 -0700126 ServiceManager.addService(Context.ACCOUNT_SERVICE,
127 new AccountManagerService(context));
128 } catch (Throwable e) {
129 Log.e(TAG, "Failure starting Account Manager", e);
130 }
131
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700132 Log.i(TAG, "Content Manager");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800133 ContentService.main(context,
134 factoryTest == SystemServer.FACTORY_TEST_LOW_LEVEL);
135
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700136 Log.i(TAG, "System Content Providers");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800137 ActivityManagerService.installSystemProviders();
138
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700139 Log.i(TAG, "Battery Service");
Mike Lockwood07a500f2009-08-12 09:56:44 -0400140 battery = new BatteryService(context);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800141 ServiceManager.addService("battery", battery);
142
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700143 Log.i(TAG, "Hardware Service");
The Android Open Source Project10592532009-03-18 17:39:46 -0700144 hardware = new HardwareService(context);
145 ServiceManager.addService("hardware", hardware);
146
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800147 // only initialize the power service after we have started the
The Android Open Source Project10592532009-03-18 17:39:46 -0700148 // hardware service, content providers and the battery service.
149 power.init(context, hardware, ActivityManagerService.getDefault(), battery);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800150
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700151 Log.i(TAG, "Alarm Manager");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800152 AlarmManagerService alarm = new AlarmManagerService(context);
153 ServiceManager.addService(Context.ALARM_SERVICE, alarm);
154
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700155 Log.i(TAG, "Init Watchdog");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800156 Watchdog.getInstance().init(context, battery, power, alarm,
157 ActivityManagerService.self());
158
159 // Sensor Service is needed by Window Manager, so this goes first
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700160 Log.i(TAG, "Sensor Service");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800161 ServiceManager.addService(Context.SENSOR_SERVICE, new SensorService(context));
162
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700163 Log.i(TAG, "Window Manager");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800164 wm = WindowManagerService.main(context, power,
165 factoryTest != SystemServer.FACTORY_TEST_LOW_LEVEL);
166 ServiceManager.addService(Context.WINDOW_SERVICE, wm);
167
168 ((ActivityManagerService)ServiceManager.getService("activity"))
169 .setWindowManager(wm);
170
171 // Skip Bluetooth if we have an emulator kernel
172 // TODO: Use a more reliable check to see if this product should
173 // support Bluetooth - see bug 988521
174 if (SystemProperties.get("ro.kernel.qemu").equals("1")) {
175 Log.i(TAG, "Registering null Bluetooth Service (emulator)");
Nick Pellyf242b7b2009-10-08 00:12:45 +0200176 ServiceManager.addService(BluetoothAdapter.BLUETOOTH_SERVICE, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800177 } else if (factoryTest == SystemServer.FACTORY_TEST_LOW_LEVEL) {
178 Log.i(TAG, "Registering null Bluetooth Service (factory test)");
Nick Pellyf242b7b2009-10-08 00:12:45 +0200179 ServiceManager.addService(BluetoothAdapter.BLUETOOTH_SERVICE, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800180 } else {
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700181 Log.i(TAG, "Bluetooth Service");
Nick Pellybd022f42009-08-14 18:33:38 -0700182 bluetooth = new BluetoothService(context);
Nick Pellyf242b7b2009-10-08 00:12:45 +0200183 ServiceManager.addService(BluetoothAdapter.BLUETOOTH_SERVICE, bluetooth);
Nick Pellybd022f42009-08-14 18:33:38 -0700184 bluetooth.initAfterRegistration();
Jaikumar Ganeshd5ac1ae2009-05-05 22:26:12 -0700185 bluetoothA2dp = new BluetoothA2dpService(context, bluetooth);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800186 ServiceManager.addService(BluetoothA2dpService.BLUETOOTH_A2DP_SERVICE,
187 bluetoothA2dp);
188
189 int bluetoothOn = Settings.Secure.getInt(mContentResolver,
190 Settings.Secure.BLUETOOTH_ON, 0);
191 if (bluetoothOn > 0) {
The Android Open Source Project10592532009-03-18 17:39:46 -0700192 bluetooth.enable();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800193 }
194 }
195
196 } catch (RuntimeException e) {
197 Log.e("System", "Failure starting core service", e);
198 }
199
200 StatusBarService statusBar = null;
201 InputMethodManagerService imm = null;
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700202 AppWidgetService appWidget = null;
Joe Onorato30275482009-07-08 17:09:14 -0700203 NotificationManagerService notification = null;
Dianne Hackbornf21adf62009-08-13 10:20:21 -0700204 WallpaperManagerService wallpaper = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800205
206 if (factoryTest != SystemServer.FACTORY_TEST_LOW_LEVEL) {
207 try {
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700208 Log.i(TAG, "Status Bar");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800209 statusBar = new StatusBarService(context);
210 ServiceManager.addService("statusbar", statusBar);
211 } catch (Throwable e) {
212 Log.e(TAG, "Failure starting StatusBarService", e);
213 }
214
215 try {
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700216 Log.i(TAG, "Clipboard Service");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800217 ServiceManager.addService("clipboard", new ClipboardService(context));
218 } catch (Throwable e) {
219 Log.e(TAG, "Failure starting Clipboard Service", e);
220 }
221
222 try {
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700223 Log.i(TAG, "Input Method Service");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800224 imm = new InputMethodManagerService(context, statusBar);
225 ServiceManager.addService(Context.INPUT_METHOD_SERVICE, imm);
226 } catch (Throwable e) {
227 Log.e(TAG, "Failure starting Input Manager Service", e);
228 }
229
230 try {
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700231 Log.i(TAG, "NetStat Service");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800232 ServiceManager.addService("netstat", new NetStatService(context));
233 } catch (Throwable e) {
234 Log.e(TAG, "Failure starting NetStat Service", e);
235 }
236
237 try {
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700238 Log.i(TAG, "Connectivity Service");
Mike Lockwood0f79b542009-08-14 14:18:49 -0400239 connectivity = ConnectivityService.getInstance(context);
240 ServiceManager.addService(Context.CONNECTIVITY_SERVICE, connectivity);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800241 } catch (Throwable e) {
242 Log.e(TAG, "Failure starting Connectivity Service", e);
243 }
244
245 try {
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700246 Log.i(TAG, "Accessibility Manager");
svetoslavganov75986cf2009-05-14 22:28:01 -0700247 ServiceManager.addService(Context.ACCESSIBILITY_SERVICE,
248 new AccessibilityManagerService(context));
249 } catch (Throwable e) {
250 Log.e(TAG, "Failure starting Accessibility Manager", e);
251 }
252
253 try {
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700254 Log.i(TAG, "Notification Manager");
Joe Onorato30275482009-07-08 17:09:14 -0700255 notification = new NotificationManagerService(context, statusBar, hardware);
256 ServiceManager.addService(Context.NOTIFICATION_SERVICE, notification);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800257 } catch (Throwable e) {
258 Log.e(TAG, "Failure starting Notification Manager", e);
259 }
260
261 try {
262 // MountService must start after NotificationManagerService
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700263 Log.i(TAG, "Mount Service");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800264 ServiceManager.addService("mount", new MountService(context));
265 } catch (Throwable e) {
266 Log.e(TAG, "Failure starting Mount Service", e);
267 }
268
269 try {
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700270 Log.i(TAG, "Device Storage Monitor");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800271 ServiceManager.addService(DeviceStorageMonitorService.SERVICE,
272 new DeviceStorageMonitorService(context));
273 } catch (Throwable e) {
274 Log.e(TAG, "Failure starting DeviceStorageMonitor service", e);
275 }
276
277 try {
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700278 Log.i(TAG, "Location Manager");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800279 ServiceManager.addService(Context.LOCATION_SERVICE, new LocationManagerService(context));
280 } catch (Throwable e) {
281 Log.e(TAG, "Failure starting Location Manager", e);
282 }
283
284 try {
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700285 Log.i(TAG, "Search Service");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800286 ServiceManager.addService( Context.SEARCH_SERVICE, new SearchManagerService(context) );
287 } catch (Throwable e) {
288 Log.e(TAG, "Failure starting Search Service", e);
289 }
290
291 if (INCLUDE_DEMO) {
292 Log.i(TAG, "Installing demo data...");
293 (new DemoThread(context)).start();
294 }
295
296 try {
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700297 Log.i(TAG, "Checkin Service");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800298 Intent intent = new Intent().setComponent(new ComponentName(
299 "com.google.android.server.checkin",
300 "com.google.android.server.checkin.CheckinService"));
301 if (context.startService(intent) == null) {
302 Log.w(TAG, "Using fallback Checkin Service.");
303 ServiceManager.addService("checkin", new FallbackCheckinService(context));
304 }
305 } catch (Throwable e) {
306 Log.e(TAG, "Failure starting Checkin Service", e);
307 }
308
309 try {
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700310 Log.i(TAG, "Wallpaper Service");
Dianne Hackbornf21adf62009-08-13 10:20:21 -0700311 wallpaper = new WallpaperManagerService(context);
312 ServiceManager.addService(Context.WALLPAPER_SERVICE, wallpaper);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800313 } catch (Throwable e) {
314 Log.e(TAG, "Failure starting Wallpaper Service", e);
315 }
316
317 try {
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700318 Log.i(TAG, "Audio Service");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800319 ServiceManager.addService(Context.AUDIO_SERVICE, new AudioService(context));
320 } catch (Throwable e) {
321 Log.e(TAG, "Failure starting Audio Service", e);
322 }
323
324 try {
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700325 Log.i(TAG, "Headset Observer");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800326 // Listen for wired headset changes
327 headset = new HeadsetObserver(context);
328 } catch (Throwable e) {
329 Log.e(TAG, "Failure starting HeadsetObserver", e);
330 }
331
332 try {
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700333 Log.i(TAG, "Dock Observer");
Dan Murphyc9f4eaf2009-08-12 15:15:43 -0500334 // Listen for dock station changes
Ken Schultzf02c0742009-09-10 18:37:37 -0500335 dock = new DockObserver(context, power);
Dan Murphyc9f4eaf2009-08-12 15:15:43 -0500336 } catch (Throwable e) {
337 Log.e(TAG, "Failure starting DockObserver", e);
338 }
339
340 try {
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700341 Log.i(TAG, "Backup Service");
Christopher Tate487529a2009-04-29 14:03:25 -0700342 ServiceManager.addService(Context.BACKUP_SERVICE, new BackupManagerService(context));
343 } catch (Throwable e) {
344 Log.e(TAG, "Failure starting Backup Service", e);
345 }
346
347 try {
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700348 Log.i(TAG, "AppWidget Service");
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700349 appWidget = new AppWidgetService(context);
350 ServiceManager.addService(Context.APPWIDGET_SERVICE, appWidget);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800351 } catch (Throwable e) {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700352 Log.e(TAG, "Failure starting AppWidget Service", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800353 }
354
355 try {
356 com.android.server.status.StatusBarPolicy.installIcons(context, statusBar);
357 } catch (Throwable e) {
358 Log.e(TAG, "Failure installing status bar icons", e);
359 }
360 }
361
362 // make sure the ADB_ENABLED setting value matches the secure property value
363 Settings.Secure.putInt(mContentResolver, Settings.Secure.ADB_ENABLED,
364 "1".equals(SystemProperties.get("persist.service.adb.enable")) ? 1 : 0);
365
366 // register observer to listen for settings changes
367 mContentResolver.registerContentObserver(Settings.Secure.getUriFor(Settings.Secure.ADB_ENABLED),
368 false, new AdbSettingsObserver());
369
Dianne Hackborn6af0d502009-09-28 13:25:46 -0700370 // Before things start rolling, be sure we have decided whether
371 // we are in safe mode.
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700372 final boolean safeMode = wm.detectSafeMode();
Dianne Hackborn6af0d502009-09-28 13:25:46 -0700373 if (safeMode) {
374 try {
375 ActivityManagerNative.getDefault().enterSafeMode();
376 } catch (RemoteException e) {
377 }
378 }
379
380 // It is now time to start up the app processes...
Joe Onorato30275482009-07-08 17:09:14 -0700381
382 if (notification != null) {
383 notification.systemReady();
384 }
385
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800386 if (statusBar != null) {
387 statusBar.systemReady();
388 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800389 wm.systemReady();
390 power.systemReady();
391 try {
392 pm.systemReady();
393 } catch (RemoteException e) {
394 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800395
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700396 // These are needed to propagate to the runnable below.
397 final BatteryService batteryF = battery;
398 final ConnectivityService connectivityF = connectivity;
399 final DockObserver dockF = dock;
400 final AppWidgetService appWidgetF = appWidget;
401 final WallpaperManagerService wallpaperF = wallpaper;
402 final InputMethodManagerService immF = imm;
403
404 // We now tell the activity manager it is okay to run third party
405 // code. It will call back into us once it has gotten to the state
406 // where third party code can really run (but before it has actually
407 // started launching the initial applications), for us to complete our
408 // initialization.
409 ((ActivityManagerService)ActivityManagerNative.getDefault())
410 .systemReady(new Runnable() {
411 public void run() {
412 Log.i(TAG, "Making services ready");
413
414 if (batteryF != null) batteryF.systemReady();
415 if (connectivityF != null) connectivityF.systemReady();
416 if (dockF != null) dockF.systemReady();
417 Watchdog.getInstance().start();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800418
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700419 // It is now okay to let the various system services start their
420 // third party code...
421
422 if (appWidgetF != null) appWidgetF.systemReady(safeMode);
423 if (wallpaperF != null) wallpaperF.systemReady();
424 if (immF != null) immF.systemReady();
425 }
426 });
427
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800428 Looper.loop();
429 Log.d(TAG, "System ServerThread is exiting!");
430 }
431}
432
433class DemoThread extends Thread
434{
435 DemoThread(Context context)
436 {
437 mContext = context;
438 }
439
440 @Override
441 public void run()
442 {
443 try {
444 Cursor c = mContext.getContentResolver().query(People.CONTENT_URI, null, null, null, null);
445 boolean hasData = c != null && c.moveToFirst();
446 if (c != null) {
447 c.deactivate();
448 }
449 if (!hasData) {
450 DemoDataSet dataset = new DemoDataSet();
451 dataset.add(mContext);
452 }
453 } catch (Throwable e) {
454 Log.e("SystemServer", "Failure installing demo data", e);
455 }
456
457 }
458
459 Context mContext;
460}
461
462public class SystemServer
463{
464 private static final String TAG = "SystemServer";
465
466 public static final int FACTORY_TEST_OFF = 0;
467 public static final int FACTORY_TEST_LOW_LEVEL = 1;
468 public static final int FACTORY_TEST_HIGH_LEVEL = 2;
Jaikumar Ganeshd5ac1ae2009-05-05 22:26:12 -0700469
Bob Leee5408332009-09-04 18:31:17 -0700470 static Timer timer;
471 static final long SNAPSHOT_INTERVAL = 60 * 60 * 1000; // 1hr
472
Jaikumar Ganeshd5ac1ae2009-05-05 22:26:12 -0700473 /**
474 * This method is called from Zygote to initialize the system. This will cause the native
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800475 * services (SurfaceFlinger, AudioFlinger, etc..) to be started. After that it will call back
476 * up into init2() to start the Android services.
Jaikumar Ganeshd5ac1ae2009-05-05 22:26:12 -0700477 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800478 native public static void init1(String[] args);
479
480 public static void main(String[] args) {
Bob Leee5408332009-09-04 18:31:17 -0700481 if (SamplingProfilerIntegration.isEnabled()) {
482 SamplingProfilerIntegration.start();
483 timer = new Timer();
484 timer.schedule(new TimerTask() {
485 @Override
486 public void run() {
487 SamplingProfilerIntegration.writeSnapshot("system_server");
488 }
489 }, SNAPSHOT_INTERVAL, SNAPSHOT_INTERVAL);
490 }
491
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800492 // The system server has to run all of the time, so it needs to be
493 // as efficient as possible with its memory usage.
494 VMRuntime.getRuntime().setTargetHeapUtilization(0.8f);
Jaikumar Ganeshd5ac1ae2009-05-05 22:26:12 -0700495
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800496 System.loadLibrary("android_servers");
497 init1(args);
498 }
499
500 public static final void init2() {
501 Log.i(TAG, "Entered the Android system server!");
502 Thread thr = new ServerThread();
503 thr.setName("android.server.ServerThread");
504 thr.start();
505 }
506}