diff options
author | Amin Shaikh <ashaikh@google.com> | 2018-11-19 12:33:27 -0500 |
---|---|---|
committer | Amin Shaikh <ashaikh@google.com> | 2018-12-18 11:44:13 -0500 |
commit | 305e87e6d91ad48a0f1194411c7760c9ecb4e695 (patch) | |
tree | 28354c8044e3a9247e9a3eb3f90a1137f9cfe251 | |
parent | 3e24ffd20862f651a059ee4b966d40d9c81334fa (diff) |
Add StorageVolume#createOpenDocumentTreeIntent
Change-Id: I6894bad24fa7757dee1028a31ba0b07701baa7b3
Fixes: 119519300
Test: manually using ApiDemos Content > Storage > Documents
4 files changed, 34 insertions, 12 deletions
diff --git a/api/current.txt b/api/current.txt index 38bf3abd5013..885c5b0b2562 100644 --- a/api/current.txt +++ b/api/current.txt @@ -35129,6 +35129,7 @@ package android.os.storage { public final class StorageVolume implements android.os.Parcelable { method public deprecated android.content.Intent createAccessIntent(java.lang.String); + method public android.content.Intent createOpenDocumentTreeIntent(); method public int describeContents(); method public java.lang.String getDescription(android.content.Context); method public java.lang.String getState(); diff --git a/core/java/android/os/storage/StorageVolume.java b/core/java/android/os/storage/StorageVolume.java index 8a03e9eb7507..df1a7131a7ae 100644 --- a/core/java/android/os/storage/StorageVolume.java +++ b/core/java/android/os/storage/StorageVolume.java @@ -16,6 +16,7 @@ package android.os.storage; +import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.TestApi; import android.annotation.UnsupportedAppUsage; @@ -348,6 +349,32 @@ public final class StorageVolume implements Parcelable { return intent; } + /** + * Builds an {@link Intent#ACTION_OPEN_DOCUMENT_TREE} to allow the user to grant access to any + * directory subtree (or entire volume) from the {@link android.provider.DocumentsProvider}s + * available on the device. The initial location of the document navigation will be the root of + * this {@link StorageVolume}. + * + * Note that the returned {@link Intent} simply suggests that the user picks this {@link + * StorageVolume} by default, but the user may select a different location. Callers must respect + * the user's chosen location, even if it is different from the originally requested location. + * + * @return intent to {@link Intent#ACTION_OPEN_DOCUMENT_TREE} initially showing the contents + * of this {@link StorageVolume} + * @see Intent#ACTION_OPEN_DOCUMENT_TREE + */ + @NonNull public Intent createOpenDocumentTreeIntent() { + final String rootId = isEmulated() + ? DocumentsContract.EXTERNAL_STORAGE_PRIMARY_EMULATED_ROOT_ID + : mFsUuid; + final Uri rootUri = DocumentsContract.buildRootUri( + DocumentsContract.EXTERNAL_STORAGE_PROVIDER_AUTHORITY, rootId); + final Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE) + .putExtra(DocumentsContract.EXTRA_INITIAL_URI, rootUri) + .putExtra(DocumentsContract.EXTRA_SHOW_ADVANCED, true); + return intent; + } + @Override public boolean equals(Object obj) { if (obj instanceof StorageVolume && mPath != null) { diff --git a/core/java/android/provider/DocumentsContract.java b/core/java/android/provider/DocumentsContract.java index cd991cc0d6fc..a323ed1a51cb 100644 --- a/core/java/android/provider/DocumentsContract.java +++ b/core/java/android/provider/DocumentsContract.java @@ -238,6 +238,9 @@ public final class DocumentsContract { "com.android.externalstorage.documents"; /** {@hide} */ + public static final String EXTERNAL_STORAGE_PRIMARY_EMULATED_ROOT_ID = "primary"; + + /** {@hide} */ public static final String PACKAGE_DOCUMENTS_UI = "com.android.documentsui"; /** @@ -857,16 +860,6 @@ public final class DocumentsContract { } /** - * Builds URI for user home directory on external (local) storage. - * {@hide} - */ - public static Uri buildHomeUri() { - // TODO: Avoid this type of interpackage copying. Added here to avoid - // direct coupling, but not ideal. - return DocumentsContract.buildRootUri(EXTERNAL_STORAGE_PROVIDER_AUTHORITY, "home"); - } - - /** * Build URI representing the recently modified documents of a specific root * in a document provider. When queried, a provider will return zero or more * rows with columns defined by {@link Document}. diff --git a/packages/ExternalStorageProvider/src/com/android/externalstorage/ExternalStorageProvider.java b/packages/ExternalStorageProvider/src/com/android/externalstorage/ExternalStorageProvider.java index 1eb4b7494085..8d04702ea5f6 100644 --- a/packages/ExternalStorageProvider/src/com/android/externalstorage/ExternalStorageProvider.java +++ b/packages/ExternalStorageProvider/src/com/android/externalstorage/ExternalStorageProvider.java @@ -67,7 +67,7 @@ public class ExternalStorageProvider extends FileSystemProvider { private static final boolean DEBUG = false; - public static final String AUTHORITY = "com.android.externalstorage.documents"; + public static final String AUTHORITY = DocumentsContract.EXTERNAL_STORAGE_PROVIDER_AUTHORITY; private static final Uri BASE_URI = new Uri.Builder().scheme(ContentResolver.SCHEME_CONTENT).authority(AUTHORITY).build(); @@ -96,7 +96,8 @@ public class ExternalStorageProvider extends FileSystemProvider { public boolean reportAvailableBytes = true; } - private static final String ROOT_ID_PRIMARY_EMULATED = "primary"; + private static final String ROOT_ID_PRIMARY_EMULATED = + DocumentsContract.EXTERNAL_STORAGE_PRIMARY_EMULATED_ROOT_ID; private static final String ROOT_ID_HOME = "home"; private StorageManager mStorageManager; |