1 /* 2 * Copyright (c) 2021-2024 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_SERVICE_H 17 #define OHOS_ABILITY_RUNTIME_APP_MGR_SERVICE_H 18 19 #include <list> 20 #include <string> 21 #include <vector> 22 23 #include "ability_info.h" 24 #include "ability_running_record.h" 25 #include "ams_mgr_scheduler.h" 26 #include "app_malloc_info.h" 27 #include "app_mgr_constants.h" 28 #include "app_mgr_service_event_handler.h" 29 #include "app_mgr_service_inner.h" 30 #include "app_mgr_stub.h" 31 #include "app_record_id.h" 32 #include "app_running_record.h" 33 #include "app_running_status_listener_interface.h" 34 #include "app_scheduler_proxy.h" 35 #include "appexecfwk_errors.h" 36 #include "application_info.h" 37 #include "if_system_ability_manager.h" 38 #include "nocopyable.h" 39 #include "system_ability.h" 40 #include "task_handler_wrap.h" 41 #include "app_jsheap_mem_info.h" 42 43 namespace OHOS { 44 namespace AppExecFwk { 45 enum class ServiceRunningState { STATE_NOT_START, STATE_RUNNING }; 46 47 struct AppMgrServiceState { 48 ServiceRunningState serviceRunningState = ServiceRunningState::STATE_NOT_START; 49 SpawnConnectionState connectionState = SpawnConnectionState::STATE_NOT_CONNECT; 50 }; 51 52 class AMSEventHandler; 53 54 class AppMgrService : public SystemAbility, public AppMgrStub { 55 public: 56 DECLEAR_SYSTEM_ABILITY(AppMgrService); 57 58 AppMgrService(); 59 explicit AppMgrService(const int32_t serviceId, bool runOnCreate = false); 60 virtual ~AppMgrService() override; 61 62 // the function about application 63 // attach the application to ams, then ams can control it. 64 /** 65 * AttachApplication, call AttachApplication() through proxy object, 66 * get all the information needed to start the Application (data related to the Application ). 67 * 68 * @param app, information needed to start the Application. 69 * @return 70 */ 71 virtual void AttachApplication(const sptr<IRemoteObject> &app) override; 72 73 /** 74 * Preload application. 75 * 76 * @param bundleName The bundle name of the application to preload. 77 * @param userId Indicates the user identification. 78 * @param preloadMode Preload application mode. 79 * @param appIndex The index of application clone. 80 * @return Returns ERR_OK on success, others on failure. 81 */ 82 virtual int32_t PreloadApplication(const std::string &bundleName, int32_t userId, 83 AppExecFwk::PreloadMode preloadMode, int32_t appIndex) override; 84 85 // notify the ams update the state of an app, when it entered foreground. 86 87 /** 88 * ApplicationForegrounded, call ApplicationForegrounded() through proxy object, 89 * set the application to Foreground State. 90 * 91 * @param recordId, a unique record that identifies this Application from others. 92 * @return 93 */ 94 virtual void ApplicationForegrounded(const int32_t recordId) override; 95 96 /** 97 * ApplicationBackgrounded, call ApplicationBackgrounded() through proxy object, 98 * set the application to Backgrounded State. 99 * 100 * @param recordId, a unique record that identifies this Application from others. 101 * @return 102 */ 103 virtual void ApplicationBackgrounded(const int32_t recordId) override; 104 105 /** 106 * ApplicationTerminated, call ApplicationTerminated() through proxy object, 107 * terminate the application. 108 * 109 * @param recordId, a unique record that identifies this Application from others. 110 * @return 111 */ 112 virtual void ApplicationTerminated(const int32_t recordId) override; 113 114 /** 115 * AbilityCleaned,call through AbilityCleaned() proxy project, clean Ability record. 116 * 117 * @param token, a unique record that identifies AbilityCleaned from others. 118 * @return 119 */ 120 virtual void AbilityCleaned(const sptr<IRemoteObject> &token) override; 121 122 /** 123 * ClearUpApplicationData, call ClearUpApplicationData() through proxy project, 124 * clear the application data. 125 * 126 * @param bundleName, bundle name in Application record. 127 * @param appCloneIndex the app clone id. 128 * @param userId the user id. 129 * @return Returns ERR_OK on success, others on failure. 130 */ 131 virtual int32_t ClearUpApplicationData(const std::string &bundleName, int32_t appCloneIndex, 132 int32_t userId = -1) override; 133 134 /** 135 * ClearUpApplicationDataBySelf, call ClearUpApplicationDataBySelf() through proxy project, 136 * clear the application data by self. 137 * 138 * @param userId, user ID. 139 * @return Returns ERR_OK on success, others on failure. 140 */ 141 virtual int32_t ClearUpApplicationDataBySelf(int32_t userId = -1) override; 142 143 /** 144 * GetAllRunningProcesses, call GetAllRunningProcesses() through proxy project. 145 * Obtains information about application processes that are running on the device. 146 * 147 * @param info, app name in Application record. 148 * @return Returns ERR_OK on success, others on failure. 149 */ 150 virtual int32_t GetAllRunningProcesses(std::vector<RunningProcessInfo> &info) override; 151 152 /** 153 * GetRunningMultiAppInfoByBundleName, call GetRunningMultiAppInfoByBundleName() through proxy project. 154 * Obtains information about multiapp that are running on the device. 155 * 156 * @param bundlename, input. 157 * @param info, output multiapp information. 158 * @return ERR_OK ,return back success,others fail. 159 */ 160 virtual int32_t GetRunningMultiAppInfoByBundleName(const std::string &bundleName, 161 RunningMultiAppInfo &info) override; 162 163 /** 164 * GetRunningProcessesByBundleType, call GetRunningProcessesByBundleType() through proxy project. 165 * Obtains information about application processes by bundle type that are running on the device. 166 * 167 * @param bundleType, bundle type of the processes 168 * @param info, app name in Application record. 169 * @return ERR_OK ,return back success,others fail. 170 */ 171 virtual int GetRunningProcessesByBundleType(const BundleType bundleType, 172 std::vector<RunningProcessInfo> &info) override; 173 174 /** 175 * GetAllRenderProcesses, call GetAllRenderProcesses() through proxy project. 176 * Obtains information about render processes that are running on the device. 177 * 178 * @param info, render process info. 179 * @return ERR_OK, return back success, others fail. 180 */ 181 virtual int32_t GetAllRenderProcesses(std::vector<RenderProcessInfo> &info) override; 182 183 /** 184 * GetAllChildrenProcesses, call GetAllChildrenProcesses() through proxy project. 185 * Obtains information about children processes that are running on the device. 186 * 187 * @param info, child process info. 188 * @return ERR_OK, return back success, others fail. 189 */ 190 virtual int GetAllChildrenProcesses(std::vector<ChildProcessInfo> &info) override; 191 192 /** 193 * JudgeSandboxByPid, call JudgeSandboxByPid() through proxy project. 194 * Obtains information about application processes that are running on the device. 195 * 196 * @param pid, the pid of current app running record. 197 * @param isSandbox, current app is or not a sandbox. 198 * @return Returns ERR_OK on success, others on failure. 199 */ 200 virtual int32_t JudgeSandboxByPid(pid_t pid, bool &isSandbox) override; 201 202 /** 203 * GetProcessRunningInfosByUserId, call GetProcessRunningInfosByUserId() through proxy project. 204 * Obtains information about application processes that are running on the device. 205 * 206 * @param info, app name in Application record. 207 * @param userId, userId. 208 * 209 * @return Returns ERR_OK on success, others on failure. 210 */ 211 virtual int32_t GetProcessRunningInfosByUserId(std::vector<RunningProcessInfo> &info, int32_t userId) override; 212 213 /** 214 * GetProcessRunningInformation, call GetProcessRunningInformation() through proxy project. 215 * Obtains information about current application process which is running on the device. 216 * 217 * @param info, app name in Application record. 218 * 219 * @return Returns ERR_OK on success, others on failure. 220 */ 221 virtual int32_t GetProcessRunningInformation(RunningProcessInfo &info) override; 222 223 /** 224 * NotifyMemoryLevel, call NotifyMemoryLevel() through proxy project. 225 * Notify applications background the current memory level. 226 * 227 * @param level, current memory level. 228 * @return Returns ERR_OK on success, others on failure. 229 */ 230 virtual int32_t NotifyMemoryLevel(int32_t level) override; 231 232 /** 233 * NotifyProcMemoryLevel, call NotifyMemoryLevel() through proxy project. 234 * Notify applications the current memory level. 235 * 236 * @param procLevelMap , <pid_t, MemoryLevel> map. 237 * @return Returns ERR_OK on success, others on failure. 238 */ 239 virtual int32_t NotifyProcMemoryLevel(const std::map<pid_t, MemoryLevel> &procLevelMap) override; 240 241 /** 242 * DumpHeapMemory, call DumpHeapMemory() through proxy project. 243 * Get the application's memory allocation info. 244 * 245 * @param pid, pid input. 246 * @param mallocInfo, dynamic storage information output. 247 * @return Returns ERR_OK on success, others on failure. 248 */ 249 virtual int32_t DumpHeapMemory(const int32_t pid, OHOS::AppExecFwk::MallocInfo &mallocInfo) override; 250 251 /** 252 * Authenticate dump permissions 253 * 254 * @return Returns true on permission, others on false 255 */ 256 bool HasDumpPermission() const; 257 /** 258 * DumpJsHeapMemory, call DumpJsHeapMemory() through proxy project. 259 * triggerGC and dump the application's jsheap memory info. 260 * 261 * @param info, pid, tid, needGc, needSnapshot 262 * @return Returns ERR_OK on success, others on failure. 263 */ 264 virtual int32_t DumpJsHeapMemory(OHOS::AppExecFwk::JsHeapDumpInfo &info) override; 265 266 // the function about service running info 267 /** 268 * QueryServiceState, Query application service status. 269 * 270 * @return the application service status. 271 */ 272 AppMgrServiceState QueryServiceState(); 273 274 /** 275 * GetAmsMgr, call GetAmsMgr() through proxy object, get AMS interface instance. 276 * 277 * @return sptr<IAmsMgr>, return to AMS interface instance. 278 */ 279 virtual sptr<IAmsMgr> GetAmsMgr() override; 280 281 /** 282 * Notify that the ability stage has been updated 283 * @param recordId, the app record. 284 */ 285 virtual void AddAbilityStageDone(const int32_t recordId) override; 286 287 /** 288 * Start all resident process 289 */ 290 virtual void StartupResidentProcess(const std::vector<AppExecFwk::BundleInfo> &bundleInfos) override; 291 292 /** 293 * Start user test process. 294 * @param want, want object. 295 * @param observer, test observer remote object. 296 * @param bundleInfo, bundle info. 297 * @param userId the user id. 298 * @return Returns ERR_OK on success, others on failure. 299 */ 300 virtual int StartUserTestProcess(const AAFwk::Want &want, const sptr<IRemoteObject> &observer, 301 const AppExecFwk::BundleInfo &bundleInfo, int32_t userId) override; 302 303 /** 304 * @brief Finish user test. 305 * @param msg user test message. 306 * @param resultCode user test result Code. 307 * @param bundleName user test bundleName. 308 * 309 * @return Returns ERR_OK on success, others on failure. 310 */ 311 virtual int FinishUserTest( 312 const std::string &msg, const int64_t &resultCode, const std::string &bundleName) override; 313 314 /** 315 * @brief Application hidumper. 316 * @param fd Indicates the fd. 317 * @param args Indicates the params. 318 * @return Returns the dump result. 319 */ 320 int Dump(int fd, const std::vector<std::u16string>& args) override; 321 322 virtual void ScheduleAcceptWantDone( 323 const int32_t recordId, const AAFwk::Want &want, const std::string &flag) override; 324 325 virtual void ScheduleNewProcessRequestDone( 326 const int32_t recordId, const AAFwk::Want &want, const std::string &flag) override; 327 328 virtual int GetAbilityRecordsByProcessID(const int pid, std::vector<sptr<IRemoteObject>> &tokens) override; 329 330 virtual int PreStartNWebSpawnProcess() override; 331 332 virtual int StartRenderProcess(const std::string &renderParam, 333 int32_t ipcFd, int32_t sharedFd, 334 int32_t crashFd, pid_t &renderPid, bool isGPU = false) override; 335 336 virtual void AttachRenderProcess(const sptr<IRemoteObject> &shceduler) override; 337 338 virtual int GetRenderProcessTerminationStatus(pid_t renderPid, int &status) override; 339 340 virtual int32_t GetConfiguration(Configuration& config) override; 341 342 virtual int32_t UpdateConfiguration(const Configuration &config, const int32_t userId = -1) override; 343 344 virtual int32_t UpdateConfigurationByBundleName(const Configuration &config, const std::string &name) override; 345 346 virtual int32_t RegisterConfigurationObserver(const sptr<IConfigurationObserver> &observer) override; 347 348 virtual int32_t UnregisterConfigurationObserver(const sptr<IConfigurationObserver> &observer) override; 349 350 bool GetAppRunningStateByBundleName(const std::string &bundleName) override; 351 352 int32_t NotifyLoadRepairPatch(const std::string &bundleName, const sptr<IQuickFixCallback> &callback) override; 353 354 int32_t NotifyHotReloadPage(const std::string &bundleName, const sptr<IQuickFixCallback> &callback) override; 355 356 int32_t NotifyUnLoadRepairPatch(const std::string &bundleName, const sptr<IQuickFixCallback> &callback) override; 357 358 #ifdef BGTASKMGR_CONTINUOUS_TASK_ENABLE 359 int32_t SetContinuousTaskProcess(int32_t pid, bool isContinuousTask) override; 360 #endif 361 362 /** 363 * @brief Check whether the shared bundle is running. 364 * 365 * @param bundleName Shared bundle name. 366 * @param versionCode Shared bundle version code. 367 * @return Returns the shared bundle running result. The result is true if running, false otherwise. 368 */ 369 virtual bool IsSharedBundleRunning(const std::string &bundleName, uint32_t versionCode) override; 370 371 virtual int32_t StartNativeProcessForDebugger(const AAFwk::Want &want) override; 372 373 /** 374 * Get bundleName by pid. 375 * 376 * @param pid process id. 377 * @param bundleName Output parameters, return bundleName. 378 * @param uid Output parameters, return userId. 379 * @return Returns ERR_OK on success, others on failure. 380 */ 381 virtual int32_t GetBundleNameByPid(const int32_t pid, std::string &bundleName, int32_t &uid) override; 382 383 /** 384 * Get running process information by pid. 385 * 386 * @param pid process id. 387 * @param info Output parameters, return runningProcessInfo. 388 * @return Returns ERR_OK on success, others on failure. 389 */ 390 virtual int32_t GetRunningProcessInfoByPid(const pid_t pid, OHOS::AppExecFwk::RunningProcessInfo &info) override; 391 392 /** 393 * Notify Fault Data 394 * 395 * @param faultData the fault data. 396 * @return Returns ERR_OK on success, others on failure. 397 */ 398 int32_t NotifyAppFault(const FaultData &faultData) override; 399 400 /** 401 * Notify Fault Data By SA 402 * 403 * @param faultData the fault data notified by SA. 404 * @return Returns ERR_OK on success, others on failure. 405 */ 406 int32_t NotifyAppFaultBySA(const AppFaultDataBySA &faultData) override; 407 408 /** 409 * Set Appfreeze Detect Filter 410 * 411 * @param pid the process pid. 412 * @return Returns true on success, others on failure. 413 */ 414 bool SetAppFreezeFilter(int32_t pid) override; 415 416 /** 417 * get memorySize by pid. 418 * 419 * @param pid process id. 420 * @param memorySize Output parameters, return memorySize in KB. 421 * @return Returns ERR_OK on success, others on failure. 422 */ 423 virtual int32_t GetProcessMemoryByPid(const int32_t pid, int32_t &memorySize) override; 424 425 /** 426 * get application processes information list by bundleName. 427 * 428 * @param bundleName Bundle name. 429 * @param userId user Id in Application record. 430 * @param info Output parameters, return running process info list. 431 * @return Returns ERR_OK on success, others on failure. 432 */ 433 virtual int32_t GetRunningProcessInformation( 434 const std::string &bundleName, int32_t userId, std::vector<RunningProcessInfo> &info) override; 435 436 /** 437 * on add systemAbility. 438 * 439 * @return 440 */ 441 virtual void OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override; 442 443 /** 444 * on remove systemAbility. 445 * 446 * @return 447 */ 448 virtual void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override; 449 450 /** 451 * @brief Notify NativeEngine GC of status change. 452 * 453 * @param state GC state 454 * @param pid pid 455 * 456 * @return Is the status change completed. 457 */ 458 virtual int32_t ChangeAppGcState(pid_t pid, int32_t state) override; 459 460 /** 461 * Register appRunning status listener. 462 * 463 * @param listener Running status listener. 464 * @return Returns ERR_OK on success, others on failure. 465 */ 466 int32_t RegisterAppRunningStatusListener(const sptr<IRemoteObject> &listener) override; 467 468 /** 469 * Unregister appRunning status listener. 470 * 471 * @param listener Running status listener. 472 * @return Returns ERR_OK on success, others on failure. 473 */ 474 int32_t UnregisterAppRunningStatusListener(const sptr<IRemoteObject> &listener) override; 475 476 /** 477 * Register application foreground state observer. 478 * @param observer Is App Foreground Statue Observer 479 * @return Returns ERR_OK on success, others on failure. 480 */ 481 int32_t RegisterAppForegroundStateObserver(const sptr<IAppForegroundStateObserver> &observer) override; 482 483 /** 484 * Unregister application foreground state observer. 485 * @param observer Is App Foreground Statue Observer 486 * @return Returns ERR_OK on success, others on failure. 487 */ 488 int32_t UnregisterAppForegroundStateObserver(const sptr<IAppForegroundStateObserver> &observer) override; 489 490 /** 491 * Start child process, called by ChildProcessManager. 492 * 493 * @param childPid Created child process pid. 494 * @param request Child process start request params. 495 * @return Returns ERR_OK on success, others on failure. 496 */ 497 int32_t StartChildProcess(pid_t &childPid, const ChildProcessRequest &request) override; 498 499 /** 500 * Get child process record for self. 501 * 502 * @return child process info. 503 */ 504 int32_t GetChildProcessInfoForSelf(ChildProcessInfo &info) override; 505 506 /** 507 * Attach child process scheduler to app manager service. 508 * 509 * @param childScheduler scheduler of child process. 510 */ 511 void AttachChildProcess(const sptr<IRemoteObject> &childScheduler) override; 512 513 /** 514 * Exit child process, called by itself. 515 */ 516 void ExitChildProcessSafely() override; 517 518 int32_t RegisterRenderStateObserver(const sptr<IRenderStateObserver> &observer) override; 519 520 int32_t UnregisterRenderStateObserver(const sptr<IRenderStateObserver> &observer) override; 521 522 int32_t UpdateRenderState(pid_t renderPid, int32_t state) override; 523 524 int32_t SignRestartAppFlag(int32_t uid) override; 525 526 int32_t GetAppRunningUniqueIdByPid(pid_t pid, std::string &appRunningUniqueId) override; 527 528 int32_t GetAllUIExtensionRootHostPid(pid_t pid, std::vector<pid_t> &hostPids) override; 529 530 int32_t GetAllUIExtensionProviderPid(pid_t hostPid, std::vector<pid_t> &providerPids) override; 531 532 int32_t NotifyMemorySizeStateChanged(bool isMemorySizeSufficent) override; 533 534 void SetAppAssertionPauseState(bool flag) override; 535 536 int32_t SetSupportedProcessCacheSelf(bool isSupport) override; 537 538 int32_t SetSupportedProcessCache(int32_t pid, bool isSupport) override; 539 540 virtual void SaveBrowserChannel(sptr<IRemoteObject> browser) override; 541 542 /** 543 * Check caller is test ability 544 * 545 * @param pid, the pid of ability. 546 * @return Returns ERR_OK is test ability, others is not test ability. 547 */ 548 int32_t CheckCallingIsUserTestMode(const pid_t pid, bool &isUserTest) override; 549 /** 550 * Start native child process, callde by ChildProcessManager. 551 * @param libName lib file name to be load in child process 552 * @param childProcessCount current started child process count 553 * @param callback callback for notify start result 554 * @return Returns ERR_OK on success, others on failure. 555 */ 556 int32_t StartNativeChildProcess(const std::string &libName, int32_t childProcessCount, 557 const sptr<IRemoteObject> &callback) override; 558 559 virtual int32_t NotifyProcessDependedOnWeb() override; 560 561 virtual void KillProcessDependedOnWeb() override; 562 563 virtual void RestartResidentProcessDependedOnWeb() override; 564 565 int32_t GetAppIndexByPid(pid_t pid, int32_t &appIndex) override; 566 private: 567 /** 568 * Init, Initialize application services. 569 * 570 * @return ERR_OK, return back success, others fail. 571 */ 572 ErrCode Init(); 573 574 // the function that overrode from SystemAbility 575 /** 576 * OnStart, Start application service. 577 * 578 * @return 579 */ 580 virtual void OnStart() override; 581 582 /** 583 * OnStop, Stop application service. 584 * 585 * @return 586 */ 587 virtual void OnStop() override; 588 589 /** 590 * @brief Judge whether the application service is ready. 591 * 592 * @return Returns true means service is ready, otherwise service is not ready. 593 */ 594 bool IsReady() const; 595 596 /** 597 * SetInnerService, Setting application service Inner instance. 598 * 599 * @return 600 */ 601 void SetInnerService(const std::shared_ptr<AppMgrServiceInner> &innerService); 602 603 /** 604 * Register application or process state observer. 605 * @param observer, ability token. 606 * @return Returns ERR_OK on success, others on failure. 607 */ 608 virtual int32_t RegisterApplicationStateObserver(const sptr<IApplicationStateObserver> &observer, 609 const std::vector<std::string> &bundleNameList = {}) override; 610 611 /** 612 * Unregister application or process state observer. 613 * @param observer, ability token. 614 * @return Returns ERR_OK on success, others on failure. 615 */ 616 virtual int32_t UnregisterApplicationStateObserver(const sptr<IApplicationStateObserver> &observer) override; 617 618 /** 619 * Register application or process state observer. 620 * @param observer, Is ability foreground state observer 621 * @return Returns ERR_OK on success, others on failure. 622 */ 623 int32_t RegisterAbilityForegroundStateObserver(const sptr<IAbilityForegroundStateObserver> &observer) override; 624 625 /** 626 * Unregister application or process state observer. 627 * @param observer, Is ability foreground state observer 628 * @return Returns ERR_OK on success, others on failure. 629 */ 630 int32_t UnregisterAbilityForegroundStateObserver(const sptr<IAbilityForegroundStateObserver> &observer) override; 631 632 /** 633 * Get foreground applications. 634 * @param list, foreground apps. 635 * @return Returns ERR_OK on success, others on failure. 636 */ 637 virtual int32_t GetForegroundApplications(std::vector<AppStateData> &list) override; 638 639 int Dump(const std::vector<std::u16string>& args, std::string& result); 640 int ShowHelp(const std::vector<std::u16string>& args, std::string& result); 641 int DumpIpc(const std::vector<std::u16string>& args, std::string& result); 642 int DumpIpcAllStart(std::string& result); 643 int DumpIpcAllStop(std::string& result); 644 int DumpIpcAllStat(std::string& result); 645 int DumpIpcStart(const int32_t pid, std::string& result); 646 int DumpIpcStop(const int32_t pid, std::string& result); 647 int DumpIpcStat(const int32_t pid, std::string& result); 648 649 int DumpFfrt(const std::vector<std::u16string>& args, std::string& result); 650 651 bool JudgeAppSelfCalled(int32_t recordId); 652 653 /** 654 * @brief Notify AbilityManagerService the page show. 655 * @param token Ability identify. 656 * @param pageStateData The data of ability's page state. 657 * @return Returns ERR_OK on success, others on failure. 658 */ 659 virtual int32_t NotifyPageShow(const sptr<IRemoteObject> &token, const PageStateData &pageStateData) override; 660 661 /** 662 * @brief Notify AbilityManagerService the page hide. 663 * @param token Ability identify. 664 * @param pageStateData The data of ability's page state. 665 * @return Returns ERR_OK on success, others on failure. 666 */ 667 virtual int32_t NotifyPageHide(const sptr<IRemoteObject> &token, const PageStateData &pageStateData) override; 668 669 /** 670 * Check whether the bundle is running. 671 * 672 * @param bundleName Indicates the bundle name of the bundle. 673 * @param isRunning Obtain the running status of the application, the result is true if running, false otherwise. 674 * @return Return ERR_OK if success, others fail. 675 */ 676 int32_t IsApplicationRunning(const std::string &bundleName, bool &isRunning) override; 677 678 /** 679 * Check whether the bundle is running. 680 * 681 * @param bundleName Indicates the bundle name of the bundle. 682 * @param appCloneIndex the appindex of the bundle. 683 * @param isRunning Obtain the running status of the application, the result is true if running, false otherwise. 684 * @return Return ERR_OK if success, others fail. 685 */ 686 int32_t IsAppRunning(const std::string &bundleName, int32_t appCloneIndex, bool &isRunning) override; 687 688 /** 689 * Whether the current application process is the last surviving process. 690 * 691 * @return Returns true is final application process, others return false. 692 */ 693 bool IsFinalAppProcess() override; 694 695 enum DumpIpcKey { 696 KEY_DUMP_IPC_START = 0, 697 KEY_DUMP_IPC_STOP, 698 KEY_DUMP_IPC_STAT, 699 }; 700 701 private: 702 int DumpIpcAllInner(const AppMgrService::DumpIpcKey key, std::string& result); 703 int DumpIpcWithPidInner(const AppMgrService::DumpIpcKey key, 704 const std::string& optionPid, std::string& result); 705 706 int DumpFfrtInner(const std::string& pidsRaw, std::string& result); 707 708 private: 709 std::shared_ptr<AppMgrServiceInner> appMgrServiceInner_; 710 AppMgrServiceState appMgrServiceState_; 711 std::shared_ptr<AAFwk::TaskHandlerWrap> taskHandler_; 712 std::shared_ptr<AMSEventHandler> eventHandler_; 713 sptr<ISystemAbilityManager> systemAbilityMgr_; 714 sptr<IAmsMgr> amsMgrScheduler_; 715 716 bool GetDumpIpcKeyByOption(const std::string &option, DumpIpcKey &key); 717 718 DISALLOW_COPY_AND_MOVE(AppMgrService); 719 }; 720 } // namespace AppExecFwk 721 } // namespace OHOS 722 #endif // OHOS_ABILITY_RUNTIME_APP_MGR_SERVICE_H 723