Fix ahat parsing to allow leading whitespaces for comments

Test: atest ahat-tests:com.android.ahat.InstanceTest
Test: atest ahat-tests:com.android.ahat.ProguardMapTest
Bug: 215523729
Change-Id: I37e16065ba6e3d36e92d4de1e0a4c0efac2d03e6
diff --git a/tools/ahat/src/main/com/android/ahat/proguard/ProguardMap.java b/tools/ahat/src/main/com/android/ahat/proguard/ProguardMap.java
index f2f2383..699c417 100644
--- a/tools/ahat/src/main/com/android/ahat/proguard/ProguardMap.java
+++ b/tools/ahat/src/main/com/android/ahat/proguard/ProguardMap.java
@@ -211,8 +211,8 @@
     BufferedReader reader = new BufferedReader(mapReader);
     String line = reader.readLine();
     while (line != null) {
-      // Comment lines start with '#'. Skip over them.
-      if (line.startsWith("#")) {
+      // Skip comment lines.
+      if (isCommentLine(line)) {
         line = reader.readLine();
         continue;
       }
@@ -234,14 +234,14 @@
       //   '    type clearName -> obfuscatedName'
       //   '# comment line'
       line = reader.readLine();
-      while (line != null && (line.startsWith("    ") || line.startsWith("#"))) {
-        // Comment lines start with '#' and may occur anywhere in the file.
+      while (line != null && (line.startsWith("    ") || isCommentLine(line))) {
+        String trimmed = line.trim();
+        // Comment lines may occur anywhere in the file.
         // Skip over them.
-        if (line.startsWith("#")) {
+        if (isCommentLine(trimmed)) {
           line = reader.readLine();
           continue;
         }
-        String trimmed = line.trim();
         int ws = trimmed.indexOf(' ');
         sep = trimmed.indexOf(" -> ");
         if (ws == -1 || sep == -1) {
@@ -309,6 +309,11 @@
     reader.close();
   }
 
+  private boolean isCommentLine(String line) {
+      // Comment lines start with '#' and my have leading whitespaces.
+      return line.trim().startsWith("#");
+  }
+
   /**
    * Returns the deobfuscated version of the given obfuscated class name.
    * If this proguard mapping does not include information about how to
diff --git a/tools/ahat/src/test/com/android/ahat/ProguardMapTest.java b/tools/ahat/src/test/com/android/ahat/ProguardMapTest.java
index 2343b45..a569fd4 100644
--- a/tools/ahat/src/test/com/android/ahat/ProguardMapTest.java
+++ b/tools/ahat/src/test/com/android/ahat/ProguardMapTest.java
@@ -29,9 +29,11 @@
     + "# compiler_version: 3.0-dev\n"
     + "# min_api: 10000\n"
     + "# compiler_hash: b7e25308967a577aa1f05a4b5a745c26\n"
+    + "  # indented comment\n"
     + "class.that.is.Empty -> a:\n"
     + "class.that.is.Empty$subclass -> b:\n"
     + "class.with.only.Fields -> c:\n"
+    + "  # indented inner comment\n"
     + "    int prim_type_field -> a\n"
     + "    int[] prim_array_type_field -> b\n"
     + "    class.that.is.Empty class_type_field -> c\n"
@@ -41,6 +43,7 @@
     + "    int some_field -> a\n"
     + "    12:23:void <clinit>() -> <clinit>\n"
     + "    42:43:void boringMethod() -> m\n"
+    + "      # indented further inner comment\n"
     + "    45:48:void methodWithPrimArgs(int,float) -> m\n"
     + "    49:50:void methodWithPrimArrArgs(int[],float) -> m\n"
     + "    52:55:void methodWithClearObjArg(class.not.in.Map) -> m\n"