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 namespace OHOS {
25 namespace PowerMgr {
26 /**
27  * Runninglock acquisition type
28  */
29 enum class RunningLockType : uint32_t {
30     /**
31      * RunningLock type: used to keep screen on.
32      */
33     RUNNINGLOCK_SCREEN = 0,
34     /**
35      * RunningLock type: used to keep cpu running.
36      */
37     RUNNINGLOCK_BACKGROUND = 1,
38     /**
39      * RunningLock type: used to keep the screen on/off when the proximity sensor is active.
40      */
41     RUNNINGLOCK_PROXIMITY_SCREEN_CONTROL = 2,
42     /**
43      * RunningLock type: keeping image transmission when the current screen is off.
44      */
45     RUNNINGLOCK_COORDINATION = 4,
46     /**
47      * Background runningLock type, keeping phone background task active.
48      */
49     RUNNINGLOCK_BACKGROUND_PHONE = RUNNINGLOCK_BACKGROUND | 1 << 1,  // 0b00000011
50     /**
51      * Background runningLock type, keeping notification background task active.
52      */
53     RUNNINGLOCK_BACKGROUND_NOTIFICATION =  RUNNINGLOCK_BACKGROUND | 1 << 2, // 0b00000101
54     /**
55      * Background runningLock type, keeping audio background task active.
56      */
57     RUNNINGLOCK_BACKGROUND_AUDIO =   RUNNINGLOCK_BACKGROUND | 1 << 3, // 0b00001001
58     /**
59      * Background runningLock type, keeping sport background task active.
60      */
61     RUNNINGLOCK_BACKGROUND_SPORT =  RUNNINGLOCK_BACKGROUND | 1 << 4, // 0b00010001
62     /**
63      * Background runningLock type, keeping navigation background task active.
64      */
65     RUNNINGLOCK_BACKGROUND_NAVIGATION =  RUNNINGLOCK_BACKGROUND | 1 << 5, // 0b00100001
66     /**
67      * Background runningLock type, keeping common background task active.
68      */
69     RUNNINGLOCK_BACKGROUND_TASK =  RUNNINGLOCK_BACKGROUND | 1 << 6, // 0b01000001
70     /**
71      * RunningLock reserved type.
72      */
73     RUNNINGLOCK_BUTT
74 };
75 
76 /**
77  * Maintain runninglock information.
78  */
79 struct RunningLockInfo : public Parcelable {
80     /**
81      * RunningLock name: used to identify user of the runninglock.
82      * You are advised to set it to a combination of information,
83      * such as package name and class name and a unique name.
84      */
85     std::string name;
86 
87     /**
88      * RunningLock type: used to identify the type of RunningLock.
89      */
90     RunningLockType type;
91 
92     std::string bundleName;
93     int32_t pid = 0;
94     int32_t uid = 0;
95     RunningLockInfo() = default;
RunningLockInfoRunningLockInfo96     RunningLockInfo(const std::string& namestr, RunningLockType locktype) : name(namestr), type(locktype) {}
97     bool ReadFromParcel(Parcel& parcel);
98     bool Marshalling(Parcel& parcel) const override;
99     static RunningLockInfo* Unmarshalling(Parcel& parcel);
100 };
101 } // namespace PowerMgr
102 } // namespace OHOS
103 #endif // POWERMGR_RUNNING_LOCK_INFO_H
104