Merge pull request #327 from febeslmeisl/ota-slot-change-fix

Ota slot change fix
This commit is contained in:
Pierre-Hugues HUSSON 2022-09-19 22:21:09 +02:00 committed by GitHub
commit 8bd41df06c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 14 deletions

View File

@ -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", &current_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", &current_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", &current_slot) &&
current_slot.c_str()[0] == 'a') {
next_slot = "b";
}
std::string next_slot = getNextSlot();
std::string imageName = "system_otaphh_"s + next_slot;