Stop using LinkProperties for static configuration.
Bug: 16114392 Bug: 16893413 Change-Id: Ib33f35c004e30b6067bb20235ffa43c247d174df
This commit is contained in:
@@ -24,11 +24,11 @@ import android.net.IpConfiguration;
|
|||||||
import android.net.IpConfiguration.IpAssignment;
|
import android.net.IpConfiguration.IpAssignment;
|
||||||
import android.net.IpConfiguration.ProxySettings;
|
import android.net.IpConfiguration.ProxySettings;
|
||||||
import android.net.LinkAddress;
|
import android.net.LinkAddress;
|
||||||
import android.net.LinkProperties;
|
|
||||||
import android.net.NetworkInfo.DetailedState;
|
import android.net.NetworkInfo.DetailedState;
|
||||||
import android.net.NetworkUtils;
|
import android.net.NetworkUtils;
|
||||||
import android.net.ProxyInfo;
|
import android.net.ProxyInfo;
|
||||||
import android.net.RouteInfo;
|
import android.net.RouteInfo;
|
||||||
|
import android.net.StaticIpConfiguration;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.net.wifi.WifiConfiguration;
|
import android.net.wifi.WifiConfiguration;
|
||||||
import android.net.wifi.WifiConfiguration.AuthAlgorithm;
|
import android.net.wifi.WifiConfiguration.AuthAlgorithm;
|
||||||
@@ -61,6 +61,7 @@ import com.android.settings.ProxySelector;
|
|||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
|
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
|
import java.net.Inet4Address;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -137,7 +138,8 @@ public class WifiConfigController implements TextWatcher,
|
|||||||
|
|
||||||
private IpAssignment mIpAssignment = IpAssignment.UNASSIGNED;
|
private IpAssignment mIpAssignment = IpAssignment.UNASSIGNED;
|
||||||
private ProxySettings mProxySettings = ProxySettings.UNASSIGNED;
|
private ProxySettings mProxySettings = ProxySettings.UNASSIGNED;
|
||||||
private LinkProperties mLinkProperties = new LinkProperties();
|
private ProxyInfo mHttpProxy = null;
|
||||||
|
private StaticIpConfiguration mStaticIpConfiguration = null;
|
||||||
|
|
||||||
private String[] mLevels;
|
private String[] mLevels;
|
||||||
private boolean mEdit;
|
private boolean mEdit;
|
||||||
@@ -216,13 +218,15 @@ public class WifiConfigController implements TextWatcher,
|
|||||||
if (config.getIpAssignment() == IpAssignment.STATIC) {
|
if (config.getIpAssignment() == IpAssignment.STATIC) {
|
||||||
mIpSettingsSpinner.setSelection(STATIC_IP);
|
mIpSettingsSpinner.setSelection(STATIC_IP);
|
||||||
showAdvancedFields = true;
|
showAdvancedFields = true;
|
||||||
|
// Display IP address.
|
||||||
|
StaticIpConfiguration staticConfig = config.getStaticIpConfiguration();
|
||||||
|
if (staticConfig != null && staticConfig.ipAddress != null) {
|
||||||
|
addRow(group, R.string.wifi_ip_address,
|
||||||
|
staticConfig.ipAddress.getAddress().getHostAddress());
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
mIpSettingsSpinner.setSelection(DHCP);
|
mIpSettingsSpinner.setSelection(DHCP);
|
||||||
}
|
}
|
||||||
//Display IP addresses
|
|
||||||
for(InetAddress a : config.getLinkProperties().getAddresses()) {
|
|
||||||
addRow(group, R.string.wifi_ip_address, a.getHostAddress());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (config.getProxySettings() == ProxySettings.STATIC) {
|
if (config.getProxySettings() == ProxySettings.STATIC) {
|
||||||
@@ -462,19 +466,20 @@ public class WifiConfigController implements TextWatcher,
|
|||||||
}
|
}
|
||||||
|
|
||||||
config.setIpConfiguration(
|
config.setIpConfiguration(
|
||||||
new IpConfiguration(mIpAssignment, mProxySettings, mLinkProperties));
|
new IpConfiguration(mIpAssignment, mProxySettings,
|
||||||
|
mStaticIpConfiguration, mHttpProxy));
|
||||||
|
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean ipAndProxyFieldsAreValid() {
|
private boolean ipAndProxyFieldsAreValid() {
|
||||||
mLinkProperties.clear();
|
|
||||||
mIpAssignment = (mIpSettingsSpinner != null &&
|
mIpAssignment = (mIpSettingsSpinner != null &&
|
||||||
mIpSettingsSpinner.getSelectedItemPosition() == STATIC_IP) ?
|
mIpSettingsSpinner.getSelectedItemPosition() == STATIC_IP) ?
|
||||||
IpAssignment.STATIC : IpAssignment.DHCP;
|
IpAssignment.STATIC : IpAssignment.DHCP;
|
||||||
|
|
||||||
if (mIpAssignment == IpAssignment.STATIC) {
|
if (mIpAssignment == IpAssignment.STATIC) {
|
||||||
int result = validateIpConfigFields(mLinkProperties);
|
mStaticIpConfiguration = new StaticIpConfiguration();
|
||||||
|
int result = validateIpConfigFields(mStaticIpConfiguration);
|
||||||
if (result != 0) {
|
if (result != 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -482,6 +487,7 @@ public class WifiConfigController implements TextWatcher,
|
|||||||
|
|
||||||
final int selectedPosition = mProxySettingsSpinner.getSelectedItemPosition();
|
final int selectedPosition = mProxySettingsSpinner.getSelectedItemPosition();
|
||||||
mProxySettings = ProxySettings.NONE;
|
mProxySettings = ProxySettings.NONE;
|
||||||
|
mHttpProxy = null;
|
||||||
if (selectedPosition == PROXY_STATIC && mProxyHostView != null) {
|
if (selectedPosition == PROXY_STATIC && mProxyHostView != null) {
|
||||||
mProxySettings = ProxySettings.STATIC;
|
mProxySettings = ProxySettings.STATIC;
|
||||||
String host = mProxyHostView.getText().toString();
|
String host = mProxyHostView.getText().toString();
|
||||||
@@ -496,8 +502,7 @@ public class WifiConfigController implements TextWatcher,
|
|||||||
result = R.string.proxy_error_invalid_port;
|
result = R.string.proxy_error_invalid_port;
|
||||||
}
|
}
|
||||||
if (result == 0) {
|
if (result == 0) {
|
||||||
ProxyInfo proxyProperties= new ProxyInfo(host, port, exclusionList);
|
mHttpProxy = new ProxyInfo(host, port, exclusionList);
|
||||||
mLinkProperties.setHttpProxy(proxyProperties);
|
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -511,22 +516,27 @@ public class WifiConfigController implements TextWatcher,
|
|||||||
if (uri == null) {
|
if (uri == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
ProxyInfo proxyInfo = new ProxyInfo(uri);
|
mHttpProxy = new ProxyInfo(uri);
|
||||||
mLinkProperties.setHttpProxy(proxyInfo);
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int validateIpConfigFields(LinkProperties linkProperties) {
|
private Inet4Address getIPv4Address(String text) {
|
||||||
|
try {
|
||||||
|
return (Inet4Address) NetworkUtils.numericToInetAddress(text);
|
||||||
|
} catch (IllegalArgumentException|ClassCastException e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private int validateIpConfigFields(StaticIpConfiguration staticIpConfiguration) {
|
||||||
if (mIpAddressView == null) return 0;
|
if (mIpAddressView == null) return 0;
|
||||||
|
|
||||||
String ipAddr = mIpAddressView.getText().toString();
|
String ipAddr = mIpAddressView.getText().toString();
|
||||||
if (TextUtils.isEmpty(ipAddr)) return R.string.wifi_ip_settings_invalid_ip_address;
|
if (TextUtils.isEmpty(ipAddr)) return R.string.wifi_ip_settings_invalid_ip_address;
|
||||||
|
|
||||||
InetAddress inetAddr = null;
|
Inet4Address inetAddr = getIPv4Address(ipAddr);
|
||||||
try {
|
if (inetAddr == null) {
|
||||||
inetAddr = NetworkUtils.numericToInetAddress(ipAddr);
|
|
||||||
} catch (IllegalArgumentException e) {
|
|
||||||
return R.string.wifi_ip_settings_invalid_ip_address;
|
return R.string.wifi_ip_settings_invalid_ip_address;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -536,7 +546,7 @@ public class WifiConfigController implements TextWatcher,
|
|||||||
if (networkPrefixLength < 0 || networkPrefixLength > 32) {
|
if (networkPrefixLength < 0 || networkPrefixLength > 32) {
|
||||||
return R.string.wifi_ip_settings_invalid_network_prefix_length;
|
return R.string.wifi_ip_settings_invalid_network_prefix_length;
|
||||||
}
|
}
|
||||||
linkProperties.addLinkAddress(new LinkAddress(inetAddr, networkPrefixLength));
|
staticIpConfiguration.ipAddress = new LinkAddress(inetAddr, networkPrefixLength);
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
// Set the hint as default after user types in ip address
|
// Set the hint as default after user types in ip address
|
||||||
mNetworkPrefixLengthView.setText(mConfigUi.getContext().getString(
|
mNetworkPrefixLengthView.setText(mConfigUi.getContext().getString(
|
||||||
@@ -555,13 +565,11 @@ public class WifiConfigController implements TextWatcher,
|
|||||||
} catch (java.net.UnknownHostException u) {
|
} catch (java.net.UnknownHostException u) {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
InetAddress gatewayAddr = null;
|
InetAddress gatewayAddr = getIPv4Address(gateway);
|
||||||
try {
|
if (gatewayAddr == null) {
|
||||||
gatewayAddr = NetworkUtils.numericToInetAddress(gateway);
|
|
||||||
} catch (IllegalArgumentException e) {
|
|
||||||
return R.string.wifi_ip_settings_invalid_gateway;
|
return R.string.wifi_ip_settings_invalid_gateway;
|
||||||
}
|
}
|
||||||
linkProperties.addRoute(new RouteInfo(gatewayAddr));
|
staticIpConfiguration.gateway = gatewayAddr;
|
||||||
}
|
}
|
||||||
|
|
||||||
String dns = mDns1View.getText().toString();
|
String dns = mDns1View.getText().toString();
|
||||||
@@ -571,22 +579,20 @@ public class WifiConfigController implements TextWatcher,
|
|||||||
//If everything else is valid, provide hint as a default option
|
//If everything else is valid, provide hint as a default option
|
||||||
mDns1View.setText(mConfigUi.getContext().getString(R.string.wifi_dns1_hint));
|
mDns1View.setText(mConfigUi.getContext().getString(R.string.wifi_dns1_hint));
|
||||||
} else {
|
} else {
|
||||||
try {
|
dnsAddr = getIPv4Address(dns);
|
||||||
dnsAddr = NetworkUtils.numericToInetAddress(dns);
|
if (dnsAddr == null) {
|
||||||
} catch (IllegalArgumentException e) {
|
|
||||||
return R.string.wifi_ip_settings_invalid_dns;
|
return R.string.wifi_ip_settings_invalid_dns;
|
||||||
}
|
}
|
||||||
linkProperties.addDnsServer(dnsAddr);
|
staticIpConfiguration.dnsServers.add(dnsAddr);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mDns2View.length() > 0) {
|
if (mDns2View.length() > 0) {
|
||||||
dns = mDns2View.getText().toString();
|
dns = mDns2View.getText().toString();
|
||||||
try {
|
dnsAddr = getIPv4Address(dns);
|
||||||
dnsAddr = NetworkUtils.numericToInetAddress(dns);
|
if (dnsAddr == null) {
|
||||||
} catch (IllegalArgumentException e) {
|
|
||||||
return R.string.wifi_ip_settings_invalid_dns;
|
return R.string.wifi_ip_settings_invalid_dns;
|
||||||
}
|
}
|
||||||
linkProperties.addDnsServer(dnsAddr);
|
staticIpConfiguration.dnsServers.add(dnsAddr);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -797,23 +803,20 @@ public class WifiConfigController implements TextWatcher,
|
|||||||
mDns2View.addTextChangedListener(this);
|
mDns2View.addTextChangedListener(this);
|
||||||
}
|
}
|
||||||
if (config != null) {
|
if (config != null) {
|
||||||
LinkProperties linkProperties = config.getLinkProperties();
|
StaticIpConfiguration staticConfig = config.getStaticIpConfiguration();
|
||||||
Iterator<LinkAddress> iterator = linkProperties.getLinkAddresses().iterator();
|
if (staticConfig != null) {
|
||||||
if (iterator.hasNext()) {
|
if (staticConfig.ipAddress != null) {
|
||||||
LinkAddress linkAddress = iterator.next();
|
mIpAddressView.setText(
|
||||||
mIpAddressView.setText(linkAddress.getAddress().getHostAddress());
|
staticConfig.ipAddress.getAddress().getHostAddress());
|
||||||
mNetworkPrefixLengthView.setText(Integer.toString(linkAddress
|
mNetworkPrefixLengthView.setText(Integer.toString(staticConfig.ipAddress
|
||||||
.getNetworkPrefixLength()));
|
.getNetworkPrefixLength()));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (RouteInfo route : linkProperties.getRoutes()) {
|
if (staticConfig.gateway != null) {
|
||||||
if (route.isDefaultRoute()) {
|
mGatewayView.setText(staticConfig.gateway.getHostAddress());
|
||||||
mGatewayView.setText(route.getGateway().getHostAddress());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Iterator<InetAddress> dnsIterator = linkProperties.getDnsServers().iterator();
|
Iterator<InetAddress> dnsIterator = staticConfig.dnsServers.iterator();
|
||||||
if (dnsIterator.hasNext()) {
|
if (dnsIterator.hasNext()) {
|
||||||
mDns1View.setText(dnsIterator.next().getHostAddress());
|
mDns1View.setText(dnsIterator.next().getHostAddress());
|
||||||
}
|
}
|
||||||
@@ -821,6 +824,7 @@ public class WifiConfigController implements TextWatcher,
|
|||||||
mDns2View.setText(dnsIterator.next().getHostAddress());
|
mDns2View.setText(dnsIterator.next().getHostAddress());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
mView.findViewById(R.id.staticip).setVisibility(View.GONE);
|
mView.findViewById(R.id.staticip).setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
@@ -848,7 +852,7 @@ public class WifiConfigController implements TextWatcher,
|
|||||||
mProxyExclusionListView.addTextChangedListener(this);
|
mProxyExclusionListView.addTextChangedListener(this);
|
||||||
}
|
}
|
||||||
if (config != null) {
|
if (config != null) {
|
||||||
ProxyInfo proxyProperties = config.getLinkProperties().getHttpProxy();
|
ProxyInfo proxyProperties = config.getHttpProxy();
|
||||||
if (proxyProperties != null) {
|
if (proxyProperties != null) {
|
||||||
mProxyHostView.setText(proxyProperties.getHost());
|
mProxyHostView.setText(proxyProperties.getHost());
|
||||||
mProxyPortView.setText(Integer.toString(proxyProperties.getPort()));
|
mProxyPortView.setText(Integer.toString(proxyProperties.getPort()));
|
||||||
@@ -865,7 +869,7 @@ public class WifiConfigController implements TextWatcher,
|
|||||||
mProxyPacView.addTextChangedListener(this);
|
mProxyPacView.addTextChangedListener(this);
|
||||||
}
|
}
|
||||||
if (config != null) {
|
if (config != null) {
|
||||||
ProxyInfo proxyInfo = config.getLinkProperties().getHttpProxy();
|
ProxyInfo proxyInfo = config.getHttpProxy();
|
||||||
if (proxyInfo != null) {
|
if (proxyInfo != null) {
|
||||||
mProxyPacView.setText(proxyInfo.getPacFileUrl().toString());
|
mProxyPacView.setText(proxyInfo.getPacFileUrl().toString());
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user