From dad1cd6fdfbde5d434d91d499132aac69cf43c95 Mon Sep 17 00:00:00 2001 From: Joshua Trask Date: Mon, 6 Dec 2021 14:15:47 -0500 Subject: Query "post" targets only when rebuild complete. When we perform our initial query and then kick off an async sorting task, we predictably see two list-ready callbacks, both with doPostProcessing=true, first with rebuildCompleted=false, then true. If we perform the post-processing step both times, we'll double-log events, double-query app prediction, etc. This is described in more detail in b/209018315. In this CL, we specifically ensure that the logging & APS query only occur when the async rebuild is complete. This is the minimal change to address the duplication while restoring the general conditions of how this flow worked prior to the introduction of the async step. In subsequent CLs, there's room to optimize this flow or polish other bugs that may have been introduced along with the async step; for more discussion see the comments on this CL. Note that we still have some disabled logging tests that were supposed to assert the correct flow step-by-step, but that regressed over time. Those tests will be re-enabled in a subsequent CL, where we'll presumably need to update the assertions to match the current flow. Test: manual + `atest ChooserActivityTest` Bug: 209018315 Change-Id: Ie1b786c46b4204ede26ab1face3f040dad77d26e --- core/java/com/android/internal/app/ChooserActivity.java | 13 ++++++++----- core/java/com/android/internal/app/ResolverActivity.java | 4 ++-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/core/java/com/android/internal/app/ChooserActivity.java b/core/java/com/android/internal/app/ChooserActivity.java index 359c382f51bc..52122eeb3f3e 100644 --- a/core/java/com/android/internal/app/ChooserActivity.java +++ b/core/java/com/android/internal/app/ChooserActivity.java @@ -2736,7 +2736,7 @@ public class ChooserActivity extends ResolverActivity implements } @Override - public void onListRebuilt(ResolverListAdapter listAdapter) { + public void onListRebuilt(ResolverListAdapter listAdapter, boolean rebuildComplete) { setupScrollListener(); maybeSetupGlobalLayoutListener(); @@ -2756,15 +2756,20 @@ public class ChooserActivity extends ResolverActivity implements chooserListAdapter.updateAlphabeticalList(); } + if (rebuildComplete) { + getChooserActivityLogger().logSharesheetAppLoadComplete(); + maybeQueryAdditionalPostProcessingTargets(chooserListAdapter); + } + } + + private void maybeQueryAdditionalPostProcessingTargets(ChooserListAdapter chooserListAdapter) { // don't support direct share on low ram devices if (ActivityManager.isLowRamDeviceStatic()) { - getChooserActivityLogger().logSharesheetAppLoadComplete(); return; } // no need to query direct share for work profile when its locked or disabled if (!shouldQueryShortcutManager(chooserListAdapter.getUserHandle())) { - getChooserActivityLogger().logSharesheetAppLoadComplete(); return; } @@ -2775,8 +2780,6 @@ public class ChooserActivity extends ResolverActivity implements queryDirectShareTargets(chooserListAdapter, false); } - - getChooserActivityLogger().logSharesheetAppLoadComplete(); } @VisibleForTesting diff --git a/core/java/com/android/internal/app/ResolverActivity.java b/core/java/com/android/internal/app/ResolverActivity.java index fd8637abfc6b..b273f6ded8d0 100644 --- a/core/java/com/android/internal/app/ResolverActivity.java +++ b/core/java/com/android/internal/app/ResolverActivity.java @@ -1159,11 +1159,11 @@ public class ResolverActivity extends Activity implements if (doPostProcessing) { maybeCreateHeader(listAdapter); resetButtonBar(); - onListRebuilt(listAdapter); + onListRebuilt(listAdapter, rebuildCompleted); } } - protected void onListRebuilt(ResolverListAdapter listAdapter) { + protected void onListRebuilt(ResolverListAdapter listAdapter, boolean rebuildCompleted) { final ItemClickListener listener = new ItemClickListener(); setupAdapterListView((ListView) mMultiProfilePagerAdapter.getActiveAdapterView(), listener); if (shouldShowTabs() && isIntentPicker()) { -- cgit v1.2.3-59-g8ed1b