Merge "Add StorageVolume#createOpenDocumentTreeIntent"

This commit is contained in:
TreeHugger Robot
2018-12-20 15:49:11 +00:00
committed by Android (Google) Code Review
4 changed files with 34 additions and 12 deletions

View File

@@ -35147,6 +35147,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();

View File

@@ -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) {

View File

@@ -237,6 +237,9 @@ public final class DocumentsContract {
public static final String EXTERNAL_STORAGE_PROVIDER_AUTHORITY =
"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";
@@ -856,16 +859,6 @@ public final class DocumentsContract {
.authority(authority).appendPath(PATH_ROOT).appendPath(rootId).build();
}
/**
* 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

View File

@@ -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;