| 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 | |
| 129 engine.getFilterEngine().setAllowedConnectionType("new_type"); | |
| 130 String ct = engine.getFilterEngine().getAllowedConnectionType(); | |
| 131 | 124 |
| 132 AdblockSettings settings = storage.load(); | 125 AdblockSettings settings = storage.load(); |
| 133 if (settings != null) | 126 if (settings != null) |
| 134 { | 127 { |
| 135 Log.d(TAG, "Applying saved adblock settings to adblock engine"); | 128 Log.d(TAG, "Applying saved adblock settings to adblock engine"); |
| 136 // apply last saved settings to adblock engine | 129 // apply last saved settings to adblock engine |
| 137 | 130 |
| 138 // all the settings except `enabled`, whitelisted domains list | 131 // all the settings except `enabled` and whitelisted domains list |
| 139 // and allowed connection type are saved by adblock engine itself | 132 // are saved by adblock engine itself |
| 140 engine.setEnabled(settings.isAdblockEnabled()); | 133 engine.setEnabled(settings.isAdblockEnabled()); |
| 141 engine.setWhitelistedDomains(settings.getWhitelistedDomains()); | 134 engine.setWhitelistedDomains(settings.getWhitelistedDomains()); |
| 142 | 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 |
| 143 String connectionType = (settings.getAllowedConnectionType() != null | 138 String connectionType = (settings.getAllowedConnectionType() != null |
| 144 ? settings.getAllowedConnectionType().getValue() | 139 ? settings.getAllowedConnectionType().getValue() |
| 145 : null); | 140 : null); |
| 146 engine.getFilterEngine().setAllowedConnectionType(connectionType); | 141 engine.getFilterEngine().setAllowedConnectionType(connectionType); |
| 147 } | 142 } |
| 148 else | 143 else |
| 149 { | 144 { |
| 150 Log.w(TAG, "No saved adblock settings"); | 145 Log.w(TAG, "No saved adblock settings"); |
| 151 } | 146 } |
| 152 | 147 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 177 } | 172 } |
| 178 } | 173 } |
| 179 | 174 |
| 180 private void disposeAdblock() | 175 private void disposeAdblock() |
| 181 { | 176 { |
| 182 Log.w(TAG, "Disposing adblock engine"); | 177 Log.w(TAG, "Disposing adblock engine"); |
| 183 | 178 |
| 184 engine.dispose(); | 179 engine.dispose(); |
| 185 engine = null; | 180 engine = null; |
| 186 | 181 |
| 187 // to unlock waiting client in WaitForReady() | 182 // to unlock waiting client in waitForReady() |
| 188 engineCreated.countDown(); | 183 engineCreated.countDown(); |
| 189 engineCreated = null; | 184 engineCreated = null; |
| 190 | 185 |
| 191 storage = null; | 186 storage = null; |
| 192 | 187 |
| 193 // callbacks | 188 // callbacks |
| 194 this.isAllowedConnectionCallback.dispose(); | 189 this.isAllowedConnectionCallback.dispose(); |
| 195 this.isAllowedConnectionCallback = null; | 190 this.isAllowedConnectionCallback = null; |
| 196 } | 191 } |
| 197 | 192 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 */ | 232 */ |
| 238 public synchronized void release() | 233 public synchronized void release() |
| 239 { | 234 { |
| 240 if (referenceCounter.decrementAndGet() == 0) | 235 if (referenceCounter.decrementAndGet() == 0) |
| 241 { | 236 { |
| 242 waitForReady(); | 237 waitForReady(); |
| 243 disposeAdblock(); | 238 disposeAdblock(); |
| 244 } | 239 } |
| 245 } | 240 } |
| 246 } | 241 } |
| LEFT | RIGHT |