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 UNREF_EVENT, 35 }; 36 37 enum { 38 // sa load key stage 39 SA_LOAD_OPENSO = 1, 40 SA_LOAD_ON_START, 41 42 // sa unload key stage 43 SA_UNLOAD_ON_STOP = 10, 44 }; 45 46 enum { 47 START_ON_DEMAND = 1, 48 STOP_ON_DEMAND, 49 }; 50 51 enum { 52 START = 1, 53 KILL, 54 FREEZE, 55 }; 56 57 enum { 58 HIGH_PRIORITY = 1, 59 MEDIUM_PRIORITY = 2, 60 LOW_PRIORITY = 3, 61 }; 62 63 enum { 64 IMMEDIATELY = 0, 65 LOW_MEMORY, 66 }; 67 68 struct OnDemandCondition { 69 int32_t eventId; 70 std::string name; 71 std::string value; 72 std::map<std::string, std::string> extraMessages; 73 }; 74 75 struct OnDemandEvent { 76 int32_t eventId; 77 std::string name; 78 std::string value; 79 int64_t extraDataId = -1; 80 bool persistence = false; 81 std::vector<OnDemandCondition> conditions; 82 bool enableOnce = false; 83 uint32_t loadPriority = LOW_PRIORITY; 84 std::map<std::string, std::string> extraMessages; 85 86 bool operator==(const OnDemandEvent& event) const 87 { 88 return this->eventId == event.eventId && this->name == event.name && this->value == event.value; 89 } 90 ToStringOnDemandEvent91 std::string ToString() const 92 { 93 return this->name + "_" + this->value; 94 } 95 }; 96 97 struct SaControlInfo { 98 int32_t ondemandId; 99 int32_t saId; 100 bool enableOnce = false; 101 uint32_t loadPriority = LOW_PRIORITY; 102 bool cacheCommonEvent = false; 103 }; 104 105 struct StartOnDemand { 106 bool allowUpdate = false; 107 std::vector<OnDemandEvent> onDemandEvents; 108 }; 109 110 struct StopOnDemand { 111 bool allowUpdate = false; 112 bool unrefUnload = false; 113 int32_t delayTime = 20000; 114 int32_t unusedTimeout = -1; 115 std::vector<OnDemandEvent> onDemandEvents; 116 }; 117 118 struct SaProfile { 119 std::u16string process; 120 int32_t saId = 0; 121 std::string libPath; 122 std::vector<int32_t> dependSa; 123 int32_t dependTimeout = 0; 124 bool runOnCreate = false; 125 bool moduleUpdate = false; 126 bool autoRestart = false; 127 bool distributed = false; 128 int32_t dumpLevel = 0; 129 std::u16string capability; 130 std::u16string permission; 131 // default OTHER_START 132 uint32_t bootPhase = 3; 133 StartOnDemand startOnDemand; 134 StopOnDemand stopOnDemand; 135 DlHandle handle = nullptr; 136 int32_t recycleStrategy = IMMEDIATELY; 137 std::list<std::string> extension; 138 bool cacheCommonEvent = false; 139 }; 140 141 struct CommonSaProfile { 142 std::u16string process; 143 int32_t saId = 0; 144 bool moduleUpdate = false; 145 bool distributed = false; 146 bool cacheCommonEvent = false; 147 bool startAllowUpdate = false; 148 bool stopAllowUpdate = false; 149 int32_t recycleStrategy = IMMEDIATELY; 150 std::list<std::string> extension; 151 }; 152 153 struct CollMgrSaProfile { 154 int32_t saId = 0; 155 std::vector<OnDemandEvent> startOnDemandEvents; 156 std::vector<OnDemandEvent> stopOnDemandEvents; 157 bool cacheCommonEvent = false; 158 }; 159 } 160 #endif // SAMGR_INTERFACE_INNERKITS_COMMOM_INCLUDE_SAPROFILE_H 161