aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoshua Trask <joshtrask@google.com>2023-12-11 22:22:22 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2023-12-11 22:22:22 +0000
commitd9986258a1ea3cecb6e3d9d287c8b483da57694c (patch)
treed02106fa72c95fcf8dddf3a74cc682c75f3047aa
parentd259bcfbf0350283c8483cb980078d3ef1b339ee (diff)
parent15a4eef126161ee09961d3687c094f5a91ee2133 (diff)
downloadIntentResolver-d9986258a1ea3cecb6e3d9d287c8b483da57694c.tar.gz
Merge "Pull package change handling into pager-adapter" into main
-rw-r--r--java/src/com/android/intentresolver/v2/ChooserActivity.java11
-rw-r--r--java/src/com/android/intentresolver/v2/ChooserMultiProfilePagerAdapter.java8
-rw-r--r--java/src/com/android/intentresolver/v2/MultiProfilePagerAdapter.java60
-rw-r--r--java/src/com/android/intentresolver/v2/ResolverActivity.java36
4 files changed, 75 insertions, 40 deletions
diff --git a/java/src/com/android/intentresolver/v2/ChooserActivity.java b/java/src/com/android/intentresolver/v2/ChooserActivity.java
index fcd45b0..66705ce 100644
--- a/java/src/com/android/intentresolver/v2/ChooserActivity.java
+++ b/java/src/com/android/intentresolver/v2/ChooserActivity.java
@@ -593,10 +593,7 @@ public class ChooserActivity extends Hilt_ChooserActivity implements
// Refresh pinned items
mPinnedSharedPrefs = getPinnedSharedPrefs(this);
if (listAdapter == null) {
- mChooserMultiProfilePagerAdapter.getActiveListAdapter().handlePackagesChanged();
- if (mChooserMultiProfilePagerAdapter.getCount() > 1) {
- mChooserMultiProfilePagerAdapter.getInactiveListAdapter().handlePackagesChanged();
- }
+ mChooserMultiProfilePagerAdapter.refreshPackagesInAllTabs();
} else {
listAdapter.handlePackagesChanged();
}
@@ -1520,12 +1517,6 @@ public class ChooserActivity extends Hilt_ChooserActivity implements
return PROFILE_PERSONAL;
}
- @Override // ResolverListCommunicator
- public void onHandlePackagesChanged(ResolverListAdapter listAdapter) {
- mChooserMultiProfilePagerAdapter.getActiveListAdapter().notifyDataSetChanged();
- super.onHandlePackagesChanged(listAdapter);
- }
-
@Override
protected void onListRebuilt(ResolverListAdapter listAdapter, boolean rebuildComplete) {
setupScrollListener();
diff --git a/java/src/com/android/intentresolver/v2/ChooserMultiProfilePagerAdapter.java b/java/src/com/android/intentresolver/v2/ChooserMultiProfilePagerAdapter.java
index 87b3b20..b9ee962 100644
--- a/java/src/com/android/intentresolver/v2/ChooserMultiProfilePagerAdapter.java
+++ b/java/src/com/android/intentresolver/v2/ChooserMultiProfilePagerAdapter.java
@@ -154,6 +154,14 @@ public class ChooserMultiProfilePagerAdapter extends MultiProfilePagerAdapter<
}
@Override
+ public boolean onHandlePackagesChanged(
+ ChooserListAdapter listAdapter, boolean waitingToEnableWorkProfile) {
+ // TODO: why do we need to do the extra `notifyDataSetChanged()` in (only) the Chooser case?
+ getActiveListAdapter().notifyDataSetChanged();
+ return super.onHandlePackagesChanged(listAdapter, waitingToEnableWorkProfile);
+ }
+
+ @Override
protected final boolean rebuildTab(ChooserListAdapter listAdapter, boolean doPostProcessing) {
if (doPostProcessing) {
Tracer.INSTANCE.beginAppTargetLoadingSection(listAdapter.getUserHandle());
diff --git a/java/src/com/android/intentresolver/v2/MultiProfilePagerAdapter.java b/java/src/com/android/intentresolver/v2/MultiProfilePagerAdapter.java
index a600d4a..6d1870b 100644
--- a/java/src/com/android/intentresolver/v2/MultiProfilePagerAdapter.java
+++ b/java/src/com/android/intentresolver/v2/MultiProfilePagerAdapter.java
@@ -353,6 +353,66 @@ public class MultiProfilePagerAdapter<
return getListViewForIndex(1 - getCurrentPage());
}
+ private boolean anyAdapterHasItems() {
+ for (int i = 0; i < mItems.size(); ++i) {
+ ListAdapterT listAdapter = mListAdapterExtractor.apply(getAdapterForIndex(i));
+ if (listAdapter.getCount() > 0) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public void refreshPackagesInAllTabs() {
+ // TODO: handle all inactive profiles; for now we can only have at most one. It's unclear if
+ // this legacy logic really requires the active tab to be rebuilt first, or if we could just
+ // iterate over the tabs in arbitrary order.
+ getActiveListAdapter().handlePackagesChanged();
+ if (getCount() > 1) {
+ getInactiveListAdapter().handlePackagesChanged();
+ }
+ }
+
+ /**
+ * Notify that there has been a package change which could potentially modify the set of targets
+ * that should be shown in the specified {@code listAdapter}. This <em>may</em> result in
+ * "rebuilding" the target list for that adapter.
+ *
+ * @param listAdapter an adapter that may need to be updated after the package-change event.
+ * @param waitingToEnableWorkProfile whether we've turned on the work profile, but haven't yet
+ * seen an {@code ACTION_USER_UNLOCKED} broadcast. In this case we skip the rebuild of any
+ * work-profile adapter because we wouldn't expect meaningful results -- but another rebuild
+ * will be prompted when we eventually get the broadcast.
+ *
+ * @return whether we're able to proceed with a Sharesheet session after processing this
+ * package-change event. If false, we were able to rebuild the targets but determined that there
+ * aren't any we could present in the UI without the app looking broken, so we should just quit.
+ */
+ public boolean onHandlePackagesChanged(
+ ListAdapterT listAdapter, boolean waitingToEnableWorkProfile) {
+ if (listAdapter == getActiveListAdapter()) {
+ if (listAdapter.getUserHandle().equals(mWorkProfileUserHandle)
+ && waitingToEnableWorkProfile) {
+ // We have just turned on the work profile and entered the passcode to start it,
+ // now we are waiting to receive the ACTION_USER_UNLOCKED broadcast. There is no
+ // point in reloading the list now, since the work profile user is still turning on.
+ return true;
+ }
+
+ boolean listRebuilt = rebuildActiveTab(true);
+ if (listRebuilt) {
+ listAdapter.notifyDataSetChanged();
+ }
+
+ // TODO: shouldn't we check that the inactive tabs are built before declaring that we
+ // have to quit for lack of items?
+ return anyAdapterHasItems();
+ } else {
+ clearInactiveProfileCache();
+ return true;
+ }
+ }
+
/**
* Rebuilds the tab that is currently visible to the user.
* <p>Returns {@code true} if rebuild has completed.
diff --git a/java/src/com/android/intentresolver/v2/ResolverActivity.java b/java/src/com/android/intentresolver/v2/ResolverActivity.java
index 8f8a7d0..39a4752 100644
--- a/java/src/com/android/intentresolver/v2/ResolverActivity.java
+++ b/java/src/com/android/intentresolver/v2/ResolverActivity.java
@@ -966,29 +966,12 @@ public class ResolverActivity extends FragmentActivity implements
}
@Override // ResolverListCommunicator
- public void onHandlePackagesChanged(ResolverListAdapter listAdapter) {
- if (listAdapter == mMultiProfilePagerAdapter.getActiveListAdapter()) {
- if (listAdapter.getUserHandle().equals(
- requireAnnotatedUserHandles().workProfileUserHandle)
- && mLogic.getWorkProfileAvailabilityManager().isWaitingToEnableWorkProfile()) {
- // We have just turned on the work profile and entered the pass code to start it,
- // now we are waiting to receive the ACTION_USER_UNLOCKED broadcast. There is no
- // point in reloading the list now, since the work profile user is still
- // turning on.
- return;
- }
- boolean listRebuilt = mMultiProfilePagerAdapter.rebuildActiveTab(true);
- if (listRebuilt) {
- ResolverListAdapter activeListAdapter =
- mMultiProfilePagerAdapter.getActiveListAdapter();
- activeListAdapter.notifyDataSetChanged();
- if (activeListAdapter.getCount() == 0 && !inactiveListAdapterHasItems()) {
- // We no longer have any items... just finish the activity.
- finish();
- }
- }
- } else {
- mMultiProfilePagerAdapter.clearInactiveProfileCache();
+ public final void onHandlePackagesChanged(ResolverListAdapter listAdapter) {
+ if (!mMultiProfilePagerAdapter.onHandlePackagesChanged(
+ listAdapter,
+ mLogic.getWorkProfileAvailabilityManager().isWaitingToEnableWorkProfile())) {
+ // We no longer have any items... just finish the activity.
+ finish();
}
}
@@ -2126,13 +2109,6 @@ public class ResolverActivity extends FragmentActivity implements
mRetainInOnStop = retainInOnStop;
}
- private boolean inactiveListAdapterHasItems() {
- if (!shouldShowTabs()) {
- return false;
- }
- return mMultiProfilePagerAdapter.getInactiveListAdapter().getCount() > 0;
- }
-
final class ItemClickListener implements AdapterView.OnItemClickListener,
AdapterView.OnItemLongClickListener {
@Override