• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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_AAFWK_ABILITY_MANAGER_PROXY_H
17 #define OHOS_AAFWK_ABILITY_MANAGER_PROXY_H
18 
19 #include "ability_manager_interface.h"
20 #include "hilog_wrapper.h"
21 #include "iremote_proxy.h"
22 
23 namespace OHOS {
24 namespace AAFwk {
25 /**
26  * @class AbilityManagerProxy
27  * AbilityManagerProxy.
28  */
29 class AbilityManagerProxy : public IRemoteProxy<IAbilityManager> {
30 public:
AbilityManagerProxy(const sptr<IRemoteObject> & impl)31     explicit AbilityManagerProxy(const sptr<IRemoteObject> &impl) : IRemoteProxy<IAbilityManager>(impl)
32     {}
33 
~AbilityManagerProxy()34     virtual ~AbilityManagerProxy()
35     {}
36 
37     /**
38      * StartAbility with want, send want to ability manager service.
39      *
40      * @param want, the want of the ability to start.
41      * @param requestCode, Ability request code.
42      * @return Returns ERR_OK on success, others on failure.
43      */
44     virtual int StartAbility(const Want &want, int requestCode = DEFAULT_INVAL_VALUE) override;
45 
46     /**
47      * StartAbility with want, send want to ability manager service.
48      *
49      * @param want, the want of the ability to start.
50      * @param callerToken, caller ability token.
51      * @param requestCode the resultCode of the ability to start.
52      * @return Returns ERR_OK on success, others on failure.
53      */
54     virtual int StartAbility(
55         const Want &want, const sptr<IRemoteObject> &callerToken, int requestCode = DEFAULT_INVAL_VALUE) override;
56 
57     /**
58      * Starts a new ability with specific start settings.
59      *
60      * @param want Indicates the ability to start.
61      * @param requestCode the resultCode of the ability to start.
62      * @param abilityStartSetting Indicates the setting ability used to start.
63      * @return Returns ERR_OK on success, others on failure.
64      */
65     virtual int StartAbility(const Want &want, const AbilityStartSetting &abilityStartSetting,
66         const sptr<IRemoteObject> &callerToken, int requestCode = DEFAULT_INVAL_VALUE) override;
67 
68     /**
69      * TerminateAbility, terminate the special ability.
70      *
71      * @param token, the token of the ability to terminate.
72      * @param resultCode, the resultCode of the ability to terminate.
73      * @param resultWant, the Want of the ability to return.
74      * @return Returns ERR_OK on success, others on failure.
75      */
76     virtual int TerminateAbility(
77         const sptr<IRemoteObject> &token, int resultCode, const Want *resultWant = nullptr) override;
78 
79     /**
80      * TerminateAbility, terminate the special ability.
81      *
82      * @param callerToken, caller ability token.
83      * @param requestCode, Ability request code.
84      * @return Returns ERR_OK on success, others on failure.
85      */
86     virtual int TerminateAbilityByCaller(const sptr<IRemoteObject> &callerToken, int requestCode) override;
87 
88     /**
89      * ConnectAbility, connect session with service ability.
90      *
91      * @param want, Special want for service type's ability.
92      * @param connect, Callback used to notify caller the result of connecting or disconnecting.
93      * @param callerToken, caller ability token.
94      * @return Returns ERR_OK on success, others on failure.
95      */
96     virtual int ConnectAbility(
97         const Want &want, const sptr<IAbilityConnection> &connect, const sptr<IRemoteObject> &callerToken) override;
98 
99     /**
100      * DisconnectAbility, connect session with service ability.
101      *
102      * @param connect, Callback used to notify caller the result of connecting or disconnecting.
103      * @return Returns ERR_OK on success, others on failure.
104      */
105     virtual int DisconnectAbility(const sptr<IAbilityConnection> &connect) override;
106 
107     /**
108      * AcquireDataAbility, acquire a data ability by its authority, if it not existed,
109      * AMS loads it synchronously.
110      *
111      * @param uri, data ability uri.
112      * @param isKill, true: when a data ability is died, ams will kill this client, or do nothing.
113      * @param callerToken, specifies the caller ability token.
114      * @return returns the data ability ipc object, or nullptr for failed.
115      */
116     virtual sptr<IAbilityScheduler> AcquireDataAbility(
117         const Uri &uri, bool isKill, const sptr<IRemoteObject> &callerToken) override;
118 
119     /**
120      * ReleaseDataAbility, release the data ability that referenced by 'dataAbilityToken'.
121      *
122      * @param dataAbilityScheduler, specifies the data ability that will be released.
123      * @param callerToken, specifies the caller ability token.
124      * @return returns ERR_OK if succeeded, or error codes for failed.
125      */
126     virtual int ReleaseDataAbility(
127         sptr<IAbilityScheduler> dataAbilityScheduler, const sptr<IRemoteObject> &callerToken) override;
128 
129     /**
130      * AddWindowInfo, add windowToken to AbilityRecord.
131      *
132      * @param token, the token of the ability.
133      * @param windowToken, window id of the ability.
134      */
135     virtual void AddWindowInfo(const sptr<IRemoteObject> &token, int32_t windowToken) override;
136 
137     /**
138      * AttachAbilityThread, ability call this interface after loaded.
139      *
140      * @param scheduler,.the interface handler of kit ability.
141      * @param token,.ability's token.
142      * @return Returns ERR_OK on success, others on failure.
143      */
144     virtual int AttachAbilityThread(
145         const sptr<IAbilityScheduler> &scheduler, const sptr<IRemoteObject> &token) override;
146 
147     /**
148      * AbilityTransitionDone, ability call this interface after lift cycle was changed.
149      *
150      * @param token,.ability's token.
151      * @param state,.the state of ability lift cycle.
152      * @return Returns ERR_OK on success, others on failure.
153      */
154     virtual int AbilityTransitionDone(const sptr<IRemoteObject> &token, int state) override;
155 
156     /**
157      * ScheduleConnectAbilityDone, service ability call this interface while session was connected.
158      *
159      * @param token,.service ability's token.
160      * @param remoteObject,.the session proxy of service ability.
161      * @return Returns ERR_OK on success, others on failure.
162      */
163     virtual int ScheduleConnectAbilityDone(
164         const sptr<IRemoteObject> &token, const sptr<IRemoteObject> &remoteObject) override;
165 
166     /**
167      * ScheduleDisconnectAbilityDone, service ability call this interface while session was disconnected.
168      *
169      * @param token,.service ability's token.
170      * @return Returns ERR_OK on success, others on failure.
171      */
172     virtual int ScheduleDisconnectAbilityDone(const sptr<IRemoteObject> &token) override;
173 
174     /**
175      * ScheduleCommandAbilityDone, service ability call this interface while session was commanded.
176      *
177      * @param token,.service ability's token.
178      * @return Returns ERR_OK on success, others on failure.
179      */
180     virtual int ScheduleCommandAbilityDone(const sptr<IRemoteObject> &token) override;
181 
182     /**
183      * dump ability stack info, about userID, mission stack info,
184      * mission record info and ability info.
185      *
186      * @param state Ability stack info.
187      * @return Returns ERR_OK on success, others on failure.
188      */
189     virtual void DumpState(const std::string &args, std::vector<std::string> &state) override;
190 
191     /**
192      * Destroys this Service ability if the number of times it
193      * has been started equals the number represented by
194      * the given startId.
195      *
196      * @param token ability's token.
197      * @param startId is incremented by 1 every time this ability is started.
198      * @return Returns true if the startId matches the number of startup times
199      * and this Service ability will be destroyed; returns false otherwise.
200      */
201     virtual int TerminateAbilityResult(const sptr<IRemoteObject> &token, int startId) override;
202 
203     /**
204      * Destroys this Service ability by Want.
205      *
206      * @param want, Special want for service type's ability.
207      * @return Returns true if this Service ability will be destroyed; returns false otherwise.
208      */
209     virtual int StopServiceAbility(const Want &want) override;
210 
211     /**
212      * Obtains information about ability stack that are running on the device.
213      *
214      * @param stackInfo Ability stack info.
215      * @return Returns ERR_OK on success, others on failure.
216      */
217     virtual int GetAllStackInfo(StackInfo &stackInfo) override;
218 
219     /**
220      * Get the list of the missions that the user has recently launched,
221      * with the most recent being first and older ones after in order.
222      *
223      * @param recentList recent mission info
224      * @param numMax The maximum number of entries to return in the list. The
225      * actual number returned may be smaller, depending on how many tasks the
226      * user has started and the maximum number the system can remember.
227      * @param falgs Information about what to return.  May be any combination
228      * of {@link #RECENT_WITH_EXCLUDED} and {@link #RECENT_IGNORE_UNAVAILABLE}.
229      * @return Returns ERR_OK on success, others on failure.
230      */
231     virtual int GetRecentMissions(
232         const int32_t numMax, const int32_t flags, std::vector<AbilityMissionInfo> &recentList) override;
233 
234     /**
235      * Get mission snapshot by mission id
236      *
237      * @param missionId the id of the mission to retrieve the sAutoapshots
238      * @return Returns ERR_OK on success, others on failure.
239      */
240     virtual int GetMissionSnapshot(const int32_t missionId, MissionSnapshotInfo &snapshot) override;
241 
242     /**
243      * Ask that the mission associated with a given mission ID be moved to the
244      * front of the stack, so it is now visible to the user.
245      *
246      * @param missionId.
247      * @return Returns ERR_OK on success, others on failure.
248      */
249     virtual int MoveMissionToTop(int32_t missionId) override;
250 
251     /**
252      * Requires that tasks associated with a given capability token be moved to the background
253      *
254      * @param token ability token
255      * @param nonFirst If nonfirst is false and not the lowest ability of the mission, you cannot move mission to end
256      * @return Returns ERR_OK on success, others on failure.
257      */
258     virtual int MoveMissionToEnd(const sptr<IRemoteObject> &token, bool nonFirst) override;
259 
260     /**
261      * Remove the specified mission from the stack by missionid
262      *
263      * @param id.
264      * @return Returns ERR_OK on success, others on failure.
265      */
266     virtual int RemoveMission(int id) override;
267 
268     /**
269      * Remove the specified mission stack by stack id
270      *
271      * @param id.
272      * @return Returns ERR_OK on success, others on failure.
273      */
274     virtual int RemoveStack(int id) override;
275 
276     /**
277      * Kill the process immediately.
278      *
279      * @param bundleName.
280      * @return Returns ERR_OK on success, others on failure.
281      */
282     virtual int KillProcess(const std::string &bundleName) override;
283 
284     /**
285      * Uninstall app
286      *
287      * @param bundleName.
288      * @return Returns ERR_OK on success, others on failure.
289      */
290     virtual int UninstallApp(const std::string &bundleName) override;
291 
292     /**
293      * Moving mission to the specified stack by mission option(Enter floating window mode).
294      * @param missionOption, target mission option
295      * @return Returns ERR_OK on success, others on failure.
296      */
297     virtual int MoveMissionToFloatingStack(const MissionOption &missionOption) override;
298 
299     /**
300      * Moving mission to the specified stack by mission option(Enter floating window mode).
301      * @param missionOption, target mission option
302      * @return Returns ERR_OK on success, others on failure.
303      */
304     virtual int MoveMissionToSplitScreenStack(const MissionOption &missionOption) override;
305 
306     /**
307      * Change the focus of ability in the mission stack.
308      * @param lostToken, the token of lost focus ability
309      * @param getToken, the token of get focus ability
310      * @return Returns ERR_OK on success, others on failure.
311      */
312     virtual int ChangeFocusAbility(
313         const sptr<IRemoteObject> &lostFocusToken, const sptr<IRemoteObject> &getFocusToken) override;
314 
315     /**
316      * minimize multiwindow by mission id.
317      * @param missionId, the id of target mission
318      * @return Returns ERR_OK on success, others on failure.
319      */
320     virtual int MinimizeMultiWindow(int missionId) override;
321 
322     /**
323      * maximize multiwindow by mission id.
324      * @param missionId, the id of target mission
325      * @return Returns ERR_OK on success, others on failure.
326      */
327     virtual int MaximizeMultiWindow(int missionId) override;
328 
329     /**
330      * get missions info of floating mission stack.
331      * @param list, mission info.
332      * @return Returns ERR_OK on success, others on failure.
333      */
334     virtual int GetFloatingMissions(std::vector<AbilityMissionInfo> &list) override;
335 
336     /**
337      * close multiwindow by mission id.
338      * @param missionId, the id of target mission.
339      * @return Returns ERR_OK on success, others on failure.
340      */
341     virtual int CloseMultiWindow(int missionId) override;
342 
343     /**
344      * set special mission stack default settings.
345      * @param stackSetting, mission stack default settings.
346      * @return Returns ERR_OK on success, others on failure.
347      */
348     virtual int SetMissionStackSetting(const StackSetting &stackSetting) override;
349 
350     /**
351      * @brief Checks whether this ability is the first ability in a mission.
352      *
353      * @return Returns true is first in Mission.
354      */
355     virtual bool IsFirstInMission(const sptr<IRemoteObject> &token) override;
356 
357     /**
358      * Checks whether a specified permission has been granted to the process identified by pid and uid
359      *
360      * @param permission Indicates the permission to check.
361      * @param pid Indicates the ID of the process to check.
362      * @param uid Indicates the UID of the process to check.
363      * @param message Describe success or failure
364      *
365      * @return Returns ERR_OK on success, others on failure.
366      */
367     virtual int CompelVerifyPermission(const std::string &permission, int pid, int uid, std::string &message) override;
368 
369     /**
370      * Save the top ability States and move them to the background
371      * @return Returns ERR_OK on success, others on failure.
372      */
373     virtual int PowerOff() override;
374 
375     /**
376      * Restore the state before top ability poweroff
377      * @return Returns ERR_OK on success, others on failure.
378      */
379     virtual int PowerOn() override;
380 
381     /**
382      * Sets the application to start its ability in lock mission mode.
383      * @param missionId luck mission id
384      * @return Returns ERR_OK on success, others on failure.
385      */
386     virtual int LockMission(int missionId) override;
387 
388     /**
389      * Unlocks this ability by exiting the lock mission mode.
390      * @param missionId unluck mission id
391      * @return Returns ERR_OK on success, others on failure.
392      */
393     virtual int UnlockMission(int missionId) override;
394 
395     /**
396      * Sets description information about the mission containing this ability.
397      *
398      * @param description Indicates the object containing information about the
399      *                    mission. This parameter cannot be null.
400      * @return Returns ERR_OK on success, others on failure.
401      */
402     virtual int SetMissionDescriptionInfo(
403         const sptr<IRemoteObject> &token, const MissionDescriptionInfo &description) override;
404 
405     /**
406      * get current system mission lock mode state.
407      *
408      * @return Returns 0: LOCK_MISSION_STATE_NONE, 1: LOCK_MISSION_STATE_LOCKED
409      */
410     virtual int GetMissionLockModeState() override;
411 
412     /**
413      * Updates the configuration by modifying the configuration.
414      *
415      * @param config Indicates the new configuration
416      * @return Returns ERR_OK on success, others on failure.
417      */
418     virtual int UpdateConfiguration(const DummyConfiguration &config) override;
419 
420     virtual sptr<IWantSender> GetWantSender(
421         const WantSenderInfo &wantSenderInfo, const sptr<IRemoteObject> &callerToken) override;
422 
423     virtual int SendWantSender(const sptr<IWantSender> &target, const SenderInfo &senderInfo) override;
424 
425     virtual void CancelWantSender(const sptr<IWantSender> &sender) override;
426 
427     virtual int GetPendingWantUid(const sptr<IWantSender> &target) override;
428 
429     virtual int GetPendingWantUserId(const sptr<IWantSender> &target) override;
430 
431     virtual std::string GetPendingWantBundleName(const sptr<IWantSender> &target) override;
432 
433     virtual int GetPendingWantCode(const sptr<IWantSender> &target) override;
434 
435     virtual int GetPendingWantType(const sptr<IWantSender> &target) override;
436 
437     virtual void RegisterCancelListener(const sptr<IWantSender> &sender, const sptr<IWantReceiver> &receiver) override;
438 
439     virtual void UnregisterCancelListener(
440         const sptr<IWantSender> &sender, const sptr<IWantReceiver> &receiver) override;
441 
442     virtual int GetPendingRequestWant(const sptr<IWantSender> &target, std::shared_ptr<Want> &want) override;
443 
444 private:
445     template<typename T>
446     int GetParcelableInfos(MessageParcel &reply, std::vector<T> &parcelableInfos);
447     bool WriteInterfaceToken(MessageParcel &data);
448 
449 private:
450     static inline BrokerDelegator<AbilityManagerProxy> delegator_;
451 };
452 }  // namespace AAFwk
453 }  // namespace OHOS
454 #endif
455