Disable hidden API checks for Am
Am starts its own runtime and its Java code should be exempt from
hidden API checks. Change the logic in runtime.cc to disable hidden
API checks by default and only enable them if:
(a) dex2oat runs without -Xno-hidden-api-checks
(b) zygote forks a new process without DISABLE_HIDDEN_API_CHECKS flag
This logic can be simplified by changing the flag from negative to
positive. Since the cleanup requires touching multiple projects, it
will be done in a future CL.
Bug: 73001007
Bug: 64382372
Test: manual
Change-Id: I8a222f7a16bf88ffe4541558f3ba789f38d7322e
diff --git a/runtime/gc/heap_test.cc b/runtime/gc/heap_test.cc
index 6d426c2..9d8e5d2 100644
--- a/runtime/gc/heap_test.cc
+++ b/runtime/gc/heap_test.cc
@@ -81,6 +81,7 @@
void SetUpRuntimeOptions(RuntimeOptions* options) {
CommonRuntimeTest::SetUpRuntimeOptions(options);
options->push_back(std::make_pair("-Xzygote", nullptr));
+ options->push_back(std::make_pair("-Xno-hidden-api-checks", nullptr));
}
};
diff --git a/runtime/runtime.cc b/runtime/runtime.cc
index 25d83df..3afd320 100644
--- a/runtime/runtime.cc
+++ b/runtime/runtime.cc
@@ -1172,11 +1172,15 @@
target_sdk_version_ = runtime_options.GetOrDefault(Opt::TargetSdkVersion);
- // Check whether to enforce hidden API access checks. Zygote needs to be exempt
- // but checks may be enabled for forked processes (see dalvik_system_ZygoteHooks).
- if (is_zygote_ || runtime_options.Exists(Opt::NoHiddenApiChecks)) {
- do_hidden_api_checks_ = false;
- }
+ // Check whether to enforce hidden API access checks. The checks are disabled
+ // by default and we only enable them if:
+ // (a) runtime was started with a flag that enables the checks, or
+ // (b) Zygote forked a new process that is not exempt (see ZygoteHooks).
+ // TODO(dbrazdil): Turn the NoHiddenApiChecks negative flag into a positive one
+ // to clean up this logic.
+ do_hidden_api_checks_ = IsAotCompiler() && !runtime_options.Exists(Opt::NoHiddenApiChecks);
+ DCHECK(!is_zygote_ || !do_hidden_api_checks_)
+ << "Zygote should not be started with hidden API checks";
no_sig_chain_ = runtime_options.Exists(Opt::NoSigChain);
force_native_bridge_ = runtime_options.Exists(Opt::ForceNativeBridge);