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_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 int 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 int 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 113 /** 114 * PreloadUIExtensionAbilityLocked, preload uiextension ability. 115 * 116 * @param abilityRequest, Special want for service type's ability. 117 * @param hostBundleName, the caller application bundle name. 118 * @return Returns ERR_OK on success, others on failure. 119 */ 120 int PreloadUIExtensionAbilityLocked(const AbilityRequest &abilityRequest, std::string &hostBundleName); 121 122 /** 123 * UnloadUIExtensionAbility, unload uiextension ability. 124 * 125 * @param abilityRecord, uiextension ability record. 126 * @param hostBundleName, the caller application bundle name. 127 * @return Returns ERR_OK on success, others on failure. 128 */ 129 int UnloadUIExtensionAbility(const std::shared_ptr<AAFwk::AbilityRecord> &abilityRecord, std::string &bundleName); 130 131 /** 132 * ClearPreloadUIExtensionRecord, clear preload uiextension record. 133 * 134 * @param abilityRecord, uiextension ability record. 135 */ 136 void ClearPreloadUIExtensionRecord(const std::shared_ptr<AbilityRecord> &abilityRecord); 137 138 /** 139 * DisconnectAbilityLocked, disconnect session with callback. 140 * 141 * @param connect, Callback used to notify caller the result of connecting or disconnecting. 142 * @return Returns ERR_OK on success, others on failure. 143 */ 144 int DisconnectAbilityLocked(const sptr<IAbilityConnection> &connect); 145 146 /** 147 * AttachAbilityThreadLocked, ability call this interface after loaded. 148 * 149 * @param scheduler, the interface handler of kit ability. 150 * @param token, ability's token. 151 * @return Returns ERR_OK on success, others on failure. 152 */ 153 int AttachAbilityThreadLocked(const sptr<IAbilityScheduler> &scheduler, const sptr<IRemoteObject> &token); 154 155 void OnAbilityRequestDone(const sptr<IRemoteObject> &token, const int32_t state); 156 157 void OnAppStateChanged(const AppInfo &info); 158 159 /** 160 * AbilityTransitionDone, ability call this interface after lift cycle was changed. 161 * 162 * @param token, ability's token. 163 * @param state, the state of ability lift cycle. 164 * @return Returns ERR_OK on success, others on failure. 165 */ 166 int AbilityTransitionDone(const sptr<IRemoteObject> &token, int state); 167 168 /** 169 * ScheduleConnectAbilityDoneLocked, service ability call this interface while session was connected. 170 * 171 * @param token, service ability's token. 172 * @param remoteObject, the session proxy of service ability. 173 * @return Returns ERR_OK on success, others on failure. 174 */ 175 int ScheduleConnectAbilityDoneLocked(const sptr<IRemoteObject> &token, const sptr<IRemoteObject> &remoteObject); 176 177 /** 178 * ScheduleDisconnectAbilityDone, service ability call this interface while session was disconnected. 179 * 180 * @param token,service ability's token. 181 * @return Returns ERR_OK on success, others on failure. 182 */ 183 int ScheduleDisconnectAbilityDoneLocked(const sptr<IRemoteObject> &token); 184 185 /** 186 * ScheduleCommandAbilityDoneLocked, service ability call this interface while session was onCommanded. 187 * 188 * @param token,service ability's token. 189 * @return Returns ERR_OK on success, others on failure. 190 */ 191 int ScheduleCommandAbilityDoneLocked(const sptr<IRemoteObject> &token); 192 193 int ScheduleCommandAbilityWindowDone( 194 const sptr<IRemoteObject> &token, 195 const sptr<SessionInfo> &sessionInfo, 196 WindowCommand winCmd, 197 AbilityCommand abilityCmd); 198 199 /** 200 * GetUIExtensioBySessionInfo. 201 * 202 * @param sessionToken, service ability's session token. 203 * @return Returns AbilityRecord shared_ptr. 204 */ 205 std::shared_ptr<AbilityRecord> GetUIExtensioBySessionInfo(const sptr<SessionInfo> &sessionInfo); 206 207 std::shared_ptr<AbilityRecord> GetExtensionByTokenFromServiceMap(const sptr<IRemoteObject> &token); 208 std::shared_ptr<AbilityRecord> GetExtensionByTokenFromAbilityCache(const sptr<IRemoteObject> &token); 209 std::shared_ptr<AbilityRecord> GetExtensionByTokenFromTerminatingMap(const sptr<IRemoteObject> &token); 210 std::shared_ptr<AbilityRecord> GetExtensionByIdFromServiceMap(const int64_t &abilityRecordId); 211 std::shared_ptr<AbilityRecord> GetExtensionByIdFromTerminatingMap(const int64_t &abilityRecordId); 212 ConnectListType GetConnectRecordListByCallback(sptr<IAbilityConnection> callback); 213 214 void GetExtensionRunningInfos(int upperLimit, std::vector<ExtensionRunningInfo> &info, 215 const int32_t userId, bool isPerm); 216 217 void GetAbilityRunningInfos(std::vector<AbilityRunningInfo> &info, bool isPerm); 218 219 void GetExtensionRunningInfo(std::shared_ptr<AbilityRecord> &abilityRecord, const int32_t userId, 220 std::vector<ExtensionRunningInfo> &info); 221 222 /** 223 * set from ability manager service for sequenced task 224 */ SetTaskHandler(const std::shared_ptr<TaskHandlerWrap> & taskHandler)225 inline void SetTaskHandler(const std::shared_ptr<TaskHandlerWrap> &taskHandler) 226 { 227 taskHandler_ = taskHandler; 228 } 229 /** 230 * SetEventHandler. 231 * 232 * @param handler,EventHandler 233 */ SetEventHandler(const std::shared_ptr<EventHandlerWrap> & handler)234 inline void SetEventHandler(const std::shared_ptr<EventHandlerWrap> &handler) 235 { 236 eventHandler_ = handler; 237 } 238 GetSceneBoardTokenId()239 uint32_t GetSceneBoardTokenId() const 240 { 241 return sceneBoardTokenId_; 242 } 243 244 /** 245 * @brief Get extensionList by pid. 246 * @param pid Process id. 247 * @param extensionList UIExtensionAbility name list. 248 */ 249 int32_t GetActiveUIExtensionList(const int32_t pid, std::vector<std::string> &extensionList); 250 251 /** 252 * @brief Get extensionList by bundleName. 253 * @param bundleName The application bundle name. 254 * @param extensionList UIExtensionAbility name list. 255 */ 256 int32_t GetActiveUIExtensionList(const std::string &bundleName, std::vector<std::string> &extensionList); 257 258 /** 259 * OnAbilityDied. 260 * 261 * @param abilityRecord, service ability record. 262 */ 263 void OnAbilityDied(const std::shared_ptr<AbilityRecord> &abilityRecord, int32_t currentUserId); 264 265 void DumpState(std::vector<std::string> &info, bool isClient, const std::string &args = ""); 266 267 void DumpStateByUri(std::vector<std::string> &info, bool isClient, const std::string &args, 268 std::vector<std::string> ¶ms); 269 270 void PauseExtensions(); 271 272 void OnTimeOut(uint32_t msgId, int64_t abilityRecordId, bool isHalf = false); 273 274 /** 275 * @brief schedule to background 276 * 277 * @param abilityRecord the ability to move 278 */ 279 void MoveToBackground(const std::shared_ptr<AbilityRecord> &abilityRecord); 280 281 void CommandAbilityWindow(const std::shared_ptr<AbilityRecord> &abilityRecord, 282 const sptr<SessionInfo> &sessionInfo, WindowCommand winCmd); 283 284 bool IsUIExtensionFocused(uint32_t uiExtensionTokenId, const sptr<IRemoteObject>& focusToken); 285 286 sptr<IRemoteObject> GetUIExtensionSourceToken(const sptr<IRemoteObject> &token); 287 288 bool IsWindowExtensionFocused(uint32_t extensionTokenId, const sptr<IRemoteObject>& focusToken); 289 290 void HandleProcessFrozen(const std::vector<int32_t> &pidList, int32_t uid); 291 292 void ForegroundAbilityWindowLocked(const std::shared_ptr<AbilityRecord> &abilityRecord, 293 const sptr<SessionInfo> &sessionInfo); 294 295 void BackgroundAbilityWindowLocked(const std::shared_ptr<AbilityRecord> &abilityRecord, 296 const sptr<SessionInfo> &sessionInfo); 297 298 void TerminateAbilityWindowLocked(const std::shared_ptr<AbilityRecord> &abilityRecord, 299 const sptr<SessionInfo> &sessionInfo); 300 301 void RemoveLauncherDeathRecipient(); 302 303 /** 304 * @brief Get ui extension session info 305 * 306 * @param token The ability token. 307 * @param uiExtensionSessionInfo The ui extension session info. 308 * @param userId The user id. 309 * @return int32_t Returns ERR_OK on success, others on failure. 310 */ 311 int32_t GetUIExtensionSessionInfo(const sptr<IRemoteObject> token, UIExtensionSessionInfo &uiExtensionSessionInfo); 312 313 void GetUIExtensionCallerTokenList(const std::shared_ptr<AbilityRecord> &abilityRecord, 314 std::list<sptr<IRemoteObject>> &callerList); 315 316 void CloseAssertDialog(const std::string &assertSessionId); 317 318 void SignRestartAppFlag(int32_t uid); 319 320 std::shared_ptr<AAFwk::AbilityRecord> GetUIExtensionRootHostInfo(const sptr<IRemoteObject> token); 321 void UninstallApp(const std::string &bundleName); 322 323 int32_t UpdateKeepAliveEnableState(const std::string &bundleName, const std::string &moduleName, 324 const std::string &mainElement, bool updateEnable); 325 326 // MSG 0 - 20 represents timeout message 327 static constexpr uint32_t CONNECT_TIMEOUT_MSG = 1; 328 329 private: 330 /** 331 * StartAbilityLocked with request. 332 * 333 * @param abilityRequest, the request of the service ability to start. 334 * @return Returns ERR_OK on success, others on failure. 335 */ 336 int StartAbilityLocked(const AbilityRequest &abilityRequest); 337 338 /** 339 * TerminateAbilityLocked with token and result want. 340 * 341 * @param token, the token of service type's ability to terminate. 342 * @param resultCode, the result code of service type's ability to terminate. 343 * @param resultWant, the result want for service type's ability to terminate. 344 * @return Returns ERR_OK on success, others on failure. 345 */ 346 int TerminateAbilityLocked(const sptr<IRemoteObject> &token); 347 348 /** 349 * StopAbilityLocked with request. 350 * 351 * @param abilityRequest, the request of the service ability to start. 352 * @return Returns ERR_OK on success, others on failure. 353 */ 354 int StopServiceAbilityLocked(const AbilityRequest &abilityRequest); 355 356 /** 357 * DisconnectAbilityLocked, disconnect session with callback. 358 * 359 * @param connect, Callback used to notify caller the result of connecting or disconnecting. 360 * @param callerDied, bool Indicates if it is caused by the caller's death. 361 * @return Returns ERR_OK on success, others on failure. 362 */ 363 int DisconnectAbilityLocked(const sptr<IAbilityConnection> &connect, bool callerDied); 364 365 /** 366 * LoadAbility. 367 * 368 * @param abilityRecord, the ptr of the ability to load. 369 */ 370 void LoadAbility(const std::shared_ptr<AbilityRecord> &abilityRecord); 371 372 /** 373 * ConnectAbility.Schedule connect ability 374 * 375 * @param abilityRecord, the ptr of the ability to connect. 376 */ 377 void ConnectAbility(const std::shared_ptr<AbilityRecord> &abilityRecord); 378 379 /** 380 * CommandAbility. Schedule command ability 381 * 382 * @param abilityRecord, the ptr of the ability to command. 383 */ 384 void CommandAbility(const std::shared_ptr<AbilityRecord> &abilityRecord); 385 386 /** 387 * CompleteCommandAbility. complete command ability 388 * 389 * @param abilityRecord, the ptr of the ability to command. 390 */ 391 void CompleteCommandAbility(std::shared_ptr<AbilityRecord> abilityRecord); 392 393 /** 394 * TerminateDone. 395 * 396 * @param abilityRecord, the ptr of the ability to terminate. 397 */ 398 void TerminateDone(const std::shared_ptr<AbilityRecord> &abilityRecord); 399 400 /** 401 * GetServiceRecordByElementName. 402 * 403 * @param element, service ability's element. 404 * @return Returns AbilityRecord shared_ptr. 405 */ 406 std::shared_ptr<AbilityRecord> GetServiceRecordByElementName(const std::string &element); 407 408 /** 409 * dispatch service ability life cycle . 410 * 411 * @param abilityRecord. 412 * @param state. 413 */ 414 int DispatchInactive(const std::shared_ptr<AbilityRecord> &abilityRecord, int state); 415 int DispatchForeground(const std::shared_ptr<AbilityRecord> &abilityRecord); 416 int DispatchBackground(const std::shared_ptr<AbilityRecord> &abilityRecord); 417 int DispatchTerminate(const std::shared_ptr<AbilityRecord> &abilityRecord); 418 419 void HandleStartTimeoutTask(const std::shared_ptr<AbilityRecord> &abilityRecord); 420 void HandleStopTimeoutTask(const std::shared_ptr<AbilityRecord> &abilityRecord); 421 void HandleTerminateDisconnectTask(const ConnectListType& connectlist); 422 void HandleCommandTimeoutTask(const std::shared_ptr<AbilityRecord> &abilityRecord); 423 void HandleCommandWindowTimeoutTask(const std::shared_ptr<AbilityRecord> &abilityRecord, 424 const sptr<SessionInfo> &sessionInfo, WindowCommand winCmd); 425 void HandleForegroundTimeoutTask(const std::shared_ptr<AbilityRecord> &abilityRecord); 426 void HandleConnectTimeoutTask(std::shared_ptr<AbilityRecord> abilityRecord); 427 void HandleRestartResidentTask(const AbilityRequest &abilityRequest); 428 void HandleActiveAbility(std::shared_ptr<AbilityRecord> &targetService, 429 std::shared_ptr<ConnectionRecord> &connectRecord); 430 void HandleCommandDestroy(const sptr<SessionInfo> &sessionInfo); 431 void TerminateOrCacheAbility(std::shared_ptr<AbilityRecord> abilityRecord); 432 433 /** 434 * IsAbilityConnected. 435 * 436 * @param abilityRecord, the ptr of the connected ability. 437 * @param connectRecordList, connect record list. 438 * @return true: ability is connected, false: ability is not connected 439 */ 440 bool IsAbilityConnected(const std::shared_ptr<AbilityRecord> &abilityRecord, 441 const std::list<std::shared_ptr<ConnectionRecord>> &connectRecordList); 442 443 /** 444 * RemoveConnectionRecordFromMap. 445 * 446 * @param connect, the ptr of the connect record. 447 */ 448 void RemoveConnectionRecordFromMap(std::shared_ptr<ConnectionRecord> connect); 449 450 /** 451 * RemoveServiceAbility. 452 * 453 * @param service, the ptr of the ability record. 454 */ 455 void RemoveServiceAbility(const std::shared_ptr<AbilityRecord> &service); 456 457 /** 458 * GetOrCreateServiceRecord. 459 * 460 * @param abilityRequest, Special want for service type's ability. 461 * @param isCreatedByConnect, whether is created by connect ability mode. 462 * @param targetAbilityRecord, the target service ability record. 463 * @param isLoadedAbility, whether the target ability has been loaded. 464 */ 465 void GetOrCreateServiceRecord(const AbilityRequest &abilityRequest, const bool isCreatedByConnect, 466 std::shared_ptr<AbilityRecord> &targetAbilityRecord, bool &isLoadedAbility); 467 468 /** 469 * GetConnectRecordListFromMap. 470 * 471 * @param connect, callback object. 472 * @param isCreatedByConnect, whether is created by connect ability mode. 473 * @param connectRecordList, the target connectRecordList. 474 * @param isCallbackConnected, whether the callback has been connected. 475 */ 476 void GetConnectRecordListFromMap( 477 const sptr<IAbilityConnection> &connect, std::list<std::shared_ptr<ConnectionRecord>> &connectRecordList); 478 479 /** 480 * AddConnectDeathRecipient. 481 * 482 * @param connect, callback object. 483 */ 484 void AddConnectDeathRecipient(sptr<IRemoteObject> connectObject); 485 486 /** 487 * RemoteConnectDeathRecipient. 488 * 489 * @param connect, callback object. 490 */ 491 void RemoveConnectDeathRecipient(sptr<IRemoteObject> connectObject); 492 493 /** 494 * RemoteConnectDeathRecipient. 495 * 496 * @param remote, callback object. 497 */ 498 void OnCallBackDied(const wptr<IRemoteObject> &remote); 499 500 /** 501 * HandleOnCallBackDied. 502 * 503 * @param connect, callback object. 504 */ 505 void HandleCallBackDiedTask(const sptr<IRemoteObject> &connect); 506 507 /** 508 * HandleOnCallBackDied. 509 * 510 * @param abilityRecord, died ability. 511 */ 512 void HandleAbilityDiedTask(const std::shared_ptr<AbilityRecord> &abilityRecord, int32_t currentUserId); 513 void HandleUIExtensionDied(const std::shared_ptr<AbilityRecord> &abilityRecord); 514 515 void RestartAbility(const std::shared_ptr<AbilityRecord> &abilityRecord, int32_t currentUserId); 516 517 /** 518 * PostTimeOutTask. 519 * 520 * @param abilityRecord, ability. 521 * @param messageId, message id. 522 */ 523 void PostTimeOutTask(const std::shared_ptr<AbilityRecord> &abilityRecord, uint32_t messageId); 524 525 void CompleteForeground(const std::shared_ptr<AbilityRecord> &abilityRecord); 526 void CompleteBackground(const std::shared_ptr<AbilityRecord> &abilityRecord); 527 void PrintTimeOutLog(const std::shared_ptr<AbilityRecord> &ability, uint32_t msgId, bool isHalf = false); 528 529 void PostRestartResidentTask(const AbilityRequest &abilityRequest); 530 531 bool IsAbilityNeedKeepAlive(const std::shared_ptr<AbilityRecord> &abilityRecord); 532 533 void ProcessPreload(const std::shared_ptr<AbilityRecord> &record) const; 534 535 void HandleInactiveTimeout(const std::shared_ptr<AbilityRecord> &ability); 536 void MoveToTerminatingMap(const std::shared_ptr<AbilityRecord>& abilityRecord); 537 538 void DoForegroundUIExtension(std::shared_ptr<AbilityRecord> abilityRecord, const AbilityRequest &abilityRequest); 539 void DoBackgroundAbilityWindow(const std::shared_ptr<AbilityRecord> &abilityRecord, 540 const sptr<SessionInfo> &sessionInfo); 541 542 /** 543 * When a service is under starting, enque the request and handle it after the service starting completes 544 */ 545 void EnqueueStartServiceReq(const AbilityRequest &abilityRequest, const std::string &serviceUri = ""); 546 /** 547 * After the service starting completes, complete the request list 548 */ 549 void CompleteStartServiceReq(const std::string &serviceUri); 550 551 void AddUIExtWindowDeathRecipient(const sptr<IRemoteObject> &session); 552 void RemoveUIExtWindowDeathRecipient(const sptr<IRemoteObject> &session); 553 void OnUIExtWindowDied(const wptr<IRemoteObject> &remote); 554 void HandleUIExtWindowDiedTask(const sptr<IRemoteObject> &remote); 555 556 /** 557 * Post an extension's disconnect task, auto disconnect when extension conected timeout. 558 */ 559 void PostExtensionDelayDisconnectTask(const std::shared_ptr<ConnectionRecord> &connectRecord); 560 561 /** 562 * Remove the extension's disconnect task. 563 */ 564 void RemoveExtensionDelayDisconnectTask(const std::shared_ptr<ConnectionRecord> &connectRecord); 565 566 /** 567 * Handle extension disconnect task. 568 */ 569 void HandleExtensionDisconnectTask(const std::shared_ptr<ConnectionRecord> &connectRecord); 570 571 private: 572 void TerminateRecord(std::shared_ptr<AbilityRecord> abilityRecord); 573 int DisconnectRecordNormal(ConnectListType &list, std::shared_ptr<ConnectionRecord> connectRecord, 574 bool callerDied) const; 575 void DisconnectRecordForce(ConnectListType &list, std::shared_ptr<ConnectionRecord> connectRecord); 576 int TerminateAbilityInner(const sptr<IRemoteObject> &token); 577 bool IsLauncher(std::shared_ptr<AbilityRecord> serviceExtension) const; 578 void KillProcessesByUserId() const; 579 void SetLastExitReason(const AbilityRequest &abilityRequest, std::shared_ptr<AbilityRecord> &targetService); 580 inline bool IsUIExtensionAbility(const std::shared_ptr<AbilityRecord> &abilityRecord); 581 inline bool IsCacheExtensionAbilityType(const std::shared_ptr<AbilityRecord> &abilityRecord); 582 inline bool CheckUIExtensionAbilityLoaded(const AbilityRequest &abilityRequest); 583 inline bool CheckUIExtensionAbilitySessionExist(const std::shared_ptr<AbilityRecord> &abilityRecord); 584 inline void RemoveUIExtensionAbilityRecord(const std::shared_ptr<AbilityRecord> &abilityRecord); 585 inline void AddUIExtensionAbilityRecordToTerminatedList(const std::shared_ptr<AbilityRecord> &abilityRecord); 586 inline bool IsCallerValid(const std::shared_ptr<AbilityRecord> &abilityRecord); 587 int32_t GetOrCreateExtensionRecord(const AbilityRequest &abilityRequest, bool isCreatedByConnect, 588 const std::string &hostBundleName, std::shared_ptr<AbilityRecord> &extensionRecord, bool &isLoaded); 589 int32_t GetOrCreateTargetServiceRecord( 590 const AbilityRequest &abilityRequest, const sptr<UIExtensionAbilityConnectInfo> &connectInfo, 591 std::shared_ptr<AbilityRecord> &targetService, bool &isLoadedAbility); 592 void HandleNotifyAssertFaultDialogDied(const std::shared_ptr<AbilityRecord> &abilityRecord); 593 EventInfo BuildEventInfo(const std::shared_ptr<AbilityRecord> &abilityRecord); 594 void UpdateUIExtensionInfo(const std::shared_ptr<AbilityRecord> &abilityRecord); 595 std::string GenerateBundleName(const AbilityRequest &abilityRequest) const; 596 597 bool AddToServiceMap(const std::string &key, std::shared_ptr<AbilityRecord> abilityRecord); 598 ServiceMapType GetServiceMap(); 599 600 void AddConnectObjectToMap(sptr<IRemoteObject> connectObject, const ConnectListType &connectRecordList, 601 bool updateOnly); 602 603 void KeepAbilityAlive(const std::shared_ptr<AbilityRecord> &abilityRecord, int32_t currentUserId); 604 void ProcessEliminateAbilityRecord(std::shared_ptr<AbilityRecord> eliminateRecord); 605 std::string GetServiceKey(const std::shared_ptr<AbilityRecord> &service); 606 607 int32_t ReportXiaoYiToRSSIfNeeded(const AppExecFwk::AbilityInfo &abilityInfo); 608 int32_t ReportAbilityStartInfoToRSS(const AppExecFwk::AbilityInfo &abilityInfo); 609 610 private: 611 const std::string TASK_ON_CALLBACK_DIED = "OnCallbackDiedTask"; 612 const std::string TASK_ON_ABILITY_DIED = "OnAbilityDiedTask"; 613 614 ffrt::mutex serialMutex_; 615 616 std::mutex connectMapMutex_; 617 ConnectMapType connectMap_; 618 619 ffrt::mutex serviceMapMutex_; 620 ServiceMapType serviceMap_; 621 std::list<std::shared_ptr<AbilityRecord>> terminatingExtensionList_; 622 623 std::mutex recipientMapMutex_; 624 RecipientMapType recipientMap_; 625 626 std::mutex uiExtRecipientMapMutex_; 627 RecipientMapType uiExtRecipientMap_; 628 629 std::shared_ptr<TaskHandlerWrap> taskHandler_; 630 std::shared_ptr<EventHandlerWrap> eventHandler_; 631 int userId_; 632 std::vector<AbilityRequest> restartResidentTaskList_; 633 634 std::mutex startServiceReqListLock_; 635 std::unordered_map<std::string, std::shared_ptr<std::list<AbilityRequest>>> startServiceReqList_; 636 637 std::mutex uiExtensionMapMutex_; 638 UIExtensionMapType uiExtensionMap_; 639 640 std::mutex windowExtensionMapMutex_; 641 WindowExtensionMapType windowExtensionMap_; 642 643 std::unique_ptr<UIExtensionAbilityConnectManager> uiExtensionAbilityRecordMgr_ = nullptr; 644 uint32_t sceneBoardTokenId_ = 0; 645 646 DISALLOW_COPY_AND_MOVE(AbilityConnectManager); 647 }; 648 } // namespace AAFwk 649 } // namespace OHOS 650 #endif // OHOS_ABILITY_RUNTIME_ABILITY_CONNECT_MANAGER_H 651