From 05fddff84ff2255c4acb6579306c4c0d5f9b182f Mon Sep 17 00:00:00 2001 From: tonihei Date: Tue, 2 Feb 2021 09:29:00 +0000 Subject: [PATCH] Modernize bandwidth profile simulator. Main improvement is to switch away from ExoPlayerTestRunner and to split out the waiting component so that the same class can be used from Robolectric tests in the future. The only functional difference is that that BufferLengthLogAction is removed completely because the data isn't used downstream and the method of collecting this data is a bit arbitrary. PiperOrigin-RevId: 355117850 --- .../google/android/exoplayer2/testutil/FakeClock.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/testutils/src/main/java/com/google/android/exoplayer2/testutil/FakeClock.java b/testutils/src/main/java/com/google/android/exoplayer2/testutil/FakeClock.java index 629729bd23..7bce01f5ce 100644 --- a/testutils/src/main/java/com/google/android/exoplayer2/testutil/FakeClock.java +++ b/testutils/src/main/java/com/google/android/exoplayer2/testutil/FakeClock.java @@ -17,6 +17,7 @@ package com.google.android.exoplayer2.testutil; import static com.google.android.exoplayer2.util.Assertions.checkNotNull; +import android.os.Build; import android.os.Handler; import android.os.Handler.Callback; import android.os.Looper; @@ -50,6 +51,7 @@ public class FakeClock implements Clock { private static long messageIdProvider = 0; + private final boolean isRobolectric; private final boolean isAutoAdvancing; @GuardedBy("this") @@ -105,7 +107,10 @@ public class FakeClock implements Clock { this.isAutoAdvancing = isAutoAdvancing; this.handlerMessages = new ArrayList<>(); this.busyLoopers = new HashSet<>(); - SystemClock.setCurrentTimeMillis(initialTimeMs); + this.isRobolectric = "robolectric".equals(Build.FINGERPRINT); + if (isRobolectric) { + SystemClock.setCurrentTimeMillis(initialTimeMs); + } } /** @@ -245,7 +250,9 @@ public class FakeClock implements Clock { private synchronized void advanceTimeInternal(long timeDiffMs) { timeSinceBootMs += timeDiffMs; - SystemClock.setCurrentTimeMillis(timeSinceBootMs); + if (isRobolectric) { + SystemClock.setCurrentTimeMillis(timeSinceBootMs); + } } private static synchronized long getNextMessageId() {