1 /*
2  * Copyright (c) 2021-2022 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 FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_PRE_SCAN_INFO_H
17 #define FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_PRE_SCAN_INFO_H
18 
19 #include <string>
20 
21 namespace OHOS {
22 namespace AppExecFwk {
23 namespace {
GetBoolStrVal(bool val)24     std::string GetBoolStrVal(bool val)
25     {
26         return val ? "true" : "false";
27     }
28 }
29 struct PreBundleConfigInfo {
30     std::string bundleName;
31     bool keepAlive = false;
32     bool singleton = false;
33     bool runningResourcesApply = false;
34     bool associatedWakeUp = false;
35     bool allowUsePrivilegeExtension = false;
36     bool allowMultiProcess = false;
37     bool formVisibleNotify = false;
38     bool allowQueryPriority = false;
39     bool allowExcludeFromMissions = false;
40     bool allowMissionNotCleared = false;
41     bool userDataClearable = true;
42     bool hideDesktopIcon = false;
43     bool appShareLibrary = false;
44     bool allowEnableNotification = false;
45     bool allowAppRunWhenDeviceFirstLocked = false;
46     std::vector<std::string> allowCommonEvent;
47     std::vector<std::string> appSignature;
48     std::vector<std::string> existInJsonFile;
49     std::vector<int32_t> resourcesApply;
50 
51     bool operator <(const PreBundleConfigInfo &preBundleConfigInfo) const
52     {
53         return bundleName < preBundleConfigInfo.bundleName;
54     }
55 
ResetPreBundleConfigInfo56     void Reset()
57     {
58         bundleName.clear();
59         keepAlive = false;
60         singleton = false;
61         runningResourcesApply = false;
62         associatedWakeUp = false;
63         allowUsePrivilegeExtension = false;
64         allowMultiProcess = false;
65         formVisibleNotify = false;
66         allowQueryPriority = false;
67         allowExcludeFromMissions = false;
68         allowMissionNotCleared = false;
69         userDataClearable = true;
70         hideDesktopIcon = false;
71         appShareLibrary = false;
72         allowEnableNotification = false;
73         allowAppRunWhenDeviceFirstLocked = false;
74         allowCommonEvent.clear();
75         appSignature.clear();
76         existInJsonFile.clear();
77         resourcesApply.clear();
78     }
79 
ToStringPreBundleConfigInfo80     std::string ToString() const
81     {
82         return "[ bundleName = " + bundleName
83             + ", keepAlive = " + GetBoolStrVal(keepAlive)
84             + ", singleton = " + GetBoolStrVal(singleton)
85             + ", runningResourcesApply = " + GetBoolStrVal(runningResourcesApply)
86             + ", associatedWakeUp = " + GetBoolStrVal(associatedWakeUp)
87             + ", allowUsePrivilegeExtension = " + GetBoolStrVal(allowUsePrivilegeExtension)
88             + ", allowMultiProcess = " + GetBoolStrVal(allowMultiProcess)
89             + ", formVisibleNotify = " + GetBoolStrVal(formVisibleNotify)
90             + ", allowQueryPriority = " + GetBoolStrVal(allowQueryPriority)
91             + ", allowExcludeFromMissions = " + GetBoolStrVal(allowExcludeFromMissions)
92             + ", allowMissionNotCleared = " + GetBoolStrVal(allowMissionNotCleared)
93             + ", userDataClearable = " + GetBoolStrVal(userDataClearable)
94             + ", hideDesktopIcon = " + GetBoolStrVal(hideDesktopIcon)
95             + ", appShareLibrary = " + GetBoolStrVal(appShareLibrary)
96             + ", allowAppRunWhenDeviceFirstLocked = " + GetBoolStrVal(allowAppRunWhenDeviceFirstLocked)
97             + ", allowEnableNotification = " + GetBoolStrVal(allowEnableNotification) + "]";
98     }
99 };
100 
101 struct PreScanInfo {
102     std::string bundleDir;
103     bool removable = true;
104     int32_t priority = 0;
105 
106     bool operator < (const PreScanInfo &preScanInfo) const
107     {
108         if (bundleDir == preScanInfo.bundleDir) {
109             return false;
110         }
111 
112         return priority >= preScanInfo.priority;
113     }
114 
115     friend bool operator == (const PreScanInfo& oldPreScanInfo, const PreScanInfo& newPreScanInfo)
116     {
117         return oldPreScanInfo.bundleDir == newPreScanInfo.bundleDir;
118     }
119 
ResetPreScanInfo120     void Reset()
121     {
122         bundleDir.clear();
123         removable = true;
124         priority = 0;
125     }
126 
ToStringPreScanInfo127     std::string ToString() const
128     {
129         return "[ bundleDir = " + bundleDir
130             + ", removable = " + GetBoolStrVal(removable)
131             + ", priority = " + std::to_string(priority) + "]";
132     }
133 };
134 }  // namespace AppExecFwk
135 }  // namespace OHOS
136 #endif  // FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_PRE_SCAN_INFO_H
137