summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeff Sharkey <jsharkey@android.com>2013-10-01 14:02:35 -0700
committerJeff Sharkey <jsharkey@android.com>2013-10-01 14:02:38 -0700
commit04c1c2afb7481e7fb9b66f96023c79d19cad8c90 (patch)
tree226c8284cc317df5ee05771349b6d24578035f96
parente4dc524e195b2dd8d86dd80504500f8f5bb11d92 (diff)
downloadandroid_packages_providers_DownloadProvider-04c1c2afb7481e7fb9b66f96023c79d19cad8c90.zip
android_packages_providers_DownloadProvider-04c1c2afb7481e7fb9b66f96023c79d19cad8c90.tar.gz
android_packages_providers_DownloadProvider-04c1c2afb7481e7fb9b66f96023c79d19cad8c90.tar.bz2
Allow all downloads to be writable.
Bug: 10943812 Change-Id: Ib0cb3e608c1f40a2e2fcd6e493c8f920d8b4221b
-rw-r--r--src/com/android/providers/downloads/DownloadProvider.java22
-rw-r--r--src/com/android/providers/downloads/DownloadStorageProvider.java11
-rw-r--r--src/com/android/providers/downloads/OpenHelper.java4
3 files changed, 9 insertions, 28 deletions
diff --git a/src/com/android/providers/downloads/DownloadProvider.java b/src/com/android/providers/downloads/DownloadProvider.java
index cb3dc18..750ee0f 100644
--- a/src/com/android/providers/downloads/DownloadProvider.java
+++ b/src/com/android/providers/downloads/DownloadProvider.java
@@ -1195,10 +1195,8 @@ public final class DownloadProvider extends ContentProvider {
logVerboseOpenFileInfo(uri, mode);
}
- final Cursor cursor = query(uri, new String[] {
- Downloads.Impl._DATA, Downloads.Impl.COLUMN_ALLOW_WRITE }, null, null, null);
+ final Cursor cursor = query(uri, new String[] { Downloads.Impl._DATA }, null, null, null);
String path;
- boolean allowWrite;
try {
int count = (cursor != null) ? cursor.getCount() : 0;
if (count != 1) {
@@ -1211,7 +1209,6 @@ public final class DownloadProvider extends ContentProvider {
cursor.moveToFirst();
path = cursor.getString(0);
- allowWrite = cursor.getInt(1) != 0;
} finally {
IoUtils.closeQuietly(cursor);
}
@@ -1222,19 +1219,14 @@ public final class DownloadProvider extends ContentProvider {
if (!Helpers.isFilenameValid(path, mDownloadsDataDir)) {
throw new FileNotFoundException("Invalid filename: " + path);
}
- if (!allowWrite && !"r".equals(mode)) {
- throw new FileNotFoundException("Bad mode for " + uri + ": " + mode);
- }
final File file = new File(path);
-
- ParcelFileDescriptor ret;
if ("r".equals(mode)) {
- ret = ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY);
+ return ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY);
} else {
try {
// When finished writing, update size and timestamp
- ret = ParcelFileDescriptor.open(file, ParcelFileDescriptor.parseMode(mode),
+ return ParcelFileDescriptor.open(file, ParcelFileDescriptor.parseMode(mode),
mHandler, new OnCloseListener() {
@Override
public void onClose(IOException e) {
@@ -1249,14 +1241,6 @@ public final class DownloadProvider extends ContentProvider {
throw new FileNotFoundException("Failed to open for writing: " + e);
}
}
-
- if (ret == null) {
- if (Constants.LOGV) {
- Log.v(Constants.TAG, "couldn't open file");
- }
- throw new FileNotFoundException("couldn't open file");
- }
- return ret;
}
@Override
diff --git a/src/com/android/providers/downloads/DownloadStorageProvider.java b/src/com/android/providers/downloads/DownloadStorageProvider.java
index 622633a..c32f745 100644
--- a/src/com/android/providers/downloads/DownloadStorageProvider.java
+++ b/src/com/android/providers/downloads/DownloadStorageProvider.java
@@ -292,7 +292,8 @@ public class DownloadStorageProvider extends DocumentsProvider {
String mimeType = cursor.getString(
cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_MEDIA_TYPE));
if (mimeType == null) {
- mimeType = "application/octet-stream";
+ // Provide fake MIME type so it's openable
+ mimeType = "vnd.android.document/file";
}
Long size = cursor.getLong(
cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_TOTAL_SIZE_BYTES));
@@ -327,17 +328,11 @@ public class DownloadStorageProvider extends DocumentsProvider {
break;
}
- int flags = Document.FLAG_SUPPORTS_DELETE;
+ int flags = Document.FLAG_SUPPORTS_DELETE | Document.FLAG_SUPPORTS_WRITE;
if (mimeType != null && mimeType.startsWith("image/")) {
flags |= Document.FLAG_SUPPORTS_THUMBNAIL;
}
- final int allowWrite = cursor.getInt(
- cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_ALLOW_WRITE));
- if (allowWrite != 0) {
- flags |= Document.FLAG_SUPPORTS_WRITE;
- }
-
final long lastModified = cursor.getLong(
cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_LAST_MODIFIED_TIMESTAMP));
diff --git a/src/com/android/providers/downloads/OpenHelper.java b/src/com/android/providers/downloads/OpenHelper.java
index af7a37f..4eb319c 100644
--- a/src/com/android/providers/downloads/OpenHelper.java
+++ b/src/com/android/providers/downloads/OpenHelper.java
@@ -78,7 +78,6 @@ public class OpenHelper {
mimeType = DownloadDrmHelper.getOriginalMimeType(context, file, mimeType);
final Intent intent = new Intent(Intent.ACTION_VIEW);
- intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
if ("application/vnd.android.package-archive".equals(mimeType)) {
// PackageInstaller doesn't like content URIs, so open file
@@ -90,9 +89,12 @@ public class OpenHelper {
intent.putExtra(Intent.EXTRA_REFERRER, getRefererUri(context, id));
intent.putExtra(Intent.EXTRA_ORIGINATING_UID, getOriginatingUid(context, id));
} else if ("file".equals(localUri.getScheme())) {
+ intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION
+ | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
intent.setDataAndType(
ContentUris.withAppendedId(ALL_DOWNLOADS_CONTENT_URI, id), mimeType);
} else {
+ intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.setDataAndType(localUri, mimeType);
}