| 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 44 private static final String[] USER_SUBSCRIPTIONS = | 44 private static final String[] USER_SUBSCRIPTIONS = |
| 45 { Engine.USER_FILTERS_TITLE, Engine.USER_EXCEPTIONS_TITLE }; | 45 { Engine.USER_FILTERS_TITLE, Engine.USER_EXCEPTIONS_TITLE }; |
| 46 // Filters that begin with '|$' , '||$' , '@@|$' or '@@||$' | 46 // Filters that begin with '|$' , '||$' , '@@|$' or '@@||$' |
| 47 // See https://issues.adblockplus.org/ticket/4772 | 47 // See https://issues.adblockplus.org/ticket/4772 |
| 48 private static final String UNSUPPORTED_FILTERS_REGEX = "^(\\|\\$|\\|\\|\\$|@ @\\|\\$|@@\\|\\|\\$).*"; | 48 private static final String UNSUPPORTED_FILTERS_REGEX = "^(\\|\\$|\\|\\|\\$|@ @\\|\\$|@@\\|\\|\\$).*"; |
| 49 private final HashMap<String, Subscription> subscriptions = new HashMap<>(); | 49 private final HashMap<String, Subscription> subscriptions = new HashMap<>(); |
| 50 | 50 |
| 51 private final Engine engine; | 51 private final Engine engine; |
| 52 private final File subscriptionFolder; | 52 private final File subscriptionFolder; |
| 53 private final File cacheFolder; | 53 private final File cacheFolder; |
| 54 private final boolean wasUnitialized; | 54 private final boolean wasUninitialized; |
| 55 | 55 |
| 56 private Subscriptions(final Engine engine, final File appFolder, final File ca cheFolder) | 56 private Subscriptions(final Engine engine, final File appFolder, final File ca cheFolder) |
| 57 { | 57 { |
| 58 this.engine = engine; | 58 this.engine = engine; |
| 59 this.subscriptionFolder = appFolder; | 59 this.subscriptionFolder = appFolder; |
| 60 this.wasUnitialized = !this.subscriptionFolder.exists(); | 60 this.wasUninitialized = !this.subscriptionFolder.exists(); |
| 61 this.cacheFolder = cacheFolder; | 61 this.cacheFolder = cacheFolder; |
| 62 } | 62 } |
| 63 | 63 |
| 64 public boolean wasUnitialized() | 64 public boolean wasUnitialized() |
| 65 { | 65 { |
| 66 return this.wasUnitialized; | 66 return this.wasUninitialized; |
| 67 } | 67 } |
| 68 | 68 |
| 69 public File createAndWriteFile() throws IOException | 69 public File createAndWriteFile() throws IOException |
| 70 { | 70 { |
| 71 for (;;) | 71 for (;;) |
| 72 { | 72 { |
| 73 final File file = new File(this.cacheFolder, String.format(Locale.ENGLISH, "tmp-%d.txt", | 73 final File file = new File(this.cacheFolder, String.format(Locale.ENGLISH, "tmp-%d.txt", |
|
anton
2017/06/02 07:39:56
what's a purpose of setting locale explicitly?
diegocarloslima
2017/06/02 21:03:42
Mainly because it produces a Lint warning: Implici
| |
| 74 (int) (Math.random() * 1e8))); | 74 (int) (Math.random() * 1e8))); |
| 75 if (!file.exists()) | 75 if (!file.exists()) |
| 76 { | 76 { |
| 77 Log.d(TAG, "Writing filters to " + file); | 77 Log.d(TAG, "Writing filters to " + file); |
| 78 this.writeFile(file); | 78 this.writeFile(file); |
| 79 return file; | 79 return file; |
| 80 } | 80 } |
| 81 } | 81 } |
| 82 } | 82 } |
| 83 | 83 |
| 84 List<SubscriptionInfo> getSubscriptions(final Engine engine) | 84 List<SubscriptionInfo> getSubscriptions(final Engine engine) |
| 85 { | 85 { |
| 86 final ArrayList<SubscriptionInfo> subs = new ArrayList<>(); | 86 final ArrayList<SubscriptionInfo> subs = new ArrayList<>(); |
| 87 for (final Subscription sub : this.subscriptions.values()) | 87 for (final Subscription sub : this.subscriptions.values()) |
| 88 { | 88 { |
| 89 subs.add(SubscriptionInfo.create(engine, sub)); | 89 subs.add(SubscriptionInfo.create(engine, sub)); |
| 90 } | 90 } |
| 91 return subs; | 91 return subs; |
| 92 } | 92 } |
| 93 | 93 |
| 94 void getSubscriptions(final List<Subscription> list) | 94 void loadSubscriptions(final List<Subscription> list) |
| 95 { | 95 { |
| 96 list.addAll(this.subscriptions.values()); | 96 list.addAll(this.subscriptions.values()); |
| 97 } | 97 } |
| 98 | 98 |
| 99 public boolean hasSubscription(final String id) | 99 public boolean hasSubscription(final String id) |
| 100 { | 100 { |
| 101 return this.subscriptions.containsKey(id); | 101 return this.subscriptions.containsKey(id); |
| 102 } | 102 } |
| 103 | 103 |
| 104 public boolean isSubscriptionEnabled(final String id) | 104 public boolean isSubscriptionEnabled(final String id) |
| 105 { | 105 { |
| 106 final Subscription sub = this.subscriptions.get(id); | 106 final Subscription sub = this.subscriptions.get(id); |
| 107 return sub != null && sub.isEnabled(); | 107 return sub != null && sub.isEnabled(); |
| 108 } | 108 } |
| 109 | 109 |
| 110 public boolean changeSubscriptionState(final String id, final boolean enabled) throws IOException | 110 public boolean changeSubscriptionState(final String id, final boolean enabled) throws IOException |
| 111 { | 111 { |
| 112 final Subscription sub = this.subscriptions.get(id); | 112 final Subscription sub = this.subscriptions.get(id); |
| 113 if (sub != null) | 113 if (sub != null) |
| 114 { | 114 { |
| 115 if (enabled != sub.isEnabled()) | 115 if (enabled != sub.isEnabled()) |
| 116 { | 116 { |
| 117 sub.setEnabled(enabled); | 117 sub.setEnabled(enabled); |
| 118 sub.serializeMetaData(this.getMetaFile(sub)); | 118 sub.serializeMetaData(this.getMetaFile(sub)); |
| 119 if (enabled) | 119 if (enabled) |
| 120 { | 120 { |
| 121 this.engine.enqueueDownload(sub, true); | 121 this.engine.enqueueDownload(sub, true); |
| 122 } | 122 } |
| 123 | 123 |
| 124 this.engine.subscriptionStateChanged(); | |
| 124 this.engine.requestUpdateBroadcast(); | 125 this.engine.requestUpdateBroadcast(); |
| 125 return true; | 126 return true; |
| 126 } | 127 } |
| 127 } | 128 } |
| 128 return false; | 129 return false; |
| 129 } | 130 } |
| 130 | 131 |
| 131 File getFiltersFile(final Subscription sub) | 132 File getFiltersFile(final Subscription sub) |
| 132 { | 133 { |
| 133 final File filtersFile; | 134 final File filtersFile; |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 283 if (sub != null) | 284 if (sub != null) |
| 284 { | 285 { |
| 285 if (sub.updateSubscription(responseCode, text, httpHeaders, this.getMetaFi le(sub), | 286 if (sub.updateSubscription(responseCode, text, httpHeaders, this.getMetaFi le(sub), |
| 286 this.getFiltersFile(sub))) | 287 this.getFiltersFile(sub))) |
| 287 { | 288 { |
| 288 this.engine.requestUpdateBroadcast(); | 289 this.engine.requestUpdateBroadcast(); |
| 289 } | 290 } |
| 290 } | 291 } |
| 291 } | 292 } |
| 292 } | 293 } |
| LEFT | RIGHT |