Clean up sharing virtual files.
Test: Unit tests.
Bug: 28409713
Change-Id: I40a3429497220dd379060c5dddaee58dc2084b24
(cherry picked from commit 699acefa333ffed55bba9ab01bef82447ccd4ab0)
diff --git a/src/com/android/documentsui/dirlist/Model.java b/src/com/android/documentsui/dirlist/Model.java
index 259529a..63dcb4b 100644
--- a/src/com/android/documentsui/dirlist/Model.java
+++ b/src/com/android/documentsui/dirlist/Model.java
@@ -56,7 +56,7 @@
/**
* Filter that passes (returns true) all non-partial files and non-archived files.
*/
- public static final Predicate<Cursor> NO_PARTIAL_NOR_ARCHIVED_FILE_FILTER = (Cursor c) -> {
+ public static final Predicate<Cursor> SHARABLE_FILE_FILTER = (Cursor c) -> {
int flags = getCursorInt(c, Document.COLUMN_FLAGS);
String authority = getCursorString(c, RootCursorWrapper.COLUMN_AUTHORITY);
return (flags & Document.FLAG_PARTIAL) == 0
@@ -232,29 +232,42 @@
final int size = (selection != null) ? selection.size() : 0;
final List<DocumentInfo> docs = new ArrayList<>(size);
+ DocumentInfo doc;
for (String modelId: selection) {
- loadDocument(docs, modelId, filter);
+ doc = loadDocument(modelId, filter);
+ if (doc != null) {
+ docs.add(doc);
+ }
}
return docs;
}
+ public boolean hasDocuments(Selection selection, Predicate<Cursor> filter) {
+ for (String modelId: selection) {
+ if (loadDocument(modelId, filter) != null) {
+ return true;
+ }
+ }
+ return false;
+ }
+
/**
- * @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) {
+ private @Nullable DocumentInfo loadDocument(String modelId, Predicate<Cursor> filter) {
final Cursor cursor = getItem(modelId);
if (cursor == null) {
Log.w(TAG, "Unable to obtain document for modelId: " + modelId);
+ return null;
}
if (filter.test(cursor)) {
- docs.add(DocumentInfo.fromDirectoryCursor(cursor));
- } else {
- if (VERBOSE) Log.v(TAG, "Filtered document from results: " + modelId);
+ return DocumentInfo.fromDirectoryCursor(cursor);
}
+
+ if (VERBOSE) Log.v(TAG, "Filtered out document from results: " + modelId);
+ return null;
}
public Uri getItemUri(String modelId) {
diff --git a/src/com/android/documentsui/files/ActionHandler.java b/src/com/android/documentsui/files/ActionHandler.java
index fd5959a..ff8f5a9 100644
--- a/src/com/android/documentsui/files/ActionHandler.java
+++ b/src/com/android/documentsui/files/ActionHandler.java
@@ -290,10 +290,7 @@
// Model must be accessed in UI thread, since underlying cursor is not threadsafe.
List<DocumentInfo> docs =
- mScope.model.loadDocuments(selection, Model.NO_PARTIAL_NOR_ARCHIVED_FILE_FILTER);
-
- List<DocumentInfo> virtualDocs =
- mScope.model.loadDocuments(selection, Model.VIRTUAL_DOCUMENT_FILTER);
+ mScope.model.loadDocuments(selection, Model.SHARABLE_FILE_FILTER);
Intent intent;
@@ -323,7 +320,8 @@
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.addCategory(Intent.CATEGORY_DEFAULT);
- if (virtualDocs.size() > 0) {
+
+ if (mScope.model.hasDocuments(selection, Model.VIRTUAL_DOCUMENT_FILTER)) {
intent.addCategory(Intent.CATEGORY_TYPED_OPENABLE);
}