Add runtime option for no hidden API access checks

Add a new Runtime option -Xno-hidden-api-checks to disable
enforcing hidden API access restrictions.

Test: m test-art-host
Bug: 64382372
Change-Id: I8bd5b7ef307f21ba71d05a066a9d5dd2d7614543
diff --git a/runtime/parsed_options.cc b/runtime/parsed_options.cc
index 2f60162..92eb703 100644
--- a/runtime/parsed_options.cc
+++ b/runtime/parsed_options.cc
@@ -330,6 +330,8 @@
       .Define("-Xtarget-sdk-version:_")
           .WithType<int>()
           .IntoKey(M::TargetSdkVersion)
+      .Define("-Xno-hidden-api-checks")
+          .IntoKey(M::NoHiddenApiChecks)
       .Ignore({
           "-ea", "-da", "-enableassertions", "-disableassertions", "--runtime-arg", "-esa",
           "-dsa", "-enablesystemassertions", "-disablesystemassertions", "-Xrs", "-Xint:_",
diff --git a/runtime/runtime.cc b/runtime/runtime.cc
index 007d361..33bebe0 100644
--- a/runtime/runtime.cc
+++ b/runtime/runtime.cc
@@ -265,6 +265,7 @@
       oat_file_manager_(nullptr),
       is_low_memory_mode_(false),
       safe_mode_(false),
+      do_hidden_api_checks_(false),
       dump_native_stack_on_sig_quit_(true),
       pruned_dalvik_cache_(false),
       // Initially assume we perceive jank in case the process state is never updated.
@@ -1168,6 +1169,10 @@
 
   target_sdk_version_ = runtime_options.GetOrDefault(Opt::TargetSdkVersion);
 
+  if (runtime_options.Exists(Opt::NoHiddenApiChecks)) {
+    do_hidden_api_checks_ = false;
+  }
+
   no_sig_chain_ = runtime_options.Exists(Opt::NoSigChain);
   force_native_bridge_ = runtime_options.Exists(Opt::ForceNativeBridge);
 
diff --git a/runtime/runtime.h b/runtime/runtime.h
index 6d2887c..022a1be 100644
--- a/runtime/runtime.h
+++ b/runtime/runtime.h
@@ -520,6 +520,14 @@
   bool IsVerificationEnabled() const;
   bool IsVerificationSoftFail() const;
 
+  void DisableHiddenApiChecks() {
+    do_hidden_api_checks_ = false;
+  }
+
+  bool AreHiddenApiChecksEnabled() const {
+    return do_hidden_api_checks_;
+  }
+
   bool IsDexFileFallbackEnabled() const {
     return allow_dex_file_fallback_;
   }
@@ -957,6 +965,9 @@
   // Whether the application should run in safe mode, that is, interpreter only.
   bool safe_mode_;
 
+  // Whether access checks on hidden API should be performed.
+  bool do_hidden_api_checks_;
+
   // Whether threads should dump their native stack on SIGQUIT.
   bool dump_native_stack_on_sig_quit_;
 
diff --git a/runtime/runtime_options.def b/runtime/runtime_options.def
index 3996989..6e1a68b 100644
--- a/runtime/runtime_options.def
+++ b/runtime/runtime_options.def
@@ -119,6 +119,7 @@
 RUNTIME_OPTIONS_KEY (verifier::VerifyMode, \
                                           Verify,                         verifier::VerifyMode::kEnable)
 RUNTIME_OPTIONS_KEY (int,                 TargetSdkVersion,               Runtime::kUnsetSdkVersion)
+RUNTIME_OPTIONS_KEY (Unit,                NoHiddenApiChecks)
 RUNTIME_OPTIONS_KEY (std::string,         NativeBridge)
 RUNTIME_OPTIONS_KEY (unsigned int,        ZygoteMaxFailedBoots,           10)
 RUNTIME_OPTIONS_KEY (Unit,                NoDexFileFallback)