Skip battery saver related tests on unsupported devices.
Bug: 133761301 Test: atest com.android.cts.net.HostsideRestrictBackgroundNetworkTests Change-Id: Ifec84425febf38d732367fae6b43fa80c427c79f
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -34,6 +34,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;
|
||||
@@ -43,12 +44,15 @@ import android.os.BatteryManager;
|
||||
import android.os.Binder;
|
||||
import android.os.Bundle;
|
||||
import android.os.SystemClock;
|
||||
import android.os.SystemProperties;
|
||||
import android.provider.Settings;
|
||||
import android.service.notification.NotificationListenerService;
|
||||
import android.test.InstrumentationTestCase;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.compatibility.common.util.BatteryUtils;
|
||||
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@@ -311,6 +315,10 @@ abstract class AbstractRestrictBackgroundNetworkTestCase extends Instrumentation
|
||||
return mSupported;
|
||||
}
|
||||
|
||||
protected boolean isBatterySaverSupported() {
|
||||
return BatteryUtils.isBatterySaverSupported();
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that an app always have access while on foreground or running a foreground service.
|
||||
*
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -361,6 +381,11 @@ public class MixedModesTest extends AbstractRestrictBackgroundNetworkTestCase {
|
||||
}
|
||||
|
||||
public void testAppIdleAndBatterySaver_tempPowerSaveAndAppIdleWhitelists() throws Exception {
|
||||
if (!isBatterySaverSupported()) {
|
||||
Log.i(TAG, "Skipping " + getClass() + "." + getName()
|
||||
+ "() because device does not support Battery saver mode");
|
||||
return;
|
||||
}
|
||||
if (!isSupported()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user