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

Unverified Commit 6520016e authored by Timi Rautamäki's avatar Timi Rautamäki Committed by Michael Bestas
Browse files

SystemUI: screenshot: open the screenshot instead of edit

Open the taken screenshot in gallery application when clicking on the
preview. There is a seperate edit button, so the preview imageview
should open gallery instead.

Test: atest com.android.systemui.screenshot.ScreenshotNotificationSmartActionsTest
Change-Id: I8f882ddd0da47ca50acc37d25ee0866ce5698e4f
parent add9f4dc
Loading
Loading
Loading
Loading
+10 −3
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.systemui.screenshot;

import static com.android.systemui.screenshot.ScreenshotController.ACTION_TYPE_EDIT;
import static com.android.systemui.screenshot.ScreenshotController.ACTION_TYPE_SHARE;
import static com.android.systemui.screenshot.ScreenshotController.ACTION_TYPE_VIEW;
import static com.android.systemui.screenshot.ScreenshotController.EXTRA_ACTION_INTENT;
import static com.android.systemui.screenshot.ScreenshotController.EXTRA_DISALLOW_ENTER_PIP;
import static com.android.systemui.screenshot.ScreenshotController.EXTRA_ID;
@@ -97,9 +98,15 @@ public class ActionProxyReceiver extends BroadcastReceiver {
                true /* deferred */);

        if (intent.getBooleanExtra(EXTRA_SMART_ACTIONS_ENABLED, false)) {
            String actionType = Intent.ACTION_EDIT.equals(intent.getAction())
                    ? ACTION_TYPE_EDIT
                    : ACTION_TYPE_SHARE;
            String action = intent.getAction();
            String actionType;
            if (Intent.ACTION_VIEW.equals(action)) {
                actionType = ACTION_TYPE_VIEW;
            } else if (Intent.ACTION_EDIT.equals(action)) {
                actionType = ACTION_TYPE_EDIT;
            } else {
                actionType = ACTION_TYPE_SHARE;
            }
            mScreenshotSmartActions.notifyScreenshotAction(
                    intent.getStringExtra(EXTRA_ID), actionType, false, null);
        }
