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