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_INFO_H 17 #define POWERMGR_RUNNING_LOCK_INFO_H 18 19 #include <list> 20 #include <string> 21 22 #include <parcel.h> 23 24 #include "work_trigger.h" 25 26 namespace OHOS { 27 namespace PowerMgr { 28 /** 29 * Runninglock acquisition type 30 */ 31 enum class RunningLockType : uint32_t { 32 /** 33 * RunningLock type: used to keep screen on. 34 */ 35 RUNNINGLOCK_SCREEN, 36 /** 37 * RunningLock type: used to keep cpu running. 38 */ 39 RUNNINGLOCK_BACKGROUND, 40 /** 41 * RunningLock type: used to keep the screen on/off when the proximity sensor is active. 42 */ 43 RUNNINGLOCK_PROXIMITY_SCREEN_CONTROL, 44 45 RUNNINGLOCK_BUTT 46 }; 47 48 using WorkTriggerList = std::list<std::shared_ptr<WorkTrigger>>; 49 50 /** 51 * Maintain runninglock information. 52 */ 53 struct RunningLockInfo : public Parcelable { 54 /** 55 * RunningLock name: used to identify user of the runninglock. 56 * You are advised to set it to a combination of information, 57 * such as package name and class name and a unique name. 58 */ 59 std::string name; 60 61 /** 62 * RunningLock type: used to identify the type of RunningLock. 63 */ 64 RunningLockType type; 65 66 /** 67 * WorkTriggerList: generally used to manintain the information about the application, 68 * which attempts to acquire the RunningLock. 69 */ 70 WorkTriggerList workTriggerlist; 71 RunningLockInfo() = default; RunningLockInfoRunningLockInfo72 RunningLockInfo(const std::string& namestr, RunningLockType locktype) : name(namestr), type(locktype) {} 73 bool ReadFromParcel(Parcel& parcel); 74 bool Marshalling(Parcel& parcel) const override; 75 static RunningLockInfo* Unmarshalling(Parcel& parcel); 76 static bool MarshallingWorkTriggerList(Parcel& parcel, const WorkTriggerList& list); 77 static bool ReadFromParcelWorkTriggerList(Parcel& parcel, WorkTriggerList& list); 78 }; 79 } // namespace PowerMgr 80 } // namespace OHOS 81 #endif // POWERMGR_RUNNING_LOCK_INFO_H 82