DeviceIdleController state exit conditions tests.
This tests exit conditions and transitions (going to ACTIVE) for
each state in DeviceIdleController.
Bug: 116512267
Test: atest com.android.server.DeviceIdleControllerTest
Change-Id: I3b46ebd4e683b865e05f0a481147a96a796fe5f2
diff --git a/services/core/java/com/android/server/DeviceIdleController.java b/services/core/java/com/android/server/DeviceIdleController.java
index 376bc0d..26421a2 100644
--- a/services/core/java/com/android/server/DeviceIdleController.java
+++ b/services/core/java/com/android/server/DeviceIdleController.java
@@ -666,7 +666,8 @@
* global Settings. Any access to this class or its fields should be done while
* holding the DeviceIdleController lock.
*/
- private final class Constants extends ContentObserver {
+ @VisibleForTesting
+ final class Constants extends ContentObserver {
// Key names stored in the settings value.
private static final String KEY_LIGHT_IDLE_AFTER_INACTIVE_TIMEOUT
= "light_after_inactive_to";
@@ -1529,12 +1530,17 @@
return (ConnectivityService) ServiceManager.getService(Context.CONNECTIVITY_SERVICE);
}
+ Constants getConstants(DeviceIdleController controller, Handler handler,
+ ContentResolver resolver) {
+ return controller.new Constants(handler, resolver);
+ }
+
LocationManager getLocationManager() {
return mContext.getSystemService(LocationManager.class);
}
- MyHandler getHandler(DeviceIdleController ctlr) {
- return ctlr.new MyHandler(BackgroundThread.getHandler().getLooper());
+ MyHandler getHandler(DeviceIdleController controller) {
+ return controller.new MyHandler(BackgroundThread.getHandler().getLooper());
}
PowerManager getPowerManager() {
@@ -1623,7 +1629,7 @@
}
}
- mConstants = new Constants(mHandler, getContext().getContentResolver());
+ mConstants = mInjector.getConstants(this, mHandler, getContext().getContentResolver());
readConfigFileLocked();
updateWhitelistAppIdsLocked();
@@ -2325,6 +2331,16 @@
}
}
+ /**
+ * Must only be used in tests.
+ *
+ * This sets the state value directly and thus doesn't trigger any behavioral changes.
+ */
+ @VisibleForTesting
+ void setLightStateForTest(int lightState) {
+ mLightState = lightState;
+ }
+
@VisibleForTesting
int getLightState() {
return mLightState;
@@ -2556,6 +2572,12 @@
}
}
+ /** Must only be used in tests. */
+ @VisibleForTesting
+ void setActiveIdleOpsForTest(int count) {
+ mActiveIdleOpCount = count;
+ }
+
void setJobsActive(boolean active) {
synchronized (this) {
mJobsActive = active;