package org.robolectric.android.fakes;

import android.app.Activity;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import androidx.test.runner.MonitoringInstrumentation;
import org.robolectric.Robolectric;
import org.robolectric.android.controller.ActivityController;

public class RoboMonitoringInstrumentation extends MonitoringInstrumentation {

  @Override
  protected void specifyDexMakerCacheProperty() {
    // ignore, unnecessary for robolectric
  }

  @Override
  protected void installMultidex() {
    // ignore, unnecessary for robolectric
  }

  @Override
  public void setInTouchMode(boolean inTouch) {
    // ignore
  }

  @Override
  public void waitForIdleSync() {
    // ignore
  }

  @Override
  public Activity startActivitySync(final Intent intent) {
    ActivityInfo ai = intent.resolveActivityInfo(getTargetContext().getPackageManager(), 0);
    try {
      Class<? extends Activity> activityClass = Class.forName(ai.name).asSubclass(Activity.class);
      ActivityController<? extends Activity> controller = Robolectric.buildActivity(activityClass, intent);
      Activity activity = controller.get();
      callActivityOnCreate(activity, null);
      controller.postCreate(null);
      callActivityOnStart(activity);
      callActivityOnResume(activity);
      controller.visible().windowFocusChanged(true);
      return activity;
    } catch (ClassNotFoundException e) {
      throw new RuntimeException("Could not load activity " + ai.name, e);
    }
  }

  @Override
  public void runOnMainSync(Runnable runner) {
    runner.run();
  }
}

@@ -285,16 +285,61 @@
 troller;
+%0Aimport org.robolectric.shadows.ShadowLooper;
 %0A%0Apublic
@@ -744,33 +744,66 @@
 ync() %7B%0A    
-// ignore
+ShadowLooper.getShadowMainLooper().idle();
 %0A  %7D%0A%0A  @Ove

Call through to ShadowLooper on Instrumentation.waitForIdleSync