diff options
author | Jeff Sharkey <jsharkey@android.com> | 2016-09-16 17:44:18 -0600 |
---|---|---|
committer | Jeff Sharkey <jsharkey@android.com> | 2016-09-16 17:44:18 -0600 |
commit | f367d6b2a0431db77c1f49f918c6f8df373e08dc (patch) | |
tree | 9059a7e76223e5b25d0068d07aa5fe6b1ed63331 | |
parent | 12d4497cc12cb9390f6efe953bd70bef1e6a41b3 (diff) | |
parent | c85df59e1cbc19afd486e2743fc59b3dc5ad8b35 (diff) | |
download | android_packages_providers_DownloadProvider-f367d6b2a0431db77c1f49f918c6f8df373e08dc.tar.gz android_packages_providers_DownloadProvider-f367d6b2a0431db77c1f49f918c6f8df373e08dc.tar.bz2 android_packages_providers_DownloadProvider-f367d6b2a0431db77c1f49f918c6f8df373e08dc.zip |
Merge commit 'c85df59e1cbc19afd486e2743fc59b3dc5ad8b35' into manual_merge_c85df59
Change-Id: Ie5f42d107b637c2231647ab97b0d124cba72bb8e
-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 8fd06d94..b2b2c08d 100644 --- a/src/com/android/providers/downloads/DownloadProvider.java +++ b/src/com/android/providers/downloads/DownloadProvider.java @@ -468,6 +468,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; } @@ -690,6 +703,7 @@ public final class DownloadProvider extends ContentProvider { } insertRequestHeaders(db, rowID, values); + grantAllDownloadsPermission(rowID, Binder.getCallingUid()); notifyContentChanged(uri, match); final long token = Binder.clearCallingIdentity(); @@ -1216,6 +1230,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; @@ -1273,6 +1288,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, @@ -1455,4 +1483,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); + } } |