Merge "Skip battery saver related tests on unsupported devices." into pie-cts-dev

am: e3c9363b92

Change-Id: Ib587d87add52de4d2e076876edbae7c519eb70ab
This commit is contained in:
Sudheer Shanka
2019-06-19 11:44:23 -07:00
committed by android-build-merger
4 changed files with 45 additions and 5 deletions

View File

@@ -150,6 +150,11 @@ abstract class AbstractAppIdleTestCase extends AbstractRestrictBackgroundNetwork
} }
public void testAppIdleNetworkAccess_whenCharging() throws Exception { public void testAppIdleNetworkAccess_whenCharging() throws Exception {
if (!isBatterySaverSupported()) {
Log.i(TAG, "Skipping " + getClass() + "." + getName()
+ "() because device does not support Battery saver mode");
return;
}
if (!isSupported()) return; if (!isSupported()) return;
// Check that app is paroled when charging // Check that app is paroled when charging

View File

@@ -16,6 +16,7 @@
package com.android.cts.net.hostside; package com.android.cts.net.hostside;
import android.text.TextUtils;
import android.util.Log; import android.util.Log;
/** /**
@@ -52,12 +53,19 @@ abstract class AbstractBatterySaverModeTestCase extends AbstractRestrictBackgrou
@Override @Override
protected boolean isSupported() throws Exception { protected boolean isSupported() throws Exception {
boolean supported = isDozeModeEnabled(); String unSupported = "";
if (!supported) { if (!isDozeModeEnabled()) {
Log.i(TAG, "Skipping " + getClass() + "." + getName() unSupported += "Doze mode,";
+ "() because device does not support Doze Mode");
} }
return supported; if (!isBatterySaverSupported()) {
unSupported += "Battery saver mode,";
}
if (!TextUtils.isEmpty(unSupported)) {
Log.i(TAG, "Skipping " + getClass() + "." + getName()
+ "() because device does not support " + unSupported);
return false;
}
return true;
} }
/** /**

View File

@@ -38,6 +38,7 @@ import android.content.ComponentName;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.net.ConnectivityManager; import android.net.ConnectivityManager;
import android.net.NetworkInfo; import android.net.NetworkInfo;
import android.net.NetworkInfo.DetailedState; import android.net.NetworkInfo.DetailedState;
@@ -53,6 +54,8 @@ import android.test.InstrumentationTestCase;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import com.android.compatibility.common.util.BatteryUtils;
/** /**
* Superclass for tests related to background network restrictions. * Superclass for tests related to background network restrictions.
*/ */
@@ -301,6 +304,10 @@ abstract class AbstractRestrictBackgroundNetworkTestCase extends Instrumentation
return mSupported; return mSupported;
} }
protected boolean isBatterySaverSupported() throws Exception {
return BatteryUtils.isBatterySaverSupported();
}
/** /**
* Asserts that an app always have access while on foreground or running a foreground service. * Asserts that an app always have access while on foreground or running a foreground service.
* *

View File

@@ -71,6 +71,11 @@ public class MixedModesTest extends AbstractRestrictBackgroundNetworkTestCase {
* Tests all DS ON and BS ON scenarios from network-policy-restrictions.md on metered networks. * Tests all DS ON and BS ON scenarios from network-policy-restrictions.md on metered networks.
*/ */
public void testDataAndBatterySaverModes_meteredNetwork() throws Exception { public void testDataAndBatterySaverModes_meteredNetwork() throws Exception {
if (!isBatterySaverSupported()) {
Log.i(TAG, "Skipping " + getClass() + "." + getName()
+ "() because device does not support Battery saver mode");
return;
}
if (!isSupported()) return; if (!isSupported()) return;
Log.i(TAG, "testDataAndBatterySaverModes_meteredNetwork() tests"); Log.i(TAG, "testDataAndBatterySaverModes_meteredNetwork() tests");
@@ -141,6 +146,11 @@ public class MixedModesTest extends AbstractRestrictBackgroundNetworkTestCase {
* networks. * networks.
*/ */
public void testDataAndBatterySaverModes_nonMeteredNetwork() throws Exception { public void testDataAndBatterySaverModes_nonMeteredNetwork() throws Exception {
if (!isBatterySaverSupported()) {
Log.i(TAG, "Skipping " + getClass() + "." + getName()
+ "() because device does not support Battery saver mode");
return;
}
if (!isSupported()) return; if (!isSupported()) return;
if (!setUnmeteredNetwork()) { if (!setUnmeteredNetwork()) {
@@ -206,6 +216,11 @@ public class MixedModesTest extends AbstractRestrictBackgroundNetworkTestCase {
* are enabled. * are enabled.
*/ */
public void testDozeAndBatterySaverMode_powerSaveWhitelists() throws Exception { public void testDozeAndBatterySaverMode_powerSaveWhitelists() throws Exception {
if (!isBatterySaverSupported()) {
Log.i(TAG, "Skipping " + getClass() + "." + getName()
+ "() because device does not support Battery saver mode");
return;
}
if (!isSupported()) { if (!isSupported()) {
return; return;
} }
@@ -285,6 +300,11 @@ public class MixedModesTest extends AbstractRestrictBackgroundNetworkTestCase {
} }
public void testAppIdleAndBatterySaver_tempPowerSaveWhitelists() throws Exception { public void testAppIdleAndBatterySaver_tempPowerSaveWhitelists() throws Exception {
if (!isBatterySaverSupported()) {
Log.i(TAG, "Skipping " + getClass() + "." + getName()
+ "() because device does not support Battery saver mode");
return;
}
if (!isSupported()) { if (!isSupported()) {
return; return;
} }