• 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 ABILITY_MANAGER_H
17 #define ABILITY_MANAGER_H
18 
19 #include "ability_manager_client.h"
20 #include "app_mgr_interface.h"
21 #include "stack_info.h"
22 
23 namespace OHOS {
24 namespace AppExecFwk {
25 
26 using OHOS::AAFwk::AbilityManagerClient;
27 using OHOS::AAFwk::AbilityMissionInfo;
28 using OHOS::AAFwk::RECENT_IGNORE_UNAVAILABLE;
29 using OHOS::AAFwk::StackInfo;
30 using OHOS::AAFwk::Want;
31 using OHOS::AppExecFwk::RunningProcessInfo;
32 using RuningMissionInfo = AbilityMissionInfo;
33 
34 class AbilityManager {
35 public:
36     AbilityManager() = default;
37     virtual ~AbilityManager() = default;
38 
39     static AbilityManager &GetInstance();
40 
41     /**
42      * StartAbility with want, send want to ability manager service.
43      *
44      * @param want Ability want.
45      * @param requestCode Ability request code.
46      * @return Returns ERR_OK on success, others on failure.
47      */
48     void StartAbility(const Want &want, int requestCode);
49 
50     /**
51      * Ask that the mission associated with a given mission ID be moved to the
52      * front of the stack, so it is now visible to the user.
53      *
54      * @param missionId mission record id
55      */
56     void MoveMissionToTop(int missionId);
57 
58     /**
59      * Get all stack info from ability manager service.
60      *
61      * @return Return stack information
62      */
63     StackInfo GetAllStackInfo() const;
64 
65     /**
66      * Query recent Ability Mission info.
67      * @param numMax The maximum number of entries to return in the list. The
68      * actual number returned may be smaller, depending on how many tasks the
69      * user has started and the maximum number the system can remember.
70      * @param falgs Information about what to return.  May be any combination
71      * of {@link #RECENT_WITH_EXCLUDED} and {@link #RECENT_IGNORE_UNAVAILABLE}.
72      *
73      * @returns Returns the AbilityMissionInfo.
74      */
75     std::vector<AbilityMissionInfo> QueryRecentAbilityMissionInfo(int numMax, int flags) const;
76 
77     /**
78      * Query running Ability Mission info.
79      * @param numMax The maximum number of entries to return in the list. The
80      * actual number returned may be smaller, depending on how many tasks the
81      * user has started and the maximum number the system can remember.
82      *
83      * @returns Returns the AbilityMissionInfo.
84      */
85     std::vector<RuningMissionInfo> QueryRunningAbilityMissionInfo(int numMax) const;
86 
87     /**
88      * Remove the specified mission from the stack by mission id
89      */
90     void RemoveMissions(const std::vector<int> &missionId);
91 
92     /**
93      * Clears user data of the application, which is equivalent to initializing the application.
94      *
95      * @param bundleName.
96      */
97     int32_t ClearUpApplicationData(const std::string &bundleName);
98 
99     /**
100      * Obtains information about application processes that are running on the device.
101      *
102      * @returns Returns a list of running processes.
103      */
104     std::vector<RunningProcessInfo> GetAllRunningProcesses();
105 
106     /**
107      * Kill the process immediately.
108      *
109      * @param bundleName.
110      * @return Returns ERR_OK on success, others on failure.
111      */
112     int KillProcessesByBundleName(const std::string &bundleName);
113 };
114 
115 }  // namespace AppExecFwk
116 }  // namespace OHOS
117 #endif  // ABILITY_MANAGER_H
118