• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <string>
23 
24 #include "samgr_ffrt_api.h"
25 #include "refbase.h"
26 #include "sa_profiles.h"
27 #include "isystem_ability_load_callback.h"
28 #include "sa_profiles.h"
29 
30 namespace OHOS {
31 enum class SystemAbilityState {
32     NOT_LOADED = 0,
33     LOADING,
34     LOADED,
35     UNLOADABLE,
36     UNLOADING,
37 };
38 
39 enum class SystemProcessState {
40     NOT_STARTED = 0,
41     STARTED,
42     STOPPING,
43 };
44 
45 enum class PendingEvent {
46     NO_EVENT = 0,
47     LOAD_ABILITY_EVENT,
48     UNLOAD_ABILITY_EVENT,
49 };
50 
51 struct LoadRequestInfo {
52     std::string deviceId;
53     sptr<ISystemAbilityLoadCallback> callback;
54     int32_t systemAbilityId = -1;
55     int32_t callingPid = -1;
56     OnDemandEvent loadEvent;
57 };
58 
59 struct UnloadRequestInfo {
60     OnDemandEvent unloadEvent;
61     int32_t systemAbilityId;
62     int32_t callingPid;
63     UnloadRequestInfo(OnDemandEvent ue, int32_t said = -1, int32_t cpid = -1)
unloadEventUnloadRequestInfo64         :unloadEvent(ue), systemAbilityId(said), callingPid(cpid) {}
65 };
66 
67 struct SystemProcessContext {
68     samgr::mutex stateCountLock;
69     samgr::mutex processLock;
70     std::u16string processName;
71     std::list<int32_t> saList;
72     std::map<SystemAbilityState, uint32_t> abilityStateCountMap;
73     std::list<int64_t> restartCountsCtrl;
74     int32_t pid = -1;
75     int32_t uid = -1;
76     SystemProcessState state = SystemProcessState::NOT_STARTED;
77     bool enableRestart = true;
78     int64_t lastStopTime = -1;
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     int64_t lastIdleTime = -1;
91     SystemAbilityState state = SystemAbilityState::NOT_LOADED;
92     PendingEvent pendingEvent = PendingEvent::NO_EVENT;
93     bool isAutoRestart = false;
94 };
95 } // namespace OHOS
96 
97 #endif // !defined(OHOS_SYSTEM_ABILITY_MANAGER_SYSTEM_ABILITY_STATE_CONTEXT_H)