summaryrefslogtreecommitdiff
path: root/java
diff options
context:
space:
mode:
authorChalard Jean <jchalard@google.com>2020-01-22 16:47:43 +0900
committerChalard Jean <jchalard@google.com>2020-04-01 09:09:32 +0000
commit6a0919ce10f28f9ae6c78e24d89695a92bc63048 (patch)
tree0ea6a21a477e286cfa6129d9a91144dce0818d14 /java
parent867b259cba897d97a1f2ac344122a38cbb4870bc (diff)
downloadethernet-6a0919ce10f28f9ae6c78e24d89695a92bc63048.tar.gz
Convert the Ethernet factory to the new network agent
This is a combination of ag/10147368 and ag/10438581. ag/10147368 implemented this conversion together with using the planned NetworkScore API, while ag/10438581 reverted the parts that had to do with NetworkScore. This is just a squash of these two patches and it brings the factory in line with the code in rvc-dev. Test: FrameworksNetTests NetworkStackTests EthernetTetheringTest Change-Id: Ib214fbbd042f2c0ebd01cf5b0ec33d922629677e Merged-In: Ie7b70750ef0e17141080f4266dea6155c3601569
Diffstat (limited to 'java')
-rw-r--r--java/com/android/server/ethernet/EthernetNetworkFactory.java56
1 files changed, 20 insertions, 36 deletions
diff --git a/java/com/android/server/ethernet/EthernetNetworkFactory.java b/java/com/android/server/ethernet/EthernetNetworkFactory.java
index ab2cfc7..f5ab8b7 100644
--- a/java/com/android/server/ethernet/EthernetNetworkFactory.java
+++ b/java/com/android/server/ethernet/EthernetNetworkFactory.java
@@ -16,7 +16,6 @@
package com.android.server.ethernet;
-import static android.net.ConnectivityManager.TYPE_ETHERNET;
import static android.net.shared.LinkPropertiesParcelableUtil.toStableParcelable;
import static com.android.internal.util.Preconditions.checkNotNull;
@@ -29,10 +28,9 @@ import android.net.IpConfiguration.IpAssignment;
import android.net.IpConfiguration.ProxySettings;
import android.net.LinkProperties;
import android.net.NetworkAgent;
+import android.net.NetworkAgentConfig;
import android.net.NetworkCapabilities;
import android.net.NetworkFactory;
-import android.net.NetworkInfo;
-import android.net.NetworkInfo.DetailedState;
import android.net.NetworkRequest;
import android.net.NetworkSpecifier;
import android.net.StringNetworkSpecifier;
@@ -52,7 +50,6 @@ import android.util.SparseArray;
import com.android.internal.util.IndentingPrintWriter;
import java.io.FileDescriptor;
-import java.lang.Math;
import java.util.concurrent.ConcurrentHashMap;
import java.util.Objects;
@@ -221,12 +218,12 @@ public class EthernetNetworkFactory extends NetworkFactory {
NetworkInterfaceState network = null;
if (!TextUtils.isEmpty(requestedIface)) {
NetworkInterfaceState n = mTrackingInterfaces.get(requestedIface);
- if (n != null && n.statisified(request.networkCapabilities)) {
+ if (n != null && n.satisfied(request.networkCapabilities)) {
network = n;
}
} else {
for (NetworkInterfaceState n : mTrackingInterfaces.values()) {
- if (n.statisified(request.networkCapabilities) && n.mLinkUp) {
+ if (n.satisfied(request.networkCapabilities) && n.mLinkUp) {
network = n;
break;
}
@@ -247,8 +244,8 @@ public class EthernetNetworkFactory extends NetworkFactory {
private final NetworkCapabilities mCapabilities;
private final Handler mHandler;
private final Context mContext;
- private final NetworkInfo mNetworkInfo;
private final NetworkFactory mNetworkFactory;
+ private final int mLegacyType;
private static String sTcpBufferSizes = null; // Lazy initialized.
@@ -375,9 +372,7 @@ public class EthernetNetworkFactory extends NetworkFactory {
}
mHwAddress = hwAddress;
- mNetworkInfo = new NetworkInfo(legacyType, 0, NETWORK_TYPE, "");
- mNetworkInfo.setExtraInfo(mHwAddress);
- mNetworkInfo.setIsAvailable(true);
+ mLegacyType = legacyType;
}
void setIpConfig(IpConfiguration ipConfig) {
@@ -386,12 +381,12 @@ public class EthernetNetworkFactory extends NetworkFactory {
return;
}
this.mIpConfig = ipConfig;
- if (mNetworkInfo.getDetailedState() != DetailedState.DISCONNECTED) {
+ if (mNetworkAgent != null) {
restart();
}
}
- boolean statisified(NetworkCapabilities requestedCapabilities) {
+ boolean satisfied(NetworkCapabilities requestedCapabilities) {
return requestedCapabilities.satisfiedByNetworkCapabilities(mCapabilities);
}
@@ -446,11 +441,9 @@ public class EthernetNetworkFactory extends NetworkFactory {
return;
}
if (DBG) {
- Log.d(TAG, String.format("starting IpClient(%s): mNetworkInfo=%s", name,
- mNetworkInfo));
+ Log.d(TAG, String.format("Starting Ethernet IpClient(%s)", name));
}
- mNetworkInfo.setDetailedState(DetailedState.OBTAINING_IPADDR, null, mHwAddress);
mIpClientCallback = new IpClientCallbacksImpl();
IpClientUtil.makeIpClient(mContext, name, mIpClientCallback);
mIpClientCallback.awaitIpClientStart();
@@ -468,13 +461,15 @@ public class EthernetNetworkFactory extends NetworkFactory {
return;
}
mLinkProperties = linkProperties;
- mNetworkInfo.setDetailedState(DetailedState.CONNECTED, null, mHwAddress);
- mNetworkInfo.setIsAvailable(true);
// Create our NetworkAgent.
- mNetworkAgent = new NetworkAgent(mHandler.getLooper(), mContext,
- NETWORK_TYPE, mNetworkInfo, mCapabilities, mLinkProperties,
- getNetworkScore(), mNetworkFactory.getSerialNumber()) {
+ final NetworkAgentConfig config = new NetworkAgentConfig.Builder()
+ .setLegacyType(mLegacyType)
+ .setLegacyTypeName(NETWORK_TYPE)
+ .build();
+ mNetworkAgent = new NetworkAgent(mContext, mHandler.getLooper(),
+ NETWORK_TYPE, mCapabilities, mLinkProperties,
+ getNetworkScore(), config, mNetworkFactory.getProvider()) {
public void unwanted() {
if (this == mNetworkAgent) {
stop();
@@ -484,6 +479,9 @@ public class EthernetNetworkFactory extends NetworkFactory {
} // Otherwise, we've already called stop.
}
};
+ mNetworkAgent.register();
+ mNetworkAgent.setLegacyExtraInfo(mHwAddress);
+ mNetworkAgent.setConnected();
}
void onIpLayerStopped(LinkProperties linkProperties) {
@@ -526,16 +524,11 @@ public class EthernetNetworkFactory extends NetworkFactory {
}
mIpClientCallback = null;
- // ConnectivityService will only forget our NetworkAgent if we send it a NetworkInfo object
- // with a state of DISCONNECTED or SUSPENDED. So we can't simply clear our NetworkInfo here:
- // that sets the state to IDLE, and ConnectivityService will still think we're connected.
- //
- mNetworkInfo.setDetailedState(DetailedState.DISCONNECTED, null, mHwAddress);
if (mNetworkAgent != null) {
- updateAgent();
+ mNetworkAgent.unregister();
mNetworkAgent = null;
}
- clear();
+ mLinkProperties.clear();
}
private void updateAgent() {
@@ -543,11 +536,9 @@ public class EthernetNetworkFactory extends NetworkFactory {
if (DBG) {
Log.i(TAG, "Updating mNetworkAgent with: " +
mCapabilities + ", " +
- mNetworkInfo + ", " +
mLinkProperties);
}
mNetworkAgent.sendNetworkCapabilities(mCapabilities);
- mNetworkAgent.sendNetworkInfo(mNetworkInfo);
mNetworkAgent.sendLinkProperties(mLinkProperties);
// As a note, getNetworkScore() is fairly expensive to calculate. This is fine for now
@@ -556,12 +547,6 @@ public class EthernetNetworkFactory extends NetworkFactory {
mNetworkAgent.sendNetworkScore(getNetworkScore());
}
- private void clear() {
- mLinkProperties.clear();
- mNetworkInfo.setDetailedState(DetailedState.IDLE, null, null);
- mNetworkInfo.setIsAvailable(false);
- }
-
private static void provisionIpClient(IIpClient ipClient, IpConfiguration config,
String tcpBufferSizes) {
if (config.getProxySettings() == ProxySettings.STATIC ||
@@ -612,7 +597,6 @@ public class EthernetNetworkFactory extends NetworkFactory {
+ "iface: " + name + ", "
+ "up: " + mLinkUp + ", "
+ "hwAddress: " + mHwAddress + ", "
- + "networkInfo: " + mNetworkInfo + ", "
+ "networkCapabilities: " + mCapabilities + ", "
+ "networkAgent: " + mNetworkAgent + ", "
+ "score: " + getNetworkScore() + ", "