Add Feature Flag support.

Bug: 35923154
Change-Id: I34dd956e8309c779e7a3f35eadc3d84132b970ce
diff --git a/src/com/android/documentsui/dirlist/Model.java b/src/com/android/documentsui/dirlist/Model.java
index 3de9c73..43aed9a 100644
--- a/src/com/android/documentsui/dirlist/Model.java
+++ b/src/com/android/documentsui/dirlist/Model.java
@@ -16,10 +16,8 @@
 
 package com.android.documentsui.dirlist;
 
-import static com.android.documentsui.base.DocumentInfo.getCursorInt;
 import static com.android.documentsui.base.DocumentInfo.getCursorString;
 import static com.android.documentsui.base.Shared.DEBUG;
-import static com.android.documentsui.base.Shared.ENABLE_OMC_API_FEATURES;
 import static com.android.documentsui.base.Shared.VERBOSE;
 
 import android.annotation.IntDef;
@@ -35,10 +33,10 @@
 import android.util.Log;
 
 import com.android.documentsui.DirectoryResult;
-import com.android.documentsui.archives.ArchivesProvider;
+import com.android.documentsui.base.DocumentFilters;
 import com.android.documentsui.base.DocumentInfo;
 import com.android.documentsui.base.EventListener;
-import com.android.documentsui.base.Shared;
+import com.android.documentsui.base.Features;
 import com.android.documentsui.roots.RootCursorWrapper;
 import com.android.documentsui.selection.Selection;
 
@@ -58,46 +56,26 @@
 @VisibleForTesting
 public class Model {
 
-    /**
-     * Filter that passes (returns true) for all files which can be shared.
-     */
-    public static final Predicate<Cursor> SHARABLE_FILE_FILTER = (Cursor c) -> {
-        int flags = getCursorInt(c, Document.COLUMN_FLAGS);
-        String authority = getCursorString(c, RootCursorWrapper.COLUMN_AUTHORITY);
-        if (!ENABLE_OMC_API_FEATURES) {
-            return (flags & Document.FLAG_PARTIAL) == 0
-                    && (flags & Document.FLAG_VIRTUAL_DOCUMENT) == 0
-                    && !ArchivesProvider.AUTHORITY.equals(authority);
-        }
-        return (flags & Document.FLAG_PARTIAL) == 0
-                && !ArchivesProvider.AUTHORITY.equals(authority);
-    };
-
-    /**
-     * Filter that passes (returns true) only virtual documents.
-     */
-    public static final Predicate<Cursor> VIRTUAL_DOCUMENT_FILTER  = (Cursor c) -> {
-        int flags = getCursorInt(c, Document.COLUMN_FLAGS);
-        return (flags & Document.FLAG_VIRTUAL_DOCUMENT) != 0;
-    };
-
-    private static final Predicate<Cursor> ANY_FILE_FILTER = (Cursor c) -> true;
-
     private static final String TAG = "Model";
 
+    @Nullable String info;
+    @Nullable String error;
+    @Nullable DocumentInfo doc;
+
+    private final Features mFeatures;
     /** Maps Model ID to cursor positions, for looking up items by Model ID. */
     private final Map<String, Integer> mPositions = new HashMap<>();
     private final Set<String> mFileNames = new HashSet<>();
 
     private boolean mIsLoading;
     private List<EventListener<Update>> mUpdateListeners = new ArrayList<>();
-    @Nullable private Cursor mCursor;
+    private @Nullable Cursor mCursor;
     private int mCursorCount;
     private String mIds[] = new String[0];
 
-    @Nullable String info;
-    @Nullable String error;
-    @Nullable DocumentInfo doc;
+    public Model(Features features) {
+        mFeatures = features;
+    }
 
     public void addUpdateListener(EventListener<Update> listener) {
         mUpdateListeners.add(listener);
@@ -114,7 +92,7 @@
     }
 
     private void notifyUpdateListeners(Exception e) {
-        Update error = new Update(e);
+        Update error = new Update(e, mFeatures.isRemoteActionsEnabled());
         for (EventListener<Update> handler: mUpdateListeners) {
             handler.accept(error);
         }
@@ -227,7 +205,7 @@
     }
 
     public List<DocumentInfo> getDocuments(Selection selection) {
-        return loadDocuments(selection, ANY_FILE_FILTER);
+        return loadDocuments(selection, DocumentFilters.ANY);
     }
 
     public @Nullable DocumentInfo getDocument(String modelId) {
@@ -307,16 +285,19 @@
 
         private final @UpdateType int mUpdateType;
         private final @Nullable Exception mException;
+        private final boolean mRemoteActionEnabled;
 
         private Update() {
             mUpdateType = TYPE_UPDATE;
             mException = null;
+            mRemoteActionEnabled = false;
         }
 
-        public Update(Exception exception) {
+        public Update(Exception exception, boolean remoteActionsEnabled) {
             assert(exception != null);
             mUpdateType = TYPE_UPDATE_EXCEPTION;
             mException = exception;
+            mRemoteActionEnabled = remoteActionsEnabled;
         }
 
         public boolean isUpdate() {
@@ -328,7 +309,8 @@
         }
 
         public boolean hasRecoverableException() {
-            return Shared.ENABLE_OMC_API_FEATURES && hasException()
+            return mRemoteActionEnabled
+                    && hasException()
                     && mException instanceof RecoverableSecurityException;
         }