private void storeBitmap(final RecordBuilderImpl recordBuilder) {
    if (recordBuilder.getTiling().getAt(0, 0) != null || recordBuilder.getError() != null) {
      return;
    }

    if (!isUiThread()) {
      runCallableOnUiThread(
          new Callable<Void>() {
            @Override
            public Void call() {
              storeBitmap(recordBuilder);
              return null;
            }
          });
      return;
    }

    View measuredView = recordBuilder.getView();
    if (measuredView.getMeasuredHeight() == 0 || measuredView.getMeasuredWidth() == 0) {
      throw new RuntimeException("Can't take a screenshot, since this view is not measured");
    }

    WindowAttachment.Detacher detacher = WindowAttachment.dispatchAttach(measuredView);
    try {
      int width = measuredView.getWidth();
      int height = measuredView.getHeight();

      assertNotTooLarge(width, height, recordBuilder);

      int maxi = (width + mTileSize - 1) / mTileSize;
      int maxj = (height + mTileSize - 1) / mTileSize;
      recordBuilder.setTiling(new Tiling(maxi, maxj));

      for (int i = 0; i < maxi; i++) {
        for (int j = 0; j < maxj; j++) {
          drawTile(measuredView, i, j, recordBuilder);
        }
      }
    } catch (IOException e) {
      throw new RuntimeException(e);
    } finally {
      detacher.detach();
    }
  }
Snaps a screenshot of the view (which should already be measured and layouted) using testName
as the name.
core/src/main/java/com/facebook/testing/screenshot/internal/ScreenshotImpl.java