diff options
| author | 2023-03-09 22:01:50 +0000 | |
|---|---|---|
| committer | 2023-03-13 16:16:31 +0000 | |
| commit | 7c05ee5c8b7c934776d1c74a558f29dadde5ee9d (patch) | |
| tree | ece043b5a82ae2acc54cd763e78c15a2a90aa4de /java/src | |
| parent | f86a0bde4809b63efd2db49bfa0aa59cc4c96b35 (diff) | |
Switch EXTRA_MODIFY_SHARE from PendingIntent to ChooserAction
Honor the label provided in the action.
Bug: 272008339
Test: atest IntentResolverUnitTests
Test: atest CtsSharesheetDeviceTest
Change-Id: I48f9bb46f1be1f8ab42a93169b4c5ab332cd8400
Diffstat (limited to 'java/src')
4 files changed, 37 insertions, 41 deletions
diff --git a/java/src/com/android/intentresolver/ChooserActionFactory.java b/java/src/com/android/intentresolver/ChooserActionFactory.java index 947155f3..1cadd314 100644 --- a/java/src/com/android/intentresolver/ChooserActionFactory.java +++ b/java/src/com/android/intentresolver/ChooserActionFactory.java @@ -97,7 +97,7 @@ public final class ChooserActionFactory implements ChooserContentPreviewUi.Actio private final TargetInfo mNearbySharingTarget; private final Runnable mOnNearbyButtonClicked; private final ImmutableList<ChooserAction> mCustomActions; - private final Runnable mOnModifyShareClicked; + private final @Nullable ChooserAction mModifyShareAction; private final Consumer<Boolean> mExcludeSharedTextAction; private final Consumer</* @Nullable */ Integer> mFinishCallback; private final ChooserActivityLogger mLogger; @@ -162,10 +162,7 @@ public final class ChooserActionFactory implements ChooserContentPreviewUi.Actio logger), chooserRequest.getChooserActions(), (featureFlagRepository.isEnabled(Flags.SHARESHEET_RESELECTION_ACTION) - ? createModifyShareRunnable( - chooserRequest.getModifyShareAction(), - finishCallback, - logger) + ? chooserRequest.getModifyShareAction() : null), onUpdateSharedTextIsExcluded, logger, @@ -183,7 +180,7 @@ public final class ChooserActionFactory implements ChooserContentPreviewUi.Actio TargetInfo nearbySharingTarget, Runnable onNearbyButtonClicked, List<ChooserAction> customActions, - @Nullable Runnable onModifyShareClicked, + @Nullable ChooserAction modifyShareAction, Consumer<Boolean> onUpdateSharedTextIsExcluded, ChooserActivityLogger logger, Consumer</* @Nullable */ Integer> finishCallback) { @@ -196,7 +193,7 @@ public final class ChooserActionFactory implements ChooserContentPreviewUi.Actio mNearbySharingTarget = nearbySharingTarget; mOnNearbyButtonClicked = onNearbyButtonClicked; mCustomActions = ImmutableList.copyOf(customActions); - mOnModifyShareClicked = onModifyShareClicked; + mModifyShareAction = modifyShareAction; mExcludeSharedTextAction = onUpdateSharedTextIsExcluded; mLogger = logger; mFinishCallback = finishCallback; @@ -247,8 +244,15 @@ public final class ChooserActionFactory implements ChooserContentPreviewUi.Actio public List<ActionRow.Action> createCustomActions() { List<ActionRow.Action> actions = new ArrayList<>(); for (int i = 0; i < mCustomActions.size(); i++) { + final int position = i; ActionRow.Action actionRow = createCustomAction( - mContext, mCustomActions.get(i), mFinishCallback, i, mLogger); + mContext, + mCustomActions.get(i), + mFinishCallback, + () -> { + mLogger.logCustomActionSelected(position); + } + ); if (actionRow != null) { actions.add(actionRow); } @@ -261,27 +265,14 @@ public final class ChooserActionFactory implements ChooserContentPreviewUi.Actio */ @Override @Nullable - public Runnable getModifyShareAction() { - return mOnModifyShareClicked; - } - - private static Runnable createModifyShareRunnable( - PendingIntent pendingIntent, - Consumer<Integer> finishCallback, - ChooserActivityLogger logger) { - if (pendingIntent == null) { - return null; - } - - return () -> { - try { - pendingIntent.send(); - } catch (PendingIntent.CanceledException e) { - Log.d(TAG, "Payload reselection action has been cancelled"); - } - logger.logActionSelected(ChooserActivityLogger.SELECTION_TYPE_MODIFY_SHARE); - finishCallback.accept(Activity.RESULT_OK); - }; + public ActionRow.Action getModifyShareAction() { + return createCustomAction( + mContext, + mModifyShareAction, + mFinishCallback, + () -> { + mLogger.logActionSelected(ChooserActivityLogger.SELECTION_TYPE_MODIFY_SHARE); + }); } /** @@ -481,8 +472,10 @@ public final class ChooserActionFactory implements ChooserContentPreviewUi.Actio Context context, ChooserAction action, Consumer<Integer> finishCallback, - int position, - ChooserActivityLogger logger) { + Runnable loggingRunnable) { + if (action == null || action.getAction() == null) { + return null; + } Drawable icon = action.getIcon().loadDrawable(context); if (icon == null && TextUtils.isEmpty(action.getLabel())) { return null; @@ -507,7 +500,9 @@ public final class ChooserActionFactory implements ChooserContentPreviewUi.Actio } catch (PendingIntent.CanceledException e) { Log.d(TAG, "Custom action, " + action.getLabel() + ", has been cancelled"); } - logger.logCustomActionSelected(position); + if (loggingRunnable != null) { + loggingRunnable.run(); + } finishCallback.accept(Activity.RESULT_OK); } ); diff --git a/java/src/com/android/intentresolver/ChooserRequestParameters.java b/java/src/com/android/intentresolver/ChooserRequestParameters.java index 3d99e475..948fe4cd 100644 --- a/java/src/com/android/intentresolver/ChooserRequestParameters.java +++ b/java/src/com/android/intentresolver/ChooserRequestParameters.java @@ -18,7 +18,6 @@ package com.android.intentresolver; import android.annotation.NonNull; import android.annotation.Nullable; -import android.app.PendingIntent; import android.content.ComponentName; import android.content.Intent; import android.content.IntentFilter; @@ -78,7 +77,7 @@ public class ChooserRequestParameters { private final ImmutableList<ComponentName> mFilteredComponentNames; private final ImmutableList<ChooserTarget> mCallerChooserTargets; private final @NonNull ImmutableList<ChooserAction> mChooserActions; - private final PendingIntent mModifyShareAction; + private final ChooserAction mModifyShareAction; private final boolean mRetainInOnStop; @Nullable @@ -204,7 +203,7 @@ public class ChooserRequestParameters { } @Nullable - public PendingIntent getModifyShareAction() { + public ChooserAction getModifyShareAction() { return mModifyShareAction; } @@ -353,11 +352,11 @@ public class ChooserRequestParameters { } @Nullable - private static PendingIntent getModifyShareAction(Intent intent) { + private static ChooserAction getModifyShareAction(Intent intent) { try { return intent.getParcelableExtra( Intent.EXTRA_CHOOSER_MODIFY_SHARE_ACTION, - PendingIntent.class); + ChooserAction.class); } catch (Throwable t) { Log.w( TAG, diff --git a/java/src/com/android/intentresolver/contentpreview/ChooserContentPreviewUi.java b/java/src/com/android/intentresolver/contentpreview/ChooserContentPreviewUi.java index 205be444..8cc747bf 100644 --- a/java/src/com/android/intentresolver/contentpreview/ChooserContentPreviewUi.java +++ b/java/src/com/android/intentresolver/contentpreview/ChooserContentPreviewUi.java @@ -74,7 +74,7 @@ public final class ChooserContentPreviewUi { * Provides a share modification action, if any. */ @Nullable - Runnable getModifyShareAction(); + ActionRow.Action getModifyShareAction(); /** * <p> diff --git a/java/src/com/android/intentresolver/contentpreview/ContentPreviewUi.java b/java/src/com/android/intentresolver/contentpreview/ContentPreviewUi.java index 39856e66..96f1c376 100644 --- a/java/src/com/android/intentresolver/contentpreview/ContentPreviewUi.java +++ b/java/src/com/android/intentresolver/contentpreview/ContentPreviewUi.java @@ -30,6 +30,7 @@ import android.view.View; import android.view.ViewGroup; import android.view.ViewStub; import android.view.animation.DecelerateInterpolator; +import android.widget.TextView; import androidx.annotation.LayoutRes; @@ -117,13 +118,14 @@ abstract class ContentPreviewUi { ViewGroup layout, ChooserContentPreviewUi.ActionFactory actionFactory, FeatureFlagRepository featureFlagRepository) { - Runnable modifyShareAction = actionFactory.getModifyShareAction(); + ActionRow.Action modifyShareAction = actionFactory.getModifyShareAction(); if (modifyShareAction != null && layout != null && featureFlagRepository.isEnabled(Flags.SHARESHEET_RESELECTION_ACTION)) { - View modifyShareView = layout.findViewById(R.id.reselection_action); + TextView modifyShareView = layout.findViewById(R.id.reselection_action); if (modifyShareView != null) { + modifyShareView.setText(modifyShareAction.getLabel()); modifyShareView.setVisibility(View.VISIBLE); - modifyShareView.setOnClickListener(view -> modifyShareAction.run()); + modifyShareView.setOnClickListener(view -> modifyShareAction.getOnClicked().run()); } } } |