wifi: add setSecurityParams APIs for wifi service migration
Bug: 162685856 Test: atest FrameworksWifiApiTest Change-Id: I6b53227a9fb5e68cc2039cb29a8ab3e11bc70bc8
This commit is contained in:
@@ -566,10 +566,27 @@ public class WifiConfiguration implements Parcelable {
|
||||
*/
|
||||
public void setSecurityParams(@SecurityType int securityType) {
|
||||
// Clear existing data.
|
||||
mSecurityParamsList = new ArrayList<>();
|
||||
mSecurityParamsList.clear();
|
||||
addSecurityParams(securityType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set security params by the given key management mask.
|
||||
*
|
||||
* @param givenAllowedKeyManagement the given allowed key management mask.
|
||||
* @hide
|
||||
*/
|
||||
public void setSecurityParams(@NonNull BitSet givenAllowedKeyManagement) {
|
||||
if (givenAllowedKeyManagement == null) {
|
||||
throw new IllegalArgumentException("Invalid allowed key management mask.");
|
||||
}
|
||||
// Clear existing data.
|
||||
mSecurityParamsList.clear();
|
||||
|
||||
allowedKeyManagement = (BitSet) givenAllowedKeyManagement.clone();
|
||||
convertLegacyFieldsToSecurityParamsIfNeeded();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the various security params.
|
||||
* <br>
|
||||
@@ -578,10 +595,25 @@ public class WifiConfiguration implements Parcelable {
|
||||
*/
|
||||
public void setSecurityParams(SecurityParams params) {
|
||||
// Clear existing data.
|
||||
mSecurityParamsList = new ArrayList<>();
|
||||
mSecurityParamsList.clear();
|
||||
addSecurityParams(params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the security params by the given security params list.
|
||||
*
|
||||
* This will overwrite existing security params list directly.
|
||||
*
|
||||
* @param securityParamsList the desired security params list.
|
||||
* @hide
|
||||
*/
|
||||
public void setSecurityParams(@NonNull List<SecurityParams> securityParamsList) {
|
||||
if (securityParamsList == null || securityParamsList.isEmpty()) {
|
||||
throw new IllegalArgumentException("An empty security params list is invalid.");
|
||||
}
|
||||
mSecurityParamsList = new ArrayList<>(securityParamsList);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the various security params to correspond to the provided security type.
|
||||
* This is accomplished by setting the various BitSets exposed in WifiConfiguration.
|
||||
|
||||
@@ -53,6 +53,8 @@ import com.android.net.module.util.MacAddressUtils;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.BitSet;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -1123,4 +1125,76 @@ public class WifiConfigurationTest {
|
||||
assertNotNull(config.getSecurityParams(type));
|
||||
}
|
||||
}
|
||||
|
||||
/** Verify the set security params by an allowed key management mask. */
|
||||
@Test
|
||||
public void testSetSecurityParamsByAllowedKeyManagement() {
|
||||
Pair[] keyMgmtSecurityTypePairs = new Pair[] {
|
||||
new Pair<>(KeyMgmt.WAPI_CERT, SECURITY_TYPE_WAPI_CERT),
|
||||
new Pair<>(KeyMgmt.WAPI_PSK, SECURITY_TYPE_WAPI_PSK),
|
||||
new Pair<>(KeyMgmt.SUITE_B_192, SECURITY_TYPE_EAP_WPA3_ENTERPRISE_192_BIT),
|
||||
new Pair<>(KeyMgmt.OWE, SECURITY_TYPE_OWE),
|
||||
new Pair<>(KeyMgmt.SAE, SECURITY_TYPE_SAE),
|
||||
new Pair<>(KeyMgmt.OSEN, SECURITY_TYPE_OSEN),
|
||||
new Pair<>(KeyMgmt.WPA2_PSK, SECURITY_TYPE_PSK),
|
||||
new Pair<>(KeyMgmt.WPA_EAP, SECURITY_TYPE_EAP),
|
||||
new Pair<>(KeyMgmt.WPA_PSK, SECURITY_TYPE_PSK),
|
||||
new Pair<>(KeyMgmt.NONE, SECURITY_TYPE_OPEN),
|
||||
};
|
||||
|
||||
for (Pair pair: keyMgmtSecurityTypePairs) {
|
||||
BitSet akm = new BitSet();
|
||||
akm.set((int) pair.first);
|
||||
WifiConfiguration config = new WifiConfiguration();
|
||||
config.setSecurityParams(akm);
|
||||
assertNotNull(config.getSecurityParams((int) pair.second));
|
||||
}
|
||||
}
|
||||
|
||||
/** Verify the set security params by an invalid allowed key management mask. */
|
||||
@Test (expected = IllegalArgumentException.class)
|
||||
public void testSetSecurityParamsByInvalidAllowedKeyManagement() {
|
||||
WifiConfiguration config = new WifiConfiguration();
|
||||
BitSet akm = null;
|
||||
config.setSecurityParams(akm);
|
||||
}
|
||||
|
||||
/** Verify the set security params by a security params list. */
|
||||
@Test
|
||||
public void testSetSecurityParamsBySecurityParamsList() {
|
||||
WifiConfiguration config = new WifiConfiguration();
|
||||
config.enterpriseConfig.setEapMethod(WifiEnterpriseConfig.Eap.SIM);
|
||||
config.enterpriseConfig.setPhase2Method(WifiEnterpriseConfig.Phase2.NONE);
|
||||
config.addSecurityParams(SECURITY_TYPE_EAP);
|
||||
config.addSecurityParams(SECURITY_TYPE_EAP_WPA3_ENTERPRISE);
|
||||
assertTrue(config.isSecurityType(SECURITY_TYPE_EAP));
|
||||
assertTrue(config.isSecurityType(SECURITY_TYPE_EAP_WPA3_ENTERPRISE));
|
||||
assertFalse(config.isSecurityType(SECURITY_TYPE_PSK));
|
||||
assertFalse(config.isSecurityType(SECURITY_TYPE_SAE));
|
||||
|
||||
List<SecurityParams> list = new ArrayList<>();
|
||||
list.add(SecurityParams.createSecurityParamsBySecurityType(SECURITY_TYPE_PSK));
|
||||
list.add(SecurityParams.createSecurityParamsBySecurityType(SECURITY_TYPE_SAE));
|
||||
config.setSecurityParams(list);
|
||||
assertFalse(config.isSecurityType(SECURITY_TYPE_EAP));
|
||||
assertFalse(config.isSecurityType(SECURITY_TYPE_EAP_WPA3_ENTERPRISE));
|
||||
assertTrue(config.isSecurityType(SECURITY_TYPE_PSK));
|
||||
assertTrue(config.isSecurityType(SECURITY_TYPE_SAE));
|
||||
}
|
||||
|
||||
/** Verify the set security params by an empty security params list. */
|
||||
@Test (expected = IllegalArgumentException.class)
|
||||
public void testSetSecurityParamsByEmptySecurityParamsList() {
|
||||
WifiConfiguration config = new WifiConfiguration();
|
||||
List<SecurityParams> list = new ArrayList<>();
|
||||
config.setSecurityParams(list);
|
||||
}
|
||||
|
||||
/** Verify the set security params by a null security params list. */
|
||||
@Test (expected = IllegalArgumentException.class)
|
||||
public void testSetSecurityParamsByNullSecurityParamsList() {
|
||||
WifiConfiguration config = new WifiConfiguration();
|
||||
List<SecurityParams> list = null;
|
||||
config.setSecurityParams(list);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user