1 /* 2 * Copyright (c) 2021-2022 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_STATE_COLLECTION_H 17 #define CHARGER_STATE_COLLECTION_H 18 19 #include "istate_collection.h" 20 #include "thermal_common_event_receiver.h" 21 #include "thermal_level_info.h" 22 #include "thermal_mgr_listener.h" 23 24 using IntentWant = OHOS::AAFwk::Want; 25 namespace OHOS { 26 namespace PowerMgr { 27 typedef struct IdleState { 28 int32_t level; 29 int32_t soc; 30 int32_t charging; 31 int32_t current; 32 } IdleState; 33 34 class ChargerStateCollection : public IStateCollection { 35 public: 36 enum { 37 /** 38 * Battery is charging. 39 */ 40 DISABLE = 0, 41 42 /** 43 * Battery is not charging. 44 */ 45 ENABLE = 1, 46 47 /** 48 * Battery charge full. 49 */ 50 FULL = 2, 51 52 /** 53 * Battery is discharge. 54 */ 55 NONE = 3, 56 /** 57 * The bottom of the enum. 58 */ 59 BUTT = 4, 60 }; 61 ChargerStateCollection() = default; 62 ~ChargerStateCollection() = default; 63 bool Init() override; 64 bool InitParam(std::string& params) override; 65 std::string GetState() override; 66 virtual bool DecideState(const std::string& value) override; 67 void HandleChangerStatusCompleted(const EventFwk::CommonEventData& data); 68 void HandleChangerInnerStatusCompleted(const EventFwk::CommonEventData& data); 69 void HandleThermalLevelCompleted(const EventFwk::CommonEventData& data); 70 bool RegisterEvent(); 71 public: 72 virtual void SetState(const std::string& stateValue) override; 73 #ifndef THERMAL_OBSERVER_UT_TEST 74 private: 75 #endif 76 static void HandleChargeIdleState(); 77 static void PublishIdleEvent(bool isIdle, const std::string commonEventSupport); 78 std::string state_; 79 std::string params_; 80 std::string mockState_; 81 std::mutex mutex_; 82 sptr<IThermalLevelCallback> callback_ {nullptr}; 83 }; 84 } // namespace PowerMgr 85 } // namespace OHOS 86 #endif // CHARGER_STATE_COLLECTION_H 87