Loading health/aidl/Android.bp +5 −0 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ aidl_interface { name: "android.hardware.health", vendor_available: true, recovery_available: true, host_supported: true, srcs: ["android/hardware/health/*.aidl"], stability: "vintf", backend: { Loading @@ -48,6 +49,7 @@ cc_library { name: "android.hardware.health-translate-ndk", vendor_available: true, recovery_available: true, host_supported: true, srcs: ["android/hardware/health/translate-ndk.cpp"], shared_libs: [ "libbinder_ndk", Loading @@ -61,6 +63,9 @@ cc_library { "android.hardware.health@2.0", "android.hardware.health@2.1", ], defaults: [ "libbinder_ndk_host_user", ], } java_library { Loading health/aidl/android/hardware/health/translate-ndk.cpp +32 −27 Original line number Diff line number Diff line Loading @@ -106,36 +106,41 @@ __attribute__((warn_unused_result)) bool translate( } __attribute__((warn_unused_result)) bool translate( const ::android::hardware::health::V2_1::HealthInfo& in, const ::android::hardware::health::V2_0::HealthInfo& in, aidl::android::hardware::health::HealthInfo* out) { out->chargerAcOnline = static_cast<bool>(in.legacy.legacy.chargerAcOnline); out->chargerUsbOnline = static_cast<bool>(in.legacy.legacy.chargerUsbOnline); out->chargerWirelessOnline = static_cast<bool>(in.legacy.legacy.chargerWirelessOnline); out->maxChargingCurrentMicroamps = static_cast<int32_t>(in.legacy.legacy.maxChargingCurrent); out->maxChargingVoltageMicrovolts = static_cast<int32_t>(in.legacy.legacy.maxChargingVoltage); out->batteryStatus = static_cast<aidl::android::hardware::health::BatteryStatus>( in.legacy.legacy.batteryStatus); out->batteryHealth = static_cast<aidl::android::hardware::health::BatteryHealth>( in.legacy.legacy.batteryHealth); out->batteryPresent = static_cast<bool>(in.legacy.legacy.batteryPresent); out->batteryLevel = static_cast<int32_t>(in.legacy.legacy.batteryLevel); out->batteryVoltageMillivolts = static_cast<int32_t>(in.legacy.legacy.batteryVoltage); out->batteryTemperatureTenthsCelsius = static_cast<int32_t>(in.legacy.legacy.batteryTemperature); out->batteryCurrentMicroamps = static_cast<int32_t>(in.legacy.legacy.batteryCurrent); out->batteryCycleCount = static_cast<int32_t>(in.legacy.legacy.batteryCycleCount); out->batteryFullChargeUah = static_cast<int32_t>(in.legacy.legacy.batteryFullCharge); out->batteryChargeCounterUah = static_cast<int32_t>(in.legacy.legacy.batteryChargeCounter); out->batteryTechnology = in.legacy.legacy.batteryTechnology; out->batteryCurrentAverageMicroamps = static_cast<int32_t>(in.legacy.batteryCurrentAverage); out->chargerAcOnline = static_cast<bool>(in.legacy.chargerAcOnline); out->chargerUsbOnline = static_cast<bool>(in.legacy.chargerUsbOnline); out->chargerWirelessOnline = static_cast<bool>(in.legacy.chargerWirelessOnline); out->maxChargingCurrentMicroamps = static_cast<int32_t>(in.legacy.maxChargingCurrent); out->maxChargingVoltageMicrovolts = static_cast<int32_t>(in.legacy.maxChargingVoltage); out->batteryStatus = static_cast<aidl::android::hardware::health::BatteryStatus>(in.legacy.batteryStatus); out->batteryHealth = static_cast<aidl::android::hardware::health::BatteryHealth>(in.legacy.batteryHealth); out->batteryPresent = static_cast<bool>(in.legacy.batteryPresent); out->batteryLevel = static_cast<int32_t>(in.legacy.batteryLevel); out->batteryVoltageMillivolts = static_cast<int32_t>(in.legacy.batteryVoltage); out->batteryTemperatureTenthsCelsius = static_cast<int32_t>(in.legacy.batteryTemperature); out->batteryCurrentMicroamps = static_cast<int32_t>(in.legacy.batteryCurrent); out->batteryCycleCount = static_cast<int32_t>(in.legacy.batteryCycleCount); out->batteryFullChargeUah = static_cast<int32_t>(in.legacy.batteryFullCharge); out->batteryChargeCounterUah = static_cast<int32_t>(in.legacy.batteryChargeCounter); out->batteryTechnology = in.legacy.batteryTechnology; out->batteryCurrentAverageMicroamps = static_cast<int32_t>(in.batteryCurrentAverage); out->diskStats.clear(); out->diskStats.resize(in.legacy.diskStats.size()); for (size_t i = 0; i < in.legacy.diskStats.size(); ++i) if (!translate(in.legacy.diskStats[i], &out->diskStats[i])) return false; out->diskStats.resize(in.diskStats.size()); for (size_t i = 0; i < in.diskStats.size(); ++i) if (!translate(in.diskStats[i], &out->diskStats[i])) return false; out->storageInfos.clear(); out->storageInfos.resize(in.legacy.storageInfos.size()); for (size_t i = 0; i < in.legacy.storageInfos.size(); ++i) if (!translate(in.legacy.storageInfos[i], &out->storageInfos[i])) return false; out->storageInfos.resize(in.storageInfos.size()); for (size_t i = 0; i < in.storageInfos.size(); ++i) if (!translate(in.storageInfos[i], &out->storageInfos[i])) return false; return true; } __attribute__((warn_unused_result)) bool translate( const ::android::hardware::health::V2_1::HealthInfo& in, aidl::android::hardware::health::HealthInfo* out) { if (!translate(in.legacy, out)) return false; out->batteryCapacityLevel = static_cast<aidl::android::hardware::health::BatteryCapacityLevel>( in.batteryCapacityLevel); out->batteryChargeTimeToFullNowSeconds = Loading health/aidl/include/android/hardware/health/translate-ndk.h +3 −0 Original line number Diff line number Diff line Loading @@ -32,6 +32,9 @@ __attribute__((warn_unused_result)) bool translate( __attribute__((warn_unused_result)) bool translate( const ::android::hardware::health::V2_0::DiskStats& in, aidl::android::hardware::health::DiskStats* out); __attribute__((warn_unused_result)) bool translate( const ::android::hardware::health::V2_0::HealthInfo& in, aidl::android::hardware::health::HealthInfo* out); __attribute__((warn_unused_result)) bool translate( const ::android::hardware::health::V2_1::HealthInfo& in, aidl::android::hardware::health::HealthInfo* out); Loading health/utils/libhealthshim/Android.bp 0 → 100644 +78 −0 Original line number Diff line number Diff line // Copyright (C) 2021 The Android Open Source Project // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package { // See: http://go/android-license-faq // A large-scale-change added 'default_applicable_licenses' to import // all of the 'license_kinds' from "hardware_interfaces_license" // to get the below license kinds: // SPDX-license-identifier-Apache-2.0 default_applicable_licenses: ["hardware_interfaces_license"], } cc_defaults { name: "libhealthshim_defaults", host_supported: true, // for testing defaults: [ "libbinder_ndk_host_user", ], cflags: [ "-Wall", "-Werror", ], static_libs: [ "android.hardware.health-V1-ndk", "android.hardware.health-translate-ndk", "android.hardware.health@1.0", "android.hardware.health@2.0", ], shared_libs: [ // These can be expected from the device or from host. "libbase", "libbinder_ndk", "libcutils", "libhidlbase", "liblog", "libutils", ], } // Shim library that wraps a HIDL IHealth object into an AIDL IHealth object. cc_library_static { name: "libhealthshim", defaults: ["libhealthshim_defaults"], recovery_available: true, srcs: [ "shim.cpp", ], export_include_dirs: [ "include", ], } cc_test { name: "libhealthshim_test", defaults: ["libhealthshim_defaults"], static_libs: [ "libhealthshim", "libgmock", ], srcs: [ "test.cpp", ], test_suites: ["general-tests"], test_options: { unit_test: true, }, } health/utils/libhealthshim/include/health-shim/shim.h 0 → 100644 +55 −0 Original line number Diff line number Diff line /* * Copyright (C) 2021 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #pragma once #include <map> #include <aidl/android/hardware/health/BnHealth.h> #include <android/hardware/health/2.0/IHealth.h> namespace aidl::android::hardware::health { // Shim that wraps HIDL IHealth with an AIDL BnHealth. // The wrapper always have isRemote() == false because it is BnHealth. class HealthShim : public BnHealth { using HidlHealth = ::android::hardware::health::V2_0::IHealth; using HidlHealthInfoCallback = ::android::hardware::health::V2_0::IHealthInfoCallback; public: explicit HealthShim(const ::android::sp<HidlHealth>& service); ndk::ScopedAStatus registerCallback( const std::shared_ptr<IHealthInfoCallback>& in_callback) override; ndk::ScopedAStatus unregisterCallback( const std::shared_ptr<IHealthInfoCallback>& in_callback) override; ndk::ScopedAStatus update() override; ndk::ScopedAStatus getChargeCounterUah(int32_t* _aidl_return) override; ndk::ScopedAStatus getCurrentNowMicroamps(int32_t* _aidl_return) override; ndk::ScopedAStatus getCurrentAverageMicroamps(int32_t* _aidl_return) override; ndk::ScopedAStatus getCapacity(int32_t* _aidl_return) override; ndk::ScopedAStatus getEnergyCounterNwh(int64_t* _aidl_return) override; ndk::ScopedAStatus getChargeStatus(BatteryStatus* _aidl_return) override; ndk::ScopedAStatus getStorageInfo(std::vector<StorageInfo>* _aidl_return) override; ndk::ScopedAStatus getDiskStats(std::vector<DiskStats>* _aidl_return) override; ndk::ScopedAStatus getHealthInfo(HealthInfo* _aidl_return) override; private: ::android::sp<HidlHealth> service_; std::map<std::shared_ptr<IHealthInfoCallback>, ::android::sp<HidlHealthInfoCallback>> callback_map_; }; } // namespace aidl::android::hardware::health Loading
health/aidl/Android.bp +5 −0 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ aidl_interface { name: "android.hardware.health", vendor_available: true, recovery_available: true, host_supported: true, srcs: ["android/hardware/health/*.aidl"], stability: "vintf", backend: { Loading @@ -48,6 +49,7 @@ cc_library { name: "android.hardware.health-translate-ndk", vendor_available: true, recovery_available: true, host_supported: true, srcs: ["android/hardware/health/translate-ndk.cpp"], shared_libs: [ "libbinder_ndk", Loading @@ -61,6 +63,9 @@ cc_library { "android.hardware.health@2.0", "android.hardware.health@2.1", ], defaults: [ "libbinder_ndk_host_user", ], } java_library { Loading
health/aidl/android/hardware/health/translate-ndk.cpp +32 −27 Original line number Diff line number Diff line Loading @@ -106,36 +106,41 @@ __attribute__((warn_unused_result)) bool translate( } __attribute__((warn_unused_result)) bool translate( const ::android::hardware::health::V2_1::HealthInfo& in, const ::android::hardware::health::V2_0::HealthInfo& in, aidl::android::hardware::health::HealthInfo* out) { out->chargerAcOnline = static_cast<bool>(in.legacy.legacy.chargerAcOnline); out->chargerUsbOnline = static_cast<bool>(in.legacy.legacy.chargerUsbOnline); out->chargerWirelessOnline = static_cast<bool>(in.legacy.legacy.chargerWirelessOnline); out->maxChargingCurrentMicroamps = static_cast<int32_t>(in.legacy.legacy.maxChargingCurrent); out->maxChargingVoltageMicrovolts = static_cast<int32_t>(in.legacy.legacy.maxChargingVoltage); out->batteryStatus = static_cast<aidl::android::hardware::health::BatteryStatus>( in.legacy.legacy.batteryStatus); out->batteryHealth = static_cast<aidl::android::hardware::health::BatteryHealth>( in.legacy.legacy.batteryHealth); out->batteryPresent = static_cast<bool>(in.legacy.legacy.batteryPresent); out->batteryLevel = static_cast<int32_t>(in.legacy.legacy.batteryLevel); out->batteryVoltageMillivolts = static_cast<int32_t>(in.legacy.legacy.batteryVoltage); out->batteryTemperatureTenthsCelsius = static_cast<int32_t>(in.legacy.legacy.batteryTemperature); out->batteryCurrentMicroamps = static_cast<int32_t>(in.legacy.legacy.batteryCurrent); out->batteryCycleCount = static_cast<int32_t>(in.legacy.legacy.batteryCycleCount); out->batteryFullChargeUah = static_cast<int32_t>(in.legacy.legacy.batteryFullCharge); out->batteryChargeCounterUah = static_cast<int32_t>(in.legacy.legacy.batteryChargeCounter); out->batteryTechnology = in.legacy.legacy.batteryTechnology; out->batteryCurrentAverageMicroamps = static_cast<int32_t>(in.legacy.batteryCurrentAverage); out->chargerAcOnline = static_cast<bool>(in.legacy.chargerAcOnline); out->chargerUsbOnline = static_cast<bool>(in.legacy.chargerUsbOnline); out->chargerWirelessOnline = static_cast<bool>(in.legacy.chargerWirelessOnline); out->maxChargingCurrentMicroamps = static_cast<int32_t>(in.legacy.maxChargingCurrent); out->maxChargingVoltageMicrovolts = static_cast<int32_t>(in.legacy.maxChargingVoltage); out->batteryStatus = static_cast<aidl::android::hardware::health::BatteryStatus>(in.legacy.batteryStatus); out->batteryHealth = static_cast<aidl::android::hardware::health::BatteryHealth>(in.legacy.batteryHealth); out->batteryPresent = static_cast<bool>(in.legacy.batteryPresent); out->batteryLevel = static_cast<int32_t>(in.legacy.batteryLevel); out->batteryVoltageMillivolts = static_cast<int32_t>(in.legacy.batteryVoltage); out->batteryTemperatureTenthsCelsius = static_cast<int32_t>(in.legacy.batteryTemperature); out->batteryCurrentMicroamps = static_cast<int32_t>(in.legacy.batteryCurrent); out->batteryCycleCount = static_cast<int32_t>(in.legacy.batteryCycleCount); out->batteryFullChargeUah = static_cast<int32_t>(in.legacy.batteryFullCharge); out->batteryChargeCounterUah = static_cast<int32_t>(in.legacy.batteryChargeCounter); out->batteryTechnology = in.legacy.batteryTechnology; out->batteryCurrentAverageMicroamps = static_cast<int32_t>(in.batteryCurrentAverage); out->diskStats.clear(); out->diskStats.resize(in.legacy.diskStats.size()); for (size_t i = 0; i < in.legacy.diskStats.size(); ++i) if (!translate(in.legacy.diskStats[i], &out->diskStats[i])) return false; out->diskStats.resize(in.diskStats.size()); for (size_t i = 0; i < in.diskStats.size(); ++i) if (!translate(in.diskStats[i], &out->diskStats[i])) return false; out->storageInfos.clear(); out->storageInfos.resize(in.legacy.storageInfos.size()); for (size_t i = 0; i < in.legacy.storageInfos.size(); ++i) if (!translate(in.legacy.storageInfos[i], &out->storageInfos[i])) return false; out->storageInfos.resize(in.storageInfos.size()); for (size_t i = 0; i < in.storageInfos.size(); ++i) if (!translate(in.storageInfos[i], &out->storageInfos[i])) return false; return true; } __attribute__((warn_unused_result)) bool translate( const ::android::hardware::health::V2_1::HealthInfo& in, aidl::android::hardware::health::HealthInfo* out) { if (!translate(in.legacy, out)) return false; out->batteryCapacityLevel = static_cast<aidl::android::hardware::health::BatteryCapacityLevel>( in.batteryCapacityLevel); out->batteryChargeTimeToFullNowSeconds = Loading
health/aidl/include/android/hardware/health/translate-ndk.h +3 −0 Original line number Diff line number Diff line Loading @@ -32,6 +32,9 @@ __attribute__((warn_unused_result)) bool translate( __attribute__((warn_unused_result)) bool translate( const ::android::hardware::health::V2_0::DiskStats& in, aidl::android::hardware::health::DiskStats* out); __attribute__((warn_unused_result)) bool translate( const ::android::hardware::health::V2_0::HealthInfo& in, aidl::android::hardware::health::HealthInfo* out); __attribute__((warn_unused_result)) bool translate( const ::android::hardware::health::V2_1::HealthInfo& in, aidl::android::hardware::health::HealthInfo* out); Loading
health/utils/libhealthshim/Android.bp 0 → 100644 +78 −0 Original line number Diff line number Diff line // Copyright (C) 2021 The Android Open Source Project // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package { // See: http://go/android-license-faq // A large-scale-change added 'default_applicable_licenses' to import // all of the 'license_kinds' from "hardware_interfaces_license" // to get the below license kinds: // SPDX-license-identifier-Apache-2.0 default_applicable_licenses: ["hardware_interfaces_license"], } cc_defaults { name: "libhealthshim_defaults", host_supported: true, // for testing defaults: [ "libbinder_ndk_host_user", ], cflags: [ "-Wall", "-Werror", ], static_libs: [ "android.hardware.health-V1-ndk", "android.hardware.health-translate-ndk", "android.hardware.health@1.0", "android.hardware.health@2.0", ], shared_libs: [ // These can be expected from the device or from host. "libbase", "libbinder_ndk", "libcutils", "libhidlbase", "liblog", "libutils", ], } // Shim library that wraps a HIDL IHealth object into an AIDL IHealth object. cc_library_static { name: "libhealthshim", defaults: ["libhealthshim_defaults"], recovery_available: true, srcs: [ "shim.cpp", ], export_include_dirs: [ "include", ], } cc_test { name: "libhealthshim_test", defaults: ["libhealthshim_defaults"], static_libs: [ "libhealthshim", "libgmock", ], srcs: [ "test.cpp", ], test_suites: ["general-tests"], test_options: { unit_test: true, }, }
health/utils/libhealthshim/include/health-shim/shim.h 0 → 100644 +55 −0 Original line number Diff line number Diff line /* * Copyright (C) 2021 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #pragma once #include <map> #include <aidl/android/hardware/health/BnHealth.h> #include <android/hardware/health/2.0/IHealth.h> namespace aidl::android::hardware::health { // Shim that wraps HIDL IHealth with an AIDL BnHealth. // The wrapper always have isRemote() == false because it is BnHealth. class HealthShim : public BnHealth { using HidlHealth = ::android::hardware::health::V2_0::IHealth; using HidlHealthInfoCallback = ::android::hardware::health::V2_0::IHealthInfoCallback; public: explicit HealthShim(const ::android::sp<HidlHealth>& service); ndk::ScopedAStatus registerCallback( const std::shared_ptr<IHealthInfoCallback>& in_callback) override; ndk::ScopedAStatus unregisterCallback( const std::shared_ptr<IHealthInfoCallback>& in_callback) override; ndk::ScopedAStatus update() override; ndk::ScopedAStatus getChargeCounterUah(int32_t* _aidl_return) override; ndk::ScopedAStatus getCurrentNowMicroamps(int32_t* _aidl_return) override; ndk::ScopedAStatus getCurrentAverageMicroamps(int32_t* _aidl_return) override; ndk::ScopedAStatus getCapacity(int32_t* _aidl_return) override; ndk::ScopedAStatus getEnergyCounterNwh(int64_t* _aidl_return) override; ndk::ScopedAStatus getChargeStatus(BatteryStatus* _aidl_return) override; ndk::ScopedAStatus getStorageInfo(std::vector<StorageInfo>* _aidl_return) override; ndk::ScopedAStatus getDiskStats(std::vector<DiskStats>* _aidl_return) override; ndk::ScopedAStatus getHealthInfo(HealthInfo* _aidl_return) override; private: ::android::sp<HidlHealth> service_; std::map<std::shared_ptr<IHealthInfoCallback>, ::android::sp<HidlHealthInfoCallback>> callback_map_; }; } // namespace aidl::android::hardware::health