[automerger skipped] DO NOT MERGE - Merge pie-platform-release (PPRL.181205.001) into master am: 61b64108d7 -s ours am: f032484732 -s ours
am: ba9ecd40fd -s ours
Change-Id: I7812eba5a69ea9a01cf7d701b410524f0b7f1101
diff --git a/tests/cts/hostside/app/src/com/android/cts/net/hostside/AbstractAppIdleTestCase.java b/tests/cts/hostside/app/src/com/android/cts/net/hostside/AbstractAppIdleTestCase.java
index 0e141c0..7bf7bd4 100644
--- a/tests/cts/hostside/app/src/com/android/cts/net/hostside/AbstractAppIdleTestCase.java
+++ b/tests/cts/hostside/app/src/com/android/cts/net/hostside/AbstractAppIdleTestCase.java
@@ -175,6 +175,25 @@
assertBackgroundNetworkAccess(true);
}
+ public void testAppIdleNetworkAccess_idleWhitelisted() throws Exception {
+ if (!isSupported()) return;
+
+ setAppIdle(true);
+ assertAppIdle(true);
+ assertBackgroundNetworkAccess(false);
+
+ addAppIdleWhitelist(mUid);
+ assertBackgroundNetworkAccess(true);
+
+ removeAppIdleWhitelist(mUid);
+ assertBackgroundNetworkAccess(false);
+
+ // Make sure whitelisting a random app doesn't affect the tested app.
+ addAppIdleWhitelist(mUid + 1);
+ assertBackgroundNetworkAccess(false);
+ removeAppIdleWhitelist(mUid + 1);
+ }
+
public void testAppIdle_toast() throws Exception {
if (!isSupported()) return;
diff --git a/tests/cts/hostside/app/src/com/android/cts/net/hostside/AbstractRestrictBackgroundNetworkTestCase.java b/tests/cts/hostside/app/src/com/android/cts/net/hostside/AbstractRestrictBackgroundNetworkTestCase.java
index 5232372..ec5a877 100644
--- a/tests/cts/hostside/app/src/com/android/cts/net/hostside/AbstractRestrictBackgroundNetworkTestCase.java
+++ b/tests/cts/hostside/app/src/com/android/cts/net/hostside/AbstractRestrictBackgroundNetworkTestCase.java
@@ -26,10 +26,6 @@
import static com.android.compatibility.common.util.SystemUtil.runShellCommand;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.LinkedBlockingQueue;
-import java.util.concurrent.TimeUnit;
-
import android.app.ActivityManager;
import android.app.Instrumentation;
import android.app.NotificationManager;
@@ -53,6 +49,10 @@
import android.text.TextUtils;
import android.util.Log;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.TimeUnit;
+
/**
* Superclass for tests related to background network restrictions.
*/
@@ -744,6 +744,20 @@
assertRestrictBackground("restrict-background-blacklist", uid, expected);
}
+ protected void addAppIdleWhitelist(int uid) throws Exception {
+ executeShellCommand("cmd netpolicy add app-idle-whitelist " + uid);
+ assertAppIdleWhitelist(uid, true);
+ }
+
+ protected void removeAppIdleWhitelist(int uid) throws Exception {
+ executeShellCommand("cmd netpolicy remove app-idle-whitelist " + uid);
+ assertAppIdleWhitelist(uid, false);
+ }
+
+ protected void assertAppIdleWhitelist(int uid, boolean expected) throws Exception {
+ assertRestrictBackground("app-idle-whitelist", uid, expected);
+ }
+
private void assertRestrictBackground(String list, int uid, boolean expected) throws Exception {
final int maxTries = 5;
boolean actual = false;
diff --git a/tests/cts/hostside/app/src/com/android/cts/net/hostside/MixedModesTest.java b/tests/cts/hostside/app/src/com/android/cts/net/hostside/MixedModesTest.java
index 87f9d77..74875cd 100644
--- a/tests/cts/hostside/app/src/com/android/cts/net/hostside/MixedModesTest.java
+++ b/tests/cts/hostside/app/src/com/android/cts/net/hostside/MixedModesTest.java
@@ -306,4 +306,84 @@
setBatterySaverMode(false);
}
}
+
+ /**
+ * Tests that the app idle whitelist works as expected when doze and appIdle mode are enabled.
+ */
+ public void testDozeAndAppIdle_appIdleWhitelist() throws Exception {
+ if (!isSupported()) {
+ return;
+ }
+
+ setDozeMode(true);
+ setAppIdle(true);
+
+ try {
+ assertBackgroundNetworkAccess(false);
+
+ // UID still shouldn't have access because of Doze.
+ addAppIdleWhitelist(mUid);
+ assertBackgroundNetworkAccess(false);
+
+ removeAppIdleWhitelist(mUid);
+ assertBackgroundNetworkAccess(false);
+ } finally {
+ setAppIdle(false);
+ setDozeMode(false);
+ }
+ }
+
+ public void testAppIdleAndDoze_tempPowerSaveAndAppIdleWhitelists() throws Exception {
+ if (!isSupported()) {
+ return;
+ }
+
+ setDozeMode(true);
+ setAppIdle(true);
+
+ try {
+ assertBackgroundNetworkAccess(false);
+
+ addAppIdleWhitelist(mUid);
+ assertBackgroundNetworkAccess(false);
+
+ addTempPowerSaveModeWhitelist(TEST_APP2_PKG, TEMP_POWERSAVE_WHITELIST_DURATION_MS);
+ assertBackgroundNetworkAccess(true);
+
+ // Wait until the whitelist duration is expired.
+ SystemClock.sleep(TEMP_POWERSAVE_WHITELIST_DURATION_MS);
+ assertBackgroundNetworkAccess(false);
+ } finally {
+ setAppIdle(false);
+ setDozeMode(false);
+ removeAppIdleWhitelist(mUid);
+ }
+ }
+
+ public void testAppIdleAndBatterySaver_tempPowerSaveAndAppIdleWhitelists() throws Exception {
+ if (!isSupported()) {
+ return;
+ }
+
+ setBatterySaverMode(true);
+ setAppIdle(true);
+
+ try {
+ assertBackgroundNetworkAccess(false);
+
+ addAppIdleWhitelist(mUid);
+ assertBackgroundNetworkAccess(false);
+
+ addTempPowerSaveModeWhitelist(TEST_APP2_PKG, TEMP_POWERSAVE_WHITELIST_DURATION_MS);
+ assertBackgroundNetworkAccess(true);
+
+ // Wait until the whitelist duration is expired.
+ SystemClock.sleep(TEMP_POWERSAVE_WHITELIST_DURATION_MS);
+ assertBackgroundNetworkAccess(false);
+ } finally {
+ setAppIdle(false);
+ setBatterySaverMode(false);
+ removeAppIdleWhitelist(mUid);
+ }
+ }
}
diff --git a/tests/cts/hostside/src/com/android/cts/net/HostsideRestrictBackgroundNetworkTests.java b/tests/cts/hostside/src/com/android/cts/net/HostsideRestrictBackgroundNetworkTests.java
index fe9d36c..5f5ea43 100644
--- a/tests/cts/hostside/src/com/android/cts/net/HostsideRestrictBackgroundNetworkTests.java
+++ b/tests/cts/hostside/src/com/android/cts/net/HostsideRestrictBackgroundNetworkTests.java
@@ -156,6 +156,11 @@
"testBackgroundNetworkAccess_enabled");
}
+ public void testAppIdleMetered_idleWhitelisted() throws Exception {
+ runDeviceTests(TEST_PKG, TEST_PKG + ".AppIdleMeteredTest",
+ "testAppIdleNetworkAccess_idleWhitelisted");
+ }
+
// TODO: currently power-save mode and idle uses the same whitelist, so this test would be
// redundant (as it would be testing the same as testBatterySaverMode_reinstall())
// public void testAppIdle_reinstall() throws Exception {
@@ -181,6 +186,11 @@
"testBackgroundNetworkAccess_enabled");
}
+ public void testAppIdleNonMetered_idleWhitelisted() throws Exception {
+ runDeviceTests(TEST_PKG, TEST_PKG + ".AppIdleNonMeteredTest",
+ "testAppIdleNetworkAccess_idleWhitelisted");
+ }
+
public void testAppIdleNonMetered_whenCharging() throws Exception {
runDeviceTests(TEST_PKG, TEST_PKG + ".AppIdleNonMeteredTest",
"testAppIdleNetworkAccess_whenCharging");
@@ -281,6 +291,21 @@
"testAppIdleAndBatterySaver_tempPowerSaveWhitelists");
}
+ public void testDozeAndAppIdle_appIdleWhitelist() throws Exception {
+ runDeviceTests(TEST_PKG, TEST_PKG + ".MixedModesTest",
+ "testDozeAndAppIdle_appIdleWhitelist");
+ }
+
+ public void testAppIdleAndDoze_tempPowerSaveAndAppIdleWhitelists() throws Exception {
+ runDeviceTests(TEST_PKG, TEST_PKG + ".MixedModesTest",
+ "testAppIdleAndDoze_tempPowerSaveAndAppIdleWhitelists");
+ }
+
+ public void testAppIdleAndBatterySaver_tempPowerSaveAndAppIdleWhitelists() throws Exception {
+ runDeviceTests(TEST_PKG, TEST_PKG + ".MixedModesTest",
+ "testAppIdleAndBatterySaver_tempPowerSaveAndAppIdleWhitelists");
+ }
+
/*******************
* Helper methods. *
*******************/
diff --git a/tests/cts/net/src/android/net/wifi/aware/OWNERS b/tests/cts/net/src/android/net/wifi/aware/OWNERS
index 4afc47f..cf116f8 100644
--- a/tests/cts/net/src/android/net/wifi/aware/OWNERS
+++ b/tests/cts/net/src/android/net/wifi/aware/OWNERS
@@ -1,2 +1 @@
etancohen@google.com
-satk@google.com
\ No newline at end of file
diff --git a/tests/cts/net/src/android/net/wifi/cts/WifiManagerTest.java b/tests/cts/net/src/android/net/wifi/cts/WifiManagerTest.java
index af91fbf..deaa644 100644
--- a/tests/cts/net/src/android/net/wifi/cts/WifiManagerTest.java
+++ b/tests/cts/net/src/android/net/wifi/cts/WifiManagerTest.java
@@ -21,7 +21,10 @@
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
+import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
+import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.wifi.ScanResult;
import android.net.wifi.WifiConfiguration;
@@ -32,11 +35,17 @@
import android.net.wifi.hotspot2.PasspointConfiguration;
import android.net.wifi.hotspot2.pps.Credential;
import android.net.wifi.hotspot2.pps.HomeSp;
+import android.os.Process;
import android.os.SystemClock;
import android.provider.Settings;
+import android.support.test.InstrumentationRegistry;
+import android.support.test.uiautomator.UiDevice;
import android.test.AndroidTestCase;
+import android.text.TextUtils;
+import android.util.ArraySet;
import android.util.Log;
+import com.android.compatibility.common.util.SystemUtil;
import com.android.compatibility.common.util.WifiConfigCreator;
import java.net.HttpURLConnection;
@@ -45,6 +54,7 @@
import java.security.cert.X509Certificate;
import java.util.HashSet;
import java.util.List;
+import java.util.Objects;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
@@ -60,6 +70,7 @@
private List<ScanResult> mScanResults = null;
private NetworkInfo mNetworkInfo;
private Object mLOHSLock = new Object();
+ private UiDevice mUiDevice;
// Please refer to WifiManager
private static final int MIN_RSSI = -100;
@@ -74,9 +85,6 @@
private static final String TAG = "WifiManagerTest";
private static final String SSID1 = "\"WifiManagerTest\"";
- private static final String SSID2 = "\"WifiManagerTestModified\"";
- private static final String PROXY_TEST_SSID = "SomeProxyAp";
- private static final String ADD_NETWORK_EXCEPTION_SUBSTR = "addNetwork";
// A full single scan duration is about 6-7 seconds if country code is set
// to US. If country code is set to world mode (00), we would expect a scan
// duration of roughly 8 seconds. So we set scan timeout as 9 seconds here.
@@ -84,11 +92,14 @@
private static final int TIMEOUT_MSEC = 6000;
private static final int WAIT_MSEC = 60;
private static final int DURATION = 10000;
+ private static final int DURATION_SCREEN_TOGGLE = 2000;
private static final int WIFI_SCAN_TEST_INTERVAL_MILLIS = 60 * 1000;
private static final int WIFI_SCAN_TEST_CACHE_DELAY_MILLIS = 3 * 60 * 1000;
private static final int WIFI_SCAN_TEST_ITERATIONS = 5;
private static final String TEST_PAC_URL = "http://www.example.com/proxy.pac";
+ private static final String MANAGED_PROVISIONING_PACKAGE_NAME
+ = "com.android.managedprovisioning";
private IntentFilter mIntentFilter;
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
@@ -156,6 +167,8 @@
mWifiLock.acquire();
if (!mWifiManager.isWifiEnabled())
setWifiEnabled(true);
+ mUiDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
+ turnScreenOnNoDelay();
Thread.sleep(DURATION);
assertTrue(mWifiManager.isWifiEnabled());
synchronized (mMySync) {
@@ -186,8 +199,8 @@
} else {
mMySync.expectedState = (enable ? STATE_WIFI_ENABLED : STATE_WIFI_DISABLED);
}
- // now trigger the change
- assertTrue(mWifiManager.setWifiEnabled(enable));
+ // now trigger the change using shell commands.
+ SystemUtil.runShellCommand("svc wifi " + (enable ? "enable" : "disable"));
waitForExpectedWifiState(enable);
}
}
@@ -262,20 +275,13 @@
}
/**
- * test point of wifiManager actions:
- * 1.reconnect
- * 2.reassociate
- * 3.disconnect
- * 4.createWifiLock
+ * Test creation of WifiManager Lock.
*/
- public void testWifiManagerActions() throws Exception {
+ public void testWifiManagerLock() throws Exception {
if (!WifiFeature.isWifiSupported(getContext())) {
// skip the test if WiFi is not supported
return;
}
- assertTrue(mWifiManager.reconnect());
- assertTrue(mWifiManager.reassociate());
- assertTrue(mWifiManager.disconnect());
final String TAG = "Test";
assertNotNull(mWifiManager.createWifiLock(TAG));
assertNotNull(mWifiManager.createWifiLock(WifiManager.WIFI_MODE_FULL, TAG));
@@ -396,123 +402,8 @@
return getContext().getPackageManager().hasSystemFeature(PackageManager.FEATURE_LOCATION);
}
- /**
- * test point of wifiManager NetWork:
- * 1.add NetWork
- * 2.update NetWork
- * 3.remove NetWork
- * 4.enable NetWork
- * 5.disable NetWork
- * 6.configured Networks
- * 7.save configure;
- */
- public void testWifiManagerNetWork() throws Exception {
- if (!WifiFeature.isWifiSupported(getContext())) {
- // skip the test if WiFi is not supported
- return;
- }
-
- // store the list of enabled networks, so they can be re-enabled after test completes
- Set<String> enabledSsids = getEnabledNetworks(mWifiManager.getConfiguredNetworks());
- try {
- WifiConfiguration wifiConfiguration;
- // add a WifiConfig
- final int notExist = -1;
- List<WifiConfiguration> wifiConfiguredNetworks = mWifiManager.getConfiguredNetworks();
- int pos = findConfiguredNetworks(SSID1, wifiConfiguredNetworks);
- if (notExist != pos) {
- wifiConfiguration = wifiConfiguredNetworks.get(pos);
- mWifiManager.removeNetwork(wifiConfiguration.networkId);
- }
- pos = findConfiguredNetworks(SSID1, wifiConfiguredNetworks);
- assertEquals(notExist, pos);
- final int size = wifiConfiguredNetworks.size();
-
- wifiConfiguration = new WifiConfiguration();
- wifiConfiguration.SSID = SSID1;
- wifiConfiguration.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
- int netId = mWifiManager.addNetwork(wifiConfiguration);
- assertTrue(existSSID(SSID1));
-
- wifiConfiguredNetworks = mWifiManager.getConfiguredNetworks();
- assertEquals(size + 1, wifiConfiguredNetworks.size());
- pos = findConfiguredNetworks(SSID1, wifiConfiguredNetworks);
- assertTrue(notExist != pos);
-
- // Enable & disable network
- boolean disableOthers = true;
- assertTrue(mWifiManager.enableNetwork(netId, disableOthers));
- wifiConfiguration = mWifiManager.getConfiguredNetworks().get(pos);
- assertEquals(Status.ENABLED, wifiConfiguration.status);
-
- assertTrue(mWifiManager.disableNetwork(netId));
- wifiConfiguration = mWifiManager.getConfiguredNetworks().get(pos);
- assertEquals(Status.DISABLED, wifiConfiguration.status);
-
- // Update a WifiConfig
- wifiConfiguration = wifiConfiguredNetworks.get(pos);
- wifiConfiguration.SSID = SSID2;
- netId = mWifiManager.updateNetwork(wifiConfiguration);
- assertFalse(existSSID(SSID1));
- assertTrue(existSSID(SSID2));
-
- // Remove a WifiConfig
- assertTrue(mWifiManager.removeNetwork(netId));
- assertFalse(mWifiManager.removeNetwork(notExist));
- assertFalse(existSSID(SSID1));
- assertFalse(existSSID(SSID2));
-
- assertTrue(mWifiManager.saveConfiguration());
- } finally {
- reEnableNetworks(enabledSsids, mWifiManager.getConfiguredNetworks());
- mWifiManager.saveConfiguration();
- }
- }
-
- /**
- * Verifies that addNetwork() fails for WifiConfigurations containing a non-null http proxy when
- * the caller doesn't have OVERRIDE_WIFI_CONFIG permission, DeviceOwner or ProfileOwner device
- * management policies
- */
- public void testSetHttpProxy_PermissionFail() throws Exception {
- if (!WifiFeature.isWifiSupported(getContext())) {
- // skip the test if WiFi is not supported
- return;
- }
- WifiConfigCreator configCreator = new WifiConfigCreator(getContext());
- boolean exceptionThrown = false;
- try {
- configCreator.addHttpProxyNetworkVerifyAndRemove(
- PROXY_TEST_SSID, TEST_PAC_URL);
- } catch (IllegalStateException e) {
- // addHttpProxyNetworkVerifyAndRemove throws three IllegalStateException,
- // expect it to throw for the addNetwork operation
- if (e.getMessage().contains(ADD_NETWORK_EXCEPTION_SUBSTR)) {
- exceptionThrown = true;
- }
- }
- assertTrue(exceptionThrown);
- }
-
- private Set<String> getEnabledNetworks(List<WifiConfiguration> configuredNetworks) {
- Set<String> ssids = new HashSet<String>();
- for (WifiConfiguration wifiConfig : configuredNetworks) {
- if (Status.ENABLED == wifiConfig.status || Status.CURRENT == wifiConfig.status) {
- ssids.add(wifiConfig.SSID);
- Log.i(TAG, String.format("remembering enabled network %s", wifiConfig.SSID));
- }
- }
- return ssids;
- }
-
- private void reEnableNetworks(Set<String> enabledSsids,
- List<WifiConfiguration> configuredNetworks) {
- for (WifiConfiguration wifiConfig : configuredNetworks) {
- if (enabledSsids.contains(wifiConfig.SSID)) {
- mWifiManager.enableNetwork(wifiConfig.networkId, false);
- Log.i(TAG, String.format("re-enabling network %s", wifiConfig.SSID));
- }
- }
+ private boolean hasAutomotiveFeature() {
+ return getContext().getPackageManager().hasSystemFeature(PackageManager.FEATURE_AUTOMOTIVE);
}
public void testSignal() {
@@ -835,6 +726,11 @@
// 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);
}
@@ -881,37 +777,37 @@
}
/**
- * 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());
}
/**
@@ -951,4 +847,238 @@
stopLocalOnlyHotspot(callback, wifiEnabled);
}
+
+ /**
+ * Verify that the {@link android.Manifest.permission#NETWORK_STACK} permission is never held by
+ * any package.
+ * <p>
+ * No apps should <em>ever</em> 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<PackageInfo> 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.
+ * <p>
+ * Only Settings, SysUi and shell apps should <em>ever</em> 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<String> allowedPackages = new ArraySet();
+ final ArraySet<Integer> allowedUIDs = new ArraySet();
+ // explicitly add allowed UIDs
+ allowedUIDs.add(Process.SYSTEM_UID);
+ allowedUIDs.add(Process.SHELL_UID);
+ allowedUIDs.add(Process.PHONE_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
+ String validPkg = "";
+ final List<PackageInfo> sysuiPackage = pm.getPackagesHoldingPermissions(new String[] {
+ android.Manifest.permission.BIND_QUICK_SETTINGS_TILE
+ }, PackageManager.MATCH_UNINSTALLED_PACKAGES);
+
+ if (sysuiPackage.size() > 1) {
+ fail("The BIND_QUICK_SETTINGS_TILE permission must only be held by one package");
+ }
+
+ if (sysuiPackage.size() == 1) {
+ validPkg = sysuiPackage.get(0).packageName;
+ allowedPackages.add(validPkg);
+ }
+
+ // 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<PackageInfo> holding = pm.getPackagesHoldingPermissions(new String[] {
+ android.Manifest.permission.NETWORK_SETTINGS
+ }, PackageManager.MATCH_UNINSTALLED_PACKAGES);
+ for (PackageInfo pi : holding) {
+ String packageName = pi.packageName;
+ if (allowedPackages.contains(packageName)) {
+ // this is an explicitly allowed package
+ } else {
+ // now check if the packages are from allowed UIDs
+ boolean allowed = false;
+ try {
+ if (allowedUIDs.contains(pm.getPackageUid(packageName, 0))) {
+ allowed = true;
+ Log.d(TAG, packageName + " is on an allowed UID");
+ }
+ } catch (PackageManager.NameNotFoundException e) { }
+ if (!allowed) {
+ fail("The NETWORK_SETTINGS permission must not be held by "
+ + packageName + " 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.
+ * <p>
+ * Only the SetupWizard app should <em>ever</em> 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 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) {
+ validPkg = ri.activityInfo.packageName;
+ }
+
+ final List<PackageInfo> holding = pm.getPackagesHoldingPermissions(new String[] {
+ android.Manifest.permission.NETWORK_SETUP_WIZARD
+ }, PackageManager.MATCH_UNINSTALLED_PACKAGES);
+ for (PackageInfo pi : holding) {
+ if (!Objects.equals(pi.packageName, validPkg)) {
+ 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.
+ * <p>
+ * Only the ManagedProvisioning app should <em>ever</em> 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<PackageInfo> 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 +"]");
+ }
+ }
+ }
+
+ 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();
+ }
+
+ private void assertWifiScanningIsOn() {
+ if(!mWifiManager.isScanAlwaysAvailable()) {
+ fail("Wi-Fi scanning should be on.");
+ }
+ }
}
diff --git a/tests/cts/net/src/android/net/wifi/rtt/OWNERS b/tests/cts/net/src/android/net/wifi/rtt/OWNERS
index 4afc47f..cf116f8 100644
--- a/tests/cts/net/src/android/net/wifi/rtt/OWNERS
+++ b/tests/cts/net/src/android/net/wifi/rtt/OWNERS
@@ -1,2 +1 @@
etancohen@google.com
-satk@google.com
\ No newline at end of file
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 74a0c3d..20791c0 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
@@ -16,11 +16,9 @@
package android.net.wifi.rtt.cts;
-import android.content.IntentFilter;
import android.net.wifi.ScanResult;
import android.net.wifi.rtt.RangingRequest;
import android.net.wifi.rtt.RangingResult;
-import android.net.wifi.rtt.WifiRttManager;
import com.android.compatibility.common.util.DeviceReportLog;
import com.android.compatibility.common.util.ResultType;
@@ -64,7 +62,10 @@
// 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();