From 0f1aae327a9e4c68044d767e9bafbac747b6d985 Mon Sep 17 00:00:00 2001 From: Leon Scroggins Date: Thu, 21 Jan 2010 13:09:54 -0500 Subject: Download files even if there is no activity to launch them. Fixes http://b/issue?id=2367247 --- .../providers/downloads/DownloadNotification.java | 13 ++++++-- .../providers/downloads/DownloadService.java | 39 ---------------------- src/com/android/providers/downloads/Helpers.java | 27 --------------- 3 files changed, 11 insertions(+), 68 deletions(-) (limited to 'src/com/android') diff --git a/src/com/android/providers/downloads/DownloadNotification.java b/src/com/android/providers/downloads/DownloadNotification.java index a9362e8d..fd62e6f8 100644 --- a/src/com/android/providers/downloads/DownloadNotification.java +++ b/src/com/android/providers/downloads/DownloadNotification.java @@ -21,6 +21,7 @@ import android.app.NotificationManager; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; +import android.content.pm.PackageManager; import android.database.Cursor; import android.net.Uri; import android.provider.Downloads; @@ -227,7 +228,8 @@ class DownloadNotification { Downloads.Impl.COLUMN_STATUS, Downloads.Impl._DATA, Downloads.Impl.COLUMN_LAST_MODIFICATION, - Downloads.Impl.COLUMN_DESTINATION + Downloads.Impl.COLUMN_DESTINATION, + Downloads.Impl.COLUMN_MIME_TYPE }, WHERE_COMPLETED, null, Downloads.Impl._ID); @@ -247,6 +249,7 @@ class DownloadNotification { final int filenameColumnId = 8; final int lastModColumnId = 9; final int destinationColumnId = 10; + final int mimeTypeColumnId = 11; for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) { // Add the notifications @@ -268,7 +271,13 @@ class DownloadNotification { } else { caption = mContext.getResources() .getString(R.string.notification_download_complete); - if (c.getInt(destinationColumnId) == Downloads.Impl.DESTINATION_EXTERNAL) { + if (c.getInt(destinationColumnId) == Downloads.Impl.DESTINATION_EXTERNAL + // If there is no Activity to view the file, show the + // list + && null != mContext.getPackageManager().resolveActivity( + new Intent().setDataAndType(Uri.fromParts("file", "", + null), c.getString(mimeTypeColumnId)), + PackageManager.MATCH_DEFAULT_ONLY)) { intent = new Intent(Constants.ACTION_OPEN); } else { intent = new Intent(Constants.ACTION_LIST); diff --git a/src/com/android/providers/downloads/DownloadService.java b/src/com/android/providers/downloads/DownloadService.java index c451d3c6..5b56f686 100644 --- a/src/com/android/providers/downloads/DownloadService.java +++ b/src/com/android/providers/downloads/DownloadService.java @@ -27,8 +27,6 @@ import android.content.ContentValues; import android.content.Context; import android.content.Intent; import android.content.ServiceConnection; -import android.content.pm.PackageManager; -import android.content.pm.ResolveInfo; import android.database.CharArrayBuffer; import android.database.ContentObserver; import android.database.Cursor; @@ -612,43 +610,6 @@ public class DownloadService extends Service { mDownloads.add(arrayPos, info); - if (info.mStatus == 0 - && (info.mDestination == Downloads.Impl.DESTINATION_EXTERNAL - || info.mDestination == Downloads.Impl.DESTINATION_CACHE_PARTITION_PURGEABLE) - && info.mMimeType != null - && !DrmRawContent.DRM_MIMETYPE_MESSAGE_STRING.equalsIgnoreCase(info.mMimeType)) { - // Check to see if we are allowed to download this file. Only files - // that can be handled by the platform can be downloaded. - // special case DRM files, which we should always allow downloading. - Intent mimetypeIntent = new Intent(Intent.ACTION_VIEW); - - // We can provide data as either content: or file: URIs, - // so allow both. (I think it would be nice if we just did - // everything as content: URIs) - // Actually, right now the download manager's UId restrictions - // prevent use from using content: so it's got to be file: or - // nothing - - mimetypeIntent.setDataAndType(Uri.fromParts("file", "", null), info.mMimeType); - ResolveInfo ri = getPackageManager().resolveActivity(mimetypeIntent, - PackageManager.MATCH_DEFAULT_ONLY); - //Log.i(Constants.TAG, "*** QUERY " + mimetypeIntent + ": " + list); - - if (ri == null) { - if (Config.LOGD) { - Log.d(Constants.TAG, "no application to handle MIME type " + info.mMimeType); - } - info.mStatus = Downloads.Impl.STATUS_NOT_ACCEPTABLE; - - Uri uri = ContentUris.withAppendedId(Downloads.Impl.CONTENT_URI, info.mId); - ContentValues values = new ContentValues(); - values.put(Downloads.Impl.COLUMN_STATUS, Downloads.Impl.STATUS_NOT_ACCEPTABLE); - getContentResolver().update(uri, values, null, null); - info.sendIntentIfRequested(uri, this); - return; - } - } - if (info.canUseNetwork(networkAvailable, networkRoaming)) { if (info.isReadyToStart(now)) { if (Constants.LOGV) { diff --git a/src/com/android/providers/downloads/Helpers.java b/src/com/android/providers/downloads/Helpers.java index 774aba66..0847b78e 100644 --- a/src/com/android/providers/downloads/Helpers.java +++ b/src/com/android/providers/downloads/Helpers.java @@ -19,8 +19,6 @@ package com.android.providers.downloads; import android.content.ContentUris; import android.content.Context; import android.content.Intent; -import android.content.pm.PackageManager; -import android.content.pm.ResolveInfo; import android.database.Cursor; import android.drm.mobile1.DrmRawContent; import android.net.ConnectivityManager; @@ -99,31 +97,6 @@ public class Helpers { } return new DownloadFileInfo(null, null, Downloads.Impl.STATUS_NOT_ACCEPTABLE); } - if (!DrmRawContent.DRM_MIMETYPE_MESSAGE_STRING.equalsIgnoreCase(mimeType)) { - // Check to see if we are allowed to download this file. Only files - // that can be handled by the platform can be downloaded. - // special case DRM files, which we should always allow downloading. - Intent intent = new Intent(Intent.ACTION_VIEW); - - // We can provide data as either content: or file: URIs, - // so allow both. (I think it would be nice if we just did - // everything as content: URIs) - // Actually, right now the download manager's UId restrictions - // prevent use from using content: so it's got to be file: or - // nothing - - PackageManager pm = context.getPackageManager(); - intent.setDataAndType(Uri.fromParts("file", "", null), mimeType); - ResolveInfo ri = pm.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY); - //Log.i(Constants.TAG, "*** FILENAME QUERY " + intent + ": " + list); - - if (ri == null) { - if (Config.LOGD) { - Log.d(Constants.TAG, "no handler found for type " + mimeType); - } - return new DownloadFileInfo(null, null, Downloads.Impl.STATUS_NOT_ACCEPTABLE); - } - } } String filename = chooseFilename( url, hint, contentDisposition, contentLocation, destination); -- cgit v1.2.3