Report result SKIPPED in ConnDiags if the network is not validated.
This CL updates ConnectivityDiagnostics to report
NETWORK_VALIDATION_RESULT_SKIPPED when the platform does not validate
the reported Network. This CL also updates the behavior for
ConnectivityManager#reportNetworkConnectivity, such that it will always
generate a ConnectivityReport on the reported network. If the reported
connectivity does not match the known connectivity of this network, the
network is revalidated and a report is generated. Otherwise,
revalidation is not performed and the cached ConnectivityReport is sent
instead.
This CL also updates ConnDiags behavior for calls to
ConnectivityManager#reportNetworkConnectivity. Specifically, ConnDiags
callbacks are only notified for these calls if:
a) the call causes the Network to be re-validated, or
b) the callback registrant was the caller of
#reportNetworkConnectivity().
For b), the caller is always guaranteed to receive a ConnectivityReport
(a fresh report if the Network is re-validated, else the cached report).
Bug: 162407730
Test: atest FrameworksNetTests ConnectivityDiagnosticsManagerTest
Change-Id: I78b78919d5b0f09348dfdd5fdb37418b8c7f861f
This commit is contained in:
@@ -10197,6 +10197,9 @@ public class ConnectivityServiceTest {
|
||||
public void testConnectivityDiagnosticsCallbackOnConnectivityReported() throws Exception {
|
||||
setUpConnectivityDiagnosticsCallback();
|
||||
|
||||
// reset to ignore callbacks from setup
|
||||
reset(mConnectivityDiagnosticsCallback);
|
||||
|
||||
final Network n = mCellNetworkAgent.getNetwork();
|
||||
final boolean hasConnectivity = true;
|
||||
mService.reportNetworkConnectivity(n, hasConnectivity);
|
||||
@@ -10207,6 +10210,8 @@ public class ConnectivityServiceTest {
|
||||
// Verify onNetworkConnectivityReported fired
|
||||
verify(mConnectivityDiagnosticsCallback)
|
||||
.onNetworkConnectivityReported(eq(n), eq(hasConnectivity));
|
||||
verify(mConnectivityDiagnosticsCallback).onConnectivityReportAvailable(
|
||||
argThat(report -> areConnDiagCapsRedacted(report.getNetworkCapabilities())));
|
||||
|
||||
final boolean noConnectivity = false;
|
||||
mService.reportNetworkConnectivity(n, noConnectivity);
|
||||
@@ -10217,6 +10222,54 @@ public class ConnectivityServiceTest {
|
||||
// Wait for onNetworkConnectivityReported to fire
|
||||
verify(mConnectivityDiagnosticsCallback)
|
||||
.onNetworkConnectivityReported(eq(n), eq(noConnectivity));
|
||||
|
||||
// Also expect a ConnectivityReport after NetworkMonitor asynchronously re-validates
|
||||
verify(mConnectivityDiagnosticsCallback, timeout(TIMEOUT_MS).times(2))
|
||||
.onConnectivityReportAvailable(
|
||||
argThat(report ->
|
||||
areConnDiagCapsRedacted(report.getNetworkCapabilities())));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConnectivityDiagnosticsCallbackOnConnectivityReportedSeparateUid()
|
||||
throws Exception {
|
||||
setUpConnectivityDiagnosticsCallback();
|
||||
|
||||
// reset to ignore callbacks from setup
|
||||
reset(mConnectivityDiagnosticsCallback);
|
||||
|
||||
// report known Connectivity from a different uid. Verify that network is not re-validated
|
||||
// and this callback is not notified.
|
||||
final Network n = mCellNetworkAgent.getNetwork();
|
||||
final boolean hasConnectivity = true;
|
||||
doAsUid(Process.myUid() + 1, () -> mService.reportNetworkConnectivity(n, hasConnectivity));
|
||||
|
||||
// Block until all other events are done processing.
|
||||
HandlerUtils.waitForIdle(mCsHandlerThread, TIMEOUT_MS);
|
||||
|
||||
// Verify onNetworkConnectivityReported did not fire
|
||||
verify(mConnectivityDiagnosticsCallback, never())
|
||||
.onNetworkConnectivityReported(any(), anyBoolean());
|
||||
verify(mConnectivityDiagnosticsCallback, never())
|
||||
.onConnectivityReportAvailable(any());
|
||||
|
||||
// report different Connectivity from a different uid. Verify that network is re-validated
|
||||
// and that this callback is notified.
|
||||
final boolean noConnectivity = false;
|
||||
doAsUid(Process.myUid() + 1, () -> mService.reportNetworkConnectivity(n, noConnectivity));
|
||||
|
||||
// Block until all other events are done processing.
|
||||
HandlerUtils.waitForIdle(mCsHandlerThread, TIMEOUT_MS);
|
||||
|
||||
// Wait for onNetworkConnectivityReported to fire
|
||||
verify(mConnectivityDiagnosticsCallback, timeout(TIMEOUT_MS))
|
||||
.onNetworkConnectivityReported(eq(n), eq(noConnectivity));
|
||||
|
||||
// Also expect a ConnectivityReport after NetworkMonitor asynchronously re-validates
|
||||
verify(mConnectivityDiagnosticsCallback, timeout(TIMEOUT_MS))
|
||||
.onConnectivityReportAvailable(
|
||||
argThat(report ->
|
||||
areConnDiagCapsRedacted(report.getNetworkCapabilities())));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user