Yifan Hong | a8f55ca | 2021-10-20 23:05:45 -0700 | [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 | |
| 17 | #include <optional> |
| 18 | #include <type_traits> |
| 19 | |
| 20 | #include <android/binder_auto_utils.h> |
| 21 | #include <charger/healthd_mode_charger.h> |
| 22 | #include <health-impl/Health.h> |
| 23 | |
| 24 | #pragma once |
| 25 | |
| 26 | namespace aidl::android::hardware::health::charger { |
| 27 | |
| 28 | // Implements ChargerHalHealthLoopInterface for AIDL charger |
| 29 | // Adapter of (Health, HalHealthLoop) -> ChargerHalHealthLoopInterface |
| 30 | class ChargerCallback : public ::android::ChargerConfigurationInterface { |
| 31 | public: |
| 32 | ChargerCallback(const std::shared_ptr<Health>& service) : service_(service) {} |
| 33 | std::optional<bool> ChargerShouldKeepScreenOn() override; |
| 34 | bool ChargerIsOnline() override; |
| 35 | void ChargerInitConfig(healthd_config* config) override; |
| 36 | int ChargerRegisterEvent(int fd, BoundFunction func, EventWakeup wakeup) override; |
| 37 | |
| 38 | // Override to return true to replace `ro.charger.enable_suspend=true` |
| 39 | bool ChargerEnableSuspend() override { return false; } |
| 40 | |
| 41 | void set_hal_health_loop(const std::weak_ptr<HalHealthLoop>& hal_health_loop); |
| 42 | |
| 43 | private: |
| 44 | std::shared_ptr<Health> service_; |
| 45 | std::weak_ptr<HalHealthLoop> hal_health_loop_; |
| 46 | }; |
| 47 | |
| 48 | int ChargerModeMain(const std::shared_ptr<Health>& binder, |
| 49 | const std::shared_ptr<ChargerCallback>& charger_callback); |
| 50 | |
| 51 | } // namespace aidl::android::hardware::health::charger |