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: Created March 31, 2017, 1:28 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
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;
anton 2017/03/31 13:34:21 not related to the task directly
diegocarloslima 2017/03/31 14:07:14 I would prefer this to be in a separate task, but
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;
anton 2017/03/31 13:34:21 not related to the task directly - just cleanup
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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 this.developmentBuild = developmentBuild; 119 this.developmentBuild = developmentBuild;
120 this.settingsPreferenceName = preferenceName; 120 this.settingsPreferenceName = preferenceName;
121 return this; 121 return this;
122 } 122 }
123 123
124 /** 124 /**
125 * Use preloaded subscriptions 125 * Use preloaded subscriptions
126 * @param preferenceName Shared Preferences name to store intercepted requests stats 126 * @param preferenceName Shared Preferences name to store intercepted requests stats
127 * @param urlToResourceIdMap 127 * @param urlToResourceIdMap
128 */ 128 */
129 public void preloadSubscriptions(String preferenceName, Map<String, Integer> u rlToResourceIdMap) 129 public AdblockHelper preloadSubscriptions(String preferenceName, Map<String, I nteger> urlToResourceIdMap)
130 { 130 {
131 this.preloadedPreferenceName = preferenceName; 131 this.preloadedPreferenceName = preferenceName;
132 this.urlToResourceIdMap = urlToResourceIdMap; 132 this.urlToResourceIdMap = urlToResourceIdMap;
133 return this;
134 }
135
136 /**
137 * Use for requests to identify the client
138 * @param application application
139 */
140 public AdblockHelper setApplication(String application)
141 {
142 this.application = application;
143 return this;
144 }
145
146 /**
147 * Use for requests to identify the client
148 * @param applicationVersion application
149 */
150 public AdblockHelper setApplicationVersion(String applicationVersion)
151 {
152 this.applicationVersion = applicationVersion;
153 return this;
diegocarloslima 2017/03/31 14:07:14 By the ticket description, it seems that applicati
anton 2017/03/31 14:16:08 if they are required then i agree. it's not clear
133 } 154 }
134 155
135 private void createAdblock() 156 private void createAdblock()
136 { 157 {
137 this.isAllowedConnectionCallback = new IsAllowedConnectionCallbackImpl(conte xt); 158 this.isAllowedConnectionCallback = new IsAllowedConnectionCallbackImpl(conte xt);
138 159
139 Log.d(TAG, "Creating adblock engine ..."); 160 Log.d(TAG, "Creating adblock engine ...");
140 161
141 // read and apply current settings 162 // read and apply current settings
142 SharedPreferences settingsPrefs = context.getSharedPreferences( 163 SharedPreferences settingsPrefs = context.getSharedPreferences(
143 settingsPreferenceName, 164 settingsPreferenceName,
144 Context.MODE_PRIVATE); 165 Context.MODE_PRIVATE);
145 storage = new SharedPrefsStorage(settingsPrefs); 166 storage = new SharedPrefsStorage(settingsPrefs);
146 167
147 AdblockEngine.Builder builder = AdblockEngine 168 AdblockEngine.Builder builder = AdblockEngine
148 .builder( 169 .builder(
149 AdblockEngine.generateAppInfo(context, developmentBuild), 170 AdblockEngine.generateAppInfo(context, developmentBuild, application, ap plicationVersion),
150 basePath) 171 basePath)
151 .setIsAllowedConnectionCallback(isAllowedConnectionCallback) 172 .setIsAllowedConnectionCallback(isAllowedConnectionCallback)
152 .enableElementHiding(true); 173 .enableElementHiding(true);
153 174
154 // if preloaded subscriptions provided 175 // if preloaded subscriptions provided
155 if (preloadedPreferenceName != null) 176 if (preloadedPreferenceName != null)
156 { 177 {
157 SharedPreferences preloadedSubscriptionsPrefs = context.getSharedPreferenc es( 178 SharedPreferences preloadedSubscriptionsPrefs = context.getSharedPreferenc es(
158 preloadedPreferenceName, 179 preloadedPreferenceName,
159 Context.MODE_PRIVATE); 180 Context.MODE_PRIVATE);
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 engineCreated.countDown(); 309 engineCreated.countDown();
289 engineCreated = null; 310 engineCreated = null;
290 } 311 }
291 else 312 else
292 { 313 {
293 disposeAdblock(); 314 disposeAdblock();
294 } 315 }
295 } 316 }
296 } 317 }
297 } 318 }
OLDNEW

Powered by Google App Engine
This is Rietveld