| 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 | 
| (...skipping 29 matching lines...) Expand all  Loading... | 
|   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 = "AdvancedPreferences"; |   50   private static final String TAG = Utils.getTag(AdvancedPreferences.class); | 
|   51  |  | 
|   52   private static final int CONFIGURATION_DIALOG = 1; |   51   private static final int CONFIGURATION_DIALOG = 1; | 
|   53  |   52  | 
|   54   private ProxyService proxyService = null; |   53   private ProxyService proxyService = null; | 
|   55  |   54  | 
|   56   @Override |   55   @Override | 
|   57   public void onCreate(Bundle savedInstanceState) |   56   public void onCreate(final Bundle savedInstanceState) | 
|   58   { |   57   { | 
|   59     super.onCreate(savedInstanceState); |   58     super.onCreate(savedInstanceState); | 
|   60  |   59  | 
|   61     addPreferencesFromResource(R.xml.preferences_advanced); |   60     addPreferencesFromResource(R.xml.preferences_advanced); | 
|   62  |   61  | 
|   63     SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this
     ); |   62     final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreference
     s(this); | 
|   64  |   63  | 
|   65     PreferenceScreen screen = getPreferenceScreen(); |   64     final PreferenceScreen screen = getPreferenceScreen(); | 
|   66     if (ProxyService.NATIVE_PROXY_SUPPORTED) |   65     if (ProxyService.NATIVE_PROXY_SUPPORTED) | 
|   67     { |   66     { | 
|   68       screen.removePreference(findPreference(getString(R.string.pref_proxy))); |   67       screen.removePreference(findPreference(getString(R.string.pref_proxy))); | 
|   69       if (prefs.getBoolean(getString(R.string.pref_proxyautoconfigured), false)) |   68       if (prefs.getBoolean(getString(R.string.pref_proxyautoconfigured), false)) | 
|   70       { |   69       { | 
|   71         screen.removePreference(findPreference(getString(R.string.pref_proxyenab
     led))); |   70         screen.removePreference(findPreference(getString(R.string.pref_proxyenab
     led))); | 
|   72       } |   71       } | 
|   73     } |   72     } | 
|   74     if (getResources().getBoolean(R.bool.def_release)) |   73     if (getResources().getBoolean(R.bool.def_release)) | 
|   75     { |   74     { | 
|   76       screen.removePreference(findPreference(getString(R.string.pref_support))); |   75       screen.removePreference(findPreference(getString(R.string.pref_support))); | 
|   77     } |   76     } | 
|   78     else |   77     else | 
|   79     { |   78     { | 
|   80       Preference prefUpdate = findPreference(getString(R.string.pref_checkupdate
     )); |   79       final Preference prefUpdate = findPreference(getString(R.string.pref_check
     update)); | 
|   81       prefUpdate.setOnPreferenceClickListener(new OnPreferenceClickListener() |   80       prefUpdate.setOnPreferenceClickListener(new OnPreferenceClickListener() | 
|   82       { |   81       { | 
|   83         public boolean onPreferenceClick(Preference preference) |   82         @Override | 
 |   83         public boolean onPreferenceClick(final Preference preference) | 
|   84         { |   84         { | 
|   85           AdblockPlus application = AdblockPlus.getApplication(); |   85           final AdblockPlus application = AdblockPlus.getApplication(); | 
|   86           application.checkUpdates(); |   86           application.checkUpdates(); | 
|   87           return true; |   87           return true; | 
|   88         } |   88         } | 
|   89       }); |   89       }); | 
|   90  |   90  | 
|   91       Preference prefConfiguration = findPreference(getString(R.string.pref_conf
     iguration)); |   91       final Preference prefConfiguration = findPreference(getString(R.string.pre
     f_configuration)); | 
|   92       prefConfiguration.setOnPreferenceClickListener(new OnPreferenceClickListen
     er() |   92       prefConfiguration.setOnPreferenceClickListener(new OnPreferenceClickListen
     er() | 
|   93       { |   93       { | 
|   94         public boolean onPreferenceClick(Preference preference) |   94         @Override | 
 |   95         public boolean onPreferenceClick(final Preference preference) | 
|   95         { |   96         { | 
|   96           showDialog(CONFIGURATION_DIALOG); |   97           showDialog(CONFIGURATION_DIALOG); | 
|   97           return true; |   98           return true; | 
|   98         } |   99         } | 
|   99       }); |  100       }); | 
|  100     } |  101     } | 
|  101   } |  102   } | 
|  102  |  103  | 
|  103   @Override |  104   @Override | 
|  104   public void onResume() |  105   public void onResume() | 
|  105   { |  106   { | 
|  106     super.onResume(); |  107     super.onResume(); | 
|  107     SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this
     ); |  108     final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreference
     s(this); | 
|  108     int refresh = Integer.valueOf(prefs.getString(getString(R.string.pref_refres
     h), "0")); |  109     final int refresh = Integer.valueOf(prefs.getString(getString(R.string.pref_
     refresh), "0")); | 
|  109     findPreference(getString(R.string.pref_wifirefresh)).setEnabled(refresh > 0)
     ; |  110     findPreference(getString(R.string.pref_wifirefresh)).setEnabled(refresh > 0)
     ; | 
|  110     connect(); |  111     connect(); | 
|  111   } |  112   } | 
|  112  |  113  | 
|  113   @Override |  114   @Override | 
|  114   public void onPause() |  115   public void onPause() | 
|  115   { |  116   { | 
|  116     super.onPause(); |  117     super.onPause(); | 
|  117     disconnect(); |  118     disconnect(); | 
|  118   } |  119   } | 
|  119  |  120  | 
|  120   @Override |  121   @Override | 
|  121   public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, Str
     ing key) |  122   public void onSharedPreferenceChanged(final SharedPreferences sharedPreference
     s, final String key) | 
