Merge "Access apex sysprops via the generated API"

This commit is contained in:
Treehugger Robot 2019-03-06 17:38:46 +00:00 committed by Gerrit Code Review
commit 51deeb569f
3 changed files with 9 additions and 7 deletions

View file

@ -132,7 +132,7 @@ cc_library_static {
"ueventd_parser.cpp", "ueventd_parser.cpp",
"util.cpp", "util.cpp",
], ],
whole_static_libs: ["libcap"], whole_static_libs: ["libcap", "com.android.sysprop.apex"],
header_libs: ["bootimg_headers"], header_libs: ["bootimg_headers"],
proto: { proto: {
type: "lite", type: "lite",

View file

@ -93,6 +93,7 @@ LOCAL_STATIC_LIBRARIES := \
libselinux \ libselinux \
libcap \ libcap \
libgsi \ libgsi \
libcom.android.sysprop.apex \
LOCAL_SANITIZE := signed-integer-overflow LOCAL_SANITIZE := signed-integer-overflow
# First stage init is weird: it may start without stdout/stderr, and no /proc. # First stage init is weird: it may start without stdout/stderr, and no /proc.

View file

@ -21,6 +21,7 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include <ApexProperties.sysprop.h>
#include <android-base/file.h> #include <android-base/file.h>
#include <android-base/logging.h> #include <android-base/logging.h>
#include <android-base/properties.h> #include <android-base/properties.h>
@ -132,9 +133,9 @@ static bool BindMountBionic(const std::string& linker_source, const std::string&
return true; return true;
} }
static bool IsBionicUpdatable() { static bool IsApexUpdatable() {
static bool result = android::base::GetBoolProperty("ro.apex.IsBionicUpdatable", false); static bool updatable = android::sysprop::ApexProperties::updatable().value_or(false);
return result; return updatable;
} }
static android::base::unique_fd bootstrap_ns_fd; static android::base::unique_fd bootstrap_ns_fd;
@ -187,7 +188,7 @@ bool SetupMountNamespaces() {
// bind-mounted. In the namespace for post-apexd processes, the bionic from // bind-mounted. In the namespace for post-apexd processes, the bionic from
// the runtime APEX is bind-mounted. // the runtime APEX is bind-mounted.
bool success = true; bool success = true;
if (IsBionicUpdatable() && !IsRecoveryMode()) { if (IsApexUpdatable() && !IsRecoveryMode()) {
// Creating a new namespace by cloning, saving, and switching back to // Creating a new namespace by cloning, saving, and switching back to
// the original namespace. // the original namespace.
if (unshare(CLONE_NEWNS) == -1) { if (unshare(CLONE_NEWNS) == -1) {
@ -244,7 +245,7 @@ bool SetupRuntimeBionic() {
return true; return true;
} }
// Bind-mount bionic from the runtime APEX since it is now available. Note // Bind-mount bionic from the runtime APEX since it is now available. Note
// that in case of IsBionicUpdatable() == false, these mounts are over the // that in case of IsApexUpdatable() == false, these mounts are over the
// existing existing bind mounts for the bootstrap bionic, which effectively // existing existing bind mounts for the bootstrap bionic, which effectively
// becomes hidden. // becomes hidden.
if (!BindMountBionic(kRuntimeLinkerPath, kRuntimeBionicLibsDir, kLinkerMountPoint, if (!BindMountBionic(kRuntimeLinkerPath, kRuntimeBionicLibsDir, kLinkerMountPoint,
@ -264,7 +265,7 @@ bool SwitchToBootstrapMountNamespaceIfNeeded() {
return true; return true;
} }
if (bootstrap_ns_id != GetMountNamespaceId() && bootstrap_ns_fd.get() != -1 && if (bootstrap_ns_id != GetMountNamespaceId() && bootstrap_ns_fd.get() != -1 &&
IsBionicUpdatable()) { IsApexUpdatable()) {
if (setns(bootstrap_ns_fd.get(), CLONE_NEWNS) == -1) { if (setns(bootstrap_ns_fd.get(), CLONE_NEWNS) == -1) {
PLOG(ERROR) << "Failed to switch to bootstrap mount namespace."; PLOG(ERROR) << "Failed to switch to bootstrap mount namespace.";
return false; return false;