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

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

Add more selection check when action clicked

Add size check on selection in case user rapidly click menu
above twice to cause IllegalArgumentException.

Fix: 136710834
Test: manual
Test: atest DocumentsUIGoogle
Change-Id: Idde46a67d692043c914894067819895a09b35435
parent 3b617862
Loading
Loading
Loading
Loading
+19 −0
Original line number Diff line number Diff line
@@ -803,6 +803,10 @@ public class DirectoryFragment extends Fragment implements SwipeRefreshLayout.On
    private void openDocuments(final Selection selected) {
        Metrics.logUserAction(MetricConsts.USER_ACTION_OPEN);

        if (selected.isEmpty()) {
            return;
        }

        // Model must be accessed in UI thread, since underlying cursor is not threadsafe.
        List<DocumentInfo> docs = mModel.getDocuments(selected);
        if (docs.size() > 1) {
@@ -815,6 +819,10 @@ public class DirectoryFragment extends Fragment implements SwipeRefreshLayout.On
    private void showChooserForDoc(final Selection<String> selected) {
        Metrics.logUserAction(MetricConsts.USER_ACTION_OPEN);

        if (selected.isEmpty()) {
            return;
        }

        assert selected.size() == 1;
        DocumentInfo doc =
                DocumentInfo.fromDirectoryCursor(mModel.getItem(selected.iterator().next()));
@@ -824,6 +832,10 @@ public class DirectoryFragment extends Fragment implements SwipeRefreshLayout.On
    private void transferDocuments(
            final Selection<String> selected, @Nullable DocumentStack destination,
            final @OpType int mode) {
        if (selected.isEmpty()) {
            return;
        }

        switch (mode) {
            case FileOperationService.OPERATION_COPY:
                Metrics.logUserAction(MetricConsts.USER_ACTION_COPY_TO);
@@ -936,6 +948,10 @@ public class DirectoryFragment extends Fragment implements SwipeRefreshLayout.On
    private void renameDocuments(Selection selected) {
        Metrics.logUserAction(MetricConsts.USER_ACTION_RENAME);

        if (selected.isEmpty()) {
            return;
        }

        // Batch renaming not supported
        // Rename option is only available in menu when 1 document selected
        assert selected.size() == 1;
@@ -963,6 +979,9 @@ public class DirectoryFragment extends Fragment implements SwipeRefreshLayout.On
    }

    public void pasteIntoFolder() {
        if (mSelectionMgr.getSelection().isEmpty()) {
            return;
        }
        assert (mSelectionMgr.getSelection().size() == 1);

        String modelId = mSelectionMgr.getSelection().iterator().next();
+7 −2
Original line number Diff line number Diff line
@@ -142,6 +142,10 @@ public class ActionHandler<T extends FragmentActivity & Addons> extends Abstract
    @Override
    public void openSelectedInNewWindow() {
        Selection<String> selection = getStableSelection();
        if (selection.isEmpty()) {
            return;
        }

        assert(selection.size() == 1);
        DocumentInfo doc = mModel.getDocument(selection.iterator().next());
        assert(doc != null);
@@ -352,8 +356,9 @@ public class ActionHandler<T extends FragmentActivity & Addons> extends Abstract
        Metrics.logUserAction(MetricConsts.USER_ACTION_SHARE);

        Selection<String> selection = getStableSelection();

        assert(!selection.isEmpty());
        if (selection.isEmpty()) {
            return;
        }

        // Model must be accessed in UI thread, since underlying cursor is not threadsafe.
        List<DocumentInfo> docs = mModel.loadDocuments(