[LT2] Fix release request while lingering.

Test: runtest framework-net
Change-Id: Ic28c5653d16351903b792e76ba8b199b7ed1f8d4
This commit is contained in:
Chalard Jean
2018-02-16 16:08:35 +09:00
parent a7c93b0b5b
commit 9f48d166f6
2 changed files with 11 additions and 6 deletions

View File

@@ -384,12 +384,15 @@ public class NetworkAgentInfo implements Comparable<NetworkAgentInfo> {
/** /**
* Returns whether the network is a background network. A network is a background network if it * Returns whether the network is a background network. A network is a background network if it
* is satisfying no foreground requests and at least one background request. (If it did not have * does not have the NET_CAPABILITY_FOREGROUND capability, which implies it is satisfying no
* a background request, it would be a speculative network that is only being kept up because * foreground request, is not lingering (i.e. kept for a while after being outscored), and is
* it might satisfy a request if it validated). * not a speculative network (i.e. kept pending validation when validation would have it
* outscore another foreground network). That implies it is being kept up by some background
* request (otherwise it would be torn down), maybe the mobile always-on request.
*/ */
public boolean isBackgroundNetwork() { public boolean isBackgroundNetwork() {
return !isVPN() && numForegroundNetworkRequests() == 0 && mNumBackgroundNetworkRequests > 0; return !isVPN() && numForegroundNetworkRequests() == 0 && mNumBackgroundNetworkRequests > 0
&& !isLingering();
} }
/** /**

View File

@@ -50,6 +50,7 @@ import static android.net.NetworkCapabilities.TRANSPORT_WIFI;
import static android.net.NetworkCapabilities.TRANSPORT_WIFI_AWARE; import static android.net.NetworkCapabilities.TRANSPORT_WIFI_AWARE;
import static com.android.internal.util.TestUtils.waitForIdleHandler; import static com.android.internal.util.TestUtils.waitForIdleHandler;
import static com.android.internal.util.TestUtils.waitForIdleLooper;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
@@ -85,6 +86,7 @@ import android.net.ConnectivityManager.NetworkCallback;
import android.net.ConnectivityManager.PacketKeepalive; import android.net.ConnectivityManager.PacketKeepalive;
import android.net.ConnectivityManager.PacketKeepaliveCallback; import android.net.ConnectivityManager.PacketKeepaliveCallback;
import android.net.ConnectivityManager.TooManyRequestsException; import android.net.ConnectivityManager.TooManyRequestsException;
import android.net.ConnectivityThread;
import android.net.INetworkPolicyManager; import android.net.INetworkPolicyManager;
import android.net.INetworkStatsService; import android.net.INetworkStatsService;
import android.net.IpPrefix; import android.net.IpPrefix;
@@ -279,6 +281,7 @@ public class ConnectivityServiceTest {
waitForIdle(mWiFiNetworkAgent, timeoutMs); waitForIdle(mWiFiNetworkAgent, timeoutMs);
waitForIdle(mEthernetNetworkAgent, timeoutMs); waitForIdle(mEthernetNetworkAgent, timeoutMs);
waitForIdleHandler(mService.mHandlerThread, timeoutMs); waitForIdleHandler(mService.mHandlerThread, timeoutMs);
waitForIdleLooper(ConnectivityThread.getInstanceLooper(), timeoutMs);
} }
public void waitForIdle(MockNetworkAgent agent, long timeoutMs) { public void waitForIdle(MockNetworkAgent agent, long timeoutMs) {
@@ -1875,8 +1878,7 @@ public class ConnectivityServiceTest {
callback.expectCallback(CallbackState.LOSING, mCellNetworkAgent); callback.expectCallback(CallbackState.LOSING, mCellNetworkAgent);
// Let linger run its course. // Let linger run its course.
// TODO : the callback should be delayed by the linger delay. Fix this. callback.assertNoCallback();
// callback.assertNoCallback();
final int lingerTimeoutMs = TEST_LINGER_DELAY_MS + TEST_LINGER_DELAY_MS / 4; final int lingerTimeoutMs = TEST_LINGER_DELAY_MS + TEST_LINGER_DELAY_MS / 4;
callback.expectCapabilitiesWithout(NET_CAPABILITY_FOREGROUND, mCellNetworkAgent, callback.expectCapabilitiesWithout(NET_CAPABILITY_FOREGROUND, mCellNetworkAgent,
lingerTimeoutMs); lingerTimeoutMs);