diff options
10 files changed, 171 insertions, 223 deletions
diff --git a/core/java/android/app/ContextImpl.java b/core/java/android/app/ContextImpl.java index 3e7d9b450708..477dd59f6cb2 100644 --- a/core/java/android/app/ContextImpl.java +++ b/core/java/android/app/ContextImpl.java @@ -513,6 +513,9 @@ class ContextImpl extends Context { public Object createService(ContextImpl ctx) { IBinder b = ServiceManager.getService(POWER_SERVICE); IPowerManager service = IPowerManager.Stub.asInterface(b); + if (service == null) { + Log.wtf(TAG, "Failed to get power manager service."); + } return new PowerManager(ctx.getOuterContext(), service, ctx.mMainThread.getHandler()); }}); diff --git a/core/java/android/os/PowerManagerInternal.java b/core/java/android/os/PowerManagerInternal.java index 69b828f82ac8..08a15eb7dfa1 100644 --- a/core/java/android/os/PowerManagerInternal.java +++ b/core/java/android/os/PowerManagerInternal.java @@ -16,8 +16,6 @@ package android.os; -import android.view.WindowManagerPolicy; - /** * Power manager local system service interface. * @@ -57,12 +55,9 @@ public abstract class PowerManagerInternal { public abstract boolean getLowPowerModeEnabled(); + public abstract void registerLowPowerModeObserver(LowPowerModeListener listener); + public interface LowPowerModeListener { public void onLowPowerModeChanged(boolean enabled); } - - public abstract void registerLowPowerModeObserver(LowPowerModeListener listener); - - // TODO: Remove this and retrieve as a local service instead. - public abstract void setPolicy(WindowManagerPolicy policy); } diff --git a/core/java/com/android/server/SystemServiceManager.java b/core/java/com/android/server/SystemServiceManager.java index 87a50a9940af..fda6479e2d56 100644 --- a/core/java/com/android/server/SystemServiceManager.java +++ b/core/java/com/android/server/SystemServiceManager.java @@ -50,8 +50,19 @@ public class SystemServiceManager { * @return The service instance. */ @SuppressWarnings("unchecked") - public SystemService startService(String className) throws ClassNotFoundException { - return startService((Class<SystemService>) Class.forName(className)); + public SystemService startService(String className) { + final Class<SystemService> serviceClass; + try { + serviceClass = (Class<SystemService>)Class.forName(className); + } catch (ClassNotFoundException ex) { + Slog.i(TAG, "Starting " + className); + throw new RuntimeException("Failed to create service " + className + + ": service class not found, usually indicates that the caller should " + + "have called PackageManager.hasSystemFeature() to check whether the " + + "feature is available on this device before trying to start the " + + "services that implement it", ex); + } + return startService(serviceClass); } /** diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java index 697e1f203336..61908684cde2 100644 --- a/services/core/java/com/android/server/am/ActivityManagerService.java +++ b/services/core/java/com/android/server/am/ActivityManagerService.java @@ -2194,6 +2194,11 @@ public final class ActivityManagerService extends ActivityManagerNative LocalServices.addService(ActivityManagerInternal.class, new LocalService()); } + public void initPowerManagement() { + mStackSupervisor.initPowerManagement(); + mBatteryStatsService.initPowerManagement(); + } + @Override public boolean onTransact(int code, Parcel data, Parcel reply, int flags) throws RemoteException { diff --git a/services/core/java/com/android/server/am/ActivityStackSupervisor.java b/services/core/java/com/android/server/am/ActivityStackSupervisor.java index 66e9eb3e0134..ed7e5945022c 100644 --- a/services/core/java/com/android/server/am/ActivityStackSupervisor.java +++ b/services/core/java/com/android/server/am/ActivityStackSupervisor.java @@ -227,14 +227,14 @@ public final class ActivityStackSupervisor implements DisplayListener { * receivers to launch an activity and get that to run before the device * goes back to sleep. */ - final PowerManager.WakeLock mLaunchingActivity; + PowerManager.WakeLock mLaunchingActivity; /** * Set when the system is going to sleep, until we have * successfully paused the current activity and released our wake lock. * At that point the system is allowed to actually sleep. */ - final PowerManager.WakeLock mGoingToSleep; + PowerManager.WakeLock mGoingToSleep; /** Stack id of the front stack when user switched, indexed by userId. */ SparseIntArray mUserStackInFront = new SparseIntArray(2); @@ -255,12 +255,16 @@ public final class ActivityStackSupervisor implements DisplayListener { public ActivityStackSupervisor(ActivityManagerService service) { mService = service; + mHandler = new ActivityStackSupervisorHandler(mService.mHandler.getLooper()); + } + + /** + * At the time when the constructor runs, the power manager has not yet been + * initialized. So we initialize our wakelocks afterwards. + */ + void initPowerManagement() { PowerManager pm = (PowerManager)mService.mContext.getSystemService(Context.POWER_SERVICE); mGoingToSleep = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "ActivityManager-Sleep"); - mHandler = new ActivityStackSupervisorHandler(mService.mHandler.getLooper()); - if (VALIDATE_WAKE_LOCK_CALLER && Binder.getCallingUid() != Process.myUid()) { - throw new IllegalStateException("Calling must be system uid"); - } mLaunchingActivity = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "ActivityManager-Launch"); mLaunchingActivity.setReferenceCounted(false); diff --git a/services/core/java/com/android/server/am/BatteryStatsService.java b/services/core/java/com/android/server/am/BatteryStatsService.java index eb253ebeaa19..f403d0875306 100644 --- a/services/core/java/com/android/server/am/BatteryStatsService.java +++ b/services/core/java/com/android/server/am/BatteryStatsService.java @@ -74,12 +74,19 @@ public final class BatteryStatsService extends IBatteryStats.Stub mStats.setRadioScanningTimeout(mContext.getResources().getInteger( com.android.internal.R.integer.config_radioScanningTimeout) * 1000L); + } + + /** + * At the time when the constructor runs, the power manager has not yet been + * initialized. So we initialize the low power observer later. + */ + public void initPowerManagement() { mPowerManagerInternal = LocalServices.getService(PowerManagerInternal.class); mPowerManagerInternal.registerLowPowerModeObserver(this); mStats.noteLowPowerMode(mPowerManagerInternal.getLowPowerModeEnabled()); (new WakeupReasonThread()).start(); - } - + } + public void shutdown() { Slog.w("BatteryStats", "Writing battery stats before shutdown..."); synchronized (mStats) { diff --git a/services/core/java/com/android/server/pm/PackageManagerService.java b/services/core/java/com/android/server/pm/PackageManagerService.java index 5feee50bad20..dc7645576896 100755 --- a/services/core/java/com/android/server/pm/PackageManagerService.java +++ b/services/core/java/com/android/server/pm/PackageManagerService.java @@ -1248,7 +1248,7 @@ public class PackageManagerService extends IPackageManager.Stub { } } - public static final IPackageManager main(Context context, Installer installer, + public static final PackageManagerService main(Context context, Installer installer, boolean factoryTest, boolean onlyCore) { PackageManagerService m = new PackageManagerService(context, installer, factoryTest, onlyCore); diff --git a/services/core/java/com/android/server/power/PowerManagerService.java b/services/core/java/com/android/server/power/PowerManagerService.java index fb4b8f0b69c6..b25012fe9b17 100644 --- a/services/core/java/com/android/server/power/PowerManagerService.java +++ b/services/core/java/com/android/server/power/PowerManagerService.java @@ -23,6 +23,7 @@ import com.android.server.BatteryService; import com.android.server.EventLogTags; import com.android.server.LocalServices; import com.android.server.ServiceThread; +import com.android.server.am.BatteryStatsService; import com.android.server.lights.Light; import com.android.server.lights.LightsManager; import com.android.server.Watchdog; @@ -163,13 +164,14 @@ public final class PowerManagerService extends com.android.server.SystemService private static final int POWER_HINT_LOW_POWER_MODE = 5; private final Context mContext; + private final ServiceThread mHandlerThread; + private final PowerManagerHandler mHandler; + private LightsManager mLightsManager; private BatteryService mBatteryService; private DisplayManagerInternal mDisplayManagerInternal; private IBatteryStats mBatteryStats; private IAppOpsService mAppOps; - private ServiceThread mHandlerThread; - private PowerManagerHandler mHandler; private WindowManagerPolicy mPolicy; private Notifier mNotifier; private WirelessChargerDetector mWirelessChargerDetector; @@ -429,6 +431,11 @@ public final class PowerManagerService extends com.android.server.SystemService public PowerManagerService(Context context) { super(context); mContext = context; + mHandlerThread = new ServiceThread(TAG, + Process.THREAD_PRIORITY_DISPLAY, false /*allowIo*/); + mHandlerThread.start(); + mHandler = new PowerManagerHandler(mHandlerThread.getLooper()); + synchronized (mLock) { mWakeLockSuspendBlocker = createSuspendBlockerLocked("PowerManagerService.WakeLocks"); mDisplaySuspendBlocker = createSuspendBlockerLocked("PowerManagerService.Display"); @@ -451,39 +458,19 @@ public final class PowerManagerService extends com.android.server.SystemService public void onStart() { publishBinderService(Context.POWER_SERVICE, new BinderService()); publishLocalService(PowerManagerInternal.class, new LocalService()); - } - - /** - * Initialize the power manager. - * Must be called before any other functions within the power manager are called. - */ - public void init(LightsManager ls, - BatteryService bs, IBatteryStats bss, - IAppOpsService appOps) { - mLightsManager = ls; - mBatteryService = bs; - mBatteryStats = bss; - mAppOps = appOps; - mDisplayManagerInternal = getLocalService(DisplayManagerInternal.class); - mHandlerThread = new ServiceThread(TAG, - Process.THREAD_PRIORITY_DISPLAY, false /*allowIo*/); - mHandlerThread.start(); - mHandler = new PowerManagerHandler(mHandlerThread.getLooper()); Watchdog.getInstance().addMonitor(this); Watchdog.getInstance().addThread(mHandler); } - void setPolicy(WindowManagerPolicy policy) { - synchronized (mLock) { - mPolicy = policy; - } - } - - public void systemReady() { + public void systemReady(BatteryService batteryService, IAppOpsService appOps) { synchronized (mLock) { mSystemReady = true; - mDreamManager = LocalServices.getService(DreamManagerInternal.class); + mBatteryService = batteryService; + mAppOps = appOps; + mDreamManager = getLocalService(DreamManagerInternal.class); + mDisplayManagerInternal = getLocalService(DisplayManagerInternal.class); + mPolicy = getLocalService(WindowManagerPolicy.class); PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE); mScreenBrightnessSettingMinimum = pm.getMinimumScreenBrightnessSetting(); @@ -494,6 +481,7 @@ public final class PowerManagerService extends com.android.server.SystemService // The notifier runs on the system server's main looper so as not to interfere // with the animations and other critical functions of the power manager. + mBatteryStats = BatteryStatsService.getService(); mNotifier = new Notifier(Looper.getMainLooper(), mContext, mBatteryStats, mAppOps, createSuspendBlockerLocked("PowerManagerService.Broadcasts"), mScreenOnBlocker, mPolicy); @@ -502,6 +490,8 @@ public final class PowerManagerService extends com.android.server.SystemService createSuspendBlockerLocked("PowerManagerService.WirelessChargerDetector"), mHandler); mSettingsObserver = new SettingsObserver(mHandler); + + mLightsManager = getLocalService(LightsManager.class); mAttentionLight = mLightsManager.getLight(LightsManager.LIGHT_ID_ATTENTION); // Initialize display power management. @@ -3076,10 +3066,5 @@ public final class PowerManagerService extends com.android.server.SystemService mLowPowerModeListeners.add(listener); } } - - @Override - public void setPolicy(WindowManagerPolicy policy) { - PowerManagerService.this.setPolicy(policy); - } } } diff --git a/services/core/java/com/android/server/wm/WindowManagerService.java b/services/core/java/com/android/server/wm/WindowManagerService.java index 2d8a34b6512f..d04d668a8ef0 100644 --- a/services/core/java/com/android/server/wm/WindowManagerService.java +++ b/services/core/java/com/android/server/wm/WindowManagerService.java @@ -766,6 +766,8 @@ public class WindowManagerService extends IWindowManager.Stub mDisplaySettings = new DisplaySettings(context); mDisplaySettings.readSettingsLocked(); + LocalServices.addService(WindowManagerPolicy.class, mPolicy); + mPointerEventDispatcher = new PointerEventDispatcher(mInputManager.monitorInput(TAG)); mFxSession = new SurfaceSession(); @@ -779,7 +781,6 @@ public class WindowManagerService extends IWindowManager.Stub mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE); mPowerManagerInternal = LocalServices.getService(PowerManagerInternal.class); - mPowerManagerInternal.setPolicy(mPolicy); // TODO: register as local service instead mPowerManagerInternal.registerLowPowerModeObserver( new PowerManagerInternal.LowPowerModeListener() { @Override diff --git a/services/java/com/android/server/SystemServer.java b/services/java/com/android/server/SystemServer.java index f9465956567d..4b67155df550 100644 --- a/services/java/com/android/server/SystemServer.java +++ b/services/java/com/android/server/SystemServer.java @@ -148,8 +148,14 @@ public final class SystemServer { private PowerManagerService mPowerManagerService; private ActivityManagerService mActivityManagerService; private DisplayManagerService mDisplayManagerService; + private PackageManagerService mPackageManagerService; + private PackageManager mPackageManager; + private BatteryService mBatteryService; private ContentResolver mContentResolver; + private boolean mOnlyCore; + private boolean mFirstBoot; + /** * Called to initialize native system services. */ @@ -163,6 +169,7 @@ public final class SystemServer { } public SystemServer() { + // Check for factory test mode. mFactoryTestMode = FactoryTest.getMode(); } @@ -245,7 +252,7 @@ public final class SystemServer { startBootstrapServices(); startCoreServices(); startOtherServices(); - } catch (RuntimeException ex) { + } catch (Throwable ex) { Slog.e("System", "******************************************"); Slog.e("System", "************ Failure starting system services", ex); throw ex; @@ -289,36 +296,87 @@ public final class SystemServer { mSystemContext.setTheme(android.R.style.Theme_DeviceDefault_Light_DarkActionBar); } + /** + * Starts the small tangle of critical services that are needed to get + * the system off the ground. These services have complex mutual dependencies + * which is why we initialize them all in one place here. Unless your service + * is also entwined in these dependencies, it should be initialized in one of + * the other functions. + */ private void startBootstrapServices() { // Wait for installd to finish starting up so that it has a chance to // create critical directories such as /data/user with the appropriate // permissions. We need this to complete before we initialize other services. mInstaller = mSystemServiceManager.startService(Installer.class); - // Power manager needs to be started early because other services need it. - // TODO: The conversion to the new pattern is incomplete. We need to switch - // the power manager's dependencies over then we can use boot phases to arrange - // initialization order and remove the mPowerManagerService field. - mPowerManagerService = mSystemServiceManager.startService(PowerManagerService.class); - // Activity manager runs the show. mActivityManagerService = mSystemServiceManager.startService( ActivityManagerService.Lifecycle.class).getService(); mActivityManagerService.setSystemServiceManager(mSystemServiceManager); - } - private void startCoreServices() { + // Power manager needs to be started early because other services need it. + // Native daemons may be watching for it to be registered so it must be ready + // to handle incoming binder calls immediately (including being able to verify + // the permissions for those calls). + mPowerManagerService = mSystemServiceManager.startService(PowerManagerService.class); + + // Now that the power manager has been started, let the activity manager + // initialize power management features. + mActivityManagerService.initPowerManagement(); + // Display manager is needed to provide display metrics before package manager // starts up. mDisplayManagerService = mSystemServiceManager.startService(DisplayManagerService.class); + + // We need the default display before we can initialize the package manager. + mSystemServiceManager.startBootPhase(SystemService.PHASE_WAIT_FOR_DEFAULT_DISPLAY); + + // Only run "core" apps if we're encrypting the device. + String cryptState = SystemProperties.get("vold.decrypt"); + if (ENCRYPTING_STATE.equals(cryptState)) { + Slog.w(TAG, "Detected encryption in progress - only parsing core apps"); + mOnlyCore = true; + } else if (ENCRYPTED_STATE.equals(cryptState)) { + Slog.w(TAG, "Device encrypted - only parsing core apps"); + mOnlyCore = true; + } + + // Start the package manager. + Slog.i(TAG, "Package Manager"); + mPackageManagerService = PackageManagerService.main(mSystemContext, mInstaller, + mFactoryTestMode != FactoryTest.FACTORY_TEST_OFF, mOnlyCore); + mFirstBoot = mPackageManagerService.isFirstBoot(); + mPackageManager = mSystemContext.getPackageManager(); + + // Initialize attribute cache used to cache resources from packages. + AttributeCache.init(mSystemContext); + + // Set up the Application instance for the system process and get started. + mActivityManagerService.setSystemProcess(); + } + + /** + * Starts some essential services that are not tangled up in the bootstrap process. + */ + private void startCoreServices() { + // Manages LEDs and display backlight. + mSystemServiceManager.startService(LightsService.class); + + // Tracks the battery level. + Slog.i(TAG, "Battery Service"); + mBatteryService = new BatteryService(mSystemContext, + LocalServices.getService(LightsManager.class)); + ServiceManager.addService("battery", mBatteryService); } + /** + * Starts a miscellaneous grab bag of stuff that has yet to be refactored + * and organized. + */ private void startOtherServices() { final Context context = mSystemContext; AccountManagerService accountManager = null; ContentService contentService = null; - LightsManager lights = null; - BatteryService battery = null; VibratorService vibrator = null; IAlarmManager alarm = null; MountService mountService = null; @@ -328,7 +386,6 @@ public final class SystemServer { ConnectivityService connectivity = null; NetworkScoreService networkScore = null; NsdService serviceDiscovery= null; - IPackageManager pm = null; WindowManagerService wm = null; BluetoothManagerService bluetooth = null; UsbService usb = null; @@ -341,8 +398,6 @@ public final class SystemServer { ConsumerIrService consumerIr = null; AudioService audioService = null; - boolean onlyCore = false; - boolean firstBoot = false; boolean disableStorage = SystemProperties.getBoolean("config.disable_storage", false); boolean disableMedia = SystemProperties.getBoolean("config.disable_media", false); boolean disableBluetooth = SystemProperties.getBoolean("config.disable_bluetooth", false); @@ -354,38 +409,12 @@ public final class SystemServer { boolean isEmulator = SystemProperties.get("ro.kernel.qemu").equals("1"); try { - Slog.i(TAG, "Telephony Registry"); - telephonyRegistry = new TelephonyRegistry(context); - ServiceManager.addService("telephony.registry", telephonyRegistry); - Slog.i(TAG, "Scheduling Policy"); ServiceManager.addService("scheduling_policy", new SchedulingPolicyService()); - AttributeCache.init(context); - - // We need the default display before we can initialize the package manager. - mSystemServiceManager.startBootPhase(SystemService.PHASE_WAIT_FOR_DEFAULT_DISPLAY); - - Slog.i(TAG, "Package Manager"); - // Only run "core" apps if we're encrypting the device. - String cryptState = SystemProperties.get("vold.decrypt"); - if (ENCRYPTING_STATE.equals(cryptState)) { - Slog.w(TAG, "Detected encryption in progress - only parsing core apps"); - onlyCore = true; - } else if (ENCRYPTED_STATE.equals(cryptState)) { - Slog.w(TAG, "Device encrypted - only parsing core apps"); - onlyCore = true; - } - - pm = PackageManagerService.main(context, mInstaller, - mFactoryTestMode != FactoryTest.FACTORY_TEST_OFF, - onlyCore); - try { - firstBoot = pm.isFirstBoot(); - } catch (RemoteException e) { - } - - mActivityManagerService.setSystemProcess(); + Slog.i(TAG, "Telephony Registry"); + telephonyRegistry = new TelephonyRegistry(context); + ServiceManager.addService("telephony.registry", telephonyRegistry); Slog.i(TAG, "Entropy Mixer"); ServiceManager.addService("entropy", new EntropyMixer(context)); @@ -413,24 +442,10 @@ public final class SystemServer { Slog.i(TAG, "System Content Providers"); mActivityManagerService.installSystemProviders(); - mSystemServiceManager.startService(LightsService.class); - lights = LocalServices.getService(LightsManager.class); - - Slog.i(TAG, "Battery Service"); - battery = new BatteryService(context, lights); - ServiceManager.addService("battery", battery); - Slog.i(TAG, "Vibrator Service"); vibrator = new VibratorService(context); ServiceManager.addService("vibrator", vibrator); - // TODO: use boot phase - // only initialize the power service after we have started the - // lights service, content providers and the battery service. - mPowerManagerService.init(lights, battery, - BatteryStatsService.getService(), - mActivityManagerService.getAppOpsService()); - Slog.i(TAG, "Consumer IR Service"); consumerIr = new ConsumerIrService(context); ServiceManager.addService(Context.CONSUMER_IR_SERVICE, consumerIr); @@ -449,7 +464,7 @@ public final class SystemServer { Slog.i(TAG, "Window Manager"); wm = WindowManagerService.main(context, inputManager, mFactoryTestMode != FactoryTest.FACTORY_TEST_LOW_LEVEL, - !firstBoot, onlyCore); + !mFirstBoot, mOnlyCore); ServiceManager.addService(Context.WINDOW_SERVICE, wm); ServiceManager.addService(Context.INPUT_SERVICE, inputManager); @@ -523,7 +538,7 @@ public final class SystemServer { } try { - pm.performBootDexOpt(); + mPackageManagerService.performBootDexOpt(); } catch (Throwable e) { reportWtf("performing boot dexopt", e); } @@ -561,13 +576,9 @@ public final class SystemServer { reportWtf("starting LockSettingsService service", e); } - try { - // Always start the Device Policy Manager, so that the API is compatible with - // API8. - mSystemServiceManager.startService(DevicePolicyManagerService.Lifecycle.class); - } catch (Throwable e) { - reportWtf("starting DevicePolicyService", e); - } + // Always start the Device Policy Manager, so that the API is compatible with + // API8. + mSystemServiceManager.startService(DevicePolicyManagerService.Lifecycle.class); } if (!disableSystemUI) { @@ -638,39 +649,17 @@ public final class SystemServer { reportWtf("starting NetworkPolicy Service", e); } - try { - mSystemServiceManager.startService(WIFI_P2P_SERVICE_CLASS); - } catch (Throwable e) { - reportWtf("starting Wi-Fi P2pService", e); - } + mSystemServiceManager.startService(WIFI_P2P_SERVICE_CLASS); - try { - mSystemServiceManager.startService(WIFI_PASSPOINT_SERVICE_CLASS); - } catch (Throwable e) { - reportWtf("starting Wi-Fi PasspointService", e); - } + mSystemServiceManager.startService(WIFI_PASSPOINT_SERVICE_CLASS); - try { - mSystemServiceManager.startService(WIFI_SERVICE_CLASS); - } catch (Throwable e) { - reportWtf("starting Wi-Fi Service", e); - } + mSystemServiceManager.startService(WIFI_SERVICE_CLASS); - try { - Slog.i(TAG, "Wi-Fi Scanning Service"); - mSystemServiceManager.startService( + mSystemServiceManager.startService( "com.android.server.wifi.WifiScanningService"); - } catch (Throwable e) { - reportWtf("starting Wi-Fi Scanning Service", e); - } - if (!isEmulator) { - try { - mSystemServiceManager.startService(ETHERNET_SERVICE_CLASS); - } catch (Throwable e) { - reportWtf("starting Ethernet Service", e); - } + mSystemServiceManager.startService(ETHERNET_SERVICE_CLASS); } else { // Don't start the Ethernet service on the emulator because // it interferes with qemu's SLIRP emulation, which uses @@ -714,7 +703,7 @@ public final class SystemServer { * AppWidget Provider. Make sure MountService is completely started * first before continuing. */ - if (mountService != null && !onlyCore) { + if (mountService != null && !mOnlyCore) { mountService.waitForAsecScan(); } @@ -812,14 +801,11 @@ public final class SystemServer { } if (!disableNonCoreServices) { - try { - if (pm.hasSystemFeature(PackageManager.FEATURE_USB_HOST) || - pm.hasSystemFeature(PackageManager.FEATURE_USB_ACCESSORY)) { - // Manage USB host and device support - mSystemServiceManager.startService(USB_SERVICE_CLASS); - } - } catch (Throwable e) { - reportWtf("starting UsbService", e); + if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_USB_HOST) + || mPackageManager.hasSystemFeature( + PackageManager.FEATURE_USB_ACCESSORY)) { + // Manage USB host and device support + mSystemServiceManager.startService(USB_SERVICE_CLASS); } try { @@ -839,20 +825,12 @@ public final class SystemServer { mSystemServiceManager.startService(JobSchedulerService.class); if (!disableNonCoreServices) { - try { - if (pm.hasSystemFeature(PackageManager.FEATURE_BACKUP)) { - mSystemServiceManager.startService(BACKUP_MANAGER_SERVICE_CLASS); - } - } catch (Throwable e) { - Slog.e(TAG, "Failure starting Backup Service", e); + if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_BACKUP)) { + mSystemServiceManager.startService(BACKUP_MANAGER_SERVICE_CLASS); } - try { - if (pm.hasSystemFeature(PackageManager.FEATURE_APP_WIDGETS)) { - mSystemServiceManager.startService(APPWIDGET_SERVICE_CLASS); - } - } catch (Throwable e) { - reportWtf("starting AppWidget Service", e); + if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_APP_WIDGETS)) { + mSystemServiceManager.startService(APPWIDGET_SERVICE_CLASS); } try { @@ -862,13 +840,8 @@ public final class SystemServer { reportWtf("starting Recognition Service", e); } - try { - if (pm.hasSystemFeature(PackageManager.FEATURE_VOICE_RECOGNIZERS)) { - Slog.i(TAG, "Voice Recognition Service"); - mSystemServiceManager.startService(VOICE_RECOGNITION_MANAGER_SERVICE_CLASS); - } - } catch (Throwable e) { - reportWtf("starting Voice Recognition Service", e); + if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_VOICE_RECOGNIZERS)) { + mSystemServiceManager.startService(VOICE_RECOGNITION_MANAGER_SERVICE_CLASS); } } @@ -934,38 +907,17 @@ public final class SystemServer { } } - try { - if (pm.hasSystemFeature(PackageManager.FEATURE_PRINTING)) { - mSystemServiceManager.startService(PRINT_MANAGER_SERVICE_CLASS); - } - } catch (Throwable e) { - reportWtf("starting Print Service", e); + if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_PRINTING)) { + mSystemServiceManager.startService(PRINT_MANAGER_SERVICE_CLASS); } - try { - mSystemServiceManager.startService(RestrictionsManagerService.class); - } catch (Throwable e) { - reportWtf("starting RestrictionsManagerService", e); - } + mSystemServiceManager.startService(RestrictionsManagerService.class); - try { - mSystemServiceManager.startService(MediaSessionService.class); - } catch (Throwable e) { - reportWtf("starting MediaSessionService", e); - } + mSystemServiceManager.startService(MediaSessionService.class); - try { - mSystemServiceManager.startService(HdmiControlService.class); - } catch (Throwable e) { - reportWtf("starting HdmiControlService", e); - } + mSystemServiceManager.startService(HdmiControlService.class); - try { - Slog.i(TAG, "TvInputManagerService"); - mSystemServiceManager.startService(TvInputManagerService.class); - } catch (Throwable e) { - reportWtf("starting TvInputManagerService", e); - } + mSystemServiceManager.startService(TvInputManagerService.class); if (!disableNonCoreServices) { try { @@ -976,19 +928,9 @@ public final class SystemServer { reportWtf("starting MediaRouterService", e); } - try { - Slog.i(TAG, "Trust Manager"); - mSystemServiceManager.startService(TrustManagerService.class); - } catch (Throwable e) { - Slog.e(TAG, "Failure starting TrustManagerService", e); - } + mSystemServiceManager.startService(TrustManagerService.class); - try { - Slog.i(TAG, "Fingerprint Manager"); - mSystemServiceManager.startService(FingerprintService.class); - } catch (Throwable e) { - Slog.e(TAG, "Failure starting FingerprintService", e); - } + mSystemServiceManager.startService(FingerprintService.class); try { Slog.i(TAG, "BackgroundDexOptService"); @@ -999,12 +941,7 @@ public final class SystemServer { } - try { - Slog.i(TAG, "LauncherAppsService"); - mSystemServiceManager.startService(LauncherAppsService.class); - } catch (Throwable t) { - reportWtf("starting LauncherAppsService", t); - } + mSystemServiceManager.startService(LauncherAppsService.class); } // Before things start rolling, be sure we have decided whether @@ -1061,27 +998,27 @@ public final class SystemServer { try { // TODO: use boot phase - mPowerManagerService.systemReady(); + mPowerManagerService.systemReady(mBatteryService, + mActivityManagerService.getAppOpsService()); } catch (Throwable e) { reportWtf("making Power Manager Service ready", e); } try { - pm.systemReady(); + mPackageManagerService.systemReady(); } catch (Throwable e) { reportWtf("making Package Manager Service ready", e); } try { // TODO: use boot phase and communicate these flags some other way - mDisplayManagerService.systemReady(safeMode, onlyCore); + mDisplayManagerService.systemReady(safeMode, mOnlyCore); } catch (Throwable e) { reportWtf("making Display Manager Service ready", e); } // These are needed to propagate to the runnable below. final MountService mountServiceF = mountService; - final BatteryService batteryF = battery; final NetworkManagementService networkManagementF = networkManagement; final NetworkStatsService networkStatsF = networkStats; final NetworkPolicyManagerService networkPolicyF = networkPolicy; @@ -1130,7 +1067,7 @@ public final class SystemServer { reportWtf("making Mount Service ready", e); } try { - if (batteryF != null) batteryF.systemReady(); + mBatteryService.systemReady(); } catch (Throwable e) { reportWtf("making Battery Service ready", e); } |