Check and skip certain operations if they are unsupported.
Fixes: 178334463 Test: com.android.cts.net.HostsideRestrictBackgroundNetworkTests#testMeteredNetworkAccess_expeditedJob Change-Id: Ie68e17063454e7feeffc93b20b1b8fbb276e837f Merged-In: Ie68e17063454e7feeffc93b20b1b8fbb276e837f
This commit is contained in:
@@ -25,7 +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.getWifiManager;
|
||||
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;
|
||||
|
||||
@@ -46,12 +47,10 @@ import android.content.IntentFilter;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo.DetailedState;
|
||||
import android.net.NetworkInfo.State;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.BatteryManager;
|
||||
import android.os.Binder;
|
||||
import android.os.Bundle;
|
||||
import android.os.SystemClock;
|
||||
import android.provider.Settings;
|
||||
import android.service.notification.NotificationListenerService;
|
||||
import android.util.Log;
|
||||
|
||||
@@ -628,6 +627,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();
|
||||
@@ -639,8 +641,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) {
|
||||
@@ -660,12 +663,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 );
|
||||
}
|
||||
|
||||
@@ -106,11 +106,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;
|
||||
@@ -318,6 +318,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