| 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     { | 
| 76       screen.removePreference(findPreference(getString(R.string.pref_support))); | 79       screen.removePreference(findPreference(getString(R.string.pref_support))); | 
| (...skipping 25 matching lines...) Expand all  Loading... | 
| 102     } | 105     } | 
| 103   } | 106   } | 
| 104 | 107 | 
| 105   @Override | 108   @Override | 
| 106   public void onResume() | 109   public void onResume() | 
| 107   { | 110   { | 
| 108     super.onResume(); | 111     super.onResume(); | 
| 109     final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreference
     s(this); | 112     final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreference
     s(this); | 
| 110     final int refresh = Integer.valueOf(prefs.getString(getString(R.string.pref_
     refresh), "0")); | 113     final int refresh = Integer.valueOf(prefs.getString(getString(R.string.pref_
     refresh), "0")); | 
| 111     findPreference(getString(R.string.pref_wifirefresh)).setEnabled(refresh > 0)
     ; | 114     findPreference(getString(R.string.pref_wifirefresh)).setEnabled(refresh > 0)
     ; | 
| 112     connect(); | 115     this.serviceBinder.bind(); | 
| 113   } | 116   } | 
| 114 | 117 | 
| 115   @Override | 118   @Override | 
| 116   public void onPause() | 119   public void onPause() | 
| 117   { | 120   { | 
| 118     super.onPause(); | 121     super.onPause(); | 
| 119     disconnect(); | 122     this.serviceBinder.unbind(); | 
| 120   } | 123   } | 
| 121 | 124 | 
| 122   @Override | 125   @Override | 
| 123   public void onSharedPreferenceChanged(final SharedPreferences sharedPreference
     s, final String key) | 126   public void onSharedPreferenceChanged(final SharedPreferences sharedPreference
     s, final String key) | 
