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 OHOS_ABILITY_RUNTIME_APP_MGR_SERVICE_INNER_H 17 #define OHOS_ABILITY_RUNTIME_APP_MGR_SERVICE_INNER_H 18 19 #include <list> 20 #include <map> 21 #include <vector> 22 #include <regex> 23 #include <unordered_map> 24 25 #include "iremote_object.h" 26 #include "refbase.h" 27 28 #include "ability_info.h" 29 #include "appexecfwk_errors.h" 30 #include "app_death_recipient.h" 31 #include "app_mgr_constants.h" 32 #include "app_record_id.h" 33 #include "app_running_record.h" 34 #include "app_scheduler_interface.h" 35 #include "app_spawn_client.h" 36 #include "app_task_info.h" 37 #include "iapp_state_callback.h" 38 #include "iapplication_state_observer.h" 39 #include "iconfiguration_observer.h" 40 #include "app_process_manager.h" 41 #include "remote_client_manager.h" 42 #include "app_running_manager.h" 43 #include "record_query_result.h" 44 #include "running_process_info.h" 45 #include "bundle_info.h" 46 #include "istart_specified_ability_response.h" 47 48 #include "want.h" 49 #include "window_focus_changed_listener.h" 50 51 namespace OHOS { 52 namespace AppExecFwk { 53 using OHOS::AAFwk::Want; 54 class AppMgrServiceInner : public std::enable_shared_from_this<AppMgrServiceInner> { 55 public: 56 AppMgrServiceInner(); 57 virtual ~AppMgrServiceInner(); 58 59 /** 60 * Initialize the object. 61 */ 62 void Init(); 63 /** 64 * LoadAbility, load the ability that needed to be started. 65 * 66 * @param token, the unique identification to start the ability. 67 * @param preToken, the unique identification to call the ability. 68 * @param abilityInfo, the ability information. 69 * @param appInfo, the app information. 70 * @param want the ability want. 71 * 72 * @return 73 */ 74 virtual void LoadAbility(const sptr<IRemoteObject> &token, const sptr<IRemoteObject> &preToken, 75 const std::shared_ptr<AbilityInfo> &abilityInfo, const std::shared_ptr<ApplicationInfo> &appInfo, 76 const std::shared_ptr<AAFwk::Want> &want); 77 78 /** 79 * TerminateAbility, terminate the token ability. 80 * 81 * @param token, he unique identification to terminate the ability. 82 * @param clearMissionFlag, indicates whether terminate the ability when clearMission. 83 * @return 84 */ 85 virtual void TerminateAbility(const sptr<IRemoteObject> &token, bool clearMissionFlag); 86 87 /** 88 * UpdateAbilityState, update the ability status. 89 * 90 * @param token, the unique identification to update the ability. 91 * @param state, ability status that needs to be updated. 92 * 93 * @return 94 */ 95 virtual void UpdateAbilityState(const sptr<IRemoteObject> &token, const AbilityState state); 96 97 /** 98 * UpdateExtensionState, call UpdateExtensionState() through the proxy object, update the extension status. 99 * 100 * @param token, the unique identification to update the extension. 101 * @param state, extension status that needs to be updated. 102 */ 103 virtual void UpdateExtensionState(const sptr<IRemoteObject> &token, const ExtensionState state); 104 105 /** 106 * StateChangedNotifyObserver, Call ability state change. 107 * 108 * @param ability, the ability info. 109 * @param state, the ability state. 110 * 111 * @return 112 */ 113 void StateChangedNotifyObserver(const AbilityStateData abilityStateData, bool isAbility); 114 115 /** 116 * RegisterAppStateCallback, register the callback. 117 * 118 * @param callback, Ams register the callback. 119 * 120 * @return 121 */ 122 virtual void RegisterAppStateCallback(const sptr<IAppStateCallback> &callback); 123 124 /** 125 * AbilityBehaviorAnalysis, ability behavior analysis assistant process optimization. 126 * 127 * @param token, the unique identification to start the ability. 128 * @param preToken, the unique identification to call the ability. 129 * @param visibility, the visibility information about windows info. 130 * @param perceptibility, the Perceptibility information about windows info. 131 * @param connectionState, the service ability connection state. 132 * @return 133 */ 134 virtual void AbilityBehaviorAnalysis(const sptr<IRemoteObject> &token, const sptr<IRemoteObject> &preToken, 135 const int32_t visibility, const int32_t perceptibility, const int32_t connectionState); 136 137 /** 138 * KillProcessByAbilityToken, kill the process by ability token. 139 * 140 * @param token, the unique identification to the ability. 141 * @return 142 */ 143 virtual void KillProcessByAbilityToken(const sptr<IRemoteObject> &token); 144 145 /** 146 * KillProcessesByUserId, kill the processes by userId. 147 * 148 * @param userId, the user id. 149 * @return 150 */ 151 virtual void KillProcessesByUserId(int32_t userId); 152 153 /** 154 * AttachApplication, get all the information needed to start the Application 155 * (data related to the Application ). 156 * 157 * @param appScheduler, information needed to start the Application. 158 * 159 * @return 160 */ 161 virtual void AttachApplication(const pid_t pid, const sptr<IAppScheduler> &appScheduler); 162 163 /** 164 * ApplicationForegrounded, set the application to Foreground State. 165 * 166 * @param recordId, a unique record that identifies this Application from others. 167 * 168 * @return 169 */ 170 virtual void ApplicationForegrounded(const int32_t recordId); 171 172 /** 173 * ApplicationBackgrounded, set the application to Backgrounded State. 174 * 175 * @param recordId, a unique record that identifies this Application from others. 176 * 177 * @return 178 */ 179 virtual void ApplicationBackgrounded(const int32_t recordId); 180 181 /** 182 * ApplicationTerminated, terminate the application. 183 * 184 * @param recordId, a unique record that identifies this Application from others. 185 * 186 * @return 187 */ 188 virtual void ApplicationTerminated(const int32_t recordId); 189 190 /** 191 * AbilityTerminated, terminate the ability. 192 * 193 * @param token, the unique identification to terminated the ability. 194 * 195 * @return 196 */ 197 virtual void AbilityTerminated(const sptr<IRemoteObject> &token); 198 199 /** 200 * UpdateApplicationInfoInstalled, update the application info after new module installed. 201 * 202 * @param bundleName, bundle name in Application record. 203 * @param uid, uid. 204 * @return ERR_OK, return back success, others fail. 205 */ 206 virtual int32_t UpdateApplicationInfoInstalled(const std::string &bundleName, const int uid); 207 208 /** 209 * KillApplication, kill the application. 210 * 211 * @param bundleName, bundle name in Application record. 212 * 213 * @return ERR_OK, return back success, others fail. 214 */ 215 virtual int32_t KillApplication(const std::string &bundleName); 216 217 /** 218 * KillApplicationByUid, call KillApplicationByUid() through proxy object, kill the application. 219 * 220 * @param bundleName, bundle name in Application record. 221 * @param uid, uid. 222 * @return ERR_OK, return back success, others fail. 223 */ 224 virtual int32_t KillApplicationByUid(const std::string &bundleName, const int uid); 225 226 virtual int32_t KillApplicationSelf(); 227 228 /** 229 * KillApplicationByUserId, kill the application by user ID. 230 * 231 * @param bundleName, bundle name in Application record. 232 * @param userId, user ID. 233 * 234 * @return ERR_OK, return back success, others fail. 235 */ 236 virtual int32_t KillApplicationByUserId(const std::string &bundleName, const int userId); 237 238 /** 239 * ClearUpApplicationData, clear the application data. 240 * 241 * @param bundleName, bundle name in Application record. 242 * @param callerUid, app uid in Application record. 243 * @param callerPid, app pid in Application record. 244 * 245 * @return 246 */ 247 virtual void ClearUpApplicationData(const std::string &bundleName, const int32_t callerUid, const pid_t callerPid); 248 249 /** 250 * GetAllRunningProcesses, Obtains information about application processes that are running on the device. 251 * 252 * @param info, app name in Application record. 253 * 254 * @return ERR_OK ,return back success,others fail. 255 */ 256 virtual int32_t GetAllRunningProcesses(std::vector<RunningProcessInfo> &info); 257 258 /** 259 * GetProcessRunningInfosByUserId, Obtains information about application processes that are running on the device. 260 * 261 * @param info, app name in Application record. 262 * @param userId, userId. 263 * 264 * @return ERR_OK ,return back success,others fail. 265 */ 266 virtual int32_t GetProcessRunningInfosByUserId(std::vector<RunningProcessInfo> &info, int32_t userId); 267 268 /** 269 * GetProcessRunningInformation, Obtains information about current application process 270 * which is running on the device. 271 * @param info, app name in Application record. 272 * 273 * @return ERR_OK ,return back success,others fail. 274 */ 275 virtual int32_t GetProcessRunningInformation(RunningProcessInfo &info); 276 277 /** 278 * NotifyMemoryLevel, Notify applications background the current memory level. 279 * 280 * @param level, current memory level. 281 * 282 * @return ERR_OK ,return back success,others fail. 283 */ 284 virtual int32_t NotifyMemoryLevel(int32_t level); 285 286 std::shared_ptr<AppRunningRecord> CreateAppRunningRecord( 287 const sptr<IRemoteObject> &token, 288 const sptr<IRemoteObject> &preToken, 289 const std::shared_ptr<ApplicationInfo> &appInfo, 290 const std::shared_ptr<AbilityInfo> &abilityInfo, 291 const std::string &processName, 292 const BundleInfo &bundleInfo, 293 const HapModuleInfo &hapModuleInfo, 294 const std::shared_ptr<AAFwk::Want> &want); 295 296 /** 297 * OnStop, Application management service stopped. 298 * 299 * @return 300 */ 301 void OnStop(); 302 303 /** 304 * OpenAppSpawnConnection, Open connection with appspawn. 305 * 306 * @return ERR_OK ,return back success,others fail. 307 */ 308 virtual ErrCode OpenAppSpawnConnection(); 309 310 /** 311 * CloseAppSpawnConnection, Close connection with appspawn. 312 * 313 * @return 314 */ 315 virtual void CloseAppSpawnConnection() const; 316 317 /** 318 * QueryAppSpawnConnectionState, Query the connection status with appspawn. 319 * 320 * @return Returns the connection status with appspawn. 321 */ 322 virtual SpawnConnectionState QueryAppSpawnConnectionState() const; 323 324 /** 325 * SetAppSpawnClient, Setting the client to connect with appspawn. 326 * 327 * @param spawnClient, the client to connect with appspawn. 328 * 329 * @return 330 */ 331 void SetAppSpawnClient(std::shared_ptr<AppSpawnClient> spawnClient); 332 333 // Schedule launch application with specified |appRecord| 334 335 /** 336 * LaunchApplication, Notify application to launch application. 337 * 338 * @param appRecord, the application record. 339 * 340 * @return 341 */ 342 void LaunchApplication(const std::shared_ptr<AppRunningRecord> &appRecord); 343 344 /** 345 * Notice of AddAbilityStageInfo() 346 * 347 * @param recordId, the application record. 348 */ 349 virtual void AddAbilityStageDone(const int32_t recordId); 350 351 /** 352 * GetAppRunningRecordByPid, Get process record by application pid. 353 * 354 * @param pid, the application pid. 355 * 356 * @return process record. 357 */ 358 std::shared_ptr<AppRunningRecord> GetAppRunningRecordByPid(const pid_t pid) const; 359 360 /** 361 * GetAppRunningRecordByAbilityToken, Get process record by ability token. 362 * 363 * @param abilityToken, the ability token. 364 * 365 * @return process record. 366 */ 367 std::shared_ptr<AppRunningRecord> GetAppRunningRecordByAbilityToken(const sptr<IRemoteObject> &abilityToken) const; 368 369 /** 370 * GetAppRunningRecordByAppRecordId, Get process record by application id. 371 * 372 * @param recordId, the application id. 373 * 374 * @return process record. 375 */ 376 std::shared_ptr<AppRunningRecord> GetAppRunningRecordByAppRecordId(const int32_t recordId) const; 377 378 /** 379 * OnAbilityStateChanged, Call ability state change. 380 * 381 * @param ability, the ability info. 382 * @param state, the ability state. 383 * 384 * @return 385 */ 386 void OnAbilityStateChanged(const std::shared_ptr<AbilityRunningRecord> &ability, const AbilityState state); 387 388 /** 389 * GetRecentAppList, Get a list of recent applications. 390 * 391 * @return a list of recent applications. 392 */ 393 const std::list<const std::shared_ptr<AppTaskInfo>> &GetRecentAppList() const; 394 395 /** 396 * GetRecentAppList, Remove the corresponding latest application list data by applying the name. 397 * 398 * @param appName, the application name. 399 * @param processName, the process name. 400 * 401 * @return 402 */ 403 void RemoveAppFromRecentList(const std::string &appName, const std::string &processName); 404 405 /** 406 * GetRecentAppList, Clear recent application list. 407 * 408 * @return 409 */ 410 void ClearRecentAppList(); 411 412 /** 413 * OnRemoteDied, Equipment death notification. 414 * 415 * @param remote, Death client. 416 * @param isRenderProcess is render process died. 417 * @return 418 */ 419 void OnRemoteDied(const wptr<IRemoteObject> &remote, bool isRenderProcess = false); 420 421 /** 422 * AddAppDeathRecipient, Add monitoring death application record. 423 * 424 * @param pid, the application pid. 425 * @param appDeathRecipient, Application death recipient list. 426 * 427 * @return 428 */ 429 430 virtual void AddAppDeathRecipient(const pid_t pid, const sptr<AppDeathRecipient> &appDeathRecipient) const; 431 432 void HandleTimeOut(const InnerEvent::Pointer &event); 433 434 void SetEventHandler(const std::shared_ptr<AMSEventHandler> &handler); 435 436 void HandleAbilityAttachTimeOut(const sptr<IRemoteObject> &token); 437 438 void PrepareTerminate(const sptr<IRemoteObject> &token); 439 440 void OnAppStateChanged(const std::shared_ptr<AppRunningRecord> &appRecord, const ApplicationState state, 441 bool needNotifyApp); 442 443 void GetRunningProcessInfoByToken(const sptr<IRemoteObject> &token, AppExecFwk::RunningProcessInfo &info); 444 445 void GetRunningProcessInfoByPid(const pid_t pid, OHOS::AppExecFwk::RunningProcessInfo &info) const; 446 447 /** 448 * UpdateConfiguration, ANotify application update system environment changes. 449 * 450 * @param config, System environment change parameters. 451 * @return Returns ERR_OK on success, others on failure. 452 */ 453 int32_t UpdateConfiguration(const Configuration &config); 454 455 std::shared_ptr<AppExecFwk::Configuration> GetConfiguration(); 456 457 int32_t RegisterConfigurationObserver(const sptr<IConfigurationObserver>& observer); 458 459 int32_t UnregisterConfigurationObserver(const sptr<IConfigurationObserver>& observer); 460 461 /** 462 * Start empty process 463 */ 464 void LoadResidentProcess(const std::vector<BundleInfo> &infos); 465 466 void StartResidentProcess(const std::vector<BundleInfo> &infos, int restartCount, bool isEmptyKeepAliveApp); 467 468 bool CheckRemoteClient(); 469 470 /** 471 * Register application or process state observer. 472 * @param observer, ability token. 473 * @return Returns ERR_OK on success, others on failure. 474 */ 475 int32_t RegisterApplicationStateObserver(const sptr<IApplicationStateObserver> &observer, 476 const std::vector<std::string> &bundleNameList = {}); 477 478 /** 479 * Unregister application or process state observer. 480 * @param observer, ability token. 481 * @return Returns ERR_OK on success, others on failure. 482 */ 483 int32_t UnregisterApplicationStateObserver(const sptr<IApplicationStateObserver> &observer); 484 485 /** 486 * Get Foreground Applications. 487 * 488 * @return Foreground Applications. 489 */ 490 int32_t GetForegroundApplications(std::vector<AppStateData> &list); 491 492 /** 493 * Start user test process. 494 * @param want, want object. 495 * @param observer, test observer remote object. 496 * @param bundleInfo, bundle info. 497 * @param userId the user id. 498 * @return Returns ERR_OK on success, others on failure. 499 */ 500 int StartUserTestProcess(const AAFwk::Want &want, const sptr<IRemoteObject> &observer, 501 const AppExecFwk::BundleInfo &bundleInfo, int32_t userId); 502 503 /** 504 * @brief Finish user test. 505 * @param msg user test message. 506 * @param resultCode user test result Code. 507 * @param bundleName user test bundleName. 508 * @param pid the user test process id. 509 * 510 * @return Returns ERR_OK on success, others on failure. 511 */ 512 int FinishUserTest( 513 const std::string &msg, const int64_t &resultCode, const std::string &bundleName, const pid_t &pid); 514 515 void StartSpecifiedAbility(const AAFwk::Want &want, const AppExecFwk::AbilityInfo &abilityInfo); 516 517 void RegisterStartSpecifiedAbilityResponse(const sptr<IStartSpecifiedAbilityResponse> &response); 518 519 void ScheduleAcceptWantDone(const int32_t recordId, const AAFwk::Want &want, const std::string &flag); 520 521 /** 522 * Get the token of ability records by process ID. 523 * 524 * @param pid The process id. 525 * @param tokens The token of ability records. 526 * @return Returns true on success, others on failure. 527 */ 528 int GetAbilityRecordsByProcessID(const int pid, std::vector<sptr<IRemoteObject>> &tokens); 529 530 virtual int32_t PreStartNWebSpawnProcess(const pid_t hostPid); 531 532 virtual int32_t StartRenderProcess(const pid_t hostPid, const std::string &renderParam, 533 int32_t ipcFd, int32_t sharedFd, pid_t &renderPid); 534 535 virtual void AttachRenderProcess(const pid_t pid, const sptr<IRenderScheduler> &scheduler); 536 537 virtual int GetRenderProcessTerminationStatus(pid_t renderPid, int &status); 538 539 int VerifyProcessPermission(const sptr<IRemoteObject> &token) const; 540 541 int VerifyAccountPermission(const std::string &permissionName, const int userId) const; 542 543 int VerifyRequestPermission() const; 544 545 void ClearAppRunningData(const std::shared_ptr<AppRunningRecord> &appRecord, bool containsApp); 546 547 void TerminateApplication(const std::shared_ptr<AppRunningRecord> &appRecord); 548 549 int GetApplicationInfoByProcessID(const int pid, AppExecFwk::ApplicationInfo &application, bool &debug); 550 /** 551 * Notify application status. 552 * 553 * @param bundleName Indicates the name of the bundle. 554 * @param eventData Indicates the event defined by CommonEventSupport 555 * 556 * @return 557 */ 558 void NotifyAppStatus(const std::string &bundleName, const std::string &eventData); 559 560 /** 561 * KillProcessByPid, Kill process by PID. 562 * 563 * @param pid_t, the app record pid. 564 * 565 * @return ERR_OK, return back success,others fail. 566 */ 567 int32_t KillProcessByPid(const pid_t pid) const; 568 569 bool GetAppRunningStateByBundleName(const std::string &bundleName); 570 571 int32_t NotifyLoadRepairPatch(const std::string &bundleName, const sptr<IQuickFixCallback> &callback); 572 573 int32_t NotifyHotReloadPage(const std::string &bundleName, const sptr<IQuickFixCallback> &callback); 574 575 int32_t NotifyUnLoadRepairPatch(const std::string &bundleName, const sptr<IQuickFixCallback> &callback); 576 577 void HandleFocused(const sptr<OHOS::Rosen::FocusChangeInfo> &focusChangeInfo); 578 void HandleUnfocused(const sptr<OHOS::Rosen::FocusChangeInfo> &focusChangeInfo); 579 580 #ifdef BGTASKMGR_CONTINUOUS_TASK_ENABLE 581 int32_t SetContinuousTaskProcess(int32_t pid, bool isContinuousTask); 582 #endif 583 584 private: 585 586 void StartEmptyResidentProcess(const BundleInfo &info, const std::string &processName, int restartCount, 587 bool isEmptyKeepAliveApp); 588 589 void RestartResidentProcess(std::shared_ptr<AppRunningRecord> appRecord); 590 591 bool CheckLoadAbilityConditions(const sptr<IRemoteObject> &token, 592 const std::shared_ptr<AbilityInfo> &abilityInfo, const std::shared_ptr<ApplicationInfo> &appInfo); 593 594 bool GetBundleInfo(const std::string &bundleName, BundleInfo &bundleInfo); 595 596 void MakeProcessName(const std::shared_ptr<AbilityInfo> &abilityInfo, 597 const std::shared_ptr<ApplicationInfo> &appInfo, 598 const HapModuleInfo &hapModuleInfo, int32_t appIndex, std::string &processName); 599 600 void MakeProcessName( 601 const std::shared_ptr<ApplicationInfo> &appInfo, const HapModuleInfo &hapModuleInfo, std::string &processName); 602 /** 603 * StartAbility, load the ability that needed to be started(Start on the basis of the original process). 604 * Start on a new boot process 605 * @param token, the unique identification to start the ability. 606 * @param preToken, the unique identification to call the ability. 607 * @param abilityInfo, the ability information. 608 * @param appInfo, the app information. 609 * 610 * @return 611 */ 612 void StartAbility(const sptr<IRemoteObject> &token, const sptr<IRemoteObject> &preToken, 613 const std::shared_ptr<AbilityInfo> &abilityInfo, const std::shared_ptr<AppRunningRecord> &appRecord, 614 const HapModuleInfo &hapModuleInfo, const std::shared_ptr<AAFwk::Want> &want); 615 616 /** 617 * StartProcess, load the ability that needed to be started(Start on a new boot process). 618 * 619 * @param appName, the app name. 620 * @param processName, the process name. 621 * @param appRecord, the app information. 622 * @param uid, the process uid. 623 * @param bundleName, the app bundleName. 624 * 625 * @return 626 */ 627 void StartProcess(const std::string &appName, const std::string &processName, uint32_t startFlags, 628 const std::shared_ptr<AppRunningRecord> &appRecord, const int uid, 629 const std::string &bundleName, const int32_t bundleIndex); 630 631 /** 632 * PushAppFront, Adjust the latest application record to the top level. 633 * 634 * @param recordId, the app record id. 635 * 636 * @return 637 */ 638 void PushAppFront(const int32_t recordId); 639 640 /** 641 * RemoveAppFromRecentListById, Remove the specified recent application record by application record id. 642 * 643 * @param recordId, the app record id. 644 * 645 * @return 646 */ 647 void RemoveAppFromRecentListById(const int32_t recordId); 648 649 /** 650 * AddAppToRecentList, Add application to recent list. 651 * 652 * @param appName, the app name. 653 * @param processName, the process name. 654 * @param pid, the app pid. 655 * @param recordId, the app record id. 656 * 657 * @return 658 */ 659 void AddAppToRecentList( 660 const std::string &appName, const std::string &processName, const pid_t pid, const int32_t recordId); 661 662 /** 663 * AddAppToRecentList, Get application task information through ID. 664 * 665 * @param recordId, the app record id. 666 * 667 * @return application task information. 668 */ 669 const std::shared_ptr<AppTaskInfo> GetAppTaskInfoById(const int32_t recordId) const; 670 671 /** 672 * KillApplicationByUserId, kill the application by user ID. 673 * 674 * @param bundleName, bundle name in Application record. 675 * @param userId, user ID. 676 * 677 * @return ERR_OK, return back success, others fail. 678 */ 679 int32_t KillApplicationByUserIdLocked(const std::string &bundleName, const int userId); 680 681 /** 682 * WaitForRemoteProcessExit, Wait for the process to exit normally. 683 * 684 * @param pids, process number collection to exit. 685 * @param startTime, execution process security exit start time. 686 * 687 * @return true, return back success,others fail. 688 */ 689 bool WaitForRemoteProcessExit(std::list<pid_t> &pids, const int64_t startTime); 690 691 /** 692 * GetAllPids, Get the corresponding pid collection. 693 * 694 * @param pids, process number collection to exit. 695 * 696 * @return true, return back success,others fail. 697 */ 698 bool GetAllPids(std::list<pid_t> &pids); 699 700 /** 701 * ProcessExist, Judge whether the process exists. 702 * 703 * @param pids, process number collection to exit. 704 * 705 * @return true, return back existed,others non-existent. 706 */ 707 bool ProcessExist(pid_t &pid); 708 709 /** 710 * CheckAllProcessExist, Determine whether all processes exist . 711 * 712 * @param pids, process number collection to exit. 713 * 714 * @return true, Returns that a process exists and all other processes do not exist. 715 */ 716 bool CheckAllProcessExist(std::list<pid_t> &pids); 717 718 /** 719 * SystemTimeMillisecond, Get system time. 720 * 721 * @return the system time. 722 */ 723 int64_t SystemTimeMillisecond(); 724 725 // Test add the bundle manager instance. 726 void SetBundleManager(sptr<IBundleMgr> bundleManager); 727 728 void HandleTerminateApplicationTimeOut(const int64_t eventId); 729 730 void HandleAddAbilityStageTimeOut(const int64_t eventId); 731 732 void ClipStringContent(const std::regex &re, const std::string &source, std::string &afterCutStr); 733 734 bool GetBundleAndHapInfo(const AbilityInfo &abilityInfo, const std::shared_ptr<ApplicationInfo> &appInfo, 735 BundleInfo &bundleInfo, HapModuleInfo &hapModuleInfo, int32_t appIndex = 0); 736 AppProcessData WrapAppProcessData(const std::shared_ptr<AppRunningRecord> &appRecord, 737 const ApplicationState state); 738 739 int UserTestAbnormalFinish(const sptr<IRemoteObject> &observer, const std::string &msg); 740 int GetHapModuleInfoForTestRunner(const AAFwk::Want &want, const sptr<IRemoteObject> &observer, 741 const BundleInfo &bundleInfo, HapModuleInfo &hapModuleInfo); 742 int StartEmptyProcess(const AAFwk::Want &want, const sptr<IRemoteObject> &observer, const BundleInfo &info, 743 const std::string &processName, const int userId); 744 745 void HandleStartSpecifiedAbilityTimeOut(const int64_t eventId); 746 747 void InitGlobalConfiguration(); 748 749 void GetRunningProcesses(const std::shared_ptr<AppRunningRecord> &appRecord, std::vector<RunningProcessInfo> &info); 750 void GetRunningProcess(const std::shared_ptr<AppRunningRecord> &appRecord, RunningProcessInfo &info); 751 752 int StartRenderProcessImpl(const std::shared_ptr<RenderRecord> &renderRecord, 753 const std::shared_ptr<AppRunningRecord> appRecord, pid_t &renderPid); 754 755 void OnRenderRemoteDied(const wptr<IRemoteObject> &remote); 756 757 void AddWatchParameter(); 758 759 bool VerifyAPL() const; 760 761 void InitFocusListener(); 762 void RegisterFocusListener(); 763 764 static void PointerDeviceEventCallback(const char *key, const char *value, void *context); 765 766 int VerifyProcessPermission(const std::string &bundleName) const; 767 768 private: 769 /** 770 * ClearUpApplicationData, clear the application data. 771 * 772 * @param bundleName, bundle name in Application record. 773 * @param uid, app uid in Application record. 774 * @param pid, app pid in Application record. 775 * @param userId, userId. 776 * 777 * @return 778 */ 779 void ClearUpApplicationDataByUserId(const std::string &bundleName, 780 int32_t callerUid, pid_t callerPid, const int userId); 781 782 uint32_t BuildStartFlags(const AAFwk::Want &want, const AbilityInfo &abilityInfo); 783 784 bool CheckGetRunningInfoPermission() const; 785 786 int32_t KillApplicationByBundleName(const std::string &bundleName); 787 788 private: 789 /** 790 * Notify application status. 791 * 792 * @param bundleName Indicates the name of the bundle. 793 * @param bundleName Indicates the name of the bundle. 794 * @param eventData Indicates the event defined by CommonEventSupport 795 * 796 * @return 797 */ 798 void NotifyAppStatusByCallerUid(const std::string &bundleName, const int32_t userId, const int32_t callerUid, 799 const std::string &eventData); 800 void KillApplicationByRecord(const std::shared_ptr<AppRunningRecord> &appRecord); 801 void SendHiSysEvent(const int32_t innerEventId, const int64_t eventId); 802 int FinishUserTestLocked( 803 const std::string &msg, const int64_t &resultCode, const std::shared_ptr<AppRunningRecord> &appRecord); 804 const std::string TASK_ON_CALLBACK_DIED = "OnCallbackDiedTask"; 805 std::vector<const sptr<IAppStateCallback>> appStateCallbacks_; 806 std::shared_ptr<AppProcessManager> appProcessManager_; 807 std::shared_ptr<RemoteClientManager> remoteClientManager_; 808 std::shared_ptr<AppRunningManager> appRunningManager_; 809 std::shared_ptr<AMSEventHandler> eventHandler_; 810 std::shared_ptr<Configuration> configuration_; 811 std::mutex userTestLock_; 812 sptr<IStartSpecifiedAbilityResponse> startSpecifiedAbilityResponse_; 813 std::recursive_mutex configurationObserverLock_; 814 std::vector<sptr<IConfigurationObserver>> configurationObservers_; 815 sptr<WindowFocusChangedListener> focusListener_; 816 std::vector<std::shared_ptr<AppRunningRecord>> restartResedentTaskList_; 817 }; 818 } // namespace AppExecFwk 819 } // namespace OHOS 820 #endif // OHOS_ABILITY_RUNTIME_APP_MGR_SERVICE_INNER_H 821