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