From df71f480dee389192a080fba6fe417f83506b33b Mon Sep 17 00:00:00 2001 From: Mark Renouf Date: Tue, 13 Feb 2024 13:55:54 -0500 Subject: Remove direct reference to Activity getIntent() ActivityLaunch provides activity-scoped values from launch time. This abstraction is important for testability, allowing us to consistently test startup conditions in isolation without involving actually starting an activity, or depending on the state of the system in any way. Test: atest IntentResolver-tests-activity Test: atest IntentResolver-tests-unit Change-Id: Iec8b6b7067c6535f723ab47d712e1a937000e1c4 --- .../src/com/android/intentresolver/v2/ChooserActivity.java | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) (limited to 'java/src') diff --git a/java/src/com/android/intentresolver/v2/ChooserActivity.java b/java/src/com/android/intentresolver/v2/ChooserActivity.java index cdc05b95..072c56de 100644 --- a/java/src/com/android/intentresolver/v2/ChooserActivity.java +++ b/java/src/com/android/intentresolver/v2/ChooserActivity.java @@ -485,7 +485,7 @@ public class ChooserActivity extends Hilt_ChooserActivity implements .get(BasePreviewViewModel.class); previewViewModel.init( chooserRequest.getTargetIntent(), - getIntent(), + mActivityLaunch.getIntent(), chooserRequest.getAdditionalContentUri(), chooserRequest.getFocusedItemPosition(), mChooserServiceFeatureFlags.chooserPayloadToggling()); @@ -807,10 +807,6 @@ public class ChooserActivity extends Hilt_ChooserActivity implements mChooserMultiProfilePagerAdapter.getActiveListAdapter().handlePackagesChanged(); } - public boolean super_shouldAutoLaunchSingleChoice(TargetInfo target) { - return !target.isSuspended(); - } - /** Start the activity specified by the {@link TargetInfo}.*/ public final void safelyStartActivity(TargetInfo cti) { // In case cloned apps are present, we would want to start those apps in cloned user @@ -1652,14 +1648,12 @@ public class ChooserActivity extends Hilt_ChooserActivity implements } public boolean shouldAutoLaunchSingleChoice(TargetInfo target) { - // Note that this is only safe because the Intent handled by the ChooserActivity is - // guaranteed to contain no extras unknown to the local ClassLoader. That is why this - // method can not be replaced in the ResolverActivity whole hog. - if (!super_shouldAutoLaunchSingleChoice(target)) { + if (target.isSuspended()) { return false; } - return getIntent().getBooleanExtra(Intent.EXTRA_AUTO_LAUNCH_SINGLE_CHOICE, true); + return mActivityLaunch.getIntent().getBooleanExtra(Intent.EXTRA_AUTO_LAUNCH_SINGLE_CHOICE, + true); } private void showTargetDetails(TargetInfo targetInfo) { -- cgit v1.2.3-59-g8ed1b