Created a new API to grant scoped directory access to applications.

The Storage Access Framework currently provides an
API (OPEN_DOCUMENT_TREE) that lets the user pick a directory to be used
by the application. Although this APIs is very powerful (for example, it
allows the user to create sub-directories, delete and share files,
etc...), it's too complex for simpler use cases like a camera
application trying to have access to the standard Pictures directory.

The new API (OPEN_EXTERNAL_DIRECTORY) simplifies this scenario by
letting the application select a standard, pre-defined directory (as
defined by android.os.Environment). The user still needs to grant access
to the requested directory, but the resulting UI will be simpler and
more straightforward.

Usage example:

  // ...
  int requestCode = 42;
  Intent intent = new Intent(Intent.ACTION_OPEN_EXTERNAL_DIRECTORY);
  intent.setData(Uri.fromFile(
    new File(Environment.getExternalStorageDirectory(),
             Environment.DIRECTORY_PICTURES)));
  startActivityForResult(intent, requestCode);
  // ...

  @Override
  public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode != Activity.RESULT_OK) {
      return;
    }
    Uri uri = data.getData();
    int modeFlags = data.getFlags()
        & (Intent.FLAG_GRANT_READ_URI_PERMISSION
        | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
    getContentResolver().takePersistableUriPermission(uri, modeFlags);
  }

BUG: 23011462
Change-Id: Ie832026532f74e681ef220b761667eb66ff3c8b0
6 files changed