From c6ce1d051ed57281923afb0c64d71ad0f8b0fe2a Mon Sep 17 00:00:00 2001 From: Chris Manton Date: Fri, 14 Oct 2016 17:30:15 -0700 Subject: [PATCH] Include Wear device idle settings Certain tests interacting with device idle must set correctly both the normal and wear device idle setting space. Bug: 32183373 Test: Run on wear device and Nexus6P run cts --skip-device-info -m CtsHostsideNetworkTests -t com.android.cts.net.HostsideRestrictBackgroundNetworkTests#testDozeModeMetered_enabledButWhitelistedOnNotificationAction run cts --skip-device-info -m CtsHostsideNetworkTests -t com.android.cts.net.HostsideRestrictBackgroundNetworkTests#testDozeModeNonMetered_enabledButWhitelistedOnNotificationAction Change-Id: I6a53d29021a7d4a257b102a4d3bd5d2cc845c16f (cherry picked from commit a84bb771d1f0c46f9505f31c2b18400f6ab9c352) --- ...ractRestrictBackgroundNetworkTestCase.java | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 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 b4d7d9db78..cbd8feaa72 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; @@ -99,6 +100,8 @@ abstract class AbstractRestrictBackgroundNetworkTestCase extends Instrumentation protected WifiManager mWfm; protected int mUid; private String mMeteredWifi; + private boolean mHasWatch; + private String mDeviceIdleConstantsSetting; @Override protected void setUp() throws Exception { @@ -110,7 +113,13 @@ abstract class AbstractRestrictBackgroundNetworkTestCase extends Instrumentation mWfm = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE); mUid = getUid(TEST_APP2_PKG); final int myUid = getUid(mContext.getPackageName()); - + 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)); @@ -726,14 +735,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 {