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.app.Notification; | 7 import android.app.Notification; |
8 import android.app.NotificationManager; | 8 import android.app.NotificationManager; |
9 import android.app.PendingIntent; | 9 import android.app.PendingIntent; |
10 import android.app.Service; | 10 import android.app.Service; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
46 static final String EXTRA_DOWNLOAD_FILE_NAME = "DownloadFileName"; | 46 static final String EXTRA_DOWNLOAD_FILE_NAME = "DownloadFileName"; |
47 static final String ACTION_DOWNLOAD_CANCEL = | 47 static final String ACTION_DOWNLOAD_CANCEL = |
48 "org.chromium.chrome.browser.download.DOWNLOAD_CANCEL"; | 48 "org.chromium.chrome.browser.download.DOWNLOAD_CANCEL"; |
49 static final String ACTION_DOWNLOAD_PAUSE = | 49 static final String ACTION_DOWNLOAD_PAUSE = |
50 "org.chromium.chrome.browser.download.DOWNLOAD_PAUSE"; | 50 "org.chromium.chrome.browser.download.DOWNLOAD_PAUSE"; |
51 static final String ACTION_DOWNLOAD_RESUME = | 51 static final String ACTION_DOWNLOAD_RESUME = |
52 "org.chromium.chrome.browser.download.DOWNLOAD_RESUME"; | 52 "org.chromium.chrome.browser.download.DOWNLOAD_RESUME"; |
53 static final int INVALID_DOWNLOAD_PERCENTAGE = -1; | 53 static final int INVALID_DOWNLOAD_PERCENTAGE = -1; |
54 @VisibleForTesting | 54 @VisibleForTesting |
55 static final String PENDING_DOWNLOAD_NOTIFICATIONS = "PendingDownloadNotific ations"; | 55 static final String PENDING_DOWNLOAD_NOTIFICATIONS = "PendingDownloadNotific ations"; |
56 private static final String NOTIFICATION_NAMESPACE = "DownloadNotificationSe rvice"; | 56 static final String NOTIFICATION_NAMESPACE = "DownloadNotificationService"; |
Ted C
2016/05/20 00:02:13
rename DEPRECATED?
qinmin
2016/05/23 23:03:14
There is no need to deprecate it. See reasons belo
| |
57 private static final String TAG = "DownloadNotification"; | 57 private static final String TAG = "DownloadNotification"; |
58 private static final String NEXT_DOWNLOAD_NOTIFICATION_ID = "NextDownloadNot ificationId"; | |
Ted C
2016/05/20 00:02:13
Instead of Next, I would use V2
qinmin
2016/05/23 23:03:13
Since I am keeping the namespace, V2 is probably n
Ted C
2016/05/23 23:15:23
got it...I was thinking it was a namespace...do'h
| |
59 // Notification Id starting value, to avoid conflicts from IDs used in prior versions. | |
60 private static final int STARTING_NOTIFICATION_ID = 1000000; | |
Ted C
2016/05/20 00:02:13
any reason we don't use a different notification n
qinmin
2016/05/23 23:03:14
If we clear all existing notifications, we have to
| |
58 private final IBinder mBinder = new LocalBinder(); | 61 private final IBinder mBinder = new LocalBinder(); |
59 private final List<DownloadSharedPreferenceEntry> mDownloadSharedPreferenceE ntries = | 62 private final List<DownloadSharedPreferenceEntry> mDownloadSharedPreferenceE ntries = |
60 new ArrayList<DownloadSharedPreferenceEntry>(); | 63 new ArrayList<DownloadSharedPreferenceEntry>(); |
61 private NotificationManager mNotificationManager; | 64 private NotificationManager mNotificationManager; |
62 private SharedPreferences mSharedPrefs; | 65 private SharedPreferences mSharedPrefs; |
63 private Context mContext; | 66 private Context mContext; |
67 private int mNextNotificationId; | |
64 | 68 |
65 /** | 69 /** |
66 * Class for clients to access. | 70 * Class for clients to access. |
67 */ | 71 */ |
68 public class LocalBinder extends Binder { | 72 public class LocalBinder extends Binder { |
69 DownloadNotificationService getService() { | 73 DownloadNotificationService getService() { |
70 return DownloadNotificationService.this; | 74 return DownloadNotificationService.this; |
71 } | 75 } |
72 } | 76 } |
73 | 77 |
(...skipping 17 matching lines...) Expand all Loading... | |
91 // onStartCommand(), it will be restarted as soon as resources are avail able | 95 // onStartCommand(), it will be restarted as soon as resources are avail able |
92 // after it is killed. As a result, onCreate() may be called after Chrom e | 96 // after it is killed. As a result, onCreate() may be called after Chrom e |
93 // gets killed and before user restarts chrome. In that case, | 97 // gets killed and before user restarts chrome. In that case, |
94 // DownloadManagerService.hasDownloadManagerService() will return false as | 98 // DownloadManagerService.hasDownloadManagerService() will return false as |
95 // there are no calls to initialize DownloadManagerService. Pause all th e | 99 // there are no calls to initialize DownloadManagerService. Pause all th e |
96 // download notifications as download will not progress without chrome. | 100 // download notifications as download will not progress without chrome. |
97 if (!DownloadManagerService.hasDownloadManagerService()) { | 101 if (!DownloadManagerService.hasDownloadManagerService()) { |
98 pauseAllDownloads(); | 102 pauseAllDownloads(); |
99 stopSelf(); | 103 stopSelf(); |
100 } | 104 } |
105 mNextNotificationId = mSharedPrefs.getInt( | |
106 NEXT_DOWNLOAD_NOTIFICATION_ID, STARTING_NOTIFICATION_ID); | |
Ted C
2016/05/20 00:02:13
+4 indent
qinmin
2016/05/23 23:03:14
Done.
| |
107 | |
101 } | 108 } |
102 | 109 |
103 @Override | 110 @Override |
104 public int onStartCommand(final Intent intent, int flags, int startId) { | 111 public int onStartCommand(final Intent intent, int flags, int startId) { |
105 if (isDownloadOperationIntent(intent)) { | 112 if (isDownloadOperationIntent(intent)) { |
106 handleDownloadOperation(intent); | 113 handleDownloadOperation(intent); |
107 } | 114 } |
108 | 115 |
109 // This should restart the service after Chrome gets killed. However, th is | 116 // This should restart the service after Chrome gets killed. However, th is |
110 // doesn't work on Android 4.4.2. | 117 // doesn't work on Android 4.4.2. |
111 return START_STICKY; | 118 return START_STICKY; |
112 } | 119 } |
113 | 120 |
114 @Override | 121 @Override |
115 public IBinder onBind(Intent intent) { | 122 public IBinder onBind(Intent intent) { |
116 return mBinder; | 123 return mBinder; |
117 } | 124 } |
118 | 125 |
119 /** | 126 /** |
120 * Add a in-progress download notification. | 127 * Add a in-progress download notification. |
121 * @param notificationId Notification ID of the download. | |
122 * @param downloadGuid GUID of the download. | 128 * @param downloadGuid GUID of the download. |
123 * @param fileName File name of the download. | 129 * @param fileName File name of the download. |
124 * @param percentage Percentage completed. Value should be between 0 to 100 if | 130 * @param percentage Percentage completed. Value should be between 0 to 100 if |
125 * the percentage can be determined, or -1 if it is unknown. | 131 * the percentage can be determined, or -1 if it is unknown. |
126 * @param timeRemainingInMillis Remaining download time in milliseconds. | 132 * @param timeRemainingInMillis Remaining download time in milliseconds. |
127 * @param startTime Time when download started. | 133 * @param startTime Time when download started. |
128 * @param isResumable Whether the download can be resumed. | 134 * @param isResumable Whether the download can be resumed. |
129 * @param canDownloadWhileMetered Whether the download can happen in metered network. | 135 * @param canDownloadWhileMetered Whether the download can happen in metered network. |
130 */ | 136 */ |
131 public void notifyDownloadProgress(int notificationId, String downloadGuid, String fileName, | 137 public void notifyDownloadProgress(String downloadGuid, String fileName, int percentage, |
132 int percentage, long timeRemainingInMillis, long startTime, boolean isResumable, | 138 long timeRemainingInMillis, long startTime, boolean isResumable, |
133 boolean canDownloadWhileMetered) { | 139 boolean canDownloadWhileMetered) { |
134 boolean indeterminate = percentage == INVALID_DOWNLOAD_PERCENTAGE; | 140 boolean indeterminate = percentage == INVALID_DOWNLOAD_PERCENTAGE; |
135 NotificationCompat.Builder builder = buildNotification( | 141 NotificationCompat.Builder builder = buildNotification( |
136 android.R.drawable.stat_sys_download, fileName, null); | 142 android.R.drawable.stat_sys_download, fileName, null); |
137 builder.setOngoing(true).setProgress(100, percentage, indeterminate); | 143 builder.setOngoing(true).setProgress(100, percentage, indeterminate); |
138 builder.setPriority(Notification.PRIORITY_HIGH); | 144 builder.setPriority(Notification.PRIORITY_HIGH); |
139 if (!indeterminate) { | 145 if (!indeterminate) { |
140 NumberFormat formatter = NumberFormat.getPercentInstance(Locale.getD efault()); | 146 NumberFormat formatter = NumberFormat.getPercentInstance(Locale.getD efault()); |
141 String percentText = formatter.format(percentage / 100.0); | 147 String percentText = formatter.format(percentage / 100.0); |
142 String duration = getDurationString(timeRemainingInMillis); | 148 String duration = getDurationString(timeRemainingInMillis); |
143 builder.setContentText(duration).setContentInfo(percentText); | 149 builder.setContentText(duration).setContentInfo(percentText); |
144 } | 150 } |
151 int notificationId = getNotificationId(downloadGuid); | |
145 addOrReplaceSharedPreferenceEntry(new DownloadSharedPreferenceEntry( | 152 addOrReplaceSharedPreferenceEntry(new DownloadSharedPreferenceEntry( |
146 notificationId, isResumable, canDownloadWhileMetered, downloadGu id, fileName)); | 153 notificationId, isResumable, canDownloadWhileMetered, downloadGu id, fileName)); |
147 if (startTime > 0) builder.setWhen(startTime); | 154 if (startTime > 0) builder.setWhen(startTime); |
148 builder.addAction(R.drawable.bookmark_cancel_active, | 155 builder.addAction(R.drawable.bookmark_cancel_active, |
149 mContext.getResources().getString(R.string.download_notification _cancel_button), | 156 mContext.getResources().getString(R.string.download_notification _cancel_button), |
150 buildPendingIntent(ACTION_DOWNLOAD_CANCEL, notificationId, downl oadGuid, fileName)); | 157 buildPendingIntent(ACTION_DOWNLOAD_CANCEL, notificationId, downl oadGuid, fileName)); |
151 if (isResumable) { | 158 if (isResumable) { |
152 builder.addAction(R.drawable.ic_vidcontrol_pause, | 159 builder.addAction(R.drawable.ic_vidcontrol_pause, |
153 mContext.getResources().getString(R.string.download_notifica tion_pause_button), | 160 mContext.getResources().getString(R.string.download_notifica tion_pause_button), |
154 buildPendingIntent(ACTION_DOWNLOAD_PAUSE, notificationId, do wnloadGuid, | 161 buildPendingIntent(ACTION_DOWNLOAD_PAUSE, notificationId, do wnloadGuid, |
155 fileName)); | 162 fileName)); |
156 } | 163 } |
157 updateNotification(notificationId, builder.build()); | 164 updateNotification(notificationId, builder.build()); |
158 } | 165 } |
159 | 166 |
160 /** | 167 /** |
161 * Converts milliseconds to time remaining format. | 168 * Converts milliseconds to time remaining format. |
162 * @param timeRemainingInMillis Remaining download time in milliseconds. | 169 * @param timeRemainingInMillis Remaining download time in milliseconds. |
163 * @return formatted remaining time string for display. | 170 * @return formatted remaining time string for display. |
164 */ | 171 */ |
165 @VisibleForTesting | 172 @VisibleForTesting |
166 String getDurationString(long timeRemainingInMillis) { | 173 String getDurationString(long timeRemainingInMillis) { |
167 return LocalizationUtils.getDurationString(timeRemainingInMillis); | 174 return LocalizationUtils.getDurationString(timeRemainingInMillis); |
168 } | 175 } |
169 | 176 |
170 /** | 177 /** |
171 * Cancel a download notification. | 178 * Cancel a download notification. |
172 * @param notificationId Notification ID of the download. | 179 * @notificationId Notification ID of the download |
173 * @param downloadGuid GUID of the download. | 180 * @param downloadGuid GUID of the download. |
174 */ | 181 */ |
175 public void cancelNotification(int notificationId, String downloadGuid) { | 182 @VisibleForTesting |
176 mNotificationManager.cancel(NOTIFICATION_NAMESPACE, notificationId); | 183 void cancelNotification(int notificaitonId, String downloadGuid) { |
184 mNotificationManager.cancel(NOTIFICATION_NAMESPACE, notificaitonId); | |
177 removeSharedPreferenceEntry(downloadGuid); | 185 removeSharedPreferenceEntry(downloadGuid); |
178 } | 186 } |
179 | 187 |
180 /** | 188 /** |
189 * Called when a download is canceled. | |
190 * @param downloadGuid GUID of the download. | |
191 */ | |
192 public void notifyDownloadCanceled(String downloadGuid) { | |
193 DownloadSharedPreferenceEntry entry = getDownloadSharedPreferenceEntry(d ownloadGuid); | |
194 if (entry == null) return; | |
195 cancelNotification(entry.notificationId, downloadGuid); | |
196 } | |
197 | |
198 /** | |
181 * Change a download notification to paused state. | 199 * Change a download notification to paused state. |
182 * @param downloadGuid GUID of the download. | 200 * @param downloadGuid GUID of the download. |
183 * @param isAutoResumable whether download is can be resumed automatically. | 201 * @param isAutoResumable whether download is can be resumed automatically. |
184 */ | 202 */ |
185 public void notifyDownloadPaused(String downloadGuid, boolean isAutoResumabl e) { | 203 public void notifyDownloadPaused(String downloadGuid, boolean isAutoResumabl e) { |
186 DownloadSharedPreferenceEntry entry = getDownloadSharedPreferenceEntry(d ownloadGuid); | 204 DownloadSharedPreferenceEntry entry = getDownloadSharedPreferenceEntry(d ownloadGuid); |
187 if (entry == null) return; | 205 if (entry == null) return; |
188 NotificationCompat.Builder builder = buildNotification( | 206 NotificationCompat.Builder builder = buildNotification( |
189 android.R.drawable.ic_media_pause, entry.fileName, | 207 android.R.drawable.ic_media_pause, entry.fileName, |
190 mContext.getResources().getString(R.string.download_notification _paused)); | 208 mContext.getResources().getString(R.string.download_notification _paused)); |
(...skipping 12 matching lines...) Expand all Loading... | |
203 } | 221 } |
204 updateNotification(entry.notificationId, builder.build()); | 222 updateNotification(entry.notificationId, builder.build()); |
205 // If download is not auto resumable, there is no need to keep it in Sha redPreferences. | 223 // If download is not auto resumable, there is no need to keep it in Sha redPreferences. |
206 if (!entry.isResumable || !isAutoResumable) { | 224 if (!entry.isResumable || !isAutoResumable) { |
207 removeSharedPreferenceEntry(downloadGuid); | 225 removeSharedPreferenceEntry(downloadGuid); |
208 } | 226 } |
209 } | 227 } |
210 | 228 |
211 /** | 229 /** |
212 * Add a download successful notification. | 230 * Add a download successful notification. |
213 * @param notificationId Notification ID of the download. | |
214 * @param downloadGuid GUID of the download. | 231 * @param downloadGuid GUID of the download. |
215 * @param fileName GUID of the download. | 232 * @param fileName GUID of the download. |
216 * @param intent Intent to launch when clicking the notification. | 233 * @param intent Intent to launch when clicking the notification. |
234 * @return ID of the successful download notification. Used for removing the notification when | |
235 * user click on the snackbar. | |
217 */ | 236 */ |
218 public void notifyDownloadSuccessful(int notificationId, String downloadGuid , String fileName, | 237 public int notifyDownloadSuccessful(String downloadGuid, String fileName, In tent intent) { |
219 Intent intent) { | 238 int notificationId = getNotificationId(downloadGuid); |
220 NotificationCompat.Builder builder = buildNotification( | 239 NotificationCompat.Builder builder = buildNotification( |
221 android.R.drawable.stat_sys_download_done, fileName, | 240 android.R.drawable.stat_sys_download_done, fileName, |
222 mContext.getResources().getString(R.string.download_notification _completed)); | 241 mContext.getResources().getString(R.string.download_notification _completed)); |
223 if (intent != null) { | 242 if (intent != null) { |
224 builder.setContentIntent(PendingIntent.getActivity( | 243 builder.setContentIntent(PendingIntent.getActivity( |
225 mContext, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT)); | 244 mContext, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT)); |
226 } | 245 } |
227 updateNotification(notificationId, builder.build()); | 246 updateNotification(notificationId, builder.build()); |
228 removeSharedPreferenceEntry(downloadGuid); | 247 removeSharedPreferenceEntry(downloadGuid); |
248 return notificationId; | |
229 } | 249 } |
230 | 250 |
231 /** | 251 /** |
232 * Add a download failed notification. | 252 * Add a download failed notification. |
233 * @param notificationId Notification ID of the download. | |
234 * @param downloadGuid GUID of the download. | 253 * @param downloadGuid GUID of the download. |
235 * @param fileName GUID of the download. | 254 * @param fileName GUID of the download. |
236 */ | 255 */ |
237 public void notifyDownloadFailed(int notificationId, String downloadGuid, St ring fileName) { | 256 public void notifyDownloadFailed(String downloadGuid, String fileName) { |
257 int notificationId = getNotificationId(downloadGuid); | |
238 NotificationCompat.Builder builder = buildNotification( | 258 NotificationCompat.Builder builder = buildNotification( |
239 android.R.drawable.stat_sys_download_done, fileName, | 259 android.R.drawable.stat_sys_download_done, fileName, |
240 mContext.getResources().getString(R.string.download_notification _failed)); | 260 mContext.getResources().getString(R.string.download_notification _failed)); |
241 updateNotification(notificationId, builder.build()); | 261 updateNotification(notificationId, builder.build()); |
242 removeSharedPreferenceEntry(downloadGuid); | 262 removeSharedPreferenceEntry(downloadGuid); |
243 } | 263 } |
244 | 264 |
245 /** | 265 /** |
246 * Called to pause all the download notifications. | 266 * Called to pause all the download notifications. |
247 */ | 267 */ |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
335 // SD card, and remove the download ID from the SharedPr eferences so we | 355 // SD card, and remove the download ID from the SharedPr eferences so we |
336 // don't need to restart the browser process. http://crb ug.com/579643. | 356 // don't need to restart the browser process. http://crb ug.com/579643. |
337 cancelNotification(notificationId, guid); | 357 cancelNotification(notificationId, guid); |
338 service.cancelDownload(guid); | 358 service.cancelDownload(guid); |
339 break; | 359 break; |
340 case ACTION_DOWNLOAD_PAUSE: | 360 case ACTION_DOWNLOAD_PAUSE: |
341 service.pauseDownload(guid); | 361 service.pauseDownload(guid); |
342 break; | 362 break; |
343 case ACTION_DOWNLOAD_RESUME: | 363 case ACTION_DOWNLOAD_RESUME: |
344 assert item != null; | 364 assert item != null; |
345 notifyDownloadProgress(notificationId, guid, fileName, | 365 notifyDownloadProgress(guid, fileName, INVALID_DOWNLOAD_ PERCENTAGE, 0, 0, |
346 INVALID_DOWNLOAD_PERCENTAGE, 0, 0, true, | 366 true, canDownloadWhileMetered); |
347 canDownloadWhileMetered); | |
348 service.resumeDownload(item, true); | 367 service.resumeDownload(item, true); |
349 break; | 368 break; |
350 default: | 369 default: |
351 Log.e(TAG, "Unrecognized intent action.", intent); | 370 Log.e(TAG, "Unrecognized intent action.", intent); |
352 break; | 371 break; |
353 } | 372 } |
354 } | 373 } |
355 }; | 374 }; |
356 try { | 375 try { |
357 ChromeBrowserInitializer.getInstance(mContext).handlePreNativeStartu p(parts); | 376 ChromeBrowserInitializer.getInstance(mContext).handlePreNativeStartu p(parts); |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
444 * Resumes all pending downloads from |mDownloadSharedPreferenceEntries|. | 463 * Resumes all pending downloads from |mDownloadSharedPreferenceEntries|. |
445 */ | 464 */ |
446 public void resumeAllPendingDownloads() { | 465 public void resumeAllPendingDownloads() { |
447 boolean isNetworkMetered = DownloadManagerService.isActiveNetworkMetered (mContext); | 466 boolean isNetworkMetered = DownloadManagerService.isActiveNetworkMetered (mContext); |
448 if (!DownloadManagerService.hasDownloadManagerService()) return; | 467 if (!DownloadManagerService.hasDownloadManagerService()) return; |
449 DownloadManagerService service = | 468 DownloadManagerService service = |
450 DownloadManagerService.getDownloadManagerService(getApplicationC ontext()); | 469 DownloadManagerService.getDownloadManagerService(getApplicationC ontext()); |
451 for (int i = 0; i < mDownloadSharedPreferenceEntries.size(); ++i) { | 470 for (int i = 0; i < mDownloadSharedPreferenceEntries.size(); ++i) { |
452 DownloadSharedPreferenceEntry entry = mDownloadSharedPreferenceEntri es.get(i); | 471 DownloadSharedPreferenceEntry entry = mDownloadSharedPreferenceEntri es.get(i); |
453 if (!entry.canDownloadWhileMetered && isNetworkMetered) continue; | 472 if (!entry.canDownloadWhileMetered && isNetworkMetered) continue; |
454 notifyDownloadProgress(entry.notificationId, entry.downloadGuid, ent ry.fileName, | 473 notifyDownloadProgress(entry.downloadGuid, entry.fileName, INVALID_D OWNLOAD_PERCENTAGE, |
455 INVALID_DOWNLOAD_PERCENTAGE, 0, 0, true, entry.canDownloadWh ileMetered); | 474 0, 0, true, entry.canDownloadWhileMetered); |
456 service.resumeDownload(entry.buildDownloadItem(), false); | 475 service.resumeDownload(entry.buildDownloadItem(), false); |
457 } | 476 } |
458 } | 477 } |
459 | 478 |
460 /** | 479 /** |
461 * Parse the DownloadSharedPreferenceEntry from the shared preference and re turn a list of them. | 480 * Parse the DownloadSharedPreferenceEntry from the shared preference and re turn a list of them. |
462 * @return a list of parsed DownloadSharedPreferenceEntry. | 481 * @return a list of parsed DownloadSharedPreferenceEntry. |
463 */ | 482 */ |
464 void parseDownloadSharedPrefs() { | 483 void parseDownloadSharedPrefs() { |
465 if (!mSharedPrefs.contains(PENDING_DOWNLOAD_NOTIFICATIONS)) return; | 484 if (!mSharedPrefs.contains(PENDING_DOWNLOAD_NOTIFICATIONS)) return; |
(...skipping 27 matching lines...) Expand all Loading... | |
493 * Helper method to store all the SharedPreferences entries. | 512 * Helper method to store all the SharedPreferences entries. |
494 */ | 513 */ |
495 private void storeDownloadSharedPreferenceEntries() { | 514 private void storeDownloadSharedPreferenceEntries() { |
496 Set<String> entries = new HashSet<String>(); | 515 Set<String> entries = new HashSet<String>(); |
497 for (int i = 0; i < mDownloadSharedPreferenceEntries.size(); ++i) { | 516 for (int i = 0; i < mDownloadSharedPreferenceEntries.size(); ++i) { |
498 entries.add(mDownloadSharedPreferenceEntries.get(i).getSharedPrefere nceString()); | 517 entries.add(mDownloadSharedPreferenceEntries.get(i).getSharedPrefere nceString()); |
499 } | 518 } |
500 DownloadManagerService.storeDownloadInfo( | 519 DownloadManagerService.storeDownloadInfo( |
501 mSharedPrefs, PENDING_DOWNLOAD_NOTIFICATIONS, entries); | 520 mSharedPrefs, PENDING_DOWNLOAD_NOTIFICATIONS, entries); |
502 } | 521 } |
522 | |
523 /** | |
524 * Return the notification ID for the given download GUID. | |
525 * @return notification ID to be used. | |
526 */ | |
527 private int getNotificationId(String downloadGuid) { | |
528 DownloadSharedPreferenceEntry entry = getDownloadSharedPreferenceEntry(d ownloadGuid); | |
529 if (entry != null) return entry.notificationId; | |
530 int notificationId = mNextNotificationId; | |
531 mNextNotificationId = mNextNotificationId == Integer.MAX_VALUE | |
532 ? STARTING_NOTIFICATION_ID : mNextNotificationId + 1; | |
533 SharedPreferences.Editor editor = mSharedPrefs.edit(); | |
534 editor.putInt(NEXT_DOWNLOAD_NOTIFICATION_ID, mNextNotificationId); | |
535 editor.apply(); | |
536 return notificationId; | |
537 } | |
503 } | 538 } |
OLD | NEW |