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 P10 when booting
Bug: 227541760
Signed-off-by: chungkai <chungkai@google.com>
Change-Id: Ia94bccdf479262e96210c2eda4794c2708e56861
This commit is contained in:
chungkai 2022-04-07 06:28:08 +00:00 committed by Chung-Kai (Michael) Mei
parent 9b7f753e57
commit c9cd788e18
3 changed files with 48 additions and 3 deletions

View file

@ -27,6 +27,7 @@
#include <android/binder_manager.h> #include <android/binder_manager.h>
#include <android/binder_process.h> #include <android/binder_process.h>
#include <log/log.h> #include <log/log.h>
#include <sys/stat.h>
using aidl::android::hardware::power::stats::DisplayStateResidencyDataProvider; using aidl::android::hardware::power::stats::DisplayStateResidencyDataProvider;
using aidl::android::hardware::power::stats::EnergyConsumerType; using aidl::android::hardware::power::stats::EnergyConsumerType;
@ -100,6 +101,8 @@ void addUwb(std::shared_ptr<PowerStats> p) {
} }
int main() { int main() {
struct stat buffer;
LOG(INFO) << "Pixel PowerStats HAL AIDL Service is starting."; LOG(INFO) << "Pixel PowerStats HAL AIDL Service is starting.";
// single thread // single thread
@ -110,8 +113,20 @@ int main() {
addGs201CommonDataProviders(p); addGs201CommonDataProviders(p);
addDisplay(p); addDisplay(p);
addUwb(p); addUwb(p);
addNFC(p, "/sys/devices/platform/10970000.hsi2c/i2c-4/i2c-st21nfc/power_stats");
if (!stat("/sys/devices/platform/10970000.hsi2c/i2c-3/i2c-st21nfc/power_stats", &buffer)) {
addNFC(p, "/sys/devices/platform/10970000.hsi2c/i2c-3/i2c-st21nfc/power_stats");
} else if (!stat("/sys/devices/platform/10970000.hsi2c/i2c-4/i2c-st21nfc/power_stats", &buffer)) {
addNFC(p, "/sys/devices/platform/10970000.hsi2c/i2c-4/i2c-st21nfc/power_stats");
} else if (!stat("/sys/devices/platform/10970000.hsi2c/i2c-5/i2c-st21nfc/power_stats", &buffer)) {
addNFC(p, "/sys/devices/platform/10970000.hsi2c/i2c-5/i2c-st21nfc/power_stats");
} else if (!stat("/sys/devices/platform/10970000.hsi2c/i2c-6/i2c-st21nfc/power_stats", &buffer)) {
addNFC(p, "/sys/devices/platform/10970000.hsi2c/i2c-6/i2c-st21nfc/power_stats");
} else if (!stat("/sys/devices/platform/10970000.hsi2c/i2c-7/i2c-st21nfc/power_stats", &buffer)) {
addNFC(p, "/sys/devices/platform/10970000.hsi2c/i2c-7/i2c-st21nfc/power_stats");
} else {
addNFC(p, "/sys/devices/platform/10970000.hsi2c/i2c-8/i2c-st21nfc/power_stats");
}
const std::string instance = std::string() + PowerStats::descriptor + "/default"; const std::string instance = std::string() + PowerStats::descriptor + "/default";
binder_status_t status = AServiceManager_addService(p->asBinder().get(), instance.c_str()); binder_status_t status = AServiceManager_addService(p->asBinder().get(), instance.c_str());
LOG_ALWAYS_FATAL_IF(status != STATUS_OK); LOG_ALWAYS_FATAL_IF(status != STATUS_OK);

View file

@ -26,6 +26,7 @@
#include <android/binder_manager.h> #include <android/binder_manager.h>
#include <android/binder_process.h> #include <android/binder_process.h>
#include <log/log.h> #include <log/log.h>
#include <sys/stat.h>
using aidl::android::hardware::power::stats::DisplayStateResidencyDataProvider; using aidl::android::hardware::power::stats::DisplayStateResidencyDataProvider;
using aidl::android::hardware::power::stats::EnergyConsumerType; using aidl::android::hardware::power::stats::EnergyConsumerType;
@ -57,6 +58,8 @@ void addDisplay(std::shared_ptr<PowerStats> p) {
} }
int main() { int main() {
struct stat buffer;
LOG(INFO) << "Pixel PowerStats HAL AIDL Service is starting."; LOG(INFO) << "Pixel PowerStats HAL AIDL Service is starting.";
// single thread // single thread
@ -66,8 +69,20 @@ int main() {
addGs201CommonDataProviders(p); addGs201CommonDataProviders(p);
addDisplay(p); addDisplay(p);
addNFC(p, "/sys/devices/platform/10970000.hsi2c/i2c-4/i2c-st21nfc/power_stats");
if (!stat("/sys/devices/platform/10970000.hsi2c/i2c-3/i2c-st21nfc/power_stats", &buffer)) {
addNFC(p, "/sys/devices/platform/10970000.hsi2c/i2c-3/i2c-st21nfc/power_stats");
} else if (!stat("/sys/devices/platform/10970000.hsi2c/i2c-4/i2c-st21nfc/power_stats", &buffer)) {
addNFC(p, "/sys/devices/platform/10970000.hsi2c/i2c-4/i2c-st21nfc/power_stats");
} else if (!stat("/sys/devices/platform/10970000.hsi2c/i2c-5/i2c-st21nfc/power_stats", &buffer)) {
addNFC(p, "/sys/devices/platform/10970000.hsi2c/i2c-5/i2c-st21nfc/power_stats");
} else if (!stat("/sys/devices/platform/10970000.hsi2c/i2c-6/i2c-st21nfc/power_stats", &buffer)) {
addNFC(p, "/sys/devices/platform/10970000.hsi2c/i2c-6/i2c-st21nfc/power_stats");
} else if (!stat("/sys/devices/platform/10970000.hsi2c/i2c-7/i2c-st21nfc/power_stats", &buffer)) {
addNFC(p, "/sys/devices/platform/10970000.hsi2c/i2c-7/i2c-st21nfc/power_stats");
} else {
addNFC(p, "/sys/devices/platform/10970000.hsi2c/i2c-8/i2c-st21nfc/power_stats");
}
const std::string instance = std::string() + PowerStats::descriptor + "/default"; const std::string instance = std::string() + PowerStats::descriptor + "/default";
binder_status_t status = AServiceManager_addService(p->asBinder().get(), instance.c_str()); binder_status_t status = AServiceManager_addService(p->asBinder().get(), instance.c_str());
LOG_ALWAYS_FATAL_IF(status != STATUS_OK); LOG_ALWAYS_FATAL_IF(status != STATUS_OK);

View file

@ -26,6 +26,7 @@
#include <android/binder_manager.h> #include <android/binder_manager.h>
#include <android/binder_process.h> #include <android/binder_process.h>
#include <log/log.h> #include <log/log.h>
#include <sys/stat.h>
using aidl::android::hardware::power::stats::DisplayStateResidencyDataProvider; using aidl::android::hardware::power::stats::DisplayStateResidencyDataProvider;
using aidl::android::hardware::power::stats::EnergyConsumerType; using aidl::android::hardware::power::stats::EnergyConsumerType;
@ -61,6 +62,8 @@ void addDisplay(std::shared_ptr<PowerStats> p) {
} }
int main() { int main() {
struct stat buffer;
LOG(INFO) << "Pixel PowerStats HAL AIDL Service is starting."; LOG(INFO) << "Pixel PowerStats HAL AIDL Service is starting.";
// single thread // single thread
@ -70,8 +73,20 @@ int main() {
addGs201CommonDataProviders(p); addGs201CommonDataProviders(p);
addDisplay(p); addDisplay(p);
addNFC(p, "/sys/devices/platform/10970000.hsi2c/i2c-4/i2c-st21nfc/power_stats");
if (!stat("/sys/devices/platform/10970000.hsi2c/i2c-3/i2c-st21nfc/power_stats", &buffer)) {
addNFC(p, "/sys/devices/platform/10970000.hsi2c/i2c-3/i2c-st21nfc/power_stats");
} else if (!stat("/sys/devices/platform/10970000.hsi2c/i2c-4/i2c-st21nfc/power_stats", &buffer)) {
addNFC(p, "/sys/devices/platform/10970000.hsi2c/i2c-4/i2c-st21nfc/power_stats");
} else if (!stat("/sys/devices/platform/10970000.hsi2c/i2c-5/i2c-st21nfc/power_stats", &buffer)) {
addNFC(p, "/sys/devices/platform/10970000.hsi2c/i2c-5/i2c-st21nfc/power_stats");
} else if (!stat("/sys/devices/platform/10970000.hsi2c/i2c-6/i2c-st21nfc/power_stats", &buffer)) {
addNFC(p, "/sys/devices/platform/10970000.hsi2c/i2c-6/i2c-st21nfc/power_stats");
} else if (!stat("/sys/devices/platform/10970000.hsi2c/i2c-7/i2c-st21nfc/power_stats", &buffer)) {
addNFC(p, "/sys/devices/platform/10970000.hsi2c/i2c-7/i2c-st21nfc/power_stats");
} else {
addNFC(p, "/sys/devices/platform/10970000.hsi2c/i2c-8/i2c-st21nfc/power_stats");
}
const std::string instance = std::string() + PowerStats::descriptor + "/default"; const std::string instance = std::string() + PowerStats::descriptor + "/default";
binder_status_t status = AServiceManager_addService(p->asBinder().get(), instance.c_str()); binder_status_t status = AServiceManager_addService(p->asBinder().get(), instance.c_str());
LOG_ALWAYS_FATAL_IF(status != STATUS_OK); LOG_ALWAYS_FATAL_IF(status != STATUS_OK);