Updated Data Saver blacklist assumptions.

On Android N, Data Saver's whitelist and blacklist UIDs were stored
separately, hence it would be possible for app to be present in
both (although only through adb commands - the UI only allows one
state).

Now the both lists are stored in the same data structure (UID policies),
hence they comply with the Highlander rule: There Can Be Only One.

Test: cts-tradefed run commandAndExit cts --skip-device-info --skip-system-status-check com.android.compatibility.common.tradefed.targetprep.NetworkConnectivityChecker --skip-preconditions -m CtsHostsideNetworkTests --abi armeabi-v7a -t com.android.cts.net.HostsideRestrictBackgroundNetworkTests

BUG: 28791717
Change-Id: I8649972088b439a2ef87f8630269033f116866bf
This commit is contained in:
Felipe Leme
2016-08-22 11:45:21 -07:00
parent b2f0d2e01a
commit 6784786c0a
2 changed files with 17 additions and 5 deletions

View File

@@ -541,6 +541,9 @@ abstract class AbstractRestrictBackgroundNetworkTestCase extends Instrumentation
protected void addRestrictBackgroundWhitelist(int uid) throws Exception {
executeShellCommand("cmd netpolicy add restrict-background-whitelist " + uid);
assertRestrictBackgroundWhitelist(uid, true);
// UID policies live by the Highlander rule: "There can be only one".
// Hence, if app is whitelisted, it should not be blacklisted.
assertRestrictBackgroundBlacklist(uid, false);
}
protected void removeRestrictBackgroundWhitelist(int uid) throws Exception {
@@ -555,6 +558,9 @@ abstract class AbstractRestrictBackgroundNetworkTestCase extends Instrumentation
protected void addRestrictBackgroundBlacklist(int uid) throws Exception {
executeShellCommand("cmd netpolicy add restrict-background-blacklist " + uid);
assertRestrictBackgroundBlacklist(uid, true);
// UID policies live by the Highlander rule: "There can be only one".
// Hence, if app is blacklisted, it should not be whitelisted.
assertRestrictBackgroundWhitelist(uid, false);
}
protected void removeRestrictBackgroundBlacklist(int uid) throws Exception {

View File

@@ -135,24 +135,30 @@ public class DataSaverModeTest extends AbstractRestrictBackgroundNetworkTestCase
assertsForegroundAlwaysHasNetworkAccess();
assertDataSaverStatusOnBackground(RESTRICT_BACKGROUND_STATUS_ENABLED);
// Make sure blacklist prevails over whitelist.
// UID policies live by the Highlander rule: "There can be only one".
// Hence, if app is whitelisted, it should not be blacklisted anymore.
setRestrictBackground(true);
assertRestrictBackgroundChangedReceived(2);
assertDataSaverStatusOnBackground(RESTRICT_BACKGROUND_STATUS_ENABLED);
addRestrictBackgroundWhitelist(mUid);
assertRestrictBackgroundChangedReceived(3);
assertDataSaverStatusOnBackground(RESTRICT_BACKGROUND_STATUS_ENABLED);
assertDataSaverStatusOnBackground(RESTRICT_BACKGROUND_STATUS_WHITELISTED);
// Check status after removing blacklist.
// ...re-enables first
addRestrictBackgroundBlacklist(mUid);
assertDataSaverStatusOnBackground(RESTRICT_BACKGROUND_STATUS_ENABLED);
assertsForegroundAlwaysHasNetworkAccess();
// ... remove blacklist - access's still rejected because Data Saver is on
removeRestrictBackgroundBlacklist(mUid);
assertRestrictBackgroundChangedReceived(4);
assertDataSaverStatusOnBackground(RESTRICT_BACKGROUND_STATUS_WHITELISTED);
assertDataSaverStatusOnBackground(RESTRICT_BACKGROUND_STATUS_ENABLED);
assertsForegroundAlwaysHasNetworkAccess();
// ... finally, disable Data Saver
setRestrictBackground(false);
assertRestrictBackgroundChangedReceived(5);
assertDataSaverStatusOnBackground(RESTRICT_BACKGROUND_STATUS_DISABLED);
assertsForegroundAlwaysHasNetworkAccess();
assertDataSaverStatusOnBackground(RESTRICT_BACKGROUND_STATUS_DISABLED);
}
public void testGetRestrictBackgroundStatus_requiredWhitelistedPackages() throws Exception {