From 5148311d60646c01463458bab442352a3cbcc58f Mon Sep 17 00:00:00 2001 From: Syaoran Kuo Date: Fri, 25 Jun 2021 13:19:11 +0800 Subject: [PATCH] Bug fix: null string will cause exception in checkStringInAdbCommandOutput Bug: 192036015 Test: atest com.android.settings.fuelgauge.batterysaver.BatterySaverButtonPreferenceControllerComponentTest#test_check_battery_saver_button Change-Id: Ifc73c8c9d6b5fabca6af5ea604f23a789b99d217 https://atp.googleplex.com/test_runs/128222905 --- .../src/com/android/settings/testutils/AdbUtils.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/componenttests/src/com/android/settings/testutils/AdbUtils.java b/tests/componenttests/src/com/android/settings/testutils/AdbUtils.java index 81f98549e84..b6e3c5236df 100644 --- a/tests/componenttests/src/com/android/settings/testutils/AdbUtils.java +++ b/tests/componenttests/src/com/android/settings/testutils/AdbUtils.java @@ -43,10 +43,12 @@ public class AdbUtils { public static boolean checkStringInAdbCommandOutput(String logTag, String command, String prefix, String target, int timeoutInMillis) throws Exception { long start = System.nanoTime(); + //Sometimes the change do no reflect in adn output immediately, so need a wait and poll here while (System.nanoTime() - start < (timeoutInMillis * 1000000)) { String result = shell(command); - if (result.contains(prefix) && result.contains(target)) { + if (result.contains(prefix == null ? "" : prefix) + && result.contains(target == null ? "" : target)) { return true; } else { Thread.sleep(100);