Deal gracefully with empty srcs.
Bug: 28184194, 28173827 Change-Id: I6794b147a7e3d3aba73600a87d565bfffe4a4b93
This commit is contained in:
@@ -229,31 +229,32 @@ public class FileOperationService extends Service implements Job.Listener {
|
||||
@OpType int operationType, String id, List<DocumentInfo> srcs, DocumentInfo srcParent,
|
||||
DocumentStack stack) {
|
||||
|
||||
if (srcs.isEmpty()) {
|
||||
Log.w(TAG, "Ignoring job request with empty srcs list. Id: " + id);
|
||||
return null;
|
||||
}
|
||||
|
||||
if (mRunning.containsKey(id)) {
|
||||
Log.w(TAG, "Duplicate job id: " + id
|
||||
+ ". Ignoring job request for srcs: " + srcs + ", stack: " + stack + ".");
|
||||
return null;
|
||||
}
|
||||
|
||||
Job job = null;
|
||||
switch (operationType) {
|
||||
case OPERATION_COPY:
|
||||
job = jobFactory.createCopy(this, getApplicationContext(), this, id, stack, srcs);
|
||||
break;
|
||||
return jobFactory.createCopy(
|
||||
this, getApplicationContext(), this, id, stack, srcs);
|
||||
case OPERATION_MOVE:
|
||||
job = jobFactory.createMove(this, getApplicationContext(), this, id, stack, srcs,
|
||||
return jobFactory.createMove(
|
||||
this, getApplicationContext(), this, id, stack, srcs,
|
||||
srcParent);
|
||||
break;
|
||||
case OPERATION_DELETE:
|
||||
job = jobFactory.createDelete(this, getApplicationContext(), this, id, stack, srcs,
|
||||
return jobFactory.createDelete(
|
||||
this, getApplicationContext(), this, id, stack, srcs,
|
||||
srcParent);
|
||||
break;
|
||||
default:
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
assert(job != null);
|
||||
return job;
|
||||
}
|
||||
|
||||
@GuardedBy("mRunning")
|
||||
|
||||
@@ -291,18 +291,24 @@ abstract public class Job implements Runnable {
|
||||
|
||||
Job createCopy(Context service, Context appContext, Listener listener,
|
||||
String id, DocumentStack stack, List<DocumentInfo> srcs) {
|
||||
assert(!srcs.isEmpty());
|
||||
assert(stack.peek().isCreateSupported());
|
||||
return new CopyJob(service, appContext, listener, id, stack, srcs);
|
||||
}
|
||||
|
||||
Job createMove(Context service, Context appContext, Listener listener,
|
||||
String id, DocumentStack stack, List<DocumentInfo> srcs,
|
||||
DocumentInfo srcParent) {
|
||||
assert(!srcs.isEmpty());
|
||||
assert(stack.peek().isCreateSupported());
|
||||
return new MoveJob(service, appContext, listener, id, stack, srcs, srcParent);
|
||||
}
|
||||
|
||||
Job createDelete(Context service, Context appContext, Listener listener,
|
||||
String id, DocumentStack stack, List<DocumentInfo> srcs,
|
||||
DocumentInfo srcParent) {
|
||||
assert(!srcs.isEmpty());
|
||||
assert(stack.peek().isDirectory()); // we can't currently delete from archives.
|
||||
return new DeleteJob(service, appContext, listener, id, stack, srcs, srcParent);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,6 +79,16 @@ public class FileOperationServiceTest extends ServiceTestCase<FileOperationServi
|
||||
mJobFactory.assertAllJobsStarted();
|
||||
}
|
||||
|
||||
public void testRunsJobs_AfterExceptionInJobCreation() throws Exception {
|
||||
startService(createCopyIntent(new ArrayList<DocumentInfo>(), BETA_DOC));
|
||||
startService(createCopyIntent(newArrayList(GAMMA_DOC), DELTA_DOC));
|
||||
|
||||
mJobFactory.assertJobsCreated(1);
|
||||
|
||||
mExecutor.runAll();
|
||||
mJobFactory.assertAllJobsStarted();
|
||||
}
|
||||
|
||||
public void testRunsJobs_AfterFailure() throws Exception {
|
||||
startService(createCopyIntent(newArrayList(ALPHA_DOC), BETA_DOC));
|
||||
startService(createCopyIntent(newArrayList(GAMMA_DOC), DELTA_DOC));
|
||||
@@ -182,9 +192,18 @@ public class FileOperationServiceTest extends ServiceTestCase<FileOperationServi
|
||||
}
|
||||
}
|
||||
|
||||
void assertJobsCreated(int expected) {
|
||||
assertEquals(expected, jobs.size());
|
||||
}
|
||||
|
||||
@Override
|
||||
Job createCopy(Context service, Context appContext, Listener listener, String id,
|
||||
DocumentStack stack, List<DocumentInfo> srcs) {
|
||||
|
||||
if (srcs.isEmpty()) {
|
||||
throw new RuntimeException("Empty srcs not supported!");
|
||||
}
|
||||
|
||||
TestJob job = new TestJob(service, appContext, listener, OPERATION_COPY, id, stack);
|
||||
jobs.add(job);
|
||||
return job;
|
||||
|
||||
Reference in New Issue
Block a user