• 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 
17 #ifndef INTERFACES_INNERKITS_SAMGR_INCLUDE_SYSTEM_ABILITY_MANAGER_PROXY_H
18 #define INTERFACES_INNERKITS_SAMGR_INCLUDE_SYSTEM_ABILITY_MANAGER_PROXY_H
19 
20 #include <string>
21 #include "if_system_ability_manager.h"
22 #include "system_ability_on_demand_event.h"
23 
24 namespace OHOS {
25 class SystemAbilityManagerProxy : public IRemoteProxy<ISystemAbilityManager> {
26 public:
SystemAbilityManagerProxy(const sptr<IRemoteObject> & impl)27     explicit SystemAbilityManagerProxy(const sptr<IRemoteObject>& impl)
28         : IRemoteProxy<ISystemAbilityManager>(impl) {}
29     ~SystemAbilityManagerProxy() = default;
30     /**
31      * ListSystemAbilities, Return list of all existing abilities.
32      *
33      * @param dumpFlags, dump all
34      * @return Returns the sa where the current samgr exists.
35      */
36     std::vector<std::u16string> ListSystemAbilities(unsigned int dumpFlags) override;
37 
38     /**
39      * GetSystemAbility, Retrieve an existing ability, retrying and blocking for a few seconds if it doesn't exist.
40      *
41      * @param systemAbilityId, Need to obtain the said of sa.
42      * @return nullptr indicates acquisition failure.
43      */
44     sptr<IRemoteObject> GetSystemAbility(int32_t systemAbilityId) override;
45 
46     /**
47      * CheckSystemAbility, Retrieve an existing ability, no-blocking.
48      *
49      * @param systemAbilityId, Need to obtain the said of sa.
50      * @return nullptr indicates acquisition failure.
51      */
52     sptr<IRemoteObject> CheckSystemAbility(int32_t systemAbilityId) override;
53 
54     /**
55      * RemoveSystemAbility, Remove an ability.
56      *
57      * @param systemAbilityId, Need to remove the said of sa.
58      * @return ERR_OK indicates remove success.
59      */
60     int32_t RemoveSystemAbility(int32_t systemAbilityId) override;
61 
62     /**
63      * SubscribeSystemAbility, Subscribe a system ability status, and inherit from ISystemAbilityStatusChange class.
64      *
65      * @param systemAbilityId, Need to subscribe the said of sa.
66      * @param listener, Need to implement OnAddSystemAbility, OnRemoveSystemAbility.
67      * @return ERR_OK indicates SubscribeSystemAbility success.
68      */
69     int32_t SubscribeSystemAbility(int32_t systemAbilityId, const sptr<ISystemAbilityStatusChange>& listener) override;
70 
71     /**
72      * UnSubscribeSystemAbility, UnSubscribe a system ability status, and inherit from ISystemAbilityStatusChange class.
73      *
74      * @param systemAbilityId, Need to UnSubscribe the said of sa.
75      * @param listener, Need to implement OnAddSystemAbility, OnRemoveSystemAbility.
76      * @return ERR_OK indicates SubscribeSystemAbility success.
77      */
78     int32_t UnSubscribeSystemAbility(int32_t systemAbilityId,
79         const sptr<ISystemAbilityStatusChange> &listener) override;
80 
81     /**
82      * GetSystemAbility, Retrieve an existing ability, blocking for a few seconds if it doesn't exist.
83      *
84      * @param systemAbilityId, Need to get the said of sa.
85      * @param deviceId, If the device id is empty, it indicates that it is a local get.
86      * @return nullptr indicates acquisition failure.
87      */
88     sptr<IRemoteObject> GetSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override;
89 
90     /**
91      * CheckSystemAbility, Retrieve an existing ability, no-blocking.
92      *
93      * @param systemAbilityId, Need to get the said of sa.
94      * @param deviceId, If the device id is empty, it indicates that it is a local get.
95      * @return nullptr indicates acquisition failure.
96      */
97     sptr<IRemoteObject> CheckSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override;
98 
99     /**
100      * AddOnDemandSystemAbilityInfo, Add ondemand ability info.
101      *
102      * @param systemAbilityId, Need to add info the said of sa.
103      * @param localAbilityManagerName, Process Name.
104      * @return ERR_OK indicates AddOnDemandSystemAbilityInfo success.
105      */
106     int32_t AddOnDemandSystemAbilityInfo(int32_t systemAbilityId,
107         const std::u16string& localAbilityManagerName) override;
108 
109     /**
110      * CheckSystemAbility, Retrieve an ability, no-blocking.
111      *
112      * @param systemAbilityId, Need to check the said of sa.
113      * @param isExist, Issue parameters, and a result of true indicates success.
114      * @return nullptr indicates acquisition failure.
115      */
116     sptr<IRemoteObject> CheckSystemAbility(int32_t systemAbilityId, bool& isExist) override;
117 
118     /**
119      * AddSystemAbility, add an ability to samgr
120      *
121      * @param systemAbilityId, Need to add the said of sa.
122      * @param ability, SA to be added.
123      * @param extraProp, Additional parameters for sa, such as whether it is distributed.
124      * @return ERR_OK indicates successful add.
125      */
126     int32_t AddSystemAbility(int32_t systemAbilityId, const sptr<IRemoteObject>& ability,
127         const SAExtraProp& extraProp) override;
128 
129     /**
130      * AddSystemProcess, add an process.
131      *
132      * @param procName, Need to add the procName of process.
133      * @param procObject, Remoteobject of procName.
134      * @return ERR_OK indicates successful add.
135      */
136     int32_t AddSystemProcess(const std::u16string& procName, const sptr<IRemoteObject>& procObject) override;
137 
138     /**
139      * LoadSystemAbility, Load sa.
140      *
141      * @param systemAbilityId, Need to load the said of sa.
142      * @param callback, OnLoadSystemAbilityFail and OnLoadSystemAbilitySuccess need be rewritten.
143      * @return ERR_OK It does not mean that the load was successful, but a callback function is.
144      required to confirm whether it was successful.
145      */
146     int32_t LoadSystemAbility(int32_t systemAbilityId, const sptr<ISystemAbilityLoadCallback>& callback) override;
147 
148     /**
149      * LoadSystemAbility, Load sa.
150      *
151      * @param systemAbilityId, Need to load the said of sa.
152      * @param deviceId, if deviceId is empty, it indicates local load.
153      * @param callback, OnLoadSystemAbilityFail and OnLoadSystemAbilitySuccess need be rewritten.
154      * @return ERR_OK It does not mean that the load was successful
155      */
156     int32_t LoadSystemAbility(int32_t systemAbilityId, const std::string& deviceId,
157         const sptr<ISystemAbilityLoadCallback>& callback) override;
158 
159     /**
160      * UnloadSystemAbility, UnLoad sa.
161      *
162      * @param systemAbilityId, Need to UnLoad the said of sa.
163      * @return ERR_OK It does not mean that the unload was successful.
164      */
165     int32_t UnloadSystemAbility(int32_t systemAbilityId) override;
166 
167     /**
168      * CancelUnloadSystemAbility, CancelUnload sa.
169      *
170      * @param systemAbilityId, Need to CancelUnload the said of sa.
171      * @return ERR_OK indicates that the uninstall was canceled successfully.
172      */
173     int32_t CancelUnloadSystemAbility(int32_t systemAbilityId) override;
174 
175     /**
176      * GetRunningSystemProcess, Get all processes currently running.
177      *
178      * @param systemProcessInfos, Issue a parameter and return it as a result.
179      * @return ERR_OK indicates that the get successfully.
180      */
181     int32_t GetRunningSystemProcess(std::list<SystemProcessInfo>& systemProcessInfos) override;
182 
183     /**
184      * SubscribeSystemProcess, Subscribe the status of process.
185      *
186      * @param listener, callback.
187      * @return ERR_OK indicates that the Subscribe successfully.
188      */
189     int32_t SubscribeSystemProcess(const sptr<ISystemProcessStatusChange>& listener) override;
190 
191     /**
192      * UnSubscribeSystemProcess, UnSubscribe the status of process.
193      *
194      * @param listener, callback.
195      * @return ERR_OK indicates that the UnSubscribe successfully.
196      */
197     int32_t UnSubscribeSystemProcess(const sptr<ISystemProcessStatusChange>& listener) override;
198     int32_t GetOnDemandReasonExtraData(int64_t extraDataId, MessageParcel& extraDataParcel) override;
199     int32_t GetOnDemandPolicy(int32_t systemAbilityId, OnDemandPolicyType type,
200         std::vector<SystemAbilityOnDemandEvent>& abilityOnDemandEvents) override;
201     int32_t UpdateOnDemandPolicy(int32_t systemAbilityId, OnDemandPolicyType type,
202         const std::vector<SystemAbilityOnDemandEvent>& sabilityOnDemandEvents) override;
203 private:
204     sptr<IRemoteObject> GetSystemAbilityWrapper(int32_t systemAbilityId, const std::string& deviceId = "");
205     sptr<IRemoteObject> CheckSystemAbilityWrapper(int32_t code, MessageParcel& data);
206     int32_t MarshalSAExtraProp(const SAExtraProp& extraProp, MessageParcel& data) const;
207     int32_t AddSystemAbilityWrapper(int32_t code, MessageParcel& data);
208     int32_t RemoveSystemAbilityWrapper(int32_t code, MessageParcel& data);
209     int32_t ReadSystemProcessFromParcel(std::list<SystemProcessInfo>& systemProcessInfos, MessageParcel& reply);
210 private:
211     static inline BrokerDelegator<SystemAbilityManagerProxy> delegator_;
212 };
213 } // namespace OHOS
214 
215 #endif // !defined(INTERFACES_INNERKITS_SAMGR_INCLUDE_SYSTEM_ABILITY_MANAGER_PROXY_H)
216