From e593aaa350f80296127f3e1231ca6e5e1c0baa9d Mon Sep 17 00:00:00 2001 From: chungkai Date: Wed, 6 Apr 2022 10:11:12 +0000 Subject: [PATCH] fix path for i2c peripheral device paths are changed when we enable parallel module loading and reorder the initializtaion of devices. Test: without avc denial on B3 when booting Bug: 227541760 Signed-off-by: chungkai Change-Id: Ibc9f9138d5becc26d9fbf0c2df43e55dddd40a97 --- powerstats/oriole/service.cpp | 18 ++++++++++++++++-- powerstats/raven/service.cpp | 19 ++++++++++++++++--- powerstats/slider/service.cpp | 17 ++++++++++++++++- 3 files changed, 48 insertions(+), 6 deletions(-) diff --git a/powerstats/oriole/service.cpp b/powerstats/oriole/service.cpp index 8331997..af936a3 100644 --- a/powerstats/oriole/service.cpp +++ b/powerstats/oriole/service.cpp @@ -26,6 +26,7 @@ #include #include #include +#include using aidl::android::hardware::power::stats::DisplayStateResidencyDataProvider; using aidl::android::hardware::power::stats::EnergyConsumerType; @@ -75,6 +76,8 @@ void addDisplay(std::shared_ptr p) { } int main() { + struct stat buffer; + LOG(INFO) << "Pixel PowerStats HAL AIDL Service is starting."; // single thread @@ -84,8 +87,19 @@ int main() { addGs101CommonDataProviders(p); addDisplay(p); - addNFC(p, "/sys/devices/platform/10960000.hsi2c/i2c-3/i2c-st21nfc/power_stats"); - + if (!stat("/sys/devices/platform/10960000.hsi2c/i2c-3/i2c-st21nfc/power_stats", &buffer)) { + addNFC(p, "/sys/devices/platform/10960000.hsi2c/i2c-3/i2c-st21nfc/power_stats"); + } else if (!stat("/sys/devices/platform/10960000.hsi2c/i2c-4/i2c-st21nfc/power_stats", &buffer)) { + addNFC(p, "/sys/devices/platform/10960000.hsi2c/i2c-4/i2c-st21nfc/power_stats"); + } else if (!stat("/sys/devices/platform/10960000.hsi2c/i2c-5/i2c-st21nfc/power_stats", &buffer)) { + addNFC(p, "/sys/devices/platform/10960000.hsi2c/i2c-5/i2c-st21nfc/power_stats"); + } else if (!stat("/sys/devices/platform/10960000.hsi2c/i2c-6/i2c-st21nfc/power_stats", &buffer)) { + addNFC(p, "/sys/devices/platform/10960000.hsi2c/i2c-6/i2c-st21nfc/power_stats"); + } else if (!stat("/sys/devices/platform/10960000.hsi2c/i2c-7/i2c-st21nfc/power_stats", &buffer)) { + addNFC(p, "/sys/devices/platform/10960000.hsi2c/i2c-7/i2c-st21nfc/power_stats"); + } else { + addNFC(p, "/sys/devices/platform/10960000.hsi2c/i2c-8/i2c-st21nfc/power_stats"); + } const std::string instance = std::string() + PowerStats::descriptor + "/default"; binder_status_t status = AServiceManager_addService(p->asBinder().get(), instance.c_str()); LOG_ALWAYS_FATAL_IF(status != STATUS_OK); diff --git a/powerstats/raven/service.cpp b/powerstats/raven/service.cpp index 579efa1..10bf17e 100644 --- a/powerstats/raven/service.cpp +++ b/powerstats/raven/service.cpp @@ -27,6 +27,7 @@ #include #include #include +#include using aidl::android::hardware::power::stats::DisplayStateResidencyDataProvider; using aidl::android::hardware::power::stats::EnergyConsumerType; @@ -117,6 +118,8 @@ void addUwb(std::shared_ptr p) { } int main() { + struct stat buffer; + LOG(INFO) << "Pixel PowerStats HAL AIDL Service is starting."; // single thread @@ -126,9 +129,19 @@ int main() { addGs101CommonDataProviders(p); addDisplay(p); - addNFC(p, "/sys/devices/platform/10960000.hsi2c/i2c-4/i2c-st21nfc/power_stats"); - addUwb(p); - + if (!stat("/sys/devices/platform/10960000.hsi2c/i2c-3/i2c-st21nfc/power_stats", &buffer)) { + addNFC(p, "/sys/devices/platform/10960000.hsi2c/i2c-3/i2c-st21nfc/power_stats"); + } else if (!stat("/sys/devices/platform/10960000.hsi2c/i2c-4/i2c-st21nfc/power_stats", &buffer)) { + addNFC(p, "/sys/devices/platform/10960000.hsi2c/i2c-4/i2c-st21nfc/power_stats"); + } else if (!stat("/sys/devices/platform/10960000.hsi2c/i2c-5/i2c-st21nfc/power_stats", &buffer)) { + addNFC(p, "/sys/devices/platform/10960000.hsi2c/i2c-5/i2c-st21nfc/power_stats"); + } else if (!stat("/sys/devices/platform/10960000.hsi2c/i2c-6/i2c-st21nfc/power_stats", &buffer)) { + addNFC(p, "/sys/devices/platform/10960000.hsi2c/i2c-6/i2c-st21nfc/power_stats"); + } else if (!stat("/sys/devices/platform/10960000.hsi2c/i2c-7/i2c-st21nfc/power_stats", &buffer)) { + addNFC(p, "/sys/devices/platform/10960000.hsi2c/i2c-7/i2c-st21nfc/power_stats"); + } else { + addNFC(p, "/sys/devices/platform/10960000.hsi2c/i2c-8/i2c-st21nfc/power_stats"); + } const std::string instance = std::string() + PowerStats::descriptor + "/default"; binder_status_t status = AServiceManager_addService(p->asBinder().get(), instance.c_str()); LOG_ALWAYS_FATAL_IF(status != STATUS_OK); diff --git a/powerstats/slider/service.cpp b/powerstats/slider/service.cpp index 5fe5332..6969cc0 100644 --- a/powerstats/slider/service.cpp +++ b/powerstats/slider/service.cpp @@ -26,6 +26,7 @@ #include #include #include +#include using aidl::android::hardware::power::stats::DisplayStateResidencyDataProvider; using aidl::android::hardware::power::stats::EnergyConsumerType; @@ -58,6 +59,8 @@ void addDisplay(std::shared_ptr p) { } int main() { + struct stat buffer; + LOG(INFO) << "Pixel PowerStats HAL AIDL Service is starting."; // single thread @@ -67,7 +70,19 @@ int main() { addGs101CommonDataProviders(p); addDisplay(p); - + if (!stat("/sys/devices/platform/10960000.hsi2c/i2c-3/i2c-st21nfc/power_stats", &buffer)) { + addNFC(p, "/sys/devices/platform/10960000.hsi2c/i2c-3/i2c-st21nfc/power_stats"); + } else if (!stat("/sys/devices/platform/10960000.hsi2c/i2c-4/i2c-st21nfc/power_stats", &buffer)) { + addNFC(p, "/sys/devices/platform/10960000.hsi2c/i2c-4/i2c-st21nfc/power_stats"); + } else if (!stat("/sys/devices/platform/10960000.hsi2c/i2c-5/i2c-st21nfc/power_stats", &buffer)) { + addNFC(p, "/sys/devices/platform/10960000.hsi2c/i2c-5/i2c-st21nfc/power_stats"); + } else if (!stat("/sys/devices/platform/10960000.hsi2c/i2c-6/i2c-st21nfc/power_stats", &buffer)) { + addNFC(p, "/sys/devices/platform/10960000.hsi2c/i2c-6/i2c-st21nfc/power_stats"); + } else if (!stat("/sys/devices/platform/10960000.hsi2c/i2c-7/i2c-st21nfc/power_stats", &buffer)) { + addNFC(p, "/sys/devices/platform/10960000.hsi2c/i2c-7/i2c-st21nfc/power_stats"); + } else { + addNFC(p, "/sys/devices/platform/10960000.hsi2c/i2c-8/i2c-st21nfc/power_stats"); + } const std::string instance = std::string() + PowerStats::descriptor + "/default"; binder_status_t status = AServiceManager_addService(p->asBinder().get(), instance.c_str()); LOG_ALWAYS_FATAL_IF(status != STATUS_OK);