From 4d64bd6b2aff66eaeccf924ca8c181cfafaf2cee Mon Sep 17 00:00:00 2001 From: Rambo Wang Date: Fri, 4 Feb 2022 07:55:45 -0800 Subject: [PATCH] Reduce the flakiness of carrier privileges check Monitoring carrier config change broadcast and then checking carrier privileges status is racy. The component that updates CP status (e.g. CarrierPrivilegeTracker) may monitor the same broadcast and the status check result will be determined by the fact who received it firstly. This CL moves the CP check after the current sleep to reduce the flakiness to unblock the CP migration. The follow CL (aosp/1971439) will throughly resolve the flakiness by the the help of CarrierPrivilegesListener. Bug: 217557996 Test: atest android.net.cts.ConnectivityDiagnosticsManagerTest Change-Id: Ib1ab554732b6bb25426a07a42043801a2d05c546 --- .../net/cts/ConnectivityDiagnosticsManagerTest.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tests/cts/net/src/android/net/cts/ConnectivityDiagnosticsManagerTest.java b/tests/cts/net/src/android/net/cts/ConnectivityDiagnosticsManagerTest.java index 232114e27f..68fa38da0f 100644 --- a/tests/cts/net/src/android/net/cts/ConnectivityDiagnosticsManagerTest.java +++ b/tests/cts/net/src/android/net/cts/ConnectivityDiagnosticsManagerTest.java @@ -278,18 +278,23 @@ public class ConnectivityDiagnosticsManagerTest { assertTrue("Didn't receive broadcast for ACTION_CARRIER_CONFIG_CHANGED for subId=" + subId, carrierConfigReceiver.waitForCarrierConfigChanged()); - assertTrue("Don't have Carrier Privileges after adding cert for this package", - mTelephonyManager.createForSubscriptionId(subId).hasCarrierPrivileges()); // Wait for CarrierPrivilegesTracker to receive the ACTION_CARRIER_CONFIG_CHANGED // broadcast. CPT then needs to update the corresponding DataConnection, which then // updates ConnectivityService. Unfortunately, this update to the NetworkCapabilities in // CS does not trigger NetworkCallback#onCapabilitiesChanged as changing the // administratorUids is not a publicly visible change. In lieu of a better signal to - // detministically wait for, use Thread#sleep here. + // deterministically wait for, use Thread#sleep here. // TODO(b/157949581): replace this Thread#sleep with a deterministic signal Thread.sleep(DELAY_FOR_ADMIN_UIDS_MILLIS); + // TODO(b/217559768): Receiving carrier config change and immediately checking carrier + // privileges is racy, as the CP status is updated after receiving the same signal. Move + // the CP check after sleep to temporarily reduce the flakiness. This will soon be fixed + // by switching to CarrierPrivilegesListener. + assertTrue("Don't have Carrier Privileges after adding cert for this package", + mTelephonyManager.createForSubscriptionId(subId).hasCarrierPrivileges()); + final TestConnectivityDiagnosticsCallback connDiagsCallback = createAndRegisterConnectivityDiagnosticsCallback(CELLULAR_NETWORK_REQUEST);