Search in sources :

Example 26 with ConditionVariable

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

the class ConnectivityServiceTest method testMMSonWiFi.

@LargeTest
public void testMMSonWiFi() throws Exception {
    // Test bringing up cellular without MMS NetworkRequest gets reaped
    mCellNetworkAgent = new MockNetworkAgent(TRANSPORT_CELLULAR);
    mCellNetworkAgent.addCapability(NET_CAPABILITY_MMS);
    ConditionVariable cv = mCellNetworkAgent.getDisconnectedCV();
    mCellNetworkAgent.connectWithoutInternet();
    waitFor(cv);
    waitFor(new Criteria() {

        public boolean get() {
            return mCm.getAllNetworks().length == 0;
        }
    });
    verifyNoNetwork();
    // Test bringing up validated WiFi.
    mWiFiNetworkAgent = new MockNetworkAgent(TRANSPORT_WIFI);
    cv = waitForConnectivityBroadcasts(1);
    mWiFiNetworkAgent.connect(true);
    waitFor(cv);
    verifyActiveNetwork(TRANSPORT_WIFI);
    // Register MMS NetworkRequest
    NetworkRequest.Builder builder = new NetworkRequest.Builder();
    builder.addCapability(NetworkCapabilities.NET_CAPABILITY_MMS);
    final TestNetworkCallback networkCallback = new TestNetworkCallback();
    mCm.requestNetwork(builder.build(), networkCallback);
    // Test bringing up unvalidated cellular with MMS
    mCellNetworkAgent = new MockNetworkAgent(TRANSPORT_CELLULAR);
    mCellNetworkAgent.addCapability(NET_CAPABILITY_MMS);
    mCellNetworkAgent.connectWithoutInternet();
    networkCallback.expectCallback(CallbackState.AVAILABLE, mCellNetworkAgent);
    verifyActiveNetwork(TRANSPORT_WIFI);
    // Test releasing NetworkRequest disconnects cellular with MMS
    cv = mCellNetworkAgent.getDisconnectedCV();
    mCm.unregisterNetworkCallback(networkCallback);
    waitFor(cv);
    verifyActiveNetwork(TRANSPORT_WIFI);
}
Also used : ConditionVariable(android.os.ConditionVariable) NetworkRequest(android.net.NetworkRequest) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 27 with ConditionVariable

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

the class ConnectivityServiceTest method testAvoidOrIgnoreCaptivePortals.

@LargeTest
public void testAvoidOrIgnoreCaptivePortals() {
    final TestNetworkCallback captivePortalCallback = new TestNetworkCallback();
    final NetworkRequest captivePortalRequest = new NetworkRequest.Builder().addCapability(NET_CAPABILITY_CAPTIVE_PORTAL).build();
    mCm.registerNetworkCallback(captivePortalRequest, captivePortalCallback);
    final TestNetworkCallback validatedCallback = new TestNetworkCallback();
    final NetworkRequest validatedRequest = new NetworkRequest.Builder().addCapability(NET_CAPABILITY_VALIDATED).build();
    mCm.registerNetworkCallback(validatedRequest, validatedCallback);
    setCaptivePortalMode(Settings.Global.CAPTIVE_PORTAL_MODE_AVOID);
    // Bring up a network with a captive portal.
    // Expect it to fail to connect and not result in any callbacks.
    mWiFiNetworkAgent = new MockNetworkAgent(TRANSPORT_WIFI);
    String firstRedirectUrl = "http://example.com/firstPath";
    ConditionVariable disconnectCv = mWiFiNetworkAgent.getDisconnectedCV();
    ConditionVariable avoidCv = mWiFiNetworkAgent.getPreventReconnectReceived();
    mWiFiNetworkAgent.connectWithCaptivePortal(firstRedirectUrl);
    waitFor(disconnectCv);
    waitFor(avoidCv);
    assertNoCallbacks(captivePortalCallback, validatedCallback);
    // Now test ignore mode.
    setCaptivePortalMode(Settings.Global.CAPTIVE_PORTAL_MODE_IGNORE);
    // Bring up a network with a captive portal.
    // Since we're ignoring captive portals, the network will validate.
    mWiFiNetworkAgent = new MockNetworkAgent(TRANSPORT_WIFI);
    String secondRedirectUrl = "http://example.com/secondPath";
    mWiFiNetworkAgent.connectWithCaptivePortal(secondRedirectUrl);
    // Expect NET_CAPABILITY_VALIDATED onAvailable callback.
    validatedCallback.expectCallback(CallbackState.AVAILABLE, mWiFiNetworkAgent);
    // But there should be no CaptivePortal callback.
    captivePortalCallback.assertNoCallback();
}
Also used : ConditionVariable(android.os.ConditionVariable) NetworkRequest(android.net.NetworkRequest) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 28 with ConditionVariable

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

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 29 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 30 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)

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