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

Commit a36f48e0 authored by Steve McKay's avatar Steve McKay Committed by android-build-merger
Browse files

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

am: 1db228a

* commit '1db228a74bf80829b1b06d39f516f8b40aa44f1b':
  Daeal with null cursors more leniently.

Change-Id: Ic63fe4fb2e9116aa81a2795b1413b7d9aa9f3ef1
parents 15d1104e 3c9f7a7a
Loading
Loading
Loading
Loading
+12 −1
Original line number Original line Diff line number Diff line
@@ -17,7 +17,6 @@
package com.android.documentsui;
package com.android.documentsui;


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


import android.content.ClipData;
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.
 * Provides support for gather a list of quick-viewable files into a quick view intent.
 */
 */
final class QuickViewIntentBuilder {
final class QuickViewIntentBuilder {

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


    private final DocumentInfo mDocument;
    private final DocumentInfo mDocument;
@@ -127,8 +128,18 @@ final class QuickViewIntentBuilder {
        for (int i = 0; i < siblingIds.length; i++) {
        for (int i = 0; i < siblingIds.length; i++) {
            cursor = mModel.getItem(siblingIds[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);
            mimeType = getCursorString(cursor, Document.COLUMN_MIME_TYPE);
            if (Document.MIME_TYPE_DIR.equals(mimeType)) {
            if (Document.MIME_TYPE_DIR.equals(mimeType)) {
                if (DEBUG) Log.d(TAG,
                        "Skipping directory, not supported by quick view. modelId: "
                        + siblingIds[i]);
                continue;
                continue;
            }
            }


+22 −7
Original line number Original line Diff line number Diff line
@@ -352,7 +352,10 @@ public class DirectoryFragment extends Fragment
    private boolean handleViewItem(String id) {
    private boolean handleViewItem(String id) {
        final Cursor cursor = mModel.getItem(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 String docMimeType = getCursorString(cursor, Document.COLUMN_MIME_TYPE);
        final int docFlags = getCursorInt(cursor, Document.COLUMN_FLAGS);
        final int docFlags = getCursorInt(cursor, Document.COLUMN_FLAGS);
@@ -466,11 +469,14 @@ public class DirectoryFragment extends Fragment
        public boolean onBeforeItemStateChange(String modelId, boolean selected) {
        public boolean onBeforeItemStateChange(String modelId, boolean selected) {
            if (selected) {
            if (selected) {
                final Cursor cursor = mModel.getItem(modelId);
                final Cursor cursor = mModel.getItem(modelId);

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


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

                return mTuner.canSelectType(docMimeType, docFlags);
                return mTuner.canSelectType(docMimeType, docFlags);
            }
            }
            return true;
            return true;
@@ -480,7 +486,7 @@ public class DirectoryFragment extends Fragment
        public void onItemStateChanged(String modelId, boolean selected) {
        public void onItemStateChanged(String modelId, boolean selected) {
            final Cursor cursor = mModel.getItem(modelId);
            final Cursor cursor = mModel.getItem(modelId);
            if (cursor == null) {
            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.");
                        + ". Ignoring state changed event.");
                return;
                return;
            }
            }
@@ -1105,6 +1111,10 @@ public class DirectoryFragment extends Fragment
        List<String> enabled = new ArrayList<String>();
        List<String> enabled = new ArrayList<String>();
        for (String id : mAdapter.getModelIds()) {
        for (String id : mAdapter.getModelIds()) {
            Cursor cursor = getModel().getItem(id);
            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);
            String docMimeType = getCursorString(cursor, Document.COLUMN_MIME_TYPE);
            int docFlags = getCursorInt(cursor, Document.COLUMN_FLAGS);
            int docFlags = getCursorInt(cursor, Document.COLUMN_FLAGS);
            if (isDocumentEnabled(docMimeType, docFlags)) {
            if (isDocumentEnabled(docMimeType, docFlags)) {
@@ -1193,7 +1203,10 @@ public class DirectoryFragment extends Fragment
            String id = getModelId(v);
            String id = getModelId(v);
            if (id != null) {
            if (id != null) {
                Cursor dstCursor = mModel.getItem(id);
                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);
                return DocumentInfo.fromDirectoryCursor(dstCursor);
            }
            }


@@ -1266,8 +1279,10 @@ public class DirectoryFragment extends Fragment
        }
        }


        final Cursor cursor = mModel.getItem(modelId);
        final Cursor cursor = mModel.getItem(modelId);

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


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


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


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


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

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


        return mCursor;
    }

    boolean isEmpty() {
    boolean isEmpty() {
        return mCursorCount == 0;
        return mCursorCount == 0;
    }
    }
@@ -424,8 +432,11 @@ public class Model {
        final List<DocumentInfo> docs =  new ArrayList<>(size);
        final List<DocumentInfo> docs =  new ArrayList<>(size);
        for (String modelId: items.getAll()) {
        for (String modelId: items.getAll()) {
            final Cursor cursor = getItem(modelId);
            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));
            docs.add(DocumentInfo.fromDirectoryCursor(cursor));
        }
        }
        return docs;
        return docs;
+2 −0
Original line number Original line Diff line number Diff line
@@ -139,11 +139,13 @@ public class DocumentInfo implements Durable, Parcelable {
    };
    };


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


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