hiddenapi: add 'test-api' flag into dex files.

Only tests should have access to @TestApi signatures. But now all of them are greylisted, hence can be accessed by anyone. This should be changed so that grey/black/whitelist properties would be orthogonal to test-api.

The first step to fix this is to introduce extra flag and embed it into dex files. In the future access decisions will be made based on that flag.

Bug: 133832325
Test: make -j32 test-art-host-gtest-hiddenapi_test
Change-Id: I0db8938391d6aefe5e9a3bc51ec99b948ae41f6d
diff --git a/tools/hiddenapi/hiddenapi_test.cc b/tools/hiddenapi/hiddenapi_test.cc
index 7c9a95c..337fae4 100644
--- a/tools/hiddenapi/hiddenapi_test.cc
+++ b/tools/hiddenapi/hiddenapi_test.cc
@@ -690,6 +690,40 @@
   ASSERT_EQ(dex_file.get(), nullptr);
 }
 
+TEST_F(HiddenApiTest, InstanceFieldCorePlatformApiMatch) {
+  ScratchFile dex, flags_csv;
+  OpenStream(flags_csv)
+      << "LMain;->ifield:LBadType1;,greylist" << std::endl
+      << "LMain;->ifield:LBadType2;,greylist-max-o" << std::endl
+      << "LMain;->ifield:I,greylist,core-platform-api" << std::endl;
+  auto dex_file = RunHiddenapiEncode(flags_csv, {}, dex);
+  ASSERT_NE(dex_file.get(), nullptr);
+  ASSERT_EQ(hiddenapi::ApiList::CorePlatformApi() |
+  hiddenapi::ApiList::Greylist(), GetIFieldHiddenFlags(*dex_file));
+}
+
+TEST_F(HiddenApiTest, InstanceFieldTestApiMatch) {
+  ScratchFile dex, flags_csv;
+  OpenStream(flags_csv)
+      << "LMain;->ifield:LBadType1;,greylist" << std::endl
+      << "LMain;->ifield:LBadType2;,greylist-max-o" << std::endl
+      << "LMain;->ifield:I,greylist,test-api" << std::endl;
+  auto dex_file = RunHiddenapiEncode(flags_csv, {}, dex);
+  ASSERT_NE(dex_file.get(), nullptr);
+  ASSERT_EQ(hiddenapi::ApiList::TestApi()
+  | hiddenapi::ApiList::Greylist(), GetIFieldHiddenFlags(*dex_file));
+}
+
+TEST_F(HiddenApiTest, InstanceFieldUnknownFlagMatch) {
+  ScratchFile dex, flags_csv;
+  OpenStream(flags_csv)
+      << "LMain;->ifield:LBadType1;,greylist" << std::endl
+      << "LMain;->ifield:LBadType2;,greylist-max-o" << std::endl
+      << "LMain;->ifield:I,greylist,unknown-flag" << std::endl;
+  auto dex_file = RunHiddenapiEncode(flags_csv, {}, dex);
+  ASSERT_EQ(dex_file.get(), nullptr);
+}
+
 // The following tests use this class hierarchy:
 //
 //    AbstractPackageClass  PublicInterface