diff options
3 files changed, 27 insertions, 27 deletions
diff --git a/java/src/com/android/intentresolver/v2/ChooserActivity.java b/java/src/com/android/intentresolver/v2/ChooserActivity.java index 70812642..b791b1c1 100644 --- a/java/src/com/android/intentresolver/v2/ChooserActivity.java +++ b/java/src/com/android/intentresolver/v2/ChooserActivity.java @@ -787,10 +787,7 @@ public class ChooserActivity extends Hilt_ChooserActivity implements ChooserRequestParameters chooserRequest = requireChooserRequest(); if (!chooserRequest.getCallerChooserTargets().isEmpty()) { // Send the caller's chooser targets only to the default profile. - UserHandle defaultUser = (findSelectedProfile() == PROFILE_WORK) - ? requireAnnotatedUserHandles().workProfileUserHandle - : requireAnnotatedUserHandles().personalProfileUserHandle; - if (mChooserMultiProfilePagerAdapter.getCurrentUserHandle() == defaultUser) { + if (mChooserMultiProfilePagerAdapter.getActiveProfile() == findSelectedProfile()) { mChooserMultiProfilePagerAdapter.getActiveListAdapter().addServiceResults( /* origTarget */ null, new ArrayList<>(chooserRequest.getCallerChooserTargets()), @@ -1404,8 +1401,7 @@ public class ChooserActivity extends Hilt_ChooserActivity implements updateTabPadding(); } - UserHandle currentUserHandle = mChooserMultiProfilePagerAdapter.getCurrentUserHandle(); - int currentProfile = getProfileForUser(currentUserHandle); + int currentProfile = mChooserMultiProfilePagerAdapter.getActiveProfile(); int initialProfile = findSelectedProfile(); if (currentProfile != initialProfile) { return; diff --git a/java/src/com/android/intentresolver/v2/MultiProfilePagerAdapter.java b/java/src/com/android/intentresolver/v2/MultiProfilePagerAdapter.java index 2d9be816..aa161921 100644 --- a/java/src/com/android/intentresolver/v2/MultiProfilePagerAdapter.java +++ b/java/src/com/android/intentresolver/v2/MultiProfilePagerAdapter.java @@ -140,6 +140,14 @@ public class MultiProfilePagerAdapter< mPageViewInflater.get(), adapter, containerBottomPaddingOverrideSupplier); } + private @Profile int getProfileForPageNumber(int position) { + return position; + } + + private int getPageNumberForProfile(@Profile int profile) { + return profile; + } + public void setOnProfileSelectedListener(OnProfileSelectedListener listener) { mOnProfileSelectedListener = listener; } @@ -205,11 +213,7 @@ public class MultiProfilePagerAdapter< } public final @Profile int getActiveProfile() { - // TODO: here and elsewhere in this class, distinguish between a "profile ID" integer and - // its mapped "page index." When we support more than two profiles, this won't be a "stable - // mapping" -- some particular profile may not be represented by a "page," but the ones that - // are will be assigned contiguous page numbers that skip over the holes. - return getCurrentPage(); + return getProfileForPageNumber(getCurrentPage()); } @VisibleForTesting @@ -304,6 +308,10 @@ public class MultiProfilePagerAdapter< return null; } + private ListAdapterT getListAdapterForPageNumber(int pageNumber) { + return mListAdapterExtractor.apply(getAdapterForIndex(pageNumber)); + } + /** * Returns the {@link ListAdapterT} instance of the profile that is currently visible * to the user. @@ -313,7 +321,7 @@ public class MultiProfilePagerAdapter< */ @VisibleForTesting public final ListAdapterT getActiveListAdapter() { - return mListAdapterExtractor.apply(getAdapterForIndex(getCurrentPage())); + return getListAdapterForPageNumber(getCurrentPage()); } /** @@ -330,28 +338,24 @@ public class MultiProfilePagerAdapter< if (getCount() < 2) { return null; } - return mListAdapterExtractor.apply(getAdapterForIndex(1 - getCurrentPage())); + return getListAdapterForPageNumber(1 - getCurrentPage()); } public final ListAdapterT getPersonalListAdapter() { - return mListAdapterExtractor.apply(getAdapterForIndex(PROFILE_PERSONAL)); + return getListAdapterForPageNumber(getPageNumberForProfile(PROFILE_PERSONAL)); } /** @return whether our tab data contains a page for the specified {@code profile} ID. */ public final boolean hasPageForProfile(@Profile int profile) { - // TODO: here and elsewhere in this class, distinguish between a "profile ID" integer and - // its mapped "page index." When we support more than two profiles, this won't be a "stable - // mapping" -- some particular profile may not be represented by a "page," but the ones that - // are will be assigned contiguous page numbers that skip over the holes. - return hasAdapterForIndex(profile); + return hasAdapterForIndex(getPageNumberForProfile(profile)); } @Nullable public final ListAdapterT getWorkListAdapter() { - if (!hasAdapterForIndex(PROFILE_WORK)) { + if (!hasPageForProfile(PROFILE_WORK)) { return null; } - return mListAdapterExtractor.apply(getAdapterForIndex(PROFILE_WORK)); + return getListAdapterForPageNumber(getPageNumberForProfile(PROFILE_WORK)); } public final SinglePageAdapterT getCurrentRootAdapter() { @@ -480,9 +484,9 @@ public class MultiProfilePagerAdapter< private int userHandleToPageIndex(UserHandle userHandle) { if (userHandle.equals(getPersonalListAdapter().getUserHandle())) { - return PROFILE_PERSONAL; + return getPageNumberForProfile(PROFILE_PERSONAL); } else { - return PROFILE_WORK; + return getPageNumberForProfile(PROFILE_WORK); } } @@ -500,7 +504,7 @@ public class MultiProfilePagerAdapter< } private boolean hasAdapterForIndex(int pageIndex) { - return (pageIndex < getCount()); + return (pageIndex >= 0) && (pageIndex < getCount()); } /** diff --git a/java/src/com/android/intentresolver/v2/ResolverActivity.java b/java/src/com/android/intentresolver/v2/ResolverActivity.java index 2ba50ec3..cc91e9bf 100644 --- a/java/src/com/android/intentresolver/v2/ResolverActivity.java +++ b/java/src/com/android/intentresolver/v2/ResolverActivity.java @@ -934,8 +934,7 @@ public class ResolverActivity extends FragmentActivity implements } protected Unit onWorkProfileStatusUpdated() { - if (mMultiProfilePagerAdapter.getCurrentUserHandle().equals( - requireAnnotatedUserHandles().workProfileUserHandle)) { + if (mMultiProfilePagerAdapter.getActiveProfile() == PROFILE_WORK) { mMultiProfilePagerAdapter.rebuildActiveTab(true); } else { mMultiProfilePagerAdapter.clearInactiveProfileCache(); @@ -1358,7 +1357,8 @@ public class ResolverActivity extends FragmentActivity implements // In case of clonedProfile being active, we do not allow the 'Always' option in the // disambiguation dialog of Personal Profile as the package manager cannot distinguish // between cross-profile preferred activities. - if (hasCloneProfile() && (mMultiProfilePagerAdapter.getCurrentPage() == PROFILE_PERSONAL)) { + if (hasCloneProfile() + && (mMultiProfilePagerAdapter.getActiveProfile() == PROFILE_PERSONAL)) { mAlwaysButton.setEnabled(false); return; } |