Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f256805d authored by Etan Cohen's avatar Etan Cohen Committed by Android (Google) Code Review
Browse files

Merge "[CS] Remove timeout event after first available"

parents 6ce1e98c 681fcda5
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -5342,6 +5342,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
    // notify only this one new request of the current state
    // notify only this one new request of the current state
    protected void notifyNetworkCallback(NetworkAgentInfo nai, NetworkRequestInfo nri) {
    protected void notifyNetworkCallback(NetworkAgentInfo nai, NetworkRequestInfo nri) {
        int notifyType = ConnectivityManager.CALLBACK_AVAILABLE;
        int notifyType = ConnectivityManager.CALLBACK_AVAILABLE;
        mHandler.removeMessages(EVENT_TIMEOUT_NETWORK_REQUEST, nri);
        if (nri.mPendingIntent == null) {
        if (nri.mPendingIntent == null) {
            callCallbackForRequest(nri, nai, notifyType, 0);
            callCallbackForRequest(nri, nai, notifyType, 0);
        } else {
        } else {
+35 −12
Original line number Original line Diff line number Diff line
@@ -728,10 +728,7 @@ public class ConnectivityServiceTest extends AndroidTestCase {
    static private void waitFor(Criteria criteria) {
    static private void waitFor(Criteria criteria) {
        int delays = 0;
        int delays = 0;
        while (!criteria.get()) {
        while (!criteria.get()) {
            try {
            sleepFor(50);
                Thread.sleep(50);
            } catch (InterruptedException e) {
            }
            if (++delays == 10) fail();
            if (++delays == 10) fail();
        }
        }
    }
    }
@@ -2313,10 +2310,30 @@ public class ConnectivityServiceTest extends AndroidTestCase {
        networkCallback.expectCallback(CallbackState.AVAILABLE, mWiFiNetworkAgent);
        networkCallback.expectCallback(CallbackState.AVAILABLE, mWiFiNetworkAgent);


        // pass timeout and validate that UNAVAILABLE is not called
        // pass timeout and validate that UNAVAILABLE is not called
        try {
        sleepFor(15);
            Thread.sleep(15);
        networkCallback.assertNoCallback();
        } catch (InterruptedException e) {
    }
    }

    /**
     * Validate that a satisfied network request followed by a disconnected (lost) network does
     * not trigger onUnavailable() once the time-out period expires.
     */
    @SmallTest
    public void testSatisfiedThenLostNetworkRequestDoesNotTriggerOnUnavailable() {
        NetworkRequest nr = new NetworkRequest.Builder().addTransportType(
                NetworkCapabilities.TRANSPORT_WIFI).build();
        final TestNetworkCallback networkCallback = new TestNetworkCallback();
        mCm.requestNetwork(nr, networkCallback, 500);

        mWiFiNetworkAgent = new MockNetworkAgent(TRANSPORT_WIFI);
        mWiFiNetworkAgent.connect(false);
        networkCallback.expectCallback(CallbackState.AVAILABLE, mWiFiNetworkAgent);
        sleepFor(20);
        mWiFiNetworkAgent.disconnect();
        networkCallback.expectCallback(CallbackState.LOST, mWiFiNetworkAgent);

        // pass timeout and validate that UNAVAILABLE is not called
        sleepFor(600);
        networkCallback.assertNoCallback();
        networkCallback.assertNoCallback();
    }
    }


@@ -2358,10 +2375,7 @@ public class ConnectivityServiceTest extends AndroidTestCase {
        // pass timeout and validate that no callbacks
        // pass timeout and validate that no callbacks
        // Note: doesn't validate that nothing called from CS since even if called the CM already
        // Note: doesn't validate that nothing called from CS since even if called the CM already
        // unregisters the callback and won't pass it through!
        // unregisters the callback and won't pass it through!
        try {
        sleepFor(15);
            Thread.sleep(15);
        } catch (InterruptedException e) {
        }
        networkCallback.assertNoCallback();
        networkCallback.assertNoCallback();


        // create a network satisfying request - validate that request not triggered
        // create a network satisfying request - validate that request not triggered
@@ -2775,4 +2789,13 @@ public class ConnectivityServiceTest extends AndroidTestCase {
            mCm.unregisterNetworkCallback(pendingIntent);
            mCm.unregisterNetworkCallback(pendingIntent);
        }
        }
    }
    }

    /* test utilities */
    static private void sleepFor(int ms) {
        try {
            Thread.sleep(ms);
        } catch (InterruptedException e) {
        }

    }
}
}