Disable the public SDK Checker during exception throwing

The compiler will try to throw exception when it cannot
resolved methods/classes or when there's an incompatible class
change. While doing so, it requires the thrown exception class
to be initialized.

However, when verifying with a public SDK Checker installed,
it's possible that the exception class may not initialized due
to private member access (e.g. serialVersionUid).

Since during verification the exceptions are simply mechanism
for the compiler to propagate the verification error it is OK
to disable the SDK Checker and allow the class to be initialized.

Bug: 177017481
Test: m test-art-host & manual
Change-Id: I3765897bf9885b7e26b3ab044002df88866cd3cd
diff --git a/runtime/sdk_checker.cc b/runtime/sdk_checker.cc
index 22c4305..1dbe39c 100644
--- a/runtime/sdk_checker.cc
+++ b/runtime/sdk_checker.cc
@@ -23,7 +23,7 @@
 
 namespace art {
 
-SdkChecker::SdkChecker() {}
+SdkChecker::SdkChecker() : enabled_(true) {}
 
 SdkChecker* SdkChecker::Create(
     const std::string& public_sdk, std::string* error_msg) {
@@ -47,6 +47,10 @@
 }
 
 bool SdkChecker::ShouldDenyAccess(ArtMethod* art_method) const {
+  if (!enabled_) {
+    return false;
+  }
+
   bool found = false;
   for (const std::unique_ptr<const DexFile>& dex_file : sdk_dex_files_) {
     const dex::TypeId* declaring_type_id =
@@ -89,6 +93,10 @@
 }
 
 bool SdkChecker::ShouldDenyAccess(ArtField* art_field) const {
+  if (!enabled_) {
+    return false;
+  }
+
   bool found = false;
   for (const std::unique_ptr<const DexFile>& dex_file : sdk_dex_files_) {
     std::string declaring_class;
@@ -123,6 +131,10 @@
 }
 
 bool SdkChecker::ShouldDenyAccess(const char* descriptor) const {
+  if (!enabled_) {
+    return false;
+  }
+
   bool found = false;
   for (const std::unique_ptr<const DexFile>& dex_file : sdk_dex_files_) {
     const dex::TypeId* type_id = dex_file->FindTypeId(descriptor);