Search in sources :

Example 36 with ConditionVariable

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

the class ConnectivityServiceTest method testUnlingeringDoesNotValidate.

@LargeTest
public void testUnlingeringDoesNotValidate() throws Exception {
    // Test bringing up unvalidated WiFi.
    mWiFiNetworkAgent = new MockNetworkAgent(TRANSPORT_WIFI);
    ConditionVariable cv = waitForConnectivityBroadcasts(1);
    mWiFiNetworkAgent.connect(false);
    waitFor(cv);
    verifyActiveNetwork(TRANSPORT_WIFI);
    assertFalse(mCm.getNetworkCapabilities(mWiFiNetworkAgent.getNetwork()).hasCapability(NET_CAPABILITY_VALIDATED));
    // Test bringing up validated cellular.
    mCellNetworkAgent = new MockNetworkAgent(TRANSPORT_CELLULAR);
    cv = waitForConnectivityBroadcasts(2);
    mCellNetworkAgent.connect(true);
    waitFor(cv);
    verifyActiveNetwork(TRANSPORT_CELLULAR);
    assertFalse(mCm.getNetworkCapabilities(mWiFiNetworkAgent.getNetwork()).hasCapability(NET_CAPABILITY_VALIDATED));
    // Test cellular disconnect.
    cv = waitForConnectivityBroadcasts(2);
    mCellNetworkAgent.disconnect();
    waitFor(cv);
    verifyActiveNetwork(TRANSPORT_WIFI);
    // Unlingering a network should not cause it to be marked as validated.
    assertFalse(mCm.getNetworkCapabilities(mWiFiNetworkAgent.getNetwork()).hasCapability(NET_CAPABILITY_VALIDATED));
}
Also used : ConditionVariable(android.os.ConditionVariable) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 37 with ConditionVariable

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

the class ConnectivityServiceTest method testValidatedCellularOutscoresUnvalidatedWiFi.

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

Example 38 with ConditionVariable

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

the class ConnectivityServiceTest method testCellularOutscoresWeakWifi.

@LargeTest
public void testCellularOutscoresWeakWifi() throws Exception {
    // Test bringing up validated cellular.
    mCellNetworkAgent = new MockNetworkAgent(TRANSPORT_CELLULAR);
    ConditionVariable cv = waitForConnectivityBroadcasts(1);
    mCellNetworkAgent.connect(true);
    waitFor(cv);
    verifyActiveNetwork(TRANSPORT_CELLULAR);
    // Test bringing up validated WiFi.
    mWiFiNetworkAgent = new MockNetworkAgent(TRANSPORT_WIFI);
    cv = waitForConnectivityBroadcasts(2);
    mWiFiNetworkAgent.connect(true);
    waitFor(cv);
    verifyActiveNetwork(TRANSPORT_WIFI);
    // Test WiFi getting really weak.
    cv = waitForConnectivityBroadcasts(2);
    mWiFiNetworkAgent.adjustScore(-11);
    waitFor(cv);
    verifyActiveNetwork(TRANSPORT_CELLULAR);
    // Test WiFi restoring signal strength.
    cv = waitForConnectivityBroadcasts(2);
    mWiFiNetworkAgent.adjustScore(11);
    waitFor(cv);
    verifyActiveNetwork(TRANSPORT_WIFI);
}
Also used : ConditionVariable(android.os.ConditionVariable) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 39 with ConditionVariable

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

the class ConnectivityServiceTest method testReapingNetwork.

@LargeTest
public void testReapingNetwork() throws Exception {
    // Test bringing up WiFi without NET_CAPABILITY_INTERNET.
    // Expect it to be torn down immediately because it satisfies no requests.
    mWiFiNetworkAgent = new MockNetworkAgent(TRANSPORT_WIFI);
    ConditionVariable cv = mWiFiNetworkAgent.getDisconnectedCV();
    mWiFiNetworkAgent.connectWithoutInternet();
    waitFor(cv);
    // Test bringing up cellular without NET_CAPABILITY_INTERNET.
    // Expect it to be torn down immediately because it satisfies no requests.
    mCellNetworkAgent = new MockNetworkAgent(TRANSPORT_WIFI);
    cv = mCellNetworkAgent.getDisconnectedCV();
    mCellNetworkAgent.connectWithoutInternet();
    waitFor(cv);
    // Test bringing up validated WiFi.
    mWiFiNetworkAgent = new MockNetworkAgent(TRANSPORT_WIFI);
    cv = waitForConnectivityBroadcasts(1);
    mWiFiNetworkAgent.connect(true);
    waitFor(cv);
    verifyActiveNetwork(TRANSPORT_WIFI);
    // Test bringing up unvalidated cellular.
    // Expect it to be torn down because it could never be the highest scoring network
    // satisfying the default request even if it validated.
    mCellNetworkAgent = new MockNetworkAgent(TRANSPORT_CELLULAR);
    cv = mCellNetworkAgent.getDisconnectedCV();
    mCellNetworkAgent.connect(false);
    waitFor(cv);
    verifyActiveNetwork(TRANSPORT_WIFI);
    cv = mWiFiNetworkAgent.getDisconnectedCV();
    mWiFiNetworkAgent.disconnect();
    waitFor(cv);
}
Also used : ConditionVariable(android.os.ConditionVariable) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 40 with ConditionVariable

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

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)

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