Make the tests permissive
1. android.jobscheduler.cts.BatteryConstraintTest#testBatteryNotLowConstraintFails_withoutPower
Bug:121302074
Test: Build CTS
Test: Device Build No.5197801 passed the following tests
Test: run cts -o -m CtsJobSchedulerTestCases -t android.jobscheduler.cts.BatteryConstraintTest#testBatteryNotLowConstraintFails_withoutPower
Change-Id: Ib59b83c8af947e7a9c95c09a58ab58dde9a5faff
Signed-off-by: Yoshiki ISHIGE <ishige@casio.co.jp>
(cherry picked from commit c4e0b7423c115b1570a6caa6094fbe33016c3f40)
diff --git a/tests/JobScheduler/src/android/jobscheduler/cts/BatteryConstraintTest.java b/tests/JobScheduler/src/android/jobscheduler/cts/BatteryConstraintTest.java
index f6ff23f..e26f8b4 100644
--- a/tests/JobScheduler/src/android/jobscheduler/cts/BatteryConstraintTest.java
+++ b/tests/JobScheduler/src/android/jobscheduler/cts/BatteryConstraintTest.java
@@ -24,6 +24,7 @@
import android.os.BatteryManager;
import android.provider.Settings;
import android.util.Log;
+import android.content.res.Resources;
import com.android.compatibility.common.util.SystemUtil;
@@ -41,6 +42,7 @@
public static final int BATTERY_JOB_ID = BatteryConstraintTest.class.hashCode();
private JobInfo.Builder mBuilder;
+ private int mLowBatteryWarningLevel = 15;
/**
* Record of the previous state of power save mode trigger level to reset it after the test
* finishes.
@@ -51,6 +53,9 @@
public void setUp() throws Exception {
super.setUp();
+ mLowBatteryWarningLevel = Resources.getSystem().getInteger(
+ Resources.getSystem().getIdentifier(
+ "config_lowBatteryWarningLevel", "integer", "android"));
// Disable power save mode as some devices may turn off Android when power save mode is
// enabled, causing the test to fail.
mPreviousLowPowerTriggerLevel = Settings.Global.getInt(getContext().getContentResolver(),
@@ -253,7 +258,7 @@
return;
}
- setBatteryState(false, 5);
+ setBatteryState(false, mLowBatteryWarningLevel);
// setBatteryState() waited for the charging/not-charging state to formally settle,
// but battery level reporting lags behind that. wait a moment to let that happen
// before proceeding.
@@ -288,8 +293,8 @@
kTestEnvironment.awaitExecution());
// And check that the job is stopped if battery goes low again.
- setBatteryState(false, 5);
- setBatteryState(false, 4);
+ setBatteryState(false, mLowBatteryWarningLevel);
+ setBatteryState(false, mLowBatteryWarningLevel - 1);
Thread.sleep(2_000);
verifyChargingState(false);
verifyBatteryNotLowState(false);