WifiNetworkSpecifier: Ensure we don't match a regular wifi network

In Android 10, ClientModeImpl would always attach a
WifiNetworkAgentSpecifier for all wifi network agents created
(regardless of whether it was created in response to a specific request
or not). In Android 11, we changed that behavior to ensure that we
attach the WifiNetworkAgentSpecifier only for agents created in response
to a specific request. However, that is exposing a bug in
WifiNetworkSpecifier matching. WifiNetworkSpecifier attached requests
should not satisfy a generic wifi network agent. Fix the
canSatisfiedBy() matching to ensure that it only matches
WifiNetworkAgentSpecifier (or itself which cannot happen during network
matching)

Bug: 149500993
Test: Add a saved network manually while running the failing ACTS test:
act.py -c wifi_manager_cross.config -tb dut-name -tc WifiNetworkRequestTest:
test_match_failure_with_invalid_ssid_pattern
Test: atest android.net.wifi

Change-Id: I38d154bd0a5685fcc38de891256a8e1d4b8cfbb5
This commit is contained in:
Roshan Pius
2020-04-06 23:30:23 -07:00
parent f241f95205
commit 573e3fe6be
2 changed files with 4 additions and 12 deletions

View File

@@ -21,7 +21,6 @@ import static com.android.internal.util.Preconditions.checkNotNull;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.net.MacAddress;
import android.net.MatchAllNetworkSpecifier;
import android.net.NetworkRequest;
import android.net.NetworkSpecifier;
import android.os.Parcel;
@@ -553,13 +552,6 @@ public final class WifiNetworkSpecifier extends NetworkSpecifier implements Parc
/** @hide */
@Override
public boolean canBeSatisfiedBy(NetworkSpecifier other) {
if (this == other) {
return true;
}
// Any generic requests should be satisifed by a specific wifi network.
if (other == null || other instanceof MatchAllNetworkSpecifier) {
return true;
}
if (other instanceof WifiNetworkAgentSpecifier) {
return ((WifiNetworkAgentSpecifier) other).satisfiesNetworkSpecifier(this);
}

View File

@@ -382,11 +382,11 @@ public class WifiNetworkSpecifierTest {
/**
* Validate NetworkSpecifier matching.
* a) Create a network specifier for WPA_PSK network
* b) Ensure that the specifier matches {@code null} and {@link MatchAllNetworkSpecifier}
* b) Ensure that the specifier does not match {@code null} and {@link MatchAllNetworkSpecifier}
* specifiers.
*/
@Test
public void testWifiNetworkSpecifierSatisfiesNullAndAllMatch() {
public void testWifiNetworkSpecifierDoesNotSatisfyNullAndAllMatch() {
WifiConfiguration wifiConfiguration = new WifiConfiguration();
wifiConfiguration.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);
wifiConfiguration.preSharedKey = TEST_PRESHARED_KEY;
@@ -396,8 +396,8 @@ public class WifiNetworkSpecifierTest {
MacAddress.fromString(TEST_BSSID_OUI_MASK)),
wifiConfiguration);
assertTrue(specifier.canBeSatisfiedBy(null));
assertTrue(specifier.canBeSatisfiedBy(new MatchAllNetworkSpecifier()));
assertFalse(specifier.canBeSatisfiedBy(null));
assertFalse(specifier.canBeSatisfiedBy(new MatchAllNetworkSpecifier()));
}
/**