summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Bestas <mkbestas@lineageos.org>2022-05-11 20:43:25 +0300
committerSemavi Ulusoy <doc.divxm@gmail.com>2022-06-03 00:25:04 +0300
commit661f76b54703de6a74fd42e02a898ef8f04f0525 (patch)
tree0de8b5c9f7ed904c621930b9abc78315278d2610
parent502c7d55343b6a253f5fc6c5f8ab49709441279a (diff)
fastboot: Implement oem getprop commandHEADs12.1
Loosely adapted doOemCommand from pixel fastboot HAL. Test: fastboot oem getprop ro.boot.project_codename (bootloader) ro.boot.project_codename:lemonade OKAY [ 0.000s] Finished. Total time: 0.000s Change-Id: Ied18e52a793a2fab62bb6a01a713c1c421b634fa
-rw-r--r--fastboot/1.1-custom/Fastboot.cpp42
-rw-r--r--fastboot/1.1-custom/Fastboot.h2
2 files changed, 42 insertions, 2 deletions
diff --git a/fastboot/1.1-custom/Fastboot.cpp b/fastboot/1.1-custom/Fastboot.cpp
index 4515ef9..862fe31 100644
--- a/fastboot/1.1-custom/Fastboot.cpp
+++ b/fastboot/1.1-custom/Fastboot.cpp
@@ -16,12 +16,19 @@
#include "Fastboot.h"
+#include <unordered_map>
+
+#include <android-base/properties.h>
+#include <android-base/strings.h>
+
namespace android {
namespace hardware {
namespace fastboot {
namespace V1_1 {
namespace implementation {
+using OEMCommandHandler = std::function<Result(const std::vector<std::string>&)>;
+
// Methods from ::android::hardware::fastboot::V1_1::IFastboot follow.
Return<void> Fastboot::getPartitionType(const hidl_string& /* partitionName */,
getPartitionType_cb _hidl_cb) {
@@ -29,8 +36,39 @@ Return<void> Fastboot::getPartitionType(const hidl_string& /* partitionName */,
return Void();
}
-Return<void> Fastboot::doOemCommand(const hidl_string& /* oemCmdArgs */, doOemCommand_cb _hidl_cb) {
- _hidl_cb({Status::FAILURE_UNKNOWN, "Command not supported"});
+Result GetProp(const std::vector<std::string>& args) {
+ if (!args.size()) {
+ return { Status::INVALID_ARGUMENT, "Property unspecified" };
+ }
+
+ auto property = android::base::GetProperty(args[0], "");
+
+ if (!property.empty()) {
+ return { Status::SUCCESS, args[0] + ": " + property };
+ }
+
+ return { Status::FAILURE_UNKNOWN, "Unable to get property" };
+}
+
+Return<void> Fastboot::doOemCommand(const hidl_string& oemCmdArgs, doOemCommand_cb _hidl_cb) {
+ const std::unordered_map<std::string, OEMCommandHandler> kOEMCmdMap = {
+ {FB_OEM_GET_PROP, GetProp},
+ };
+
+ auto args = android::base::Split(oemCmdArgs, " ");
+ if (args.size() < 2) {
+ _hidl_cb({ Status::INVALID_ARGUMENT, "Invalid OEM command" });
+ return Void();
+ }
+
+ // args[0] will be "oem", args[1] will be the command name
+ auto cmd_handler = kOEMCmdMap.find(args[1]);
+ if (cmd_handler != kOEMCmdMap.end()) {
+ _hidl_cb(cmd_handler->second(std::vector<std::string>(args.begin() + 2, args.end())));
+ } else {
+ _hidl_cb({ Status::FAILURE_UNKNOWN, "Unknown OEM command" });
+ }
+
return Void();
}
diff --git a/fastboot/1.1-custom/Fastboot.h b/fastboot/1.1-custom/Fastboot.h
index 09b39c2..b07d0b7 100644
--- a/fastboot/1.1-custom/Fastboot.h
+++ b/fastboot/1.1-custom/Fastboot.h
@@ -24,6 +24,8 @@ namespace fastboot {
namespace V1_1 {
namespace implementation {
+#define FB_OEM_GET_PROP "getprop"
+
using ::android::hardware::hidl_string;
using ::android::hardware::Return;
using ::android::hardware::Void;