RESTRICT AUTOMERGE Reland "Ensure CONFIGURED_NETWORKS_CHANGED_ACTION broadcast is received"

This reverts commit d65503229232437d3d7ef3f5f1e60cc52bd9a0ce.

Reason for revert: Reland with security patch level check

Bug: 172364816
Change-Id: I4e1210083b695994a15e78fe64c91888b6b23a07
diff --git a/tests/tests/net/src/android/net/wifi/cts/WifiManagerTest.java b/tests/tests/net/src/android/net/wifi/cts/WifiManagerTest.java
index 2ed0124..dea68de 100644
--- a/tests/tests/net/src/android/net/wifi/cts/WifiManagerTest.java
+++ b/tests/tests/net/src/android/net/wifi/cts/WifiManagerTest.java
@@ -32,17 +32,20 @@
 import android.net.wifi.hotspot2.PasspointConfiguration;
 import android.net.wifi.hotspot2.pps.Credential;
 import android.net.wifi.hotspot2.pps.HomeSp;
+import android.os.Build;
 import android.os.SystemClock;
 import android.provider.Settings;
 import android.test.AndroidTestCase;
 import android.util.Log;
 
+import com.android.compatibility.common.util.PollingCheck;
 import com.android.compatibility.common.util.WifiConfigCreator;
 
 import java.net.HttpURLConnection;
 import java.net.URL;
 import java.security.MessageDigest;
 import java.security.cert.X509Certificate;
+import java.time.LocalDate;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
@@ -131,6 +134,14 @@
         }
     };
 
+    private static final LocalDate SECURITY_PATCH_DATE_2020_12 = LocalDate.of(2020, 12, 1);
+
+    private static boolean doesDeviceHave2020_12SecurityPatch() {
+        LocalDate deviceSecurityPatchDate = LocalDate.parse(Build.VERSION.SECURITY_PATCH);
+        // LocalDate#isBefore() is exclusive, so use workaround: !(a < b) <=> (b <= a)
+        return !deviceSecurityPatchDate.isBefore(SECURITY_PATCH_DATE_2020_12);
+    }
+
     @Override
     protected void setUp() throws Exception {
         super.setUp();
@@ -456,12 +467,37 @@
             assertFalse(existSSID(SSID1));
             assertTrue(existSSID(SSID2));
 
+            // Need an effectively-final holder because we need to modify inner Intent in callback.
+            class IntentHolder {
+              Intent intent;
+            }
+            IntentHolder intentHolder = new IntentHolder();
+            mContext.registerReceiver(new BroadcastReceiver() {
+              @Override
+              public void onReceive(Context context, Intent intent) {
+                Log.i(TAG, "Received CONFIGURED_NETWORKS_CHANGED_ACTION broadcast: " + intent);
+                intentHolder.intent = intent;
+              }
+            }, new IntentFilter(WifiManager.CONFIGURED_NETWORKS_CHANGED_ACTION));
+
             // Remove a WifiConfig
             assertTrue(mWifiManager.removeNetwork(netId));
             assertFalse(mWifiManager.removeNetwork(notExist));
             assertFalse(existSSID(SSID1));
             assertFalse(existSSID(SSID2));
 
+            if (doesDeviceHave2020_12SecurityPatch()) {
+                // Should receive CONFIGURED_NETWORKS_CHANGED_ACTION broadcast because
+                // CtsNetTestCases' AndroidManifest.xml has both ACCESS_WIFI_STATE &
+                // ACCESS_FINE_LOCATION permissions.
+                PollingCheck.check(
+                        "Didn't receive CONFIGURED_NETWORKS_CHANGED_ACTION broadcast!",
+                        DURATION,
+                        () -> intentHolder.intent != null);
+                Intent intent = intentHolder.intent;
+                assertEquals(WifiManager.CONFIGURED_NETWORKS_CHANGED_ACTION, intent.getAction());
+            }
+
             assertTrue(mWifiManager.saveConfiguration());
         } finally {
             reEnableNetworks(enabledSsids, mWifiManager.getConfiguredNetworks());