ril: sehradiomanager: Add support for a config file
authorTim Zimmermann <tim@linux4.de>
Fri, 15 Mar 2024 04:58:09 +0000 (05:58 +0100)
committerJan Altensen (Stricted) <info@stricted.net>
Fri, 21 Jun 2024 04:02:30 +0000 (04:02 +0000)
Change-Id: Ia6a752932af1cc70c7ef75fd15573ec78629e9f7

ril/sehradiomanager/sehradiomanager.cpp

index 8472db8a80c597ea23af3d561357bc1f79301eb4..f9d3c99288768ec9067619c4ca1f0b16d9e2cfae 100644 (file)
@@ -9,15 +9,20 @@
 #include "SehRadioIndication.h"
 #include "SehRadioResponse.h"
 
+#include <android-base/file.h>
 #include <android-base/logging.h>
 #include <android-base/properties.h>
+#include <android-base/strings.h>
 #include <hidl/HidlTransportSupport.h>
 
 #include <vendor/samsung/hardware/radio/2.2/ISehRadio.h>
 
 using android::sp;
 using android::base::GetIntProperty;
+using android::base::ReadFileToString;
+using android::base::Split;
 using android::hardware::configureRpcThreadpool;
+using android::hardware::hidl_vec;
 using android::hardware::joinRpcThreadpool;
 
 using vendor::samsung::hardware::radio::V2_2::ISehRadio;
@@ -25,22 +30,42 @@ using vendor::samsung::hardware::radio::V2_2::SehVendorConfiguration;
 using vendor::samsung::hardware::radio::V2_2::implementation::SehRadioIndication;
 using vendor::samsung::hardware::radio::V2_2::implementation::SehRadioResponse;
 
+hidl_vec<SehVendorConfiguration> LoadConfiguration(std::string data) {
+    std::vector<SehVendorConfiguration> config;
+
+    for (std::string line : Split(data, "\n")) {
+        if (line == "\0") break;
+
+        std::vector<std::string> parts = Split(line, "=");
+        if (parts.size() == 2) {
+            config.push_back(SehVendorConfiguration(parts[0], parts[1]));
+            LOG(INFO) << line;
+        } else {
+            LOG(ERROR) << "Invalid data: " << line;
+        }
+    }
+
+    return hidl_vec<SehVendorConfiguration>(config);
+}
+
 int main() {
     int slotCount = GetIntProperty("ro.vendor.multisim.simslotcount", 1);
     configureRpcThreadpool(slotCount * 2 + 1, true);
 
+    std::string content;
+    if (!ReadFileToString("/vendor/etc/sehradiomanager.conf", &content)) {
+        LOG(WARNING) << "Could not read config, setting defaults";
+        content = "FW_READY=1";
+    }
+    auto config = LoadConfiguration(content);
+
     for (int slot = 1; slot <= slotCount; slot++) {
         auto samsungIndication = sp<SehRadioIndication>::make();
         auto samsungResponse = sp<SehRadioResponse>::make();
         auto svc = ISehRadio::getService("slot" + std::to_string(slot));
         svc->setResponseFunction(samsungResponse, samsungIndication);
-
-        SehVendorConfiguration arg;
-        arg.name = "FW_READY";
-        arg.value = "1";
-
-        svc->setVendorSpecificConfiguration(0x3232, {arg});
-        LOG(INFO) << "HIDL FW_READY done (slot" << slot << ")";
+        svc->setVendorSpecificConfiguration(0x3232, config);
+        LOG(INFO) << "Done (slot" << slot << ")";
     }
 
     joinRpcThreadpool();