Commit fe96fd4a authored by qinmin's avatar qinmin Committed by Commit bot

Adding a new extra field to intent for offline page downloads

getDownloadEntryFromIntent() always assume intent is for regular
download.
This causes chrome to use DownloadManagerService rather than
OfflinePageDownloadBridge when clicking on a notification.
This change fixes the issue by adding an extra field for offline page.

BUG=640467

Review-Url: https://codereview.chromium.org/2278663002
Cr-Commit-Position: refs/heads/master@{#414182}
parent 3e988531
...@@ -49,6 +49,7 @@ public class DownloadNotificationService extends Service { ...@@ -49,6 +49,7 @@ public class DownloadNotificationService extends Service {
static final String EXTRA_DOWNLOAD_FILE_NAME = "DownloadFileName"; static final String EXTRA_DOWNLOAD_FILE_NAME = "DownloadFileName";
static final String EXTRA_NOTIFICATION_DISMISSED = "NotificationDismissed"; static final String EXTRA_NOTIFICATION_DISMISSED = "NotificationDismissed";
static final String EXTRA_DOWNLOAD_IS_OFF_THE_RECORD = "DownloadIsOffTheRecord"; static final String EXTRA_DOWNLOAD_IS_OFF_THE_RECORD = "DownloadIsOffTheRecord";
static final String EXTRA_DOWNLOAD_IS_OFFLINE_PAGE = "DownloadIsOfflinePage";
static final String ACTION_DOWNLOAD_CANCEL = static final String ACTION_DOWNLOAD_CANCEL =
"org.chromium.chrome.browser.download.DOWNLOAD_CANCEL"; "org.chromium.chrome.browser.download.DOWNLOAD_CANCEL";
static final String ACTION_DOWNLOAD_PAUSE = static final String ACTION_DOWNLOAD_PAUSE =
...@@ -229,12 +230,12 @@ public class DownloadNotificationService extends Service { ...@@ -229,12 +230,12 @@ public class DownloadNotificationService extends Service {
isOffTheRecord, canDownloadWhileMetered, downloadGuid, fileName, itemType)); isOffTheRecord, canDownloadWhileMetered, downloadGuid, fileName, itemType));
if (startTime > 0) builder.setWhen(startTime); if (startTime > 0) builder.setWhen(startTime);
Intent cancelIntent = buildActionIntent( Intent cancelIntent = buildActionIntent(
ACTION_DOWNLOAD_CANCEL, notificationId, downloadGuid, fileName); ACTION_DOWNLOAD_CANCEL, notificationId, downloadGuid, fileName, isOfflinePage);
builder.addAction(R.drawable.btn_close_white, builder.addAction(R.drawable.btn_close_white,
mContext.getResources().getString(R.string.download_notification_cancel_button), mContext.getResources().getString(R.string.download_notification_cancel_button),
buildPendingIntent(cancelIntent, notificationId)); buildPendingIntent(cancelIntent, notificationId));
Intent pauseIntent = buildActionIntent( Intent pauseIntent = buildActionIntent(
ACTION_DOWNLOAD_PAUSE, notificationId, downloadGuid, fileName); ACTION_DOWNLOAD_PAUSE, notificationId, downloadGuid, fileName, isOfflinePage);
builder.addAction(R.drawable.ic_vidcontrol_pause, builder.addAction(R.drawable.ic_vidcontrol_pause,
mContext.getResources().getString(R.string.download_notification_pause_button), mContext.getResources().getString(R.string.download_notification_pause_button),
buildPendingIntent(pauseIntent, notificationId)); buildPendingIntent(pauseIntent, notificationId));
...@@ -284,7 +285,8 @@ public class DownloadNotificationService extends Service { ...@@ -284,7 +285,8 @@ public class DownloadNotificationService extends Service {
android.R.drawable.ic_media_pause, entry.fileName, android.R.drawable.ic_media_pause, entry.fileName,
mContext.getResources().getString(R.string.download_notification_paused)); mContext.getResources().getString(R.string.download_notification_paused));
Intent cancelIntent = buildActionIntent( Intent cancelIntent = buildActionIntent(
ACTION_DOWNLOAD_CANCEL, entry.notificationId, entry.downloadGuid, entry.fileName); ACTION_DOWNLOAD_CANCEL, entry.notificationId, entry.downloadGuid, entry.fileName,
entry.isOfflinePage());
Intent dismissIntent = new Intent(cancelIntent); Intent dismissIntent = new Intent(cancelIntent);
dismissIntent.putExtra(EXTRA_NOTIFICATION_DISMISSED, true); dismissIntent.putExtra(EXTRA_NOTIFICATION_DISMISSED, true);
builder.setDeleteIntent(buildPendingIntent(dismissIntent, entry.notificationId)); builder.setDeleteIntent(buildPendingIntent(dismissIntent, entry.notificationId));
...@@ -292,7 +294,8 @@ public class DownloadNotificationService extends Service { ...@@ -292,7 +294,8 @@ public class DownloadNotificationService extends Service {
mContext.getResources().getString(R.string.download_notification_cancel_button), mContext.getResources().getString(R.string.download_notification_cancel_button),
buildPendingIntent(cancelIntent, entry.notificationId)); buildPendingIntent(cancelIntent, entry.notificationId));
Intent resumeIntent = buildActionIntent( Intent resumeIntent = buildActionIntent(
ACTION_DOWNLOAD_RESUME, entry.notificationId, entry.downloadGuid, entry.fileName); ACTION_DOWNLOAD_RESUME, entry.notificationId, entry.downloadGuid, entry.fileName,
entry.isOfflinePage());
resumeIntent.putExtra(EXTRA_DOWNLOAD_IS_OFF_THE_RECORD, entry.isOffTheRecord); resumeIntent.putExtra(EXTRA_DOWNLOAD_IS_OFF_THE_RECORD, entry.isOffTheRecord);
builder.addAction(R.drawable.ic_get_app_white_24dp, builder.addAction(R.drawable.ic_get_app_white_24dp,
mContext.getResources().getString(R.string.download_notification_resume_button), mContext.getResources().getString(R.string.download_notification_resume_button),
...@@ -325,8 +328,8 @@ public class DownloadNotificationService extends Service { ...@@ -325,8 +328,8 @@ public class DownloadNotificationService extends Service {
mContext.getPackageName(), DownloadBroadcastReceiver.class.getName()); mContext.getPackageName(), DownloadBroadcastReceiver.class.getName());
Intent intent; Intent intent;
if (isOfflinePage) { if (isOfflinePage) {
intent = intent = buildActionIntent(ACTION_DOWNLOAD_OPEN, notificationId, downloadGuid, fileName,
buildActionIntent(ACTION_DOWNLOAD_OPEN, notificationId, downloadGuid, fileName); isOfflinePage);
} else { } else {
intent = new Intent(DownloadManager.ACTION_NOTIFICATION_CLICKED); intent = new Intent(DownloadManager.ACTION_NOTIFICATION_CLICKED);
long[] idArray = {systemDownloadId}; long[] idArray = {systemDownloadId};
...@@ -403,9 +406,11 @@ public class DownloadNotificationService extends Service { ...@@ -403,9 +406,11 @@ public class DownloadNotificationService extends Service {
* @param notificationId ID of the notification. * @param notificationId ID of the notification.
* @param downloadGuid GUID of the download. * @param downloadGuid GUID of the download.
* @param fileName Name of the download file. * @param fileName Name of the download file.
* @param isOfflinePage Whether the intent is for offline page download.
*/ */
private Intent buildActionIntent( private Intent buildActionIntent(
String action, int notificationId, String downloadGuid, String fileName) { String action, int notificationId, String downloadGuid, String fileName,
boolean isOfflinePage) {
ComponentName component = new ComponentName( ComponentName component = new ComponentName(
mContext.getPackageName(), DownloadBroadcastReceiver.class.getName()); mContext.getPackageName(), DownloadBroadcastReceiver.class.getName());
Intent intent = new Intent(action); Intent intent = new Intent(action);
...@@ -413,6 +418,7 @@ public class DownloadNotificationService extends Service { ...@@ -413,6 +418,7 @@ public class DownloadNotificationService extends Service {
intent.putExtra(EXTRA_DOWNLOAD_NOTIFICATION_ID, notificationId); intent.putExtra(EXTRA_DOWNLOAD_NOTIFICATION_ID, notificationId);
intent.putExtra(EXTRA_DOWNLOAD_GUID, downloadGuid); intent.putExtra(EXTRA_DOWNLOAD_GUID, downloadGuid);
intent.putExtra(EXTRA_DOWNLOAD_FILE_NAME, fileName); intent.putExtra(EXTRA_DOWNLOAD_FILE_NAME, fileName);
intent.putExtra(EXTRA_DOWNLOAD_IS_OFFLINE_PAGE, isOfflinePage);
return intent; return intent;
} }
...@@ -449,8 +455,11 @@ public class DownloadNotificationService extends Service { ...@@ -449,8 +455,11 @@ public class DownloadNotificationService extends Service {
boolean metered = DownloadManagerService.isActiveNetworkMetered(mContext); boolean metered = DownloadManagerService.isActiveNetworkMetered(mContext);
boolean isOffTheRecord = IntentUtils.safeGetBooleanExtra( boolean isOffTheRecord = IntentUtils.safeGetBooleanExtra(
intent, EXTRA_DOWNLOAD_IS_OFF_THE_RECORD, false); intent, EXTRA_DOWNLOAD_IS_OFF_THE_RECORD, false);
boolean isOfflinePage = IntentUtils.safeGetBooleanExtra(
intent, EXTRA_DOWNLOAD_IS_OFFLINE_PAGE, false);
return new DownloadSharedPreferenceEntry(notificationId, isOffTheRecord, metered, guid, return new DownloadSharedPreferenceEntry(notificationId, isOffTheRecord, metered, guid,
fileName, DownloadSharedPreferenceEntry.ITEM_TYPE_DOWNLOAD); fileName, isOfflinePage ? DownloadSharedPreferenceEntry.ITEM_TYPE_OFFLINE_PAGE
: DownloadSharedPreferenceEntry.ITEM_TYPE_DOWNLOAD);
} }
/** /**
...@@ -514,7 +523,7 @@ public class DownloadNotificationService extends Service { ...@@ -514,7 +523,7 @@ public class DownloadNotificationService extends Service {
case ACTION_DOWNLOAD_RESUME: case ACTION_DOWNLOAD_RESUME:
notifyDownloadProgress(entry.downloadGuid, entry.fileName, notifyDownloadProgress(entry.downloadGuid, entry.fileName,
INVALID_DOWNLOAD_PERCENTAGE, 0, 0, entry.isOffTheRecord, INVALID_DOWNLOAD_PERCENTAGE, 0, 0, entry.isOffTheRecord,
entry.canDownloadWhileMetered, isOfflinePage(entry)); entry.canDownloadWhileMetered, entry.isOfflinePage());
downloadServiceDelegate.resumeDownload(entry.buildDownloadItem(), true); downloadServiceDelegate.resumeDownload(entry.buildDownloadItem(), true);
break; break;
case ACTION_DOWNLOAD_RESUME_ALL: case ACTION_DOWNLOAD_RESUME_ALL:
...@@ -650,7 +659,7 @@ public class DownloadNotificationService extends Service { ...@@ -650,7 +659,7 @@ public class DownloadNotificationService extends Service {
if (mDownloadsInProgress.contains(entry.downloadGuid)) continue; if (mDownloadsInProgress.contains(entry.downloadGuid)) continue;
if (!entry.canDownloadWhileMetered && isNetworkMetered) continue; if (!entry.canDownloadWhileMetered && isNetworkMetered) continue;
notifyDownloadProgress(entry.downloadGuid, entry.fileName, INVALID_DOWNLOAD_PERCENTAGE, notifyDownloadProgress(entry.downloadGuid, entry.fileName, INVALID_DOWNLOAD_PERCENTAGE,
0, 0, false, entry.canDownloadWhileMetered, isOfflinePage(entry)); 0, 0, false, entry.canDownloadWhileMetered, entry.isOfflinePage());
DownloadServiceDelegate downloadServiceDelegate = getServiceDelegate(entry.itemType); DownloadServiceDelegate downloadServiceDelegate = getServiceDelegate(entry.itemType);
downloadServiceDelegate.resumeDownload(entry.buildDownloadItem(), false); downloadServiceDelegate.resumeDownload(entry.buildDownloadItem(), false);
downloadServiceDelegate.destroyServiceDelegate(); downloadServiceDelegate.destroyServiceDelegate();
...@@ -719,10 +728,6 @@ public class DownloadNotificationService extends Service { ...@@ -719,10 +728,6 @@ public class DownloadNotificationService extends Service {
return notificationId; return notificationId;
} }
private boolean isOfflinePage(DownloadSharedPreferenceEntry entry) {
return entry.itemType == DownloadSharedPreferenceEntry.ITEM_TYPE_OFFLINE_PAGE;
}
/** /**
* Format remaining time for the given millis, in the following format: * Format remaining time for the given millis, in the following format:
* 5 hours; will include 1 unit, can go down to seconds precision. * 5 hours; will include 1 unit, can go down to seconds precision.
......
...@@ -128,6 +128,10 @@ public class DownloadSharedPreferenceEntry { ...@@ -128,6 +128,10 @@ public class DownloadSharedPreferenceEntry {
} }
} }
public boolean isOfflinePage() {
return itemType == ITEM_TYPE_OFFLINE_PAGE;
}
/** /**
* Build a download item from this object. * Build a download item from this object.
*/ */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment