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

Commit c3436bdd authored by Matt Casey's avatar Matt Casey
Browse files

Disable screenshot actions for work profile.

Additional work will be needed to ensure intent launching works properly
for these, defering that to post-launch.

Behavior changes all protected by the flag SCREENSHOT_WORK_PROFILE_POLICY
but had to move the smartActionsEnabled computation to be passed around instead
of an instance variable (so it could honor the new constraint).

Bug: 258706103
Test: Validate that actions work in personal profile but not work
      profile
Test: atest ScreenshotNotificationSmartActionsTest
Change-Id: I08b6c50f98cdf38287b6dadb9dde563f57af5dc2
parent ed19f58a
Loading
Loading
Loading
Loading
+32 −19
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ import android.graphics.drawable.Icon;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Process;
import android.os.RemoteException;
import android.os.UserHandle;
import android.os.UserManager;
@@ -81,7 +82,6 @@ class SaveImageInBackgroundTask extends AsyncTask<Void, Void, Void> {

    private final ScreenshotNotificationSmartActionsProvider mSmartActionsProvider;
    private String mScreenshotId;
    private final boolean mSmartActionsEnabled;
    private final Random mRandom = new Random();
    private final Supplier<ActionTransition> mSharedElementTransition;
    private final ImageExporter mImageExporter;
@@ -109,8 +109,6 @@ class SaveImageInBackgroundTask extends AsyncTask<Void, Void, Void> {
        mParams = data;

        // Initialize screenshot notification smart actions provider.
        mSmartActionsEnabled = DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_SYSTEMUI,
                SystemUiDeviceConfigFlags.ENABLE_SCREENSHOT_NOTIFICATION_SMART_ACTIONS, true);
        mSmartActionsProvider = screenshotNotificationSmartActionsProvider;
    }

