Merge "Fix job persistence & re-inflation" into qt-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
ac54e30fe5
@@ -1596,6 +1596,16 @@ 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 + "}";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -543,6 +543,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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -903,6 +906,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
|
||||||
@@ -986,6 +998,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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -379,6 +379,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.
|
||||||
|
|||||||
Reference in New Issue
Block a user