configList = mWifiManager.getPasspointConfigurations();
- assertEquals(numOfNetworks + 1, configList.size());
-
- boolean anyMatch = false;
- for (PasspointConfiguration passpointConfiguration : configList) {
- if (passpointConfiguration.equals(config)) {
- anyMatch = true;
- break;
- }
- }
- assertTrue(anyMatch);
-
- // remove the (test) configuration and verify number of installed configurations
- mWifiManager.removePasspointConfiguration(config.getHomeSp().getFqdn());
- assertEquals(mWifiManager.getPasspointConfigurations().size(), numOfNetworks);
- } catch (UnsupportedOperationException e) {
- // Passpoint build config |config_wifi_hotspot2_enabled| is disabled, so noop.
- }
- }
-
public class TestLocalOnlyHotspotCallback extends WifiManager.LocalOnlyHotspotCallback {
Object hotspotLock;
WifiManager.LocalOnlyHotspotReservation reservation = null;
@@ -837,6 +570,11 @@ public class WifiManagerTest extends AndroidTestCase {
// check if we got the callback
assertTrue(callback.onStartedCalled);
assertNotNull(callback.reservation.getWifiConfiguration());
+ if (!hasAutomotiveFeature()) {
+ assertEquals(
+ WifiConfiguration.AP_BAND_2GHZ,
+ callback.reservation.getWifiConfiguration().apBand);
+ }
assertFalse(callback.onFailedCalled);
assertFalse(callback.onStoppedCalled);
}
@@ -892,37 +630,37 @@ public class WifiManagerTest extends AndroidTestCase {
}
/**
- * Verify calls to setWifiEnabled from a non-settings app while softap mode is active do not
- * exit softap mode.
- *
- * This test uses the LocalOnlyHotspot API to enter softap mode. This should also be true when
- * tethering is started.
- * Note: Location mode must be enabled for this test.
+ * Verify calls to deprecated API's all fail for non-settings apps targeting >= Q SDK.
*/
- public void testSetWifiEnabledByAppDoesNotStopHotspot() throws Exception {
+ public void testDeprecatedApis() throws Exception {
if (!WifiFeature.isWifiSupported(getContext())) {
// skip the test if WiFi is not supported
return;
}
- // check that softap mode is supported by the device
- if (!mWifiManager.isPortableHotspotSupported()) {
- return;
- }
+ setWifiEnabled(true);
+ connectWifi(); // ensures that there is at-least 1 saved network on the device.
+
+ WifiConfiguration wifiConfiguration = new WifiConfiguration();
+ wifiConfiguration.SSID = SSID1;
+ wifiConfiguration.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
+
+ assertEquals(WifiConfiguration.INVALID_NETWORK_ID,
+ mWifiManager.addNetwork(wifiConfiguration));
+ assertEquals(WifiConfiguration.INVALID_NETWORK_ID,
+ mWifiManager.updateNetwork(wifiConfiguration));
+ assertFalse(mWifiManager.enableNetwork(0, true));
+ assertFalse(mWifiManager.disableNetwork(0));
+ assertFalse(mWifiManager.removeNetwork(0));
+ assertFalse(mWifiManager.disconnect());
+ assertFalse(mWifiManager.reconnect());
+ assertFalse(mWifiManager.reassociate());
+ assertTrue(mWifiManager.getConfiguredNetworks().isEmpty());
boolean wifiEnabled = mWifiManager.isWifiEnabled();
-
- if (wifiEnabled) {
- // disable wifi so we have something to turn on (some devices may be able to run
- // simultaneous modes)
- setWifiEnabled(false);
- }
-
- TestLocalOnlyHotspotCallback callback = startLocalOnlyHotspot();
-
- // now we should fail to turn on wifi
- assertFalse(mWifiManager.setWifiEnabled(true));
-
- stopLocalOnlyHotspot(callback, wifiEnabled);
+ // now we should fail to toggle wifi state.
+ assertFalse(mWifiManager.setWifiEnabled(!wifiEnabled));
+ Thread.sleep(DURATION);
+ assertEquals(wifiEnabled, mWifiManager.isWifiEnabled());
}
/**
@@ -971,4 +709,343 @@ public class WifiManagerTest extends AndroidTestCase {
stopLocalOnlyHotspot(callback, wifiEnabled);
}
+
+ /**
+ * Verify that the {@link android.Manifest.permission#NETWORK_STACK} permission is never held by
+ * any package.
+ *
+ * No apps should ever attempt to acquire this permission, since it would give those
+ * apps extremely broad access to connectivity functionality.
+ */
+ public void testNetworkStackPermission() {
+ final PackageManager pm = getContext().getPackageManager();
+
+ final List holding = pm.getPackagesHoldingPermissions(new String[] {
+ android.Manifest.permission.NETWORK_STACK
+ }, PackageManager.MATCH_UNINSTALLED_PACKAGES);
+ for (PackageInfo pi : holding) {
+ fail("The NETWORK_STACK permission must not be held by " + pi.packageName
+ + " and must be revoked for security reasons");
+ }
+ }
+
+ /**
+ * Verify that the {@link android.Manifest.permission#NETWORK_SETTINGS} permission is
+ * never held by any package.
+ *
+ * Only Settings, SysUi, NetworkStack and shell apps should ever attempt to acquire
+ * this permission, since it would give those apps extremely broad access to connectivity
+ * functionality. The permission is intended to be granted to only those apps with direct user
+ * access and no others.
+ */
+ public void testNetworkSettingsPermission() {
+ final PackageManager pm = getContext().getPackageManager();
+
+ final ArraySet allowedPackages = new ArraySet();
+ final ArraySet allowedUIDs = new ArraySet();
+ // explicitly add allowed UIDs
+ allowedUIDs.add(Process.SYSTEM_UID);
+ allowedUIDs.add(Process.SHELL_UID);
+ allowedUIDs.add(Process.PHONE_UID);
+ allowedUIDs.add(Process.NETWORK_STACK_UID);
+ allowedUIDs.add(Process.NFC_UID);
+
+ // only quick settings is allowed to bind to the BIND_QUICK_SETTINGS_TILE permission, using
+ // this fact to determined allowed package name for sysui. This is a signature permission,
+ // so allow any package with this permission.
+ final List sysuiPackages = pm.getPackagesHoldingPermissions(new String[] {
+ android.Manifest.permission.BIND_QUICK_SETTINGS_TILE
+ }, PackageManager.MATCH_UNINSTALLED_PACKAGES);
+ for (PackageInfo info : sysuiPackages) {
+ allowedPackages.add(info.packageName);
+ }
+
+ // the captive portal flow also currently holds the NETWORK_SETTINGS permission
+ final Intent intent = new Intent(ConnectivityManager.ACTION_CAPTIVE_PORTAL_SIGN_IN);
+ final ResolveInfo ri = pm.resolveActivity(intent, PackageManager.MATCH_DISABLED_COMPONENTS);
+ if (ri != null) {
+ allowedPackages.add(ri.activityInfo.packageName);
+ }
+
+ final List holding = pm.getPackagesHoldingPermissions(new String[] {
+ android.Manifest.permission.NETWORK_SETTINGS
+ }, PackageManager.MATCH_UNINSTALLED_PACKAGES);
+ for (PackageInfo pi : holding) {
+ String packageName = pi.packageName;
+
+ // this is an explicitly allowed package
+ if (allowedPackages.contains(packageName)) continue;
+
+ // now check if the packages are from allowed UIDs
+ int uid = -1;
+ try {
+ uid = pm.getPackageUidAsUser(packageName, UserHandle.USER_SYSTEM);
+ } catch (PackageManager.NameNotFoundException e) {
+ continue;
+ }
+ if (!allowedUIDs.contains(uid)) {
+ fail("The NETWORK_SETTINGS permission must not be held by " + packageName
+ + ":" + uid + " and must be revoked for security reasons");
+ }
+ }
+ }
+
+ /**
+ * Verify that the {@link android.Manifest.permission#NETWORK_SETUP_WIZARD} permission is
+ * only held by the device setup wizard application.
+ *
+ * Only the SetupWizard app should ever attempt to acquire this
+ * permission, since it would give those apps extremely broad access to connectivity
+ * functionality. The permission is intended to be granted to only the device setup wizard.
+ */
+ public void testNetworkSetupWizardPermission() {
+ final ArraySet allowedPackages = new ArraySet();
+
+ final PackageManager pm = getContext().getPackageManager();
+
+ final Intent intent = new Intent(Intent.ACTION_MAIN);
+ intent.addCategory(Intent.CATEGORY_SETUP_WIZARD);
+ final ResolveInfo ri = pm.resolveActivity(intent, PackageManager.MATCH_DISABLED_COMPONENTS);
+ String validPkg = "";
+ if (ri != null) {
+ allowedPackages.add(ri.activityInfo.packageName);
+ validPkg = ri.activityInfo.packageName;
+ }
+
+ final Intent preIntent = new Intent("com.android.setupwizard.OEM_PRE_SETUP");
+ preIntent.addCategory(Intent.CATEGORY_DEFAULT);
+ final ResolveInfo preRi = pm
+ .resolveActivity(preIntent, PackageManager.MATCH_DISABLED_COMPONENTS);
+ String prePackageName = "";
+ if (null != preRi) {
+ prePackageName = preRi.activityInfo.packageName;
+ }
+
+ final Intent postIntent = new Intent("com.android.setupwizard.OEM_POST_SETUP");
+ postIntent.addCategory(Intent.CATEGORY_DEFAULT);
+ final ResolveInfo postRi = pm
+ .resolveActivity(postIntent, PackageManager.MATCH_DISABLED_COMPONENTS);
+ String postPackageName = "";
+ if (null != postRi) {
+ postPackageName = postRi.activityInfo.packageName;
+ }
+ if (!TextUtils.isEmpty(prePackageName) && !TextUtils.isEmpty(postPackageName)
+ && prePackageName.equals(postPackageName)) {
+ allowedPackages.add(prePackageName);
+ }
+
+ final List holding = pm.getPackagesHoldingPermissions(new String[]{
+ android.Manifest.permission.NETWORK_SETUP_WIZARD
+ }, PackageManager.MATCH_UNINSTALLED_PACKAGES);
+ for (PackageInfo pi : holding) {
+ if (!allowedPackages.contains(pi.packageName)) {
+ fail("The NETWORK_SETUP_WIZARD permission must not be held by " + pi.packageName
+ + " and must be revoked for security reasons [" + validPkg + "]");
+ }
+ }
+ }
+
+ /**
+ * Verify that the {@link android.Manifest.permission#NETWORK_MANAGED_PROVISIONING} permission
+ * is only held by the device managed provisioning application.
+ *
+ * Only the ManagedProvisioning app should ever attempt to acquire this
+ * permission, since it would give those apps extremely broad access to connectivity
+ * functionality. The permission is intended to be granted to only the device managed
+ * provisioning.
+ */
+ public void testNetworkManagedProvisioningPermission() {
+ final PackageManager pm = getContext().getPackageManager();
+
+ // TODO(b/115980767): Using hardcoded package name. Need a better mechanism to find the
+ // managed provisioning app.
+ // Ensure that the package exists.
+ final Intent intent = new Intent(Intent.ACTION_MAIN);
+ intent.setPackage(MANAGED_PROVISIONING_PACKAGE_NAME);
+ final ResolveInfo ri = pm.resolveActivity(intent, PackageManager.MATCH_DISABLED_COMPONENTS);
+ String validPkg = "";
+ if (ri != null) {
+ validPkg = ri.activityInfo.packageName;
+ }
+
+ final List holding = pm.getPackagesHoldingPermissions(new String[] {
+ android.Manifest.permission.NETWORK_MANAGED_PROVISIONING
+ }, PackageManager.MATCH_UNINSTALLED_PACKAGES);
+ for (PackageInfo pi : holding) {
+ if (!Objects.equals(pi.packageName, validPkg)) {
+ fail("The NETWORK_MANAGED_PROVISIONING permission must not be held by "
+ + pi.packageName + " and must be revoked for security reasons ["
+ + validPkg +"]");
+ }
+ }
+ }
+
+ /**
+ * Verify that the {@link android.Manifest.permission#WIFI_SET_DEVICE_MOBILITY_STATE} permission
+ * is held by at most one application.
+ */
+ public void testWifiSetDeviceMobilityStatePermission() {
+ final PackageManager pm = getContext().getPackageManager();
+
+ final List holding = pm.getPackagesHoldingPermissions(new String[] {
+ android.Manifest.permission.WIFI_SET_DEVICE_MOBILITY_STATE
+ }, PackageManager.MATCH_UNINSTALLED_PACKAGES);
+
+ List uniquePackageNames = holding
+ .stream()
+ .map(pi -> pi.packageName)
+ .distinct()
+ .collect(Collectors.toList());
+
+ if (uniquePackageNames.size() > 1) {
+ fail("The WIFI_SET_DEVICE_MOBILITY_STATE permission must not be held by more than one "
+ + "application, but is held by " + uniquePackageNames.size() + " applications: "
+ + String.join(", ", uniquePackageNames));
+ }
+ }
+
+ /**
+ * Verify that the {@link android.Manifest.permission#NETWORK_CARRIER_PROVISIONING} permission
+ * is held by at most one application.
+ */
+ public void testNetworkCarrierProvisioningPermission() {
+ final PackageManager pm = getContext().getPackageManager();
+
+ final List holding = pm.getPackagesHoldingPermissions(new String[] {
+ android.Manifest.permission.NETWORK_CARRIER_PROVISIONING
+ }, PackageManager.MATCH_UNINSTALLED_PACKAGES);
+
+ List uniquePackageNames = holding
+ .stream()
+ .map(pi -> pi.packageName)
+ .distinct()
+ .collect(Collectors.toList());
+
+ if (uniquePackageNames.size() > 1) {
+ fail("The NETWORK_CARRIER_PROVISIONING permission must not be held by more than one "
+ + "application, but is held by " + uniquePackageNames.size() + " applications: "
+ + String.join(", ", uniquePackageNames));
+ }
+ }
+
+ /**
+ * Verify that the {@link android.Manifest.permission#WIFI_UPDATE_USABILITY_STATS_SCORE}
+ * permission is held by at most one application.
+ */
+ public void testUpdateWifiUsabilityStatsScorePermission() {
+ final PackageManager pm = getContext().getPackageManager();
+
+ final List holding = pm.getPackagesHoldingPermissions(new String[] {
+ android.Manifest.permission.WIFI_UPDATE_USABILITY_STATS_SCORE
+ }, PackageManager.MATCH_UNINSTALLED_PACKAGES);
+
+ List uniquePackageNames = holding
+ .stream()
+ .map(pi -> pi.packageName)
+ .distinct()
+ .collect(Collectors.toList());
+
+ if (uniquePackageNames.size() > 1) {
+ fail("The WIFI_UPDATE_USABILITY_STATS_SCORE permission must not be held by more than "
+ + "one application, but is held by " + uniquePackageNames.size() + " applications: "
+ + String.join(", ", uniquePackageNames));
+ }
+ }
+
+ private void turnScreenOnNoDelay() throws Exception {
+ mUiDevice.executeShellCommand("input keyevent KEYCODE_WAKEUP");
+ mUiDevice.executeShellCommand("wm dismiss-keyguard");
+ }
+
+ private void turnScreenOn() throws Exception {
+ turnScreenOnNoDelay();
+ // Since the screen on/off intent is ordered, they will not be sent right now.
+ Thread.sleep(DURATION_SCREEN_TOGGLE);
+ }
+
+ private void turnScreenOff() throws Exception {
+ mUiDevice.executeShellCommand("input keyevent KEYCODE_SLEEP");
+ // Since the screen on/off intent is ordered, they will not be sent right now.
+ Thread.sleep(DURATION_SCREEN_TOGGLE);
+ }
+
+ /**
+ * Verify that Wi-Fi scanning is not turned off when the screen turns off while wifi is disabled
+ * but location is on.
+ * @throws Exception
+ */
+ public void testScreenOffDoesNotTurnOffWifiScanningWhenWifiDisabled() throws Exception {
+ if (!WifiFeature.isWifiSupported(getContext())) {
+ // skip the test if WiFi is not supported
+ return;
+ }
+ if (!hasLocationFeature()) {
+ // skip the test if location is not supported
+ return;
+ }
+ if (!isLocationEnabled()) {
+ fail("Please enable location for this test - since Marshmallow WiFi scan results are"
+ + " empty when location is disabled!");
+ }
+ if(!mWifiManager.isScanAlwaysAvailable()) {
+ fail("Please enable Wi-Fi scanning for this test!");
+ }
+ setWifiEnabled(false);
+ turnScreenOn();
+ assertWifiScanningIsOn();
+ // Toggle screen and verify Wi-Fi scanning is still on.
+ turnScreenOff();
+ assertWifiScanningIsOn();
+ turnScreenOn();
+ assertWifiScanningIsOn();
+ }
+
+ /**
+ * Verify that Wi-Fi scanning is not turned off when the screen turns off while wifi is enabled.
+ * @throws Exception
+ */
+ public void testScreenOffDoesNotTurnOffWifiScanningWhenWifiEnabled() throws Exception {
+ if (!WifiFeature.isWifiSupported(getContext())) {
+ // skip the test if WiFi is not supported
+ return;
+ }
+ if (!hasLocationFeature()) {
+ // skip the test if location is not supported
+ return;
+ }
+ if (!isLocationEnabled()) {
+ fail("Please enable location for this test - since Marshmallow WiFi scan results are"
+ + " empty when location is disabled!");
+ }
+ if(!mWifiManager.isScanAlwaysAvailable()) {
+ fail("Please enable Wi-Fi scanning for this test!");
+ }
+ setWifiEnabled(true);
+ turnScreenOn();
+ assertWifiScanningIsOn();
+ // Toggle screen and verify Wi-Fi scanning is still on.
+ turnScreenOff();
+ assertWifiScanningIsOn();
+ turnScreenOn();
+ assertWifiScanningIsOn();
+ }
+
+ /**
+ * Verify that the platform supports a reasonable number of suggestions per app.
+ * @throws Exception
+ */
+ public void testMaxNumberOfNetworkSuggestionsPerApp() throws Exception {
+ if (!WifiFeature.isWifiSupported(getContext())) {
+ // skip the test if WiFi is not supported
+ return;
+ }
+ assertTrue(mWifiManager.getMaxNumberOfNetworkSuggestionsPerApp()
+ > ENFORCED_NUM_NETWORK_SUGGESTIONS_PER_APP);
+ }
+
+ private void assertWifiScanningIsOn() {
+ if(!mWifiManager.isScanAlwaysAvailable()) {
+ fail("Wi-Fi scanning should be on.");
+ }
+ }
}
diff --git a/tests/cts/net/src/android/net/wifi/p2p/cts/WifiP2pConfigTest.java b/tests/cts/net/src/android/net/wifi/p2p/cts/WifiP2pConfigTest.java
new file mode 100644
index 0000000000..639db8a7c3
--- /dev/null
+++ b/tests/cts/net/src/android/net/wifi/p2p/cts/WifiP2pConfigTest.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.net.wifi.p2p.cts;
+
+import android.net.MacAddress;
+import android.net.wifi.p2p.WifiP2pConfig;
+import android.net.wifi.p2p.WifiP2pGroup;
+import android.test.AndroidTestCase;
+
+public class WifiP2pConfigTest extends AndroidTestCase {
+ static final String TEST_NETWORK_NAME = "DIRECT-xy-Hello";
+ static final String TEST_PASSPHRASE = "8etterW0r1d";
+ static final int TEST_OWNER_BAND = WifiP2pConfig.GROUP_OWNER_BAND_5GHZ;
+ static final int TEST_OWNER_FREQ = 2447;
+ static final String TEST_DEVICE_ADDRESS = "aa:bb:cc:dd:ee:ff";
+
+ public void testWifiP2pConfigBuilderForPersist() {
+ WifiP2pConfig.Builder builder = new WifiP2pConfig.Builder();
+ builder.setNetworkName(TEST_NETWORK_NAME)
+ .setPassphrase(TEST_PASSPHRASE)
+ .setGroupOperatingBand(TEST_OWNER_BAND)
+ .setDeviceAddress(MacAddress.fromString(TEST_DEVICE_ADDRESS))
+ .enablePersistentMode(true);
+ WifiP2pConfig config = builder.build();
+
+ assertTrue(config.deviceAddress.equals(TEST_DEVICE_ADDRESS));
+ assertTrue(config.networkName.equals(TEST_NETWORK_NAME));
+ assertTrue(config.passphrase.equals(TEST_PASSPHRASE));
+ assertEquals(config.groupOwnerBand, TEST_OWNER_BAND);
+ assertEquals(config.netId, WifiP2pGroup.PERSISTENT_NET_ID);
+ }
+
+ public void testWifiP2pConfigBuilderForNonPersist() {
+ WifiP2pConfig.Builder builder = new WifiP2pConfig.Builder();
+ builder.setNetworkName(TEST_NETWORK_NAME)
+ .setPassphrase(TEST_PASSPHRASE)
+ .setGroupOperatingFrequency(TEST_OWNER_FREQ)
+ .setDeviceAddress(MacAddress.fromString(TEST_DEVICE_ADDRESS))
+ .enablePersistentMode(false);
+ WifiP2pConfig config = builder.build();
+
+ assertTrue(config.deviceAddress.equals(TEST_DEVICE_ADDRESS));
+ assertTrue(config.networkName.equals(TEST_NETWORK_NAME));
+ assertTrue(config.passphrase.equals(TEST_PASSPHRASE));
+ assertEquals(config.groupOwnerBand, TEST_OWNER_FREQ);
+ assertEquals(config.netId, WifiP2pGroup.TEMPORARY_NET_ID);
+ }
+}
diff --git a/tests/cts/net/src/android/net/wifi/rtt/OWNERS b/tests/cts/net/src/android/net/wifi/rtt/OWNERS
deleted file mode 100644
index 4afc47f43f..0000000000
--- a/tests/cts/net/src/android/net/wifi/rtt/OWNERS
+++ /dev/null
@@ -1,2 +0,0 @@
-etancohen@google.com
-satk@google.com
\ No newline at end of file
diff --git a/tests/cts/net/src/android/net/wifi/rtt/cts/TestBase.java b/tests/cts/net/src/android/net/wifi/rtt/cts/TestBase.java
index 57ea2a5da8..07d5718044 100644
--- a/tests/cts/net/src/android/net/wifi/rtt/cts/TestBase.java
+++ b/tests/cts/net/src/android/net/wifi/rtt/cts/TestBase.java
@@ -32,6 +32,8 @@ import android.os.HandlerExecutor;
import android.os.HandlerThread;
import android.test.AndroidTestCase;
+import com.android.compatibility.common.util.SystemUtil;
+
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executor;
@@ -93,7 +95,7 @@ public class TestBase extends AndroidTestCase {
mWifiLock = mWifiManager.createWifiLock(TAG);
mWifiLock.acquire();
if (!mWifiManager.isWifiEnabled()) {
- mWifiManager.setWifiEnabled(true);
+ SystemUtil.runShellCommand("svc wifi enable");
}
IntentFilter intentFilter = new IntentFilter();
diff --git a/tests/cts/net/src/android/net/wifi/rtt/cts/WifiRttTest.java b/tests/cts/net/src/android/net/wifi/rtt/cts/WifiRttTest.java
index adb4ce8b66..f71cadba7e 100644
--- a/tests/cts/net/src/android/net/wifi/rtt/cts/WifiRttTest.java
+++ b/tests/cts/net/src/android/net/wifi/rtt/cts/WifiRttTest.java
@@ -64,7 +64,10 @@ public class WifiRttTest extends TestBase {
// Scan for IEEE 802.11mc supporting APs
ScanResult testAp = scanForTestAp(NUM_SCANS_SEARCHING_FOR_IEEE80211MC_AP);
- assertTrue("Cannot find test AP", testAp != null);
+ assertTrue(
+ "Cannot find any test APs which support RTT / IEEE 802.11mc - please verify that "
+ + "your test setup includes them!",
+ testAp != null);
// Perform RTT operations
RangingRequest request = new RangingRequest.Builder().addAccessPoint(testAp).build();