1 /* 2 * Copyright (c) 2021-2025 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 <mutex> 22 #include <regex> 23 #include <unordered_map> 24 #include <unordered_set> 25 #include <vector> 26 27 #include "ability_debug_response_interface.h" 28 #include "ability_foreground_state_observer_interface.h" 29 #include "ability_info.h" 30 #include "advanced_security_mode_manager.h" 31 #include "app_death_recipient.h" 32 #include "app_debug_listener_interface.h" 33 #include "app_debug_manager.h" 34 #include "app_foreground_state_observer_interface.h" 35 #include "app_malloc_info.h" 36 #include "app_mgr_constants.h" 37 #include "app_mgr_event.h" 38 #include "app_preloader.h" 39 #include "app_record_id.h" 40 #include "app_running_manager.h" 41 #include "app_running_record.h" 42 #include "app_running_status_listener_interface.h" 43 #include "app_running_status_module.h" 44 #include "app_scheduler_interface.h" 45 #include "app_spawn_client.h" 46 #include "appexecfwk_errors.h" 47 #include "bundle_info.h" 48 #include "bundle_mgr_helper.h" 49 #ifdef SUPPORT_CHILD_PROCESS 50 #include "child_process_info.h" 51 #include "child_process_request.h" 52 #endif // SUPPORT_CHILD_PROCESS 53 #include "cpp/mutex.h" 54 #include "event_report.h" 55 #include "fault_data.h" 56 #include "fd_guard.h" 57 #include "hisysevent.h" 58 #include "iapp_state_callback.h" 59 #include "iapplication_state_observer.h" 60 #include "iconfiguration_observer.h" 61 #include "iremote_object.h" 62 #include "irender_state_observer.h" 63 #include "istart_specified_ability_response.h" 64 #include "kia_interceptor_interface.h" 65 #include "kill_process_config.h" 66 #include "killed_process_info.h" 67 #include "process_memory_state.h" 68 #include "process_util.h" 69 #include "record_query_result.h" 70 #include "refbase.h" 71 #include "remote_client_manager.h" 72 #include "render_process_info.h" 73 #include "running_process_info.h" 74 #include "shared/base_shared_bundle_info.h" 75 #include "task_handler_wrap.h" 76 #include "want.h" 77 #include "app_jsheap_mem_info.h" 78 #include "running_multi_info.h" 79 #include "multi_user_config_mgr.h" 80 #include "user_callback.h" 81 82 namespace OHOS { 83 namespace AbilityRuntime { 84 struct LoadParam; 85 } 86 namespace Rosen { 87 class WindowVisibilityInfo; 88 class WindowPidVisibilityInfo; 89 class FocusChangeInfo; 90 } 91 namespace AppExecFwk { 92 using OHOS::AAFwk::Want; 93 using AAFwk::FdGuard; 94 class WindowFocusChangedListener; 95 class WindowVisibilityChangedListener; 96 class WindowPidVisibilityChangedListener; 97 using LoadAbilityTaskFunc = std::function<void()>; 98 constexpr int32_t BASE_USER_RANGE = 200000; 99 100 class AppMgrServiceInner : public std::enable_shared_from_this<AppMgrServiceInner> { 101 public: 102 struct ConfigurationObserverWithUserId { 103 sptr<IConfigurationObserver> observer; 104 int32_t userId = -1; 105 }; 106 struct AppStateCallbackWithUserId { 107 sptr<IAppStateCallback> callback; 108 int32_t userId = -1; 109 }; 110 111 AppMgrServiceInner(); 112 virtual ~AppMgrServiceInner(); 113 114 /** 115 * Initialize the object. 116 */ 117 void Init(); 118 /** 119 * LoadAbility, load the ability that needed to be started. 120 * 121 * @param token, the unique identification to start the ability. 122 * @param preToken, the unique identification to call the ability. 123 * @param abilityInfo, the ability information. 124 * @param appInfo, the app information. 125 * @param want the ability want. 126 * 127 * @return 128 */ 129 virtual void LoadAbility(std::shared_ptr<AbilityInfo> abilityInfo, std::shared_ptr<ApplicationInfo> appInfo, 130 std::shared_ptr<AAFwk::Want> want, std::shared_ptr<AbilityRuntime::LoadParam> loadParam); 131 132 /** 133 * TerminateAbility, terminate the token ability. 134 * 135 * @param token, he unique identification to terminate the ability. 136 * @param clearMissionFlag, indicates whether terminate the ability when clearMission. 137 * @return 138 */ 139 virtual void TerminateAbility(const sptr<IRemoteObject> &token, bool clearMissionFlag); 140 141 /** 142 * UpdateAbilityState, update the ability status. 143 * 144 * @param token, the unique identification to update the ability. 145 * @param state, ability status that needs to be updated. 146 * 147 * @return 148 */ 149 virtual void UpdateAbilityState(const sptr<IRemoteObject> &token, const AbilityState state); 150 151 /** 152 * UpdateExtensionState, call UpdateExtensionState() through the proxy object, update the extension status. 153 * 154 * @param token, the unique identification to update the extension. 155 * @param state, extension status that needs to be updated. 156 */ 157 virtual void UpdateExtensionState(const sptr<IRemoteObject> &token, const ExtensionState state); 158 159 /** 160 * StateChangedNotifyObserver, Call ability state change. 161 * 162 * @param ability, the ability info. 163 * @param state, the ability state. 164 * 165 * @return 166 */ 167 void StateChangedNotifyObserver( 168 const AbilityStateData abilityStateData, bool isAbility, bool isFromWindowFocusChanged); 169 170 /** 171 * RegisterAppStateCallback, register the callback. 172 * 173 * @param callback, Ams register the callback. 174 * 175 * @return 176 */ 177 virtual void RegisterAppStateCallback(const sptr<IAppStateCallback> &callback); 178 void RemoveDeadAppStateCallback(const wptr<IRemoteObject> &remote); 179 180 /** 181 * KillProcessByAbilityToken, kill the process by ability token. 182 * 183 * @param token, the unique identification to the ability. 184 * @return 185 */ 186 virtual void KillProcessByAbilityToken(const sptr<IRemoteObject> &token); 187 188 /** 189 * KillProcessesByUserId, kill the processes by userId. 190 * Send appSpawn uninstall debug hap message. 191 * 192 * @param userId, the user id. 193 * @param isNeedSendAppSpawnMsg, true send appSpawn message otherwise not send. 194 * @return 195 */ 196 virtual void KillProcessesByUserId(int32_t userId, bool isNeedSendAppSpawnMsg = false, 197 sptr<AAFwk::IUserCallback> callback = nullptr); 198 199 /** 200 * KillProcessesByPids, only in process call is allowed, 201 * kill the processes by pid list given. 202 * 203 * @param pids, the pid list of processes are going to be killed. 204 * @param reason, the reason to kill the processes. 205 * @return 206 */ 207 virtual void KillProcessesByPids(const std::vector<int32_t> &pids, 208 const std::string &reason = "KillProcessesByPids"); 209 210 /** 211 * KillProcessesInBatch, kill processes in batch; 212 * the killed bundle won't be started by the watcher. 213 * 214 * @param pids, the pid list of processes are going to be killed. 215 * @return ERR_OK, return back success, others fail. 216 */ 217 virtual int32_t KillProcessesInBatch(const std::vector<int32_t> &pids); 218 219 /** 220 * Set child and parent relationship 221 * @param token child process 222 * @param callerToken parent process 223 */ 224 virtual void AttachPidToParent(const sptr<IRemoteObject> &token, const sptr<IRemoteObject> &callerToken); 225 226 /** 227 * AttachApplication, get all the information needed to start the Application 228 * (data related to the Application ). 229 * 230 * @param appScheduler, information needed to start the Application. 231 * 232 * @return 233 */ 234 virtual void AttachApplication(const pid_t pid, const sptr<IAppScheduler> &appScheduler); 235 236 /** 237 * Preload application. 238 * 239 * @param bundleName The bundle name of the application to preload. 240 * @param userId Indicates the user identification. 241 * @param preloadMode Preload application mode. 242 * @param appIndex The index of application clone. 243 * @return Returns ERR_OK on success, others on failure. 244 */ 245 virtual int32_t PreloadApplication(const std::string &bundleName, int32_t userId, 246 AppExecFwk::PreloadMode preloadMode, int32_t appIndex); 247 248 /** 249 * ApplicationForegrounded, set the application to Foreground State. 250 * 251 * @param recordId, a unique record that identifies this Application from others. 252 * 253 * @return 254 */ 255 virtual void ApplicationForegrounded(const int32_t recordId); 256 257 /** 258 * ApplicationBackgrounded, set the application to Backgrounded State. 259 * 260 * @param recordId, a unique record that identifies this Application from others. 261 * 262 * @return 263 */ 264 virtual void ApplicationBackgrounded(const int32_t recordId); 265 266 /** 267 * ApplicationTerminated, terminate the application. 268 * 269 * @param recordId, a unique record that identifies this Application from others. 270 * 271 * @return 272 */ 273 virtual void ApplicationTerminated(const int32_t recordId); 274 275 /** 276 * AbilityTerminated, terminate the ability. 277 * 278 * @param token, the unique identification to terminated the ability. 279 * 280 * @return 281 */ 282 virtual void AbilityTerminated(const sptr<IRemoteObject> &token); 283 284 /** 285 * UpdateApplicationInfoInstalled, update the application info after new module installed. 286 * 287 * @param bundleName, bundle name in Application record. 288 * @param uid, uid. 289 * @return ERR_OK, return back success, others fail. 290 */ 291 virtual int32_t UpdateApplicationInfoInstalled(const std::string &bundleName, const int uid, 292 const std::string &moduleName); 293 294 /** 295 * KillApplication, kill the application. 296 * 297 * @param bundleName, bundle name in Application record. 298 * 299 * @return ERR_OK, return back success, others fail. 300 */ 301 virtual int32_t KillApplication(const std::string &bundleName, bool clearPageStack = false, int32_t appIndex = 0); 302 303 /** 304 * ForceKillApplication, force kill the application. 305 * 306 * @param bundleName, bundle name in Application record. 307 * @param userId, userId. 308 * @param appIndex, appIndex. 309 * @return ERR_OK, return back success, others fail. 310 */ 311 virtual int32_t ForceKillApplication(const std::string &bundleName, const int userId = -1, 312 const int appIndex = 0); 313 314 /** 315 * KillProcessesByAccessTokenId. 316 * 317 * @param accessTokenId, accessTokenId. 318 * @return ERR_OK, return back success, others fail. 319 */ 320 virtual int32_t KillProcessesByAccessTokenId(const uint32_t accessTokenId); 321 322 /** 323 * KillApplicationByUid, call KillApplicationByUid() through proxy object, kill the application. 324 * 325 * @param bundleName, bundle name in Application record. 326 * @param uid, uid. 327 * @param reason, caller function name. 328 * @return ERR_OK, return back success, others fail. 329 */ 330 virtual int32_t KillApplicationByUid(const std::string &bundleName, const int uid, 331 const std::string& reason = "KillApplicationByUid"); 332 333 /** 334 * KillApplicationSelf, this allows app to terminate itself. 335 * 336 * @param clearPageStack, the flag indicates if ClearPageStack lifecycle should be scheduled. 337 * @return ERR_OK for success call, others for failure. 338 */ 339 virtual int32_t KillApplicationSelf(const bool clearPageStack = false, 340 const std::string& reason = "KillApplicationSelf"); 341 342 int32_t KillAppSelfWithInstanceKey(const std::string &instanceKey, bool clearPageStack, const std::string& reason); 343 344 /** 345 * KillApplicationByUserId, kill the application by user ID. 346 * 347 * @param bundleName, bundle name in Application record. 348 * @param appCloneIndex the app clone id. 349 * @param userId, user ID. 350 * @param reason, caller function name. 351 * 352 * @return ERR_OK, return back success, others fail. 353 */ 354 virtual int32_t KillApplicationByUserId(const std::string &bundleName, int32_t appCloneIndex, int userId, 355 const bool clearPageStack = false, const std::string& reason = "KillApplicationByUserId"); 356 357 /** 358 * update process rss and pss value. 359 * 360 * @param procMemStates, the memory states of all apps. 361 * @return ERR_OK, return back success, others fail. 362 */ 363 virtual int32_t UpdateProcessMemoryState(const std::vector<ProcessMemoryState> &procMemState); 364 365 /** 366 * ClearUpApplicationData, clear the application data. 367 * 368 * @param bundleName, bundle name in Application record. 369 * @param callerUid, app uid in Application record. 370 * @param callerPid, app pid in Application record. 371 * @param appCloneIndex the app clone id. 372 * @param userId the user id 373 * @return ERR_OK, return back success, others fail. 374 */ 375 virtual int32_t ClearUpApplicationData(const std::string &bundleName, 376 int32_t callerUid, pid_t callerPid, int32_t appCloneIndex, int32_t userId = -1); 377 378 /** 379 * ClearUpApplicationDataBySelf, clear the application data. 380 * 381 * @param callerUid, app uid in Application record. 382 * @param callerPid, app pid in Application record. 383 * @param userId, user ID. 384 * 385 * @return ERR_OK, return back success, others fail. 386 */ 387 virtual int32_t ClearUpApplicationDataBySelf(int32_t callerUid, pid_t callerPid, int32_t userId = -1); 388 389 /** 390 * GetAllRunningProcesses, Obtains information about application processes that are running on the device. 391 * 392 * @param info, app name in Application record. 393 * 394 * @return ERR_OK ,return back success,others fail. 395 */ 396 virtual int32_t GetAllRunningProcesses(std::vector<RunningProcessInfo> &info); 397 398 /** 399 * GetRunningMultiAppInfoByBundleName, call GetRunningMultiAppInfoByBundleName through proxy project. 400 * Obtains information about TwinApp that are running on the device. 401 * 402 * @param bundleName, input. 403 * @param info, output multiapp information. 404 * @return void. 405 */ 406 virtual int32_t GetRunningMultiAppInfoByBundleName(const std::string &bundleName, 407 RunningMultiAppInfo &info); 408 409 /** 410 * GetAllRunningInstanceKeysBySelf, call GetAllRunningInstanceKeysBySelf() through proxy project. 411 * Obtains running instance keys of multi-instance app that are running on the device. 412 * 413 * @param instanceKeys, output instance keys of the multi-instance app. 414 * @return ERR_OK ,return back success,others fail. 415 */ 416 virtual int32_t GetAllRunningInstanceKeysBySelf(std::vector<std::string> &instanceKeys); 417 418 /** 419 * GetAllRunningInstanceKeysByBundleName, call GetAllRunningInstanceKeysByBundleName() through proxy project. 420 * Obtains running instance keys of multi-instance app that are running on the device. 421 * 422 * @param bundlename, bundle name in Application record. 423 * @param instanceKeys, output instance keys of the multi-instance app. 424 * @param userId, user id. 425 * @return ERR_OK ,return back success,others fail. 426 */ 427 virtual int32_t GetAllRunningInstanceKeysByBundleName(const std::string &bundleName, 428 std::vector<std::string> &instanceKeys, int32_t userId = -1); 429 430 /** 431 * GetRunningProcessesByBundleType, Obtains information about application processes by bundle type. 432 * 433 * @param bundleType, the bundle type of the application process 434 * @param info, app name in Application record. 435 * 436 * @return ERR_OK ,return back success,others fail. 437 */ 438 virtual int32_t GetRunningProcessesByBundleType(BundleType bundleType, std::vector<RunningProcessInfo> &info); 439 440 /** 441 * GetProcessRunningInfosByUserId, Obtains information about application processes that are running on the device. 442 * 443 * @param info, app name in Application record. 444 * @param userId, userId. 445 * 446 * @return ERR_OK ,return back success,others fail. 447 */ 448 virtual int32_t GetProcessRunningInfosByUserId(std::vector<RunningProcessInfo> &info, int32_t userId); 449 450 /** 451 * GetProcessRunningInformation, Obtains information about current application process 452 * which is running on the device. 453 * @param info, app name in Application record. 454 * 455 * @return ERR_OK ,return back success,others fail. 456 */ 457 virtual int32_t GetProcessRunningInformation(RunningProcessInfo &info); 458 459 /** 460 * GetAllRenderProcesses, Obtains information about render processes that are running on the device. 461 * 462 * @param info, render process record. 463 * 464 * @return ERR_OK, return back success, others fail. 465 */ 466 virtual int32_t GetAllRenderProcesses(std::vector<RenderProcessInfo> &info); 467 468 #ifdef SUPPORT_CHILD_PROCESS 469 /** 470 * GetAllChildrenProcesses, call GetAllChildrenProcesses() through proxy project. 471 * Obtains information about children processes that are running on the device. 472 * 473 * @param info, child process info. 474 * @return ERR_OK, return back success, others fail. 475 */ 476 virtual int GetAllChildrenProcesses(std::vector<ChildProcessInfo> &info); 477 #endif // SUPPORT_CHILD_PROCESS 478 479 /** 480 * NotifyMemoryLevel, Notify applications background the current memory level. 481 * 482 * @param level, current memory level. 483 * 484 * @return ERR_OK ,return back success,others fail. 485 */ 486 virtual int32_t NotifyMemoryLevel(int32_t level); 487 488 /** 489 * NotifyProcMemoryLevel, Notify applications background the current memory level. 490 * 491 * @param procLevelMap , <pid_t, MemoryLevel>. 492 * 493 * @return ERR_OK ,return back success,others fail. 494 */ 495 virtual int32_t NotifyProcMemoryLevel(const std::map<pid_t, MemoryLevel> &procLevelMap); 496 497 /** 498 * DumpHeapMemory, get the application's memory info. 499 * Get the application's memory allocation info. 500 * 501 * @param pid, pid input. 502 * @param mallocInfo, dynamic storage information output. 503 * 504 * @return ERR_OK, return back success,others fail. 505 */ 506 virtual int32_t DumpHeapMemory(const int32_t pid, OHOS::AppExecFwk::MallocInfo &mallocInfo); 507 508 /** 509 * DumpJsHeapMemory, call DumpJsHeapMemory() through proxy project. 510 * triggerGC and dump the application's jsheap memory info. 511 * 512 * @param info, pid, tid, needGc, needSnapshot 513 * @return Returns ERR_OK on success, others on failure. 514 */ 515 virtual int32_t DumpJsHeapMemory(OHOS::AppExecFwk::JsHeapDumpInfo &info); 516 517 /** 518 * @brief Check whether the shared bundle is running. 519 * 520 * @param bundleName Shared bundle name. 521 * @param versionCode Shared bundle version code. 522 * @return Returns the shared bundle running result. The result is true if running, false otherwise. 523 */ 524 virtual bool IsSharedBundleRunning(const std::string &bundleName, uint32_t versionCode); 525 526 /** 527 * Check whether the bundle is running. 528 * 529 * @param bundleName Indicates the bundle name of the bundle. 530 * @param isRunning Obtain the running status of the application, the result is true if running, false otherwise. 531 * @return Return ERR_OK if success, others fail. 532 */ 533 int32_t IsApplicationRunning(const std::string &bundleName, bool &isRunning); 534 535 /** 536 * Check whether the bundle is running. 537 * 538 * @param bundleName Indicates the bundle name of the bundle. 539 * @param appCloneIndex the appindex of the bundle. 540 * @param isRunning Obtain the running status of the application, the result is true if running, false otherwise. 541 * @return Return ERR_OK if success, others fail. 542 */ 543 int32_t IsAppRunning(const std::string &bundleName, int32_t appCloneIndex, bool &isRunning); 544 545 /** 546 * Check whether the process of the application under the specified user exists. 547 * 548 * @param bundleName Indicates the bundle name of the bundle. 549 * @param userId the userId of the bundle. 550 * @param isRunning Obtain the running status of the application, the result is true if running, false otherwise. 551 * @return Return ERR_OK if success, others fail. 552 */ 553 virtual int32_t IsAppRunningByBundleNameAndUserId(const std::string &bundleName, int32_t userId, 554 bool &isRunning); 555 556 /** 557 * start native process for debugger. 558 * 559 * @param want param to start a process. 560 */ 561 int32_t StartNativeProcessForDebugger(const AAFwk::Want &want); 562 563 std::shared_ptr<AppRunningRecord> CreateAppRunningRecord( 564 std::shared_ptr<AbilityRuntime::LoadParam> loadParam, 565 std::shared_ptr<ApplicationInfo> appInfo, 566 std::shared_ptr<AbilityInfo> abilityInfo, 567 const std::string &processName, 568 const BundleInfo &bundleInfo, 569 const HapModuleInfo &hapModuleInfo, 570 std::shared_ptr<AAFwk::Want> want, 571 bool isKia = false); 572 573 /** 574 * OnStop, Application management service stopped. 575 * 576 * @return 577 */ 578 void OnStop(); 579 580 /** 581 * OpenAppSpawnConnection, Open connection with appspawn. 582 * 583 * @return ERR_OK ,return back success,others fail. 584 */ 585 virtual ErrCode OpenAppSpawnConnection(); 586 587 /** 588 * CloseAppSpawnConnection, Close connection with appspawn. 589 * 590 * @return 591 */ 592 virtual void CloseAppSpawnConnection() const; 593 594 /** 595 * QueryAppSpawnConnectionState, Query the connection status with appspawn. 596 * 597 * @return Returns the connection status with appspawn. 598 */ 599 virtual SpawnConnectionState QueryAppSpawnConnectionState() const; 600 601 /** 602 * SetAppSpawnClient, Setting the client to connect with appspawn. 603 * 604 * @param spawnClient, the client to connect with appspawn. 605 * 606 * @return 607 */ 608 void SetAppSpawnClient(std::shared_ptr<AppSpawnClient> spawnClient); 609 610 // Schedule launch application with specified |appRecord| 611 612 /** 613 * LaunchApplication, Notify application to launch application. 614 * 615 * @param appRecord, the application record. 616 * 617 * @return 618 */ 619 void LaunchApplication(const std::shared_ptr<AppRunningRecord> &appRecord); 620 621 /** 622 * LaunchApplicationExt, to solve the nbnc of method over 50. 623 * 624 * @param appRecord, the application record. 625 * 626 * @return 627 */ 628 void LaunchApplicationExt(const std::shared_ptr<AppRunningRecord> &appRecord); 629 630 /** 631 * Notice of AddAbilityStageInfo() 632 * 633 * @param recordId, the application record. 634 */ 635 virtual void AddAbilityStageDone(const int32_t recordId); 636 637 /** 638 * GetAppRunningRecordByPid, Get process record by application pid. 639 * 640 * @param pid, the application pid. 641 * 642 * @return process record. 643 */ 644 std::shared_ptr<AppRunningRecord> GetAppRunningRecordByPid(const pid_t pid) const; 645 646 /** 647 * GetAppRunningRecordByAbilityToken, Get process record by ability token. 648 * 649 * @param abilityToken, the ability token. 650 * 651 * @return process record. 652 */ 653 std::shared_ptr<AppRunningRecord> GetAppRunningRecordByAbilityToken(const sptr<IRemoteObject> &abilityToken) const; 654 655 /** 656 * GetTerminatingAppRunningRecord, Get process record by ability token. 657 * 658 * @param abilityToken, the ability token. 659 * 660 * @return process record. 661 */ 662 std::shared_ptr<AppRunningRecord> GetTerminatingAppRunningRecord(const sptr<IRemoteObject> &token) const; 663 664 /** 665 * GetAppRunningRecordByAppRecordId, Get process record by application id. 666 * 667 * @param recordId, the application id. 668 * 669 * @return process record. 670 */ 671 std::shared_ptr<AppRunningRecord> GetAppRunningRecordByAppRecordId(const int32_t recordId) const; 672 673 /** 674 * OnAbilityStateChanged, Call ability state change. 675 * 676 * @param ability, the ability info. 677 * @param state, the ability state. 678 * 679 * @return 680 */ 681 void OnAbilityStateChanged(const std::shared_ptr<AbilityRunningRecord> &ability, const AbilityState state); 682 683 /** 684 * OnRemoteDied, Equipment death notification. 685 * 686 * @param remote, Death client. 687 * @param isRenderProcess is render process died. 688 * @param isChildProcess is child process died. 689 * @return 690 */ 691 void OnRemoteDied(const wptr<IRemoteObject> &remote, bool isRenderProcess = false, bool isChildProcess = false); 692 693 void HandleTimeOut(const AAFwk::EventWrap &event); 694 695 void CacheExitInfo(const std::shared_ptr<AppRunningRecord> &appRecord); 696 DecreaseWillKillPidsNum()697 void DecreaseWillKillPidsNum() 698 { 699 willKillPidsNum_ -= 1; 700 } 701 SetTaskHandler(std::shared_ptr<AAFwk::TaskHandlerWrap> taskHandler)702 void SetTaskHandler(std::shared_ptr<AAFwk::TaskHandlerWrap> taskHandler) 703 { 704 taskHandler_ = taskHandler; 705 } 706 SetEventHandler(const std::shared_ptr<AMSEventHandler> & eventHandler)707 void SetEventHandler(const std::shared_ptr<AMSEventHandler> &eventHandler) 708 { 709 eventHandler_ = eventHandler; 710 } 711 712 /** 713 * HandleAbilityAttachTimeOut, called by ability manager service when an ability is loaded timeout. 714 * 715 * @param token indicates the token of the ability which is timeout. 716 */ 717 void HandleAbilityAttachTimeOut(const sptr<IRemoteObject> &token); 718 719 /** 720 * PrepareTerminate, called before terminating one ability by ability manager service to notify application. 721 * 722 * @param token indicates the token of the ability to be terminated. 723 * @param clearMissionFlag indicates whether it is caused by cleaning mission. 724 */ 725 void PrepareTerminate(const sptr<IRemoteObject> &token, bool clearMissionFlag = false); 726 727 void OnAppStateChanged(const std::shared_ptr<AppRunningRecord> &appRecord, const ApplicationState state, 728 bool needNotifyApp, bool isFromWindowFocusChanged); 729 730 void OnAppStarted(const std::shared_ptr<AppRunningRecord> &appRecord); 731 732 void OnAppStopped(const std::shared_ptr<AppRunningRecord> &appRecord); 733 734 /** 735 * GetRunningProcessInfoByToken, get process info for one ability. 736 * 737 * @param token indicates the token of the ability requested. 738 * @param info output of the information. 739 */ 740 void GetRunningProcessInfoByToken(const sptr<IRemoteObject> &token, AppExecFwk::RunningProcessInfo &info); 741 742 int32_t GetRunningProcessInfoByPid(const pid_t pid, OHOS::AppExecFwk::RunningProcessInfo &info) const; 743 744 int32_t GetRunningProcessInfoByChildProcessPid(const pid_t childPid, 745 OHOS::AppExecFwk::RunningProcessInfo &info) const; 746 747 /** 748 * Set AbilityForegroundingFlag of an app-record to true. 749 * 750 * @param pid, pid. 751 * 752 */ 753 void SetAbilityForegroundingFlagToAppRecord(const pid_t pid) const; 754 755 /** 756 * UpdateConfiguration, ANotify application update system environment changes. 757 * 758 * @param config, System environment change parameters. 759 * @return Returns ERR_OK on success, others on failure. 760 */ 761 int32_t UpdateConfiguration(const Configuration &config, const int32_t userId = -1); 762 763 int32_t UpdateConfigurationByBundleName(const Configuration &config, const std::string &name, int32_t appIndex); 764 765 std::shared_ptr<AppExecFwk::Configuration> GetConfiguration(); 766 767 int32_t RegisterConfigurationObserver(const sptr<IConfigurationObserver>& observer); 768 769 int32_t UnregisterConfigurationObserver(const sptr<IConfigurationObserver>& observer); 770 771 /** 772 * Start empty process 773 */ 774 void LoadResidentProcess(const std::vector<BundleInfo> &infos); 775 776 void StartResidentProcess(const std::vector<BundleInfo> &infos, int restartCount, bool isEmptyKeepAliveApp); 777 778 bool CheckRemoteClient(); 779 780 /** 781 * Register application or process state observer. 782 * @param observer, ability token. 783 * @return Returns ERR_OK on success, others on failure. 784 */ 785 int32_t RegisterApplicationStateObserver(const sptr<IApplicationStateObserver> &observer, 786 const std::vector<std::string> &bundleNameList = {}); 787 788 /** 789 * Unregister application or process state observer. 790 * @param observer, ability token. 791 * @return Returns ERR_OK on success, others on failure. 792 */ 793 int32_t UnregisterApplicationStateObserver(const sptr<IApplicationStateObserver> &observer); 794 795 /** 796 * Register application or process state observer. 797 * @param observer, Is ability foreground state observer 798 * @return Returns ERR_OK on success, others on failure. 799 */ 800 int32_t RegisterAbilityForegroundStateObserver(const sptr<IAbilityForegroundStateObserver> &observer); 801 802 /** 803 * Unregister application or process state observer. 804 * @param observer, Is ability foreground state observer 805 * @return Returns ERR_OK on success, others on failure. 806 */ 807 int32_t UnregisterAbilityForegroundStateObserver(const sptr<IAbilityForegroundStateObserver> &observer); 808 809 /** 810 * Get Foreground Applications. 811 * 812 * @return Foreground Applications. 813 */ 814 int32_t GetForegroundApplications(std::vector<AppStateData> &list); 815 816 /** 817 * Start user test process. 818 * @param want, want object. 819 * @param observer, test observer remote object. 820 * @param bundleInfo, bundle info. 821 * @param userId the user id. 822 * @return Returns ERR_OK on success, others on failure. 823 */ 824 int StartUserTestProcess(const AAFwk::Want &want, const sptr<IRemoteObject> &observer, 825 const AppExecFwk::BundleInfo &bundleInfo, int32_t userId); 826 827 /** 828 * @brief Finish user test. 829 * @param msg user test message. 830 * @param resultCode user test result Code. 831 * @param bundleName user test bundleName. 832 * @param pid the user test process id. 833 * 834 * @return Returns ERR_OK on success, others on failure. 835 */ 836 int FinishUserTest( 837 const std::string &msg, const int64_t &resultCode, const std::string &bundleName, const pid_t &pid); 838 839 /** 840 * Start specified ability. 841 * 842 * @param want Want contains information of the ability to start. 843 * @param abilityInfo Ability information. 844 * @param requestId request id to callback 845 */ 846 void StartSpecifiedAbility(const AAFwk::Want &want, const AppExecFwk::AbilityInfo &abilityInfo, 847 int32_t requestId = 0); 848 849 /** 850 * Start specified process. 851 * 852 * @param want Want contains information wish to start. 853 * @param abilityInfo Ability information. 854 * @param requestId for callback 855 */ 856 void StartSpecifiedProcess(const AAFwk::Want &want, const AppExecFwk::AbilityInfo &abilityInfo, 857 int32_t requestId = 0); 858 859 void RegisterStartSpecifiedAbilityResponse(const sptr<IStartSpecifiedAbilityResponse> &response); 860 861 /** 862 * @brief called when the abilityStage's onAcceptWant lifecycle completed. 863 * @param recordId record id of the ability. 864 * @param want want has been accepted. 865 * @param flag flag get from OnAcceptWant. 866 */ 867 void ScheduleAcceptWantDone(const int32_t recordId, const AAFwk::Want &want, const std::string &flag); 868 869 void SchedulePrepareTerminate(const pid_t pid, const std::string &moduleName); 870 871 void ScheduleNewProcessRequestDone(const int32_t recordId, const AAFwk::Want &want, const std::string &flag); 872 873 /** 874 * Get the token of ability records by process ID. 875 * 876 * @param pid The process id. 877 * @param tokens The token of ability records. 878 * @return Returns true on success, others on failure. 879 */ 880 int GetAbilityRecordsByProcessID(const int pid, std::vector<sptr<IRemoteObject>> &tokens); 881 882 virtual int32_t PreStartNWebSpawnProcess(const pid_t hostPid); 883 884 virtual int32_t StartRenderProcess(const pid_t hostPid, 885 const std::string &renderParam, 886 FdGuard &&ipcFd, FdGuard &&sharedFd, 887 FdGuard &&crashFd, pid_t &renderPid, bool isGPU = false); 888 889 virtual void AttachRenderProcess(const pid_t pid, const sptr<IRenderScheduler> &scheduler); 890 891 virtual int GetRenderProcessTerminationStatus(pid_t renderPid, int &status); 892 893 int VerifyKillProcessPermission(const sptr<IRemoteObject> &token) const; 894 895 int VerifyAccountPermission(const std::string &permissionName, const int userId) const; 896 897 int VerifyRequestPermission() const; 898 899 void ClearAppRunningData(const std::shared_ptr<AppRunningRecord> &appRecord); 900 901 void TerminateApplication(const std::shared_ptr<AppRunningRecord> &appRecord); 902 903 int GetApplicationInfoByProcessID(const int pid, AppExecFwk::ApplicationInfo &application, bool &debug); 904 905 /** 906 * Record process exit reason to appRunningRecord 907 * @param pid pid 908 * @param reason reason enum 909 * @param exitMsg exitMsg 910 * @return Returns ERR_OK on success, others on failure. 911 */ 912 int32_t NotifyAppMgrRecordExitReason(int32_t pid, int32_t reason, const std::string &exitMsg); 913 914 /** 915 * Notify application status. 916 * 917 * @param bundleName Indicates the name of the bundle. 918 * @param eventData Indicates the event defined by CommonEventSupport 919 * 920 * @return 921 */ 922 void NotifyAppStatus(const std::string &bundleName, int32_t appIndex, const std::string &eventData); 923 924 int32_t KillProcessByPid(const pid_t pid, const std::string& reason = "foundation"); 925 926 /** 927 * @brief Get the running state of application by bundle name. 928 * 929 * @param bundleName Bundle name 930 * @return Returns true if process is running, false if process isn't running. 931 */ 932 bool GetAppRunningStateByBundleName(const std::string &bundleName); 933 934 /** 935 * @brief Notify application load patch. 936 * 937 * @param bundleName Bundle name 938 * @param callback called when LoadPatch finished. 939 * @return Returns ERR_OK on success, error code on failure. 940 */ 941 int32_t NotifyLoadRepairPatch(const std::string &bundleName, const sptr<IQuickFixCallback> &callback); 942 943 int32_t NotifyHotReloadPage(const std::string &bundleName, const sptr<IQuickFixCallback> &callback); 944 945 int32_t NotifyUnLoadRepairPatch(const std::string &bundleName, const sptr<IQuickFixCallback> &callback); 946 #ifdef SUPPORT_SCREEN 947 void HandleFocused(const sptr<OHOS::Rosen::FocusChangeInfo> &focusChangeInfo); 948 void HandleUnfocused(const sptr<OHOS::Rosen::FocusChangeInfo> &focusChangeInfo); 949 950 /** 951 * Handle window visibility changed. 952 */ 953 void HandleWindowVisibilityChanged( 954 const std::vector<sptr<OHOS::Rosen::WindowVisibilityInfo>> &windowVisibilityInfos); 955 956 /** 957 * Handle window pid visibility changed. 958 */ 959 void HandleWindowPidVisibilityChanged(const sptr<OHOS::Rosen::WindowPidVisibilityInfo>& windowPidVisibilityInfo); 960 #endif //SUPPORT_SCREEN 961 /** 962 * Set the current userId, only used by abilityMgr. 963 * 964 * @param userId the user id. 965 * 966 * @return 967 */ 968 void SetCurrentUserId(const int32_t userId); 969 970 /** 971 * Set enable start process flag by userId 972 * @param userId the user id. 973 * @param enableStartProcess enable start process. 974 * @return 975 */ 976 void SetEnableStartProcessFlagByUserId(int32_t userId, bool enableStartProcess); 977 978 #ifdef BGTASKMGR_CONTINUOUS_TASK_ENABLE 979 int32_t SetContinuousTaskProcess(int32_t pid, bool isContinuousTask); 980 #endif 981 982 /** 983 * Get bundleName by pid. 984 * 985 * @param pid process id. 986 * @param bundleName Output parameters, return bundleName. 987 * @param uid Output parameters, return userId. 988 * @return Returns ERR_OK on success, others on failure. 989 */ 990 int32_t GetBundleNameByPid(const int32_t pid, std::string &bundleName, int32_t &uid); 991 992 /** 993 * Notify Fault Data 994 * 995 * @param faultData the fault data. 996 * @return Returns ERR_OK on success, others on failure. 997 */ 998 int32_t NotifyAppFault(const FaultData &faultData); 999 1000 /** 1001 * Transformed Notify Fault Data 1002 * 1003 * @param faultData Transformed the fault data. 1004 * @return Returns ERR_OK on success, others on failure. 1005 */ 1006 1007 int32_t TransformedNotifyAppFault(const AppFaultDataBySA &faultData); 1008 1009 /** 1010 * Notify Fault Data By SA 1011 * 1012 * @param faultData the fault data notified by SA. 1013 * @return Returns ERR_OK on success, others on failure. 1014 */ 1015 int32_t NotifyAppFaultBySA(const AppFaultDataBySA &faultData); 1016 1017 /** 1018 * Set Appfreeze Detect Filter 1019 * 1020 * @param pid the process pid. 1021 * @return Returns true on success, others on failure. 1022 */ 1023 bool SetAppFreezeFilter(int32_t pid); 1024 1025 /** 1026 * get memorySize by pid. 1027 * 1028 * @param pid process id. 1029 * @param memorySize Output parameters, return memorySize in KB. 1030 * @return Returns ERR_OK on success, others on failure. 1031 */ 1032 virtual int32_t GetProcessMemoryByPid(const int32_t pid, int32_t &memorySize); 1033 1034 /** 1035 * get application processes information list by bundleName. 1036 * 1037 * @param bundleName Bundle name. 1038 * @param userId user Id in Application record. 1039 * @param info Output parameters, return running process info list. 1040 * @return Returns ERR_OK on success, others on failure. 1041 */ 1042 virtual int32_t GetRunningProcessInformation( 1043 const std::string &bundleName, int32_t userId, std::vector<RunningProcessInfo> &info); 1044 1045 /** 1046 * init focusListener. 1047 * 1048 * @return 1049 */ 1050 void InitFocusListener(); 1051 1052 /** 1053 * free focusListener. 1054 * 1055 * @return 1056 */ 1057 void FreeFocusListener(); 1058 1059 /** 1060 * Init window visibility changed listener. 1061 */ 1062 void InitWindowVisibilityChangedListener(); 1063 1064 /** 1065 * Free window visibility changed listener. 1066 */ 1067 void FreeWindowVisibilityChangedListener(); 1068 1069 /** 1070 * Init window pid visibility changed listener. 1071 */ 1072 void InitWindowPidVisibilityChangedListener(); 1073 1074 /** 1075 * Free window pid visibility changed listener. 1076 */ 1077 void FreeWindowPidVisibilityChangedListener(); 1078 1079 /* 1080 * @brief Notify NativeEngine GC of status change. 1081 * 1082 * @param state GC state 1083 * @param pid pid 1084 * 1085 * @return Is the status change completed. 1086 */ 1087 int32_t ChangeAppGcState(pid_t pid, int32_t state); 1088 1089 /** 1090 * @brief Register app debug listener. 1091 * @param listener App debug listener. 1092 * @return Returns ERR_OK on success, others on failure. 1093 */ 1094 int32_t RegisterAppDebugListener(const sptr<IAppDebugListener> &listener); 1095 1096 /** 1097 * @brief Unregister app debug listener. 1098 * @param listener App debug listener. 1099 * @return Returns ERR_OK on success, others on failure. 1100 */ 1101 int32_t UnregisterAppDebugListener(const sptr<IAppDebugListener> &listener); 1102 1103 /** 1104 * @brief Attach app debug. 1105 * @param bundleName The application bundle name. 1106 * @return Returns ERR_OK on success, others on failure. 1107 */ 1108 int32_t AttachAppDebug(const std::string &bundleName, bool isDebugFromLocal); 1109 1110 /** 1111 * @brief Detach app debug. 1112 * @param bundleName The application bundle name. 1113 * @return Returns ERR_OK on success, others on failure. 1114 */ 1115 int32_t DetachAppDebug(const std::string &bundleName); 1116 1117 /** 1118 * @brief Set app waiting debug mode. 1119 * @param bundleName The application bundle name. 1120 * @param isPersist The persist flag. 1121 * @return Returns ERR_OK on success, others on failure. 1122 */ 1123 int32_t SetAppWaitingDebug(const std::string &bundleName, bool isPersist); 1124 1125 /** 1126 * @brief Cancel app waiting debug mode. 1127 * @return Returns ERR_OK on success, others on failure. 1128 */ 1129 int32_t CancelAppWaitingDebug(); 1130 1131 /** 1132 * @brief Get waiting debug mode application. 1133 * @param bundleNameList The application bundle name list. 1134 * @return Returns ERR_OK on success, others on failure. 1135 */ 1136 int32_t GetWaitingDebugApp(std::vector<std::string> &bundleNameList); 1137 1138 /** 1139 * @brief Determine whether it is a waiting debug application based on the bundle name. 1140 * @return Returns true if it is a waiting debug application, otherwise it returns false. 1141 */ 1142 bool IsWaitingDebugApp(const std::string &bundleName); 1143 1144 /** 1145 * @brief Clear non persist waiting debug flag. 1146 */ 1147 void ClearNonPersistWaitingDebugFlag(); 1148 1149 /** 1150 * @brief Registering ability debug mode response. 1151 * @param response Response for ability debug object. 1152 * @return Returns ERR_OK on success, others on failure. 1153 */ 1154 int32_t RegisterAbilityDebugResponse(const sptr<IAbilityDebugResponse> &response); 1155 1156 /** 1157 * @brief Determine whether it is an attachment debug application based on the bundle name. 1158 * @param bundleName The application bundle name. 1159 * @return Returns true if it is an attach debug application, otherwise it returns false. 1160 */ 1161 bool IsAttachDebug(const std::string &bundleName); 1162 1163 /** 1164 * @brief Notify AbilityManagerService the page show. 1165 * @param token Ability identify. 1166 * @param pageStateData The data of ability's page state. 1167 * @return Returns ERR_OK on success, others on failure. 1168 */ 1169 virtual int32_t NotifyPageShow(const sptr<IRemoteObject> &token, const PageStateData &pageStateData); 1170 1171 /** 1172 * @brief Notify AbilityManagerService the page hide. 1173 * @param token Ability identify. 1174 * @param pageStateData The data of ability's page state. 1175 * @return Returns ERR_OK on success, others on failure. 1176 */ 1177 virtual int32_t NotifyPageHide(const sptr<IRemoteObject> &token, const PageStateData &pageStateData); 1178 1179 /** 1180 * Register appRunning status listener. 1181 * 1182 * @param listener Running status listener. 1183 * @return Returns ERR_OK on success, others on failure. 1184 */ 1185 int32_t RegisterAppRunningStatusListener(const sptr<IRemoteObject> &listener); 1186 1187 /** 1188 * Unregister appRunning status listener. 1189 * 1190 * @param listener Running status listener. 1191 * @return Returns ERR_OK on success, others on failure. 1192 */ 1193 int32_t UnregisterAppRunningStatusListener(const sptr<IRemoteObject> &listener); 1194 1195 /** 1196 * Register application foreground state observer. 1197 * @param observer Is app foreground statue observer 1198 * @return Returns ERR_OK on success, others on failure. 1199 */ 1200 int32_t RegisterAppForegroundStateObserver(const sptr<IAppForegroundStateObserver> &observer); 1201 1202 /** 1203 * Unregister application foreground state observer. 1204 * @param observer Is app foreground statue observer 1205 * @return Returns ERR_OK on success, others on failure. 1206 */ 1207 int32_t UnregisterAppForegroundStateObserver(const sptr<IAppForegroundStateObserver> &observer); 1208 1209 #ifdef SUPPORT_CHILD_PROCESS 1210 /** 1211 * Start child process, called by ChildProcessManager. 1212 * 1213 * @param callingPid Calling process pid. 1214 * @param childPid Created child process pid. 1215 * @param request Child process start request params. 1216 * @return Returns ERR_OK on success, others on failure. 1217 */ 1218 virtual int32_t StartChildProcess(const pid_t callingPid, pid_t &childPid, const ChildProcessRequest &request); 1219 1220 /** 1221 * Get child process record for self. 1222 * 1223 * @return child process record. 1224 */ 1225 virtual int32_t GetChildProcessInfoForSelf(ChildProcessInfo &info); 1226 1227 /** 1228 * Attach child process scheduler to app manager service. 1229 * 1230 * @param pid the child process pid to exit. 1231 * @param childScheduler scheduler of child process. 1232 */ 1233 virtual void AttachChildProcess(const pid_t pid, const sptr<IChildScheduler> &childScheduler); 1234 1235 /** 1236 * Exit child process safely by child process pid. 1237 * 1238 * @param pid child process pid. 1239 */ 1240 virtual void ExitChildProcessSafelyByChildPid(const pid_t pid); 1241 1242 /** 1243 * Start native child process, callde by ChildProcessManager. 1244 * @param hostPid Host process pid. 1245 * @param childProcessCount current started child process count 1246 * @param libName lib file name to be load in child process 1247 * @param callback callback for notify start result 1248 * @return Returns ERR_OK on success, others on failure. 1249 */ 1250 virtual int32_t StartNativeChildProcess(const pid_t hostPid, 1251 const std::string &libName, int32_t childProcessCount, const sptr<IRemoteObject> &callback); 1252 #endif // SUPPORT_CHILD_PROCESS 1253 1254 /** 1255 * To clear the process by ability token. 1256 * 1257 * @param token the unique identification to the ability. 1258 */ 1259 void ClearProcessByToken(sptr<IRemoteObject> token); 1260 1261 /** 1262 * Whether the current application process is the last surviving process. 1263 * @param bundleName To query the bundle name of a process. 1264 * @return Returns true is final application process, others return false. 1265 */ 1266 bool IsFinalAppProcessByBundleName(const std::string &bundleName); 1267 1268 /** 1269 * @brief Notify memory size state changed to sufficient or insufficient. 1270 * @param isMemorySizeSufficient Indicates the memory size state. 1271 * @return Returns ERR_OK on success, others on failure. 1272 */ 1273 int32_t NotifyMemorySizeStateChanged(bool isMemorySizeSufficient); 1274 1275 /** 1276 * whether memory size is sufficient. 1277 * @return Returns true is sufficient memory size, others return false. 1278 */ 1279 bool IsMemorySizeSufficient(); 1280 1281 /** 1282 * Register render state observer. 1283 * @param observer Render process state observer. 1284 * @return Returns ERR_OK on success, others on failure. 1285 */ 1286 int32_t RegisterRenderStateObserver(const sptr<IRenderStateObserver> &observer); 1287 1288 /** 1289 * Unregister render state observer. 1290 * @param observer Render process state observer. 1291 * @return Returns ERR_OK on success, others on failure. 1292 */ 1293 int32_t UnregisterRenderStateObserver(const sptr<IRenderStateObserver> &observer); 1294 1295 /** 1296 * Update render state. 1297 * @param renderPid Render pid. 1298 * @param state foreground or background state. 1299 * @return Returns ERR_OK on success, others on failure. 1300 */ 1301 int32_t UpdateRenderState(pid_t renderPid, int32_t state); 1302 1303 /** 1304 * Mark processes of the uid as the app is going to be restarted. 1305 */ 1306 int32_t SignRestartAppFlag(int32_t uid, const std::string &instanceKey); 1307 1308 /** 1309 * Set application assertion pause state. 1310 * 1311 * @param flag assertion pause state. 1312 */ 1313 void SetAppAssertionPauseState(bool flag); 1314 1315 /** 1316 * @brief A process can config itself to keep alive or not. 1317 * when one process started, this method will be called from ability mgr with data selected from db. 1318 * 1319 * @param bundleName processed of witch to be configed 1320 * @param enable config value 1321 * @param uid indicates user, 0 for all users 1322 */ 1323 void SetKeepAliveEnableState(const std::string &bundleName, bool enable, int32_t uid); 1324 1325 /** 1326 * @brief Set non-resident keep-alive process status. 1327 * when one process started, this method will be called from ability mgr with data selected from db. 1328 * 1329 * @param bundleName processed of witch to be configed 1330 * @param enable config value 1331 * @param uid indicates user, 0 for all users 1332 */ 1333 void SetKeepAliveDkv(const std::string &bundleName, bool enable, int32_t uid); 1334 1335 int32_t GetAppRunningUniqueIdByPid(pid_t pid, std::string &appRunningUniqueId); 1336 1337 int32_t GetAllUIExtensionRootHostPid(pid_t pid, std::vector<pid_t> &hostPids); 1338 1339 int32_t GetAllUIExtensionProviderPid(pid_t hostPid, std::vector<pid_t> &providerPids); 1340 1341 virtual int DumpIpcAllStart(std::string& result); 1342 1343 virtual int DumpIpcAllStop(std::string& result); 1344 1345 virtual int DumpIpcAllStat(std::string& result); 1346 1347 virtual int DumpIpcStart(const int32_t pid, std::string& result); 1348 1349 virtual int DumpIpcStop(const int32_t pid, std::string& result); 1350 1351 virtual int DumpIpcStat(const int32_t pid, std::string& result); 1352 1353 virtual int DumpFfrt(const std::vector<int32_t>& pids, std::string& result); 1354 1355 /** 1356 * @brief set support process cache by self 1357 */ 1358 int32_t SetSupportedProcessCacheSelf(bool isSupport); 1359 1360 int32_t SetSupportedProcessCache(int32_t pid, bool isSupport); 1361 1362 void OnAppCacheStateChanged(const std::shared_ptr<AppRunningRecord> &appRecord, ApplicationState state); 1363 1364 /** 1365 * set browser channel for caller 1366 * @param hostPid caller pid 1367 */ 1368 virtual void SaveBrowserChannel(const pid_t hostPid, sptr<IRemoteObject> browser); 1369 1370 bool IsAppProcessesAllCached(const std::string &bundleName, int32_t uid, 1371 const std::set<std::shared_ptr<AppRunningRecord>> &cachedSet); 1372 1373 /** 1374 * Check caller is test ability 1375 * 1376 * @param pid, the pid of ability. 1377 * @return Returns ERR_OK is test ability, others is not test ability. 1378 */ 1379 int32_t CheckCallingIsUserTestModeInner(const pid_t pid, bool &isUserTest); 1380 1381 bool GetSceneBoardAttachFlag() const; 1382 1383 void SetSceneBoardAttachFlag(bool flag); 1384 1385 /** 1386 * Scene board has the highest priority. If Scene board is loading cache other apps' request. 1387 */ 1388 void CacheLoadAbilityTask(const LoadAbilityTaskFunc&& func); 1389 1390 void SubmitCacheLoadAbilityTask(); 1391 /** 1392 * Notifies that one ability is attached to status bar. 1393 * 1394 * @param token the token of the abilityRecord that is attached to status bar. 1395 */ 1396 void AttachedToStatusBar(const sptr<IRemoteObject> &token); 1397 void KillApplicationByRecord(const std::shared_ptr<AppRunningRecord> &appRecord); 1398 1399 int32_t NotifyProcessDependedOnWeb(); 1400 1401 void KillProcessDependedOnWeb(); 1402 1403 void RestartResidentProcessDependedOnWeb(); 1404 1405 void BlockProcessCacheByPids(const std::vector<int32_t>& pids); 1406 1407 bool CleanAbilityByUserRequest(const sptr<IRemoteObject> &token); 1408 1409 /** 1410 * whether killed for upgrade web. 1411 * 1412 * @param bundleName the bundle name is killed for upgrade web. 1413 * @return Returns true is killed for upgrade web, others return false. 1414 */ 1415 bool IsKilledForUpgradeWeb(const std::string &bundleName) const; 1416 1417 bool IsProcessContainsOnlyUIAbility(const pid_t pid); 1418 1419 /** 1420 * Whether a process is attached, refer to AttachApplication 1421 */ 1422 bool IsProcessAttached(sptr<IRemoteObject> token) const; 1423 1424 /** 1425 * Is a process of a ability killing 1426 * @param indicates the ability 1427 */ 1428 bool IsCallerKilling(const std::string& callerKey) const; 1429 1430 /** 1431 * @brief Notify abilityms app process pre cache 1432 * @param pid process pid. 1433 * @param userId userId Designation User ID. 1434 */ 1435 void NotifyAppPreCache(int32_t pid, int32_t userId); 1436 1437 /** 1438 * Get pids of processes which belong to specific bundle name and support process cache feature. 1439 * 1440 * @param bundleName bundle name. 1441 * @param pidList pid list of processes that support process cache. 1442 * @return Returns ERR_OK on success, others on failure. 1443 */ 1444 virtual int32_t GetSupportedProcessCachePids(const std::string &bundleName, std::vector<int32_t> &pidList); 1445 1446 /** 1447 * Register KIA interceptor. 1448 * @param interceptor KIA interceptor. 1449 * @return Returns ERR_OK on success, others on failure. 1450 */ 1451 virtual int32_t RegisterKiaInterceptor(const sptr<IKiaInterceptor> &interceptor); 1452 1453 /** 1454 * Check if the given pid is a KIA process. 1455 * @param pid process id. 1456 * @return Returns true if it is a KIA process, false otherwise. 1457 */ 1458 virtual int32_t CheckIsKiaProcess(pid_t pid, bool &isKia); 1459 1460 void UpdateInstanceKeyBySpecifiedId(int32_t specifiedId, std::string &instanceKey); 1461 1462 bool IsSpecifiedModuleLoaded(const AAFwk::Want &want, const AbilityInfo &abilityInfo); 1463 int32_t GetKilledProcessInfo(int pid, int uid, KilledProcessInfo &info); 1464 1465 private: 1466 int32_t ForceKillApplicationInner(const std::string &bundleName, const int userId = -1, 1467 const int appIndex = 0); 1468 1469 std::string FaultTypeToString(FaultDataType type); 1470 1471 FaultData ConvertDataTypes(const AppFaultDataBySA &faultData); 1472 1473 /** 1474 * Start a empty resident process 1475 */ 1476 void StartEmptyResidentProcess(const BundleInfo &info, const std::string &processName, int restartCount, 1477 bool isEmptyKeepAliveApp); 1478 1479 /** 1480 * If one app needs keepalive and dies, restart the app again 1481 */ 1482 void RestartResidentProcess(std::shared_ptr<AppRunningRecord> appRecord); 1483 1484 /** 1485 * If one app needs keepalive and dies, restart the app again 1486 */ 1487 void RestartKeepAliveProcess(std::shared_ptr<AppRunningRecord> appRecord); 1488 1489 bool CheckLoadAbilityConditions(const sptr<IRemoteObject> &token, 1490 const std::shared_ptr<AbilityInfo> &abilityInfo, const std::shared_ptr<ApplicationInfo> &appInfo); 1491 1492 /** 1493 * query bundle info for the given bundleName 1494 */ 1495 bool GetBundleInfo(const std::string &bundleName, BundleInfo &bundleInfo); 1496 1497 bool GenerateRenderUid(int32_t &renderUid); 1498 1499 /** 1500 * Build a process's name for service extension 1501 */ 1502 void MakeServiceExtProcessName(const std::shared_ptr<AbilityInfo> &abilityInfo, 1503 const std::shared_ptr<ApplicationInfo> &appInfo, std::string &processName) const; 1504 1505 /** 1506 * Build a process's name for the info given 1507 */ 1508 void MakeProcessName(const std::shared_ptr<AbilityInfo> &abilityInfo, 1509 const std::shared_ptr<ApplicationInfo> &appInfo, const HapModuleInfo &hapModuleInfo, int32_t appIndex, 1510 const std::string &specifiedProcessFlag, std::string &processName, bool isCallerSetProcess) const; 1511 1512 /** 1513 * Build a process's name based on the info given 1514 */ 1515 void MakeProcessName(const std::shared_ptr<ApplicationInfo> &appInfo, const HapModuleInfo &hapModuleInfo, 1516 std::string &processName) const; 1517 1518 bool CheckIsolationMode(const HapModuleInfo &hapModuleInfo) const; 1519 1520 bool IsMainProcess(const std::shared_ptr<ApplicationInfo> &appInfo, const std::string &processName) const; 1521 1522 /** 1523 * StartAbility, load the ability that needed to be started(Start on the basis of the original process). 1524 * Start on a new boot process 1525 * @param token, the unique identification to start the ability. 1526 * @param preToken, the unique identification to call the ability. 1527 * @param abilityInfo, the ability information. 1528 * @param appInfo, the app information. 1529 * 1530 * @return 1531 */ 1532 void StartAbility(sptr<IRemoteObject> token, sptr<IRemoteObject> preToken, 1533 std::shared_ptr<AbilityInfo> abilityInfo, std::shared_ptr<AppRunningRecord> appRecord, 1534 const HapModuleInfo &hapModuleInfo, std::shared_ptr<AAFwk::Want> want, int32_t abilityRecordId); 1535 1536 int32_t StartPerfProcess(const std::shared_ptr<AppRunningRecord> &appRecord, const std::string& perfCmd, 1537 const std::string& debugCmd, bool isSandboxApp); 1538 1539 void StartProcessVerifyPermission(const BundleInfo &bundleInfo, bool &hasAccessBundleDirReq, 1540 uint8_t &setAllowInternet, uint8_t &allowInternet, std::vector<int32_t> &gids); 1541 1542 void AddMountPermission(uint32_t accessTokenId, std::set<std::string> &permissions); 1543 1544 /** 1545 * StartProcess, load the ability that needed to be started(Start on a new boot process). 1546 * 1547 * @param appName, the app name. 1548 * @param processName, the process name. 1549 * @param appRecord, the app information. 1550 * @param uid, the process uid. 1551 * @param bundleName, the app bundleName. 1552 * 1553 * @return 1554 */ 1555 int32_t StartProcess(const std::string &appName, const std::string &processName, uint32_t startFlags, 1556 std::shared_ptr<AppRunningRecord> appRecord, const int uid, const BundleInfo &bundleInfo, 1557 const std::string &bundleName, const int32_t bundleIndex, bool appExistFlag = true, 1558 bool isPreload = false, AppExecFwk::PreloadMode preloadMode = AppExecFwk::PreloadMode::PRE_MAKE, 1559 const std::string &moduleName = "", const std::string &abilityName = "", 1560 sptr<IRemoteObject> token = nullptr, std::shared_ptr<AAFwk::Want> want = nullptr, 1561 ExtensionAbilityType extensionAbilityType = ExtensionAbilityType::UNSPECIFIED); 1562 1563 /** 1564 * KillApplicationByUserId, kill the application by user ID. 1565 * 1566 * @param bundleName, bundle name in Application record. 1567 * @param appCloneIndex the app clone id. 1568 * @param userId, user ID. 1569 * @param reason, caller function name. 1570 * 1571 * @return ERR_OK, return back success, others fail. 1572 */ 1573 int32_t KillApplicationByUserIdLocked(const std::string &bundleName, int32_t appCloneIndex, int32_t userId, 1574 const KillProcessConfig &config = {}); 1575 1576 /** 1577 * WaitForRemoteProcessExit, Wait for the process to exit normally. 1578 * 1579 * @param pids, process number collection to exit. 1580 * @param startTime, execution process security exit start time. 1581 * 1582 * @return true, return back success,others fail. 1583 */ 1584 bool WaitForRemoteProcessExit(std::list<pid_t> &pids, const int64_t startTime); 1585 1586 bool WaitForRemoteProcessExit(std::list<SimpleProcessInfo> &processInfos, const int64_t startTime); 1587 1588 /** 1589 * WaitProcessesExitAndKill, Wait for the process to exit normally, and kill it if time out. 1590 * 1591 * @param pids, process number collection to exit. 1592 * @param startTime, execution process security exit start time. 1593 * @param reason caller function name 1594 * 1595 * @return ERR_OK, return back success, others fail. 1596 */ 1597 int32_t WaitProcessesExitAndKill(std::list<pid_t> &pids, const int64_t startTime, const std::string& reason); 1598 1599 int32_t WaitProcessesExitAndKill(std::list<SimpleProcessInfo> &processInfos, const int64_t startTime, 1600 const std::string& reason, int32_t userId, sptr<AAFwk::IUserCallback> callback); 1601 1602 void DoAllProcessExitCallback(std::list<SimpleProcessInfo> &processInfos, int32_t userId, 1603 sptr<AAFwk::IUserCallback> callback); 1604 1605 /** 1606 * SystemTimeMillisecond, Get system time. 1607 * 1608 * @return the system time. 1609 */ 1610 int64_t SystemTimeMillisecond(); 1611 1612 // Test add the bundle manager instance. 1613 void SetBundleManagerHelper(const std::shared_ptr<BundleMgrHelper> &bundleMgrHelper); 1614 1615 void HandleTerminateApplicationTimeOut(std::shared_ptr<AppRunningRecord> appRecord); 1616 1617 void HandleAddAbilityStageTimeOut(std::shared_ptr<AppRunningRecord> appRecord); 1618 1619 void ClipStringContent(const std::regex &re, const std::string &source, std::string &afterCutStr); 1620 1621 bool GetBundleAndHapInfo(const AbilityInfo &abilityInfo, const std::shared_ptr<ApplicationInfo> &appInfo, 1622 BundleInfo &bundleInfo, HapModuleInfo &hapModuleInfo, int32_t appIndex = 0) const; 1623 AppProcessData WrapAppProcessData(const std::shared_ptr<AppRunningRecord> &appRecord, 1624 const ApplicationState state); 1625 1626 int UserTestAbnormalFinish(const sptr<IRemoteObject> &observer, const std::string &msg); 1627 int GetHapModuleInfoForTestRunner(const AAFwk::Want &want, const sptr<IRemoteObject> &observer, 1628 const BundleInfo &bundleInfo, HapModuleInfo &hapModuleInfo); 1629 int StartEmptyProcess(const AAFwk::Want &want, const sptr<IRemoteObject> &observer, const BundleInfo &info, 1630 const std::string &processName, const int userId); 1631 1632 void HandleStartSpecifiedAbilityTimeOut(std::shared_ptr<AppRunningRecord> appRecord); 1633 1634 void HandleStartSpecifiedProcessTimeout(std::shared_ptr<AppRunningRecord> appRecord); 1635 1636 void InitGlobalConfiguration(); 1637 1638 /** 1639 * @brief Another way of GetRunningProcess, only one item will be filled into the info 1640 */ 1641 void GetRunningProcesses(const std::shared_ptr<AppRunningRecord> &appRecord, std::vector<RunningProcessInfo> &info); 1642 /** 1643 * @brief Retrieve a process's running info 1644 */ 1645 void GetRunningProcess(const std::shared_ptr<AppRunningRecord> &appRecord, RunningProcessInfo &info); 1646 1647 /** 1648 * @brief query a process's render process info 1649 * @param appRecord the main process 1650 * @param info to retrieve render process info 1651 */ 1652 void GetRenderProcesses(const std::shared_ptr<AppRunningRecord> &appRecord, std::vector<RenderProcessInfo> &info); 1653 1654 #ifdef SUPPORT_CHILD_PROCESS 1655 void GetChildrenProcesses(const std::shared_ptr<AppRunningRecord> &appRecord, std::vector<ChildProcessInfo> &info); 1656 #endif // SUPPORT_CHILD_PROCESS 1657 1658 #ifdef ABILITY_PLATFORM_CHECK_PERMISSION 1659 int CheckStablePermission(const BundleInfo &bundleInfo); 1660 bool CheckDeviceStatus(Security::AccessToken::PermissionStateFull &status, 1661 std::string deviceid); 1662 #endif //ABILITY_PLATFORM_CHECK_PERMISSION 1663 1664 int StartRenderProcessImpl(const std::shared_ptr<RenderRecord> &renderRecord, 1665 const std::shared_ptr<AppRunningRecord> appRecord, pid_t &renderPid, bool isGPU = false); 1666 1667 void SetRenderStartMsg(AppSpawnStartMsg &startMsg, std::shared_ptr<RenderRecord> renderRecord, 1668 const int32_t renderUid, const bool isGPU); 1669 1670 void OnRenderRemoteDied(const wptr<IRemoteObject> &remote); 1671 1672 void AddWatchParameter(); 1673 1674 bool VerifyAPL() const; 1675 1676 /** 1677 * Register a focus listener to window manager 1678 */ 1679 void RegisterFocusListener(); 1680 1681 static void PointerDeviceEventCallback(const char *key, const char *value, void *context); 1682 1683 /** 1684 * Verify whether the caller has the permission to kill processes of a bundleName. 1685 */ 1686 int VerifyKillProcessPermission(const std::string &bundleName) const; 1687 1688 int32_t VerifyKillProcessPermissionCommon() const; 1689 1690 void ApplicationTerminatedSendProcessEvent(const std::shared_ptr<AppRunningRecord> &appRecord); 1691 void ClearAppRunningDataForKeepAlive(const std::shared_ptr<AppRunningRecord> &appRecord); 1692 void ClearResidentProcessAppRunningData(const std::shared_ptr<AppRunningRecord> &appRecord); 1693 void ClearNonResidentKeepAliveAppRunningData(const std::shared_ptr<AppRunningRecord> &appRecord); 1694 1695 #ifdef SUPPORT_CHILD_PROCESS 1696 int32_t StartChildProcessPreCheck(pid_t callingPid, int32_t childProcessType); 1697 1698 int32_t StartChildProcessImpl(const std::shared_ptr<ChildProcessRecord> childProcessRecord, 1699 const std::shared_ptr<AppRunningRecord> appRecord, pid_t &childPid, const ChildProcessArgs &args, 1700 const ChildProcessOptions &options); 1701 1702 int32_t GetChildProcessInfo(const std::shared_ptr<ChildProcessRecord> childProcessRecord, 1703 const std::shared_ptr<AppRunningRecord> appRecord, ChildProcessInfo &info, 1704 bool isCallFromGetChildrenProcesses = false); 1705 1706 void OnChildProcessRemoteDied(const wptr<IRemoteObject> &remote); 1707 1708 /** 1709 * kill all child processed of a main process 1710 * @param appRecord indicates the main process 1711 */ 1712 void KillChildProcess(const std::shared_ptr<AppRunningRecord> &appRecord); 1713 1714 void KillAttachedChildProcess(const std::shared_ptr<AppRunningRecord> &appRecord); 1715 1716 void PresetMaxChildProcess(std::shared_ptr<AppRunningRecord> appRecord, 1717 int32_t &maxChildProcess); 1718 #endif // SUPPORT_CHILD_PROCESS 1719 1720 void AfterLoadAbility(std::shared_ptr<AppRunningRecord> appRecord, std::shared_ptr<AbilityInfo> abilityInfo, 1721 std::shared_ptr<AbilityRuntime::LoadParam> loadParam); 1722 1723 void RemoveRenderRecordNoAttach(const std::shared_ptr<AppRunningRecord> &hostRecord, int32_t renderPid); 1724 1725 private: 1726 /** 1727 * ClearUpApplicationData, clear the application data. 1728 * 1729 * @param bundleName, bundle name in Application record. 1730 * @param uid, app uid in Application record. 1731 * @param pid, app pid in Application record. 1732 * @param appCloneIndex the app clone id. 1733 * @param userId, userId. 1734 * @param isBySelf, clear data by application self. 1735 * @param reason, caller function. 1736 * 1737 * @return Returns ERR_OK on success, others on failure. 1738 */ 1739 int32_t ClearUpApplicationDataByUserId(const std::string &bundleName, 1740 int32_t callerUid, pid_t callerPid, int32_t appCloneIndex, int32_t userId, bool isBySelf = false, 1741 const std::string& reason = "ClearUpApplicationDataByUserId"); 1742 1743 bool CheckGetRunningInfoPermission() const; 1744 1745 /** 1746 * kill all processes of a bundleName 1747 * @param bundleName bundleName of which to be killed 1748 * @param clearPageStack should schedule clearPage lifecycle 1749 * @param reason caller function name 1750 */ 1751 int32_t KillApplicationByBundleName(const std::string &bundleName, int32_t appIndex, bool clearPageStack = false, 1752 const std::string& reason = "KillApplicationByBundleName"); 1753 1754 bool SendProcessStartEvent(const std::shared_ptr<AppRunningRecord> &appRecord, bool isPreload, 1755 AppExecFwk::PreloadMode preloadMode); 1756 1757 bool SendProcessStartFailedEvent(std::shared_ptr<AppRunningRecord> appRecord, ProcessStartFailedReason reason, 1758 int32_t subReason); 1759 1760 void SendPreloadAppStartupTypeEvent(const std::shared_ptr<AppRunningRecord> &appRecord, 1761 const std::shared_ptr<AbilityInfo> &abilityInfo); 1762 1763 void SendAppStartupTypeEvent(const std::shared_ptr<AppRunningRecord> &appRecord, 1764 const std::shared_ptr<AbilityInfo> &abilityInfo, const AppStartType startType, const AppStartReason reason); 1765 1766 bool SendCreateAtomicServiceProcessEvent(const std::shared_ptr<AppRunningRecord> &appRecord, 1767 const BundleType &bundleType, const std::string &moduleName = "", const std::string &abilityName = ""); 1768 1769 void SendProcessExitEvent(const std::shared_ptr<AppRunningRecord> &appRecord); 1770 1771 void SendProcessExitEventTask(const std::shared_ptr<AppRunningRecord> &appRecord, time_t exitTime, int32_t count); 1772 1773 void SetRunningSharedBundleList(const std::string &bundleName, 1774 const std::vector<BaseSharedBundleInfo> baseSharedBundleInfoList); 1775 1776 void RemoveRunningSharedBundleList(const std::string &bundleName); 1777 1778 /** 1779 * kill one process's render process 1780 * @param appRecord the main process 1781 */ 1782 void KillRenderProcess(const std::shared_ptr<AppRunningRecord> &appRecord); 1783 1784 void SetOverlayInfo(const std::string& bundleName, const int32_t userId, AppSpawnStartMsg& startMsg); 1785 void SetAppEnvInfo(const BundleInfo &bundleInfo, AppSpawnStartMsg& startMsg); 1786 1787 void TimeoutNotifyApp(int32_t pid, int32_t uid, const std::string& bundleName, const std::string& processName, 1788 const FaultData &faultData); 1789 1790 void AppRecoveryNotifyApp(int32_t pid, const std::string& bundleName, 1791 FaultDataType faultType, const std::string& markers); 1792 1793 void ProcessAppDebug(const std::shared_ptr<AppRunningRecord> &appRecord, const bool &isDebugStart); 1794 AppDebugInfo MakeAppDebugInfo(const std::shared_ptr<AppRunningRecord> &appRecord, const bool &isDebugStart); 1795 int32_t NotifyAbilitiesDebugChange(const std::string &bundleName, const bool &isAppDebug); 1796 int32_t NotifyAbilitiesAssertDebugChange(const std::shared_ptr<AppRunningRecord> &appRecord, bool isAssertDebug); 1797 1798 void SetProcessJITState(const std::shared_ptr<AppRunningRecord> appRecord); 1799 1800 bool JudgeSelfCalledByToken(const sptr<IRemoteObject> &token, const PageStateData &pageStateData); 1801 1802 void ParseServiceExtMultiProcessWhiteList(); 1803 void ClearData(std::shared_ptr<AppRunningRecord> appRecord); 1804 1805 /** 1806 * Notify the app running status. 1807 * 1808 * @param bundle Bundle name in application record. 1809 * @param uid Uid of bundle. 1810 * @param runningStatus The app running status. 1811 * 1812 * @return 1813 */ 1814 void NotifyAppRunningStatusEvent( 1815 const std::string &bundle, int32_t uid, AbilityRuntime::RunningStatus runningStatus); 1816 1817 #ifdef SUPPORT_CHILD_PROCESS 1818 void GetRunningCloneAppInfo(const std::shared_ptr<AppRunningRecord> &appRecord, 1819 RunningMultiAppInfo &info); 1820 #endif // SUPPORT_CHILD_PROCESS 1821 1822 void GetRunningMultiInstanceKeys(const std::shared_ptr<AppRunningRecord> &appRecord, 1823 std::vector<std::string> &instanceKeys); 1824 /** 1825 * To Prevent process being killed when ability is starting in an existing process, 1826 * we need notify memmgr to increase process priority. 1827 * 1828 * @param appRecord Current app running record. 1829 * 1830 * @return Whether improve priority succeed. 1831 */ 1832 bool NotifyMemMgrPriorityChanged(const std::shared_ptr<AppRunningRecord> appRecord); 1833 1834 void HandlePreloadApplication(const PreloadRequest &request); 1835 void SetPreloadDebugApp(std::shared_ptr<AAFwk::Want> want, std::shared_ptr<ApplicationInfo> appInfo); 1836 1837 void reportpreLoadTask(const std::shared_ptr<AppRunningRecord> appRecord); 1838 1839 std::string GetSpecifiedProcessFlag(std::shared_ptr<AbilityInfo> abilityInfo, std::shared_ptr<AAFwk::Want> want); 1840 std::string GetSpecifiedProcessFlag(const AbilityInfo &abilityInfo, const AAFwk::Want &want); 1841 1842 void LoadAbilityNoAppRecord(const std::shared_ptr<AppRunningRecord> appRecord, 1843 bool isShellCall, std::shared_ptr<ApplicationInfo> appInfo, 1844 std::shared_ptr<AbilityInfo> abilityInfo, const std::string &processName, 1845 const std::string &specifiedProcessFlag, const BundleInfo &bundleInfo, 1846 const HapModuleInfo &hapModuleInfo, std::shared_ptr<AAFwk::Want> want, 1847 bool appExistFlag, bool isPreload, AppExecFwk::PreloadMode preloadMode, 1848 sptr<IRemoteObject> token = nullptr, const std::string &customProcessFlag = ""); 1849 1850 int32_t CreatNewStartMsg(const Want &want, const AbilityInfo &abilityInfo, 1851 const std::shared_ptr<ApplicationInfo> &appInfo, const std::string &processName, 1852 AppSpawnStartMsg &startMsg); 1853 1854 /** 1855 * Build message body for app spawn 1856 */ 1857 int32_t CreateStartMsg(const CreateStartMsgParam ¶m, AppSpawnStartMsg &startMsg); 1858 1859 void SetStartMsgStrictMode(AppSpawnStartMsg &startMsg, const CreateStartMsgParam ¶m); 1860 1861 void SetAppRunningRecordStrictMode(std::shared_ptr<AppRunningRecord> appRecord, 1862 std::shared_ptr<AbilityRuntime::LoadParam> loadParam); 1863 1864 void QueryExtensionSandBox(const std::string &moduleName, const std::string &abilityName, 1865 const BundleInfo &bundleInfo, AppSpawnStartMsg &startMsg, DataGroupInfoList& dataGroupInfoList, 1866 std::shared_ptr<AAFwk::Want> want); 1867 1868 int32_t StartPerfProcessByStartMsg(AppSpawnStartMsg &startMsg, const std::string& perfCmd, 1869 const std::string& debugCmd, bool isSandboxApp); 1870 1871 void SetAtomicServiceInfo(BundleType bundleType, AppSpawnStartMsg &startMsg); 1872 1873 void SetAppInfo(const BundleInfo &bundleInfo, AppSpawnStartMsg &startMsg); 1874 1875 void SetStartMsgCustomSandboxFlag(AppSpawnStartMsg &startMsg, int32_t userId); 1876 1877 /** 1878 * Query ability for one want param 1879 */ 1880 bool CreateAbilityInfo(const AAFwk::Want &want, AbilityInfo &abilityInfo); 1881 1882 /** 1883 * Build event info for one app record 1884 */ 1885 AAFwk::EventInfo BuildEventInfo(std::shared_ptr<AppRunningRecord> appRecord) const; 1886 1887 /** 1888 * @brief Call the callbacks to notify one process should go dying due fatal error. 1889 * @param appRecord indicates the process is going to die. 1890 */ 1891 void NotifyAppAttachFailed(std::shared_ptr<AppRunningRecord> appRecord); 1892 1893 void NotifyLoadAbilityFailed(sptr<IRemoteObject> token); 1894 1895 void NotifyStartProcessFailed(sptr<IRemoteObject> token); 1896 private: 1897 /** 1898 * Notify application status. 1899 * 1900 * @param bundleName Indicates the name of the bundle. 1901 * @param bundleName Indicates the name of the bundle. 1902 * @param eventData Indicates the event defined by CommonEventSupport 1903 * 1904 * @return 1905 */ 1906 void NotifyAppStatusByCallerUid(const std::string &bundleName, const int32_t tokenId, const int32_t userId, 1907 const int32_t callerUid, const int32_t targetUid, const std::string &eventData); 1908 void UpdateAllProviderConfig(const std::shared_ptr<AppRunningRecord> &appRecord); 1909 void SendHiSysEvent(int32_t innerEventId, std::shared_ptr<AppRunningRecord> appRecord); 1910 int FinishUserTestLocked( 1911 const std::string &msg, const int64_t &resultCode, const std::shared_ptr<AppRunningRecord> &appRecord); 1912 int32_t GetCurrentAccountId() const; 1913 void SendReStartProcessEvent(AAFwk::EventInfo &eventInfo, int32_t appUid); 1914 void SendAppLaunchEvent(const std::shared_ptr<AppRunningRecord> &appRecord); 1915 void InitAppWaitingDebugList(); 1916 bool IsWaitingDebugAppInner(const std::string &bundleName); 1917 void HandleConfigurationChange(const Configuration &config, const int32_t userId = -1); 1918 bool CheckIsThreadInFoundation(pid_t pid); 1919 bool CheckAppFault(const std::shared_ptr<AppRunningRecord> &appRecord, const FaultData &faultData); 1920 int32_t KillFaultApp(int32_t pid, const std::string &bundleName, const FaultData &faultData, 1921 bool isNeedExit = false); 1922 void AddUIExtensionLauncherItem(std::shared_ptr<AAFwk::Want> want, std::shared_ptr<AppRunningRecord> appRecord, 1923 sptr<IRemoteObject> token); 1924 void NotifyStartResidentProcess(std::vector<AppExecFwk::BundleInfo> &bundleInfos); 1925 void NotifyStartKeepAliveProcess(std::vector<AppExecFwk::BundleInfo> &bundleInfos); 1926 void RemoveUIExtensionLauncherItem(std::shared_ptr<AppRunningRecord> appRecord, sptr<IRemoteObject> token); 1927 bool IsSceneBoardCall(); 1928 void CheckCleanAbilityByUserRequest(const std::shared_ptr<AppRunningRecord> &appRecord, 1929 const std::shared_ptr<AbilityRunningRecord> &abilityRecord, const AbilityState state); 1930 int32_t GetPidsByAccessTokenId(const uint32_t accessTokenId, std::vector<pid_t> &pids); 1931 void MakeIsolateSandBoxProcessName(const std::shared_ptr<AbilityInfo> &abilityInfo, 1932 const HapModuleInfo &hapModuleInfo, std::string &processName) const; 1933 int32_t DealWithUserConfiguration(const Configuration &config, const int32_t userId, int32_t ¬ifyUserId); 1934 bool CheckIsDebugApp(const std::string &bundleName); 1935 int32_t MakeKiaProcess(std::shared_ptr<AAFwk::Want> want, bool &isKia, std::string &watermarkBusinessName, 1936 bool &isWatermarkEnabled, bool &isFileUri, std::string &processName); 1937 int32_t ProcessKia(bool isKia, std::shared_ptr<AppRunningRecord> appRecord, 1938 const std::string& watermarkBusinessName, bool isWatermarkEnabled); 1939 bool CheckAppRecordAndPriorityObject(const std::shared_ptr<AppRunningRecord> &appRecord); 1940 #ifdef SUPPORT_CHILD_PROCESS 1941 void GetAppCloneInfo(const std::shared_ptr<AppRunningRecord> &appRecord, 1942 RunningMultiAppInfo &info); 1943 void GetMultiInstanceInfo(const std::shared_ptr<AppRunningRecord> &appRecord, 1944 RunningMultiAppInfo &info); 1945 #endif //SUPPORT_CHILD_PROCESS 1946 int32_t GetAllRunningInstanceKeysByBundleNameInner(const std::string &bundleName, 1947 std::vector<std::string> &instanceKeys, int32_t userId); 1948 int32_t KillProcessByPidInner(const pid_t pid, const std::string& reason, 1949 const std::string& killReason, std::shared_ptr<AppRunningRecord> appRecord); 1950 bool IsAllowedNWebPreload(const std::string &processName); 1951 void ParseInfoToAppfreeze(const FaultData &faultData, int32_t pid, int32_t uid, const std::string &bundleName, 1952 const std::string &processName, const bool isOccurException = false); 1953 int GetExceptionTimerId(const FaultData &faultData, const std::string &bundleName, 1954 const std::shared_ptr<AppRunningRecord> &appRecord, const int32_t pid, const int32_t callerUid); 1955 int32_t SubmitDfxFaultTask(const FaultData &faultData, const std::string &bundleName, 1956 const std::shared_ptr<AppRunningRecord> &appRecord, const int32_t pid); 1957 void AddAbilityStageForSpecified(std::shared_ptr<AppRunningRecord> appRecord); 1958 void GetKernelPermissions(uint32_t accessTokenId, JITPermissionsMap &permissionsMap); 1959 void SendAppSpawnUninstallDebugHapMsg(int32_t userId); 1960 1961 bool isInitAppWaitingDebugListExecuted_ = false; 1962 std::atomic<bool> sceneBoardAttachFlag_ = true; 1963 std::atomic<int32_t> willKillPidsNum_ = 0; 1964 int32_t currentUserId_ = 0; 1965 int32_t lastRenderUid_ = Constants::START_UID_FOR_RENDER_PROCESS; 1966 const std::string TASK_ON_CALLBACK_DIED = "OnCallbackDiedTask"; 1967 std::vector<AppStateCallbackWithUserId> appStateCallbacks_; 1968 std::shared_ptr<RemoteClientManager> remoteClientManager_; 1969 std::shared_ptr<AppRunningManager> appRunningManager_; 1970 std::shared_ptr<AAFwk::TaskHandlerWrap> taskHandler_; 1971 std::shared_ptr<AMSEventHandler> eventHandler_; 1972 ffrt::mutex userTestLock_; 1973 ffrt::mutex appStateCallbacksLock_; 1974 ffrt::mutex renderUidSetLock_; 1975 ffrt::mutex exceptionLock_; 1976 ffrt::mutex browserHostLock_; 1977 ffrt::mutex restartResidentTaskListMutex_; 1978 sptr<IStartSpecifiedAbilityResponse> startSpecifiedAbilityResponse_; 1979 ffrt::mutex configurationObserverLock_; 1980 std::vector<ConfigurationObserverWithUserId> configurationObservers_; 1981 1982 #ifdef SUPPORT_SCREEN 1983 sptr<WindowFocusChangedListener> focusListener_; 1984 sptr<WindowVisibilityChangedListener> windowVisibilityChangedListener_; 1985 sptr<WindowPidVisibilityChangedListener> windowPidVisibilityChangedListener_; 1986 #endif //SUPPORT_SCREEN 1987 std::vector<std::shared_ptr<AppRunningRecord>> restartResidentTaskList_; 1988 ffrt::mutex runningSharedBundleListMutex_; 1989 std::map<std::string, std::vector<BaseSharedBundleInfo>> runningSharedBundleList_; 1990 std::map<std::string, bool> waitingDebugBundleList_; 1991 ffrt::mutex waitingDebugLock_; 1992 std::unordered_set<int32_t> renderUidSet_; 1993 std::string supportIsolationMode_ {"false"}; 1994 std::string supportServiceExtMultiProcess_ {"false"}; 1995 sptr<IAbilityDebugResponse> abilityDebugResponse_; 1996 std::shared_ptr<AppDebugManager> appDebugManager_; 1997 ffrt::mutex killedProcessMapLock_; 1998 mutable std::map<int64_t, std::string> killedProcessMap_; 1999 #ifdef SUPPORT_CHILD_PROCESS 2000 ffrt::mutex startChildProcessLock_; 2001 #endif //SUPPORT_CHILD_PROCESS 2002 std::vector<std::string> serviceExtensionWhiteList_; 2003 std::shared_ptr<AbilityRuntime::AppRunningStatusModule> appRunningStatusModule_; 2004 std::shared_ptr<AdvancedSecurityModeManager> securityModeManager_; 2005 std::shared_ptr<AAFwk::TaskHandlerWrap> dfxTaskHandler_; 2006 std::shared_ptr<AAFwk::TaskHandlerWrap> otherTaskHandler_; 2007 std::shared_ptr<AppPreloader> appPreloader_; 2008 2009 std::mutex loadTaskListMutex_; 2010 std::vector<LoadAbilityTaskFunc> loadAbilityTaskFuncList_; 2011 sptr<IKiaInterceptor> kiaInterceptor_; 2012 std::shared_ptr<MultiUserConfigurationMgr> multiUserConfigurationMgr_; 2013 std::shared_ptr<AAFwk::TaskHandlerWrap> delayKillTaskHandler_; 2014 std::unordered_set<std::string> nwebPreloadSet_ {}; 2015 2016 std::mutex childProcessRecordMapMutex_; 2017 }; 2018 } // namespace AppExecFwk 2019 } // namespace OHOS 2020 #endif // OHOS_ABILITY_RUNTIME_APP_MGR_SERVICE_INNER_H 2021