summaryrefslogtreecommitdiffstats
path: root/services/core/java/com/android/server/power
diff options
context:
space:
mode:
authorJeff Brown <jeffbrown@google.com>2014-06-12 22:38:59 -0700
committerJeff Brown <jeffbrown@google.com>2014-06-17 18:20:42 -0700
commit2c43c339de5aaf4fef58aa9b5ac3af48609263a8 (patch)
treea6ffedae0013f7c54483fdf9cd60de6fb6e22b46 /services/core/java/com/android/server/power
parent12758423770455f75fede0cb47d743ea18640f2f (diff)
downloadframeworks_base-2c43c339de5aaf4fef58aa9b5ac3af48609263a8.zip
frameworks_base-2c43c339de5aaf4fef58aa9b5ac3af48609263a8.tar.gz
frameworks_base-2c43c339de5aaf4fef58aa9b5ac3af48609263a8.tar.bz2
Resolve boot time dependencies related to the power manager.
This change fixes a bug where native daemons may try to communicate with the power manager before it was fully initialized due to a race between publishing the binder service and completing init(). The solution was to simplify the dependencies related to the power manager. It turns out that most services that were passed in init are not actually needed until systemReady. What remained was a dependency on the activity manager to check permissions for incoming calls. So now we start activity manager first. However, the activity manager also depends on power manager for wakelocks. To break the cycle, we now defer initializing the activity manager's wakelocks until after the power manager has been started. Cleaned up a bunch of boot-time service dependencies so that we can have better confidence that they are correctly maintained. Bug: 13884219 Change-Id: If08e2d7ccd44e7026a72441bb6bd5afd7bb9fffe
Diffstat (limited to 'services/core/java/com/android/server/power')
-rw-r--r--services/core/java/com/android/server/power/PowerManagerService.java51
1 files changed, 18 insertions, 33 deletions
diff --git a/services/core/java/com/android/server/power/PowerManagerService.java b/services/core/java/com/android/server/power/PowerManagerService.java
index fb4b8f0..b25012f 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);
- }
}
}