Merge "Minor tweaks on Scoped Directory Access:" into nyc-dev
am: d847b51
* commit 'd847b511d3828fa6cb7a740ecd8876f16524f684':
Minor tweaks on Scoped Directory Access:
Change-Id: I03bb83eccb448ced4c919ada46102c514930ec1b
This commit is contained in:
@@ -315,27 +315,34 @@ public final class StorageVolume implements Parcelable {
|
|||||||
* To gain access to descendants (child, grandchild, etc) documents, use
|
* To gain access to descendants (child, grandchild, etc) documents, use
|
||||||
* {@link DocumentsContract#buildDocumentUriUsingTree(Uri, String)}, or
|
* {@link DocumentsContract#buildDocumentUriUsingTree(Uri, String)}, or
|
||||||
* {@link DocumentsContract#buildChildDocumentsUriUsingTree(Uri, String)} with the returned URI.
|
* {@link DocumentsContract#buildChildDocumentsUriUsingTree(Uri, String)} with the returned URI.
|
||||||
*
|
* <p>
|
||||||
* <b>If your application only needs to store internal data, consider using
|
* If your application only needs to store internal data, consider using
|
||||||
* {@link Context#getExternalFilesDirs(String) Context.getExternalFilesDirs},
|
* {@link Context#getExternalFilesDirs(String) Context.getExternalFilesDirs},
|
||||||
* {@link Context#getExternalCacheDirs()}, or
|
* {@link Context#getExternalCacheDirs()}, or {@link Context#getExternalMediaDirs()}, which
|
||||||
* {@link Context#getExternalMediaDirs()}, which require no permissions to read or write.
|
* require no permissions to read or write.
|
||||||
*
|
* <p>
|
||||||
* <strong>NOTE: </strong>requesting access to the entire volume is not recommended and it will
|
* Access to the entire volume is only available for non-primary volumes (for the primary
|
||||||
* result in a stronger message displayed to the user, which may cause the user to reject
|
* volume, apps can use the {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} and
|
||||||
* the request.
|
* {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} permissions) and should be used
|
||||||
*
|
* with caution, since users are more likely to deny access when asked for entire volume access
|
||||||
* @param directoryName must be one of
|
* rather than specific directories.
|
||||||
* {@link Environment#DIRECTORY_MUSIC}, {@link Environment#DIRECTORY_PODCASTS},
|
|
||||||
* {@link Environment#DIRECTORY_RINGTONES}, {@link Environment#DIRECTORY_ALARMS},
|
|
||||||
* {@link Environment#DIRECTORY_NOTIFICATIONS}, {@link Environment#DIRECTORY_PICTURES},
|
|
||||||
* {@link Environment#DIRECTORY_MOVIES}, {@link Environment#DIRECTORY_DOWNLOADS},
|
|
||||||
* {@link Environment#DIRECTORY_DCIM}, or {@link Environment#DIRECTORY_DOCUMENTS}, or
|
|
||||||
* {code null} to request access to the entire volume.
|
|
||||||
*
|
*
|
||||||
|
* @param directoryName must be one of {@link Environment#DIRECTORY_MUSIC},
|
||||||
|
* {@link Environment#DIRECTORY_PODCASTS}, {@link Environment#DIRECTORY_RINGTONES},
|
||||||
|
* {@link Environment#DIRECTORY_ALARMS}, {@link Environment#DIRECTORY_NOTIFICATIONS},
|
||||||
|
* {@link Environment#DIRECTORY_PICTURES}, {@link Environment#DIRECTORY_MOVIES},
|
||||||
|
* {@link Environment#DIRECTORY_DOWNLOADS}, {@link Environment#DIRECTORY_DCIM}, or
|
||||||
|
* {@link Environment#DIRECTORY_DOCUMENTS}, or {code null} to request access to the
|
||||||
|
* entire volume.
|
||||||
|
* @return intent to request access, or {@code null} if the requested directory is invalid for
|
||||||
|
* that volume.
|
||||||
* @see DocumentsContract
|
* @see DocumentsContract
|
||||||
*/
|
*/
|
||||||
public Intent createAccessIntent(String directoryName) {
|
public @Nullable Intent createAccessIntent(String directoryName) {
|
||||||
|
if ((isPrimary() && directoryName == null) ||
|
||||||
|
(directoryName != null && !Environment.isStandardDirectory(directoryName))) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
final Intent intent = new Intent(ACTION_OPEN_EXTERNAL_DIRECTORY);
|
final Intent intent = new Intent(ACTION_OPEN_EXTERNAL_DIRECTORY);
|
||||||
intent.putExtra(EXTRA_STORAGE_VOLUME, this);
|
intent.putExtra(EXTRA_STORAGE_VOLUME, this);
|
||||||
intent.putExtra(EXTRA_DIRECTORY_NAME, directoryName);
|
intent.putExtra(EXTRA_DIRECTORY_NAME, directoryName);
|
||||||
|
|||||||
@@ -204,6 +204,9 @@
|
|||||||
<string name="open_external_dialog_request">Grant <xliff:g id="appName" example="System Settings"><b>^1</b></xliff:g>
|
<string name="open_external_dialog_request">Grant <xliff:g id="appName" example="System Settings"><b>^1</b></xliff:g>
|
||||||
access to <xliff:g id="directory" example="Pictures"><i>^2</i></xliff:g> directory on
|
access to <xliff:g id="directory" example="Pictures"><i>^2</i></xliff:g> directory on
|
||||||
<xliff:g id="storage" example="SD Card"><i>^3</i></xliff:g>?</string>
|
<xliff:g id="storage" example="SD Card"><i>^3</i></xliff:g>?</string>
|
||||||
|
<!-- Text in an alert dialog asking user to grant app access to a given directory in the internal storage -->
|
||||||
|
<string name="open_external_dialog_request_primary_volume">Grant <xliff:g id="appName" example="System Settings"><b>^1</b></xliff:g>
|
||||||
|
access to <xliff:g id="directory" example="Pictures"><i>^2</i></xliff:g> directory?</string>
|
||||||
<!-- Text in an alert dialog asking user to grant app access to all data in an external storage volume -->
|
<!-- Text in an alert dialog asking user to grant app access to all data in an external storage volume -->
|
||||||
<string name="open_external_dialog_root_request">Grant <xliff:g id="appName" example="System Settings"><b>^1</b></xliff:g>
|
<string name="open_external_dialog_root_request">Grant <xliff:g id="appName" example="System Settings"><b>^1</b></xliff:g>
|
||||||
access to your data, including photos and videos, on <xliff:g id="storage" example="SD Card"><i>^2</i></xliff:g>?</string>
|
access to your data, including photos and videos, on <xliff:g id="storage" example="SD Card"><i>^2</i></xliff:g>?</string>
|
||||||
|
|||||||
@@ -86,6 +86,7 @@ public class OpenExternalDirectoryActivity extends Activity {
|
|||||||
private static final String EXTRA_VOLUME_LABEL = "com.android.documentsui.VOLUME_LABEL";
|
private static final String EXTRA_VOLUME_LABEL = "com.android.documentsui.VOLUME_LABEL";
|
||||||
private static final String EXTRA_VOLUME_UUID = "com.android.documentsui.VOLUME_UUID";
|
private static final String EXTRA_VOLUME_UUID = "com.android.documentsui.VOLUME_UUID";
|
||||||
private static final String EXTRA_IS_ROOT = "com.android.documentsui.IS_ROOT";
|
private static final String EXTRA_IS_ROOT = "com.android.documentsui.IS_ROOT";
|
||||||
|
private static final String EXTRA_IS_PRIMARY = "com.android.documentsui.IS_PRIMARY";
|
||||||
// Special directory name representing the full volume
|
// Special directory name representing the full volume
|
||||||
static final String DIRECTORY_ROOT = "ROOT_DIRECTORY";
|
static final String DIRECTORY_ROOT = "ROOT_DIRECTORY";
|
||||||
|
|
||||||
@@ -157,6 +158,13 @@ public class OpenExternalDirectoryActivity extends Activity {
|
|||||||
Log.d(TAG, "showFragment() for volume " + storageVolume.dump() + ", directory "
|
Log.d(TAG, "showFragment() for volume " + storageVolume.dump() + ", directory "
|
||||||
+ directoryName + ", and user " + userId);
|
+ directoryName + ", and user " + userId);
|
||||||
final boolean isRoot = directoryName.equals(DIRECTORY_ROOT);
|
final boolean isRoot = directoryName.equals(DIRECTORY_ROOT);
|
||||||
|
final boolean isPrimary = storageVolume.isPrimary();
|
||||||
|
|
||||||
|
if (isRoot && isPrimary) {
|
||||||
|
if (DEBUG) Log.d(TAG, "root access requested on primary volume");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
final File volumeRoot = storageVolume.getPathFile();
|
final File volumeRoot = storageVolume.getPathFile();
|
||||||
File file;
|
File file;
|
||||||
try {
|
try {
|
||||||
@@ -235,6 +243,7 @@ public class OpenExternalDirectoryActivity extends Activity {
|
|||||||
args.putString(EXTRA_VOLUME_UUID, volumeUuid);
|
args.putString(EXTRA_VOLUME_UUID, volumeUuid);
|
||||||
args.putString(EXTRA_APP_LABEL, appLabel);
|
args.putString(EXTRA_APP_LABEL, appLabel);
|
||||||
args.putBoolean(EXTRA_IS_ROOT, isRoot);
|
args.putBoolean(EXTRA_IS_ROOT, isRoot);
|
||||||
|
args.putBoolean(EXTRA_IS_PRIMARY, isPrimary);
|
||||||
|
|
||||||
final FragmentManager fm = activity.getFragmentManager();
|
final FragmentManager fm = activity.getFragmentManager();
|
||||||
final FragmentTransaction ft = fm.beginTransaction();
|
final FragmentTransaction ft = fm.beginTransaction();
|
||||||
@@ -352,6 +361,7 @@ public class OpenExternalDirectoryActivity extends Activity {
|
|||||||
private String mVolumeLabel;
|
private String mVolumeLabel;
|
||||||
private String mAppLabel;
|
private String mAppLabel;
|
||||||
private boolean mIsRoot;
|
private boolean mIsRoot;
|
||||||
|
private boolean mIsPrimary;
|
||||||
private CheckBox mDontAskAgain;
|
private CheckBox mDontAskAgain;
|
||||||
private OpenExternalDirectoryActivity mActivity;
|
private OpenExternalDirectoryActivity mActivity;
|
||||||
private AlertDialog mDialog;
|
private AlertDialog mDialog;
|
||||||
@@ -367,6 +377,7 @@ public class OpenExternalDirectoryActivity extends Activity {
|
|||||||
mVolumeLabel = args.getString(EXTRA_VOLUME_LABEL);
|
mVolumeLabel = args.getString(EXTRA_VOLUME_LABEL);
|
||||||
mAppLabel = args.getString(EXTRA_APP_LABEL);
|
mAppLabel = args.getString(EXTRA_APP_LABEL);
|
||||||
mIsRoot = args.getBoolean(EXTRA_IS_ROOT);
|
mIsRoot = args.getBoolean(EXTRA_IS_ROOT);
|
||||||
|
mIsPrimary= args.getBoolean(EXTRA_IS_PRIMARY);
|
||||||
}
|
}
|
||||||
mActivity = (OpenExternalDirectoryActivity) getActivity();
|
mActivity = (OpenExternalDirectoryActivity) getActivity();
|
||||||
}
|
}
|
||||||
@@ -435,7 +446,9 @@ public class OpenExternalDirectoryActivity extends Activity {
|
|||||||
message = TextUtils.expandTemplate(getText(
|
message = TextUtils.expandTemplate(getText(
|
||||||
R.string.open_external_dialog_root_request), mAppLabel, mVolumeLabel);
|
R.string.open_external_dialog_root_request), mAppLabel, mVolumeLabel);
|
||||||
} else {
|
} else {
|
||||||
message = TextUtils.expandTemplate(getText(R.string.open_external_dialog_request),
|
message = TextUtils.expandTemplate(
|
||||||
|
getText(mIsPrimary ? R.string.open_external_dialog_request_primary_volume
|
||||||
|
: R.string.open_external_dialog_request),
|
||||||
mAppLabel, directory, mVolumeLabel);
|
mAppLabel, directory, mVolumeLabel);
|
||||||
}
|
}
|
||||||
final TextView messageField = (TextView) view.findViewById(R.id.message);
|
final TextView messageField = (TextView) view.findViewById(R.id.message);
|
||||||
|
|||||||
Reference in New Issue
Block a user