From 09ae57bf02f30812a9d0fbb5dc394eb38b1c2edf Mon Sep 17 00:00:00 2001 From: Felix Beslmeisl <> Date: Tue, 6 Sep 2022 14:20:16 +0200 Subject: [PATCH 1/2] Further fix on slot change --- ota/phh-ota.cpp | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/ota/phh-ota.cpp b/ota/phh-ota.cpp index 0a4c7d5..9b25721 100644 --- a/ota/phh-ota.cpp +++ b/ota/phh-ota.cpp @@ -14,6 +14,17 @@ using namespace std::chrono_literals; using namespace std::string_literals; using android::fiemap::IImageManager; + +std::string getNextSlot() { + std::string current_slot; + std::string next_slot = "a"; + if(android::base::ReadFileToString("/metadata/phh/img", ¤t_slot) && + current_slot.c_str()[0] == 'a') { + next_slot = "b"; + } + return next_slot; +} + int main(int argc, char **argv) { mkdir("/metadata/gsi/phh", 0771); chown("/metadata/gsi/phh", 0, 1000); @@ -27,25 +38,13 @@ int main(int argc, char **argv) { return 0; } if(argc>=2 && strcmp(argv[1], "switch-slot") == 0) { - std::string current_slot; - std::string next_slot; - if(!android::base::ReadFileToString("/metadata/phh/img", ¤t_slot)) { - next_slot = "a"; - } else { - if(current_slot.c_str()[0] == 'a') - next_slot = "b"; - } + std::string next_slot = getNextSlot(); mkdir("/metadata/phh", 0700); android::base::WriteStringToFile(next_slot, "/metadata/phh/img"); return 0; } if(argc>=2 && strcmp(argv[1], "new-slot") == 0) { - std::string current_slot; - std::string next_slot = "a"; - if(android::base::ReadFileToString("/metadata/phh/img", ¤t_slot) && - current_slot.c_str()[0] == 'a') { - next_slot = "b"; - } + std::string next_slot = getNextSlot(); std::string imageName = "system_otaphh_"s + next_slot; From f6e059b8e44fc15634f62e1ab5722b8ba767fa84 Mon Sep 17 00:00:00 2001 From: Felix Beslmeisl Date: Sun, 18 Sep 2022 23:03:47 +0200 Subject: [PATCH 2/2] Fixed line indent --- ota/phh-ota.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ota/phh-ota.cpp b/ota/phh-ota.cpp index 9b25721..895a897 100644 --- a/ota/phh-ota.cpp +++ b/ota/phh-ota.cpp @@ -16,7 +16,7 @@ using android::fiemap::IImageManager; std::string getNextSlot() { - std::string current_slot; + std::string current_slot; std::string next_slot = "a"; if(android::base::ReadFileToString("/metadata/phh/img", ¤t_slot) && current_slot.c_str()[0] == 'a') {