• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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_ABILITY_RUNTIME_APP_MGR_PROXY_H
17 #define OHOS_ABILITY_RUNTIME_APP_MGR_PROXY_H
18 
19 #include "iremote_proxy.h"
20 #include "want.h"
21 
22 #include "app_mgr_interface.h"
23 #include "bundle_info.h"
24 
25 namespace OHOS {
26 namespace AppExecFwk {
27 class AppMgrProxy : public IRemoteProxy<IAppMgr> {
28 public:
29     explicit AppMgrProxy(const sptr<IRemoteObject> &impl);
30     virtual ~AppMgrProxy() = default;
31 
32     /**
33      * AttachApplication, call AttachApplication() through proxy object,
34      * get all the information needed to start the Application (data related to the Application ).
35      *
36      * @param app, information needed to start the Application.
37      * @return
38      */
39     virtual void AttachApplication(const sptr<IRemoteObject> &obj) override;
40 
41     /**
42      * ApplicationForegrounded, call ApplicationForegrounded() through proxy object,
43      * set the application to Foreground State.
44      *
45      * @param recordId, a unique record that identifies this Application from others.
46      * @return
47      */
48     virtual void ApplicationForegrounded(const int32_t recordId) override;
49 
50     /**
51      * ApplicationBackgrounded, call ApplicationBackgrounded() through proxy object,
52      * set the application to Backgrounded State.
53      *
54      * @param recordId, a unique record that identifies this Application from others.
55      * @return
56      */
57     virtual void ApplicationBackgrounded(const int32_t recordId) override;
58 
59     /**
60      * ApplicationTerminated, call ApplicationTerminated() through proxy object,
61      * terminate the application.
62      *
63      * @param recordId, a unique record that identifies this Application from others.
64      * @return
65      */
66     virtual void ApplicationTerminated(const int32_t recordId) override;
67 
68     /**
69      * CheckPermission, call CheckPermission() through proxy object, check the permission.
70      *
71      * @param recordId, a unique record that identifies this Application from others.
72      * @param permission, check the permissions.
73      * @return ERR_OK, return back success, others fail.
74      */
75     virtual int32_t CheckPermission(const int32_t recordId, const std::string &permission) override;
76 
77     /**
78      * AbilityCleaned,call through AbilityCleaned() proxy project, clean Ability record.
79      *
80      * @param token, a unique record that identifies AbilityCleaned from others.
81      * @return
82      */
83     virtual void AbilityCleaned(const sptr<IRemoteObject> &token) override;
84 
85     /**
86      * GetAmsMgr, call GetAmsMgr() through proxy object, get AMS interface instance.
87      *
88      * @return sptr<IAmsMgr>, return to AMS interface instance.
89      */
90     virtual sptr<IAmsMgr> GetAmsMgr() override;
91 
92     /**
93      * ClearUpApplicationData, call ClearUpApplicationData() through proxy project,
94      * clear the application data.
95      *
96      * @param bundleName, bundle name in Application record.
97      * @return
98      */
99     virtual int32_t ClearUpApplicationData(const std::string &bundleName) override;
100 
101     /**
102      * GetAllRunningProcesses, call GetAllRunningProcesses() through proxy project.
103      * Obtains information about application processes that are running on the device.
104      *
105      * @param info, app name in Application record.
106      * @return ERR_OK ,return back success,others fail.
107      */
108     virtual int32_t GetAllRunningProcesses(std::vector<RunningProcessInfo> &info) override;
109 
110     /**
111      * GetProcessRunningInfosByUserId, call GetProcessRunningInfosByUserId() through proxy project.
112      * Obtains information about application processes that are running on the device.
113      *
114      * @param info, app name in Application record.
115      * @return ERR_OK ,return back success,others fail.
116      */
117     virtual int32_t GetProcessRunningInfosByUserId(std::vector<RunningProcessInfo> &info, int32_t userId) override;
118 
119     /**
120      * GetProcessRunningInformation, call GetProcessRunningInformation() through proxy project.
121      * Obtains information about current application process which is running on the device.
122      *
123      * @param info, app name in Application record.
124      * @return ERR_OK ,return back success,others fail.
125      */
126     virtual int32_t GetProcessRunningInformation(RunningProcessInfo &info) override;
127 
128     /**
129      * NotifyMemoryLevel, call NotifyMemoryLevel() through proxy project.
130      * Notify abilities background the current memory level.
131      *
132      * @param level, the current memory level
133      * @return ERR_OK ,return back success,others fail.
134      */
135     virtual int32_t NotifyMemoryLevel(int32_t level) override;
136 
137     /**
138      * Notify that the ability stage has been updated
139      * @param recordId, the app record.
140      */
141     virtual void AddAbilityStageDone(const int32_t recordId) override;
142 
143     /**
144      * Start a resident process
145      */
146     virtual void StartupResidentProcess(const std::vector<AppExecFwk::BundleInfo> &bundleInfos) override;
147 
148     /**
149      * Register application or process state observer.
150      * @param observer, ability token.
151      * @return Returns ERR_OK on success, others on failure.
152      */
153     virtual int32_t RegisterApplicationStateObserver(const sptr<IApplicationStateObserver> &observer,
154         const std::vector<std::string> &bundleNameList = {}) override;
155 
156     /**
157      * Unregister application or process state observer.
158      * @param observer, ability token.
159      * @return Returns ERR_OK on success, others on failure.
160      */
161     virtual int32_t UnregisterApplicationStateObserver(const sptr<IApplicationStateObserver> &observer) override;
162 
163     /**
164      * Get foreground applications.
165      * @param list, foreground apps.
166      * @return Returns ERR_OK on success, others on failure.
167      */
168     virtual int32_t GetForegroundApplications(std::vector<AppStateData> &list) override;
169 
170     /**
171      * Start user test process.
172      * @param want, want object.
173      * @param observer, test observer remote object.
174      * @param bundleInfo, bundle info.
175      * @param userId the user id.
176      * @return Returns ERR_OK on success, others on failure.
177      */
178     virtual int StartUserTestProcess(const AAFwk::Want &want, const sptr<IRemoteObject> &observer,
179         const BundleInfo &bundleInfo, int32_t userId) override;
180 
181     /**
182      * @brief Finish user test.
183      * @param msg user test message.
184      * @param resultCode user test result Code.
185      * @param bundleName user test bundleName.
186      *
187      * @return Returns ERR_OK on success, others on failure.
188      */
189     virtual int FinishUserTest(
190         const std::string &msg, const int64_t &resultCode, const std::string &bundleName) override;
191 
192     virtual void ScheduleAcceptWantDone(
193         const int32_t recordId, const AAFwk::Want &want, const std::string &flag) override;
194 
195     /**
196      *  Get the token of ability records by process ID.
197      *
198      * @param pid The process id.
199      * @param tokens The token of ability records.
200      * @return Returns true on success, others on failure.
201      */
202     virtual int GetAbilityRecordsByProcessID(const int pid, std::vector<sptr<IRemoteObject>> &tokens) override;
203 
204     /**
205      * Prestart nwebspawn process.
206      *
207      * @return Returns ERR_OK on success, others on failure.
208      */
209     virtual int PreStartNWebSpawnProcess() override;
210 
211     /**
212      * Start nweb render process, called by nweb host.
213      *
214      * @param renderParam, params passed to renderprocess.
215      * @param ipcFd, ipc file descriptior for web browser and render process.
216      * @param sharedFd, shared memory file descriptior.
217      * @param renderPid, created render pid.
218      * @return Returns ERR_OK on success, others on failure.
219      */
220     virtual int StartRenderProcess(const std::string &renderParam, int32_t ipcFd,
221         int32_t sharedFd, pid_t &renderPid) override;
222 
223     /**
224      * Render process call this to attach app manager service.
225      *
226      * @param renderApp, information needed to start the Application.
227      */
228     virtual void AttachRenderProcess(const sptr<IRemoteObject> &renderApp) override;
229 
230     /**
231      * Get render process termination status, called by nweb host.
232      *
233      * @param renderPid, target render pid.
234      * @param status, termination status of the render process.
235      * @return Returns ERR_OK on success, others on failure.
236      */
237     virtual int GetRenderProcessTerminationStatus(pid_t renderPid, int &status) override;
238 
239     #ifdef ABILITY_COMMAND_FOR_TEST
240     /**
241      * Block app service.
242      *
243      * @return Returns ERR_OK on success, others on failure.
244      */
245     virtual int BlockAppService() override;
246     #endif
247 
248     virtual int32_t GetConfiguration(Configuration& config) override;
249 
250     virtual int32_t UpdateConfiguration(const Configuration &config) override;
251 
252     virtual int32_t RegisterConfigurationObserver(const sptr<IConfigurationObserver> &observer) override;
253 
254     virtual int32_t UnregisterConfigurationObserver(const sptr<IConfigurationObserver> &observer) override;
255 
256     bool GetAppRunningStateByBundleName(const std::string &bundleName) override;
257 
258     int32_t NotifyLoadRepairPatch(const std::string &bundleName, const sptr<IQuickFixCallback> &callback) override;
259 
260     int32_t NotifyHotReloadPage(const std::string &bundleName, const sptr<IQuickFixCallback> &callback) override;
261 
262     int32_t NotifyUnLoadRepairPatch(const std::string &bundleName, const sptr<IQuickFixCallback> &callback) override;
263 
264 #ifdef BGTASKMGR_CONTINUOUS_TASK_ENABLE
265     int32_t SetContinuousTaskProcess(int32_t pid, bool isContinuousTask) override;
266 #endif
267 
268 private:
269     bool SendTransactCmd(IAppMgr::Message code, MessageParcel &data, MessageParcel &reply);
270     bool WriteInterfaceToken(MessageParcel &data);
271     template<typename T>
272     int GetParcelableInfos(MessageParcel &reply, std::vector<T> &parcelableInfos);
273     static inline BrokerDelegator<AppMgrProxy> delegator_;
274 };
275 }  // namespace AppExecFwk
276 }  // namespace OHOS
277 #endif  // OHOS_ABILITY_RUNTIME_APP_MGR_PROXY_H
278