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

Commit 95574b02 authored by Matt Pietal's avatar Matt Pietal
Browse files

Sharesheet - Only show direct share with ACTION_SEND*

Do not run direct share logic with non ACTION_SEND* action
codes, as ChooserActivity can be used for many other types.
Update tests to check for correct target counts.

Bug: 127806974
Test: atest ChooserActivityTest
Change-Id: I2b37fc8312ca3602475dee1c989d945c0fdce7e1
parent 309eb41a
Loading
Loading
Loading
Loading
+31 −16
Original line number Diff line number Diff line
@@ -318,9 +318,7 @@ public class ChooserActivity extends ResolverActivity {
        // Do not allow the title to be changed when sharing content
        CharSequence title = null;
        if (target != null) {
            String targetAction = target.getAction();
            if (!(Intent.ACTION_SEND.equals(targetAction) || Intent.ACTION_SEND_MULTIPLE.equals(
                    targetAction))) {
            if (!isSendAction(target)) {
                title = intent.getCharSequenceExtra(Intent.EXTRA_TITLE);
            } else {
                Log.w(TAG, "Ignoring intent's EXTRA_TITLE, deprecated in P. You may wish to set a"
@@ -444,7 +442,7 @@ public class ChooserActivity extends ResolverActivity {
                                        .getDimensionPixelSize(R.dimen.chooser_service_spacing);

        // expand/shrink direct share 4 -> 8 viewgroup
        if (mResolverDrawerLayout != null) {
        if (mResolverDrawerLayout != null && isSendAction(target)) {
            mResolverDrawerLayout.setOnScrollChangeListener(this::handleScroll);
        }

@@ -470,13 +468,8 @@ public class ChooserActivity extends ResolverActivity {
    public void setHeader() {
        super.setHeader();

        Intent targetIntent = getTargetIntent();
        if (targetIntent == null) {
            return;
        }

        String action = targetIntent.getAction();
        if (!(Intent.ACTION_SEND.equals(action) || Intent.ACTION_SEND_MULTIPLE.equals(action))) {
        final Intent targetIntent = getTargetIntent();
        if (!isSendAction(targetIntent)) {
            return;
        }

@@ -943,9 +936,7 @@ public class ChooserActivity extends ResolverActivity {
    }

    private void modifyTargetIntent(Intent in) {
        final String action = in.getAction();
        if (Intent.ACTION_SEND.equals(action) ||
                Intent.ACTION_SEND_MULTIPLE.equals(action)) {
        if (isSendAction(in)) {
            in.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT |
                    Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
        }
@@ -1939,9 +1930,13 @@ public class ChooserActivity extends ResolverActivity {
        }

        public int getServiceTargetCount() {
            if (isSendAction(getTargetIntent())) {
                return Math.min(mServiceTargets.size(), MAX_SERVICE_TARGETS);
            }

            return 0;
        }

        public int getStandardTargetCount() {
            return super.getCount();
        }
@@ -2088,6 +2083,23 @@ public class ChooserActivity extends ResolverActivity {
        }
    }

    private boolean isSendAction(Intent targetIntent) {
        if (targetIntent == null) {
            return false;
        }

        String action = targetIntent.getAction();
        if (action == null) {
            return false;
        }

        if (Intent.ACTION_SEND.equals(action) || Intent.ACTION_SEND_MULTIPLE.equals(action)) {
            return true;
        }

        return false;
    }

    class ChooserRowAdapter extends BaseAdapter {
        private ChooserListAdapter mChooserListAdapter;
        private final LayoutInflater mLayoutInflater;
@@ -2141,8 +2153,11 @@ public class ChooserActivity extends ResolverActivity {
        // There can be at most one row in the listview, that is internally
        // a ViewGroup with 2 rows
        public int getServiceTargetRowCount() {
            if (isSendAction(getTargetIntent())) {
                return 1;
            }
            return 0;
        }

        @Override
        public Object getItem(int position) {
+4 −1
Original line number Diff line number Diff line
@@ -97,9 +97,12 @@ public class ChooserActivityTest {
        when(sOverrides.resolverListController.getResolversForIntent(Mockito.anyBoolean(),
                Mockito.anyBoolean(),
                Mockito.isA(List.class))).thenReturn(resolvedComponentInfos);
        mActivityRule.launchActivity(Intent.createChooser(viewIntent, "chooser test"));
        final ChooserWrapperActivity activity = mActivityRule.launchActivity(
                Intent.createChooser(viewIntent, "chooser test"));

        waitForIdle();
        assertThat(activity.getAdapter().getCount(), is(2));
        assertThat(activity.getAdapter().getServiceTargetCount(), is(0));
        onView(withId(R.id.title)).check(matches(withText("chooser test")));
    }

+2 −2
Original line number Diff line number Diff line
@@ -39,8 +39,8 @@ public class ChooserWrapperActivity extends ChooserActivity {
    static final OverrideData sOverrides = new OverrideData();
    private UsageStatsManager mUsm;

    ResolveListAdapter getAdapter() {
        return mAdapter;
    ChooserListAdapter getAdapter() {
        return (ChooserListAdapter) mAdapter;
    }

    boolean getIsSelected() { return mIsSuccessfullySelected; }