Also fix thread blocking nullness assertion when called from non-Looper

PiperOrigin-RevId: 354268013
This commit is contained in:
tonihei 2021-01-28 09:55:09 +00:00 committed by Oliver Woodman
parent 60f3d8168c
commit ae51e2e1d1

View File

@ -140,6 +140,11 @@ public class FakeClock implements Clock {
@Override @Override
public synchronized void onThreadBlocked() { public synchronized void onThreadBlocked() {
@Nullable Looper currentLooper = Looper.myLooper();
if (currentLooper == null || !waitingForMessage) {
// This isn't a looper message created by this class, so no need to handle the blocking.
return;
}
busyLoopers.add(checkNotNull(Looper.myLooper())); busyLoopers.add(checkNotNull(Looper.myLooper()));
waitingForMessage = false; waitingForMessage = false;
maybeTriggerMessage(); maybeTriggerMessage();