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

Commit 84932f80 authored by Andreas Gampe's avatar Andreas Gampe Committed by Android (Google) Code Review
Browse files

Merge changes from topic 'ab_ota_dexopt_target_slot' into nyc-mr1-dev

* changes:
  Otapreopt: Add init script for A/B artifact move
  Otapreopt: Implement new A/B OTA path
parents 72d1772e 99e2b263
Loading
Loading
Loading
Loading
+14 −3
Original line number Diff line number Diff line
@@ -96,6 +96,17 @@ LOCAL_ADDITIONAL_DEPENDENCIES += $(LOCAL_PATH)/Android.mk
LOCAL_CLANG := true
include $(BUILD_EXECUTABLE)

# OTA slot script

include $(CLEAR_VARS)
LOCAL_MODULE:= otapreopt_slot
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_CLASS := EXECUTABLES
LOCAL_SRC_FILES := otapreopt_slot.sh
LOCAL_INIT_RC := otapreopt.rc

include $(BUILD_PREBUILT)

# OTA postinstall script

include $(CLEAR_VARS)
@@ -104,9 +115,9 @@ LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_CLASS := EXECUTABLES
LOCAL_SRC_FILES := otapreopt_script.sh

# Let this depend on otapreopt and the chroot tool, so we just have to mention one in a
# configuration.
LOCAL_REQUIRED_MODULES := otapreopt otapreopt_chroot
# Let this depend on otapreopt, the chroot tool and the slot script, so we just have to mention one
# in a configuration.
LOCAL_REQUIRED_MODULES := otapreopt otapreopt_chroot otapreopt_slot

include $(BUILD_PREBUILT)

+47 −4
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@

#include <errno.h>
#include <inttypes.h>
#include <regex>
#include <stdlib.h>
#include <sys/capability.h>
#include <sys/file.h>
@@ -58,6 +59,26 @@ namespace installd {
static constexpr const char* kCpPath = "/system/bin/cp";
static constexpr const char* kXattrDefault = "user.default";

static constexpr const char* PKG_LIB_POSTFIX = "/lib";
static constexpr const char* CACHE_DIR_POSTFIX = "/cache";
static constexpr const char* CODE_CACHE_DIR_POSTFIX = "/code_cache";

static constexpr const char* IDMAP_PREFIX = "/data/resource-cache/";
static constexpr const char* IDMAP_SUFFIX = "@idmap";

// NOTE: keep in sync with StorageManager
static constexpr int FLAG_STORAGE_DE = 1 << 0;
static constexpr int FLAG_STORAGE_CE = 1 << 1;

// NOTE: keep in sync with Installer
static constexpr int FLAG_CLEAR_CACHE_ONLY = 1 << 8;
static constexpr int FLAG_CLEAR_CODE_CACHE_ONLY = 1 << 9;

/* dexopt needed flags matching those in dalvik.system.DexFile */
static constexpr int DEXOPT_DEX2OAT_NEEDED       = 1;
static constexpr int DEXOPT_PATCHOAT_NEEDED      = 2;
static constexpr int DEXOPT_SELF_PATCHOAT_NEEDED = 3;

#define MIN_RESTRICTED_HOME_SDK_VERSION 24 // > M

typedef int fd_t;
@@ -1427,7 +1448,7 @@ static const char* parse_null(const char* arg) {
    }
}

