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

Commit 3c9f7a7a authored by Steve McKay's avatar Steve McKay Committed by Android (Google) Code Review
Browse files

Merge "Daeal with null cursors more leniently." into nyc-dev

parents 8a9e67d3 5a22a119
Loading
Loading
Loading
Loading
+12 −1
Original line number Diff line number Diff line
@@ -17,7 +17,6 @@
package com.android.documentsui;

import static com.android.documentsui.Shared.DEBUG;
import static com.android.documentsui.Shared.TAG;
import static com.android.documentsui.model.DocumentInfo.getCursorString;

import android.content.ClipData;
@@ -45,6 +44,8 @@ import java.util.List;
 * Provides support for gather a list of quick-viewable files into a quick view intent.
 */
final class QuickViewIntentBuilder {

    private static final String TAG = "QuickViewIntentBuilder";
    private static final int MAX_CLIP_ITEMS = 1000;

    private final DocumentInfo mDocument;
@@ -127,8 +128,18 @@ final class QuickViewIntentBuilder {
        for (int i = 0; i < siblingIds.length; i++) {
            cursor = mModel.getItem(siblingIds[i]);

            if (cursor == null) {
                if (DEBUG) Log.d(TAG,
                        "Unable to obtain cursor for sibling document, modelId: "
                        + siblingIds[i]);
                continue;
            }

            mimeType = getCursorString(cursor, Document.COLUMN_MIME_TYPE);
            if (Document.MIME_TYPE_DIR.equals(mimeType)) {
                if (DEBUG) Log.d(TAG,
                        "Skipping directory, not supported by quick view. modelId: "
                        + siblingIds[i]);
                continue;
            }

+22 −7
Original line number Diff line number Diff line
@@ -351,7 +351,10 @@ public class DirectoryFragment extends Fragment
    private boolean handleViewItem(String id) {
        final Cursor cursor = mModel.getItem(id);

        assert(cursor != null);
        if (cursor == null) {
            Log.w(TAG, "Can't view item. Can't obtain cursor for modeId" + id);
            return false;
        }

        final String docMimeType = getCursorString(cursor, Document.COLUMN_MIME_TYPE);
        final int docFlags = getCursorInt(cursor, Document.COLUMN_FLAGS);
@@ -465,11 +468,14 @@ public class DirectoryFragment extends Fragment
        public boolean onBeforeItemStateChange(String modelId, boolean selected) {
            if (selected) {
                final Cursor cursor = mModel.getItem(modelId);

                assert(cursor != null);
                if (cursor == null) {
                    Log.w(TAG, "Can't obtain cursor for modelId: " + modelId);
                    return false;
                }

                final String docMimeType = getCursorString(cursor, Document.COLUMN_MIME_TYPE);
                final int docFlags = getCursorInt(cursor, Document.COLUMN_FLAGS);

                return mTuner.canSelectType(docMimeType, docFlags);
            }
            return true;
@@ -479,7 +485,7 @@ public class DirectoryFragment extends Fragment
        public void onItemStateChanged(String modelId, boolean selected) {
            final Cursor cursor = mModel.getItem(modelId);
            if (cursor == null) {
                Log.e(TAG, "Model returned null cursor for document: " + modelId
                Log.w(TAG, "Model returned null cursor for document: " + modelId
                        + ". Ignoring state changed event.");
                return;
            }
@@ -1104,6 +1110,10 @@ public class DirectoryFragment extends Fragment
        List<String> enabled = new ArrayList<String>();
        for (String id : mAdapter.getModelIds()) {
            Cursor cursor = getModel().getItem(id);
            if (cursor != null) {
                Log.w(TAG, "Skipping selection. Can't obtain cursor for modeId: " + id);
                continue;
            }
            String docMimeType = getCursorString(cursor, Document.COLUMN_MIME_TYPE);
            int docFlags = getCursorInt(cursor, Document.COLUMN_FLAGS);
            if (isDocumentEnabled(docMimeType, docFlags)) {
@@ -1192,7 +1202,10 @@ public class DirectoryFragment extends Fragment
            String id = getModelId(v);
            if (id != null) {
                Cursor dstCursor = mModel.getItem(id);
                assert(dstCursor != null);
                if (dstCursor != null) {
                    Log.w(TAG, "Invalid destination. Can't obtain cursor for modelId: " + id);
                    return null;
                }
                return DocumentInfo.fromDirectoryCursor(dstCursor);
            }

@@ -1265,8 +1278,10 @@ public class DirectoryFragment extends Fragment
        }

        final Cursor cursor = mModel.getItem(modelId);

        assert(cursor != null);
        if (cursor == null) {
            Log.w(TAG, "Undraggable document. Can't obtain cursor for modelId " + modelId);
            return Collections.EMPTY_LIST;
        }

        return Lists.newArrayList(
                DocumentInfo.fromDirectoryCursor(cursor));
+4 −3
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import static com.android.documentsui.model.DocumentInfo.getCursorString;

import android.annotation.Nullable;
import android.content.Context;
import android.database.Cursor;
import android.os.Handler;
import android.os.Looper;
import android.os.SystemClock;
@@ -476,9 +477,9 @@ class FocusManager implements View.OnFocusChangeListener {
            List<String> index = new ArrayList<>(itemCount);
            for (int i = 0; i < itemCount; i++) {
                String modelId = mAdapter.getModelId(i);
                if (modelId != null) {
                    String title =
                            getCursorString(mModel.getItem(modelId), Document.COLUMN_DISPLAY_NAME);
                Cursor cursor = mModel.getItem(modelId);
                if (modelId != null && cursor != null) {
                    String title = getCursorString(cursor, Document.COLUMN_DISPLAY_NAME);
                    // Perform case-insensitive search.
                    index.add(title.toLowerCase());
                } else {
+17 −6
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@ import com.android.documentsui.dirlist.MultiSelectManager.Selection;
import com.android.documentsui.model.DocumentInfo;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -403,13 +404,20 @@ public class Model {

    public @Nullable Cursor getItem(String modelId) {
        Integer pos = mPositions.get(modelId);
        if (pos != null) {
            mCursor.moveToPosition(pos);
            return mCursor;
        if (pos == null) {
            if (DEBUG) Log.d(TAG, "Unabled to find cursor position for modelId: " + modelId);
            return null;
        }

        if (!mCursor.moveToPosition(pos)) {
            if (DEBUG) Log.d(TAG,
                    "Unabled to move cursor to position " + pos + " for modelId: " + modelId);
            return null;
        }

        return mCursor;
    }

    boolean isEmpty() {
        return mCursorCount == 0;
    }
@@ -424,8 +432,11 @@ public class Model {
        final List<DocumentInfo> docs =  new ArrayList<>(size);
        for (String modelId: items.getAll()) {
            final Cursor cursor = getItem(modelId);
            assert(cursor != null);

            if (cursor == null) {
                Log.w(TAG,
                        "Skipping document. Unabled to obtain cursor for modelId: " + modelId);
                continue;
            }
            docs.add(DocumentInfo.fromDirectoryCursor(cursor));
        }
        return docs;
+2 −0
Original line number Diff line number Diff line
@@ -139,11 +139,13 @@ public class DocumentInfo implements Durable, Parcelable {
    };

    public static DocumentInfo fromDirectoryCursor(Cursor cursor) {
        assert(cursor != null);
        final String authority = getCursorString(cursor, RootCursorWrapper.COLUMN_AUTHORITY);
        return fromCursor(cursor, authority);
    }

    public static DocumentInfo fromCursor(Cursor cursor, String authority) {
        assert(cursor != null);
        final DocumentInfo info = new DocumentInfo();
        info.updateFromCursor(cursor, authority);
        return info;