Replace INetd#trafficSwapActiveStatsMap with ConnectivityManager API

This is the corresponding test change with INetd#trafficSwapActiveStatsMap
usage replacement.

Bug: 209935649
Test: atest NetworkStatsFactoryTest
Change-Id: Ic5e29f6a928c4230322ed658fe8ddbd71d7ea56a
This commit is contained in:
markchien
2022-01-14 22:36:18 +08:00
parent e0322e3fd1
commit daf30ef9a8

View File

@@ -32,9 +32,12 @@ import static com.android.server.NetworkManagementSocketTagger.kernelToTag;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.doReturn;
import android.content.Context;
import android.content.res.Resources; import android.content.res.Resources;
import android.net.INetd; import android.net.ConnectivityManager;
import android.net.NetworkStats; import android.net.NetworkStats;
import android.net.TrafficStats; import android.net.TrafficStats;
import android.net.UnderlyingNetworkInfo; import android.net.UnderlyingNetworkInfo;
@@ -73,8 +76,8 @@ public class NetworkStatsFactoryTest extends NetworkStatsBaseTest {
private File mTestProc; private File mTestProc;
private NetworkStatsFactory mFactory; private NetworkStatsFactory mFactory;
@Mock @Mock private Context mContext;
private INetd mNetd; @Mock private ConnectivityManager mCm;
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
@@ -85,7 +88,10 @@ public class NetworkStatsFactoryTest extends NetworkStatsBaseTest {
// applications. So in order to have a test support native library, the native code // applications. So in order to have a test support native library, the native code
// related to networkStatsFactory is compiled to a minimal native library and loaded here. // related to networkStatsFactory is compiled to a minimal native library and loaded here.
System.loadLibrary("networkstatsfactorytestjni"); System.loadLibrary("networkstatsfactorytestjni");
mFactory = new NetworkStatsFactory(mTestProc, false, mNetd); doReturn(Context.CONNECTIVITY_SERVICE).when(mContext).getSystemServiceName(
eq(ConnectivityManager.class));
doReturn(mCm).when(mContext).getSystemService(eq(Context.CONNECTIVITY_SERVICE));
mFactory = new NetworkStatsFactory(mContext, mTestProc, false);
mFactory.updateUnderlyingNetworkInfos(new UnderlyingNetworkInfo[0]); mFactory.updateUnderlyingNetworkInfos(new UnderlyingNetworkInfo[0]);
} }