Do not show UI hidden API warning for exempt apps but print into log

This is a configuration for dogfood builds in which we want to print
warnings into the log for all apps but not show UI toast for system
apps so as to not spam dogfooders unnecessarily.

Bug: 64382372
Test: make
Change-Id: I5b0d5757610dadd1593a5e388e5345c060cf39cf
(cherry picked from commit e5bc69765d685bcbd3d98a3b792f6d90e4e3dabc)
diff --git a/runtime/hidden_api.h b/runtime/hidden_api.h
index 05e68e6..6b42259 100644
--- a/runtime/hidden_api.h
+++ b/runtime/hidden_api.h
@@ -106,7 +106,8 @@
           member->GetAccessFlags(), HiddenApiAccessFlags::kWhitelist));
     }
     WarnAboutMemberAccess(member);
-    if (action == kAllowButWarnAndToast || runtime->ShouldAlwaysSetHiddenApiWarningFlag()) {
+    if ((action == kAllowButWarnAndToast && runtime->ShouldSetHiddenApiWarningFlag()) ||
+        runtime->ShouldAlwaysSetHiddenApiWarningFlag()) {
       Runtime::Current()->SetPendingHiddenApiWarning(true);
     }
     return false;
diff --git a/runtime/native/dalvik_system_ZygoteHooks.cc b/runtime/native/dalvik_system_ZygoteHooks.cc
index 648a464..a57bf99 100644
--- a/runtime/native/dalvik_system_ZygoteHooks.cc
+++ b/runtime/native/dalvik_system_ZygoteHooks.cc
@@ -348,7 +348,12 @@
 
   DCHECK(!is_system_server || !do_hidden_api_checks)
       << "SystemServer should be forked with DISABLE_HIDDEN_API_CHECKS";
-  Runtime::Current()->SetHiddenApiChecksEnabled(do_hidden_api_checks);
+
+  // Skip checks only if this is the system server. Show UI warnings if not
+  // exempt from hidden API checks. This is a temporary configuration for
+  // dogfood builds.
+  Runtime::Current()->SetHiddenApiChecksEnabled(!is_system_server);
+  Runtime::Current()->SetUseHiddenApiWarningFlag(do_hidden_api_checks);
 
   // Clear the hidden API warning flag, in case it was set.
   Runtime::Current()->SetPendingHiddenApiWarning(false);
diff --git a/runtime/runtime.cc b/runtime/runtime.cc
index 25d83df..e910df6 100644
--- a/runtime/runtime.cc
+++ b/runtime/runtime.cc
@@ -266,6 +266,7 @@
       is_low_memory_mode_(false),
       safe_mode_(false),
       do_hidden_api_checks_(true),
+      use_hidden_api_warning_flag_(true),
       pending_hidden_api_warning_(false),
       dedupe_hidden_api_warnings_(true),
       always_set_hidden_api_warning_flag_(false),
diff --git a/runtime/runtime.h b/runtime/runtime.h
index 7ab9be5..8b468e9 100644
--- a/runtime/runtime.h
+++ b/runtime/runtime.h
@@ -528,6 +528,14 @@
     return do_hidden_api_checks_;
   }
 
+  void SetUseHiddenApiWarningFlag(bool value) {
+    use_hidden_api_warning_flag_ = value;
+  }
+
+  bool ShouldSetHiddenApiWarningFlag() const {
+    return use_hidden_api_warning_flag_;
+  }
+
   void SetPendingHiddenApiWarning(bool value) {
     pending_hidden_api_warning_ = value;
   }
@@ -992,6 +1000,9 @@
   // Whether access checks on hidden API should be performed.
   bool do_hidden_api_checks_;
 
+  // Whether hidden API UI warning flag should be set or not.
+  bool use_hidden_api_warning_flag_;
+
   // Whether the application has used an API which is not restricted but we
   // should issue a warning about it.
   bool pending_hidden_api_warning_;