|
@@ -15,7 +15,7 @@ import android.net.wifi.WifiManager;
|
|
|
* @author liuyuqi
|
|
|
*
|
|
|
*/
|
|
|
-public class ProxySetting {
|
|
|
+public class WifiProxyManager {
|
|
|
|
|
|
private static Object proxySettings;
|
|
|
|
|
@@ -47,13 +47,23 @@ public class ProxySetting {
|
|
|
* @throws IllegalArgumentException
|
|
|
* @throws IllegalAccessException
|
|
|
*/
|
|
|
- public static Object getFieldObject(Object obj, String name)
|
|
|
+ public static Object getDeclaredFieldObject(Object obj, String name)
|
|
|
throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException {
|
|
|
Field f = obj.getClass().getField(name);
|
|
|
Object out = f.get(obj);
|
|
|
return out;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @param config
|
|
|
+ * @param string
|
|
|
+ * @param mIpConfiguration
|
|
|
+ */
|
|
|
+ private static void setDeclardFildObject(WifiConfiguration config, String string, Object mIpConfiguration) {
|
|
|
+ // TODO Auto-generated method stub
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 获取当前WiFi状态
|
|
|
*
|
|
@@ -91,7 +101,7 @@ public class ProxySetting {
|
|
|
if (config == null)
|
|
|
return;
|
|
|
try {
|
|
|
- Object linkProperties = getFieldObject(config, "linkProperties");
|
|
|
+ Object linkProperties = getDeclaredFieldObject(config, "linkProperties");
|
|
|
if (null == linkProperties)
|
|
|
return;
|
|
|
// 获取类 LinkProperties的setHttpProxy方法
|
|
@@ -129,7 +139,7 @@ public class ProxySetting {
|
|
|
if (null == config)
|
|
|
return;
|
|
|
try {
|
|
|
- Object linkProperties = getFieldObject(config, "linkProperties");
|
|
|
+ Object linkProperties = getDeclaredFieldObject(config, "linkProperties");
|
|
|
if (null == linkProperties)
|
|
|
return;
|
|
|
// get the setHttpProxy method for LinkProperties
|
|
@@ -144,7 +154,7 @@ public class ProxySetting {
|
|
|
params[0] = null;
|
|
|
setHttpProxy.invoke(linkProperties, params);
|
|
|
setEnumField(config, "NONE", "proxySettings");
|
|
|
- // save the config
|
|
|
+
|
|
|
wifiManager.updateNetwork(config);
|
|
|
wifiManager.disconnect();
|
|
|
wifiManager.reconnect();
|