Commit c1e3cb76 by tonihei Committed by Oliver Woodman

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
parent 41026495
......@@ -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);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment