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