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