diff --git a/tests/cts/hostside/app/src/com/android/cts/net/hostside/AbstractDozeModeTestCase.java b/tests/cts/hostside/app/src/com/android/cts/net/hostside/AbstractDozeModeTestCase.java index e0ce4ead39..6f32c563c1 100644 --- a/tests/cts/hostside/app/src/com/android/cts/net/hostside/AbstractDozeModeTestCase.java +++ b/tests/cts/hostside/app/src/com/android/cts/net/hostside/AbstractDozeModeTestCase.java @@ -101,7 +101,7 @@ abstract class AbstractDozeModeTestCase extends AbstractRestrictBackgroundNetwor @Test public void testBackgroundNetworkAccess_enabledButWhitelistedOnNotificationAction() throws Exception { - setPendingIntentAllowlistDuration(NETWORK_TIMEOUT_MS); + setPendingIntentWhitelistDuration(NETWORK_TIMEOUT_MS); try { registerNotificationListenerService(); setDozeMode(true); diff --git a/tests/cts/hostside/app/src/com/android/cts/net/hostside/AbstractRestrictBackgroundNetworkTestCase.java b/tests/cts/hostside/app/src/com/android/cts/net/hostside/AbstractRestrictBackgroundNetworkTestCase.java index b5e763d1eb..f423503c56 100644 --- a/tests/cts/hostside/app/src/com/android/cts/net/hostside/AbstractRestrictBackgroundNetworkTestCase.java +++ b/tests/cts/hostside/app/src/com/android/cts/net/hostside/AbstractRestrictBackgroundNetworkTestCase.java @@ -25,6 +25,7 @@ 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.isDozeModeSupported; import static com.android.cts.net.hostside.NetworkPolicyTestUtils.restrictBackgroundValueToString; @@ -45,17 +46,15 @@ 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.DeviceConfig; import android.provider.Settings; import android.service.notification.NotificationListenerService; import android.util.Log; -import com.android.compatibility.common.util.SystemUtil; - import org.junit.Rule; import org.junit.rules.RuleChain; import org.junit.runner.RunWith; @@ -131,6 +130,7 @@ public abstract class AbstractRestrictBackgroundNetworkTestCase { protected int mUid; private int mMyUid; private MyServiceClient mServiceClient; + private String mDeviceIdleConstantsSetting; @Rule public final RuleChain mRuleChain = RuleChain.outerRule(new RequiredPropertiesRule()) @@ -147,6 +147,7 @@ public abstract class AbstractRestrictBackgroundNetworkTestCase { mMyUid = getUid(mContext.getPackageName()); mServiceClient = new MyServiceClient(mContext); mServiceClient.bind(); + mDeviceIdleConstantsSetting = "device_idle_constants"; executeShellCommand("cmd netpolicy start-watching " + mUid); setAppIdle(false); @@ -724,18 +725,15 @@ public abstract class AbstractRestrictBackgroundNetworkTestCase { nm.isNotificationListenerAccessGranted(listenerComponent)); } - protected void setPendingIntentAllowlistDuration(long durationMs) { - SystemUtil.runWithShellPermissionIdentity(() -> { - DeviceConfig.setProperty( - DeviceConfig.NAMESPACE_DEVICE_IDLE, "notification_allowlist_duration_ms", - String.valueOf(durationMs), /* makeDefault */ false); - }); + protected void setPendingIntentWhitelistDuration(int durationMs) throws Exception { + executeSilentShellCommand(String.format( + "settings put global %s %s=%d", mDeviceIdleConstantsSetting, + "notification_whitelist_duration", durationMs)); } - protected void resetDeviceIdleSettings() { - SystemUtil.runWithShellPermissionIdentity(() -> - DeviceConfig.resetToDefaults(Settings.RESET_MODE_PACKAGE_DEFAULTS, - DeviceConfig.NAMESPACE_DEVICE_IDLE)); + protected void resetDeviceIdleSettings() throws Exception { + executeShellCommand(String.format("settings delete global %s", + mDeviceIdleConstantsSetting)); } protected void launchComponentAndAssertNetworkAccess(int type) throws Exception {