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

Commit 71666eb6 authored by markchien's avatar markchien
Browse files

Mock IpConnectivityLog in IpClientTest

IpConnectivityLog which is used to send metrics need NETWORK_STACK
permission. Mock IpConnectivityLog to avoid sending metrics from
tests. Also remove platform cert from the network stack unit test
because it is not necessary for any signature permission anymore.

Bug: 156866746
Test: NetworkStackNextTests, NetworkStackCoverageTests, TetheringTests,
TetheringCoverageTests

Change-Id: Ibff052b30e000de3c5a08d7265c7642d67d9b0d0
Merged-In: Ibff052b30e000de3c5a08d7265c7642d67d9b0d0
parent 11219dd0
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -458,7 +458,7 @@ public class IpClient extends StateMachine {
    private final SharedLog mLog;
    private final LocalLog mConnectivityPacketLog;
    private final MessageHandlingLogger mMsgStateLogger;
    private final IpConnectivityLog mMetricsLog = new IpConnectivityLog();
    private final IpConnectivityLog mMetricsLog;
    private final InterfaceController mInterfaceCtrl;

    // Ignore nonzero RDNSS option lifetimes below this value. 0 = disabled.
@@ -537,6 +537,13 @@ public class IpClient extends StateMachine {
            return NetworkStackUtils.getDeviceConfigPropertyInt(NAMESPACE_CONNECTIVITY, name,
                    defaultValue);
        }

        /**
         * Get a IpConnectivityLog instance.
         */
        public IpConnectivityLog getIpConnectivityLog() {
            return new IpConnectivityLog();
        }
    }

    public IpClient(Context context, String ifName, IIpClientCallbacks callback,
@@ -558,6 +565,7 @@ public class IpClient extends StateMachine {
        mInterfaceName = ifName;
        mClatInterfaceName = CLAT_PREFIX + ifName;
        mDependencies = deps;
        mMetricsLog = deps.getIpConnectivityLog();
        mShutdownLatch = new CountDownLatch(1);
        mCm = mContext.getSystemService(ConnectivityManager.class);
        mObserverRegistry = observerRegistry;
+1 −1
Original line number Diff line number Diff line
@@ -16,7 +16,7 @@

java_defaults {
    name: "NetworkStackTestsDefaults",
    certificate: "platform",
    platform_apis: true,
    srcs: ["src/**/*.java", "src/**/*.kt"],
    resource_dirs: ["res"],
    static_libs: [
+0 −1
Original line number Diff line number Diff line
@@ -27,7 +27,6 @@
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
    <uses-permission android:name="android.permission.NETWORK_STACK" />

    <application android:debuggable="true">
        <uses-library android:name="android.test.runner" />
+3 −0
Original line number Diff line number Diff line
@@ -49,6 +49,7 @@ import android.net.MacAddress;
import android.net.NetworkStackIpMemoryStore;
import android.net.RouteInfo;
import android.net.ipmemorystore.NetworkAttributes;
import android.net.metrics.IpConnectivityLog;
import android.net.shared.InitialConfiguration;
import android.net.shared.ProvisioningConfiguration;
import android.net.util.InterfaceParams;
@@ -120,6 +121,7 @@ public class IpClientTest {
    @Mock private NetworkStackIpMemoryStore mIpMemoryStore;
    @Mock private IpMemoryStoreService mIpMemoryStoreService;
    @Mock private InterfaceParams mInterfaceParams;
    @Mock private IpConnectivityLog mMetricsLog;

    private NetworkObserver mObserver;
    private InterfaceParams mIfParams;
@@ -139,6 +141,7 @@ public class IpClientTest {
        when(mDependencies.getInterfaceParams(any())).thenReturn(mInterfaceParams);
        when(mDependencies.getIpMemoryStore(mContext, mNetworkStackServiceManager))
                .thenReturn(mIpMemoryStore);
        when(mDependencies.getIpConnectivityLog()).thenReturn(mMetricsLog);

        mIfParams = null;
    }