Merge "Merge "Merge "Ensure CONFIGURED_NETWORKS_CHANGED not received without permissions" into oreo-cts-dev am: f23d174804" into oreo-mr1-cts-dev am: 09eb86e9af" into pie-cts-dev

This commit is contained in:
Automerger Merge Worker
2020-10-13 15:08:06 +00:00
committed by Gerrit Code Review

View File

@@ -456,12 +456,33 @@ public class WifiManagerTest extends AndroidTestCase {
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));
// wait 10 seconds to ensure that broadcast wasn't received
Thread.sleep(DURATION);
Intent intent = intentHolder.intent;
// Broadcast shouldn't be received because although CtsNetTestCases has
// ACCESS_WIFI_STATE permission, it doesn't have ACCESS_FINE_LOCATION permission.
// Receivers need both permissions to get the broadcast.
assertNull("Unexpected received CONFIGURED_NETWORKS_CHANGED_ACTION broadcast!", intent);
assertTrue(mWifiManager.saveConfiguration());
} finally {
reEnableNetworks(enabledSsids, mWifiManager.getConfiguredNetworks());