| 124   { | 127   { | 
| 125     if (getString(R.string.pref_proxyenabled).equals(key)) | 128     if (getString(R.string.pref_proxyenabled).equals(key)) | 
| 126     { | 129     { | 
| 127       final AdblockPlus application = AdblockPlus.getApplication(); | 130       final AdblockPlus application = AdblockPlus.getApplication(); | 
| 128       final boolean enabled = sharedPreferences.getBoolean(key, false); | 131       final boolean enabled = sharedPreferences.getBoolean(key, false); | 
| 129       final boolean serviceRunning = application.isServiceRunning(); | 132       final boolean serviceRunning = application.isServiceRunning(); | 
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 167   @Override | 170   @Override | 
| 168   protected Dialog onCreateDialog(final int id) | 171   protected Dialog onCreateDialog(final int id) | 
| 169   { | 172   { | 
| 170     Dialog dialog = null; | 173     Dialog dialog = null; | 
| 171     switch (id) | 174     switch (id) | 
| 172     { | 175     { | 
| 173       case CONFIGURATION_DIALOG: | 176       case CONFIGURATION_DIALOG: | 
| 174         final List<String> items = new ArrayList<String>(); | 177         final List<String> items = new ArrayList<String>(); | 
| 175         items.add(AdblockPlus.getDeviceName()); | 178         items.add(AdblockPlus.getDeviceName()); | 
| 176         items.add(String.format("API: %d Build: %d", Build.VERSION.SDK_INT, Adbl
     ockPlus.getApplication().getBuildNumber())); | 179         items.add(String.format("API: %d Build: %d", Build.VERSION.SDK_INT, Adbl
     ockPlus.getApplication().getBuildNumber())); | 
|  | 180 | 
|  | 181         final ProxyService proxyService = this.serviceBinder.get(); | 
|  | 182 | 
| 177         if (proxyService != null) | 183         if (proxyService != null) | 
| 178         { | 184         { | 
| 179           items.add(String.format("Local port: %d", proxyService.port)); | 185           items.add(String.format("Local port: %d", proxyService.port)); | 
| 180           if (proxyService.isTransparent()) | 186           if (proxyService.getProxyRegistrationType() == ProxyRegistrationType.I
     PTABLES) | 
| 181           { | 187           { | 
| 182             items.add("Running in root mode"); | 188             items.add("Running in root mode"); | 
| 183             items.add("iptables output:"); | 189             items.add("iptables output:"); | 
| 184             final List<String> output = proxyService.getIptablesOutput(); | 190             final List<String> output = IptablesProxyConfigurator.getIptablesOut
     put(getApplicationContext()); | 
| 185             if (output != null) | 191             if (output != null) | 
| 186             { | 192             { | 
| 187               for (final String line : output) | 193               for (final String line : output) | 
| 188               { | 194               { | 
| 189                 if (!"".equals(line)) | 195                 if (StringUtils.isNotEmpty(line)) | 
| 190                   items.add(line); | 196                   items.add(line); | 
| 191               } | 197               } | 
| 192             } | 198             } | 
| 193           } | 199           } | 
| 194           if (proxyService.isNativeProxyAutoConfigured()) | 200           if (proxyService.isNativeProxyAutoConfigured()) | 
| 195           { | 201           { | 
| 196             items.add("Has native proxy auto configured"); | 202             items.add("Has native proxy auto configured"); | 
| 197           } | 203           } | 
| 198           if (ProxyService.NATIVE_PROXY_SUPPORTED) | 204           if (Utils.isNativeProxySupported(this)) | 
| 199           { | 205           { | 
| 200             final String[] px = ProxySettings.getUserProxy(getApplicationContext
     ()); | 206             final ProxyProperties pp = ProxyProperties.fromContext(getApplicatio
     nContext()); | 
| 201             if (px != null) | 207             if (pp != null) | 
| 202             { | 208             { | 
| 203               items.add("System settings:"); | 209               items.add("System settings:"); | 
| 204               items.add(String.format("Host: [%s] Port: [%s] Excl: [%s]", px[0],
      px[1], px[2])); | 210               items.add(String.format("Host: [%s] Port: [%d] Excl: [%s]", pp.get
     Host(), pp.getPort(), pp.getExclusionList())); | 
| 205             } | 211             } | 
| 206           } | 212           } | 
| 207           items.add("Proxy settings:"); | 213           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"), | 214           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"))); | 215               proxyService.proxy.props.getProperty("adblock.proxyExcl"))); | 
| 210           if (proxyService.proxy.props.getProperty("adblock.auth") != null) | 216           if (proxyService.proxy.props.getProperty("adblock.auth") != null) | 
| 211             items.add("Auth: yes"); | 217             items.add("Auth: yes"); | 
| 212         } | 218         } | 
| 213         else | 219         else | 
| 214         { | 220         { | 
| 215           items.add("Service not running"); | 221           items.add("Service not running"); | 
| 216         } | 222         } | 
| 217 | 223 | 
| 218         final ScrollView scrollPane = new ScrollView(this); | 224         final ScrollView scrollPane = new ScrollView(this); | 
| 219         final TextView messageText = new TextView(this); | 225         final TextView messageText = new TextView(this); | 
| 220         messageText.setPadding(12, 6, 12, 6); | 226         messageText.setPadding(12, 6, 12, 6); | 
| 221         messageText.setText(TextUtils.join("\n", items)); | 227         messageText.setText(TextUtils.join("\n", items)); | 
| 222         messageText.setOnClickListener(new View.OnClickListener() | 228         messageText.setOnClickListener(new View.OnClickListener() | 
| 223         { | 229         { | 
| 224 |  | 
| 225           @Override | 230           @Override | 
| 226           public void onClick(final View v) | 231           public void onClick(final View v) | 
| 227           { | 232           { | 
| 228             final ClipboardManager manager = (ClipboardManager) getSystemService
     (CLIPBOARD_SERVICE); | 233             final ClipboardManager manager = (ClipboardManager) getSystemService
     (CLIPBOARD_SERVICE); | 
| 229             final TextView showTextParam = (TextView) v; | 234             final TextView showTextParam = (TextView) v; | 
| 230             manager.setText(showTextParam.getText()); | 235             manager.setText(showTextParam.getText()); | 
| 231             Toast.makeText(v.getContext(), R.string.msg_clipboard, Toast.LENGTH_
     SHORT).show(); | 236             Toast.makeText(v.getContext(), R.string.msg_clipboard, Toast.LENGTH_
     SHORT).show(); | 
| 232           } | 237           } | 
| 233         }); | 238         }); | 
| 234         scrollPane.addView(messageText); | 239         scrollPane.addView(messageText); | 
| 235 | 240 | 
| 236         final AlertDialog.Builder builder = new AlertDialog.Builder(this); | 241         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) | 242         builder.setView(scrollPane) | 
|  | 243             .setTitle(R.string.configuration_name) | 
|  | 244             .setIcon(android.R.drawable.ic_dialog_info) | 
|  | 245             .setCancelable(false) | 
| 238             .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener(
     ) | 246             .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener(
     ) | 
| 239             { | 247             { | 
| 240               @Override | 248               @Override | 
| 241               public void onClick(final DialogInterface dialog, final int id) | 249               public void onClick(final DialogInterface dialog, final int id) | 
| 242               { | 250               { | 
| 243                 dialog.cancel(); | 251                 dialog.cancel(); | 
| 244               } | 252               } | 
| 245             }); | 253             }); | 
| 246         dialog = builder.create(); | 254         dialog = builder.create(); | 
| 247         break; | 255         break; | 
| 248     } | 256     } | 
| 249     return dialog; | 257     return dialog; | 
| 250   } | 258   } | 
| 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 } | 259 } | 
| OLD | NEW | 
|---|