diff options
author | David Anderson <dvander@google.com> | 2018-08-08 17:58:56 -0700 |
---|---|---|
committer | David Anderson <dvander@google.com> | 2018-08-08 18:24:09 -0700 |
commit | 856b7ecbb6625fc4bae7dfe246e585bbc2d0f1e4 (patch) | |
tree | 9b7e37bdf69031c91c4afab6a188cc404dd0a656 /fastboot/device/variables.cpp | |
parent | 7b1d163cb8a482c94b61a798d510c77e7f675945 (diff) |
fastbootd: Allow returning errors from getvar handlers.
Currently a few getvar handlers will return invalid strings when an
error occurs. This change allows those handlers to instead send a proper
failure message.
Bug: 78793464
Test: N/A
Change-Id: I7ff7d036c1e6fb0a3d700ecf21b1103ab77278d2
Diffstat (limited to 'fastboot/device/variables.cpp')
-rw-r--r-- | fastboot/device/variables.cpp | 79 |
1 files changed, 42 insertions, 37 deletions
diff --git a/fastboot/device/variables.cpp b/fastboot/device/variables.cpp index 153ab9274..33f7f74bd 100644 --- a/fastboot/device/variables.cpp +++ b/fastboot/device/variables.cpp @@ -32,91 +32,96 @@ using ::android::hardware::boot::V1_0::Slot; constexpr int kMaxDownloadSizeDefault = 0x20000000; constexpr char kFastbootProtocolVersion[] = "0.4"; -std::string GetVersion(FastbootDevice* /* device */, const std::vector<std::string>& /* args */) { - return kFastbootProtocolVersion; +bool GetVersion(FastbootDevice* device, const std::vector<std::string>& /* args */) { + return device->WriteOkay(kFastbootProtocolVersion); } -std::string GetBootloaderVersion(FastbootDevice* /* device */, - const std::vector<std::string>& /* args */) { - return android::base::GetProperty("ro.bootloader", ""); +bool GetBootloaderVersion(FastbootDevice* device, const std::vector<std::string>& /* args */) { + return device->WriteOkay(android::base::GetProperty("ro.bootloader", "")); } -std::string GetBasebandVersion(FastbootDevice* /* device */, - const std::vector<std::string>& /* args */) { - return android::base::GetProperty("ro.build.expect.baseband", ""); +bool GetBasebandVersion(FastbootDevice* device, const std::vector<std::string>& /* args */) { + return device->WriteOkay(android::base::GetProperty("ro.build.expect.baseband", "")); } -std::string GetProduct(FastbootDevice* /* device */, const std::vector<std::string>& /* args */) { - return android::base::GetProperty("ro.product.device", ""); +bool GetProduct(FastbootDevice* device, const std::vector<std::string>& /* args */) { + return device->WriteOkay(android::base::GetProperty("ro.product.device", "")); } -std::string GetSerial(FastbootDevice* /* device */, const std::vector<std::string>& /* args */) { - return android::base::GetProperty("ro.serialno", ""); +bool GetSerial(FastbootDevice* device, const std::vector<std::string>& /* args */) { + return device->WriteOkay(android::base::GetProperty("ro.serialno", "")); } -std::string GetSecure(FastbootDevice* /* device */, const std::vector<std::string>& /* args */) { - return android::base::GetBoolProperty("ro.secure", "") ? "yes" : "no"; +bool GetSecure(FastbootDevice* device, const std::vector<std::string>& /* args */) { + return device->WriteOkay(android::base::GetBoolProperty("ro.secure", "") ? "yes" : "no"); } -std::string GetCurrentSlot(FastbootDevice* device, const std::vector<std::string>& /* args */) { +bool GetCurrentSlot(FastbootDevice* device, const std::vector<std::string>& /* args */) { std::string suffix = device->GetCurrentSlot(); - return suffix.size() == 2 ? suffix.substr(1) : suffix; + std::string slot = suffix.size() == 2 ? suffix.substr(1) : suffix; + return device->WriteOkay(slot); } -std::string GetSlotCount(FastbootDevice* device, const std::vector<std::string>& /* args */) { +bool GetSlotCount(FastbootDevice* device, const std::vector<std::string>& /* args */) { auto boot_control_hal = device->boot_control_hal(); if (!boot_control_hal) { return "0"; } - return std::to_string(boot_control_hal->getNumberSlots()); + return device->WriteOkay(std::to_string(boot_control_hal->getNumberSlots())); } -std::string GetSlotSuccessful(FastbootDevice* device, const std::vector<std::string>& args) { +bool GetSlotSuccessful(FastbootDevice* device, const std::vector<std::string>& args) { if (args.empty()) { - return "no"; + return device->WriteFail("Missing argument"); } Slot slot; if (!GetSlotNumber(args[0], &slot)) { - return "no"; + return device->WriteFail("Invalid slot"); } auto boot_control_hal = device->boot_control_hal(); if (!boot_control_hal) { - return "no"; + return device->WriteFail("Device has no slots"); } - return boot_control_hal->isSlotMarkedSuccessful(slot) == BoolResult::TRUE ? "yes" : "no"; + if (boot_control_hal->isSlotMarkedSuccessful(slot) != BoolResult::TRUE) { + return device->WriteOkay("no"); + } + return device->WriteOkay("yes"); } -std::string GetSlotUnbootable(FastbootDevice* device, const std::vector<std::string>& args) { +bool GetSlotUnbootable(FastbootDevice* device, const std::vector<std::string>& args) { if (args.empty()) { - return "no"; + return device->WriteFail("Missing argument"); } Slot slot; if (!GetSlotNumber(args[0], &slot)) { - return "no"; + return device->WriteFail("Invalid slot"); } auto boot_control_hal = device->boot_control_hal(); if (!boot_control_hal) { - return "no"; + return device->WriteFail("Device has no slots"); + } + if (boot_control_hal->isSlotBootable(slot) != BoolResult::TRUE) { + return device->WriteOkay("yes"); } - return boot_control_hal->isSlotBootable(slot) == BoolResult::TRUE ? "no" : "yes"; + return device->WriteOkay("no"); } -std::string GetMaxDownloadSize(FastbootDevice* /* device */, - const std::vector<std::string>& /* args */) { - return std::to_string(kMaxDownloadSizeDefault); +bool GetMaxDownloadSize(FastbootDevice* device, const std::vector<std::string>& /* args */) { + return device->WriteOkay(std::to_string(kMaxDownloadSizeDefault)); } -std::string GetUnlocked(FastbootDevice* /* device */, const std::vector<std::string>& /* args */) { - return "yes"; +bool GetUnlocked(FastbootDevice* device, const std::vector<std::string>& /* args */) { + return device->WriteOkay("yes"); } -std::string GetHasSlot(FastbootDevice* device, const std::vector<std::string>& args) { +bool GetHasSlot(FastbootDevice* device, const std::vector<std::string>& args) { if (args.empty()) { - return "no"; + return device->WriteFail("Missing argument"); } std::string slot_suffix = device->GetCurrentSlot(); if (slot_suffix.empty()) { - return "no"; + return device->WriteFail("Invalid slot"); } - return args[0] == "userdata" ? "no" : "yes"; + std::string result = (args[0] == "userdata" ? "no" : "yes"); + return device->WriteOkay(result); } |