From 6784786c0a3c1eef558259cc69624449743afa1a Mon Sep 17 00:00:00 2001 From: Felipe Leme Date: Mon, 22 Aug 2016 11:45:21 -0700 Subject: [PATCH] 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 --- ...bstractRestrictBackgroundNetworkTestCase.java | 6 ++++++ .../cts/net/hostside/DataSaverModeTest.java | 16 +++++++++++----- 2 files changed, 17 insertions(+), 5 deletions(-) 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 9245a6f3d0..6c0a3c030f 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 @@ -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 { diff --git a/tests/cts/hostside/app/src/com/android/cts/net/hostside/DataSaverModeTest.java b/tests/cts/hostside/app/src/com/android/cts/net/hostside/DataSaverModeTest.java index 881b3b4759..63a66da3a9 100644 --- a/tests/cts/hostside/app/src/com/android/cts/net/hostside/DataSaverModeTest.java +++ b/tests/cts/hostside/app/src/com/android/cts/net/hostside/DataSaverModeTest.java @@ -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 {