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 OHOS_SYSTEM_ABILITY_MANAGER_SYSTEM_ABILITY_STATE_CONTEXT_H 17 #define OHOS_SYSTEM_ABILITY_MANAGER_SYSTEM_ABILITY_STATE_CONTEXT_H 18 19 #include <list> 20 #include <map> 21 #include <memory> 22 #include <mutex> 23 #include <string> 24 #include <shared_mutex> 25 26 #include "refbase.h" 27 #include "sa_profiles.h" 28 #include "isystem_ability_load_callback.h" 29 #include "sa_profiles.h" 30 31 namespace OHOS { 32 enum class SystemAbilityState { 33 NOT_LOADED = 0, 34 LOADING, 35 LOADED, 36 UNLOADABLE, 37 UNLOADING, 38 }; 39 40 enum class SystemProcessState { 41 NOT_STARTED = 0, 42 STARTED, 43 STOPPING, 44 }; 45 46 enum class PendingEvent { 47 NO_EVENT = 0, 48 LOAD_ABILITY_EVENT, 49 UNLOAD_ABILITY_EVENT, 50 }; 51 52 struct LoadRequestInfo { 53 std::string deviceId; 54 sptr<ISystemAbilityLoadCallback> callback; 55 int32_t systemAbilityId = -1; 56 int32_t callingPid = -1; 57 OnDemandEvent loadEvent; 58 }; 59 60 struct UnloadRequestInfo { 61 OnDemandEvent unloadEvent; 62 int32_t systemAbilityId; 63 int32_t callingPid; 64 UnloadRequestInfo(OnDemandEvent ue, int32_t said = -1, int32_t cpid = -1) 65 :unloadEvent(ue), systemAbilityId(said), callingPid(cpid) {} 66 }; 67 68 struct SystemProcessContext { 69 std::mutex stateCountLock; 70 std::mutex processLock; 71 std::u16string processName; 72 std::list<int32_t> saList; 73 std::map<SystemAbilityState, uint32_t> abilityStateCountMap; 74 std::list<int64_t> restartCountsCtrl; 75 int32_t pid = -1; 76 int32_t uid = -1; 77 SystemProcessState state = SystemProcessState::NOT_STARTED; 78 bool enableRestart = true; 79 }; 80 81 struct SystemAbilityContext { 82 std::map<int32_t, int32_t> pendingLoadEventCountMap; 83 std::list<LoadRequestInfo> pendingLoadEventList; 84 std::shared_ptr<SystemProcessContext> ownProcessContext; 85 std::shared_ptr<UnloadRequestInfo> pendingUnloadEvent; 86 std::shared_ptr<UnloadRequestInfo> unloadRequest; 87 int32_t systemAbilityId = -1; 88 int32_t delayUnloadTime = 0; 89 int64_t lastStartTime = 0; 90 SystemAbilityState state = SystemAbilityState::NOT_LOADED; 91 PendingEvent pendingEvent = PendingEvent::NO_EVENT; 92 bool isAutoRestart = false; 93 }; 94 } // namespace OHOS 95 96 #endif // !defined(OHOS_SYSTEM_ABILITY_MANAGER_SYSTEM_ABILITY_STATE_CONTEXT_H)