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

Commit 1b76cb48 authored by Akilesh Kailash's avatar Akilesh Kailash
Browse files

libsnapshot: Address GRF config when updating from Android S config



Bug: 333854394
Test: 1)S+U > V+V , FULL OTA pass
2)S+U > S+V, FULL OTA pass
Change-Id: Ia8e6db89c3395930856ace8940424e60cae92375
Signed-off-by: default avatarAkilesh Kailash <akailash@google.com>
parent 007224d5
Loading
Loading
Loading
Loading
+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;
}