1 /* 2 * Copyright (c) 2021-2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef OHOS_ABILITY_RUNTIME_ABILITY_CONNECT_MANAGER_H 17 #define OHOS_ABILITY_RUNTIME_ABILITY_CONNECT_MANAGER_H 18 19 #include <list> 20 #include <map> 21 #include <string> 22 #include <unordered_map> 23 #include "cpp/mutex.h" 24 25 #include "ability_cache_manager.h" 26 #include "ability_connect_callback_interface.h" 27 #include "task_handler_wrap.h" 28 #include "event_handler_wrap.h" 29 #include "ability_record.h" 30 #include "ability_running_info.h" 31 #include "event_report.h" 32 #include "extension_config.h" 33 #include "extension_running_info.h" 34 #include "connection_record.h" 35 #include "element_name.h" 36 #include "ui_extension/ui_extension_ability_connect_info.h" 37 #include "extension_record_manager.h" 38 #include "want.h" 39 #include "iremote_object.h" 40 #include "nocopyable.h" 41 42 namespace OHOS { 43 namespace AAFwk { 44 using OHOS::AppExecFwk::AbilityType; 45 using UIExtensionAbilityConnectInfo = AbilityRuntime::UIExtensionAbilityConnectInfo; 46 using UIExtensionAbilityConnectManager = AbilityRuntime::ExtensionRecordManager; 47 using UIExtensionSessionInfo = AbilityRuntime::UIExtensionSessionInfo; 48 /** 49 * @class AbilityConnectManager 50 * AbilityConnectManager provides a facility for managing service ability connection. 51 */ 52 class AbilityConnectManager : public std::enable_shared_from_this<AbilityConnectManager> { 53 public: 54 using ConnectMapType = std::map<sptr<IRemoteObject>, std::list<std::shared_ptr<ConnectionRecord>>>; 55 using ServiceMapType = std::map<std::string, std::shared_ptr<AbilityRecord>>; 56 using ConnectListType = std::list<std::shared_ptr<ConnectionRecord>>; 57 using RecipientMapType = std::map<sptr<IRemoteObject>, sptr<IRemoteObject::DeathRecipient>>; 58 using UIExtWindowMapValType = std::pair<std::weak_ptr<AbilityRecord>, sptr<SessionInfo>>; 59 using UIExtensionMapType = std::map<sptr<IRemoteObject>, UIExtWindowMapValType>; 60 using WindowExtMapValType = std::pair<uint32_t, sptr<SessionInfo>>; 61 using WindowExtensionMapType = std::map<sptr<IRemoteObject>, WindowExtMapValType>; 62 63 explicit AbilityConnectManager(int userId); 64 virtual ~AbilityConnectManager(); 65 66 /** 67 * StartAbility with request. 68 * 69 * @param abilityRequest, the request of the service ability to start. 70 * @return Returns ERR_OK on success, others on failure. 71 */ 72 int32_t StartAbility(const AbilityRequest &abilityRequest); 73 74 /** 75 * TerminateAbility with token and result want. 76 * 77 * @param token, the token of service type's ability to terminate. 78 * @return Returns ERR_OK on success, others on failure. 79 */ 80 int TerminateAbility(const sptr<IRemoteObject> &token); 81 82 /** 83 * StopServiceAbility with request. 84 * 85 * @param abilityRequest, request. 86 * @return Returns ERR_OK on success, others on failure. 87 */ 88 int StopServiceAbility(const AbilityRequest &abilityRequest); 89 90 /** 91 * ConnectAbilityLocked, connect session with service ability. 92 * 93 * @param abilityRequest, Special want for service type's ability. 94 * @param connect, Callback used to notify caller the result of connecting or disconnecting. 95 * @param callerToken, caller ability token. 96 * @param sessionInfo the extension session info of the ability to connect. 97 * @param connectInfo the connect info. 98 * @return Returns ERR_OK on success, others on failure. 99 */ 100 int32_t ConnectAbilityLocked(const AbilityRequest &abilityRequest, const sptr<IAbilityConnection> &connect, 101 const sptr<IRemoteObject> &callerToken, sptr<SessionInfo> sessionInfo = nullptr, 102 sptr<UIExtensionAbilityConnectInfo> connectInfo = nullptr); 103 104 /** 105 * PreloadUIExtensionAbilityInner, preload uiextension ability. 106 * 107 * @param abilityRequest, Special want for service type's ability. 108 * @param hostBundleName, the caller application bundle name. 109 * @return Returns ERR_OK on success, others on failure. 110 */ 111 int PreloadUIExtensionAbilityInner(const AbilityRequest &abilityRequest, std::string &hostBundleName, 112 int32_t hostPid = AAFwk::DEFAULT_INVAL_VALUE); 113 114 /** 115 * PreloadUIExtensionAbilityLocked, preload uiextension ability. 116 * 117 * @param abilityRequest, Special want for service type's ability. 118 * @param hostBundleName, the caller application bundle name. 119 * @return Returns ERR_OK on success, others on failure. 120 */ 121 int PreloadUIExtensionAbilityLocked(const AbilityRequest &abilityRequest, std::string &hostBundleName, 122 int32_t hostPid = AAFwk::DEFAULT_INVAL_VALUE); 123 124 /** 125 * Query preload uiextension record. 126 * 127 * @param element, The uiextension ElementName. 128 * @param moduleName, The uiextension moduleName. 129 * @param hostBundleName, The uiextension caller hostBundleName. 130 * @param recordNum, The returned count of uiextension. 131 * @return Returns ERR_OK on success, others on failure. 132 */ 133 int QueryPreLoadUIExtensionRecordInner(const AppExecFwk::ElementName &element, 134 const std::string &moduleName, 135 const std::string &hostBundleName, 136 int32_t &recordNum); 137 138 /** 139 * UnloadUIExtensionAbility, unload uiextension ability. 140 * 141 * @param abilityRecord, uiextension ability record. 142 * @param hostBundleName, the caller application bundle name. 143 * @return Returns ERR_OK on success, others on failure. 144 */ 145 int UnloadUIExtensionAbility(const std::shared_ptr<AAFwk::AbilityRecord> &abilityRecord, std::string &bundleName); 146 147 /** 148 * ClearPreloadUIExtensionRecord, clear preload uiextension record. 149 * 150 * @param abilityRecord, uiextension ability record. 151 */ 152 void ClearPreloadUIExtensionRecord(const std::shared_ptr<AbilityRecord> &abilityRecord); 153 154 /** 155 * DisconnectAbilityLocked, disconnect session with callback. 156 * 157 * @param connect, Callback used to notify caller the result of connecting or disconnecting. 158 * @return Returns ERR_OK on success, others on failure. 159 */ 160 int DisconnectAbilityLocked(const sptr<IAbilityConnection> &connect); 161 162 /** 163 * AttachAbilityThreadLocked, ability call this interface after loaded. 164 * 165 * @param scheduler, the interface handler of kit ability. 166 * @param token, ability's token. 167 * @return Returns ERR_OK on success, others on failure. 168 */ 169 int AttachAbilityThreadLocked(const sptr<IAbilityScheduler> &scheduler, const sptr<IRemoteObject> &token); 170 171 void OnAbilityRequestDone(const sptr<IRemoteObject> &token, const int32_t state); 172 173 void OnAppStateChanged(const AppInfo &info); 174 175 /** 176 * AbilityTransitionDone, ability call this interface after lift cycle was changed. 177 * 178 * @param token, ability's token. 179 * @param state, the state of ability lift cycle. 180 * @return Returns ERR_OK on success, others on failure. 181 */ 182 int AbilityTransitionDone(const sptr<IRemoteObject> &token, int state); 183 184 /** 185 * @brief execute after the ability schedule the lifecycle 186 * 187 * @param token the ability token 188 * @param windowConfig the windowconfig 189 * @return execute error code 190 */ 191 int AbilityWindowConfigTransactionDone( 192 const sptr<IRemoteObject> &token, const AppExecFwk::WindowConfig &windowConfig); 193 194 /** 195 * ScheduleConnectAbilityDoneLocked, service ability call this interface while session was connected. 196 * 197 * @param token, service ability's token. 198 * @param remoteObject, the session proxy of service ability. 199 * @return Returns ERR_OK on success, others on failure. 200 */ 201 int ScheduleConnectAbilityDoneLocked(const sptr<IRemoteObject> &token, const sptr<IRemoteObject> &remoteObject); 202 203 /** 204 * ScheduleDisconnectAbilityDone, service ability call this interface while session was disconnected. 205 * 206 * @param token,service ability's token. 207 * @return Returns ERR_OK on success, others on failure. 208 */ 209 int ScheduleDisconnectAbilityDoneLocked(const sptr<IRemoteObject> &token); 210 211 /** 212 * ScheduleCommandAbilityDoneLocked, service ability call this interface while session was onCommanded. 213 * 214 * @param token,service ability's token. 215 * @return Returns ERR_OK on success, others on failure. 216 */ 217 int ScheduleCommandAbilityDoneLocked(const sptr<IRemoteObject> &token); 218 219 int ScheduleCommandAbilityWindowDone( 220 const sptr<IRemoteObject> &token, 221 const sptr<SessionInfo> &sessionInfo, 222 WindowCommand winCmd, 223 AbilityCommand abilityCmd); 224 225 /** 226 * GetUIExtensionBySessionInfo. 227 * 228 * @param sessionToken, service ability's session token. 229 * @return Returns AbilityRecord shared_ptr. 230 */ 231 std::shared_ptr<AbilityRecord> GetUIExtensionBySessionInfo(const sptr<SessionInfo> &sessionInfo); 232 233 std::shared_ptr<AbilityRecord> GetExtensionByTokenFromServiceMap(const sptr<IRemoteObject> &token); 234 std::shared_ptr<AbilityRecord> GetExtensionByTokenFromTerminatingMap(const sptr<IRemoteObject> &token); 235 std::shared_ptr<AbilityRecord> GetExtensionByIdFromServiceMap(const int64_t &abilityRecordId); 236 std::shared_ptr<AbilityRecord> GetExtensionByIdFromTerminatingMap(const int64_t &abilityRecordId); 237 std::shared_ptr<AbilityRecord> GetUIExtensionBySessionFromServiceMap(const sptr<SessionInfo> &sessionInfo); 238 ConnectListType GetConnectRecordListByCallback(sptr<IAbilityConnection> callback); 239 240 void GetExtensionRunningInfos(int upperLimit, std::vector<ExtensionRunningInfo> &info, 241 const int32_t userId, bool isPerm); 242 243 void GetAbilityRunningInfos(std::vector<AbilityRunningInfo> &info, bool isPerm); 244 245 void GetExtensionRunningInfo(std::shared_ptr<AbilityRecord> &abilityRecord, const int32_t userId, 246 std::vector<ExtensionRunningInfo> &info); 247 248 /** 249 * set from ability manager service for sequenced task 250 */ SetTaskHandler(const std::shared_ptr<TaskHandlerWrap> & taskHandler)251 inline void SetTaskHandler(const std::shared_ptr<TaskHandlerWrap> &taskHandler) 252 { 253 taskHandler_ = taskHandler; 254 } 255 /** 256 * SetEventHandler. 257 * 258 * @param handler,EventHandler 259 */ SetEventHandler(const std::shared_ptr<EventHandlerWrap> & handler)260 inline void SetEventHandler(const std::shared_ptr<EventHandlerWrap> &handler) 261 { 262 eventHandler_ = handler; 263 } 264 GetSceneBoardTokenId()265 uint32_t GetSceneBoardTokenId() const 266 { 267 return sceneBoardTokenId_; 268 } 269 270 /** 271 * @brief Get extensionList by pid. 272 * @param pid Process id. 273 * @param extensionList UIExtensionAbility name list. 274 */ 275 int32_t GetActiveUIExtensionList(const int32_t pid, std::vector<std::string> &extensionList); 276 277 /** 278 * @brief Get extensionList by bundleName. 279 * @param bundleName The application bundle name. 280 * @param extensionList UIExtensionAbility name list. 281 */ 282 int32_t GetActiveUIExtensionList(const std::string &bundleName, std::vector<std::string> &extensionList); 283 284 void OnLoadAbilityFailed(std::shared_ptr<AbilityRecord> abilityRecord); 285 286 /** 287 * OnAbilityDied. 288 * 289 * @param abilityRecord, service ability record. 290 */ 291 void OnAbilityDied(const std::shared_ptr<AbilityRecord> &abilityRecord, int32_t currentUserId); 292 293 void DumpState(std::vector<std::string> &info, bool isClient, const std::string &args = ""); 294 295 void DumpStateByUri(std::vector<std::string> &info, bool isClient, const std::string &args, 296 std::vector<std::string> ¶ms); 297 298 void PauseExtensions(); 299 300 void OnTimeOut(uint32_t msgId, int64_t abilityRecordId, bool isHalf = false); 301 302 /** 303 * @brief schedule to background 304 * 305 * @param abilityRecord the ability to move 306 */ 307 void MoveToBackground(const std::shared_ptr<AbilityRecord> &abilityRecord); 308 309 void CommandAbilityWindow(const std::shared_ptr<AbilityRecord> &abilityRecord, 310 const sptr<SessionInfo> &sessionInfo, WindowCommand winCmd); 311 312 bool IsUIExtensionFocused(uint32_t uiExtensionTokenId, const sptr<IRemoteObject>& focusToken); 313 314 sptr<IRemoteObject> GetUIExtensionSourceToken(const sptr<IRemoteObject> &token); 315 316 bool IsWindowExtensionFocused(uint32_t extensionTokenId, const sptr<IRemoteObject>& focusToken); 317 318 void HandleProcessFrozen(const std::vector<int32_t> &pidList, int32_t uid); 319 320 void ForegroundAbilityWindowLocked(const std::shared_ptr<AbilityRecord> &abilityRecord, 321 const sptr<SessionInfo> &sessionInfo); 322 323 void BackgroundAbilityWindowLocked(const std::shared_ptr<AbilityRecord> &abilityRecord, 324 const sptr<SessionInfo> &sessionInfo); 325 326 void TerminateAbilityWindowLocked(const std::shared_ptr<AbilityRecord> &abilityRecord, 327 const sptr<SessionInfo> &sessionInfo); 328 329 void RemoveLauncherDeathRecipient(); 330 331 /** 332 * @brief Get ui extension session info 333 * 334 * @param token The ability token. 335 * @param uiExtensionSessionInfo The ui extension session info. 336 * @param userId The user id. 337 * @return int32_t Returns ERR_OK on success, others on failure. 338 */ 339 int32_t GetUIExtensionSessionInfo(const sptr<IRemoteObject> token, UIExtensionSessionInfo &uiExtensionSessionInfo); 340 341 void GetUIExtensionCallerTokenList(const std::shared_ptr<AbilityRecord> &abilityRecord, 342 std::list<sptr<IRemoteObject>> &callerList); 343 344 void CloseAssertDialog(const std::string &assertSessionId); 345 346 void SignRestartAppFlag(int32_t uid, const std::string &instanceKey); 347 348 std::shared_ptr<AAFwk::AbilityRecord> GetUIExtensionRootHostInfo(const sptr<IRemoteObject> token); 349 void UninstallApp(const std::string &bundleName, int32_t uid); 350 351 int32_t UpdateKeepAliveEnableState(const std::string &bundleName, const std::string &moduleName, 352 const std::string &mainElement, bool updateEnable); 353 354 /** 355 * Handle extension disconnect task. 356 */ 357 void HandleExtensionDisconnectTask(const std::shared_ptr<ConnectionRecord> &connectRecord); 358 359 // MSG 0 - 20 represents timeout message 360 static constexpr uint32_t CONNECT_TIMEOUT_MSG = 1; 361 362 private: 363 /** 364 * StartAbilityLocked with request. 365 * 366 * @param abilityRequest, the request of the service ability to start. 367 * @return Returns ERR_OK on success, others on failure. 368 */ 369 int32_t StartAbilityLocked(const AbilityRequest &abilityRequest); 370 371 /** 372 * TerminateAbilityLocked with token and result want. 373 * 374 * @param token, the token of service type's ability to terminate. 375 * @param resultCode, the result code of service type's ability to terminate. 376 * @param resultWant, the result want for service type's ability to terminate. 377 * @return Returns ERR_OK on success, others on failure. 378 */ 379 int TerminateAbilityLocked(const sptr<IRemoteObject> &token); 380 381 /** 382 * StopAbilityLocked with request. 383 * 384 * @param abilityRequest, the request of the service ability to start. 385 * @return Returns ERR_OK on success, others on failure. 386 */ 387 int StopServiceAbilityLocked(const AbilityRequest &abilityRequest); 388 389 /** 390 * DisconnectAbilityLocked, disconnect session with callback. 391 * 392 * @param connect, Callback used to notify caller the result of connecting or disconnecting. 393 * @param callerDied, bool Indicates if it is caused by the caller's death. 394 * @return Returns ERR_OK on success, others on failure. 395 */ 396 int DisconnectAbilityLocked(const sptr<IAbilityConnection> &connect, bool callerDied); 397 398 /** 399 * LoadAbility. 400 * 401 * @param abilityRecord, the ptr of the ability to load. 402 */ 403 void LoadAbility(const std::shared_ptr<AbilityRecord> &abilityRecord, 404 std::function<void(const std::shared_ptr<AbilityRecord>&)> updateRecordCallback = nullptr); 405 406 /** 407 * ConnectAbility.Schedule connect ability 408 * 409 * @param abilityRecord, the ptr of the ability to connect. 410 */ 411 void ConnectAbility(const std::shared_ptr<AbilityRecord> &abilityRecord); 412 413 /** 414 * ConnectAbility.Schedule connect ability 415 * 416 * @param abilityRecord, the ptr of the ability to connect. 417 */ 418 void ConnectUIServiceExtAbility(const std::shared_ptr<AbilityRecord> &abilityRecord, 419 int connectRecordId, const Want &want); 420 421 /** 422 * ConnectAbility.Schedule Resume Connect ability 423 * 424 * @param abilityRecord, the ptr of the ability to connect. 425 */ 426 void ResumeConnectAbility(const std::shared_ptr<AbilityRecord> &abilityRecord); 427 428 /** 429 * CommandAbility. Schedule command ability 430 * 431 * @param abilityRecord, the ptr of the ability to command. 432 */ 433 void CommandAbility(const std::shared_ptr<AbilityRecord> &abilityRecord); 434 435 /** 436 * CompleteCommandAbility. complete command ability 437 * 438 * @param abilityRecord, the ptr of the ability to command. 439 */ 440 void CompleteCommandAbility(std::shared_ptr<AbilityRecord> abilityRecord); 441 442 /** 443 * TerminateDone. 444 * 445 * @param abilityRecord, the ptr of the ability to terminate. 446 */ 447 void TerminateDone(const std::shared_ptr<AbilityRecord> &abilityRecord); 448 449 /** 450 * GetServiceRecordByElementName. 451 * 452 * @param element, service ability's element. 453 * @return Returns AbilityRecord shared_ptr. 454 */ 455 std::shared_ptr<AbilityRecord> GetServiceRecordByElementName(const std::string &element); 456 457 /** 458 * dispatch service ability life cycle . 459 * 460 * @param abilityRecord. 461 * @param state. 462 */ 463 int DispatchInactive(const std::shared_ptr<AbilityRecord> &abilityRecord, int state); 464 int DispatchForeground(const std::shared_ptr<AbilityRecord> &abilityRecord); 465 int DispatchBackground(const std::shared_ptr<AbilityRecord> &abilityRecord); 466 int DispatchTerminate(const std::shared_ptr<AbilityRecord> &abilityRecord); 467 468 void HandleStartTimeoutTask(const std::shared_ptr<AbilityRecord> &abilityRecord); 469 void HandleStopTimeoutTask(const std::shared_ptr<AbilityRecord> &abilityRecord); 470 void HandleTerminateDisconnectTask(const ConnectListType& connectlist); 471 void HandleCommandTimeoutTask(const std::shared_ptr<AbilityRecord> &abilityRecord); 472 void HandleCommandWindowTimeoutTask(const std::shared_ptr<AbilityRecord> &abilityRecord, 473 const sptr<SessionInfo> &sessionInfo, WindowCommand winCmd); 474 void HandleForegroundTimeoutTask(const std::shared_ptr<AbilityRecord> &abilityRecord); 475 void HandleConnectTimeoutTask(std::shared_ptr<AbilityRecord> abilityRecord); 476 void HandleRestartResidentTask(const AbilityRequest &abilityRequest); 477 void HandleActiveAbility(std::shared_ptr<AbilityRecord> &targetService, 478 std::shared_ptr<ConnectionRecord> &connectRecord); 479 void HandleCommandDestroy(const sptr<SessionInfo> &sessionInfo); 480 void TerminateOrCacheAbility(std::shared_ptr<AbilityRecord> abilityRecord); 481 void CancelLoadTimeoutTask(std::shared_ptr<AbilityRecord> abilityRecord); 482 483 /** 484 * IsAbilityConnected. 485 * 486 * @param abilityRecord, the ptr of the connected ability. 487 * @param connectRecordList, connect record list. 488 * @return true: ability is connected, false: ability is not connected 489 */ 490 bool IsAbilityConnected(const std::shared_ptr<AbilityRecord> &abilityRecord, 491 const std::list<std::shared_ptr<ConnectionRecord>> &connectRecordList); 492 493 /** 494 * RemoveConnectionRecordFromMap. 495 * 496 * @param connect, the ptr of the connect record. 497 */ 498 void RemoveConnectionRecordFromMap(std::shared_ptr<ConnectionRecord> connect); 499 500 /** 501 * RemoveServiceAbility. 502 * 503 * @param service, the ptr of the ability record. 504 */ 505 void RemoveServiceAbility(const std::shared_ptr<AbilityRecord> &service); 506 507 /** 508 * GetOrCreateServiceRecord. 509 * 510 * @param abilityRequest, Special want for service type's ability. 511 * @param isCreatedByConnect, whether is created by connect ability mode. 512 * @param targetAbilityRecord, the target service ability record. 513 * @param isLoadedAbility, whether the target ability has been loaded. 514 */ 515 void GetOrCreateServiceRecord(const AbilityRequest &abilityRequest, const bool isCreatedByConnect, 516 std::shared_ptr<AbilityRecord> &targetAbilityRecord, bool &isLoadedAbility); 517 518 void RemoveServiceFromMapSafe(const std::string &serviceKey); 519 520 /** 521 * GetConnectRecordListFromMap. 522 * 523 * @param connect, callback object. 524 * @param isCreatedByConnect, whether is created by connect ability mode. 525 * @param connectRecordList, the target connectRecordList. 526 * @param isCallbackConnected, whether the callback has been connected. 527 */ 528 void GetConnectRecordListFromMap( 529 const sptr<IAbilityConnection> &connect, std::list<std::shared_ptr<ConnectionRecord>> &connectRecordList); 530 531 /** 532 * AddConnectDeathRecipient. 533 * 534 * @param connect, callback object. 535 */ 536 void AddConnectDeathRecipient(sptr<IRemoteObject> connectObject); 537 538 /** 539 * RemoteConnectDeathRecipient. 540 * 541 * @param connect, callback object. 542 */ 543 void RemoveConnectDeathRecipient(sptr<IRemoteObject> connectObject); 544 545 /** 546 * RemoteConnectDeathRecipient. 547 * 548 * @param remote, callback object. 549 */ 550 void OnCallBackDied(const wptr<IRemoteObject> &remote); 551 552 /** 553 * HandleOnCallBackDied. 554 * 555 * @param connect, callback object. 556 */ 557 void HandleCallBackDiedTask(const sptr<IRemoteObject> &connect); 558 559 /** 560 * HandleOnCallBackDied. 561 * 562 * @param abilityRecord, died ability. 563 */ 564 void HandleAbilityDiedTask(const std::shared_ptr<AbilityRecord> &abilityRecord, int32_t currentUserId); 565 void HandleUIExtensionDied(const std::shared_ptr<AbilityRecord> &abilityRecord); 566 567 void RestartAbility(const std::shared_ptr<AbilityRecord> &abilityRecord, int32_t currentUserId); 568 569 /** 570 * PostTimeOutTask. 571 * 572 * @param abilityRecord, ability. 573 * @param messageId, message id. 574 */ 575 void PostTimeOutTask(const std::shared_ptr<AbilityRecord> &abilityRecord, uint32_t messageId); 576 void PostTimeOutTask(const std::shared_ptr<AbilityRecord> &abilityRecord, int connectRecordId, uint32_t messageId); 577 578 void CompleteForeground(const std::shared_ptr<AbilityRecord> &abilityRecord); 579 void CompleteBackground(const std::shared_ptr<AbilityRecord> &abilityRecord); 580 void PrintTimeOutLog(const std::shared_ptr<AbilityRecord> &ability, uint32_t msgId, bool isHalf = false); 581 582 void PostRestartResidentTask(const AbilityRequest &abilityRequest); 583 584 bool IsAbilityNeedKeepAlive(const std::shared_ptr<AbilityRecord> &abilityRecord); 585 586 void ProcessPreload(const std::shared_ptr<AbilityRecord> &record) const; 587 588 void HandleInactiveTimeout(const std::shared_ptr<AbilityRecord> &ability); 589 void CleanActivatingTimeoutAbility(std::shared_ptr<AbilityRecord> abilityRecord); 590 void MoveToTerminatingMap(const std::shared_ptr<AbilityRecord>& abilityRecord); 591 592 void DoForegroundUIExtension(std::shared_ptr<AbilityRecord> abilityRecord, const AbilityRequest &abilityRequest); 593 void DoBackgroundAbilityWindow(const std::shared_ptr<AbilityRecord> &abilityRecord, 594 const sptr<SessionInfo> &sessionInfo); 595 596 /** 597 * When a service is under starting, enque the request and handle it after the service starting completes 598 */ 599 void EnqueueStartServiceReq(const AbilityRequest &abilityRequest, const std::string &serviceUri = ""); 600 /** 601 * After the service starting completes, complete the request list 602 */ 603 void CompleteStartServiceReq(const std::string &serviceUri); 604 605 void AddUIExtWindowDeathRecipient(const sptr<IRemoteObject> &session); 606 void RemoveUIExtWindowDeathRecipient(const sptr<IRemoteObject> &session); 607 void OnUIExtWindowDied(const wptr<IRemoteObject> &remote); 608 void HandleUIExtWindowDiedTask(const sptr<IRemoteObject> &remote); 609 610 /** 611 * Post an extension's disconnect task, auto disconnect when extension connected timeout. 612 */ 613 void PostExtensionDelayDisconnectTask(const std::shared_ptr<ConnectionRecord> &connectRecord); 614 615 /** 616 * Remove the extension's disconnect task. 617 */ 618 void RemoveExtensionDelayDisconnectTask(const std::shared_ptr<ConnectionRecord> &connectRecord); 619 620 private: 621 void TerminateRecord(std::shared_ptr<AbilityRecord> abilityRecord); 622 int DisconnectRecordNormal(ConnectListType &list, std::shared_ptr<ConnectionRecord> connectRecord, 623 bool callerDied) const; 624 void DisconnectRecordForce(ConnectListType &list, std::shared_ptr<ConnectionRecord> connectRecord); 625 int TerminateAbilityInner(const sptr<IRemoteObject> &token); 626 bool IsLauncher(std::shared_ptr<AbilityRecord> serviceExtension) const; 627 void KillProcessesByUserId() const; 628 void SetLastExitReason(const AbilityRequest &abilityRequest, std::shared_ptr<AbilityRecord> &targetService); 629 inline bool IsUIExtensionAbility(const std::shared_ptr<AbilityRecord> &abilityRecord); 630 inline bool IsCacheExtensionAbilityByInfo(const AppExecFwk::AbilityInfo &abilityInfo); 631 inline bool IsCacheExtensionAbility(const std::shared_ptr<AbilityRecord> &abilityRecord); 632 inline bool CheckUIExtensionAbilityLoaded(const AbilityRequest &abilityRequest); 633 inline bool CheckUIExtensionAbilitySessionExist(const std::shared_ptr<AbilityRecord> &abilityRecord); 634 inline void RemoveUIExtensionAbilityRecord(const std::shared_ptr<AbilityRecord> &abilityRecord); 635 inline void AddUIExtensionAbilityRecordToTerminatedList(const std::shared_ptr<AbilityRecord> &abilityRecord); 636 inline bool IsCallerValid(const std::shared_ptr<AbilityRecord> &abilityRecord); 637 int32_t GetOrCreateExtensionRecord(const AbilityRequest &abilityRequest, bool isCreatedByConnect, 638 const std::string &hostBundleName, std::shared_ptr<AbilityRecord> &extensionRecord, bool &isLoaded); 639 int32_t GetOrCreateTargetServiceRecord( 640 const AbilityRequest &abilityRequest, const sptr<UIExtensionAbilityConnectInfo> &connectInfo, 641 std::shared_ptr<AbilityRecord> &targetService, bool &isLoadedAbility); 642 void HandleNotifyAssertFaultDialogDied(const std::shared_ptr<AbilityRecord> &abilityRecord); 643 EventInfo BuildEventInfo(const std::shared_ptr<AbilityRecord> &abilityRecord); 644 void UpdateUIExtensionInfo(const std::shared_ptr<AbilityRecord> &abilityRecord, 645 int32_t hostPid = AAFwk::DEFAULT_INVAL_VALUE); 646 std::string GenerateBundleName(const AbilityRequest &abilityRequest) const; 647 648 bool AddToServiceMap(const std::string &key, std::shared_ptr<AbilityRecord> abilityRecord); 649 ServiceMapType GetServiceMap(); 650 651 void AddConnectObjectToMap(sptr<IRemoteObject> connectObject, const ConnectListType &connectRecordList, 652 bool updateOnly); 653 654 void KeepAbilityAlive(const std::shared_ptr<AbilityRecord> &abilityRecord, int32_t currentUserId); 655 void ProcessEliminateAbilityRecord(std::shared_ptr<AbilityRecord> eliminateRecord); 656 std::string GetServiceKey(const std::shared_ptr<AbilityRecord> &service); 657 658 int32_t ReportXiaoYiToRSSIfNeeded(const AppExecFwk::AbilityInfo &abilityInfo); 659 int32_t ReportAbilityStartInfoToRSS(const AppExecFwk::AbilityInfo &abilityInfo); 660 void ReportEventToRSS(const AppExecFwk::AbilityInfo &abilityInfo, 661 const std::shared_ptr<AbilityRecord> abilityRecord, sptr<IRemoteObject> callerToken); 662 663 void SetExtensionLoadParam(AbilityRuntime::LoadParam &loadParam, std::shared_ptr<AbilityRecord> abilityRecord); 664 bool IsStrictMode(std::shared_ptr<AbilityRecord> abilityRecord); 665 bool NeedExtensionControl(std::shared_ptr<AbilityRecord> abilityRecord); 666 667 private: 668 const std::string TASK_ON_CALLBACK_DIED = "OnCallbackDiedTask"; 669 const std::string TASK_ON_ABILITY_DIED = "OnAbilityDiedTask"; 670 671 int userId_; 672 uint32_t sceneBoardTokenId_ = 0; 673 674 ConnectMapType connectMap_; 675 ServiceMapType serviceMap_; 676 RecipientMapType recipientMap_; 677 RecipientMapType uiExtRecipientMap_; 678 UIExtensionMapType uiExtensionMap_; 679 WindowExtensionMapType windowExtensionMap_; 680 681 std::list<std::shared_ptr<AbilityRecord>> terminatingExtensionList_; 682 std::shared_ptr<TaskHandlerWrap> taskHandler_; 683 std::shared_ptr<EventHandlerWrap> eventHandler_; 684 std::vector<AbilityRequest> restartResidentTaskList_; 685 std::unordered_map<std::string, std::shared_ptr<std::list<AbilityRequest>>> startServiceReqList_; 686 687 std::unique_ptr<UIExtensionAbilityConnectManager> uiExtensionAbilityRecordMgr_ = nullptr; 688 ffrt::mutex serialMutex_; 689 std::mutex connectMapMutex_; 690 ffrt::mutex serviceMapMutex_; 691 std::mutex recipientMapMutex_; 692 std::mutex uiExtRecipientMapMutex_; 693 std::mutex uiExtensionMapMutex_; 694 std::mutex windowExtensionMapMutex_; 695 std::mutex startServiceReqListLock_; 696 697 DISALLOW_COPY_AND_MOVE(AbilityConnectManager); 698 }; 699 } // namespace AAFwk 700 } // namespace OHOS 701 #endif // OHOS_ABILITY_RUNTIME_ABILITY_CONNECT_MANAGER_H 702