From: Tim Zimmermann Date: Tue, 2 Apr 2024 04:12:23 +0000 (+0200) Subject: ril: sehradiomanager: Restart when RILD died X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=b5e4ed61e1eeca861389e71a34de83bf8d80914e;p=GitHub%2FLineageOS%2Fandroid_hardware_samsung.git ril: sehradiomanager: Restart when RILD died Change-Id: Ie6864990b074f0b8c9ec40adf72276812dc346dc --- diff --git a/ril/sehradiomanager/sehradiomanager.cpp b/ril/sehradiomanager/sehradiomanager.cpp index 4cd7cdf..268a6e7 100644 --- a/ril/sehradiomanager/sehradiomanager.cpp +++ b/ril/sehradiomanager/sehradiomanager.cpp @@ -11,6 +11,8 @@ #include "hidl/SehRadioIndication.h" #include "hidl/SehRadioResponse.h" +#include + #include #include #include @@ -21,12 +23,17 @@ #include #include +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 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& who) override { onRILDDeath((void*)cookie); } +}; + +static const auto gHalDeathRecipient = AIBinder_DeathRecipient_new(onRILDDeath); +static const auto gHidlHalDeathRecipient = sp::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(content); auto samsungIndication = sp::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 << ")"; }