Search in sources :

Example 31 with ConditionVariable

use of android.os.ConditionVariable in project android_frameworks_base by ResurrectionRemix.

the class ConnectivityServiceTest method testMMSonWiFi.

@LargeTest
public void testMMSonWiFi() throws Exception {
    // Test bringing up cellular without MMS NetworkRequest gets reaped
    mCellNetworkAgent = new MockNetworkAgent(TRANSPORT_CELLULAR);
    mCellNetworkAgent.addCapability(NET_CAPABILITY_MMS);
    ConditionVariable cv = mCellNetworkAgent.getDisconnectedCV();
    mCellNetworkAgent.connectWithoutInternet();
    waitFor(cv);
    waitFor(new Criteria() {

        public boolean get() {
            return mCm.getAllNetworks().length == 0;
        }
    });
    verifyNoNetwork();
    // Test bringing up validated WiFi.
    mWiFiNetworkAgent = new MockNetworkAgent(TRANSPORT_WIFI);
    cv = waitForConnectivityBroadcasts(1);
    mWiFiNetworkAgent.connect(true);
    waitFor(cv);
    verifyActiveNetwork(TRANSPORT_WIFI);
    // Register MMS NetworkRequest
    NetworkRequest.Builder builder = new NetworkRequest.Builder();
    builder.addCapability(NetworkCapabilities.NET_CAPABILITY_MMS);
    final TestNetworkCallback networkCallback = new TestNetworkCallback();
    mCm.requestNetwork(builder.build(), networkCallback);
    // Test bringing up unvalidated cellular with MMS
    mCellNetworkAgent = new MockNetworkAgent(TRANSPORT_CELLULAR);
    mCellNetworkAgent.addCapability(NET_CAPABILITY_MMS);
    mCellNetworkAgent.connectWithoutInternet();
    networkCallback.expectCallback(CallbackState.AVAILABLE, mCellNetworkAgent);
    verifyActiveNetwork(TRANSPORT_WIFI);
    // Test releasing NetworkRequest disconnects cellular with MMS
    cv = mCellNetworkAgent.getDisconnectedCV();
    mCm.unregisterNetworkCallback(networkCallback);
    waitFor(cv);
    verifyActiveNetwork(TRANSPORT_WIFI);
}
Also used : ConditionVariable(android.os.ConditionVariable) NetworkRequest(android.net.NetworkRequest) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 32 with ConditionVariable

use of android.os.ConditionVariable in project android_frameworks_base by ResurrectionRemix.

the class SyncRunner method scheduleFilterWake.

protected void scheduleFilterWake(Filter filter, int delay) {
    // Close the wake condition
    mWakeCondition.close();
    // Schedule the wake-up
    final Filter filterToSchedule = filter;
    final ConditionVariable conditionToWake = mWakeCondition;
    mWakeExecutor.schedule(new Runnable() {

        @Override
        public void run() {
            filterToSchedule.unsetStatus(Filter.STATUS_SLEEPING);
            conditionToWake.open();
        }
    }, delay, TimeUnit.MILLISECONDS);
}
Also used : ConditionVariable(android.os.ConditionVariable)

Example 33 with ConditionVariable

use of android.os.ConditionVariable in project android_frameworks_base by DirtyUnicorns.

the class ConnectivityServiceTest method testNetworkPinner.

