Check and skip certain operations if they are unsupported. am: b0f50c579b am: 7695f293a7
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1658759 Change-Id: I29d4c5a2b332f6eff426393212583fae6a8c0e11
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.getConnectivityManager;
|
||||||
import static com.android.cts.net.hostside.NetworkPolicyTestUtils.getContext;
|
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.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.isDozeModeSupported;
|
||||||
import static com.android.cts.net.hostside.NetworkPolicyTestUtils.restrictBackgroundValueToString;
|
import static com.android.cts.net.hostside.NetworkPolicyTestUtils.restrictBackgroundValueToString;
|
||||||
|
|
||||||
@@ -46,12 +47,10 @@ import android.content.IntentFilter;
|
|||||||
import android.net.ConnectivityManager;
|
import android.net.ConnectivityManager;
|
||||||
import android.net.NetworkInfo.DetailedState;
|
import android.net.NetworkInfo.DetailedState;
|
||||||
import android.net.NetworkInfo.State;
|
import android.net.NetworkInfo.State;
|
||||||
import android.net.wifi.WifiManager;
|
|
||||||
import android.os.BatteryManager;
|
import android.os.BatteryManager;
|
||||||
import android.os.Binder;
|
import android.os.Binder;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
import android.provider.Settings;
|
|
||||||
import android.service.notification.NotificationListenerService;
|
import android.service.notification.NotificationListenerService;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
@@ -628,6 +627,9 @@ public abstract class AbstractRestrictBackgroundNetworkTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void setBatterySaverMode(boolean enabled) throws Exception {
|
protected void setBatterySaverMode(boolean enabled) throws Exception {
|
||||||
|
if (!isBatterySaverSupported()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
Log.i(TAG, "Setting Battery Saver Mode to " + enabled);
|
Log.i(TAG, "Setting Battery Saver Mode to " + enabled);
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
turnBatteryOn();
|
turnBatteryOn();
|
||||||
@@ -639,8 +641,9 @@ public abstract class AbstractRestrictBackgroundNetworkTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void setDozeMode(boolean enabled) throws Exception {
|
protected void setDozeMode(boolean enabled) throws Exception {
|
||||||
// Check doze mode is supported.
|
if (!isDozeModeSupported()) {
|
||||||
assertTrue("Device does not support Doze Mode", isDozeModeSupported());
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Log.i(TAG, "Setting Doze Mode to " + enabled);
|
Log.i(TAG, "Setting Doze Mode to " + enabled);
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
@@ -660,12 +663,18 @@ public abstract class AbstractRestrictBackgroundNetworkTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void setAppIdle(boolean enabled) throws Exception {
|
protected void setAppIdle(boolean enabled) throws Exception {
|
||||||
|
if (!isAppStandbySupported()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
Log.i(TAG, "Setting app idle to " + enabled);
|
Log.i(TAG, "Setting app idle to " + enabled);
|
||||||
executeSilentShellCommand("am set-inactive " + TEST_APP2_PKG + " " + enabled );
|
executeSilentShellCommand("am set-inactive " + TEST_APP2_PKG + " " + enabled );
|
||||||
assertAppIdle(enabled);
|
assertAppIdle(enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setAppIdleNoAssert(boolean enabled) throws Exception {
|
protected void setAppIdleNoAssert(boolean enabled) throws Exception {
|
||||||
|
if (!isAppStandbySupported()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
Log.i(TAG, "Setting app idle to " + enabled);
|
Log.i(TAG, "Setting app idle to " + enabled);
|
||||||
executeSilentShellCommand("am set-inactive " + TEST_APP2_PKG + " " + enabled );
|
executeSilentShellCommand("am set-inactive " + TEST_APP2_PKG + " " + enabled );
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -106,11 +106,11 @@ public class NetworkPolicyTestUtils {
|
|||||||
if (mDataSaverSupported == null) {
|
if (mDataSaverSupported == null) {
|
||||||
assertMyRestrictBackgroundStatus(RESTRICT_BACKGROUND_STATUS_DISABLED);
|
assertMyRestrictBackgroundStatus(RESTRICT_BACKGROUND_STATUS_DISABLED);
|
||||||
try {
|
try {
|
||||||
setRestrictBackground(true);
|
setRestrictBackgroundInternal(true);
|
||||||
mDataSaverSupported = !isMyRestrictBackgroundStatus(
|
mDataSaverSupported = !isMyRestrictBackgroundStatus(
|
||||||
RESTRICT_BACKGROUND_STATUS_DISABLED);
|
RESTRICT_BACKGROUND_STATUS_DISABLED);
|
||||||
} finally {
|
} finally {
|
||||||
setRestrictBackground(false);
|
setRestrictBackgroundInternal(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return mDataSaverSupported;
|
return mDataSaverSupported;
|
||||||
@@ -318,6 +318,13 @@ public class NetworkPolicyTestUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void setRestrictBackground(boolean enabled) {
|
public static void setRestrictBackground(boolean enabled) {
|
||||||
|
if (!isDataSaverSupported()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setRestrictBackgroundInternal(enabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void setRestrictBackgroundInternal(boolean enabled) {
|
||||||
executeShellCommand("cmd netpolicy set restrict-background " + enabled);
|
executeShellCommand("cmd netpolicy set restrict-background " + enabled);
|
||||||
final String output = executeShellCommand("cmd netpolicy get restrict-background");
|
final String output = executeShellCommand("cmd netpolicy get restrict-background");
|
||||||
final String expectedSuffix = enabled ? "enabled" : "disabled";
|
final String expectedSuffix = enabled ? "enabled" : "disabled";
|
||||||
|
|||||||
Reference in New Issue
Block a user