Search in sources :

Example 51 with ConditionVariable

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

the class SyncRunner method scheduleFilterWake.

protected void scheduleFilterWake(Filter filter, int delay) {
    // Close the wake condition
    mWakeCondition.close();
    // Schedule the wake-up
    final Filter filterToSchedule = filter;
    final ConditionVariable conditionToWake = mWakeCondition;
    mWakeExecutor.schedule(new Runnable() {

        @Override
        public void run() {
            filterToSchedule.unsetStatus(Filter.STATUS_SLEEPING);
            conditionToWake.open();
        }
    }, delay, TimeUnit.MILLISECONDS);
}
Also used : ConditionVariable(android.os.ConditionVariable)

Example 52 with ConditionVariable

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

the class GLThreadManager method setConfigurationAndWait.

/**
     * Configure the GL renderer for the given set of output surfaces, and block until
     * this configuration has been applied.
     *
     * @param surfaces a collection of pairs of {@link android.view.Surface}s and their
     *                 corresponding sizes to configure.
     * @param collector a {@link CaptureCollector} to retrieve requests from.
     */
public void setConfigurationAndWait(Collection<Pair<Surface, Size>> surfaces, CaptureCollector collector) {
    checkNotNull(collector, "collector must not be null");
    Handler handler = mGLHandlerThread.getHandler();
    final ConditionVariable condition = new ConditionVariable(/*closed*/
    false);
    ConfigureHolder configure = new ConfigureHolder(condition, surfaces, collector);
    Message m = handler.obtainMessage(MSG_NEW_CONFIGURATION, /*arg1*/
    0, /*arg2*/
    0, configure);
    handler.sendMessage(m);
    // Block until configuration applied.
    condition.block();
}
Also used : ConditionVariable(android.os.ConditionVariable) Message(android.os.Message) Handler(android.os.Handler)

Example 53 with ConditionVariable

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

the class ConnectivityServiceTest method connectKeepaliveNetwork.

private Network connectKeepaliveNetwork(LinkProperties lp) {
    // Ensure the network is disconnected before we do anything.
    if (mWiFiNetworkAgent != null) {
        assertNull(mCm.getNetworkCapabilities(mWiFiNetworkAgent.getNetwork()));
    }
    mWiFiNetworkAgent = new MockNetworkAgent(TRANSPORT_WIFI);
    ConditionVariable cv = waitForConnectivityBroadcasts(1);
    mWiFiNetworkAgent.connect(true);
    waitFor(cv);
    verifyActiveNetwork(TRANSPORT_WIFI);
    mWiFiNetworkAgent.sendLinkProperties(lp);
    mService.waitForIdle();
    return mWiFiNetworkAgent.getNetwork();
}
Also used : ConditionVariable(android.os.ConditionVariable)

Example 54 with ConditionVariable

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

the class ConnectivityServiceTest method testUnlingeringDoesNotValidate.

@SmallTest
public void testUnlingeringDoesNotValidate() throws Exception {
    // Test bringing up unvalidated WiFi.
    mWiFiNetworkAgent = new MockNetworkAgent(TRANSPORT_WIFI);
    ConditionVariable cv = waitForConnectivityBroadcasts(1);
    mWiFiNetworkAgent.connect(false);
    waitFor(cv);
    verifyActiveNetwork(TRANSPORT_WIFI);
    assertFalse(mCm.getNetworkCapabilities(mWiFiNetworkAgent.getNetwork()).hasCapability(NET_CAPABILITY_VALIDATED));
    // Test bringing up validated cellular.
    mCellNetworkAgent = new MockNetworkAgent(TRANSPORT_CELLULAR);
    cv = waitForConnectivityBroadcasts(2);
    mCellNetworkAgent.connect(true);
    waitFor(cv);
    verifyActiveNetwork(TRANSPORT_CELLULAR);
    assertFalse(mCm.getNetworkCapabilities(mWiFiNetworkAgent.getNetwork()).hasCapability(NET_CAPABILITY_VALIDATED));
    // Test cellular disconnect.
    cv = waitForConnectivityBroadcasts(2);
    mCellNetworkAgent.disconnect();
    waitFor(cv);
    verifyActiveNetwork(TRANSPORT_WIFI);
    // Unlingering a network should not cause it to be marked as validated.
    assertFalse(mCm.getNetworkCapabilities(mWiFiNetworkAgent.getNetwork()).hasCapability(NET_CAPABILITY_VALIDATED));
}
Also used : ConditionVariable(android.os.ConditionVariable) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 55 with ConditionVariable

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

the class ConnectivityServiceTest method waitForConnectivityBroadcasts.

/**
     * Return a ConditionVariable that opens when {@code count} numbers of CONNECTIVITY_ACTION
     * broadcasts are received.
     */
private ConditionVariable waitForConnectivityBroadcasts(final int count) {
    final ConditionVariable cv = new ConditionVariable();
    mServiceContext.registerReceiver(new BroadcastReceiver() {

        private int remaining = count;

        public void onReceive(Context context, Intent intent) {
            if (--remaining == 0) {
                cv.open();
                mServiceContext.unregisterReceiver(this);
            }
        }
    }, new IntentFilter(CONNECTIVITY_ACTION));
    return cv;
}
Also used : ConditionVariable(android.os.ConditionVariable) BroadcastInterceptingContext(com.android.internal.util.test.BroadcastInterceptingContext) Context(android.content.Context) IntentFilter(android.content.IntentFilter) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) BroadcastReceiver(android.content.BroadcastReceiver)

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