Set EthernetNetworkSpecifier on ethernet networks
Bug: 175199512
Test: atest EthernetServiceTests
Change-Id: I4a4762a6509099a5c0954296cbf1b42e3a6cfc25
diff --git a/service-t/src/com/android/server/ethernet/EthernetNetworkFactory.java b/service-t/src/com/android/server/ethernet/EthernetNetworkFactory.java
index a15fec4..cc8103b 100644
--- a/service-t/src/com/android/server/ethernet/EthernetNetworkFactory.java
+++ b/service-t/src/com/android/server/ethernet/EthernetNetworkFactory.java
@@ -176,12 +176,16 @@
return;
}
+ final NetworkCapabilities nc = new NetworkCapabilities.Builder(capabilities)
+ .setNetworkSpecifier(new EthernetNetworkSpecifier(ifaceName))
+ .build();
+
if (DBG) {
- Log.d(TAG, "addInterface, iface: " + ifaceName + ", capabilities: " + capabilities);
+ Log.d(TAG, "addInterface, iface: " + ifaceName + ", capabilities: " + nc);
}
final NetworkInterfaceState iface = new NetworkInterfaceState(
- ifaceName, hwAddress, mHandler, mContext, ipConfig, capabilities, this, mDeps);
+ ifaceName, hwAddress, mHandler, mContext, ipConfig, nc, this, mDeps);
mTrackingInterfaces.put(ifaceName, iface);
updateCapabilityFilter();
}
diff --git a/tests/ethernet/java/com/android/server/ethernet/EthernetNetworkFactoryTest.java b/tests/ethernet/java/com/android/server/ethernet/EthernetNetworkFactoryTest.java
index 7a90eee..ae52a75 100644
--- a/tests/ethernet/java/com/android/server/ethernet/EthernetNetworkFactoryTest.java
+++ b/tests/ethernet/java/com/android/server/ethernet/EthernetNetworkFactoryTest.java
@@ -71,6 +71,7 @@
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
@@ -265,8 +266,12 @@
triggerOnProvisioningSuccess();
// provisioning succeeded, verify that the network agent is created, registered, marked
// as connected and legacy type are correctly set.
- verify(mDeps).makeEthernetNetworkAgent(any(), any(), any(), any(),
+ final ArgumentCaptor<NetworkCapabilities> ncCaptor = ArgumentCaptor.forClass(
+ NetworkCapabilities.class);
+ verify(mDeps).makeEthernetNetworkAgent(any(), any(), ncCaptor.capture(), any(),
argThat(x -> x.getLegacyType() == expectedLegacyType), any(), any());
+ assertEquals(
+ new EthernetNetworkSpecifier(iface), ncCaptor.getValue().getNetworkSpecifier());
verifyNetworkAgentRegistersAndConnects();
clearInvocations(mDeps);
clearInvocations(mNetworkAgent);