From 926a3cb0262c295fb10ed6cb40c594ccfaa09f04 Mon Sep 17 00:00:00 2001 From: Sudheer Shanka Date: Tue, 22 May 2018 12:17:52 -0700 Subject: [PATCH 1/2] CtsHostsideNetworkTests: Skip unsupported tests. If appStandby is not enabled, then testAppIdleAndBatterySaver_tempPowerSaveWhitelists is not supported. Fixes: 79942156 Test: cts-tradefed run singleCommand cts-dev -m CtsHostsideNetworkTests -t \ com.android.cts.net.HostsideRestrictBackgroundNetworkTests Change-Id: I2f4012ff2cf42481e089d7fc33930258e501ddbf --- .../cts/net/hostside/MixedModesTest.java | 37 +++++-------------- 1 file changed, 10 insertions(+), 27 deletions(-) diff --git a/tests/cts/hostside/app/src/com/android/cts/net/hostside/MixedModesTest.java b/tests/cts/hostside/app/src/com/android/cts/net/hostside/MixedModesTest.java index 76332bedb5..87f9d7738d 100644 --- a/tests/cts/hostside/app/src/com/android/cts/net/hostside/MixedModesTest.java +++ b/tests/cts/hostside/app/src/com/android/cts/net/hostside/MixedModesTest.java @@ -57,18 +57,22 @@ public class MixedModesTest extends AbstractRestrictBackgroundNetworkTestCase { } } + @Override + public boolean isSupported() throws Exception { + if (!isDozeModeEnabled()) { + Log.i(TAG, "Skipping " + getClass() + "." + getName() + + "() because device does not support Doze Mode"); + return false; + } + return true; + } + /** * Tests all DS ON and BS ON scenarios from network-policy-restrictions.md on metered networks. */ public void testDataAndBatterySaverModes_meteredNetwork() throws Exception { if (!isSupported()) return; - if (!isDozeModeEnabled()) { - Log.w(TAG, "testDataAndBatterySaverModes_meteredNetwork() skipped because " - + "device does not support Doze Mode"); - return; - } - Log.i(TAG, "testDataAndBatterySaverModes_meteredNetwork() tests"); if (!setMeteredNetwork()) { Log.w(TAG, "testDataAndBatterySaverModes_meteredNetwork() skipped because " @@ -139,12 +143,6 @@ public class MixedModesTest extends AbstractRestrictBackgroundNetworkTestCase { public void testDataAndBatterySaverModes_nonMeteredNetwork() throws Exception { if (!isSupported()) return; - if (!isDozeModeEnabled()) { - Log.w(TAG, "testDataAndBatterySaverModes_nonMeteredNetwork() skipped because " - + "device does not support Doze Mode"); - return; - } - if (!setUnmeteredNetwork()) { Log.w(TAG, "testDataAndBatterySaverModes_nonMeteredNetwork() skipped because network" + " is metered"); @@ -211,11 +209,6 @@ public class MixedModesTest extends AbstractRestrictBackgroundNetworkTestCase { if (!isSupported()) { return; } - if (!isDozeModeEnabled()) { - Log.i(TAG, "Skipping " + getClass() + "." + getName() - + "() because device does not support Doze Mode"); - return; - } setBatterySaverMode(true); setDozeMode(true); @@ -246,11 +239,6 @@ public class MixedModesTest extends AbstractRestrictBackgroundNetworkTestCase { if (!isSupported()) { return; } - if (!isDozeModeEnabled()) { - Log.i(TAG, "Skipping " + getClass() + "." + getName() - + "() because device does not support Doze Mode"); - return; - } setDozeMode(true); setAppIdle(true); @@ -277,11 +265,6 @@ public class MixedModesTest extends AbstractRestrictBackgroundNetworkTestCase { if (!isSupported()) { return; } - if (!isDozeModeEnabled()) { - Log.i(TAG, "Skipping " + getClass() + "." + getName() - + "() because device does not support Doze Mode"); - return; - } setDozeMode(true); setAppIdle(true); From 1b3cc387bf326218b3bd00d599bf38f828faa3f7 Mon Sep 17 00:00:00 2001 From: Sudheer Shanka Date: Tue, 22 May 2018 11:50:43 -0700 Subject: [PATCH 2/2] Update turnBatteryOff to include changing charging status too. AppStandbyController is now listening to BatteryManager.ACTION_CHARGING for starting parole state and this broadcast won't be sent immediately after plugging in the device. So, update the charging status too which is going to trigger this broadcast and parole state can be started immediately. Bug: 80109076 Test: cts-tradefed run singleCommand cts-dev -m CtsHostsideNetworkTests -t \ com.android.cts.net.HostsideRestrictBackgroundNetworkTests Change-Id: I6f19f7a509ec48e96eaea4b188262d5a9735edf1 --- .../AbstractRestrictBackgroundNetworkTestCase.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) 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 03659dc36f..d8fbc8fd5f 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 @@ -20,6 +20,10 @@ import static android.net.ConnectivityManager.ACTION_RESTRICT_BACKGROUND_CHANGED import static android.net.ConnectivityManager.RESTRICT_BACKGROUND_STATUS_DISABLED; import static android.net.ConnectivityManager.RESTRICT_BACKGROUND_STATUS_ENABLED; import static android.net.ConnectivityManager.RESTRICT_BACKGROUND_STATUS_WHITELISTED; +import static android.os.BatteryManager.BATTERY_PLUGGED_AC; +import static android.os.BatteryManager.BATTERY_PLUGGED_USB; +import static android.os.BatteryManager.BATTERY_PLUGGED_WIRELESS; + import static com.android.compatibility.common.util.SystemUtil.runShellCommand; import java.util.concurrent.CountDownLatch; @@ -81,6 +85,9 @@ abstract class AbstractRestrictBackgroundNetworkTestCase extends Instrumentation protected static final String NOTIFICATION_TYPE_ACTION_BUNDLE = "ACTION_BUNDLE"; protected static final String NOTIFICATION_TYPE_ACTION_REMOTE_INPUT = "ACTION_REMOTE_INPUT"; + // TODO: Update BatteryManager.BATTERY_PLUGGED_ANY as @TestApi + public static final int BATTERY_PLUGGED_ANY = + BATTERY_PLUGGED_AC | BATTERY_PLUGGED_USB | BATTERY_PLUGGED_WIRELESS; private static final String NETWORK_STATUS_SEPARATOR = "\\|"; private static final int SECOND_IN_MS = 1000; @@ -817,11 +824,15 @@ abstract class AbstractRestrictBackgroundNetworkTestCase extends Instrumentation protected void turnBatteryOn() throws Exception { executeSilentShellCommand("cmd battery unplug"); + executeSilentShellCommand("cmd battery set status " + + BatteryManager.BATTERY_STATUS_DISCHARGING); assertBatteryState(false); } protected void turnBatteryOff() throws Exception { - executeSilentShellCommand("cmd battery reset"); + executeSilentShellCommand("cmd battery set ac " + BATTERY_PLUGGED_ANY); + executeSilentShellCommand("cmd battery set status " + + BatteryManager.BATTERY_STATUS_CHARGING); assertBatteryState(true); }