From 2c02577af19bf11714220d14cfc96d2c017ac1ab Mon Sep 17 00:00:00 2001 From: Vasu Nori Date: Thu, 10 Feb 2011 15:01:29 -0800 Subject: bug:3425749 if adding completed download to db, send completion notif Change-Id: I9f9f6f2e0b2bd18f3767574fc51301b75bb1b76d --- .../providers/downloads/DownloadNotification.java | 78 +++++++++++----------- .../providers/downloads/DownloadProvider.java | 35 +++++++--- 2 files changed, 67 insertions(+), 46 deletions(-) (limited to 'src') diff --git a/src/com/android/providers/downloads/DownloadNotification.java b/src/com/android/providers/downloads/DownloadNotification.java index 51f0ba95..df14abb1 100644 --- a/src/com/android/providers/downloads/DownloadNotification.java +++ b/src/com/android/providers/downloads/DownloadNotification.java @@ -212,49 +212,51 @@ class DownloadNotification { if (!isCompleteAndVisible(download)) { continue; } - // Add the notifications - Notification n = new Notification(); - n.icon = android.R.drawable.stat_sys_download_done; - - long id = download.mId; - String title = download.mTitle; - if (title == null || title.length() == 0) { - title = mContext.getResources().getString( - R.string.download_unknown_title); - } - Uri contentUri = - ContentUris.withAppendedId(Downloads.Impl.ALL_DOWNLOADS_CONTENT_URI, id); - String caption; - Intent intent; - if (Downloads.Impl.isStatusError(download.mStatus)) { - caption = mContext.getResources() - .getString(R.string.notification_download_failed); - intent = new Intent(Constants.ACTION_LIST); + notificationForCompletedDownload(download.mId, download.mTitle, + download.mStatus, download.mDestination, download.mLastMod); + } + } + void notificationForCompletedDownload(long id, String title, int status, + int destination, long lastMod) { + // Add the notifications + Notification n = new Notification(); + n.icon = android.R.drawable.stat_sys_download_done; + if (title == null || title.length() == 0) { + title = mContext.getResources().getString( + R.string.download_unknown_title); + } + Uri contentUri = + ContentUris.withAppendedId(Downloads.Impl.ALL_DOWNLOADS_CONTENT_URI, id); + String caption; + Intent intent; + if (Downloads.Impl.isStatusError(status)) { + caption = mContext.getResources() + .getString(R.string.notification_download_failed); + intent = new Intent(Constants.ACTION_LIST); + } else { + caption = mContext.getResources() + .getString(R.string.notification_download_complete); + if (destination != Downloads.Impl.DESTINATION_SYSTEMCACHE_PARTITION) { + intent = new Intent(Constants.ACTION_OPEN); } else { - caption = mContext.getResources() - .getString(R.string.notification_download_complete); - if (download.mDestination != Downloads.Impl.DESTINATION_SYSTEMCACHE_PARTITION) { - intent = new Intent(Constants.ACTION_OPEN); - } else { - intent = new Intent(Constants.ACTION_LIST); - } + intent = new Intent(Constants.ACTION_LIST); } - intent.setClassName("com.android.providers.downloads", - DownloadReceiver.class.getName()); - intent.setData(contentUri); + } + intent.setClassName("com.android.providers.downloads", + DownloadReceiver.class.getName()); + intent.setData(contentUri); - n.when = download.mLastMod; - n.setLatestEventInfo(mContext, title, caption, - PendingIntent.getBroadcast(mContext, 0, intent, 0)); + n.when = lastMod; + n.setLatestEventInfo(mContext, title, caption, + PendingIntent.getBroadcast(mContext, 0, intent, 0)); - intent = new Intent(Constants.ACTION_HIDE); - intent.setClassName("com.android.providers.downloads", - DownloadReceiver.class.getName()); - intent.setData(contentUri); - n.deleteIntent = PendingIntent.getBroadcast(mContext, 0, intent, 0); + intent = new Intent(Constants.ACTION_HIDE); + intent.setClassName("com.android.providers.downloads", + DownloadReceiver.class.getName()); + intent.setData(contentUri); + n.deleteIntent = PendingIntent.getBroadcast(mContext, 0, intent, 0); - mSystemFacade.postNotification(download.mId, n); - } + mSystemFacade.postNotification(id, n); } private boolean isActiveAndVisible(DownloadInfo download) { diff --git a/src/com/android/providers/downloads/DownloadProvider.java b/src/com/android/providers/downloads/DownloadProvider.java index 113be5a5..fd57e900 100644 --- a/src/com/android/providers/downloads/DownloadProvider.java +++ b/src/com/android/providers/downloads/DownloadProvider.java @@ -562,8 +562,8 @@ public final class DownloadProvider extends ContentProvider { } // set lastupdate to current time - filteredValues.put(Downloads.Impl.COLUMN_LAST_MODIFICATION, - mSystemFacade.currentTimeMillis()); + long lastMod = mSystemFacade.currentTimeMillis(); + filteredValues.put(Downloads.Impl.COLUMN_LAST_MODIFICATION, lastMod); // use packagename of the caller to set the notification columns String pckg = values.getAsString(Downloads.Impl.COLUMN_NOTIFICATION_PACKAGE); @@ -626,9 +626,6 @@ public final class DownloadProvider extends ContentProvider { } } - Context context = getContext(); - context.startService(new Intent(context, DownloadService.class)); - long rowID = db.insert(DB_TABLE, null, filteredValues); if (rowID == -1) { Log.d(Constants.TAG, "couldn't insert into downloads database"); @@ -636,7 +633,27 @@ public final class DownloadProvider extends ContentProvider { } insertRequestHeaders(db, rowID, values); - context.startService(new Intent(context, DownloadService.class)); + /* + * requests coming from + * DownloadManager.completedDownload(String, String, String, boolean, String, + * String, long) need special treatment + */ + Context context = getContext(); + if (values.getAsInteger(Downloads.Impl.COLUMN_DESTINATION) == + Downloads.Impl.DESTINATION_NON_DOWNLOADMANAGER_DOWNLOAD) { + // don't start downloadservice because it has nothing to do in this case. + // but does a completion notification need to be sent? + if (Downloads.Impl.isNotificationToBeDisplayed(vis)) { + DownloadNotification notifier = new DownloadNotification(context, mSystemFacade); + notifier.notificationForCompletedDownload(rowID, + values.getAsString(Downloads.Impl.COLUMN_TITLE), + Downloads.Impl.STATUS_SUCCESS, + Downloads.Impl.DESTINATION_NON_DOWNLOADMANAGER_DOWNLOAD, + lastMod); + } + } else { + context.startService(new Intent(context, DownloadService.class)); + } notifyContentChanged(uri, match); return ContentUris.withAppendedId(Downloads.Impl.CONTENT_URI, rowID); } @@ -708,10 +725,12 @@ public final class DownloadProvider extends ContentProvider { if (getContext().checkCallingOrSelfPermission(Downloads.Impl.PERMISSION_NO_NOTIFICATION) == PackageManager.PERMISSION_GRANTED) { enforceAllowedValues(values, Downloads.Impl.COLUMN_VISIBILITY, - Downloads.Impl.VISIBILITY_HIDDEN, Downloads.Impl.VISIBILITY_VISIBLE); + Downloads.Impl.VISIBILITY_HIDDEN, Downloads.Impl.VISIBILITY_VISIBLE, + DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_ONLY_COMPLETION); } else { enforceAllowedValues(values, Downloads.Impl.COLUMN_VISIBILITY, - Downloads.Impl.VISIBILITY_VISIBLE); + Downloads.Impl.VISIBILITY_VISIBLE, + DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_ONLY_COMPLETION); } // remove the rest of the columns that are allowed (with any value) -- cgit v1.2.3