From e7f8555d956c8bf5f338a182d8023b2740edc389 Mon Sep 17 00:00:00 2001 From: Joshua Trask Date: Mon, 13 Mar 2023 12:28:41 +0000 Subject: Allow refinement of caller-provided chooser targets More specifically, this provides refinement behavior for any `SelectableTargetInfo` targets that weren't joined to a `DisplayResolveInfo` in our intent-resolution step. AFAIK this is only for the caller's `EXTRA_CHOOSER_TARGETS`. CTS coverage is provided by the pending ag/21973239 (in the same topic as this CL). Bug: 271149302 Test: `atest CtsSharesheetDeviceTest`. New `testChooserTargetsRefinement` (pending in the same topic) exercises the fix from this CL, or fails without that fix. Change-Id: Ie7772953e63fe69dfe080f75eb73ac795693b1ad --- .../intentresolver/chooser/SelectableTargetInfo.java | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'java/src') diff --git a/java/src/com/android/intentresolver/chooser/SelectableTargetInfo.java b/java/src/com/android/intentresolver/chooser/SelectableTargetInfo.java index e8847edc..74c19e67 100644 --- a/java/src/com/android/intentresolver/chooser/SelectableTargetInfo.java +++ b/java/src/com/android/intentresolver/chooser/SelectableTargetInfo.java @@ -195,13 +195,13 @@ public final class SelectableTargetInfo extends ChooserTargetInfo { mResolvedComponentName = getResolvedComponentName(mSourceInfo, mBackupResolveInfo); - mAllSourceIntents = getAllSourceIntents(sourceInfo); - mBaseIntentToSend = getBaseIntentToSend( baseIntentToSend, mResolvedIntent, mReferrerFillInIntent); + mAllSourceIntents = getAllSourceIntents(sourceInfo, mBaseIntentToSend); + mHashProvider = context -> { final String plaintext = getChooserTargetComponentName().getPackageName() @@ -395,12 +395,24 @@ public final class SelectableTargetInfo extends ChooserTargetInfo { return sb.toString(); } - private static List getAllSourceIntents(@Nullable DisplayResolveInfo sourceInfo) { + private static List getAllSourceIntents( + @Nullable DisplayResolveInfo sourceInfo, Intent fallbackSourceIntent) { final List results = new ArrayList<>(); if (sourceInfo != null) { results.addAll(sourceInfo.getAllSourceIntents()); + } else { + // This target wasn't joined to a `DisplayResolveInfo` result from our intent-resolution + // step, so it was provided directly by the caller. We don't support alternate intents + // in this case, but we still permit refinement of the intent we'll dispatch; e.g., + // clients may use this hook to defer the computation of "lazy" extras in their share + // payload. Note this accommodation isn't strictly "necessary" because clients could + // always implement equivalent behavior by pointing custom targets back at their own app + // for any amount of further refinement/modification outside of the Sharesheet flow; + // nevertheless, it's offered as a convenience for clients who may expect their normal + // refinement logic to apply equally in the case of these "special targets." + results.add(fallbackSourceIntent); } - return results; // TODO: just use our own intent if there's no sourceInfo? + return results; } private static ComponentName getResolvedComponentName( -- cgit v1.2.3-59-g8ed1b