diff --git a/native/src/init/getinfo.cpp b/native/src/init/getinfo.cpp index df0bd38cf..7de8a63bd 100644 --- a/native/src/init/getinfo.cpp +++ b/native/src/init/getinfo.cpp @@ -230,7 +230,9 @@ kv_pairs load_partition_map() { } bool check_two_stage() { - if (access("/apex", F_OK) == 0) + if (access("/first_stage_ramdisk", F_OK) == 0) + return true; + if (access("/second_stage_resources", F_OK) == 0) return true; if (access("/system/bin/init", F_OK) == 0) return true; diff --git a/native/src/init/init.cpp b/native/src/init/init.cpp index ae221002e..42a9ef843 100644 --- a/native/src/init/init.cpp +++ b/native/src/init/init.cpp @@ -90,15 +90,17 @@ int main(int argc, char *argv[]) { } else { // This will also mount /sys and /proc load_kernel_info(&config); + bool recovery = access("/sbin/recovery", F_OK) == 0 || + access("/system/bin/recovery", F_OK) == 0; - if (config.skip_initramfs) + if (config.force_normal_boot) + init = new FirstStageInit(argv, &config); + else if (!recovery && check_two_stage()) + init = new FirstStageInit(argv, &config); + else if (config.skip_initramfs) init = new LegacySARInit(argv, &config); - else if (config.force_normal_boot) - init = new FirstStageInit(argv, &config); - else if (access("/sbin/recovery", F_OK) == 0 || access("/system/bin/recovery", F_OK) == 0) + else if (recovery) init = new RecoveryInit(argv, &config); - else if (check_two_stage()) - init = new FirstStageInit(argv, &config); else init = new RootFSInit(argv, &config); } diff --git a/native/src/init/mount.cpp b/native/src/init/mount.cpp index 4d547fc0b..a09f7cbec 100644 --- a/native/src/init/mount.cpp +++ b/native/src/init/mount.cpp @@ -200,8 +200,7 @@ mount_root: xmount("tmpfs", "/dev", "tmpfs", 0, "mode=755"); mount_list.emplace_back("/dev"); - // Use the apex folder to determine whether 2SI (Android 10+) - bool is_two_stage = access("/apex", F_OK) == 0; + bool is_two_stage = access("/system/bin/init", F_OK) == 0; LOGD("is_two_stage: [%d]\n", is_two_stage); // For API 28 AVD, it uses legacy SAR setup that requires