1 /* 2 * Copyright (c) 2021-2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef CHARGER_THREAD_H 17 #define CHARGER_THREAD_H 18 19 #include <thread> 20 21 #include "battery_backlight.h" 22 #include "battery_led.h" 23 #include "battery_thread.h" 24 #include "battery_vibrate.h" 25 #include "charger_animation.h" 26 #include "v1_0/iinput_interfaces.h" 27 #include <linux/input.h> 28 29 namespace OHOS { 30 namespace PowerMgr { 31 using namespace OHOS::HDI::Input::V1_0; 32 class ChargerThread : public BatteryThread { 33 public: 34 class HdfInputEventCallback : public IInputCallback { 35 public: 36 HdfInputEventCallback() = default; 37 ~HdfInputEventCallback() override = default; 38 39 int32_t EventPkgCallback(const std::vector<HDI::Input::V1_0::EventPackage> &pkgs, uint32_t devIndex) override; 40 int32_t HotPlugCallback(const HotPlugEvent &event) override; 41 42 private: 43 void SetKeyState(int32_t code, int32_t value, int64_t now); 44 void HandleInputEvent(const struct input_event* iev); 45 }; 46 47 private: 48 void Init(); 49 static void UpdateAnimation(const int32_t& chargeState, const int32_t& capacity); 50 void Run(void* service) override; 51 void UpdateBatteryInfo(void* arg) override; 52 void HandleChargingState(); 53 void HandleScreenState(); 54 void HandleTemperature(const int32_t& temperature); 55 void HandleCapacity(const int32_t& capacity); 56 void HandleStates() override; 57 int32_t UpdateWaitInterval() override; 58 void CycleMatters() override; 59 static void InitAnimation(); 60 void SetKeyWait(struct KeyState& key, int64_t timeout); 61 static void InitInput(); 62 void HandlePowerKeyState(); 63 void HandlePowerKey(int32_t keycode, int64_t now); 64 void InitLackPowerCapacity(); 65 void InitBatteryFileSystem(); 66 void InitVibration(); 67 void InitBacklight(); 68 void InitLed(); 69 std::unique_ptr<PowerSupplyProvider> provider_ = nullptr; 70 std::unique_ptr<BatteryVibrate> vibrate_ = nullptr; 71 std::unique_ptr<BatteryBacklight> backlight_ = nullptr; 72 std::unique_ptr<BatteryLed> led_ = nullptr; 73 static sptr<HDI::Input::V1_0::IInputInterfaces> inputInterface; 74 75 static const int32_t INVALID = -1; 76 int64_t keyWait_ = INVALID; 77 int64_t backlightWait_ = INVALID; 78 int32_t capacity_ = INVALID; 79 int32_t chargeState_ = PowerSupplyProvider::BatteryChargeState::CHARGE_STATE_RESERVED; 80 bool started_ = false; 81 82 static std::unique_ptr<ChargerAnimation> animation_; 83 static bool isChargeStateChanged_; 84 static bool isConfigParse_; 85 static int32_t lackPowerCapacity_; 86 }; 87 } // namespace PowerMgr 88 } // namespace OHOS 89 #endif 90