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

Side by Side Diff: src/org/adblockplus/android/ABPEngine.java

Issue 5153282527854592: Issue 98 - Use the libadblockplus update mechanism (Closed)
Patch Set: Only append the revision to the version for devbuilds Created Sept. 26, 2014, 2:54 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 | « res/values/strings.xml ('k') | src/org/adblockplus/android/AdblockPlus.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 <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
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.android; 18 package org.adblockplus.android;
19 19
20 import java.util.List; 20 import java.util.List;
21 import java.util.Locale; 21 import java.util.Locale;
22 22
23 import org.adblockplus.libadblockplus.AppInfo; 23 import org.adblockplus.libadblockplus.AppInfo;
24 import org.adblockplus.libadblockplus.EventCallback;
25 import org.adblockplus.libadblockplus.Filter; 24 import org.adblockplus.libadblockplus.Filter;
26 import org.adblockplus.libadblockplus.FilterChangeCallback; 25 import org.adblockplus.libadblockplus.FilterChangeCallback;
27 import org.adblockplus.libadblockplus.FilterEngine; 26 import org.adblockplus.libadblockplus.FilterEngine;
28 import org.adblockplus.libadblockplus.FilterEngine.ContentType; 27 import org.adblockplus.libadblockplus.FilterEngine.ContentType;
29 import org.adblockplus.libadblockplus.JsEngine; 28 import org.adblockplus.libadblockplus.JsEngine;
30 import org.adblockplus.libadblockplus.LogSystem; 29 import org.adblockplus.libadblockplus.LogSystem;
31 import org.adblockplus.libadblockplus.Subscription; 30 import org.adblockplus.libadblockplus.Subscription;
31 import org.adblockplus.libadblockplus.UpdateAvailableCallback;
32 import org.adblockplus.libadblockplus.UpdateCheckDoneCallback; 32 import org.adblockplus.libadblockplus.UpdateCheckDoneCallback;
33 import org.adblockplus.libadblockplus.WebRequest; 33 import org.adblockplus.libadblockplus.WebRequest;
34 34
35 import android.content.Context; 35 import android.content.Context;
36 import android.content.pm.PackageInfo; 36 import android.content.pm.PackageInfo;
37 import android.content.pm.PackageManager.NameNotFoundException; 37 import android.content.pm.PackageManager.NameNotFoundException;
38 import android.os.Build.VERSION; 38 import android.os.Build.VERSION;
39 import android.util.Log; 39 import android.util.Log;
40 40
41 public final class ABPEngine 41 public final class ABPEngine
(...skipping 10 matching lines...) Expand all
52 * release the object, sometimes even on access. 52 * release the object, sometimes even on access.
53 * 53 *
54 * The only solution that really worked was to declare the variables holding t he references 54 * The only solution that really worked was to declare the variables holding t he references
55 * volatile, this seems to prevent the JNI from 'optimizing away' those object s (as a volatile 55 * volatile, this seems to prevent the JNI from 'optimizing away' those object s (as a volatile
56 * variable might be changed at any time from any thread). 56 * variable might be changed at any time from any thread).
57 */ 57 */
58 private volatile JsEngine jsEngine; 58 private volatile JsEngine jsEngine;
59 private volatile FilterEngine filterEngine; 59 private volatile FilterEngine filterEngine;
60 private volatile LogSystem logSystem; 60 private volatile LogSystem logSystem;
61 private volatile WebRequest webRequest; 61 private volatile WebRequest webRequest;
62 private volatile EventCallback updateCallback; 62 private volatile UpdateAvailableCallback updateAvailableCallback;
63 private volatile UpdateCheckDoneCallback updateCheckDoneCallback; 63 private volatile UpdateCheckDoneCallback updateCheckDoneCallback;
64 private volatile FilterChangeCallback filterChangeCallback; 64 private volatile FilterChangeCallback filterChangeCallback;
65 65
66 private ABPEngine(final Context context) 66 private ABPEngine(final Context context)
67 { 67 {
68 this.context = context; 68 this.context = context;
69 } 69 }
70 70
71 public static AppInfo generateAppInfo(final Context context) 71 public static AppInfo generateAppInfo(final Context context)
72 { 72 {
73 final boolean developmentBuild = !context.getResources().getBoolean(R.bool.d ef_release);
73 String version = "0"; 74 String version = "0";
74 try 75 try
75 { 76 {
76 final PackageInfo info = context.getPackageManager().getPackageInfo(contex t.getPackageName(), 0); 77 final PackageInfo info = context.getPackageManager().getPackageInfo(contex t.getPackageName(), 0);
77 version = info.versionName + "." + info.versionCode; 78 version = info.versionName;
79 if (developmentBuild)
80 version += "." + info.versionCode;
78 } 81 }
79 catch (final NameNotFoundException e) 82 catch (final NameNotFoundException e)
80 { 83 {
81 Log.e(TAG, "Failed to get the application version number", e); 84 Log.e(TAG, "Failed to get the application version number", e);
82 } 85 }
83 final String sdkVersion = String.valueOf(VERSION.SDK_INT); 86 final String sdkVersion = String.valueOf(VERSION.SDK_INT);
84 final String locale = Locale.getDefault().toString().replace('_', '-'); 87 final String locale = Locale.getDefault().toString().replace('_', '-');
85 final boolean developmentBuild = !context.getResources().getBoolean(R.bool.d ef_release);
86 88
87 return AppInfo.builder() 89 return AppInfo.builder()
88 .setVersion(version) 90 .setVersion(version)
89 .setApplicationVersion(sdkVersion) 91 .setApplicationVersion(sdkVersion)
90 .setLocale(locale) 92 .setLocale(locale)
91 .setDevelopmentBuild(developmentBuild) 93 .setDevelopmentBuild(developmentBuild)
92 .build(); 94 .build();
93 } 95 }
94 96
95 public static ABPEngine create(final Context context, final AppInfo appInfo, f inal String basePath) 97 public static ABPEngine create(final Context context, final AppInfo appInfo, f inal String basePath)
96 { 98 {
97 final ABPEngine engine = new ABPEngine(context); 99 final ABPEngine engine = new ABPEngine(context);
98 100
99 engine.jsEngine = new JsEngine(appInfo); 101 engine.jsEngine = new JsEngine(appInfo);
100 engine.jsEngine.setDefaultFileSystem(basePath); 102 engine.jsEngine.setDefaultFileSystem(basePath);
101 103
102 engine.logSystem = new AndroidLogSystem(); 104 engine.logSystem = new AndroidLogSystem();
103 engine.jsEngine.setLogSystem(engine.logSystem); 105 engine.jsEngine.setLogSystem(engine.logSystem);
104 106
105 engine.webRequest = new AndroidWebRequest(); 107 engine.webRequest = new AndroidWebRequest();
106 engine.jsEngine.setWebRequest(engine.webRequest); 108 engine.jsEngine.setWebRequest(engine.webRequest);
107 109
108 engine.updateCallback = new AndroidUpdateAvailableCallback(context);
109 engine.jsEngine.setEventCallback("updateAvailable", engine.updateCallback);
110
111 engine.filterEngine = new FilterEngine(engine.jsEngine); 110 engine.filterEngine = new FilterEngine(engine.jsEngine);
111 engine.updateAvailableCallback = new AndroidUpdateAvailableCallback(context) ;
112 engine.filterEngine.setUpdateAvailableCallback(engine.updateAvailableCallbac k);
112 engine.filterChangeCallback = new AndroidFilterChangeCallback(context); 113 engine.filterChangeCallback = new AndroidFilterChangeCallback(context);
113 engine.filterEngine.setFilterChangeCallback(engine.filterChangeCallback); 114 engine.filterEngine.setFilterChangeCallback(engine.filterChangeCallback);
114 115
115 engine.updateCheckDoneCallback = new AndroidUpdateCheckDoneCallback(context) ; 116 engine.updateCheckDoneCallback = new AndroidUpdateCheckDoneCallback(context) ;
116 117
117 return engine; 118 return engine;
118 } 119 }
119 120
120 public void dispose() 121 public void dispose()
121 { 122 {
(...skipping 15 matching lines...) Expand all
137 this.logSystem.dispose(); 138 this.logSystem.dispose();
138 this.logSystem = null; 139 this.logSystem = null;
139 } 140 }
140 141
141 if (this.webRequest != null) 142 if (this.webRequest != null)
142 { 143 {
143 this.webRequest.dispose(); 144 this.webRequest.dispose();
144 this.webRequest = null; 145 this.webRequest = null;
145 } 146 }
146 147
147 if (this.updateCallback != null) 148 if (this.updateAvailableCallback != null)
148 { 149 {
149 this.updateCallback.dispose(); 150 this.updateAvailableCallback.dispose();
150 this.updateCallback = null; 151 this.updateAvailableCallback = null;
151 } 152 }
152 153
153 if (this.updateCheckDoneCallback != null) 154 if (this.updateCheckDoneCallback != null)
154 { 155 {
155 this.updateCheckDoneCallback.dispose(); 156 this.updateCheckDoneCallback.dispose();
156 this.updateCheckDoneCallback = null; 157 this.updateCheckDoneCallback = null;
157 } 158 }
158 159
159 if (this.filterChangeCallback != null) 160 if (this.filterChangeCallback != null)
160 { 161 {
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 272
272 public void updateSubscriptionStatus(final String url) 273 public void updateSubscriptionStatus(final String url)
273 { 274 {
274 final Subscription sub = this.filterEngine.getSubscription(url); 275 final Subscription sub = this.filterEngine.getSubscription(url);
275 if (sub != null) 276 if (sub != null)
276 { 277 {
277 Utils.updateSubscriptionStatus(this.context, sub); 278 Utils.updateSubscriptionStatus(this.context, sub);
278 } 279 }
279 } 280 }
280 } 281 }
OLDNEW
« no previous file with comments | « res/values/strings.xml ('k') | src/org/adblockplus/android/AdblockPlus.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld