SystemServer.java revision 367d15ab1a33b6159447fa8542d4fa8ff148371c
1/* 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 android.accounts.AccountManagerService; 20import android.app.ActivityManagerNative; 21import android.bluetooth.BluetoothAdapter; 22import android.content.ComponentName; 23import android.content.ContentResolver; 24import android.content.ContentService; 25import android.content.Context; 26import android.content.Intent; 27import android.content.pm.IPackageManager; 28import android.content.res.Configuration; 29import android.media.AudioService; 30import android.net.wifi.p2p.WifiP2pService; 31import android.os.Looper; 32import android.os.RemoteException; 33import android.os.ServiceManager; 34import android.os.StrictMode; 35import android.os.SystemClock; 36import android.os.SystemProperties; 37import android.provider.Settings; 38import android.server.BluetoothA2dpService; 39import android.server.BluetoothService; 40import android.server.search.SearchManagerService; 41import android.util.DisplayMetrics; 42import android.util.EventLog; 43import android.util.Log; 44import android.util.Slog; 45import android.view.WindowManager; 46 47import com.android.internal.app.ShutdownThread; 48import com.android.internal.os.BinderInternal; 49import com.android.internal.os.SamplingProfilerIntegration; 50import com.android.server.accessibility.AccessibilityManagerService; 51import com.android.server.am.ActivityManagerService; 52import com.android.server.net.NetworkPolicyManagerService; 53import com.android.server.net.NetworkStatsService; 54import com.android.server.pm.PackageManagerService; 55import com.android.server.usb.UsbService; 56import com.android.server.wm.WindowManagerService; 57 58import dalvik.system.VMRuntime; 59import dalvik.system.Zygote; 60 61import java.io.File; 62import java.util.Timer; 63import java.util.TimerTask; 64 65class ServerThread extends Thread { 66 private static final String TAG = "SystemServer"; 67 private static final String ENCRYPTING_STATE = "trigger_restart_min_framework"; 68 69 ContentResolver mContentResolver; 70 71 void reportWtf(String msg, Throwable e) { 72 Slog.w(TAG, "***********************************************"); 73 Log.wtf(TAG, "BOOT FAILURE " + msg, e); 74 } 75 76 @Override 77 public void run() { 78 EventLog.writeEvent(EventLogTags.BOOT_PROGRESS_SYSTEM_RUN, 79 SystemClock.uptimeMillis()); 80 81 Looper.prepare(); 82 83 android.os.Process.setThreadPriority( 84 android.os.Process.THREAD_PRIORITY_FOREGROUND); 85 86 BinderInternal.disableBackgroundScheduling(true); 87 android.os.Process.setCanSelfBackground(false); 88 89 // Check whether we failed to shut down last time we tried. 90 { 91 final String shutdownAction = SystemProperties.get( 92 ShutdownThread.SHUTDOWN_ACTION_PROPERTY, ""); 93 if (shutdownAction != null && shutdownAction.length() > 0) { 94 boolean reboot = (shutdownAction.charAt(0) == '1'); 95 96 final String reason; 97 if (shutdownAction.length() > 1) { 98 reason = shutdownAction.substring(1, shutdownAction.length()); 99 } else { 100 reason = null; 101 } 102 103 ShutdownThread.rebootOrShutdown(reboot, reason); 104 } 105 } 106 107 String factoryTestStr = SystemProperties.get("ro.factorytest"); 108 int factoryTest = "".equals(factoryTestStr) ? SystemServer.FACTORY_TEST_OFF 109 : Integer.parseInt(factoryTestStr); 110 111 LightsService lights = null; 112 PowerManagerService power = null; 113 BatteryService battery = null; 114 AlarmManagerService alarm = null; 115 NetworkManagementService networkManagement = null; 116 NetworkStatsService networkStats = null; 117 NetworkPolicyManagerService networkPolicy = null; 118 ConnectivityService connectivity = null; 119 WifiP2pService wifiP2p = null; 120 WifiService wifi = null; 121 IPackageManager pm = null; 122 Context context = null; 123 WindowManagerService wm = null; 124 BluetoothService bluetooth = null; 125 BluetoothA2dpService bluetoothA2dp = null; 126 DockObserver dock = null; 127 UsbService usb = null; 128 UiModeManagerService uiMode = null; 129 RecognitionManagerService recognition = null; 130 ThrottleService throttle = null; 131 NetworkTimeUpdateService networkTimeUpdater = null; 132 133 // Critical services... 134 try { 135 Slog.i(TAG, "Entropy Service"); 136 ServiceManager.addService("entropy", new EntropyService()); 137 138 Slog.i(TAG, "Power Manager"); 139 power = new PowerManagerService(); 140 ServiceManager.addService(Context.POWER_SERVICE, power); 141 142 Slog.i(TAG, "Activity Manager"); 143 context = ActivityManagerService.main(factoryTest); 144 145 Slog.i(TAG, "Telephony Registry"); 146 ServiceManager.addService("telephony.registry", new TelephonyRegistry(context)); 147 148 AttributeCache.init(context); 149 150 Slog.i(TAG, "Package Manager"); 151 // Only run "core" apps if we're encrypting the device. 152 String cryptState = SystemProperties.get("vold.decrypt"); 153 boolean onlyCore = ENCRYPTING_STATE.equals(cryptState); 154 if (onlyCore) { 155 Slog.w(TAG, "Detected encryption in progress - only parsing core apps"); 156 } 157 pm = PackageManagerService.main(context, 158 factoryTest != SystemServer.FACTORY_TEST_OFF, 159 onlyCore); 160 161 ActivityManagerService.setSystemProcess(); 162 163 mContentResolver = context.getContentResolver(); 164 165 // The AccountManager must come before the ContentService 166 try { 167 Slog.i(TAG, "Account Manager"); 168 ServiceManager.addService(Context.ACCOUNT_SERVICE, 169 new AccountManagerService(context)); 170 } catch (Throwable e) { 171 Slog.e(TAG, "Failure starting Account Manager", e); 172 } 173 174 Slog.i(TAG, "Content Manager"); 175 ContentService.main(context, 176 factoryTest == SystemServer.FACTORY_TEST_LOW_LEVEL); 177 178 Slog.i(TAG, "System Content Providers"); 179 ActivityManagerService.installSystemProviders(); 180 181 Slog.i(TAG, "Lights Service"); 182 lights = new LightsService(context); 183 184 Slog.i(TAG, "Battery Service"); 185 battery = new BatteryService(context, lights); 186 ServiceManager.addService("battery", battery); 187 188 Slog.i(TAG, "Vibrator Service"); 189 ServiceManager.addService("vibrator", new VibratorService(context)); 190 191 // only initialize the power service after we have started the 192 // lights service, content providers and the battery service. 193 power.init(context, lights, ActivityManagerService.self(), battery); 194 195 Slog.i(TAG, "Alarm Manager"); 196 alarm = new AlarmManagerService(context); 197 ServiceManager.addService(Context.ALARM_SERVICE, alarm); 198 199 Slog.i(TAG, "Init Watchdog"); 200 Watchdog.getInstance().init(context, battery, power, alarm, 201 ActivityManagerService.self()); 202 203 Slog.i(TAG, "Window Manager"); 204 wm = WindowManagerService.main(context, power, 205 factoryTest != SystemServer.FACTORY_TEST_LOW_LEVEL); 206 ServiceManager.addService(Context.WINDOW_SERVICE, wm); 207 208 ActivityManagerService.self().setWindowManager(wm); 209 210 // Skip Bluetooth if we have an emulator kernel 211 // TODO: Use a more reliable check to see if this product should 212 // support Bluetooth - see bug 988521 213 if (SystemProperties.get("ro.kernel.qemu").equals("1")) { 214 Slog.i(TAG, "No Bluetooh Service (emulator)"); 215 } else if (factoryTest == SystemServer.FACTORY_TEST_LOW_LEVEL) { 216 Slog.i(TAG, "No Bluetooth Service (factory test)"); 217 } else { 218 Slog.i(TAG, "Bluetooth Service"); 219 bluetooth = new BluetoothService(context); 220 ServiceManager.addService(BluetoothAdapter.BLUETOOTH_SERVICE, bluetooth); 221 bluetooth.initAfterRegistration(); 222 bluetoothA2dp = new BluetoothA2dpService(context, bluetooth); 223 ServiceManager.addService(BluetoothA2dpService.BLUETOOTH_A2DP_SERVICE, 224 bluetoothA2dp); 225 bluetooth.initAfterA2dpRegistration(); 226 227 int airplaneModeOn = Settings.System.getInt(mContentResolver, 228 Settings.System.AIRPLANE_MODE_ON, 0); 229 int bluetoothOn = Settings.Secure.getInt(mContentResolver, 230 Settings.Secure.BLUETOOTH_ON, 0); 231 if (airplaneModeOn == 0 && bluetoothOn != 0) { 232 bluetooth.enable(); 233 } 234 } 235 236 } catch (RuntimeException e) { 237 Slog.e("System", "******************************************"); 238 Slog.e("System", "************ Failure starting core service", e); 239 } 240 241 DevicePolicyManagerService devicePolicy = null; 242 StatusBarManagerService statusBar = null; 243 InputMethodManagerService imm = null; 244 AppWidgetService appWidget = null; 245 NotificationManagerService notification = null; 246 WallpaperManagerService wallpaper = null; 247 LocationManagerService location = null; 248 CountryDetectorService countryDetector = null; 249 TextServicesManagerService tsms = null; 250 251 // Bring up services needed for UI. 252 if (factoryTest != SystemServer.FACTORY_TEST_LOW_LEVEL) { 253 try { 254 Slog.i(TAG, "Input Method Service"); 255 imm = new InputMethodManagerService(context); 256 ServiceManager.addService(Context.INPUT_METHOD_SERVICE, imm); 257 } catch (Throwable e) { 258 reportWtf("starting Input Manager Service", e); 259 } 260 261 try { 262 Slog.i(TAG, "Accessibility Manager"); 263 ServiceManager.addService(Context.ACCESSIBILITY_SERVICE, 264 new AccessibilityManagerService(context)); 265 } catch (Throwable e) { 266 reportWtf("starting Accessibility Manager", e); 267 } 268 } 269 270 try { 271 wm.displayReady(); 272 } catch (Throwable e) { 273 reportWtf("making display ready", e); 274 } 275 276 try { 277 pm.performBootDexOpt(); 278 } catch (Throwable e) { 279 reportWtf("performing boot dexopt", e); 280 } 281 282 try { 283 ActivityManagerNative.getDefault().showBootMessage( 284 context.getResources().getText( 285 com.android.internal.R.string.android_upgrading_starting_apps), 286 false); 287 } catch (RemoteException e) { 288 } 289 290 if (factoryTest != SystemServer.FACTORY_TEST_LOW_LEVEL) { 291 try { 292 Slog.i(TAG, "Device Policy"); 293 devicePolicy = new DevicePolicyManagerService(context); 294 ServiceManager.addService(Context.DEVICE_POLICY_SERVICE, devicePolicy); 295 } catch (Throwable e) { 296 reportWtf("starting DevicePolicyService", e); 297 } 298 299 try { 300 Slog.i(TAG, "Status Bar"); 301 statusBar = new StatusBarManagerService(context, wm); 302 ServiceManager.addService(Context.STATUS_BAR_SERVICE, statusBar); 303 } catch (Throwable e) { 304 reportWtf("starting StatusBarManagerService", e); 305 } 306 307 try { 308 Slog.i(TAG, "Clipboard Service"); 309 ServiceManager.addService(Context.CLIPBOARD_SERVICE, 310 new ClipboardService(context)); 311 } catch (Throwable e) { 312 reportWtf("starting Clipboard Service", e); 313 } 314 315 try { 316 Slog.i(TAG, "NetworkManagement Service"); 317 networkManagement = NetworkManagementService.create(context); 318 ServiceManager.addService(Context.NETWORKMANAGEMENT_SERVICE, networkManagement); 319 } catch (Throwable e) { 320 reportWtf("starting NetworkManagement Service", e); 321 } 322 323 try { 324 Slog.i(TAG, "Text Service Manager Service"); 325 tsms = new TextServicesManagerService(context); 326 ServiceManager.addService(Context.TEXT_SERVICES_MANAGER_SERVICE, tsms); 327 } catch (Throwable e) { 328 reportWtf("starting Text Service Manager Service", e); 329 } 330 331 try { 332 Slog.i(TAG, "NetworkStats Service"); 333 networkStats = new NetworkStatsService(context, networkManagement, alarm); 334 ServiceManager.addService(Context.NETWORK_STATS_SERVICE, networkStats); 335 } catch (Throwable e) { 336 reportWtf("starting NetworkStats Service", e); 337 } 338 339 try { 340 Slog.i(TAG, "NetworkPolicy Service"); 341 networkPolicy = new NetworkPolicyManagerService( 342 context, ActivityManagerService.self(), power, 343 networkStats, networkManagement); 344 ServiceManager.addService(Context.NETWORK_POLICY_SERVICE, networkPolicy); 345 } catch (Throwable e) { 346 reportWtf("starting NetworkPolicy Service", e); 347 } 348 349 try { 350 Slog.i(TAG, "Wi-Fi P2pService"); 351 wifiP2p = new WifiP2pService(context); 352 ServiceManager.addService(Context.WIFI_P2P_SERVICE, wifiP2p); 353 } catch (Throwable e) { 354 reportWtf("starting Wi-Fi P2pService", e); 355 } 356 357 try { 358 Slog.i(TAG, "Wi-Fi Service"); 359 wifi = new WifiService(context); 360 ServiceManager.addService(Context.WIFI_SERVICE, wifi); 361 } catch (Throwable e) { 362 reportWtf("starting Wi-Fi Service", e); 363 } 364 365 try { 366 Slog.i(TAG, "Connectivity Service"); 367 connectivity = new ConnectivityService( 368 context, networkManagement, networkStats, networkPolicy); 369 ServiceManager.addService(Context.CONNECTIVITY_SERVICE, connectivity); 370 networkStats.bindConnectivityManager(connectivity); 371 networkPolicy.bindConnectivityManager(connectivity); 372 wifi.checkAndStartWifi(); 373 wifiP2p.connectivityServiceReady(); 374 } catch (Throwable e) { 375 reportWtf("starting Connectivity Service", e); 376 } 377 378 try { 379 Slog.i(TAG, "Throttle Service"); 380 throttle = new ThrottleService(context); 381 ServiceManager.addService( 382 Context.THROTTLE_SERVICE, throttle); 383 } catch (Throwable e) { 384 reportWtf("starting ThrottleService", e); 385 } 386 387 try { 388 /* 389 * NotificationManagerService is dependant on MountService, 390 * (for media / usb notifications) so we must start MountService first. 391 */ 392 Slog.i(TAG, "Mount Service"); 393 ServiceManager.addService("mount", new MountService(context)); 394 } catch (Throwable e) { 395 reportWtf("starting Mount Service", e); 396 } 397 398 try { 399 Slog.i(TAG, "Notification Manager"); 400 notification = new NotificationManagerService(context, statusBar, lights); 401 ServiceManager.addService(Context.NOTIFICATION_SERVICE, notification); 402 networkPolicy.bindNotificationManager(notification); 403 } catch (Throwable e) { 404 reportWtf("starting Notification Manager", e); 405 } 406 407 try { 408 Slog.i(TAG, "Device Storage Monitor"); 409 ServiceManager.addService(DeviceStorageMonitorService.SERVICE, 410 new DeviceStorageMonitorService(context)); 411 } catch (Throwable e) { 412 reportWtf("starting DeviceStorageMonitor service", e); 413 } 414 415 try { 416 Slog.i(TAG, "Location Manager"); 417 location = new LocationManagerService(context); 418 ServiceManager.addService(Context.LOCATION_SERVICE, location); 419 } catch (Throwable e) { 420 reportWtf("starting Location Manager", e); 421 } 422 423 try { 424 Slog.i(TAG, "Country Detector"); 425 countryDetector = new CountryDetectorService(context); 426 ServiceManager.addService(Context.COUNTRY_DETECTOR, countryDetector); 427 } catch (Throwable e) { 428 reportWtf("starting Country Detector", e); 429 } 430 431 try { 432 Slog.i(TAG, "Search Service"); 433 ServiceManager.addService(Context.SEARCH_SERVICE, 434 new SearchManagerService(context)); 435 } catch (Throwable e) { 436 reportWtf("starting Search Service", e); 437 } 438 439 try { 440 Slog.i(TAG, "DropBox Service"); 441 ServiceManager.addService(Context.DROPBOX_SERVICE, 442 new DropBoxManagerService(context, new File("/data/system/dropbox"))); 443 } catch (Throwable e) { 444 reportWtf("starting DropBoxManagerService", e); 445 } 446 447 try { 448 Slog.i(TAG, "Wallpaper Service"); 449 wallpaper = new WallpaperManagerService(context); 450 ServiceManager.addService(Context.WALLPAPER_SERVICE, wallpaper); 451 } catch (Throwable e) { 452 reportWtf("starting Wallpaper Service", e); 453 } 454 455 try { 456 Slog.i(TAG, "Audio Service"); 457 ServiceManager.addService(Context.AUDIO_SERVICE, new AudioService(context)); 458 } catch (Throwable e) { 459 reportWtf("starting Audio Service", e); 460 } 461 462 try { 463 Slog.i(TAG, "Dock Observer"); 464 // Listen for dock station changes 465 dock = new DockObserver(context, power); 466 } catch (Throwable e) { 467 reportWtf("starting DockObserver", e); 468 } 469 470 try { 471 Slog.i(TAG, "Wired Accessory Observer"); 472 // Listen for wired headset changes 473 new WiredAccessoryObserver(context); 474 } catch (Throwable e) { 475 reportWtf("starting WiredAccessoryObserver", e); 476 } 477 478 try { 479 Slog.i(TAG, "USB Service"); 480 // Manage USB host and device support 481 usb = new UsbService(context); 482 ServiceManager.addService(Context.USB_SERVICE, usb); 483 } catch (Throwable e) { 484 reportWtf("starting UsbService", e); 485 } 486 487 try { 488 Slog.i(TAG, "UI Mode Manager Service"); 489 // Listen for UI mode changes 490 uiMode = new UiModeManagerService(context); 491 } catch (Throwable e) { 492 reportWtf("starting UiModeManagerService", e); 493 } 494 495 try { 496 Slog.i(TAG, "Backup Service"); 497 ServiceManager.addService(Context.BACKUP_SERVICE, 498 new BackupManagerService(context)); 499 } catch (Throwable e) { 500 Slog.e(TAG, "Failure starting Backup Service", e); 501 } 502 503 try { 504 Slog.i(TAG, "AppWidget Service"); 505 appWidget = new AppWidgetService(context); 506 ServiceManager.addService(Context.APPWIDGET_SERVICE, appWidget); 507 } catch (Throwable e) { 508 reportWtf("starting AppWidget Service", e); 509 } 510 511 try { 512 Slog.i(TAG, "Recognition Service"); 513 recognition = new RecognitionManagerService(context); 514 } catch (Throwable e) { 515 reportWtf("starting Recognition Service", e); 516 } 517 518 try { 519 Slog.i(TAG, "DiskStats Service"); 520 ServiceManager.addService("diskstats", new DiskStatsService(context)); 521 } catch (Throwable e) { 522 reportWtf("starting DiskStats Service", e); 523 } 524 525 try { 526 // need to add this service even if SamplingProfilerIntegration.isEnabled() 527 // is false, because it is this service that detects system property change and 528 // turns on SamplingProfilerIntegration. Plus, when sampling profiler doesn't work, 529 // there is little overhead for running this service. 530 Slog.i(TAG, "SamplingProfiler Service"); 531 ServiceManager.addService("samplingprofiler", 532 new SamplingProfilerService(context)); 533 } catch (Throwable e) { 534 reportWtf("starting SamplingProfiler Service", e); 535 } 536 537 try { 538 Slog.i(TAG, "NetworkTimeUpdateService"); 539 networkTimeUpdater = new NetworkTimeUpdateService(context); 540 } catch (Throwable e) { 541 reportWtf("starting NetworkTimeUpdate service", e); 542 } 543 } 544 545 // Before things start rolling, be sure we have decided whether 546 // we are in safe mode. 547 final boolean safeMode = wm.detectSafeMode(); 548 if (safeMode) { 549 ActivityManagerService.self().enterSafeMode(); 550 // Post the safe mode state in the Zygote class 551 Zygote.systemInSafeMode = true; 552 // Disable the JIT for the system_server process 553 VMRuntime.getRuntime().disableJitCompilation(); 554 } else { 555 // Enable the JIT for the system_server process 556 VMRuntime.getRuntime().startJitCompilation(); 557 } 558 559 // It is now time to start up the app processes... 560 561 if (devicePolicy != null) { 562 try { 563 devicePolicy.systemReady(); 564 } catch (Throwable e) { 565 reportWtf("making Device Policy Service ready", e); 566 } 567 } 568 569 if (notification != null) { 570 try { 571 notification.systemReady(); 572 } catch (Throwable e) { 573 reportWtf("making Notification Service ready", e); 574 } 575 } 576 577 try { 578 wm.systemReady(); 579 } catch (Throwable e) { 580 reportWtf("making Window Manager Service ready", e); 581 } 582 583 if (safeMode) { 584 ActivityManagerService.self().showSafeModeOverlay(); 585 } 586 587 // Update the configuration for this context by hand, because we're going 588 // to start using it before the config change done in wm.systemReady() will 589 // propagate to it. 590 Configuration config = wm.computeNewConfiguration(); 591 DisplayMetrics metrics = new DisplayMetrics(); 592 WindowManager w = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE); 593 w.getDefaultDisplay().getMetrics(metrics); 594 context.getResources().updateConfiguration(config, metrics); 595 596 power.systemReady(); 597 try { 598 pm.systemReady(); 599 } catch (Throwable e) { 600 reportWtf("making Package Manager Service ready", e); 601 } 602 603 // These are needed to propagate to the runnable below. 604 final Context contextF = context; 605 final BatteryService batteryF = battery; 606 final NetworkManagementService networkManagementF = networkManagement; 607 final NetworkStatsService networkStatsF = networkStats; 608 final NetworkPolicyManagerService networkPolicyF = networkPolicy; 609 final ConnectivityService connectivityF = connectivity; 610 final DockObserver dockF = dock; 611 final UsbService usbF = usb; 612 final ThrottleService throttleF = throttle; 613 final UiModeManagerService uiModeF = uiMode; 614 final AppWidgetService appWidgetF = appWidget; 615 final WallpaperManagerService wallpaperF = wallpaper; 616 final InputMethodManagerService immF = imm; 617 final RecognitionManagerService recognitionF = recognition; 618 final LocationManagerService locationF = location; 619 final CountryDetectorService countryDetectorF = countryDetector; 620 final NetworkTimeUpdateService networkTimeUpdaterF = networkTimeUpdater; 621 final TextServicesManagerService textServiceManagerServiceF = tsms; 622 final StatusBarManagerService statusBarF = statusBar; 623 624 // We now tell the activity manager it is okay to run third party 625 // code. It will call back into us once it has gotten to the state 626 // where third party code can really run (but before it has actually 627 // started launching the initial applications), for us to complete our 628 // initialization. 629 ActivityManagerService.self().systemReady(new Runnable() { 630 public void run() { 631 Slog.i(TAG, "Making services ready"); 632 633 startSystemUi(contextF); 634 try { 635 if (batteryF != null) batteryF.systemReady(); 636 } catch (Throwable e) { 637 reportWtf("making Battery Service ready", e); 638 } 639 try { 640 if (networkManagementF != null) networkManagementF.systemReady(); 641 } catch (Throwable e) { 642 reportWtf("making Network Managment Service ready", e); 643 } 644 try { 645 if (networkStatsF != null) networkStatsF.systemReady(); 646 } catch (Throwable e) { 647 reportWtf("making Network Stats Service ready", e); 648 } 649 try { 650 if (networkPolicyF != null) networkPolicyF.systemReady(); 651 } catch (Throwable e) { 652 reportWtf("making Network Policy Service ready", e); 653 } 654 try { 655 if (connectivityF != null) connectivityF.systemReady(); 656 } catch (Throwable e) { 657 reportWtf("making Connectivity Service ready", e); 658 } 659 try { 660 if (dockF != null) dockF.systemReady(); 661 } catch (Throwable e) { 662 reportWtf("making Dock Service ready", e); 663 } 664 try { 665 if (usbF != null) usbF.systemReady(); 666 } catch (Throwable e) { 667 reportWtf("making USB Service ready", e); 668 } 669 try { 670 if (uiModeF != null) uiModeF.systemReady(); 671 } catch (Throwable e) { 672 reportWtf("making UI Mode Service ready", e); 673 } 674 try { 675 if (recognitionF != null) recognitionF.systemReady(); 676 } catch (Throwable e) { 677 reportWtf("making Recognition Service ready", e); 678 } 679 Watchdog.getInstance().start(); 680 681 // It is now okay to let the various system services start their 682 // third party code... 683 684 try { 685 if (appWidgetF != null) appWidgetF.systemReady(safeMode); 686 } catch (Throwable e) { 687 reportWtf("making App Widget Service ready", e); 688 } 689 try { 690 if (wallpaperF != null) wallpaperF.systemReady(); 691 } catch (Throwable e) { 692 reportWtf("making Wallpaper Service ready", e); 693 } 694 try { 695 if (immF != null) immF.systemReady(statusBarF); 696 } catch (Throwable e) { 697 reportWtf("making Input Method Service ready", e); 698 } 699 try { 700 if (locationF != null) locationF.systemReady(); 701 } catch (Throwable e) { 702 reportWtf("making Location Service ready", e); 703 } 704 try { 705 if (countryDetectorF != null) countryDetectorF.systemReady(); 706 } catch (Throwable e) { 707 reportWtf("making Country Detector Service ready", e); 708 } 709 try { 710 if (throttleF != null) throttleF.systemReady(); 711 } catch (Throwable e) { 712 reportWtf("making Throttle Service ready", e); 713 } 714 try { 715 if (networkTimeUpdaterF != null) networkTimeUpdaterF.systemReady(); 716 } catch (Throwable e) { 717 reportWtf("making Network Time Service ready", e); 718 } 719 try { 720 if (textServiceManagerServiceF != null) textServiceManagerServiceF.systemReady(); 721 } catch (Throwable e) { 722 reportWtf("making Text Services Manager Service ready", e); 723 } 724 } 725 }); 726 727 // For debug builds, log event loop stalls to dropbox for analysis. 728 if (StrictMode.conditionallyEnableDebugLogging()) { 729 Slog.i(TAG, "Enabled StrictMode for system server main thread."); 730 } 731 732 Looper.loop(); 733 Slog.d(TAG, "System ServerThread is exiting!"); 734 } 735 736 static final void startSystemUi(Context context) { 737 Intent intent = new Intent(); 738 intent.setComponent(new ComponentName("com.android.systemui", 739 "com.android.systemui.SystemUIService")); 740 Slog.d(TAG, "Starting service: " + intent); 741 context.startService(intent); 742 } 743} 744 745public class SystemServer { 746 private static final String TAG = "SystemServer"; 747 748 public static final int FACTORY_TEST_OFF = 0; 749 public static final int FACTORY_TEST_LOW_LEVEL = 1; 750 public static final int FACTORY_TEST_HIGH_LEVEL = 2; 751 752 static Timer timer; 753 static final long SNAPSHOT_INTERVAL = 60 * 60 * 1000; // 1hr 754 755 // The earliest supported time. We pick one day into 1970, to 756 // give any timezone code room without going into negative time. 757 private static final long EARLIEST_SUPPORTED_TIME = 86400 * 1000; 758 759 /** 760 * This method is called from Zygote to initialize the system. This will cause the native 761 * services (SurfaceFlinger, AudioFlinger, etc..) to be started. After that it will call back 762 * up into init2() to start the Android services. 763 */ 764 native public static void init1(String[] args); 765 766 public static void main(String[] args) { 767 if (System.currentTimeMillis() < EARLIEST_SUPPORTED_TIME) { 768 // If a device's clock is before 1970 (before 0), a lot of 769 // APIs crash dealing with negative numbers, notably 770 // java.io.File#setLastModified, so instead we fake it and 771 // hope that time from cell towers or NTP fixes it 772 // shortly. 773 Slog.w(TAG, "System clock is before 1970; setting to 1970."); 774 SystemClock.setCurrentTimeMillis(EARLIEST_SUPPORTED_TIME); 775 } 776 777 if (SamplingProfilerIntegration.isEnabled()) { 778 SamplingProfilerIntegration.start(); 779 timer = new Timer(); 780 timer.schedule(new TimerTask() { 781 @Override 782 public void run() { 783 SamplingProfilerIntegration.writeSnapshot("system_server", null); 784 } 785 }, SNAPSHOT_INTERVAL, SNAPSHOT_INTERVAL); 786 } 787 788 // Mmmmmm... more memory! 789 dalvik.system.VMRuntime.getRuntime().clearGrowthLimit(); 790 791 // The system server has to run all of the time, so it needs to be 792 // as efficient as possible with its memory usage. 793 VMRuntime.getRuntime().setTargetHeapUtilization(0.8f); 794 795 System.loadLibrary("android_servers"); 796 init1(args); 797 } 798 799 public static final void init2() { 800 Slog.i(TAG, "Entered the Android system server!"); 801 Thread thr = new ServerThread(); 802 thr.setName("android.server.ServerThread"); 803 thr.start(); 804 } 805} 806