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