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 "app_malloc_info.h" 20 #include "app_mgr_interface.h" 21 #include "bundle_info.h" 22 #include "iremote_proxy.h" 23 #include "want.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, 100 const int32_t userId = -1) override; 101 102 /** 103 * ClearUpApplicationData, call ClearUpApplicationData() through proxy project, 104 * clear the application data. 105 * 106 * @param bundleName, bundle name in Application record. 107 * @return 108 */ 109 virtual int32_t ClearUpApplicationDataBySelf(int32_t userId = -1) override; 110 111 /** 112 * GetAllRunningProcesses, call GetAllRunningProcesses() through proxy project. 113 * Obtains information about application processes that are running on the device. 114 * 115 * @param info, app name in Application record. 116 * @return ERR_OK ,return back success,others fail. 117 */ 118 virtual int32_t GetAllRunningProcesses(std::vector<RunningProcessInfo> &info) override; 119 120 /** 121 * GetAllRenderProcesses, call GetAllRenderProcesses() through proxy project. 122 * Obtains information about render processes that are running on the device. 123 * 124 * @param info, render process info. 125 * @return ERR_OK, return back success, others fail. 126 */ 127 virtual int32_t GetAllRenderProcesses(std::vector<RenderProcessInfo> &info) override; 128 129 /** 130 * JudgeSandboxByPid, call JudgeSandboxByPid() through proxy project. 131 * Obtains information about application processes that are running on the device. 132 * 133 * @param pid, the pid of current app running record. 134 * @param isSandbox, current app is or not a sandbox. 135 * @return ERR_OK ,return back success,others fail. 136 */ 137 virtual int32_t JudgeSandboxByPid(pid_t pid, bool &isSandbox) override; 138 139 /** 140 * GetProcessRunningInfosByUserId, call GetProcessRunningInfosByUserId() through proxy project. 141 * Obtains information about application processes that are 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 GetProcessRunningInfosByUserId(std::vector<RunningProcessInfo> &info, int32_t userId) override; 147 148 /** 149 * GetProcessRunningInformation, call GetProcessRunningInformation() through proxy project. 150 * Obtains information about current application process which is running on the device. 151 * 152 * @param info, app name in Application record. 153 * @return ERR_OK ,return back success,others fail. 154 */ 155 virtual int32_t GetProcessRunningInformation(RunningProcessInfo &info) override; 156 157 /** 158 * NotifyMemoryLevel, call NotifyMemoryLevel() through proxy project. 159 * Notify abilities background the current memory level. 160 * 161 * @param level, the current memory level 162 * @return ERR_OK ,return back success,others fail. 163 */ 164 virtual int32_t NotifyMemoryLevel(int32_t level) override; 165 166 /** 167 * DumpHeapMemory, call DumpHeapMemory() through proxy project. 168 * Get the application's memory allocation info. 169 * 170 * @param pid, pid input. 171 * @param mallocInfo, dynamic storage information output. 172 * @return ERR_OK ,return back success,others fail. 173 */ 174 virtual int32_t DumpHeapMemory(const int32_t pid, OHOS::AppExecFwk::MallocInfo &mallocInfo) override; 175 176 /** 177 * Notify that the ability stage has been updated 178 * @param recordId, the app record. 179 */ 180 virtual void AddAbilityStageDone(const int32_t recordId) override; 181 182 /** 183 * Start a resident process 184 */ 185 virtual void StartupResidentProcess(const std::vector<AppExecFwk::BundleInfo> &bundleInfos) override; 186 187 /** 188 * Register application or process state observer. 189 * @param observer, ability token. 190 * @return Returns ERR_OK on success, others on failure. 191 */ 192 virtual int32_t RegisterApplicationStateObserver(const sptr<IApplicationStateObserver> &observer, 193 const std::vector<std::string> &bundleNameList = {}) override; 194 195 /** 196 * Unregister application or process state observer. 197 * @param observer, ability token. 198 * @return Returns ERR_OK on success, others on failure. 199 */ 200 virtual int32_t UnregisterApplicationStateObserver(const sptr<IApplicationStateObserver> &observer) override; 201 202 /** 203 * Register application or process state observer. 204 * @param observer, Is ability foreground state observer 205 * @return Returns ERR_OK on success, others on failure. 206 */ 207 int32_t RegisterAbilityForegroundStateObserver(const sptr<IAbilityForegroundStateObserver> &observer) override; 208 209 /** 210 * Unregister application or process state observer. 211 * @param observer, Is ability foreground state observer 212 * @return Returns ERR_OK on success, others on failure. 213 */ 214 int32_t UnregisterAbilityForegroundStateObserver(const sptr<IAbilityForegroundStateObserver> &observer) override; 215 216 /** 217 * Get foreground applications. 218 * @param list, foreground apps. 219 * @return Returns ERR_OK on success, others on failure. 220 */ 221 virtual int32_t GetForegroundApplications(std::vector<AppStateData> &list) override; 222 223 /** 224 * Start user test process. 225 * @param want, want object. 226 * @param observer, test observer remote object. 227 * @param bundleInfo, bundle info. 228 * @param userId the user id. 229 * @return Returns ERR_OK on success, others on failure. 230 */ 231 virtual int StartUserTestProcess(const AAFwk::Want &want, const sptr<IRemoteObject> &observer, 232 const BundleInfo &bundleInfo, int32_t userId) override; 233 234 /** 235 * @brief Finish user test. 236 * @param msg user test message. 237 * @param resultCode user test result Code. 238 * @param bundleName user test bundleName. 239 * 240 * @return Returns ERR_OK on success, others on failure. 241 */ 242 virtual int FinishUserTest( 243 const std::string &msg, const int64_t &resultCode, const std::string &bundleName) override; 244 245 virtual void ScheduleAcceptWantDone( 246 const int32_t recordId, const AAFwk::Want &want, const std::string &flag) override; 247 248 virtual void ScheduleNewProcessRequestDone( 249 const int32_t recordId, const AAFwk::Want &want, const std::string &flag) override; 250 251 /** 252 * Get the token of ability records by process ID. 253 * 254 * @param pid The process id. 255 * @param tokens The token of ability records. 256 * @return Returns true on success, others on failure. 257 */ 258 virtual int GetAbilityRecordsByProcessID(const int pid, std::vector<sptr<IRemoteObject>> &tokens) override; 259 260 /** 261 * Prestart nwebspawn process. 262 * 263 * @return Returns ERR_OK on success, others on failure. 264 */ 265 virtual int PreStartNWebSpawnProcess() override; 266 267 /** 268 * Start nweb render process, called by nweb host. 269 * 270 * @param renderParam, params passed to renderprocess. 271 * @param ipcFd, ipc file descriptior for web browser and render process. 272 * @param sharedFd, shared memory file descriptior. 273 * @param crashFd, crash signal file descriptior. 274 * @param renderPid, created render pid. 275 * @return Returns ERR_OK on success, others on failure. 276 */ 277 virtual int StartRenderProcess(const std::string &renderParam, 278 int32_t ipcFd, int32_t sharedFd, 279 int32_t crashFd, pid_t &renderPid) override; 280 281 /** 282 * Render process call this to attach app manager service. 283 * 284 * @param renderApp, information needed to start the Application. 285 */ 286 virtual void AttachRenderProcess(const sptr<IRemoteObject> &renderApp) override; 287 288 /** 289 * Get render process termination status, called by nweb host. 290 * 291 * @param renderPid, target render pid. 292 * @param status, termination status of the render process. 293 * @return Returns ERR_OK on success, others on failure. 294 */ 295 virtual int GetRenderProcessTerminationStatus(pid_t renderPid, int &status) override; 296 297 /** 298 * Notify Fault Data 299 * 300 * @param faultData the fault data. 301 * @return Returns ERR_OK on success, others on failure. 302 */ 303 virtual int32_t NotifyAppFault(const FaultData &faultData) override; 304 305 /** 306 * Notify App Fault Data By SA 307 * 308 * @param faultData the fault data notified by SA. 309 * @return Returns ERR_OK on success, others on failure. 310 */ 311 virtual int32_t NotifyAppFaultBySA(const AppFaultDataBySA &faultData) override; 312 313 #ifdef ABILITY_COMMAND_FOR_TEST 314 /** 315 * Block app service. 316 * 317 * @return Returns ERR_OK on success, others on failure. 318 */ 319 virtual int BlockAppService() override; 320 #endif 321 322 virtual int32_t GetConfiguration(Configuration& config) override; 323 324 virtual int32_t UpdateConfiguration(const Configuration &config) override; 325 326 virtual int32_t RegisterConfigurationObserver(const sptr<IConfigurationObserver> &observer) override; 327 328 virtual int32_t UnregisterConfigurationObserver(const sptr<IConfigurationObserver> &observer) override; 329 330 bool GetAppRunningStateByBundleName(const std::string &bundleName) override; 331 332 int32_t NotifyLoadRepairPatch(const std::string &bundleName, const sptr<IQuickFixCallback> &callback) override; 333 334 int32_t NotifyHotReloadPage(const std::string &bundleName, const sptr<IQuickFixCallback> &callback) override; 335 336 int32_t NotifyUnLoadRepairPatch(const std::string &bundleName, const sptr<IQuickFixCallback> &callback) override; 337 338 #ifdef BGTASKMGR_CONTINUOUS_TASK_ENABLE 339 int32_t SetContinuousTaskProcess(int32_t pid, bool isContinuousTask) override; 340 #endif 341 342 /** 343 * @brief Check whether the shared bundle is running. 344 * 345 * @param bundleName Shared bundle name. 346 * @param versionCode Shared bundle version code. 347 * @return Returns the shared bundle running result. The result is true if running, false otherwise. 348 */ 349 virtual bool IsSharedBundleRunning(const std::string &bundleName, uint32_t versionCode) override; 350 351 virtual int32_t StartNativeProcessForDebugger(const AAFwk::Want &want) override; 352 353 /** 354 * Get bundleName by pid. 355 * 356 * @param pid process id. 357 * @param bundleName Output parameters, return bundleName. 358 * @param uid Output parameters, return userId. 359 * @return Returns ERR_OK on success, others on failure. 360 */ 361 virtual int32_t GetBundleNameByPid(const int pid, std::string &bundleName, int32_t &uid) override; 362 363 /** 364 * get memorySize by pid. 365 * 366 * @param pid process id. 367 * @param memorySize Output parameters, return memorySize in KB. 368 * @return Returns ERR_OK on success, others on failure. 369 */ 370 virtual int32_t GetProcessMemoryByPid(const int32_t pid, int32_t &memorySize) override; 371 372 /** 373 * get application processes information list by bundleName. 374 * 375 * @param bundleName Bundle name. 376 * @param userId user Id in Application record. 377 * @param info Output parameters, return running process info list. 378 * @return Returns ERR_OK on success, others on failure. 379 */ 380 virtual int32_t GetRunningProcessInformation( 381 const std::string &bundleName, int32_t userId, std::vector<RunningProcessInfo> &info) override; 382 383 /** 384 * @brief Notify AbilityManagerService the page show. 385 * @param token Ability identify. 386 * @param pageStateData The data of ability's page state. 387 * @return Returns ERR_OK on success, others on failure. 388 */ 389 virtual int32_t NotifyPageShow(const sptr<IRemoteObject> &token, const PageStateData &pageStateData) override; 390 391 /** 392 * @brief Notify AbilityManagerService the page hide. 393 * @param token Ability identify. 394 * @param pageStateData The data of ability's page state. 395 * @return Returns ERR_OK on success, others on failure. 396 */ 397 virtual int32_t NotifyPageHide(const sptr<IRemoteObject> &token, const PageStateData &pageStateData) override; 398 399 /** 400 * @brief Notify NativeEngine GC of status change. 401 * 402 * @param state GC state 403 * @param pid pid 404 * @return Returns ERR_OK on success, others on failure. 405 */ 406 virtual int32_t ChangeAppGcState(pid_t pid, int32_t state) override; 407 408 /** 409 * Register appRunning status listener. 410 * 411 * @param listener Running status listener. 412 * @return Returns ERR_OK on success, others on failure. 413 */ 414 int32_t RegisterAppRunningStatusListener(const sptr<IRemoteObject> &listener) override; 415 416 /** 417 * Unregister appRunning status listener. 418 * 419 * @param listener Running status listener. 420 * @return Returns ERR_OK on success, others on failure. 421 */ 422 int32_t UnregisterAppRunningStatusListener(const sptr<IRemoteObject> &listener) override; 423 424 /** 425 * Register application foreground state observer. 426 * @param observer, app Is app foreground state observer 427 * @return Returns ERR_OK on success, others on failure. 428 */ 429 int32_t RegisterAppForegroundStateObserver(const sptr<IAppForegroundStateObserver> &observer) override; 430 431 /** 432 * Unregister application foreground state observer. 433 * @param observer, app Is app foreground state observer 434 * @return Returns ERR_OK on success, others on failure. 435 */ 436 int32_t UnregisterAppForegroundStateObserver(const sptr<IAppForegroundStateObserver> &observer) override; 437 438 /** 439 * Check whether the bundle is running. 440 * 441 * @param bundleName Indicates the bundle name of the bundle. 442 * @param isRunning Obtain the running status of the application, the result is true if running, false otherwise. 443 * @return Return ERR_OK if success, others fail. 444 */ 445 int32_t IsApplicationRunning(const std::string &bundleName, bool &isRunning) override; 446 447 /** 448 * Start child process, called by ChildProcessManager. 449 * 450 * @param srcEntry Child process source file entrance path to be started. 451 * @param childPid Created child process pid. 452 * @return Returns ERR_OK on success, others on failure. 453 */ 454 int32_t StartChildProcess(const std::string &srcEntry, pid_t &childPid) override; 455 456 /** 457 * Get child process record for self. 458 * 459 * @return child process info. 460 */ 461 int32_t GetChildProcessInfoForSelf(ChildProcessInfo &info) override; 462 463 /** 464 * Attach child process scheduler to app manager service. 465 * 466 * @param childScheduler scheduler of child process. 467 */ 468 void AttachChildProcess(const sptr<IRemoteObject> &childScheduler) override; 469 470 /** 471 * Exit child process, called by itself. 472 */ 473 void ExitChildProcessSafely() override; 474 475 /** 476 * Whether the current application process is the last surviving process. 477 * 478 * @return Returns true is final application process, others return false. 479 */ 480 bool IsFinalAppProcess() override; 481 482 private: 483 bool SendTransactCmd(AppMgrInterfaceCode code, MessageParcel &data, MessageParcel &reply); 484 bool WriteInterfaceToken(MessageParcel &data); 485 int32_t SendRequest(AppMgrInterfaceCode code, MessageParcel &data, MessageParcel &reply, 486 MessageOption& option); 487 template<typename T> 488 int GetParcelableInfos(MessageParcel &reply, std::vector<T> &parcelableInfos); 489 static inline BrokerDelegator<AppMgrProxy> delegator_; 490 }; 491 } // namespace AppExecFwk 492 } // namespace OHOS 493 #endif // OHOS_ABILITY_RUNTIME_APP_MGR_PROXY_H 494