public static void setAttachInfo(View view) {
    if (sAttachInfo == null) {
      sAttachInfo = generateAttachInfo(view);
    }

    try {
      Method dispatch =
          View.class.getDeclaredMethod(
              "dispatchAttachedToWindow", Class.forName("android.view.View$AttachInfo"), int.class);
      dispatch.setAccessible(true);
      dispatch.invoke(view, sAttachInfo, 0);
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
  }
Similar to dispatchAttach, except dispatchest the corresponding detach.
core/src/main/java/com/facebook/testing/screenshot/WindowAttachment.java