OLD | NEW |
1 /* | 1 /* |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
3 * Copyright (C) 2006-present eyeo GmbH | 3 * Copyright (C) 2006-present eyeo GmbH |
4 * | 4 * |
5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
8 * | 8 * |
9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 13 matching lines...) Expand all Loading... |
24 import java.io.OutputStreamWriter; | 24 import java.io.OutputStreamWriter; |
25 import java.nio.charset.StandardCharsets; | 25 import java.nio.charset.StandardCharsets; |
26 import java.util.ArrayList; | 26 import java.util.ArrayList; |
27 import java.util.HashMap; | 27 import java.util.HashMap; |
28 import java.util.HashSet; | 28 import java.util.HashSet; |
29 import java.util.List; | 29 import java.util.List; |
30 import java.util.Locale; | 30 import java.util.Locale; |
31 import java.util.Map; | 31 import java.util.Map; |
32 | 32 |
33 import org.adblockplus.sbrowser.contentblocker.engine.Subscription.Type; | 33 import org.adblockplus.sbrowser.contentblocker.engine.Subscription.Type; |
| 34 import org.adblockplus.sbrowser.contentblocker.util.SubscriptionUtils; |
34 | 35 |
35 import android.util.Log; | 36 import android.util.Log; |
36 | 37 |
37 /** | 38 /** |
38 * This class holds all listed subscriptions and manages the subscription | 39 * This class holds all listed subscriptions and manages the subscription |
39 * aggregation cache folder. | 40 * aggregation cache folder. |
40 */ | 41 */ |
41 final class Subscriptions | 42 final class Subscriptions |
42 { | 43 { |
43 private static final String TAG = Subscriptions.class.getSimpleName(); | 44 private static final String TAG = Subscriptions.class.getSimpleName(); |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 filtersFile = new File(this.subscriptionFolder, "user_" + sub.getTitle() +
".sub"); | 138 filtersFile = new File(this.subscriptionFolder, "user_" + sub.getTitle() +
".sub"); |
138 } | 139 } |
139 else | 140 else |
140 { | 141 { |
141 filtersFile = new File(this.subscriptionFolder, "url_" | 142 filtersFile = new File(this.subscriptionFolder, "url_" |
142 + new File(sub.getURL().getPath()).getName() + ".sub"); | 143 + new File(sub.getURL().getPath()).getName() + ".sub"); |
143 } | 144 } |
144 return filtersFile; | 145 return filtersFile; |
145 } | 146 } |
146 | 147 |
| 148 private File getNotificationDataFile() |
| 149 { |
| 150 return new File (this.subscriptionFolder, Notification.NOTIFICATON_DATA_FILE
_NAME); |
| 151 } |
| 152 |
147 File getMetaFile(final Subscription sub) | 153 File getMetaFile(final Subscription sub) |
148 { | 154 { |
149 return new File(getFiltersFile(sub).getAbsolutePath() + ".meta"); | 155 return new File(getFiltersFile(sub).getAbsolutePath() + ".meta"); |
150 } | 156 } |
151 | 157 |
152 void persistSubscription(final Subscription sub) throws IOException | 158 void persistSubscription(final Subscription sub) throws IOException |
153 { | 159 { |
154 sub.serializeSubscription(this.getMetaFile(sub), this.getFiltersFile(sub)); | 160 sub.serializeSubscription(this.getMetaFile(sub), this.getFiltersFile(sub)); |
155 } | 161 } |
156 | 162 |
(...skipping 10 matching lines...) Expand all Loading... |
167 * one text file. | 173 * one text file. |
168 * | 174 * |
169 * @param output | 175 * @param output |
170 * @throws IOException | 176 * @throws IOException |
171 */ | 177 */ |
172 private void writeFile(final File output) throws IOException | 178 private void writeFile(final File output) throws IOException |
173 { | 179 { |
174 final HashSet<String> filters = new HashSet<>(); | 180 final HashSet<String> filters = new HashSet<>(); |
175 for (final Subscription s : this.subscriptions.values()) | 181 for (final Subscription s : this.subscriptions.values()) |
176 { | 182 { |
177 if (s.isEnabled()) | 183 if (s.isEnabled() && !SubscriptionUtils.isNotificationSubscription(s.getId
())) |
178 { | 184 { |
179 Log.d(TAG, "Adding filters for '" + s.getId() + "'"); | 185 Log.d(TAG, "Adding filters for '" + s.getId() + "'"); |
180 s.deserializeFilters(this.getFiltersFile(s)); | 186 s.deserializeFilters(this.getFiltersFile(s)); |
181 s.copyFilters(filters); | 187 s.copyFilters(filters); |
182 s.clearFilters(); | 188 s.clearFilters(); |
183 } | 189 } |
184 if ((!s.isMetaDataValid() || !s.isFiltersValid()) && s.getURL() != null) | 190 if ((!s.isMetaDataValid() || !s.isFiltersValid()) && s.getURL() != null) |
185 { | 191 { |
186 this.engine.enqueueDownload(s, true, false); | 192 this.engine.enqueueDownload(s, true, false); |
187 } | 193 } |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 } | 287 } |
282 } | 288 } |
283 | 289 |
284 public void updateSubscription(final String id, final int responseCode, final
String text, | 290 public void updateSubscription(final String id, final int responseCode, final
String text, |
285 final Map<String, String> httpHeaders) | 291 final Map<String, String> httpHeaders) |
286 throws IOException | 292 throws IOException |
287 { | 293 { |
288 final Subscription sub = this.subscriptions.get(id); | 294 final Subscription sub = this.subscriptions.get(id); |
289 if (sub != null) | 295 if (sub != null) |
290 { | 296 { |
291 if (sub.updateSubscription(responseCode, text, httpHeaders, this.getMetaFi
le(sub), | 297 if (SubscriptionUtils.isNotificationSubscription(id)) |
| 298 { |
| 299 sub.updateNotification(responseCode, text, getNotificationDataFile(), ge
tMetaFile(sub)); |
| 300 return; |
| 301 } |
| 302 if (sub.updateSubscription(id, responseCode, text, httpHeaders, this.getMe
taFile(sub), |
292 this.getFiltersFile(sub))) | 303 this.getFiltersFile(sub))) |
293 { | 304 { |
294 this.engine.requestUpdateBroadcast(); | 305 this.engine.requestUpdateBroadcast(); |
295 } | 306 } |
296 } | 307 } |
297 } | 308 } |
298 } | 309 } |
OLD | NEW |