Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d3a346ac authored by Steve McKay's avatar Steve McKay Committed by Android (Google) Code Review
Browse files

Merge "Deal gracefully with empty srcs." into nyc-dev

parents 0adf29b8 3d68b2b3
Loading
Loading
Loading
Loading
+11 −10
Original line number Diff line number Diff line
@@ -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")
+6 −0
Original line number Diff line number Diff line
@@ -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);
        }
    }
+19 −0
Original line number Diff line number Diff line
@@ -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;