Adding limit for active apps.
Add an overall time limit for all apps, including ACTIVE apps. Right
now, the default is 4 hours per day, so apps can only have their jobs
running for a maximum of 4 hours in a rolling 24 hour window.
Also fix calculation bug where an app could be brought back into quota
despite having less than the quota buffer time available.
Bug: 117846754
Bug: 111423978
Test: atest com.android.server.job.controllers.QuotaControllerTest
Change-Id: Ia0773ef9fe26f0a502fe487f1e11c243eede30b3
diff --git a/services/core/java/com/android/server/job/JobSchedulerService.java b/services/core/java/com/android/server/job/JobSchedulerService.java
index 1325f04..ba6857d9 100644
--- a/services/core/java/com/android/server/job/JobSchedulerService.java
+++ b/services/core/java/com/android/server/job/JobSchedulerService.java
@@ -376,6 +376,8 @@
"qc_window_size_frequent_ms";
private static final String KEY_QUOTA_CONTROLLER_WINDOW_SIZE_RARE_MS =
"qc_window_size_rare_ms";
+ private static final String KEY_QUOTA_CONTROLLER_MAX_EXECUTION_TIME_MS =
+ "qc_max_execution_time_ms";
private static final int DEFAULT_MIN_IDLE_COUNT = 1;
private static final int DEFAULT_MIN_CHARGING_COUNT = 1;
@@ -414,6 +416,8 @@
8 * 60 * 60 * 1000L; // 8 hours
private static final long DEFAULT_QUOTA_CONTROLLER_WINDOW_SIZE_RARE_MS =
24 * 60 * 60 * 1000L; // 24 hours
+ private static final long DEFAULT_QUOTA_CONTROLLER_MAX_EXECUTION_TIME_MS =
+ 4 * 60 * 60 * 1000L; // 4 hours
/**
* Minimum # of idle jobs that must be ready in order to force the JMS to schedule things
@@ -581,6 +585,12 @@
public long QUOTA_CONTROLLER_WINDOW_SIZE_RARE_MS =
DEFAULT_QUOTA_CONTROLLER_WINDOW_SIZE_RARE_MS;
+ /**
+ * The maximum amount of time an app can have its jobs running within a 24 hour window.
+ */
+ public long QUOTA_CONTROLLER_MAX_EXECUTION_TIME_MS =
+ DEFAULT_QUOTA_CONTROLLER_MAX_EXECUTION_TIME_MS;
+
private final KeyValueListParser mParser = new KeyValueListParser(',');
void updateConstantsLocked(String value) {
@@ -671,6 +681,9 @@
QUOTA_CONTROLLER_WINDOW_SIZE_RARE_MS = mParser.getDurationMillis(
KEY_QUOTA_CONTROLLER_WINDOW_SIZE_RARE_MS,
DEFAULT_QUOTA_CONTROLLER_WINDOW_SIZE_RARE_MS);
+ QUOTA_CONTROLLER_MAX_EXECUTION_TIME_MS = mParser.getDurationMillis(
+ KEY_QUOTA_CONTROLLER_MAX_EXECUTION_TIME_MS,
+ DEFAULT_QUOTA_CONTROLLER_MAX_EXECUTION_TIME_MS);
}
void dump(IndentingPrintWriter pw) {
@@ -717,6 +730,8 @@
QUOTA_CONTROLLER_WINDOW_SIZE_FREQUENT_MS).println();
pw.printPair(KEY_QUOTA_CONTROLLER_WINDOW_SIZE_RARE_MS,
QUOTA_CONTROLLER_WINDOW_SIZE_RARE_MS).println();
+ pw.printPair(KEY_QUOTA_CONTROLLER_MAX_EXECUTION_TIME_MS,
+ QUOTA_CONTROLLER_MAX_EXECUTION_TIME_MS).println();
pw.decreaseIndent();
}
@@ -761,6 +776,8 @@
QUOTA_CONTROLLER_WINDOW_SIZE_FREQUENT_MS);
proto.write(ConstantsProto.QuotaController.RARE_WINDOW_SIZE_MS,
QUOTA_CONTROLLER_WINDOW_SIZE_RARE_MS);
+ proto.write(ConstantsProto.QuotaController.MAX_EXECUTION_TIME_MS,
+ QUOTA_CONTROLLER_MAX_EXECUTION_TIME_MS);
proto.end(qcToken);
proto.end(token);