1 package org.robolectric.android.internal;
2 
3 import static org.robolectric.Shadows.shadowOf;
4 import static org.robolectric.util.ReflectionHelpers.ClassParameter.from;
5 
6 import android.view.View;
7 import android.view.ViewRootImpl;
8 import android.os.Looper;
9 import androidx.test.internal.platform.os.ControlledLooper;
10 import org.robolectric.util.ReflectionHelpers;
11 
12 public class LocalControlledLooper implements ControlledLooper {
13 
14   @Override
drainMainThreadUntilIdle()15   public void drainMainThreadUntilIdle() {
16     shadowOf(Looper.getMainLooper()).idle();
17   }
18 
19   @Override
simulateWindowFocus(View decorView)20   public void simulateWindowFocus(View decorView) {
21     ViewRootImpl viewRoot = ReflectionHelpers.callInstanceMethod(decorView, "getViewRootImpl");
22     if (viewRoot != null) {
23       ReflectionHelpers.callInstanceMethod(
24           viewRoot,
25           "windowFocusChanged",
26           from(boolean.class, true), /* hasFocus */
27           from(boolean.class, false) /* inTouchMode */);
28     }
29   }
30 }
31