diff options
| author | 2023-06-07 16:50:57 +0000 | |
|---|---|---|
| committer | 2023-06-09 14:49:40 +0000 | |
| commit | 7cbff193529acbfbccce1d270127cd889c65b68c (patch) | |
| tree | 011b086f2bac5cd23720287089220bf7f4450cd3 /java | |
| parent | 5d76bc638c7d3617af573dcba981e30b8b477123 (diff) | |
Move two params to ResolverActivity.onCreate()
Namely, this is the data that subclasses previously configured by
calling up to `ResolverActivity.setSafeForwardingMode()` and
`ResolverActivity.setAdditionalTargets()`.
Both parameters are constant within a session (even though we still
don't have a great place to hold them as `final`) -- and both can
affect the behavior of `ResolverActivity.onCreate()`, so it's
important that we have the data prepared for that call (and,
especially in the case of "additional targets" it's not necessarily
clear what would happen if we made additional changes afterward).
Chooser was already setting these at the right time, but this makes
the dependency explicit and prevents accidental misuse.
This is a pure refactoring that trivially has no side effects in the
IntentResolver codebase. The API change in ResolverActivity would
break other subclasses (if they were depending on the IntentResolver
fork instead of the framework version), but that's not relevant right
now, and besides, the only client that would seem to be broken is
CarResolverActivity, which currently uses these APIs incorrectly.
Test: IntentResolverUnitTests, CtsSharesheetDeviceTest
Bug: 286249609
Change-Id: I7309a4fb33244cfac20c8dffc81e738a91381904
Diffstat (limited to 'java')
| -rw-r--r-- | java/src/com/android/intentresolver/ChooserActivity.java | 12 | ||||
| -rw-r--r-- | java/src/com/android/intentresolver/ResolverActivity.java | 98 |
2 files changed, 57 insertions, 53 deletions
diff --git a/java/src/com/android/intentresolver/ChooserActivity.java b/java/src/com/android/intentresolver/ChooserActivity.java index a2dff970..f5558a00 100644 --- a/java/src/com/android/intentresolver/ChooserActivity.java +++ b/java/src/com/android/intentresolver/ChooserActivity.java @@ -286,10 +286,6 @@ public class ChooserActivity extends ResolverActivity implements mEnterTransitionAnimationDelegate, new HeadlineGeneratorImpl(this)); - setAdditionalTargets(mChooserRequest.getAdditionalTargets()); - - setSafeForwardingMode(true); - mPinnedSharedPrefs = getPinnedSharedPrefs(this); mMaxTargetsPerRow = getResources().getInteger(R.integer.config_chooser_max_targets_per_row); @@ -307,12 +303,14 @@ public class ChooserActivity extends ResolverActivity implements super.onCreate( savedInstanceState, mChooserRequest.getTargetIntent(), + mChooserRequest.getAdditionalTargets(), mChooserRequest.getTitle(), mChooserRequest.getDefaultTitleResource(), mChooserRequest.getInitialIntents(), - /* rList: List<ResolveInfo> = */ null, - /* supportsAlwaysUseOption = */ false, - new DefaultTargetDataLoader(this, getLifecycle(), false)); + /* resolutionList= */ null, + /* supportsAlwaysUseOption= */ false, + new DefaultTargetDataLoader(this, getLifecycle(), false), + /* safeForwardingMode= */ true); mChooserShownTime = System.currentTimeMillis(); final long systemCost = mChooserShownTime - intentReceivedTime; diff --git a/java/src/com/android/intentresolver/ResolverActivity.java b/java/src/com/android/intentresolver/ResolverActivity.java index 57871532..f6637d0f 100644 --- a/java/src/com/android/intentresolver/ResolverActivity.java +++ b/java/src/com/android/intentresolver/ResolverActivity.java @@ -119,6 +119,7 @@ import com.android.internal.util.LatencyTracker; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.Iterator; import java.util.List; import java.util.Objects; @@ -143,7 +144,14 @@ public class ResolverActivity extends FragmentActivity implements mIsIntentPicker = isIntentPicker; } + /** + * Whether to enable a launch mode that is safe to use when forwarding intents received from + * applications and running in system processes. This mode uses Activity.startActivityAsCaller + * instead of the normal Activity.startActivity for launching the activity selected + * by the user. + */ private boolean mSafeForwardingMode; + private Button mAlwaysButton; private Button mOnceButton; protected View mProfileView; @@ -332,38 +340,55 @@ public class ResolverActivity extends FragmentActivity implements mResolvingHome = true; } - setSafeForwardingMode(true); - - onCreate(savedInstanceState, intent, null, 0, null, null, true, createIconLoader()); + onCreate( + savedInstanceState, + intent, + /* additionalTargets= */ null, + /* title= */ null, + /* defaultTitleRes= */ 0, + /* initialIntents= */ null, + /* resolutionList= */ null, + /* supportsAlwaysUseOption= */ true, + createIconLoader(), + /* safeForwardingMode= */ true); } /** * Compatibility version for other bundled services that use this overload without * a default title resource */ - protected void onCreate(Bundle savedInstanceState, Intent intent, - CharSequence title, Intent[] initialIntents, - List<ResolveInfo> rList, boolean supportsAlwaysUseOption) { + protected void onCreate( + Bundle savedInstanceState, + Intent intent, + CharSequence title, + Intent[] initialIntents, + List<ResolveInfo> resolutionList, + boolean supportsAlwaysUseOption, + boolean safeForwardingMode) { onCreate( savedInstanceState, intent, + null, title, 0, initialIntents, - rList, + resolutionList, supportsAlwaysUseOption, - createIconLoader()); + createIconLoader(), + safeForwardingMode); } protected void onCreate( Bundle savedInstanceState, Intent intent, + Intent[] additionalTargets, CharSequence title, int defaultTitleRes, Intent[] initialIntents, - List<ResolveInfo> rList, + List<ResolveInfo> resolutionList, boolean supportsAlwaysUseOption, - TargetDataLoader targetDataLoader) { + TargetDataLoader targetDataLoader, + boolean safeForwardingMode) { setTheme(appliedThemeResId()); super.onCreate(savedInstanceState); @@ -381,12 +406,17 @@ public class ResolverActivity extends FragmentActivity implements mReferrerPackage = getReferrerPackageName(); - // Add our initial intent as the first item, regardless of what else has already been added. + // The initial intent must come before any other targets that are to be added. mIntents.add(0, new Intent(intent)); + if (additionalTargets != null) { + Collections.addAll(mIntents, additionalTargets); + } + mTitle = title; mDefaultTitleResId = defaultTitleRes; mSupportsAlwaysUseOption = supportsAlwaysUseOption; + mSafeForwardingMode = safeForwardingMode; // The last argument of createResolverListAdapter is whether to do special handling // of the last used choice to highlight it in the list. We need to always @@ -399,7 +429,7 @@ public class ResolverActivity extends FragmentActivity implements boolean filterLastUsed = mSupportsAlwaysUseOption && !isVoiceInteraction() && !shouldShowTabs() && !hasCloneProfile(); mMultiProfilePagerAdapter = createMultiProfilePagerAdapter( - initialIntents, rList, filterLastUsed, targetDataLoader); + initialIntents, resolutionList, filterLastUsed, targetDataLoader); if (configureContentView(targetDataLoader)) { return; } @@ -455,17 +485,17 @@ public class ResolverActivity extends FragmentActivity implements protected AbstractMultiProfilePagerAdapter createMultiProfilePagerAdapter( Intent[] initialIntents, - List<ResolveInfo> rList, + List<ResolveInfo> resolutionList, boolean filterLastUsed, TargetDataLoader targetDataLoader) { AbstractMultiProfilePagerAdapter resolverMultiProfilePagerAdapter = null; if (shouldShowTabs()) { resolverMultiProfilePagerAdapter = createResolverMultiProfilePagerAdapterForTwoProfiles( - initialIntents, rList, filterLastUsed, targetDataLoader); + initialIntents, resolutionList, filterLastUsed, targetDataLoader); } else { resolverMultiProfilePagerAdapter = createResolverMultiProfilePagerAdapterForOneProfile( - initialIntents, rList, filterLastUsed, targetDataLoader); + initialIntents, resolutionList, filterLastUsed, targetDataLoader); } return resolverMultiProfilePagerAdapter; } @@ -1043,7 +1073,7 @@ public class ResolverActivity extends FragmentActivity implements Context context, List<Intent> payloadIntents, Intent[] initialIntents, - List<ResolveInfo> rList, + List<ResolveInfo> resolutionList, boolean filterLastUsed, UserHandle userHandle, TargetDataLoader targetDataLoader) { @@ -1054,7 +1084,7 @@ public class ResolverActivity extends FragmentActivity implements context, payloadIntents, initialIntents, - rList, + resolutionList, filterLastUsed, createListController(userHandle), userHandle, @@ -1142,14 +1172,14 @@ public class ResolverActivity extends FragmentActivity implements private ResolverMultiProfilePagerAdapter createResolverMultiProfilePagerAdapterForOneProfile( Intent[] initialIntents, - List<ResolveInfo> rList, + List<ResolveInfo> resolutionList, boolean filterLastUsed, TargetDataLoader targetDataLoader) { ResolverListAdapter adapter = createResolverListAdapter( /* context */ this, /* payloadIntents */ mIntents, initialIntents, - rList, + resolutionList, filterLastUsed, /* userHandle */ getPersonalProfileUserHandle(), targetDataLoader); @@ -1170,7 +1200,7 @@ public class ResolverActivity extends FragmentActivity implements private ResolverMultiProfilePagerAdapter createResolverMultiProfilePagerAdapterForTwoProfiles( Intent[] initialIntents, - List<ResolveInfo> rList, + List<ResolveInfo> resolutionList, boolean filterLastUsed, TargetDataLoader targetDataLoader) { // In the edge case when we have 0 apps in the current profile and >1 apps in the other, @@ -1197,7 +1227,7 @@ public class ResolverActivity extends FragmentActivity implements /* context */ this, /* payloadIntents */ mIntents, selectedProfile == PROFILE_PERSONAL ? initialIntents : null, - rList, + resolutionList, (filterLastUsed && UserHandle.myUserId() == getPersonalProfileUserHandle().getIdentifier()), /* userHandle */ getPersonalProfileUserHandle(), @@ -1207,7 +1237,7 @@ public class ResolverActivity extends FragmentActivity implements /* context */ this, /* payloadIntents */ mIntents, selectedProfile == PROFILE_WORK ? initialIntents : null, - rList, + resolutionList, (filterLastUsed && UserHandle.myUserId() == workProfileUserHandle.getIdentifier()), /* userHandle */ workProfileUserHandle, @@ -1365,14 +1395,6 @@ public class ResolverActivity extends FragmentActivity implements return new Option(target.getDisplayLabel(), index); } - protected final void setAdditionalTargets(Intent[] intents) { - if (intents != null) { - for (Intent intent : intents) { - mIntents.add(intent); - } - } - } - public final Intent getTargetIntent() { return mIntents.isEmpty() ? null : mIntents.get(0); } @@ -1433,22 +1455,6 @@ public class ResolverActivity extends FragmentActivity implements () -> getString(R.string.forward_intent_to_work)); } - /** - * Turn on launch mode that is safe to use when forwarding intents received from - * applications and running in system processes. This mode uses Activity.startActivityAsCaller - * instead of the normal Activity.startActivity for launching the activity selected - * by the user. - * - * <p>This mode is set to true by default if the activity is initialized through - * {@link #onCreate(android.os.Bundle)}. If a subclass calls one of the other onCreate - * methods, it is set to false by default. You must set it before calling one of the - * more detailed onCreate methods, so that it will be set correctly in the case where - * there is only one intent to resolve and it is thus started immediately.</p> - */ - public final void setSafeForwardingMode(boolean safeForwarding) { - mSafeForwardingMode = safeForwarding; - } - protected final CharSequence getTitleForAction(Intent intent, int defaultTitleRes) { final ActionTitle title = mResolvingHome ? ActionTitle.HOME |