Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e79c1056 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "De-duplicate with callerTargets(added by using...

Merge "De-duplicate with callerTargets(added by using Intent.EXTRA_INITIAL_INTENTS) when adding DisplayResolveInfo." into rvc-dev
parents 3a9ceed2 276e384e
Loading
Loading
Loading
Loading
+23 −4
Original line number Diff line number Diff line
@@ -104,7 +104,7 @@ public class ChooserListAdapter extends ResolverListAdapter {
    private Set<ComponentName> mPendingChooserTargetService = new HashSet<>();
    private Set<ComponentName> mShortcutComponents = new HashSet<>();
    private final List<ChooserTargetInfo> mServiceTargets = new ArrayList<>();
    private final List<TargetInfo> mCallerTargets = new ArrayList<>();
    private final List<DisplayResolveInfo> mCallerTargets = new ArrayList<>();

    private final ChooserActivity.BaseChooserTargetComparator mBaseTargetComparator =
            new ChooserActivity.BaseChooserTargetComparator();
@@ -268,10 +268,13 @@ public class ChooserListAdapter extends ResolverListAdapter {

    void updateAlphabeticalList() {
        mSortedList.clear();
        List<DisplayResolveInfo> tempList = new ArrayList<>();
        tempList.addAll(mDisplayList);
        tempList.addAll(mCallerTargets);
        if (mEnableStackedApps) {
            // Consolidate multiple targets from same app.
            Map<String, DisplayResolveInfo> consolidated = new HashMap<>();
            for (DisplayResolveInfo info : mDisplayList) {
            for (DisplayResolveInfo info : tempList) {
                String packageName = info.getResolvedComponentName().getPackageName();
                DisplayResolveInfo multiDri = consolidated.get(packageName);
                if (multiDri == null) {
@@ -288,7 +291,7 @@ public class ChooserListAdapter extends ResolverListAdapter {
            }
            mSortedList.addAll(consolidated.values());
        } else {
            mSortedList.addAll(mDisplayList);
            mSortedList.addAll(tempList);
        }
        Collections.sort(mSortedList, new ChooserActivity.AzInfoComparator(mContext));
    }
@@ -340,7 +343,10 @@ public class ChooserListAdapter extends ResolverListAdapter {
        return standardCount > mChooserListCommunicator.getMaxRankedTargets() ? standardCount : 0;
    }

    int getRankedTargetCount() {
    /**
     * Fetch ranked app target count
     */
    public int getRankedTargetCount() {
        int spacesAvailable =
                mChooserListCommunicator.getMaxRankedTargets() - getCallerTargetCount();
        return Math.min(spacesAvailable, super.getCount());
@@ -425,6 +431,19 @@ public class ChooserListAdapter extends ResolverListAdapter {
        return null;
    }

    // Check whether {@code dri} should be added into mDisplayList.
    @Override
    protected boolean shouldAddResolveInfo(DisplayResolveInfo dri) {
        // Checks if this info is already listed in callerTargets.
        for (TargetInfo existingInfo : mCallerTargets) {
            if (mResolverListCommunicator
                    .resolveInfoMatch(dri.getResolveInfo(), existingInfo.getResolveInfo())) {
                return false;
            }
        }
        return super.shouldAddResolveInfo(dri);
    }

    /**
     * Fetch surfaced direct share target info
     */
+15 −8
Original line number Diff line number Diff line
@@ -85,7 +85,7 @@ public class ResolverListAdapter extends BaseAdapter {

    private int mLastChosenPosition = -1;
    private boolean mFilterLastUsed;
    private final ResolverListCommunicator mResolverListCommunicator;
    final ResolverListCommunicator mResolverListCommunicator;
    private Runnable mPostListReadyRunnable;
    private final boolean mIsAudioCaptureDevice;
    private boolean mIsTabLoaded;
@@ -443,15 +443,22 @@ public class ResolverListAdapter extends BaseAdapter {
        // TODO(arangelov): Is that UserHandle.USER_CURRENT check okay?
        if (dri != null && dri.getResolveInfo() != null
                && dri.getResolveInfo().targetUserId == UserHandle.USER_CURRENT) {
            if (shouldAddResolveInfo(dri)) {
                mDisplayList.add(dri);
            }
        }
    }

    // Check whether {@code dri} should be added into mDisplayList.
    protected boolean shouldAddResolveInfo(DisplayResolveInfo dri) {
        // Checks if this info is already listed in display.
        for (DisplayResolveInfo existingInfo : mDisplayList) {
            if (mResolverListCommunicator
                    .resolveInfoMatch(dri.getResolveInfo(), existingInfo.getResolveInfo())) {
                    return;
                return false;
            }
        }
            mDisplayList.add(dri);
        }
        return true;
    }

    @Nullable
+27 −0
Original line number Diff line number Diff line
@@ -1926,6 +1926,33 @@ public class ChooserActivityTest {
                .check(matches(isDisplayed()));
    }

    @Test
    public void testDeduplicateCallerTargetRankedTarget() {
        // Create 4 ranked app targets.
        List<ResolvedComponentInfo> personalResolvedComponentInfos =
                createResolvedComponentsForTest(4);
        when(sOverrides.resolverListController.getResolversForIntent(Mockito.anyBoolean(),
                Mockito.anyBoolean(),
                Mockito.isA(List.class)))
                .thenReturn(new ArrayList<>(personalResolvedComponentInfos));
        // Create caller target which is duplicate with one of app targets
        Intent chooserIntent = createChooserIntent(createSendTextIntent(),
                new Intent[] {new Intent("action.fake")});
        sOverrides.packageManager = mock(PackageManager.class);
        ResolveInfo ri = ResolverDataProvider.createResolveInfo(0,
                UserHandle.USER_CURRENT);
        when(sOverrides.packageManager.resolveActivity(any(Intent.class), anyInt())).thenReturn(ri);
        waitForIdle();

        ChooserWrapperActivity activity = mActivityRule.launchActivity(chooserIntent);
        waitForIdle();

        // Total 4 targets (1 caller target, 3 ranked targets)
        assertThat(activity.getAdapter().getCount(), is(4));
        assertThat(activity.getAdapter().getCallerTargetCount(), is(1));
        assertThat(activity.getAdapter().getRankedTargetCount(), is(3));
    }

    private Intent createChooserIntent(Intent intent, Intent[] initialIntents) {
        Intent chooserIntent = new Intent();
        chooserIntent.setAction(Intent.ACTION_CHOOSER);