From 7ba95b9cfbcef84efbcc0ccc3ac596ab08d320e3 Mon Sep 17 00:00:00 2001 From: Mark Renouf Date: Wed, 29 May 2024 21:46:09 -0400 Subject: Suppress ShareResult for launch of Editor component An edit action is reported explicitly as a ShareResult with type=EDIT. This change suppresses dispatch of a ShareResult with type 'COMPONENT_SELECTED' type when launching the editor component. Test: CTS-V Bug: NONE Flag: EXEMPT bugfix Change-Id: Ie13464cba88191dc26d8e5d9758541fd6c75017c --- java/src/com/android/intentresolver/ChooserActionFactory.java | 4 +++- java/src/com/android/intentresolver/ChooserActivity.java | 6 +++++- 2 files changed, 8 insertions(+), 2 deletions(-) (limited to 'java/src/com') diff --git a/java/src/com/android/intentresolver/ChooserActionFactory.java b/java/src/com/android/intentresolver/ChooserActionFactory.java index 79998fbc..d6153b36 100644 --- a/java/src/com/android/intentresolver/ChooserActionFactory.java +++ b/java/src/com/android/intentresolver/ChooserActionFactory.java @@ -88,7 +88,9 @@ public final class ChooserActionFactory implements ChooserContentPreviewUi.Actio // Boolean extra used to inform the editor that it may want to customize the editing experience // for the sharesheet editing flow. - private static final String EDIT_SOURCE = "edit_source"; + // Note: EDIT_SOURCE is also used as a signal to avoid sending a 'Component Selected' + // ShareResult for this intent when sent via ChooserActivity#safelyStartActivityAsUser + static final String EDIT_SOURCE = "edit_source"; private static final String EDIT_SOURCE_SHARESHEET = "sharesheet"; private static final String CHIP_LABEL_METADATA_KEY = "android.service.chooser.chip_label"; diff --git a/java/src/com/android/intentresolver/ChooserActivity.java b/java/src/com/android/intentresolver/ChooserActivity.java index 9643b9f0..66810187 100644 --- a/java/src/com/android/intentresolver/ChooserActivity.java +++ b/java/src/com/android/intentresolver/ChooserActivity.java @@ -22,6 +22,7 @@ import static android.view.WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTE import static androidx.lifecycle.LifecycleKt.getCoroutineScope; +import static com.android.intentresolver.ChooserActionFactory.EDIT_SOURCE; import static com.android.intentresolver.ext.CreationExtrasExtKt.addDefaultArgs; import static com.android.intentresolver.profiles.MultiProfilePagerAdapter.PROFILE_PERSONAL; import static com.android.intentresolver.profiles.MultiProfilePagerAdapter.PROFILE_WORK; @@ -1079,7 +1080,10 @@ public class ChooserActivity extends Hilt_ChooserActivity implements } try { if (cti.startAsCaller(this, options, user.getIdentifier())) { - maybeSendShareResult(cti); + // Prevent sending a second chooser result when starting the edit action intent. + if (!cti.getTargetIntent().hasExtra(EDIT_SOURCE)) { + maybeSendShareResult(cti); + } maybeLogCrossProfileTargetLaunch(cti, user); } } catch (RuntimeException e) { -- cgit v1.2.3-59-g8ed1b From 41bb0f4081f43e84cf4120b79ad4957311b4896b Mon Sep 17 00:00:00 2001 From: Mark Renouf Date: Wed, 29 May 2024 22:00:09 -0400 Subject: Add logcat to all finish() call sites For future troubleshooting aid and ongoing investigation of b/334179669 (sharesheet dismisses unexpectedly during GTS-I). The theory is that Sharesheet is incorrectly invoking finish at some point after switching tabs within the test, but there is no way to identify the code path taken to calling finish(). Bug: 334179669 Flag: EXEMPT bugfix Test: compile Change-Id: I6b81b87506ce1ecff795772f9d1283ce533552a3 --- .../com/android/intentresolver/ChooserActionFactory.java | 2 ++ java/src/com/android/intentresolver/ChooserActivity.java | 14 ++++++++++++++ 2 files changed, 16 insertions(+) (limited to 'java/src/com') diff --git a/java/src/com/android/intentresolver/ChooserActionFactory.java b/java/src/com/android/intentresolver/ChooserActionFactory.java index d6153b36..dae1ab52 100644 --- a/java/src/com/android/intentresolver/ChooserActionFactory.java +++ b/java/src/com/android/intentresolver/ChooserActionFactory.java @@ -257,6 +257,7 @@ public final class ChooserActionFactory implements ChooserContentPreviewUi.Actio clipboardManager.setPrimaryClipAsPackage(clipData, referrerPackageName); log.logActionSelected(EventLog.SELECTION_TYPE_COPY); + Log.d(TAG, "finish due to copy clicked"); finishCallback.accept(Activity.RESULT_OK); }; } @@ -395,6 +396,7 @@ public final class ChooserActionFactory implements ChooserContentPreviewUi.Actio if (shareResultSender != null) { shareResultSender.onActionSelected(ShareAction.APPLICATION_DEFINED); } + Log.d(TAG, "finish due to custom action clicked"); finishCallback.accept(Activity.RESULT_OK); } ); diff --git a/java/src/com/android/intentresolver/ChooserActivity.java b/java/src/com/android/intentresolver/ChooserActivity.java index 66810187..7353ff37 100644 --- a/java/src/com/android/intentresolver/ChooserActivity.java +++ b/java/src/com/android/intentresolver/ChooserActivity.java @@ -393,6 +393,7 @@ public class ChooserActivity extends Hilt_ChooserActivity implements // so we will now finish ourself since being no longer visible, // the user probably can't get back to us. if (!isChangingConfigurations()) { + Log.d(TAG, "finishing in onStop"); finish(); } } @@ -725,6 +726,9 @@ public class ChooserActivity extends Hilt_ChooserActivity implements } private void onAppTargetsLoaded(ResolverListAdapter listAdapter) { + Log.d(TAG, "onAppTargetsLoaded(" + + "listAdapter.userHandle=" + listAdapter.getUserHandle() + ")"); + if (mChooserMultiProfilePagerAdapter == null) { return; } @@ -860,6 +864,7 @@ public class ChooserActivity extends Hilt_ChooserActivity implements final TargetInfo target = mChooserMultiProfilePagerAdapter.getActiveListAdapter() .targetInfoForPosition(0, false); if (shouldAutoLaunchSingleChoice(target)) { + Log.d(TAG, "auto launching " + target + " and finishing."); safelyStartActivity(target); finish(); return true; @@ -928,6 +933,7 @@ public class ChooserActivity extends Hilt_ChooserActivity implements .setStrings(getMetricsCategory()) .write(); safelyStartActivity(activeProfileTarget); + Log.d(TAG, "auto launching! " + activeProfileTarget); finish(); return true; } @@ -1194,6 +1200,7 @@ public class ChooserActivity extends Hilt_ChooserActivity implements (ChooserListAdapter) listAdapter, mProfileAvailability.getWaitingToEnableProfile())) { // We no longer have any items... just finish the activity. + Log.d(TAG, "onHandlePackagesChanged(): returned false, finishing"); finish(); } } @@ -1761,6 +1768,7 @@ public class ChooserActivity extends Hilt_ChooserActivity implements mChooserMultiProfilePagerAdapter.getActiveListAdapter().hasFilteredItem() ? MetricsEvent.ACTION_HIDE_APP_DISAMBIG_APP_FEATURED : MetricsEvent.ACTION_HIDE_APP_DISAMBIG_NONE_FEATURED); + Log.d(TAG, "onTargetSelected() returned true, finishing! " + target); finish(); } } @@ -2183,6 +2191,8 @@ public class ChooserActivity extends Hilt_ChooserActivity implements targetInfo, mProfiles.getPersonalHandle() ); + Log.d(TAG, "safelyStartActivityAsPersonalProfileUser(" + + targetInfo + "): finishing!"); finish(); } @@ -2218,6 +2228,7 @@ public class ChooserActivity extends Hilt_ChooserActivity implements if (status != null) { setResult(status); } + Log.d(TAG, "finishWithStatus: result=" + status); finish(); } @@ -2360,6 +2371,8 @@ public class ChooserActivity extends Hilt_ChooserActivity implements } protected void onListRebuilt(ResolverListAdapter listAdapter, boolean rebuildComplete) { + Log.d(TAG, "onListRebuilt(listAdapter.userHandle=" + listAdapter.getUserHandle() + ", " + + "rebuildComplete=" + rebuildComplete + ")"); setupScrollListener(); maybeSetupGlobalLayoutListener(); @@ -2375,6 +2388,7 @@ public class ChooserActivity extends Hilt_ChooserActivity implements //TODO: move this block inside ChooserListAdapter (should be called when // ResolverListAdapter#mPostListReadyRunnable is executed. if (chooserListAdapter.getDisplayResolveInfoCount() == 0) { + Log.d(TAG, "getDisplayResolveInfoCount() == 0"); if (rebuildComplete && mChooserServiceFeatureFlags.chooserPayloadToggling()) { onAppTargetsLoaded(listAdapter); } -- cgit v1.2.3-59-g8ed1b