Merge "Change network parole while charging tests."
This commit is contained in:
@@ -20,8 +20,6 @@
|
||||
<option name="config-descriptor:metadata" key="parameter" value="not_multi_abi" />
|
||||
<option name="config-descriptor:metadata" key="parameter" value="secondary_user" />
|
||||
|
||||
<target_preparer class="com.android.cts.net.NetPolicyTestsPreparer" />
|
||||
|
||||
<target_preparer class="com.android.tradefed.targetprep.RunCommandTargetPreparer">
|
||||
<option name="teardown-command" value="cmd power set-mode 0" />
|
||||
<option name="teardown-command" value="cmd battery reset" />
|
||||
|
||||
@@ -131,11 +131,11 @@ abstract class AbstractAppIdleTestCase extends AbstractRestrictBackgroundNetwork
|
||||
@RequiredProperties({BATTERY_SAVER_MODE})
|
||||
@Test
|
||||
public void testAppIdleNetworkAccess_whenCharging() throws Exception {
|
||||
// Check that app is paroled when charging
|
||||
// Check that idle app doesn't get network when charging
|
||||
setAppIdle(true);
|
||||
assertBackgroundNetworkAccess(false);
|
||||
turnBatteryOff();
|
||||
assertBackgroundNetworkAccess(true);
|
||||
assertBackgroundNetworkAccess(false);
|
||||
turnBatteryOn();
|
||||
assertBackgroundNetworkAccess(false);
|
||||
|
||||
|
||||
@@ -164,14 +164,6 @@ public abstract class AbstractRestrictBackgroundNetworkTestCase {
|
||||
Log.i(TAG, "Apps status:\n"
|
||||
+ "\ttest app: uid=" + mMyUid + ", state=" + getProcessStateByUid(mMyUid) + "\n"
|
||||
+ "\tapp2: uid=" + mUid + ", state=" + getProcessStateByUid(mUid));
|
||||
|
||||
// app_idle_constants set in NetPolicyTestsPreparer.setUp() is not always sucessful (suspect
|
||||
// timing issue), here we set it again to make sure.
|
||||
final String appIdleConstants = "parole_duration=0,stable_charging_threshold=0";
|
||||
executeShellCommand("settings put global app_idle_constants " + appIdleConstants);
|
||||
final String currentConstants =
|
||||
executeShellCommand("settings get global app_idle_constants");
|
||||
assertEquals(appIdleConstants, currentConstants);
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
|
||||
@@ -1,63 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.build.IBuildInfo;
|
||||
import com.android.tradefed.device.DeviceNotAvailableException;
|
||||
import com.android.tradefed.device.ITestDevice;
|
||||
import com.android.tradefed.log.LogUtil;
|
||||
import com.android.tradefed.targetprep.ITargetCleaner;
|
||||
import com.android.tradefed.targetprep.ITargetPreparer;
|
||||
|
||||
public class NetPolicyTestsPreparer implements ITargetPreparer, ITargetCleaner {
|
||||
private final static String KEY_PAROLE_DURATION = "parole_duration";
|
||||
private final static int DESIRED_PAROLE_DURATION = 0;
|
||||
private final static String KEY_STABLE_CHARGING_THRESHOLD = "stable_charging_threshold";
|
||||
private final static int DESIRED_STABLE_CHARGING_THRESHOLD = 0;
|
||||
|
||||
private ITestDevice mDevice;
|
||||
private String mOriginalAppIdleConsts;
|
||||
|
||||
@Override
|
||||
public void setUp(ITestDevice device, IBuildInfo buildInfo) throws DeviceNotAvailableException {
|
||||
mDevice = device;
|
||||
mOriginalAppIdleConsts = getAppIdleConstants();
|
||||
setAppIdleConstants(KEY_PAROLE_DURATION + "=" + DESIRED_PAROLE_DURATION + ","
|
||||
+ KEY_STABLE_CHARGING_THRESHOLD + "=" + DESIRED_STABLE_CHARGING_THRESHOLD);
|
||||
LogUtil.CLog.d("Original app_idle_constants: " + mOriginalAppIdleConsts);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tearDown(ITestDevice device, IBuildInfo buildInfo, Throwable throwable)
|
||||
throws DeviceNotAvailableException {
|
||||
setAppIdleConstants(mOriginalAppIdleConsts);
|
||||
}
|
||||
|
||||
private void setAppIdleConstants(String appIdleConstants) throws DeviceNotAvailableException {
|
||||
executeCmd("settings put global app_idle_constants \"" + appIdleConstants + "\"");
|
||||
}
|
||||
|
||||
private String getAppIdleConstants() throws DeviceNotAvailableException {
|
||||
return executeCmd("settings get global app_idle_constants");
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user