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 SetBundleName(const std::string & bundleName)52 void SetBundleName(const std::string& bundleName) 53 { 54 runningLockParam_.bundleName = bundleName; 55 } 56 GetType()57 RunningLockType GetType() const 58 { 59 return runningLockParam_.type; 60 } GetPid()61 int32_t GetPid() const 62 { 63 return runningLockParam_.pid; 64 } GetUid()65 int32_t GetUid() const 66 { 67 return runningLockParam_.uid; 68 } SetTimeOutMs(int32_t timeoutMs)69 void SetTimeOutMs(int32_t timeoutMs) 70 { 71 runningLockParam_.timeoutMs = timeoutMs; 72 } GetTimeOutMs()73 int32_t GetTimeOutMs() const 74 { 75 return runningLockParam_.timeoutMs; 76 } GetParam()77 const RunningLockParam& GetParam() const 78 { 79 return runningLockParam_; 80 } SetState(RunningLockState state)81 void SetState(RunningLockState state) 82 { 83 state_ = state; 84 } GetState()85 RunningLockState GetState() const 86 { 87 return state_; 88 } IsProxied()89 bool IsProxied() const 90 { 91 return state_ == RunningLockState::RUNNINGLOCK_STATE_PROXIED || 92 state_ == RunningLockState::RUNNINGLOCK_STATE_UNPROXIED_RESTORE; 93 } GetLockTimeMs()94 int64_t GetLockTimeMs() const 95 { 96 return lockTimeMs_; 97 } GetLockId()98 uint64_t GetLockId() const 99 { 100 return runningLockParam_.lockid; 101 } 102 103 private: 104 std::mutex mutex_; 105 RunningLockParam runningLockParam_; 106 RunningLockState state_ = RunningLockState::RUNNINGLOCK_STATE_DISABLE; 107 int64_t lockTimeMs_ = 0; 108 }; 109 } // namespace PowerMgr 110 } // namespace OHOS 111 #endif // POWERMGR_RUNNING_LOCK_INNER_H 112