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

Unverified Commit 67fde062 authored by Michael Bestas's avatar Michael Bestas
Browse files

fixup! SystemUI: screenshot: open long screenshot activity for partial screenshots

Change-Id: I718cb0d8516d72d55fd439b132c27e6edc81158c
parent 2919024a
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -776,6 +776,12 @@ public interface WindowManager extends ViewManager {
     */
    int TAKE_SCREENSHOT_FULLSCREEN = 1;

    /**
     * Invoke screenshot flow allowing the user to select a region.
     * @hide
     */
    int TAKE_SCREENSHOT_SELECTED_REGION = 2;

    /**
     * Invoke screenshot flow with an image provided by the caller.
     * @hide
@@ -788,6 +794,7 @@ public interface WindowManager extends ViewManager {
     * @hide
     */
    @IntDef({TAKE_SCREENSHOT_FULLSCREEN,
            TAKE_SCREENSHOT_SELECTED_REGION,
            TAKE_SCREENSHOT_PROVIDED_IMAGE})
    @interface ScreenshotType {}

+7 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.internal.util;

import static android.view.WindowManager.TAKE_SCREENSHOT_FULLSCREEN;
import static android.view.WindowManager.TAKE_SCREENSHOT_SELECTED_REGION;

import static junit.framework.Assert.assertNull;
import static junit.framework.Assert.fail;
@@ -83,6 +84,12 @@ public final class ScreenshotHelperTest {
                WindowManager.ScreenshotSource.SCREENSHOT_OTHER, mHandler, null);
    }

    @Test
    public void testSelectedRegionScreenshot() {
        mScreenshotHelper.takeScreenshot(TAKE_SCREENSHOT_SELECTED_REGION,
                WindowManager.ScreenshotSource.SCREENSHOT_OTHER, mHandler, null);
    }

    @Test
    public void testProvidedImageScreenshot() {
        mScreenshotHelper.provideScreenshot(
+16 −4
Original line number Diff line number Diff line
@@ -473,6 +473,17 @@ public class ScreenshotController {
                showFlash, UserHandle.of(userId));
    }

    /**
     * Displays a screenshot selector
     */
    @MainThread
    void takeScreenshotPartial(ComponentName topComponent,
            final Consumer<Uri> finisher, RequestCallback requestCallback) {
        Assert.isMainThread();
        startPartialScreenshotActivity(Process.myUserHandle());
        finisher.accept(null);
    }

    /**
     * Clears current screenshot
     */
@@ -773,7 +784,8 @@ public class ScreenshotController {
                onScrollCaptureResponseReady(future, owner), mMainExecutor);
    }

    public void startLongScreenshotActivity(ScrollCaptureController.LongScreenshot longScreenshot) {
    public void startLongScreenshotActivity(ScrollCaptureController.LongScreenshot longScreenshot,
            UserHandle owner) {
        mLongScreenshotHolder.setLongScreenshot(longScreenshot);
        mLongScreenshotHolder.setTransitionDestinationCallback(
                (transitionDestination, onTransitionEnd) -> {
@@ -811,14 +823,14 @@ public class ScreenshotController {
        }
    }

    private void startPartialScreenshotActivity() {
    private void startPartialScreenshotActivity(UserHandle owner) {
        Bitmap newScreenshot = captureScreenshot();

        ScrollCaptureController.BitmapScreenshot bitmapScreenshot =
            new ScrollCaptureController.BitmapScreenshot(mContext, newScreenshot);

        mLongScreenshotHolder.setNeedsMagnification(false);
        startLongScreenshotActivity(bitmapScreenshot);
        startLongScreenshotActivity(bitmapScreenshot, owner);
    }

    private void onScrollCaptureResponseReady(Future<ScrollCaptureResponse> responseFuture,
@@ -889,7 +901,7 @@ public class ScreenshotController {

            mLongScreenshotHolder.setForegroundAppName(getForegroundAppLabel());
            mLongScreenshotHolder.setNeedsMagnification(true);
            startLongScreenshotActivity(longScreenshot);
            startLongScreenshotActivity(longScreenshot, owner);
        }, mMainExecutor);
    }

+6 −0
Original line number Diff line number Diff line
@@ -248,6 +248,12 @@ public class TakeScreenshotService extends Service {
                }
                mScreenshot.takeScreenshotFullscreen(topComponent, uriConsumer, callback);
                break;
            case WindowManager.TAKE_SCREENSHOT_SELECTED_REGION:
                if (DEBUG_SERVICE) {
                    Log.d(TAG, "handleMessage: TAKE_SCREENSHOT_SELECTED_REGION");
                }
                mScreenshot.takeScreenshotPartial(topComponent, uriConsumer, callback);
                break;
            case WindowManager.TAKE_SCREENSHOT_PROVIDED_IMAGE:
                if (DEBUG_SERVICE) {
                    Log.d(TAG, "handleMessage: TAKE_SCREENSHOT_PROVIDED_IMAGE");
+61 −0
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import android.view.WindowManager.ScreenshotSource.SCREENSHOT_KEY_CHORD
import android.view.WindowManager.ScreenshotSource.SCREENSHOT_OTHER
import android.view.WindowManager.TAKE_SCREENSHOT_FULLSCREEN
import android.view.WindowManager.TAKE_SCREENSHOT_PROVIDED_IMAGE
import android.view.WindowManager.TAKE_SCREENSHOT_SELECTED_REGION
import com.android.internal.util.ScreenshotHelper.HardwareBitmapBundler
import com.android.internal.util.ScreenshotHelper.HardwareBitmapBundler.bundleToHardwareBitmap
import com.android.internal.util.ScreenshotHelper.ScreenshotRequest
@@ -139,6 +140,66 @@ class RequestProcessorTest {
        assertThat(processedRequest.topComponent).isEqualTo(component)
    }

    @Test
    fun testSelectedRegionScreenshot_workProfilePolicyDisabled() = runBlocking {
        flags.set(Flags.SCREENSHOT_WORK_PROFILE_POLICY, false)

        val request = ScreenshotRequest(TAKE_SCREENSHOT_SELECTED_REGION, SCREENSHOT_KEY_CHORD)
        val processor = RequestProcessor(imageCapture, policy, flags, scope)

        val processedRequest = processor.process(request)

        // No changes
        assertThat(processedRequest).isEqualTo(request)
     }

    @Test
    fun testSelectedRegionScreenshot() = runBlocking {
        flags.set(Flags.SCREENSHOT_WORK_PROFILE_POLICY, true)

        val request = ScreenshotRequest(TAKE_SCREENSHOT_SELECTED_REGION, SCREENSHOT_KEY_CHORD)
        val processor = RequestProcessor(imageCapture, policy, flags, scope)

        policy.setManagedProfile(USER_ID, false)
        policy.setDisplayContentInfo(policy.getDefaultDisplayId(),
            DisplayContentInfo(component, bounds, UserHandle.of(USER_ID), TASK_ID))

        val processedRequest = processor.process(request)

        // Request has topComponent added, but otherwise unchanged.
        assertThat(processedRequest.type).isEqualTo(TAKE_SCREENSHOT_FULLSCREEN)
        assertThat(processedRequest.topComponent).isEqualTo(component)
    }

    @Test
    fun testSelectedRegionScreenshot_managedProfile() = runBlocking {
        flags.set(Flags.SCREENSHOT_WORK_PROFILE_POLICY, true)

        // Provide a fake task bitmap when asked
        val bitmap = makeHardwareBitmap(100, 100)
        imageCapture.image = bitmap

        val request = ScreenshotRequest(TAKE_SCREENSHOT_SELECTED_REGION, SCREENSHOT_KEY_CHORD)
        val processor = RequestProcessor(imageCapture, policy, flags, scope)

        // Indicate that the primary content belongs to a manged profile
        policy.setManagedProfile(USER_ID, true)
        policy.setDisplayContentInfo(policy.getDefaultDisplayId(),
            DisplayContentInfo(component, bounds, UserHandle.of(USER_ID), TASK_ID))

        val processedRequest = processor.process(request)

        // Expect a task snapshot is taken, overriding the selected region mode
        assertThat(processedRequest.type).isEqualTo(TAKE_SCREENSHOT_PROVIDED_IMAGE)
        assertThat(bitmap.equalsHardwareBitmapBundle(processedRequest.bitmapBundle)).isTrue()
        assertThat(processedRequest.boundsInScreen).isEqualTo(bounds)
        assertThat(processedRequest.insets).isEqualTo(Insets.NONE)
        assertThat(processedRequest.taskId).isEqualTo(TASK_ID)
        assertThat(imageCapture.requestedTaskId).isEqualTo(TASK_ID)
        assertThat(processedRequest.userId).isEqualTo(USER_ID)
        assertThat(processedRequest.topComponent).isEqualTo(component)
    }

    @Test
    fun testProvidedImageScreenshot_workProfilePolicyDisabled() = runBlocking {
        flags.set(Flags.SCREENSHOT_WORK_PROFILE_POLICY, false)
Loading