Ensure CONFIGURED_NETWORKS_CHANGED not received without permissions
Ensure that the CONFIGURED_NETWORKS_CHANGED_ACTION broadcast is not received without the required permissions. Bug: 159373687 Test: cts-tradefed run cts -m CtsNetTestCases --test android.net.wifi.cts.WifiManagerTest#testWifiManagerNetWork Change-Id: I2e3f38b05d63571e838b148fbbb2ce6f68c19c01 Merged-In: I4669a6ff79b3d2e99795015e42bfa611cffb9070
This commit is contained in:
@@ -411,12 +411,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());
|
||||
|
||||
Reference in New Issue
Block a user