[NS06] Implement the don't-reap mechanism

This exposes a mechanism for network providers to tell
the network stack that a given network must be kept up
for some specific reason. This is meant to be easier
for them than to have to file a request, in particular
because there is no guaranteed way to make sure the
request will be best matched by any given network.

Test: new test for this
Bug: 167544279
Merged-In: I3c2563d4ae4e3715d0c6270344ba8f7ef067872f
Merged-In: I238a3ee5ee9262477a23b897e4141769dd1505d1
Change-Id: I238a3ee5ee9262477a23b897e4141769dd1505d1
  (cherry-picked from ag/13929760)
This commit is contained in:
Chalard Jean
2021-03-08 22:29:27 +09:00
committed by Junyu Lai
parent 5c3bb5b1ce
commit 947acd4275
8 changed files with 171 additions and 18 deletions

View File

@@ -3974,6 +3974,12 @@ public class ConnectivityService extends IConnectivityManager.Stub
// then it should be lingered.
private boolean unneeded(NetworkAgentInfo nai, UnneededFor reason) {
ensureRunningOnConnectivityServiceThread();
if (!nai.everConnected || nai.isVPN() || nai.isInactive()
|| nai.getScore().getKeepConnectedReason() != NetworkScore.KEEP_CONNECTED_NONE) {
return false;
}
final int numRequests;
switch (reason) {
case TEARDOWN:
@@ -3987,9 +3993,8 @@ public class ConnectivityService extends IConnectivityManager.Stub
return true;
}
if (!nai.everConnected || nai.isVPN() || nai.isInactive() || numRequests > 0) {
return false;
}
if (numRequests > 0) return false;
for (NetworkRequestInfo nri : mNetworkRequests.values()) {
if (reason == UnneededFor.LINGER
&& !nri.isMultilayerRequest()