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 16 #ifndef OHOS_HDI_POWER_V1_2_RUNNINGLOCKIMPL_H 17 #define OHOS_HDI_POWER_V1_2_RUNNINGLOCKIMPL_H 18 19 #include <cstdint> 20 #include <map> 21 #include <mutex> 22 23 #include "running_lock_counter.h" 24 #include "running_lock_timer_handler.h" 25 #include "v1_2/power_types.h" 26 #include "v1_2/ipower_running_lock_callback.h" 27 #include "v1_2/running_lock_types.h" 28 29 namespace OHOS { 30 namespace HDI { 31 namespace Power { 32 namespace V1_2 { 33 class RunningLockImpl { 34 public: 35 static int32_t Hold(const RunningLockInfo &info, PowerHdfState state, 36 uint64_t lockid = 0, const std::string &bundleName = ""); 37 static int32_t Unhold(const RunningLockInfo &info, 38 uint64_t lockid = 0, const std::string &bundleName = ""); 39 static int32_t HoldLock(const RunningLockInfo &info, PowerHdfState state, 40 uint64_t lockid = 0, const std::string &bundleName = ""); 41 static int32_t UnholdLock(const RunningLockInfo &info, 42 uint64_t lockid = 0, const std::string &bundleName = ""); 43 static void Clean(); 44 static uint32_t GetCount(RunningLockType type); 45 static std::string GetRunningLockTag(RunningLockType type); 46 static std::string GetRunningLockTagInner(RunningLockType type); 47 static void SetDefaultTimeOutMs(int32_t timeOutMs); 48 49 static void RegisterRunningLockCallback(const sptr<IPowerRunningLockCallback> 50 &iPowerRunningLockCallback); 51 static void UnRegisterRunningLockCallback(); 52 53 static void NotifyChanged(const RunningLockInfo &info, 54 const uint64_t &lockid, const std::string &bundleName, const std::string &tag); 55 56 private: 57 static bool IsValidType(RunningLockType type, PowerHdfState state = PowerHdfState::AWAKE); 58 static RunningLockInfo FillRunningLockInfo(const RunningLockInfo &info); 59 static std::mutex mutex_; 60 static int32_t defaultTimeOutMs_; 61 static std::unique_ptr<RunningLockTimerHandler> timerHandler_; 62 static std::map<RunningLockType, std::shared_ptr<RunningLockCounter>> lockCounters_; 63 }; 64 65 } // namespace V1_2 66 } // namespace Power 67 } // namespace HDI 68 } // namespace OHOS 69 70 #endif // OHOS_HDI_POWER_V1_2_RUNNINGLOCKIMPL_H 71