Snap for 6538416 from f034d7c25aa22203c1fa7d4df5a4407885ac960f to rvc-release
Change-Id: I099ac6f47958841605d3a8c713a1168ca2096ec6
This commit is contained in:
@@ -130,14 +130,11 @@ public class NetworkCallbackTest extends AbstractRestrictBackgroundNetworkTestCa
|
||||
setLastCallback(CallbackState.CAPABILITIES, network, cap);
|
||||
}
|
||||
|
||||
public void expectLostCallback(Network expectedNetwork) {
|
||||
expectCallback(CallbackState.LOST, expectedNetwork, null);
|
||||
}
|
||||
|
||||
public Network expectAvailableCallbackAndGetNetwork() {
|
||||
final CallbackInfo cb = nextCallback(TEST_CALLBACK_TIMEOUT_MS);
|
||||
if (cb.state != CallbackState.AVAILABLE) {
|
||||
fail("Network is not available");
|
||||
fail("Network is not available. Instead obtained the following callback :"
|
||||
+ cb);
|
||||
}
|
||||
return cb.network;
|
||||
}
|
||||
@@ -152,7 +149,7 @@ public class NetworkCallbackTest extends AbstractRestrictBackgroundNetworkTestCa
|
||||
do {
|
||||
final CallbackInfo cb = nextCallback((int) (deadline - System.currentTimeMillis()));
|
||||
if (cb.state == CallbackState.BLOCKED_STATUS) {
|
||||
assertEquals(expectBlocked, (Boolean) cb.arg);
|
||||
assertEquals(expectBlocked, cb.arg);
|
||||
return;
|
||||
}
|
||||
} while (System.currentTimeMillis() <= deadline);
|
||||
@@ -165,10 +162,10 @@ public class NetworkCallbackTest extends AbstractRestrictBackgroundNetworkTestCa
|
||||
final NetworkCapabilities cap = (NetworkCapabilities) cb.arg;
|
||||
assertEquals(expectedNetwork, cb.network);
|
||||
assertEquals(CallbackState.CAPABILITIES, cb.state);
|
||||
if (hasCapability) {
|
||||
assertTrue(cap.hasCapability(capability));
|
||||
} else {
|
||||
assertFalse(cap.hasCapability(capability));
|
||||
if (hasCapability != cap.hasCapability(capability)) {
|
||||
fail("NetworkCapabilities callback "
|
||||
+ (hasCapability ? "missing expected" : "has unexpected")
|
||||
+ " capability. " + cb);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,12 +18,15 @@ package android.net.cts;
|
||||
|
||||
import static android.os.Process.INVALID_UID;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import android.annotation.NonNull;
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.net.INetworkStatsService;
|
||||
import android.net.TrafficStats;
|
||||
import android.os.Build;
|
||||
import android.os.IBinder;
|
||||
import android.os.Process;
|
||||
import android.os.RemoteException;
|
||||
@@ -31,8 +34,15 @@ import android.test.AndroidTestCase;
|
||||
import android.util.SparseArray;
|
||||
|
||||
import androidx.test.InstrumentationRegistry;
|
||||
import androidx.test.runner.AndroidJUnit4;
|
||||
|
||||
import com.android.internal.util.CollectionUtils;
|
||||
import com.android.testutils.DevSdkIgnoreRule;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
@@ -41,17 +51,22 @@ import java.util.List;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class NetworkStatsBinderTest extends AndroidTestCase {
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class NetworkStatsBinderTest {
|
||||
// NOTE: These are shamelessly copied from TrafficStats.
|
||||
private static final int TYPE_RX_BYTES = 0;
|
||||
private static final int TYPE_RX_PACKETS = 1;
|
||||
private static final int TYPE_TX_BYTES = 2;
|
||||
private static final int TYPE_TX_PACKETS = 3;
|
||||
|
||||
@Rule
|
||||
public DevSdkIgnoreRule mIgnoreRule = new DevSdkIgnoreRule(
|
||||
Build.VERSION_CODES.Q /* ignoreClassUpTo */);
|
||||
|
||||
private final SparseArray<Function<Integer, Long>> mUidStatsQueryOpArray = new SparseArray<>();
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
mUidStatsQueryOpArray.put(TYPE_RX_BYTES, uid -> TrafficStats.getUidRxBytes(uid));
|
||||
mUidStatsQueryOpArray.put(TYPE_RX_PACKETS, uid -> TrafficStats.getUidRxPackets(uid));
|
||||
mUidStatsQueryOpArray.put(TYPE_TX_BYTES, uid -> TrafficStats.getUidTxBytes(uid));
|
||||
@@ -75,6 +90,7 @@ public class NetworkStatsBinderTest extends AndroidTestCase {
|
||||
return INVALID_UID;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAccessUidStatsFromBinder() throws Exception {
|
||||
final int myUid = Process.myUid();
|
||||
final List<Integer> testUidList = new ArrayList<>();
|
||||
|
||||
@@ -56,6 +56,7 @@ import android.net.TetheringManager.TetheringEventCallback;
|
||||
import android.net.TetheringManager.TetheringInterfaceRegexps;
|
||||
import android.net.TetheringManager.TetheringRequest;
|
||||
import android.net.cts.util.CtsNetUtils;
|
||||
import android.net.cts.util.CtsNetUtils.TestNetworkCallback;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.Bundle;
|
||||
import android.os.PersistableBundle;
|
||||
@@ -714,7 +715,15 @@ public class TetheringManagerTest {
|
||||
mCtsNetUtils.disconnectFromWifi(null);
|
||||
}
|
||||
|
||||
final Network activeNetwork = mCm.getActiveNetwork();
|
||||
final TestNetworkCallback networkCallback = new TestNetworkCallback();
|
||||
Network activeNetwork = null;
|
||||
try {
|
||||
mCm.registerDefaultNetworkCallback(networkCallback);
|
||||
activeNetwork = networkCallback.waitForAvailable();
|
||||
} finally {
|
||||
mCm.unregisterNetworkCallback(networkCallback);
|
||||
}
|
||||
|
||||
assertNotNull("No active network. Please ensure the device has working mobile data.",
|
||||
activeNetwork);
|
||||
final NetworkCapabilities activeNetCap = mCm.getNetworkCapabilities(activeNetwork);
|
||||
|
||||
Reference in New Issue
Block a user