Use more IpManager features

- WaitForProvisioningCallback
    - setHttpProxy
    - setTcpBufferSizes

Bug: 26991160
Change-Id: I5e02039a35006f0466fb40c43805f0443cd758c2
This commit is contained in:
Erik Kline
2016-02-22 11:11:38 +09:00
parent 1cb0138ad3
commit 5774ef5328

View File

@@ -33,6 +33,7 @@ import android.net.NetworkInfo;
import android.net.NetworkInfo.DetailedState;
import android.net.StaticIpConfiguration;
import android.net.ip.IpManager;
import android.net.ip.IpManager.WaitForProvisioningCallback;
import android.os.Handler;
import android.os.IBinder;
import android.os.INetworkManagementService;
@@ -274,36 +275,6 @@ class EthernetNetworkFactory {
}
}
private class IpManagerCallback extends IpManager.Callback {
private LinkProperties mCallbackLinkProperties;
public LinkProperties waitForProvisioning() {
synchronized (this) {
try {
wait();
} catch (InterruptedException e) {}
return mCallbackLinkProperties;
}
}
@Override
public void onProvisioningSuccess(LinkProperties newLp) {
synchronized (this) {
mCallbackLinkProperties = newLp;
notify();
}
}
@Override
public void onProvisioningFailure(LinkProperties newLp) {
synchronized (this) {
mCallbackLinkProperties = null;
notify();
}
}
}
/* Called by the NetworkFactory on the handler thread. */
public void onRequestNetwork() {
synchronized(EthernetNetworkFactory.this) {
@@ -332,13 +303,36 @@ class EthernetNetworkFactory {
linkProperties = config.getStaticIpConfiguration().toLinkProperties(mIface);
} else {
mNetworkInfo.setDetailedState(DetailedState.OBTAINING_IPADDR, null, mHwAddr);
IpManagerCallback blockingCallback = new IpManagerCallback();
WaitForProvisioningCallback ipmCallback = new WaitForProvisioningCallback() {
@Override
public void onLinkPropertiesChange(LinkProperties newLp) {
synchronized(EthernetNetworkFactory.this) {
if (mNetworkAgent != null && mNetworkInfo.isConnected()) {
mNetworkAgent.sendLinkProperties(newLp);
}
}
}
};
synchronized(EthernetNetworkFactory.this) {
stopIpManagerLocked();
mIpManager = new IpManager(mContext, mIface, blockingCallback);
mIpManager = new IpManager(mContext, mIface, ipmCallback);
if (config.getProxySettings() == ProxySettings.STATIC ||
config.getProxySettings() == ProxySettings.PAC) {
mIpManager.setHttpProxy(config.getHttpProxy());
}
final String tcpBufferSizes = mContext.getResources().getString(
com.android.internal.R.string.config_ethernet_tcp_buffers);
if (!TextUtils.isEmpty(tcpBufferSizes)) {
mIpManager.setTcpBufferSizes(tcpBufferSizes);
}
mIpManager.startProvisioning();
}
linkProperties = blockingCallback.waitForProvisioning();
linkProperties = ipmCallback.waitForProvisioning();
if (linkProperties == null) {
Log.e(TAG, "IP provisioning error");
// set our score lower than any network could go
@@ -351,17 +345,6 @@ class EthernetNetworkFactory {
}
}
if (config.getProxySettings() == ProxySettings.STATIC ||
config.getProxySettings() == ProxySettings.PAC) {
linkProperties.setHttpProxy(config.getHttpProxy());
}
final String tcpBufferSizes = mContext.getResources().getString(
com.android.internal.R.string.config_ethernet_tcp_buffers);
if (!TextUtils.isEmpty(tcpBufferSizes)) {
linkProperties.setTcpBufferSizes(tcpBufferSizes);
}
synchronized(EthernetNetworkFactory.this) {
if (mNetworkAgent != null) {
Log.e(TAG, "Already have a NetworkAgent - aborting new request");