use of android.net.Network in project android_frameworks_base by crdroidandroid.
the class NetdEventListenerServiceTest method testDnsBatchAndNetworkLost.
@SmallTest
public void testDnsBatchAndNetworkLost() throws Exception {
byte[] eventTypes = Arrays.copyOf(EVENT_TYPES, 20);
byte[] returnCodes = Arrays.copyOf(RETURN_CODES, 20);
int[] latencies = Arrays.copyOf(LATENCIES, 20);
log(105, LATENCIES);
log(105, latencies);
mCallbackCaptor.getValue().onLost(new Network(105));
log(105, LATENCIES);
verifyLoggedDnsEvents(new DnsEvent(105, eventTypes, returnCodes, latencies), new DnsEvent(105, EVENT_TYPES, RETURN_CODES, LATENCIES), new DnsEvent(105, EVENT_TYPES, RETURN_CODES, LATENCIES));
}
use of android.net.Network in project android_frameworks_base by crdroidandroid.
the class ConnectivityService method getAllNetworkState.
@Override
public NetworkState[] getAllNetworkState() {
// Require internal since we're handing out IMSI details
enforceConnectivityInternalPermission();
final ArrayList<NetworkState> result = Lists.newArrayList();
for (Network network : getAllNetworks()) {
final NetworkAgentInfo nai = getNetworkAgentInfoForNetwork(network);
if (nai != null) {
result.add(nai.getNetworkState());
}
}
return result.toArray(new NetworkState[result.size()]);
}
use of android.net.Network in project android_frameworks_base by crdroidandroid.
the class NetworkTest method testGetNetworkHandle.
@SmallTest
public void testGetNetworkHandle() {
Network one = new Network(1);
Network two = new Network(2);
Network three = new Network(3);
// None of the hashcodes are zero.
assertNotEqual(0, one.hashCode());
assertNotEqual(0, two.hashCode());
assertNotEqual(0, three.hashCode());
// All the hashcodes are distinct.
assertNotEqual(one.hashCode(), two.hashCode());
assertNotEqual(one.hashCode(), three.hashCode());
assertNotEqual(two.hashCode(), three.hashCode());
// None of the handles are zero.
assertNotEqual(0, one.getNetworkHandle());
assertNotEqual(0, two.getNetworkHandle());
assertNotEqual(0, three.getNetworkHandle());
// All the handles are distinct.
assertNotEqual(one.getNetworkHandle(), two.getNetworkHandle());
assertNotEqual(one.getNetworkHandle(), three.getNetworkHandle());
assertNotEqual(two.getNetworkHandle(), three.getNetworkHandle());
// The handles are not equal to the hashcodes.
assertNotEqual(one.hashCode(), one.getNetworkHandle());
assertNotEqual(two.hashCode(), two.getNetworkHandle());
assertNotEqual(three.hashCode(), three.getNetworkHandle());
// Adjust as necessary to test an implementation's specific constants.
// When running with runtest, "adb logcat -s TestRunner" can be useful.
assertEquals(4311403230L, one.getNetworkHandle());
assertEquals(8606370526L, two.getNetworkHandle());
assertEquals(12901337822L, three.getNetworkHandle());
}
use of android.net.Network in project android_frameworks_base by crdroidandroid.
the class NetworkTest method testZeroIsObviousForDebugging.
@SmallTest
public void testZeroIsObviousForDebugging() {
Network zero = new Network(0);
assertEquals(0, zero.hashCode());
assertEquals(0, zero.getNetworkHandle());
assertEquals("0", zero.toString());
}
use of android.net.Network in project android_frameworks_base by crdroidandroid.
the class ConnectivityServiceTest method testIdleableHandlerThread.
// Tests that IdleableHandlerThread works as expected.
public void testIdleableHandlerThread() {
// Causes the test to take about 200ms on bullhead-eng.
final int attempts = 50;
// Tests that waitForIdle returns immediately if the service is already idle.
for (int i = 0; i < attempts; i++) {
mService.waitForIdle();
}
// Bring up a network that we can use to send messages to ConnectivityService.
ConditionVariable cv = waitForConnectivityBroadcasts(1);
mWiFiNetworkAgent = new MockNetworkAgent(TRANSPORT_WIFI);
mWiFiNetworkAgent.connect(false);
waitFor(cv);
Network n = mWiFiNetworkAgent.getNetwork();
assertNotNull(n);
// Tests that calling waitForIdle waits for messages to be processed.
for (int i = 0; i < attempts; i++) {
mWiFiNetworkAgent.setSignalStrength(i);
mService.waitForIdle();
assertEquals(i, mCm.getNetworkCapabilities(n).getSignalStrength());
}
// Ensure that not calling waitForIdle causes a race condition.
for (int i = 0; i < attempts; i++) {
mWiFiNetworkAgent.setSignalStrength(i);
if (i != mCm.getNetworkCapabilities(n).getSignalStrength()) {
// We hit a race condition, as expected. Pass the test.
return;
}
}
// No race? There is a bug in this test.
fail("expected race condition at least once in " + attempts + " attempts");
}
Aggregations