in core/src/main/java/com/facebook/testing/screenshot/WindowAttachment.java [69:94]
public static Detacher dispatchAttach(View view) {
if (view.getWindowToken() != null || sAttachments.containsKey(view)) {
// Screenshot tests can often be run against a View that's
// attached to a real activity, in which case we have nothing to
// do
Log.i("WindowAttachment", "Skipping window attach hack since it's really attached");
return new NoopDetacher();
}
sAttachments.put(view, true);
if (Build.VERSION.SDK_INT < 23) {
// On older versions of Android, requesting focus on a view that would bring the
// soft keyboard up prior to attachment would result in a NPE in the view's onAttachedToWindow
// callback. This is due to the fact that it internally calls
// InputMethodManager.peekInstance() to
// grab the singleton instance, however it isn't created at that point, leading to the NPE.
// So in order to avoid that, we just grab the InputMethodManager from the view's context
// ahead of time to ensure the instance exists.
// https://android.googlesource.com/platform/frameworks/base/+/a046faaf38ad818e6b5e981a39fd7394cf7cee03
view.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
}
sAttachInfo = generateAttachInfo(view);
setAttachInfo(view);
return new RealDetacher(view);
}