Merge "Revert "Remove custom installation rules""
am: 68c846ae56

Change-Id: I57e63f13dc0542ffd6e4e5db1d03e650b739f7c1
diff --git a/test_framework/com/android/tradefed/targetprep/TemperatureThrottlingWaiter.java b/test_framework/com/android/tradefed/targetprep/TemperatureThrottlingWaiter.java
index f776296..598d78a 100644
--- a/test_framework/com/android/tradefed/targetprep/TemperatureThrottlingWaiter.java
+++ b/test_framework/com/android/tradefed/targetprep/TemperatureThrottlingWaiter.java
@@ -23,6 +23,9 @@
 import com.android.tradefed.log.LogUtil.CLog;
 import com.android.tradefed.util.RunUtil;
 
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
 /** An {@link ITargetPreparer} that waits until device's temperature gets down to target */
 @OptionClass(alias = "temperature-throttle-waiter")
 public class TemperatureThrottlingWaiter extends BaseTargetPreparer {
@@ -46,11 +49,10 @@
     public static final String DEVICE_TEMPERATURE_FILE_PATH_NAME = "device-temperature-file-path";
 
     @Option(
-        name = DEVICE_TEMPERATURE_FILE_PATH_NAME,
-        description =
-                "Name of file that contains device"
-                        + "temperature. Example: /sys/class/hwmon/hwmon1/device/msm_therm"
-    )
+            name = DEVICE_TEMPERATURE_FILE_PATH_NAME,
+            description =
+                    "Name of file that contains device"
+                            + "temperature. Example: /sys/class/hwmon/hwmon1/device/msm_therm")
     private String mDeviceTemperatureFilePath = null;
 
     @Option(name = "target-temperature", description = "Target Temperature that device should have;"
@@ -110,23 +112,30 @@
         String result = device.executeShellCommand(
                 String.format("cat %s", fileName)).trim();
         CLog.i(String.format("Temperature file output : %s", result));
-        // example output : Result:30 Raw:7f6f
+
         if (result == null || result.contains("No such file or directory")) {
             throw new TargetSetupError(String.format("File %s doesn't exist", fileName),
                     device.getDeviceDescriptor());
-        } else if (!result.toLowerCase().startsWith("result:")) {
-            throw new TargetSetupError(
-                    String.format("file content is not as expected. Content : %s", result),
-                    device.getDeviceDescriptor());
         }
 
-        try {
-            deviceTemp = Integer.parseInt(result.split(" ")[0].split(":")[1].trim());
-        } catch (NumberFormatException numEx) {
-            CLog.e(String.format("Temperature is not of right format %s", numEx.getMessage()));
-            throw numEx;
+        // temperature raw format example output : Result:30 Raw:7f6f
+        final Pattern TEMPERATURE_RAW_FORMAT_REGEX = Pattern.compile("Result:(\\d+)\\sRaw:(\\w+)");
+        // temperature format example output : 30
+        final Pattern TEMPERATURE_FORMAT_REGEX = Pattern.compile("\\d+");
+        Matcher matcher = TEMPERATURE_RAW_FORMAT_REGEX.matcher(result);
+        if (matcher.find()) {
+            deviceTemp = Integer.parseInt(matcher.group(1));
+        } else {
+            matcher = TEMPERATURE_FORMAT_REGEX.matcher(result);
+            if (matcher.find()) {
+                deviceTemp = Integer.parseInt(matcher.group());
+            } else {
+                throw new TargetSetupError(
+                        String.format("file content is not as expected. Content : %s", result),
+                        device.getDeviceDescriptor());
+            }
         }
 
         return deviceTemp;
     }
-}
\ No newline at end of file
+}