|
@@ -33,8 +33,7 @@ public class ProxySetting {
|
|
|
public static void setEnumField(Object obj, String value, String name)
|
|
|
throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException {
|
|
|
Field f = obj.getClass().getField(name);
|
|
|
-// Type safety: Unchecked invocation valueOf(Class<Enum>, String) of the generic method valueOf(Class<T>, String) of type Enum
|
|
|
- f.set(obj, Enum.valueOf((Class<Enum>) f.getType(), value));
|
|
|
+ f.set(obj, Enum.valueOf((Class<Enum>) f.getType(), value));
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -64,23 +63,14 @@ public class ProxySetting {
|
|
|
public static WifiConfiguration getCurrentWifiConfiguration(WifiManager wifiManager) {
|
|
|
if (!wifiManager.isWifiEnabled())
|
|
|
return null;// 没有打开wifi
|
|
|
-
|
|
|
List<WifiConfiguration> configurationList = wifiManager.getConfiguredNetworks();
|
|
|
-
|
|
|
WifiConfiguration configuration = null;
|
|
|
-
|
|
|
int cur = wifiManager.getConnectionInfo().getNetworkId();
|
|
|
-
|
|
|
for (int i = 0; i < configurationList.size(); ++i) {
|
|
|
-
|
|
|
WifiConfiguration wifiConfiguration = configurationList.get(i);
|
|
|
-
|
|
|
if (wifiConfiguration.networkId == cur)
|
|
|
-
|
|
|
configuration = wifiConfiguration;
|
|
|
-
|
|
|
}
|
|
|
-
|
|
|
return configuration;
|
|
|
}
|
|
|
|
|
@@ -93,15 +83,14 @@ public class ProxySetting {
|
|
|
* @param port
|
|
|
* 代理端口
|
|
|
* @param exclList
|
|
|
+ * 添加不用代理的网址
|
|
|
*/
|
|
|
public static void setWifiProxySettingsFor17And(Context context, String host, int port, String exclList) {
|
|
|
WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
|
|
|
- WifiConfiguration config;
|
|
|
- config = getCurrentWifiConfiguration(wifiManager);
|
|
|
+ WifiConfiguration config = getCurrentWifiConfiguration(wifiManager);
|
|
|
if (config == null)
|
|
|
return;
|
|
|
try {
|
|
|
- // get the link properties from the wifi configuration
|
|
|
Object linkProperties = getFieldObject(config, "linkProperties");
|
|
|
if (null == linkProperties)
|
|
|
return;
|
|
@@ -115,9 +104,8 @@ public class ProxySetting {
|
|
|
// 获取类 ProxyProperties的构造函数
|
|
|
Constructor<?> proxyPropertiesCtor = proxyPropertiesClass.getConstructor(String.class, int.class,
|
|
|
String.class);
|
|
|
- // 实例化类ProxyProperties Object proxySettings
|
|
|
- // =proxyPropertiesCtor.newInstance(host, port, exclList);
|
|
|
- // pass the new object to setHttpProxy
|
|
|
+ // 实例化类ProxyProperties
|
|
|
+ proxySettings = proxyPropertiesCtor.newInstance(host, port, exclList);
|
|
|
Object[] params = new Object[1];
|
|
|
params[0] = proxySettings;
|
|
|
setHttpProxy.invoke(linkProperties, params);
|
|
@@ -137,12 +125,10 @@ public class ProxySetting {
|
|
|
*/
|
|
|
public static void unsetWifiProxySettingsFor17And(Context context) {
|
|
|
WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
|
|
|
- WifiConfiguration config;
|
|
|
- config = getCurrentWifiConfiguration(wifiManager);
|
|
|
+ WifiConfiguration config = getCurrentWifiConfiguration(wifiManager);
|
|
|
if (null == config)
|
|
|
return;
|
|
|
try {
|
|
|
- // get the link properties from the wifi configuration
|
|
|
Object linkProperties = getFieldObject(config, "linkProperties");
|
|
|
if (null == linkProperties)
|
|
|
return;
|