From 32cd694ad544d0e5271baf3eebb0433e4e742f09 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Thu, 17 Mar 2022 22:32:49 -0700 Subject: [PATCH] SAR can also have monolithic sepolicy --- native/jni/init/init.hpp | 3 --- native/jni/init/rootdir.cpp | 10 ++++++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/native/jni/init/init.hpp b/native/jni/init/init.hpp index 12fcea7ca..6c011cddf 100644 --- a/native/jni/init/init.hpp +++ b/native/jni/init/init.hpp @@ -61,9 +61,6 @@ protected: // When this boolean is set, this means we are currently // running magiskinit on legacy SAR AVD emulator bool avd_hack = false; -#else - // Make it constexpr so compiler can optimize hacks out of the code - static constexpr bool avd_hack = false; #endif void patch_sepolicy(const char *file); diff --git a/native/jni/init/rootdir.cpp b/native/jni/init/rootdir.cpp index 41a1cb5c2..7b34fb418 100644 --- a/native/jni/init/rootdir.cpp +++ b/native/jni/init/rootdir.cpp @@ -181,6 +181,7 @@ void SARBase::patch_ro_root() { xmkdir(ROOTOVL, 0); +#if ENABLE_AVD_HACK // Handle avd hack if (avd_hack) { int src = xopen("/init", O_RDONLY | O_CLOEXEC); @@ -193,6 +194,7 @@ void SARBase::patch_ro_root() { close(src); close(dest); } +#endif // Handle overlay.d restore_folder(ROOTOVL, overlays); @@ -233,14 +235,18 @@ void SARBase::patch_ro_root() { } } + if (access("/sepolicy", F_OK) == 0) { + patch_sepolicy(ROOTOVL "/sepolicy"); + } else { + hijack_sepolicy(); + } + // Mount rootdir magic_mount(ROOTOVL); int dest = xopen(ROOTMNT, O_WRONLY | O_CREAT, 0); write(dest, magic_mount_list.data(), magic_mount_list.length()); close(dest); - hijack_sepolicy(); - chdir("/"); }