Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3ace0147 authored by Mark Renouf's avatar Mark Renouf
Browse files

Long screenshots: allow adjusting the max capture size

Adjusts max capture size in multiples of page size

example:
  adb shell settings put secure screenshot.scroll_max_pages 3.5

Bug: 179378294
Test: manual, adjust setting, capture long screenshot
Change-Id: Id95e80ff333f8e39c07a59701b4b9f27d59ee5c9
parent cb077ba6
Loading
Loading
Loading
Loading
+11 −8
Original line number Diff line number Diff line
@@ -50,8 +50,6 @@ import javax.inject.Inject;
public class ScrollCaptureClient {
    private static final int TILE_SIZE_PX_MAX = 4 * (1024 * 1024);
    private static final int TILES_PER_PAGE = 2; // increase once b/174571735 is addressed
    private static final float MAX_PAGES = 3f;
    private static final int MAX_IMAGE_COUNT = (int) Math.ceil(MAX_PAGES * TILES_PER_PAGE);

    @VisibleForTesting
    static final int MATCH_ANY_TASK = ActivityTaskManager.INVALID_TASK_ID;
@@ -66,10 +64,11 @@ public class ScrollCaptureClient {
        /**
         * Session start should be deferred until UI is active because of resource allocation and
         * potential visible side effects in the target window.

         *
         * @param sessionConsumer listener to receive the session once active
         * @param maxPages the capture buffer size expressed as a multiple of the content height
         */
        void start(Consumer<Session> sessionConsumer);
        void start(Consumer<Session> sessionConsumer, float maxPages);

        /**
         * Close the connection.
@@ -196,6 +195,7 @@ public class ScrollCaptureClient {
        private int mTileWidth;
        private Rect mRequestRect;
        private boolean mStarted;
        private int mMaxTiles;

        private ControllerCallbacks(Consumer<Connection> connectionConsumer) {
            mConnectionConsumer = connectionConsumer;
@@ -285,12 +285,15 @@ public class ScrollCaptureClient {
        // ScrollCaptureController.Connection

        @Override
        public void start(Consumer<Session> sessionConsumer) {
        public void start(Consumer<Session> sessionConsumer, float maxPages) {
            if (DEBUG_SCROLL) {
                Log.d(TAG, "start(sessionConsumer=" + sessionConsumer + ")");
                Log.d(TAG, "start(sessionConsumer=" + sessionConsumer + ","
                        + " maxPages=" + maxPages + ")"
                        + " [maxHeight: " + (mMaxTiles * mTileHeight) + "px]");
            }
            mMaxTiles = (int) Math.ceil(maxPages * TILES_PER_PAGE);
            mReader = ImageReader.newInstance(mTileWidth, mTileHeight, PixelFormat.RGBA_8888,
                    MAX_IMAGE_COUNT, HardwareBuffer.USAGE_GPU_SAMPLED_IMAGE);
                    mMaxTiles, HardwareBuffer.USAGE_GPU_SAMPLED_IMAGE);
            mSessionConsumer = sessionConsumer;
            try {
                mConnection.startCapture(mReader.getSurface());
@@ -345,7 +348,7 @@ public class ScrollCaptureClient {

        @Override
        public int getMaxTiles() {
            return MAX_IMAGE_COUNT;
            return mMaxTiles;
        }

        @Override
+7 −1
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import android.content.Intent;
import android.graphics.Rect;
import android.net.Uri;
import android.os.UserHandle;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
@@ -51,6 +52,9 @@ import java.util.concurrent.Executor;
 */
public class ScrollCaptureController implements OnComputeInternalInsetsListener {
    private static final String TAG = "ScrollCaptureController";
    private static final float MAX_PAGES_DEFAULT = 3f;

    private static final String SETTING_KEY_MAX_PAGES = "screenshot.scroll_max_pages";

    private static final int UP = -1;
    private static final int DOWN = 1;
@@ -136,7 +140,9 @@ public class ScrollCaptureController implements OnComputeInternalInsetsListener
        mEdit.setOnClickListener(this::onClicked);
        mShare.setOnClickListener(this::onClicked);

        mConnection.start(this::startCapture);
        float maxPages = Settings.Secure.getFloat(mContext.getContentResolver(),
                SETTING_KEY_MAX_PAGES, MAX_PAGES_DEFAULT);
        mConnection.start(this::startCapture, maxPages);
    }


+3 −1
Original line number Diff line number Diff line
@@ -57,6 +57,8 @@ import org.mockito.stubbing.Answer;
@SmallTest
@RunWith(AndroidTestingRunner.class)
public class ScrollCaptureClientTest extends SysuiTestCase {
    private static final float MAX_PAGES = 3f;

    private Context mContext;
    private IWindowManager mWm;

@@ -96,7 +98,7 @@ public class ScrollCaptureClientTest extends SysuiTestCase {

        Connection conn = mConnectionConsumer.getValue();

        conn.start(mSessionConsumer);
        conn.start(mSessionConsumer, MAX_PAGES);
        verify(mSessionConsumer, timeout(100)).accept(any(Session.class));

        Session session = mSessionConsumer.getValue();