Support Android Q new init setup

This commit is contained in:
topjohnwu 2019-03-03 06:35:25 -05:00
parent e8f35b02ca
commit 14ae29d907
4 changed files with 28 additions and 11 deletions

1
.gitignore vendored
View File

@ -15,4 +15,3 @@ native/out
/.idea /.idea
/build /build
/captures /captures
.externalNativeBuild

4
native/.gitignore vendored
View File

@ -1,3 +1,5 @@
/build /build
obj obj
libs libs
/.externalNativeBuild
/.cxx

View File

@ -281,14 +281,29 @@ static bool patch_sepolicy() {
} }
if (init_patch) { if (init_patch) {
// Force init to load /sepolicy // If init is symlink, copy it to rootfs so we can patch
uint8_t *addr; char real_init[128];
real_init[0] = '\0';
struct stat st;
lstat("/init", &st);
if (S_ISLNK(st.st_mode)) {
xreadlink("/init", real_init, sizeof(real_init));
cp_afc(real_init, "/init");
}
size_t real_init_len = strlen(real_init);
char *addr;
size_t size; size_t size;
mmap_rw("/init", addr, size); mmap_rw("/init", addr, size);
for (int i = 0; i < size; ++i) { for (char *p = addr; p < addr + size; ++p) {
if (memcmp(addr + i, SPLIT_PLAT_CIL, sizeof(SPLIT_PLAT_CIL) - 1) == 0) { if (memcmp(p, SPLIT_PLAT_CIL, sizeof(SPLIT_PLAT_CIL)) == 0) {
memcpy(addr + i + sizeof(SPLIT_PLAT_CIL) - 4, "xxx", 3); // Force init to load /sepolicy
break; memset(p, 'x', sizeof(SPLIT_PLAT_CIL) - 1);
p += sizeof(SPLIT_PLAT_CIL) - 1;
} else if (real_init_len > 0 && memcmp(p, real_init, real_init_len + 1) == 0) {
// Force execute /init instead of real init
strcpy(p, "/init");
p += real_init_len;
} }
} }
munmap(addr, size); munmap(addr, size);

View File

@ -185,12 +185,13 @@ mount_partitions() {
fi fi
[ -f /system/build.prop ] || is_mounted /system || abort "! Cannot mount /system" [ -f /system/build.prop ] || is_mounted /system || abort "! Cannot mount /system"
grep -qE '/dev/root|/system_root' /proc/mounts && SYSTEM_ROOT=true || SYSTEM_ROOT=false grep -qE '/dev/root|/system_root' /proc/mounts && SYSTEM_ROOT=true || SYSTEM_ROOT=false
if [ -f /system/init ]; then if [ -f /system/init.rc ]; then
SYSTEM_ROOT=true SYSTEM_ROOT=true
mkdir /system_root 2>/dev/null mkdir /system_root 2>/dev/null
mount --move /system /system_root mount --move /system /system_root
mount -o bind /system_root/system /system mount -o bind /system_root/system /system
fi fi
$SYSTEM_ROOT && ui_print "- Device is system-as-root"
if [ -L /system/vendor ]; then if [ -L /system/vendor ]; then
mkdir /vendor 2>/dev/null mkdir /vendor 2>/dev/null
is_mounted /vendor || mount -o ro /vendor 2>/dev/null is_mounted /vendor || mount -o ro /vendor 2>/dev/null
@ -210,7 +211,7 @@ get_flags() {
if [ -z $KEEPVERITY ]; then if [ -z $KEEPVERITY ]; then
if $SYSTEM_ROOT; then if $SYSTEM_ROOT; then
KEEPVERITY=true KEEPVERITY=true
ui_print "- Using system_root_image, keep dm/avb-verity" ui_print "- System-as-root, keep dm/avb-verity"
else else
KEEPVERITY=false KEEPVERITY=false
fi fi
@ -221,7 +222,7 @@ get_flags() {
# No data access means unable to decrypt in recovery # No data access means unable to decrypt in recovery
if $FDE || $FBE || ! $DATA; then if $FDE || $FBE || ! $DATA; then
KEEPFORCEENCRYPT=true KEEPFORCEENCRYPT=true
ui_print "- Encrypted data detected, keep forceencrypt" ui_print "- Encrypted data, keep forceencrypt"
else else
KEEPFORCEENCRYPT=false KEEPFORCEENCRYPT=false
fi fi