• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 POWERMGR_RUNNING_LOCK_INNER_H
17 #define POWERMGR_RUNNING_LOCK_INNER_H
18 
19 #include <mutex>
20 
21 #include "actions/running_lock_action_info.h"
22 #include "power_common.h"
23 #include "running_lock_info.h"
24 
25 namespace OHOS {
26 namespace PowerMgr {
27 enum class RunningLockState : uint32_t {
28     RUNNINGLOCK_STATE_DISABLE  = 0,
29     RUNNINGLOCK_STATE_ENABLE,
30     RUNNINGLOCK_STATE_PROXIED,
31     RUNNINGLOCK_STATE_UNPROXIED_RESTORE,
32 };
33 
34 class RunningLockInner {
35 public:
36     explicit RunningLockInner(const RunningLockParam& runningLockParam);
37     ~RunningLockInner() = default;
38 
39     static std::shared_ptr<RunningLockInner> CreateRunningLockInner(const RunningLockParam& runningLockParam);
40     void DumpInfo(const std::string& description);
41 
GetName()42     const std::string& GetName() const
43     {
44         return runningLockParam_.name;
45     }
46 
GetBundleName()47     const std::string& GetBundleName() const
48     {
49         return runningLockParam_.bundleName;
50     }
51 
52 #ifdef HAS_HIVIEWDFX_HISYSEVENT_PART
SetBeginTime(int32_t beginTimeMs)53     void SetBeginTime(int32_t beginTimeMs)
54     {
55         beginTimeMs_ = beginTimeMs;
56     }
57 
GetBeginTime()58     int32_t GetBeginTime()
59     {
60         return beginTimeMs_;
61     }
62 #endif
63 
SetBundleName(const std::string & bundleName)64     void SetBundleName(const std::string& bundleName)
65     {
66         runningLockParam_.bundleName = bundleName;
67     }
68 
GetType()69     RunningLockType GetType() const
70     {
71         return runningLockParam_.type;
72     }
GetPid()73     int32_t GetPid() const
74     {
75         return runningLockParam_.pid;
76     }
GetUid()77     int32_t GetUid() const
78     {
79         return runningLockParam_.uid;
80     }
SetTimeOutMs(int32_t timeoutMs)81     void SetTimeOutMs(int32_t timeoutMs)
82     {
83         runningLockParam_.timeoutMs = timeoutMs;
84     }
GetTimeOutMs()85     int32_t GetTimeOutMs() const
86     {
87         return runningLockParam_.timeoutMs;
88     }
GetParam()89     const RunningLockParam& GetParam() const
90     {
91         return runningLockParam_;
92     }
SetState(RunningLockState state)93     void SetState(RunningLockState state)
94     {
95         state_ = state;
96     }
GetState()97     RunningLockState GetState() const
98     {
99         return state_;
100     }
IsProxied()101     bool IsProxied() const
102     {
103         return state_ == RunningLockState::RUNNINGLOCK_STATE_PROXIED ||
104             state_ == RunningLockState::RUNNINGLOCK_STATE_UNPROXIED_RESTORE;
105     }
GetLockTimeMs()106     int64_t GetLockTimeMs() const
107     {
108         return lockTimeMs_;
109     }
GetLockId()110     uint64_t GetLockId() const
111     {
112         return runningLockParam_.lockid;
113     }
114 
115 private:
116     std::mutex mutex_;
117     RunningLockParam runningLockParam_;
118     RunningLockState state_ = RunningLockState::RUNNINGLOCK_STATE_DISABLE;
119     int64_t lockTimeMs_ = 0;
120 #ifdef HAS_HIVIEWDFX_HISYSEVENT_PART
121     int32_t beginTimeMs_ = 0;
122 #endif
123 };
124 } // namespace PowerMgr
125 } // namespace OHOS
126 #endif // POWERMGR_RUNNING_LOCK_INNER_H
127