Loading apex/jobscheduler/service/java/com/android/server/job/JobSchedulerService.java +10 −0 Original line number Diff line number Diff line Loading @@ -1503,6 +1503,16 @@ public class JobSchedulerService extends com.android.server.SystemService } toCancel.enqueueWorkLocked(work); if (toCancel.getJob().isUserInitiated()) { // The app is in a state to successfully schedule a UI job. Presumably, the // user has asked for this additional bit of work, so remove any demotion // flags. Only do this for UI jobs since they have strict scheduling // requirements; it's harder to assume other jobs were scheduled due to // user interaction/request. toCancel.removeInternalFlags( JobStatus.INTERNAL_FLAG_DEMOTED_BY_USER | JobStatus.INTERNAL_FLAG_DEMOTED_BY_SYSTEM_UIJ); } mJobs.touchJob(toCancel); sEnqueuedJwiHighWaterMarkLogger.logSampleWithUid(uId, toCancel.getWorkCount()); Loading apex/jobscheduler/service/java/com/android/server/job/controllers/JobStatus.java +4 −0 Original line number Diff line number Diff line Loading @@ -1177,6 +1177,10 @@ public final class JobStatus { mInternalFlags |= flags; } public void removeInternalFlags(int flags) { mInternalFlags = mInternalFlags & ~flags; } int getPreferredConstraintFlags() { return mPreferredConstraints; } Loading services/tests/mockingservicestests/src/com/android/server/job/controllers/JobStatusTest.java +49 −0 Original line number Diff line number Diff line Loading @@ -581,6 +581,49 @@ public class JobStatusTest { assertEquals(JobInfo.PRIORITY_HIGH, job.getEffectivePriority()); } @Test public void testModifyingInternalFlags() { final JobInfo jobInfo = new JobInfo.Builder(101, new ComponentName("foo", "bar")) .setExpedited(true) .build(); JobStatus job = createJobStatus(jobInfo); assertEquals(0, job.getInternalFlags()); // Add single flag job.addInternalFlags(JobStatus.INTERNAL_FLAG_HAS_FOREGROUND_EXEMPTION); assertEquals(JobStatus.INTERNAL_FLAG_HAS_FOREGROUND_EXEMPTION, job.getInternalFlags()); // Add multiple flags job.addInternalFlags(JobStatus.INTERNAL_FLAG_DEMOTED_BY_USER | JobStatus.INTERNAL_FLAG_DEMOTED_BY_SYSTEM_UIJ); assertEquals(JobStatus.INTERNAL_FLAG_HAS_FOREGROUND_EXEMPTION | JobStatus.INTERNAL_FLAG_DEMOTED_BY_USER | JobStatus.INTERNAL_FLAG_DEMOTED_BY_SYSTEM_UIJ, job.getInternalFlags()); // Add flag that's already set job.addInternalFlags(JobStatus.INTERNAL_FLAG_DEMOTED_BY_SYSTEM_UIJ); assertEquals(JobStatus.INTERNAL_FLAG_HAS_FOREGROUND_EXEMPTION | JobStatus.INTERNAL_FLAG_DEMOTED_BY_USER | JobStatus.INTERNAL_FLAG_DEMOTED_BY_SYSTEM_UIJ, job.getInternalFlags()); // Remove multiple job.removeInternalFlags(JobStatus.INTERNAL_FLAG_HAS_FOREGROUND_EXEMPTION | JobStatus.INTERNAL_FLAG_DEMOTED_BY_USER); assertEquals(JobStatus.INTERNAL_FLAG_DEMOTED_BY_SYSTEM_UIJ, job.getInternalFlags()); // Remove one that isn't set job.removeInternalFlags(JobStatus.INTERNAL_FLAG_DEMOTED_BY_USER); assertEquals(JobStatus.INTERNAL_FLAG_DEMOTED_BY_SYSTEM_UIJ, job.getInternalFlags()); // Remove final flag. job.removeInternalFlags(JobStatus.INTERNAL_FLAG_DEMOTED_BY_SYSTEM_UIJ); assertEquals(0, job.getInternalFlags()); } @Test public void testShouldTreatAsUserInitiated() { JobInfo jobInfo = new JobInfo.Builder(101, new ComponentName("foo", "bar")) Loading Loading @@ -619,6 +662,9 @@ public class JobStatusTest { rescheduledJob = new JobStatus(job, NO_EARLIEST_RUNTIME, NO_LATEST_RUNTIME, 0, 0, 0, 0, 0); assertFalse(rescheduledJob.shouldTreatAsUserInitiatedJob()); rescheduledJob.removeInternalFlags(JobStatus.INTERNAL_FLAG_DEMOTED_BY_USER); assertTrue(rescheduledJob.shouldTreatAsUserInitiatedJob()); } @Test Loading @@ -641,6 +687,9 @@ public class JobStatusTest { rescheduledJob = new JobStatus(job, NO_EARLIEST_RUNTIME, NO_LATEST_RUNTIME, 0, 0, 0, 0, 0); assertFalse(rescheduledJob.shouldTreatAsUserInitiatedJob()); rescheduledJob.removeInternalFlags(JobStatus.INTERNAL_FLAG_DEMOTED_BY_SYSTEM_UIJ); assertTrue(rescheduledJob.shouldTreatAsUserInitiatedJob()); } /** Loading Loading
apex/jobscheduler/service/java/com/android/server/job/JobSchedulerService.java +10 −0 Original line number Diff line number Diff line Loading @@ -1503,6 +1503,16 @@ public class JobSchedulerService extends com.android.server.SystemService } toCancel.enqueueWorkLocked(work); if (toCancel.getJob().isUserInitiated()) { // The app is in a state to successfully schedule a UI job. Presumably, the // user has asked for this additional bit of work, so remove any demotion // flags. Only do this for UI jobs since they have strict scheduling // requirements; it's harder to assume other jobs were scheduled due to // user interaction/request. toCancel.removeInternalFlags( JobStatus.INTERNAL_FLAG_DEMOTED_BY_USER | JobStatus.INTERNAL_FLAG_DEMOTED_BY_SYSTEM_UIJ); } mJobs.touchJob(toCancel); sEnqueuedJwiHighWaterMarkLogger.logSampleWithUid(uId, toCancel.getWorkCount()); Loading
apex/jobscheduler/service/java/com/android/server/job/controllers/JobStatus.java +4 −0 Original line number Diff line number Diff line Loading @@ -1177,6 +1177,10 @@ public final class JobStatus { mInternalFlags |= flags; } public void removeInternalFlags(int flags) { mInternalFlags = mInternalFlags & ~flags; } int getPreferredConstraintFlags() { return mPreferredConstraints; } Loading
services/tests/mockingservicestests/src/com/android/server/job/controllers/JobStatusTest.java +49 −0 Original line number Diff line number Diff line Loading @@ -581,6 +581,49 @@ public class JobStatusTest { assertEquals(JobInfo.PRIORITY_HIGH, job.getEffectivePriority()); } @Test public void testModifyingInternalFlags() { final JobInfo jobInfo = new JobInfo.Builder(101, new ComponentName("foo", "bar")) .setExpedited(true) .build(); JobStatus job = createJobStatus(jobInfo); assertEquals(0, job.getInternalFlags()); // Add single flag job.addInternalFlags(JobStatus.INTERNAL_FLAG_HAS_FOREGROUND_EXEMPTION); assertEquals(JobStatus.INTERNAL_FLAG_HAS_FOREGROUND_EXEMPTION, job.getInternalFlags()); // Add multiple flags job.addInternalFlags(JobStatus.INTERNAL_FLAG_DEMOTED_BY_USER | JobStatus.INTERNAL_FLAG_DEMOTED_BY_SYSTEM_UIJ); assertEquals(JobStatus.INTERNAL_FLAG_HAS_FOREGROUND_EXEMPTION | JobStatus.INTERNAL_FLAG_DEMOTED_BY_USER | JobStatus.INTERNAL_FLAG_DEMOTED_BY_SYSTEM_UIJ, job.getInternalFlags()); // Add flag that's already set job.addInternalFlags(JobStatus.INTERNAL_FLAG_DEMOTED_BY_SYSTEM_UIJ); assertEquals(JobStatus.INTERNAL_FLAG_HAS_FOREGROUND_EXEMPTION | JobStatus.INTERNAL_FLAG_DEMOTED_BY_USER | JobStatus.INTERNAL_FLAG_DEMOTED_BY_SYSTEM_UIJ, job.getInternalFlags()); // Remove multiple job.removeInternalFlags(JobStatus.INTERNAL_FLAG_HAS_FOREGROUND_EXEMPTION | JobStatus.INTERNAL_FLAG_DEMOTED_BY_USER); assertEquals(JobStatus.INTERNAL_FLAG_DEMOTED_BY_SYSTEM_UIJ, job.getInternalFlags()); // Remove one that isn't set job.removeInternalFlags(JobStatus.INTERNAL_FLAG_DEMOTED_BY_USER); assertEquals(JobStatus.INTERNAL_FLAG_DEMOTED_BY_SYSTEM_UIJ, job.getInternalFlags()); // Remove final flag. job.removeInternalFlags(JobStatus.INTERNAL_FLAG_DEMOTED_BY_SYSTEM_UIJ); assertEquals(0, job.getInternalFlags()); } @Test public void testShouldTreatAsUserInitiated() { JobInfo jobInfo = new JobInfo.Builder(101, new ComponentName("foo", "bar")) Loading Loading @@ -619,6 +662,9 @@ public class JobStatusTest { rescheduledJob = new JobStatus(job, NO_EARLIEST_RUNTIME, NO_LATEST_RUNTIME, 0, 0, 0, 0, 0); assertFalse(rescheduledJob.shouldTreatAsUserInitiatedJob()); rescheduledJob.removeInternalFlags(JobStatus.INTERNAL_FLAG_DEMOTED_BY_USER); assertTrue(rescheduledJob.shouldTreatAsUserInitiatedJob()); } @Test Loading @@ -641,6 +687,9 @@ public class JobStatusTest { rescheduledJob = new JobStatus(job, NO_EARLIEST_RUNTIME, NO_LATEST_RUNTIME, 0, 0, 0, 0, 0); assertFalse(rescheduledJob.shouldTreatAsUserInitiatedJob()); rescheduledJob.removeInternalFlags(JobStatus.INTERNAL_FLAG_DEMOTED_BY_SYSTEM_UIJ); assertTrue(rescheduledJob.shouldTreatAsUserInitiatedJob()); } /** Loading