Loading core/java/android/app/job/JobInfo.java +10 −0 Original line number Original line Diff line number Diff line Loading @@ -1592,5 +1592,15 @@ public class JobInfo implements Parcelable { } } return new JobInfo(this); return new JobInfo(this); } } /** * @hide */ public String summarize() { final String service = (mJobService != null) ? mJobService.flattenToShortString() : "null"; return "JobInfo.Builder{job:" + mJobId + "/" + service + "}"; } } } } } services/core/java/com/android/server/job/JobStore.java +20 −0 Original line number Original line Diff line number Diff line Loading @@ -492,6 +492,9 @@ public final class JobStore { if (jobStatus.hasBatteryNotLowConstraint()) { if (jobStatus.hasBatteryNotLowConstraint()) { out.attribute(null, "battery-not-low", Boolean.toString(true)); 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); out.endTag(null, XML_TAG_PARAMS_CONSTRAINTS); } } Loading Loading @@ -852,6 +855,15 @@ public final class JobStore { jobBuilder.setExtras(extras); jobBuilder.setExtras(extras); parser.nextTag(); // Consume </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 // Migrate sync jobs forward from earlier, incomplete representation if ("android".equals(sourcePackageName) if ("android".equals(sourcePackageName) && extras != null && extras != null Loading Loading @@ -935,6 +947,14 @@ public final class JobStore { if (val != null) { if (val != null) { jobBuilder.setRequiresCharging(true); 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 Original line Diff line number Diff line Loading @@ -382,6 +382,82 @@ public class JobStoreTest { .build()); .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 * Helper function to kick a {@link JobInfo} through a persistence cycle and * assert that it's unchanged. * assert that it's unchanged. Loading Loading
core/java/android/app/job/JobInfo.java +10 −0 Original line number Original line Diff line number Diff line Loading @@ -1592,5 +1592,15 @@ public class JobInfo implements Parcelable { } } return new JobInfo(this); return new JobInfo(this); } } /** * @hide */ public String summarize() { final String service = (mJobService != null) ? mJobService.flattenToShortString() : "null"; return "JobInfo.Builder{job:" + mJobId + "/" + service + "}"; } } } } }
services/core/java/com/android/server/job/JobStore.java +20 −0 Original line number Original line Diff line number Diff line Loading @@ -492,6 +492,9 @@ public final class JobStore { if (jobStatus.hasBatteryNotLowConstraint()) { if (jobStatus.hasBatteryNotLowConstraint()) { out.attribute(null, "battery-not-low", Boolean.toString(true)); 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); out.endTag(null, XML_TAG_PARAMS_CONSTRAINTS); } } Loading Loading @@ -852,6 +855,15 @@ public final class JobStore { jobBuilder.setExtras(extras); jobBuilder.setExtras(extras); parser.nextTag(); // Consume </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 // Migrate sync jobs forward from earlier, incomplete representation if ("android".equals(sourcePackageName) if ("android".equals(sourcePackageName) && extras != null && extras != null Loading Loading @@ -935,6 +947,14 @@ public final class JobStore { if (val != null) { if (val != null) { jobBuilder.setRequiresCharging(true); 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 Original line Diff line number Diff line Loading @@ -382,6 +382,82 @@ public class JobStoreTest { .build()); .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 * Helper function to kick a {@link JobInfo} through a persistence cycle and * assert that it's unchanged. * assert that it's unchanged. Loading