check-flagged-apis: parse flag names and values

Teach check-flagged-apis to parse the parsed_flags protobuf generated by
aconfig.

Note: `m all_aconfig_declarations` generates a protobuf file that
contains all info about all flags.

Bug: 334870672
Test: atest --host check-flagged-apis-test
Test: check-flagged-apis --api-signature out/target/product/mainline_x86/obj/ETC/frameworks-base-api-current.txt_intermediates/frameworks-base-api-current.txt --flag-values out/soong/.intermediates/all_aconfig_declarations.pb
Change-Id: I397b32ae2a373b429ef6ce22e0a06a0f15202b91
diff --git a/tools/check-flagged-apis/src/com/android/checkflaggedapis/CheckFlaggedApisTest.kt b/tools/check-flagged-apis/src/com/android/checkflaggedapis/CheckFlaggedApisTest.kt
index d7890d7..5fb67be 100644
--- a/tools/check-flagged-apis/src/com/android/checkflaggedapis/CheckFlaggedApisTest.kt
+++ b/tools/check-flagged-apis/src/com/android/checkflaggedapis/CheckFlaggedApisTest.kt
@@ -15,8 +15,11 @@
  */
 package com.android.checkflaggedapis
 
+import android.aconfig.Aconfig
 import com.android.tradefed.testtype.DeviceJUnit4ClassRunner
 import com.android.tradefed.testtype.junit4.BaseHostJUnit4Test
+import java.io.ByteArrayInputStream
+import java.io.ByteArrayOutputStream
 import org.junit.Assert.assertEquals
 import org.junit.Test
 import org.junit.runner.RunWith
@@ -33,6 +36,22 @@
 """
         .trim()
 
+private val PARSED_FLAGS =
+    {
+      val parsed_flag =
+          Aconfig.parsed_flag
+              .newBuilder()
+              .setPackage("android.flag")
+              .setName("foo")
+              .setState(Aconfig.flag_state.ENABLED)
+              .setPermission(Aconfig.flag_permission.READ_ONLY)
+              .build()
+      val parsed_flags = Aconfig.parsed_flags.newBuilder().addParsedFlag(parsed_flag).build()
+      val binaryProto = ByteArrayOutputStream()
+      parsed_flags.writeTo(binaryProto)
+      ByteArrayInputStream(binaryProto.toByteArray())
+    }()
+
 @RunWith(DeviceJUnit4ClassRunner::class)
 class CheckFlaggedApisTest : BaseHostJUnit4Test() {
   @Test
@@ -41,4 +60,11 @@
     val actual = parseApiSignature("in-memory", API_SIGNATURE.byteInputStream())
     assertEquals(expected, actual)
   }
+
+  @Test
+  fun testParseFlagValues() {
+    val expected: Map<Flag, Boolean> = mapOf(Flag("android.flag.foo") to true)
+    val actual = parseFlagValues(PARSED_FLAGS)
+    assertEquals(expected, actual)
+  }
 }