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();
}
}
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);
}
}
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];
}
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;
}
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);
}
}
Aggregations