@@ -131,8 +129,16 @@ class SaveImageInBackgroundTask extends AsyncTask<Void, Void, Void> {

        Bitmap image = mParams.image;
        mScreenshotId = String.format(SCREENSHOT_ID_TEMPLATE, requestId);

        boolean savingToOtherUser = mFlags.isEnabled(Flags.SCREENSHOT_WORK_PROFILE_POLICY)
                && (user != Process.myUserHandle());
        // Smart actions don't yet work for cross-user saves.
        boolean smartActionsEnabled = !savingToOtherUser
                && DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_SYSTEMUI,
                SystemUiDeviceConfigFlags.ENABLE_SCREENSHOT_NOTIFICATION_SMART_ACTIONS,
                true);
        try {
            if (mSmartActionsEnabled && mParams.mQuickShareActionsReadyListener != null) {
            if (smartActionsEnabled && mParams.mQuickShareActionsReadyListener != null) {
                // Since Quick Share target recommendation does not rely on image URL, it is
                // queried and surfaced before image compress/export. Action intent would not be
                // used, because it does not contain image URL.
@@ -150,10 +156,9 @@ class SaveImageInBackgroundTask extends AsyncTask<Void, Void, Void> {
            CompletableFuture<List<Notification.Action>> smartActionsFuture =
                    mScreenshotSmartActions.getSmartActionsFuture(
                            mScreenshotId, uri, image, mSmartActionsProvider, REGULAR_SMART_ACTIONS,
                            mSmartActionsEnabled, user);

                            smartActionsEnabled, user);
            List<Notification.Action> smartActions = new ArrayList<>();
            if (mSmartActionsEnabled) {
            if (smartActionsEnabled) {
                int timeoutMs = DeviceConfig.getInt(
                        DeviceConfig.NAMESPACE_SYSTEMUI,
                        SystemUiDeviceConfigFlags.SCREENSHOT_NOTIFICATION_SMART_ACTIONS_TIMEOUT_MS,
@@ -168,9 +173,12 @@ class SaveImageInBackgroundTask extends AsyncTask<Void, Void, Void> {
            mImageData.uri = uri;
            mImageData.owner = user;
            mImageData.smartActions = smartActions;
            mImageData.shareTransition = createShareAction(mContext, mContext.getResources(), uri);
            mImageData.editTransition = createEditAction(mContext, mContext.getResources(), uri);
            mImageData.deleteAction = createDeleteAction(mContext, mContext.getResources(), uri);
            mImageData.shareTransition = createShareAction(mContext, mContext.getResources(), uri,
                    smartActionsEnabled);
            mImageData.editTransition = createEditAction(mContext, mContext.getResources(), uri,
                    smartActionsEnabled);
            mImageData.deleteAction = createDeleteAction(mContext, mContext.getResources(), uri,
                    smartActionsEnabled);
            mImageData.quickShareAction = createQuickShareAction(mContext,
                    mQuickShareData.quickShareAction, uri);
            mImageData.subject = getSubjectString();
@@ -228,7 +236,8 @@ class SaveImageInBackgroundTask extends AsyncTask<Void, Void, Void> {
     * Assumes that the action intent is sent immediately after being supplied.
     */
    @VisibleForTesting
    Supplier<ActionTransition> createShareAction(Context context, Resources r, Uri uri) {
    Supplier<ActionTransition> createShareAction(Context context, Resources r, Uri uri,
            boolean smartActionsEnabled) {
        return () -> {
            ActionTransition transition = mSharedElementTransition.get();

@@ -274,7 +283,7 @@ class SaveImageInBackgroundTask extends AsyncTask<Void, Void, Void> {
                            .putExtra(ScreenshotController.EXTRA_DISALLOW_ENTER_PIP, true)
                            .putExtra(ScreenshotController.EXTRA_ID, mScreenshotId)
                            .putExtra(ScreenshotController.EXTRA_SMART_ACTIONS_ENABLED,
                                    mSmartActionsEnabled)
                                    smartActionsEnabled)
                            .setAction(Intent.ACTION_SEND)
                            .addFlags(Intent.FLAG_RECEIVER_FOREGROUND),
                    PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_IMMUTABLE,
@@ -290,7 +299,8 @@ class SaveImageInBackgroundTask extends AsyncTask<Void, Void, Void> {
    }

    @VisibleForTesting
    Supplier<ActionTransition> createEditAction(Context context, Resources r, Uri uri) {
    Supplier<ActionTransition> createEditAction(Context context, Resources r, Uri uri,
            boolean smartActionsEnabled) {
        return () -> {
            ActionTransition transition = mSharedElementTransition.get();
            // Note: Both the share and edit actions are proxied through ActionProxyReceiver in
@@ -323,7 +333,7 @@ class SaveImageInBackgroundTask extends AsyncTask<Void, Void, Void> {
                            .putExtra(ScreenshotController.EXTRA_ACTION_INTENT, pendingIntent)
                            .putExtra(ScreenshotController.EXTRA_ID, mScreenshotId)
                            .putExtra(ScreenshotController.EXTRA_SMART_ACTIONS_ENABLED,
                                    mSmartActionsEnabled)
                                    smartActionsEnabled)
                            .putExtra(ScreenshotController.EXTRA_OVERRIDE_TRANSITION, true)
                            .setAction(Intent.ACTION_EDIT)
                            .addFlags(Intent.FLAG_RECEIVER_FOREGROUND),
@@ -339,7 +349,8 @@ class SaveImageInBackgroundTask extends AsyncTask<Void, Void, Void> {
    }

    @VisibleForTesting
    Notification.Action createDeleteAction(Context context, Resources r, Uri uri) {
    Notification.Action createDeleteAction(Context context, Resources r, Uri uri,
            boolean smartActionsEnabled) {
        // 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();
@@ -350,7 +361,7 @@ class SaveImageInBackgroundTask extends AsyncTask<Void, Void, Void> {
                        .putExtra(ScreenshotController.SCREENSHOT_URI_ID, uri.toString())
                        .putExtra(ScreenshotController.EXTRA_ID, mScreenshotId)
                        .putExtra(ScreenshotController.EXTRA_SMART_ACTIONS_ENABLED,
                                mSmartActionsEnabled)
                                smartActionsEnabled)
                        .addFlags(Intent.FLAG_RECEIVER_FOREGROUND),
                PendingIntent.FLAG_CANCEL_CURRENT
                        | PendingIntent.FLAG_ONE_SHOT
@@ -391,7 +402,7 @@ class SaveImageInBackgroundTask extends AsyncTask<Void, Void, Void> {
            Intent intent = new Intent(context, SmartActionsReceiver.class)
                    .putExtra(ScreenshotController.EXTRA_ACTION_INTENT, action.actionIntent)
                    .addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
            addIntentExtras(mScreenshotId, intent, actionType, mSmartActionsEnabled);
            addIntentExtras(mScreenshotId, intent, actionType, true /* smartActionsEnabled */);
            PendingIntent broadcastIntent = PendingIntent.getBroadcast(context,
                    mRandom.nextInt(),
                    intent,
@@ -445,7 +456,9 @@ class SaveImageInBackgroundTask extends AsyncTask<Void, Void, Void> {
        Intent intent = new Intent(context, SmartActionsReceiver.class)
                .putExtra(ScreenshotController.EXTRA_ACTION_INTENT, updatedPendingIntent)
                .addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
        addIntentExtras(mScreenshotId, intent, actionType, mSmartActionsEnabled);
        // We only query for quick share actions when smart actions are enabled, so we can assert
        // that it's true here.
        addIntentExtras(mScreenshotId, intent, actionType, true /* smartActionsEnabled */);
        PendingIntent broadcastIntent = PendingIntent.getBroadcast(context,
                mRandom.nextInt(),
                intent,
@@ -464,7 +477,7 @@ class SaveImageInBackgroundTask extends AsyncTask<Void, Void, Void> {
                mScreenshotSmartActions.getSmartActionsFuture(
                        mScreenshotId, null, image, mSmartActionsProvider,
                        QUICK_SHARE_ACTION,
                        mSmartActionsEnabled, user);
                        true /* smartActionsEnabled */, user);
        int timeoutMs = DeviceConfig.getInt(
                DeviceConfig.NAMESPACE_SYSTEMUI,
                SystemUiDeviceConfigFlags.SCREENSHOT_NOTIFICATION_QUICK_SHARE_ACTIONS_TIMEOUT_MS,
+3 −3
Original line number Diff line number Diff line
@@ -184,7 +184,7 @@ public class ScreenshotNotificationSmartActionsTest extends SysuiTestCase {
                        ActionTransition::new, mSmartActionsProvider);

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

        Intent intent = shareAction.actionIntent.getIntent();
        assertNotNull(intent);
@@ -212,7 +212,7 @@ public class ScreenshotNotificationSmartActionsTest extends SysuiTestCase {
                        ActionTransition::new, mSmartActionsProvider);

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

        Intent intent = editAction.actionIntent.getIntent();
        assertNotNull(intent);
@@ -241,7 +241,7 @@ public class ScreenshotNotificationSmartActionsTest extends SysuiTestCase {

        Notification.Action deleteAction = task.createDeleteAction(mContext,
                mContext.getResources(),
                Uri.parse("Screenshot_123.png"));
                Uri.parse("Screenshot_123.png"), true);

        Intent intent = deleteAction.actionIntent.getIntent();
        assertNotNull(intent);