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

Commit 9b1f2efc authored by Android Build Coastguard Worker's avatar Android Build Coastguard Worker
Browse files

Snap for 13744166 from 74e91afd to 25Q4-release

Change-Id: I66f3d09ad99188de14fd1ec20fc9a998347b024a
parents dc5199f3 74e91afd
Loading
Loading
Loading
Loading
+0 −106
Original line number Diff line number Diff line
@@ -191,30 +191,6 @@ cc_binary {
    required: ["migrate_legacy_obb_data"],
}

// OTA chroot tool

cc_binary {
    name: "otapreopt_chroot",
    defaults: ["libapexd-deps"],
    cflags: [
        "-Wall",
        "-Werror",
    ],

    srcs: [
        "otapreopt_chroot.cpp",
        "otapreopt_utils.cpp",
    ],
    shared_libs: [
        "libbase",
        "liblog",
        "libutils",
    ],
    required: [
        "apexd",
    ],
}

filegroup {
    name: "installd_aidl",
    srcs: [
@@ -223,92 +199,10 @@ filegroup {
    path: "binder",
}

//
// Static library for otapreopt used in testing
//
cc_library_static {
    name: "libotapreoptparameters",
    cflags: [
        "-Wall",
        "-Werror",
    ],

    srcs: ["otapreopt_parameters.cpp"],

    export_include_dirs: ["."],

    shared_libs: [
        "libbase",
        "libcutils",
        "liblog",
        "libprocessgroup",
        "libutils",
    ],
}

//
//  OTA Executable
//

cc_binary {
    name: "otapreopt",
    cflags: [
        "-Wall",
        "-Werror",
    ],

    srcs: [
        "dexopt.cpp",
        "execv_helper.cpp",
        "globals.cpp",
        "otapreopt.cpp",
        "otapreopt_utils.cpp",
        "restorable_file.cpp",
        "run_dex2oat.cpp",
        "unique_file.cpp",
        "utils.cpp",
        "utils_default.cpp",
    ],

    static_libs: [
        "libasync_safe",
        "libdiskusage",
        "libotapreoptparameters",
        "libext2_uuid",
    ],

    shared_libs: [
        "libbase",
        "libcrypto",
        "libcutils",
        "liblog",
        "liblogwrap",
        "libprocessgroup",
        "libselinux",
        "libutils",
        "libziparchive",
        "server_configurable_flags",
    ],
}

// OTA slot script
sh_binary {
    name: "otapreopt_slot",
    src: "otapreopt_slot.sh",
    init_rc: ["otapreopt.rc"],
}

// OTA postinstall script
sh_binary {
    name: "otapreopt_script",
    src: "otapreopt_script.sh",
    // Let this depend on otapreopt, the chroot tool and the slot script,
    // so we just have to mention one in a configuration.
    required: [
        "otapreopt",
        "otapreopt_chroot",
        "otapreopt_slot",
    ],
}

// Script to migrate legacy obb data.
+0 −1
Original line number Diff line number Diff line
@@ -68,7 +68,6 @@
#include "dexopt.h"
#include "globals.h"
#include "installd_deps.h"
#include "otapreopt_utils.h"
#include "utils.h"

#include "CacheTracker.h"
+0 −3
Original line number Diff line number Diff line
@@ -6,9 +6,6 @@
    {
      "name": "installd_dexopt_test"
    },
    {
      "name": "installd_otapreopt_test"
    },
    {
      "name": "installd_service_test"
    },
+2 −124
Original line number Diff line number Diff line
@@ -60,7 +60,6 @@
#include "globals.h"
#include "installd_constants.h"
#include "installd_deps.h"
#include "otapreopt_utils.h"
#include "restorable_file.h"
#include "run_dex2oat.h"
#include "unique_file.h"
@@ -2301,130 +2300,9 @@ bool hash_secondary_dex_file(const std::string& dex_path, const std::string& pkg
    return wait_child_with_timeout(pid, kShortTimeoutMs) == 0;
}

// Helper for move_ab, so that we can have common failure-case cleanup.
static bool unlink_and_rename(const char* from, const char* to) {
    // Check whether "from" exists, and if so whether it's regular. If it is, unlink. Otherwise,
    // return a failure.
    struct stat s;
    if (stat(to, &s) == 0) {
        if (!S_ISREG(s.st_mode)) {
            LOG(ERROR) << from << " is not a regular file to replace for A/B.";
bool move_ab(const char*, const char*, const char*) {
    return false;
}
        if (unlink(to) != 0) {
            LOG(ERROR) << "Could not unlink " << to << " to move A/B.";
            return false;
        }
    } else {
        // This may be a permission problem. We could investigate the error code, but we'll just
        // let the rename failure do the work for us.
    }

    // Try to rename "to" to "from."
    if (rename(from, to) != 0) {
        PLOG(ERROR) << "Could not rename " << from << " to " << to;
        return false;
    }
    return true;
}

// Move/rename a B artifact (from) to an A artifact (to).
static bool move_ab_path(const std::string& b_path, const std::string& a_path) {
    // Check whether B exists.
    {
        struct stat s;
        if (stat(b_path.c_str(), &s) != 0) {
            // Ignore for now. The service calling this isn't smart enough to
            // understand lack of artifacts at the moment.
            LOG(VERBOSE) << "A/B artifact " << b_path << " does not exist!";
            return false;
        }
        if (!S_ISREG(s.st_mode)) {
            LOG(ERROR) << "A/B artifact " << b_path << " is not a regular file.";
            // Try to unlink, but swallow errors.
            unlink(b_path.c_str());
            return false;
        }
    }

    // Rename B to A.
    if (!unlink_and_rename(b_path.c_str(), a_path.c_str())) {
        // Delete the b_path so we don't try again (or fail earlier).
        if (unlink(b_path.c_str()) != 0) {
            PLOG(ERROR) << "Could not unlink " << b_path;
        }

        return false;
    }

    return true;
}

bool move_ab(const char* apk_path, const char* instruction_set, const char* oat_dir) {
    // Get the current slot suffix. No suffix, no A/B.
    const std::string slot_suffix = GetProperty("ro.boot.slot_suffix", "");
    if (slot_suffix.empty()) {
        return false;
    }

    if (!ValidateTargetSlotSuffix(slot_suffix)) {
        LOG(ERROR) << "Target slot suffix not legal: " << slot_suffix;
        return false;
    }

    // Validate other inputs.
    if (validate_apk_path(apk_path) != 0) {
        LOG(ERROR) << "Invalid apk_path: " << apk_path;
        return false;
    }
    if (validate_apk_path(oat_dir) != 0) {
        LOG(ERROR) << "Invalid oat_dir: " << oat_dir;
        return false;
    }

    char a_path[PKG_PATH_MAX];
    if (!calculate_oat_file_path(a_path, oat_dir, apk_path, instruction_set)) {
        return false;
    }
    const std::string a_vdex_path = create_vdex_filename(a_path);
    const std::string a_image_path = create_image_filename(a_path);

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

    bool success = true;
    if (move_ab_path(b_path, a_path)) {
        if (move_ab_path(b_vdex_path, a_vdex_path)) {
            // Note: we can live without an app image. As such, ignore failure to move the image file.
            //       If we decide to require the app image, or the app image being moved correctly,
            //       then change accordingly.
            constexpr bool kIgnoreAppImageFailure = true;

            if (!a_image_path.empty()) {
                if (!move_ab_path(b_image_path, a_image_path)) {
                    unlink(a_image_path.c_str());
                    if (!kIgnoreAppImageFailure) {
                        success = false;
                    }
                }
            }
        } else {
            // Cleanup: delete B image, ignore errors.
            unlink(b_image_path.c_str());
            success = false;
        }
    } else {
        // Cleanup: delete B image, ignore errors.
        unlink(b_vdex_path.c_str());
        unlink(b_image_path.c_str());
        success = false;
    }
    return success;
}

int64_t delete_odex(const char* apk_path, const char* instruction_set, const char* oat_dir) {
    // Delete the oat/odex file.

cmds/installd/file_parsing.h

deleted100644 → 0
+0 −65
Original line number Diff line number Diff line
/*
 * Copyright (C) 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef OTAPREOPT_FILE_PARSING_H_
#define OTAPREOPT_FILE_PARSING_H_

#include <fstream>
#include <functional>
#include <string_view>
#include "android-base/unique_fd.h"

namespace android {
namespace installd {

template<typename Func>
bool ParseFile(std::istream& input_stream, Func parse) {
    while (!input_stream.eof()) {
        // Read the next line.
        std::string line;
        getline(input_stream, line);

        // Is the line empty? Simplifies the next check.
        if (line.empty()) {
            continue;
        }

        // Is this a comment (starts with pound)?
        if (line[0] == '#') {
            continue;
        }

        if (!parse(line)) {
            return false;
        }
    }

    return true;
}

template<typename Func>
bool ParseFile(const std::string& str_file, Func parse) {
  std::ifstream ifs(str_file);
  if (!ifs.is_open()) {
    return false;
  }
  return ParseFile(ifs, parse);
}

}  // namespace installd
}  // namespace android

#endif  // OTAPREOPT_FILE_PARSING_H_
Loading