Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 /* | 1 /* |
2 * This file is part of Adblock Plus <http://adblockplus.org/>, | 2 * This file is part of Adblock Plus <http://adblockplus.org/>, |
3 * Copyright (C) 2006-2014 Eyeo GmbH | 3 * Copyright (C) 2006-2014 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 24 matching lines...) Expand all Loading... | |
35 import android.content.pm.PackageManager.NameNotFoundException; | 35 import android.content.pm.PackageManager.NameNotFoundException; |
36 import android.os.Build.VERSION; | 36 import android.os.Build.VERSION; |
37 import android.util.Log; | 37 import android.util.Log; |
38 | 38 |
39 public final class ABPEngine | 39 public final class ABPEngine |
40 { | 40 { |
41 private static final String TAG = Utils.getTag(ABPEngine.class); | 41 private static final String TAG = Utils.getTag(ABPEngine.class); |
42 | 42 |
43 private final Context context; | 43 private final Context context; |
44 | 44 |
45 /* | |
46 * The fields below are volatile because: | |
47 * | |
48 * I encountered JNI related bugs/crashes caused by JNI backed Java objects. I t seemed that under | |
49 * certain conditions the objects were optimized away which resulted in crashe s when trying to | |
50 * release the object, sometimes even on access. | |
51 * | |
52 * The only solution that really worked was to declare the variables holding t he references | |
53 * volatile, this seems to prevent the JNI from 'optimizing away' those object s (as a volatile | |
54 * variable might be changed at any time from any thread). | |
55 */ | |
45 private volatile JsEngine jsEngine; | 56 private volatile JsEngine jsEngine; |
Felix Dahlke
2014/04/28 07:29:01
I know we discussed this in the last path set, but
René Jeschke
2014/04/28 08:34:32
Done.
| |
46 private volatile FilterEngine filterEngine; | 57 private volatile FilterEngine filterEngine; |
47 private volatile LogSystem logSystem; | 58 private volatile LogSystem logSystem; |
48 private volatile WebRequest webRequest; | 59 private volatile WebRequest webRequest; |
49 private volatile EventCallback updateCallback; | 60 private volatile EventCallback updateCallback; |
50 private volatile UpdaterCallback updaterCallback; | 61 private volatile UpdaterCallback updaterCallback; |
51 private volatile FilterChangeCallback filterChangeCallback; | 62 private volatile FilterChangeCallback filterChangeCallback; |
52 | 63 |
53 private ABPEngine(final Context context) | 64 private ABPEngine(final Context context) |
54 { | 65 { |
55 this.context = context; | 66 this.context = context; |
(...skipping 12 matching lines...) Expand all Loading... | |
68 Log.e(TAG, "Failed to get the application version number", e); | 79 Log.e(TAG, "Failed to get the application version number", e); |
69 } | 80 } |
70 final String sdkVersion = String.valueOf(VERSION.SDK_INT); | 81 final String sdkVersion = String.valueOf(VERSION.SDK_INT); |
71 final String locale = context.getResources().getConfiguration().locale.toStr ing(); | 82 final String locale = context.getResources().getConfiguration().locale.toStr ing(); |
72 final boolean developmentBuild = !context.getResources().getBoolean(R.bool.d ef_release); | 83 final boolean developmentBuild = !context.getResources().getBoolean(R.bool.d ef_release); |
73 | 84 |
74 return AppInfo.builder() | 85 return AppInfo.builder() |
75 .setVersion(version) | 86 .setVersion(version) |
76 .setApplicationVersion(sdkVersion) | 87 .setApplicationVersion(sdkVersion) |
77 .setLocale(locale) | 88 .setLocale(locale) |
78 .setDevelopmentBuild(developmentBuild) | 89 .setDevelopmentBuild(developmentBuild) |
Felix Dahlke
2014/04/28 07:29:01
Is this trailing whitespace? I can't really tell f
René Jeschke
2014/04/28 08:34:32
Nope, Editor->Save actions->Remove trailing whites
Felix Dahlke
2014/04/28 10:09:41
Ah, so I guess the diff is telling me that there W
René Jeschke
2014/04/28 10:18:34
Done.
| |
79 .build(); | 90 .build(); |
80 } | 91 } |
81 | 92 |
82 public static ABPEngine create(final Context context, final AppInfo appInfo, f inal String basePath) | 93 public static ABPEngine create(final Context context, final AppInfo appInfo, f inal String basePath) |
83 { | 94 { |
84 final ABPEngine engine = new ABPEngine(context); | 95 final ABPEngine engine = new ABPEngine(context); |
85 | 96 |
86 engine.jsEngine = new JsEngine(appInfo); | 97 engine.jsEngine = new JsEngine(appInfo); |
87 engine.jsEngine.setDefaultFileSystem(basePath); | 98 engine.jsEngine.setDefaultFileSystem(basePath); |
88 | 99 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
158 private static org.adblockplus.android.Subscription convertJsSubscription(fina l Subscription jsSubscription) | 169 private static org.adblockplus.android.Subscription convertJsSubscription(fina l Subscription jsSubscription) |
159 { | 170 { |
160 final org.adblockplus.android.Subscription subscription = new org.adblockplu s.android.Subscription(); | 171 final org.adblockplus.android.Subscription subscription = new org.adblockplu s.android.Subscription(); |
161 | 172 |
162 subscription.title = jsSubscription.getProperty("title").toString(); | 173 subscription.title = jsSubscription.getProperty("title").toString(); |
163 subscription.url = jsSubscription.getProperty("url").toString(); | 174 subscription.url = jsSubscription.getProperty("url").toString(); |
164 | 175 |
165 return subscription; | 176 return subscription; |
166 } | 177 } |
167 | 178 |
168 private static org.adblockplus.android.Subscription[] convertJsSubscriptions(f inal List<Subscription> subs) | 179 private static org.adblockplus.android.Subscription[] convertJsSubscriptions(f inal List<Subscription> jsSubscriptions) |
Felix Dahlke
2014/04/28 07:29:01
How about renaming "subs" to "jsSubscription" and
René Jeschke
2014/04/28 08:34:32
Done.
| |
169 { | 180 { |
170 final org.adblockplus.android.Subscription[] ret = new org.adblockplus.andro id.Subscription[subs.size()]; | 181 final org.adblockplus.android.Subscription[] subscriptions = new org.adblock plus.android.Subscription[jsSubscriptions.size()]; |
171 | 182 |
172 for (int i = 0; i < ret.length; i++) | 183 for (int i = 0; i < subscriptions.length; i++) |
173 { | 184 { |
174 ret[i] = convertJsSubscription(subs.get(i)); | 185 subscriptions[i] = convertJsSubscription(jsSubscriptions.get(i)); |
175 } | 186 } |
176 | 187 |
177 return ret; | 188 return subscriptions; |
178 } | 189 } |
179 | 190 |
180 public org.adblockplus.android.Subscription[] getRecommendedSubscriptions() | 191 public org.adblockplus.android.Subscription[] getRecommendedSubscriptions() |
181 { | 192 { |
182 return convertJsSubscriptions(this.filterEngine.fetchAvailableSubscriptions( )); | 193 return convertJsSubscriptions(this.filterEngine.fetchAvailableSubscriptions( )); |
183 } | 194 } |
184 | 195 |
185 public org.adblockplus.android.Subscription[] getListedSubscriptions() | 196 public org.adblockplus.android.Subscription[] getListedSubscriptions() |
186 { | 197 { |
187 return convertJsSubscriptions(this.filterEngine.getListedSubscriptions()); | 198 return convertJsSubscriptions(this.filterEngine.getListedSubscriptions()); |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
261 | 272 |
262 public void updateSubscriptionStatus(final String url) | 273 public void updateSubscriptionStatus(final String url) |
263 { | 274 { |
264 final Subscription sub = this.filterEngine.getSubscription(url); | 275 final Subscription sub = this.filterEngine.getSubscription(url); |
265 if (sub != null) | 276 if (sub != null) |
266 { | 277 { |
267 Utils.updateSubscriptionStatus(this.context, sub); | 278 Utils.updateSubscriptionStatus(this.context, sub); |
268 } | 279 } |
269 } | 280 } |
270 } | 281 } |
LEFT | RIGHT |