Search in sources :

Example 66 with ConditionVariable

use of android.os.ConditionVariable in project VirtualApp by asLody.

the class VClientImpl method bindApplication.

public void bindApplication(final String packageName, final String processName) {
    if (Looper.getMainLooper() == Looper.myLooper()) {
        bindApplicationNoCheck(packageName, processName, new ConditionVariable());
    } else {
        final ConditionVariable lock = new ConditionVariable();
        VirtualRuntime.getUIHandler().post(new Runnable() {

            @Override
            public void run() {
                bindApplicationNoCheck(packageName, processName, lock);
                lock.open();
            }
        });
        lock.block();
    }
}
Also used : ConditionVariable(android.os.ConditionVariable)

Example 67 with ConditionVariable

use of android.os.ConditionVariable in project facebook-android-sdk by facebook.

the class FacebookActivityTestCase method runOnBlockerThread.

protected void runOnBlockerThread(final Runnable runnable, boolean waitForCompletion) {
    Runnable runnableToPost = runnable;
    final ConditionVariable condition = waitForCompletion ? new ConditionVariable(!waitForCompletion) : null;
    if (waitForCompletion) {
        runnableToPost = new Runnable() {

            @Override
            public void run() {
                runnable.run();
                condition.open();
            }
        };
    }
    TestBlocker blocker = getTestBlocker();
    Handler handler = blocker.getHandler();
    handler.post(runnableToPost);
    if (waitForCompletion) {
        boolean success = condition.block(10000);
        assertTrue(success);
    }
}
Also used : ConditionVariable(android.os.ConditionVariable) Handler(android.os.Handler)

Example 68 with ConditionVariable

use of android.os.ConditionVariable in project ExoPlayer by google.

the class CronetDataSource method getStatus.

private static int getStatus(UrlRequest request) {
    final ConditionVariable conditionVariable = new ConditionVariable();
    final int[] statusHolder = new int[1];
    request.getStatus(new UrlRequest.StatusListener() {

        @Override
        public void onStatus(int status) {
            statusHolder[0] = status;
            conditionVariable.open();
        }
    });
    conditionVariable.block();
    return statusHolder[0];
}
Also used : ConditionVariable(android.os.ConditionVariable) UrlRequest(org.chromium.net.UrlRequest)

Example 69 with ConditionVariable

use of android.os.ConditionVariable in project ExoPlayer by google.

the class CronetDataSourceTest method buildUrlRequestStartedCondition.

private ConditionVariable buildUrlRequestStartedCondition() {
    final ConditionVariable startedCondition = new ConditionVariable();
    doAnswer(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            startedCondition.open();
            return null;
        }
    }).when(mockUrlRequest).start();
    return startedCondition;
}
Also used : ConditionVariable(android.os.ConditionVariable) InvocationOnMock(org.mockito.invocation.InvocationOnMock)

Example 70 with ConditionVariable

use of android.os.ConditionVariable in project ExoPlayer by google.

the class HostActivity method runTest.

/**
   * Executes a {@link HostedTest} inside the host.
   *
   * @param hostedTest The test to execute.
   * @param timeoutMs The number of milliseconds to wait for the test to finish. If the timeout
   *     is exceeded then the test will fail.
   */
public void runTest(final HostedTest hostedTest, long timeoutMs) {
    Assertions.checkArgument(timeoutMs > 0);
    Assertions.checkState(Thread.currentThread() != getMainLooper().getThread());
    Assertions.checkState(this.hostedTest == null);
    this.hostedTest = Assertions.checkNotNull(hostedTest);
    hostedTestStoppedCondition = new ConditionVariable();
    hostedTestStarted = false;
    hostedTestFinished = false;
    runOnUiThread(new Runnable() {

        @Override
        public void run() {
            maybeStartHostedTest();
        }
    });
    if (hostedTestStoppedCondition.block(timeoutMs)) {
        if (hostedTestFinished) {
            Log.d(TAG, "Test finished. Checking pass conditions.");
            hostedTest.onFinished();
            Log.d(TAG, "Pass conditions checked.");
        } else {
            String message = "Test released before it finished. Activity may have been paused whilst " + "test was in progress.";
            Log.e(TAG, message);
            fail(message);
        }
    } else {
        String message = "Test timed out after " + timeoutMs + " ms.";
        Log.e(TAG, message);
        fail(message);
    }
}
Also used : ConditionVariable(android.os.ConditionVariable)

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