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