Left: | ||
Right: |
LEFT | RIGHT |
---|---|
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-2016 Eyeo GmbH | 3 * Copyright (C) 2006-2016 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 23 matching lines...) Expand all Loading... | |
34 | 34 |
35 /** | 35 /** |
36 * This class holds all listed subscriptions and manages the subscription | 36 * This class holds all listed subscriptions and manages the subscription |
37 * aggregation cache folder. | 37 * aggregation cache folder. |
38 */ | 38 */ |
39 final class Subscriptions | 39 final class Subscriptions |
40 { | 40 { |
41 private static final String TAG = Subscriptions.class.getSimpleName(); | 41 private static final String TAG = Subscriptions.class.getSimpleName(); |
42 private static final String[] USER_SUBSCRIPTIONS = | 42 private static final String[] USER_SUBSCRIPTIONS = |
43 { Engine.USER_FILTERS_TITLE, Engine.USER_EXCEPTIONS_TITLE }; | 43 { Engine.USER_FILTERS_TITLE, Engine.USER_EXCEPTIONS_TITLE }; |
44 // Filters that begin with '|$' , '||$' , '@@|$' or '@@||$' | 44 // Filters that begin with '|$' , '||$' , '@@|$' or '@@||$' need to be removed |
Felix Dahlke
2017/02/07 15:34:15
Nit: Maybe reference the issue? e.g.:
// Filters
| |
45 // See https://issues.adblockplus.org/ticket/4772 | |
45 private static final String UNSUPPORTED_FILTERS_REGEX = "^(\\|\\$|\\|\\|\\$|@ @\\|\\$|@@\\|\\|\\$).*"; | 46 private static final String UNSUPPORTED_FILTERS_REGEX = "^(\\|\\$|\\|\\|\\$|@ @\\|\\$|@@\\|\\|\\$).*"; |
46 private final HashMap<String, Subscription> subscriptions = new HashMap<String , Subscription>(); | 47 private final HashMap<String, Subscription> subscriptions = new HashMap<String , Subscription>(); |
47 | 48 |
48 private final Engine engine; | 49 private final Engine engine; |
49 private final File subscriptionFolder; | 50 private final File subscriptionFolder; |
50 private final File cacheFolder; | 51 private final File cacheFolder; |
51 private final boolean wasUnitialized; | 52 private final boolean wasUnitialized; |
52 | 53 |
53 private Subscriptions(final Engine engine, final File appFolder, final File ca cheFolder) | 54 private Subscriptions(final Engine engine, final File appFolder, final File ca cheFolder) |
54 { | 55 { |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
183 final BufferedWriter w = new BufferedWriter( | 184 final BufferedWriter w = new BufferedWriter( |
184 new OutputStreamWriter(new FileOutputStream(output), "UTF-8")); | 185 new OutputStreamWriter(new FileOutputStream(output), "UTF-8")); |
185 try | 186 try |
186 { | 187 { |
187 Log.d(TAG, "Writing " + filters.size() + " filters"); | 188 Log.d(TAG, "Writing " + filters.size() + " filters"); |
188 Engine.writeFilterHeaders(w); | 189 Engine.writeFilterHeaders(w); |
189 for (final String filter : filters) | 190 for (final String filter : filters) |
190 { | 191 { |
191 // This is a temporary fix to not write filters that might crash Samsung Internet | 192 // This is a temporary fix to not write filters that might crash Samsung Internet |
192 // See https://issues.adblockplus.org/ticket/4772 | 193 // See https://issues.adblockplus.org/ticket/4772 |
193 if (isFilterSupported(filter)) | 194 if (!filter.matches(UNSUPPORTED_FILTERS_REGEX)) |
194 { | 195 { |
195 w.write(filter); | 196 w.write(filter); |
196 w.write('\n'); | 197 w.write('\n'); |
197 } | 198 } |
198 else | 199 else |
199 { | 200 { |
200 Log.d(TAG, "Ignoring unsupported filter: " + filter); | 201 Log.d(TAG, "Ignoring unsupported filter: " + filter); |
201 } | 202 } |
202 } | 203 } |
203 } | 204 } |
204 finally | 205 finally |
205 { | 206 { |
206 w.close(); | 207 w.close(); |
207 } | 208 } |
208 } | |
209 | |
210 private static boolean isFilterSupported(String filter) | |
211 { | |
212 if (filter.matches(UNSUPPORTED_FILTERS_REGEX)) | |
Felix Dahlke
2017/02/07 15:34:15
Seems we can simplify the function to:
return !fi
| |
213 { | |
214 return false; | |
215 } | |
216 return true; | |
217 } | 209 } |
218 | 210 |
219 public Subscription add(final Subscription sub) | 211 public Subscription add(final Subscription sub) |
220 { | 212 { |
221 final String id = sub.getId(); | 213 final String id = sub.getId(); |
222 if (!this.subscriptions.containsKey(id)) | 214 if (!this.subscriptions.containsKey(id)) |
223 { | 215 { |
224 this.subscriptions.put(id, sub); | 216 this.subscriptions.put(id, sub); |
225 return sub; | 217 return sub; |
226 } | 218 } |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
289 if (sub != null) | 281 if (sub != null) |
290 { | 282 { |
291 if (sub.updateSubscription(responseCode, text, httpHeaders, this.getMetaFi le(sub), | 283 if (sub.updateSubscription(responseCode, text, httpHeaders, this.getMetaFi le(sub), |
292 this.getFiltersFile(sub))) | 284 this.getFiltersFile(sub))) |
293 { | 285 { |
294 this.engine.requestUpdateBroadcast(); | 286 this.engine.requestUpdateBroadcast(); |
295 } | 287 } |
296 } | 288 } |
297 } | 289 } |
298 } | 290 } |
LEFT | RIGHT |