@SmallTest
public void testNetworkPinner() {
    NetworkRequest wifiRequest = new NetworkRequest.Builder().addTransportType(TRANSPORT_WIFI).build();
    assertNull(mCm.getBoundNetworkForProcess());
    TestNetworkPinner.pin(mServiceContext, wifiRequest);
    assertNull(mCm.getBoundNetworkForProcess());
    mCellNetworkAgent = new MockNetworkAgent(TRANSPORT_CELLULAR);
    mCellNetworkAgent.connect(true);
    mWiFiNetworkAgent = new MockNetworkAgent(TRANSPORT_WIFI);
    mWiFiNetworkAgent.connect(false);
    // When wi-fi connects, expect to be pinned.
    assertTrue(TestNetworkPinner.awaitPin(100));
    assertPinnedToWifiWithCellDefault();
    // Disconnect and expect the pin to drop.
    mWiFiNetworkAgent.disconnect();
    assertTrue(TestNetworkPinner.awaitUnpin(100));
    assertNotPinnedToWifi();
    // Reconnecting does not cause the pin to come back.
    mWiFiNetworkAgent = new MockNetworkAgent(TRANSPORT_WIFI);
    mWiFiNetworkAgent.connect(false);
    assertFalse(TestNetworkPinner.awaitPin(100));
    assertNotPinnedToWifi();
    // Pinning while connected causes the pin to take effect immediately.
    TestNetworkPinner.pin(mServiceContext, wifiRequest);
    assertTrue(TestNetworkPinner.awaitPin(100));
    assertPinnedToWifiWithCellDefault();
    // Explicitly unpin and expect to use the default network again.
    TestNetworkPinner.unpin();
    assertNotPinnedToWifi();
    // Disconnect cell and wifi.
    // cell down, wifi up, wifi down.
    ConditionVariable cv = waitForConnectivityBroadcasts(3);
    mCellNetworkAgent.disconnect();
    mWiFiNetworkAgent.disconnect();
    waitFor(cv);
    // Pinning takes effect even if the pinned network is the default when the pin is set...
    TestNetworkPinner.pin(mServiceContext, wifiRequest);
    mWiFiNetworkAgent = new MockNetworkAgent(TRANSPORT_WIFI);
    mWiFiNetworkAgent.connect(false);
    assertTrue(TestNetworkPinner.awaitPin(100));
    assertPinnedToWifiWithWifiDefault();
    // ... and is maintained even when that network is no longer the default.
    cv = waitForConnectivityBroadcasts(1);
    mCellNetworkAgent = new MockNetworkAgent(TRANSPORT_WIFI);
    mCellNetworkAgent.connect(true);
    waitFor(cv);
    assertPinnedToWifiWithCellDefault();
}
Also used : ConditionVariable(android.os.ConditionVariable) NetworkRequest(android.net.NetworkRequest) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 34 with ConditionVariable

use of android.os.ConditionVariable in project android_frameworks_base by DirtyUnicorns.

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");
}
Also used : ConditionVariable(android.os.ConditionVariable) Network(android.net.Network)

Example 35 with ConditionVariable

use of android.os.ConditionVariable in project android_frameworks_base by DirtyUnicorns.

the class ConnectivityServiceTest method testUnvalidatedWifiOutscoresUnvalidatedCellular.

@LargeTest
public void testUnvalidatedWifiOutscoresUnvalidatedCellular() throws Exception {
    // Test bringing up unvalidated cellular.
    mCellNetworkAgent = new MockNetworkAgent(TRANSPORT_CELLULAR);
    ConditionVariable cv = waitForConnectivityBroadcasts(1);
    mCellNetworkAgent.connect(false);
    waitFor(cv);
    verifyActiveNetwork(TRANSPORT_CELLULAR);
    // Test bringing up unvalidated WiFi.
    mWiFiNetworkAgent = new MockNetworkAgent(TRANSPORT_WIFI);
    cv = waitForConnectivityBroadcasts(2);
    mWiFiNetworkAgent.connect(false);
    waitFor(cv);
    verifyActiveNetwork(TRANSPORT_WIFI);
    // Test WiFi disconnect.
    cv = waitForConnectivityBroadcasts(2);
    mWiFiNetworkAgent.disconnect();
    waitFor(cv);
    verifyActiveNetwork(TRANSPORT_CELLULAR);
    // Test cellular disconnect.
    cv = waitForConnectivityBroadcasts(1);
    mCellNetworkAgent.disconnect();
    waitFor(cv);
    verifyNoNetwork();
}
Also used : ConditionVariable(android.os.ConditionVariable) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Aggregations

ConditionVariable (android.os.ConditionVariable)122 LargeTest (android.test.suitebuilder.annotation.LargeTest)36 NetworkRequest (android.net.NetworkRequest)24 SmallTest (android.test.suitebuilder.annotation.SmallTest)17 Handler (android.os.Handler)16 Messenger (android.os.Messenger)8 Test (org.junit.Test)6 Network (android.net.Network)5 Message (android.os.Message)5 PendingIntent (android.app.PendingIntent)4 BroadcastReceiver (android.content.BroadcastReceiver)4 Context (android.content.Context)4 Intent (android.content.Intent)4 IntentFilter (android.content.IntentFilter)4 ConnectivityManager (android.net.ConnectivityManager)4 NetworkCallback (android.net.ConnectivityManager.NetworkCallback)4 DataUsageRequest (android.net.DataUsageRequest)4 NetworkCapabilities (android.net.NetworkCapabilities)4 NetworkStats (android.net.NetworkStats)4 HandlerThread (android.os.HandlerThread)4