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

Commit 67a8d6ed authored by Mohammed Althaf T's avatar Mohammed Althaf T 😊
Browse files

Merge branch '5558-r-screenshot_modify' into 'v1-r'

base: Enable support for editing screenshot after taken

See merge request e/os/android_frameworks_base!127
parents 92416c78 7f3da493
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.GlobalScreenshot.ACTION_TYPE_EDIT;
import static com.android.systemui.screenshot.GlobalScreenshot.ACTION_TYPE_SHARE;
import static com.android.systemui.screenshot.GlobalScreenshot.ACTION_TYPE_VIEW;
import static com.android.systemui.screenshot.GlobalScreenshot.EXTRA_ACTION_INTENT;
import static com.android.systemui.screenshot.GlobalScreenshot.EXTRA_DISALLOW_ENTER_PIP;
import static com.android.systemui.screenshot.GlobalScreenshot.EXTRA_ID;
@@ -95,9 +96,15 @@ public class ActionProxyReceiver extends BroadcastReceiver {
        }

        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(
                    context, intent.getStringExtra(EXTRA_ID), actionType, false);
        }
+3 −1
Original line number Diff line number Diff line
@@ -133,6 +133,7 @@ public class GlobalScreenshot implements ViewTreeObserver.OnComputeInternalInset
     */
    static class SavedImageData {
        public Uri uri;
        public Notification.Action viewAction;
        public Notification.Action shareAction;
        public Notification.Action editAction;
        public Notification.Action deleteAction;
@@ -161,6 +162,7 @@ public class GlobalScreenshot implements ViewTreeObserver.OnComputeInternalInset
    static final String ACTION_TYPE_DELETE = "Delete";
    static final String ACTION_TYPE_SHARE = "Share";
    static final String ACTION_TYPE_EDIT = "Edit";
    static final String ACTION_TYPE_VIEW = "View";
    static final String EXTRA_SMART_ACTIONS_ENABLED = "android:smart_actions_enabled";
    static final String EXTRA_ACTION_INTENT = "android:screenshot_action_intent";

@@ -1080,7 +1082,7 @@ public class GlobalScreenshot implements ViewTreeObserver.OnComputeInternalInset

        mScreenshotPreview.setOnClickListener(v -> {
            try {
                imageData.editAction.actionIntent.send();
                imageData.viewAction.actionIntent.send();
                mUiEventLogger.log(ScreenshotEvent.SCREENSHOT_PREVIEW_TAPPED);
                dismissScreenshot("screenshot preview tapped", false);
                mOnCompleteRunnable.run();
+42 −0
Original line number Diff line number Diff line
@@ -221,6 +221,7 @@ class SaveImageInBackgroundTask extends AsyncTask<Void, Void, Void> {

            mImageData.uri = uri;
            mImageData.smartActions = smartActions;
            mImageData.viewAction = createViewAction(mContext, mContext.getResources(), uri);
            mImageData.shareAction = createShareAction(mContext, mContext.getResources(), uri);
            mImageData.editAction = createEditAction(mContext, mContext.getResources(), uri);
            mImageData.deleteAction = createDeleteAction(mContext, mContext.getResources(), uri);
@@ -262,6 +263,47 @@ class SaveImageInBackgroundTask extends AsyncTask<Void, Void, Void> {
        mParams.clearImage();
    }

    @VisibleForTesting
    Notification.Action createViewAction(Context context, Resources r, Uri uri) {
        // 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 an edit intent, if a specific package is provided as the editor, then
        // launch that directly
        Intent viewIntent = new Intent(Intent.ACTION_VIEW);
        viewIntent.setDataAndType(uri, "image/png");
        viewIntent.putExtra("from-snapcam", true);
        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,
                null, 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(GlobalScreenshot.EXTRA_ACTION_INTENT, pendingIntent)
                        .putExtra(GlobalScreenshot.EXTRA_ID, mScreenshotId)
                        .putExtra(GlobalScreenshot.EXTRA_SMART_ACTIONS_ENABLED,
                                mSmartActionsEnabled)
                        .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);

        return editActionBuilder.build();
    }

    @VisibleForTesting
    Notification.Action createShareAction(Context context, Resources r, Uri uri) {
        // Note: Both the share and edit actions are proxied through ActionProxyReceiver in
+28 −0
Original line number Diff line number Diff line
@@ -162,6 +162,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();
        }

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

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

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

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