Search in sources :

Example 91 with ConditionVariable

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

the class MediaPlayerPerformance method initializeMessageLooper.

private void initializeMessageLooper() {
    final ConditionVariable startDone = new ConditionVariable();
    new Thread() {

        @Override
        public void run() {
            Looper.prepare();
            Log.v(TAG, "start loopRun");
            mLooper = Looper.myLooper();
            mCamera = Camera.open(CAMERA_ID);
            startDone.open();
            Looper.loop();
            Log.v(TAG, "initializeMessageLooper: quit.");
        }
    }.start();
    if (!startDone.block(WAIT_FOR_COMMAND_TO_COMPLETE)) {
        fail("initializeMessageLooper: start timeout");
    }
}
Also used : ConditionVariable(android.os.ConditionVariable)

Example 92 with ConditionVariable

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

the class MediaPlayerPerformance method initializeMessageLooper.

private void initializeMessageLooper() {
    final ConditionVariable startDone = new ConditionVariable();
    new Thread() {

        @Override
        public void run() {
            Looper.prepare();
            Log.v(TAG, "start loopRun");
            mLooper = Looper.myLooper();
            mCamera = Camera.open(CAMERA_ID);
            startDone.open();
            Looper.loop();
            Log.v(TAG, "initializeMessageLooper: quit.");
        }
    }.start();
    if (!startDone.block(WAIT_FOR_COMMAND_TO_COMPLETE)) {
        fail("initializeMessageLooper: start timeout");
    }
}
Also used : ConditionVariable(android.os.ConditionVariable)

Example 93 with ConditionVariable

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

the class RequestThreadManager method configure.

/**
     * Configure with the current list of output Surfaces.
     *
     * <p>
     * This operation blocks until the configuration is complete.
     * </p>
     *
     * <p>Using a {@code null} or empty {@code outputs} list is the equivalent of unconfiguring.</p>
     *
     * @param outputs a {@link java.util.Collection} of outputs to configure.
     */
public void configure(Collection<Pair<Surface, Size>> outputs) {
    Handler handler = mRequestThread.waitAndGetHandler();
    final ConditionVariable condition = new ConditionVariable(/*closed*/
    false);
    ConfigureHolder holder = new ConfigureHolder(condition, outputs);
    handler.sendMessage(handler.obtainMessage(MSG_CONFIGURE_OUTPUTS, 0, 0, holder));
    condition.block();
}
Also used : ConditionVariable(android.os.ConditionVariable) Handler(android.os.Handler)

Example 94 with ConditionVariable

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

the class CameraTest method initializeMessageLooper.

/*
     * Initializes the message looper so that the Camera object can 
     * receive the callback messages.
     */
private void initializeMessageLooper() {
    final ConditionVariable startDone = new ConditionVariable();
    Log.v(TAG, "start looper");
    new Thread() {

        @Override
        public void run() {
            // Set up a looper to be used by camera.
            Looper.prepare();
            Log.v(TAG, "start loopRun");
            // Save the looper so that we can terminate this thread 
            // after we are done with it.
            mLooper = Looper.myLooper();
            mCamera = Camera.open(CAMERA_ID);
            startDone.open();
            // Blocks forever until Looper.quit() is called.
            Looper.loop();
            Log.v(TAG, "initializeMessageLooper: quit.");
        }
    }.start();
    if (!startDone.block(WAIT_FOR_COMMAND_TO_COMPLETE)) {
        fail("initializeMessageLooper: start timeout");
    }
}
Also used : ConditionVariable(android.os.ConditionVariable)

Example 95 with ConditionVariable

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

the class ConnectivityServiceTest method testStateChangeNetworkCallbacks.

