Merge "Added test for required packages whitelisted for Data Saver Mode." into nyc-dev
am: 16ae24badd * commit '16ae24badd79bf100b26dc4e6dfb3ed649a0c3ad': Added test for required packages whitelisted for Data Saver Mode. Change-Id: I1916d82a0fcc883679e200f79594381d29afd6b2
This commit is contained in:
@@ -377,18 +377,24 @@ abstract class AbstractRestrictBackgroundNetworkTestCase extends Instrumentation
|
||||
private void assertRestrictBackground(String list, int uid, boolean expected) throws Exception {
|
||||
final int maxTries = 5;
|
||||
boolean actual = false;
|
||||
final String expectedUid = Integer.toString(uid);
|
||||
String uids = "";
|
||||
for (int i = 1; i <= maxTries; i++) {
|
||||
final String output =
|
||||
executeShellCommand("cmd netpolicy list " + list);
|
||||
actual = output.contains(Integer.toString(uid));
|
||||
if (expected == actual) {
|
||||
return;
|
||||
uids = output.split(":")[1];
|
||||
for (String candidate : uids.split(" ")) {
|
||||
actual = candidate.trim().equals(expectedUid);
|
||||
if (expected == actual) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
Log.v(TAG, list + " check for uid " + uid + " doesn't match yet (expected "
|
||||
+ expected + ", got " + actual + "); sleeping 1s before polling again");
|
||||
Thread.sleep(SECOND_IN_MS);
|
||||
}
|
||||
fail(list + " check for uid " + uid + " failed: expected " + expected + ", got " + actual);
|
||||
fail(list + " check for uid " + uid + " failed: expected " + expected + ", got " + actual
|
||||
+ ". Full list: " + uids);
|
||||
}
|
||||
|
||||
protected void assertPowerSaveModeWhitelist(String packageName, boolean expected)
|
||||
|
||||
@@ -31,6 +31,10 @@ import static android.net.ConnectivityManager.RESTRICT_BACKGROUND_STATUS_WHITELI
|
||||
*/
|
||||
public class DataSaverModeTest extends AbstractRestrictBackgroundNetworkTestCase {
|
||||
|
||||
private static final String[] REQUIRED_WHITELISTED_PACKAGES = {
|
||||
"com.android.providers.downloads"
|
||||
};
|
||||
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
@@ -108,4 +112,24 @@ public class DataSaverModeTest extends AbstractRestrictBackgroundNetworkTestCase
|
||||
assertRestrictBackgroundChangedReceived(5);
|
||||
assertRestrictBackgroundStatus(RESTRICT_BACKGROUND_STATUS_DISABLED);
|
||||
}
|
||||
|
||||
public void testGetRestrictBackgroundStatus_requiredWhitelistedPackages() throws Exception {
|
||||
final StringBuilder error = new StringBuilder();
|
||||
for (String packageName : REQUIRED_WHITELISTED_PACKAGES) {
|
||||
int uid = -1;
|
||||
try {
|
||||
uid = getUid(packageName);
|
||||
assertRestrictBackgroundWhitelist(uid, true);
|
||||
} catch (Throwable t) {
|
||||
error.append("\nFailed for '").append(packageName).append("'");
|
||||
if (uid > 0) {
|
||||
error.append(" (uid ").append(uid).append(")");
|
||||
}
|
||||
error.append(": ").append(t).append("\n");
|
||||
}
|
||||
}
|
||||
if (error.length() > 0) {
|
||||
fail(error.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,6 +73,11 @@ public class HostsideRestrictBackgroundNetworkTests extends HostsideNetworkTestC
|
||||
assertRestrictBackgroundWhitelist(newUid, false);
|
||||
}
|
||||
|
||||
public void testDataSaverMode_requiredWhitelistedPackages() throws Exception {
|
||||
runDeviceTests(TEST_PKG, TEST_PKG + ".DataSaverModeTest",
|
||||
"testGetRestrictBackgroundStatus_requiredWhitelistedPackages");
|
||||
}
|
||||
|
||||
public void testBatterySaverMode_disabled() throws Exception {
|
||||
runDeviceTests(TEST_PKG, TEST_PKG + ".BatterySaverModeTest",
|
||||
"testBackgroundNetworkAccess_disabled");
|
||||
|
||||
Reference in New Issue
Block a user