Left: | ||
Right: |
OLD | NEW |
---|---|
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.ArrayList; | 20 import java.util.ArrayList; |
21 import java.util.List; | 21 import java.util.List; |
22 | 22 |
23 import org.adblockplus.android.compat.ProxyProperties; | |
24 import org.adblockplus.android.configurators.IptablesProxyConfigurator; | |
25 import org.adblockplus.android.configurators.ProxyRegistrationType; | |
26 import org.apache.commons.lang.StringUtils; | |
27 | |
23 import android.app.AlertDialog; | 28 import android.app.AlertDialog; |
24 import android.app.Dialog; | 29 import android.app.Dialog; |
25 import android.content.ComponentName; | |
26 import android.content.DialogInterface; | 30 import android.content.DialogInterface; |
27 import android.content.Intent; | 31 import android.content.Intent; |
28 import android.content.ServiceConnection; | |
29 import android.content.SharedPreferences; | 32 import android.content.SharedPreferences; |
30 import android.os.Build; | 33 import android.os.Build; |
31 import android.os.Bundle; | 34 import android.os.Bundle; |
32 import android.os.IBinder; | |
33 import android.preference.Preference; | 35 import android.preference.Preference; |
34 import android.preference.Preference.OnPreferenceClickListener; | 36 import android.preference.Preference.OnPreferenceClickListener; |
35 import android.preference.PreferenceManager; | 37 import android.preference.PreferenceManager; |
36 import android.preference.PreferenceScreen; | 38 import android.preference.PreferenceScreen; |
37 import android.text.ClipboardManager; | 39 import android.text.ClipboardManager; |
38 import android.text.TextUtils; | 40 import android.text.TextUtils; |
39 import android.util.Log; | |
40 import android.view.View; | 41 import android.view.View; |
41 import android.widget.ScrollView; | 42 import android.widget.ScrollView; |
42 import android.widget.TextView; | 43 import android.widget.TextView; |
43 import android.widget.Toast; | 44 import android.widget.Toast; |
44 | 45 |
45 /** | 46 /** |
46 * Advanced settings UI. | 47 * Advanced settings UI. |
47 */ | 48 */ |
48 public class AdvancedPreferences extends SummarizedPreferences | 49 public class AdvancedPreferences extends SummarizedPreferences |
49 { | 50 { |
50 private static final String TAG = Utils.getTag(AdvancedPreferences.class); | 51 private static final String TAG = Utils.getTag(AdvancedPreferences.class); |
51 | 52 |
52 private static final int CONFIGURATION_DIALOG = 1; | 53 private static final int CONFIGURATION_DIALOG = 1; |
53 | 54 |
54 private ProxyService proxyService = null; | 55 private ServiceBinder serviceBinder = null; |
55 | 56 |
56 @Override | 57 @Override |
57 public void onCreate(final Bundle savedInstanceState) | 58 public void onCreate(final Bundle savedInstanceState) |
58 { | 59 { |
59 super.onCreate(savedInstanceState); | 60 super.onCreate(savedInstanceState); |
60 | 61 |
61 addPreferencesFromResource(R.xml.preferences_advanced); | 62 addPreferencesFromResource(R.xml.preferences_advanced); |
62 | 63 |
63 final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreference s(this); | 64 final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreference s(this); |
64 | 65 |
66 this.serviceBinder = new ServiceBinder(this); | |
67 | |
65 final PreferenceScreen screen = getPreferenceScreen(); | 68 final PreferenceScreen screen = getPreferenceScreen(); |
66 if (ProxyService.NATIVE_PROXY_SUPPORTED) | 69 if (Utils.isNativeProxySupported(this)) |
67 { | 70 { |
68 screen.removePreference(findPreference(getString(R.string.pref_proxy))); | 71 screen.removePreference(findPreference(getString(R.string.pref_proxy))); |
69 if (prefs.getBoolean(getString(R.string.pref_proxyautoconfigured), false)) | 72 if (prefs.getBoolean(getString(R.string.pref_proxyautoconfigured), false)) |
70 { | 73 { |
71 screen.removePreference(findPreference(getString(R.string.pref_proxyenab led))); | 74 screen.removePreference(findPreference(getString(R.string.pref_proxyenab led))); |
72 } | 75 } |
73 } | 76 } |
74 if (getResources().getBoolean(R.bool.def_release)) | 77 if (getResources().getBoolean(R.bool.def_release)) |
75 { | 78 { |
79 // FIXME Do we really want to disable support in dev-builds? ... and what does this do? | |
Felix Dahlke
2014/08/19 09:06:00
How about creating an issue instead? :)
René Jeschke
2014/08/19 10:41:33
Done.
| |
76 screen.removePreference(findPreference(getString(R.string.pref_support))); | 80 screen.removePreference(findPreference(getString(R.string.pref_support))); |
77 } | 81 } |
78 else | 82 else |
79 { | 83 { |
80 final Preference prefUpdate = findPreference(getString(R.string.pref_check update)); | 84 final Preference prefUpdate = findPreference(getString(R.string.pref_check update)); |
81 prefUpdate.setOnPreferenceClickListener(new OnPreferenceClickListener() | 85 prefUpdate.setOnPreferenceClickListener(new OnPreferenceClickListener() |
82 { | 86 { |
83 @Override | 87 @Override |
84 public boolean onPreferenceClick(final Preference preference) | 88 public boolean onPreferenceClick(final Preference preference) |
85 { | 89 { |
(...skipping 16 matching lines...) Expand all Loading... | |
102 } | 106 } |
103 } | 107 } |
104 | 108 |
105 @Override | 109 @Override |
106 public void onResume() | 110 public void onResume() |
107 { | 111 { |
108 super.onResume(); | 112 super.onResume(); |
109 final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreference s(this); | 113 final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreference s(this); |
110 final int refresh = Integer.valueOf(prefs.getString(getString(R.string.pref_ refresh), "0")); | 114 final int refresh = Integer.valueOf(prefs.getString(getString(R.string.pref_ refresh), "0")); |
111 findPreference(getString(R.string.pref_wifirefresh)).setEnabled(refresh > 0) ; | 115 findPreference(getString(R.string.pref_wifirefresh)).setEnabled(refresh > 0) ; |
112 connect(); | 116 this.serviceBinder.bind(); |
113 } | 117 } |
114 | 118 |
115 @Override | 119 @Override |
116 public void onPause() | 120 public void onPause() |
117 { | 121 { |
118 super.onPause(); | 122 super.onPause(); |
119 disconnect(); | 123 this.serviceBinder.unbind(); |
120 } | 124 } |
121 | 125 |
122 @Override | 126 @Override |
123 public void onSharedPreferenceChanged(final SharedPreferences sharedPreference s, final String key) | 127 public void onSharedPreferenceChanged(final SharedPreferences sharedPreference s, final String key) |
124 { | 128 { |
125 if (getString(R.string.pref_proxyenabled).equals(key)) | 129 if (getString(R.string.pref_proxyenabled).equals(key)) |
126 { | 130 { |
127 final AdblockPlus application = AdblockPlus.getApplication(); | 131 final AdblockPlus application = AdblockPlus.getApplication(); |
128 final boolean enabled = sharedPreferences.getBoolean(key, false); | 132 final boolean enabled = sharedPreferences.getBoolean(key, false); |
129 final boolean serviceRunning = application.isServiceRunning(); | 133 final boolean serviceRunning = application.isServiceRunning(); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
167 @Override | 171 @Override |
168 protected Dialog onCreateDialog(final int id) | 172 protected Dialog onCreateDialog(final int id) |
169 { | 173 { |
170 Dialog dialog = null; | 174 Dialog dialog = null; |
171 switch (id) | 175 switch (id) |
172 { | 176 { |
173 case CONFIGURATION_DIALOG: | 177 case CONFIGURATION_DIALOG: |
174 final List<String> items = new ArrayList<String>(); | 178 final List<String> items = new ArrayList<String>(); |
175 items.add(AdblockPlus.getDeviceName()); | 179 items.add(AdblockPlus.getDeviceName()); |
176 items.add(String.format("API: %d Build: %d", Build.VERSION.SDK_INT, Adbl ockPlus.getApplication().getBuildNumber())); | 180 items.add(String.format("API: %d Build: %d", Build.VERSION.SDK_INT, Adbl ockPlus.getApplication().getBuildNumber())); |
181 | |
182 final ProxyService proxyService = this.serviceBinder.get(); | |
183 | |
177 if (proxyService != null) | 184 if (proxyService != null) |
178 { | 185 { |
179 items.add(String.format("Local port: %d", proxyService.port)); | 186 items.add(String.format("Local port: %d", proxyService.port)); |
180 if (proxyService.isTransparent()) | 187 if (proxyService.getProxyRegistrationType() == ProxyRegistrationType.I PTABLES) |
181 { | 188 { |
182 items.add("Running in root mode"); | 189 items.add("Running in root mode"); |
183 items.add("iptables output:"); | 190 items.add("iptables output:"); |
184 final List<String> output = proxyService.getIptablesOutput(); | 191 final List<String> output = IptablesProxyConfigurator.getIptablesOut put(getApplicationContext()); |
185 if (output != null) | 192 if (output != null) |
186 { | 193 { |
187 for (final String line : output) | 194 for (final String line : output) |
188 { | 195 { |
189 if (!"".equals(line)) | 196 if (StringUtils.isNotEmpty(line)) |
190 items.add(line); | 197 items.add(line); |
191 } | 198 } |
192 } | 199 } |
193 } | 200 } |
194 if (proxyService.isNativeProxyAutoConfigured()) | 201 if (proxyService.isNativeProxyAutoConfigured()) |
195 { | 202 { |
196 items.add("Has native proxy auto configured"); | 203 items.add("Has native proxy auto configured"); |
197 } | 204 } |
198 if (ProxyService.NATIVE_PROXY_SUPPORTED) | 205 if (Utils.isNativeProxySupported(this)) |
199 { | 206 { |
200 final String[] px = ProxySettings.getUserProxy(getApplicationContext ()); | 207 final ProxyProperties pp = ProxyProperties.fromContext(getApplicatio nContext()); |
201 if (px != null) | 208 if (pp != null) |
202 { | 209 { |
203 items.add("System settings:"); | 210 items.add("System settings:"); |
204 items.add(String.format("Host: [%s] Port: [%s] Excl: [%s]", px[0], px[1], px[2])); | 211 items.add(String.format("Host: [%s] Port: [%d] Excl: [%s]", pp.get Host(), pp.getPort(), pp.getExclusionList())); |
205 } | 212 } |
206 } | 213 } |
207 items.add("Proxy settings:"); | 214 items.add("Proxy settings:"); |
208 items.add(String.format("Host: [%s] Port: [%s] Excl: [%s]", proxyServi ce.proxy.props.getProperty("adblock.proxyHost"), proxyService.proxy.props.getPro perty("adblock.proxyPort"), | 215 items.add(String.format("Host: [%s] Port: [%s] Excl: [%s]", proxyServi ce.proxy.props.getProperty("adblock.proxyHost"), proxyService.proxy.props.getPro perty("adblock.proxyPort"), |
209 proxyService.proxy.props.getProperty("adblock.proxyExcl"))); | 216 proxyService.proxy.props.getProperty("adblock.proxyExcl"))); |
210 if (proxyService.proxy.props.getProperty("adblock.auth") != null) | 217 if (proxyService.proxy.props.getProperty("adblock.auth") != null) |
211 items.add("Auth: yes"); | 218 items.add("Auth: yes"); |
212 } | 219 } |
213 else | 220 else |
214 { | 221 { |
215 items.add("Service not running"); | 222 items.add("Service not running"); |
216 } | 223 } |
217 | 224 |
218 final ScrollView scrollPane = new ScrollView(this); | 225 final ScrollView scrollPane = new ScrollView(this); |
219 final TextView messageText = new TextView(this); | 226 final TextView messageText = new TextView(this); |
220 messageText.setPadding(12, 6, 12, 6); | 227 messageText.setPadding(12, 6, 12, 6); |
221 messageText.setText(TextUtils.join("\n", items)); | 228 messageText.setText(TextUtils.join("\n", items)); |
222 messageText.setOnClickListener(new View.OnClickListener() | 229 messageText.setOnClickListener(new View.OnClickListener() |
223 { | 230 { |
224 | |
225 @Override | 231 @Override |
226 public void onClick(final View v) | 232 public void onClick(final View v) |
227 { | 233 { |
228 final ClipboardManager manager = (ClipboardManager) getSystemService (CLIPBOARD_SERVICE); | 234 final ClipboardManager manager = (ClipboardManager) getSystemService (CLIPBOARD_SERVICE); |
229 final TextView showTextParam = (TextView) v; | 235 final TextView showTextParam = (TextView) v; |
230 manager.setText(showTextParam.getText()); | 236 manager.setText(showTextParam.getText()); |
231 Toast.makeText(v.getContext(), R.string.msg_clipboard, Toast.LENGTH_ SHORT).show(); | 237 Toast.makeText(v.getContext(), R.string.msg_clipboard, Toast.LENGTH_ SHORT).show(); |
232 } | 238 } |
233 }); | 239 }); |
234 scrollPane.addView(messageText); | 240 scrollPane.addView(messageText); |
235 | 241 |
236 final AlertDialog.Builder builder = new AlertDialog.Builder(this); | 242 final AlertDialog.Builder builder = new AlertDialog.Builder(this); |
237 builder.setView(scrollPane).setTitle(R.string.configuration_name).setIco n(android.R.drawable.ic_dialog_info).setCancelable(false) | 243 builder.setView(scrollPane) |
244 .setTitle(R.string.configuration_name) | |
245 .setIcon(android.R.drawable.ic_dialog_info) | |
246 .setCancelable(false) | |
238 .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener( ) | 247 .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener( ) |
239 { | 248 { |
240 @Override | 249 @Override |
241 public void onClick(final DialogInterface dialog, final int id) | 250 public void onClick(final DialogInterface dialog, final int id) |
242 { | 251 { |
243 dialog.cancel(); | 252 dialog.cancel(); |
244 } | 253 } |
245 }); | 254 }); |
246 dialog = builder.create(); | 255 dialog = builder.create(); |
247 break; | 256 break; |
248 } | 257 } |
249 return dialog; | 258 return dialog; |
250 } | 259 } |
251 | |
252 private void connect() | |
253 { | |
254 bindService(new Intent(this, ProxyService.class), proxyServiceConnection, 0) ; | |
255 } | |
256 | |
257 private void disconnect() | |
258 { | |
259 unbindService(proxyServiceConnection); | |
260 proxyService = null; | |
261 } | |
262 | |
263 private final ServiceConnection proxyServiceConnection = new ServiceConnection () | |
264 { | |
265 @Override | |
266 public void onServiceConnected(final ComponentName className, final IBinder service) | |
267 { | |
268 proxyService = ((ProxyService.LocalBinder) service).getService(); | |
269 Log.d(TAG, "Proxy service connected"); | |
270 } | |
271 | |
272 @Override | |
273 public void onServiceDisconnected(final ComponentName className) | |
274 { | |
275 proxyService = null; | |
276 Log.d(TAG, "Proxy service disconnected"); | |
277 } | |
278 }; | |
279 } | 260 } |
OLD | NEW |