From 06f159c8aad3379d037a828d5b1bbdf85d6f4796 Mon Sep 17 00:00:00 2001 From: Remi NGUYEN VAN Date: Fri, 11 Jan 2019 09:43:04 +0900 Subject: Use IIpClient in LowpanInterfaceTracker Test: make lowpan-service Bug: b/112869080 Exempt-From-Owner-Approval: owner and team lead both unavailable Change-Id: Ic294324d1a8f9b9ad076043554c1b781d7ee14e0 --- .../server/lowpan/LowpanInterfaceTracker.java | 63 +++++++++++++++++----- 1 file changed, 50 insertions(+), 13 deletions(-) diff --git a/service/java/com/android/server/lowpan/LowpanInterfaceTracker.java b/service/java/com/android/server/lowpan/LowpanInterfaceTracker.java index 69842c2..f863d3d 100644 --- a/service/java/com/android/server/lowpan/LowpanInterfaceTracker.java +++ b/service/java/com/android/server/lowpan/LowpanInterfaceTracker.java @@ -27,13 +27,16 @@ import android.net.NetworkCapabilities; import android.net.NetworkFactory; import android.net.NetworkInfo; import android.net.NetworkInfo.DetailedState; -import android.net.ip.IpManager; -import android.net.ip.IpManager.InitialConfiguration; -import android.net.ip.IpManager.ProvisioningConfiguration; +import android.net.ip.IIpClient; +import android.net.ip.IpClientCallbacks; +import android.net.ip.IpClientUtil; import android.net.lowpan.ILowpanInterface; import android.net.lowpan.LowpanException; import android.net.lowpan.LowpanInterface; import android.net.lowpan.LowpanRuntimeException; +import android.net.shared.InitialConfiguration; +import android.net.shared.ProvisioningConfiguration; +import android.os.ConditionVariable; import android.os.Looper; import android.os.Message; import android.os.RemoteException; @@ -62,6 +65,9 @@ class LowpanInterfaceTracker extends StateMachine { */ private static final int NETWORK_SCORE = 30; + // TODO: create IpClient asynchronously + private static final int IPCLIENT_CREATE_TIMEOUT_MS = 10000; + /** Internal debugging flag. */ private static final boolean DBG = true; @@ -87,8 +93,8 @@ class LowpanInterfaceTracker extends StateMachine { private LowpanInterface mLowpanInterface; private NetworkAgent mNetworkAgent; private NetworkFactory mNetworkFactory; - private IpManager mIpManager; - private final IpManager.Callback mIpManagerCallback = new IpManagerCallback(); + private volatile IIpClient mIpClient; + private final IpClientCallbackImpl mIpClientCallback = new IpClientCallbackImpl(); // Instance Variables @@ -132,7 +138,19 @@ class LowpanInterfaceTracker extends StateMachine { } } - class IpManagerCallback extends IpManager.Callback { + class IpClientCallbackImpl extends IpClientCallbacks { + private final ConditionVariable mObtainedCv = new ConditionVariable(false); + + @Override + public void onIpClientCreated(IIpClient ipClient) { + mIpClient = ipClient; + mObtainedCv.open(); + } + + public boolean waitUntilCreated() { + return mObtainedCv.block(IPCLIENT_CREATE_TIMEOUT_MS); + } + @Override public void onProvisioningSuccess(LinkProperties newLp) { LowpanInterfaceTracker.this.sendMessage(CMD_PROVISIONING_SUCCESS, newLp); @@ -248,7 +266,12 @@ class LowpanInterfaceTracker extends StateMachine { Log.i(TAG, "NormalState.enter()"); } - mIpManager = new IpManager(mContext, mInterfaceName, mIpManagerCallback); + IpClientUtil.makeIpClient(mContext, mInterfaceName, mIpClientCallback); + if (!mIpClientCallback.waitUntilCreated()) { + Log.e(TAG, "Failed to create IpClient"); + transitionTo(mFaultState); + return; + } if (mHwAddr == null) { byte[] hwAddr = null; @@ -314,10 +337,14 @@ class LowpanInterfaceTracker extends StateMachine { shutdownNetworkAgent(); mNetworkFactory.unregister(); - if (mIpManager != null) { - mIpManager.shutdown(); + if (mIpClient != null) { + try { + mIpClient.shutdown(); + } catch (RemoteException e) { + Log.e(TAG, "Error shutting down IpClient", e); + } } - mIpManager = null; + mIpClient = null; } } @@ -327,7 +354,11 @@ class LowpanInterfaceTracker extends StateMachine { shutdownNetworkAgent(); mNetworkInfo.setIsAvailable(true); - mIpManager.stop(); + try { + mIpClient.stop(); + } catch (RemoteException e) { + Log.e(TAG, "Error stopping IpClient"); + } } @Override @@ -453,7 +484,7 @@ class LowpanInterfaceTracker extends StateMachine { } final ProvisioningConfiguration.Builder builder = - mIpManager.buildProvisioningConfiguration(); + new ProvisioningConfiguration.Builder(); builder.withInitialConfiguration(initialConfiguration).withProvisioningTimeoutMs(0); @@ -466,7 +497,13 @@ class LowpanInterfaceTracker extends StateMachine { // the InitialConfiguration for any IPv4 addresses. builder.withoutIPv4(); - mIpManager.startProvisioning(builder.build()); + try { + mIpClient.startProvisioning(builder.build().toStableParcelable()); + } catch (RemoteException e) { + Log.e(TAG, "Error starting IpClient provisioning", e); + transitionTo(mFaultState); + return; + } mNetworkInfo.setDetailedState(DetailedState.OBTAINING_IPADDR, null, mHwAddr); mNetworkAgent.sendNetworkInfo(mNetworkInfo); -- cgit v1.2.3