Disable hidden API checks during WellKnownClasses::Init

WellKnownClasses gets handles on hidden methods/fields from an
unattached native thread using JNI. The hidden API logic assumes
these calls are not coming from boot class path and blocks access.
Disable the checks during the Init routing.

Bug: 64382372
Test: make
Change-Id: I53b2c5a29b2b01667a002283b84c6095b37ba724
diff --git a/runtime/well_known_classes.cc b/runtime/well_known_classes.cc
index 5fe10f5..f4f5420 100644
--- a/runtime/well_known_classes.cc
+++ b/runtime/well_known_classes.cc
@@ -278,6 +278,12 @@
 #undef STRING_INIT_LIST
 
 void WellKnownClasses::Init(JNIEnv* env) {
+  // The following initializers use JNI to get handles on hidden methods/fields.
+  // Temporarily disable hidden API checks as they would see these calls coming
+  // from an unattached thread and assume the caller is not in boot class path.
+  const bool hidden_api_checks_enabled =  Runtime::Current()->AreHiddenApiChecksEnabled();
+  Runtime::Current()->SetHiddenApiChecksEnabled(false);
+
   dalvik_annotation_optimization_CriticalNative =
       CacheClass(env, "dalvik/annotation/optimization/CriticalNative");
   dalvik_annotation_optimization_FastNative = CacheClass(env, "dalvik/annotation/optimization/FastNative");
@@ -401,6 +407,9 @@
 
   InitStringInit(env);
   Thread::Current()->InitStringEntryPoints();
+
+  // Reenable hidden API checks if necessary.
+  Runtime::Current()->SetHiddenApiChecksEnabled(hidden_api_checks_enabled);
 }
 
 void WellKnownClasses::LateInit(JNIEnv* env) {