Merge "Add tests to check connectivity during temp-powersave-whitelist changes."

This commit is contained in:
Sudheer Shanka
2017-08-11 01:36:20 +00:00
committed by Android (Google) Code Review
4 changed files with 93 additions and 0 deletions

View File

@@ -127,6 +127,19 @@ abstract class AbstractAppIdleTestCase extends AbstractRestrictBackgroundNetwork
assertBackgroundNetworkAccess(false);
}
public void testBackgroundNetworkAccess_tempWhitelisted() throws Exception {
if (!isSupported()) return;
setAppIdle(true);
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);
}
public void testBackgroundNetworkAccess_disabled() throws Exception {
if (!isSupported()) return;

View File

@@ -106,6 +106,8 @@ abstract class AbstractRestrictBackgroundNetworkTestCase extends Instrumentation
private static final String APP_NOT_FOREGROUND_ERROR = "app_not_fg";
protected static final long TEMP_POWERSAVE_WHITELIST_DURATION_MS = 5_000; // 5 sec
protected Context mContext;
protected Instrumentation mInstrumentation;
protected ConnectivityManager mCm;
@@ -676,6 +678,12 @@ abstract class AbstractRestrictBackgroundNetworkTestCase extends Instrumentation
+ ". Full list: " + uids);
}
protected void addTempPowerSaveModeWhitelist(String packageName, long duration)
throws Exception {
Log.i(TAG, "Adding pkg " + packageName + " to temp-power-save-mode whitelist");
executeShellCommand("dumpsys deviceidle tempwhitelist -d " + duration + " " + packageName);
}
protected void assertPowerSaveModeWhitelist(String packageName, boolean expected)
throws Exception {
// TODO: currently the power-save mode is behaving like idle, but once it changes, we'll

View File

@@ -15,6 +15,7 @@
*/
package com.android.cts.net.hostside;
import android.os.SystemClock;
import android.util.Log;
/**
@@ -271,4 +272,55 @@ public class MixedModesTest extends AbstractRestrictBackgroundNetworkTestCase {
setDozeMode(false);
}
}
public void testAppIdleAndDoze_tempPowerSaveWhitelists() throws Exception {
if (!isSupported()) {
return;
}
if (!isDozeModeEnabled()) {
Log.i(TAG, "Skipping " + getClass() + "." + getName()
+ "() because device does not support Doze Mode");
return;
}
setDozeMode(true);
setAppIdle(true);
try {
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);
}
}
public void testAppIdleAndBatterySaver_tempPowerSaveWhitelists() throws Exception {
if (!isSupported()) {
return;
}
setBatterySaverMode(true);
setAppIdle(true);
try {
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);
}
}
}

View File

@@ -146,6 +146,11 @@ public class HostsideRestrictBackgroundNetworkTests extends HostsideNetworkTestC
"testBackgroundNetworkAccess_whitelisted");
}
public void testAppIdleMetered_tempWhitelisted() throws Exception {
runDeviceTests(TEST_PKG, TEST_PKG + ".AppIdleMeteredTest",
"testBackgroundNetworkAccess_tempWhitelisted");
}
public void testAppIdleMetered_enabled() throws Exception {
runDeviceTests(TEST_PKG, TEST_PKG + ".AppIdleMeteredTest",
"testBackgroundNetworkAccess_enabled");
@@ -166,6 +171,11 @@ public class HostsideRestrictBackgroundNetworkTests extends HostsideNetworkTestC
"testBackgroundNetworkAccess_whitelisted");
}
public void testAppIdleNonMetered_tempWhitelisted() throws Exception {
runDeviceTests(TEST_PKG, TEST_PKG + ".AppIdleNonMeteredTest",
"testBackgroundNetworkAccess_tempWhitelisted");
}
public void testAppIdleNonMetered_enabled() throws Exception {
runDeviceTests(TEST_PKG, TEST_PKG + ".AppIdleNonMeteredTest",
"testBackgroundNetworkAccess_enabled");
@@ -261,6 +271,16 @@ public class HostsideRestrictBackgroundNetworkTests extends HostsideNetworkTestC
"testDozeAndAppIdle_powerSaveWhitelists");
}
public void testAppIdleAndDoze_tempPowerSaveWhitelists() throws Exception {
runDeviceTests(TEST_PKG, TEST_PKG + ".MixedModesTest",
"testAppIdleAndDoze_tempPowerSaveWhitelists");
}
public void testAppIdleAndBatterySaver_tempPowerSaveWhitelists() throws Exception {
runDeviceTests(TEST_PKG, TEST_PKG + ".MixedModesTest",
"testAppIdleAndBatterySaver_tempPowerSaveWhitelists");
}
/*******************
* Helper methods. *
*******************/