Search in sources :

Example 6 with ConditionVariable

use of android.os.ConditionVariable in project platform_frameworks_base by android.

the class CameraTestThread method start.

/**
     * Create and start a looper thread, return the Handler
     */
public synchronized Handler start() throws Exception {
    final ConditionVariable startDone = new ConditionVariable();
    if (mLooper != null || mHandler != null) {
        Log.w(TAG, "Looper thread already started");
        return mHandler;
    }
    new Thread() {

        @Override
        public void run() {
            if (VERBOSE)
                Log.v(TAG, "start loopRun");
            Looper.prepare();
            // Save the looper so that we can terminate this thread
            // after we are done with it.
            mLooper = Looper.myLooper();
            mHandler = new Handler();
            startDone.open();
            Looper.loop();
            if (VERBOSE)
                Log.v(TAG, "createLooperThread: finished");
        }
    }.start();
    if (VERBOSE)
        Log.v(TAG, "start waiting for looper");
    if (!startDone.block(WAIT_FOR_COMMAND_TO_COMPLETE)) {
        throw new TimeoutException("createLooperThread: start timeout");
    }
    return mHandler;
}
Also used : ConditionVariable(android.os.ConditionVariable) Handler(android.os.Handler) TimeoutException(java.util.concurrent.TimeoutException)

Example 7 with ConditionVariable

use of android.os.ConditionVariable in project platform_frameworks_base by android.

the class ConnectivityServiceTest method testReapingNetwork.

@SmallTest
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) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 8 with ConditionVariable

use of android.os.ConditionVariable in project platform_frameworks_base by android.

the class ConnectivityServiceTest method waitForIdleHandler.

/**
     * Block until the given handler becomes idle, or until timeoutMs has passed.
     */
private static void waitForIdleHandler(HandlerThread handlerThread, int timeoutMs) {
    final ConditionVariable cv = new ConditionVariable();
    final Handler handler = new Handler(handlerThread.getLooper());
    handler.post(() -> cv.open());
    if (!cv.block(timeoutMs)) {
        fail("HandlerThread " + handlerThread.getName() + " did not become idle after " + timeoutMs + " ms");
    }
}
Also used : ConditionVariable(android.os.ConditionVariable) Handler(android.os.Handler) IdleHandler(android.os.MessageQueue.IdleHandler)

Example 9 with ConditionVariable

use of android.os.ConditionVariable in project platform_frameworks_base by android.

the class ConnectivityServiceTest method testValidatedCellularOutscoresUnvalidatedWiFi.

@SmallTest
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) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 10 with ConditionVariable

use of android.os.ConditionVariable in project platform_frameworks_base by android.

the class ConnectivityServiceTest method testCellularOutscoresWeakWifi.

@SmallTest
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) SmallTest(android.test.suitebuilder.annotation.SmallTest)

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