| LEFT | RIGHT |
| 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 | 56 |
| 57 import com.stericson.RootTools.RootTools; | 57 import com.stericson.RootTools.RootTools; |
| 58 import com.stericson.RootTools.RootToolsException; | 58 import com.stericson.RootTools.RootToolsException; |
| 59 | 59 |
| 60 public class ProxyService extends Service implements OnSharedPreferenceChangeLis
tener | 60 public class ProxyService extends Service implements OnSharedPreferenceChangeLis
tener |
| 61 { | 61 { |
| 62 private static final String LOCALHOST = "127.0.0.1"; | 62 private static final String LOCALHOST = "127.0.0.1"; |
| 63 /** | 63 /** |
| 64 * Indicates that system supports native proxy configuration. | 64 * Indicates that system supports native proxy configuration. |
| 65 */ | 65 */ |
| 66 public static final boolean NATIVE_PROXY_SUPPORTED = Build.VERSION.SDK_INT >=
12; // Honeycomb | 66 public static final boolean NATIVE_PROXY_SUPPORTED = Build.VERSION.SDK_INT >=
12; // Honeycomb 3.1 |
| 67 | 67 |
| 68 static | 68 static |
| 69 { | 69 { |
| 70 RootTools.debugMode = false; | 70 RootTools.debugMode = false; |
| 71 } | 71 } |
| 72 | 72 |
| 73 private static final String TAG = Utils.getTag(ProxyService.class); | 73 private static final String TAG = Utils.getTag(ProxyService.class); |
| 74 private static final boolean logRequests = false; | 74 private static final boolean logRequests = false; |
| 75 | 75 |
| 76 // Do not use 8080 because it is a "dirty" port, Android uses it if something
goes wrong | 76 // Do not use 8080 because it is a "dirty" port, Android uses it if something
goes wrong |
| 77 // first element is reserved for previously used port | 77 // first element is reserved for previously used port |
| 78 private static final int[] portVariants = new int[] { -1, 2020, 3030, 4040, 50
50, 6060, 7070, 9090, 1234, 12345, 4321, 0 }; | 78 private static final int[] portVariants = new int[] {-1, 2020, 3030, 4040, 505
0, 6060, 7070, 9090, 1234, 12345, 4321, 0}; |
| 79 | 79 |
| 80 private static final int DEFAULT_TIMEOUT = 3000; | 80 private static final int DEFAULT_TIMEOUT = 3000; |
| 81 private static final int NO_TRAFFIC_TIMEOUT = 5 * 60 * 1000; // 5 minutes | 81 private static final int NO_TRAFFIC_TIMEOUT = 5 * 60 * 1000; // 5 minutes |
| 82 | 82 |
| 83 static final int ONGOING_NOTIFICATION_ID = R.string.app_name; | 83 static final int ONGOING_NOTIFICATION_ID = R.string.app_name; |
| 84 private static final long POSITION_RIGHT = Build.VERSION.SDK_INT >= Build.VERS
ION_CODES.GINGERBREAD ? Long.MIN_VALUE : Long.MAX_VALUE; | 84 private static final long POSITION_RIGHT = Build.VERSION.SDK_INT >= Build.VERS
ION_CODES.GINGERBREAD ? Long.MIN_VALUE : Long.MAX_VALUE; |
| 85 private static final int NOTRAFFIC_NOTIFICATION_ID = R.string.app_name + 3; | 85 private static final int NOTRAFFIC_NOTIFICATION_ID = R.string.app_name + 3; |
| 86 | 86 |
| 87 /** | 87 /** |
| 88 * Broadcasted when service starts or stops. | 88 * Broadcasted when service starts or stops. |
| (...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 if (proxy != null) | 382 if (proxy != null) |
| 383 proxy.close(); | 383 proxy.close(); |
| 384 | 384 |
| 385 // Release service lock | 385 // Release service lock |
| 386 stopForeground(true); | 386 stopForeground(true); |
| 387 | 387 |
| 388 Log.i(TAG, "Service stopped"); | 388 Log.i(TAG, "Service stopped"); |
| 389 } | 389 } |
| 390 | 390 |
| 391 /** | 391 /** |
| 392 * Restores system proxy settings via native call on Android 3.1+ devices usin
g Java reflection. | 392 * Restores system proxy settings via native call on Android 3.1+ devices |
| 393 * using Java reflection. |
| 393 */ | 394 */ |
| 394 private void clearConnectionProxy() | 395 private void clearConnectionProxy() |
| 395 { | 396 { |
| 396 final String proxyHost = proxyConfiguration.getProperty("adblock.proxyHost")
; | 397 final String proxyHost = proxyConfiguration.getProperty("adblock.proxyHost")
; |
| 397 final String proxyPort = proxyConfiguration.getProperty("adblock.proxyPort")
; | 398 final String proxyPort = proxyConfiguration.getProperty("adblock.proxyPort")
; |
| 398 final String proxyExcl = proxyConfiguration.getProperty("adblock.proxyExcl")
; | 399 final String proxyExcl = proxyConfiguration.getProperty("adblock.proxyExcl")
; |
| 399 int port = 0; | 400 int port = 0; |
| 400 try | 401 try |
| 401 { | 402 { |
| 402 if (proxyHost != null) | 403 if (proxyHost != null) |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 628 return RootTools.sendShell(command, DEFAULT_TIMEOUT); | 629 return RootTools.sendShell(command, DEFAULT_TIMEOUT); |
| 629 } | 630 } |
| 630 catch (final Exception e) | 631 catch (final Exception e) |
| 631 { | 632 { |
| 632 Log.e(TAG, "Failed to get iptables configuration", e); | 633 Log.e(TAG, "Failed to get iptables configuration", e); |
| 633 return null; | 634 return null; |
| 634 } | 635 } |
| 635 } | 636 } |
| 636 | 637 |
| 637 /** | 638 /** |
| 638 * Raises or removes no traffic notification based on current link proxy setti
ngs | 639 * Raises or removes no traffic notification based on current link proxy |
| 640 * settings |
| 639 */ | 641 */ |
| 640 private void updateNoTrafficCheck(final ConnectivityManager connectivityManage
r) | 642 private void updateNoTrafficCheck(final ConnectivityManager connectivityManage
r) |
| 641 { | 643 { |
| 642 try | 644 try |
| 643 { | 645 { |
| 644 final Object pp = ProxySettings.getActiveLinkProxy(connectivityManager); | 646 final Object pp = ProxySettings.getActiveLinkProxy(connectivityManager); |
| 645 final String[] userProxy = ProxySettings.getUserProxy(pp); | 647 final String[] userProxy = ProxySettings.getUserProxy(pp); |
| 646 if (userProxy != null) | 648 if (userProxy != null) |
| 647 Log.i(TAG, "Proxy settings: " + userProxy[0] + ":" + userProxy[1] + "("
+ userProxy[2] + ")"); | 649 Log.i(TAG, "Proxy settings: " + userProxy[0] + ":" + userProxy[1] + "("
+ userProxy[2] + ")"); |
| 648 updateNoTrafficCheck(userProxy); | 650 updateNoTrafficCheck(userProxy); |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 755 } | 757 } |
| 756 } | 758 } |
| 757 | 759 |
| 758 @Override | 760 @Override |
| 759 public IBinder onBind(final Intent intent) | 761 public IBinder onBind(final Intent intent) |
| 760 { | 762 { |
| 761 return binder; | 763 return binder; |
| 762 } | 764 } |
| 763 | 765 |
| 764 /** | 766 /** |
| 765 * Executed if no traffic is detected after a period of time. Notifies user ab
out possible | 767 * Executed if no traffic is detected after a period of time. Notifies user |
| 766 * configuration problems. | 768 * about possible configuration problems. |
| 767 */ | 769 */ |
| 768 private final Runnable noTraffic = new Runnable() | 770 private final Runnable noTraffic = new Runnable() |
| 769 { | 771 { |
| 770 @Override | 772 @Override |
| 771 public void run() | 773 public void run() |
| 772 { | 774 { |
| 773 // It's weird but notrafficHandler.removeCallbacks(noTraffic) does not rem
ove this callback | 775 // It's weird but notrafficHandler.removeCallbacks(noTraffic) does not rem
ove this callback |
| 774 if (notrafficHandler == null) | 776 if (notrafficHandler == null) |
| 775 return; | 777 return; |
| 776 // Show warning notification | 778 // Show warning notification |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 826 public void onReceive(final Context context, final Intent intent) | 828 public void onReceive(final Context context, final Intent intent) |
| 827 { | 829 { |
| 828 if (intent.getAction().equals(ProxyService.BROADCAST_PROXY_FAILED)) | 830 if (intent.getAction().equals(ProxyService.BROADCAST_PROXY_FAILED)) |
| 829 { | 831 { |
| 830 stopSelf(); | 832 stopSelf(); |
| 831 } | 833 } |
| 832 } | 834 } |
| 833 }; | 835 }; |
| 834 | 836 |
| 835 /** | 837 /** |
| 836 * Monitors system network connection settings changes and updates proxy setti
ngs accordingly. | 838 * Monitors system network connection settings changes and updates proxy |
| 839 * settings accordingly. |
| 837 */ | 840 */ |
| 838 private final BroadcastReceiver connectionReceiver = new BroadcastReceiver() | 841 private final BroadcastReceiver connectionReceiver = new BroadcastReceiver() |
| 839 { | 842 { |
| 840 @Override | 843 @Override |
| 841 public void onReceive(final Context ctx, final Intent intent) | 844 public void onReceive(final Context ctx, final Intent intent) |
| 842 { | 845 { |
| 843 final String action = intent.getAction(); | 846 final String action = intent.getAction(); |
| 844 Log.i(TAG, "Action: " + action); | 847 Log.i(TAG, "Action: " + action); |
| 845 // Connectivity change | 848 // Connectivity change |
| 846 if (ConnectivityManager.CONNECTIVITY_ACTION.equals(action)) | 849 if (ConnectivityManager.CONNECTIVITY_ACTION.equals(action)) |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 922 @Override | 925 @Override |
| 923 public void log(final int level, final Object obj, final String message) | 926 public void log(final int level, final Object obj, final String message) |
| 924 { | 927 { |
| 925 if (level <= logLevel) | 928 if (level <= logLevel) |
| 926 { | 929 { |
| 927 Log.println(7 - level, obj != null ? obj.toString() : TAG, message); | 930 Log.println(7 - level, obj != null ? obj.toString() : TAG, message); |
| 928 } | 931 } |
| 929 } | 932 } |
| 930 } | 933 } |
| 931 } | 934 } |
| LEFT | RIGHT |