Move share impl into files ActionHandler.

Don't include partial files when sharing.
Add test coverage.

Filter documents as list is loaded for sharing, eliminating need to copy.
Rename MimePredicate to MimeTypes and drop the Predicate impl (since nobody was using it).
    Move additional mime type functioanlity to the class.

Input DocumentsAdapter.Environment and LoaderCallbacks in inner classes.
    This reduces the number of public methods hanging off of DirectoryFragment.
In DirFragment normalize access to context/activity and State.

Added an IntentAssert class with some handy assert methods.

Addressed xutan@'s comment from last CL.

Add friendly support for selecting documents in TestEnv.

Change-Id: I55ea78ab5bef3a2b2644f6e0a3384adeaba78599
diff --git a/src/com/android/documentsui/dirlist/Model.java b/src/com/android/documentsui/dirlist/Model.java
index 016346a..ea51e91 100644
--- a/src/com/android/documentsui/dirlist/Model.java
+++ b/src/com/android/documentsui/dirlist/Model.java
@@ -42,12 +42,23 @@
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.function.Predicate;
 
 /**
  * The data model for the current loaded directory.
  */
 @VisibleForTesting
 public class Model {
+
+    /**
+     * Filter that passes (returns true) all non-virtual, non-partial files.
+     */
+    public static final Predicate<Cursor> CONCRETE_FILE_FILTER = (Cursor c) -> {
+        int flags = DocumentInfo.getCursorInt(c, Document.COLUMN_FLAGS);
+        return (flags & Document.FLAG_VIRTUAL_DOCUMENT) == 0
+                && (flags & Document.FLAG_PARTIAL) == 0;
+    };
+
     private static final String TAG = "Model";
 
     private boolean mIsLoading;
@@ -215,6 +226,35 @@
                 : DocumentInfo.fromDirectoryCursor(cursor);
     }
 
+    public List<DocumentInfo> loadDocuments(Selection selection, Predicate<Cursor> filter) {
+        final int size = (selection != null) ? selection.size() : 0;
+
+        final List<DocumentInfo> docs =  new ArrayList<>(size);
+        for (String modelId: selection) {
+            loadDocument(docs, modelId, filter);
+        }
+        return docs;
+    }
+
+    /**
+     * @param docs
+     * @return DocumentInfo, or null. If filter returns false, null will be returned.
+     */
+    private void loadDocument(
+            List<DocumentInfo> docs, String modelId, Predicate<Cursor> filter) {
+        final Cursor cursor = getItem(modelId);
+
+        if (cursor == null) {
+            Log.w(TAG, "Unable to obtain document for modelId: " + modelId);
+        }
+
+        if (filter.test(cursor)) {
+            docs.add(DocumentInfo.fromDirectoryCursor(cursor));
+        } else {
+            if (DEBUG) Log.v(TAG, "Filtered document from results: " + modelId);
+        }
+    }
+
     public Uri getItemUri(String modelId) {
         final Cursor cursor = getItem(modelId);
         return DocumentInfo.getUri(cursor);