@LargeTest
public void testStateChangeNetworkCallbacks() throws Exception {
    final TestNetworkCallback genericNetworkCallback = new TestNetworkCallback();
    final TestNetworkCallback wifiNetworkCallback = new TestNetworkCallback();
    final TestNetworkCallback cellNetworkCallback = new TestNetworkCallback();
    final NetworkRequest genericRequest = new NetworkRequest.Builder().clearCapabilities().build();
    final NetworkRequest wifiRequest = new NetworkRequest.Builder().addTransportType(TRANSPORT_WIFI).build();
    final NetworkRequest cellRequest = new NetworkRequest.Builder().addTransportType(TRANSPORT_CELLULAR).build();
    mCm.registerNetworkCallback(genericRequest, genericNetworkCallback);
    mCm.registerNetworkCallback(wifiRequest, wifiNetworkCallback);
    mCm.registerNetworkCallback(cellRequest, cellNetworkCallback);
    // Test unvalidated networks
    ConditionVariable cv = waitForConnectivityBroadcasts(1);
    mCellNetworkAgent = new MockNetworkAgent(TRANSPORT_CELLULAR);
    mCellNetworkAgent.connect(false);
    genericNetworkCallback.expectCallback(CallbackState.AVAILABLE, mCellNetworkAgent);
    cellNetworkCallback.expectCallback(CallbackState.AVAILABLE, mCellNetworkAgent);
    assertEquals(mCellNetworkAgent.getNetwork(), mCm.getActiveNetwork());
    waitFor(cv);
    assertNoCallbacks(genericNetworkCallback, wifiNetworkCallback, cellNetworkCallback);
    // This should not trigger spurious onAvailable() callbacks, b/21762680.
    mCellNetworkAgent.adjustScore(-1);
    mService.waitForIdle();
    assertNoCallbacks(genericNetworkCallback, wifiNetworkCallback, cellNetworkCallback);
    assertEquals(mCellNetworkAgent.getNetwork(), mCm.getActiveNetwork());
    cv = waitForConnectivityBroadcasts(2);
    mWiFiNetworkAgent = new MockNetworkAgent(TRANSPORT_WIFI);
    mWiFiNetworkAgent.connect(false);
    genericNetworkCallback.expectCallback(CallbackState.AVAILABLE, mWiFiNetworkAgent);
    wifiNetworkCallback.expectCallback(CallbackState.AVAILABLE, mWiFiNetworkAgent);
    assertEquals(mWiFiNetworkAgent.getNetwork(), mCm.getActiveNetwork());
    waitFor(cv);
    assertNoCallbacks(genericNetworkCallback, wifiNetworkCallback, cellNetworkCallback);
    cv = waitForConnectivityBroadcasts(2);
    mWiFiNetworkAgent.disconnect();
    genericNetworkCallback.expectCallback(CallbackState.LOST, mWiFiNetworkAgent);
    wifiNetworkCallback.expectCallback(CallbackState.LOST, mWiFiNetworkAgent);
    cellNetworkCallback.assertNoCallback();
    waitFor(cv);
    assertNoCallbacks(genericNetworkCallback, wifiNetworkCallback, cellNetworkCallback);
    cv = waitForConnectivityBroadcasts(1);
    mCellNetworkAgent.disconnect();
    genericNetworkCallback.expectCallback(CallbackState.LOST, mCellNetworkAgent);
    cellNetworkCallback.expectCallback(CallbackState.LOST, mCellNetworkAgent);
    waitFor(cv);
    assertNoCallbacks(genericNetworkCallback, wifiNetworkCallback, cellNetworkCallback);
    // Test validated networks
    mCellNetworkAgent = new MockNetworkAgent(TRANSPORT_CELLULAR);
    mCellNetworkAgent.connect(true);
    genericNetworkCallback.expectCallback(CallbackState.AVAILABLE, mCellNetworkAgent);
    cellNetworkCallback.expectCallback(CallbackState.AVAILABLE, mCellNetworkAgent);
    assertEquals(mCellNetworkAgent.getNetwork(), mCm.getActiveNetwork());
    assertNoCallbacks(genericNetworkCallback, wifiNetworkCallback, cellNetworkCallback);
    // This should not trigger spurious onAvailable() callbacks, b/21762680.
    mCellNetworkAgent.adjustScore(-1);
    mService.waitForIdle();
    assertNoCallbacks(genericNetworkCallback, wifiNetworkCallback, cellNetworkCallback);
    assertEquals(mCellNetworkAgent.getNetwork(), mCm.getActiveNetwork());
    mWiFiNetworkAgent = new MockNetworkAgent(TRANSPORT_WIFI);
    mWiFiNetworkAgent.connect(true);
    genericNetworkCallback.expectCallback(CallbackState.AVAILABLE, mWiFiNetworkAgent);
    genericNetworkCallback.expectCallback(CallbackState.LOSING, mCellNetworkAgent);
    wifiNetworkCallback.expectCallback(CallbackState.AVAILABLE, mWiFiNetworkAgent);
    cellNetworkCallback.expectCallback(CallbackState.LOSING, mCellNetworkAgent);
    assertEquals(mWiFiNetworkAgent.getNetwork(), mCm.getActiveNetwork());
    assertNoCallbacks(genericNetworkCallback, wifiNetworkCallback, cellNetworkCallback);
    mWiFiNetworkAgent.disconnect();
    genericNetworkCallback.expectCallback(CallbackState.LOST, mWiFiNetworkAgent);
    wifiNetworkCallback.expectCallback(CallbackState.LOST, mWiFiNetworkAgent);
    assertNoCallbacks(genericNetworkCallback, wifiNetworkCallback, cellNetworkCallback);
    mCellNetworkAgent.disconnect();
    genericNetworkCallback.expectCallback(CallbackState.LOST, mCellNetworkAgent);
    cellNetworkCallback.expectCallback(CallbackState.LOST, mCellNetworkAgent);
    assertNoCallbacks(genericNetworkCallback, wifiNetworkCallback, cellNetworkCallback);
}
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