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_PLUGINS_EXT_INCLUDE_ISTATE_MANAGER_ADAPTER_H
16 #define FOUNDATION_RESOURCESCHEDULE_STANDBY_SERVICE_PLUGINS_EXT_INCLUDE_ISTATE_MANAGER_ADAPTER_H
17 
18 #include <vector>
19 #include <memory>
20 #include <list>
21 #include <utility>
22 
23 #include "event_handler.h"
24 
25 #include "standby_service_errors.h"
26 #include "base_state.h"
27 #include "istrategy_manager_adapter.h"
28 
29 namespace OHOS {
30 namespace DevStandbyMgr {
31 class IConstraintManagerAdapter;
32 class BaseState;
33 struct ConstraintEvalParam;
34 class IStateManagerAdapter {
35 public:
36     virtual ~IStateManagerAdapter() = default;
37     virtual bool Init() = 0;
38     virtual bool UnInit() = 0;
39     virtual void HandleEvent(const StandbyMessage& message) = 0;
40 
41     virtual ErrCode StartEvalCurrentState(const ConstraintEvalParam& params) = 0;
42     virtual ErrCode EndEvalCurrentState(bool evalResult) = 0;
43 
44     virtual ErrCode TransitToState(uint32_t nextState) = 0;
45     virtual ErrCode TransitToStateInner(uint32_t nextState) = 0;
46     virtual void ShellDump(const std::vector<std::string>& argsInStr, std::string& result) = 0;
47 
48     virtual uint32_t GetCurState() = 0;
49     virtual uint32_t GetPreState() = 0;
50     virtual void BlockCurrentState() = 0;
51     virtual void UnblockCurrentState() = 0;
52     virtual void OnScreenOffHalfHour(bool scrOffHalfHourCtrl, bool repeated) = 0;
53     virtual void StopEvalution() = 0;
54     void SetEvalution(bool isEvalution);
55     bool IsEvalution();
56     bool IsScreenOn();
57     virtual int64_t GetScreenOffTimeStamp();
58     virtual bool IsScrOffHalfHourCtrl();
59 protected:
60     bool isEvalution_ {false};
61     bool isBlocked_ {false};
62     std::shared_ptr<BaseState> preStatePtr_ {nullptr};
63     std::shared_ptr<BaseState> curStatePtr_ {nullptr};
64     std::shared_ptr<AppExecFwk::EventHandler> handler_ {nullptr};
65     std::shared_ptr<IConstraintManagerAdapter> constraintManager_ {nullptr};
66     std::shared_ptr<IStrategyManagerAdapter> strategyManager_ {nullptr};
67     int64_t screenOffTimeStamp_ {0};
68     uint64_t scrOffHalfHourTimerId_ {0};
69     bool isScreenOn_ {false};
70     bool scrOffHalfHourCtrl_ {false};
71 
72     // record the history of state transition, the element of stateRecordList_ is (state, timestamp of exit)
73     const uint32_t MAX_RECORD_SIZE = 10;
74     std::list<std::pair<uint32_t, int64_t>> stateRecordList_ {};
75 };
76 }  // namespace DevStandbyMgr
77 }  // namespace OHOS
78 #endif  // FOUNDATION_RESOURCESCHEDULE_STANDBY_SERVICE_PLUGINS_EXT_INCLUDE_ISTATE_MANAGER_ADAPTER_H
79