Merge "Improve partial connectivity" am: f6cbc2d533

am: 270e77d930

Change-Id: Ie68acfe6e2182588cdd8b70d67651241573b2189
This commit is contained in:
Lucas Lin
2019-03-20 20:56:16 -07:00
committed by android-build-merger
6 changed files with 44 additions and 38 deletions

View File

@@ -41,7 +41,7 @@ oneway interface INetworkMonitor {
void start();
void launchCaptivePortalApp();
void notifyCaptivePortalAppFinished(int response);
void notifyAcceptPartialConnectivity();
void setAcceptPartialConnectivity();
void forceReevaluation(int uid);
void notifyPrivateDnsChanged(in PrivateDnsConfigParcel config);
void notifyDnsResponse(int returnCode);

View File

@@ -277,9 +277,9 @@ public class NetworkStackService extends Service {
}
@Override
public void notifyAcceptPartialConnectivity() {
public void setAcceptPartialConnectivity() {
checkNetworkStackCallingPermission();
mNm.notifyAcceptPartialConnectivity();
mNm.setAcceptPartialConnectivity();
}
@Override

View File

@@ -319,7 +319,8 @@ public class NetworkMonitor extends StateMachine {
private final DnsStallDetector mDnsStallDetector;
private long mLastProbeTime;
// Set to true if data stall is suspected and reset to false after metrics are sent to statsd.
private boolean mCollectDataStallMetrics = false;
private boolean mCollectDataStallMetrics;
private boolean mAcceptPartialConnectivity;
public NetworkMonitor(Context context, INetworkMonitorCallbacks cb, Network network,
SharedLog validationLog) {
@@ -386,10 +387,11 @@ public class NetworkMonitor extends StateMachine {
}
/**
* ConnectivityService notifies NetworkMonitor that the user accepts partial connectivity and
* NetworkMonitor should ignore the https probe.
* ConnectivityService notifies NetworkMonitor that the user already accepted partial
* connectivity previously, so NetworkMonitor can validate the network even if it has partial
* connectivity.
*/
public void notifyAcceptPartialConnectivity() {
public void setAcceptPartialConnectivity() {
sendMessage(EVENT_ACCEPT_PARTIAL_CONNECTIVITY);
}
@@ -651,9 +653,11 @@ public class NetworkMonitor extends StateMachine {
case EVENT_DNS_NOTIFICATION:
mDnsStallDetector.accumulateConsecutiveDnsTimeoutCount(message.arg1);
break;
// Set mAcceptPartialConnectivity to true and if network start evaluating or
// re-evaluating and get the result of partial connectivity, ProbingState will
// disable HTTPS probe and transition to EvaluatingPrivateDnsState.
case EVENT_ACCEPT_PARTIAL_CONNECTIVITY:
mUseHttps = false;
transitionTo(mEvaluatingPrivateDnsState);
mAcceptPartialConnectivity = true;
break;
default:
break;
@@ -849,6 +853,14 @@ public class NetworkMonitor extends StateMachine {
// ignore any re-evaluation requests. After, restart the
// evaluation process via EvaluatingState#enter.
return (mEvaluateAttempts < IGNORE_REEVALUATE_ATTEMPTS) ? HANDLED : NOT_HANDLED;
// Disable HTTPS probe and transition to EvaluatingPrivateDnsState because:
// 1. Network is connected and finish the network validation.
// 2. NetworkMonitor detects network is partial connectivity and user accepts it.
case EVENT_ACCEPT_PARTIAL_CONNECTIVITY:
mAcceptPartialConnectivity = true;
mUseHttps = false;
transitionTo(mEvaluatingPrivateDnsState);
return HANDLED;
default:
return NOT_HANDLED;
}
@@ -1081,7 +1093,12 @@ public class NetworkMonitor extends StateMachine {
logNetworkEvent(NetworkEvent.NETWORK_PARTIAL_CONNECTIVITY);
notifyNetworkTested(NETWORK_TEST_RESULT_PARTIAL_CONNECTIVITY,
probeResult.redirectUrl);
transitionTo(mWaitingForNextProbeState);
if (mAcceptPartialConnectivity) {
mUseHttps = false;
transitionTo(mEvaluatingPrivateDnsState);
} else {
transitionTo(mWaitingForNextProbeState);
}
} else {
logNetworkEvent(NetworkEvent.NETWORK_VALIDATION_FAILED);
notifyNetworkTested(NETWORK_TEST_RESULT_INVALID, probeResult.redirectUrl);

View File

@@ -583,7 +583,7 @@ public class NetworkMonitorTest {
verify(mCallbacks, timeout(HANDLER_TIMEOUT_MS).times(1))
.notifyNetworkTested(NETWORK_TEST_RESULT_PARTIAL_CONNECTIVITY, null);
nm.notifyAcceptPartialConnectivity();
nm.setAcceptPartialConnectivity();
verify(mCallbacks, timeout(HANDLER_TIMEOUT_MS).times(1))
.notifyNetworkTested(NETWORK_TEST_RESULT_VALID, null);
}

View File

@@ -2561,19 +2561,11 @@ public class ConnectivityService extends IConnectivityManager.Stub
final boolean partialConnectivity =
(msg.arg1 == NETWORK_TEST_RESULT_PARTIAL_CONNECTIVITY)
// If user accepts partial connectivity network, NetworkMonitor
// will skip https probing. It will make partial connectivity
// network becomes valid. But user still need to know this
// network is limited. So, it's needed to refer to
// acceptPartialConnectivity to add
// NET_CAPABILITY_PARTIAL_CONNECTIVITY into NetworkCapabilities
// of this network. So that user can see "Limited connection"
// in the settings.
|| (nai.networkMisc.acceptPartialConnectivity
&& nai.partialConnectivity);
// Once a network is determined to have partial connectivity, it cannot
// go back to full connectivity without a disconnect.
final boolean partialConnectivityChange =
final boolean partialConnectivityChanged =
(partialConnectivity && !nai.partialConnectivity);
final boolean valid = (msg.arg1 == NETWORK_TEST_RESULT_VALID);
@@ -2584,17 +2576,6 @@ public class ConnectivityService extends IConnectivityManager.Stub
nai.captivePortalLoginNotified = true;
showNetworkNotification(nai, NotificationType.LOGGED_IN);
}
// If this network has just connected and partial connectivity has just been
// detected, tell NetworkMonitor if the user accepted partial connectivity on a
// previous connect.
if ((msg.arg1 == NETWORK_TEST_RESULT_PARTIAL_CONNECTIVITY)
&& nai.networkMisc.acceptPartialConnectivity) {
try {
nai.networkMonitor().notifyAcceptPartialConnectivity();
} catch (RemoteException e) {
e.rethrowFromSystemServer();
}
}
final String redirectUrl = (msg.obj instanceof String) ? (String) msg.obj : "";
@@ -2624,7 +2605,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
mNotifier.clearNotification(nai.network.netId,
NotificationType.LOST_INTERNET);
}
} else if (partialConnectivityChange) {
} else if (partialConnectivityChanged) {
nai.partialConnectivity = partialConnectivity;
updateCapabilities(nai.getCurrentScore(), nai, nai.networkCapabilities);
}
@@ -3378,8 +3359,11 @@ public class ConnectivityService extends IConnectivityManager.Stub
// Tear down the network.
teardownUnneededNetwork(nai);
} else {
// Inform NetworkMonitor that partial connectivity is acceptable. This will likely
// result in a partial connectivity result which will be processed by
// maybeHandleNetworkMonitorMessage.
try {
nai.networkMonitor().notifyAcceptPartialConnectivity();
nai.networkMonitor().setAcceptPartialConnectivity();
} catch (RemoteException e) {
e.rethrowFromSystemServer();
}
@@ -3587,6 +3571,9 @@ public class ConnectivityService extends IConnectivityManager.Stub
// because we're already prompting the user to sign in.
if (nai == null || nai.everValidated || nai.everCaptivePortalDetected
|| !nai.networkMisc.explicitlySelected || nai.networkMisc.acceptUnvalidated
// TODO: Once the value of acceptPartialConnectivity is moved to IpMemoryStore,
// we should reevaluate how to handle acceptPartialConnectivity when network just
// connected.
|| nai.networkMisc.acceptPartialConnectivity) {
return;
}
@@ -6395,6 +6382,9 @@ public class ConnectivityService extends IConnectivityManager.Stub
// NetworkMonitor seeing the correct LinkProperties when starting.
// TODO: pass LinkProperties to the NetworkMonitor in the notifyNetworkConnected call.
try {
if (networkAgent.networkMisc.acceptPartialConnectivity) {
networkAgent.networkMonitor().setAcceptPartialConnectivity();
}
networkAgent.networkMonitor().notifyNetworkConnected();
} catch (RemoteException e) {
e.rethrowFromSystemServer();

View File

@@ -495,7 +495,7 @@ public class ConnectivityServiceTest {
try {
doAnswer(validateAnswer).when(mNetworkMonitor).notifyNetworkConnected();
doAnswer(validateAnswer).when(mNetworkMonitor).forceReevaluation(anyInt());
doAnswer(validateAnswer).when(mNetworkMonitor).notifyAcceptPartialConnectivity();
doAnswer(validateAnswer).when(mNetworkMonitor).setAcceptPartialConnectivity();
} catch (RemoteException e) {
fail(e.getMessage());
}
@@ -2550,8 +2550,7 @@ public class ConnectivityServiceTest {
verifyActiveNetwork(TRANSPORT_CELLULAR);
}
// TODO: deflake and re-enable
// @Test
@Test
public void testPartialConnectivity() {
// Register network callback.
NetworkRequest request = new NetworkRequest.Builder()
@@ -2585,7 +2584,7 @@ public class ConnectivityServiceTest {
waitForIdle();
try {
verify(mWiFiNetworkAgent.mNetworkMonitor,
timeout(TIMEOUT_MS).times(1)).notifyAcceptPartialConnectivity();
timeout(TIMEOUT_MS).times(1)).setAcceptPartialConnectivity();
} catch (RemoteException e) {
fail(e.getMessage());
}
@@ -2641,7 +2640,7 @@ public class ConnectivityServiceTest {
waitForIdle();
try {
verify(mWiFiNetworkAgent.mNetworkMonitor,
timeout(TIMEOUT_MS).times(1)).notifyAcceptPartialConnectivity();
timeout(TIMEOUT_MS).times(1)).setAcceptPartialConnectivity();
} catch (RemoteException e) {
fail(e.getMessage());
}