Send uid of the application that initiated the download
Ben Gruver [Thu, 27 Sep 2012 18:12:30 +0000 (11:12 -0700)]
Bug: 6923241
Change-Id: Idf4037b4e360cb6453b315d1cc95608762c9e0c8

src/com/android/providers/downloads/OpenHelper.java

index 0151c8d..c7d90ed 100644 (file)
@@ -59,6 +59,7 @@ public class OpenHelper {
                 final Uri remoteUri = getCursorUri(cursor, COLUMN_URI);
                 intent.putExtra(Intent.EXTRA_ORIGINATING_URI, remoteUri);
                 intent.putExtra(Intent.EXTRA_REFERRER, getRefererUri(context, id));
+                intent.putExtra(Intent.EXTRA_ORIGINATING_UID, getOriginatingUid(context, id));
             } else if ("file".equals(localUri.getScheme())) {
                 intent.setDataAndType(
                         ContentUris.withAppendedId(ALL_DOWNLOADS_CONTENT_URI, id), mimeType);
@@ -91,6 +92,22 @@ public class OpenHelper {
         return null;
     }
 
+    private static int getOriginatingUid(Context context, long id) {
+        final Uri uri = ContentUris.withAppendedId(ALL_DOWNLOADS_CONTENT_URI, id);
+        final Cursor cursor = context.getContentResolver().query(uri, new String[]{Constants.UID},
+                null, null, null);
+        if (cursor != null) {
+            try {
+                if (cursor.moveToFirst()) {
+                    return cursor.getInt(cursor.getColumnIndexOrThrow(Constants.UID));
+                }
+            } finally {
+                cursor.close();
+            }
+        }
+        return -1;
+    }
+
     private static String getCursorString(Cursor cursor, String column) {
         return cursor.getString(cursor.getColumnIndexOrThrow(column));
     }