diff options
author | Jeff Sharkey <jsharkey@android.com> | 2013-09-12 21:59:06 -0700 |
---|---|---|
committer | Jeff Sharkey <jsharkey@android.com> | 2013-09-13 11:35:04 -0700 |
commit | 3e1189b3590aefb65a2af720ae2ba959bbd4188d (patch) | |
tree | d3cf503e72f633e7c6ef51792bec077434deede6 /packages/ExternalStorageProvider/src | |
parent | ab62870c7e787323057d3b16a3ff1fd118fb5925 (diff) | |
download | frameworks_base-3e1189b3590aefb65a2af720ae2ba959bbd4188d.zip frameworks_base-3e1189b3590aefb65a2af720ae2ba959bbd4188d.tar.gz frameworks_base-3e1189b3590aefb65a2af720ae2ba959bbd4188d.tar.bz2 |
Move search to roots; Documents root; hide empty.
Documents searches now happen root-wide, instead of only under a
subdirectory. Updates abstract class and flags to match. Add flag
for a root to indicate it's empty, and hide empty roots in UI unless
creating.
Define "Documents" public directory and storage backend to contain
files.
Bug: 10712057, 10710865, 10710758
Change-Id: I8716367568969f9cb1d83927b2bf5a7013809350
Diffstat (limited to 'packages/ExternalStorageProvider/src')
-rw-r--r-- | packages/ExternalStorageProvider/src/com/android/externalstorage/ExternalStorageProvider.java | 36 |
1 files changed, 27 insertions, 9 deletions
diff --git a/packages/ExternalStorageProvider/src/com/android/externalstorage/ExternalStorageProvider.java b/packages/ExternalStorageProvider/src/com/android/externalstorage/ExternalStorageProvider.java index ada3ad7..3e2cd15 100644 --- a/packages/ExternalStorageProvider/src/com/android/externalstorage/ExternalStorageProvider.java +++ b/packages/ExternalStorageProvider/src/com/android/externalstorage/ExternalStorageProvider.java @@ -62,7 +62,6 @@ public class ExternalStorageProvider extends DocumentsProvider { public String rootId; public int rootType; public int flags; - public int icon; public String title; public String docId; } @@ -85,9 +84,10 @@ public class ExternalStorageProvider extends DocumentsProvider { mIdToPath.put(rootId, path); final RootInfo root = new RootInfo(); - root.rootId = "primary"; + root.rootId = rootId; root.rootType = Root.ROOT_TYPE_DEVICE; - root.flags = Root.FLAG_SUPPORTS_CREATE | Root.FLAG_LOCAL_ONLY | Root.FLAG_ADVANCED; + root.flags = Root.FLAG_SUPPORTS_CREATE | Root.FLAG_LOCAL_ONLY | Root.FLAG_ADVANCED + | Root.FLAG_SUPPORTS_SEARCH; root.title = getContext().getString(R.string.root_internal_storage); root.docId = getDocIdForFile(path); mRoots.add(root); @@ -96,6 +96,25 @@ public class ExternalStorageProvider extends DocumentsProvider { throw new IllegalStateException(e); } + try { + final String rootId = "documents"; + final File path = Environment.getExternalStoragePublicDirectory( + Environment.DIRECTORY_DOCUMENTS); + mIdToPath.put(rootId, path); + + final RootInfo root = new RootInfo(); + root.rootId = rootId; + root.rootType = Root.ROOT_TYPE_SHORTCUT; + root.flags = Root.FLAG_SUPPORTS_CREATE | Root.FLAG_LOCAL_ONLY + | Root.FLAG_SUPPORTS_SEARCH; + root.title = getContext().getString(R.string.root_documents); + root.docId = getDocIdForFile(path); + mRoots.add(root); + mIdToRoot.put(rootId, root); + } catch (FileNotFoundException e) { + throw new IllegalStateException(e); + } + return true; } @@ -146,6 +165,9 @@ public class ExternalStorageProvider extends DocumentsProvider { if (target == null) { throw new FileNotFoundException("No root for " + tag); } + if (!target.exists()) { + target.mkdirs(); + } target = new File(target, path); if (!target.exists()) { throw new FileNotFoundException("Missing file for " + docId + " at " + target); @@ -163,9 +185,6 @@ public class ExternalStorageProvider extends DocumentsProvider { int flags = 0; - if (file.isDirectory()) { - flags |= Document.FLAG_DIR_SUPPORTS_SEARCH; - } if (file.isDirectory() && file.canWrite()) { flags |= Document.FLAG_DIR_SUPPORTS_CREATE; } @@ -200,7 +219,6 @@ public class ExternalStorageProvider extends DocumentsProvider { row.add(Root.COLUMN_ROOT_ID, root.rootId); row.add(Root.COLUMN_ROOT_TYPE, root.rootType); row.add(Root.COLUMN_FLAGS, root.flags); - row.add(Root.COLUMN_ICON, root.icon); row.add(Root.COLUMN_TITLE, root.title); row.add(Root.COLUMN_DOCUMENT_ID, root.docId); row.add(Root.COLUMN_AVAILABLE_BYTES, path.getFreeSpace()); @@ -260,10 +278,10 @@ public class ExternalStorageProvider extends DocumentsProvider { } @Override - public Cursor querySearchDocuments(String parentDocumentId, String query, String[] projection) + public Cursor querySearchDocuments(String rootId, String query, String[] projection) throws FileNotFoundException { final MatrixCursor result = new MatrixCursor(resolveDocumentProjection(projection)); - final File parent = getFileForDocId(parentDocumentId); + final File parent = mIdToPath.get(rootId); final LinkedList<File> pending = new LinkedList<File>(); pending.add(parent); |