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 FOUNDATION_APPEXECFWK_INTERFACES_INNERKITS_APPEXECFWK_CORE_INCLUDE_APPMGR_APP_MGR_CLIENT_H 17 #define FOUNDATION_APPEXECFWK_INTERFACES_INNERKITS_APPEXECFWK_CORE_INCLUDE_APPMGR_APP_MGR_CLIENT_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 * Get system memory information. 121 * @param SystemMemoryAttr, memory information. 122 */ 123 virtual void GetSystemMemoryAttr(SystemMemoryAttr &memoryInfo, std::string &strConfig) override; 124 125 /** 126 * Notify that the ability stage has been updated 127 * @param recordId, the app record. 128 */ 129 virtual void AddAbilityStageDone(const int32_t recordId) override; 130 131 /** 132 * Start a resident process 133 */ 134 virtual void StartupResidentProcess(const std::vector<AppExecFwk::BundleInfo> &bundleInfos) override; 135 136 /** 137 * Register application or process state observer. 138 * @param observer, ability token. 139 * @return Returns ERR_OK on success, others on failure. 140 */ 141 virtual int32_t RegisterApplicationStateObserver(const sptr<IApplicationStateObserver> &observer) override; 142 143 /** 144 * Unregister application or process state observer. 145 * @param observer, ability token. 146 * @return Returns ERR_OK on success, others on failure. 147 */ 148 virtual int32_t UnregisterApplicationStateObserver(const sptr<IApplicationStateObserver> &observer) override; 149 150 /** 151 * Get foreground applications. 152 * @param list, foreground apps. 153 * @return Returns ERR_OK on success, others on failure. 154 */ 155 virtual int32_t GetForegroundApplications(std::vector<AppStateData> &list) override; 156 157 /** 158 * Start user test process. 159 * @param want, want object. 160 * @param observer, test observer remote object. 161 * @param bundleInfo, bundle info. 162 * @param userId the user id. 163 * @return Returns ERR_OK on success, others on failure. 164 */ 165 virtual int StartUserTestProcess(const AAFwk::Want &want, const sptr<IRemoteObject> &observer, 166 const BundleInfo &bundleInfo, int32_t userId) override; 167 168 /** 169 * @brief Finish user test. 170 * @param msg user test message. 171 * @param resultCode user test result Code. 172 * @param bundleName user test bundleName. 173 * 174 * @return Returns ERR_OK on success, others on failure. 175 */ 176 virtual int FinishUserTest(const std::string &msg, const int &resultCode, const std::string &bundleName) override; 177 178 virtual void ScheduleAcceptWantDone( 179 const int32_t recordId, const AAFwk::Want &want, const std::string &flag) override; 180 181 /** 182 * Get the token of ability records by process ID. 183 * 184 * @param pid The process id. 185 * @param tokens The token of ability records. 186 * @return Returns true on success, others on failure. 187 */ 188 virtual int GetAbilityRecordsByProcessID(const int pid, std::vector<sptr<IRemoteObject>> &tokens) override; 189 190 /** 191 * Start nweb render process, called by nweb host. 192 * 193 * @param renderParam, params passed to renderprocess. 194 * @param ipcFd, ipc file descriptior for web browser and render process. 195 * @param sharedFd, shared memory file descriptior. 196 * @param renderPid, created render pid. 197 * @return Returns ERR_OK on success, others on failure. 198 */ 199 virtual int StartRenderProcess(const std::string &renderParam, int32_t ipcFd, 200 int32_t sharedFd, pid_t &renderPid) override; 201 202 /** 203 * Render process call this to attach app manager service. 204 * 205 * @param renderApp, information needed to start the Application. 206 */ 207 virtual void AttachRenderProcess(const sptr<IRemoteObject> &renderApp) override; 208 209 /** 210 * Get render process termination status, called by nweb host. 211 * 212 * @param renderPid, target render pid. 213 * @param status, termination status of the render process. 214 * @return Returns ERR_OK on success, others on failure. 215 */ 216 virtual int GetRenderProcessTerminationStatus(pid_t renderPid, int &status) override; 217 218 /** 219 * Post a task to the not response process. 220 * 221 * @param pid, the not response process id. 222 */ 223 virtual void PostANRTaskByProcessID(const pid_t pid) override; 224 225 private: 226 bool SendTransactCmd(IAppMgr::Message code, MessageParcel &data, MessageParcel &reply); 227 bool WriteInterfaceToken(MessageParcel &data); 228 template<typename T> 229 int GetParcelableInfos(MessageParcel &reply, std::vector<T> &parcelableInfos); 230 static inline BrokerDelegator<AppMgrProxy> delegator_; 231 }; 232 } // namespace AppExecFwk 233 } // namespace OHOS 234 #endif // FOUNDATION_APPEXECFWK_INTERFACES_INNERKITS_APPEXECFWK_CORE_INCLUDE_APPMGR_APP_MGR_CLIENT_H 235