Loading apex/jobscheduler/service/aconfig/job.aconfig +10 −0 Original line number Diff line number Diff line Loading @@ -96,3 +96,13 @@ flag { 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 apex/jobscheduler/service/java/com/android/server/job/JobSchedulerService.java +3 −2 Original line number Diff line number Diff line Loading @@ -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)) { Loading services/tests/mockingservicestests/src/com/android/server/job/JobSchedulerServiceTest.java +30 −2 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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; Loading @@ -2341,6 +2343,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. Loading Loading
apex/jobscheduler/service/aconfig/job.aconfig +10 −0 Original line number Diff line number Diff line Loading @@ -96,3 +96,13 @@ flag { 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
apex/jobscheduler/service/java/com/android/server/job/JobSchedulerService.java +3 −2 Original line number Diff line number Diff line Loading @@ -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)) { Loading
services/tests/mockingservicestests/src/com/android/server/job/JobSchedulerServiceTest.java +30 −2 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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; Loading @@ -2341,6 +2343,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. Loading