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 /** 581 * Set the current userId, only used by abilityMgr. 582 * 583 * @param userId the user id. 584 * 585 * @return 586 */ 587 void SetCurrentUserId(const int32_t userId); 588 589 #ifdef BGTASKMGR_CONTINUOUS_TASK_ENABLE 590 int32_t SetContinuousTaskProcess(int32_t pid, bool isContinuousTask); 591 #endif 592 593 private: 594 595 void StartEmptyResidentProcess(const BundleInfo &info, const std::string &processName, int restartCount, 596 bool isEmptyKeepAliveApp); 597 598 void RestartResidentProcess(std::shared_ptr<AppRunningRecord> appRecord); 599 600 bool CheckLoadAbilityConditions(const sptr<IRemoteObject> &token, 601 const std::shared_ptr<AbilityInfo> &abilityInfo, const std::shared_ptr<ApplicationInfo> &appInfo); 602 603 bool GetBundleInfo(const std::string &bundleName, BundleInfo &bundleInfo); 604 605 void MakeProcessName(const std::shared_ptr<AbilityInfo> &abilityInfo, 606 const std::shared_ptr<ApplicationInfo> &appInfo, 607 const HapModuleInfo &hapModuleInfo, int32_t appIndex, std::string &processName); 608 609 void MakeProcessName( 610 const std::shared_ptr<ApplicationInfo> &appInfo, const HapModuleInfo &hapModuleInfo, std::string &processName); 611 /** 612 * StartAbility, load the ability that needed to be started(Start on the basis of the original process). 613 * Start on a new boot process 614 * @param token, the unique identification to start the ability. 615 * @param preToken, the unique identification to call the ability. 616 * @param abilityInfo, the ability information. 617 * @param appInfo, the app information. 618 * 619 * @return 620 */ 621 void StartAbility(const sptr<IRemoteObject> &token, const sptr<IRemoteObject> &preToken, 622 const std::shared_ptr<AbilityInfo> &abilityInfo, const std::shared_ptr<AppRunningRecord> &appRecord, 623 const HapModuleInfo &hapModuleInfo, const std::shared_ptr<AAFwk::Want> &want); 624 625 /** 626 * StartProcess, load the ability that needed to be started(Start on a new boot process). 627 * 628 * @param appName, the app name. 629 * @param processName, the process name. 630 * @param appRecord, the app information. 631 * @param uid, the process uid. 632 * @param bundleName, the app bundleName. 633 * 634 * @return 635 */ 636 void StartProcess(const std::string &appName, const std::string &processName, uint32_t startFlags, 637 const std::shared_ptr<AppRunningRecord> &appRecord, const int uid, 638 const std::string &bundleName, const int32_t bundleIndex); 639 640 /** 641 * PushAppFront, Adjust the latest application record to the top level. 642 * 643 * @param recordId, the app record id. 644 * 645 * @return 646 */ 647 void PushAppFront(const int32_t recordId); 648 649 /** 650 * RemoveAppFromRecentListById, Remove the specified recent application record by application record id. 651 * 652 * @param recordId, the app record id. 653 * 654 * @return 655 */ 656 void RemoveAppFromRecentListById(const int32_t recordId); 657 658 /** 659 * AddAppToRecentList, Add application to recent list. 660 * 661 * @param appName, the app name. 662 * @param processName, the process name. 663 * @param pid, the app pid. 664 * @param recordId, the app record id. 665 * 666 * @return 667 */ 668 void AddAppToRecentList( 669 const std::string &appName, const std::string &processName, const pid_t pid, const int32_t recordId); 670 671 /** 672 * AddAppToRecentList, Get application task information through ID. 673 * 674 * @param recordId, the app record id. 675 * 676 * @return application task information. 677 */ 678 const std::shared_ptr<AppTaskInfo> GetAppTaskInfoById(const int32_t recordId) const; 679 680 /** 681 * KillApplicationByUserId, kill the application by user ID. 682 * 683 * @param bundleName, bundle name in Application record. 684 * @param userId, user ID. 685 * 686 * @return ERR_OK, return back success, others fail. 687 */ 688 int32_t KillApplicationByUserIdLocked(const std::string &bundleName, const int userId); 689 690 /** 691 * WaitForRemoteProcessExit, Wait for the process to exit normally. 692 * 693 * @param pids, process number collection to exit. 694 * @param startTime, execution process security exit start time. 695 * 696 * @return true, return back success,others fail. 697 */ 698 bool WaitForRemoteProcessExit(std::list<pid_t> &pids, const int64_t startTime); 699 700 /** 701 * GetAllPids, Get the corresponding pid collection. 702 * 703 * @param pids, process number collection to exit. 704 * 705 * @return true, return back success,others fail. 706 */ 707 bool GetAllPids(std::list<pid_t> &pids); 708 709 /** 710 * ProcessExist, Judge whether the process exists. 711 * 712 * @param pids, process number collection to exit. 713 * 714 * @return true, return back existed,others non-existent. 715 */ 716 bool ProcessExist(pid_t &pid); 717 718 /** 719 * CheckAllProcessExist, Determine whether all processes exist . 720 * 721 * @param pids, process number collection to exit. 722 * 723 * @return true, Returns that a process exists and all other processes do not exist. 724 */ 725 bool CheckAllProcessExist(std::list<pid_t> &pids); 726 727 /** 728 * SystemTimeMillisecond, Get system time. 729 * 730 * @return the system time. 731 */ 732 int64_t SystemTimeMillisecond(); 733 734 // Test add the bundle manager instance. 735 void SetBundleManager(sptr<IBundleMgr> bundleManager); 736 737 void HandleTerminateApplicationTimeOut(const int64_t eventId); 738 739 void HandleAddAbilityStageTimeOut(const int64_t eventId); 740 741 void ClipStringContent(const std::regex &re, const std::string &source, std::string &afterCutStr); 742 743 bool GetBundleAndHapInfo(const AbilityInfo &abilityInfo, const std::shared_ptr<ApplicationInfo> &appInfo, 744 BundleInfo &bundleInfo, HapModuleInfo &hapModuleInfo, int32_t appIndex = 0); 745 AppProcessData WrapAppProcessData(const std::shared_ptr<AppRunningRecord> &appRecord, 746 const ApplicationState state); 747 748 int UserTestAbnormalFinish(const sptr<IRemoteObject> &observer, const std::string &msg); 749 int GetHapModuleInfoForTestRunner(const AAFwk::Want &want, const sptr<IRemoteObject> &observer, 750 const BundleInfo &bundleInfo, HapModuleInfo &hapModuleInfo); 751 int StartEmptyProcess(const AAFwk::Want &want, const sptr<IRemoteObject> &observer, const BundleInfo &info, 752 const std::string &processName, const int userId); 753 754 void HandleStartSpecifiedAbilityTimeOut(const int64_t eventId); 755 756 void InitGlobalConfiguration(); 757 758 void GetRunningProcesses(const std::shared_ptr<AppRunningRecord> &appRecord, std::vector<RunningProcessInfo> &info); 759 void GetRunningProcess(const std::shared_ptr<AppRunningRecord> &appRecord, RunningProcessInfo &info); 760 761 int StartRenderProcessImpl(const std::shared_ptr<RenderRecord> &renderRecord, 762 const std::shared_ptr<AppRunningRecord> appRecord, pid_t &renderPid); 763 764 void OnRenderRemoteDied(const wptr<IRemoteObject> &remote); 765 766 void AddWatchParameter(); 767 768 bool VerifyAPL() const; 769 770 void InitFocusListener(); 771 void RegisterFocusListener(); 772 773 static void PointerDeviceEventCallback(const char *key, const char *value, void *context); 774 775 int VerifyProcessPermission(const std::string &bundleName) const; 776 777 private: 778 /** 779 * ClearUpApplicationData, clear the application data. 780 * 781 * @param bundleName, bundle name in Application record. 782 * @param uid, app uid in Application record. 783 * @param pid, app pid in Application record. 784 * @param userId, userId. 785 * 786 * @return 787 */ 788 void ClearUpApplicationDataByUserId(const std::string &bundleName, 789 int32_t callerUid, pid_t callerPid, const int userId); 790 791 uint32_t BuildStartFlags(const AAFwk::Want &want, const AbilityInfo &abilityInfo); 792 793 bool CheckGetRunningInfoPermission() const; 794 795 int32_t KillApplicationByBundleName(const std::string &bundleName); 796 797 private: 798 /** 799 * Notify application status. 800 * 801 * @param bundleName Indicates the name of the bundle. 802 * @param bundleName Indicates the name of the bundle. 803 * @param eventData Indicates the event defined by CommonEventSupport 804 * 805 * @return 806 */ 807 void NotifyAppStatusByCallerUid(const std::string &bundleName, const int32_t userId, const int32_t callerUid, 808 const std::string &eventData); 809 void KillApplicationByRecord(const std::shared_ptr<AppRunningRecord> &appRecord); 810 void SendHiSysEvent(const int32_t innerEventId, const int64_t eventId); 811 int FinishUserTestLocked( 812 const std::string &msg, const int64_t &resultCode, const std::shared_ptr<AppRunningRecord> &appRecord); 813 const std::string TASK_ON_CALLBACK_DIED = "OnCallbackDiedTask"; 814 std::vector<const sptr<IAppStateCallback>> appStateCallbacks_; 815 std::shared_ptr<AppProcessManager> appProcessManager_; 816 std::shared_ptr<RemoteClientManager> remoteClientManager_; 817 std::shared_ptr<AppRunningManager> appRunningManager_; 818 std::shared_ptr<AMSEventHandler> eventHandler_; 819 std::shared_ptr<Configuration> configuration_; 820 std::mutex userTestLock_; 821 sptr<IStartSpecifiedAbilityResponse> startSpecifiedAbilityResponse_; 822 std::recursive_mutex configurationObserverLock_; 823 std::vector<sptr<IConfigurationObserver>> configurationObservers_; 824 sptr<WindowFocusChangedListener> focusListener_; 825 std::vector<std::shared_ptr<AppRunningRecord>> restartResedentTaskList_; 826 int32_t currentUserId_ = 0; 827 }; 828 } // namespace AppExecFwk 829 } // namespace OHOS 830 #endif // OHOS_ABILITY_RUNTIME_APP_MGR_SERVICE_INNER_H 831