1 /* 2 * Copyright (c) 2021-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 INTERFACES_INNERKITS_SAMGR_INCLUDE_IF_SYSTEM_ABILITY_MANAGER_H 17 #define INTERFACES_INNERKITS_SAMGR_INCLUDE_IF_SYSTEM_ABILITY_MANAGER_H 18 19 #include <string> 20 #include <list> 21 22 #include "iremote_broker.h" 23 #include "iremote_object.h" 24 #include "iremote_proxy.h" 25 #include "isystem_ability_load_callback.h" 26 #include "isystem_ability_status_change.h" 27 #include "isystem_process_status_change.h" 28 #include "samgr_ipc_interface_code.h" 29 #include "system_ability_on_demand_event.h" 30 31 namespace OHOS { 32 33 struct IdleProcessInfo { 34 int32_t pid = -1; 35 std::u16string processName; 36 int64_t lastIdleTime = 0; 37 }; 38 39 class ISystemAbilityManager : public IRemoteBroker { 40 public: 41 /** 42 * ListSystemAbilities, Return list of all existing abilities. 43 * 44 * @param dumpFlags, dump all. 45 * @return Returns the sa where the current samgr exists. 46 */ 47 virtual std::vector<std::u16string> ListSystemAbilities(unsigned int dumpFlags = DUMP_FLAG_PRIORITY_ALL) = 0; 48 49 enum { 50 SHEEFT_CRITICAL = 0, 51 SHEEFT_HIGH, 52 SHEEFT_NORMAL, 53 SHEEFT_DEFAULT, 54 SHEEFT_PROTO, 55 }; 56 57 static const unsigned int DUMP_FLAG_PRIORITY_CRITICAL = 1 << SHEEFT_CRITICAL; 58 static const unsigned int DUMP_FLAG_PRIORITY_HIGH = 1 << SHEEFT_HIGH; 59 static const unsigned int DUMP_FLAG_PRIORITY_NORMAL = 1 << SHEEFT_NORMAL; 60 61 static const unsigned int DUMP_FLAG_PRIORITY_DEFAULT = 1 << SHEEFT_DEFAULT; 62 static const unsigned int DUMP_FLAG_PRIORITY_ALL = DUMP_FLAG_PRIORITY_CRITICAL | 63 DUMP_FLAG_PRIORITY_HIGH | DUMP_FLAG_PRIORITY_NORMAL | DUMP_FLAG_PRIORITY_DEFAULT; 64 static const unsigned int DUMP_FLAG_PROTO = 1 << SHEEFT_PROTO; 65 66 /** 67 * GetSystemAbility, Retrieve an existing ability, retrying and blocking for a few seconds if it doesn't exist. 68 * 69 * @param systemAbilityId, Need to obtain the said of sa. 70 * @return nullptr indicates acquisition failure. 71 */ 72 virtual sptr<IRemoteObject> GetSystemAbility(int32_t systemAbilityId) = 0; 73 74 /** 75 * CheckSystemAbility, Retrieve an existing ability, no-blocking. 76 * 77 * @param systemAbilityId, Need to obtain the said of sa. 78 * @return nullptr indicates acquisition failure. 79 */ 80 virtual sptr<IRemoteObject> CheckSystemAbility(int32_t systemAbilityId) = 0; 81 82 /** 83 * RemoveSystemAbility, Remove an ability. 84 * 85 * @param systemAbilityId, Need to remove the said of sa. 86 * @return ERR_OK indicates remove success. 87 */ 88 virtual int32_t RemoveSystemAbility(int32_t systemAbilityId) = 0; 89 90 /** 91 * SubscribeSystemAbility, Subscribe a system ability status. 92 * 93 * @param systemAbilityId, Need to subscribe the said of sa. 94 * @param listener, Need to implement OnAddSystemAbility, OnRemoveSystemAbility. 95 * @return ERR_OK indicates SubscribeSystemAbility success. 96 */ 97 virtual int32_t SubscribeSystemAbility(int32_t systemAbilityId, 98 const sptr<ISystemAbilityStatusChange>& listener) = 0; 99 100 /** 101 * UnSubscribeSystemAbility, UnSubscribe a system ability status. 102 * 103 * @param systemAbilityId, Need to UnSubscribe the said of sa. 104 * @param listener, Need to implement OnAddSystemAbility, OnRemoveSystemAbility. 105 * @return ERR_OK indicates SubscribeSystemAbility success. 106 */ 107 virtual int32_t UnSubscribeSystemAbility(int32_t systemAbilityId, 108 const sptr<ISystemAbilityStatusChange>& listener) = 0; 109 110 /** 111 * GetSystemAbility, Retrieve an existing ability, blocking for a few seconds if it doesn't exist. 112 * 113 * @param systemAbilityId, Need to get the said of sa. 114 * @param deviceId, If the device id is empty, it indicates that it is a local get. 115 * @return nullptr indicates acquisition failure. 116 */ 117 virtual sptr<IRemoteObject> GetSystemAbility(int32_t systemAbilityId, const std::string& deviceId) = 0; 118 119 /** 120 * CheckSystemAbility, Retrieve an existing ability, no-blocking. 121 * 122 * @param systemAbilityId, Need to get the said of sa. 123 * @param deviceId, If the device id is empty, it indicates that it is a local get. 124 * @return nullptr indicates acquisition failure. 125 */ 126 virtual sptr<IRemoteObject> CheckSystemAbility(int32_t systemAbilityId, const std::string& deviceId) = 0; 127 128 /** 129 * AddOnDemandSystemAbilityInfo, Add ondemand ability info. 130 * 131 * @param systemAbilityId, Need to add info the said of sa. 132 * @param localAbilityManagerName, Process Name. 133 * @return ERR_OK indicates AddOnDemandSystemAbilityInfo success. 134 */ 135 virtual int32_t AddOnDemandSystemAbilityInfo(int32_t systemAbilityId, 136 const std::u16string& localAbilityManagerName) = 0; 137 138 /** 139 * CheckSystemAbility, Retrieve an ability, no-blocking. 140 * 141 * @param systemAbilityId, Need to check the said of sa. 142 * @param isExist, Issue parameters, and a result of true indicates success. 143 * @return nullptr indicates acquisition failure. 144 */ 145 virtual sptr<IRemoteObject> CheckSystemAbility(int32_t systemAbilityId, bool& isExist) = 0; 146 147 struct SAExtraProp { 148 SAExtraProp() = default; SAExtraPropSAExtraProp149 SAExtraProp(bool isDistributed, unsigned int dumpFlags, const std::u16string& capability, 150 const std::u16string& permission) 151 { 152 this->isDistributed = isDistributed; 153 this->dumpFlags = dumpFlags; 154 this->capability = capability; 155 this->permission = permission; 156 } 157 158 bool isDistributed = false; 159 unsigned int dumpFlags = DUMP_FLAG_PRIORITY_DEFAULT; 160 std::u16string capability; 161 std::u16string permission; 162 }; 163 164 /** 165 * AddSystemAbility, add an ability to samgr. 166 * 167 * @param systemAbilityId, Need to add the said of sa. 168 * @param ability, SA to be added. 169 * @param extraProp, Additional parameters for sa, such as whether it is distributed. 170 * @return ERR_OK indicates successful add. 171 */ 172 virtual int32_t AddSystemAbility(int32_t systemAbilityId, const sptr<IRemoteObject>& ability, 173 const SAExtraProp& extraProp = SAExtraProp(false, DUMP_FLAG_PRIORITY_DEFAULT, u"", u"")) = 0; 174 175 /** 176 * AddSystemProcess, add an process. 177 * 178 * @param procName, Need to add the procName of process. 179 * @param procObject, Remoteobject of procName. 180 * @return ERR_OK indicates successful add. 181 */ 182 virtual int32_t AddSystemProcess(const std::u16string& procName, const sptr<IRemoteObject>& procObject) = 0; 183 184 /** 185 * LoadSystemAbility, Load sa. 186 * 187 * @param systemAbilityId, Need to load the said of sa. 188 * @param timeout, limited time to load sa. 189 * @return remote object means that the load was successful. 190 */ 191 virtual sptr<IRemoteObject> LoadSystemAbility(int32_t systemAbilityId, int32_t timeout) = 0; 192 193 /** 194 * LoadSystemAbility, Load sa. 195 * 196 * @param systemAbilityId, Need to load the said of sa. 197 * @param callback, OnLoadSystemAbilityFail and OnLoadSystemAbilitySuccess need be rewritten. 198 * @return ERR_OK It does not mean that the load was successful. 199 */ 200 virtual int32_t LoadSystemAbility(int32_t systemAbilityId, const sptr<ISystemAbilityLoadCallback>& callback) = 0; 201 202 /** 203 * LoadSystemAbility, Load sa. 204 * 205 * @param systemAbilityId, Need to load the said of sa. 206 * @param deviceId, if deviceId is empty, it indicates local load. 207 * @param callback, OnLoadSystemAbilityFail and OnLoadSystemAbilitySuccess need be rewritten. 208 * @return ERR_OK It does not mean that the load was successful. 209 */ 210 virtual int32_t LoadSystemAbility(int32_t systemAbilityId, const std::string& deviceId, 211 const sptr<ISystemAbilityLoadCallback>& callback) = 0; 212 213 /** 214 * UnloadSystemAbility, UnLoad sa. 215 * 216 * @param systemAbilityId, Need to UnLoad the said of sa. 217 * @return ERR_OK It does not mean that the unload was successful, but sa entered an idle state. 218 */ 219 virtual int32_t UnloadSystemAbility(int32_t systemAbilityId) = 0; 220 221 /** 222 * CancelUnloadSystemAbility, CancelUnload sa. 223 * 224 * @param systemAbilityId, Need to CancelUnload the said of sa. 225 * @return ERR_OK indicates that the uninstall was canceled successfully. 226 */ 227 virtual int32_t CancelUnloadSystemAbility(int32_t systemAbilityId) = 0; 228 229 /** 230 * UnloadAllIdleSystemAbility, unload all idle sa. 231 * only support for memmgrservice 232 * 233 * @return ERR_OK It means unload all idle sa success. 234 */ 235 virtual int32_t UnloadAllIdleSystemAbility() = 0; 236 237 /** 238 * UnloadProcess, unload process by process name list. 239 * only support for memmgrservice 240 * 241 * @param processList, Need a processList to unload. 242 * @return ERR_OK It means unload process in processList success. 243 */ UnloadProcess(const std::vector<std::u16string> & processList)244 virtual int32_t UnloadProcess(const std::vector<std::u16string>& processList) 245 { 246 (void)processList; 247 return 0; 248 } 249 250 /** 251 * GetLruIdleSystemAbilityProc, Get idle process info list. 252 * only support for memmgrservice 253 * 254 * @param processInfos, Issue a parameter and return it as a result. 255 * @return ERR_OK indicates that the get successfully. 256 */ GetLruIdleSystemAbilityProc(std::vector<IdleProcessInfo> & processInfos)257 virtual int32_t GetLruIdleSystemAbilityProc(std::vector<IdleProcessInfo>& processInfos) 258 { 259 (void)processInfos; 260 return 0; 261 } 262 263 /** 264 * GetSystemProcessInfo, Get process info by said. 265 * 266 * @param systemAbilityId, Need the said of sa which wants to get process info. 267 * @param systemProcessInfo, Issue a parameter and return it as a result. 268 * @return ERR_OK indicates that the get successfully. 269 */ 270 virtual int32_t GetSystemProcessInfo(int32_t systemAbilityId, SystemProcessInfo& systemProcessInfo) = 0; 271 272 /** 273 * GetRunningSystemProcess, Get all processes currently running. 274 * 275 * @param systemProcessInfos, Issue a parameter and return it as a result. 276 * @return ERR_OK indicates that the get successfully. 277 */ 278 virtual int32_t GetRunningSystemProcess(std::list<SystemProcessInfo>& systemProcessInfos) = 0; 279 280 /** 281 * SubscribeSystemProcess, Subscribe the status of process. 282 * 283 * @param listener, callback 284 * @return ERR_OK indicates that the Subscribe successfully. 285 */ 286 virtual int32_t SubscribeSystemProcess(const sptr<ISystemProcessStatusChange>& listener) = 0; 287 288 /** 289 * SendStrategy, Send strategy to SA. 290 * 291 * @param type, type is a certain device status type. 292 * @param systemAbilityIds, Need the vector of said which wants to send strategy. 293 * @param level, level is level of a certain device status type. 294 * @param action, action is scheduling strategy. 295 * @return ERR_OK indicates that the Subscribe successfully. 296 */ 297 virtual int32_t SendStrategy(int32_t type, std::vector<int32_t>& systemAbilityIds, 298 int32_t level, std::string& action) = 0; 299 300 /** 301 * UnSubscribeSystemProcess, UnSubscribe the status of process. 302 * 303 * @param listener, callback 304 * @return ERR_OK indicates that the UnSubscribe successfully. 305 */ 306 virtual int32_t UnSubscribeSystemProcess(const sptr<ISystemProcessStatusChange>& listener) = 0; 307 308 /** 309 * GetExtensionSaIds, Return list of saId that match extension. 310 * 311 * @param extension, extension, match with profile extension. 312 * @param saIds, list of saId that match extension 313 * @return ERR_OK indicates that the list of saId that match extension success. 314 */ 315 virtual int32_t GetExtensionSaIds(const std::string& extension, std::vector<int32_t> &saIds) = 0; 316 317 /** 318 * GetExtensionRunningSaList, Return started list of hanlde that match extension. 319 * 320 * @param extension, extension, match with profile extension. 321 * @param saList, started list of remote obj that match extension 322 * @return ERR_OK indicates that the list of hanlde that match extension success. 323 */ 324 virtual int32_t GetExtensionRunningSaList(const std::string& extension, 325 std::vector<sptr<IRemoteObject>>& saList) = 0; 326 327 /** 328 * GetLocalAbilityManagerProxy, Return local ability manager proxy. 329 * 330 * @param systemAbilityId, need to obtain the said of sa. 331 * @return nullptr indicates acquistion failure. 332 */ GetLocalAbilityManagerProxy(int32_t systemAbilityId)333 virtual sptr<IRemoteObject> GetLocalAbilityManagerProxy(int32_t systemAbilityId) 334 { 335 (void)systemAbilityId; 336 return nullptr; 337 } 338 339 /** 340 * GetRunningSaExtensionInfoList, Return list of started said and process hanlde that match extension. 341 * 342 * @param extension, extension, match with profile extension. 343 * @param infoList, list of started said and sa process remote obj that match extension 344 * @return ERR_OK indicates that the list of hanlde that match extension success. 345 */ 346 struct SaExtensionInfo { 347 int32_t saId = -1; 348 sptr<IRemoteObject> processObj = nullptr; 349 }; 350 virtual int32_t GetRunningSaExtensionInfoList(const std::string& extension, 351 std::vector<SaExtensionInfo>& infoList) = 0; 352 353 virtual int32_t GetCommonEventExtraDataIdlist(int32_t saId, std::vector<int64_t>& extraDataIdList, 354 const std::string& eventName = "") = 0; 355 356 virtual int32_t GetOnDemandReasonExtraData(int64_t extraDataId, MessageParcel& extraDataParcel) = 0; 357 virtual int32_t GetOnDemandPolicy(int32_t systemAbilityId, OnDemandPolicyType type, 358 std::vector<SystemAbilityOnDemandEvent>& abilityOnDemandEvents) = 0; 359 virtual int32_t UpdateOnDemandPolicy(int32_t systemAbilityId, OnDemandPolicyType type, 360 const std::vector<SystemAbilityOnDemandEvent>& abilityOnDemandEvents) = 0; 361 virtual int32_t GetOnDemandSystemAbilityIds(std::vector<int32_t>& systemAbilityIds) = 0; 362 public: 363 DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.ISystemAbilityManager"); 364 protected: 365 static constexpr int32_t FIRST_SYS_ABILITY_ID = 0x00000000; 366 static constexpr int32_t LAST_SYS_ABILITY_ID = 0x00ffffff; CheckInputSysAbilityId(int32_t sysAbilityId)367 bool CheckInputSysAbilityId(int32_t sysAbilityId) const 368 { 369 if (sysAbilityId >= FIRST_SYS_ABILITY_ID && sysAbilityId <= LAST_SYS_ABILITY_ID) { 370 return true; 371 } 372 return false; 373 } 374 static inline const std::u16string SAMANAGER_INTERFACE_TOKEN = u"ohos.samgr.accessToken"; 375 }; 376 } // namespace OHOS 377 378 #endif // !defined(INTERFACES_INNERKITS_SAMGR_INCLUDE_IF_SYSTEM_ABILITY_MANAGER_H ) 379