Fix a regression in how required properties are collected.

+ Enable app standby mode before running the tests.

Fixes: 147459100
Fixes: 117169751
Test: atest hostsidetests/net/src/com/android/cts/net/HostsideRestrictBackgroundNetworkTests.java
Test: cts-tradefed run singleCommand cts-on-gsi --skip-device-info \
      --skip-preconditions -m CtsHostsideNetworkTests \
      -t com.android.cts.net.HostsideRestrictBackgroundNetworkTests

Change-Id: I782f8a06922622d28f9a9d5c9f2afa2b12f8aa80
Merged-In: I782f8a06922622d28f9a9d5c9f2afa2b12f8aa80
This commit is contained in:
Sudheer Shanka
2020-02-05 17:54:01 -08:00
parent 39cc315273
commit a6a1ad183e
3 changed files with 64 additions and 4 deletions

View File

@@ -21,6 +21,7 @@
<option name="config-descriptor:metadata" key="parameter" value="secondary_user" />
<target_preparer class="com.android.cts.net.NetPolicyTestsPreparer" />
<target_preparer class="com.android.cts.net.NetworkPolicyTestsPreparer" />
<target_preparer class="com.android.tradefed.targetprep.RunCommandTargetPreparer">
<option name="teardown-command" value="cmd power set-mode 0" />

View File

@@ -59,12 +59,12 @@ public class RequiredPropertiesRule extends BeforeAfterRule {
}
for (Property requiredProperty : requiredProperties.value()) {
for (Property p : Property.values()) {
if (p.getValue() == ~requiredProperty.getValue()) {
if (!allRequiredProperties.contains(p)) {
allRequiredProperties.add(requiredProperty);
}
if (p.getValue() == ~requiredProperty.getValue()
&& allRequiredProperties.contains(p)) {
continue;
}
}
allRequiredProperties.add(requiredProperty);
}
}
return allRequiredProperties;

View File

@@ -0,0 +1,59 @@
/*
* Copyright (C) 2020 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.cts.net;
import com.android.tradefed.device.DeviceNotAvailableException;
import com.android.tradefed.device.ITestDevice;
import com.android.tradefed.invoker.TestInformation;
import com.android.tradefed.log.LogUtil;
import com.android.tradefed.targetprep.ITargetPreparer;
public class NetworkPolicyTestsPreparer implements ITargetPreparer {
private ITestDevice mDevice;
private String mOriginalAppStandbyEnabled;
@Override
public void setUp(TestInformation testInformation) throws DeviceNotAvailableException {
mDevice = testInformation.getDevice();
mOriginalAppStandbyEnabled = getAppStandbyEnabled();
setAppStandbyEnabled("1");
LogUtil.CLog.d("Original app_standby_enabled: " + mOriginalAppStandbyEnabled);
}
@Override
public void tearDown(TestInformation testInformation, Throwable e)
throws DeviceNotAvailableException {
setAppStandbyEnabled(mOriginalAppStandbyEnabled);
}
private void setAppStandbyEnabled(String appStandbyEnabled) throws DeviceNotAvailableException {
if ("null".equals(appStandbyEnabled)) {
executeCmd("settings delete global app_standby_enabled");
} else {
executeCmd("settings put global app_standby_enabled " + appStandbyEnabled);
}
}
private String getAppStandbyEnabled() throws DeviceNotAvailableException {
return executeCmd("settings get global app_standby_enabled").trim();
}
private String executeCmd(String cmd) throws DeviceNotAvailableException {
final String output = mDevice.executeShellCommand(cmd).trim();
LogUtil.CLog.d("Output for '%s': %s", cmd, output);
return output;
}
}