Snap for 6370344 from d5729ebc66f333af206c96e81f9e1c18129d7f83 to rvc-release

Change-Id: Ia051ce889de0ccce3eb4d428daee4e33d7f23046
This commit is contained in:
android-build-team Robot
2020-04-07 02:05:37 +00:00
8 changed files with 347 additions and 20 deletions

View File

@@ -624,7 +624,9 @@ public abstract class NetworkAgent {
throw new UnsupportedOperationException( throw new UnsupportedOperationException(
"Legacy agents can't call markConnected."); "Legacy agents can't call markConnected.");
} }
mNetworkInfo.setDetailedState(NetworkInfo.DetailedState.CONNECTED, null, null); // |reason| cannot be used by the non-legacy agents
mNetworkInfo.setDetailedState(NetworkInfo.DetailedState.CONNECTED, null /* reason */,
mNetworkInfo.getExtraInfo());
queueOrSendMessage(EVENT_NETWORK_INFO_CHANGED, mNetworkInfo); queueOrSendMessage(EVENT_NETWORK_INFO_CHANGED, mNetworkInfo);
} }
@@ -638,7 +640,9 @@ public abstract class NetworkAgent {
if (mIsLegacy) { if (mIsLegacy) {
throw new UnsupportedOperationException("Legacy agents can't call unregister."); throw new UnsupportedOperationException("Legacy agents can't call unregister.");
} }
mNetworkInfo.setDetailedState(NetworkInfo.DetailedState.DISCONNECTED, null, null); // When unregistering an agent nobody should use the extrainfo (or reason) any more.
mNetworkInfo.setDetailedState(NetworkInfo.DetailedState.DISCONNECTED, null /* reason */,
null /* extraInfo */);
queueOrSendMessage(EVENT_NETWORK_INFO_CHANGED, mNetworkInfo); queueOrSendMessage(EVENT_NETWORK_INFO_CHANGED, mNetworkInfo);
} }

View File

