| 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 59     try | 59     try | 
| 60     { | 60     { | 
| 61       final ConnectivityManager conMan = (ConnectivityManager) context.getSystem
     Service(Context.CONNECTIVITY_SERVICE); | 61       final ConnectivityManager conMan = (ConnectivityManager) context.getSystem
     Service(Context.CONNECTIVITY_SERVICE); | 
| 62       final NetworkInfo ni = conMan.getActiveNetworkInfo(); | 62       final NetworkInfo ni = conMan.getActiveNetworkInfo(); | 
| 63 | 63 | 
| 64       final Object lp; | 64       final Object lp; | 
| 65 | 65 | 
| 66       // Check if we're currently running on WiFi | 66       // Check if we're currently running on WiFi | 
| 67       if (ni != null && ni.getType() == ConnectivityManager.TYPE_WIFI) | 67       if (ni != null && ni.getType() == ConnectivityManager.TYPE_WIFI) | 
| 68       { | 68       { | 
| 69         // I'm using reflection directly here to keep this method self-contained
     . | 69         // We're using reflection directly here to keep this method self-contain
     ed. | 
| 70         lp = conMan.getClass() | 70         lp = conMan.getClass() | 
| 71             .getMethod("getActiveLinkProperties") | 71             .getMethod("getActiveLinkProperties") | 
| 72             .invoke(conMan); | 72             .invoke(conMan); | 
| 73       } | 73       } | 
| 74       else | 74       else | 
| 75       // We're not running on WiFi so get the last used WiFi link properties | 75       // We're not running on WiFi so get the last used WiFi link properties | 
| 76       { | 76       { | 
| 77         // I'm using reflection directly here to keep this method self-contained
     . | 77         // We're using reflection directly here to keep this method self-contain
     ed. | 
| 78         lp = conMan.getClass() | 78         lp = conMan.getClass() | 
| 79             .getMethod("getLinkProperties", int.class) | 79             .getMethod("getLinkProperties", int.class) | 
| 80             .invoke(conMan, ConnectivityManager.TYPE_WIFI); | 80             .invoke(conMan, ConnectivityManager.TYPE_WIFI); | 
| 81       } | 81       } | 
| 82 | 82 | 
| 83       if (lp == null) | 83       if (lp == null) | 
| 84       { | 84       { | 
| 85         // Is this even possible? | 85         // Is this even possible? | 
| 86         throw new IllegalStateException("No WiFi?"); | 86         throw new IllegalStateException("No WiFi?"); | 
| 87       } | 87       } | 
| (...skipping 17 matching lines...) Expand all  Loading... | 
| 105     { | 105     { | 
| 106       this.context.registerReceiver(this.wiFiChangeReceiver, new IntentFilter(Co
     nnectivityManager.CONNECTIVITY_ACTION)); | 106       this.context.registerReceiver(this.wiFiChangeReceiver, new IntentFilter(Co
     nnectivityManager.CONNECTIVITY_ACTION)); | 
| 107       return true; | 107       return true; | 
| 108     } | 108     } | 
| 109 | 109 | 
| 110     return false; | 110     return false; | 
| 111   } | 111   } | 
| 112 | 112 | 
| 113   private boolean sendIntent(final LinkProperties lp, final ProxyProperties prox
     yProperties) | 113   private boolean sendIntent(final LinkProperties lp, final ProxyProperties prox
     yProperties) | 
| 114   { | 114   { | 
| 115     boolean success = true; |  | 
| 116 |  | 
| 117     final ConnectivityManager conMan = (ConnectivityManager) context.getSystemSe
     rvice(Context.CONNECTIVITY_SERVICE); | 115     final ConnectivityManager conMan = (ConnectivityManager) context.getSystemSe
     rvice(Context.CONNECTIVITY_SERVICE); | 
| 118     final NetworkInfo ni = conMan.getActiveNetworkInfo(); | 116     final NetworkInfo ni = conMan.getActiveNetworkInfo(); | 
| 119 | 117 | 
| 120     if (ni != null && ni.getType() == ConnectivityManager.TYPE_WIFI) | 118     if (ni != null && ni.getType() == ConnectivityManager.TYPE_WIFI) | 
| 121     { | 119     { | 
| 122       final Intent intent = new Intent("android.net.wifi.LINK_CONFIGURATION_CHAN
     GED"); | 120       final Intent intent = new Intent("android.net.wifi.LINK_CONFIGURATION_CHAN
     GED"); | 
| 123 | 121 | 
| 124       if (lp.isValid()) | 122       if (lp.isValid()) | 
| 125       { | 123       { | 
| 126         try | 124         try | 
| 127         { | 125         { | 
| 128           lp.setHttpProxy(proxyProperties); | 126           lp.setHttpProxy(proxyProperties); | 
| 129           intent.putExtra("linkProperties", (Parcelable) lp.getLinkProperties())
     ; | 127           intent.putExtra("linkProperties", (Parcelable) lp.getLinkProperties())
     ; | 
| 130           context.sendBroadcast(intent); | 128           context.sendBroadcast(intent); | 
| 131         } | 129         } | 
| 132         catch (final Exception e) | 130         catch (final Exception e) | 
| 133         { | 131         { | 
| 134           // Catch all, again | 132           // Catch all, again | 
| 135           success = false; | 133           return false; | 
| 136         } | 134         } | 
| 137       } | 135       } | 
| 138     } | 136     } | 
| 139 | 137 | 
| 140     return success; | 138     return true; | 
| 141   } | 139   } | 
| 142 | 140 | 
| 143   private boolean registerProxy(final ProxyProperties proxyProperties) | 141   private boolean registerProxy(final ProxyProperties proxyProperties) | 
| 144   { | 142   { | 
| 145     try | 143     try | 
| 146     { | 144     { | 
| 147       final ConnectivityManager conMan = (ConnectivityManager) context.getSystem
     Service(Context.CONNECTIVITY_SERVICE); | 145       final ConnectivityManager conMan = (ConnectivityManager) context.getSystem
     Service(Context.CONNECTIVITY_SERVICE); | 
| 148 | 146 | 
| 149       return this.sendIntent(LinkProperties.getActiveLinkProperties(conMan), pro
     xyProperties); | 147       return this.sendIntent(LinkProperties.getActiveLinkProperties(conMan), pro
     xyProperties); | 
| 150     } | 148     } | 
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 223         final NetworkInfo ni = connectivityManager.getActiveNetworkInfo(); | 221         final NetworkInfo ni = connectivityManager.getActiveNetworkInfo(); | 
| 224 | 222 | 
| 225         if (ni != null && ni.getType() == ConnectivityManager.TYPE_WIFI && ni.is
     Available() && ni.isConnected()) | 223         if (ni != null && ni.getType() == ConnectivityManager.TYPE_WIFI && ni.is
     Available() && ni.isConnected()) | 
| 226         { | 224         { | 
| 227           this.configurator.reRegisterProxy(); | 225           this.configurator.reRegisterProxy(); | 
| 228         } | 226         } | 
| 229       } | 227       } | 
| 230     } | 228     } | 
| 231   } | 229   } | 
| 232 } | 230 } | 
| LEFT | RIGHT | 
|---|