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

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

Merge "Simplify SystemClock and FakeSystemClock"

parents 3cef3e0b 582ee23c
Loading
Loading
Loading
Loading
+0 −6
Original line number Original line Diff line number Diff line
@@ -37,10 +37,4 @@ public interface SystemClock {


    /** @see android.os.SystemClock#currentThreadTimeMillis() */
    /** @see android.os.SystemClock#currentThreadTimeMillis() */
    long currentThreadTimeMillis();
    long currentThreadTimeMillis();

    /** @see android.os.SystemClock#currentThreadTimeMicro() */
    long currentThreadTimeMicro();

    /** @see android.os.SystemClock#currentTimeMicro() */
    long currentTimeMicro();
}
}
+0 −10
Original line number Original line Diff line number Diff line
@@ -42,14 +42,4 @@ public class SystemClockImpl implements SystemClock {
    public long currentThreadTimeMillis() {
    public long currentThreadTimeMillis() {
        return android.os.SystemClock.currentThreadTimeMillis();
        return android.os.SystemClock.currentThreadTimeMillis();
    }
    }

    @Override
    public long currentThreadTimeMicro() {
        return android.os.SystemClock.currentThreadTimeMicro();
    }

    @Override
    public long currentTimeMicro() {
        return android.os.SystemClock.currentTimeMicro();
    }
}
}
+7 −7
Original line number Original line Diff line number Diff line
@@ -727,7 +727,7 @@ public class NotifListBuilderImplTest extends SysuiTestCase {
        mListBuilder.addPreGroupFilter(filter3);
        mListBuilder.addPreGroupFilter(filter3);


        // GIVEN the SystemClock is set to a particular time:
        // GIVEN the SystemClock is set to a particular time:
        mSystemClock.setUptimeMillis(47);
        mSystemClock.setUptimeMillis(10047);


        // WHEN the pipeline is kicked off on a list of notifs
        // WHEN the pipeline is kicked off on a list of notifs
        addNotif(0, PACKAGE_1);
        addNotif(0, PACKAGE_1);
@@ -735,12 +735,12 @@ public class NotifListBuilderImplTest extends SysuiTestCase {
        dispatchBuild();
        dispatchBuild();


        // THEN the value of `now` is the same for all calls to shouldFilterOut
        // THEN the value of `now` is the same for all calls to shouldFilterOut
        verify(filter1).shouldFilterOut(mEntrySet.get(0), 47);
        verify(filter1).shouldFilterOut(mEntrySet.get(0), 10047);
        verify(filter2).shouldFilterOut(mEntrySet.get(0), 47);
        verify(filter2).shouldFilterOut(mEntrySet.get(0), 10047);
        verify(filter3).shouldFilterOut(mEntrySet.get(0), 47);
        verify(filter3).shouldFilterOut(mEntrySet.get(0), 10047);
        verify(filter1).shouldFilterOut(mEntrySet.get(1), 47);
        verify(filter1).shouldFilterOut(mEntrySet.get(1), 10047);
        verify(filter2).shouldFilterOut(mEntrySet.get(1), 47);
        verify(filter2).shouldFilterOut(mEntrySet.get(1), 10047);
        verify(filter3).shouldFilterOut(mEntrySet.get(1), 47);
        verify(filter3).shouldFilterOut(mEntrySet.get(1), 10047);
    }
    }


    @Test
    @Test
+5 −11
Original line number Original line Diff line number Diff line
@@ -17,7 +17,6 @@
package com.android.systemui.util.concurrency;
package com.android.systemui.util.concurrency;


import com.android.systemui.util.time.FakeSystemClock;
import com.android.systemui.util.time.FakeSystemClock;
import com.android.systemui.util.time.FakeSystemClock.ClockTickListener;


