[MS33.2] Remove NetdService dependency

This change pass INetd to NetworkStatsFactory to replace
NetdService#getNetdInstance.

Test: atest FrameworksNetTests
Bug: 204830222
Change-Id: I0756188adb394fa5343c8d2ae354567df63acf21
This commit is contained in:
Junyu Lai
2022-01-03 12:37:33 +00:00
parent 90cf8dbd92
commit 37880f857a

View File

@@ -34,6 +34,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
import android.content.res.Resources; import android.content.res.Resources;
import android.net.INetd;
import android.net.NetworkStats; import android.net.NetworkStats;
import android.net.TrafficStats; import android.net.TrafficStats;
import android.net.UnderlyingNetworkInfo; import android.net.UnderlyingNetworkInfo;
@@ -54,6 +55,8 @@ import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
@@ -70,16 +73,19 @@ public class NetworkStatsFactoryTest extends NetworkStatsBaseTest {
private File mTestProc; private File mTestProc;
private NetworkStatsFactory mFactory; private NetworkStatsFactory mFactory;
@Mock
private INetd mNetd;
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
mTestProc = TestIoUtils.createTemporaryDirectory("proc"); mTestProc = TestIoUtils.createTemporaryDirectory("proc");
// The libandroid_servers which have the native method is not available to // The libandroid_servers which have the native method is not available to
// 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); mFactory = new NetworkStatsFactory(mTestProc, false, mNetd);
mFactory.updateUnderlyingNetworkInfos(new UnderlyingNetworkInfo[0]); mFactory.updateUnderlyingNetworkInfos(new UnderlyingNetworkInfo[0]);
} }