summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Andrey Yepin <ayepin@google.com> 2025-03-14 13:59:06 -0700
committer Android (Google) Code Review <android-gerrit@google.com> 2025-03-14 13:59:06 -0700
commit05bd7cee5aaa677175374cd09cf33d6715b9db00 (patch)
tree36bd662ac8e3a42d32112a26a61f13543d88faf5
parent7267e8137f53bfed26969d4f7f2e4ee9b4988160 (diff)
parent262c6a7841cb575f93e7bc8f17d472b9ad84bf97 (diff)
Merge "Avoid drawer offset calculation if app targets are not yet processed." into main
-rw-r--r--aconfig/FeatureFlags.aconfig10
-rw-r--r--java/src/com/android/intentresolver/ChooserActivity.java18
-rw-r--r--java/src/com/android/intentresolver/ChooserListAdapter.java35
3 files changed, 52 insertions, 11 deletions
diff --git a/aconfig/FeatureFlags.aconfig b/aconfig/FeatureFlags.aconfig
index fe0dcffc..a5509b22 100644
--- a/aconfig/FeatureFlags.aconfig
+++ b/aconfig/FeatureFlags.aconfig
@@ -26,6 +26,16 @@ flag {
}
flag {
+ name: "delay_drawer_offset_calculation"
+ namespace: "intentresolver"
+ description: "Do not update the drawer offset until app targets are ready."
+ bug: "338229069"
+ metadata {
+ purpose: PURPOSE_BUGFIX
+ }
+}
+
+flag {
name: "individual_metadata_title_read"
namespace: "intentresolver"
description: "Enables separate title URI metadata calls"
diff --git a/java/src/com/android/intentresolver/ChooserActivity.java b/java/src/com/android/intentresolver/ChooserActivity.java
index d4cf82ff..aff34580 100644
--- a/java/src/com/android/intentresolver/ChooserActivity.java
+++ b/java/src/com/android/intentresolver/ChooserActivity.java
@@ -23,6 +23,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.Flags.delayDrawerOffsetCalculation;
import static com.android.intentresolver.Flags.fixShortcutsFlashingFixed;
import static com.android.intentresolver.Flags.interactiveSession;
import static com.android.intentresolver.Flags.keyboardNavigationFix;
@@ -2353,6 +2354,9 @@ public class ChooserActivity extends Hilt_ChooserActivity implements
|| recyclerView.computeVerticalScrollOffset() != 0) {
return;
}
+ if (delayDrawerOffsetCalculation() && !gridAdapter.getListAdapter().areAppTargetsReady()) {
+ return;
+ }
final int availableWidth = right - left - v.getPaddingLeft() - v.getPaddingRight();
final int maxChooserWidth = getResources().getDimensionPixelSize(R.dimen.chooser_width);
@@ -2381,7 +2385,7 @@ public class ChooserActivity extends Hilt_ChooserActivity implements
}
getMainThreadHandler().post(() -> {
- if (mResolverDrawerLayout == null || gridAdapter == null) {
+ if (mResolverDrawerLayout == null) {
return;
}
int offset = calculateDrawerOffset(top, bottom, recyclerView, gridAdapter);
@@ -2482,15 +2486,9 @@ 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) {
- onAppTargetsLoaded(listAdapter);
- }
- chooserListAdapter.notifyDataSetChanged();
- } else {
- chooserListAdapter.updateAlphabeticalList(() -> onAppTargetsLoaded(listAdapter));
- }
+ chooserListAdapter.updateAlphabeticalList(
+ rebuildComplete,
+ () -> onAppTargetsLoaded(listAdapter));
if (rebuildComplete) {
long duration = Tracer.INSTANCE.endAppTargetLoadingSection(listProfileUserHandle);
diff --git a/java/src/com/android/intentresolver/ChooserListAdapter.java b/java/src/com/android/intentresolver/ChooserListAdapter.java
index d743f859..7e5de74b 100644
--- a/java/src/com/android/intentresolver/ChooserListAdapter.java
+++ b/java/src/com/android/intentresolver/ChooserListAdapter.java
@@ -124,6 +124,21 @@ public class ChooserListAdapter extends ResolverListAdapter {
private final ItemRevealAnimationTracker mAnimationTracker = new ItemRevealAnimationTracker();
+ /**
+ * Indicates whether the app targets are ready. The flag is reset in
+ * {@link #rebuildList(boolean)} and set to true in {@link #updateAlphabeticalList(Runnable)}'s
+ * onPostExecute.
+ * There's one nuance though, {@link #updateAlphabeticalList(Runnable)} is called by the
+ * {@link ChooserActivity} only when {@link #rebuildList(boolean)} was called with {@code true}
+ * It is called with {@code false} only for inactive tabs in the
+ * MultiProfilePagerAdapter.rebuildTabs which, in turn, is called from either
+ * {@link ChooserActivity#recreatePagerAdapter} or {@link ChooserActivity#configureContentView}
+ * and, in both cases, there are no inactive pages in the MultiProfilePagerAdapter and
+ * {@link #rebuildList(boolean)} will be called with true upon navigation to the missing page.
+ * Yeah.
+ */
+ private boolean mAppTargetsReady = false;
+
// For pinned direct share labels, if the text spans multiple lines, the TextView will consume
// the full width, even if the characters actually take up less than that. Measure the actual
// line widths and constrain the View's width based upon that so that the pin doesn't end up
@@ -312,6 +327,13 @@ public class ChooserListAdapter extends ResolverListAdapter {
}
/**
+ * @return {@code true} if the app targets are ready.
+ */
+ public final boolean areAppTargetsReady() {
+ return mAppTargetsReady;
+ }
+
+ /**
* Set the enabled state for all targets.
*/
public void setTargetsEnabled(boolean isEnabled) {
@@ -354,6 +376,7 @@ public class ChooserListAdapter extends ResolverListAdapter {
public boolean rebuildList(boolean doPostProcessing) {
mAnimationTracker.reset();
mSortedList.clear();
+ mAppTargetsReady = false;
boolean result = super.rebuildList(doPostProcessing);
notifyDataSetChanged();
return result;
@@ -518,7 +541,16 @@ public class ChooserListAdapter extends ResolverListAdapter {
/**
* Group application targets
*/
- public void updateAlphabeticalList(Runnable onCompleted) {
+ public void updateAlphabeticalList(boolean rebuildComplete, Runnable onCompleted) {
+ if (getDisplayResolveInfoCount() == 0) {
+ Log.d(TAG, "getDisplayResolveInfoCount() == 0");
+ if (rebuildComplete) {
+ mAppTargetsReady = true;
+ onCompleted.run();
+ }
+ notifyDataSetChanged();
+ return;
+ }
final DisplayResolveInfoAzInfoComparator
comparator = new DisplayResolveInfoAzInfoComparator(mContext);
ImmutableList<DisplayResolveInfo> displayList = getTargetsInCurrentDisplayList();
@@ -582,6 +614,7 @@ public class ChooserListAdapter extends ResolverListAdapter {
protected void onPostExecute(List<DisplayResolveInfo> newList) {
mSortedList.clear();
mSortedList.addAll(newList);
+ mAppTargetsReady = true;
notifyDataSetChanged();
onCompleted.run();
}