int dexopt(const char* params[DEXOPT_PARAM_COUNT]) {
int dexopt(const char* const params[DEXOPT_PARAM_COUNT]) {
    return dexopt(params[0],                    // apk_path
                  atoi(params[1]),              // uid
                  params[2],                    // pkgname
@@ -2094,6 +2115,26 @@ int move_ab(const char* apk_path, const char* instruction_set, const char* oat_d
        LOG(ERROR) << "Cannot move_ab with null input";
        return -1;
    }

    // Get the current slot suffix. No suffix, no A/B.
    std::string slot_suffix;
    {
        char buf[kPropertyValueMax];
        if (get_property("ro.boot.slot_suffix", buf, nullptr) <= 0) {
            return -1;
        }
        slot_suffix = buf;

        // Validate.
        std::regex slot_suffix_regex("[a-zA-Z0-9_]+");
        std::smatch slot_suffix_match;
        if (!std::regex_match(slot_suffix, slot_suffix_match, slot_suffix_regex)) {
            LOG(ERROR) << "Target slot suffix not legal: " << slot_suffix;
            return -1;
        }
    }

    // Validate other inputs.
    if (validate_apk_path(apk_path) != 0) {
        LOG(ERROR) << "invalid apk_path " << apk_path;
        return -1;
@@ -2109,9 +2150,11 @@ int move_ab(const char* apk_path, const char* instruction_set, const char* oat_d
    }
    const std::string a_image_path = create_image_filename(a_path);

    // B path = A path + ".b"
    const std::string b_path = StringPrintf("%s.b", a_path);
    const std::string b_image_path = StringPrintf("%s.b", a_image_path.c_str());
    // B path = A path + slot suffix.
    const std::string b_path = StringPrintf("%s.%s", a_path, slot_suffix.c_str());
    const std::string b_image_path = StringPrintf("%s.%s",
                                                  a_image_path.c_str(),
                                                  slot_suffix.c_str());

    bool oat_success = move_ab_path(b_path, a_path);
    bool success;
+3 −1
Original line number Diff line number Diff line
@@ -28,6 +28,8 @@
namespace android {
namespace installd {

static constexpr size_t DEXOPT_PARAM_COUNT = 10U;

int create_app_data(const char *uuid, const char *pkgname, userid_t userid, int flags,
        appid_t appid, const char* seinfo, int target_sdk_version);
int restorecon_app_data(const char* uuid, const char* pkgName, userid_t userid, int flags,
@@ -69,7 +71,7 @@ int dexopt(const char *apk_path,
static_assert(DEXOPT_PARAM_COUNT == 10U, "Unexpected dexopt param size");

// Helper for the above, converting arguments.
int dexopt(const char* params[DEXOPT_PARAM_COUNT]);
int dexopt(const char* const params[DEXOPT_PARAM_COUNT]);

int mark_boot_complete(const char *instruction_set);
int linklib(const char* uuid, const char* pkgname, const char* asecLibDir, int userId);
+18 −2
Original line number Diff line number Diff line
@@ -30,6 +30,22 @@
namespace android {
namespace installd {

static constexpr const char* APP_SUBDIR = "app/"; // sub-directory under ANDROID_DATA

static constexpr const char* PRIV_APP_SUBDIR = "priv-app/"; // sub-directory under ANDROID_DATA

static constexpr const char* EPHEMERAL_APP_SUBDIR = "app-ephemeral/"; // sub-directory under
                                                                      // ANDROID_DATA

static constexpr const char* APP_LIB_SUBDIR = "app-lib/"; // sub-directory under ANDROID_DATA

static constexpr const char* MEDIA_SUBDIR = "media/"; // sub-directory under ANDROID_DATA

static constexpr const char* PROFILES_SUBDIR = "misc/profiles"; // sub-directory under ANDROID_DATA

static constexpr const char* PRIVATE_APP_SUBDIR = "app-private/"; // sub-directory under
                                                                  // ANDROID_DATA

/* Directory records that are used in execution of commands. */
dir_rec_t android_app_dir;
dir_rec_t android_app_ephemeral_dir;
@@ -77,7 +93,7 @@ bool init_globals_from_data_and_root(const char* data, const char* root) {

    // Get the android ephemeral app directory.
    if (copy_and_append(&android_app_ephemeral_dir, &android_data_dir, EPHEMERAL_APP_SUBDIR) < 0) {
        return -1;
        return false;
    }

    // Get the android app native library directory.
@@ -86,7 +102,7 @@ bool init_globals_from_data_and_root(const char* data, const char* root) {
    }

    // Get the sd-card ASEC mount point.
    if (get_path_from_env(&android_asec_dir, "ASEC_MOUNTPOINT") < 0) {
    if (get_path_from_env(&android_asec_dir, ASEC_MOUNTPOINT_ENV_NAME) < 0) {
        return false;
    }

+5 −0
Original line number Diff line number Diff line
@@ -23,6 +23,11 @@
namespace android {
namespace installd {

/* constants */

// Name of the environment variable that contains the asec mountpoint.
static constexpr const char* ASEC_MOUNTPOINT_ENV_NAME = "ASEC_MOUNTPOINT";

/* data structures */

struct dir_rec_t {
Loading