summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Xin Guan <guanxin@google.com> 2024-12-11 16:09:27 -0800
committer Android (Google) Code Review <android-gerrit@google.com> 2024-12-11 16:09:27 -0800
commit41ef600b957a2e1625f51bec4f8b2c3aa76e24cb (patch)
tree8f4be158f6ee5a53cd6f2e032140b0a29edc2e78
parentc3c82f000c202e5bb3a8aaa965f2f709e902a139 (diff)
parent0fc16f3e7263f85bf570058c98cb57aa645676e7 (diff)
Merge "Count proxy jobs toward scheduling limit." into main
-rw-r--r--apex/jobscheduler/service/aconfig/job.aconfig10
-rw-r--r--apex/jobscheduler/service/java/com/android/server/job/JobSchedulerService.java5
-rw-r--r--services/tests/mockingservicestests/src/com/android/server/job/JobSchedulerServiceTest.java32
3 files changed, 43 insertions, 4 deletions
diff --git a/apex/jobscheduler/service/aconfig/job.aconfig b/apex/jobscheduler/service/aconfig/job.aconfig
index fe95a59622f4..86ed06bf4e3d 100644
--- a/apex/jobscheduler/service/aconfig/job.aconfig
+++ b/apex/jobscheduler/service/aconfig/job.aconfig
@@ -95,4 +95,14 @@ flag {
namespace: "backstage_power"
description: "Apply the quota policy to jobs started when the app was in TOP state"
bug: "374323858"
+}
+
+flag {
+ name: "enforce_schedule_limit_to_proxy_jobs"
+ namespace: "backstage_power"
+ description: "Limit the schedule calls towards the persisted proxy jobs"
+ bug: "377912323"
+ metadata {
+ purpose: PURPOSE_BUGFIX
+ }
} \ No newline at end of file
diff --git a/apex/jobscheduler/service/java/com/android/server/job/JobSchedulerService.java b/apex/jobscheduler/service/java/com/android/server/job/JobSchedulerService.java
index 8fad79a845b4..0b884057ea19 100644
--- a/apex/jobscheduler/service/java/com/android/server/job/JobSchedulerService.java
+++ b/apex/jobscheduler/service/java/com/android/server/job/JobSchedulerService.java
@@ -1718,8 +1718,9 @@ public class JobSchedulerService extends com.android.server.SystemService
int userId, @Nullable String namespace, String tag) {
// Rate limit excessive schedule() calls.
final String servicePkg = job.getService().getPackageName();
- if (job.isPersisted() && (packageName == null || packageName.equals(servicePkg))) {
- // Only limit schedule calls for persisted jobs scheduled by the app itself.
+ if (job.isPersisted() && (Flags.enforceScheduleLimitToProxyJobs()
+ || (packageName == null || packageName.equals(servicePkg)))) {
+ // limit excessive schedule calls for persisted jobs.
final String pkg = packageName == null ? servicePkg : packageName;
if (!mQuotaTracker.isWithinQuota(userId, pkg, QUOTA_TRACKER_SCHEDULE_PERSISTED_TAG)) {
if (mQuotaTracker.isWithinQuota(userId, pkg, QUOTA_TRACKER_SCHEDULE_LOGGED)) {
diff --git a/services/tests/mockingservicestests/src/com/android/server/job/JobSchedulerServiceTest.java b/services/tests/mockingservicestests/src/com/android/server/job/JobSchedulerServiceTest.java
index c831475577d8..1e7a4f6cf51b 100644
--- a/services/tests/mockingservicestests/src/com/android/server/job/JobSchedulerServiceTest.java
+++ b/services/tests/mockingservicestests/src/com/android/server/job/JobSchedulerServiceTest.java
@@ -83,6 +83,7 @@ import android.os.ServiceManager;
import android.os.SystemClock;
import android.os.WorkSource;
import android.os.WorkSource.WorkChain;
+import android.platform.test.annotations.DisableFlags;
import android.platform.test.annotations.EnableFlags;
import android.platform.test.annotations.RequiresFlagsDisabled;
import android.platform.test.annotations.RequiresFlagsEnabled;
@@ -2319,11 +2320,12 @@ public class JobSchedulerServiceTest {
}
/**
- * Tests that jobs scheduled through a proxy (eg. system server) don't count towards scheduling
+ * Tests that jobs scheduled through a proxy (eg. system server) count towards scheduling
* limits.
*/
@Test
- public void testScheduleLimiting_Proxy() {
+ @DisableFlags(Flags.FLAG_ENFORCE_SCHEDULE_LIMIT_TO_PROXY_JOBS)
+ public void testScheduleLimiting_Proxy_NotCountTowardsLimit() {
mService.mConstants.ENABLE_API_QUOTAS = true;
mService.mConstants.API_QUOTA_SCHEDULE_COUNT = 300;
mService.mConstants.API_QUOTA_SCHEDULE_WINDOW_MS = 300000;
@@ -2342,6 +2344,32 @@ public class JobSchedulerServiceTest {
}
/**
+ * Tests that jobs scheduled through a proxy (eg. system server) don't count towards scheduling
+ * limits.
+ */
+ @Test
+ @EnableFlags(Flags.FLAG_ENFORCE_SCHEDULE_LIMIT_TO_PROXY_JOBS)
+ public void testScheduleLimiting_Proxy_CountTowardsLimit() {
+ mService.mConstants.ENABLE_API_QUOTAS = true;
+ mService.mConstants.API_QUOTA_SCHEDULE_COUNT = 300;
+ mService.mConstants.API_QUOTA_SCHEDULE_WINDOW_MS = 300000;
+ mService.mConstants.API_QUOTA_SCHEDULE_THROW_EXCEPTION = false;
+ mService.mConstants.API_QUOTA_SCHEDULE_RETURN_FAILURE_RESULT = true;
+ mService.updateQuotaTracker();
+ mService.resetScheduleQuota();
+
+ final JobInfo job = createJobInfo().setPersisted(true).build();
+ for (int i = 0; i < 500; ++i) {
+ final int expected =
+ i < 300 ? JobScheduler.RESULT_SUCCESS : JobScheduler.RESULT_FAILURE;
+ assertEquals("Got unexpected result for schedule #" + (i + 1),
+ expected,
+ mService.scheduleAsPackage(job, null, TEST_UID, "proxied.package", 0, "JSSTest",
+ ""));
+ }
+ }
+
+ /**
* Tests that jobs scheduled by an app for itself as if through a proxy are counted towards
* scheduling limits.
*/