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

Commit 7445be51 authored by David Anderson's avatar David Anderson Committed by Cherrypicker Worker
Browse files

snapuserd: Remove DaemonOps.

These are only used for a single switch statement. Just compare the
input strings instead.

Bug: 269361087
Test: builds, ota applies
Ignore-AOSP-First: cherry-pick from aosp
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:f84f9c319e5a05fa6bfed9730ea6b9d28407a84b)
Merged-In: Ib90ae55309ea99c181585c64ed2ac814e5ed6c72
Change-Id: Ib90ae55309ea99c181585c64ed2ac814e5ed6c72
parent 395edf84
Loading
Loading
Loading
Loading
+94 −124
Original line number Diff line number Diff line
@@ -45,22 +45,6 @@ using namespace std::string_literals;
using android::base::borrowed_fd;
using android::base::unique_fd;

DaemonOps UserSnapshotServer::Resolveop(std::string& input) {
    if (input == "init") return DaemonOps::INIT;
    if (input == "start") return DaemonOps::START;
    if (input == "stop") return DaemonOps::STOP;
    if (input == "query") return DaemonOps::QUERY;
    if (input == "delete") return DaemonOps::DELETE;
    if (input == "detach") return DaemonOps::DETACH;
    if (input == "supports") return DaemonOps::SUPPORTS;
    if (input == "initiate_merge") return DaemonOps::INITIATE;
    if (input == "merge_percent") return DaemonOps::PERCENTAGE;
    if (input == "getstatus") return DaemonOps::GETSTATUS;
    if (input == "update-verify") return DaemonOps::UPDATE_VERIFY;

    return DaemonOps::INVALID;
}

UserSnapshotServer::UserSnapshotServer() {
    terminating_ = false;
    handlers_ = std::make_unique<SnapshotHandlerManager>();
@@ -132,10 +116,9 @@ bool UserSnapshotServer::Receivemsg(android::base::borrowed_fd fd, const std::st

    std::vector<std::string> out;
    Parsemsg(str, delim, out);
    DaemonOps op = Resolveop(out[0]);

    switch (op) {
        case DaemonOps::INIT: {
    const auto& cmd = out[0];
    if (cmd == "init") {
        // Message format:
        // init,<misc_name>,<cow_device_path>,<backing_device>,<base_path_merge>
        //
@@ -152,8 +135,7 @@ bool UserSnapshotServer::Receivemsg(android::base::borrowed_fd fd, const std::st

        auto retval = "success," + std::to_string(handler->snapuserd()->GetNumSectors());
        return Sendmsg(fd, retval);
        }
        case DaemonOps::START: {
    } else if (cmd == "start") {
        // Message format:
        // start,<misc_name>
        //
@@ -167,8 +149,7 @@ bool UserSnapshotServer::Receivemsg(android::base::borrowed_fd fd, const std::st
            return Sendmsg(fd, "fail");
        }
        return Sendmsg(fd, "success");
        }
        case DaemonOps::STOP: {
    } else if (cmd == "stop") {
        // Message format: stop
        //
        // Stop all the threads gracefully and then shutdown the
@@ -176,8 +157,7 @@ bool UserSnapshotServer::Receivemsg(android::base::borrowed_fd fd, const std::st
        SetTerminating();
        ShutdownThreads();
        return true;
        }
        case DaemonOps::QUERY: {
    } else if (cmd == "query") {
        // Message format: query
        //
        // As part of transition, Second stage daemon will be
@@ -188,8 +168,7 @@ bool UserSnapshotServer::Receivemsg(android::base::borrowed_fd fd, const std::st
        // Second stage daemon is marked as active and hence will
        // be ready to receive control message.
        return Sendmsg(fd, GetDaemonStatus());
        }
        case DaemonOps::DELETE: {
    } else if (cmd == "delete") {
        // Message format:
        // delete,<misc_name>
        if (out.size() != 2) {
@@ -200,13 +179,11 @@ bool UserSnapshotServer::Receivemsg(android::base::borrowed_fd fd, const std::st
            return Sendmsg(fd, "fail");
        }
        return Sendmsg(fd, "success");
        }
        case DaemonOps::DETACH: {
    } else if (cmd == "detach") {
        handlers_->TerminateMergeThreads();
        terminating_ = true;
        return true;
        }
        case DaemonOps::SUPPORTS: {
    } else if (cmd == "supports") {
        if (out.size() != 2) {
            LOG(ERROR) << "Malformed supports message, " << out.size() << " parts";
            return Sendmsg(fd, "fail");
@@ -215,8 +192,7 @@ bool UserSnapshotServer::Receivemsg(android::base::borrowed_fd fd, const std::st
            return Sendmsg(fd, "success");
        }
        return Sendmsg(fd, "fail");
        }
        case DaemonOps::INITIATE: {
    } else if (cmd == "initiate_merge") {
        if (out.size() != 2) {
            LOG(ERROR) << "Malformed initiate-merge message, " << out.size() << " parts";
            return Sendmsg(fd, "fail");
@@ -228,13 +204,10 @@ bool UserSnapshotServer::Receivemsg(android::base::borrowed_fd fd, const std::st
            return Sendmsg(fd, "success");
        }
        return Sendmsg(fd, "fail");
        }
        case DaemonOps::PERCENTAGE: {
    } else if (cmd == "merge_percent") {
        double percentage = handlers_->GetMergePercentage();

        return Sendmsg(fd, std::to_string(percentage));
        }
        case DaemonOps::GETSTATUS: {
    } else if (cmd == "getstatus") {
        // Message format:
        // getstatus,<misc_name>
        if (out.size() != 2) {
@@ -246,20 +219,17 @@ bool UserSnapshotServer::Receivemsg(android::base::borrowed_fd fd, const std::st
            return Sendmsg(fd, "snapshot-merge-failed");
        }
        return Sendmsg(fd, status);
        }
        case DaemonOps::UPDATE_VERIFY: {
    } else if (cmd == "update-verify") {
        if (!handlers_->GetVerificationStatus()) {
            return Sendmsg(fd, "fail");
        }
        return Sendmsg(fd, "success");
        }
        default: {
    } else {
        LOG(ERROR) << "Received unknown message type from client";
        Sendmsg(fd, "fail");
        return false;
    }
}
}

bool UserSnapshotServer::Start(const std::string& socketname) {
    bool start_listening = true;
+0 −16
Original line number Diff line number Diff line
@@ -40,21 +40,6 @@ namespace snapshot {
static constexpr uint32_t kMaxPacketSize = 512;
static constexpr uint8_t kMaxMergeThreads = 2;

enum class DaemonOps {
    INIT,
    START,
    QUERY,
    STOP,
    DELETE,
    DETACH,
    SUPPORTS,
    INITIATE,
    PERCENTAGE,
    GETSTATUS,
    UPDATE_VERIFY,
    INVALID,
};

class UserSnapshotServer {
  private:
    android::base::unique_fd sockfd_;
@@ -76,7 +61,6 @@ class UserSnapshotServer {
    bool Receivemsg(android::base::borrowed_fd fd, const std::string& str);

    void ShutdownThreads();
    DaemonOps Resolveop(std::string& input);
    std::string GetDaemonStatus();
    void Parsemsg(std::string const& msg, const char delim, std::vector<std::string>& out);