summaryrefslogtreecommitdiff
path: root/fastboot/device/variables.cpp
diff options
context:
space:
mode:
authorDavid Anderson <dvander@google.com>2018-09-04 19:45:39 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2018-09-04 19:45:39 +0000
commit304308ca3f9903674db9afda6b0dfbdf9c0ba672 (patch)
tree9e55d729e2177d28df7a92e43e8e4977a51a992d /fastboot/device/variables.cpp
parentd230bcf4b05d785b43bbcfa1e6c4aef6c6fb9530 (diff)
parent1fb3fd72428569fb6be8e7c13180d3dad139076d (diff)
Merge "fastbootd: Refactor for getvar all."
Diffstat (limited to 'fastboot/device/variables.cpp')
-rw-r--r--fastboot/device/variables.cpp151
1 files changed, 100 insertions, 51 deletions
diff --git a/fastboot/device/variables.cpp b/fastboot/device/variables.cpp
index 65cfea327..8eeda98f7 100644
--- a/fastboot/device/variables.cpp
+++ b/fastboot/device/variables.cpp
@@ -35,141 +35,190 @@ using ::android::hardware::boot::V1_0::Slot;
constexpr int kMaxDownloadSizeDefault = 0x20000000;
constexpr char kFastbootProtocolVersion[] = "0.4";
-bool GetVersion(FastbootDevice* device, const std::vector<std::string>& /* args */) {
- return device->WriteOkay(kFastbootProtocolVersion);
+bool GetVersion(FastbootDevice* /* device */, const std::vector<std::string>& /* args */,
+ std::string* message) {
+ *message = kFastbootProtocolVersion;
+ return true;
}
-bool GetBootloaderVersion(FastbootDevice* device, const std::vector<std::string>& /* args */) {
- return device->WriteOkay(android::base::GetProperty("ro.bootloader", ""));
+bool GetBootloaderVersion(FastbootDevice* /* device */, const std::vector<std::string>& /* args */,
+ std::string* message) {
+ *message = android::base::GetProperty("ro.bootloader", "");
+ return true;
}
-bool GetBasebandVersion(FastbootDevice* device, const std::vector<std::string>& /* args */) {
- return device->WriteOkay(android::base::GetProperty("ro.build.expect.baseband", ""));
+bool GetBasebandVersion(FastbootDevice* /* device */, const std::vector<std::string>& /* args */,
+ std::string* message) {
+ *message = android::base::GetProperty("ro.build.expect.baseband", "");
+ return true;
}
-bool GetProduct(FastbootDevice* device, const std::vector<std::string>& /* args */) {
- return device->WriteOkay(android::base::GetProperty("ro.product.device", ""));
+bool GetProduct(FastbootDevice* /* device */, const std::vector<std::string>& /* args */,
+ std::string* message) {
+ *message = android::base::GetProperty("ro.product.device", "");
+ return true;
}
-bool GetSerial(FastbootDevice* device, const std::vector<std::string>& /* args */) {
- return device->WriteOkay(android::base::GetProperty("ro.serialno", ""));
+bool GetSerial(FastbootDevice* /* device */, const std::vector<std::string>& /* args */,
+ std::string* message) {
+ *message = android::base::GetProperty("ro.serialno", "");
+ return true;
}
-bool GetSecure(FastbootDevice* device, const std::vector<std::string>& /* args */) {
- return device->WriteOkay(android::base::GetBoolProperty("ro.secure", "") ? "yes" : "no");
+bool GetSecure(FastbootDevice* /* device */, const std::vector<std::string>& /* args */,
+ std::string* message) {
+ *message = android::base::GetBoolProperty("ro.secure", "") ? "yes" : "no";
+ return true;
}
-bool GetCurrentSlot(FastbootDevice* device, const std::vector<std::string>& /* args */) {
+bool GetCurrentSlot(FastbootDevice* device, const std::vector<std::string>& /* args */,
+ std::string* message) {
std::string suffix = device->GetCurrentSlot();
- std::string slot = suffix.size() == 2 ? suffix.substr(1) : suffix;
- return device->WriteOkay(slot);
+ *message = suffix.size() == 2 ? suffix.substr(1) : suffix;
+ return true;
}
-bool GetSlotCount(FastbootDevice* device, const std::vector<std::string>& /* args */) {
+bool GetSlotCount(FastbootDevice* device, const std::vector<std::string>& /* args */,
+ std::string* message) {
auto boot_control_hal = device->boot_control_hal();
if (!boot_control_hal) {
- return "0";
+ *message = "0";
+ } else {
+ *message = std::to_string(boot_control_hal->getNumberSlots());
}
- return device->WriteOkay(std::to_string(boot_control_hal->getNumberSlots()));
+ return true;
}
-bool GetSlotSuccessful(FastbootDevice* device, const std::vector<std::string>& args) {
+bool GetSlotSuccessful(FastbootDevice* device, const std::vector<std::string>& args,
+ std::string* message) {
if (args.empty()) {
- return device->WriteFail("Missing argument");
+ *message = "Missing argument";
+ return false;
}
Slot slot;
if (!GetSlotNumber(args[0], &slot)) {
- return device->WriteFail("Invalid slot");
+ *message = "Invalid slot";
+ return false;
}
auto boot_control_hal = device->boot_control_hal();
if (!boot_control_hal) {
- return device->WriteFail("Device has no slots");
+ *message = "Device has no slots";
+ return false;
}
if (boot_control_hal->isSlotMarkedSuccessful(slot) != BoolResult::TRUE) {
- return device->WriteOkay("no");
+ *message = "no";
+ } else {
+ *message = "yes";
}
- return device->WriteOkay("yes");
+ return true;
}
-bool GetSlotUnbootable(FastbootDevice* device, const std::vector<std::string>& args) {
+bool GetSlotUnbootable(FastbootDevice* device, const std::vector<std::string>& args,
+ std::string* message) {
if (args.empty()) {
- return device->WriteFail("Missing argument");
+ *message = "Missing argument";
+ return false;
}
Slot slot;
if (!GetSlotNumber(args[0], &slot)) {
- return device->WriteFail("Invalid slot");
+ *message = "Invalid slot";
+ return false;
}
auto boot_control_hal = device->boot_control_hal();
if (!boot_control_hal) {
- return device->WriteFail("Device has no slots");
+ *message = "Device has no slots";
+ return false;
}
if (boot_control_hal->isSlotBootable(slot) != BoolResult::TRUE) {
- return device->WriteOkay("yes");
+ *message = "yes";
+ } else {
+ *message = "no";
}
- return device->WriteOkay("no");
+ return true;
}
-bool GetMaxDownloadSize(FastbootDevice* device, const std::vector<std::string>& /* args */) {
- return device->WriteOkay(std::to_string(kMaxDownloadSizeDefault));
+bool GetMaxDownloadSize(FastbootDevice* /* device */, const std::vector<std::string>& /* args */,
+ std::string* message) {
+ *message = std::to_string(kMaxDownloadSizeDefault);
+ return true;
}
-bool GetUnlocked(FastbootDevice* device, const std::vector<std::string>& /* args */) {
- return device->WriteOkay("yes");
+bool GetUnlocked(FastbootDevice* /* device */, const std::vector<std::string>& /* args */,
+ std::string* message) {
+ *message = "yes";
+ return true;
}
-bool GetHasSlot(FastbootDevice* device, const std::vector<std::string>& args) {
+bool GetHasSlot(FastbootDevice* device, const std::vector<std::string>& args,
+ std::string* message) {
if (args.empty()) {
- return device->WriteFail("Missing argument");
+ *message = "Missing argument";
+ return false;
}
std::string slot_suffix = device->GetCurrentSlot();
if (slot_suffix.empty()) {
- return device->WriteOkay("no");
+ *message = "no";
+ return true;
}
std::string partition_name = args[0] + slot_suffix;
if (FindPhysicalPartition(partition_name) ||
LogicalPartitionExists(partition_name, slot_suffix)) {
- return device->WriteOkay("yes");
+ *message = "yes";
+ } else {
+ *message = "no";
}
- return device->WriteOkay("no");
+ return true;
}
-bool GetPartitionSize(FastbootDevice* device, const std::vector<std::string>& args) {
+bool GetPartitionSize(FastbootDevice* device, const std::vector<std::string>& args,
+ std::string* message) {
if (args.size() < 1) {
- return device->WriteFail("Missing argument");
+ *message = "Missing argument";
+ return false;
}
// Zero-length partitions cannot be created through device-mapper, so we
// special case them here.
bool is_zero_length;
if (LogicalPartitionExists(args[0], device->GetCurrentSlot(), &is_zero_length) &&
is_zero_length) {
- return device->WriteOkay("0");
+ *message = "0";
+ return true;
}
// Otherwise, open the partition as normal.
PartitionHandle handle;
if (!OpenPartition(device, args[0], &handle)) {
- return device->WriteFail("Could not open partition");
+ *message = "Could not open partition";
+ return false;
}
uint64_t size = get_block_device_size(handle.fd());
- return device->WriteOkay(android::base::StringPrintf("%" PRIX64, size));
+ *message = android::base::StringPrintf("%" PRIX64, size);
+ return true;
}
-bool GetPartitionIsLogical(FastbootDevice* device, const std::vector<std::string>& args) {
+bool GetPartitionIsLogical(FastbootDevice* device, const std::vector<std::string>& args,
+ std::string* message) {
if (args.size() < 1) {
- return device->WriteFail("Missing argument");
+ *message = "Missing argument";
+ return false;
}
// Note: if a partition name is in both the GPT and the super partition, we
// return "true", to be consistent with prefering to flash logical partitions
// over physical ones.
std::string partition_name = args[0];
if (LogicalPartitionExists(partition_name, device->GetCurrentSlot())) {
- return device->WriteOkay("yes");
+ *message = "yes";
+ return true;
}
if (FindPhysicalPartition(partition_name)) {
- return device->WriteOkay("no");
+ *message = "no";
+ return true;
}
- return device->WriteFail("Partition not found");
+ *message = "Partition not found";
+ return false;
}
-bool GetIsUserspace(FastbootDevice* device, const std::vector<std::string>& /* args */) {
- return device->WriteOkay("yes");
+bool GetIsUserspace(FastbootDevice* /* device */, const std::vector<std::string>& /* args */,
+ std::string* message) {
+ *message = "yes";
+ return true;
}