| 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-2017 eyeo GmbH | 3 * Copyright (C) 2006-2017 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 */ | 49 */ |
| 50 public static final String PRELOAD_PREFERENCE_NAME = "ADBLOCK_PRELOAD"; | 50 public static final String PRELOAD_PREFERENCE_NAME = "ADBLOCK_PRELOAD"; |
| 51 private static AdblockHelper _instance; | 51 private static AdblockHelper _instance; |
| 52 | 52 |
| 53 private Context context; | 53 private Context context; |
| 54 private String basePath; | 54 private String basePath; |
| 55 private boolean developmentBuild; | 55 private boolean developmentBuild; |
| 56 private String settingsPreferenceName; | 56 private String settingsPreferenceName; |
| 57 private String preloadedPreferenceName; | 57 private String preloadedPreferenceName; |
| 58 private Map<String, Integer> urlToResourceIdMap; | 58 private Map<String, Integer> urlToResourceIdMap; |
| 59 private String application; | |
| 60 private String applicationVersion; | |
| 61 private AdblockEngine engine; | 59 private AdblockEngine engine; |
| 62 private AdblockSettingsStorage storage; | 60 private AdblockSettingsStorage storage; |
| 63 private CountDownLatch engineCreated; | 61 private CountDownLatch engineCreated; |
| 64 | 62 |
| 65 private IsAllowedConnectionCallback isAllowedConnectionCallback; | 63 private IsAllowedConnectionCallback isAllowedConnectionCallback; |
| 66 | 64 |
| 67 /* | 65 /* |
| 68 Simple ARC management for AdblockEngine | 66 Simple ARC management for AdblockEngine |
| 69 Use `retain` and `release` | 67 Use `retain` and `release` |
| 70 */ | 68 */ |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 * Init with context | 103 * Init with context |
| 106 * @param context application context | 104 * @param context application context |
| 107 * @param basePath file system root to store files | 105 * @param basePath file system root to store files |
| 108 * | 106 * |
| 109 * Adblock Plus library will download subscription files and s
tore them on | 107 * Adblock Plus library will download subscription files and s
tore them on |
| 110 * the path passed. The path should exist and the directory co
ntent should not be | 108 * the path passed. The path should exist and the directory co
ntent should not be |
| 111 * cleared out occasionally. Using `context.getCacheDir().getA
bsolutePath()` is not | 109 * cleared out occasionally. Using `context.getCacheDir().getA
bsolutePath()` is not |
| 112 * recommended because it can be cleared by the system. | 110 * recommended because it can be cleared by the system. |
| 113 * @param developmentBuild debug or release? | 111 * @param developmentBuild debug or release? |
| 114 * @param preferenceName Shared Preferences name to store adblock settings | 112 * @param preferenceName Shared Preferences name to store adblock settings |
| 115 * @param application Technical name of the platform the app is running on (no
t user visible). | |
| 116 * @param applicationVersion Current version of the platform the app is runnin
g on. | |
| 117 */ | 113 */ |
| 118 public AdblockHelper init(Context context, String basePath, | 114 public AdblockHelper init(Context context, String basePath, |
| 119 boolean developmentBuild, String preferenceName, | 115 boolean developmentBuild, String preferenceName) |
| 120 String application, String applicationVersion) | |
| 121 { | 116 { |
| 122 this.context = context.getApplicationContext(); | 117 this.context = context.getApplicationContext(); |
| 123 this.basePath = basePath; | 118 this.basePath = basePath; |
| 124 this.developmentBuild = developmentBuild; | 119 this.developmentBuild = developmentBuild; |
| 125 this.settingsPreferenceName = preferenceName; | 120 this.settingsPreferenceName = preferenceName; |
| 126 this.application = application; | |
| 127 this.applicationVersion = applicationVersion; | |
| 128 return this; | 121 return this; |
| 129 } | 122 } |
| 130 | 123 |
| 131 /** | 124 /** |
| 132 * Use preloaded subscriptions | 125 * Use preloaded subscriptions |
| 133 * @param preferenceName Shared Preferences name to store intercepted requests
stats | 126 * @param preferenceName Shared Preferences name to store intercepted requests
stats |
| 134 * @param urlToResourceIdMap | 127 * @param urlToResourceIdMap |
| 135 */ | 128 */ |
| 136 public AdblockHelper preloadSubscriptions(String preferenceName, Map<String, I
nteger> urlToResourceIdMap) | 129 public AdblockHelper preloadSubscriptions(String preferenceName, Map<String, I
nteger> urlToResourceIdMap) |
| 137 { | 130 { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 149 Log.d(TAG, "Creating adblock engine ..."); | 142 Log.d(TAG, "Creating adblock engine ..."); |
| 150 | 143 |
| 151 // read and apply current settings | 144 // read and apply current settings |
| 152 SharedPreferences settingsPrefs = context.getSharedPreferences( | 145 SharedPreferences settingsPrefs = context.getSharedPreferences( |
| 153 settingsPreferenceName, | 146 settingsPreferenceName, |
| 154 Context.MODE_PRIVATE); | 147 Context.MODE_PRIVATE); |
| 155 storage = new SharedPrefsStorage(settingsPrefs); | 148 storage = new SharedPrefsStorage(settingsPrefs); |
| 156 | 149 |
| 157 AdblockEngine.Builder builder = AdblockEngine | 150 AdblockEngine.Builder builder = AdblockEngine |
| 158 .builder( | 151 .builder( |
| 159 AdblockEngine.generateAppInfo(context, developmentBuild, application, ap
plicationVersion), | 152 AdblockEngine.generateAppInfo(context, developmentBuild), |
| 160 basePath) | 153 basePath) |
| 161 .setIsAllowedConnectionCallback(isAllowedConnectionCallback) | 154 .setIsAllowedConnectionCallback(isAllowedConnectionCallback) |
| 162 .enableElementHiding(true); | 155 .enableElementHiding(true); |
| 163 | 156 |
| 164 // if preloaded subscriptions provided | 157 // if preloaded subscriptions provided |
| 165 if (preloadedPreferenceName != null) | 158 if (preloadedPreferenceName != null) |
| 166 { | 159 { |
| 167 SharedPreferences preloadedSubscriptionsPrefs = context.getSharedPreferenc
es( | 160 SharedPreferences preloadedSubscriptionsPrefs = context.getSharedPreferenc
es( |
| 168 preloadedPreferenceName, | 161 preloadedPreferenceName, |
| 169 Context.MODE_PRIVATE); | 162 Context.MODE_PRIVATE); |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 engineCreated.countDown(); | 291 engineCreated.countDown(); |
| 299 engineCreated = null; | 292 engineCreated = null; |
| 300 } | 293 } |
| 301 else | 294 else |
| 302 { | 295 { |
| 303 disposeAdblock(); | 296 disposeAdblock(); |
| 304 } | 297 } |
| 305 } | 298 } |
| 306 } | 299 } |
| 307 } | 300 } |
| OLD | NEW |