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
This commit is contained in:
tonihei 2018-04-30 06:45:47 -07:00 committed by Oliver Woodman
parent 410264954f
commit c1e3cb767e

View file

@ -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);
}
}