Check and skip certain operations if they are unsupported.
Fixes: 178334463 Test: com.android.cts.net.HostsideRestrictBackgroundNetworkTests#testMeteredNetworkAccess_expeditedJob Ignore-AOSP-First: Expedited jobs are not available in AOSP yet Change-Id: Ie68e17063454e7feeffc93b20b1b8fbb276e837f
This commit is contained in:
@@ -25,6 +25,8 @@ import static com.android.cts.net.hostside.NetworkPolicyTestUtils.executeShellCo
|
||||
import static com.android.cts.net.hostside.NetworkPolicyTestUtils.getConnectivityManager;
|
||||
import static com.android.cts.net.hostside.NetworkPolicyTestUtils.getContext;
|
||||
import static com.android.cts.net.hostside.NetworkPolicyTestUtils.getInstrumentation;
|
||||
import static com.android.cts.net.hostside.NetworkPolicyTestUtils.isAppStandbySupported;
|
||||
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.runSatisfiedJob;
|
||||
@@ -653,6 +655,9 @@ public abstract class AbstractRestrictBackgroundNetworkTestCase {
|
||||
}
|
||||
|
||||
protected void setBatterySaverMode(boolean enabled) throws Exception {
|
||||
if (!isBatterySaverSupported()) {
|
||||
return;
|
||||
}
|
||||
Log.i(TAG, "Setting Battery Saver Mode to " + enabled);
|
||||
if (enabled) {
|
||||
turnBatteryOn();
|
||||
@@ -664,8 +669,9 @@ public abstract class AbstractRestrictBackgroundNetworkTestCase {
|
||||
}
|
||||
|
||||
protected void setDozeMode(boolean enabled) throws Exception {
|
||||
// Check doze mode is supported.
|
||||
assertTrue("Device does not support Doze Mode", isDozeModeSupported());
|
||||
if (!isDozeModeSupported()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Log.i(TAG, "Setting Doze Mode to " + enabled);
|
||||
if (enabled) {
|
||||
@@ -685,12 +691,18 @@ public abstract class AbstractRestrictBackgroundNetworkTestCase {
|
||||
}
|
||||
|
||||
protected void setAppIdle(boolean enabled) throws Exception {
|
||||
if (!isAppStandbySupported()) {
|
||||
return;
|
||||
}
|
||||
Log.i(TAG, "Setting app idle to " + enabled);
|
||||
executeSilentShellCommand("am set-inactive " + TEST_APP2_PKG + " " + enabled );
|
||||
assertAppIdle(enabled);
|
||||
}
|
||||
|
||||
protected void setAppIdleNoAssert(boolean enabled) throws Exception {
|
||||
if (!isAppStandbySupported()) {
|
||||
return;
|
||||
}
|
||||
Log.i(TAG, "Setting app idle to " + enabled);
|
||||
executeSilentShellCommand("am set-inactive " + TEST_APP2_PKG + " " + enabled );
|
||||
}
|
||||
|
||||
@@ -86,11 +86,11 @@ public class NetworkPolicyTestUtils {
|
||||
if (mDataSaverSupported == null) {
|
||||
assertMyRestrictBackgroundStatus(RESTRICT_BACKGROUND_STATUS_DISABLED);
|
||||
try {
|
||||
setRestrictBackground(true);
|
||||
setRestrictBackgroundInternal(true);
|
||||
mDataSaverSupported = !isMyRestrictBackgroundStatus(
|
||||
RESTRICT_BACKGROUND_STATUS_DISABLED);
|
||||
} finally {
|
||||
setRestrictBackground(false);
|
||||
setRestrictBackgroundInternal(false);
|
||||
}
|
||||
}
|
||||
return mDataSaverSupported;
|
||||
@@ -213,6 +213,13 @@ public class NetworkPolicyTestUtils {
|
||||
}
|
||||
|
||||
public static void setRestrictBackground(boolean enabled) {
|
||||
if (!isDataSaverSupported()) {
|
||||
return;
|
||||
}
|
||||
setRestrictBackgroundInternal(enabled);
|
||||
}
|
||||
|
||||
private 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";
|
||||
|
||||
Reference in New Issue
Block a user