Implement INetworkMonitorCallbacks#notifyDataStallSuspected.

INetworkMonitorCallbacks defines notifyDataStallSuspected() for
notifying ConnectivityService of networks encountering a potential data
stall. A new event is introduced for ConnectivityDiagnosticsHandler to
process the notification and invoke the relevant
ConnectivityDiagnosticsCallbacks.

Bug: 143187964
Test: compiles
Test: atest CtsNetTestCases FrameworksNetTests
Change-Id: I70320bdda9855dced31e08e6a0b25329fb5cb535
(cherry picked from commit 6c51dc9de39d7963a6bc6d03eacadf2ba2131e20)
This commit is contained in:
Cody Kesting
2020-01-06 16:55:35 -08:00
parent 231f1fac04
commit a1bb47a768
2 changed files with 94 additions and 0 deletions

View File

@@ -24,6 +24,7 @@ import static android.content.pm.PackageManager.MATCH_ANY_USER;
import static android.content.pm.PackageManager.PERMISSION_DENIED;
import static android.content.pm.PackageManager.PERMISSION_GRANTED;
import static android.net.ConnectivityDiagnosticsManager.ConnectivityReport;
import static android.net.ConnectivityDiagnosticsManager.DataStallReport;
import static android.net.ConnectivityManager.ACTION_CAPTIVE_PORTAL_SIGN_IN;
import static android.net.ConnectivityManager.CONNECTIVITY_ACTION;
import static android.net.ConnectivityManager.CONNECTIVITY_ACTION_SUPL;
@@ -570,6 +571,9 @@ public class ConnectivityServiceTest {
| NETWORK_VALIDATION_RESULT_PARTIAL;
private static final int VALIDATION_RESULT_INVALID = 0;
private static final long DATA_STALL_TIMESTAMP = 10L;
private static final int DATA_STALL_DETECTION_METHOD = 1;
private INetworkMonitor mNetworkMonitor;
private INetworkMonitorCallbacks mNmCallbacks;
private int mNmValidationResult = VALIDATION_RESULT_BASE;
@@ -577,6 +581,7 @@ public class ConnectivityServiceTest {
private int mProbesSucceeded;
private String mNmValidationRedirectUrl = null;
private PersistableBundle mValidationExtras = PersistableBundle.EMPTY;
private PersistableBundle mDataStallExtras = PersistableBundle.EMPTY;
private boolean mNmProvNotificationRequested = false;
private final ConditionVariable mNetworkStatusReceived = new ConditionVariable();
@@ -804,6 +809,11 @@ public class ConnectivityServiceTest {
public void expectPreventReconnectReceived() {
expectPreventReconnectReceived(TIMEOUT_MS);
}
void notifyDataStallSuspected() throws Exception {
mNmCallbacks.notifyDataStallSuspected(
DATA_STALL_TIMESTAMP, DATA_STALL_DETECTION_METHOD, mDataStallExtras);
}
}
/**
@@ -6625,4 +6635,35 @@ public class ConnectivityServiceTest {
verify(mConnectivityDiagnosticsCallback, timeout(TIMEOUT_MS))
.onConnectivityReport(any(ConnectivityReport.class));
}
@Test
public void testConnectivityDiagnosticsCallbackOnDataStallSuspected() throws Exception {
final NetworkRequest request = new NetworkRequest.Builder().build();
when(mConnectivityDiagnosticsCallback.asBinder()).thenReturn(mIBinder);
mServiceContext.setPermission(
android.Manifest.permission.NETWORK_STACK, PERMISSION_GRANTED);
mService.registerConnectivityDiagnosticsCallback(
mConnectivityDiagnosticsCallback, request, mContext.getPackageName());
// Block until all other events are done processing.
HandlerUtilsKt.waitForIdle(mCsHandlerThread, TIMEOUT_MS);
// Connect the cell agent verify that it notifies TestNetworkCallback that it is available
final TestNetworkCallback callback = new TestNetworkCallback();
mCm.registerDefaultNetworkCallback(callback);
mCellNetworkAgent = new TestNetworkAgentWrapper(TRANSPORT_CELLULAR);
mCellNetworkAgent.connect(true);
callback.expectAvailableThenValidatedCallbacks(mCellNetworkAgent);
callback.assertNoCallback();
// Trigger notifyDataStallSuspected() on the INetworkMonitorCallbacks instance in the
// cellular network agent
mCellNetworkAgent.notifyDataStallSuspected();
// Wait for onDataStallSuspected to fire
verify(mConnectivityDiagnosticsCallback, timeout(TIMEOUT_MS))
.onDataStallSuspected(any(DataStallReport.class));
}
}