• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 class ISystemAbilityManager : public IRemoteBroker {
33 public:
34     /**
35      * ListSystemAbilities, Return list of all existing abilities.
36      *
37      * @param dumpFlags, dump all.
38      * @return Returns the sa where the current samgr exists.
39      */
40     virtual std::vector<std::u16string> ListSystemAbilities(unsigned int dumpFlags = DUMP_FLAG_PRIORITY_ALL) = 0;
41 
42     enum {
43         SHEEFT_CRITICAL = 0,
44         SHEEFT_HIGH,
45         SHEEFT_NORMAL,
46         SHEEFT_DEFAULT,
47         SHEEFT_PROTO,
48     };
49 
50     static const unsigned int DUMP_FLAG_PRIORITY_CRITICAL = 1 << SHEEFT_CRITICAL;
51     static const unsigned int DUMP_FLAG_PRIORITY_HIGH = 1 << SHEEFT_HIGH;
52     static const unsigned int DUMP_FLAG_PRIORITY_NORMAL = 1 << SHEEFT_NORMAL;
53 
54     static const unsigned int DUMP_FLAG_PRIORITY_DEFAULT = 1 << SHEEFT_DEFAULT;
55     static const unsigned int DUMP_FLAG_PRIORITY_ALL = DUMP_FLAG_PRIORITY_CRITICAL |
56         DUMP_FLAG_PRIORITY_HIGH | DUMP_FLAG_PRIORITY_NORMAL | DUMP_FLAG_PRIORITY_DEFAULT;
57     static const unsigned int DUMP_FLAG_PROTO = 1 << SHEEFT_PROTO;
58 
59     /**
60      * GetSystemAbility, Retrieve an existing ability, retrying and blocking for a few seconds if it doesn't exist.
61      *
62      * @param systemAbilityId, Need to obtain the said of sa.
63      * @return nullptr indicates acquisition failure.
64      */
65     virtual sptr<IRemoteObject> GetSystemAbility(int32_t systemAbilityId) = 0;
66 
67     /**
68      * CheckSystemAbility, Retrieve an existing ability, no-blocking.
69      *
70      * @param systemAbilityId, Need to obtain the said of sa.
71      * @return nullptr indicates acquisition failure.
72      */
73     virtual sptr<IRemoteObject> CheckSystemAbility(int32_t systemAbilityId) = 0;
74 
75     /**
76      * RemoveSystemAbility, Remove an ability.
77      *
78      * @param systemAbilityId, Need to remove the said of sa.
79      * @return ERR_OK indicates remove success.
80      */
81     virtual int32_t RemoveSystemAbility(int32_t systemAbilityId) = 0;
82 
83     /**
84      * SubscribeSystemAbility, Subscribe a system ability status.
85      *
86      * @param systemAbilityId, Need to subscribe the said of sa.
87      * @param listener, Need to implement OnAddSystemAbility, OnRemoveSystemAbility.
88      * @return ERR_OK indicates SubscribeSystemAbility success.
89      */
90     virtual int32_t SubscribeSystemAbility(int32_t systemAbilityId,
91         const sptr<ISystemAbilityStatusChange>& listener) = 0;
92 
93     /**
94      * UnSubscribeSystemAbility, UnSubscribe a system ability status.
95      *
96      * @param systemAbilityId, Need to UnSubscribe the said of sa.
97      * @param listener, Need to implement OnAddSystemAbility, OnRemoveSystemAbility.
98      * @return ERR_OK indicates SubscribeSystemAbility success.
99      */
100     virtual int32_t UnSubscribeSystemAbility(int32_t systemAbilityId,
101         const sptr<ISystemAbilityStatusChange>& listener) = 0;
102 
103     /**
104      * GetSystemAbility, Retrieve an existing ability, blocking for a few seconds if it doesn't exist.
105      *
106      * @param systemAbilityId, Need to get the said of sa.
107      * @param deviceId, If the device id is empty, it indicates that it is a local get.
108      * @return nullptr indicates acquisition failure.
109      */
110     virtual sptr<IRemoteObject> GetSystemAbility(int32_t systemAbilityId, const std::string& deviceId) = 0;
111 
112     /**
113      * CheckSystemAbility, Retrieve an existing ability, no-blocking.
114      *
115      * @param systemAbilityId, Need to get the said of sa.
116      * @param deviceId, If the device id is empty, it indicates that it is a local get.
117      * @return nullptr indicates acquisition failure.
118      */
119     virtual sptr<IRemoteObject> CheckSystemAbility(int32_t systemAbilityId, const std::string& deviceId) = 0;
120 
121     /**
122      * AddOnDemandSystemAbilityInfo, Add ondemand ability info.
123      *
124      * @param systemAbilityId, Need to add info the said of sa.
125      * @param localAbilityManagerName, Process Name.
126      * @return ERR_OK indicates AddOnDemandSystemAbilityInfo success.
127      */
128     virtual int32_t AddOnDemandSystemAbilityInfo(int32_t systemAbilityId,
129         const std::u16string& localAbilityManagerName) = 0;
130 
131     /**
132      * CheckSystemAbility, Retrieve an ability, no-blocking.
133      *
134      * @param systemAbilityId, Need to check the said of sa.
135      * @param isExist, Issue parameters, and a result of true indicates success.
136      * @return nullptr indicates acquisition failure.
137      */
138     virtual sptr<IRemoteObject> CheckSystemAbility(int32_t systemAbilityId, bool& isExist) = 0;
139 
140     struct SAExtraProp {
141         SAExtraProp() = default;
SAExtraPropSAExtraProp142         SAExtraProp(bool isDistributed, unsigned int dumpFlags, const std::u16string& capability,
143             const std::u16string& permission)
144         {
145             this->isDistributed = isDistributed;
146             this->dumpFlags = dumpFlags;
147             this->capability = capability;
148             this->permission = permission;
149         }
150 
151         bool isDistributed = false;
152         unsigned int dumpFlags = DUMP_FLAG_PRIORITY_DEFAULT;
153         std::u16string capability;
154         std::u16string permission;
155     };
156 
157     /**
158      * AddSystemAbility, add an ability to samgr.
159      *
160      * @param systemAbilityId, Need to add the said of sa.
161      * @param ability, SA to be added.
162      * @param extraProp, Additional parameters for sa, such as whether it is distributed.
163      * @return ERR_OK indicates successful add.
164      */
165     virtual int32_t AddSystemAbility(int32_t systemAbilityId, const sptr<IRemoteObject>& ability,
166         const SAExtraProp& extraProp = SAExtraProp(false, DUMP_FLAG_PRIORITY_DEFAULT, u"", u"")) = 0;
167 
168     /**
169      * AddSystemProcess, add an process.
170      *
171      * @param procName, Need to add the procName of process.
172      * @param procObject, Remoteobject of procName.
173      * @return ERR_OK indicates successful add.
174      */
175     virtual int32_t AddSystemProcess(const std::u16string& procName, const sptr<IRemoteObject>& procObject) = 0;
176 
177     /**
178      * LoadSystemAbility, Load sa.
179      *
180      * @param systemAbilityId, Need to load the said of sa.
181      * @param callback, OnLoadSystemAbilityFail and OnLoadSystemAbilitySuccess need be rewritten.
182      * @return ERR_OK It does not mean that the load was successful.
183      */
184     virtual int32_t LoadSystemAbility(int32_t systemAbilityId, const sptr<ISystemAbilityLoadCallback>& callback) = 0;
185 
186     /**
187      * LoadSystemAbility, Load sa.
188      *
189      * @param systemAbilityId, Need to load the said of sa.
190      * @param deviceId, if deviceId is empty, it indicates local load.
191      * @param callback, OnLoadSystemAbilityFail and OnLoadSystemAbilitySuccess need be rewritten.
192      * @return ERR_OK It does not mean that the load was successful.
193      */
194     virtual int32_t LoadSystemAbility(int32_t systemAbilityId, const std::string& deviceId,
195         const sptr<ISystemAbilityLoadCallback>& callback) = 0;
196 
197     /**
198      * UnloadSystemAbility, UnLoad sa.
199      *
200      * @param systemAbilityId, Need to UnLoad the said of sa.
201      * @return ERR_OK It does not mean that the unload was successful, but sa entered an idle state.
202      */
203     virtual int32_t UnloadSystemAbility(int32_t systemAbilityId) = 0;
204 
205     /**
206      * CancelUnloadSystemAbility, CancelUnload sa.
207      *
208      * @param systemAbilityId, Need to CancelUnload the said of sa.
209      * @return ERR_OK indicates that the uninstall was canceled successfully.
210      */
211     virtual int32_t CancelUnloadSystemAbility(int32_t systemAbilityId) = 0;
212 
213     /**
214      * GetRunningSystemProcess, Get all processes currently running.
215      *
216      * @param systemProcessInfos, Issue a parameter and return it as a result.
217      * @return ERR_OK indicates that the get successfully.
218      */
219     virtual int32_t GetRunningSystemProcess(std::list<SystemProcessInfo>& systemProcessInfos) = 0;
220 
221     /**
222      * SubscribeSystemProcess, Subscribe the status of process.
223      *
224      * @param listener, callback
225      * @return ERR_OK indicates that the Subscribe successfully.
226      */
227     virtual int32_t SubscribeSystemProcess(const sptr<ISystemProcessStatusChange>& listener) = 0;
228 
229     /**
230      * UnSubscribeSystemProcess, UnSubscribe the status of process.
231      *
232      * @param listener, callback
233      * @return ERR_OK indicates that the UnSubscribe successfully.
234      */
235     virtual int32_t UnSubscribeSystemProcess(const sptr<ISystemProcessStatusChange>& listener) = 0;
236     virtual int32_t GetOnDemandReasonExtraData(int64_t extraDataId, MessageParcel& extraDataParcel) = 0;
237     virtual int32_t GetOnDemandPolicy(int32_t systemAbilityId, OnDemandPolicyType type,
238         std::vector<SystemAbilityOnDemandEvent>& abilityOnDemandEvents) = 0;
239     virtual int32_t UpdateOnDemandPolicy(int32_t systemAbilityId, OnDemandPolicyType type,
240         const std::vector<SystemAbilityOnDemandEvent>& abilityOnDemandEvents) = 0;
241 public:
242     DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.ISystemAbilityManager");
243 protected:
244     static constexpr int32_t FIRST_SYS_ABILITY_ID = 0x00000001;
245     static constexpr int32_t LAST_SYS_ABILITY_ID = 0x00ffffff;
CheckInputSysAbilityId(int32_t sysAbilityId)246     bool CheckInputSysAbilityId(int32_t sysAbilityId) const
247     {
248         if (sysAbilityId >= FIRST_SYS_ABILITY_ID && sysAbilityId <= LAST_SYS_ABILITY_ID) {
249             return true;
250         }
251         return false;
252     }
253     static inline const std::u16string SAMANAGER_INTERFACE_TOKEN = u"ohos.samgr.accessToken";
254 };
255 } // namespace OHOS
256 
257 #endif // !defined(INTERFACES_INNERKITS_SAMGR_INCLUDE_IF_SYSTEM_ABILITY_MANAGER_H )
258