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

Commit 96294a8a authored by Matt Casey's avatar Matt Casey Committed by Android (Google) Code Review
Browse files

Merge "Disallow long screenshots on low-memory devices" into sc-dev

parents ce9883b6 8de060aa
Loading
Loading
Loading
Loading
+13 −1
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ import static java.util.Objects.requireNonNull;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.annotation.Nullable;
import android.app.ActivityManager;
import android.app.ActivityOptions;
import android.app.ExitTransitionCoordinator;
import android.app.ExitTransitionCoordinator.ExitTransitionCallbacks;
@@ -253,6 +254,7 @@ public class ScreenshotController {
    private final DisplayManager mDisplayManager;
    private final ScrollCaptureController mScrollCaptureController;
    private final LongScreenshotData mLongScreenshotHolder;
    private final boolean mIsLowRamDevice;

    private ScreenshotView mScreenshotView;
    private Bitmap mScreenBitmap;
@@ -297,7 +299,8 @@ public class ScreenshotController {
            ImageExporter imageExporter,
            @Main Executor mainExecutor,
            ScrollCaptureController scrollCaptureController,
            LongScreenshotData longScreenshotHolder) {
            LongScreenshotData longScreenshotHolder,
            ActivityManager activityManager) {
        mScreenshotSmartActions = screenshotSmartActions;
        mNotificationsController = screenshotNotificationsController;
        mScrollCaptureClient = scrollCaptureClient;
@@ -306,6 +309,7 @@ public class ScreenshotController {
        mMainExecutor = mainExecutor;
        mScrollCaptureController = scrollCaptureController;
        mLongScreenshotHolder = longScreenshotHolder;
        mIsLowRamDevice = activityManager.isLowRamDevice();
        mBgExecutor = Executors.newSingleThreadExecutor();

        mDisplayManager = requireNonNull(context.getSystemService(DisplayManager.class));
@@ -621,6 +625,10 @@ public class ScreenshotController {
    }

    private void requestScrollCapture() {
        if (!allowLongScreenshots()) {
            Log.d(TAG, "Long screenshots not supported on this device");
            return;
        }
        mScrollCaptureClient.setHostWindowToken(mWindow.getDecorView().getWindowToken());
        if (mLastScrollCaptureRequest != null) {
            mLastScrollCaptureRequest.cancel(true);
@@ -982,6 +990,10 @@ public class ScreenshotController {
        return mDisplayManager.getDisplay(DEFAULT_DISPLAY);
    }

    private boolean allowLongScreenshots() {
        return !mIsLowRamDevice;
    }

    /** Does the aspect ratio of the bitmap with insets removed match the bounds. */
    private static boolean aspectRatiosMatch(Bitmap bitmap, Insets bitmapInsets,
            Rect screenBounds) {