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

Commit 30b3d9e6 authored by Akilesh Kailash's avatar Akilesh Kailash Committed by Gerrit Code Review
Browse files

Merge changes I6826b287,Ia8e6db89 into main

* changes:
  Skip tests if vendor partition is on Android S
  libsnapshot: Address GRF config when updating from Android S config
parents d9095707 69062493
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -30,6 +30,8 @@
#include <storage_literals/storage_literals.h>
#include <update_engine/update_metadata.pb.h>

#include "utility.h"

namespace android {
namespace snapshot {

@@ -234,5 +236,21 @@ bool IsVirtualAbEnabled();

#define RETURN_IF_NON_VIRTUAL_AB() RETURN_IF_NON_VIRTUAL_AB_MSG("")

#define SKIP_IF_VENDOR_ON_ANDROID_S()                                        \
    do {                                                                     \
        if (IsVendorFromAndroid12())                                         \
            GTEST_SKIP() << "Skip test as Vendor partition is on Android S"; \
    } while (0)

#define RETURN_IF_VENDOR_ON_ANDROID_S_MSG(msg) \
    do {                                       \
        if (IsVendorFromAndroid12()) {         \
            std::cerr << (msg);                \
            return;                            \
        }                                      \
    } while (0)

#define RETURN_IF_VENDOR_ON_ANDROID_S() RETURN_IF_VENDOR_ON_ANDROID_S_MSG("")

}  // namespace snapshot
}  // namespace android
+36 −9
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@
#include <sys/file.h>
#include <sys/types.h>
#include <sys/unistd.h>
#include <sys/xattr.h>

#include <chrono>
#include <filesystem>
@@ -91,6 +92,8 @@ static constexpr char kBootIndicatorPath[] = "/metadata/ota/snapshot-boot";
static constexpr char kRollbackIndicatorPath[] = "/metadata/ota/rollback-indicator";
static constexpr char kSnapuserdFromSystem[] = "/metadata/ota/snapuserd-from-system";
static constexpr auto kUpdateStateCheckInterval = 2s;
static constexpr char kOtaFileContext[] = "u:object_r:ota_metadata_file:s0";

/*
 * The readahead size is set to 32kb so that
 * there is no significant memory pressure (/proc/pressure/memory) during boot.
@@ -2135,6 +2138,24 @@ bool SnapshotManager::MarkSnapuserdFromSystem() {
        PLOG(ERROR) << "Unable to write to vendor update path: " << path;
        return false;
    }

    unique_fd fd(open(path.c_str(), O_PATH));
    if (fd < 0) {
        PLOG(ERROR) << "Failed to open file: " << path;
        return false;
    }

    /*
     * This function is invoked by first stage init and hence we need to
     * explicitly set the correct selinux label for this file as update_engine
     * will try to remove this file later on once the snapshot merge is
     * complete.
     */
    if (fsetxattr(fd.get(), XATTR_NAME_SELINUX, kOtaFileContext, strlen(kOtaFileContext) + 1, 0) <
        0) {
        PLOG(ERROR) << "fsetxattr for the path: " << path << " failed";
    }

    return true;
}

@@ -2185,18 +2206,24 @@ bool SnapshotManager::MarkSnapuserdFromSystem() {
 *
 */
bool SnapshotManager::IsLegacySnapuserdPostReboot() {
    if (is_legacy_snapuserd_.has_value() && is_legacy_snapuserd_.value() == true) {
    auto slot = GetCurrentSlot();
    if (slot == Slot::Target) {
            // If this marker is present, then daemon can handle userspace
            // snapshots; also, it indicates that the vendor partition was
            // updated from Android 12.
        /*
            If this marker is present, the daemon can handle userspace snapshots.
            During post-OTA reboot, this implies that the vendor partition is
            Android 13 or higher. If the snapshots were created on an
            Android 12 vendor, this means the vendor partition has been updated.
        */
        if (access(GetSnapuserdFromSystemPath().c_str(), F_OK) == 0) {
            is_snapshot_userspace_ = true;
            return false;
        }
        // If the marker isn't present and if the vendor is still in Android 12
        if (is_legacy_snapuserd_.has_value() && is_legacy_snapuserd_.value() == true) {
            return true;
        }
    }

    return false;
}

+7 −0
Original line number Diff line number Diff line
@@ -122,6 +122,7 @@ class SnapshotTest : public ::testing::Test {
        LOG(INFO) << "Starting test: " << test_name_;

        SKIP_IF_NON_VIRTUAL_AB();
        SKIP_IF_VENDOR_ON_ANDROID_S();

        SetupProperties();
        if (!DeviceSupportsMode()) {
@@ -168,6 +169,7 @@ class SnapshotTest : public ::testing::Test {

    void TearDown() override {
        RETURN_IF_NON_VIRTUAL_AB();
        RETURN_IF_VENDOR_ON_ANDROID_S();

        LOG(INFO) << "Tearing down SnapshotTest test: " << test_name_;

@@ -1015,6 +1017,7 @@ class SnapshotUpdateTest : public SnapshotTest {
  public:
    void SetUp() override {
        SKIP_IF_NON_VIRTUAL_AB();
        SKIP_IF_VENDOR_ON_ANDROID_S();

        SnapshotTest::SetUp();
        if (!image_manager_) {
@@ -1097,6 +1100,7 @@ class SnapshotUpdateTest : public SnapshotTest {
    }
    void TearDown() override {
        RETURN_IF_NON_VIRTUAL_AB();
        RETURN_IF_VENDOR_ON_ANDROID_S();

        LOG(INFO) << "Tearing down SnapshotUpdateTest test: " << test_name_;

@@ -2833,6 +2837,7 @@ void SnapshotTestEnvironment::SetUp() {
    // that is fixed, don't call GTEST_SKIP here, but instead call GTEST_SKIP in individual test
    // suites.
    RETURN_IF_NON_VIRTUAL_AB_MSG("Virtual A/B is not enabled, skipping global setup.\n");
    RETURN_IF_VENDOR_ON_ANDROID_S_MSG("Test not enabled for Vendor on Android S.\n");

    std::vector<std::string> paths = {
            // clang-format off
@@ -2887,6 +2892,8 @@ void SnapshotTestEnvironment::SetUp() {

void SnapshotTestEnvironment::TearDown() {
    RETURN_IF_NON_VIRTUAL_AB();
    RETURN_IF_VENDOR_ON_ANDROID_S();

    if (super_images_ != nullptr) {
        DeleteBackingImage(super_images_.get(), "fake-super");
    }