1 /*
2  * Copyright (c) 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 #ifndef FOUNDATION_RESOURCESCHEDULE_STANDBY_SERVICE_SERVICES_CORE_INCLUDE_STATE_MANAGER_H
16 #define FOUNDATION_RESOURCESCHEDULE_STANDBY_SERVICE_SERVICES_CORE_INCLUDE_STATE_MANAGER_H
17 
18 #include "istate_manager_adapter.h"
19 
20 namespace OHOS {
21 namespace DevStandbyMgr {
22 class StateManagerAdapter : public IStateManagerAdapter {
23 public:
24     StateManagerAdapter() = default;
25     ~StateManagerAdapter() override = default;
26     bool Init() override;
27     bool UnInit() override;
28     void HandleEvent(const StandbyMessage& message) override;
29     uint32_t GetCurState() override;
30     uint32_t GetPreState() override;
31 
32     ErrCode StartEvalCurrentState(const ConstraintEvalParam& params) override;
33     ErrCode EndEvalCurrentState(bool evalResult) override;
34 
35     void BlockCurrentState() override;
36     void UnblockCurrentState() override;
37     void OnScreenOffHalfHour(bool scrOffHalfHourCtrl, bool repeated) override;
38 
39     ErrCode TransitToState(uint32_t nextState) override;
40     ErrCode TransitToStateInner(uint32_t nextState) override;
41     void StopEvalution() override;
42     void HandleOpenCloseLid(const StandbyMessage& message);
43     void ShellDump(const std::vector<std::string>& argsInStr, std::string& result) override;
44 private:
45     void SendNotification(uint32_t preState, bool needDispatchEvent);
46     bool CheckTransitionValid(uint32_t curState, uint32_t nextState);
47     ErrCode ExitStandby(uint32_t nextState);
48     ErrCode EnterStandby(uint32_t nextState);
49     ErrCode TransitWithMaint(uint32_t nextState);
50     void OnScreenOffHalfHourInner(bool scrOffHalfHourCtrl, bool repeated);
51 
52     void HandleCommonEvent(const StandbyMessage& message);
53     void HandleScreenStatus(const StandbyMessage& message);
54     void HandleScrOffHalfHour(const StandbyMessage& message);
55     bool CheckEnterDarkState(const StandbyMessage& message);
56     void DumpShowDetailInfo(const std::vector<std::string>& argsInStr, std::string& result);
57     void DumpEnterSpecifiedState(const std::vector<std::string>& argsInStr, std::string& result);
58     void DumpActivateMotion(const std::vector<std::string>& argsInStr, std::string& result);
59     void DumpResetState(const std::vector<std::string>& argsInStr, std::string& result);
60     void RecordStateTransition();
61 private:
62     std::shared_ptr<BaseState> darkStatePtr_ {nullptr};
63     std::shared_ptr<BaseState> maintStatePtr_ {nullptr};
64     std::shared_ptr<BaseState> napStatePtr_ {nullptr};
65     std::shared_ptr<BaseState> sleepStatePtr_ {nullptr};
66     std::shared_ptr<BaseState> workingStatePtr_ {nullptr};
67     std::vector<std::shared_ptr<BaseState>> indexToState_ {};
68 };
69 }  // namespace DevStandbyMgr
70 }  // namespace OHOS
71 
72 #endif  // FOUNDATION_RESOURCESCHEDULE_STANDBY_SERVICE_SERVICES_CORE_INCLUDE_STATE_MANAGER_H