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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 // read and apply current settings | 111 // read and apply current settings |
112 SharedPreferences prefs = context.getSharedPreferences(preferenceName, Conte
xt.MODE_PRIVATE); | 112 SharedPreferences prefs = context.getSharedPreferences(preferenceName, Conte
xt.MODE_PRIVATE); |
113 storage = new SharedPrefsStorage(prefs); | 113 storage = new SharedPrefsStorage(prefs); |
114 | 114 |
115 // latch is required for async (see `waitForReady()`) | 115 // latch is required for async (see `waitForReady()`) |
116 engineCreated = new CountDownLatch(1); | 116 engineCreated = new CountDownLatch(1); |
117 | 117 |
118 engine = AdblockEngine.create( | 118 engine = AdblockEngine.create( |
119 AdblockEngine.generateAppInfo(context, developmentBuild), | 119 AdblockEngine.generateAppInfo(context, developmentBuild), |
120 context.getCacheDir().getAbsolutePath(), | 120 context.getCacheDir().getAbsolutePath(), |
121 true, | 121 true, // `true` as we need element hiding |
122 isAllowedConnectionCallback, | 122 isAllowedConnectionCallback); |
123 null, | |
124 null, | |
125 null, | |
126 null); // `true` as we need element hiding | |
127 Log.d(TAG, "Adblock engine created"); | 123 Log.d(TAG, "Adblock engine created"); |
128 | 124 |
129 AdblockSettings settings = storage.load(); | 125 AdblockSettings settings = storage.load(); |
130 if (settings != null) | 126 if (settings != null) |
131 { | 127 { |
132 Log.d(TAG, "Applying saved adblock settings to adblock engine"); | 128 Log.d(TAG, "Applying saved adblock settings to adblock engine"); |
133 // apply last saved settings to adblock engine | 129 // apply last saved settings to adblock engine |
134 | 130 |
135 // all the settings except `enabled`, whitelisted domains list | 131 // all the settings except `enabled` and whitelisted domains list |
136 // and allowed connection type are saved by adblock engine itself | 132 // are saved by adblock engine itself |
137 engine.setEnabled(settings.isAdblockEnabled()); | 133 engine.setEnabled(settings.isAdblockEnabled()); |
138 engine.setWhitelistedDomains(settings.getWhitelistedDomains()); | 134 engine.setWhitelistedDomains(settings.getWhitelistedDomains()); |
139 | 135 |
| 136 // allowed connection type is saved by filter engine but we need to overri
de it |
| 137 // as filter engine can be not created when changing |
140 String connectionType = (settings.getAllowedConnectionType() != null | 138 String connectionType = (settings.getAllowedConnectionType() != null |
141 ? settings.getAllowedConnectionType().getValue() | 139 ? settings.getAllowedConnectionType().getValue() |
142 : null); | 140 : null); |
143 engine.getFilterEngine().setAllowedConnectionType(connectionType); | 141 engine.getFilterEngine().setAllowedConnectionType(connectionType); |
144 } | 142 } |
145 else | 143 else |
146 { | 144 { |
147 Log.w(TAG, "No saved adblock settings"); | 145 Log.w(TAG, "No saved adblock settings"); |
148 } | 146 } |
149 | 147 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 */ | 232 */ |
235 public synchronized void release() | 233 public synchronized void release() |
236 { | 234 { |
237 if (referenceCounter.decrementAndGet() == 0) | 235 if (referenceCounter.decrementAndGet() == 0) |
238 { | 236 { |
239 waitForReady(); | 237 waitForReady(); |
240 disposeAdblock(); | 238 disposeAdblock(); |
241 } | 239 } |
242 } | 240 } |
243 } | 241 } |
LEFT | RIGHT |