import java.util.Collections;
import java.util.Collections;
import java.util.PriorityQueue;
import java.util.PriorityQueue;
@@ -29,15 +28,6 @@ public class FakeExecutor implements DelayableExecutor {
    private PriorityQueue<QueuedRunnable> mQueuedRunnables = new PriorityQueue<>();
    private PriorityQueue<QueuedRunnable> mQueuedRunnables = new PriorityQueue<>();
    private boolean mIgnoreClockUpdates;
    private boolean mIgnoreClockUpdates;


    private ClockTickListener mClockTickListener = new ClockTickListener() {
        @Override
        public void onUptimeMillis(long uptimeMillis) {
            if (!mIgnoreClockUpdates) {
                runAllReady();
            }
        }
    };

    /**
    /**
     * Initializes a fake executor.
     * Initializes a fake executor.
     *
     *
@@ -47,7 +37,11 @@ public class FakeExecutor implements DelayableExecutor {
     */
     */
    public FakeExecutor(FakeSystemClock clock) {
    public FakeExecutor(FakeSystemClock clock) {
        mClock = clock;
        mClock = clock;
        mClock.addListener(mClockTickListener);
        mClock.addListener(() -> {
            if (!mIgnoreClockUpdates) {
                runAllReady();
            }
        });
    }
    }


    /**
    /**
+16 −16
Original line number Original line Diff line number Diff line
@@ -52,28 +52,28 @@ public class FakeExecutorTest extends SysuiTestCase {
        FakeExecutor fakeExecutor = new FakeExecutor(clock);
        FakeExecutor fakeExecutor = new FakeExecutor(clock);
        RunnableImpl runnable = new RunnableImpl();
        RunnableImpl runnable = new RunnableImpl();


        assertEquals(0, clock.uptimeMillis());
        assertEquals(10000, clock.uptimeMillis());
        assertEquals(0, runnable.mRunCount);
        assertEquals(0, runnable.mRunCount);


        // Execute two runnables. They should not run and should be left pending.
        // Execute two runnables. They should not run and should be left pending.
        fakeExecutor.execute(runnable);
        fakeExecutor.execute(runnable);
        assertEquals(0, runnable.mRunCount);
        assertEquals(0, runnable.mRunCount);
        assertEquals(0, clock.uptimeMillis());
        assertEquals(10000, clock.uptimeMillis());
        assertEquals(1, fakeExecutor.numPending());
        assertEquals(1, fakeExecutor.numPending());
        fakeExecutor.execute(runnable);
        fakeExecutor.execute(runnable);
        assertEquals(0, runnable.mRunCount);
        assertEquals(0, runnable.mRunCount);
        assertEquals(0, clock.uptimeMillis());
        assertEquals(10000, clock.uptimeMillis());
        assertEquals(2, fakeExecutor.numPending());
        assertEquals(2, fakeExecutor.numPending());


        // Run one pending runnable.
        // Run one pending runnable.
        assertTrue(fakeExecutor.runNextReady());
        assertTrue(fakeExecutor.runNextReady());
        assertEquals(1, runnable.mRunCount);
        assertEquals(1, runnable.mRunCount);
        assertEquals(0, clock.uptimeMillis());
        assertEquals(10000, clock.uptimeMillis());
        assertEquals(1, fakeExecutor.numPending());
        assertEquals(1, fakeExecutor.numPending());
        // Run a second pending runnable.
        // Run a second pending runnable.
        assertTrue(fakeExecutor.runNextReady());
        assertTrue(fakeExecutor.runNextReady());
        assertEquals(2, runnable.mRunCount);
        assertEquals(2, runnable.mRunCount);
        assertEquals(0, clock.uptimeMillis());
        assertEquals(10000, clock.uptimeMillis());
        assertEquals(0, fakeExecutor.numPending());
        assertEquals(0, fakeExecutor.numPending());


        // No more runnables to run.
        // No more runnables to run.
@@ -83,12 +83,12 @@ public class FakeExecutorTest extends SysuiTestCase {
        fakeExecutor.execute(runnable);
        fakeExecutor.execute(runnable);
        fakeExecutor.execute(runnable);
        fakeExecutor.execute(runnable);
        assertEquals(2, runnable.mRunCount);
        assertEquals(2, runnable.mRunCount);
        assertEquals(0, clock.uptimeMillis());
        assertEquals(10000, clock.uptimeMillis());
        assertEquals(2, fakeExecutor.numPending());
        assertEquals(2, fakeExecutor.numPending());
        // Execute all pending runnables in batch.
        // Execute all pending runnables in batch.
        assertEquals(2, fakeExecutor.runAllReady());
        assertEquals(2, fakeExecutor.runAllReady());
        assertEquals(4, runnable.mRunCount);
        assertEquals(4, runnable.mRunCount);
        assertEquals(0, clock.uptimeMillis());
        assertEquals(10000, clock.uptimeMillis());
        assertEquals(0, fakeExecutor.runAllReady());
        assertEquals(0, fakeExecutor.runAllReady());
    }
    }


@@ -106,7 +106,7 @@ public class FakeExecutorTest extends SysuiTestCase {
        fakeExecutor.executeDelayed(runnable, 50);
        fakeExecutor.executeDelayed(runnable, 50);
        fakeExecutor.executeDelayed(runnable, 100);
        fakeExecutor.executeDelayed(runnable, 100);
        assertEquals(0, runnable.mRunCount);
        assertEquals(0, runnable.mRunCount);
        assertEquals(0, clock.uptimeMillis());
        assertEquals(10000, clock.uptimeMillis());
        assertEquals(3, fakeExecutor.numPending());
        assertEquals(3, fakeExecutor.numPending());
        // Delayed runnables should not advance the clock and therefore should not run.
        // Delayed runnables should not advance the clock and therefore should not run.
        assertFalse(fakeExecutor.runNextReady());
        assertFalse(fakeExecutor.runNextReady());
@@ -140,7 +140,7 @@ public class FakeExecutorTest extends SysuiTestCase {
        fakeExecutor.executeDelayed(runnable, 50);
        fakeExecutor.executeDelayed(runnable, 50);
        fakeExecutor.executeDelayed(runnable, 100);
        fakeExecutor.executeDelayed(runnable, 100);
        assertEquals(0, runnable.mRunCount);
        assertEquals(0, runnable.mRunCount);
        assertEquals(0, clock.uptimeMillis());
        assertEquals(10000, clock.uptimeMillis());
        assertEquals(3, fakeExecutor.numPending());
        assertEquals(3, fakeExecutor.numPending());
        // Delayed runnables should not advance the clock and therefore should not run.
        // Delayed runnables should not advance the clock and therefore should not run.
        assertFalse(fakeExecutor.runNextReady());
        assertFalse(fakeExecutor.runNextReady());
@@ -150,24 +150,24 @@ public class FakeExecutorTest extends SysuiTestCase {
        // Advance the clock to the next runnable. Check that it is run.
        // Advance the clock to the next runnable. Check that it is run.
        assertEquals(1, fakeExecutor.advanceClockToNext());
        assertEquals(1, fakeExecutor.advanceClockToNext());
        assertEquals(1, fakeExecutor.runAllReady());
        assertEquals(1, fakeExecutor.runAllReady());
        assertEquals(1, clock.uptimeMillis());
        assertEquals(10001, clock.uptimeMillis());
        assertEquals(2, fakeExecutor.numPending());
        assertEquals(2, fakeExecutor.numPending());
        assertEquals(1, runnable.mRunCount);
        assertEquals(1, runnable.mRunCount);
        assertEquals(49, fakeExecutor.advanceClockToNext());
        assertEquals(49, fakeExecutor.advanceClockToNext());
        assertEquals(1, fakeExecutor.runAllReady());
        assertEquals(1, fakeExecutor.runAllReady());
        assertEquals(50, clock.uptimeMillis());
        assertEquals(10050, clock.uptimeMillis());
        assertEquals(1, fakeExecutor.numPending());
        assertEquals(1, fakeExecutor.numPending());
        assertEquals(2, runnable.mRunCount);
        assertEquals(2, runnable.mRunCount);
        assertEquals(50, fakeExecutor.advanceClockToNext());
        assertEquals(50, fakeExecutor.advanceClockToNext());
        assertEquals(1, fakeExecutor.runAllReady());
        assertEquals(1, fakeExecutor.runAllReady());
        assertEquals(100, clock.uptimeMillis());
        assertEquals(10100, clock.uptimeMillis());
        assertEquals(0, fakeExecutor.numPending());
        assertEquals(0, fakeExecutor.numPending());
        assertEquals(3, runnable.mRunCount);
        assertEquals(3, runnable.mRunCount);


        // Nothing left to do
        // Nothing left to do
        assertEquals(0, fakeExecutor.advanceClockToNext());
        assertEquals(0, fakeExecutor.advanceClockToNext());
        assertEquals(0, fakeExecutor.runAllReady());
        assertEquals(0, fakeExecutor.runAllReady());
        assertEquals(100, clock.uptimeMillis());
        assertEquals(10100, clock.uptimeMillis());
        assertEquals(0, fakeExecutor.numPending());
        assertEquals(0, fakeExecutor.numPending());
        assertEquals(3, runnable.mRunCount);
        assertEquals(3, runnable.mRunCount);
    }
    }
@@ -193,7 +193,7 @@ public class FakeExecutorTest extends SysuiTestCase {
                    return null;
                    return null;
                };
                };


        assertEquals(0, clock.uptimeMillis());
        assertEquals(10000, clock.uptimeMillis());
        checkRunCounts.invoke(0, 0, 0, 0);
        checkRunCounts.invoke(0, 0, 0, 0);


        fakeExecutor.execute(runnableA);
        fakeExecutor.execute(runnableA);
@@ -227,8 +227,8 @@ public class FakeExecutorTest extends SysuiTestCase {


        fakeExecutor.execute(runnableA);
        fakeExecutor.execute(runnableA);
        fakeExecutor.executeAtTime(runnableB, 0);  // this is in the past!
        fakeExecutor.executeAtTime(runnableB, 0);  // this is in the past!
        fakeExecutor.executeAtTime(runnableC, 1000);
        fakeExecutor.executeAtTime(runnableC, 11000);
        fakeExecutor.executeAtTime(runnableD, 500);
        fakeExecutor.executeAtTime(runnableD, 10500);


        fakeExecutor.advanceClockToNext();
        fakeExecutor.advanceClockToNext();
        fakeExecutor.runAllReady();
        fakeExecutor.runAllReady();
Loading