1 /*
2  * Copyright (c) 2022-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 SAMGR_INTERFACE_INNERKITS_COMMOM_INCLUDE_SAPROFILE_H
17 #define SAMGR_INTERFACE_INNERKITS_COMMOM_INCLUDE_SAPROFILE_H
18 
19 #include <map>
20 #include <string>
21 #include <vector>
22 #include <list>
23 
24 namespace OHOS {
25 using DlHandle = void*;
26 
27 enum {
28     INTERFACE_CALL = 0,
29     DEVICE_ONLINE,
30     SETTING_SWITCH,
31     PARAM,
32     COMMON_EVENT,
33     TIMED_EVENT,
34 };
35 
36 enum {
37     // sa load key stage
38     SA_LOAD_OPENSO = 1,
39     SA_LOAD_ON_START,
40 
41     // sa unload key stage
42     SA_UNLOAD_ON_STOP = 10,
43 };
44 
45 enum {
46     START_ON_DEMAND = 1,
47     STOP_ON_DEMAND,
48 };
49 
50 enum {
51     START = 1,
52     KILL,
53     FREEZE,
54 };
55 
56 enum {
57     HIGH_PRIORITY = 1,
58     MEDIUM_PRIORITY = 2,
59     LOW_PRIORITY = 3,
60 };
61 
62 enum {
63     IMMEDIATELY = 0,
64     LOW_MEMORY,
65 };
66 
67 struct OnDemandCondition {
68     int32_t eventId;
69     std::string name;
70     std::string value;
71     std::map<std::string, std::string> extraMessages;
72 };
73 
74 struct OnDemandEvent {
75     int32_t eventId;
76     std::string name;
77     std::string value;
78     int64_t extraDataId = -1;
79     bool persistence = false;
80     std::vector<OnDemandCondition> conditions;
81     bool enableOnce = false;
82     uint32_t loadPriority = LOW_PRIORITY;
83     std::map<std::string, std::string> extraMessages;
84 
85     bool operator==(const OnDemandEvent& event) const
86     {
87         return this->eventId == event.eventId && this->name == event.name && this->value == event.value;
88     }
89 
ToStringOnDemandEvent90     std::string ToString() const
91     {
92         return this->name + "_" + this->value;
93     }
94 };
95 
96 struct SaControlInfo {
97     int32_t ondemandId;
98     int32_t saId;
99     bool enableOnce = false;
100     uint32_t loadPriority = LOW_PRIORITY;
101     bool cacheCommonEvent = false;
102 };
103 
104 struct StartOnDemand {
105     bool allowUpdate = false;
106     std::vector<OnDemandEvent> onDemandEvents;
107 };
108 
109 struct StopOnDemand {
110     bool allowUpdate = false;
111     int32_t delayTime = 20000;
112     std::vector<OnDemandEvent> onDemandEvents;
113 };
114 
115 struct SaProfile {
116     std::u16string process;
117     int32_t saId = 0;
118     std::string libPath;
119     std::vector<int32_t> dependSa;
120     int32_t dependTimeout = 0;
121     bool runOnCreate = false;
122     bool moduleUpdate = false;
123     bool autoRestart = false;
124     bool distributed = false;
125     int32_t dumpLevel = 0;
126     std::u16string capability;
127     std::u16string permission;
128     // default OTHER_START
129     uint32_t bootPhase = 3;
130     StartOnDemand startOnDemand;
131     StopOnDemand stopOnDemand;
132     DlHandle handle = nullptr;
133     int32_t recycleStrategy = IMMEDIATELY;
134     std::list<std::string> extension;
135     bool cacheCommonEvent = false;
136 };
137 }
138 #endif // SAMGR_INTERFACE_INNERKITS_COMMOM_INCLUDE_SAPROFILE_H
139