Skip to content

Commit

Permalink
Add RSE support for update() and delete().
Browse files Browse the repository at this point in the history
We already had RSE support in place for opening a file for write
access, but this change adds support for update() and delete() too,
along with tests to verify for all common collections.

Bug: 129014648
Test: atest android.appsecurity.cts.ExternalStorageHostTest
Change-Id: Ieca04aea4e3bf9a449277d7f09e88f640a8097a3
  • Loading branch information
jsharkey committed Apr 15, 2019
1 parent 4344c09 commit b6485ce
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 23 deletions.
23 changes: 21 additions & 2 deletions src/com/android/providers/media/MediaProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -3738,7 +3738,17 @@ public int delete(Uri uri, String userWhere, String[] userWhereArgs) {
}

{
SQLiteQueryBuilder qb = getQueryBuilder(TYPE_DELETE, uri, match, null);
final SQLiteQueryBuilder qb = getQueryBuilder(TYPE_DELETE, uri, match, null);

// Give callers interacting with a specific media item a chance to
// escalate access if they don't already have it
switch (match) {
case AUDIO_MEDIA_ID:
case VIDEO_MEDIA_ID:
case IMAGES_MEDIA_ID:
enforceCallingPermission(uri, true);
}

final String[] projection = new String[] {
FileColumns.MEDIA_TYPE,
FileColumns.DATA,
Expand Down Expand Up @@ -4285,7 +4295,16 @@ public int update(Uri uri, ContentValues initialValues, String userWhere,
return e.translateForUpdateDelete(targetSdkVersion);
}

SQLiteQueryBuilder qb = getQueryBuilder(TYPE_UPDATE, uri, match, null);
final SQLiteQueryBuilder qb = getQueryBuilder(TYPE_UPDATE, uri, match, null);

// Give callers interacting with a specific media item a chance to
// escalate access if they don't already have it
switch (match) {
case AUDIO_MEDIA_ID:
case VIDEO_MEDIA_ID:
case IMAGES_MEDIA_ID:
enforceCallingPermission(uri, true);
}

boolean triggerScan = false;
String genre = null;
Expand Down
58 changes: 37 additions & 21 deletions src/com/android/providers/media/PermissionActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@
import android.util.Log;
import android.util.Size;
import android.view.WindowManager;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;
import android.widget.TextView;

import com.android.internal.app.AlertActivity;

Expand All @@ -60,15 +62,14 @@ public void onCreate(Bundle savedInstanceState) {
}

final Resources res = getResources();
final ImageView thumbnailView = new ImageView(this);
thumbnailView.setScaleType(ScaleType.CENTER_INSIDE);
thumbnailView.setPadding(
0, res.getDimensionPixelSize(com.android.internal.R.dimen.default_gap), 0, 0);
new AsyncTask<Void, Void, Thumbnail>() {
final FrameLayout view = new FrameLayout(this);
final int padding = res.getDimensionPixelSize(com.android.internal.R.dimen.default_gap);
view.setPadding(padding, padding, padding, padding);
new AsyncTask<Void, Void, Description>() {
@Override
protected Thumbnail doInBackground(Void... params) {
protected Description doInBackground(Void... params) {
try {
return new Thumbnail(PermissionActivity.this, getIntent().getData());
return new Description(PermissionActivity.this, getIntent().getData());
} catch (Exception e) {
Log.w(TAG, e);
finish();
Expand All @@ -77,12 +78,25 @@ protected Thumbnail doInBackground(Void... params) {
}

@Override
protected void onPostExecute(Thumbnail result) {
protected void onPostExecute(Description result) {
if (result == null) return;
Log.d(TAG, "Found " + result.bitmap.getWidth() + "x" + result.bitmap.getHeight()
+ " with description " + result.contentDescription);
thumbnailView.setImageBitmap(result.bitmap);
thumbnailView.setContentDescription(result.contentDescription);

if (result.thumbnail != null) {
Log.d(TAG, "Found thumbnail " + result.thumbnail.getWidth() + "x"
+ result.thumbnail.getHeight());

final ImageView child = new ImageView(PermissionActivity.this);
child.setScaleType(ScaleType.CENTER_INSIDE);
child.setImageBitmap(result.thumbnail);
child.setContentDescription(result.contentDescription);
view.addView(child);
} else {
Log.d(TAG, "Found description " + result.contentDescription);

final TextView child = new TextView(PermissionActivity.this);
child.setText(result.contentDescription);
view.addView(child);
}
}
}.execute();

Expand All @@ -92,7 +106,7 @@ protected void onPostExecute(Thumbnail result) {
mAlertParams.mNegativeButtonText = getString(R.string.grant_dialog_button_deny);
mAlertParams.mNegativeButtonListener = this;
mAlertParams.mCancelable = false;
mAlertParams.mView = thumbnailView;
mAlertParams.mView = view;
setupAlert();

getWindow().setCloseOnTouchOutside(false);
Expand Down Expand Up @@ -147,29 +161,31 @@ private int getMessageId() throws NameNotFoundException {
throw new NameNotFoundException("Unknown media type " + uri);
}

private static class Thumbnail {
public final Bitmap bitmap;
public final CharSequence contentDescription;
private static class Description {
public Bitmap thumbnail;
public CharSequence contentDescription;

public Thumbnail(Context context, Uri uri) {
public Description(Context context, Uri uri) {
final Resources res = context.getResources();
final ContentResolver resolver = context.getContentResolver();

final Size size = new Size(res.getDisplayMetrics().widthPixels,
res.getDisplayMetrics().widthPixels);
try {
bitmap = resolver.loadThumbnail(uri, size, null);
thumbnail = resolver.loadThumbnail(uri, size, null);
} catch (IOException e) {
throw new IllegalStateException(e);
Log.w(TAG, e);
}
try (Cursor c = resolver.query(uri,
new String[] { MediaColumns.DISPLAY_NAME }, null, null)) {
if (c.moveToFirst()) {
contentDescription = c.getString(0);
} else {
throw new IllegalStateException();
}
}

if (TextUtils.isEmpty(contentDescription)) {
throw new IllegalStateException();
}
}
}
}

0 comments on commit b6485ce

Please sign in to comment.