Loading src/com/android/documentsui/services/FileOperationService.java +11 −10 Original line number Diff line number Diff line Loading @@ -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") Loading src/com/android/documentsui/services/Job.java +6 −0 Original line number Diff line number Diff line Loading @@ -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); } } Loading tests/src/com/android/documentsui/services/FileOperationServiceTest.java +19 −0 Original line number Diff line number Diff line Loading @@ -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)); Loading Loading @@ -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; Loading Loading
src/com/android/documentsui/services/FileOperationService.java +11 −10 Original line number Diff line number Diff line Loading @@ -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") Loading
src/com/android/documentsui/services/Job.java +6 −0 Original line number Diff line number Diff line Loading @@ -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); } } Loading
tests/src/com/android/documentsui/services/FileOperationServiceTest.java +19 −0 Original line number Diff line number Diff line Loading @@ -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)); Loading Loading @@ -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; Loading