1 /* 2 * Copyright (c) 2021 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 "power_common.h" 22 #include "running_lock_info.h" 23 24 namespace OHOS { 25 namespace PowerMgr { 26 struct UserIPCInfo { 27 pid_t uid = INVALID_UID; 28 pid_t pid = INVALID_PID; 29 30 bool operator==(const UserIPCInfo& other) const 31 { 32 return (((uid == other.uid) && (pid == other.pid)) || 33 ((uid == other.uid) && (other.pid == INVALID_PID)) || 34 ((other.uid == INVALID_PID) && (pid == other.pid)) || 35 ((other.uid == INVALID_PID) && (other.pid == INVALID_PID))); 36 } 37 }; 38 39 class RunningLockInner { 40 public: 41 RunningLockInner(const RunningLockInfo& runningLockInfo, const UserIPCInfo &userIPCinfo); 42 ~RunningLockInner() = default; 43 44 static std::shared_ptr<RunningLockInner> CreateRunningLockInner(const RunningLockInfo& runningLockInfo, 45 const UserIPCInfo &userIPCinfo); 46 void SetWorkTriggerList(const WorkTriggerList& workTriggerList); 47 void DumpInfo(const std::string& description); 48 GetRunningLockType()49 RunningLockType GetRunningLockType() const 50 { 51 return runningLockInfo_.type; 52 } GetRunningLockName()53 const std::string& GetRunningLockName() const 54 { 55 return runningLockInfo_.name; 56 } GetRunningLockInfo()57 const RunningLockInfo& GetRunningLockInfo() const 58 { 59 return runningLockInfo_; 60 } GetUserIPCInfo()61 const UserIPCInfo& GetUserIPCInfo() const 62 { 63 return userIPCinfo_; 64 } SetDisabled(bool disabled)65 void SetDisabled(bool disabled) 66 { 67 disabled_ = disabled; 68 } GetDisabled()69 bool GetDisabled() const 70 { 71 return disabled_; 72 } SetReallyLocked(bool reallyLocked)73 void SetReallyLocked(bool reallyLocked) 74 { 75 reallyLocked_ = reallyLocked; 76 } GetReallyLocked()77 bool GetReallyLocked() const 78 { 79 return reallyLocked_; 80 } SetOverTimeFlag(bool overTimeFlag)81 void SetOverTimeFlag(bool overTimeFlag) 82 { 83 overTimeFlag_ = overTimeFlag; 84 } GetOverTimeFlag()85 bool GetOverTimeFlag() const 86 { 87 return overTimeFlag_; 88 } GetLockTimeMs()89 int64_t GetLockTimeMs() const 90 { 91 return lockTimeMs_; 92 } 93 94 private: 95 std::mutex mutex_; 96 RunningLockInfo runningLockInfo_; 97 UserIPCInfo userIPCinfo_; 98 bool disabled_ {true}; 99 bool reallyLocked_ {false}; 100 bool overTimeFlag_ {false}; 101 int64_t lockTimeMs_ {0}; 102 }; 103 } // namespace PowerMgr 104 } // namespace OHOS 105 #endif // POWERMGR_RUNNING_LOCK_INNER_H 106