OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.chrome.browser.download; | 5 package org.chromium.chrome.browser.download; |
6 | 6 |
7 import android.annotation.TargetApi; | 7 import android.annotation.TargetApi; |
8 import android.app.DownloadManager; | 8 import android.app.DownloadManager; |
9 import android.app.Notification; | 9 import android.app.Notification; |
10 import android.app.NotificationManager; | 10 import android.app.NotificationManager; |
(...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
568 | 568 |
569 @VisibleForTesting | 569 @VisibleForTesting |
570 void updateNotificationsForShutdown() { | 570 void updateNotificationsForShutdown() { |
571 cancelOffTheRecordDownloads(); | 571 cancelOffTheRecordDownloads(); |
572 List<DownloadSharedPreferenceEntry> entries = mDownloadSharedPreferenceH
elper.getEntries(); | 572 List<DownloadSharedPreferenceEntry> entries = mDownloadSharedPreferenceH
elper.getEntries(); |
573 for (DownloadSharedPreferenceEntry entry : entries) { | 573 for (DownloadSharedPreferenceEntry entry : entries) { |
574 if (entry.isOffTheRecord) continue; | 574 if (entry.isOffTheRecord) continue; |
575 // Move all regular downloads to pending. Don't propagate the pause
because | 575 // Move all regular downloads to pending. Don't propagate the pause
because |
576 // if native is still working and it triggers an update, then the se
rvice will be | 576 // if native is still working and it triggers an update, then the se
rvice will be |
577 // restarted. | 577 // restarted. |
578 notifyDownloadPaused(entry.id, !entry.isOffTheRecord, true, entry.is
Transient); | 578 notifyDownloadPaused(entry.id, !entry.isOffTheRecord, true, entry.is
Transient, null); |
579 } | 579 } |
580 } | 580 } |
581 | 581 |
582 @VisibleForTesting | 582 @VisibleForTesting |
583 void cancelOffTheRecordDownloads() { | 583 void cancelOffTheRecordDownloads() { |
584 boolean cancelActualDownload = | 584 boolean cancelActualDownload = |
585 BrowserStartupController.get(LibraryProcessType.PROCESS_BROWSER) | 585 BrowserStartupController.get(LibraryProcessType.PROCESS_BROWSER) |
586 .isStartupSuccessfullyCompleted() | 586 .isStartupSuccessfullyCompleted() |
587 && Profile.getLastUsedProfile().hasOffTheRecordProfile(); | 587 && Profile.getLastUsedProfile().hasOffTheRecordProfile(); |
588 | 588 |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
727 */ | 727 */ |
728 static void clearResumptionAttemptLeft() { | 728 static void clearResumptionAttemptLeft() { |
729 SharedPreferences SharedPrefs = ContextUtils.getAppSharedPreferences(); | 729 SharedPreferences SharedPrefs = ContextUtils.getAppSharedPreferences(); |
730 SharedPreferences.Editor editor = SharedPrefs.edit(); | 730 SharedPreferences.Editor editor = SharedPrefs.edit(); |
731 editor.remove(KEY_AUTO_RESUMPTION_ATTEMPT_LEFT); | 731 editor.remove(KEY_AUTO_RESUMPTION_ATTEMPT_LEFT); |
732 editor.apply(); | 732 editor.apply(); |
733 } | 733 } |
734 | 734 |
735 /** | 735 /** |
736 * Adds or updates an in-progress download notification. | 736 * Adds or updates an in-progress download notification. |
737 * @param id The {@link ContentId} of the download. | 737 * @param id The {@link ContentId} of the download. |
738 * @param fileName File name of the download. | 738 * @param fileName File name of the download. |
739 * @param percentage Percentage completed. Value should be between 0 to 100
if | 739 * @param percentage Percentage completed. Value should be betw
een 0 to 100 if the |
740 * the percentage can be determined, or -1 if it is unknown. | 740 * percentage can be determined, or -1 if it
is unknown. |
741 * @param bytesReceived Total number of bytes received. | 741 * @param bytesReceived Total number of bytes received. |
742 * @param timeRemainingInMillis Remaining download time in milliseconds. | 742 * @param timeRemainingInMillis Remaining download time in milliseconds. |
743 * @param startTime Time when download started. | 743 * @param startTime Time when download started. |
744 * @param isOffTheRecord Whether the download is off the record. | 744 * @param isOffTheRecord Whether the download is off the record. |
745 * @param canDownloadWhileMetered Whether the download can happen in metered
network. | 745 * @param canDownloadWhileMetered Whether the download can happen in metered
network. |
746 * @param isTransient Whether or not clicking on the download should launch
downloads home. | 746 * @param isTransient Whether or not clicking on the download sh
ould launch |
| 747 * downloads home. |
| 748 * @param icon A {@link Bitmap} to be used as the large i
con for display. |
747 */ | 749 */ |
748 @VisibleForTesting | 750 @VisibleForTesting |
749 public void notifyDownloadProgress(ContentId id, String fileName, int percen
tage, | 751 public void notifyDownloadProgress(ContentId id, String fileName, int percen
tage, |
750 long bytesReceived, long timeRemainingInMillis, long startTime, bool
ean isOffTheRecord, | 752 long bytesReceived, long timeRemainingInMillis, long startTime, bool
ean isOffTheRecord, |
751 boolean canDownloadWhileMetered, boolean isTransient) { | 753 boolean canDownloadWhileMetered, boolean isTransient, Bitmap icon) { |
752 updateActiveDownloadNotification(id, fileName, percentage, bytesReceived
, | 754 updateActiveDownloadNotification(id, fileName, percentage, bytesReceived
, |
753 timeRemainingInMillis, startTime, isOffTheRecord, canDownloadWhi
leMetered, false, | 755 timeRemainingInMillis, startTime, isOffTheRecord, canDownloadWhi
leMetered, false, |
754 isTransient); | 756 isTransient, icon); |
755 } | 757 } |
756 | 758 |
757 /** | 759 /** |
758 * Adds or updates a pending download notification. | 760 * Adds or updates a pending download notification. |
759 * @param id The {@link ContentId} of the download. | 761 * @param id The {@link ContentId} of the download. |
760 * @param fileName File name of the download. | 762 * @param fileName File name of the download. |
761 * @param isOffTheRecord Whether the download is off the record. | 763 * @param isOffTheRecord Whether the download is off the record. |
762 * @param canDownloadWhileMetered Whether the download can happen in metered
network. | 764 * @param canDownloadWhileMetered Whether the download can happen in metered
network. |
763 * @param isTransient Whether or not clicking on the download should launch
downloads home. | 765 * @param isTransient Whether or not clicking on the download sh
ould launch |
| 766 * downloads home. |
| 767 * @param icon A {@link Bitmap} to be used as the large i
con for display. |
764 */ | 768 */ |
765 private void notifyDownloadPending(ContentId id, String fileName, boolean is
OffTheRecord, | 769 private void notifyDownloadPending(ContentId id, String fileName, boolean is
OffTheRecord, |
766 boolean canDownloadWhileMetered, boolean isTransient) { | 770 boolean canDownloadWhileMetered, boolean isTransient, Bitmap icon) { |
767 updateActiveDownloadNotification(id, fileName, | 771 updateActiveDownloadNotification(id, fileName, |
768 DownloadItem.INDETERMINATE_DOWNLOAD_PERCENTAGE, 0, 0, 0, isOffTh
eRecord, | 772 DownloadItem.INDETERMINATE_DOWNLOAD_PERCENTAGE, 0, 0, 0, isOffTh
eRecord, |
769 canDownloadWhileMetered, true, isTransient); | 773 canDownloadWhileMetered, true, isTransient, icon); |
770 } | 774 } |
771 | 775 |
772 /** | 776 /** |
773 * Helper method to update the notification for an active download, the down
load is either in | 777 * Helper method to update the notification for an active download, the down
load is either in |
774 * progress or pending. | 778 * progress or pending. |
775 * @param id The {@link ContentId} of the download. | 779 * @param id The {@link ContentId} of the download. |
776 * @param fileName File name of the download. | 780 * @param fileName File name of the download. |
777 * @param percentage Percentage completed. Value should be between 0 to 100
if | 781 * @param percentage Percentage completed. Value should be betw
een 0 to 100 if the |
778 * the percentage can be determined, or -1 if it is unknown. | 782 * percentage can be determined, or -1 if it
is unknown. |
779 * @param bytesReceived Total number of bytes received. | 783 * @param bytesReceived Total number of bytes received. |
780 * @param timeRemainingInMillis Remaining download time in milliseconds or -
1 if it is unknown. | 784 * @param timeRemainingInMillis Remaining download time in milliseconds or
-1 if it is |
781 * @param startTime Time when download started. | 785 * unknown. |
782 * @param isOffTheRecord Whether the download is off the record. | 786 * @param startTime Time when download started. |
| 787 * @param isOffTheRecord Whether the download is off the record. |
783 * @param canDownloadWhileMetered Whether the download can happen in metered
network. | 788 * @param canDownloadWhileMetered Whether the download can happen in metered
network. |
784 * @param isDownloadPending Whether the download is pending. | 789 * @param isDownloadPending Whether the download is pending. |
785 * @param isTransient Whether or not clicking on the download should launch
downloads home. | 790 * @param isTransient Whether or not clicking on the download sh
ould launch |
| 791 * downloads home. |
| 792 * @param icon A {@link Bitmap} to be used as the large i
con for display. |
786 */ | 793 */ |
787 private void updateActiveDownloadNotification(ContentId id, String fileName,
int percentage, | 794 private void updateActiveDownloadNotification(ContentId id, String fileName,
int percentage, |
788 long bytesReceived, long timeRemainingInMillis, long startTime, bool
ean isOffTheRecord, | 795 long bytesReceived, long timeRemainingInMillis, long startTime, bool
ean isOffTheRecord, |
789 boolean canDownloadWhileMetered, boolean isDownloadPending, boolean
isTransient) { | 796 boolean canDownloadWhileMetered, boolean isDownloadPending, boolean
isTransient, |
| 797 Bitmap icon) { |
790 boolean indeterminate = | 798 boolean indeterminate = |
791 (percentage == DownloadItem.INDETERMINATE_DOWNLOAD_PERCENTAGE) |
| isDownloadPending; | 799 (percentage == DownloadItem.INDETERMINATE_DOWNLOAD_PERCENTAGE) |
| isDownloadPending; |
792 String contentText = null; | 800 String contentText = null; |
793 if (isDownloadPending) { | 801 if (isDownloadPending) { |
794 contentText = mContext.getResources().getString(R.string.download_no
tification_pending); | 802 contentText = mContext.getResources().getString(R.string.download_no
tification_pending); |
795 } else if (indeterminate) { | 803 } else if (indeterminate) { |
796 // TODO(dimich): Enable the byte count back in M59. See bug 704049 f
or more info and | 804 // TODO(dimich): Enable the byte count back in M59. See bug 704049 f
or more info and |
797 // details of what was temporarily reverted (for M58). | 805 // details of what was temporarily reverted (for M58). |
798 contentText = mContext.getResources().getString(R.string.download_st
arted); | 806 contentText = mContext.getResources().getString(R.string.download_st
arted); |
799 } else { | 807 } else { |
(...skipping 25 matching lines...) Expand all Loading... |
825 if (startTime > 0) builder.setWhen(startTime); | 833 if (startTime > 0) builder.setWhen(startTime); |
826 | 834 |
827 if (!isTransient) { | 835 if (!isTransient) { |
828 // Clicking on an in-progress download sends the user to see all the
ir downloads. | 836 // Clicking on an in-progress download sends the user to see all the
ir downloads. |
829 Intent downloadHomeIntent = buildActionIntent( | 837 Intent downloadHomeIntent = buildActionIntent( |
830 mContext, DownloadManager.ACTION_NOTIFICATION_CLICKED, null,
isOffTheRecord); | 838 mContext, DownloadManager.ACTION_NOTIFICATION_CLICKED, null,
isOffTheRecord); |
831 builder.setContentIntent(PendingIntent.getBroadcast(mContext, notifi
cationId, | 839 builder.setContentIntent(PendingIntent.getBroadcast(mContext, notifi
cationId, |
832 downloadHomeIntent, PendingIntent.FLAG_UPDATE_CURRENT)); | 840 downloadHomeIntent, PendingIntent.FLAG_UPDATE_CURRENT)); |
833 } | 841 } |
834 builder.setAutoCancel(false); | 842 builder.setAutoCancel(false); |
| 843 if (icon != null) builder.setLargeIcon(icon); |
835 | 844 |
836 Intent pauseIntent = buildActionIntent(mContext, ACTION_DOWNLOAD_PAUSE,
id, isOffTheRecord); | 845 Intent pauseIntent = buildActionIntent(mContext, ACTION_DOWNLOAD_PAUSE,
id, isOffTheRecord); |
837 builder.addAction(R.drawable.ic_pause_white_24dp, | 846 builder.addAction(R.drawable.ic_pause_white_24dp, |
838 mContext.getResources().getString(R.string.download_notification
_pause_button), | 847 mContext.getResources().getString(R.string.download_notification
_pause_button), |
839 buildPendingIntent(pauseIntent, notificationId)); | 848 buildPendingIntent(pauseIntent, notificationId)); |
840 | 849 |
841 Intent cancelIntent = | 850 Intent cancelIntent = |
842 buildActionIntent(mContext, ACTION_DOWNLOAD_CANCEL, id, isOffThe
Record); | 851 buildActionIntent(mContext, ACTION_DOWNLOAD_CANCEL, id, isOffThe
Record); |
843 builder.addAction(R.drawable.btn_close_white, | 852 builder.addAction(R.drawable.btn_close_white, |
844 mContext.getResources().getString(R.string.download_notification
_cancel_button), | 853 mContext.getResources().getString(R.string.download_notification
_cancel_button), |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
879 @VisibleForTesting | 888 @VisibleForTesting |
880 public void notifyDownloadCanceled(ContentId id) { | 889 public void notifyDownloadCanceled(ContentId id) { |
881 DownloadSharedPreferenceEntry entry = | 890 DownloadSharedPreferenceEntry entry = |
882 mDownloadSharedPreferenceHelper.getDownloadSharedPreferenceEntry
(id); | 891 mDownloadSharedPreferenceHelper.getDownloadSharedPreferenceEntry
(id); |
883 if (entry == null) return; | 892 if (entry == null) return; |
884 cancelNotification(entry.notificationId, id); | 893 cancelNotification(entry.notificationId, id); |
885 } | 894 } |
886 | 895 |
887 /** | 896 /** |
888 * Change a download notification to paused state. | 897 * Change a download notification to paused state. |
889 * @param id The {@link ContentId} of the download. | 898 * @param id The {@link ContentId} of the download. |
890 * @param isResumable Whether download can be resumed. | 899 * @param isResumable Whether download can be resumed. |
891 * @param isAutoResumable whether download is can be resumed automatically. | 900 * @param isAutoResumable whether download is can be resumed automatically. |
892 * @param isTransient Whether or not clicking on the download should launch
downloads home. | 901 * @param isTransient Whether or not clicking on the download should lau
nch downloads home. |
| 902 * @param icon A {@link Bitmap} to be used as the large icon for
display. |
893 */ | 903 */ |
894 public void notifyDownloadPaused( | 904 public void notifyDownloadPaused(ContentId id, boolean isResumable, boolean
isAutoResumable, |
895 ContentId id, boolean isResumable, boolean isAutoResumable, boolean
isTransient) { | 905 boolean isTransient, Bitmap icon) { |
896 DownloadSharedPreferenceEntry entry = | 906 DownloadSharedPreferenceEntry entry = |
897 mDownloadSharedPreferenceHelper.getDownloadSharedPreferenceEntry
(id); | 907 mDownloadSharedPreferenceHelper.getDownloadSharedPreferenceEntry
(id); |
898 if (entry == null) return; | 908 if (entry == null) return; |
899 if (!isResumable) { | 909 if (!isResumable) { |
900 notifyDownloadFailed(id, entry.fileName); | 910 notifyDownloadFailed(id, entry.fileName, icon); |
901 return; | 911 return; |
902 } | 912 } |
903 // If download is already paused, do nothing. | 913 // If download is already paused, do nothing. |
904 if (!entry.isAutoResumable) return; | 914 if (!entry.isAutoResumable) return; |
905 // If download is interrupted due to network disconnection, show downloa
d pending state. | 915 // If download is interrupted due to network disconnection, show downloa
d pending state. |
906 if (isAutoResumable) { | 916 if (isAutoResumable) { |
907 notifyDownloadPending(id, entry.fileName, entry.isOffTheRecord, | 917 notifyDownloadPending(id, entry.fileName, entry.isOffTheRecord, |
908 entry.canDownloadWhileMetered, isTransient); | 918 entry.canDownloadWhileMetered, isTransient, icon); |
909 stopTrackingInProgressDownload(id, true); | 919 stopTrackingInProgressDownload(id, true); |
910 return; | 920 return; |
911 } | 921 } |
912 | 922 |
913 String contentText = mContext.getResources().getString( | 923 String contentText = mContext.getResources().getString( |
914 R.string.download_notification_paused); | 924 R.string.download_notification_paused); |
915 ChromeNotificationBuilder builder = | 925 ChromeNotificationBuilder builder = |
916 buildNotification(R.drawable.ic_download_pause, entry.fileName,
contentText); | 926 buildNotification(R.drawable.ic_download_pause, entry.fileName,
contentText); |
917 | 927 |
918 if (!isTransient) { | 928 if (!isTransient) { |
919 // Clicking on an in-progress download sends the user to see all the
ir downloads. | 929 // Clicking on an in-progress download sends the user to see all the
ir downloads. |
920 Intent downloadHomeIntent = buildActionIntent( | 930 Intent downloadHomeIntent = buildActionIntent( |
921 mContext, DownloadManager.ACTION_NOTIFICATION_CLICKED, null,
false); | 931 mContext, DownloadManager.ACTION_NOTIFICATION_CLICKED, null,
false); |
922 builder.setContentIntent(PendingIntent.getBroadcast(mContext, entry.
notificationId, | 932 builder.setContentIntent(PendingIntent.getBroadcast(mContext, entry.
notificationId, |
923 downloadHomeIntent, PendingIntent.FLAG_UPDATE_CURRENT)); | 933 downloadHomeIntent, PendingIntent.FLAG_UPDATE_CURRENT)); |
924 } | 934 } |
925 builder.setAutoCancel(false); | 935 builder.setAutoCancel(false); |
| 936 if (icon != null) builder.setLargeIcon(icon); |
926 | 937 |
927 Intent resumeIntent = | 938 Intent resumeIntent = |
928 buildActionIntent(mContext, ACTION_DOWNLOAD_RESUME, id, entry.is
OffTheRecord); | 939 buildActionIntent(mContext, ACTION_DOWNLOAD_RESUME, id, entry.is
OffTheRecord); |
929 builder.addAction(R.drawable.ic_file_download_white_24dp, | 940 builder.addAction(R.drawable.ic_file_download_white_24dp, |
930 mContext.getResources().getString(R.string.download_notification
_resume_button), | 941 mContext.getResources().getString(R.string.download_notification
_resume_button), |
931 buildPendingIntent(resumeIntent, entry.notificationId)); | 942 buildPendingIntent(resumeIntent, entry.notificationId)); |
932 | 943 |
933 Intent cancelIntent = | 944 Intent cancelIntent = |
934 buildActionIntent(mContext, ACTION_DOWNLOAD_CANCEL, id, entry.is
OffTheRecord); | 945 buildActionIntent(mContext, ACTION_DOWNLOAD_CANCEL, id, entry.is
OffTheRecord); |
935 builder.addAction(R.drawable.btn_close_white, | 946 builder.addAction(R.drawable.btn_close_white, |
936 mContext.getResources().getString(R.string.download_notification
_cancel_button), | 947 mContext.getResources().getString(R.string.download_notification
_cancel_button), |
937 buildPendingIntent(cancelIntent, entry.notificationId)); | 948 buildPendingIntent(cancelIntent, entry.notificationId)); |
938 PendingIntent deleteIntent = isTransient | 949 PendingIntent deleteIntent = isTransient |
939 ? buildPendingIntent(cancelIntent, entry.notificationId) | 950 ? buildPendingIntent(cancelIntent, entry.notificationId) |
940 : buildSummaryIconIntent(entry.notificationId); | 951 : buildSummaryIconIntent(entry.notificationId); |
941 builder.setDeleteIntent(deleteIntent); | 952 builder.setDeleteIntent(deleteIntent); |
942 | 953 |
943 updateNotification(entry.notificationId, builder.build(), id, | 954 updateNotification(entry.notificationId, builder.build(), id, |
944 new DownloadSharedPreferenceEntry(id, entry.notificationId, entr
y.isOffTheRecord, | 955 new DownloadSharedPreferenceEntry(id, entry.notificationId, entr
y.isOffTheRecord, |
945 entry.canDownloadWhileMetered, entry.fileName, isAutoRes
umable, | 956 entry.canDownloadWhileMetered, entry.fileName, isAutoRes
umable, |
946 isTransient)); | 957 isTransient)); |
947 stopTrackingInProgressDownload(id, true); | 958 stopTrackingInProgressDownload(id, true); |
948 } | 959 } |
949 | 960 |
950 /** | 961 /** |
951 * Add a download successful notification. | 962 * Add a download successful notification. |
952 * @param id The {@link ContentId} of the download. | 963 * @param id The {@link ContentId} of the download. |
953 * @param filePath Full path to the download. | 964 * @param filePath Full path to the download. |
954 * @param fileName Filename of the download. | 965 * @param fileName Filename of the download. |
955 * @param systemDownloadId Download ID assigned by system DownloadManager. | 966 * @param systemDownloadId Download ID assigned by system DownloadManager
. |
956 * @param isSupportedMimeType Whether the MIME type can be viewed inside bro
wser. | 967 * @param isSupportedMimeType Whether the MIME type can be viewed inside bro
wser. |
957 * @param isOpenable Whether or not this download can be opened. | 968 * @param isOpenable Whether or not this download can be opened. |
958 * @return ID of the successful download notification. Used for removing the
notification when | 969 * @param icon A {@link Bitmap} to be used as the large icon
for display. |
959 * user click on the snackbar. | 970 * @return ID of the successful download notification. Us
ed for removing the |
| 971 * notification when user click on the snackbar. |
960 */ | 972 */ |
961 @VisibleForTesting | 973 @VisibleForTesting |
962 public int notifyDownloadSuccessful(ContentId id, String filePath, String fi
leName, | 974 public int notifyDownloadSuccessful(ContentId id, String filePath, String fi
leName, |
963 long systemDownloadId, boolean isOffTheRecord, boolean isSupportedMi
meType, | 975 long systemDownloadId, boolean isOffTheRecord, boolean isSupportedMi
meType, |
964 boolean isOpenable) { | 976 boolean isOpenable, Bitmap icon) { |
965 int notificationId = getNotificationId(id); | 977 int notificationId = getNotificationId(id); |
966 ChromeNotificationBuilder builder = buildNotification(R.drawable.offline
_pin, fileName, | 978 ChromeNotificationBuilder builder = buildNotification(R.drawable.offline
_pin, fileName, |
967 mContext.getResources().getString(R.string.download_notification
_completed)); | 979 mContext.getResources().getString(R.string.download_notification
_completed)); |
968 ComponentName component = new ComponentName( | 980 ComponentName component = new ComponentName( |
969 mContext.getPackageName(), DownloadBroadcastReceiver.class.getNa
me()); | 981 mContext.getPackageName(), DownloadBroadcastReceiver.class.getNa
me()); |
970 | 982 |
971 if (isOpenable) { | 983 if (isOpenable) { |
972 Intent intent = null; | 984 Intent intent = null; |
973 if (LegacyHelpers.isLegacyDownload(id)) { | 985 if (LegacyHelpers.isLegacyDownload(id)) { |
974 intent = new Intent(DownloadManager.ACTION_NOTIFICATION_CLICKED)
; | 986 intent = new Intent(DownloadManager.ACTION_NOTIFICATION_CLICKED)
; |
975 long[] idArray = {systemDownloadId}; | 987 long[] idArray = {systemDownloadId}; |
976 intent.putExtra(DownloadManager.EXTRA_NOTIFICATION_CLICK_DOWNLOA
D_IDS, idArray); | 988 intent.putExtra(DownloadManager.EXTRA_NOTIFICATION_CLICK_DOWNLOA
D_IDS, idArray); |
977 intent.putExtra(EXTRA_DOWNLOAD_FILE_PATH, filePath); | 989 intent.putExtra(EXTRA_DOWNLOAD_FILE_PATH, filePath); |
978 intent.putExtra(EXTRA_IS_SUPPORTED_MIME_TYPE, isSupportedMimeTyp
e); | 990 intent.putExtra(EXTRA_IS_SUPPORTED_MIME_TYPE, isSupportedMimeTyp
e); |
979 intent.putExtra(EXTRA_IS_OFF_THE_RECORD, isOffTheRecord); | 991 intent.putExtra(EXTRA_IS_OFF_THE_RECORD, isOffTheRecord); |
980 intent.putExtra(EXTRA_DOWNLOAD_CONTENTID_ID, id.id); | 992 intent.putExtra(EXTRA_DOWNLOAD_CONTENTID_ID, id.id); |
981 intent.putExtra(EXTRA_DOWNLOAD_CONTENTID_NAMESPACE, id.namespace
); | 993 intent.putExtra(EXTRA_DOWNLOAD_CONTENTID_NAMESPACE, id.namespace
); |
982 intent.putExtra(NotificationConstants.EXTRA_NOTIFICATION_ID, not
ificationId); | 994 intent.putExtra(NotificationConstants.EXTRA_NOTIFICATION_ID, not
ificationId); |
983 } else { | 995 } else { |
984 intent = buildActionIntent(mContext, ACTION_DOWNLOAD_OPEN, id, f
alse); | 996 intent = buildActionIntent(mContext, ACTION_DOWNLOAD_OPEN, id, f
alse); |
985 } | 997 } |
986 | 998 |
987 intent.setComponent(component); | 999 intent.setComponent(component); |
988 builder.setContentIntent(PendingIntent.getBroadcast( | 1000 builder.setContentIntent(PendingIntent.getBroadcast( |
989 mContext, notificationId, intent, PendingIntent.FLAG_UPDATE_
CURRENT)); | 1001 mContext, notificationId, intent, PendingIntent.FLAG_UPDATE_
CURRENT)); |
990 } | 1002 } |
991 if (mDownloadSuccessLargeIcon == null) { | 1003 if (icon == null && mDownloadSuccessLargeIcon == null) { |
992 Bitmap bitmap = BitmapFactory.decodeResource( | 1004 Bitmap bitmap = BitmapFactory.decodeResource( |
993 mContext.getResources(), R.drawable.offline_pin); | 1005 mContext.getResources(), R.drawable.offline_pin); |
994 mDownloadSuccessLargeIcon = getLargeNotificationIcon(bitmap); | 1006 mDownloadSuccessLargeIcon = getLargeNotificationIcon(bitmap); |
995 } | 1007 } |
996 builder.setDeleteIntent(buildSummaryIconIntent(notificationId)); | 1008 builder.setDeleteIntent(buildSummaryIconIntent(notificationId)); |
997 builder.setLargeIcon(mDownloadSuccessLargeIcon); | 1009 builder.setLargeIcon(icon != null ? icon : mDownloadSuccessLargeIcon); |
998 updateNotification(notificationId, builder.build(), id, null); | 1010 updateNotification(notificationId, builder.build(), id, null); |
999 stopTrackingInProgressDownload(id, true); | 1011 stopTrackingInProgressDownload(id, true); |
1000 return notificationId; | 1012 return notificationId; |
1001 } | 1013 } |
1002 | 1014 |
1003 /** | 1015 /** |
1004 * Add a download failed notification. | 1016 * Add a download failed notification. |
1005 * @param id The {@link ContentId} of the download. | 1017 * @param id The {@link ContentId} of the download. |
1006 * @param fileName GUID of the download. | 1018 * @param fileName GUID of the download. |
| 1019 * @param icon A {@link Bitmap} to be used as the large icon for display
. |
1007 */ | 1020 */ |
1008 @VisibleForTesting | 1021 @VisibleForTesting |
1009 public void notifyDownloadFailed(ContentId id, String fileName) { | 1022 public void notifyDownloadFailed(ContentId id, String fileName, Bitmap icon)
{ |
1010 // If the download is not in history db, fileName could be empty. Get it
from | 1023 // If the download is not in history db, fileName could be empty. Get it
from |
1011 // SharedPreferences. | 1024 // SharedPreferences. |
1012 if (TextUtils.isEmpty(fileName)) { | 1025 if (TextUtils.isEmpty(fileName)) { |
1013 DownloadSharedPreferenceEntry entry = | 1026 DownloadSharedPreferenceEntry entry = |
1014 mDownloadSharedPreferenceHelper.getDownloadSharedPreferenceE
ntry(id); | 1027 mDownloadSharedPreferenceHelper.getDownloadSharedPreferenceE
ntry(id); |
1015 if (entry == null) return; | 1028 if (entry == null) return; |
1016 fileName = entry.fileName; | 1029 fileName = entry.fileName; |
1017 } | 1030 } |
1018 | 1031 |
1019 int notificationId = getNotificationId(id); | 1032 int notificationId = getNotificationId(id); |
1020 ChromeNotificationBuilder builder = | 1033 ChromeNotificationBuilder builder = |
1021 buildNotification(android.R.drawable.stat_sys_download_done, fil
eName, | 1034 buildNotification(android.R.drawable.stat_sys_download_done, fil
eName, |
1022 mContext.getResources().getString(R.string.download_noti
fication_failed)); | 1035 mContext.getResources().getString(R.string.download_noti
fication_failed)); |
| 1036 if (icon != null) builder.setLargeIcon(icon); |
1023 builder.setDeleteIntent(buildSummaryIconIntent(notificationId)); | 1037 builder.setDeleteIntent(buildSummaryIconIntent(notificationId)); |
1024 updateNotification(notificationId, builder.build(), id, null); | 1038 updateNotification(notificationId, builder.build(), id, null); |
1025 stopTrackingInProgressDownload(id, true); | 1039 stopTrackingInProgressDownload(id, true); |
1026 } | 1040 } |
1027 | 1041 |
1028 /** | 1042 /** |
1029 * Helper method to build a PendingIntent from the provided intent. | 1043 * Helper method to build a PendingIntent from the provided intent. |
1030 * @param intent Intent to broadcast. | 1044 * @param intent Intent to broadcast. |
1031 * @param notificationId ID of the notification. | 1045 * @param notificationId ID of the notification. |
1032 */ | 1046 */ |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1145 && TextUtils.equals(intent.getAction(), ACTION_DOWNLO
AD_OPEN))) { | 1159 && TextUtils.equals(intent.getAction(), ACTION_DOWNLO
AD_OPEN))) { |
1146 handleDownloadOperationForMissingNotification(intent); | 1160 handleDownloadOperationForMissingNotification(intent); |
1147 hideSummaryNotificationIfNecessary(-1); | 1161 hideSummaryNotificationIfNecessary(-1); |
1148 return; | 1162 return; |
1149 } | 1163 } |
1150 | 1164 |
1151 if (ACTION_DOWNLOAD_PAUSE.equals(intent.getAction())) { | 1165 if (ACTION_DOWNLOAD_PAUSE.equals(intent.getAction())) { |
1152 // If browser process already goes away, the download should have al
ready paused. Do | 1166 // If browser process already goes away, the download should have al
ready paused. Do |
1153 // nothing in that case. | 1167 // nothing in that case. |
1154 if (!DownloadManagerService.hasDownloadManagerService()) { | 1168 if (!DownloadManagerService.hasDownloadManagerService()) { |
1155 notifyDownloadPaused(entry.id, !entry.isOffTheRecord, false, ent
ry.isTransient); | 1169 // TODO(dtrainor): Should we spin up native to make sure we have
the icon? Or maybe |
| 1170 // build a Java cache for easy access. |
| 1171 notifyDownloadPaused( |
| 1172 entry.id, !entry.isOffTheRecord, false, entry.isTransien
t, null); |
1156 hideSummaryNotificationIfNecessary(-1); | 1173 hideSummaryNotificationIfNecessary(-1); |
1157 return; | 1174 return; |
1158 } | 1175 } |
1159 } else if (ACTION_DOWNLOAD_RESUME.equals(intent.getAction())) { | 1176 } else if (ACTION_DOWNLOAD_RESUME.equals(intent.getAction())) { |
1160 // If user manually resumes a download, update the network type if i
t | 1177 // If user manually resumes a download, update the network type if i
t |
1161 // is not metered previously. | 1178 // is not metered previously. |
1162 boolean canDownloadWhileMetered = entry.canDownloadWhileMetered | 1179 boolean canDownloadWhileMetered = entry.canDownloadWhileMetered |
1163 || DownloadManagerService.isActiveNetworkMetered(mContext); | 1180 || DownloadManagerService.isActiveNetworkMetered(mContext); |
1164 // Update the SharedPreference entry. | 1181 // Update the SharedPreference entry. |
1165 mDownloadSharedPreferenceHelper.addOrReplaceSharedPreferenceEntry( | 1182 mDownloadSharedPreferenceHelper.addOrReplaceSharedPreferenceEntry( |
(...skipping 26 matching lines...) Expand all Loading... |
1192 if (ACTION_DOWNLOAD_CANCEL.equals(intent.getAction())) { | 1209 if (ACTION_DOWNLOAD_CANCEL.equals(intent.getAction())) { |
1193 // TODO(qinmin): Alternatively, we can delete the downlo
aded content on | 1210 // TODO(qinmin): Alternatively, we can delete the downlo
aded content on |
1194 // SD card, and remove the download ID from the SharedPr
eferences so we | 1211 // SD card, and remove the download ID from the SharedPr
eferences so we |
1195 // don't need to restart the browser process. http://crb
ug.com/579643. | 1212 // don't need to restart the browser process. http://crb
ug.com/579643. |
1196 cancelNotification(entry.notificationId, entry.id); | 1213 cancelNotification(entry.notificationId, entry.id); |
1197 downloadServiceDelegate.cancelDownload(entry.id, entry.i
sOffTheRecord); | 1214 downloadServiceDelegate.cancelDownload(entry.id, entry.i
sOffTheRecord); |
1198 for (Observer observer : mObservers) { | 1215 for (Observer observer : mObservers) { |
1199 observer.onDownloadCanceled(entry.id); | 1216 observer.onDownloadCanceled(entry.id); |
1200 } | 1217 } |
1201 } else if (ACTION_DOWNLOAD_PAUSE.equals(intent.getAction())) { | 1218 } else if (ACTION_DOWNLOAD_PAUSE.equals(intent.getAction())) { |
1202 notifyDownloadPaused(entry.id, true, false, entry.isTransien
t); | 1219 // TODO(dtrainor): Consider hitting the delegate and rely on
that to update the |
| 1220 // state. |
| 1221 notifyDownloadPaused(entry.id, true, false, entry.isTransien
t, null); |
1203 downloadServiceDelegate.pauseDownload(entry.id, entry.isOffT
heRecord); | 1222 downloadServiceDelegate.pauseDownload(entry.id, entry.isOffT
heRecord); |
1204 } else if (ACTION_DOWNLOAD_RESUME.equals(intent.getAction())) { | 1223 } else if (ACTION_DOWNLOAD_RESUME.equals(intent.getAction())) { |
| 1224 // TODO(dtrainor): Consider hitting the delegate and rely on
that to update the |
| 1225 // state. |
1205 notifyDownloadPending(entry.id, entry.fileName, entry.isOffT
heRecord, | 1226 notifyDownloadPending(entry.id, entry.fileName, entry.isOffT
heRecord, |
1206 entry.canDownloadWhileMetered, entry.isTransient); | 1227 entry.canDownloadWhileMetered, entry.isTransient, nu
ll); |
1207 downloadServiceDelegate.resumeDownload( | 1228 downloadServiceDelegate.resumeDownload( |
1208 entry.id, entry.buildDownloadItem(), true); | 1229 entry.id, entry.buildDownloadItem(), true); |
1209 } else if (ACTION_DOWNLOAD_RESUME_ALL.equals(intent.getAction())
) { | 1230 } else if (ACTION_DOWNLOAD_RESUME_ALL.equals(intent.getAction())
) { |
1210 assert entry == null; | 1231 assert entry == null; |
1211 resumeAllPendingDownloads(); | 1232 resumeAllPendingDownloads(); |
1212 } else if (ACTION_DOWNLOAD_OPEN.equals(intent.getAction())) { | 1233 } else if (ACTION_DOWNLOAD_OPEN.equals(intent.getAction())) { |
1213 ContentId id = getContentIdFromIntent(intent); | 1234 ContentId id = getContentIdFromIntent(intent); |
1214 if (LegacyHelpers.isLegacyOfflinePage(id)) { | 1235 if (LegacyHelpers.isLegacyOfflinePage(id)) { |
1215 OfflinePageDownloadBridge.openDownloadedPage(id); | 1236 OfflinePageDownloadBridge.openDownloadedPage(id); |
1216 } else if (id != null) { | 1237 } else if (id != null) { |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1365 */ | 1386 */ |
1366 public void resumeAllPendingDownloads() { | 1387 public void resumeAllPendingDownloads() { |
1367 if (!DownloadManagerService.hasDownloadManagerService()) return; | 1388 if (!DownloadManagerService.hasDownloadManagerService()) return; |
1368 List<DownloadSharedPreferenceEntry> entries = mDownloadSharedPreferenceH
elper.getEntries(); | 1389 List<DownloadSharedPreferenceEntry> entries = mDownloadSharedPreferenceH
elper.getEntries(); |
1369 for (int i = 0; i < entries.size(); ++i) { | 1390 for (int i = 0; i < entries.size(); ++i) { |
1370 DownloadSharedPreferenceEntry entry = entries.get(i); | 1391 DownloadSharedPreferenceEntry entry = entries.get(i); |
1371 if (!canResumeDownload(mContext, entry)) continue; | 1392 if (!canResumeDownload(mContext, entry)) continue; |
1372 if (mDownloadsInProgress.contains(entry.id)) continue; | 1393 if (mDownloadsInProgress.contains(entry.id)) continue; |
1373 | 1394 |
1374 notifyDownloadPending(entry.id, entry.fileName, false, entry.canDown
loadWhileMetered, | 1395 notifyDownloadPending(entry.id, entry.fileName, false, entry.canDown
loadWhileMetered, |
1375 entry.isTransient); | 1396 entry.isTransient, null); |
1376 DownloadServiceDelegate downloadServiceDelegate = getServiceDelegate
(entry.id); | 1397 DownloadServiceDelegate downloadServiceDelegate = getServiceDelegate
(entry.id); |
1377 downloadServiceDelegate.resumeDownload(entry.id, entry.buildDownload
Item(), false); | 1398 downloadServiceDelegate.resumeDownload(entry.id, entry.buildDownload
Item(), false); |
1378 downloadServiceDelegate.destroyServiceDelegate(); | 1399 downloadServiceDelegate.destroyServiceDelegate(); |
1379 } | 1400 } |
1380 } | 1401 } |
1381 | 1402 |
1382 /** | 1403 /** |
1383 * Return the notification ID for the given download {@link ContentId}. | 1404 * Return the notification ID for the given download {@link ContentId}. |
1384 * @param id the {@link ContentId} of the download. | 1405 * @param id the {@link ContentId} of the download. |
1385 * @return notification ID to be used. | 1406 * @return notification ID to be used. |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1442 return context.getString(R.string.remaining_duration_minutes, minute
s); | 1463 return context.getString(R.string.remaining_duration_minutes, minute
s); |
1443 } else if (minutes > 0) { | 1464 } else if (minutes > 0) { |
1444 return context.getString(R.string.remaining_duration_one_minute); | 1465 return context.getString(R.string.remaining_duration_one_minute); |
1445 } else if (seconds == 1) { | 1466 } else if (seconds == 1) { |
1446 return context.getString(R.string.remaining_duration_one_second); | 1467 return context.getString(R.string.remaining_duration_one_second); |
1447 } else { | 1468 } else { |
1448 return context.getString(R.string.remaining_duration_seconds, second
s); | 1469 return context.getString(R.string.remaining_duration_seconds, second
s); |
1449 } | 1470 } |
1450 } | 1471 } |
1451 } | 1472 } |
OLD | NEW |