Loading core/java/android/app/job/JobInfo.java +10 −0 Original line number Diff line number Diff line Loading @@ -1596,6 +1596,16 @@ public class JobInfo implements Parcelable { } return new JobInfo(this); } /** * @hide */ public String summarize() { final String service = (mJobService != null) ? mJobService.flattenToShortString() : "null"; return "JobInfo.Builder{job:" + mJobId + "/" + service + "}"; } } /** Loading services/core/java/com/android/server/job/JobStore.java +20 −0 Original line number Diff line number Diff line Loading @@ -543,6 +543,9 @@ public final class JobStore { if (jobStatus.hasBatteryNotLowConstraint()) { out.attribute(null, "battery-not-low", Boolean.toString(true)); } if (jobStatus.hasStorageNotLowConstraint()) { out.attribute(null, "storage-not-low", Boolean.toString(true)); } out.endTag(null, XML_TAG_PARAMS_CONSTRAINTS); } Loading Loading @@ -903,6 +906,15 @@ public final class JobStore { jobBuilder.setExtras(extras); parser.nextTag(); // Consume </extras> final JobInfo builtJob; try { builtJob = jobBuilder.build(); } catch (Exception e) { Slog.w(TAG, "Unable to build job from XML, ignoring: " + jobBuilder.summarize()); return null; } // Migrate sync jobs forward from earlier, incomplete representation if ("android".equals(sourcePackageName) && extras != null Loading Loading @@ -986,6 +998,14 @@ public final class JobStore { if (val != null) { jobBuilder.setRequiresCharging(true); } val = parser.getAttributeValue(null, "battery-not-low"); if (val != null) { jobBuilder.setRequiresBatteryNotLow(true); } val = parser.getAttributeValue(null, "storage-not-low"); if (val != null) { jobBuilder.setRequiresStorageNotLow(true); } } /** Loading services/tests/servicestests/src/com/android/server/job/JobStoreTest.java +76 −0 Original line number Diff line number Diff line Loading @@ -379,6 +379,82 @@ public class JobStoreTest { .build()); } @Test public void testPersistedIdleConstraint() throws Exception { JobInfo.Builder b = new Builder(8, mComponent) .setRequiresDeviceIdle(true) .setPersisted(true); JobStatus taskStatus = JobStatus.createFromJobInfo(b.build(), SOME_UID, null, -1, null); mTaskStoreUnderTest.add(taskStatus); waitForPendingIo(); final JobSet jobStatusSet = new JobSet(); mTaskStoreUnderTest.readJobMapFromDisk(jobStatusSet, true); assertEquals("Incorrect # of persisted tasks.", 1, jobStatusSet.size()); JobStatus loaded = jobStatusSet.getAllJobs().iterator().next(); assertEquals("Idle constraint not persisted correctly.", loaded.getJob().isRequireDeviceIdle(), taskStatus.getJob().isRequireDeviceIdle()); } @Test public void testPersistedChargingConstraint() throws Exception { JobInfo.Builder b = new Builder(8, mComponent) .setRequiresCharging(true) .setPersisted(true); JobStatus taskStatus = JobStatus.createFromJobInfo(b.build(), SOME_UID, null, -1, null); mTaskStoreUnderTest.add(taskStatus); waitForPendingIo(); final JobSet jobStatusSet = new JobSet(); mTaskStoreUnderTest.readJobMapFromDisk(jobStatusSet, true); assertEquals("Incorrect # of persisted tasks.", 1, jobStatusSet.size()); JobStatus loaded = jobStatusSet.getAllJobs().iterator().next(); assertEquals("Charging constraint not persisted correctly.", loaded.getJob().isRequireCharging(), taskStatus.getJob().isRequireCharging()); } @Test public void testPersistedStorageNotLowConstraint() throws Exception { JobInfo.Builder b = new Builder(8, mComponent) .setRequiresStorageNotLow(true) .setPersisted(true); JobStatus taskStatus = JobStatus.createFromJobInfo(b.build(), SOME_UID, null, -1, null); mTaskStoreUnderTest.add(taskStatus); waitForPendingIo(); final JobSet jobStatusSet = new JobSet(); mTaskStoreUnderTest.readJobMapFromDisk(jobStatusSet, true); assertEquals("Incorrect # of persisted tasks.", 1, jobStatusSet.size()); JobStatus loaded = jobStatusSet.getAllJobs().iterator().next(); assertEquals("Storage-not-low constraint not persisted correctly.", loaded.getJob().isRequireStorageNotLow(), taskStatus.getJob().isRequireStorageNotLow()); } @Test public void testPersistedBatteryNotLowConstraint() throws Exception { JobInfo.Builder b = new Builder(8, mComponent) .setRequiresBatteryNotLow(true) .setPersisted(true); JobStatus taskStatus = JobStatus.createFromJobInfo(b.build(), SOME_UID, null, -1, null); mTaskStoreUnderTest.add(taskStatus); waitForPendingIo(); final JobSet jobStatusSet = new JobSet(); mTaskStoreUnderTest.readJobMapFromDisk(jobStatusSet, true); assertEquals("Incorrect # of persisted tasks.", 1, jobStatusSet.size()); JobStatus loaded = jobStatusSet.getAllJobs().iterator().next(); assertEquals("Battery-not-low constraint not persisted correctly.", loaded.getJob().isRequireBatteryNotLow(), taskStatus.getJob().isRequireBatteryNotLow()); } /** * Helper function to kick a {@link JobInfo} through a persistence cycle and * assert that it's unchanged. Loading Loading
core/java/android/app/job/JobInfo.java +10 −0 Original line number Diff line number Diff line Loading @@ -1596,6 +1596,16 @@ public class JobInfo implements Parcelable { } return new JobInfo(this); } /** * @hide */ public String summarize() { final String service = (mJobService != null) ? mJobService.flattenToShortString() : "null"; return "JobInfo.Builder{job:" + mJobId + "/" + service + "}"; } } /** Loading
services/core/java/com/android/server/job/JobStore.java +20 −0 Original line number Diff line number Diff line Loading @@ -543,6 +543,9 @@ public final class JobStore { if (jobStatus.hasBatteryNotLowConstraint()) { out.attribute(null, "battery-not-low", Boolean.toString(true)); } if (jobStatus.hasStorageNotLowConstraint()) { out.attribute(null, "storage-not-low", Boolean.toString(true)); } out.endTag(null, XML_TAG_PARAMS_CONSTRAINTS); } Loading Loading @@ -903,6 +906,15 @@ public final class JobStore { jobBuilder.setExtras(extras); parser.nextTag(); // Consume </extras> final JobInfo builtJob; try { builtJob = jobBuilder.build(); } catch (Exception e) { Slog.w(TAG, "Unable to build job from XML, ignoring: " + jobBuilder.summarize()); return null; } // Migrate sync jobs forward from earlier, incomplete representation if ("android".equals(sourcePackageName) && extras != null Loading Loading @@ -986,6 +998,14 @@ public final class JobStore { if (val != null) { jobBuilder.setRequiresCharging(true); } val = parser.getAttributeValue(null, "battery-not-low"); if (val != null) { jobBuilder.setRequiresBatteryNotLow(true); } val = parser.getAttributeValue(null, "storage-not-low"); if (val != null) { jobBuilder.setRequiresStorageNotLow(true); } } /** Loading
services/tests/servicestests/src/com/android/server/job/JobStoreTest.java +76 −0 Original line number Diff line number Diff line Loading @@ -379,6 +379,82 @@ public class JobStoreTest { .build()); } @Test public void testPersistedIdleConstraint() throws Exception { JobInfo.Builder b = new Builder(8, mComponent) .setRequiresDeviceIdle(true) .setPersisted(true); JobStatus taskStatus = JobStatus.createFromJobInfo(b.build(), SOME_UID, null, -1, null); mTaskStoreUnderTest.add(taskStatus); waitForPendingIo(); final JobSet jobStatusSet = new JobSet(); mTaskStoreUnderTest.readJobMapFromDisk(jobStatusSet, true); assertEquals("Incorrect # of persisted tasks.", 1, jobStatusSet.size()); JobStatus loaded = jobStatusSet.getAllJobs().iterator().next(); assertEquals("Idle constraint not persisted correctly.", loaded.getJob().isRequireDeviceIdle(), taskStatus.getJob().isRequireDeviceIdle()); } @Test public void testPersistedChargingConstraint() throws Exception { JobInfo.Builder b = new Builder(8, mComponent) .setRequiresCharging(true) .setPersisted(true); JobStatus taskStatus = JobStatus.createFromJobInfo(b.build(), SOME_UID, null, -1, null); mTaskStoreUnderTest.add(taskStatus); waitForPendingIo(); final JobSet jobStatusSet = new JobSet(); mTaskStoreUnderTest.readJobMapFromDisk(jobStatusSet, true); assertEquals("Incorrect # of persisted tasks.", 1, jobStatusSet.size()); JobStatus loaded = jobStatusSet.getAllJobs().iterator().next(); assertEquals("Charging constraint not persisted correctly.", loaded.getJob().isRequireCharging(), taskStatus.getJob().isRequireCharging()); } @Test public void testPersistedStorageNotLowConstraint() throws Exception { JobInfo.Builder b = new Builder(8, mComponent) .setRequiresStorageNotLow(true) .setPersisted(true); JobStatus taskStatus = JobStatus.createFromJobInfo(b.build(), SOME_UID, null, -1, null); mTaskStoreUnderTest.add(taskStatus); waitForPendingIo(); final JobSet jobStatusSet = new JobSet(); mTaskStoreUnderTest.readJobMapFromDisk(jobStatusSet, true); assertEquals("Incorrect # of persisted tasks.", 1, jobStatusSet.size()); JobStatus loaded = jobStatusSet.getAllJobs().iterator().next(); assertEquals("Storage-not-low constraint not persisted correctly.", loaded.getJob().isRequireStorageNotLow(), taskStatus.getJob().isRequireStorageNotLow()); } @Test public void testPersistedBatteryNotLowConstraint() throws Exception { JobInfo.Builder b = new Builder(8, mComponent) .setRequiresBatteryNotLow(true) .setPersisted(true); JobStatus taskStatus = JobStatus.createFromJobInfo(b.build(), SOME_UID, null, -1, null); mTaskStoreUnderTest.add(taskStatus); waitForPendingIo(); final JobSet jobStatusSet = new JobSet(); mTaskStoreUnderTest.readJobMapFromDisk(jobStatusSet, true); assertEquals("Incorrect # of persisted tasks.", 1, jobStatusSet.size()); JobStatus loaded = jobStatusSet.getAllJobs().iterator().next(); assertEquals("Battery-not-low constraint not persisted correctly.", loaded.getJob().isRequireBatteryNotLow(), taskStatus.getJob().isRequireBatteryNotLow()); } /** * Helper function to kick a {@link JobInfo} through a persistence cycle and * assert that it's unchanged. Loading