Loading healthd/charger.cpp +3 −0 Original line number Original line Diff line number Diff line Loading @@ -14,6 +14,8 @@ * limitations under the License. * limitations under the License. */ */ #include <android-base/logging.h> #include "charger.sysprop.h" #include "charger.sysprop.h" #include "healthd_mode_charger.h" #include "healthd_mode_charger.h" #include "healthd_mode_charger_nops.h" #include "healthd_mode_charger_nops.h" Loading @@ -23,6 +25,7 @@ #endif #endif int main(int argc, char** argv) { int main(int argc, char** argv) { android::base::InitLogging(argv, &android::base::KernelLogger); if (CHARGER_FORCE_NO_UI || android::sysprop::ChargerProperties::no_ui().value_or(false)) { if (CHARGER_FORCE_NO_UI || android::sysprop::ChargerProperties::no_ui().value_or(false)) { return healthd_charger_nops(argc, argv); return healthd_charger_nops(argc, argv); } else { } else { Loading healthd/charger_utils.cpp +11 −33 Original line number Original line Diff line number Diff line Loading @@ -17,50 +17,28 @@ #include "charger_utils.h" #include "charger_utils.h" #include <android-base/logging.h> #include <android-base/logging.h> #include <android/hidl/manager/1.0/IServiceManager.h> #include <android/hardware/health/2.1/IHealth.h> #include <health/utils.h> #include <health/utils.h> #include <health2impl/Health.h> #include <health2impl/Health.h> #include <hidl/ServiceManagement.h> using android::hardware::getPassthroughServiceManager; using android::hidl::base::V1_0::IBase; using android::hidl::manager::V1_0::IServiceManager; namespace android { namespace android { namespace hardware { namespace hardware { namespace health { namespace health { sp<V2_1::IHealth> GetPassthroughHealthImpl() { // Not using getService() because there is no hwservicemanager in charger mode. sp<IServiceManager> pm = getPassthroughServiceManager(); if (pm == nullptr) { LOG(WARNING) << "Cannot get passthrough service manager."; return nullptr; } sp<IBase> base = pm->get(V2_0::IHealth::descriptor, "default"); if (base == nullptr) { LOG(WARNING) << "Cannot find passthrough implementation of health 2.0 HAL for instance " "'default' on the device."; return nullptr; } sp<V2_1::IHealth> service = V2_1::IHealth::castFrom(base); if (service == nullptr) { LOG(WARNING) << "Cannot cast passthrough implementation of health 2.0 HAL to 2.1 for instance " "'default' on the device."; return nullptr; } return service; } sp<V2_1::IHealth> GetPassthroughHealth() { sp<V2_1::IHealth> GetHealthServiceOrDefault() { auto impl = GetPassthroughHealthImpl(); // No need to use get_health_service from libhealthhalutils that if (impl == nullptr) { // checks for "backup" instance provided by healthd, since // V2_1::implementation::Health does the same thing. sp<V2_1::IHealth> service = V2_1::IHealth::getService(); if (service != nullptr) { LOG(INFO) << "Charger uses health HAL service."; } else { LOG(WARNING) << "Charger uses system defaults."; LOG(WARNING) << "Charger uses system defaults."; auto config = std::make_unique<healthd_config>(); auto config = std::make_unique<healthd_config>(); InitHealthdConfig(config.get()); InitHealthdConfig(config.get()); impl = new V2_1::implementation::Health(std::move(config)); service = new V2_1::implementation::Health(std::move(config)); } } return impl; return service; } } } // namespace health } // namespace health Loading healthd/charger_utils.h +3 −1 Original line number Original line Diff line number Diff line Loading @@ -21,7 +21,9 @@ namespace android { namespace android { namespace hardware { namespace hardware { namespace health { namespace health { sp<V2_1::IHealth> GetPassthroughHealth(); // Return health HAL service. If it is not supported on the device (with // VINTF checks), return a default passthrough implementation. sp<V2_1::IHealth> GetHealthServiceOrDefault(); } // namespace health } // namespace health } // namespace hardware } // namespace hardware } // namespace android } // namespace android healthd/healthd_mode_charger.cpp +2 −2 Original line number Original line Diff line number Diff line Loading @@ -60,7 +60,7 @@ using namespace android; using namespace android; using android::hardware::Return; using android::hardware::Return; using android::hardware::health::GetPassthroughHealth; using android::hardware::health::GetHealthServiceOrDefault; using android::hardware::health::HealthLoop; using android::hardware::health::HealthLoop; using android::hardware::health::V1_0::BatteryStatus; using android::hardware::health::V1_0::BatteryStatus; using android::hardware::health::V2_0::Result; using android::hardware::health::V2_0::Result; Loading Loading @@ -742,6 +742,6 @@ int healthd_charger_main(int argc, char** argv) { } } } } Charger charger(GetPassthroughHealth()); Charger charger(GetHealthServiceOrDefault()); return charger.StartLoop(); return charger.StartLoop(); } } healthd/healthd_mode_charger_nops.cpp +2 −2 Original line number Original line Diff line number Diff line Loading @@ -20,10 +20,10 @@ #include "charger_utils.h" #include "charger_utils.h" using android::hardware::health::GetPassthroughHealth; using android::hardware::health::GetHealthServiceOrDefault; using android::hardware::health::V2_1::implementation::HalHealthLoop; using android::hardware::health::V2_1::implementation::HalHealthLoop; int healthd_charger_nops(int /* argc */, char** /* argv */) { int healthd_charger_nops(int /* argc */, char** /* argv */) { HalHealthLoop charger("charger", GetPassthroughHealth()); HalHealthLoop charger("charger", GetHealthServiceOrDefault()); return charger.StartLoop(); return charger.StartLoop(); } } Loading
healthd/charger.cpp +3 −0 Original line number Original line Diff line number Diff line Loading @@ -14,6 +14,8 @@ * limitations under the License. * limitations under the License. */ */ #include <android-base/logging.h> #include "charger.sysprop.h" #include "charger.sysprop.h" #include "healthd_mode_charger.h" #include "healthd_mode_charger.h" #include "healthd_mode_charger_nops.h" #include "healthd_mode_charger_nops.h" Loading @@ -23,6 +25,7 @@ #endif #endif int main(int argc, char** argv) { int main(int argc, char** argv) { android::base::InitLogging(argv, &android::base::KernelLogger); if (CHARGER_FORCE_NO_UI || android::sysprop::ChargerProperties::no_ui().value_or(false)) { if (CHARGER_FORCE_NO_UI || android::sysprop::ChargerProperties::no_ui().value_or(false)) { return healthd_charger_nops(argc, argv); return healthd_charger_nops(argc, argv); } else { } else { Loading
healthd/charger_utils.cpp +11 −33 Original line number Original line Diff line number Diff line Loading @@ -17,50 +17,28 @@ #include "charger_utils.h" #include "charger_utils.h" #include <android-base/logging.h> #include <android-base/logging.h> #include <android/hidl/manager/1.0/IServiceManager.h> #include <android/hardware/health/2.1/IHealth.h> #include <health/utils.h> #include <health/utils.h> #include <health2impl/Health.h> #include <health2impl/Health.h> #include <hidl/ServiceManagement.h> using android::hardware::getPassthroughServiceManager; using android::hidl::base::V1_0::IBase; using android::hidl::manager::V1_0::IServiceManager; namespace android { namespace android { namespace hardware { namespace hardware { namespace health { namespace health { sp<V2_1::IHealth> GetPassthroughHealthImpl() { // Not using getService() because there is no hwservicemanager in charger mode. sp<IServiceManager> pm = getPassthroughServiceManager(); if (pm == nullptr) { LOG(WARNING) << "Cannot get passthrough service manager."; return nullptr; } sp<IBase> base = pm->get(V2_0::IHealth::descriptor, "default"); if (base == nullptr) { LOG(WARNING) << "Cannot find passthrough implementation of health 2.0 HAL for instance " "'default' on the device."; return nullptr; } sp<V2_1::IHealth> service = V2_1::IHealth::castFrom(base); if (service == nullptr) { LOG(WARNING) << "Cannot cast passthrough implementation of health 2.0 HAL to 2.1 for instance " "'default' on the device."; return nullptr; } return service; } sp<V2_1::IHealth> GetPassthroughHealth() { sp<V2_1::IHealth> GetHealthServiceOrDefault() { auto impl = GetPassthroughHealthImpl(); // No need to use get_health_service from libhealthhalutils that if (impl == nullptr) { // checks for "backup" instance provided by healthd, since // V2_1::implementation::Health does the same thing. sp<V2_1::IHealth> service = V2_1::IHealth::getService(); if (service != nullptr) { LOG(INFO) << "Charger uses health HAL service."; } else { LOG(WARNING) << "Charger uses system defaults."; LOG(WARNING) << "Charger uses system defaults."; auto config = std::make_unique<healthd_config>(); auto config = std::make_unique<healthd_config>(); InitHealthdConfig(config.get()); InitHealthdConfig(config.get()); impl = new V2_1::implementation::Health(std::move(config)); service = new V2_1::implementation::Health(std::move(config)); } } return impl; return service; } } } // namespace health } // namespace health Loading
healthd/charger_utils.h +3 −1 Original line number Original line Diff line number Diff line Loading @@ -21,7 +21,9 @@ namespace android { namespace android { namespace hardware { namespace hardware { namespace health { namespace health { sp<V2_1::IHealth> GetPassthroughHealth(); // Return health HAL service. If it is not supported on the device (with // VINTF checks), return a default passthrough implementation. sp<V2_1::IHealth> GetHealthServiceOrDefault(); } // namespace health } // namespace health } // namespace hardware } // namespace hardware } // namespace android } // namespace android
healthd/healthd_mode_charger.cpp +2 −2 Original line number Original line Diff line number Diff line Loading @@ -60,7 +60,7 @@ using namespace android; using namespace android; using android::hardware::Return; using android::hardware::Return; using android::hardware::health::GetPassthroughHealth; using android::hardware::health::GetHealthServiceOrDefault; using android::hardware::health::HealthLoop; using android::hardware::health::HealthLoop; using android::hardware::health::V1_0::BatteryStatus; using android::hardware::health::V1_0::BatteryStatus; using android::hardware::health::V2_0::Result; using android::hardware::health::V2_0::Result; Loading Loading @@ -742,6 +742,6 @@ int healthd_charger_main(int argc, char** argv) { } } } } Charger charger(GetPassthroughHealth()); Charger charger(GetHealthServiceOrDefault()); return charger.StartLoop(); return charger.StartLoop(); } }
healthd/healthd_mode_charger_nops.cpp +2 −2 Original line number Original line Diff line number Diff line Loading @@ -20,10 +20,10 @@ #include "charger_utils.h" #include "charger_utils.h" using android::hardware::health::GetPassthroughHealth; using android::hardware::health::GetHealthServiceOrDefault; using android::hardware::health::V2_1::implementation::HalHealthLoop; using android::hardware::health::V2_1::implementation::HalHealthLoop; int healthd_charger_nops(int /* argc */, char** /* argv */) { int healthd_charger_nops(int /* argc */, char** /* argv */) { HalHealthLoop charger("charger", GetPassthroughHealth()); HalHealthLoop charger("charger", GetHealthServiceOrDefault()); return charger.StartLoop(); return charger.StartLoop(); } }