diff options
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.       */ |