1 /* 2 * Copyright (c) 2021-2023 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 #include "app_malloc_info.h" 25 26 namespace OHOS { 27 namespace AppExecFwk { 28 class AppMgrProxy : public IRemoteProxy<IAppMgr> { 29 public: 30 explicit AppMgrProxy(const sptr<IRemoteObject> &impl); 31 virtual ~AppMgrProxy() = default; 32 33 /** 34 * AttachApplication, call AttachApplication() through proxy object, 35 * get all the information needed to start the Application (data related to the Application ). 36 * 37 * @param app, information needed to start the Application. 38 * @return 39 */ 40 virtual void AttachApplication(const sptr<IRemoteObject> &obj) override; 41 42 /** 43 * ApplicationForegrounded, call ApplicationForegrounded() through proxy object, 44 * set the application to Foreground State. 45 * 46 * @param recordId, a unique record that identifies this Application from others. 47 * @return 48 */ 49 virtual void ApplicationForegrounded(const int32_t recordId) override; 50 51 /** 52 * ApplicationBackgrounded, call ApplicationBackgrounded() through proxy object, 53 * set the application to Backgrounded State. 54 * 55 * @param recordId, a unique record that identifies this Application from others. 56 * @return 57 */ 58 virtual void ApplicationBackgrounded(const int32_t recordId) override; 59 60 /** 61 * ApplicationTerminated, call ApplicationTerminated() through proxy object, 62 * terminate the application. 63 * 64 * @param recordId, a unique record that identifies this Application from others. 65 * @return 66 */ 67 virtual void ApplicationTerminated(const int32_t recordId) override; 68 69 /** 70 * CheckPermission, call CheckPermission() through proxy object, check the permission. 71 * 72 * @param recordId, a unique record that identifies this Application from others. 73 * @param permission, check the permissions. 74 * @return ERR_OK, return back success, others fail. 75 */ 76 virtual int32_t CheckPermission(const int32_t recordId, const std::string &permission) override; 77 78 /** 79 * AbilityCleaned,call through AbilityCleaned() proxy project, clean Ability record. 80 * 81 * @param token, a unique record that identifies AbilityCleaned from others. 82 * @return 83 */ 84 virtual void AbilityCleaned(const sptr<IRemoteObject> &token) override; 85 86 /** 87 * GetAmsMgr, call GetAmsMgr() through proxy object, get AMS interface instance. 88 * 89 * @return sptr<IAmsMgr>, return to AMS interface instance. 90 */ 91 virtual sptr<IAmsMgr> GetAmsMgr() override; 92 93 /** 94 * ClearUpApplicationData, call ClearUpApplicationData() through proxy project, 95 * clear the application data. 96 * 97 * @param bundleName, bundle name in Application record. 98 * @return 99 */ 100 virtual int32_t ClearUpApplicationData(const std::string &bundleName) override; 101 102 /** 103 * GetAllRunningProcesses, call GetAllRunningProcesses() through proxy project. 104 * Obtains information about application processes that are running on the device. 105 * 106 * @param info, app name in Application record. 107 * @return ERR_OK ,return back success,others fail. 108 */ 109 virtual int32_t GetAllRunningProcesses(std::vector<RunningProcessInfo> &info) override; 110 111 /** 112 * GetAllRenderProcesses, call GetAllRenderProcesses() through proxy project. 113 * Obtains information about render processes that are running on the device. 114 * 115 * @param info, render process info. 116 * @return ERR_OK, return back success, others fail. 117 */ 118 virtual int32_t GetAllRenderProcesses(std::vector<RenderProcessInfo> &info) override; 119 120 /** 121 * JudgeSandboxByPid, call JudgeSandboxByPid() through proxy project. 122 * Obtains information about application processes that are running on the device. 123 * 124 * @param pid, the pid of current app running record. 125 * @param isSandbox, current app is or not a sandbox. 126 * @return ERR_OK ,return back success,others fail. 127 */ 128 virtual int32_t JudgeSandboxByPid(pid_t pid, bool &isSandbox) override; 129 130 /** 131 * GetProcessRunningInfosByUserId, call GetProcessRunningInfosByUserId() through proxy project. 132 * Obtains information about application processes that are running on the device. 133 * 134 * @param info, app name in Application record. 135 * @return ERR_OK ,return back success,others fail. 136 */ 137 virtual int32_t GetProcessRunningInfosByUserId(std::vector<RunningProcessInfo> &info, int32_t userId) override; 138 139 /** 140 * GetProcessRunningInformation, call GetProcessRunningInformation() through proxy project. 141 * Obtains information about current application process which is running on the device. 142 * 143 * @param info, app name in Application record. 144 * @return ERR_OK ,return back success,others fail. 145 */ 146 virtual int32_t GetProcessRunningInformation(RunningProcessInfo &info) override; 147 148 /** 149 * NotifyMemoryLevel, call NotifyMemoryLevel() through proxy project. 150 * Notify abilities background the current memory level. 151 * 152 * @param level, the current memory level 153 * @return ERR_OK ,return back success,others fail. 154 */ 155 virtual int32_t NotifyMemoryLevel(int32_t level) override; 156 157 /** 158 * DumpHeapMemory, call DumpHeapMemory() through proxy project. 159 * Get the application's memory allocation info. 160 * 161 * @param pid, pid input. 162 * @param mallocInfo, dynamic storage information output. 163 * @return ERR_OK ,return back success,others fail. 164 */ 165 virtual int32_t DumpHeapMemory(const int32_t pid, OHOS::AppExecFwk::MallocInfo &mallocInfo) override; 166 167 /** 168 * Notify that the ability stage has been updated 169 * @param recordId, the app record. 170 */ 171 virtual void AddAbilityStageDone(const int32_t recordId) override; 172 173 /** 174 * Start a resident process 175 */ 176 virtual void StartupResidentProcess(const std::vector<AppExecFwk::BundleInfo> &bundleInfos) override; 177 178 /** 179 * Register application or process state observer. 180 * @param observer, ability token. 181 * @return Returns ERR_OK on success, others on failure. 182 */ 183 virtual int32_t RegisterApplicationStateObserver(const sptr<IApplicationStateObserver> &observer, 184 const std::vector<std::string> &bundleNameList = {}) override; 185 186 /** 187 * Unregister application or process state observer. 188 * @param observer, ability token. 189 * @return Returns ERR_OK on success, others on failure. 190 */ 191 virtual int32_t UnregisterApplicationStateObserver(const sptr<IApplicationStateObserver> &observer) override; 192 193 /** 194 * Get foreground applications. 195 * @param list, foreground apps. 196 * @return Returns ERR_OK on success, others on failure. 197 */ 198 virtual int32_t GetForegroundApplications(std::vector<AppStateData> &list) override; 199 200 /** 201 * Start user test process. 202 * @param want, want object. 203 * @param observer, test observer remote object. 204 * @param bundleInfo, bundle info. 205 * @param userId the user id. 206 * @return Returns ERR_OK on success, others on failure. 207 */ 208 virtual int StartUserTestProcess(const AAFwk::Want &want, const sptr<IRemoteObject> &observer, 209 const BundleInfo &bundleInfo, int32_t userId) override; 210 211 /** 212 * @brief Finish user test. 213 * @param msg user test message. 214 * @param resultCode user test result Code. 215 * @param bundleName user test bundleName. 216 * 217 * @return Returns ERR_OK on success, others on failure. 218 */ 219 virtual int FinishUserTest( 220 const std::string &msg, const int64_t &resultCode, const std::string &bundleName) override; 221 222 virtual void ScheduleAcceptWantDone( 223 const int32_t recordId, const AAFwk::Want &want, const std::string &flag) override; 224 225 /** 226 * Get the token of ability records by process ID. 227 * 228 * @param pid The process id. 229 * @param tokens The token of ability records. 230 * @return Returns true on success, others on failure. 231 */ 232 virtual int GetAbilityRecordsByProcessID(const int pid, std::vector<sptr<IRemoteObject>> &tokens) override; 233 234 /** 235 * Prestart nwebspawn process. 236 * 237 * @return Returns ERR_OK on success, others on failure. 238 */ 239 virtual int PreStartNWebSpawnProcess() override; 240 241 /** 242 * Start nweb render process, called by nweb host. 243 * 244 * @param renderParam, params passed to renderprocess. 245 * @param ipcFd, ipc file descriptior for web browser and render process. 246 * @param sharedFd, shared memory file descriptior. 247 * @param crashFd, crash signal file descriptior. 248 * @param renderPid, created render pid. 249 * @return Returns ERR_OK on success, others on failure. 250 */ 251 virtual int StartRenderProcess(const std::string &renderParam, 252 int32_t ipcFd, int32_t sharedFd, 253 int32_t crashFd, pid_t &renderPid) override; 254 255 /** 256 * Render process call this to attach app manager service. 257 * 258 * @param renderApp, information needed to start the Application. 259 */ 260 virtual void AttachRenderProcess(const sptr<IRemoteObject> &renderApp) override; 261 262 /** 263 * Get render process termination status, called by nweb host. 264 * 265 * @param renderPid, target render pid. 266 * @param status, termination status of the render process. 267 * @return Returns ERR_OK on success, others on failure. 268 */ 269 virtual int GetRenderProcessTerminationStatus(pid_t renderPid, int &status) override; 270 271 /** 272 * Notify Fault Data 273 * 274 * @param faultData the fault data. 275 * @return Returns ERR_OK on success, others on failure. 276 */ 277 virtual int32_t NotifyAppFault(const FaultData &faultData) override; 278 279 /** 280 * Notify App Fault Data By SA 281 * 282 * @param faultData the fault data notified by SA. 283 * @return Returns ERR_OK on success, others on failure. 284 */ 285 virtual int32_t NotifyAppFaultBySA(const AppFaultDataBySA &faultData) override; 286 287 #ifdef ABILITY_COMMAND_FOR_TEST 288 /** 289 * Block app service. 290 * 291 * @return Returns ERR_OK on success, others on failure. 292 */ 293 virtual int BlockAppService() override; 294 #endif 295 296 virtual int32_t GetConfiguration(Configuration& config) override; 297 298 virtual int32_t UpdateConfiguration(const Configuration &config) override; 299 300 virtual int32_t RegisterConfigurationObserver(const sptr<IConfigurationObserver> &observer) override; 301 302 virtual int32_t UnregisterConfigurationObserver(const sptr<IConfigurationObserver> &observer) override; 303 304 bool GetAppRunningStateByBundleName(const std::string &bundleName) override; 305 306 int32_t NotifyLoadRepairPatch(const std::string &bundleName, const sptr<IQuickFixCallback> &callback) override; 307 308 int32_t NotifyHotReloadPage(const std::string &bundleName, const sptr<IQuickFixCallback> &callback) override; 309 310 int32_t NotifyUnLoadRepairPatch(const std::string &bundleName, const sptr<IQuickFixCallback> &callback) override; 311 312 #ifdef BGTASKMGR_CONTINUOUS_TASK_ENABLE 313 int32_t SetContinuousTaskProcess(int32_t pid, bool isContinuousTask) override; 314 #endif 315 316 /** 317 * @brief Check whether the shared bundle is running. 318 * 319 * @param bundleName Shared bundle name. 320 * @param versionCode Shared bundle version code. 321 * @return Returns the shared bundle running result. The result is true if running, false otherwise. 322 */ 323 virtual bool IsSharedBundleRunning(const std::string &bundleName, uint32_t versionCode) override; 324 325 virtual int32_t StartNativeProcessForDebugger(const AAFwk::Want &want) override; 326 327 /** 328 * Get bundleName by pid. 329 * 330 * @param pid process id. 331 * @param bundleName Output parameters, return bundleName. 332 * @param uid Output parameters, return userId. 333 * @return Returns ERR_OK on success, others on failure. 334 */ 335 virtual int32_t GetBundleNameByPid(const int pid, std::string &bundleName, int32_t &uid) override; 336 337 /** 338 * get memorySize by pid. 339 * 340 * @param pid process id. 341 * @param memorySize Output parameters, return memorySize in KB. 342 * @return Returns ERR_OK on success, others on failure. 343 */ 344 virtual int32_t GetProcessMemoryByPid(const int32_t pid, int32_t &memorySize) override; 345 346 /** 347 * get application processes information list by bundleName. 348 * 349 * @param bundleName Bundle name. 350 * @param userId user Id in Application record. 351 * @param info Output parameters, return running process info list. 352 * @return Returns ERR_OK on success, others on failure. 353 */ 354 virtual int32_t GetRunningProcessInformation( 355 const std::string &bundleName, int32_t userId, std::vector<RunningProcessInfo> &info) override; 356 357 private: 358 bool SendTransactCmd(AppMgrInterfaceCode code, MessageParcel &data, MessageParcel &reply); 359 bool WriteInterfaceToken(MessageParcel &data); 360 template<typename T> 361 int GetParcelableInfos(MessageParcel &reply, std::vector<T> &parcelableInfos); 362 static inline BrokerDelegator<AppMgrProxy> delegator_; 363 }; 364 } // namespace AppExecFwk 365 } // namespace OHOS 366 #endif // OHOS_ABILITY_RUNTIME_APP_MGR_PROXY_H 367