Skip battery saver related tests on unsupported devices.

Bug: 133761301
Test: atest com.android.cts.net.HostsideRestrictBackgroundNetworkTests
Change-Id: Ifec84425febf38d732367fae6b43fa80c427c79f
Merged-In: Ifec84425febf38d732367fae6b43fa80c427c79f
This commit is contained in:
Sudheer Shanka
2019-06-05 18:27:40 -07:00
parent db6336c0b8
commit 8371c77499
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 {
if (!isBatterySaverSupported()) {
Log.i(TAG, "Skipping " + getClass() + "." + getName()
+ "() because device does not support Battery saver mode");
return;
}
if (!isSupported()) return;
// Check that app is paroled when charging

View File

@@ -16,6 +16,7 @@
package com.android.cts.net.hostside;
import android.text.TextUtils;
import android.util.Log;
/**
@@ -52,12 +53,19 @@ abstract class AbstractBatterySaverModeTestCase extends AbstractRestrictBackgrou
@Override
protected boolean isSupported() throws Exception {
boolean supported = isDozeModeEnabled();
if (!supported) {
Log.i(TAG, "Skipping " + getClass() + "." + getName()
+ "() because device does not support Doze Mode");
String unSupported = "";
if (!isDozeModeEnabled()) {
unSupported += "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.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.NetworkInfo.DetailedState;
@@ -53,6 +54,8 @@ import android.test.InstrumentationTestCase;
import android.text.TextUtils;
import android.util.Log;
import com.android.compatibility.common.util.BatteryUtils;
/**
* Superclass for tests related to background network restrictions.
*/
@@ -301,6 +304,10 @@ abstract class AbstractRestrictBackgroundNetworkTestCase extends Instrumentation
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.
*

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.
*/
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;
Log.i(TAG, "testDataAndBatterySaverModes_meteredNetwork() tests");
@@ -141,6 +146,11 @@ public class MixedModesTest extends AbstractRestrictBackgroundNetworkTestCase {
* networks.
*/
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 (!setUnmeteredNetwork()) {
@@ -206,6 +216,11 @@ public class MixedModesTest extends AbstractRestrictBackgroundNetworkTestCase {
* are enabled.
*/
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()) {
return;
}
@@ -285,6 +300,11 @@ public class MixedModesTest extends AbstractRestrictBackgroundNetworkTestCase {
}
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()) {
return;
}