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 1ef9474ee2..5eefcb2ef3 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 @@ -29,6 +29,7 @@ import android.app.Instrumentation; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; +import android.content.pm.PackageManager; import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.net.NetworkInfo.DetailedState; @@ -86,6 +87,8 @@ abstract class AbstractRestrictBackgroundNetworkTestCase extends Instrumentation protected int mUid; private String mMeteredWifi; private MyServiceClient mServiceClient; + private boolean mHasWatch; + private String mDeviceIdleConstantsSetting; @Override protected void setUp() throws Exception { @@ -99,7 +102,13 @@ abstract class AbstractRestrictBackgroundNetworkTestCase extends Instrumentation final int myUid = getUid(mContext.getPackageName()); mServiceClient = new MyServiceClient(mContext); mServiceClient.bind(); - + mHasWatch = mContext.getPackageManager().hasSystemFeature( + PackageManager.FEATURE_WATCH); + if (mHasWatch) { + mDeviceIdleConstantsSetting = "device_idle_constants_watch"; + } else { + mDeviceIdleConstantsSetting = "device_idle_constants"; + } Log.i(TAG, "Apps status on " + getName() + ":\n" + "\ttest app: uid=" + myUid + ", state=" + getProcessStateByUid(myUid) + "\n" + "\tapp2: uid=" + mUid + ", state=" + getProcessStateByUid(mUid)); @@ -723,14 +732,14 @@ abstract class AbstractRestrictBackgroundNetworkTestCase extends Instrumentation } protected void setPendingIntentWhitelistDuration(int durationMs) throws Exception { - final String command = String.format( - "settings put global device_idle_constants %s=%d", - "notification_whitelist_duration", durationMs); - executeSilentShellCommand(command); + executeSilentShellCommand(String.format( + "settings put global %s %s=%d", mDeviceIdleConstantsSetting, + "notification_whitelist_duration", durationMs)); } protected void resetDeviceIdleSettings() throws Exception { - executeShellCommand("settings delete global device_idle_constants"); + executeShellCommand(String.format("settings delete global %s", + mDeviceIdleConstantsSetting)); } protected void startForegroundService() throws Exception {