CTS - WifiManager#setMacRandomizationSettingPasspointEnabled

Verify the mac randomization setting for passpoint networks could be
set.

Bug: b/150322975
Test: atest WifiMangagerTest
Change-Id: Id4c3eda797591ff5b71b62e3ba3f699ed712bda2
This commit is contained in:
xshu
2020-02-26 14:55:33 -08:00
parent da2f490cc6
commit ff16f496f1
2 changed files with 55 additions and 0 deletions

View File

@@ -0,0 +1 @@
Q29udGVudC1UeXBlOiBtdWx0aXBhcnQvbWl4ZWQ7IGJvdW5kYXJ5PXtib3VuZGFyeX0KQ29udGVudC1UcmFuc2Zlci1FbmNvZGluZzogYmFzZTY0CgotLXtib3VuZGFyeX0KQ29udGVudC1UeXBlOiBhcHBsaWNhdGlvbi94LXBhc3Nwb2ludC1wcm9maWxlCkNvbnRlbnQtVHJhbnNmZXItRW5jb2Rpbmc6IGJhc2U2NAoKUEUxbmJYUlVjbVZsSUhodGJHNXpQU0p6ZVc1amJXdzZaRzFrWkdZeExqSWlQZ29nSUR4V1pYSkVWRVErTVM0eVBDOVdaWEpFVkVRK0NpQWdQRTV2WkdVK0NpQWdJQ0E4VG05a1pVNWhiV1UrVUdWeVVISnZkbWxrWlhKVGRXSnpZM0pwY0hScGIyNDhMMDV2WkdWT1lXMWxQZ29nSUNBZ1BGSlVVSEp2Y0dWeWRHbGxjejRLSUNBZ0lDQWdQRlI1Y0dVK0NpQWdJQ0FnSUNBZ1BFUkVSazVoYldVK2RYSnVPbmRtWVRwdGJ6cG9iM1J6Y0c5ME1tUnZkREF0Y0dWeWNISnZkbWxrWlhKemRXSnpZM0pwY0hScGIyNDZNUzR3UEM5RVJFWk9ZVzFsUGdvZ0lDQWdJQ0E4TDFSNWNHVStDaUFnSUNBOEwxSlVVSEp2Y0dWeWRHbGxjejRLSUNBZ0lEeE9iMlJsUGdvZ0lDQWdJQ0E4VG05a1pVNWhiV1UrYVRBd01Ud3ZUbTlrWlU1aGJXVStDaUFnSUNBZ0lEeE9iMlJsUGdvZ0lDQWdJQ0FnSUR4T2IyUmxU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4V1lXeDFaVDR6TVRBME1UQXFQQzlXWVd4MVpUNEtJQ0FnSUNBZ0lDQWdJRHd2VG05a1pUNEtJQ0FnSUNBZ0lDQWdJQ0FnUEU1dlpHVStDaUFnSUNBZ0lDQWdJQ0FnSUNBZ1BFNXZaR1ZPWVcxbFBrVkJVRlI1Y0dVOEwwNXZaR1ZPWVcxbFBnb2dJQ0FnSUNBZ0lDQWdJQ0FnSUR4V1lXeDFaVDR5TXp3dlZtRnNkV1UrQ2lBZ0lDQWdJQ0FnSUNBZ0lEd3ZUbTlrWlQ0S0lDQWdJQ0FnSUNBOEwwNXZaR1UrQ2lBZ0lDQWdJRHd2VG05a1pUNEtJQ0FnSUR3dlRtOWtaVDRLSUNBOEwwNXZaR1UrQ2p3dlRXZHRkRlJ5WldVKwotLXtib3VuZGFyeX0tLQo=

View File

@@ -45,6 +45,8 @@ import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiManager;
import android.net.wifi.WifiManager.WifiLock;
import android.net.wifi.WifiNetworkConnectionStatistics;
import android.net.wifi.hotspot2.ConfigParser;
import android.net.wifi.hotspot2.PasspointConfiguration;
import android.os.Process;
import android.os.SystemClock;
import android.os.UserHandle;
@@ -63,6 +65,10 @@ import com.android.compatibility.common.util.PollingCheck;
import com.android.compatibility.common.util.ShellIdentityUtils;
import com.android.compatibility.common.util.SystemUtil;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.List;
@@ -125,6 +131,9 @@ public class WifiManagerTest extends AndroidTestCase {
private static final String TEST_SSID_UNQUOTED = "testSsid1";
private static final MacAddress TEST_MAC = MacAddress.fromString("aa:bb:cc:dd:ee:ff");
private static final String TEST_PASSPHRASE = "passphrase";
private static final String PASSPOINT_INSTALLATION_FILE_WITH_CA_CERT =
"assets/ValidPasspointProfile.base64";
private static final String TYPE_WIFI_CONFIG = "application/x-wifi-config";
private IntentFilter mIntentFilter;
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
@@ -742,6 +751,51 @@ public class WifiManagerTest extends AndroidTestCase {
}
}
/**
* Read the content of the given resource file into a String.
*
* @param filename String name of the file
* @return String
* @throws IOException
*/
private String loadResourceFile(String filename) throws IOException {
InputStream in = getClass().getClassLoader().getResourceAsStream(filename);
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
StringBuilder builder = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
builder.append(line).append("\n");
}
return builder.toString();
}
/**
* Verify that changing the mac randomization setting of a Passpoint configuration.
*/
public void testMacRandomizationSettingPasspoint() throws Exception {
String configStr = loadResourceFile(PASSPOINT_INSTALLATION_FILE_WITH_CA_CERT);
PasspointConfiguration config =
ConfigParser.parsePasspointConfig(TYPE_WIFI_CONFIG, configStr.getBytes());
UiAutomation uiAutomation = InstrumentationRegistry.getInstrumentation().getUiAutomation();
try {
uiAutomation.adoptShellPermissionIdentity();
mWifiManager.addOrUpdatePasspointConfiguration(config);
List<PasspointConfiguration> passpointConfigs =
mWifiManager.getPasspointConfigurations();
PasspointConfiguration passpointConfig = passpointConfigs.get(0);
assertEquals(1, passpointConfigs.size());
assertTrue("Mac randomization should be enabled for passpoint networks by default.",
passpointConfig.isMacRandomizationEnabled());
String fqdn = passpointConfig.getHomeSp().getFqdn();
mWifiManager.setMacRandomizationSettingPasspointEnabled(fqdn, false);
assertFalse("Mac randomization should be disabled by the API call.",
mWifiManager.getPasspointConfigurations().get(0).isMacRandomizationEnabled());
} finally {
uiAutomation.dropShellPermissionIdentity();
}
}
/**
* Verify that the {@link android.Manifest.permission#NETWORK_STACK} permission is never held by
* any package.