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

Commit 35453d34 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Fix the use of WakeLock."

parents 8efb27e4 8b98ab7d
Loading
Loading
Loading
Loading
+7 −4
Original line number Diff line number Diff line
@@ -183,12 +183,12 @@ public class FileOperationService extends Service implements Job.Listener {
                return;
            }

            mWakeLock.acquire();

            assert (job != null);
            if (DEBUG) Log.d(TAG, "Scheduling job " + job.id + ".");
            Future<?> future = getExecutorService(operation.getOpType()).submit(job);
            mRunning.put(jobId, new JobRecord(job, future));

            mWakeLock.acquire();
        }
    }

@@ -245,6 +245,11 @@ public class FileOperationService extends Service implements Job.Listener {
        assert(record != null);
        record.job.cleanup();

        mWakeLock.release();
        if (!mWakeLock.isHeld()) {
            mWakeLock = null;
        }

        if (mRunning.isEmpty()) {
            shutdown();
        }
@@ -256,8 +261,6 @@ public class FileOperationService extends Service implements Job.Listener {
     */
    private void shutdown() {
        if (DEBUG) Log.d(TAG, "Shutting down. Last serviceId was " + mLastServiceId);
        mWakeLock.release();
        mWakeLock = null;

        // Turns out, for us, stopSelfResult always returns false in tests,
        // so we can't guard executor shutdown. For this reason we move
+5 −1
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import static junit.framework.Assert.fail;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.Delayed;
@@ -137,8 +138,11 @@ public class TestScheduledExecutorService implements ScheduledExecutorService {
    }

    public void runAll() {
        for (TestFuture future : scheduled) {
        final Iterator<TestFuture> iter = scheduled.iterator();
        while (iter.hasNext()) {
            TestFuture future = iter.next();
            future.runnable.run();
            iter.remove();
        }
    }

+7 −1
Original line number Diff line number Diff line
@@ -90,10 +90,16 @@ public class FileOperationServiceTest extends ServiceTestCase<FileOperationServi

    @Override
    protected void tearDown() {
        // Release all possibly held wake lock here
        mExecutor.runAll();
        mDeletionExecutor.runAll();

        // There are lots of progress notifications generated in this test case.
        // Dismiss all of them here.
        while (mHandler.hasScheduledMessage()) {
            mHandler.dispatchAllMessages();
        }
    }

    public void testRunsCopyJobs() throws Exception {
        startService(createCopyIntent(newArrayList(ALPHA_DOC), BETA_DOC));