From 3d1df816d2374e7c5dc390b021d88811729dccee Mon Sep 17 00:00:00 2001 From: Cody Kesting Date: Thu, 25 Jun 2020 11:13:39 -0700 Subject: [PATCH] Send ConnDiags event before revalidating network in CS. This change updates ConnectivityService to notify the ConnectivityDiagnosticsHandler of app-reported connectivity before attempting to revalidate the network. This change forces an ordering on Connectivity Diagnostics events in the case that the reported connectivity does not match the known connectivity for the network - this leads to the network being revalidated and the ConnectivityDiagnostics event onConnectivityReportAvailable. Passing the onNetworkConnectivityReported event to the ConnectivityDiagnosticsHandler first ensures that it is passed to callbacks before any potential ConnectivityReports are. Bug: 159718782 Test: android.net.cts.ConnectivityDiagnosticsManagerTest Change-Id: Ic7bc7138c54c47bbfdf56af5811709fde66f8606 --- .../java/com/android/server/ConnectivityService.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/services/core/java/com/android/server/ConnectivityService.java b/services/core/java/com/android/server/ConnectivityService.java index 52cc8f633d..4c8fe4c347 100644 --- a/services/core/java/com/android/server/ConnectivityService.java +++ b/services/core/java/com/android/server/ConnectivityService.java @@ -4315,9 +4315,11 @@ public class ConnectivityService extends IConnectivityManager.Stub enforceInternetPermission(); final int uid = Binder.getCallingUid(); final int connectivityInfo = encodeBool(hasConnectivity); - mHandler.sendMessage( - mHandler.obtainMessage(EVENT_REVALIDATE_NETWORK, uid, connectivityInfo, network)); + // Handle ConnectivityDiagnostics event before attempting to revalidate the network. This + // forces an ordering of ConnectivityDiagnostics events in the case where hasConnectivity + // does not match the known connectivity of the network - this causes NetworkMonitor to + // revalidate the network and generate a ConnectivityDiagnostics ConnectivityReport event. final NetworkAgentInfo nai; if (network == null) { nai = getDefaultNetwork(); @@ -4330,6 +4332,9 @@ public class ConnectivityService extends IConnectivityManager.Stub ConnectivityDiagnosticsHandler.EVENT_NETWORK_CONNECTIVITY_REPORTED, connectivityInfo, 0, nai)); } + + mHandler.sendMessage( + mHandler.obtainMessage(EVENT_REVALIDATE_NETWORK, uid, connectivityInfo, network)); } private void handleReportNetworkConnectivity(