docs: @Override
    @SuppressWarnings("deprecation")
    public byte[] takeScreenshot() {
      ViewHierarchyAnalyzer viewAnalyzer = ViewHierarchyAnalyzer.getDefaultInstance();
  
      // TODO ddary review later, but with getRecentDecorView() it seems to work better
      // long drawingTime = 0;
      // View container = null;
      // for (View view : viewAnalyzer.getTopLevelViews()) {
      // if (view != null && view.isShown() && view.hasWindowFocus()
      // && view.getDrawingTime() > drawingTime) {
      // container = view;
      // drawingTime = view.getDrawingTime();
      // }
      // }
      // final View mainView = container;
      final View mainView = viewAnalyzer.getRecentDecorView();
      if (mainView == null) {
        throw new SelendroidException("No open windows.");
      }
      done = false;
      long end =
          System.currentTimeMillis() + serverInstrumentation.getAndroidWait().getTimeoutInMillis();
      final byte[][] rawPng = new byte[1][1];
      serverInstrumentation.getCurrentActivity().runOnUiThread(new Runnable() {
        public void run() {
          synchronized (syncObject) {
            Display display =
                serverInstrumentation.getCurrentActivity().getWindowManager().getDefaultDisplay();
            Point size = new Point();
            try {
              display.getSize(size);
            } catch (NoSuchMethodError ignore) { // Older than api level 13
              size.x = display.getWidth();
              size.y = display.getHeight();
            }
  
            // Get root view
            View view = mainView.getRootView();
  
            // Create the bitmap to use to draw the screenshot
            final Bitmap bitmap = Bitmap.createBitmap(size.x, size.y, Bitmap.Config.ARGB_8888);
            final Canvas canvas = new Canvas(bitmap);
  
            // Get current theme to know which background to use
            final Activity activity = serverInstrumentation.getCurrentActivity();
            final Theme theme = activity.getTheme();
            final TypedArray ta =
                theme.obtainStyledAttributes(new int[] {android.R.attr.windowBackground});
            final int res = ta.getResourceId(0, 0);
            final Drawable background = activity.getResources().getDrawable(res);
  
            // Draw background
            background.draw(canvas);
  
            // Draw views
            view.draw(canvas);
  
            ByteArrayOutputStream stream = new ByteArrayOutputStream();
            if (!bitmap.compress(Bitmap.CompressFormat.PNG, 70, stream)) {
              throw new RuntimeException("Error while compressing screenshot image.");
            }
            try {
              stream.flush();
              stream.close();
            } catch (IOException e) {
              throw new RuntimeException("I/O Error while capturing screenshot: " + e.getMessage());
            } finally {
              Closeable closeable = (Closeable) stream;
              try {
                if (closeable != null) {
                  closeable.close();
                }
              } catch (IOException ioe) {
                // ignore
              }
            }
            rawPng[0] = stream.toByteArray();
            mainView.destroyDrawingCache();
            done = true;
            syncObject.notify();
          }
        }
      });
  
      waitForDone(end, serverInstrumentation.getAndroidWait().getTimeoutInMillis(),
          "Failed to take screenshot.");
      return rawPng[0];
    }