Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c19c604b authored by Roland Levillain's avatar Roland Levillain
Browse files

Revert^2 "Have `otapreopt_chroot` mount APEX packages in the chroot dir."

We need at least the Android Runtime APEX to be able to run `dex2oat`
in `otapreopt`. For simplicity, reuse `apexd`'s logic and mount all
the APEX packages found on the system partition in /postinstall/apex.

This is a temporary change. The final design will integrate A/B OTA
updates and `apexd`.

This reverts commit 00b5b3f0.

Test: m otapreopt_chroot
Test: A/B OTA update test (asit/dexoptota/self_full).
Bug: 113373927
Bug: 120796514
Change-Id: Ifa45c282d04ae443e55bd41d8c9cbb4ea5f837d4
parent 9c45a2f3
Loading
Loading
Loading
Loading
+10 −0
Original line number Original line Diff line number Diff line
@@ -140,6 +140,16 @@ cc_binary {
    shared_libs: [
    shared_libs: [
        "libbase",
        "libbase",
        "liblog",
        "liblog",
        "libprotobuf-cpp-full",
        "libselinux",
        "libziparchive",
    ],
    static_libs: [
        "libapex",
        "libapexd",
        "lib_apex_manifest_proto",
        "libavb",
        "libdm",
    ],
    ],
}
}


+41 −0
Original line number Original line Diff line number Diff line
@@ -17,6 +17,7 @@
#include <fcntl.h>
#include <fcntl.h>
#include <linux/unistd.h>
#include <linux/unistd.h>
#include <sys/mount.h>
#include <sys/mount.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <sys/wait.h>


#include <sstream>
#include <sstream>
@@ -24,6 +25,9 @@
#include <android-base/logging.h>
#include <android-base/logging.h>
#include <android-base/macros.h>
#include <android-base/macros.h>
#include <android-base/stringprintf.h>
#include <android-base/stringprintf.h>
#include <selinux/android.h>

#include <apexd.h>


#include "installd_constants.h"
#include "installd_constants.h"
#include "otapreopt_utils.h"
#include "otapreopt_utils.h"
@@ -138,6 +142,33 @@ static int otapreopt_chroot(const int argc, char **arg) {
      UNUSED(product_result);
      UNUSED(product_result);
    }
    }


    // Setup APEX mount point and its security context.
    static constexpr const char* kPostinstallApexDir = "/postinstall/apex";
    // The following logic is similar to the one in system/core/rootdir/init.rc:
    //
    //   mount tmpfs tmpfs /apex nodev noexec nosuid
    //   chmod 0755 /apex
    //   chown root root /apex
    //   restorecon /apex
    //
    if (mount("tmpfs", kPostinstallApexDir, "tmpfs", MS_NODEV | MS_NOEXEC | MS_NOSUID, nullptr)
        != 0) {
        PLOG(ERROR) << "Failed to mount tmpfs in " << kPostinstallApexDir;
        exit(209);
    }
    if (chmod(kPostinstallApexDir, 0755) != 0) {
        PLOG(ERROR) << "Failed to chmod " << kPostinstallApexDir << " to 0755";
        exit(210);
    }
    if (chown(kPostinstallApexDir, 0, 0) != 0) {
        PLOG(ERROR) << "Failed to chown " << kPostinstallApexDir << " to root:root";
        exit(211);
    }
    if (selinux_android_restorecon(kPostinstallApexDir, 0) < 0) {
        PLOG(ERROR) << "Failed to restorecon " << kPostinstallApexDir;
        exit(212);
    }

    // Chdir into /postinstall.
    // Chdir into /postinstall.
    if (chdir("/postinstall") != 0) {
    if (chdir("/postinstall") != 0) {
        PLOG(ERROR) << "Unable to chdir into /postinstall.";
        PLOG(ERROR) << "Unable to chdir into /postinstall.";
@@ -155,6 +186,16 @@ static int otapreopt_chroot(const int argc, char **arg) {
        exit(205);
        exit(205);
    }
    }


    // Try to mount APEX packages in "/apex" in the chroot dir. We need at least
    // the Android Runtime APEX, as it is required by otapreopt to run dex2oat.
    // The logic here is (partially) copied and adapted from
    // system/apex/apexd/apexd_main.cpp.
    //
    // Only scan the APEX directory under /system (within the chroot dir).
    // Note that this leaves around the loop devices created and used by
    // libapexd's code, but this is fine, as we expect to reboot soon after.
    apex::scanPackagesDirAndActivate(apex::kApexPackageSystemDir);

    // Now go on and run otapreopt.
    // Now go on and run otapreopt.


    // Incoming:  cmd + status-fd + target-slot + cmd... + null      | Incoming | = argc + 1
    // Incoming:  cmd + status-fd + target-slot + cmd... + null      | Incoming | = argc + 1