From c1e3cb767eeca3379563ee05793feebaaf1220dc Mon Sep 17 00:00:00 2001 From: tonihei Date: Mon, 30 Apr 2018 06:45:47 -0700 Subject: [PATCH] Don't forward main looper messages to custom looper. Our current custom looper implementation tries to handle all messages including those sent to the main looper. However, the main looper does not use our doLoop implementation and thus messages never get executed. This adds a check whether the target looper is the main looper and if so, uses the default message forwarding implementation. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=194779214 --- .../google/android/exoplayer2/testutil/RobolectricUtil.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/testutils_robolectric/src/main/java/com/google/android/exoplayer2/testutil/RobolectricUtil.java b/testutils_robolectric/src/main/java/com/google/android/exoplayer2/testutil/RobolectricUtil.java index e606fd104b..0d5d4e4437 100644 --- a/testutils_robolectric/src/main/java/com/google/android/exoplayer2/testutil/RobolectricUtil.java +++ b/testutils_robolectric/src/main/java/com/google/android/exoplayer2/testutil/RobolectricUtil.java @@ -156,8 +156,10 @@ public final class RobolectricUtil { @Override public boolean enqueueMessage(Message msg, long when) { ShadowLooper looper = shadowOf(ShadowLooper.getLooperForThread(looperThread)); - if (looper instanceof CustomLooper) { + if (looper instanceof CustomLooper && looper != ShadowLooper.getShadowMainLooper()) { ((CustomLooper) looper).addPendingMessage(msg, when); + } else { + super.enqueueMessage(msg, when); } return true; } @@ -165,7 +167,7 @@ public final class RobolectricUtil { @Implementation public void removeMessages(Handler handler, int what, Object object) { ShadowLooper looper = shadowOf(ShadowLooper.getLooperForThread(looperThread)); - if (looper instanceof CustomLooper) { + if (looper instanceof CustomLooper && looper != ShadowLooper.getShadowMainLooper()) { ((CustomLooper) looper).removeMessages(handler, what, object); } }