diff options
author | Jeff Sharkey <jsharkey@android.com> | 2016-09-17 01:20:45 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2016-09-17 01:20:45 +0000 |
commit | 145350ed9ddc3d7835c760a43b04c12325911209 (patch) | |
tree | f46dd69cdb8023ac11b4a02d6db720e76133ad81 /src | |
parent | d98d0384216d54474871ad4f90c7353ccb496fed (diff) | |
parent | e2c5d91b95a39a1e5028581bd72bd0e0ea907caf (diff) | |
download | android_packages_providers_DownloadProvider-145350ed9ddc3d7835c760a43b04c12325911209.tar.gz android_packages_providers_DownloadProvider-145350ed9ddc3d7835c760a43b04c12325911209.tar.bz2 android_packages_providers_DownloadProvider-145350ed9ddc3d7835c760a43b04c12325911209.zip |
Merge commit '010fc1856c23d5a15a6e42e334b0fdc7986f7f30' into manual_merge_010fc18
am: e2c5d91b95
Change-Id: I5d3b829662449cc6068501c0cdf0f6b7bc67a8e5
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/providers/downloads/DownloadProvider.java | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/com/android/providers/downloads/DownloadProvider.java b/src/com/android/providers/downloads/DownloadProvider.java index 64ce4844..387c200d 100644 --- a/src/com/android/providers/downloads/DownloadProvider.java +++ b/src/com/android/providers/downloads/DownloadProvider.java @@ -469,6 +469,19 @@ public final class DownloadProvider extends ContentProvider { if (appInfo != null) { mDefContainerUid = appInfo.uid; } + + // Grant access permissions for all known downloads to the owning apps + final SQLiteDatabase db = mOpenHelper.getReadableDatabase(); + final Cursor cursor = db.query(DB_TABLE, new String[] { + Downloads.Impl._ID, Constants.UID }, null, null, null, null, null); + try { + while (cursor.moveToNext()) { + grantAllDownloadsPermission(cursor.getLong(0), cursor.getInt(1)); + } + } finally { + cursor.close(); + } + return true; } @@ -691,6 +704,7 @@ public final class DownloadProvider extends ContentProvider { } insertRequestHeaders(db, rowID, values); + grantAllDownloadsPermission(rowID, Binder.getCallingUid()); notifyContentChanged(uri, match); final long token = Binder.clearCallingIdentity(); @@ -1218,6 +1232,7 @@ public final class DownloadProvider extends ContentProvider { reader.updateFromDatabase(info); scheduler.cancel((int) info.mId); + revokeAllDownloadsPermission(info.mId); DownloadStorageProvider.onDownloadProviderDelete(getContext(), info.mId); final String path = info.mFileName; @@ -1275,6 +1290,19 @@ public final class DownloadProvider extends ContentProvider { logVerboseOpenFileInfo(uri, mode); } + // Perform normal query to enforce caller identity access before + // clearing it to reach internal-only columns + final Cursor probeCursor = query(uri, new String[] { + Downloads.Impl._DATA }, null, null, null); + try { + if ((probeCursor == null) || (probeCursor.getCount() == 0)) { + throw new FileNotFoundException( + "No file found for " + uri + " as UID " + Binder.getCallingUid()); + } + } finally { + IoUtils.closeQuietly(probeCursor); + } + final Cursor cursor = queryCleared(uri, new String[] { Downloads.Impl._DATA, Downloads.Impl.COLUMN_STATUS, Downloads.Impl.COLUMN_DESTINATION, Downloads.Impl.COLUMN_MEDIA_SCANNED }, null, @@ -1457,4 +1485,20 @@ public final class DownloadProvider extends ContentProvider { to.put(key, defaultValue); } } + + private void grantAllDownloadsPermission(long id, int uid) { + final String[] packageNames = getContext().getPackageManager().getPackagesForUid(uid); + if (packageNames == null || packageNames.length == 0) return; + + // We only need to grant to the first package, since the + // platform internally tracks based on UIDs + final Uri uri = ContentUris.withAppendedId(Downloads.Impl.ALL_DOWNLOADS_CONTENT_URI, id); + getContext().grantUriPermission(packageNames[0], uri, + Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION); + } + + private void revokeAllDownloadsPermission(long id) { + final Uri uri = ContentUris.withAppendedId(Downloads.Impl.ALL_DOWNLOADS_CONTENT_URI, id); + getContext().revokeUriPermission(uri, ~0); + } } |