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