1 /*
2 * Copyright (c) 2023 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 #include "scene_input_manager.h"
17
18 #include <hitrace_meter.h>
19 #include "perform_reporter.h"
20 #include "scene_session_dirty_manager.h"
21 #include "screen_session_manager_client/include/screen_session_manager_client.h"
22 #include "session_manager/include/scene_session_manager.h"
23
24 namespace OHOS {
25 namespace Rosen {
26
27 namespace {
28 constexpr HiviewDFX::HiLogLabel LABEL = { LOG_CORE, HILOG_DOMAIN_WINDOW, "SceneInputManager" };
29 const std::string SCENE_INPUT_MANAGER_THREAD = "SceneInputManager";
30 const std::string FLUSH_DISPLAY_INFO_THREAD = "OS_FlushDisplayInfoThread";
31
32 constexpr int MAX_WINDOWINFO_NUM = 15;
33 constexpr int DEFALUT_DISPLAYID = 0;
34 constexpr int EMPTY_FOCUS_WINDOW_ID = -1;
35 constexpr int INVALID_PERSISTENT_ID = 0;
36 constexpr int DEFAULT_SCREEN_POS = 0;
37 constexpr int DEFAULT_SCREEN_SCALE = 100;
38 constexpr int DEFAULT_EXPAND_HEIGHT = 0;
39
40 bool IsEqualUiExtentionWindowInfo(const std::vector<MMI::WindowInfo>& a, const std::vector<MMI::WindowInfo>& b);
41 constexpr unsigned int TRANSFORM_DATA_LEN = 9;
42
operator !=(const MMI::Rect & a,const MMI::Rect & b)43 bool operator!=(const MMI::Rect& a, const MMI::Rect& b)
44 {
45 if (a.x != b.x || a.y != b.y || a.width != b.width || a.height != b.height) {
46 return true;
47 }
48 return false;
49 }
50
operator ==(const MMI::DisplayInfo & a,const MMI::DisplayInfo & b)51 bool operator==(const MMI::DisplayInfo& a, const MMI::DisplayInfo& b)
52 {
53 if (a.id != b.id || a.x != b.x || a.y != b.y || a.width != b.width ||
54 a.height != b.height || a.dpi != b.dpi || a.name != b.name || a.uniq != b.uniq ||
55 static_cast<int32_t>(a.direction) != static_cast<int32_t>(b.direction) ||
56 static_cast<int32_t>(a.displayDirection) != static_cast<int32_t>(b.displayDirection) ||
57 static_cast<int32_t>(a.displayMode) != static_cast<int32_t>(b.displayMode) ||
58 a.transform != b.transform) {
59 return false;
60 }
61 return true;
62 }
63
operator !=(const std::vector<float> & a,const std::vector<float> & b)64 bool operator!=(const std::vector<float>& a, const std::vector<float>& b)
65 {
66 if (a.size() != b.size()) {
67 return true;
68 }
69 int sizeOfA = static_cast<int>(a.size());
70 for (int index = 0; index < sizeOfA; index++) {
71 if (a[index] != b[index]) {
72 return true;
73 }
74 }
75 return false;
76 }
77
IsEqualWindowInfo(const MMI::WindowInfo & a,const MMI::WindowInfo & b)78 bool IsEqualWindowInfo(const MMI::WindowInfo& a, const MMI::WindowInfo& b)
79 {
80 if (a.id != b.id || a.pid != b.pid || a.uid != b.uid || a.agentWindowId != b.agentWindowId || a.flags != b.flags ||
81 a.displayId != b.displayId || a.zOrder != b.zOrder) {
82 return false;
83 }
84
85 if (a.windowInputType != b.windowInputType || a.privacyMode != b.privacyMode ||
86 a.windowType != b.windowType || a.pixelMap != b.pixelMap) {
87 return false;
88 }
89 return true;
90 }
91
operator ==(const MMI::WindowInfo & a,const MMI::WindowInfo & b)92 bool operator==(const MMI::WindowInfo& a, const MMI::WindowInfo& b)
93 {
94 if (!IsEqualWindowInfo(a, b)) {
95 return false;
96 }
97
98 if (a.area != b.area || a.defaultHotAreas.size() != b.defaultHotAreas.size() ||
99 a.pointerHotAreas.size() != b.pointerHotAreas.size() ||
100 a.pointerChangeAreas.size() != b.pointerChangeAreas.size() || a.transform.size() != b.transform.size()) {
101 return false;
102 }
103
104 int sizeOfDefaultHotAreas = static_cast<int>(a.defaultHotAreas.size());
105 for (int index = 0; index < sizeOfDefaultHotAreas; index++) {
106 if (a.defaultHotAreas[index] != b.defaultHotAreas[index]) {
107 return false;
108 }
109 }
110 int sizeOfPointerHotAreas = static_cast<int>(a.pointerHotAreas.size());
111 for (int index = 0; index < sizeOfPointerHotAreas; index++) {
112 if (a.pointerHotAreas[index] != b.pointerHotAreas[index]) {
113 return false;
114 }
115 }
116 int sizeOfPointerChangeAreas = static_cast<int>(a.pointerChangeAreas.size());
117 for (int index = 0; index < sizeOfPointerChangeAreas; index++) {
118 if (a.pointerChangeAreas[index] != b.pointerChangeAreas[index]) {
119 return false;
120 }
121 }
122
123 if (a.transform != b.transform) {
124 return false;
125 }
126 if (!IsEqualUiExtentionWindowInfo(a.uiExtentionWindowInfo, b.uiExtentionWindowInfo)) {
127 return false;
128 }
129 return true;
130 }
131
operator !=(const MMI::WindowInfo & a,const MMI::WindowInfo & b)132 bool operator!=(const MMI::WindowInfo& a, const MMI::WindowInfo& b)
133 {
134 if (a == b) {
135 return false;
136 }
137 return true;
138 }
139
IsEqualUiExtentionWindowInfo(const std::vector<MMI::WindowInfo> & a,const std::vector<MMI::WindowInfo> & b)140 bool IsEqualUiExtentionWindowInfo(const std::vector<MMI::WindowInfo>& a, const std::vector<MMI::WindowInfo>& b)
141 {
142 if (a.size() != b.size()) {
143 return false;
144 }
145 int size = static_cast<int>(a.size());
146 for (int i = 0; i < size; i++) {
147 if (a[i] != b[i]) {
148 return false;
149 }
150 }
151 return true;
152 }
153
DumpTransformInDisplayInfo(const std::vector<float> & transform)154 std::string DumpTransformInDisplayInfo(const std::vector<float>& transform)
155 {
156 std::stringstream stream("[");
157 for (float transformItem : transform) {
158 stream << transformItem << ",";
159 }
160 stream << "]";
161 return stream.str();
162 }
163
DumpDisplayInfo(const MMI::DisplayInfo & info)164 std::string DumpDisplayInfo(const MMI::DisplayInfo& info)
165 {
166 std::ostringstream infoStream("DisplayInfo: ");
167 infoStream << " id: " << info.id << " x: " << info.x << " y: " << info.y
168 << " width: " << info.width << " height: " << info.height << " dpi: " << info.dpi
169 << " name: " << info.name << " uniq: " << info.uniq
170 << " displayMode: " << static_cast<int>(info.displayMode)
171 << " direction: " << static_cast<int>(info.direction)
172 << " transform: " << DumpTransformInDisplayInfo(info.transform);
173 std::string infoStr = infoStream.str();
174 return infoStr;
175 }
176 } //namespace
177
178
WM_IMPLEMENT_SINGLE_INSTANCE(SceneInputManager)179 WM_IMPLEMENT_SINGLE_INSTANCE(SceneInputManager)
180
181 void SceneInputManager::Init()
182 {
183 sceneSessionDirty_ = std::make_shared<SceneSessionDirtyManager>();
184 eventLoop_ = AppExecFwk::EventRunner::Create(FLUSH_DISPLAY_INFO_THREAD);
185 eventHandler_ = std::make_shared<AppExecFwk::EventHandler>(eventLoop_);
186 SceneSession::RegisterGetConstrainedModalExtWindowInfo(
187 [](const sptr<SceneSession>& sceneSession) -> std::optional<ExtensionWindowEventInfo> {
188 return SceneInputManager::GetInstance().GetConstrainedModalExtWindowInfo(sceneSession);
189 });
190 }
191
RegisterFlushWindowInfoCallback(FlushWindowInfoCallback && callback)192 void SceneInputManager::RegisterFlushWindowInfoCallback(FlushWindowInfoCallback&& callback)
193 {
194 sceneSessionDirty_->RegisterFlushWindowInfoCallback(std::move(callback));
195 }
196
ResetSessionDirty()197 void SceneInputManager::ResetSessionDirty()
198 {
199 sceneSessionDirty_->ResetSessionDirty();
200 }
201
GetFullWindowInfoList()202 auto SceneInputManager::GetFullWindowInfoList() ->
203 std::pair<std::vector<MMI::WindowInfo>, std::vector<std::shared_ptr<Media::PixelMap>>>
204 {
205 return sceneSessionDirty_->GetFullWindowInfoList();
206 }
207
ConstructDisplayInfos(std::vector<MMI::DisplayInfo> & displayInfos)208 void SceneInputManager::ConstructDisplayInfos(std::vector<MMI::DisplayInfo>& displayInfos)
209 {
210 std::map<ScreenId, ScreenProperty> screensProperties =
211 ScreenSessionManagerClient::GetInstance().GetAllScreensProperties();
212 if (screensProperties.empty()) {
213 TLOGE(WmsLogTag::WMS_EVENT, "screensProperties is empty");
214 return;
215 }
216 auto displayMode = ScreenSessionManagerClient::GetInstance().GetFoldDisplayMode();
217 for (auto& [screenId, screenProperty] : screensProperties) {
218 auto screenSession = ScreenSessionManagerClient::GetInstance().GetScreenSessionById(screenId);
219 if (screenSession == nullptr) {
220 TLOGE(WmsLogTag::WMS_EVENT, "screenSession get failed, screenId: %{public}" PRIu64"", screenId);
221 continue;
222 }
223 auto screenCombination = screenSession->GetScreenCombination();
224 auto screenWidth = screenProperty.GetPhysicalTouchBounds().rect_.GetWidth();
225 auto screenHeight = screenProperty.GetPhysicalTouchBounds().rect_.GetHeight();
226 auto transform = Matrix3f::IDENTITY;
227 Vector2f scale(screenProperty.GetScaleX(), screenProperty.GetScaleY());
228 transform = transform.Scale(scale, screenProperty.GetPivotX() * screenWidth,
229 screenProperty.GetPivotY() * screenHeight).Inverse();
230 std::vector<float> transformData(transform.GetData(), transform.GetData() + TRANSFORM_DATA_LEN);
231 int32_t screenOneHandX = DEFAULT_SCREEN_POS;
232 int32_t screenOneHandY = DEFAULT_SCREEN_POS;
233 int32_t scalePercent = DEFAULT_SCREEN_SCALE;
234 int32_t expandHeight = DEFAULT_EXPAND_HEIGHT;
235 const SingleHandScreenInfo& singleHandScreenInfo = SceneSessionManager::GetInstance().GetSingleHandScreenInfo();
236 if (screenId == ScreenSessionManagerClient::GetInstance().GetDefaultScreenId() &&
237 singleHandScreenInfo.mode != SingleHandMode::MIDDLE) {
238 SingleHandTransform singleHandTransform = SceneSessionManager::GetInstance().GetNormalSingleHandTransform();
239 WSRect originRect = SceneSessionManager::GetInstance().GetOriginRect();
240 screenOneHandX = singleHandTransform.posX;
241 screenOneHandY = singleHandTransform.posY;
242 scalePercent = singleHandTransform.scaleX * DEFAULT_SCREEN_SCALE;
243 expandHeight = screenProperty.GetBounds().rect_.GetHeight() - originRect.height_;
244 }
245 MMI::DisplayInfo displayInfo = {
246 .id = screenId,
247 .x = screenProperty.GetStartX(),
248 .y = screenProperty.GetStartY(),
249 .width = screenWidth,
250 .height = screenHeight,
251 .dpi = screenProperty.GetDensity() * DOT_PER_INCH,
252 .name = "display" + std::to_string(screenId),
253 .uniq = "default" + std::to_string(screenId),
254 .direction = ConvertDegreeToMMIRotation(screenProperty.GetPhysicalRotation()),
255 .displayDirection = ConvertDegreeToMMIRotation(screenProperty.GetScreenComponentRotation()),
256 .displayMode = static_cast<MMI::DisplayMode>(displayMode),
257 .transform = transformData,
258 .offsetX = screenProperty.GetInputOffsetX(),
259 .offsetY = screenProperty.GetInputOffsetY(),
260 .ppi = screenProperty.GetXDpi(),
261 .isCurrentOffScreenRendering = screenProperty.GetCurrentOffScreenRendering(),
262 .screenRealWidth = screenProperty.GetScreenRealWidth(),
263 .screenRealHeight = screenProperty.GetScreenRealHeight(),
264 .screenRealPPI = screenProperty.GetScreenRealPPI(),
265 .screenRealDPI = static_cast<int32_t>(screenProperty.GetScreenRealDPI()),
266 .screenCombination = static_cast<MMI::ScreenCombination>(screenCombination),
267 .oneHandX = screenOneHandX,
268 .oneHandY = screenOneHandY,
269 .scalePercent = scalePercent,
270 .expandHeight = expandHeight,
271 .validWidth = screenProperty.GetValidWidth(),
272 .validHeight = screenProperty.GetValidHeight(),
273 .fixedDirection = ConvertDegreeToMMIRotation(screenProperty.GetDefaultDeviceRotationOffset()),
274 .physicalWidth = screenProperty.GetPhyWidth(),
275 .physicalHeight = screenProperty.GetPhyHeight(),
276 .pointerActiveWidth = screenProperty.GetPointerActiveWidth(),
277 .pointerActiveHeight = screenProperty.GetPointerActiveHeight()
278 };
279 displayInfos.emplace_back(displayInfo);
280 }
281 }
282
FlushFullInfoToMMI(const std::vector<MMI::DisplayInfo> & displayInfos,const std::vector<MMI::WindowInfo> & windowInfoList)283 void SceneInputManager::FlushFullInfoToMMI(const std::vector<MMI::DisplayInfo>& displayInfos,
284 const std::vector<MMI::WindowInfo>& windowInfoList)
285 {
286 int mainScreenWidth = 0;
287 int mainScreenHeight = 0;
288 if (!displayInfos.empty()) {
289 mainScreenWidth = displayInfos[0].width;
290 mainScreenHeight = displayInfos[0].height;
291 }
292 MMI::DisplayGroupInfo displayGroupInfo = {
293 .width = mainScreenWidth,
294 .height = mainScreenHeight,
295 .focusWindowId = focusedSessionId_,
296 .currentUserId = currentUserId_,
297 .windowsInfo = windowInfoList,
298 .displaysInfo = displayInfos};
299 for (const auto& displayInfo : displayGroupInfo.displaysInfo) {
300 TLOGD(WmsLogTag::WMS_EVENT, "[EventDispatch] - %{public}s", DumpDisplayInfo(displayInfo).c_str());
301 }
302 std::string windowInfoListDump = "windowinfo ";
303 for (const auto& windowInfo : displayGroupInfo.windowsInfo) {
304 windowInfoListDump.append(DumpWindowInfo(windowInfo).append(" || "));
305 }
306 TLOGD(WmsLogTag::WMS_EVENT, "[EventDispatch] - %{public}s", windowInfoListDump.c_str());
307 MMI::InputManager::GetInstance()->UpdateDisplayInfo(displayGroupInfo);
308 }
309
FlushEmptyInfoToMMI()310 void SceneInputManager::FlushEmptyInfoToMMI()
311 {
312 auto task = [this]() {
313 std::vector<MMI::DisplayInfo> displayInfos;
314 ConstructDisplayInfos(displayInfos);
315 int mainScreenWidth = 0;
316 int mainScreenHeight = 0;
317 if (!displayInfos.empty()) {
318 mainScreenWidth = displayInfos[0].width;
319 mainScreenHeight = displayInfos[0].height;
320 }
321 MMI::DisplayGroupInfo displayGroupInfo = {
322 .width = mainScreenWidth,
323 .height = mainScreenHeight,
324 .focusWindowId = EMPTY_FOCUS_WINDOW_ID,
325 .currentUserId = currentUserId_,
326 .displaysInfo = displayInfos
327 };
328 TLOGI(WmsLogTag::WMS_EVENT, "userId:%{public}d width:%{public}d height:%{public}d",
329 currentUserId_, mainScreenWidth, mainScreenHeight);
330 MMI::InputManager::GetInstance()->UpdateDisplayInfo(displayGroupInfo);
331 };
332 if (eventHandler_) {
333 eventHandler_->PostTask(task);
334 }
335 }
336
NotifyWindowInfoChange(const sptr<SceneSession> & sceneSession,const WindowUpdateType & type)337 void SceneInputManager::NotifyWindowInfoChange(const sptr<SceneSession>& sceneSession, const WindowUpdateType& type)
338 {
339 if (sceneSessionDirty_) {
340 sceneSessionDirty_->NotifyWindowInfoChange(sceneSession, type);
341 }
342 }
343
NotifyMMIWindowPidChange(const sptr<SceneSession> & sceneSession,const bool startMoving)344 void SceneInputManager::NotifyMMIWindowPidChange(const sptr<SceneSession>& sceneSession, const bool startMoving)
345 {
346 if (sceneSessionDirty_) {
347 sceneSessionDirty_->NotifyWindowInfoChange(sceneSession,
348 WindowUpdateType::WINDOW_UPDATE_PROPERTY, startMoving);
349 if (sceneSession == nullptr) {
350 return;
351 }
352 sceneSession->SetIsStartMoving(startMoving);
353 }
354 }
355
NotifyWindowInfoChangeFromSession(const sptr<SceneSession> & sceneSesion)356 void SceneInputManager::NotifyWindowInfoChangeFromSession(const sptr<SceneSession>& sceneSesion)
357 {
358 if (sceneSessionDirty_) {
359 sceneSessionDirty_->NotifyWindowInfoChange(sceneSesion, WindowUpdateType::WINDOW_UPDATE_PROPERTY);
360 } else {
361 TLOGD(WmsLogTag::WMS_EVENT, "sceneSessionDirty is nullptr");
362 }
363 }
364
FlushChangeInfoToMMI(const std::map<uint64_t,std::vector<MMI::WindowInfo>> & screenId2Windows)365 void SceneInputManager::FlushChangeInfoToMMI(const std::map<uint64_t, std::vector<MMI::WindowInfo>>& screenId2Windows)
366 {
367 for (auto& iter : screenId2Windows) {
368 auto displayId = iter.first;
369 auto& windowInfos = iter.second;
370 std::string windowInfoListDump = "windowinfo ";
371 for (auto& windowInfo : windowInfos) {
372 windowInfoListDump.append(DumpWindowInfo(windowInfo).append(" || "));
373 }
374 TLOGD(WmsLogTag::WMS_EVENT, "[EventDispatch] --- %{public}s", windowInfoListDump.c_str());
375 MMI::WindowGroupInfo windowGroup = {focusedSessionId_, displayId, windowInfos};
376 MMI::InputManager::GetInstance()->UpdateWindowInfo(windowGroup);
377 }
378 }
379
CheckNeedUpdate(const std::vector<MMI::DisplayInfo> & displayInfos,const std::vector<MMI::WindowInfo> & windowInfoList)380 bool SceneInputManager::CheckNeedUpdate(const std::vector<MMI::DisplayInfo>& displayInfos,
381 const std::vector<MMI::WindowInfo>& windowInfoList)
382 {
383 int32_t focusId = SceneSessionManager::GetInstance().GetFocusedSessionId();
384 if (focusId != lastFocusId_) {
385 lastFocusId_ = focusId;
386 lastDisplayInfos_ = displayInfos;
387 lastWindowInfoList_ = windowInfoList;
388 return true;
389 }
390
391 if (displayInfos.size() != lastDisplayInfos_.size() || windowInfoList.size() != lastWindowInfoList_.size()) {
392 lastDisplayInfos_ = displayInfos;
393 lastWindowInfoList_ = windowInfoList;
394 return true;
395 }
396
397 int sizeOfDisplayInfos = static_cast<int>(displayInfos.size());
398 for (int index = 0; index < sizeOfDisplayInfos; index++) {
399 if (!(displayInfos[index] == lastDisplayInfos_[index])) {
400 lastDisplayInfos_ = displayInfos;
401 lastWindowInfoList_ = windowInfoList;
402 return true;
403 }
404 }
405
406 int sizeOfWindowInfoList = static_cast<int>(windowInfoList.size());
407 for (int index = 0; index < sizeOfWindowInfoList; index++) {
408 if (!(windowInfoList[index] == lastWindowInfoList_[index])) {
409 lastWindowInfoList_ = windowInfoList;
410 return true;
411 }
412 }
413 return false;
414 }
415
UpdateFocusedSessionId(int32_t focusedSessionId)416 void SceneInputManager::UpdateFocusedSessionId(int32_t focusedSessionId)
417 {
418 auto focusedSceneSession = SceneSessionManager::GetInstance().GetSceneSession(focusedSessionId);
419 if (focusedSceneSession == nullptr) {
420 TLOGE(WmsLogTag::WMS_EVENT, "focusedSceneSession is null");
421 return;
422 }
423 if (auto modalUIExtensionEventInfo = focusedSceneSession->GetLastModalUIExtensionEventInfo()) {
424 focusedSessionId_ = modalUIExtensionEventInfo.value().persistentId;
425 }
426 }
427
DumpUIExtentionWindowInfo(const MMI::WindowInfo & windowInfo)428 void DumpUIExtentionWindowInfo(const MMI::WindowInfo& windowInfo)
429 {
430 auto sceneSession = SceneSessionManager::GetInstance().GetSceneSession(windowInfo.id);
431 if (sceneSession == nullptr) {
432 TLOGE(WmsLogTag::WMS_EVENT, "sceneSession is null");
433 return;
434 }
435 auto surfaceNode = sceneSession->GetSurfaceNode();
436 if (surfaceNode == nullptr) {
437 TLOGE(WmsLogTag::WMS_EVENT, "surfaceNode is null");
438 return;
439 }
440 auto surfaceId = surfaceNode->GetId();
441 TLOGI(WmsLogTag::WMS_EVENT, "wid:%{public}d sid:%{public}" PRIu64 " uiExtWindowInfo:%{public}d",
442 windowInfo.id, surfaceId, static_cast<int>(windowInfo.uiExtentionWindowInfo.size()));
443 for (const auto& uiExtWindowInfo : windowInfo.uiExtentionWindowInfo) {
444 auto str = DumpWindowInfo(uiExtWindowInfo);
445 str = "sec:" + std::to_string(uiExtWindowInfo.privacyUIFlag) + " " + str;
446 TLOGI(WmsLogTag::WMS_EVENT, "uiExtWindowInfo:%{public}s", str.c_str());
447 }
448 }
449
PrintWindowInfo(const std::vector<MMI::WindowInfo> & windowInfoList)450 void SceneInputManager::PrintWindowInfo(const std::vector<MMI::WindowInfo>& windowInfoList)
451 {
452 int windowListSize = static_cast<int>(windowInfoList.size());
453 std::ostringstream idListStream;
454 static std::string lastIdList;
455 static uint32_t windowEventID = 0;
456 if (windowEventID == UINT32_MAX) {
457 windowEventID = 0;
458 }
459 focusedSessionId_ = SceneSessionManager::GetInstance().GetFocusedSessionId();
460 std::unordered_map<int32_t, MMI::Rect> currWindowDefaultHotArea;
461 static std::unordered_map<int32_t, MMI::Rect> lastWindowDefaultHotArea;
462 for (auto& e : windowInfoList) {
463 idListStream << e.id << "|" << e.flags << "|" << e.zOrder << "|"
464 << e.pid << "|" << e.defaultHotAreas.size();
465
466 if (e.defaultHotAreas.size() > 0) {
467 auto iter = lastWindowDefaultHotArea.find(e.id);
468 if (iter == lastWindowDefaultHotArea.end() || iter->second != e.defaultHotAreas[0]) {
469 idListStream << "|" << e.defaultHotAreas[0].x << "|" << e.defaultHotAreas[0].y
470 << "|" << e.defaultHotAreas[0].width << "|" << e.defaultHotAreas[0].height;
471 }
472 currWindowDefaultHotArea.insert({e.id, e.defaultHotAreas[0]});
473 }
474 idListStream << ",";
475 if ((focusedSessionId_ == e.id) && (e.id == e.agentWindowId)) {
476 UpdateFocusedSessionId(focusedSessionId_);
477 }
478 if (e.uiExtentionWindowInfo.size() > 0) {
479 DumpUIExtentionWindowInfo(e);
480 }
481 }
482 lastWindowDefaultHotArea = currWindowDefaultHotArea;
483 SingleHandTransform transform = SceneSessionManager::GetInstance().GetNormalSingleHandTransform();
484 idListStream << focusedSessionId_ << "|" << transform.posX << "|" << transform.posY
485 << "|" << transform.scaleX << "|" << transform.scaleY;
486 std::string idList = idListStream.str();
487 if (lastIdList != idList) {
488 windowEventID++;
489 TLOGNI(WmsLogTag::WMS_EVENT, "LogWinInfo: eid:%{public}d,size:%{public}d,idList:%{public}s",
490 windowEventID, windowListSize, idList.c_str());
491 lastIdList = idList;
492 }
493 }
494
PrintDisplayInfo(const std::vector<MMI::DisplayInfo> & displayInfos)495 void SceneInputManager::PrintDisplayInfo(const std::vector<MMI::DisplayInfo>& displayInfos)
496 {
497 int displayListSize = static_cast<int>(displayInfos.size());
498 std::ostringstream displayListStream;
499 static std::string lastDisplayList = "";
500 for (auto& displayInfo : displayInfos) {
501 displayListStream << displayInfo.id << "|" << displayInfo.x << "|" << displayInfo.y << "|"
502 << displayInfo.width << "|" << displayInfo.height << "|"
503 << static_cast<int32_t>(displayInfo.direction) << "|"
504 << static_cast<int32_t>(displayInfo.displayDirection) << "|"
505 << static_cast<int32_t>(displayInfo.displayMode) << "|"
506 << displayInfo.offsetX << "|" << displayInfo.offsetY << "|"
507 << displayInfo.isCurrentOffScreenRendering << "|"
508 << displayInfo.screenRealWidth << "|" << displayInfo.screenRealHeight << "|"
509 << displayInfo.screenRealPPI << "|" << displayInfo.screenRealDPI << "|"
510 << static_cast<int32_t>(displayInfo.screenCombination) << "|"
511 << displayInfo.validWidth << "|" << displayInfo.validHeight << "|"
512 << displayInfo.fixedDirection << "|" << displayInfo.physicalWidth << "|"
513 << displayInfo.physicalHeight << "|" << displayInfo.oneHandX << "|"
514 << displayInfo.oneHandY << "|" << displayInfo.scalePercent << "|"
515 << displayInfo.expandHeight << ",";
516 }
517
518 std::string displayList = displayListStream.str();
519 if (lastDisplayList != displayList) {
520 TLOGI(WmsLogTag::WMS_EVENT, "num:%{public}d,list:%{public}s", displayListSize, displayList.c_str());
521 lastDisplayList = displayList;
522 }
523 }
524
SetUserBackground(bool userBackground)525 void SceneInputManager::SetUserBackground(bool userBackground)
526 {
527 TLOGD(WmsLogTag::WMS_MULTI_USER, "userBackground=%{public}d", userBackground);
528 isUserBackground_.store(userBackground);
529 }
530
SetCurrentUserId(int32_t userId)531 void SceneInputManager::SetCurrentUserId(int32_t userId)
532 {
533 TLOGD(WmsLogTag::WMS_MULTI_USER, "Current userId=%{public}d", userId);
534 currentUserId_ = userId;
535 MMI::InputManager::GetInstance()->SetCurrentUser(userId);
536 }
537
UpdateDisplayAndWindowInfo(const std::vector<MMI::DisplayInfo> & displayInfos,std::vector<MMI::WindowInfo> windowInfoList)538 void SceneInputManager::UpdateDisplayAndWindowInfo(const std::vector<MMI::DisplayInfo>& displayInfos,
539 std::vector<MMI::WindowInfo> windowInfoList)
540 {
541 if (windowInfoList.size() == 0) {
542 return;
543 }
544 int32_t windowBatchSize = MAX_WINDOWINFO_NUM;
545 if (windowInfoList[0].defaultHotAreas.size() > MMI::WindowInfo::DEFAULT_HOTAREA_COUNT) {
546 windowBatchSize = MMI::InputManager::GetInstance()->GetWinSyncBatchSize(
547 static_cast<int32_t>(windowInfoList[0].defaultHotAreas.size()),
548 static_cast<int32_t>(displayInfos.size()));
549 }
550 windowInfoList.back().action = MMI::WINDOW_UPDATE_ACTION::ADD_END;
551 int32_t windowListSize = static_cast<int32_t>(windowInfoList.size());
552 if (windowListSize <= windowBatchSize) {
553 FlushFullInfoToMMI(displayInfos, windowInfoList);
554 return;
555 }
556 auto iterBegin = windowInfoList.begin();
557 auto iterEnd = windowInfoList.end();
558 auto iterNext = std::next(iterBegin, windowBatchSize);
559 FlushFullInfoToMMI(displayInfos, std::vector<MMI::WindowInfo>(iterBegin, iterNext));
560 while (iterNext != iterEnd) {
561 auto iterNewBegin = iterNext;
562 if (iterNewBegin->defaultHotAreas.size() <= MMI::WindowInfo::DEFAULT_HOTAREA_COUNT) {
563 windowBatchSize = MAX_WINDOWINFO_NUM;
564 }
565 if (std::distance(iterNewBegin, iterEnd) <= windowBatchSize) {
566 iterNext = iterEnd;
567 } else {
568 iterNext = std::next(iterNewBegin, windowBatchSize);
569 }
570 std::map<uint64_t, std::vector<MMI::WindowInfo>> screenToWindowInfoList;
571 screenToWindowInfoList.emplace(DEFALUT_DISPLAYID, std::vector<MMI::WindowInfo>(iterNewBegin, iterNext));
572 FlushChangeInfoToMMI(screenToWindowInfoList);
573 }
574 }
575
FlushDisplayInfoToMMI(std::vector<MMI::WindowInfo> && windowInfoList,std::vector<std::shared_ptr<Media::PixelMap>> && pixelMapList,const bool forceFlush)576 void SceneInputManager::FlushDisplayInfoToMMI(std::vector<MMI::WindowInfo>&& windowInfoList,
577 std::vector<std::shared_ptr<Media::PixelMap>>&& pixelMapList,
578 const bool forceFlush)
579 {
580 eventHandler_->PostTask([this, windowInfoList = std::move(windowInfoList),
581 pixelMapList = std::move(pixelMapList), forceFlush]() {
582 HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "FlushDisplayInfoToMMI");
583 if (isUserBackground_.load()) {
584 TLOGND(WmsLogTag::WMS_MULTI_USER, "User in background, no need to flush display info");
585 return;
586 }
587 if (sceneSessionDirty_ == nullptr) {
588 TLOGNE(WmsLogTag::WMS_EVENT, "sceneSessionDirty_ is nullptr");
589 return;
590 }
591 std::vector<MMI::DisplayInfo> displayInfos;
592 ConstructDisplayInfos(displayInfos);
593 if (displayInfos.empty()) {
594 std::ostringstream oss;
595 oss << "displayInfos flush to MMI is empty!";
596 int32_t ret = WindowInfoReporter::GetInstance().ReportEventDispatchException(
597 static_cast<int32_t>(WindowDFXHelperType::WINDOW_FLUSH_EMPTY_DISPLAY_INFO_TO_MMI_EXCEPTION),
598 getpid(), oss.str()
599 );
600 if (ret != 0) {
601 TLOGNI(WmsLogTag::WMS_EVENT, "ReportEventDispatchException message failed, ret: %{public}d", ret);
602 }
603 }
604 if (!forceFlush && !CheckNeedUpdate(displayInfos, windowInfoList)) {
605 return;
606 }
607 PrintDisplayInfo(displayInfos);
608 PrintWindowInfo(windowInfoList);
609 if (windowInfoList.size() == 0) {
610 FlushFullInfoToMMI(displayInfos, windowInfoList);
611 return;
612 }
613 UpdateDisplayAndWindowInfo(displayInfos, std::move(windowInfoList));
614 });
615 }
616
UpdateSecSurfaceInfo(const std::map<uint64_t,std::vector<SecSurfaceInfo>> & secSurfaceInfoMap)617 void SceneInputManager::UpdateSecSurfaceInfo(const std::map<uint64_t, std::vector<SecSurfaceInfo>>& secSurfaceInfoMap)
618 {
619 if (sceneSessionDirty_ == nullptr) {
620 TLOGE(WmsLogTag::WMS_EVENT, "sceneSessionDirty_ is nullptr");
621 return;
622 }
623 sceneSessionDirty_->UpdateSecSurfaceInfo(secSurfaceInfoMap);
624 }
625
UpdateConstrainedModalUIExtInfo(const std::map<uint64_t,std::vector<SecSurfaceInfo>> & constrainedModalUIExtInfoMap)626 void SceneInputManager::UpdateConstrainedModalUIExtInfo(
627 const std::map<uint64_t, std::vector<SecSurfaceInfo>>& constrainedModalUIExtInfoMap)
628 {
629 if (sceneSessionDirty_ == nullptr) {
630 TLOGE(WmsLogTag::WMS_EVENT, "sceneSessionDirty_ is nullptr");
631 return;
632 }
633 sceneSessionDirty_->UpdateConstrainedModalUIExtInfo(constrainedModalUIExtInfoMap);
634 }
635
GetConstrainedModalExtWindowInfo(const sptr<SceneSession> & sceneSession)636 std::optional<ExtensionWindowEventInfo> SceneInputManager::GetConstrainedModalExtWindowInfo(
637 const sptr<SceneSession>& sceneSession)
638 {
639 if (sceneSession == nullptr) {
640 TLOGE(WmsLogTag::WMS_EVENT, "sceneSession is nullptr");
641 return std::nullopt;
642 }
643 if (sceneSessionDirty_ == nullptr) {
644 TLOGE(WmsLogTag::WMS_EVENT, "sceneSessionDirty_ is nullptr");
645 return std::nullopt;
646 }
647 SecSurfaceInfo constrainedModalUIExtInfo;
648 if (!sceneSessionDirty_->GetLastConstrainedModalUIExtInfo(sceneSession, constrainedModalUIExtInfo)) {
649 return std::nullopt;
650 }
651 auto persistentId = sceneSession->GetUIExtPersistentIdBySurfaceNodeId(constrainedModalUIExtInfo.uiExtensionNodeId);
652 if (persistentId == INVALID_PERSISTENT_ID) {
653 TLOGE(WmsLogTag::WMS_EVENT, "invalid persistentId");
654 return std::nullopt;
655 }
656 return ExtensionWindowEventInfo {
657 .persistentId = persistentId,
658 .pid = constrainedModalUIExtInfo.uiExtensionPid,
659 .isConstrainedModal = true };
660 }
661 }
662 } // namespace OHOS::Rosen
663