Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: libadblockplus-android-settings/src/org/adblockplus/libadblockplus/android/settings/AdblockHelper.java

Issue 29399749: Issue 5081 - Make libadblockplus-android users supply the application and applicationVersion parame… (Closed)
Patch Set: application/-Version are required now Created March 31, 2017, 3:09 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | libadblockplus-android-webviewapp/src/org/adblockplus/libadblockplus/android/webviewapp/Application.java » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 package org.adblockplus.libadblockplus.android.settings; 18 package org.adblockplus.libadblockplus.android.settings;
19 19
20 import android.content.Context; 20 import android.content.Context;
21 import android.content.SharedPreferences; 21 import android.content.SharedPreferences;
22 import android.util.Log; 22 import android.util.Log;
23 23
24 import org.adblockplus.libadblockplus.IsAllowedConnectionCallback; 24 import org.adblockplus.libadblockplus.IsAllowedConnectionCallback;
25 import org.adblockplus.libadblockplus.UpdateCheckDoneCallback;
26 import org.adblockplus.libadblockplus.android.AdblockEngine; 25 import org.adblockplus.libadblockplus.android.AdblockEngine;
27 import org.adblockplus.libadblockplus.android.AndroidWebRequestResourceWrapper; 26 import org.adblockplus.libadblockplus.android.AndroidWebRequestResourceWrapper;
28 import org.adblockplus.libadblockplus.android.Utils; 27 import org.adblockplus.libadblockplus.android.Utils;
29 28
30 import java.io.File;
31 import java.util.Map; 29 import java.util.Map;
32 import java.util.concurrent.CountDownLatch; 30 import java.util.concurrent.CountDownLatch;
33 import java.util.concurrent.atomic.AtomicInteger; 31 import java.util.concurrent.atomic.AtomicInteger;
34 32
35 /** 33 /**
36 * AdblockHelper shared resources 34 * AdblockHelper shared resources
37 * (singleton) 35 * (singleton)
38 */ 36 */
39 public class AdblockHelper 37 public class AdblockHelper
40 { 38 {
41 private static final String TAG = Utils.getTag(AdblockHelper.class); 39 private static final String TAG = Utils.getTag(AdblockHelper.class);
42 40
43 /** 41 /**
44 * Suggested preference name to store settings 42 * Suggested preference name to store settings
45 */ 43 */
46 public static final String PREFERENCE_NAME = "ADBLOCK"; 44 public static final String PREFERENCE_NAME = "ADBLOCK";
47 45
48 /** 46 /**
49 * Suggested preference name to store intercepted subscription requests 47 * Suggested preference name to store intercepted subscription requests
50 */ 48 */
51 public static final String PRELOAD_PREFERENCE_NAME = "ADBLOCK_PRELOAD"; 49 public static final String PRELOAD_PREFERENCE_NAME = "ADBLOCK_PRELOAD";
52 private static AdblockHelper _instance; 50 private static AdblockHelper _instance;
53 51
54 private Context context; 52 private Context context;
55 private String basePath; 53 private String basePath;
56 private boolean developmentBuild; 54 private boolean developmentBuild;
57 private String settingsPreferenceName; 55 private String settingsPreferenceName;
58 private String preloadedPreferenceName; 56 private String preloadedPreferenceName;
59 private Map<String, Integer> urlToResourceIdMap; 57 private Map<String, Integer> urlToResourceIdMap;
58 private String application;
59 private String applicationVersion;
60 private AdblockEngine engine; 60 private AdblockEngine engine;
61 private AdblockSettingsStorage storage; 61 private AdblockSettingsStorage storage;
62 private CountDownLatch engineCreated; 62 private CountDownLatch engineCreated;
63 63
64 private IsAllowedConnectionCallback isAllowedConnectionCallback; 64 private IsAllowedConnectionCallback isAllowedConnectionCallback;
65 65
66 /* 66 /*
67 Simple ARC management for AdblockEngine 67 Simple ARC management for AdblockEngine
68 Use `retain` and `release` 68 Use `retain` and `release`
69 */ 69 */
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 * Init with context 104 * Init with context
105 * @param context application context 105 * @param context application context
106 * @param basePath file system root to store files 106 * @param basePath file system root to store files
107 * 107 *
108 * Adblock Plus library will download subscription files and s tore them on 108 * Adblock Plus library will download subscription files and s tore them on
109 * the path passed. The path should exist and the directory co ntent should not be 109 * the path passed. The path should exist and the directory co ntent should not be
110 * cleared out occasionally. Using `context.getCacheDir().getA bsolutePath()` is not 110 * cleared out occasionally. Using `context.getCacheDir().getA bsolutePath()` is not
111 * recommended because it can be cleared by the system. 111 * recommended because it can be cleared by the system.
112 * @param developmentBuild debug or release? 112 * @param developmentBuild debug or release?
113 * @param preferenceName Shared Preferences name to store adblock settings 113 * @param preferenceName Shared Preferences name to store adblock settings
114 * @param application Technical name of the platform the app is running on (no t user visible).
115 * @param applicationVersion Current version of the platform the app is runnin g on.
114 */ 116 */
115 public AdblockHelper init(Context context, String basePath, boolean developmen tBuild, String preferenceName) 117 public AdblockHelper init(Context context, String basePath,
118 boolean developmentBuild, String preferenceName,
119 String application, String applicationVersion)
116 { 120 {
117 this.context = context.getApplicationContext(); 121 this.context = context.getApplicationContext();
118 this.basePath = basePath; 122 this.basePath = basePath;
119 this.developmentBuild = developmentBuild; 123 this.developmentBuild = developmentBuild;
120 this.settingsPreferenceName = preferenceName; 124 this.settingsPreferenceName = preferenceName;
125 this.application = application;
126 this.applicationVersion = applicationVersion;
121 return this; 127 return this;
122 } 128 }
123 129
124 /** 130 /**
125 * Use preloaded subscriptions 131 * Use preloaded subscriptions
126 * @param preferenceName Shared Preferences name to store intercepted requests stats 132 * @param preferenceName Shared Preferences name to store intercepted requests stats
127 * @param urlToResourceIdMap 133 * @param urlToResourceIdMap
128 */ 134 */
129 public void preloadSubscriptions(String preferenceName, Map<String, Integer> u rlToResourceIdMap) 135 public AdblockHelper preloadSubscriptions(String preferenceName, Map<String, I nteger> urlToResourceIdMap)
130 { 136 {
131 this.preloadedPreferenceName = preferenceName; 137 this.preloadedPreferenceName = preferenceName;
132 this.urlToResourceIdMap = urlToResourceIdMap; 138 this.urlToResourceIdMap = urlToResourceIdMap;
139 return this;
133 } 140 }
134 141
135 private void createAdblock() 142 private void createAdblock()
136 { 143 {
137 this.isAllowedConnectionCallback = new IsAllowedConnectionCallbackImpl(conte xt); 144 this.isAllowedConnectionCallback = new IsAllowedConnectionCallbackImpl(conte xt);
138 145
139 Log.d(TAG, "Creating adblock engine ..."); 146 Log.d(TAG, "Creating adblock engine ...");
140 147
141 // read and apply current settings 148 // read and apply current settings
142 SharedPreferences settingsPrefs = context.getSharedPreferences( 149 SharedPreferences settingsPrefs = context.getSharedPreferences(
143 settingsPreferenceName, 150 settingsPreferenceName,
144 Context.MODE_PRIVATE); 151 Context.MODE_PRIVATE);
145 storage = new SharedPrefsStorage(settingsPrefs); 152 storage = new SharedPrefsStorage(settingsPrefs);
146 153
147 AdblockEngine.Builder builder = AdblockEngine 154 AdblockEngine.Builder builder = AdblockEngine
148 .builder( 155 .builder(
149 AdblockEngine.generateAppInfo(context, developmentBuild), 156 AdblockEngine.generateAppInfo(context, developmentBuild, application, ap plicationVersion),
150 basePath) 157 basePath)
151 .setIsAllowedConnectionCallback(isAllowedConnectionCallback) 158 .setIsAllowedConnectionCallback(isAllowedConnectionCallback)
152 .enableElementHiding(true); 159 .enableElementHiding(true);
153 160
154 // if preloaded subscriptions provided 161 // if preloaded subscriptions provided
155 if (preloadedPreferenceName != null) 162 if (preloadedPreferenceName != null)
156 { 163 {
157 SharedPreferences preloadedSubscriptionsPrefs = context.getSharedPreferenc es( 164 SharedPreferences preloadedSubscriptionsPrefs = context.getSharedPreferenc es(
158 preloadedPreferenceName, 165 preloadedPreferenceName,
159 Context.MODE_PRIVATE); 166 Context.MODE_PRIVATE);
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 engineCreated.countDown(); 295 engineCreated.countDown();
289 engineCreated = null; 296 engineCreated = null;
290 } 297 }
291 else 298 else
292 { 299 {
293 disposeAdblock(); 300 disposeAdblock();
294 } 301 }
295 } 302 }
296 } 303 }
297 } 304 }
OLDNEW
« no previous file with comments | « no previous file | libadblockplus-android-webviewapp/src/org/adblockplus/libadblockplus/android/webviewapp/Application.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld