ril: sehradiomanager: Restart when RILD died
authorTim Zimmermann <tim@linux4.de>
Tue, 2 Apr 2024 04:12:23 +0000 (06:12 +0200)
committerJan Altensen (Stricted) <info@stricted.net>
Fri, 21 Jun 2024 04:02:30 +0000 (04:02 +0000)
Change-Id: Ie6864990b074f0b8c9ec40adf72276812dc346dc

ril/sehradiomanager/sehradiomanager.cpp

index 4cd7cdf0486e10723b007ec420e1737590805a96..268a6e7d4da7150663a0c9b51d63c7903bdc5626 100644 (file)
@@ -11,6 +11,8 @@
 #include "hidl/SehRadioIndication.h"
 #include "hidl/SehRadioResponse.h"
 
+#include <thread>
+
 #include <android-base/file.h>
 #include <android-base/logging.h>
 #include <android-base/properties.h>
 #include <aidl/vendor/samsung/hardware/radio/network/ISehRadioNetwork.h>
 #include <vendor/samsung/hardware/radio/2.2/ISehRadio.h>
 
+using namespace std::chrono_literals;
+
 using android::sp;
 using android::String16;
+using android::wp;
 using android::base::GetIntProperty;
 using android::base::ReadFileToString;
 using android::base::Split;
+using android::hardware::hidl_death_recipient;
 using android::hardware::hidl_vec;
+using android::hidl::base::V1_0::IBase;
 
 using aidl::vendor::samsung::hardware::radio::network::ISehRadioNetwork;
 using aidl::vendor::samsung::hardware::radio::network::implementation::SehRadioNetworkIndication;
@@ -57,6 +64,23 @@ std::vector<C> LoadConfiguration(std::string data) {
     return config;
 }
 
+bool died = false;
+void onRILDDeath(void* cookie) {
+    if (died) return;
+    died = true;
+
+    LOG(ERROR) << "SehRadio died, sleeping for 10s before restarting";
+    std::this_thread::sleep_for(10000ms);
+    exit(1);
+}
+
+struct RilHidlDeathRecipient : public hidl_death_recipient {
+    void serviceDied(uint64_t cookie, const wp<IBase>& who) override { onRILDDeath((void*)cookie); }
+};
+
+static const auto gHalDeathRecipient = AIBinder_DeathRecipient_new(onRILDDeath);
+static const auto gHidlHalDeathRecipient = sp<RilHidlDeathRecipient>::make();
+
 int main() {
     ABinderProcess_setThreadPoolMaxThreadCount(0);
     ABinderProcess_startThreadPool();
@@ -79,6 +103,8 @@ int main() {
                     ndk::SpAIBinder(AServiceManager_waitForService(aidlSvcName.c_str())));
             svc->setResponseFunctions(samsungResponse, samsungIndication);
             svc->setVendorSpecificConfiguration(0x4242, config);
+            AIBinder_linkToDeath(svc->asBinder().get(), gHalDeathRecipient, 0);
+            AIBinder_incStrong(svc->asBinder().get());
         } else {
             auto config = LoadConfiguration<SehVendorConfiguration>(content);
             auto samsungIndication = sp<SehRadioIndication>::make();
@@ -86,6 +112,8 @@ int main() {
             auto svc = ISehRadio::getService(slotName);
             svc->setResponseFunction(samsungResponse, samsungIndication);
             svc->setVendorSpecificConfiguration(0x3232, hidl_vec(config));
+            svc->linkToDeath(gHidlHalDeathRecipient, 0);
+            svc->incStrong(gHidlHalDeathRecipient.get());
         }
         LOG(INFO) << "Done (slot" << slot << ")";
     }