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 6b21dac5faab8906bfb9ec80c32c107313815296..1c997228e68da6b89423f6368c605f98fc1cd7ec 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 @@ -29,6 +29,7 @@ import static com.android.cts.net.hostside.NetworkPolicyTestUtils.isAppStandbySu import static com.android.cts.net.hostside.NetworkPolicyTestUtils.isBatterySaverSupported; import static com.android.cts.net.hostside.NetworkPolicyTestUtils.isDozeModeSupported; import static com.android.cts.net.hostside.NetworkPolicyTestUtils.restrictBackgroundValueToString; +import static com.android.cts.net.hostside.NetworkPolicyTestUtils.setRestrictBackgroundInternal; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -52,9 +53,9 @@ import android.net.NetworkRequest; import android.os.BatteryManager; import android.os.Binder; import android.os.Bundle; +import android.os.PowerManager; import android.os.RemoteCallback; import android.os.SystemClock; -import android.os.PowerManager; import android.provider.DeviceConfig; import android.service.notification.NotificationListenerService; import android.util.Log; @@ -180,6 +181,12 @@ public abstract class AbstractRestrictBackgroundNetworkTestCase { mServiceClient.bind(); mPowerManager = mContext.getSystemService(PowerManager.class); executeShellCommand("cmd netpolicy start-watching " + mUid); + // Some of the test cases assume that Data saver mode is initially disabled, which might not + // always be the case. Therefore, explicitly disable it before running the tests. + // Invoke setRestrictBackgroundInternal() directly instead of going through + // setRestrictBackground(), as some devices do not fully support the Data saver mode but + // still have certain parts of it enabled by default. + setRestrictBackgroundInternal(false); setAppIdle(false); mLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG); diff --git a/tests/cts/hostside/app/src/com/android/cts/net/hostside/NetworkPolicyTestUtils.java b/tests/cts/hostside/app/src/com/android/cts/net/hostside/NetworkPolicyTestUtils.java index deca6a224ae52754d328368e3da4cc7336738b8a..8c38b44d342572cbcf64bba2a3fef9baa98b085a 100644 --- a/tests/cts/hostside/app/src/com/android/cts/net/hostside/NetworkPolicyTestUtils.java +++ b/tests/cts/hostside/app/src/com/android/cts/net/hostside/NetworkPolicyTestUtils.java @@ -344,7 +344,7 @@ public class NetworkPolicyTestUtils { setRestrictBackgroundInternal(enabled); } - private static void setRestrictBackgroundInternal(boolean enabled) { + static void setRestrictBackgroundInternal(boolean enabled) { executeShellCommand("cmd netpolicy set restrict-background " + enabled); final String output = executeShellCommand("cmd netpolicy get restrict-background"); final String expectedSuffix = enabled ? "enabled" : "disabled";