|
|
@ -27,6 +27,7 @@
|
|
|
|
#include <android-base/logging.h>
|
|
|
|
#include <android-base/logging.h>
|
|
|
|
#include <android-base/parseint.h>
|
|
|
|
#include <android-base/parseint.h>
|
|
|
|
#include <android-base/unique_fd.h>
|
|
|
|
#include <android-base/unique_fd.h>
|
|
|
|
|
|
|
|
#include <android/hardware/boot/1.0/IBootControl.h>
|
|
|
|
#include <cutils/android_reboot.h>
|
|
|
|
#include <cutils/android_reboot.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <fs_mgr.h>
|
|
|
|
#include <fs_mgr.h>
|
|
|
@ -35,6 +36,11 @@
|
|
|
|
#include <sys/mount.h>
|
|
|
|
#include <sys/mount.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
using android::hardware::hidl_string;
|
|
|
|
|
|
|
|
using android::hardware::boot::V1_0::BoolResult;
|
|
|
|
|
|
|
|
using android::hardware::boot::V1_0::IBootControl;
|
|
|
|
|
|
|
|
using android::hardware::boot::V1_0::Slot;
|
|
|
|
|
|
|
|
|
|
|
|
namespace android {
|
|
|
|
namespace android {
|
|
|
|
namespace vold {
|
|
|
|
namespace vold {
|
|
|
|
|
|
|
|
|
|
|
@ -61,6 +67,14 @@ bool setBowState(std::string const& block_device, std::string const& state) {
|
|
|
|
bool cp_startCheckpoint(int retry) {
|
|
|
|
bool cp_startCheckpoint(int retry) {
|
|
|
|
if (retry < -1) return false;
|
|
|
|
if (retry < -1) return false;
|
|
|
|
std::string content = std::to_string(retry);
|
|
|
|
std::string content = std::to_string(retry);
|
|
|
|
|
|
|
|
if (retry == -1) {
|
|
|
|
|
|
|
|
sp<IBootControl> module = IBootControl::getService();
|
|
|
|
|
|
|
|
if (module) {
|
|
|
|
|
|
|
|
std::string suffix;
|
|
|
|
|
|
|
|
auto cb = [&suffix](hidl_string s) { suffix = s; };
|
|
|
|
|
|
|
|
if (module->getSuffix(module->getCurrentSlot(), cb).isOk()) content += " " + suffix;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
return android::base::WriteStringToFile(content, kMetadataCPFile);
|
|
|
|
return android::base::WriteStringToFile(content, kMetadataCPFile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -100,19 +114,35 @@ void cp_abortChanges() {
|
|
|
|
android_reboot(ANDROID_RB_RESTART2, 0, nullptr);
|
|
|
|
android_reboot(ANDROID_RB_RESTART2, 0, nullptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool cp_needRollback(const std::string& id) {
|
|
|
|
bool cp_needsRollback() {
|
|
|
|
std::string content;
|
|
|
|
std::string content;
|
|
|
|
bool ret;
|
|
|
|
bool ret;
|
|
|
|
|
|
|
|
|
|
|
|
ret = android::base::ReadFileToString(kMetadataCPFile, &content);
|
|
|
|
ret = android::base::ReadFileToString(kMetadataCPFile, &content);
|
|
|
|
if (ret) return content == "0";
|
|
|
|
if (ret) {
|
|
|
|
|
|
|
|
if (content == "0") return true;
|
|
|
|
|
|
|
|
if (content.substr(0, 3) == "-1 ") {
|
|
|
|
|
|
|
|
std::string oldSuffix = content.substr(3);
|
|
|
|
|
|
|
|
sp<IBootControl> module = IBootControl::getService();
|
|
|
|
|
|
|
|
std::string newSuffix;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (module) {
|
|
|
|
|
|
|
|
auto cb = [&newSuffix](hidl_string s) { newSuffix = s; };
|
|
|
|
|
|
|
|
module->getSuffix(module->getCurrentSlot(), cb);
|
|
|
|
|
|
|
|
if (oldSuffix == newSuffix) return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool cp_needsCheckpoint(void) {
|
|
|
|
bool cp_needsCheckpoint(void) {
|
|
|
|
bool ret;
|
|
|
|
bool ret;
|
|
|
|
std::string content;
|
|
|
|
std::string content;
|
|
|
|
|
|
|
|
sp<IBootControl> module = IBootControl::getService();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (module && module->isSlotMarkedSuccessful(module->getCurrentSlot()) == BoolResult::FALSE)
|
|
|
|
|
|
|
|
return true;
|
|
|
|
ret = android::base::ReadFileToString(kMetadataCPFile, &content);
|
|
|
|
ret = android::base::ReadFileToString(kMetadataCPFile, &content);
|
|
|
|
if (ret) return content != "0";
|
|
|
|
if (ret) return content != "0";
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
@ -294,8 +324,9 @@ bool cp_markBootAttempt() {
|
|
|
|
std::string oldContent, newContent;
|
|
|
|
std::string oldContent, newContent;
|
|
|
|
int retry = 0;
|
|
|
|
int retry = 0;
|
|
|
|
if (!android::base::ReadFileToString(kMetadataCPFile, &oldContent)) return false;
|
|
|
|
if (!android::base::ReadFileToString(kMetadataCPFile, &oldContent)) return false;
|
|
|
|
|
|
|
|
std::string retryContent = oldContent.substr(0, oldContent.find_first_of(" "));
|
|
|
|
|
|
|
|
|
|
|
|
if (!android::base::ParseInt(oldContent, &retry)) return false;
|
|
|
|
if (!android::base::ParseInt(retryContent, &retry)) return false;
|
|
|
|
if (retry > 0) retry--;
|
|
|
|
if (retry > 0) retry--;
|
|
|
|
|
|
|
|
|
|
|
|
newContent = std::to_string(retry);
|
|
|
|
newContent = std::to_string(retry);
|
|
|
|