From 9afd779325c7ad64a09da8245e6f735cdcec164d Mon Sep 17 00:00:00 2001 From: Lorenzo Colitti Date: Thu, 25 Feb 2021 19:12:26 +0900 Subject: [PATCH] Revert "Fix DeviceConfig resetting." This change went into internal after R branched, and did not go to AOSP. Revert it in mainline-prod in order to ensure that CtsHostsideNetworkTests builds. These tests are developed in internal, not AOSP, so do not need to automerge to mainline-prod. Bug: 167645754 Test: treehugger Ignore-AOSP-First: needed to sync mainline-prod with AOSP Change-Id: Ieb1f0ce2a69180bbe89f810ddb3b48188ae3530e Merged-In: Ib0ac49609e444a53a6fee4575f5078e15f364eef --- ...tractRestrictBackgroundNetworkTestCase.java | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) 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 e2dc1a1143..b5e763d1eb 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 @@ -50,10 +50,11 @@ 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.DeviceConfigStateHelper; +import com.android.compatibility.common.util.SystemUtil; import org.junit.Rule; import org.junit.rules.RuleChain; @@ -130,20 +131,18 @@ public abstract class AbstractRestrictBackgroundNetworkTestCase { protected int mUid; private int mMyUid; private MyServiceClient mServiceClient; - private DeviceConfigStateHelper mDeviceIdleDeviceConfigStateHelper; @Rule public final RuleChain mRuleChain = RuleChain.outerRule(new RequiredPropertiesRule()) .around(new MeterednessConfigurationRule()); protected void setUp() throws Exception { + PROCESS_STATE_FOREGROUND_SERVICE = (Integer) ActivityManager.class .getDeclaredField("PROCESS_STATE_FOREGROUND_SERVICE").get(null); mInstrumentation = getInstrumentation(); mContext = getContext(); mCm = getConnectivityManager(); - mDeviceIdleDeviceConfigStateHelper = - new DeviceConfigStateHelper(DeviceConfig.NAMESPACE_DEVICE_IDLE); mUid = getUid(TEST_APP2_PKG); mMyUid = getUid(mContext.getPackageName()); mServiceClient = new MyServiceClient(mContext); @@ -726,12 +725,17 @@ public abstract class AbstractRestrictBackgroundNetworkTestCase { } protected void setPendingIntentAllowlistDuration(long durationMs) { - mDeviceIdleDeviceConfigStateHelper.set("notification_allowlist_duration_ms", - String.valueOf(durationMs)); + SystemUtil.runWithShellPermissionIdentity(() -> { + DeviceConfig.setProperty( + DeviceConfig.NAMESPACE_DEVICE_IDLE, "notification_allowlist_duration_ms", + String.valueOf(durationMs), /* makeDefault */ false); + }); } protected void resetDeviceIdleSettings() { - mDeviceIdleDeviceConfigStateHelper.restoreOriginalValues(); + SystemUtil.runWithShellPermissionIdentity(() -> + DeviceConfig.resetToDefaults(Settings.RESET_MODE_PACKAGE_DEFAULTS, + DeviceConfig.NAMESPACE_DEVICE_IDLE)); } protected void launchComponentAndAssertNetworkAccess(int type) throws Exception {