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 int32_t systemAbilityId = -1; 54 std::string deviceId; 55 sptr<ISystemAbilityLoadCallback> callback; 56 int32_t callingPid = -1; 57 OnDemandEvent loadEvent; 58 }; 59 60 struct UnloadRequestInfo { 61 int32_t systemAbilityId = -1; 62 OnDemandEvent unloadEvent; 63 int32_t callingPid = -1; 64 }; 65 66 struct SystemProcessContext { 67 std::u16string processName; 68 int32_t pid = -1; 69 int32_t uid = -1; 70 std::list<int32_t> saList; 71 std::mutex processLock; 72 SystemProcessState state = SystemProcessState::NOT_STARTED; 73 std::shared_mutex stateCountLock; 74 std::map<SystemAbilityState, uint32_t> abilityStateCountMap; 75 std::list<int64_t> restartCountsCtrl; 76 bool enableRestart = true; 77 }; 78 79 struct SystemAbilityContext { 80 int32_t systemAbilityId = -1; 81 std::shared_ptr<SystemProcessContext> ownProcessContext; 82 SystemAbilityState state = SystemAbilityState::NOT_LOADED; 83 PendingEvent pendingEvent = PendingEvent::NO_EVENT; 84 std::map<int32_t, int32_t> pendingLoadEventCountMap; 85 std::list<LoadRequestInfo> pendingLoadEventList; 86 UnloadRequestInfo pendingUnloadEvent; 87 int32_t delayUnloadTime = 0; 88 UnloadRequestInfo unloadRequest; 89 bool isAutoRestart = false; 90 }; 91 } // namespace OHOS 92 93 #endif // !defined(OHOS_SYSTEM_ABILITY_MANAGER_SYSTEM_ABILITY_STATE_CONTEXT_H)