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