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 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 "power_errors.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 = 0, 36 /** 37 * RunningLock type: used to keep cpu running. 38 */ 39 RUNNINGLOCK_BACKGROUND = 1, 40 /** 41 * RunningLock type: used to keep the screen on/off when the proximity sensor is active. 42 */ 43 RUNNINGLOCK_PROXIMITY_SCREEN_CONTROL = 2, 44 /** 45 * RunningLock type: keeping image transmission when the current screen is off. 46 */ 47 RUNNINGLOCK_COORDINATION = 4, 48 /** 49 * Background runningLock type, keeping phone background task active. 50 */ 51 RUNNINGLOCK_BACKGROUND_PHONE = RUNNINGLOCK_BACKGROUND | 1 << 1, // 0b00000011 52 /** 53 * Background runningLock type, keeping notification background task active. 54 */ 55 RUNNINGLOCK_BACKGROUND_NOTIFICATION = RUNNINGLOCK_BACKGROUND | 1 << 2, // 0b00000101 56 /** 57 * Background runningLock type, keeping audio background task active. 58 */ 59 RUNNINGLOCK_BACKGROUND_AUDIO = RUNNINGLOCK_BACKGROUND | 1 << 3, // 0b00001001 60 /** 61 * Background runningLock type, keeping sport background task active. 62 */ 63 RUNNINGLOCK_BACKGROUND_SPORT = RUNNINGLOCK_BACKGROUND | 1 << 4, // 0b00010001 64 /** 65 * Background runningLock type, keeping navigation background task active. 66 */ 67 RUNNINGLOCK_BACKGROUND_NAVIGATION = RUNNINGLOCK_BACKGROUND | 1 << 5, // 0b00100001 68 /** 69 * Background runningLock type, keeping common background task active. 70 */ 71 RUNNINGLOCK_BACKGROUND_TASK = RUNNINGLOCK_BACKGROUND | 1 << 6, // 0b01000001 72 /** 73 * RunningLock reserved type. 74 */ 75 RUNNINGLOCK_BUTT 76 }; 77 78 /** 79 * Maintain runninglock information. 80 */ 81 struct RunningLockInfo : public Parcelable { 82 /** 83 * RunningLock name: used to identify user of the runninglock. 84 * You are advised to set it to a combination of information, 85 * such as package name and class name and a unique name. 86 */ 87 std::string name; 88 89 /** 90 * RunningLock type: used to identify the type of RunningLock. 91 */ 92 RunningLockType type; 93 94 std::string bundleName; 95 int32_t pid = 0; 96 int32_t uid = 0; 97 RunningLockInfo() = default; RunningLockInfoRunningLockInfo98 RunningLockInfo(const std::string& namestr, RunningLockType locktype) : name(namestr), type(locktype) {} 99 bool ReadFromParcel(Parcel& parcel); 100 bool Marshalling(Parcel& parcel) const override; 101 static RunningLockInfo* Unmarshalling(Parcel& parcel); 102 }; 103 104 class VectorPair : public Parcelable { 105 public: SetProcessInfos(const std::vector<std::pair<pid_t,pid_t>> & processInfos)106 inline void SetProcessInfos(const std::vector<std::pair<pid_t, pid_t>> &processInfos) 107 { 108 processInfos_ = processInfos; 109 } 110 GetProcessInfos()111 inline std::vector<std::pair<pid_t, pid_t>> GetProcessInfos() const 112 { 113 return processInfos_; 114 } 115 116 virtual bool Marshalling(Parcel &parcel) const override; 117 static VectorPair* Unmarshalling(Parcel &parcel); 118 119 private: 120 std::vector<std::pair<pid_t, pid_t>> processInfos_; 121 }; 122 } // namespace PowerMgr 123 } // namespace OHOS 124 #endif // POWERMGR_RUNNING_LOCK_INFO_H 125