Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0c73feef authored by Chiachang Wang's avatar Chiachang Wang
Browse files

Replace InterfaceConfiguration usage with stable aidl

Replace InterfaceConfiguration with InterfaceConfigurationParcel
for the incoming ConnectivityService mainline since mainline
modules could not use @hide API.

Bug: 170598012
Test: atest FrameworksNetTests
Change-Id: I17ce8741e985fd30e3c8f0c34e79564a82890dc6
parent be52dafa
Loading
Loading
Loading
Loading
+5 −4
Original line number Diff line number Diff line
@@ -21,7 +21,7 @@ import android.net.ConnectivityManager;
import android.net.IDnsResolver;
import android.net.INetd;
import android.net.InetAddresses;
import android.net.InterfaceConfiguration;
import android.net.InterfaceConfigurationParcel;
import android.net.IpPrefix;
import android.net.LinkAddress;
import android.net.LinkProperties;
@@ -447,9 +447,10 @@ public class Nat464Xlat extends BaseNetworkObserver {

    private LinkAddress getLinkAddress(String iface) {
        try {
            InterfaceConfiguration config = mNMService.getInterfaceConfig(iface);
            return config.getLinkAddress();
        } catch (RemoteException | IllegalStateException e) {
            final InterfaceConfigurationParcel config = mNetd.interfaceGetCfg(iface);
            return new LinkAddress(
                    InetAddresses.parseNumericAddress(config.ipv4Addr), config.prefixLength);
        } catch (IllegalArgumentException | RemoteException | ServiceSpecificException e) {
            Slog.e(TAG, "Error getting link properties: " + e);
            return null;
        }
+14 −11
Original line number Diff line number Diff line
@@ -158,7 +158,7 @@ import android.net.INetworkPolicyListener;
import android.net.INetworkPolicyManager;
import android.net.INetworkStatsService;
import android.net.InetAddresses;
import android.net.InterfaceConfiguration;
import android.net.InterfaceConfigurationParcel;
import android.net.IpPrefix;
import android.net.IpSecManager;
import android.net.IpSecManager.UdpEncapsulationSocket;
@@ -6084,12 +6084,13 @@ public class ConnectivityServiceTest {
    }

    /**
     * Make simulated InterfaceConfig for Nat464Xlat to query clat lower layer info.
     * Make simulated InterfaceConfigParcel for Nat464Xlat to query clat lower layer info.
     */
    private InterfaceConfiguration getClatInterfaceConfig(LinkAddress la) {
        InterfaceConfiguration cfg = new InterfaceConfiguration();
        cfg.setHardwareAddress("11:22:33:44:55:66");
        cfg.setLinkAddress(la);
    private InterfaceConfigurationParcel getClatInterfaceConfigParcel(LinkAddress la) {
        final InterfaceConfigurationParcel cfg = new InterfaceConfigurationParcel();
        cfg.hwAddr = "11:22:33:44:55:66";
        cfg.ipv4Addr = la.getAddress().getHostAddress();
        cfg.prefixLength = la.getPrefixLength();
        return cfg;
    }

@@ -6180,8 +6181,8 @@ public class ConnectivityServiceTest {
        reset(mNetworkManagementService);
        reset(mMockNetd);
        reset(mMockDnsResolver);
        when(mNetworkManagementService.getInterfaceConfig(CLAT_PREFIX + MOBILE_IFNAME))
                .thenReturn(getClatInterfaceConfig(myIpv4));
        when(mMockNetd.interfaceGetCfg(CLAT_PREFIX + MOBILE_IFNAME))
                .thenReturn(getClatInterfaceConfigParcel(myIpv4));

        // Remove IPv4 address. Expect prefix discovery to be started again.
        cellLp.removeLinkAddress(myIpv4);
@@ -6230,7 +6231,8 @@ public class ConnectivityServiceTest {
                    TYPE_MOBILE);
        }
        reset(mMockNetd);

        when(mMockNetd.interfaceGetCfg(CLAT_PREFIX + MOBILE_IFNAME))
                .thenReturn(getClatInterfaceConfigParcel(myIpv4));
        // Change the NAT64 prefix without first removing it.
        // Expect clatd to be stopped and started with the new prefix.
        mService.mNetdEventCallback.onNat64PrefixEvent(cellNetId, true /* added */,
@@ -6279,8 +6281,8 @@ public class ConnectivityServiceTest {
        reset(mNetworkManagementService);
        reset(mMockNetd);
        reset(mMockDnsResolver);
        when(mNetworkManagementService.getInterfaceConfig(CLAT_PREFIX + MOBILE_IFNAME))
                .thenReturn(getClatInterfaceConfig(myIpv4));
        when(mMockNetd.interfaceGetCfg(CLAT_PREFIX + MOBILE_IFNAME))
                .thenReturn(getClatInterfaceConfigParcel(myIpv4));

        // Stopping prefix discovery causes netd to tell us that the NAT64 prefix is gone.
        mService.mNetdEventCallback.onNat64PrefixEvent(cellNetId, false /* added */,
@@ -6320,6 +6322,7 @@ public class ConnectivityServiceTest {
        networkCallback.expectLinkPropertiesThat(mCellNetworkAgent,
                (lp) -> lp.getStackedLinks().size() == 0);
        verify(mMockNetd, times(1)).networkRemoveInterface(cellNetId, CLAT_PREFIX + MOBILE_IFNAME);
        verify(mMockNetd, times(1)).interfaceGetCfg(CLAT_PREFIX + MOBILE_IFNAME);
        verifyNoMoreInteractions(mMockNetd);
        // Clean up.
        mCellNetworkAgent.disconnect();
+7 −7
Original line number Diff line number Diff line
@@ -29,7 +29,7 @@ import static org.mockito.Mockito.when;
import android.net.ConnectivityManager;
import android.net.IDnsResolver;
import android.net.INetd;
import android.net.InterfaceConfiguration;
import android.net.InterfaceConfigurationParcel;
import android.net.IpPrefix;
import android.net.LinkAddress;
import android.net.LinkProperties;
@@ -68,7 +68,6 @@ public class Nat464XlatTest {
    @Mock IDnsResolver mDnsResolver;
    @Mock INetd mNetd;
    @Mock INetworkManagementService mNms;
    @Mock InterfaceConfiguration mConfig;
    @Mock NetworkAgentInfo mNai;

    TestLooper mLooper;
@@ -106,9 +105,10 @@ public class Nat464XlatTest {
        when(mNai.connService()).thenReturn(mConnectivity);
        when(mNai.netAgentConfig()).thenReturn(mAgentConfig);
        when(mNai.handler()).thenReturn(mHandler);

        when(mNms.getInterfaceConfig(eq(STACKED_IFACE))).thenReturn(mConfig);
        when(mConfig.getLinkAddress()).thenReturn(ADDR);
        final InterfaceConfigurationParcel mConfig = new InterfaceConfigurationParcel();
        when(mNetd.interfaceGetCfg(eq(STACKED_IFACE))).thenReturn(mConfig);
        mConfig.ipv4Addr = ADDR.getAddress().getHostAddress();
        mConfig.prefixLength =  ADDR.getPrefixLength();
    }

    private void assertRequiresClat(boolean expected, NetworkAgentInfo nai) {
@@ -213,7 +213,7 @@ public class Nat464XlatTest {
        nat.interfaceLinkStateChanged(STACKED_IFACE, true);
        mLooper.dispatchNext();

        verify(mNms).getInterfaceConfig(eq(STACKED_IFACE));
        verify(mNetd).interfaceGetCfg(eq(STACKED_IFACE));
        verify(mConnectivity).handleUpdateLinkProperties(eq(mNai), c.capture());
        assertFalse(c.getValue().getStackedLinks().isEmpty());
        assertTrue(c.getValue().getAllInterfaceNames().contains(STACKED_IFACE));
@@ -353,7 +353,7 @@ public class Nat464XlatTest {
        nat.interfaceLinkStateChanged(STACKED_IFACE, true);
        mLooper.dispatchNext();

        verify(mNms).getInterfaceConfig(eq(STACKED_IFACE));
        verify(mNetd).interfaceGetCfg(eq(STACKED_IFACE));
        verify(mConnectivity, times(1)).handleUpdateLinkProperties(eq(mNai), c.capture());
        assertFalse(c.getValue().getStackedLinks().isEmpty());
        assertTrue(c.getValue().getAllInterfaceNames().contains(STACKED_IFACE));