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