Introduce new build tool: hiddenapi

New tool `hiddenapi` iterates over all class members inside given
DEX files and modifies their access flags if their signatures
appear on one of two lists - greylist and blacklist - provided as
text file inputs. These access flags denote to the runtime that
the marked methods/fields should be treated as internal APIs with
restricted access.

Two bits of information are encoded in the DEX access flags. These
are encoded as unsigned LEB128 values in DEX and so as to not
increase the size of the DEX, different modifiers were chosen to
carry the information under different circumstances.

First bit is encoded as the inversion of visibility access flags
(bits 2:0). At most one of these flags can be set at any given time.
Inverting these bits therefore produces a value where at least two
bits are set and there is never any loss of information.

Second bit is encoded differently for each given type of class
member as there is no single unused bit such that setting it would
not increase the size of the LEB128 encoding.
 - Bit 5 for fields as it carries no other meaning
 - Bit 5 for non-native methods, as `synchronized` can only be set
   on native methods
 - Bit 9 for native methods, as it carries no meaning and bit 8
   (native) will make the LEB128 encoding at least two bytes long

This tool is meant to be applied on boot class path DEX files and
as such, this encoding is not part of the DEX specification and may
change in the future. Access flags returned by ClassDataItemIterator
are stripped of these hidden flags and thus fully transparent to the
runtime.

Test: m test-art-host
Bug: 64382372
Change-Id: Ifc237ff8a35a8b470b7fc682a9cb879370d1e6e9
diff --git a/build/Android.gtest.mk b/build/Android.gtest.mk
index 45f4e2d..4f5df03 100644
--- a/build/Android.gtest.mk
+++ b/build/Android.gtest.mk
@@ -36,6 +36,7 @@
   ForClassLoaderD \
   ExceptionHandle \
   GetMethodSignature \
+  HiddenApi \
   ImageLayoutA \
   ImageLayoutB \
   IMTA \
@@ -113,6 +114,7 @@
 ART_GTEST_dex2oat_test_DEX_DEPS := $(ART_GTEST_dex2oat_environment_tests_DEX_DEPS) ManyMethods Statics VerifierDeps
 ART_GTEST_dex2oat_image_test_DEX_DEPS := $(ART_GTEST_dex2oat_environment_tests_DEX_DEPS) Statics VerifierDeps
 ART_GTEST_exception_test_DEX_DEPS := ExceptionHandle
+ART_GTEST_hiddenapi_test_DEX_DEPS := HiddenApi
 ART_GTEST_image_test_DEX_DEPS := ImageLayoutA ImageLayoutB DefaultMethods
 ART_GTEST_imtable_test_DEX_DEPS := IMTA IMTB
 ART_GTEST_instrumentation_test_DEX_DEPS := Instrumentation
@@ -266,6 +268,11 @@
 ART_GTEST_profile_assistant_test_HOST_DEPS := profmand-host
 ART_GTEST_profile_assistant_test_TARGET_DEPS := profmand-target
 
+ART_GTEST_hiddenapi_test_HOST_DEPS := \
+  $(HOST_CORE_IMAGE_DEFAULT_64) \
+  $(HOST_CORE_IMAGE_DEFAULT_32) \
+  hiddenapid-host
+
 # The path for which all the source files are relative, not actually the current directory.
 LOCAL_PATH := art
 
@@ -279,6 +286,7 @@
     art_dexlayout_tests \
     art_dexlist_tests \
     art_dexoptanalyzer_tests \
+    art_hiddenapi_tests \
     art_imgdiag_tests \
     art_oatdump_tests \
     art_patchoat_tests \