@@ -3153,7 +3153,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
} }
} }
nai.clatd.setNat64Prefix(prefix); nai.clatd.setNat64PrefixFromDns(prefix);
handleUpdateLinkProperties(nai, new LinkProperties(nai.linkProperties)); handleUpdateLinkProperties(nai, new LinkProperties(nai.linkProperties));
} }
@@ -5865,9 +5865,9 @@ public class ConnectivityService extends IConnectivityManager.Stub
@NonNull LinkProperties oldLp) { @NonNull LinkProperties oldLp) {
int netId = networkAgent.network.netId; int netId = networkAgent.network.netId;
// The NetworkAgentInfo does not know whether clatd is running on its network or not, or // The NetworkAgent does not know whether clatd is running on its network or not, or whether
// whether there is a NAT64 prefix. Before we do anything else, make sure its LinkProperties // a NAT64 prefix was discovered by the DNS resolver. Before we do anything else, make sure
// are accurate. // the LinkProperties for the network are accurate.
networkAgent.clatd.fixupLinkProperties(oldLp, newLp); networkAgent.clatd.fixupLinkProperties(oldLp, newLp);
updateInterfaces(newLp, oldLp, netId, networkAgent.networkCapabilities, updateInterfaces(newLp, oldLp, netId, networkAgent.networkCapabilities,

View File

@@ -81,7 +81,7 @@ public class Nat464Xlat extends BaseNetworkObserver {
RUNNING, // start() called, and the stacked iface is known to be up. RUNNING, // start() called, and the stacked iface is known to be up.
} }
private IpPrefix mNat64Prefix; private IpPrefix mNat64PrefixFromDns;
private String mBaseIface; private String mBaseIface;
private String mIface; private String mIface;
private Inet6Address mIPv6Address; private Inet6Address mIPv6Address;
@@ -100,7 +100,7 @@ public class Nat464Xlat extends BaseNetworkObserver {
* currently connected and where the NetworkAgent has not disabled 464xlat. It is the signal to * currently connected and where the NetworkAgent has not disabled 464xlat. It is the signal to
* enable NAT64 prefix discovery. * enable NAT64 prefix discovery.
* *
* @param network the NetworkAgentInfo corresponding to the network. * @param nai the NetworkAgentInfo corresponding to the network.
* @return true if the network requires clat, false otherwise. * @return true if the network requires clat, false otherwise.
*/ */
@VisibleForTesting @VisibleForTesting
@@ -180,7 +180,7 @@ public class Nat464Xlat extends BaseNetworkObserver {
String addrStr = null; String addrStr = null;
try { try {
addrStr = mNetd.clatdStart(baseIface, mNat64Prefix.toString()); addrStr = mNetd.clatdStart(baseIface, getNat64Prefix().toString());
} catch (RemoteException | ServiceSpecificException e) { } catch (RemoteException | ServiceSpecificException e) {
Slog.e(TAG, "Error starting clatd on " + baseIface + ": " + e); Slog.e(TAG, "Error starting clatd on " + baseIface + ": " + e);
} }
@@ -318,8 +318,12 @@ public class Nat464Xlat extends BaseNetworkObserver {
} }
} }
public void setNat64Prefix(IpPrefix nat64Prefix) { private IpPrefix getNat64Prefix() {
mNat64Prefix = nat64Prefix; return mNat64PrefixFromDns;
}
public void setNat64PrefixFromDns(IpPrefix prefix) {
mNat64PrefixFromDns = prefix;
} }
/** /**
@@ -328,7 +332,7 @@ public class Nat464Xlat extends BaseNetworkObserver {
* has no idea that 464xlat is running on top of it. * has no idea that 464xlat is running on top of it.
*/ */
public void fixupLinkProperties(@NonNull LinkProperties oldLp, @NonNull LinkProperties lp) { public void fixupLinkProperties(@NonNull LinkProperties oldLp, @NonNull LinkProperties lp) {
lp.setNat64Prefix(mNat64Prefix); lp.setNat64Prefix(getNat64Prefix());
if (!isRunning()) { if (!isRunning()) {
return; return;

View File

@@ -0,0 +1,50 @@
/*
* Copyright (C) 2020 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.net
import android.net.wifi.aware.DiscoverySession
import android.net.wifi.aware.PeerHandle
import android.net.wifi.aware.WifiAwareNetworkSpecifier
import androidx.test.filters.SmallTest
import androidx.test.runner.AndroidJUnit4
import com.android.testutils.assertParcelSane
import java.lang.IllegalStateException
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mockito
@RunWith(AndroidJUnit4::class)
@SmallTest
class MatchAllNetworkSpecifierTest {
@Test
fun testParcel() {
assertParcelSane(MatchAllNetworkSpecifier(), 0)
}
@Test(expected = IllegalStateException::class)
fun testSatisfiedBy() {
val specifier = MatchAllNetworkSpecifier()
val discoverySession = Mockito.mock(DiscoverySession::class.java)
val peerHandle = Mockito.mock(PeerHandle::class.java)
val wifiAwareNetworkSpecifier = WifiAwareNetworkSpecifier.Builder(discoverySession,
peerHandle).build()
specifier.satisfiedBy(wifiAwareNetworkSpecifier)
}
}

View File

@@ -55,6 +55,10 @@ import android.util.ArraySet;
import androidx.core.os.BuildCompat; import androidx.core.os.BuildCompat;
import androidx.test.runner.AndroidJUnit4; import androidx.test.runner.AndroidJUnit4;
import com.android.testutils.DevSdkIgnoreRule;
import com.android.testutils.DevSdkIgnoreRule.IgnoreUpTo;
import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
@@ -67,6 +71,9 @@ public class NetworkCapabilitiesTest {
private static final String TEST_SSID = "TEST_SSID"; private static final String TEST_SSID = "TEST_SSID";
private static final String DIFFERENT_TEST_SSID = "DIFFERENT_TEST_SSID"; private static final String DIFFERENT_TEST_SSID = "DIFFERENT_TEST_SSID";
@Rule
public DevSdkIgnoreRule mDevSdkIgnoreRule = new DevSdkIgnoreRule();
private boolean isAtLeastR() { private boolean isAtLeastR() {
// BuildCompat.isAtLeastR() is used to check the Android version before releasing Android R. // BuildCompat.isAtLeastR() is used to check the Android version before releasing Android R.
// Build.VERSION.SDK_INT > Build.VERSION_CODES.Q is used to check the Android version after // Build.VERSION.SDK_INT > Build.VERSION_CODES.Q is used to check the Android version after
@@ -441,7 +448,7 @@ public class NetworkCapabilitiesTest {
return range; return range;
} }
@Test @Test @IgnoreUpTo(Build.VERSION_CODES.Q)
public void testSetAdministratorUids() { public void testSetAdministratorUids() {
NetworkCapabilities nc = NetworkCapabilities nc =
new NetworkCapabilities().setAdministratorUids(new int[] {2, 1, 3}); new NetworkCapabilities().setAdministratorUids(new int[] {2, 1, 3});
@@ -449,7 +456,7 @@ public class NetworkCapabilitiesTest {
assertArrayEquals(new int[] {1, 2, 3}, nc.getAdministratorUids()); assertArrayEquals(new int[] {1, 2, 3}, nc.getAdministratorUids());
} }
@Test @Test @IgnoreUpTo(Build.VERSION_CODES.Q)
public void testSetAdministratorUidsWithDuplicates() { public void testSetAdministratorUidsWithDuplicates() {
try { try {
new NetworkCapabilities().setAdministratorUids(new int[] {1, 1}); new NetworkCapabilities().setAdministratorUids(new int[] {1, 1});
@@ -510,6 +517,12 @@ public class NetworkCapabilitiesTest {
assertFalse(nc2.appliesToUid(12)); assertFalse(nc2.appliesToUid(12));
assertTrue(nc1.appliesToUid(22)); assertTrue(nc1.appliesToUid(22));
assertTrue(nc2.appliesToUid(22)); assertTrue(nc2.appliesToUid(22));
}
@Test @IgnoreUpTo(Build.VERSION_CODES.Q)
public void testCombineCapabilities_AdministratorUids() {
final NetworkCapabilities nc1 = new NetworkCapabilities();
final NetworkCapabilities nc2 = new NetworkCapabilities();
final int[] adminUids = {3, 6, 12}; final int[] adminUids = {3, 6, 12};
nc1.setAdministratorUids(adminUids); nc1.setAdministratorUids(adminUids);
@@ -518,7 +531,7 @@ public class NetworkCapabilitiesTest {
assertArrayEquals(nc2.getAdministratorUids(), adminUids); assertArrayEquals(nc2.getAdministratorUids(), adminUids);
final int[] adminUidsOtherOrder = {3, 12, 6}; final int[] adminUidsOtherOrder = {3, 12, 6};
nc1.setAdministratorUids(adminUids); nc1.setAdministratorUids(adminUidsOtherOrder);
assertTrue(nc2.equalsAdministratorUids(nc1)); assertTrue(nc2.equalsAdministratorUids(nc1));
final int[] adminUids2 = {11, 1, 12, 3, 6}; final int[] adminUids2 = {11, 1, 12, 3, 6};

View File

@@ -0,0 +1,209 @@
/*
* Copyright (C) 2020 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.net.netstats
import android.net.NetworkStats
import android.net.NetworkStats.DEFAULT_NETWORK_NO
import android.net.NetworkStats.DEFAULT_NETWORK_YES
import android.net.NetworkStats.Entry
import android.net.NetworkStats.IFACE_VT
import android.net.NetworkStats.METERED_NO
import android.net.NetworkStats.METERED_YES
import android.net.NetworkStats.ROAMING_NO
import android.net.NetworkStats.ROAMING_YES
import android.net.NetworkStats.SET_DEFAULT
import android.net.NetworkStats.SET_FOREGROUND
import android.net.NetworkStats.TAG_NONE
import android.os.Build
import androidx.test.filters.SmallTest
import com.android.testutils.DevSdkIgnoreRule
import com.android.testutils.DevSdkIgnoreRule.IgnoreUpTo
import com.android.testutils.assertFieldCountEquals
import com.android.testutils.assertNetworkStatsEquals
import com.android.testutils.assertParcelingIsLossless
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
import kotlin.test.assertEquals
@RunWith(JUnit4::class)
@SmallTest
class NetworkStatsApiTest {
@Rule
@JvmField
val ignoreRule = DevSdkIgnoreRule()
private val testStatsEmpty = NetworkStats(0L, 0)
// stats1 and stats2 will have some entries with common keys, which are expected to
// be merged if performing add on these 2 stats.
private val testStats1 = NetworkStats(0L, 0)
// Entries which only appear in set1.
.addEntry(Entry(TEST_IFACE, TEST_UID1, SET_DEFAULT, TAG_NONE,
METERED_NO, ROAMING_NO, DEFAULT_NETWORK_YES, 20, 3, 57, 40, 3))
.addEntry(Entry(TEST_IFACE, TEST_UID1, SET_DEFAULT, TAG_NONE,
METERED_NO, ROAMING_YES, DEFAULT_NETWORK_NO, 31, 7, 24, 5, 8))
.addEntry(Entry(TEST_IFACE, TEST_UID1, SET_DEFAULT, TAG_NONE,
METERED_YES, ROAMING_NO, DEFAULT_NETWORK_NO, 25, 3, 47, 8, 2))
.addEntry(Entry(TEST_IFACE, TEST_UID1, SET_FOREGROUND, TAG_NONE,
METERED_NO, ROAMING_NO, DEFAULT_NETWORK_NO, 37, 52, 1, 10, 4))
// Entries which are common for set1 and set2.
.addEntry(Entry(TEST_IFACE, TEST_UID1, SET_DEFAULT, TAG_NONE,
METERED_NO, ROAMING_NO, DEFAULT_NETWORK_NO, 101, 2, 103, 4, 5))
.addEntry(Entry(TEST_IFACE, TEST_UID1, SET_DEFAULT, 0x80,
METERED_NO, ROAMING_NO, DEFAULT_NETWORK_NO, 17, 2, 11, 1, 0))
.addEntry(Entry(TEST_IFACE, TEST_UID2, SET_DEFAULT, TAG_NONE,
METERED_NO, ROAMING_NO, DEFAULT_NETWORK_NO, 40, 1, 0, 0, 8))
.addEntry(Entry(IFACE_VT, TEST_UID1, SET_DEFAULT, TAG_NONE,
METERED_NO, ROAMING_NO, DEFAULT_NETWORK_NO, 3, 1, 6, 2, 0))
private val testStats2 = NetworkStats(0L, 0)
// Entries which are common for set1 and set2.
.addEntry(Entry(TEST_IFACE, TEST_UID1, SET_DEFAULT, 0x80,
METERED_NO, ROAMING_NO, DEFAULT_NETWORK_NO, 3, 15, 2, 31, 1))
.addEntry(Entry(TEST_IFACE, TEST_UID1, SET_FOREGROUND, TAG_NONE,
METERED_NO, ROAMING_NO, DEFAULT_NETWORK_NO, 13, 61, 10, 1, 45))
.addEntry(Entry(TEST_IFACE, TEST_UID2, SET_DEFAULT, TAG_NONE,
METERED_NO, ROAMING_NO, DEFAULT_NETWORK_NO, 11, 2, 3, 4, 7))
.addEntry(Entry(IFACE_VT, TEST_UID1, SET_DEFAULT, TAG_NONE,
METERED_NO, ROAMING_NO, DEFAULT_NETWORK_NO, 4, 3, 2, 1, 0))
// Entry which only appears in set2.
.addEntry(Entry(IFACE_VT, TEST_UID2, SET_DEFAULT, TAG_NONE,
METERED_NO, ROAMING_NO, DEFAULT_NETWORK_NO, 2, 3, 7, 8, 0))
// This is a result of adding stats1 and stats2, while the merging of common key items is
// subject to test later, this should not be initialized with for a loop to add stats1
// and stats2 above.
private val testStats3 = NetworkStats(0L, 9)
// Entries which are unique either in stats1 or stats2.
.addEntry(Entry(TEST_IFACE, TEST_UID1, SET_DEFAULT, TAG_NONE,
METERED_NO, ROAMING_NO, DEFAULT_NETWORK_NO, 101, 2, 103, 4, 5))
.addEntry(Entry(TEST_IFACE, TEST_UID1, SET_DEFAULT, TAG_NONE,
METERED_NO, ROAMING_YES, DEFAULT_NETWORK_NO, 31, 7, 24, 5, 8))
.addEntry(Entry(TEST_IFACE, TEST_UID1, SET_DEFAULT, TAG_NONE,
METERED_YES, ROAMING_NO, DEFAULT_NETWORK_NO, 25, 3, 47, 8, 2))
.addEntry(Entry(IFACE_VT, TEST_UID2, SET_DEFAULT, TAG_NONE,
METERED_NO, ROAMING_NO, DEFAULT_NETWORK_NO, 2, 3, 7, 8, 0))
// Entries which are common for stats1 and stats2 are being merged.
.addEntry(Entry(TEST_IFACE, TEST_UID1, SET_DEFAULT, TAG_NONE,
METERED_NO, ROAMING_NO, DEFAULT_NETWORK_YES, 20, 3, 57, 40, 3))
.addEntry(Entry(TEST_IFACE, TEST_UID1, SET_DEFAULT, 0x80,
METERED_NO, ROAMING_NO, DEFAULT_NETWORK_NO, 20, 17, 13, 32, 1))
.addEntry(Entry(TEST_IFACE, TEST_UID1, SET_FOREGROUND, TAG_NONE,
METERED_NO, ROAMING_NO, DEFAULT_NETWORK_NO, 50, 113, 11, 11, 49))
.addEntry(Entry(TEST_IFACE, TEST_UID2, SET_DEFAULT, TAG_NONE,
METERED_NO, ROAMING_NO, DEFAULT_NETWORK_NO, 51, 3, 3, 4, 15))
.addEntry(Entry(IFACE_VT, TEST_UID1, SET_DEFAULT, TAG_NONE,
METERED_NO, ROAMING_NO, DEFAULT_NETWORK_NO, 7, 4, 8, 3, 0))
companion object {
private const val TEST_IFACE = "test0"
private const val TEST_UID1 = 1001
private const val TEST_UID2 = 1002
}
@Before
fun setUp() {
assertEquals(8, testStats1.size())
assertEquals(5, testStats2.size())
assertEquals(9, testStats3.size())
}
@Test
@IgnoreUpTo(Build.VERSION_CODES.Q)
fun testAddEntry() {
val expectedEntriesInStats2 = arrayOf(
Entry(TEST_IFACE, TEST_UID1, SET_DEFAULT, 0x80,
METERED_NO, ROAMING_NO, DEFAULT_NETWORK_NO, 3, 15, 2, 31, 1),
Entry(TEST_IFACE, TEST_UID1, SET_FOREGROUND, TAG_NONE,
METERED_NO, ROAMING_NO, DEFAULT_NETWORK_NO, 13, 61, 10, 1, 45),
Entry(TEST_IFACE, TEST_UID2, SET_DEFAULT, TAG_NONE,
METERED_NO, ROAMING_NO, DEFAULT_NETWORK_NO, 11, 2, 3, 4, 7),
Entry(IFACE_VT, TEST_UID1, SET_DEFAULT, TAG_NONE,
METERED_NO, ROAMING_NO, DEFAULT_NETWORK_NO, 4, 3, 2, 1, 0),
Entry(IFACE_VT, TEST_UID2, SET_DEFAULT, TAG_NONE,
METERED_NO, ROAMING_NO, DEFAULT_NETWORK_NO, 2, 3, 7, 8, 0))
// While testStats* are already initialized with addEntry, verify content added
// matches expectation.
for (i in expectedEntriesInStats2.indices) {
val entry = testStats2.getValues(i, null)
assertEquals(expectedEntriesInStats2[i], entry)
}
// Verify entry updated with addEntry.
val stats = testStats2.addEntry(Entry(IFACE_VT, TEST_UID1, SET_DEFAULT, TAG_NONE,
METERED_NO, ROAMING_NO, DEFAULT_NETWORK_NO, 12, -5, 7, 0, 9))
assertEquals(Entry(IFACE_VT, TEST_UID1, SET_DEFAULT, TAG_NONE,
METERED_NO, ROAMING_NO, DEFAULT_NETWORK_NO, 16, -2, 9, 1, 9),
stats.getValues(3, null))
}
@Test
@IgnoreUpTo(Build.VERSION_CODES.Q)
fun testAdd() {
var stats = NetworkStats(0L, 0)
assertNetworkStatsEquals(testStatsEmpty, stats)
stats = stats.add(testStats2)
assertNetworkStatsEquals(testStats2, stats)
stats = stats.add(testStats1)
// EMPTY + STATS2 + STATS1 = STATS3
assertNetworkStatsEquals(testStats3, stats)
}
@Test
@IgnoreUpTo(Build.VERSION_CODES.Q)
fun testParcelUnparcel() {
assertParcelingIsLossless(testStatsEmpty)
assertParcelingIsLossless(testStats1)
assertParcelingIsLossless(testStats2)
assertFieldCountEquals(15, NetworkStats::class.java)
}
@Test
@IgnoreUpTo(Build.VERSION_CODES.Q)
fun testDescribeContents() {
assertEquals(0, testStatsEmpty.describeContents())
assertEquals(0, testStats1.describeContents())
assertEquals(0, testStats2.describeContents())
assertEquals(0, testStats3.describeContents())
}
@Test
@IgnoreUpTo(Build.VERSION_CODES.Q)
fun testSubtract() {
// STATS3 - STATS2 = STATS1
assertNetworkStatsEquals(testStats1, testStats3.subtract(testStats2))
// STATS3 - STATS1 = STATS2
assertNetworkStatsEquals(testStats2, testStats3.subtract(testStats1))
}
@Test
@IgnoreUpTo(Build.VERSION_CODES.Q)
fun testMethodsDontModifyReceiver() {
listOf(testStatsEmpty, testStats1, testStats2, testStats3).forEach {
val origStats = it.clone()
it.addEntry(Entry(TEST_IFACE, TEST_UID1, SET_FOREGROUND, TAG_NONE,
METERED_NO, ROAMING_NO, DEFAULT_NETWORK_NO, 13, 61, 10, 1, 45))
it.add(testStats3)
it.subtract(testStats1)
assertNetworkStatsEquals(origStats, it)
}
}
}

View File

@@ -502,6 +502,53 @@ public class NetworkStatsTest {
DEFAULT_NETWORK_NO, 64L, 2L, 0L, 0L, 0L); DEFAULT_NETWORK_NO, 64L, 2L, 0L, 0L, 0L);
} }
@Test
public void testRemoveEmptyEntries() throws Exception {
// Test empty stats.
final NetworkStats statsEmpty = new NetworkStats(TEST_START, 3);
assertEquals(0, statsEmpty.removeEmptyEntries().size());
// Test stats with non-zero entry.
final NetworkStats statsNonZero = new NetworkStats(TEST_START, 1)
.insertEntry(TEST_IFACE, 99, SET_DEFAULT, TAG_NONE, METERED_NO,
ROAMING_NO, DEFAULT_NETWORK_NO, 1L, 128L, 0L, 2L, 20L);
assertEquals(1, statsNonZero.size());
final NetworkStats expectedNonZero = statsNonZero.removeEmptyEntries();
assertEquals(1, expectedNonZero.size());
assertValues(expectedNonZero, 0, TEST_IFACE, 99, SET_DEFAULT, TAG_NONE, METERED_NO,
ROAMING_NO, DEFAULT_NETWORK_NO, 1L, 128L, 0L, 2L, 20L);
// Test stats with empty entry.
final NetworkStats statsZero = new NetworkStats(TEST_START, 1)
.insertEntry(TEST_IFACE, 99, SET_DEFAULT, TAG_NONE, METERED_NO,
ROAMING_NO, DEFAULT_NETWORK_NO, 0L, 0L, 0L, 0L, 0L);
assertEquals(1, statsZero.size());
final NetworkStats expectedZero = statsZero.removeEmptyEntries();
assertEquals(1, statsZero.size()); // Assert immutable.
assertEquals(0, expectedZero.size());
// Test stats with multiple entries.
final NetworkStats statsMultiple = new NetworkStats(TEST_START, 0)
.insertEntry(TEST_IFACE, 100, SET_DEFAULT, TAG_NONE, 2L, 64L, 0L, 2L, 20L)
.insertEntry(TEST_IFACE2, 100, SET_DEFAULT, TAG_NONE, 4L, 32L, 0L, 0L, 0L)
.insertEntry(TEST_IFACE, 101, SET_DEFAULT, 0xF00D, 0L, 0L, 0L, 0L, 0L)
.insertEntry(TEST_IFACE, 101, SET_DEFAULT, 0xF00D, 0L, 0L, 0L, 0L, 0L)
.insertEntry(TEST_IFACE2, 100, SET_DEFAULT, 0xF00D, 8L, 0L, 0L, 0L, 0L)
.insertEntry(TEST_IFACE2, 100, SET_FOREGROUND, TAG_NONE, 0L, 8L, 0L, 0L, 0L)
.insertEntry(TEST_IFACE, 101, SET_DEFAULT, TAG_NONE, 0L, 0L, 4L, 0L, 0L)
.insertEntry(TEST_IFACE, 101, SET_DEFAULT, 0xF00D, 0L, 0L, 0L, 2L, 0L)
.insertEntry(TEST_IFACE, 101, SET_DEFAULT, 0xF00D, 0L, 0L, 0L, 0L, 1L);
assertEquals(9, statsMultiple.size());
final NetworkStats expectedMultiple = statsMultiple.removeEmptyEntries();
assertEquals(9, statsMultiple.size()); // Assert immutable.
assertEquals(7, expectedMultiple.size());
assertValues(expectedMultiple.getTotalIncludingTags(null), 14L, 104L, 4L, 4L, 21L);
// Test stats with multiple empty entries.
assertEquals(statsMultiple.size(), statsMultiple.subtract(statsMultiple).size());
assertEquals(0, statsMultiple.subtract(statsMultiple).removeEmptyEntries().size());
}
@Test @Test
public void testClone() throws Exception { public void testClone() throws Exception {
final NetworkStats original = new NetworkStats(TEST_START, 5) final NetworkStats original = new NetworkStats(TEST_START, 5)

View File

@@ -181,7 +181,7 @@ public class Nat464XlatTest {
Nat464Xlat nat = makeNat464Xlat(); Nat464Xlat nat = makeNat464Xlat();
ArgumentCaptor<LinkProperties> c = ArgumentCaptor.forClass(LinkProperties.class); ArgumentCaptor<LinkProperties> c = ArgumentCaptor.forClass(LinkProperties.class);
nat.setNat64Prefix(new IpPrefix(NAT64_PREFIX)); nat.setNat64PrefixFromDns(new IpPrefix(NAT64_PREFIX));
// Start clat. // Start clat.
nat.start(); nat.start();
@@ -222,7 +222,7 @@ public class Nat464XlatTest {
ArgumentCaptor<LinkProperties> c = ArgumentCaptor.forClass(LinkProperties.class); ArgumentCaptor<LinkProperties> c = ArgumentCaptor.forClass(LinkProperties.class);
InOrder inOrder = inOrder(mNetd, mConnectivity); InOrder inOrder = inOrder(mNetd, mConnectivity);
nat.setNat64Prefix(new IpPrefix(NAT64_PREFIX)); nat.setNat64PrefixFromDns(new IpPrefix(NAT64_PREFIX));
nat.start(); nat.start();
@@ -309,7 +309,7 @@ public class Nat464XlatTest {
Nat464Xlat nat = makeNat464Xlat(); Nat464Xlat nat = makeNat464Xlat();
ArgumentCaptor<LinkProperties> c = ArgumentCaptor.forClass(LinkProperties.class); ArgumentCaptor<LinkProperties> c = ArgumentCaptor.forClass(LinkProperties.class);
nat.setNat64Prefix(new IpPrefix(NAT64_PREFIX)); nat.setNat64PrefixFromDns(new IpPrefix(NAT64_PREFIX));
nat.start(); nat.start();
@@ -348,7 +348,7 @@ public class Nat464XlatTest {
public void testStopBeforeClatdStarts() throws Exception { public void testStopBeforeClatdStarts() throws Exception {
Nat464Xlat nat = makeNat464Xlat(); Nat464Xlat nat = makeNat464Xlat();
nat.setNat64Prefix(new IpPrefix(NAT64_PREFIX)); nat.setNat64PrefixFromDns(new IpPrefix(NAT64_PREFIX));
nat.start(); nat.start();
@@ -380,7 +380,7 @@ public class Nat464XlatTest {
public void testStopAndClatdNeverStarts() throws Exception { public void testStopAndClatdNeverStarts() throws Exception {
Nat464Xlat nat = makeNat464Xlat(); Nat464Xlat nat = makeNat464Xlat();
nat.setNat64Prefix(new IpPrefix(NAT64_PREFIX)); nat.setNat64PrefixFromDns(new IpPrefix(NAT64_PREFIX));
nat.start(); nat.start();