summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJessica Wagantall <jwagantall@cyngn.com>2016-11-08 23:13:04 (GMT)
committerJessica Wagantall <jwagantall@cyngn.com>2016-11-09 19:59:20 (GMT)
commit2e7c3155e8a61c32f9424574076cbce6bbd3479b (patch)
tree2279c8326a5ac58606e989341b9b5dd544e04691
parentb25fddceb712fc26f7b2eb67ef34e73935cc1182 (diff)
parent1f66449c3bd4328116b2b2377f1a2d284e669578 (diff)
downloadandroid_packages_providers_DownloadProvider-2e7c3155e8a61c32f9424574076cbce6bbd3479b.zip
android_packages_providers_DownloadProvider-2e7c3155e8a61c32f9424574076cbce6bbd3479b.tar.gz
android_packages_providers_DownloadProvider-2e7c3155e8a61c32f9424574076cbce6bbd3479b.tar.bz2
Merge tag 'android-6.0.1_r74' into HEAD
CYNGNOS-3303 Android 6.0.1 release 74 Change-Id: Ie2ad785b1e3682814c8779cf52662bd8a4e03fcb
-rw-r--r--src/com/android/providers/downloads/DownloadProvider.java31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/com/android/providers/downloads/DownloadProvider.java b/src/com/android/providers/downloads/DownloadProvider.java
index 667a81d..13ab545 100644
--- a/src/com/android/providers/downloads/DownloadProvider.java
+++ b/src/com/android/providers/downloads/DownloadProvider.java
@@ -462,6 +462,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();
+ }
+
// start the DownloadService class. don't wait for the 1st download to be issued.
// saves us by getting some initialization code in DownloadService out of the way.
Context context = getContext();
@@ -687,6 +700,7 @@ public final class DownloadProvider extends ContentProvider {
}
insertRequestHeaders(db, rowID, values);
+ grantAllDownloadsPermission(rowID, Binder.getCallingUid());
notifyContentChanged(uri, match);
// Always start service to handle notifications and/or scanning
@@ -1193,6 +1207,7 @@ public final class DownloadProvider extends ContentProvider {
try {
while (cursor.moveToNext()) {
final long id = cursor.getLong(0);
+ revokeAllDownloadsPermission(id);
DownloadStorageProvider.onDownloadProviderDelete(getContext(), id);
final String path = cursor.getString(1);
@@ -1426,4 +1441,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);
+ }
}