已合并
优化NotifyUnfreezed实现 #19678
peixu创建于 7月15日
优化NotifyUnfreezed实现 #19678
已合并
共 3 个文件变更+261-87
| @@ -975,7 +975,116 @@ private: | |||
| 975 | bool needReinstallExemptionList_ = true; | 975 | bool needReinstallExemptionList_ = true; |
| 976 | std::unordered_map<DisplayId, bool> hasPrivateWindowForeground_; | 976 | std::unordered_map<DisplayId, bool> hasPrivateWindowForeground_; |
| 977 | std::atomic<bool> isRecoveringDisplayMode_ = { false }; | 977 | std::atomic<bool> isRecoveringDisplayMode_ = { false }; |
| 978 | + void UpdateLastDisplayInfo(DisplayId displayId, sptr<DisplayInfo> displayInfo); | ||
| 979 | + struct UnfreezeNotifyContext { | ||
| 980 | + sptr<DisplayInfo> displayInfo; | ||
| 981 | + sptr<ScreenInfo> screenInfo; | ||
| 982 | + DMRect availableArea {}; | ||
| 983 | + std::vector<float> lastFoldAngles; | ||
| 984 | + ScreenChangeEvent lastScreenChangeEvent = ScreenChangeEvent::UNKNOWN; | ||
| 985 | + sptr<DisplayChangeInfo> lastDisplayChangeInfo; | ||
| 986 | + ScreenSessionManager* mgr; | ||
| 987 | + }; | ||
| 978 | 988 | ||
| 989 | + class UnfreezeTask { | ||
| 990 | + public: | ||
| 991 | + explicit UnfreezeTask(sptr<IDisplayManagerAgent> ag) : agent(ag) {} | ||
| 992 | + virtual ~UnfreezeTask() = default; | ||
| 993 | + virtual void Execute() = 0; | ||
| 994 | + protected: | ||
| 995 | + sptr<IDisplayManagerAgent> agent; | ||
| 996 | + }; | ||
| 997 | + | ||
| 998 | + class DisplayEventTask : public UnfreezeTask { | ||
| 999 | + public: | ||
| 1000 | + DisplayEventTask(sptr<IDisplayManagerAgent> ag, sptr<DisplayInfo> info) | ||
| 1001 | + : UnfreezeTask(ag), displayInfo(info) {} | ||
| 1002 | + void Execute() override; | ||
| 1003 | + private: | ||
| 1004 | + sptr<DisplayInfo> displayInfo; | ||
| 1005 | + }; | ||
| 1006 | + | ||
| 1007 | + class DisplayModeTask : public UnfreezeTask { | ||
| 1008 | + public: | ||
| 1009 | + DisplayModeTask(sptr<IDisplayManagerAgent> ag, FoldDisplayMode mode) | ||
| 1010 | + : UnfreezeTask(ag), displayMode(mode) {} | ||
| 1011 | + void Execute() override; | ||
| 1012 | + private: | ||
| 1013 | + FoldDisplayMode displayMode; | ||
| 1014 | + }; | ||
| 1015 | + | ||
| 1016 | + class FoldStatusTask : public UnfreezeTask { | ||
| 1017 | + public: | ||
| 1018 | + FoldStatusTask(sptr<IDisplayManagerAgent> ag, FoldStatus st) | ||
| 1019 | + : UnfreezeTask(ag), status(st) {} | ||
| 1020 | + void Execute() override; | ||
| 1021 | + private: | ||
| 1022 | + FoldStatus status; | ||
| 1023 | + }; | ||
| 1024 | + | ||
| 1025 | + class FoldAngleTask : public UnfreezeTask { | ||
| 1026 | + public: | ||
| 1027 | + FoldAngleTask(sptr<IDisplayManagerAgent> ag, const std::vector<float>& angles) | ||
| 1028 | + : UnfreezeTask(ag), foldAngles(angles) {} | ||
| 1029 | + void Execute() override; | ||
| 1030 | + private: | ||
| 1031 | + std::vector<float> foldAngles; | ||
| 1032 | + }; | ||
| 1033 | + | ||
| 1034 | + class ScreenEventTask : public UnfreezeTask { | ||
| 1035 | + public: | ||
| 1036 | + ScreenEventTask(sptr<IDisplayManagerAgent> ag, sptr<ScreenInfo> info, ScreenChangeEvent evt) | ||
| 1037 | + : UnfreezeTask(ag), screenInfo(info), event(evt) {} | ||
| 1038 | + void Execute() override; | ||
| 1039 | + private: | ||
| 1040 | + sptr<ScreenInfo> screenInfo; | ||
| 1041 | + ScreenChangeEvent event; | ||
| 1042 | + }; | ||
| 1043 | + | ||
| 1044 | + class DisplayUpdateTask : public UnfreezeTask { | ||
| 1045 | + public: | ||
| 1046 | + DisplayUpdateTask(sptr<IDisplayManagerAgent> ag, sptr<DisplayChangeInfo> info) | ||
| 1047 | + : UnfreezeTask(ag), displayChangeInfo(info) {} | ||
| 1048 | + void Execute() override; | ||
| 1049 | + private: | ||
| 1050 | + sptr<DisplayChangeInfo> displayChangeInfo; | ||
| 1051 | + }; | ||
| 1052 | + | ||
| 1053 | + class AvailableAreaTask : public UnfreezeTask { | ||
| 1054 | + public: | ||
| 1055 | + AvailableAreaTask(sptr<IDisplayManagerAgent> ag, DMRect rect, DisplayId id) | ||
| 1056 | + : UnfreezeTask(ag), area(rect), displayId(id) {} | ||
| 1057 | + void Execute() override; | ||
| 1058 | + private: | ||
| 1059 | + DMRect area; | ||
| 1060 | + DisplayId displayId; | ||
| 1061 | + }; | ||
| 1062 | + | ||
| 1063 | + class AttributeTask : public UnfreezeTask { | ||
| 1064 | + public: | ||
| 1065 | + AttributeTask(sptr<IDisplayManagerAgent> ag, sptr<DisplayInfo> info, | ||
| 1066 | + const std::vector<std::string>& attrs, DisplayId id, ScreenSessionManager* mgr) | ||
| 1067 | + : UnfreezeTask(ag), displayInfo(info), attributes(attrs), displayId(id), manager(mgr) {} | ||
| 1068 | + void Execute() override; | ||
| 1069 | + private: | ||
| 1070 | + sptr<DisplayInfo> displayInfo; | ||
| 1071 | + std::vector<std::string> attributes; | ||
| 1072 | + DisplayId displayId; | ||
| 1073 | + ScreenSessionManager* manager; | ||
| 1074 | + }; | ||
| 1075 | + void CollectUnfreezedAttributeTasks(int32_t pid, DisplayManagerAgentType agentType, | ||
| 1076 | + const UnfreezeNotifyContext& ctx, std::vector<std::unique_ptr<UnfreezeTask>>& tasks, | ||
| 1077 | + std::set<DisplayManagerAgentType>& pidAgentTypes); | ||
| 1078 | + void CollectUnfreezedAgentTasks(int32_t pid, DisplayManagerAgentType agentType, | ||
| 1079 | + const UnfreezeNotifyContext& ctx, std::vector<std::unique_ptr<UnfreezeTask>>& tasks, | ||
| 1080 | + std::set<DisplayManagerAgentType>& pidAgentTypes); | ||
| 1081 | + void CollectUnfreezedTasks(const std::set<int32_t>& unfreezedPidList, | ||
| 1082 | + const UnfreezeNotifyContext& ctx, std::vector<std::unique_ptr<UnfreezeTask>>& tasks, | ||
| 1083 | + std::vector<std::pair<int32_t, std::set<DisplayManagerAgentType>>>& logData, | ||
| 1084 | + std::map<int32_t, std::set<DisplayManagerAgentType>>& pidAgentTypeMap); | ||
| 1085 | + std::vector<std::unique_ptr<UnfreezeTask>> BuildUnfreezedTasks( | ||
| 1086 | + const std::set<int32_t>& unfreezedPidList, const UnfreezeNotifyContext& ctx, | ||
| 1087 | + std::map<int32_t, std::set<DisplayManagerAgentType>>& pidAgentTypeMap); | ||
| 979 | class ScreenIdManager { | 1088 | class ScreenIdManager { |
| 980 | friend class ScreenSessionGroup; | 1089 | friend class ScreenSessionGroup; |
| 981 | public: | 1090 | public: |
| @@ -14244,112 +14244,180 @@ DMError ScreenSessionManager::ProxyForFreeze(const std::set<int32_t>& pidList, b | |||
| 14244 | return DMError::DM_OK; | 14244 | return DMError::DM_OK; |
| 14245 | } | 14245 | } |
| 14246 | 14246 | ||
| 14247 | -void ScreenSessionManager::NotifyUnfreezedAttributeAgents(const int32_t& pid, const std::set<int32_t>& unfreezedPidList, | 14247 | +void ScreenSessionManager::DisplayEventTask::Execute() { agent->OnDisplayChange(displayInfo, DisplayChangeEvent::DISPLAY_UNFREEZED); } |
| 14248 | - const sptr<ScreenSession>& screenSession) | 14248 | +void ScreenSessionManager::DisplayModeTask::Execute() { agent->NotifyDisplayModeChanged(displayMode); } |
| 14249 | +void ScreenSessionManager::FoldStatusTask::Execute() { agent->NotifyFoldStatusChanged(status); } | ||
| 14250 | +void ScreenSessionManager::FoldAngleTask::Execute() { agent->NotifyFoldAngleChanged(foldAngles); } | ||
| 14251 | +void ScreenSessionManager::ScreenEventTask::Execute() { agent->OnScreenChange(screenInfo, event); } | ||
| 14252 | +void ScreenSessionManager::DisplayUpdateTask::Execute() { agent->NotifyDisplayChangeInfoChanged(displayChangeInfo); } | ||
| 14253 | +void ScreenSessionManager::AvailableAreaTask::Execute() { agent->NotifyAvailableAreaChanged(area, displayId); } | ||
| 14254 | +void ScreenSessionManager::AttributeTask::Execute() | ||
| 14249 | { | 14255 | { |
| 14250 | - auto attributeAgentsMap = ScreenSessionManagerAdapter::GetInstance().dmAttributeAgentContainer_.GetAttributeAgentsMap(); | 14256 | + agent->OnDisplayAttributeChange(displayInfo, attributes); |
| 14257 | + manager->UpdateLastDisplayInfo(displayId, displayInfo); | ||
| 14258 | +} | ||
| 14259 | + | ||
| 14260 | + | ||
| 14261 | +void ScreenSessionManager::CollectUnfreezedAttributeTasks(int32_t pid, DisplayManagerAgentType agentType, | ||
| 14262 | + const UnfreezeNotifyContext& ctx, std::vector<std::unique_ptr<ScreenSessionManager::UnfreezeTask>>& tasks, | ||
| 14263 | + std::set<DisplayManagerAgentType>& pidAgentTypes) | ||
| 14264 | +{ | ||
| 14265 | + auto displayInfo = ctx.displayInfo; | ||
| 14266 | + if (displayInfo == nullptr) { | ||
| 14267 | + TLOGNFE(WmsLogTag::DMS, "DisplayInfo is nullptr"); | ||
| 14268 | + return; | ||
| 14269 | + } | ||
| 14270 | + DisplayId displayId = displayInfo->GetDisplayId(); | ||
| 14271 | + sptr<DisplayInfo> lastDisplayInfo = new DisplayInfo(); | ||
| 14272 | + if (lastDisplayInfo == nullptr) { | ||
| 14273 | + TLOGNFE(WmsLogTag::DMS, "LastDisplayInfo of displayId: %{public}" PRIu64 "is nullptr", displayId); | ||
| 14274 | + return; | ||
| 14275 | + } | ||
| 14276 | + std::vector<std::string> attributes; | ||
| 14277 | + ctx.mgr->GetChangedListenableAttribute(lastDisplayInfo, displayInfo, attributes); | ||
| 14278 | + if (attributes.empty()) { | ||
| 14279 | + TLOGNFW(WmsLogTag::DMS, "No attribute changed"); | ||
| 14280 | + return; | ||
| 14281 | + } | ||
| 14282 | + auto attributeAgentsMap = | ||
| 14283 | + ScreenSessionManagerAdapter::GetInstance().dmAttributeAgentContainer_.GetAttributeAgentsMap(); | ||
| 14284 | + bool hasTask = false; | ||
| 14251 | for (auto& it : attributeAgentsMap) { | 14285 | for (auto& it : attributeAgentsMap) { |
| 14252 | auto agent = it.second.first; | 14286 | auto agent = it.second.first; |
| 14253 | - int32_t agentPid = ScreenSessionManagerAdapter::GetInstance().dmAttributeAgentContainer_.GetAgentPid(agent); | 14287 | + int32_t agentPid = |
| 14254 | - if (agent == nullptr|| agentPid != pid || unfreezedPidList.count(pid) == 0) { | 14288 | + ScreenSessionManagerAdapter::GetInstance().dmAttributeAgentContainer_.GetAgentPid(agent); |
| 14289 | + if (agent == nullptr || agentPid != pid) { | ||
| 14255 | continue; | 14290 | continue; |
| 14256 | } | 14291 | } |
| 14257 | - auto displayInfo = screenSession->ConvertToDisplayInfo(); | 14292 | + tasks.push_back(std::make_unique<AttributeTask>(agent, displayInfo, attributes, displayId, ctx.mgr)); |
| 14258 | - if (displayInfo == nullptr) { | 14293 | + hasTask = true; |
| 14259 | - TLOGNFE(WmsLogTag::DMS, "DisplayInfo is nullptr"); | 14294 | + } |
| 14260 | - continue; | 14295 | + if (hasTask) { |
| 14261 | - } | 14296 | + pidAgentTypes.erase(agentType); |
| 14262 | - std::vector<std::string> attributes; | ||
| 14263 | - DisplayId displayId = displayInfo->GetDisplayId(); | ||
| 14264 | - sptr<DisplayInfo> lastDisplayInfo = new DisplayInfo(); | ||
| 14265 | - if (lastDisplayInfo == nullptr) { | ||
| 14266 | - TLOGNFE(WmsLogTag::DMS, "LastDisplayInfo of displayId: %{public}" PRIu64 "is nullptr", displayId); | ||
| 14267 | - continue; | ||
| 14268 | - } | ||
| 14269 | - GetChangedListenableAttribute(lastDisplayInfo, displayInfo, attributes); | ||
| 14270 | - if (attributes.empty()) { | ||
| 14271 | - TLOGNFW(WmsLogTag::DMS, "No attribute changed"); | ||
| 14272 | - continue; | ||
| 14273 | - } | ||
| 14274 | - agent->OnDisplayAttributeChange(displayInfo, attributes); | ||
| 14275 | - pidAgentTypeMap_[pid].erase(DisplayManagerAgentType::DISPLAY_ATTRIBUTE_CHANGED_LISTENER); | ||
| 14276 | - std::lock_guard<std::mutex> lock(lastDisplayInfoMapMutex_); | ||
| 14277 | } | 14297 | } |
| 14278 | } | 14298 | } |
| 14279 | 14299 | ||
| 14280 | -void ScreenSessionManager::NotifyUnfreezedAgents(const int32_t& pid, const std::set<int32_t>& unfreezedPidList, | 14300 | +void ScreenSessionManager::CollectUnfreezedAgentTasks(int32_t pid, DisplayManagerAgentType agentType, |
| 14281 | - const std::set<DisplayManagerAgentType>& pidAgentTypes, const sptr<ScreenSession>& screenSession) | 14301 | + const UnfreezeNotifyContext& ctx, std::vector<std::unique_ptr<ScreenSessionManager::UnfreezeTask>>& tasks, |
| 14302 | + std::set<DisplayManagerAgentType>& pidAgentTypes) | ||
| 14282 | { | 14303 | { |
| 14283 | - bool isAgentTypeNotify = false; | 14304 | + auto agents = ScreenSessionManagerAdapter::GetInstance().dmAgentContainer_.GetAgentsByType(agentType); |
| 14284 | - for (auto agentType : pidAgentTypes) { | 14305 | + bool hasTask = false; |
| 14285 | - if (agentType == DisplayManagerAgentType::DISPLAY_ATTRIBUTE_CHANGED_LISTENER) { | 14306 | + for (auto agent : agents) { |
| 14286 | - NotifyUnfreezedAttributeAgents(pid, unfreezedPidList, screenSession); | 14307 | + int32_t agentPid = ScreenSessionManagerAdapter::GetInstance().dmAgentContainer_.GetAgentPid(agent); |
| 14308 | + if (agent == nullptr || agentPid != pid) { | ||
| 14287 | continue; | 14309 | continue; |
| 14288 | } | 14310 | } |
| 14289 | - auto agents = ScreenSessionManagerAdapter::GetInstance().dmAgentContainer_.GetAgentsByType(agentType); | 14311 | + hasTask = true; |
| 14290 | - for (auto agent : agents) { | 14312 | + if (agentType == DisplayManagerAgentType::DISPLAY_EVENT_LISTENER) { |
| 14291 | - int32_t agentPid = ScreenSessionManagerAdapter::GetInstance().dmAgentContainer_.GetAgentPid(agent); | 14313 | + tasks.push_back(std::make_unique<DisplayEventTask>(agent, ctx.displayInfo)); |
| 14292 | - if (agent == nullptr|| agentPid != pid || unfreezedPidList.count(pid) == 0) { | 14314 | + } else if (agentType == DisplayManagerAgentType::DISPLAY_MODE_CHANGED_LISTENER) { |
| 14293 | - continue; | 14315 | + tasks.push_back(std::make_unique<DisplayModeTask>(agent, ctx.mgr->GetFoldDisplayMode())); |
| 14294 | - } | 14316 | + } else if (agentType == DisplayManagerAgentType::FOLD_STATUS_CHANGED_LISTENER) { |
| 14295 | - isAgentTypeNotify = true; | 14317 | + tasks.push_back(std::make_unique<FoldStatusTask>(agent, ctx.mgr->GetFoldStatus())); |
| 14296 | - if (agentType == DisplayManagerAgentType::DISPLAY_EVENT_LISTENER) { | 14318 | + } else if (agentType == DisplayManagerAgentType::FOLD_ANGLE_CHANGED_LISTENER) { |
| 14297 | - agent->OnDisplayChange(screenSession->ConvertToDisplayInfo(), DisplayChangeEvent::DISPLAY_UNFREEZED); | 14319 | + tasks.push_back(std::make_unique<FoldAngleTask>(agent, ctx.lastFoldAngles)); |
| 14298 | - } else if (agentType == DisplayManagerAgentType::DISPLAY_MODE_CHANGED_LISTENER) { | 14320 | + } else if (agentType == DisplayManagerAgentType::SCREEN_EVENT_LISTENER) { |
| 14299 | - FoldDisplayMode displayMode = GetFoldDisplayMode(); | 14321 | + tasks.push_back(std::make_unique<ScreenEventTask>(agent, ctx.screenInfo, ctx.lastScreenChangeEvent)); |
| 14300 | - agent->NotifyDisplayModeChanged(displayMode); | 14322 | + } else if (agentType == DisplayManagerAgentType::DISPLAY_UPDATE_LISTENER) { |
| 14301 | - } else if (agentType == DisplayManagerAgentType::FOLD_STATUS_CHANGED_LISTENER) { | 14323 | + tasks.push_back(std::make_unique<DisplayUpdateTask>(agent, ctx.lastDisplayChangeInfo)); |
| 14302 | - FoldStatus foldStatus = GetFoldStatus(); | 14324 | + } else if (agentType == DisplayManagerAgentType::AVAILABLE_AREA_CHANGED_LISTENER) { |
| 14303 | - agent->NotifyFoldStatusChanged(foldStatus); | 14325 | + DisplayId displayId = ctx.displayInfo == nullptr ? DISPLAY_ID_INVALID : ctx.displayInfo->GetDisplayId(); |
| 14304 | - } else if (agentType == DisplayManagerAgentType::FOLD_ANGLE_CHANGED_LISTENER) { | 14326 | + tasks.push_back(std::make_unique<AvailableAreaTask>(agent, ctx.availableArea, displayId)); |
| 14305 | - std::lock_guard<std::mutex> lock(lastStatusUpdateMutex_); | 14327 | + } else { |
| 14306 | - agent->NotifyFoldAngleChanged(lastFoldAngles_); | 14328 | + hasTask = false; |
| 14307 | - } else if (agentType == DisplayManagerAgentType::SCREEN_EVENT_LISTENER) { | 14329 | + TLOGNFI(WmsLogTag::DMS, "Unknown agentType."); |
| 14308 | - auto displayInfo = screenSession->ConvertToDisplayInfo(); | 14330 | + } |
| 14309 | - auto screenInfo = GetScreenInfoById(displayInfo->GetScreenId()); | 14331 | + } |
| 14310 | - std::lock_guard<std::mutex> lock(lastStatusUpdateMutex_); | 14332 | + if (hasTask) { |
| 14311 | - agent->OnScreenChange(screenInfo, lastScreenChangeEvent_); | 14333 | + pidAgentTypes.erase(agentType); |
| 14312 | - } else if (agentType == DisplayManagerAgentType::DISPLAY_UPDATE_LISTENER) { | 14334 | + } |
| 14313 | - std::lock_guard<std::mutex> lock(lastStatusUpdateMutex_); | 14335 | +} |
| 14314 | - agent->NotifyDisplayChangeInfoChanged(lastDisplayChangeInfo_); | 14336 | + |
| 14315 | - } else if (agentType == DisplayManagerAgentType::AVAILABLE_AREA_CHANGED_LISTENER) { | 14337 | +void ScreenSessionManager::CollectUnfreezedTasks(const std::set<int32_t>& unfreezedPidList, |
| 14316 | - auto area = screenSession->GetAvailableArea(); | 14338 | + const UnfreezeNotifyContext& ctx, std::vector<std::unique_ptr<ScreenSessionManager::UnfreezeTask>>& tasks, |
| 14317 | - auto displayId = screenSession->ConvertToDisplayInfo()->GetDisplayId(); | 14339 | + std::vector<std::pair<int32_t, std::set<DisplayManagerAgentType>>>& logData, |
| 14318 | - std::lock_guard<std::mutex> lock(lastStatusUpdateMutex_); | 14340 | + std::map<int32_t, std::set<DisplayManagerAgentType>>& pidAgentTypeMap) |
| 14319 | - agent->NotifyAvailableAreaChanged(area, displayId); | 14341 | +{ |
| 14342 | + std::lock_guard<std::mutex> lock(ctx.mgr->freezedPidListMutex_); | ||
| 14343 | + for (auto iter = pidAgentTypeMap.begin(); iter != pidAgentTypeMap.end();) { | ||
| 14344 | + int32_t pid = iter->first; | ||
| 14345 | + if (unfreezedPidList.count(pid) == 0) { | ||
| 14346 | + ++iter; | ||
| 14347 | + continue; | ||
| 14348 | + } | ||
| 14349 | + auto& pidAgentTypes = iter->second; | ||
| 14350 | + logData.push_back({pid, pidAgentTypes}); | ||
| 14351 | + | ||
| 14352 | + auto agentTypesCopy = pidAgentTypes; | ||
| 14353 | + for (auto agentType : agentTypesCopy) { | ||
| 14354 | + if (agentType == DisplayManagerAgentType::DISPLAY_ATTRIBUTE_CHANGED_LISTENER) { | ||
| 14355 | + CollectUnfreezedAttributeTasks(pid, agentType, ctx, tasks, pidAgentTypes); | ||
| 14320 | } else { | 14356 | } else { |
| 14321 | - isAgentTypeNotify = false; | 14357 | + CollectUnfreezedAgentTasks(pid, agentType, ctx, tasks, pidAgentTypes); |
| 14322 | - TLOGNFI(WmsLogTag::DMS, "Unknown agentType."); | ||
| 14323 | } | 14358 | } |
| 14324 | } | 14359 | } |
| 14325 | - if (isAgentTypeNotify) { | 14360 | + if (pidAgentTypes.empty()) { |
| 14326 | - pidAgentTypeMap_[pid].erase(agentType); | 14361 | + iter = pidAgentTypeMap.erase(iter); |
| 14362 | + } else { | ||
| 14363 | + ++iter; | ||
| 14327 | } | 14364 | } |
| 14328 | } | 14365 | } |
| 14329 | } | 14366 | } |
| 14330 | 14367 | ||
| 14368 | +void LogUnfreezedInfo(const std::vector<std::pair<int32_t, std::set<DisplayManagerAgentType>>>& logData) | ||
| 14369 | +{ | ||
| 14370 | + std::string result = "pid,type:"; | ||
| 14371 | + for (auto& entry : logData) { | ||
| 14372 | + result.append(std::to_string(entry.first)).append(","); | ||
| 14373 | + for (auto type : entry.second) { | ||
| 14374 | + result.append(std::to_string(static_cast<int32_t>(type))).append(" "); | ||
| 14375 | + } | ||
| 14376 | + result.append("|"); | ||
| 14377 | + } | ||
| 14378 | + TLOGNFW(WmsLogTag::DMS, "%{public}s", result.c_str()); | ||
| 14379 | +} | ||
| 14380 | + | ||
| 14381 | +std::vector<std::unique_ptr<ScreenSessionManager::UnfreezeTask>> ScreenSessionManager::BuildUnfreezedTasks( | ||
| 14382 | + const std::set<int32_t>& unfreezedPidList, | ||
| 14383 | + const UnfreezeNotifyContext& ctx, | ||
| 14384 | + std::map<int32_t, std::set<DisplayManagerAgentType>>& pidAgentTypeMap) | ||
| 14385 | +{ | ||
| 14386 | + std::vector<std::unique_ptr<ScreenSessionManager::UnfreezeTask>> tasks; | ||
| 14387 | + std::vector<std::pair<int32_t, std::set<DisplayManagerAgentType>>> logData; | ||
| 14388 | + CollectUnfreezedTasks(unfreezedPidList, ctx, tasks, logData, pidAgentTypeMap); | ||
| 14389 | + LogUnfreezedInfo(logData); | ||
| 14390 | + return tasks; | ||
| 14391 | +} | ||
| 14392 | + | ||
| 14393 | + | ||
| 14331 | void ScreenSessionManager::NotifyUnfreezed(const std::set<int32_t>& unfreezedPidList, | 14394 | void ScreenSessionManager::NotifyUnfreezed(const std::set<int32_t>& unfreezedPidList, |
| 14332 | const sptr<ScreenSession>& screenSession) | 14395 | const sptr<ScreenSession>& screenSession) |
| 14333 | { | 14396 | { |
| 14334 | - std::lock_guard<std::mutex> lock(freezedPidListMutex_); | 14397 | + UnfreezeNotifyContext ctx; |
| 14335 | - std::ostringstream oss; | 14398 | + ctx.mgr = this; |
| 14336 | - oss << "pid,type:"; | 14399 | + ctx.displayInfo = screenSession->ConvertToDisplayInfo(); |
| 14337 | - for (auto iter = pidAgentTypeMap_.begin(); iter != pidAgentTypeMap_.end();) { | 14400 | + if (ctx.displayInfo != nullptr) { |
| 14338 | - int32_t pid = iter->first; | 14401 | + ctx.screenInfo = GetScreenInfoById(ctx.displayInfo->GetScreenId()); |
| 14339 | - auto pidAgentTypes = iter->second; | 14402 | + ctx.availableArea = screenSession->GetAvailableArea(); |
| 14340 | - NotifyUnfreezedAgents(pid, unfreezedPidList, pidAgentTypes, screenSession); | ||
| 14341 | - if (pidAgentTypeMap_[pid].empty()) { | ||
| 14342 | - iter = pidAgentTypeMap_.erase(iter); | ||
| 14343 | - } else { | ||
| 14344 | - iter++; | ||
| 14345 | - } | ||
| 14346 | - oss << pid << ","; | ||
| 14347 | - for (auto type : pidAgentTypes) { | ||
| 14348 | - oss << static_cast<int32_t>(type) << " "; | ||
| 14349 | - } | ||
| 14350 | - oss << "|"; | ||
| 14351 | } | 14403 | } |
| 14352 | - TLOGNFW(WmsLogTag::DMS, "%{public}s", oss.str().c_str()); | 14404 | + { |
| 14405 | + std::lock_guard<std::mutex> lock(lastStatusUpdateMutex_); | ||
| 14406 | + ctx.lastFoldAngles = lastFoldAngles_; | ||
| 14407 | + ctx.lastScreenChangeEvent = lastScreenChangeEvent_; | ||
| 14408 | + ctx.lastDisplayChangeInfo = lastDisplayChangeInfo_; | ||
| 14409 | + } | ||
| 14410 | + | ||
| 14411 | + auto tasks = BuildUnfreezedTasks(unfreezedPidList, ctx, pidAgentTypeMap_); | ||
| 14412 | + for (auto& task : tasks) { | ||
| 14413 | + task->Execute(); | ||
| 14414 | + } | ||
| 14415 | +} | ||
| 14416 | + | ||
| 14417 | +void ScreenSessionManager::UpdateLastDisplayInfo(DisplayId displayId, sptr<DisplayInfo> displayInfo) | ||
| 14418 | +{ | ||
| 14419 | + std::lock_guard<std::mutex> lock(lastDisplayInfoMapMutex_); | ||
| 14420 | + lastDisplayInfoMap_[displayId] = displayInfo; | ||
| 14353 | } | 14421 | } |
| 14354 | 14422 | ||
| 14355 | DMError ScreenSessionManager::ResetAllFreezeStatus() | 14423 | DMError ScreenSessionManager::ResetAllFreezeStatus() |
| @@ -790,10 +790,7 @@ HWTEST_F(ScreenSessionManagerTest, ProxyForFreeze, TestSize.Level1) | |||
| 790 | std::set<DisplayManagerAgentType> pidAgentTypes = {DisplayManagerAgentType::SCREEN_EVENT_LISTENER}; | 790 | std::set<DisplayManagerAgentType> pidAgentTypes = {DisplayManagerAgentType::SCREEN_EVENT_LISTENER}; |
| 791 | ScreenId screenId = 1050; | 791 | ScreenId screenId = 1050; |
| 792 | sptr<ScreenSession> screenSession = new (std::nothrow) ScreenSession(screenId, ScreenProperty(), 0); | 792 | sptr<ScreenSession> screenSession = new (std::nothrow) ScreenSession(screenId, ScreenProperty(), 0); |
| 793 | - ssm_->NotifyUnfreezedAgents(pid, unfreezedPidList, pidAgentTypes, screenSession); | ||
| 794 | - | ||
| 795 | ssm_->NotifyUnfreezed(unfreezedPidList, screenSession); | 793 | ssm_->NotifyUnfreezed(unfreezedPidList, screenSession); |
| 796 | - | ||
| 797 | std::set<int32_t> pidList = {1, 2, 3}; | 794 | std::set<int32_t> pidList = {1, 2, 3}; |
| 798 | DMError ret = ssm_->ProxyForFreeze(pidList, true); | 795 | DMError ret = ssm_->ProxyForFreeze(pidList, true); |
| 799 | ASSERT_EQ(ret, DMError::DM_OK); | 796 | ASSERT_EQ(ret, DMError::DM_OK); |