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

Commit ff4915e3 authored by Tony Huang's avatar Tony Huang
Browse files

Add file count limit when share

When share too many files, it will cause exception then crash.
Add a limit count to avoid this.

Fix: 140515766
Test: manual
Test: atest DocumentsUIGoogleTests
Change-Id: Iff40233da536659e5f83b4454642b9d2ab35fcef
parent 0fae436b
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -196,6 +196,8 @@
    <string name="toast_view_in_archives_unsupported">Cannot open files in archives</string>
    <!-- Toast shown when some of the selected documents failed to be deleted [CHAR LIMIT=48] -->
    <string name="toast_failed_delete">Unable to delete some documents</string>
    <!-- Toast shown when user want to share files amount over limit [CHAR LIMIT=48] -->
    <string name="toast_share_over_limit">Can\u2019t share more than <xliff:g id="count" example="1">%1$d</xliff:g> files</string>

    <!-- Title of dialog when prompting user to select an app to share documents with [CHAR LIMIT=32] -->
    <string name="share_via">Share via</string>
+4 −0
Original line number Diff line number Diff line
@@ -87,6 +87,7 @@ import javax.annotation.Nullable;
public class ActionHandler<T extends FragmentActivity & Addons> extends AbstractActionHandler<T> {

    private static final String TAG = "ManagerActionHandler";
    private static final int SHARE_FILES_COUNT_LIMIT = 100;

    private final ActionModeAddons mActionModeAddons;
    private final Features mFeatures;
@@ -356,6 +357,9 @@ public class ActionHandler<T extends FragmentActivity & Addons> extends Abstract
        Selection<String> selection = getStableSelection();
        if (selection.isEmpty()) {
            return;
        } else if (selection.size() > SHARE_FILES_COUNT_LIMIT) {
            mDialogs.showShareOverLimit(SHARE_FILES_COUNT_LIMIT);
            return;
        }

        // Model must be accessed in UI thread, since underlying cursor is not threadsafe.
+11 −0
Original line number Diff line number Diff line
@@ -47,6 +47,11 @@ public interface DialogController {
    void showViewInArchivesUnsupported();
    void showDocumentsClipped(int size);

    /**
     * Dialogs used when share file count over limit
     */
    void showShareOverLimit(int size);

    // Dialogs used in PickActivity
    void confirmAction(FragmentManager fm, DocumentInfo pickTarget, int type);

@@ -152,6 +157,12 @@ public interface DialogController {
            Snackbars.showDocumentsClipped(mActivity, size);
        }

        @Override
        public void showShareOverLimit(int size) {
            String message = mActivity.getString(R.string.toast_share_over_limit, size);
            Snackbars.makeSnackbar(mActivity, message, Snackbar.LENGTH_SHORT).show();
        }

        @Override
        public void confirmAction(FragmentManager fm, DocumentInfo pickTarget, int type) {
            ConfirmFragment.show(fm, pickTarget, type);
+9 −0
Original line number Diff line number Diff line
@@ -200,6 +200,15 @@ public class TestEnv {
        selectionMgr.setItemsSelected(ids, true);
    }

    public void selectMultipleFiles(int count) {
        List<String> ids = new ArrayList<>(count);
        for (int i = 0; i < count; i++) {
            DocumentInfo info = model.createFile(String.valueOf(i));
            ids.add(ModelId.build(info.authority, info.documentId));
        }
        selectionMgr.setItemsSelected(ids, true);
    }

    // Easily copy docs, so we don't pollute static data across tests.
    public static DocumentInfo clone(DocumentInfo a) {
        DocumentInfo b = new DocumentInfo();
+10 −0
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ public class TestDialogController implements DialogController {
    private boolean mDocumentsClipped;
    private boolean mViewInArchivesUnsupported;
    private boolean mShowOperationUnsupported;
    private boolean mShowShareOverLimit;
    private DocumentInfo mTarget;
    private int mConfrimType;

@@ -67,6 +68,11 @@ public class TestDialogController implements DialogController {
        mDocumentsClipped = true;
    }

    @Override
    public void showShareOverLimit(int size) {
        mShowShareOverLimit = true;
    }

    @Override
    public void confirmAction(FragmentManager fm, DocumentInfo pickTarget, int type) {
        mTarget = pickTarget;
@@ -96,6 +102,10 @@ public class TestDialogController implements DialogController {
        Assert.assertFalse(mDocumentsClipped);
    }

    public void assertShareOverLimitShown() {
        Assert.assertTrue(mShowShareOverLimit);
    }

    public void assertOverwriteConfirmed(DocumentInfo expected) {
        Assert.assertEquals(expected, mTarget);
        Assert.assertEquals(ConfirmFragment.TYPE_OVERWRITE, mConfrimType);
Loading