Yifan Hong | 7a6956e | 2021-11-08 23:52:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2021 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | #pragma once |
| 17 | |
| 18 | #include <map> |
| 19 | |
| 20 | #include <aidl/android/hardware/health/BnHealth.h> |
| 21 | #include <android/hardware/health/2.0/IHealth.h> |
| 22 | |
| 23 | namespace aidl::android::hardware::health { |
| 24 | |
| 25 | // Shim that wraps HIDL IHealth with an AIDL BnHealth. |
| 26 | // The wrapper always have isRemote() == false because it is BnHealth. |
| 27 | class HealthShim : public BnHealth { |
| 28 | using HidlHealth = ::android::hardware::health::V2_0::IHealth; |
| 29 | using HidlHealthInfoCallback = ::android::hardware::health::V2_0::IHealthInfoCallback; |
| 30 | |
| 31 | public: |
| 32 | explicit HealthShim(const ::android::sp<HidlHealth>& service); |
| 33 | |
| 34 | ndk::ScopedAStatus registerCallback( |
| 35 | const std::shared_ptr<IHealthInfoCallback>& in_callback) override; |
| 36 | ndk::ScopedAStatus unregisterCallback( |
| 37 | const std::shared_ptr<IHealthInfoCallback>& in_callback) override; |
| 38 | ndk::ScopedAStatus update() override; |
| 39 | ndk::ScopedAStatus getChargeCounterUah(int32_t* _aidl_return) override; |
| 40 | ndk::ScopedAStatus getCurrentNowMicroamps(int32_t* _aidl_return) override; |
| 41 | ndk::ScopedAStatus getCurrentAverageMicroamps(int32_t* _aidl_return) override; |
| 42 | ndk::ScopedAStatus getCapacity(int32_t* _aidl_return) override; |
| 43 | ndk::ScopedAStatus getEnergyCounterNwh(int64_t* _aidl_return) override; |
| 44 | ndk::ScopedAStatus getChargeStatus(BatteryStatus* _aidl_return) override; |
| 45 | ndk::ScopedAStatus getStorageInfo(std::vector<StorageInfo>* _aidl_return) override; |
| 46 | ndk::ScopedAStatus getDiskStats(std::vector<DiskStats>* _aidl_return) override; |
| 47 | ndk::ScopedAStatus getHealthInfo(HealthInfo* _aidl_return) override; |
Jack Wu | 3356161 | 2022-11-24 12:10:55 +0800 | [diff] [blame] | 48 | ndk::ScopedAStatus setChargingPolicy(BatteryChargingPolicy in_value) override; |
| 49 | ndk::ScopedAStatus getChargingPolicy(BatteryChargingPolicy* _aidl_return) override; |
| 50 | ndk::ScopedAStatus getBatteryHealthData(BatteryHealthData* _aidl_return) override; |
Yifan Hong | 7a6956e | 2021-11-08 23:52:44 -0800 | [diff] [blame] | 51 | |
| 52 | private: |
| 53 | ::android::sp<HidlHealth> service_; |
| 54 | std::map<std::shared_ptr<IHealthInfoCallback>, ::android::sp<HidlHealthInfoCallback>> |
| 55 | callback_map_; |
| 56 | }; |
| 57 | |
| 58 | } // namespace aidl::android::hardware::health |