|  122   { |  123   { | 
|  123     if (getString(R.string.pref_proxyenabled).equals(key)) |  124     if (getString(R.string.pref_proxyenabled).equals(key)) | 
|  124     { |  125     { | 
|  125       AdblockPlus application = AdblockPlus.getApplication(); |  126       final AdblockPlus application = AdblockPlus.getApplication(); | 
|  126       boolean enabled = sharedPreferences.getBoolean(key, false); |  127       final boolean enabled = sharedPreferences.getBoolean(key, false); | 
|  127       boolean serviceRunning = application.isServiceRunning(); |  128       final boolean serviceRunning = application.isServiceRunning(); | 
|  128       if (enabled) |  129       if (enabled) | 
|  129       { |  130       { | 
|  130         if (!serviceRunning) |  131         if (!serviceRunning) | 
|  131           startService(new Intent(this, ProxyService.class)); |  132           startService(new Intent(this, ProxyService.class)); | 
|  132       } |  133       } | 
|  133       else |  134       else | 
|  134       { |  135       { | 
|  135         if (serviceRunning) |  136         if (serviceRunning) | 
|  136           stopService(new Intent(this, ProxyService.class)); |  137           stopService(new Intent(this, ProxyService.class)); | 
|  137         // If disabled, disable filtering as well |  138         // If disabled, disable filtering as well | 
|  138         SharedPreferences.Editor editor = sharedPreferences.edit(); |  139         final SharedPreferences.Editor editor = sharedPreferences.edit(); | 
|  139         editor.putBoolean(getString(R.string.pref_enabled), false); |  140         editor.putBoolean(getString(R.string.pref_enabled), false); | 
|  140         editor.commit(); |  141         editor.commit(); | 
|  141         application.setFilteringEnabled(false); |  142         application.setFilteringEnabled(false); | 
|  142       } |  143       } | 
|  143     } |  144     } | 
|  144     if (getString(R.string.pref_refresh).equals(key)) |  145     if (getString(R.string.pref_refresh).equals(key)) | 
|  145     { |  146     { | 
|  146       int refresh = Integer.valueOf(sharedPreferences.getString(key, "0")); |  147       final int refresh = Integer.valueOf(sharedPreferences.getString(key, "0"))
     ; | 
|  147       findPreference(getString(R.string.pref_wifirefresh)).setEnabled(refresh > 
     0); |  148       findPreference(getString(R.string.pref_wifirefresh)).setEnabled(refresh > 
     0); | 
|  148     } |  149     } | 
|  149     if (getString(R.string.pref_crashreport).equals(key)) |  150     if (getString(R.string.pref_crashreport).equals(key)) | 
|  150     { |  151     { | 
|  151       boolean report = sharedPreferences.getBoolean(key, getResources().getBoole
     an(R.bool.def_crashreport)); |  152       final boolean report = sharedPreferences.getBoolean(key, getResources().ge
     tBoolean(R.bool.def_crashreport)); | 
|  152       try |  153       try | 
|  153       { |  154       { | 
|  154         CrashHandler handler = (CrashHandler) Thread.getDefaultUncaughtException
     Handler(); |  155         final CrashHandler handler = (CrashHandler) Thread.getDefaultUncaughtExc
     eptionHandler(); | 
|  155         handler.generateReport(report); |  156         handler.generateReport(report); | 
|  156       } |  157       } | 
|  157       catch (ClassCastException e) |  158       catch (final ClassCastException e) | 
|  158       { |  159       { | 
|  159         // ignore - default handler in use |  160         // ignore - default handler in use | 
|  160       } |  161       } | 
|  161     } |  162     } | 
|  162     super.onSharedPreferenceChanged(sharedPreferences, key); |  163     super.onSharedPreferenceChanged(sharedPreferences, key); | 
|  163   } |  164   } | 
|  164  |  165  | 
|  165   @Override |  166   @Override | 
|  166   protected Dialog onCreateDialog(int id) |  167   protected Dialog onCreateDialog(final int id) | 
|  167   { |  168   { | 
|  168     Dialog dialog = null; |  169     Dialog dialog = null; | 
|  169     switch (id) |  170     switch (id) | 
|  170     { |  171     { | 
|  171       case CONFIGURATION_DIALOG: |  172       case CONFIGURATION_DIALOG: | 
|  172         List<String> items = new ArrayList<String>(); |  173         final List<String> items = new ArrayList<String>(); | 
|  173         items.add(AdblockPlus.getDeviceName()); |  174         items.add(AdblockPlus.getDeviceName()); | 
|  174         items.add(String.format("API: %d Build: %d", Build.VERSION.SDK_INT, Adbl
     ockPlus.getApplication().getBuildNumber())); |  175         items.add(String.format("API: %d Build: %d", Build.VERSION.SDK_INT, Adbl
     ockPlus.getApplication().getBuildNumber())); | 
|  175         if (proxyService != null) |  176         if (proxyService != null) | 
|  176         { |  177         { | 
|  177           items.add(String.format("Local port: %d", proxyService.port)); |  178           items.add(String.format("Local port: %d", proxyService.port)); | 
|  178           if (proxyService.isTransparent()) |  179           if (proxyService.isTransparent()) | 
|  179           { |  180           { | 
|  180             items.add("Running in root mode"); |  181             items.add("Running in root mode"); | 
|  181             items.add("iptables output:"); |  182             items.add("iptables output:"); | 
|  182             List<String> output = proxyService.getIptablesOutput(); |  183             final List<String> output = proxyService.getIptablesOutput(); | 
|  183             if (output != null) |  184             if (output != null) | 
|  184             { |  185             { | 
|  185               for (String line : output) |  186               for (final String line : output) | 
|  186               { |  187               { | 
|  187                 if (!"".equals(line)) |  188                 if (!"".equals(line)) | 
|  188                   items.add(line); |  189                   items.add(line); | 
|  189               } |  190               } | 
|  190             } |  191             } | 
|  191           } |  192           } | 
|  192           if (proxyService.isNativeProxyAutoConfigured()) |  193           if (proxyService.isNativeProxyAutoConfigured()) | 
|  193           { |  194           { | 
|  194             items.add("Has native proxy auto configured"); |  195             items.add("Has native proxy auto configured"); | 
|  195           } |  196           } | 
|  196           if (ProxyService.NATIVE_PROXY_SUPPORTED) |  197           if (ProxyService.NATIVE_PROXY_SUPPORTED) | 
|  197           { |  198           { | 
|  198             String[] px = ProxySettings.getUserProxy(getApplicationContext()); |  199             final String[] px = ProxySettings.getUserProxy(getApplicationContext
     ()); | 
|  199             if (px != null) |  200             if (px != null) | 
|  200             { |  201             { | 
|  201               items.add("System settings:"); |  202               items.add("System settings:"); | 
|  202               items.add(String.format("Host: [%s] Port: [%s] Excl: [%s]", px[0],
      px[1], px[2])); |  203               items.add(String.format("Host: [%s] Port: [%s] Excl: [%s]", px[0],
      px[1], px[2])); | 
|  203             } |  204             } | 
|  204           } |  205           } | 
|  205           items.add("Proxy settings:"); |  206           items.add("Proxy settings:"); | 
|  206           items.add(String.format("Host: [%s] Port: [%s] Excl: [%s]", proxyServi
     ce.proxy.props.getProperty("adblock.proxyHost"), proxyService.proxy.props.getPro
     perty("adblock.proxyPort"), |  207           items.add(String.format("Host: [%s] Port: [%s] Excl: [%s]", proxyServi
     ce.proxy.props.getProperty("adblock.proxyHost"), | 
 |  208               proxyService.proxy.props.getProperty("adblock.proxyPort"), | 
|  207               proxyService.proxy.props.getProperty("adblock.proxyExcl"))); |  209               proxyService.proxy.props.getProperty("adblock.proxyExcl"))); | 
|  208           if (proxyService.proxy.props.getProperty("adblock.auth") != null) |  210           if (proxyService.proxy.props.getProperty("adblock.auth") != null) | 
|  209             items.add("Auth: yes"); |  211             items.add("Auth: yes"); | 
|  210         } |  212         } | 
|  211         else |  213         else | 
|  212         { |  214         { | 
|  213           items.add("Service not running"); |  215           items.add("Service not running"); | 
|  214         } |  216         } | 
|  215  |  217  | 
|  216         ScrollView scrollPane = new ScrollView(this); |  218         final ScrollView scrollPane = new ScrollView(this); | 
|  217         TextView messageText = new TextView(this); |  219         final TextView messageText = new TextView(this); | 
|  218         messageText.setPadding(12, 6, 12, 6); |  220         messageText.setPadding(12, 6, 12, 6); | 
|  219         messageText.setText(TextUtils.join("\n", items)); |  221         messageText.setText(TextUtils.join("\n", items)); | 
|  220         messageText.setOnClickListener(new View.OnClickListener() |  222         messageText.setOnClickListener(new View.OnClickListener() | 
|  221         { |  223         { | 
|  222  |  | 
|  223           @Override |  224           @Override | 
|  224           public void onClick(View v) |  225           public void onClick(final View v) | 
|  225           { |  226           { | 
|  226             ClipboardManager manager = (ClipboardManager) getSystemService(CLIPB
     OARD_SERVICE); |  227             final ClipboardManager manager = (ClipboardManager) getSystemService
     (CLIPBOARD_SERVICE); | 
|  227             TextView showTextParam = (TextView) v; |  228             final TextView showTextParam = (TextView) v; | 
|  228             manager.setText(showTextParam.getText()); |  229             manager.setText(showTextParam.getText()); | 
|  229             Toast.makeText(v.getContext(), R.string.msg_clipboard, Toast.LENGTH_
     SHORT).show(); |  230             Toast.makeText(v.getContext(), R.string.msg_clipboard, Toast.LENGTH_
     SHORT).show(); | 
|  230           } |  231           } | 
|  231         }); |  232         }); | 
|  232         scrollPane.addView(messageText); |  233         scrollPane.addView(messageText); | 
|  233  |  234  | 
|  234         AlertDialog.Builder builder = new AlertDialog.Builder(this); |  235         final AlertDialog.Builder builder = new AlertDialog.Builder(this); | 
|  235         builder.setView(scrollPane).setTitle(R.string.configuration_name).setIco
     n(android.R.drawable.ic_dialog_info).setCancelable(false) |  236         builder.setView(scrollPane).setTitle(R.string.configuration_name).setIco
     n(android.R.drawable.ic_dialog_info).setCancelable(false) | 
|  236             .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener(
     ) |  237             .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener(
     ) | 
|  237             { |  238             { | 
|  238               public void onClick(DialogInterface dialog, int id) |  239               @Override | 
 |  240               public void onClick(final DialogInterface dialog, final int id) | 
|  239               { |  241               { | 
|  240                 dialog.cancel(); |  242                 dialog.cancel(); | 
|  241               } |  243               } | 
|  242             }); |  244             }); | 
|  243         dialog = builder.create(); |  245         dialog = builder.create(); | 
|  244         break; |  246         break; | 
|  245     } |  247     } | 
|  246     return dialog; |  248     return dialog; | 
|  247   } |  249   } | 
|  248  |  250  | 
|  249   private void connect() |  251   private void connect() | 
|  250   { |  252   { | 
|  251     bindService(new Intent(this, ProxyService.class), proxyServiceConnection, 0)
     ; |  253     bindService(new Intent(this, ProxyService.class), proxyServiceConnection, 0)
     ; | 
|  252   } |  254   } | 
|  253  |  255  | 
|  254   private void disconnect() |  256   private void disconnect() | 
|  255   { |  257   { | 
|  256     unbindService(proxyServiceConnection); |  258     unbindService(proxyServiceConnection); | 
|  257     proxyService = null; |  259     proxyService = null; | 
|  258   } |  260   } | 
|  259  |  261  | 
|  260   private ServiceConnection proxyServiceConnection = new ServiceConnection() |  262   private final ServiceConnection proxyServiceConnection = new ServiceConnection
     () | 
|  261   { |  263   { | 
|  262     public void onServiceConnected(ComponentName className, IBinder service) |  264     @Override | 
 |  265     public void onServiceConnected(final ComponentName className, final IBinder 
     service) | 
|  263     { |  266     { | 
|  264       proxyService = ((ProxyService.LocalBinder) service).getService(); |  267       proxyService = ((ProxyService.LocalBinder) service).getService(); | 
|  265       Log.d(TAG, "Proxy service connected"); |  268       Log.d(TAG, "Proxy service connected"); | 
|  266     } |  269     } | 
|  267  |  270  | 
|  268     public void onServiceDisconnected(ComponentName className) |  271     @Override | 
 |  272     public void onServiceDisconnected(final ComponentName className) | 
|  269     { |  273     { | 
|  270       proxyService = null; |  274       proxyService = null; | 
|  271       Log.d(TAG, "Proxy service disconnected"); |  275       Log.d(TAG, "Proxy service disconnected"); | 
|  272     } |  276     } | 
|  273   }; |  277   }; | 
|  274 } |  278 } | 
| OLD | NEW |