Filter roots based on incoming request.

When incoming request is for local-only content, or for ACTION_CREATE,
only include roots advertise those features.

Filters roots based on the allowed MIME types and the supported types
advertised by each root.  This supports displaying Images and Audio
roots only when requesting those content types.  Applies the same
filter when deciding which roots to query for recents.

Fixes advanced filtering instead of limiting to just devices. Update
sorting so that Recent always appears first. Add testing support for
LOCAL_ONLY.

Bug: 10597317, 10526535
Change-Id: Ic5ccf475c4fe93fd52b29388d369d7f6915c0c42
diff --git a/src/com/android/documentsui/DirectoryFragment.java b/src/com/android/documentsui/DirectoryFragment.java
index c24341e..5b23ca5 100644
--- a/src/com/android/documentsui/DirectoryFragment.java
+++ b/src/com/android/documentsui/DirectoryFragment.java
@@ -191,7 +191,9 @@
                                 authority, docId, query);
                         return new DirectoryLoader(context, rootId, contentsUri, state.sortOrder);
                     case TYPE_RECENT_OPEN:
-                        return new RecentLoader(context);
+                        final RootsCache roots = DocumentsApplication.getRootsCache(context);
+                        final List<RootInfo> matchingRoots = roots.getMatchingRoots(state);
+                        return new RecentLoader(context, matchingRoots);
                     default:
                         throw new IllegalStateException("Unknown type " + mType);