+49 −0
Original line number Diff line number Diff line
@@ -175,6 +175,8 @@ class SaveImageInBackgroundTask extends AsyncTask<Void, Void, Void> {
            mImageData.uri = uri;
            mImageData.owner = mParams.owner;
            mImageData.smartActions = smartActions;
            mImageData.viewTransition = createViewAction(mContext, mContext.getResources(), uri,
                    smartActionsEnabled);
            mImageData.shareTransition = createShareAction(mContext, mContext.getResources(), uri,
                    smartActionsEnabled);
            mImageData.editTransition = createEditAction(mContext, mContext.getResources(), uri,
@@ -233,6 +235,53 @@ class SaveImageInBackgroundTask extends AsyncTask<Void, Void, Void> {
        mParams.clearImage();
    }

    @VisibleForTesting
    Supplier<ActionTransition> createViewAction(Context context, Resources r, Uri uri,
            boolean smartActionsEnabled) {
        return () -> {
            ActionTransition transition = mSharedElementTransition.get();

            // Note: the view, share and edit actions are proxied through ActionProxyReceiver in
            // order to do some common work like dismissing the keyguard and sending
            // closeSystemWindows

            // Create a view intent, if a specific package is provided as the viewer, then
            // launch that directly
            Intent viewIntent = new Intent(Intent.ACTION_VIEW);
            viewIntent.setDataAndType(uri, "image/png");
            viewIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            viewIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);

            PendingIntent pendingIntent = PendingIntent.getActivityAsUser(
                    context, 0, viewIntent, PendingIntent.FLAG_IMMUTABLE,
                    transition.bundle, UserHandle.CURRENT);

            // Make sure pending intents for the system user are still unique across users
            // by setting the (otherwise unused) request code to the current user id.
            int requestCode = mContext.getUserId();

            // Create a view action
            PendingIntent viewAction = PendingIntent.getBroadcastAsUser(context, requestCode,
                    new Intent(context, ActionProxyReceiver.class)
                            .putExtra(ScreenshotController.EXTRA_ACTION_INTENT, pendingIntent)
                            .putExtra(ScreenshotController.EXTRA_ID, mScreenshotId)
                            .putExtra(ScreenshotController.EXTRA_SMART_ACTIONS_ENABLED,
                                    smartActionsEnabled)
                            .putExtra(ScreenshotController.EXTRA_OVERRIDE_TRANSITION, true)
                            .setAction(Intent.ACTION_VIEW)
                            .addFlags(Intent.FLAG_RECEIVER_FOREGROUND),
                    PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_IMMUTABLE,
                    UserHandle.SYSTEM);
            Notification.Action.Builder editActionBuilder = new Notification.Action.Builder(
                    Icon.createWithResource(r, com.android.internal.R.drawable.ic_screenshot),
                    r.getString(com.android.internal.R.string.global_action_screenshot),
                    viewAction);

            transition.action = editActionBuilder.build();
            return transition;
        };
    }

    /**
     * Assumes that the action intent is sent immediately after being supplied.
     */
+2 −0
Original line number Diff line number Diff line
@@ -174,6 +174,7 @@ public class ScreenshotController {
     */
    static class SavedImageData {
        public Uri uri;
        public Supplier<ActionTransition> viewTransition;
        public Supplier<ActionTransition> shareTransition;
        public Supplier<ActionTransition> editTransition;
        public Notification.Action deleteAction;
@@ -240,6 +241,7 @@ public class ScreenshotController {
    // ScreenshotNotificationSmartActionsProvider.
    static final String EXTRA_ACTION_TYPE = "android:screenshot_action_type";
    static final String EXTRA_ID = "android:screenshot_id";
    static final String ACTION_TYPE_VIEW = "View";
    static final String ACTION_TYPE_DELETE = "Delete";
    static final String ACTION_TYPE_SHARE = "Share";
    static final String ACTION_TYPE_EDIT = "Edit";
+1 −1
Original line number Diff line number Diff line
@@ -817,7 +817,7 @@ public class ScreenshotView extends FrameLayout implements
            prepareSharedTransition();
            mActionExecutor.launchIntentAsync(
                    ActionIntentCreator.INSTANCE.createEdit(imageData.uri, mContext),
                    imageData.editTransition.get().bundle,
                    imageData.viewTransition.get().bundle,
                    imageData.owner, true);
        });
        if (mQuickShareChip != null) {
+28 −0
Original line number Diff line number Diff line
@@ -167,6 +167,34 @@ public class ScreenshotNotificationSmartActionsTest extends SysuiTestCase {
        assertEquals(smartActions.size(), 0);
    }

    // Tests for view action extras
    @Test
    public void testViewActionExtras() {
        if (Looper.myLooper() == null) {
            Looper.prepare();
        }

        ScreenshotController.SaveImageInBackgroundData
                data = new ScreenshotController.SaveImageInBackgroundData();
        data.image = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
        data.finisher = null;
        data.mActionsReadyListener = null;
        SaveImageInBackgroundTask task =
                new SaveImageInBackgroundTask(mContext, null, null, mScreenshotSmartActions, data,
                        ActionTransition::new, mSmartActionsProvider);

        Notification.Action viewAction = task.createViewAction(mContext, mContext.getResources(),
                Uri.parse("Screenshot_123.png"), true).get().action;

        Intent intent = viewAction.actionIntent.getIntent();
        assertNotNull(intent);
        Bundle bundle = intent.getExtras();
        assertTrue(bundle.containsKey(ScreenshotController.EXTRA_ID));
        assertTrue(bundle.containsKey(ScreenshotController.EXTRA_SMART_ACTIONS_ENABLED));
        assertEquals(ScreenshotController.ACTION_TYPE_VIEW, viewAction.title);
        assertEquals(Intent.ACTION_VIEW, intent.getAction());
    }

    // Tests for share action extras
    @Test
    public void testShareActionExtras() {