From 104ebf7025885c03c0c7511e4fe855c8035d73cd Mon Sep 17 00:00:00 2001 From: xingyanan Date: Sun, 16 Jan 2022 18:47:51 +0800 Subject: [PATCH 01/57] Signed-off-by: xingyanan Change-Id: Ic9c83bacd701ef22f6e4827430406f7f2cef1df1 --- wm/test/systemtest/BUILD.gn | 20 +++- wm/test/systemtest/window_split_test.cpp | 140 +++++++++++++++++++++++ wmserver/include/window_node_container.h | 8 +- wmserver/src/window_inner_manager.cpp | 2 - wmserver/src/window_node_container.cpp | 47 +++++--- wmserver/src/window_root.cpp | 3 +- 6 files changed, 192 insertions(+), 28 deletions(-) create mode 100644 wm/test/systemtest/window_split_test.cpp diff --git a/wm/test/systemtest/BUILD.gn b/wm/test/systemtest/BUILD.gn index 84b5b6172a..c5c734397b 100644 --- a/wm/test/systemtest/BUILD.gn +++ b/wm/test/systemtest/BUILD.gn @@ -9,7 +9,7 @@ # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and -# limitations under the License. +# limitations under the License. import("//build/test.gni") @@ -19,6 +19,7 @@ group("systemtest") { testonly = true deps = [ + ":wm_window_split_test", ":wm_window_immersive_test", ":wm_window_layout_test", ":wm_window_multi_ability_test", @@ -35,7 +36,7 @@ ohos_systemtest("wm_window_layout_test") { deps = [ ":wm_systemtest_common" ] } -## SystemTest wm_window_layout_test }}} +## SystemTest wm_window_layout_test }}} ## SystemTest wm_window_multi_ability_test {{{ ohos_systemtest("wm_window_multi_ability_test") { @@ -46,7 +47,7 @@ ohos_systemtest("wm_window_multi_ability_test") { deps = [ ":wm_systemtest_common" ] } -## SystemTest wm_window_multi_ability_test }}} +## SystemTest wm_window_multi_ability_test }}} ## SystemTest wm_window_subwindow_test {{{ ohos_systemtest("wm_window_subwindow_test") { @@ -57,7 +58,7 @@ ohos_systemtest("wm_window_subwindow_test") { deps = [ ":wm_systemtest_common" ] } -## SystemTest wm_window_subwindow_test }}} +## SystemTest wm_window_subwindow_test }}} ## SystemTest wm_window_immersive_test {{{ ohos_systemtest("wm_window_immersive_test") { @@ -70,6 +71,17 @@ ohos_systemtest("wm_window_immersive_test") { ## SystemTest wm_window_immersive_test }}} +## SystemTest wm_window_split_test {{{ +ohos_systemtest("wm_window_split_test") { + module_out_path = module_out_path + + sources = [ "window_split_test.cpp" ] + + deps = [ ":wm_systemtest_common" ] +} + +## SystemTest wm_window_split_test }}} + ## Build wm_systemtest_common.a {{{ config("wm_systemtest_common_public_config") { include_dirs = [ diff --git a/wm/test/systemtest/window_split_test.cpp b/wm/test/systemtest/window_split_test.cpp new file mode 100644 index 0000000000..453e4a90d1 --- /dev/null +++ b/wm/test/systemtest/window_split_test.cpp @@ -0,0 +1,140 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// gtest +#include +#include "window_test_utils.h" +using namespace testing; +using namespace testing::ext; + +namespace OHOS { +namespace Rosen { +using utils = WindowTestUtils; +class WindowSplitTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + virtual void SetUp() override; + virtual void TearDown() override; + std::vector> activeWindows_; +}; + +void WindowSplitTest::SetUpTestCase() +{ + +} + +void WindowSplitTest::TearDownTestCase() +{ +} + +void WindowSplitTest::SetUp() +{ + activeWindows_.clear(); +} + +void WindowSplitTest::TearDown() +{ + while (!activeWindows_.empty()) { + ASSERT_EQ(WMError::WM_OK, activeWindows_.back()->Destroy()); + activeWindows_.pop_back(); + } +} + +namespace { + +/** + * @tc.name: SplitWindow01 + * @tc.desc: one primary window and one fullscreen window + * @tc.type: FUNC + * @tc.require: AR000GGTV7 + */ +HWTEST_F(WindowSplitTest, SplitWindow01, Function | MediumTest | Level3) +{ + utils::TestWindowInfo infoFullScreen = { + .name = "fullscreen.1", + .rect = utils::defaultAppRect_, + .type = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, + .mode = WindowMode::WINDOW_MODE_FULLSCREEN, + .needAvoid = true, + .parentLimit = false, + .parentName = "", + }; + utils::TestWindowInfo infoPrimary = { + .name = "primary.1", + .rect = utils::defaultAppRect_, + .type = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, + .mode = WindowMode::WINDOW_MODE_SPLIT_PRIMARY, + .needAvoid = true, + .parentLimit = false, + .parentName = "", + }; + const sptr& windowFullScreen = utils::CreateTestWindow(infoFullScreen); + ASSERT_EQ(WMError::WM_OK, windowFullScreen->Show()); + + activeWindows_.push_back(windowFullScreen); + const sptr& windowPrimary = utils::CreateTestWindow(infoPrimary); + ASSERT_EQ(WMError::WM_OK, windowPrimary->Show()); + ASSERT_EQ(WindowMode::WINDOW_MODE_SPLIT_PRIMARY, windowPrimary->GetMode()); + activeWindows_.push_back(windowPrimary); + // show one split primary window + ASSERT_EQ(WindowMode::WINDOW_MODE_SPLIT_SECONDARY, windowFullScreen->GetMode()); + ASSERT_EQ(WMError::WM_OK, windowPrimary->Hide()); + ASSERT_EQ(WindowMode::WINDOW_MODE_FULLSCREEN, windowFullScreen->GetMode()); + ASSERT_EQ(WMError::WM_OK, windowFullScreen->Hide()); +} + +/** + * @tc.name: SplitWindow02 + * @tc.desc: one secondary window and one fullscreen window + * @tc.type: FUNC + * @tc.require: AR000GGTV7 + */ +HWTEST_F(WindowSplitTest, SplitWindow02, Function | MediumTest | Level3) +{ + utils::TestWindowInfo infoFullScreen = { + .name = "fullscreen.2", + .rect = utils::defaultAppRect_, + .type = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, + .mode = WindowMode::WINDOW_MODE_FULLSCREEN, + .needAvoid = true, + .parentLimit = false, + .parentName = "", + }; + utils::TestWindowInfo infoPrimary = { + .name = "secondary.2", + .rect = utils::defaultAppRect_, + .type = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, + .mode = WindowMode::WINDOW_MODE_SPLIT_SECONDARY, + .needAvoid = true, + .parentLimit = false, + .parentName = "", + }; + const sptr& windowFullScreen = utils::CreateTestWindow(infoFullScreen); + ASSERT_EQ(WMError::WM_OK, windowFullScreen->Show()); + activeWindows_.push_back(windowFullScreen); + const sptr& windowSecondary = utils::CreateTestWindow(infoPrimary); + ASSERT_EQ(WMError::WM_OK, windowSecondary->Show()); + ASSERT_EQ(WindowMode::WINDOW_MODE_SPLIT_SECONDARY, windowSecondary->GetMode()); + activeWindows_.push_back(windowSecondary); + // show one split primary window + ASSERT_EQ(WindowMode::WINDOW_MODE_SPLIT_PRIMARY, windowFullScreen->GetMode()); + ASSERT_EQ(WMError::WM_OK, windowFullScreen->Hide()); + ASSERT_EQ(WindowMode::WINDOW_MODE_FULLSCREEN, windowSecondary->GetMode()); + ASSERT_EQ(WMError::WM_OK, windowSecondary->Hide()); +} +} +} // namespace Rosen +} // namespace OHOS diff --git a/wmserver/include/window_node_container.h b/wmserver/include/window_node_container.h index c50759273b..ba9349b50e 100644 --- a/wmserver/include/window_node_container.h +++ b/wmserver/include/window_node_container.h @@ -52,7 +52,7 @@ public: Rect GetDisplayRect() const; sptr GetTopImmersiveNode() const; void NotifySystemBarIfChanged(); - void HandleSplitWindowModeChange(sptr& triggerNode, bool isChangeToSplit); + WMError HandleSplitWindowModeChange(sptr& triggerNode, bool isChangeToSplit); std::shared_ptr GetDisplayNode() const; void LayoutDividerWindow(sptr& node); void UpdateDisplayInfo(); @@ -87,9 +87,9 @@ private: void SendSplitScreenEvent(WindowMode mode); sptr FindSplitPairNode(sptr& node) const; - void HandleModeChangeToSplit(sptr& triggerNode); - void HandleModeChangeFromSplit(sptr& triggerNode); - void UpdateWindowPairInfo(sptr& triggerNode, sptr& pairNode); + WMError HandleModeChangeToSplit(sptr& triggerNode); + WMError HandleModeChangeFromSplit(sptr& triggerNode); + WMError UpdateWindowPairInfo(sptr& triggerNode, sptr& pairNode); sptr zorderPolicy_ = new WindowZorderPolicy(); sptr belowAppWindowNode_ = new WindowNode(); diff --git a/wmserver/src/window_inner_manager.cpp b/wmserver/src/window_inner_manager.cpp index 4f13b95c0c..29b71e7476 100644 --- a/wmserver/src/window_inner_manager.cpp +++ b/wmserver/src/window_inner_manager.cpp @@ -187,7 +187,6 @@ void WindowInnerManager::HandleMessage() void WindowInnerManager::SendMessage(InnerWMCmd cmdType, uint32_t displayId) { - std::unique_lock lk(mutex_); if (!hasInitThread_) { WLOGFI("Inner window manager thread has not been created"); return; @@ -204,7 +203,6 @@ void WindowInnerManager::SendMessage(InnerWMCmd cmdType, uint32_t displayId) void WindowInnerManager::SendMessage(InnerWMCmd cmdType, uint32_t displayId, const Rect& dividerRect) { - std::unique_lock lk(mutex_); if (!hasInitThread_) { WLOGFI("Inner window manager thread has not been created"); return; diff --git a/wmserver/src/window_node_container.cpp b/wmserver/src/window_node_container.cpp index 210f40cc30..2f917d2aeb 100644 --- a/wmserver/src/window_node_container.cpp +++ b/wmserver/src/window_node_container.cpp @@ -115,9 +115,12 @@ WMError WindowNodeContainer::AddWindowNode(sptr& node, sptrparent_ = parentNode; if (node->IsSplitMode()) { - HandleSplitWindowModeChange(node, true); + WMError ret = HandleSplitWindowModeChange(node, true); + if (ret != WMError::WM_OK) { + WLOGFE("Add split window failed!"); + return ret; + } } - UpdateWindowTree(node); UpdateRSTree(node, true); AssignZOrder(); @@ -226,9 +229,12 @@ WMError WindowNodeContainer::RemoveWindowNode(sptr& node) } if (node->IsSplitMode()) { - HandleSplitWindowModeChange(node, false); + WMError ret = HandleSplitWindowModeChange(node, false); + if (ret != WMError::WM_OK) { + WLOGFE("Remove split window failed!"); + return ret; + } } - UpdateRSTree(node, false); UpdateFocusWindow(); layoutPolicy_->RemoveWindowNode(node); @@ -589,23 +595,27 @@ sptr WindowNodeContainer::FindSplitPairNode(sptr& trigge return nullptr; } -void WindowNodeContainer::HandleModeChangeToSplit(sptr& triggerNode) +WMError WindowNodeContainer::HandleModeChangeToSplit(sptr& triggerNode) { WM_FUNCTION_TRACE(); WLOGFI("HandleModeChangeToSplit %{public}d", triggerNode->GetWindowId()); auto pairNode = FindSplitPairNode(triggerNode); if (pairNode != nullptr) { WLOGFI("Window %{public}d find pair %{public}d", triggerNode->GetWindowId(), pairNode->GetWindowId()); - UpdateWindowPairInfo(triggerNode, pairNode); + WMError ret = UpdateWindowPairInfo(triggerNode, pairNode); + if (ret != WMError::WM_OK) { + return ret; + } } else { // sent split event displayRects_->SetSplitRect(DEFAULT_SPLIT_RATIO); SendSplitScreenEvent(triggerNode->GetWindowMode()); } UpdateDisplayInfo(); + return WMError::WM_OK; } -void WindowNodeContainer::HandleModeChangeFromSplit(sptr& triggerNode) +WMError WindowNodeContainer::HandleModeChangeFromSplit(sptr& triggerNode) { WLOGFI("HandleModeChangeFromSplit %{public}d", triggerNode->GetWindowId()); if (pairedWindowMap_.find(triggerNode->GetWindowId()) != pairedWindowMap_.end()) { @@ -614,7 +624,7 @@ void WindowNodeContainer::HandleModeChangeFromSplit(sptr& triggerNod pairNode->GetWindowProperty()->ResumeLastWindowMode(); pairNode->GetWindowToken()->UpdateWindowMode(pairNode->GetWindowMode()); triggerNode->GetWindowProperty()->ResumeLastWindowMode(); - triggerNode->GetWindowToken()->UpdateWindowMode(pairNode->GetWindowMode()); + triggerNode->GetWindowToken()->UpdateWindowMode(triggerNode->GetWindowMode()); pairedWindowMap_.erase(pairNode->GetWindowId()); pairedWindowMap_.erase(triggerNode->GetWindowId()); WLOGFI("Split out, Id[%{public}d, %{public}d], Mode[%{public}d, %{public}d]", @@ -622,22 +632,21 @@ void WindowNodeContainer::HandleModeChangeFromSplit(sptr& triggerNod triggerNode->GetWindowMode(), pairNode->GetWindowMode()); } else { WLOGFE("Split out, but can not find pair in map %{public}d", triggerNode->GetWindowId()); + return WMError::WM_ERROR_INVALID_WINDOW; } if (pairedWindowMap_.empty()) { + WLOGFI("Notify devider to destroy"); SingletonContainer::Get().SendMessage(INNER_WM_DESTROY_DIVIDER, screenId_); } + return WMError::WM_OK; } -void WindowNodeContainer::HandleSplitWindowModeChange(sptr& triggerNode, bool isChangeToSplit) +WMError WindowNodeContainer::HandleSplitWindowModeChange(sptr& triggerNode, bool isChangeToSplit) { - if (isChangeToSplit) { - HandleModeChangeToSplit(triggerNode); - } else { - HandleModeChangeFromSplit(triggerNode); - } + return isChangeToSplit ? HandleModeChangeToSplit(triggerNode) : HandleModeChangeFromSplit(triggerNode); } -void WindowNodeContainer::UpdateWindowPairInfo(sptr& triggerNode, sptr& pairNode) +WMError WindowNodeContainer::UpdateWindowPairInfo(sptr& triggerNode, sptr& pairNode) { float splitRatio = DEFAULT_SPLIT_RATIO; WindowMode triggerMode = triggerNode->GetWindowMode(); @@ -647,7 +656,11 @@ void WindowNodeContainer::UpdateWindowPairInfo(sptr& triggerNode, sp WindowMode::WINDOW_MODE_SPLIT_SECONDARY : WindowMode::WINDOW_MODE_SPLIT_PRIMARY; pairNode->SetWindowMode(pairDstMode); pairNode->GetWindowToken()->UpdateWindowMode(pairDstMode); - layoutPolicy_->AddWindowNode(pairNode); + WMError ret = UpdateWindowNode(pairNode); + if (ret != WMError::WM_OK) { + WLOGFE("Update window pair info failed"); + return ret; + } WLOGFI("Pair FullScreen [%{public}d, %{public}d], Mode[%{public}d, %{public}d], splitRatio = %{public}f", triggerNode->GetWindowId(), pairNode->GetWindowId(), triggerMode, pairDstMode, splitRatio); } else { @@ -671,8 +684,10 @@ void WindowNodeContainer::UpdateWindowPairInfo(sptr& triggerNode, sp pairedWindowMap_.insert(std::pair(pairNode->GetWindowId(), {triggerNode, 1 - splitRatio})); displayRects_->SetSplitRect(splitRatio); + WLOGFI("Notify devider to create"); Rect dividerRect = displayRects_->GetDividerRect(); SingletonContainer::Get().SendMessage(INNER_WM_CREATE_DIVIDER, screenId_, dividerRect); + return WMError::WM_OK; } } } diff --git a/wmserver/src/window_root.cpp b/wmserver/src/window_root.cpp index 5e99d2312b..2676de0530 100644 --- a/wmserver/src/window_root.cpp +++ b/wmserver/src/window_root.cpp @@ -192,8 +192,7 @@ WMError WindowRoot::HandleSplitWindowModeChange(sptr& node, bool isS WLOGFE("HandleSplitWindowModeChange failed, window container could not be found"); return WMError::WM_ERROR_NULLPTR; } - container->HandleSplitWindowModeChange(node, isSplitIn); - return WMError::WM_OK; + return container->HandleSplitWindowModeChange(node, isSplitIn); } WMError WindowRoot::DestroyWindow(uint32_t windowId) -- Gitee From a85a09d6bc505bcdf0968635c87f2540fe773d75 Mon Sep 17 00:00:00 2001 From: luwei Date: Sun, 16 Jan 2022 17:29:29 +0800 Subject: [PATCH 02/57] modify screenshot Signed-off-by: luwei Change-Id: I338f93413c1c434c63cb762d14690afd3d8ddf55 --- dm/src/display_manager.cpp | 51 ++++++++++++++++------- interfaces/innerkits/dm/display_manager.h | 7 ++-- snapshot/BUILD.gn | 2 +- snapshot/snapshot_display.cpp | 12 +++++- snapshot/snapshot_utils.cpp | 21 ++++++---- snapshot/snapshot_utils.h | 2 + 6 files changed, 64 insertions(+), 31 deletions(-) diff --git a/dm/src/display_manager.cpp b/dm/src/display_manager.cpp index 43a63319db..ae251e5b33 100644 --- a/dm/src/display_manager.cpp +++ b/dm/src/display_manager.cpp @@ -68,17 +68,34 @@ std::shared_ptr DisplayManager::GetScreenshot(DisplayId display return screenShot; } -bool DisplayManager::CheckRectOffsetValid(int32_t param) const +bool DisplayManager::CheckRectValid(const Media::Rect &rect, int32_t oriHeight, int32_t oriWidth) const { - if (param < 0 || param > MAX_RESOLUTION_VALUE) { + if (!((rect.left >= 0) and (rect.left < oriWidth) and (rect.top >= 0) and (rect.top < oriHeight))) { + WLOGFE("CheckRectValid rect left top invalid!"); return false; } + + if (!((rect.width > 0) and (rect.width <= (oriWidth - rect.left)) and + (rect.height > 0) and (rect.height <= (oriHeight - rect.top)))) { + if (!((rect.width == 0) and (rect.height == 0))) { + WLOGFE("CheckRectValid rect height width invalid!"); + return false; + } + } return true; } -bool DisplayManager::CheckRectSizeValid(int32_t param) const +bool DisplayManager::CheckSizeValid(const Media::Size &size, int32_t oriHeight, int32_t oriWidth) { - if (param < MIN_RESOLUTION_VALUE || param > MAX_RESOLUTION_VALUE) { + if (!((size.width > 0) and (size.height > 0))) { + if (!((size.width == 0) and (size.height == 0))) { + WLOGFE("CheckSizeValid width height invalid!"); + return false; + } + } + + if ((size.width > MAX_RESOLUTION_SIZE_SCREENSHOT) or (size.height > MAX_RESOLUTION_SIZE_SCREENSHOT)) { + WLOGFE("CheckSizeValid width and height too big!"); return false; } return true; @@ -91,16 +108,7 @@ std::shared_ptr DisplayManager::GetScreenshot(DisplayId display WLOGFE("displayId invalid!"); return nullptr; } - if (!CheckRectOffsetValid(rect.left) || !CheckRectOffsetValid(rect.top) || - !CheckRectSizeValid(rect.width) || !CheckRectSizeValid(rect.height)) { - WLOGFE("rect invalid! left %{public}d, top %{public}d, w %{public}d, h %{public}d", - rect.left, rect.top, rect.width, rect.height); - return nullptr; - } - if (!CheckRectSizeValid(size.width) || !CheckRectSizeValid(size.height)) { - WLOGFE("size invalid! w %{public}d, h %{public}d", rect.width, rect.height); - return nullptr; - } + std::shared_ptr screenShot = SingletonContainer::Get().GetDisplaySnapshot(displayId); if (screenShot == nullptr) { @@ -108,14 +116,25 @@ std::shared_ptr DisplayManager::GetScreenshot(DisplayId display return nullptr; } + // check parameters + int32_t oriHeight = screenShot->GetHeight(); + int32_t oriWidth = screenShot->GetWidth(); + if (!CheckRectValid(rect, oriHeight, oriWidth)) { + WLOGFE("rect invalid! left %{public}d, top %{public}d, w %{public}d, h %{public}d", + rect.left, rect.top, rect.width, rect.height); + return nullptr; + } + if (!CheckSizeValid(size, oriHeight, oriWidth)) { + WLOGFE("size invalid! w %{public}d, h %{public}d", rect.width, rect.height); + return nullptr; + } + // create crop dest pixelmap Media::InitializationOptions opt; opt.size.width = size.width; opt.size.height = size.height; opt.scaleMode = Media::ScaleMode::FIT_TARGET_SIZE; opt.editable = false; - opt.useSourceIfMatch = true; - auto pixelMap = Media::PixelMap::Create(*screenShot, rect, opt); if (pixelMap == nullptr) { WLOGFE("Media::PixelMap::Create failed!"); diff --git a/interfaces/innerkits/dm/display_manager.h b/interfaces/innerkits/dm/display_manager.h index 80f1c1f1d8..4a820e7950 100644 --- a/interfaces/innerkits/dm/display_manager.h +++ b/interfaces/innerkits/dm/display_manager.h @@ -69,13 +69,12 @@ public: private: DisplayManager(); ~DisplayManager(); - bool CheckRectOffsetValid(int32_t param) const; - bool CheckRectSizeValid(int32_t param) const; + bool CheckRectValid(const Media::Rect &rect, int32_t oriHeight, int32_t oriWidth) const; + bool CheckSizeValid(const Media::Size &size, int32_t oriHeight, int32_t oriWidth); void NotifyDisplayPowerEvent(DisplayPowerEvent event, EventStatus status); static inline SingletonDelegator delegator; - const int32_t MAX_RESOLUTION_VALUE = 15260; // max resolution, 16K - const int32_t MIN_RESOLUTION_VALUE = 16; // min resolution + const int32_t MAX_RESOLUTION_SIZE_SCREENSHOT = 15360; // max resolution, 16K std::mutex mutex_; std::vector> powerEventListeners_; sptr powerEventListenerAgent_; diff --git a/snapshot/BUILD.gn b/snapshot/BUILD.gn index 947e0af375..43dc106c83 100644 --- a/snapshot/BUILD.gn +++ b/snapshot/BUILD.gn @@ -19,7 +19,7 @@ config("snapshot_config") { } ohos_executable("snapshot_display") { - install_enable = false + install_enable = true sources = [ "snapshot_display.cpp", "snapshot_utils.cpp", diff --git a/snapshot/snapshot_display.cpp b/snapshot/snapshot_display.cpp index 40a64d2d1b..12f522ad81 100644 --- a/snapshot/snapshot_display.cpp +++ b/snapshot/snapshot_display.cpp @@ -31,7 +31,17 @@ int main(int argc, char *argv[]) } // get PixelMap from DisplayManager API - auto pixelMap = DisplayManager::GetInstance().GetScreenshot(cmdArgments.displayId); + std::shared_ptr pixelMap = nullptr; + if (cmdArgments.width <= 0 || cmdArgments.height <= 0) { + pixelMap = DisplayManager::GetInstance().GetScreenshot(cmdArgments.displayId); // default width & height + } else { + auto display = DisplayManager::GetInstance().GetDefaultDisplay(); + const Media::Rect rect = {0, 0, display->GetWidth(), display->GetHeight()}; + const Media::Size size = {cmdArgments.width, cmdArgments.height}; + constexpr int rotation = 0; + pixelMap = DisplayManager::GetInstance().GetScreenshot(cmdArgments.displayId, rect, size, rotation); + } + bool ret = false; if (pixelMap != nullptr) { ret = SnapShotUtils::WriteToPngWithPixelMap(cmdArgments.fileName, *pixelMap); diff --git a/snapshot/snapshot_utils.cpp b/snapshot/snapshot_utils.cpp index cb6110cf26..e868240f72 100644 --- a/snapshot/snapshot_utils.cpp +++ b/snapshot/snapshot_utils.cpp @@ -27,7 +27,7 @@ constexpr int BITMAP_DEPTH = 8; void SnapShotUtils::PrintUsage(const std::string &cmdLine) { - printf("usage: %s [-i displayId] [-f output_file]\n", cmdLine.c_str()); + printf("usage: %s [-i displayId] [-f output_file] [-w width] [-h height] [-m]\n", cmdLine.c_str()); } bool SnapShotUtils::CheckFileNameValid(const std::string &fileName) @@ -45,11 +45,6 @@ bool SnapShotUtils::CheckFileNameValid(const std::string &fileName) printf("error: fileName %s invalid, nullptr!\n", fileName.c_str()); return false; } - std::string realPathString = realPath; - if (realPathString.find("/data") != 0) { - printf("error: fileName %s invalid, %s must dump at dir: /data \n", fileName.c_str(), realPathString.c_str()); - return false; - } return true; } @@ -143,19 +138,27 @@ bool SnapShotUtils::ProcessArgs(int argc, char * const argv[], CmdArgments &cmdA int opt = 0; const struct option longOption[] = { { "id", required_argument, nullptr, 'i' }, + { "width", required_argument, nullptr, 'w' }, + { "height", required_argument, nullptr, 'h' }, { "file", required_argument, nullptr, 'f' }, - { "help", required_argument, nullptr, 'h' }, + { "help", required_argument, nullptr, 'm' }, { nullptr, 0, nullptr, 0 } }; - while ((opt = getopt_long(argc, argv, "i:f:h", longOption, nullptr)) != -1) { + while ((opt = getopt_long(argc, argv, "i:w:h:f:m", longOption, nullptr)) != -1) { switch (opt) { case 'i': // display id cmdArgments.displayId = atoll(optarg); break; + case 'w': // output width + cmdArgments.width = atoi(optarg); + break; + case 'h': // output height + cmdArgments.height = atoi(optarg); + break; case 'f': // output file name cmdArgments.fileName = optarg; break; - case 'h': // help + case 'm': // help SnapShotUtils::PrintUsage(argv[0]); return false; default: diff --git a/snapshot/snapshot_utils.h b/snapshot/snapshot_utils.h index 3bd7cd979e..343784423c 100644 --- a/snapshot/snapshot_utils.h +++ b/snapshot/snapshot_utils.h @@ -34,6 +34,8 @@ using WriteToPngParam = struct { using CmdArgments = struct { Rosen::DisplayId displayId = Rosen::DISPLAY_ID_INVALD; std::string fileName; + int32_t width = -1; + int32_t height = -1; }; class SnapShotUtils { -- Gitee From 6ad9df402588ff63e3dbd823950da7886cf1a378 Mon Sep 17 00:00:00 2001 From: shiyueeee Date: Sat, 15 Jan 2022 12:00:25 +0800 Subject: [PATCH 03/57] Add dm system test, including minimal dm cases and screenshot cases Signed-off-by: shiyueeee Change-Id: I9400997879ac22c08b3110f2902a0b4ba0c4aef7 --- bundle.json | 3 +- dm/BUILD.gn | 5 + dm/test/BUILD.gn | 17 ++ dm/test/systemtest/BUILD.gn | 107 ++++++++++ dm/test/systemtest/display_minimal_test.cpp | 85 ++++++++ dm/test/systemtest/display_test_utils.cpp | 45 ++++ dm/test/systemtest/display_test_utils.h | 35 ++++ dm/test/systemtest/screenshot_cmd_test.cpp | 141 +++++++++++++ dm/test/systemtest/screenshot_test.cpp | 220 ++++++++++++++++++++ 9 files changed, 657 insertions(+), 1 deletion(-) create mode 100644 dm/test/BUILD.gn create mode 100644 dm/test/systemtest/BUILD.gn create mode 100644 dm/test/systemtest/display_minimal_test.cpp create mode 100644 dm/test/systemtest/display_test_utils.cpp create mode 100644 dm/test/systemtest/display_test_utils.h create mode 100644 dm/test/systemtest/screenshot_cmd_test.cpp create mode 100644 dm/test/systemtest/screenshot_test.cpp diff --git a/bundle.json b/bundle.json index 09f6e181c5..9a8ba35eec 100644 --- a/bundle.json +++ b/bundle.json @@ -62,7 +62,8 @@ } ], "test": [ - "//foundation/windowmanager/wm:test" + "//foundation/windowmanager/wm:test", + "//foundation/windowmanager/dm:test" ] } } diff --git a/dm/BUILD.gn b/dm/BUILD.gn index 80e361033f..00c8bd8e5b 100644 --- a/dm/BUILD.gn +++ b/dm/BUILD.gn @@ -68,3 +68,8 @@ ohos_shared_library("libdm") { part_name = "window_manager" subsystem_name = "window" } + +group("test") { + testonly = true + deps = [ "test:test" ] +} diff --git a/dm/test/BUILD.gn b/dm/test/BUILD.gn new file mode 100644 index 0000000000..db8ed45937 --- /dev/null +++ b/dm/test/BUILD.gn @@ -0,0 +1,17 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +group("test") { + testonly = true + deps = [ "systemtest:systemtest" ] +} diff --git a/dm/test/systemtest/BUILD.gn b/dm/test/systemtest/BUILD.gn new file mode 100644 index 0000000000..12801dcd3f --- /dev/null +++ b/dm/test/systemtest/BUILD.gn @@ -0,0 +1,107 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/test.gni") + +module_out_path = "window_manager/dm" + +group("systemtest") { + testonly = true + + deps = [ + ":dm_display_minimal_test", + ":dm_screenshot_cmd_test", + ":dm_screenshot_test", + ] +} + +## SystemTest dm_display_minimal_test {{{ +ohos_systemtest("dm_display_minimal_test") { + module_out_path = module_out_path + + sources = [ "display_minimal_test.cpp" ] + + deps = [ ":dm_systemtest_common" ] +} + +## SystemTest dm_display_minimal_test }}} + +## SystemTest dm_screenshot_test {{{ +ohos_systemtest("dm_screenshot_test") { + module_out_path = module_out_path + + sources = [ "screenshot_test.cpp" ] + + deps = [ ":dm_systemtest_common" ] +} + +## SystemTest dm_screenshot_test }}} + +## SystemTest dm_screenshot_cmd_test {{{ +ohos_systemtest("dm_screenshot_cmd_test") { + module_out_path = module_out_path + + sources = [ "screenshot_cmd_test.cpp" ] + + deps = [ ":dm_systemtest_common" ] +} + +## SystemTest dm_screenshot_cmd_test }}} + +## Build dm_systemtest_common.a {{{ +config("dm_systemtest_common_public_config") { + include_dirs = [ + "//foundation/windowmanager/dm/include", + "//foundation/windowmanager/dmserver/include", + "//foundation/windowmanager/interfaces/innerkits/dm", + "//foundation/windowmanager/utils/include", + "//foundation/communication/ipc/interfaces/innerkits/ipc_core/include", + "//base/hiviewdfx/hilog/interfaces/native/innerkits/include", + "//third_party/googletest/googlemock/include", + + # for abilityContext + "//foundation/aafwk/standard/frameworks/kits/ability/ability_runtime/include", + "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_base/include", + "//foundation/appexecfwk/standard/kits/appkit/native/ability_runtime/context", + "//base/global/resmgr_standard/interfaces/innerkits/include", + "//third_party/node/deps/icu-small/source/common", + "//foundation/aafwk/standard/interfaces/innerkits/ability_manager/include", + "//foundation/aafwk/standard/interfaces/innerkits/want/include/ohos/aafwk/content", + "//foundation/distributedschedule/dmsfwk/services/dtbschedmgr/include", + "//foundation/aafwk/standard/interfaces/innerkits/base/include", + + # abilityContext end + ] +} + +ohos_static_library("dm_systemtest_common") { + visibility = [ ":*" ] + testonly = true + + sources = [ "display_test_utils.cpp" ] + + public_configs = [ ":dm_systemtest_common_public_config" ] + + public_deps = [ + "//foundation/multimodalinput/input/frameworks/proxy:libmmi-client", + "//foundation/windowmanager/utils:libwmutil", + "//foundation/windowmanager/wm:libwm", + "//foundation/windowmanager/wmserver:libwms", + "//third_party/googletest:gmock", + "//third_party/googletest:gtest_main", + "//utils/native/base:utils", + ] + + external_deps = [ "aafwk_standard:ability_context_native" ] +} +## Build dm_systemtest_common.a }}} diff --git a/dm/test/systemtest/display_minimal_test.cpp b/dm/test/systemtest/display_minimal_test.cpp new file mode 100644 index 0000000000..b2fa31f82c --- /dev/null +++ b/dm/test/systemtest/display_minimal_test.cpp @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// gtest +#include +#include "display_test_utils.h" +using namespace testing; +using namespace testing::ext; + +namespace OHOS { +namespace Rosen { +class DisplayMinimalTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + virtual void SetUp() override; + virtual void TearDown() override; +}; + +void DisplayMinimalTest::SetUpTestCase() +{ +} + +void DisplayMinimalTest::TearDownTestCase() +{ +} + +void DisplayMinimalTest::SetUp() +{ +} + +void DisplayMinimalTest::TearDown() +{ +} + +namespace { +/** + * @tc.name: BasicDisplay + * @tc.desc: Check default display id is valid + * @tc.type: FUNC + */ +HWTEST_F(DisplayMinimalTest, BasicDisplay01, Function | MediumTest | Level1) +{ + ASSERT_NE(DISPLAY_ID_INVALD, DisplayManager::GetInstance().GetDefaultDisplayId()); +} + +/** + * @tc.name: BasicDisplay + * @tc.desc: Check default display exists + * @tc.type: FUNC + */ +HWTEST_F(DisplayMinimalTest, BasicDisplay02, Function | MediumTest | Level1) +{ + const sptr& display = DisplayManager::GetInstance().GetDefaultDisplay(); + ASSERT_NE(nullptr, display); +} + +/** + * @tc.name: BasicDisplay + * @tc.desc: Check all displays are valid + * @tc.type: FUNC + */ +HWTEST_F(DisplayMinimalTest, BasicDisplay03, Function | MediumTest | Level1) +{ + std::vector ids = DisplayManager::GetInstance().GetAllDisplayIds(); + for (DisplayId id : ids) { + const sptr& display = DisplayManager::GetInstance().GetDisplayById(id); + ASSERT_NE(nullptr, display); + } +} +} +} // namespace Rosen +} // namespace OHOS diff --git a/dm/test/systemtest/display_test_utils.cpp b/dm/test/systemtest/display_test_utils.cpp new file mode 100644 index 0000000000..fa3b46aa30 --- /dev/null +++ b/dm/test/systemtest/display_test_utils.cpp @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "display_test_utils.h" + +namespace OHOS { +namespace Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "DisplayTestUtils"}; +} + +bool DisplayTestUtils::SizeEqualToDisplay(const sptr& display, const Media::Size cur) +{ + int32_t dWidth = display->GetWidth(); + int32_t dHeight = display->GetHeight(); + + bool res = ((cur.width == dWidth) && (cur.height == dHeight)); + if (!res) { + WLOGFI("DisplaySize: %d %d, CurrentSize: %d %d\n", dWidth, dHeight, cur.width, cur.height); + } + return res; +} + +bool DisplayTestUtils::SizeEqual(const Media::Size dst, const Media::Size cur) +{ + bool res = ((cur.width == dst.width) && (cur.height == dst.height)); + if (!res) { + WLOGFI("Desired Size: %d %d, Current Size: %d %d\n", dst.width, dst.height, cur.width, cur.height); + } + return res; +} +} // namespace ROSEN +} // namespace OHOS \ No newline at end of file diff --git a/dm/test/systemtest/display_test_utils.h b/dm/test/systemtest/display_test_utils.h new file mode 100644 index 0000000000..d30204be0e --- /dev/null +++ b/dm/test/systemtest/display_test_utils.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FRAMEWORKS_DM_TEST_ST_DISPLAY_TEST_UTILS_H +#define FRAMEWORKS_DM_TEST_ST_DISPLAY_TEST_UTILS_H + +#include "display_manager.h" +#include "display_property.h" +#include "display.h" +#include "display_info.h" +#include "wm_common.h" +#include "window_manager_hilog.h" + +namespace OHOS { +namespace Rosen { +class DisplayTestUtils { +public: + static bool SizeEqualToDisplay(const sptr& display, const Media::Size cur); + static bool SizeEqual(const Media::Size dst, const Media::Size cur); +}; +} // namespace ROSEN +} // namespace OHOS +#endif // FRAMEWORKS_DM_TEST_ST_DISPLAY_TEST_UTILS_H diff --git a/dm/test/systemtest/screenshot_cmd_test.cpp b/dm/test/systemtest/screenshot_cmd_test.cpp new file mode 100644 index 0000000000..9a7d707942 --- /dev/null +++ b/dm/test/systemtest/screenshot_cmd_test.cpp @@ -0,0 +1,141 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// gtest +#include +#include +#include "display_test_utils.h" +#include "pixel_map.h" + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { +namespace Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "ScreenshotCmdTest"}; +} +using utils = DisplayTestUtils; +class ScreenshotCmdTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + virtual void SetUp() override; + virtual void TearDown() override; + static DisplayId defaultId_; + DisplayId invalidId_ = DISPLAY_ID_INVALD; + const std::string defaultCmd_ = "/system/bin/snapshot_display"; + const std::string defaultImg_ = "/data/snapshot_display_1.png"; +}; + +DisplayId ScreenshotCmdTest::defaultId_ = DISPLAY_ID_INVALD; + +void ScreenshotCmdTest::SetUpTestCase() +{ + auto display = DisplayManager::GetInstance().GetDefaultDisplay(); + if (display == nullptr) { + WLOGFI("GetDefaultDisplay: failed!\n"); + } else { + WLOGFI("GetDefaultDisplay: id %llu, w %d, h %d, fps %u\n", display->GetId(), display->GetWidth(), + display->GetHeight(), display->GetFreshRate()); + } + + defaultId_ = display->GetId(); +} + +void ScreenshotCmdTest::TearDownTestCase() +{ +} + +void ScreenshotCmdTest::SetUp() +{ +} + +void ScreenshotCmdTest::TearDown() +{ +} + +bool CheckFileExist(const std::string fPath) +{ + if (!fPath.empty()) { + FILE* fp = fopen(fPath.c_str(), "r"); + if (fp != nullptr) { + fclose(fp); + return true; + } + } + return false; +} + +namespace { +/** + * @tc.name: ScreenShotCmdValid + * @tc.desc: Call screenshot default cmd and check if it saves image in default path + * @tc.type: FUNC + */ +HWTEST_F(ScreenshotCmdTest, ScreenShotCmdValid01, Function | MediumTest | Level2) +{ + if (CheckFileExist(defaultImg_)) { + remove(defaultImg_.c_str()); + } + (void)system(defaultCmd_.c_str()); + bool isExist = CheckFileExist(defaultImg_); + if (isExist) { + remove(defaultImg_.c_str()); + } + ASSERT_EQ(true, isExist); +} + +/** + * @tc.name: ScreenShotCmdValid + * @tc.desc: Call screenshot with default displayID and default path + * @tc.type: FUNC + */ +HWTEST_F(ScreenshotCmdTest, ScreenShotCmdValid02, Function | MediumTest | Level2) +{ + if (CheckFileExist(defaultImg_)) { + remove(defaultImg_.c_str()); + } + const std::string cmd = defaultCmd_ + " -i " + std::to_string(defaultId_); + (void)system(cmd.c_str()); + bool isExist = CheckFileExist(defaultImg_); + if (isExist) { + remove(defaultImg_.c_str()); + } + ASSERT_EQ(true, isExist); +} + +/** + * @tc.name: ScreenShotCmdValid + * @tc.desc: Call screenshot with default displayID and custom path + * @tc.type: FUNC + */ +HWTEST_F(ScreenshotCmdTest, ScreenShotCmdValid03, Function | MediumTest | Level2) +{ + const std::string imgPath = "/data/snapshot_display_test.png"; + if (CheckFileExist(imgPath)) { + remove(imgPath.c_str()); + } + const std::string cmd = defaultCmd_ + " -i " + std::to_string(defaultId_) + " -f " + imgPath; + (void)system(cmd.c_str()); + bool isExist = CheckFileExist(imgPath); + if (isExist) { + remove(imgPath.c_str()); + } + ASSERT_EQ(true, isExist); +} +} // namespace +} // namespace Rosen +} // namespace OHOS \ No newline at end of file diff --git a/dm/test/systemtest/screenshot_test.cpp b/dm/test/systemtest/screenshot_test.cpp new file mode 100644 index 0000000000..8b22483614 --- /dev/null +++ b/dm/test/systemtest/screenshot_test.cpp @@ -0,0 +1,220 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// gtest +#include +#include "display_test_utils.h" +#include "pixel_map.h" + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { +namespace Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "ScreenshotTest"}; +} +using utils = DisplayTestUtils; +class ScreenshotTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + virtual void SetUp() override; + virtual void TearDown() override; + static DisplayId defaultId_; + static Media::Rect defaultScreen_; + static Media::Size defaultImage_; + DisplayId invalidId_ = DISPLAY_ID_INVALD; + Media::Rect invalidRect_ = {-1, -1, -1, -1}; + uint32_t defaultRot_ = 0; +}; + +DisplayId ScreenshotTest::defaultId_ = DISPLAY_ID_INVALD; +Media::Rect ScreenshotTest::defaultScreen_ = {0, 0, 0, 0}; +Media::Size ScreenshotTest::defaultImage_ = {0, 0}; + +void ScreenshotTest::SetUpTestCase() +{ + auto display = DisplayManager::GetInstance().GetDefaultDisplay(); + if (display == nullptr) { + WLOGFI("GetDefaultDisplay: failed!\n"); + } else { + WLOGFI("GetDefaultDisplay: id %llu, w %d, h %d, fps %u\n", display->GetId(), display->GetWidth(), + display->GetHeight(), display->GetFreshRate()); + } + + defaultId_ = display->GetId(); + defaultScreen_ = {0, 0, display->GetWidth(), display->GetHeight()}; + defaultImage_ = {display->GetWidth(), display->GetHeight()}; +} + +void ScreenshotTest::TearDownTestCase() +{ +} + +void ScreenshotTest::SetUp() +{ +} + +void ScreenshotTest::TearDown() +{ +} + +namespace { +/** + * @tc.name: ScreenShotValid + * @tc.desc: Check if screenshot of default display's ID is valid + * @tc.type: FUNC + */ +HWTEST_F(ScreenshotTest, ScreenShotValid01, Function | MediumTest | Level2) +{ + ASSERT_NE(nullptr, DisplayManager::GetInstance().GetScreenshot(defaultId_)); +} + +/** + * @tc.name: ScreenShotValid + * @tc.desc: Check if screenshot of invalid display's ID is nullptr + * @tc.type: FUNC + */ +HWTEST_F(ScreenshotTest, ScreenShotValid02, Function | MediumTest | Level2) +{ + ASSERT_EQ(nullptr, DisplayManager::GetInstance().GetScreenshot(invalidId_)); +} + +/** + * @tc.name: ScreenShotValid + * @tc.desc: Check if screenshot of default display's ID match default display's Media::Size + * @tc.type: FUNC + */ +HWTEST_F(ScreenshotTest, ScreenShotValid03, Function | MediumTest | Level2) +{ + auto& dm = DisplayManager::GetInstance(); + std::shared_ptr screenshot = dm.GetScreenshot(defaultId_); + ASSERT_NE(nullptr, screenshot); + + Media::Size screenSize = {screenshot->GetWidth(), screenshot->GetHeight()}; + ASSERT_TRUE(utils::SizeEqualToDisplay(dm.GetDefaultDisplay(), screenSize)); +} + +/** + * @tc.name: ScreenShotValid + * @tc.desc: Check if screenshot created by default parameters is valid + * @tc.type: FUNC + */ +HWTEST_F(ScreenshotTest, ScreenShotValid04, Function | MediumTest | Level2) +{ + auto& dm = DisplayManager::GetInstance(); + std::shared_ptr screenshot = dm.GetScreenshot(defaultId_, defaultScreen_, + defaultImage_, defaultRot_); + ASSERT_NE(nullptr, screenshot); +} + +/** + * @tc.name: ScreenShotValid + * @tc.desc: Check if screenshot match default imageSize + * @tc.type: FUNC + */ +HWTEST_F(ScreenshotTest, ScreenShotValid05, Function | MediumTest | Level2) +{ + auto& dm = DisplayManager::GetInstance(); + std::shared_ptr screenshot = dm.GetScreenshot(defaultId_, defaultScreen_, + defaultImage_, defaultRot_); + ASSERT_NE(nullptr, screenshot); + Media::Size screenSize = {screenshot->GetWidth(), screenshot->GetHeight()}; + ASSERT_TRUE(utils::SizeEqual(defaultImage_, screenSize)); + + Media::Size halfDefault_ = {defaultImage_.width / 2, defaultImage_.height / 2}; + Media::Rect halfRect = {defaultScreen_.left, defaultScreen_.top, halfDefault_.width, halfDefault_.height}; + screenshot = dm.GetScreenshot(defaultId_, halfRect, defaultImage_, defaultRot_); + ASSERT_NE(nullptr, screenshot); + screenSize = {screenshot->GetWidth(), screenshot->GetHeight()}; + ASSERT_TRUE(utils::SizeEqual(defaultImage_, screenSize)); + + Media::Size halfSize = {halfDefault_.width, halfDefault_.height}; + screenshot = dm.GetScreenshot(defaultId_, defaultScreen_, halfSize, defaultRot_); + ASSERT_NE(nullptr, screenshot); + screenSize = {screenshot->GetWidth(), screenshot->GetHeight()}; + ASSERT_TRUE(utils::SizeEqual(halfSize, screenSize)); +} + +/** + * @tc.name: ScreenShotValid + * @tc.desc: Check if screenshot created by default parameters match default display's Media::Size + * @tc.type: FUNC + */ +HWTEST_F(ScreenshotTest, ScreenShotValid06, Function | MediumTest | Level2) +{ + auto& dm = DisplayManager::GetInstance(); + std::shared_ptr screenshot = dm.GetScreenshot(defaultId_, defaultScreen_, + defaultImage_, defaultRot_); + ASSERT_NE(nullptr, screenshot); + Media::Size screenSize = {screenshot->GetWidth(), screenshot->GetHeight()}; + ASSERT_TRUE(utils::SizeEqualToDisplay(dm.GetDefaultDisplay(), screenSize)); +} + +/** + * @tc.name: ScreenShotValid + * @tc.desc: Check if screenshot created by invalid display ID is nullptr + * @tc.type: FUNC + */ +HWTEST_F(ScreenshotTest, ScreenShot07, Function | MediumTest | Level2) +{ + auto& dm = DisplayManager::GetInstance(); + std::shared_ptr screenshot = dm.GetScreenshot(invalidId_, defaultScreen_, + defaultImage_, defaultRot_); + ASSERT_EQ(nullptr, screenshot); +} + +/** + * @tc.name: ScreenShotValid + * @tc.desc: Check if screenshot created by invalid screenRect is nullptr + * @tc.type: FUNC + */ +HWTEST_F(ScreenshotTest, ScreenShot08, Function | MediumTest | Level2) +{ + auto& dm = DisplayManager::GetInstance(); + std::shared_ptr screenshot = dm.GetScreenshot(defaultId_, invalidRect_, + defaultImage_, defaultRot_); + ASSERT_EQ(nullptr, screenshot); + Media::Rect invalidScreen = {invalidRect_.left, defaultScreen_.top, defaultScreen_.width, defaultScreen_.height}; + screenshot = dm.GetScreenshot(defaultId_, invalidScreen, defaultImage_, defaultRot_); + ASSERT_EQ(nullptr, screenshot); + invalidScreen = {defaultScreen_.left, defaultScreen_.top, invalidRect_.width, defaultScreen_.height}; + screenshot = dm.GetScreenshot(defaultId_, invalidScreen, defaultImage_, defaultRot_); + ASSERT_EQ(nullptr, screenshot); +} + +/** + * @tc.name: ScreenShotValid + * @tc.desc: Check if screenshot created by invalid imageSize is nullptr + * @tc.type: FUNC + */ +HWTEST_F(ScreenshotTest, ScreenShot09, Function | MediumTest | Level2) +{ + auto& dm = DisplayManager::GetInstance(); + Media::Size invalidSize = {invalidRect_.width, invalidRect_.height}; + std::shared_ptr screenshot = dm.GetScreenshot(defaultId_, defaultScreen_, + invalidSize, defaultRot_); + ASSERT_EQ(nullptr, screenshot); + invalidSize = {invalidRect_.width, defaultScreen_.height}; + screenshot = dm.GetScreenshot(defaultId_, defaultScreen_, invalidSize, defaultRot_); + ASSERT_EQ(nullptr, screenshot); + invalidSize = {defaultScreen_.width, invalidRect_.height}; + screenshot = dm.GetScreenshot(defaultId_, defaultScreen_, invalidSize, defaultRot_); + ASSERT_EQ(nullptr, screenshot); +} +} // namespace +} // namespace Rosen +} // namespace OHOS \ No newline at end of file -- Gitee From f69264332a7bc8bb127f1db751cb794d082e95f7 Mon Sep 17 00:00:00 2001 From: Grady Date: Fri, 14 Jan 2022 21:28:06 +0800 Subject: [PATCH 04/57] Move virtualScreen to ScreenManager, add AddMirror to save RSDisplayNode Signed-off-by: Grady Change-Id: Icf74950fb6d48053534e9a57c3e6f7f3ebd7fe29 --- dm/include/display_manager_adapter.h | 10 ++- dm/src/display_manager.cpp | 14 ---- dm/src/display_manager_adapter.cpp | 27 ++++--- dm/src/screen_manager.cpp | 26 +++++- .../include/abstract_display_controller.h | 8 +- dmserver/include/abstract_screen.h | 9 +-- dmserver/include/abstract_screen_controller.h | 6 +- dmserver/include/display_manager_interface.h | 13 +-- dmserver/include/display_manager_proxy.h | 10 ++- dmserver/include/display_manager_service.h | 10 ++- dmserver/src/abstract_display_controller.cpp | 22 ----- dmserver/src/abstract_screen_controller.cpp | 39 +++++++-- dmserver/src/display_manager_proxy.cpp | 81 +++++++++++++------ dmserver/src/display_manager_service.cpp | 56 ++++++++++--- dmserver/src/display_manager_stub.cpp | 38 ++++++--- interfaces/innerkits/dm/display_manager.h | 5 -- interfaces/innerkits/dm/dm_common.h | 14 ++++ interfaces/innerkits/dm/screen.h | 2 +- interfaces/innerkits/dm/screen_manager.h | 11 ++- utils/BUILD.gn | 1 - utils/include/virtual_display_info.h | 46 ----------- utils/src/virtual_display_info.cpp | 61 -------------- 22 files changed, 266 insertions(+), 243 deletions(-) delete mode 100644 utils/include/virtual_display_info.h delete mode 100644 utils/src/virtual_display_info.cpp diff --git a/dm/include/display_manager_adapter.h b/dm/include/display_manager_adapter.h index 666f0ac0d2..c59de7b8a4 100644 --- a/dm/include/display_manager_adapter.h +++ b/dm/include/display_manager_adapter.h @@ -20,6 +20,8 @@ #include #include "display.h" +#include "screen.h" +#include "dm_common.h" #include "display_manager_interface.h" #include "singleton_delegator.h" @@ -34,9 +36,9 @@ WM_DECLARE_SINGLE_INSTANCE_BASE(DisplayManagerAdapter); public: DisplayId GetDefaultDisplayId(); sptr GetDisplayById(DisplayId displayId); - DisplayId CreateVirtualDisplay(const VirtualDisplayInfo &virtualDisplayInfo, - sptr surface); - bool DestroyVirtualDisplay(DisplayId displayId); + + ScreenId CreateVirtualScreen(VirtualScreenOption option); + DMError DestroyVirtualScreen(ScreenId screenId); std::shared_ptr GetDisplaySnapshot(DisplayId displayId); void RegisterDisplayManagerAgent(const sptr& displayManagerAgent, @@ -51,7 +53,7 @@ public: bool SetDisplayState(DisplayState state, DisplayStateCallback callback); DisplayState GetDisplayState(uint64_t displayId); void NotifyDisplayEvent(DisplayEvent event); - + DMError AddMirror(ScreenId mainScreenId, ScreenId mirrorScreenId); void Clear(); private: diff --git a/dm/src/display_manager.cpp b/dm/src/display_manager.cpp index 43a63319db..faca0d8dcd 100644 --- a/dm/src/display_manager.cpp +++ b/dm/src/display_manager.cpp @@ -154,20 +154,6 @@ std::vector> DisplayManager::GetAllDisplays() return res; } -DisplayId DisplayManager::CreateVirtualDisplay(const std::string &name, uint32_t width, uint32_t height, - sptr surface, DisplayId displayIdToMirror, int32_t flags) -{ - WLOGFI("DisplayManager::CreateVirtualDisplay multi params"); - VirtualDisplayInfo info(name, width, height, displayIdToMirror, flags); - return SingletonContainer::Get().CreateVirtualDisplay(info, surface); -} - -bool DisplayManager::DestroyVirtualDisplay(DisplayId displayId) -{ - WLOGFI("DisplayManager::DestroyVirtualDisplay override params"); - return SingletonContainer::Get().DestroyVirtualDisplay(displayId); -} - void DisplayManager::RegisterDisplayPowerEventListener(sptr listener) { if (listener == nullptr) { diff --git a/dm/src/display_manager_adapter.cpp b/dm/src/display_manager_adapter.cpp index bd804d7b02..2e81963a8f 100644 --- a/dm/src/display_manager_adapter.cpp +++ b/dm/src/display_manager_adapter.cpp @@ -78,23 +78,22 @@ std::shared_ptr DisplayManagerAdapter::GetDisplaySnapshot(Displ return dispalySnapshot; } -DisplayId DisplayManagerAdapter::CreateVirtualDisplay(const VirtualDisplayInfo &virtualDisplayInfo, - sptr surface) +ScreenId DisplayManagerAdapter::CreateVirtualScreen(VirtualScreenOption option) { if (!InitDMSProxyLocked()) { - return DISPLAY_ID_INVALD; + return SCREEN_ID_INVALD; } - WLOGFI("DisplayManagerAdapter::CreateVirtualDisplay"); - return displayManagerServiceProxy_->CreateVirtualDisplay(virtualDisplayInfo, surface); + WLOGFI("DisplayManagerAdapter::CreateVirtualScreen"); + return displayManagerServiceProxy_->CreateVirtualScreen(option); } -bool DisplayManagerAdapter::DestroyVirtualDisplay(DisplayId displayId) +DMError DisplayManagerAdapter::DestroyVirtualScreen(ScreenId screenId) { if (!InitDMSProxyLocked()) { - return false; + return DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED; } - WLOGFI("DisplayManagerAdapter::DestroyVirtualDisplay"); - return displayManagerServiceProxy_->DestroyVirtualDisplay(displayId); + WLOGFI("DisplayManagerAdapter::DestroyVirtualScreen"); + return displayManagerServiceProxy_->DestroyVirtualScreen(screenId); } void DisplayManagerAdapter::RegisterDisplayManagerAgent(const sptr& displayManagerAgent, @@ -265,4 +264,14 @@ void DisplayManagerAdapter::Clear() } displayManagerServiceProxy_ = nullptr; } + +DMError DisplayManagerAdapter::AddMirror(ScreenId mainScreenId, ScreenId mirrorScreenId) +{ + if (!InitDMSProxyLocked()) { + WLOGFE("DisplayManagerAdapter::AddMirror: InitDMSProxyLocked failed"); + return DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED; + } + WLOGFI("DisplayManagerAdapter::AddMirror"); + return displayManagerServiceProxy_->AddMirror(mainScreenId, mirrorScreenId); +} } // namespace OHOS::Rosen \ No newline at end of file diff --git a/dm/src/screen_manager.cpp b/dm/src/screen_manager.cpp index d13344a945..5981a1aa82 100644 --- a/dm/src/screen_manager.cpp +++ b/dm/src/screen_manager.cpp @@ -14,11 +14,17 @@ */ #include "screen_manager.h" +#include "window_manager_hilog.h" +#include "display_manager_adapter.h" + #include #include namespace OHOS::Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "ScreenManager"}; +} class ScreenManager::Impl : public RefBase { friend class ScreenManager; private: @@ -53,18 +59,32 @@ void ScreenManager::RegisterScreenChangeListener(sptr lis { } -sptr ScreenManager::makeExpand(std::vector screenId, std::vector startPoint) +sptr ScreenManager::MakeExpand(std::vector screenId, std::vector startPoint) { return nullptr; } -sptr ScreenManager::makeMirror(ScreenId mainScreenId, std::vector mirrorScreenId) +sptr ScreenManager::MakeMirror(ScreenId mainScreenId, std::vector mirrorScreenId) { return nullptr; } -sptr ScreenManager::createVirtualScreen(VirtualScreenOption option) +sptr ScreenManager::AddMirror(ScreenId mainScreenId, ScreenId mirrorScreenId) { + DMError result = SingletonContainer::Get().AddMirror(mainScreenId, mirrorScreenId); + if (result == DMError::DM_OK) { + WLOGFI("AddMirror::Successful"); + } return nullptr; } + +ScreenId ScreenManager::CreateVirtualScreen(VirtualScreenOption option) +{ + return SingletonContainer::Get().CreateVirtualScreen(option); +} + +DMError ScreenManager::DestroyVirtualScreen(ScreenId screenId) +{ + return SingletonContainer::Get().DestroyVirtualScreen(screenId); +} } // namespace OHOS::Rosen \ No newline at end of file diff --git a/dmserver/include/abstract_display_controller.h b/dmserver/include/abstract_display_controller.h index 3d588e7210..5f1b113629 100644 --- a/dmserver/include/abstract_display_controller.h +++ b/dmserver/include/abstract_display_controller.h @@ -16,15 +16,16 @@ #ifndef FOUNDATION_DMSERVER_ABSTRACT_DISPLAY_CONTROLLER_H #define FOUNDATION_DMSERVER_ABSTRACT_DISPLAY_CONTROLLER_H +#include "abstract_screen_controller.h" + #include #include #include #include +#include "screen.h" #include "abstract_display.h" -#include "abstract_screen_controller.h" #include "transaction/rs_interfaces.h" -#include "virtual_display_info.h" namespace OHOS::Rosen { class AbstractDisplayController : public RefBase { @@ -35,8 +36,7 @@ public: void Init(sptr abstractScreenController); ScreenId GetDefaultScreenId(); RSScreenModeInfo GetScreenActiveMode(ScreenId id); - ScreenId CreateVirtualScreen(const VirtualDisplayInfo &virtualDisplayInfo, sptr surface); - bool DestroyVirtualScreen(ScreenId screenId); + std::shared_ptr GetScreenSnapshot(DisplayId displayId, ScreenId screenId); private: diff --git a/dmserver/include/abstract_screen.h b/dmserver/include/abstract_screen.h index 9b9a0c3e60..517ccbb947 100644 --- a/dmserver/include/abstract_screen.h +++ b/dmserver/include/abstract_screen.h @@ -16,19 +16,16 @@ #ifndef FOUNDATION_DMSERVER_ABSTRACT_SCREEN_H #define FOUNDATION_DMSERVER_ABSTRACT_SCREEN_H -#include +#include #include #include +#include "screen.h" + namespace OHOS::Rosen { constexpr static ScreenId SCREEN_ID_INVALID = INVALID_SCREEN_ID; -struct Point { - int32_t posX_; - int32_t posY_; -}; - enum class ScreenCombination : uint32_t { SCREEN_ALONE, SCREEN_EXPAND, diff --git a/dmserver/include/abstract_screen_controller.h b/dmserver/include/abstract_screen_controller.h index b0c041fccc..13996ebffa 100644 --- a/dmserver/include/abstract_screen_controller.h +++ b/dmserver/include/abstract_screen_controller.h @@ -23,6 +23,8 @@ #include #include +#include "screen.h" +#include "dm_common.h" #include "abstract_screen.h" namespace OHOS::Rosen { @@ -45,6 +47,8 @@ public: ScreenId ConvertToRsScreenId(ScreenId dmsScreenId); ScreenId ConvertToDmsScreenId(ScreenId rsScreenId); void RegisterAbstractScreenCallback(sptr cb); + ScreenId CreateVirtualScreen(VirtualScreenOption option); + DMError DestroyVirtualScreen(ScreenId screenId); std::map> abstractDisplayMap_; @@ -56,7 +60,7 @@ private: void AddAsSuccedentScreenLocked(sptr newScreen); std::recursive_mutex& mutex_; - RSInterfaces& rsInterface_; + OHOS::Rosen::RSInterfaces *rsInterface_; std::atomic dmsScreenCount_; // No AbstractScreenGroup std::map rs2DmsScreenIdMap_; diff --git a/dmserver/include/display_manager_interface.h b/dmserver/include/display_manager_interface.h index 6834d9c2e9..4c889daf3c 100644 --- a/dmserver/include/display_manager_interface.h +++ b/dmserver/include/display_manager_interface.h @@ -21,8 +21,8 @@ #include #include "dm_common.h" +#include "screen.h" #include "display_info.h" -#include "virtual_display_info.h" #include "zidl/display_manager_agent_interface.h" namespace OHOS::Rosen { @@ -33,8 +33,6 @@ public: enum { TRANS_ID_GET_DEFAULT_DISPLAY_ID = 0, TRANS_ID_GET_DISPLAY_BY_ID, - TRANS_ID_CREATE_VIRTUAL_DISPLAY, - TRANS_ID_DESTROY_VIRTUAL_DISPLAY, TRANS_ID_GET_DISPLAY_SNAPSHOT, TRANS_ID_REGISTER_DISPLAY_MANAGER_AGENT, TRANS_ID_UNREGISTER_DISPLAY_MANAGER_AGENT, @@ -46,14 +44,16 @@ public: TRANS_ID_SET_DISPLAY_STATE, TRANS_ID_GET_DISPLAY_STATE, TRANS_ID_NOTIFY_DISPLAY_EVENT, + TRANS_ID_CREATE_VIRTUAL_SCREEN = 100000, + TRANS_ID_DESTROY_VIRTUAL_SCREEN, + TRANS_ID_ADD_MIRROR, }; virtual DisplayId GetDefaultDisplayId() = 0; virtual DisplayInfo GetDisplayInfoById(DisplayId displayId) = 0; - virtual DisplayId CreateVirtualDisplay(const VirtualDisplayInfo &virtualDisplayInfo, - sptr surface) = 0; - virtual bool DestroyVirtualDisplay(DisplayId displayId) = 0; + virtual ScreenId CreateVirtualScreen(VirtualScreenOption option) = 0; + virtual DMError DestroyVirtualScreen(ScreenId screenId) = 0; virtual std::shared_ptr GetDispalySnapshot(DisplayId displayId) = 0; virtual void RegisterDisplayManagerAgent(const sptr& displayManagerAgent, @@ -68,6 +68,7 @@ public: virtual bool SetDisplayState(DisplayState state) = 0; virtual DisplayState GetDisplayState(uint64_t displayId) = 0; virtual void NotifyDisplayEvent(DisplayEvent event) = 0; + virtual DMError AddMirror(ScreenId mainScreenId, ScreenId mirrorScreenId) = 0; }; } // namespace OHOS::Rosen diff --git a/dmserver/include/display_manager_proxy.h b/dmserver/include/display_manager_proxy.h index cc4fa0c8ce..dd1232fba0 100644 --- a/dmserver/include/display_manager_proxy.h +++ b/dmserver/include/display_manager_proxy.h @@ -18,6 +18,10 @@ #include "display_manager_interface.h" +#include "dm_common.h" + +#include "screen.h" + #include namespace OHOS::Rosen { @@ -30,9 +34,8 @@ public: DisplayId GetDefaultDisplayId() override; DisplayInfo GetDisplayInfoById(DisplayId displayId) override; - DisplayId CreateVirtualDisplay(const VirtualDisplayInfo &virtualDisplayInfo, - sptr surface) override; - bool DestroyVirtualDisplay(DisplayId displayId) override; + ScreenId CreateVirtualScreen(VirtualScreenOption option) override; + DMError DestroyVirtualScreen(ScreenId screenId) override; std::shared_ptr GetDispalySnapshot(DisplayId displayId) override; void RegisterDisplayManagerAgent(const sptr& displayManagerAgent, @@ -47,6 +50,7 @@ public: bool SetDisplayState(DisplayState state) override; DisplayState GetDisplayState(uint64_t displayId) override; void NotifyDisplayEvent(DisplayEvent event) override; + DMError AddMirror(ScreenId mainScreenId, ScreenId mirrorScreenId) override; private: static inline BrokerDelegator delegator_; diff --git a/dmserver/include/display_manager_service.h b/dmserver/include/display_manager_service.h index 1ea7380dcb..fbbefa7ae3 100644 --- a/dmserver/include/display_manager_service.h +++ b/dmserver/include/display_manager_service.h @@ -22,6 +22,8 @@ #include #include +#include "dm_common.h" +#include "screen.h" #include "abstract_display.h" #include "abstract_display_controller.h" #include "abstract_screen_controller.h" @@ -50,9 +52,8 @@ WM_DECLARE_SINGLE_INSTANCE_BASE(DisplayManagerService); public: void OnStart() override; void OnStop() override; - DisplayId CreateVirtualDisplay(const VirtualDisplayInfo &virtualDisplayInfo, - sptr surface) override; - bool DestroyVirtualDisplay(DisplayId displayId) override; + ScreenId CreateVirtualScreen(VirtualScreenOption option) override; + DMError DestroyVirtualScreen(ScreenId screenId) override; DisplayId GetDefaultDisplayId() override; DisplayInfo GetDisplayInfoById(DisplayId displayId) override; @@ -71,8 +72,8 @@ public: DisplayState GetDisplayState(uint64_t displayId) override; void NotifyDisplayEvent(DisplayEvent event) override; bool NotifyDisplayPowerEvent(DisplayPowerEvent event, EventStatus status); - sptr GetAbstractScreenController(); + DMError AddMirror(ScreenId mainScreenId, ScreenId mirrorScreenId) override; private: DisplayManagerService(); @@ -101,6 +102,7 @@ private: std::map> > displayManagerAgentMap_; sptr dmAgentDeath_ = new DMAgentDeathRecipient( std::bind(&DisplayManagerService::RemoveDisplayManagerAgent, this, std::placeholders::_1)); + std::map> displayNodeMap_; }; } // namespace OHOS::Rosen diff --git a/dmserver/src/abstract_display_controller.cpp b/dmserver/src/abstract_display_controller.cpp index 0304b9e348..cc4e790897 100644 --- a/dmserver/src/abstract_display_controller.cpp +++ b/dmserver/src/abstract_display_controller.cpp @@ -70,28 +70,6 @@ RSScreenModeInfo AbstractDisplayController::GetScreenActiveMode(ScreenId id) return rsInterface_->GetScreenActiveMode(id); } -ScreenId AbstractDisplayController::CreateVirtualScreen(const VirtualDisplayInfo &virtualDisplayInfo, - sptr surface) -{ - if (rsInterface_ == nullptr) { - return SCREEN_ID_INVALID; - } - ScreenId result = rsInterface_->CreateVirtualScreen(virtualDisplayInfo.name_, virtualDisplayInfo.width_, - virtualDisplayInfo.height_, surface, virtualDisplayInfo.displayIdToMirror_, virtualDisplayInfo.flags_); - WLOGFI("AbstractDisplayController::CreateVirtualDisplay id: %{public}" PRIu64"", result); - return result; -} - -bool AbstractDisplayController::DestroyVirtualScreen(ScreenId screenId) -{ - if (rsInterface_ == nullptr) { - return false; - } - WLOGFI("AbstractDisplayController::DestroyVirtualScreen"); - rsInterface_->RemoveVirtualScreen(screenId); - return true; -} - std::shared_ptr AbstractDisplayController::GetScreenSnapshot(DisplayId displayId, ScreenId screenId) { if (rsInterface_ == nullptr) { diff --git a/dmserver/src/abstract_screen_controller.cpp b/dmserver/src/abstract_screen_controller.cpp index fb3d8a3f21..52c0515e41 100644 --- a/dmserver/src/abstract_screen_controller.cpp +++ b/dmserver/src/abstract_screen_controller.cpp @@ -29,7 +29,7 @@ namespace { } AbstractScreenController::AbstractScreenController(std::recursive_mutex& mutex) - : mutex_(mutex), rsInterface_(RSInterfaces::GetInstance()) + : mutex_(mutex), rsInterface_(&(RSInterfaces::GetInstance())) { } @@ -41,8 +41,12 @@ void AbstractScreenController::Init() { WLOGFD("screen controller init"); dmsScreenCount_ = 0; - rsInterface_.SetScreenChangeCallback( - std::bind(&AbstractScreenController::OnRsScreenChange, this, std::placeholders::_1, std::placeholders::_2)); + if (rsInterface_ != nullptr) { + WLOGFE("rsInterface_ is nullptr, init failed"); + } else { + rsInterface_->SetScreenChangeCallback( + std::bind(&AbstractScreenController::OnRsScreenChange, this, std::placeholders::_1, std::placeholders::_2)); + } } std::vector AbstractScreenController::GetAllScreenIds() @@ -125,7 +129,11 @@ void AbstractScreenController::OnRsScreenChange(ScreenId rsScreenId, ScreenEvent bool AbstractScreenController::FillAbstractScreen(sptr& absScreen, ScreenId rsScreenId) { - std::vector allModes = rsInterface_.GetScreenSupportedModes(rsScreenId); + if (rsInterface_ == nullptr) { + WLOGFE("rsInterface_ is nullptr, FillAbstractScreen failed"); + return false; + } + std::vector allModes = rsInterface_->GetScreenSupportedModes(rsScreenId); if (allModes.size() == 0) { WLOGE("supported screen mode is 0, screenId=%{public}" PRIu64"", rsScreenId); return false; @@ -138,7 +146,7 @@ bool AbstractScreenController::FillAbstractScreen(sptr& absScree absScreen->infos_.push_back(info); WLOGD("fill screen w/h:%{public}d/%{public}d", info->width_, info->height_); } - int32_t activeModeId = rsInterface_.GetScreenActiveMode(rsScreenId).GetScreenModeId(); + int32_t activeModeId = rsInterface_->GetScreenActiveMode(rsScreenId).GetScreenModeId(); WLOGD("fill screen activeModeId:%{public}d", activeModeId); if (activeModeId >= allModes.size()) { WLOGE("activeModeId exceed, screenId=%{public}" PRIu64", activeModeId:%{public}d/%{public}ud", @@ -184,4 +192,25 @@ void AbstractScreenController::AddAsSuccedentScreenLocked(sptr n { // TODO: Mirror to default screen } + +ScreenId AbstractScreenController::CreateVirtualScreen(VirtualScreenOption option) +{ + if (rsInterface_ == nullptr) { + return SCREEN_ID_INVALID; + } + ScreenId result = rsInterface_->CreateVirtualScreen(option.name_, option.width_, + option.height_, option.surface_, INVALID_SCREEN_ID, option.flags_); + WLOGFI("AbstractScreenController::CreateVirtualScreen id: %{public}" PRIu64"", result); + return result; +} + +DMError AbstractScreenController::DestroyVirtualScreen(ScreenId screenId) +{ + if (rsInterface_ == nullptr) { + return DMError::DM_ERROR_NULLPTR; + } + WLOGFI("AbstractScreenController::DestroyVirtualScreen"); + rsInterface_->RemoveVirtualScreen(screenId); + return DMError::DM_OK; +} } // namespace OHOS::Rosen \ No newline at end of file diff --git a/dmserver/src/display_manager_proxy.cpp b/dmserver/src/display_manager_proxy.cpp index c69c99c218..b8d3906bcd 100644 --- a/dmserver/src/display_manager_proxy.cpp +++ b/dmserver/src/display_manager_proxy.cpp @@ -81,58 +81,60 @@ DisplayInfo DisplayManagerProxy::GetDisplayInfoById(DisplayId displayId) return *info; } -DisplayId DisplayManagerProxy::CreateVirtualDisplay(const VirtualDisplayInfo &virtualDisplayInfo, - sptr surface) +ScreenId DisplayManagerProxy::CreateVirtualScreen(VirtualScreenOption virtualOption) { sptr remote = Remote(); if (remote == nullptr) { - WLOGFW("create virtual display: remote is nullptr"); - return DISPLAY_ID_INVALD; + WLOGFW("DisplayManagerProxy::CreateVirtualScreen: remote is nullptr"); + return SCREEN_ID_INVALD; } MessageParcel data; MessageParcel reply; MessageOption option; if (!data.WriteInterfaceToken(GetDescriptor())) { - WLOGFE("create virtual display: WriteInterfaceToken failed"); - return DISPLAY_ID_INVALD; + WLOGFE("DisplayManagerProxy::CreateVirtualScreen: WriteInterfaceToken failed"); + return SCREEN_ID_INVALD; } - bool res = data.WriteParcelable(&virtualDisplayInfo) && - data.WriteRemoteObject(surface->GetProducer()->AsObject()); + bool res = data.WriteString(virtualOption.name_) && data.WriteUint32(virtualOption.width_) && + data.WriteUint32(virtualOption.height_) && data.WriteFloat(virtualOption.density_) && + data.WriteRemoteObject(virtualOption.surface_->GetProducer()->AsObject()) && + data.WriteInt32(virtualOption.flags_); if (!res) { - return DISPLAY_ID_INVALD; + WLOGFE("DisplayManagerProxy::Write data failed"); + return SCREEN_ID_INVALD; } - if (remote->SendRequest(TRANS_ID_CREATE_VIRTUAL_DISPLAY, data, reply, option) != ERR_NONE) { - WLOGFW("create virtual display: SendRequest failed"); - return DISPLAY_ID_INVALD; + if (remote->SendRequest(TRANS_ID_CREATE_VIRTUAL_SCREEN, data, reply, option) != ERR_NONE) { + WLOGFW("DisplayManagerProxy::CreateVirtualScreen: SendRequest failed"); + return SCREEN_ID_INVALD; } - DisplayId displayId = reply.ReadUint64(); - WLOGFI("DisplayManagerProxy::CreateVirtualDisplay %" PRIu64"", displayId); - return displayId; + ScreenId screenId = static_cast(reply.ReadUint64()); + WLOGFI("DisplayManagerProxy::CreateVirtualScreen %" PRIu64"", screenId); + return screenId; } -bool DisplayManagerProxy::DestroyVirtualDisplay(DisplayId displayId) +DMError DisplayManagerProxy::DestroyVirtualScreen(ScreenId screenId) { sptr remote = Remote(); if (remote == nullptr) { - WLOGFW("destroy virtual display: remote is nullptr"); - return false; + WLOGFW("DisplayManagerProxy::DestroyVirtualScreen: remote is nullptr"); + return DMError::DM_ERROR_REMOTE_CREATE_FAILED; } MessageParcel data; MessageParcel reply; MessageOption option; if (!data.WriteInterfaceToken(GetDescriptor())) { - WLOGFE("destroy virtual display: WriteInterfaceToken failed"); - return false; + WLOGFE("DisplayManagerProxy::DestroyVirtualScreen: WriteInterfaceToken failed"); + return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED; } - data.WriteUint64(static_cast(displayId)); - if (remote->SendRequest(TRANS_ID_DESTROY_VIRTUAL_DISPLAY, data, reply, option) != ERR_NONE) { - WLOGFW("destroy virtual display: SendRequest failed"); - return false; + data.WriteUint64(static_cast(screenId)); + if (remote->SendRequest(TRANS_ID_DESTROY_VIRTUAL_SCREEN, data, reply, option) != ERR_NONE) { + WLOGFW("DisplayManagerProxy::DestroyVirtualScreen: SendRequest failed"); + return DMError::DM_ERROR_IPC_FAILED; } - return reply.ReadBool(); + return static_cast(reply.ReadInt32()); } std::shared_ptr DisplayManagerProxy::GetDispalySnapshot(DisplayId displayId) @@ -375,4 +377,33 @@ void DisplayManagerProxy::NotifyDisplayEvent(DisplayEvent event) return; } } + +DMError DisplayManagerProxy::AddMirror(ScreenId mainScreenId, ScreenId mirrorScreenId) +{ + sptr remote = Remote(); + if (remote == nullptr) { + WLOGFW("DisplayManagerProxy::AddMirror: remote is nullptr"); + return DMError::DM_ERROR_REMOTE_CREATE_FAILED; + } + + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + WLOGFE("DisplayManagerProxy::AddMirror: WriteInterfaceToken failed"); + return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED; + } + bool res = data.WriteUint64(static_cast(mainScreenId)) && + data.WriteUint64(static_cast(mirrorScreenId)); + if (!res) { + WLOGFE("DisplayManagerProxy::AddMirror: data write failed"); + return DMError::DM_ERROR_WRITE_DATA_FAILED; + } + if (remote->SendRequest(TRANS_ID_ADD_MIRROR, data, reply, option) != ERR_NONE) { + WLOGFW("DisplayManagerProxy::AddMirror: SendRequest failed"); + return DMError::DM_ERROR_IPC_FAILED; + } + WLOGFI("DisplayManagerProxy::AddMirror"); + return static_cast(reply.ReadInt32()); +} } // namespace OHOS::Rosen \ No newline at end of file diff --git a/dmserver/src/display_manager_service.cpp b/dmserver/src/display_manager_service.cpp index f9a609c3de..8c9e58bbd7 100644 --- a/dmserver/src/display_manager_service.cpp +++ b/dmserver/src/display_manager_service.cpp @@ -14,6 +14,7 @@ */ #include "display_manager_service.h" +#include "window_manager_service.h" #include #include @@ -24,6 +25,8 @@ #include "window_manager_hilog.h" +#include "transaction/rs_interfaces.h" + namespace OHOS::Rosen { namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "DisplayManagerService"}; @@ -88,21 +91,31 @@ DisplayInfo DisplayManagerService::GetDisplayInfoById(DisplayId displayId) return displayInfo; } -DisplayId DisplayManagerService::CreateVirtualDisplay(const VirtualDisplayInfo &virtualDisplayInfo, - sptr surface) +ScreenId DisplayManagerService::CreateVirtualScreen(VirtualScreenOption option) { - WLOGFI("name %{public}s, width %{public}u, height %{public}u, mirrotId %{public}" PRIu64", flags %{public}d", - virtualDisplayInfo.name_.c_str(), virtualDisplayInfo.width_, virtualDisplayInfo.height_, - virtualDisplayInfo.displayIdToMirror_, virtualDisplayInfo.flags_); - ScreenId screenId = abstractDisplayController_->CreateVirtualScreen(virtualDisplayInfo, surface); - return GetDisplayIdFromScreenId(screenId); + ScreenId screenId = abstractScreenController_->CreateVirtualScreen(option); + if (screenId == SCREEN_ID_INVALD) { + WLOGFE("DisplayManagerService::CreateVirtualScreen: Get virtualScreenId failed"); + return SCREEN_ID_INVALD; + } + return screenId; } -bool DisplayManagerService::DestroyVirtualDisplay(DisplayId displayId) +DMError DisplayManagerService::DestroyVirtualScreen(ScreenId screenId) { - WLOGFI("DisplayManagerService::DestroyVirtualDisplay"); - ScreenId screenId = GetScreenIdFromDisplayId(displayId); - return abstractDisplayController_->DestroyVirtualScreen(screenId); + WLOGFI("DisplayManagerService::DestroyVirtualScreen"); + if (screenId == SCREEN_ID_INVALID) { + WLOGFE("DisplayManagerService: virtualScreenId is invalid"); + return DMError::DM_ERROR_INVALID_PARAM; + } + std::map>::iterator iter = displayNodeMap_.find(screenId); + if (iter == displayNodeMap_.end()) { + WLOGFE("DisplayManagerService: displayNode is nullptr"); + return abstractScreenController_->DestroyVirtualScreen(screenId); + } + displayNodeMap_[screenId]->RemoveFromTree(); + displayNodeMap_.erase(screenId); + return abstractScreenController_->DestroyVirtualScreen(screenId); } std::shared_ptr DisplayManagerService::GetDispalySnapshot(DisplayId displayId) @@ -259,4 +272,25 @@ void DMAgentDeathRecipient::OnRemoteDied(const wptr& wptrDeath) WLOGFI("call OnRemoteDied callback"); callback_(object); } + +DMError DisplayManagerService::AddMirror(ScreenId mainScreenId, ScreenId mirrorScreenId) +{ + if (mainScreenId == SCREEN_ID_INVALID) { + return DMError::DM_ERROR_INVALID_PARAM; + } + std::shared_ptr displayNode = + SingletonContainer::Get().GetDisplayNode(mainScreenId); + if (displayNode == nullptr) { + WLOGFE("DisplayManagerService::AddMirror: GetDisplayNode failed, displayNode is nullptr"); + return DMError::DM_ERROR_NULLPTR; + } + NodeId nodeId = displayNode->GetId(); + + struct RSDisplayNodeConfig config = {mirrorScreenId, true, nodeId}; + displayNodeMap_[mainScreenId] = RSDisplayNode::Create(config); + auto transactionProxy = RSTransactionProxy::GetInstance(); + transactionProxy->FlushImplicitTransaction(); + WLOGFI("DisplayManagerService::AddMirror: NodeId: %{public}" PRIu64 "", nodeId >> 32); + return DMError::DM_OK; +} } // namespace OHOS::Rosen \ No newline at end of file diff --git a/dmserver/src/display_manager_stub.cpp b/dmserver/src/display_manager_stub.cpp index b0232b6cd4..7e089ace0b 100644 --- a/dmserver/src/display_manager_stub.cpp +++ b/dmserver/src/display_manager_stub.cpp @@ -15,6 +15,8 @@ #include "display_manager_stub.h" +#include "dm_common.h" + #include #include "window_manager_hilog.h" @@ -46,20 +48,31 @@ int32_t DisplayManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, reply.WriteParcelable(&info); break; } - case TRANS_ID_CREATE_VIRTUAL_DISPLAY: { - VirtualDisplayInfo* virtualDisplayInfo = data.ReadParcelable(); + case TRANS_ID_CREATE_VIRTUAL_SCREEN: { + std::string name = data.ReadString(); + uint32_t width = data.ReadUint32(); + uint32_t height = data.ReadUint32(); + float density = data.ReadFloat(); sptr surfaceObject = data.ReadRemoteObject(); sptr bp = iface_cast(surfaceObject); sptr surface = Surface::CreateSurfaceAsProducer(bp); - DisplayId virtualId = CreateVirtualDisplay(*virtualDisplayInfo, surface); - reply.WriteUint64(virtualId); - virtualDisplayInfo = nullptr; + int32_t flags = data.ReadInt32(); + VirtualScreenOption option = { + .name_ = name, + .width_ = width, + .height_ = height, + .density_ = density, + .surface_ = surface, + .flags_ = flags + }; + ScreenId screenId = CreateVirtualScreen(option); + reply.WriteUint64(static_cast(screenId)); break; } - case TRANS_ID_DESTROY_VIRTUAL_DISPLAY: { - DisplayId virtualId = static_cast(data.ReadUint64()); - bool result = DestroyVirtualDisplay(virtualId); - reply.WriteBool(result); + case TRANS_ID_DESTROY_VIRTUAL_SCREEN: { + ScreenId screenId = static_cast(data.ReadUint64()); + DMError result = DestroyVirtualScreen(screenId); + reply.WriteInt32(static_cast(result)); break; } case TRANS_ID_GET_DISPLAY_SNAPSHOT: { @@ -122,6 +135,13 @@ int32_t DisplayManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, NotifyDisplayEvent(event); break; } + case TRANS_ID_ADD_MIRROR: { + ScreenId mainScreenId = static_cast(data.ReadUint64()); + ScreenId mirrorScreenId = static_cast(data.ReadUint64()); + DMError result = AddMirror(mainScreenId, mirrorScreenId); + reply.WriteInt32(static_cast(result)); + break; + } default: WLOGFW("unknown transaction code"); return IPCObjectStub::OnRemoteRequest(code, data, reply, option); diff --git a/interfaces/innerkits/dm/display_manager.h b/interfaces/innerkits/dm/display_manager.h index 80f1c1f1d8..4d3067ddec 100644 --- a/interfaces/innerkits/dm/display_manager.h +++ b/interfaces/innerkits/dm/display_manager.h @@ -24,7 +24,6 @@ #include "display.h" #include "dm_common.h" #include "singleton_delegator.h" -#include "virtual_display_info.h" // #include "wm_common.h" @@ -44,10 +43,6 @@ public: std::vector GetAllDisplayIds(); - DisplayId CreateVirtualDisplay(const std::string &name, uint32_t width, uint32_t height, - sptr surface, DisplayId displayIdToMirror, int32_t flags); - - bool DestroyVirtualDisplay(DisplayId displayId); std::shared_ptr GetScreenshot(DisplayId displayId); std::shared_ptr GetScreenshot(DisplayId displayId, const Media::Rect &rect, const Media::Size &size, int rotation); diff --git a/interfaces/innerkits/dm/dm_common.h b/interfaces/innerkits/dm/dm_common.h index 4bd162489a..aacbca50fc 100644 --- a/interfaces/innerkits/dm/dm_common.h +++ b/interfaces/innerkits/dm/dm_common.h @@ -43,6 +43,20 @@ enum class DisplayState : uint32_t { enum class DisplayEvent : uint32_t { UNLOCK }; + +enum class DMError : int32_t { + DM_OK = 0, + DM_ERROR_INIT_DMS_PROXY_LOCKED = 100, + DM_ERROR_IPC_FAILED = 101, + DM_ERROR_REMOTE_CREATE_FAILED = 110, + DM_ERROR_NULLPTR = 120, + DM_ERROR_INVALID_PARAM = 130, + DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED = 140, + DM_ERROR_DEATH_RECIPIENT = 150, + DM_ERROR_INVALID_MODE_ID = 160, + DM_ERROR_WRITE_DATA_FAILED = 170, + DM_ERROR_UNKNOWN, +}; using DisplayStateCallback = std::function; enum class DisplayPowerEvent : uint32_t { diff --git a/interfaces/innerkits/dm/screen.h b/interfaces/innerkits/dm/screen.h index ae2221364c..cc902bdda0 100644 --- a/interfaces/innerkits/dm/screen.h +++ b/interfaces/innerkits/dm/screen.h @@ -31,7 +31,7 @@ struct Point { }; struct VirtualScreenOption { - const std::string& name_; + const std::string name_; uint32_t width_; uint32_t height_; float density_; diff --git a/interfaces/innerkits/dm/screen_manager.h b/interfaces/innerkits/dm/screen_manager.h index 7900ef8bc0..3310d2fdac 100644 --- a/interfaces/innerkits/dm/screen_manager.h +++ b/interfaces/innerkits/dm/screen_manager.h @@ -18,8 +18,10 @@ #include #include "screen.h" +#include "dm_common.h" #include "screen_group.h" #include "wm_single_instance.h" +#include "wm_single_instance.h" namespace OHOS::Rosen { class IScreenChangeListener : public RefBase { @@ -34,10 +36,13 @@ WM_DECLARE_SINGLE_INSTANCE_BASE(ScreenManager); public: sptr GetScreenById(ScreenId id); std::vector> GetAllScreens(); + void RegisterScreenChangeListener(sptr listener); - sptr makeExpand(std::vector screenId, std::vector startPoint); - sptr makeMirror(ScreenId mainScreenId, std::vector mirrorScreenId); - sptr createVirtualScreen(VirtualScreenOption option); + sptr MakeExpand(std::vector screenId, std::vector startPoint); + sptr MakeMirror(ScreenId mainScreenId, std::vector mirrorScreenId); + sptr AddMirror(ScreenId mainScreenId, ScreenId mirrorScreenId); + ScreenId CreateVirtualScreen(VirtualScreenOption option); + DMError DestroyVirtualScreen(ScreenId screenId); private: ScreenManager(); diff --git a/utils/BUILD.gn b/utils/BUILD.gn index 722750966e..f8a56ff343 100644 --- a/utils/BUILD.gn +++ b/utils/BUILD.gn @@ -31,7 +31,6 @@ ohos_shared_library("libwmutil") { sources = [ "src/display_info.cpp", "src/singleton_container.cpp", - "src/virtual_display_info.cpp", "src/window_property.cpp", "src/wm_trace.cpp", ] diff --git a/utils/include/virtual_display_info.h b/utils/include/virtual_display_info.h deleted file mode 100644 index cb45bc7803..0000000000 --- a/utils/include/virtual_display_info.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef FOUNDATION_VIRTUAL_DISPLAY_INFO_H -#define FOUNDATION_VIRTUAL_DISPLAY_INFO_H - -#include - -#include - -#include - -#include "display.h" - -namespace OHOS::Rosen { -class VirtualDisplayInfo : public Parcelable { -public: - VirtualDisplayInfo(); - VirtualDisplayInfo(const std::string &name, uint32_t width, uint32_t height, - DisplayId displayIdToMirror, int32_t flags); - ~VirtualDisplayInfo() = default; - - virtual bool Marshalling(Parcel& parcel) const override; - static VirtualDisplayInfo* Unmarshalling(Parcel& parcel); - - std::string name_; - uint32_t width_; - uint32_t height_; - DisplayId displayIdToMirror_; - int32_t flags_; -}; -} // namespace OHOS::Rosen - -#endif // FOUNDATION_VIRTUAL_DISPLAY_INFO_H \ No newline at end of file diff --git a/utils/src/virtual_display_info.cpp b/utils/src/virtual_display_info.cpp deleted file mode 100644 index 9542f71511..0000000000 --- a/utils/src/virtual_display_info.cpp +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "virtual_display_info.h" - -namespace OHOS::Rosen { -VirtualDisplayInfo::VirtualDisplayInfo() -{ - name_ = ""; - width_ = 0; - height_ = 0; - displayIdToMirror_ = 0; - flags_ = 0; -} - -VirtualDisplayInfo::VirtualDisplayInfo(const std::string &name, uint32_t width, uint32_t height, - DisplayId displayIdToMirror, int32_t flags) -{ - name_ = name; - width_ = width; - height_ = height; - displayIdToMirror_ = displayIdToMirror; - flags_ = flags; -} - -bool VirtualDisplayInfo::Marshalling(Parcel &parcel) const -{ - return parcel.WriteString(name_) && parcel.WriteUint32(width_) && - parcel.WriteUint32(height_) && parcel.WriteUint64(displayIdToMirror_) && - parcel.WriteInt32(flags_); -} - -VirtualDisplayInfo* VirtualDisplayInfo::Unmarshalling(Parcel &parcel) -{ - VirtualDisplayInfo *virtualDisplayInfo = new VirtualDisplayInfo(); - if (virtualDisplayInfo == nullptr) { - return nullptr; - } - bool res = parcel.ReadString(virtualDisplayInfo->name_) && - parcel.ReadUint32(virtualDisplayInfo->width_) && - parcel.ReadUint32(virtualDisplayInfo->height_) && - parcel.ReadUint64(virtualDisplayInfo->displayIdToMirror_) && - parcel.ReadInt32(virtualDisplayInfo->flags_); - if (!res) { - return nullptr; - } - return virtualDisplayInfo; -} -} // namespace OHOS::Rosen \ No newline at end of file -- Gitee From 3a9341261c995ae00a7629cc1050138f60630984 Mon Sep 17 00:00:00 2001 From: xiahaiqin Date: Sun, 16 Jan 2022 20:44:56 +0800 Subject: [PATCH 05/57] split libdms Signed-off-by: xiahaiqin Change-Id: Ie6d4a88aeeb7f3c7a7e379a5d3218a44f1bc3ece --- bundle.json | 1 + dmserver/BUILD.gn | 74 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 dmserver/BUILD.gn diff --git a/bundle.json b/bundle.json index 09f6e181c5..e354583f8c 100644 --- a/bundle.json +++ b/bundle.json @@ -21,6 +21,7 @@ "//foundation/windowmanager/sa_profile:wms_sa_profile", "//foundation/windowmanager/adapter:libwmadapter", "//foundation/windowmanager/dm:libdm", + "//foundation/windowmanager/dmserver:libdms", "//foundation/windowmanager/wm:libwm", "//foundation/windowmanager/wmserver:libwms", "//foundation/windowmanager/utils:libwmutil", diff --git a/dmserver/BUILD.gn b/dmserver/BUILD.gn new file mode 100644 index 0000000000..ed23069e0a --- /dev/null +++ b/dmserver/BUILD.gn @@ -0,0 +1,74 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/ohos.gni") + +## Build libdms.so +config("libdms_private_config") { + include_dirs = [ + "../dm/include", + + # todo need delete it + "../wmserver/include", + "../wm/include", + "../interfaces/innerkits/wm", + "../wmserver/include/window_snapshot", + ] +} + +config("libdms_public_config") { + include_dirs = [ "include" ] +} + +ohos_shared_library("libdms") { + sources = [ + "../dm/src/zidl/display_manager_agent_proxy.cpp", + "src/abstract_display.cpp", + "src/abstract_display_controller.cpp", + "src/abstract_screen.cpp", + "src/abstract_screen_controller.cpp", + "src/display_manager_service.cpp", + "src/display_manager_service_inner.cpp", + "src/display_manager_stub.cpp", + "src/display_node_control.cpp", + "src/display_power_controller.cpp", + ] + + configs = [ ":libdms_private_config" ] + + public_configs = [ ":libdms_public_config" ] + + deps = [ + "//foundation/distributedschedule/safwk/interfaces/innerkits/safwk:system_ability_fwk", + "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", + "//foundation/windowmanager/utils:libwmutil", + "//utils/native/base:utils", + + # RSSurface + "//foundation/graphic/standard:libsurface", + "//foundation/graphic/standard/rosen/modules/render_service_base:librender_service_base", + + # todo need delete it + "//foundation/windowmanager/wmserver:libwms", + ] + + external_deps = [ + "bytrace_standard:bytrace_core", + "hilog_native:libhilog", + "ipc:ipc_core", + "window_manager:libdm", + ] + + part_name = "window_manager" + subsystem_name = "window" +} -- Gitee From b0bac8574620636f58877fb2c6022ecfcc5c811e Mon Sep 17 00:00:00 2001 From: l00574490 Date: Sat, 15 Jan 2022 18:42:24 +0800 Subject: [PATCH 06/57] support vertical screen Change-Id: Ibdb7978961ca2d9ae04eee5e74ce97ed58a5f707 Signed-off-by: l00574490 --- wmserver/include/window_layout_policy.h | 5 ++ wmserver/include/window_node_container.h | 4 ++ wmserver/include/window_root.h | 1 + wmserver/src/window_controller.cpp | 8 ++- wmserver/src/window_layout_policy.cpp | 73 +++++++++++++++++++----- wmserver/src/window_node_container.cpp | 51 +++++++++++++---- wmserver/src/window_root.cpp | 10 ++++ 7 files changed, 127 insertions(+), 25 deletions(-) diff --git a/wmserver/include/window_layout_policy.h b/wmserver/include/window_layout_policy.h index a9dc89d352..b83d5f0c3c 100644 --- a/wmserver/include/window_layout_policy.h +++ b/wmserver/include/window_layout_policy.h @@ -53,6 +53,7 @@ public: void RemoveWindowNode(sptr& node); void UpdateWindowNode(sptr& node); void UpdateLayoutRect(sptr& node); + Rect GetDependDisplayRects() const; private: LayoutDependRects dependRects; @@ -63,6 +64,9 @@ private: WindowType::WINDOW_TYPE_STATUS_BAR, WindowType::WINDOW_TYPE_NAVIGATION_BAR, }; + + void UpdateFloatingLayoutRect(Rect& limitRect, Rect& winRect); + void UpdateSplitLimitRect(const Rect& limitRect, Rect& limitSplitRect); void UpdateLimitRect(const sptr& node, Rect& limitRect); void LayoutWindowTree(); void LayoutWindowNode(sptr& node); @@ -70,6 +74,7 @@ private: void InitLimitRects(); Rect& GetLimitRect(const WindowMode mode); Rect& GetDisplayRect(const WindowMode mode); + void LimitMoveBounds(Rect& rect); }; } } diff --git a/wmserver/include/window_node_container.h b/wmserver/include/window_node_container.h index 6e22a2256c..b6a335ac51 100644 --- a/wmserver/include/window_node_container.h +++ b/wmserver/include/window_node_container.h @@ -60,6 +60,7 @@ public: std::shared_ptr GetDisplayNode() const; void LayoutDividerWindow(sptr& node); void UpdateDisplayInfo(); + bool isVerticalDisplay() const; class DisplayRects : public RefBase { public: @@ -71,6 +72,9 @@ public: void SetSplitRect(const Rect& rect); Rect GetRectByWindowMode(const WindowMode& mode) const; Rect GetDividerRect() const; + bool isVertical_ = false; + Rect displayDependRect_ = {0, 0, 0, 0}; + private: Rect primaryRect_ = {0, 0, 0, 0}; Rect secondaryRect_ = {0, 0, 0, 0}; diff --git a/wmserver/include/window_root.h b/wmserver/include/window_root.h index f8c6145355..0054e99e2f 100644 --- a/wmserver/include/window_root.h +++ b/wmserver/include/window_root.h @@ -66,6 +66,7 @@ public: WMError DestroyWindow(uint32_t windowId); WMError UpdateWindowNode(uint32_t windowId); WMError LayoutDividerWindow(sptr& node); + bool isVerticalDisplay(sptr& node) const; WMError RequestFocus(uint32_t windowId); WMError MinimizeOtherFullScreenAbility(sptr& node); diff --git a/wmserver/src/window_controller.cpp b/wmserver/src/window_controller.cpp index b3dd567983..963bb30517 100644 --- a/wmserver/src/window_controller.cpp +++ b/wmserver/src/window_controller.cpp @@ -105,13 +105,17 @@ WMError WindowController::MoveTo(uint32_t windowId, int32_t x, int32_t y) WLOGFE("could not find window"); return WMError::WM_ERROR_NULLPTR; } + auto property = node->GetWindowProperty(); Rect lastRect = property->GetWindowRect(); Rect newRect; WMError res; if (node->GetWindowType() == WindowType::WINDOW_TYPE_DOCK_SLICE) { - WLOGFI("Moving divider"); - newRect = { x, lastRect.posY_, lastRect.width_, lastRect.height_ }; + if (windowRoot_->isVerticalDisplay(node)) { + newRect = { lastRect.posX_, y, lastRect.width_, lastRect.height_ }; + } else { + newRect = { x, lastRect.posY_, lastRect.width_, lastRect.height_ }; + } property->SetWindowRect(newRect); res = windowRoot_->LayoutDividerWindow(node); if (res != WMError::WM_OK) { diff --git a/wmserver/src/window_layout_policy.cpp b/wmserver/src/window_layout_policy.cpp index 92fe42c7c5..8b67bcd9db 100644 --- a/wmserver/src/window_layout_policy.cpp +++ b/wmserver/src/window_layout_policy.cpp @@ -63,9 +63,9 @@ void WindowLayoutPolicy::LayoutWindowNode(sptr& node) } UpdateLayoutRect(node); if (avoidTypes_.find(node->GetWindowType()) != avoidTypes_.end()) { - UpdateLimitRect(node, dependRects.limitPriRect_); - UpdateLimitRect(node, dependRects.limitSecRect_); UpdateLimitRect(node, dependRects.limitFullRect_); + UpdateSplitLimitRect(dependRects.limitFullRect_, dependRects.limitPriRect_); + UpdateSplitLimitRect(dependRects.limitFullRect_, dependRects.limitSecRect_); } } for (auto& childNode : node->children_) { @@ -100,7 +100,6 @@ void WindowLayoutPolicy::UpdateWindowNode(sptr& node) if (avoidTypes_.find(type) != avoidTypes_.end()) { LayoutWindowTree(); } else if (type == WindowType::WINDOW_TYPE_DOCK_SLICE) { // split screen mode - // TODO: change split screen LayoutWindowTree(); } else { // layout single window LayoutWindowNode(node); @@ -112,6 +111,36 @@ static bool IsLayoutChanged(const Rect& l, const Rect& r) return !((l.posX_ == r.posX_) && (l.posY_ == r.posY_) && (l.width_ == r.width_) && (l.height_ == r.height_)); } +void WindowLayoutPolicy::LimitMoveBounds(Rect& rect) +{ + Rect curRect = rect; + rect.posX_ = std::max(curRect.posX_, dependRects.limitFullRect_.posX_); + rect.posY_ = std::max(curRect.posY_, dependRects.limitFullRect_.posY_); + if (rect.width_ < rect.height_) { + rect.posX_ = std::min(curRect.posX_ + rect.width_, + dependRects.limitFullRect_.posX_ + dependRects.limitFullRect_.width_) - rect.width_; + rect.height_ = curRect.posY_ + curRect.height_ - rect.posY_; + } else { + rect.posY_ = std::min(curRect.posY_ + rect.height_, + dependRects.limitFullRect_.posY_ + dependRects.limitFullRect_.height_) - rect.height_; + rect.width_ = curRect.posX_ + curRect.width_ - rect.posX_; + } +} + +void WindowLayoutPolicy::UpdateFloatingLayoutRect(Rect& limitRect, Rect& winRect) +{ + winRect.width_ = std::min(limitRect.width_, winRect.width_); + winRect.height_ = std::min(limitRect.height_, winRect.height_); + winRect.posX_ = std::max(limitRect.posX_, winRect.posX_); + winRect.posY_ = std::max(limitRect.posY_, winRect.posY_); + winRect.posX_ = std::min( + limitRect.posX_ + static_cast(limitRect.width_) - static_cast(winRect.width_), + winRect.posX_); + winRect.posY_ = std::min( + limitRect.posY_ + static_cast(limitRect.height_) - static_cast(winRect.height_), + winRect.posY_); +} + void WindowLayoutPolicy::UpdateLayoutRect(sptr& node) { auto type = node->GetWindowType(); @@ -140,16 +169,7 @@ void WindowLayoutPolicy::UpdateLayoutRect(sptr& node) } else { // floating window if (subWindow && parentLimit) { // subwidow and limited by parent limitRect = node->parent_->GetLayoutRect(); - winRect.width_ = std::min(limitRect.width_, winRect.width_); - winRect.height_ = std::min(limitRect.height_, winRect.height_); - winRect.posX_ = std::max(limitRect.posX_, winRect.posX_); - winRect.posY_ = std::max(limitRect.posY_, winRect.posY_); - winRect.posX_ = std::min( - limitRect.posX_ + static_cast(limitRect.width_) - static_cast(winRect.width_), - winRect.posX_); - winRect.posY_ = std::min( - limitRect.posY_ + static_cast(limitRect.height_) - static_cast(winRect.height_), - winRect.posY_); + UpdateFloatingLayoutRect(limitRect, winRect); } } // Limit window to the maximum window size @@ -158,6 +178,10 @@ void WindowLayoutPolicy::UpdateLayoutRect(sptr& node) winRect.width_ = std::max(1u, winRect.width_); winRect.height_ = std::max(1u, winRect.height_); + if (node->GetWindowType() == WindowType::WINDOW_TYPE_DOCK_SLICE) { + LimitMoveBounds(winRect); + } + node->SetLayoutRect(winRect); if (IsLayoutChanged(lastRect, winRect)) { node->GetWindowToken()->UpdateWindowRect(winRect); @@ -212,6 +236,29 @@ Rect& WindowLayoutPolicy::GetDisplayRect(const WindowMode mode) } } +Rect WindowLayoutPolicy::GetDependDisplayRects() const +{ + Rect displayRect = dependRects.fullRect_; + Rect limitDisplayRect = dependRects.limitFullRect_; + if (IsLayoutChanged(displayRect, limitDisplayRect)) { + return limitDisplayRect; + } + return displayRect; +} + +void WindowLayoutPolicy::UpdateSplitLimitRect(const Rect& limitRect, Rect& limitSplitRect) +{ + Rect curLimitRect = limitSplitRect; + limitSplitRect.posX_ = std::max(limitRect.posX_, curLimitRect.posX_); + limitSplitRect.posY_ = std::max(limitRect.posY_, curLimitRect.posY_); + limitSplitRect.width_ = std::min(limitRect.posX_ + limitRect.width_, + curLimitRect.posX_ + curLimitRect.width_) - + limitSplitRect.posX_; + limitSplitRect.height_ = std::min(limitRect.posY_ + limitRect.height_, + curLimitRect.posY_ + curLimitRect.height_) - + limitSplitRect.posY_; +} + void WindowLayoutPolicy::UpdateLimitRect(const sptr& node, Rect& limitRect) { auto& layoutRect = node->GetLayoutRect(); diff --git a/wmserver/src/window_node_container.cpp b/wmserver/src/window_node_container.cpp index f367683fd5..fb771bc996 100644 --- a/wmserver/src/window_node_container.cpp +++ b/wmserver/src/window_node_container.cpp @@ -495,18 +495,32 @@ void WindowNodeContainer::LayoutDividerWindow(sptr& node) void WindowNodeContainer::DisplayRects::InitRect(Rect& oriDisplayRect) { + if (oriDisplayRect.width_ < oriDisplayRect.height_) { + isVertical_ = true; + } displayRect_ = oriDisplayRect; - const uint32_t dividerWidth = 50; - dividerRect_ = { static_cast((displayRect_.width_ - dividerWidth) * DEFAULT_SPLIT_RATIO), 0, - dividerWidth, displayRect_.height_ }; - + if (!isVertical_) { + dividerRect_ = { static_cast((displayRect_.width_ - dividerWidth) * DEFAULT_SPLIT_RATIO), 0, + dividerWidth, displayRect_.height_ }; + } else { + dividerRect_ = { 0, static_cast((displayRect_.height_ - dividerWidth) * DEFAULT_SPLIT_RATIO), + displayRect_.width_, dividerWidth }; + } + WLOGFI("init dividerRect :[%{public}d, %{public}d, %{public}d, %{public}d]", + dividerRect_.posX_, dividerRect_.posY_, dividerRect_.width_, dividerRect_.height_); SetSplitRect(dividerRect_); } void WindowNodeContainer::DisplayRects::SetSplitRect(float ratio) { - dividerRect_.posX_ = static_cast((displayRect_.width_ - dividerRect_.width_) * ratio); + if (!isVertical_) { + dividerRect_.posX_ = displayDependRect_.posX_ + static_cast(displayDependRect_.width_ * ratio); + } else { + dividerRect_.posY_ = displayDependRect_.posY_ + static_cast(displayDependRect_.height_ * ratio); + } + WLOGFI("set dividerRect :[%{public}d, %{public}d, %{public}d, %{public}d]", + dividerRect_.posX_, dividerRect_.posY_, dividerRect_.width_, dividerRect_.height_); SetSplitRect(dividerRect_); } @@ -514,13 +528,21 @@ void WindowNodeContainer::DisplayRects::SetSplitRect(const Rect& divRect) { dividerRect_.width_ = divRect.width_; dividerRect_.height_ = divRect.height_; + if (!isVertical_) { + primaryRect_.width_ = divRect.posX_; + primaryRect_.height_ = displayRect_.height_; - primaryRect_.width_ = divRect.posX_; - primaryRect_.height_ = displayRect_.height_; + secondaryRect_.posX_ = divRect.posX_ + dividerRect_.width_; + secondaryRect_.width_ = displayRect_.width_ - secondaryRect_.posX_; + secondaryRect_.height_ = displayRect_.height_; + } else { + primaryRect_.height_ = divRect.posY_; + primaryRect_.width_ = displayRect_.width_; - secondaryRect_.posX_ = divRect.posX_ + dividerRect_.width_; - secondaryRect_.width_ = displayRect_.width_ - secondaryRect_.posX_; - secondaryRect_.height_ = displayRect_.height_; + secondaryRect_.posY_ = divRect.posY_ + dividerRect_.height_; + secondaryRect_.height_ = displayRect_.height_ - secondaryRect_.posY_; + secondaryRect_.width_ = displayRect_.width_; + } } Rect WindowNodeContainer::DisplayRects::GetDividerRect() const @@ -585,6 +607,11 @@ std::shared_ptr WindowNodeContainer::GetDisplayNode() const return displayNode_; } +bool WindowNodeContainer::isVerticalDisplay() const +{ + return displayRects_->isVertical_; +} + void WindowNodeContainer::SendSplitScreenEvent(WindowMode mode) { // should define in common_event_support.h and @ohos.commonEvent.d.ts @@ -626,6 +653,10 @@ WMError WindowNodeContainer::HandleModeChangeToSplit(sptr& triggerNo WM_FUNCTION_TRACE(); WLOGFI("HandleModeChangeToSplit %{public}d", triggerNode->GetWindowId()); auto pairNode = FindSplitPairNode(triggerNode); + displayRects_->displayDependRect_ = layoutPolicy_->GetDependDisplayRects(); // get depend display rect for split + WLOGFI("displayDependRect :[%{public}d, %{public}d, %{public}d, %{public}d]", + displayRects_->displayDependRect_.posX_, displayRects_->displayDependRect_.posY_, + displayRects_->displayDependRect_.width_, displayRects_->displayDependRect_.height_); if (pairNode != nullptr) { WLOGFI("Window %{public}d find pair %{public}d", triggerNode->GetWindowId(), pairNode->GetWindowId()); WMError ret = UpdateWindowPairInfo(triggerNode, pairNode); diff --git a/wmserver/src/window_root.cpp b/wmserver/src/window_root.cpp index a3abc4f104..6b226a6963 100644 --- a/wmserver/src/window_root.cpp +++ b/wmserver/src/window_root.cpp @@ -269,6 +269,16 @@ WMError WindowRoot::LayoutDividerWindow(sptr& node) return WMError::WM_OK; } +bool WindowRoot::isVerticalDisplay(sptr& node) const +{ + auto container = const_cast(this)->GetOrCreateWindowNodeContainer(node->GetDisplayId()); + if (container == nullptr) { + WLOGFE("get display direction failed, window container could not be found"); + return false; + } + return container->isVerticalDisplay(); +} + WMError WindowRoot::RequestFocus(uint32_t windowId) { auto node = GetWindowNode(windowId); -- Gitee From 3f807ff9468181909448dd4662d1b538187f6692 Mon Sep 17 00:00:00 2001 From: wangxinpeng Date: Sat, 15 Jan 2022 17:11:49 +0800 Subject: [PATCH 07/57] dispatch keyboard event to input method Signed-off-by: wangxinpeng Change-Id: I0fdb9724f3821fbc7b3f9ac2fae2073ca3482e58 --- wm/BUILD.gn | 1 + wm/include/window_input_channel.h | 1 + wm/src/window_input_channel.cpp | 29 ++++++++++++++++++++++++----- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/wm/BUILD.gn b/wm/BUILD.gn index 42dcfa781a..de4ee028f7 100644 --- a/wm/BUILD.gn +++ b/wm/BUILD.gn @@ -175,6 +175,7 @@ ohos_shared_library("libwm") { external_deps = [ "aafwk_standard:ability_context_native", "bytrace_standard:bytrace_core", + "inputmethod_native:inputmethod_client", "ipc:ipc_core", ] diff --git a/wm/include/window_input_channel.h b/wm/include/window_input_channel.h index fb700a1d54..c58acb6f95 100644 --- a/wm/include/window_input_channel.h +++ b/wm/include/window_input_channel.h @@ -30,6 +30,7 @@ public: void SetInputListener(std::shared_ptr& listener); private: void OnVsync(int64_t timeStamp); + bool IsKeyboardEvent(const std::shared_ptr& keyEvent) const; std::vector> pointerEventPool_; sptr window_; std::shared_ptr callback_ = diff --git a/wm/src/window_input_channel.cpp b/wm/src/window_input_channel.cpp index c436a5c6a2..07196476a4 100644 --- a/wm/src/window_input_channel.cpp +++ b/wm/src/window_input_channel.cpp @@ -14,7 +14,8 @@ */ #include "window_input_channel.h" -#include +#include +#include "window_manager_hilog.h" namespace OHOS { namespace Rosen { @@ -33,11 +34,20 @@ void WindowInputChannel::HandleKeyEvent(std::shared_ptr& keyEvent WLOGE("HandleKeyEvent keyEvent is nullptr"); return; } - if (inputListener_ != nullptr) { - inputListener_->OnInputEvent(keyEvent); - return; + bool isKeyboardEvent = IsKeyboardEvent(keyEvent); + bool inputMethodHasProcessed = false; + if (isKeyboardEvent) { + WLOGI("dispatch keyEvent to input method"); + inputMethodHasProcessed = MiscServices::InputMethodController::GetInstance()->dispatchKeyEvent(keyEvent); + } + if (!isKeyboardEvent || !inputMethodHasProcessed) { + WLOGI("dispatch keyEvent to ACE"); + if (inputListener_ != nullptr) { + inputListener_->OnInputEvent(keyEvent); + return; + } + window_->ConsumeKeyEvent(keyEvent); } - window_->ConsumeKeyEvent(keyEvent); keyEvent->MarkProcessed(); } @@ -82,5 +92,14 @@ void WindowInputChannel::SetInputListener(std::shared_ptr& keyEvent) const +{ + int32_t keyCode = keyEvent->GetKeyCode(); + bool isKeyFN = (keyCode == MMI::KeyEvent::KEYCODE_FN); + bool isKeyboard = (keyCode >= MMI::KeyEvent::KEYCODE_0 && keyCode <= MMI::KeyEvent::KEYCODE_NUMPAD_RIGHT_PAREN); + WLOGI("isKeyFN: %{public}d, isKeyboard: %{public}d", isKeyFN, isKeyboard); + return (isKeyFN || isKeyboard); +} } } \ No newline at end of file -- Gitee From 53eef7f00cd72c2bd59d342d842b702ac91abe31 Mon Sep 17 00:00:00 2001 From: lu Date: Mon, 17 Jan 2022 10:52:04 +0800 Subject: [PATCH 08/57] Add virtualPixelRatio to Ace::ViewportConfig while UiContent.UpdateViewportConfig Signed-off-by: lu Change-Id: I736a869a74fbeee4468c033f25266ee3d99252b5 --- wm/src/window_impl.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/wm/src/window_impl.cpp b/wm/src/window_impl.cpp index bf2207918e..3d51702401 100644 --- a/wm/src/window_impl.cpp +++ b/wm/src/window_impl.cpp @@ -457,8 +457,15 @@ void WindowImpl::RegisterWindowChangeListener(sptr& liste void WindowImpl::UpdateRect(const struct Rect& rect) { - WLOGFI("winId:%{public}d, rect[%{public}d, %{public}d, %{public}d, %{public}d]", GetWindowId(), rect.posX_, - rect.posY_, rect.width_, rect.height_); + auto display = DisplayManager::GetInstance().GetDisplayById(property_->GetDisplayId()); + if (display == nullptr) { + WLOGFE("get display failed displayId:%{public}d, window id:%{public}u", property_->GetDisplayId(), + property_->GetWindowId()); + return; + } + float virtualPixelRatio = display->GetVirtualPixelRatio(); + WLOGFI("winId:%{public}d, rect[%{public}d, %{public}d, %{public}d, %{public}d], vpr:%{public}f", + GetWindowId(), rect.posX_, rect.posY_, rect.width_, rect.height_, virtualPixelRatio); property_->SetWindowRect(rect); if (windowChangeListener_ != nullptr) { windowChangeListener_->OnSizeChange(rect); @@ -466,6 +473,7 @@ void WindowImpl::UpdateRect(const struct Rect& rect) if (uiContent_ != nullptr) { Ace::ViewportConfig config; config.SetSize(rect.width_, rect.height_); + config.SetDensity(virtualPixelRatio); uiContent_->UpdateViewportConfig(config); WLOGFI("notify uiContent window size change end"); } -- Gitee From 54450ca35a8ee09c530ad8774ed858e9d79f77e3 Mon Sep 17 00:00:00 2001 From: shiyueeee Date: Mon, 17 Jan 2022 11:13:37 +0800 Subject: [PATCH 09/57] Separate external includes as deps Signed-off-by: shiyueeee --- dm/test/systemtest/BUILD.gn | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/dm/test/systemtest/BUILD.gn b/dm/test/systemtest/BUILD.gn index 12801dcd3f..538148102e 100644 --- a/dm/test/systemtest/BUILD.gn +++ b/dm/test/systemtest/BUILD.gn @@ -65,22 +65,6 @@ config("dm_systemtest_common_public_config") { "//foundation/windowmanager/dmserver/include", "//foundation/windowmanager/interfaces/innerkits/dm", "//foundation/windowmanager/utils/include", - "//foundation/communication/ipc/interfaces/innerkits/ipc_core/include", - "//base/hiviewdfx/hilog/interfaces/native/innerkits/include", - "//third_party/googletest/googlemock/include", - - # for abilityContext - "//foundation/aafwk/standard/frameworks/kits/ability/ability_runtime/include", - "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_base/include", - "//foundation/appexecfwk/standard/kits/appkit/native/ability_runtime/context", - "//base/global/resmgr_standard/interfaces/innerkits/include", - "//third_party/node/deps/icu-small/source/common", - "//foundation/aafwk/standard/interfaces/innerkits/ability_manager/include", - "//foundation/aafwk/standard/interfaces/innerkits/want/include/ohos/aafwk/content", - "//foundation/distributedschedule/dmsfwk/services/dtbschedmgr/include", - "//foundation/aafwk/standard/interfaces/innerkits/base/include", - - # abilityContext end ] } @@ -102,6 +86,9 @@ ohos_static_library("dm_systemtest_common") { "//utils/native/base:utils", ] - external_deps = [ "aafwk_standard:ability_context_native" ] + external_deps = [ + "hilog_native:libhilog", + "ipc:ipc_core", + ] } ## Build dm_systemtest_common.a }}} -- Gitee From 1124ff075c60da5deb6f8f862dc692aa246e4c41 Mon Sep 17 00:00:00 2001 From: huandong Date: Mon, 17 Jan 2022 10:56:36 +0800 Subject: [PATCH 10/57] =?UTF-8?q?=E5=A2=9E=E5=8A=A0Avoid=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E7=9A=84Js=E4=BE=A7=E6=8E=A5=E5=8F=A3=EF=BC=8CGetAvoidArea,=20?= =?UTF-8?q?systemAvoidAreaChange=E7=9A=84on/off?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: huandong Change-Id: Idc1ecc18976871a602e3e54519baae065a3e4596 Signed-off-by: huandong --- interfaces/innerkits/wm/window.h | 2 +- .../kits/napi/window_runtime/js_window.cpp | 77 ++++++++++++++++++- .../kits/napi/window_runtime/js_window.h | 5 +- .../window_runtime/js_window_listener.cpp | 32 ++++++++ .../napi/window_runtime/js_window_listener.h | 5 +- .../napi/window_runtime/js_window_utils.cpp | 27 +++++-- .../napi/window_runtime/js_window_utils.h | 2 + 7 files changed, 138 insertions(+), 12 deletions(-) diff --git a/interfaces/innerkits/wm/window.h b/interfaces/innerkits/wm/window.h index f5c9b64e5c..c53b8e58db 100644 --- a/interfaces/innerkits/wm/window.h +++ b/interfaces/innerkits/wm/window.h @@ -46,7 +46,7 @@ public: virtual void OnSizeChange(Rect rect) = 0; }; -class IAvoidAreaChangedListener : public RefBase { +class IAvoidAreaChangedListener : virtual public RefBase { public: virtual void OnAvoidAreaChanged(const std::vector avoidAreas) = 0; }; diff --git a/interfaces/kits/napi/window_runtime/js_window.cpp b/interfaces/kits/napi/window_runtime/js_window.cpp index 7574d78568..3dd83d36d8 100644 --- a/interfaces/kits/napi/window_runtime/js_window.cpp +++ b/interfaces/kits/napi/window_runtime/js_window.cpp @@ -23,6 +23,9 @@ using namespace AbilityRuntime; namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "JsWindow"}; } + +constexpr Rect EMPTY_RECT = {0, 0, 0, 0}; + JsWindow::JsWindow(const sptr& window) : windowToken_(window) { } @@ -138,6 +141,13 @@ NativeValue* JsWindow::SetSystemBarProperties(NativeEngine* engine, NativeCallba return (me != nullptr) ? me->OnSetSystemBarProperties(*engine, *info) : nullptr; } +NativeValue* JsWindow::GetAvoidArea(NativeEngine* engine, NativeCallbackInfo* info) +{ + WLOGFI("JsWindow::GetAvoidArea is called"); + JsWindow* me = CheckParamsAndGetThis(engine, info); + return (me != nullptr) ? me->OnGetAvoidArea(*engine, *info) : nullptr; +} + NativeValue* JsWindow::OnShow(NativeEngine& engine, NativeCallbackInfo& info) { WLOGFI("JsWindow::OnShow is called"); @@ -405,6 +415,10 @@ void JsWindow::RegisterWindowListenerWithType(NativeEngine& engine, std::string sptr thisListener(windowListener); windowToken_->RegisterWindowChangeListener(thisListener); WLOGFI("JsWindow::RegisterWindowListenerWithType windowSizeChange success"); + } else if (type.compare("systemAvoidAreaChange") == 0) { + sptr thisListener(windowListener); + windowToken_->RegisterAvoidAreaChangeListener(thisListener); + WLOGFI("JsWindow::RegisterWindowListenerWithType systemAvoidAreaChange success"); } else { WLOGFE("JsWindow::RegisterWindowListenerWithType failed method: %{public}s not support!", type.c_str()); @@ -432,6 +446,10 @@ void JsWindow::UnregisterAllWindowListenerWithType(std::string type) windowToken_->RegisterWindowChangeListener(thisListener); WLOGFI("JsWindow::UnregisterAllWindowListenerWithType windowSizeChange success"); } + if (type.compare("systemAvoidAreaChange") == 0) { + windowToken_->UnregisterAvoidAreaChangeListener(); + WLOGFI("JsWindow::UnregisterAllWindowListenerWithType systemAvoidAreaChange success"); + } jsListenerMap_.erase(type); jsCallbackMap_.erase(type); return; @@ -460,6 +478,10 @@ void JsWindow::UnregisterWindowListenerWithType(std::string type, NativeValue* v windowToken_->RegisterWindowChangeListener(thisListener); WLOGFI("JsWindow::UnregisterWindowListenerWithType windowSizeChange success"); } + if (type.compare("systemAvoidAreaChange") == 0) { + windowToken_->UnregisterAvoidAreaChangeListener(); + WLOGFI("JsWindow::UnregisterWindowListenerWithType systemAvoidAreaChange success"); + } jsCallbackMap_.erase(type); jsListenerMap_.erase(type); } @@ -490,8 +512,8 @@ NativeValue* JsWindow::OnRegisterWindowCallback(NativeEngine& engine, NativeCall } std::lock_guard lock(mtx_); RegisterWindowListenerWithType(engine, cbType, value); - return engine.CreateUndefined(); - } + return engine.CreateUndefined(); +} NativeValue* JsWindow::OnUnregisterWindowCallback(NativeEngine& engine, NativeCallbackInfo& info) { @@ -514,7 +536,7 @@ NativeValue* JsWindow::OnUnregisterWindowCallback(NativeEngine& engine, NativeCa } else { NativeValue* value = info.argv[ARGC_ONE]; if (!value->IsCallable()) { - WLOGFI("JsWindowManager::OnUnregisterWindowManagerCallback info->argv[1] is not callable"); + WLOGFI("JsWindow::OnUnregisterWindowManagerCallback info->argv[1] is not callable"); return engine.CreateUndefined(); } UnregisterWindowListenerWithType(cbType, value); @@ -719,6 +741,54 @@ NativeValue* JsWindow::OnSetSystemBarProperties(NativeEngine& engine, NativeCall engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result)); return result; } + +NativeValue* JsWindow::OnGetAvoidArea(NativeEngine& engine, NativeCallbackInfo& info) +{ + WLOGFI("JsWindow::OnGetAvoidArea is called"); + if (windowToken_ == nullptr || info.argc < ARGC_ONE) { + WLOGFE("JsWindow windowToken_ is nullptr or param is too small!"); + return engine.CreateUndefined(); + } + // Parse info->argv[0] as AvoidAreaType + NativeNumber* nativeMode = ConvertNativeValueTo(info.argv[0]); + if (nativeMode == nullptr) { + WLOGFE("Failed to convert parameter to AvoidAreaType"); + return engine.CreateUndefined(); + } + AvoidAreaType avoidAreaType = static_cast(static_cast(*nativeMode)); + WLOGFI("JsWindow::OnGetAvoidArea get avoidAreaType success %{public}u", avoidAreaType); + + AsyncTask::CompleteCallback complete = + [this, avoidAreaType](NativeEngine& engine, AsyncTask& task, int32_t status) { + // getAvoidRect by avoidAreaType + AvoidArea avoidArea; + WMError ret = windowToken_->GetAvoidAreaByType(avoidAreaType, avoidArea); + if (ret == WMError::WM_OK) { + WLOGFI("JsWindow::OnGetAvoidArea GetAvoidAreaByType Success"); + } else { + WLOGFE("JsWindow::OnGetAvoidArea GetAvoidAreaByType Failed"); + avoidArea = { EMPTY_RECT, EMPTY_RECT, EMPTY_RECT, EMPTY_RECT }; // left, top, right, bottom + } + + // native avoidArea -> js avoidArea + NativeValue* avoidAreaObj = ChangeAvoidAreaToJsValue(engine, avoidArea); + if (avoidAreaObj != nullptr) { + WLOGFI("JsWindow::OnGetAvoidArea ChangeAvoidAreaToJsValue Success"); + task.Resolve(engine, avoidAreaObj); + } else { + task.Reject(engine, CreateJsError(engine, + static_cast(WMError::WM_ERROR_NULLPTR), "JsWindow::OnGetAvoidArea failed.")); + } + }; + + WLOGFI("JsWindow::OnGetAvoidArea AsyncTask end"); + NativeValue* lastParam = (info.argc == 0) ? nullptr : info.argv[0]; + NativeValue* result = nullptr; + AsyncTask::Schedule( + engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result)); + return result; +} + NativeValue* CreateJsWindowObject(NativeEngine& engine, sptr& window) { WLOGFI("JsWindow::CreateJsWindow is called"); @@ -743,6 +813,7 @@ NativeValue* CreateJsWindowObject(NativeEngine& engine, sptr& window) BindNativeFunction(engine, *object, "setLayoutFullScreen", JsWindow::SetLayoutFullScreen); BindNativeFunction(engine, *object, "setSystemBarEnable", JsWindow::SetSystemBarEnable); BindNativeFunction(engine, *object, "setSystemBarProperties", JsWindow::SetSystemBarProperties); + BindNativeFunction(engine, *object, "getAvoidArea", JsWindow::GetAvoidArea); return objValue; } } // namespace Rosen diff --git a/interfaces/kits/napi/window_runtime/js_window.h b/interfaces/kits/napi/window_runtime/js_window.h index 48c993d4c9..d2de111637 100644 --- a/interfaces/kits/napi/window_runtime/js_window.h +++ b/interfaces/kits/napi/window_runtime/js_window.h @@ -41,11 +41,12 @@ public: static NativeValue* RegisterWindowCallback(NativeEngine* engine, NativeCallbackInfo* info); static NativeValue* UnregisterWindowCallback(NativeEngine* engine, NativeCallbackInfo* info); static NativeValue* LoadContent(NativeEngine* engine, NativeCallbackInfo* info); - static NativeValue* SetFullScreen(NativeEngine* engine, NativeCallbackInfo* info); static NativeValue* SetLayoutFullScreen(NativeEngine* engine, NativeCallbackInfo* info); static NativeValue* SetSystemBarEnable(NativeEngine* engine, NativeCallbackInfo* info); static NativeValue* SetSystemBarProperties(NativeEngine* engine, NativeCallbackInfo* info); + static NativeValue* GetAvoidArea(NativeEngine* engine, NativeCallbackInfo* info); + private: bool IfCallbackRegistered(std::string type, NativeValue* jsListenerObject); void RegisterWindowListenerWithType(NativeEngine& engine, std::string type, NativeValue* value); @@ -66,6 +67,8 @@ private: NativeValue* OnSetSystemBarEnable(NativeEngine& engine, NativeCallbackInfo& info); NativeValue* OnSetSystemBarProperties(NativeEngine& engine, NativeCallbackInfo& info); NativeValue* OnLoadContent(NativeEngine& engine, NativeCallbackInfo& info); + NativeValue* OnGetAvoidArea(NativeEngine& engine, NativeCallbackInfo& info); + sptr windowToken_ = nullptr; std::map>> jsCallbackMap_; std::map> jsListenerMap_; diff --git a/interfaces/kits/napi/window_runtime/js_window_listener.cpp b/interfaces/kits/napi/window_runtime/js_window_listener.cpp index 274e2a2ae1..94a022cf85 100644 --- a/interfaces/kits/napi/window_runtime/js_window_listener.cpp +++ b/interfaces/kits/napi/window_runtime/js_window_listener.cpp @@ -23,6 +23,8 @@ namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "JsWindowListener"}; } +constexpr uint32_t AVOID_AREA_NUM = 4; + void JsWindowListener::AddCallback(NativeValue* jsListenerObject) { WLOGFI("JsWindowListener::AddCallbackAndRegister is called"); @@ -113,5 +115,35 @@ void JsWindowListener::OnSystemBarPropertyChange(uint64_t displayId, SystemBarPr NativeValue* argv[] = {propertyValue}; CallJsMethod("systemUiTintChange", argv, ArraySize(argv)); } + +void JsWindowListener::OnAvoidAreaChanged(const std::vector avoidAreas) +{ + std::lock_guard lock(mtx_); + WLOGFI("OnAvoidAreaChanged is called"); + if (jsCallBack_.empty()) { + WLOGFE("OnAvoidAreaChanged systemAvoidAreaChange not register!"); + return; + } + + NativeValue* avoidAreaValue = engine_->CreateObject(); + NativeObject* object = ConvertNativeValueTo(avoidAreaValue); + if (object == nullptr) { + WLOGFE("Failed to convert rect to jsObject"); + return; + } + + if (static_cast(avoidAreas.size()) != AVOID_AREA_NUM) { + WLOGFE("AvoidAreas size is not 4 (left, top, right, bottom). Current avoidAreas size is %{public}u", + static_cast(avoidAreas.size())); + return; + } + + object->SetProperty("leftRect", GetRectAndConvertToJsValue(*engine_, avoidAreas[0])); // idx 0 : leftRect + object->SetProperty("topRect", GetRectAndConvertToJsValue(*engine_, avoidAreas[1])); // idx 1 : topRect + object->SetProperty("rightRect", GetRectAndConvertToJsValue(*engine_, avoidAreas[2])); // idx 2 : rightRect + object->SetProperty("bottomRect", GetRectAndConvertToJsValue(*engine_, avoidAreas[3])); // idx 3 : bottomRect + NativeValue* argv[] = {avoidAreaValue}; + CallJsMethod("systemAvoidAreaChange", argv, ArraySize(argv)); +} } // namespace Rosen } // namespace OHOS \ No newline at end of file diff --git a/interfaces/kits/napi/window_runtime/js_window_listener.h b/interfaces/kits/napi/window_runtime/js_window_listener.h index be1548597d..599a5c3c2d 100644 --- a/interfaces/kits/napi/window_runtime/js_window_listener.h +++ b/interfaces/kits/napi/window_runtime/js_window_listener.h @@ -29,7 +29,8 @@ namespace OHOS { namespace Rosen { class JsWindowListener : public IWindowChangeListener, - public ISystemBarChangedListener { + public ISystemBarChangedListener, + public IAvoidAreaChangedListener { public: explicit JsWindowListener(NativeEngine* engine) : engine_(engine) {} virtual ~JsWindowListener() = default; @@ -38,6 +39,8 @@ public: void RemoveCallback(NativeValue* jsListenerObject); void OnSystemBarPropertyChange(uint64_t displayId, SystemBarProps props) override; void OnSizeChange(Rect rect) override; + void OnAvoidAreaChanged(const std::vector avoidAreas) override; + private: void CallJsMethod(const char* methodName, NativeValue* const* argv = nullptr, size_t argc = 0); NativeEngine* engine_ = nullptr; diff --git a/interfaces/kits/napi/window_runtime/js_window_utils.cpp b/interfaces/kits/napi/window_runtime/js_window_utils.cpp index 60f97e0ca6..82c8092de1 100644 --- a/interfaces/kits/napi/window_runtime/js_window_utils.cpp +++ b/interfaces/kits/napi/window_runtime/js_window_utils.cpp @@ -25,7 +25,7 @@ namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "JsWindowUtils"}; } -static NativeValue* GetRectAndConvertToJsValue(NativeEngine& engine, const Rect rect) +NativeValue* GetRectAndConvertToJsValue(NativeEngine& engine, const Rect rect) { NativeValue* objValue = engine.CreateObject(); NativeObject* object = ConvertNativeValueTo(objValue); @@ -42,7 +42,7 @@ static NativeValue* GetRectAndConvertToJsValue(NativeEngine& engine, const Rect NativeValue* CreateJsWindowPropertiesObject(NativeEngine& engine, sptr& window) { - WLOGFI("JsWindow::CreateJsWindowPropertiesObject is called"); + WLOGFI("JsWindowUtils::CreateJsWindowPropertiesObject is called"); NativeValue* objValue = engine.CreateObject(); NativeObject* object = ConvertNativeValueTo(objValue); if (object == nullptr) { @@ -76,7 +76,7 @@ static std::string GetHexColor(uint32_t color) static NativeValue* CreateJsSystemBarRegionTintObject(NativeEngine& engine, WindowType type, const SystemBarProperty& prop) { - WLOGFI("JsWindow::CreateJsSystemBarRegionTintObject is called"); + WLOGFI("JsWindowUtils::CreateJsSystemBarRegionTintObject is called"); NativeValue* objValue = engine.CreateObject(); NativeObject* object = ConvertNativeValueTo(objValue); @@ -87,10 +87,10 @@ static NativeValue* CreateJsSystemBarRegionTintObject(NativeEngine& engine, object->SetProperty("type", CreateJsValue(engine, static_cast(type))); object->SetProperty("isEnable", CreateJsValue(engine, prop.enable_)); std::string bkgColor = GetHexColor(prop.backgroundColor_); - WLOGFI("JsWindow::CreateJsSystemBarRegionTintObject backgroundColir: %{public}s", bkgColor.c_str()); + WLOGFI("JsWindowUtils::CreateJsSystemBarRegionTintObject backgroundColir: %{public}s", bkgColor.c_str()); object->SetProperty("backgroundColor", CreateJsValue(engine, bkgColor)); std::string contentColor = GetHexColor(prop.contentColor_); - WLOGFI("JsWindow::CreateJsSystemBarRegionTintObject contentColor: %{public}s", contentColor.c_str()); + WLOGFI("JsWindowUtils::CreateJsSystemBarRegionTintObject contentColor: %{public}s", contentColor.c_str()); object->SetProperty("contentColor", CreateJsValue(engine, contentColor)); Rect rect = {0, 0, 0, 0}; // to fix on next version object->SetProperty("region", GetRectAndConvertToJsValue(engine, rect)); @@ -100,7 +100,7 @@ static NativeValue* CreateJsSystemBarRegionTintObject(NativeEngine& engine, NativeValue* CreateJsSystemBarRegionTintArrayObject(NativeEngine& engine, const SystemBarProps& props) { - WLOGFI("JsWindow::CreateJsSystemBarRegionTintArrayObject is called"); + WLOGFI("JsWindowUtils::CreateJsSystemBarRegionTintArrayObject is called"); if (props.empty()) { return nullptr; } @@ -224,5 +224,20 @@ bool SetSystemBarPropertiesFromJs(NativeEngine& engine, NativeObject* jsObject, } return true; } + +NativeValue* ChangeAvoidAreaToJsValue(NativeEngine& engine, const AvoidArea& avoidArea) +{ + NativeValue* objValue = engine.CreateObject(); + NativeObject* object = ConvertNativeValueTo(objValue); + if (object == nullptr) { + WLOGFE("Failed to convert rect to jsObject"); + return engine.CreateUndefined(); + } + object->SetProperty("leftRect", GetRectAndConvertToJsValue(engine, avoidArea.leftRect)); + object->SetProperty("topRect", GetRectAndConvertToJsValue(engine, avoidArea.topRect)); + object->SetProperty("rightRect", GetRectAndConvertToJsValue(engine, avoidArea.rightRect)); + object->SetProperty("bottomRect", GetRectAndConvertToJsValue(engine, avoidArea.bottomRect)); + return objValue; +} } // namespace Rosen } // namespace OHOS \ No newline at end of file diff --git a/interfaces/kits/napi/window_runtime/js_window_utils.h b/interfaces/kits/napi/window_runtime/js_window_utils.h index d5f357c9b9..004e73ce7f 100644 --- a/interfaces/kits/napi/window_runtime/js_window_utils.h +++ b/interfaces/kits/napi/window_runtime/js_window_utils.h @@ -33,6 +33,7 @@ namespace { constexpr int32_t RGBA_LENGTH = 8; } + NativeValue* GetRectAndConvertToJsValue(NativeEngine& engine, const Rect rect); NativeValue* CreateJsWindowPropertiesObject(NativeEngine& engine, sptr& window); bool SetSystemBarPropertiesFromJs(NativeEngine& engine, NativeObject* jsObject, std::map& properties, sptr& window); @@ -40,6 +41,7 @@ namespace { NativeEngine& engine, NativeCallbackInfo& info, sptr& window); NativeValue* CreateJsSystemBarRegionTintArrayObject(NativeEngine& engine, const SystemBarProps& props); + NativeValue* ChangeAvoidAreaToJsValue(NativeEngine& engine, const AvoidArea& avoidArea); } } #endif \ No newline at end of file -- Gitee From 62e1db248149678b542e965ea68b0dba19cee4bb Mon Sep 17 00:00:00 2001 From: fanby01 Date: Mon, 17 Jan 2022 16:55:05 +0800 Subject: [PATCH 11/57] clear SecSolar warning Signed-off-by: fanby01 Change-Id: I8d52cdc61abfc0310322114edf98c10ffbb93d3d --- snapshot/snapshot_utils.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/snapshot/snapshot_utils.cpp b/snapshot/snapshot_utils.cpp index e868240f72..a973ddc4e8 100644 --- a/snapshot/snapshot_utils.cpp +++ b/snapshot/snapshot_utils.cpp @@ -66,7 +66,7 @@ bool SnapShotUtils::WriteToPng(const std::string &fileName, const WriteToPngPara } FILE *fp = fopen(fileName.c_str(), "wb"); if (fp == nullptr) { - printf("error: open file [%s] error, %d [%s]!\n", fileName.c_str(), errno, strerror(errno)); + printf("error: open file [%s] error, %d!\n", fileName.c_str(), errno); png_destroy_write_struct(&pngStruct, &pngInfo); return false; } @@ -100,10 +100,10 @@ bool SnapShotUtils::WriteToPng(const std::string &fileName, const WriteToPngPara bool SnapShotUtils::WriteToPngWithPixelMap(const std::string &fileName, PixelMap &pixelMap) { WriteToPngParam param; - param.width = pixelMap.GetWidth(); - param.height = pixelMap.GetHeight(); + param.width = static_cast(pixelMap.GetWidth()); + param.height = static_cast(pixelMap.GetHeight()); param.data = pixelMap.GetPixels(); - param.stride = pixelMap.GetRowBytes(); + param.stride = static_cast(pixelMap.GetRowBytes()); param.bitDepth = BITMAP_DEPTH; return SnapShotUtils::WriteToPng(fileName, param); } @@ -124,8 +124,8 @@ static bool ProcessDisplayId(DisplayId &displayId) if (!validFlag) { printf("error: displayId %" PRIu64 " invalid!\n", displayId); printf("tips: supported displayIds:\n"); - for (auto id: displayIds) { - printf("\t%" PRIu64 "\n", id); + for (auto dispId: displayIds) { + printf("\t%" PRIu64 "\n", dispId); } return false; } @@ -147,7 +147,7 @@ bool SnapShotUtils::ProcessArgs(int argc, char * const argv[], CmdArgments &cmdA while ((opt = getopt_long(argc, argv, "i:w:h:f:m", longOption, nullptr)) != -1) { switch (opt) { case 'i': // display id - cmdArgments.displayId = atoll(optarg); + cmdArgments.displayId = static_cast(atoll(optarg)); break; case 'w': // output width cmdArgments.width = atoi(optarg); -- Gitee From 6520b071e16c4be2952b390df2da56a67e821597 Mon Sep 17 00:00:00 2001 From: xingyanan Date: Mon, 17 Jan 2022 17:18:40 +0800 Subject: [PATCH 12/57] split test bugfix Signed-off-by: xingyanan Change-Id: I21764a2fa69bc41afa983e4ebb937696197af7f5 Signed-off-by: xingyanan --- wm/test/systemtest/window_split_test.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/wm/test/systemtest/window_split_test.cpp b/wm/test/systemtest/window_split_test.cpp index 5925d702ca..4f13551ebf 100644 --- a/wm/test/systemtest/window_split_test.cpp +++ b/wm/test/systemtest/window_split_test.cpp @@ -29,6 +29,9 @@ public: virtual void SetUp() override; virtual void TearDown() override; std::vector> activeWindows_; + +private: + static constexpr uint32_t SPLIT_TEST_SPEEP_S = 1; // split test spleep time }; void WindowSplitTest::SetUpTestCase() @@ -81,17 +84,20 @@ HWTEST_F(WindowSplitTest, SplitWindow01, Function | MediumTest | Level3) }; const sptr& windowFullScreen = utils::CreateTestWindow(infoFullScreen); ASSERT_EQ(WMError::WM_OK, windowFullScreen->Show()); - + sleep(SPLIT_TEST_SPEEP_S); activeWindows_.push_back(windowFullScreen); const sptr& windowPrimary = utils::CreateTestWindow(infoPrimary); ASSERT_EQ(WMError::WM_OK, windowPrimary->Show()); + sleep(SPLIT_TEST_SPEEP_S); ASSERT_EQ(WindowMode::WINDOW_MODE_SPLIT_PRIMARY, windowPrimary->GetMode()); activeWindows_.push_back(windowPrimary); // show one split primary window ASSERT_EQ(WindowMode::WINDOW_MODE_SPLIT_SECONDARY, windowFullScreen->GetMode()); ASSERT_EQ(WMError::WM_OK, windowPrimary->Hide()); + sleep(SPLIT_TEST_SPEEP_S); ASSERT_EQ(WindowMode::WINDOW_MODE_FULLSCREEN, windowFullScreen->GetMode()); ASSERT_EQ(WMError::WM_OK, windowFullScreen->Hide()); + sleep(SPLIT_TEST_SPEEP_S); } /** @@ -111,7 +117,7 @@ HWTEST_F(WindowSplitTest, SplitWindow02, Function | MediumTest | Level3) .parentLimit = false, .parentName = "", }; - utils::TestWindowInfo infoPrimary = { + utils::TestWindowInfo infoSecondary = { .name = "secondary.2", .rect = utils::defaultAppRect_, .type = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, @@ -122,16 +128,20 @@ HWTEST_F(WindowSplitTest, SplitWindow02, Function | MediumTest | Level3) }; const sptr& windowFullScreen = utils::CreateTestWindow(infoFullScreen); ASSERT_EQ(WMError::WM_OK, windowFullScreen->Show()); + sleep(SPLIT_TEST_SPEEP_S); activeWindows_.push_back(windowFullScreen); - const sptr& windowSecondary = utils::CreateTestWindow(infoPrimary); + const sptr& windowSecondary = utils::CreateTestWindow(infoSecondary); ASSERT_EQ(WMError::WM_OK, windowSecondary->Show()); + sleep(SPLIT_TEST_SPEEP_S); ASSERT_EQ(WindowMode::WINDOW_MODE_SPLIT_SECONDARY, windowSecondary->GetMode()); activeWindows_.push_back(windowSecondary); - // show one split primary window + // show one split secondary window ASSERT_EQ(WindowMode::WINDOW_MODE_SPLIT_PRIMARY, windowFullScreen->GetMode()); ASSERT_EQ(WMError::WM_OK, windowFullScreen->Hide()); + sleep(SPLIT_TEST_SPEEP_S); ASSERT_EQ(WindowMode::WINDOW_MODE_FULLSCREEN, windowSecondary->GetMode()); ASSERT_EQ(WMError::WM_OK, windowSecondary->Hide()); + sleep(SPLIT_TEST_SPEEP_S); } } } // namespace Rosen -- Gitee From 93a6a4f45f847279599b4e6e94f76a978c19dc8f Mon Sep 17 00:00:00 2001 From: qianlf Date: Sat, 15 Jan 2022 22:20:59 +0800 Subject: [PATCH 13/57] move jsWindow so to windowmanager Change-Id: I4029d653e518eeeb09b916f4c015a65a0ec2794e Signed-off-by: qianlf --- interfaces/innerkits/wm/window.h | 2 - interfaces/kits/napi/BUILD.gn | 1 + interfaces/kits/napi/window_runtime/BUILD.gn | 48 ++++++++++++++++--- .../js_window_manager.cpp | 0 .../js_window_manager.h | 0 .../window_manager_module.cpp | 3 +- .../{ => window_napi}/js_window.cpp | 0 .../{ => window_napi}/js_window.h | 0 .../{ => window_napi}/js_window_listener.cpp | 0 .../{ => window_napi}/js_window_listener.h | 0 .../{ => window_napi}/js_window_utils.cpp | 0 .../{ => window_napi}/js_window_utils.h | 1 - wm/include/window_impl.h | 2 - wm/src/window_impl.cpp | 18 ------- 14 files changed, 43 insertions(+), 32 deletions(-) rename interfaces/kits/napi/window_runtime/{ => window_manager_napi}/js_window_manager.cpp (100%) rename interfaces/kits/napi/window_runtime/{ => window_manager_napi}/js_window_manager.h (100%) rename interfaces/kits/napi/window_runtime/{ => window_manager_napi}/window_manager_module.cpp (89%) rename interfaces/kits/napi/window_runtime/{ => window_napi}/js_window.cpp (100%) rename interfaces/kits/napi/window_runtime/{ => window_napi}/js_window.h (100%) rename interfaces/kits/napi/window_runtime/{ => window_napi}/js_window_listener.cpp (100%) rename interfaces/kits/napi/window_runtime/{ => window_napi}/js_window_listener.h (100%) rename interfaces/kits/napi/window_runtime/{ => window_napi}/js_window_utils.cpp (100%) rename interfaces/kits/napi/window_runtime/{ => window_napi}/js_window_utils.h (97%) diff --git a/interfaces/innerkits/wm/window.h b/interfaces/innerkits/wm/window.h index c53b8e58db..09493ff2d7 100644 --- a/interfaces/innerkits/wm/window.h +++ b/interfaces/innerkits/wm/window.h @@ -93,8 +93,6 @@ public: virtual void RegisterWindowChangeListener(sptr& listener) = 0; virtual void RegisterAvoidAreaChangeListener(sptr& listener) = 0; virtual void UnregisterAvoidAreaChangeListener() = 0; - virtual WMError SetUIContent(std::shared_ptr context, - std::string& contentInfo, NativeEngine* engine, NativeValue* storage, bool isdistributed = false) = 0; virtual WMError SetUIContent(const std::string& contentInfo, NativeEngine* engine, NativeValue* storage, bool isdistributed = false) = 0; virtual const std::string& GetContentInfo() = 0; diff --git a/interfaces/kits/napi/BUILD.gn b/interfaces/kits/napi/BUILD.gn index 734260169f..eead3210c0 100644 --- a/interfaces/kits/napi/BUILD.gn +++ b/interfaces/kits/napi/BUILD.gn @@ -55,6 +55,7 @@ group("napi_packages") { "display:display", "screenshot:screenshot", "window:window", + "window_runtime:window_native_kit", "window_runtime:windowmanager_napi", ] } diff --git a/interfaces/kits/napi/window_runtime/BUILD.gn b/interfaces/kits/napi/window_runtime/BUILD.gn index 4247bde251..6ba32f61cb 100644 --- a/interfaces/kits/napi/window_runtime/BUILD.gn +++ b/interfaces/kits/napi/window_runtime/BUILD.gn @@ -18,25 +18,59 @@ config("window_manager_napi_config") { visibility = [ ":*" ] include_dirs = [ - "//foundation/windowmanager/interfaces/kits/napi/window_runtime", + "//foundation/windowmanager/interfaces/kits/napi/window_runtime/window_napi", + "//foundation/windowmanager/interfaces/kits/napi/window_runtime/window_manager_napi", "//foundation/windowmanager/interfaces/innerkits/wm", - "//foundation/windowmanager/interfaces/innerkits/dm", "//foundation/windowmanager/wm/include", "//foundation/windowmanager/utils/include", ] } +config("window_native_kit_config") { + visibility = [ ":*" ] + + include_dirs = [ + "//foundation/windowmanager/interfaces/kits/napi/window_runtime/window_napi", + "//foundation/windowmanager/interfaces/innerkits/wm", + "//foundation/windowmanager/wm/include", + "//foundation/windowmanager/utils/include", + ] +} + +ohos_shared_library("window_native_kit") { + sources = [ + "window_napi/js_window.cpp", + "window_napi/js_window_listener.cpp", + "window_napi/js_window_utils.cpp", + ] + + configs = [ ":window_native_kit_config" ] + deps = [ + "//foundation/windowmanager/utils:libwmutil", + "//foundation/windowmanager/wm:libwm", + "//foundation/windowmanager/wmserver:libwms", + ] + + external_deps = [ + "aafwk_standard:runtime", + "hiviewdfx_hilog_native:libhilog", + "napi:ace_napi", + ] + + part_name = "window_manager" + subsystem_name = "window" +} + ohos_shared_library("windowmanager_napi") { sources = [ - "js_window.cpp", - "js_window_listener.cpp", - "js_window_manager.cpp", - "js_window_utils.cpp", - "window_manager_module.cpp", + "window_manager_napi/js_window_manager.cpp", + "window_manager_napi/window_manager_module.cpp", ] configs = [ ":window_manager_napi_config" ] deps = [ + ":window_native_kit", + "//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native", "//foundation/appexecfwk/standard/kits:app_context", "//foundation/appexecfwk/standard/kits:appkit_native", "//foundation/windowmanager/utils:libwmutil", diff --git a/interfaces/kits/napi/window_runtime/js_window_manager.cpp b/interfaces/kits/napi/window_runtime/window_manager_napi/js_window_manager.cpp similarity index 100% rename from interfaces/kits/napi/window_runtime/js_window_manager.cpp rename to interfaces/kits/napi/window_runtime/window_manager_napi/js_window_manager.cpp diff --git a/interfaces/kits/napi/window_runtime/js_window_manager.h b/interfaces/kits/napi/window_runtime/window_manager_napi/js_window_manager.h similarity index 100% rename from interfaces/kits/napi/window_runtime/js_window_manager.h rename to interfaces/kits/napi/window_runtime/window_manager_napi/js_window_manager.h diff --git a/interfaces/kits/napi/window_runtime/window_manager_module.cpp b/interfaces/kits/napi/window_runtime/window_manager_napi/window_manager_module.cpp similarity index 89% rename from interfaces/kits/napi/window_runtime/window_manager_module.cpp rename to interfaces/kits/napi/window_runtime/window_manager_napi/window_manager_module.cpp index 70c3b95e44..6f099b4052 100644 --- a/interfaces/kits/napi/window_runtime/window_manager_module.cpp +++ b/interfaces/kits/napi/window_runtime/window_manager_napi/window_manager_module.cpp @@ -16,8 +16,7 @@ #include "js_window_manager.h" #include "native_engine/native_engine.h" -extern "C" __attribute__((constructor)) -void NAPI_application_windowmanager_AutoRegister() +extern "C" __attribute__((constructor)) void NAPI_application_windowmanager_AutoRegister() { auto moduleManager = NativeModuleManager::GetInstance(); NativeModule newModuleInfo = { diff --git a/interfaces/kits/napi/window_runtime/js_window.cpp b/interfaces/kits/napi/window_runtime/window_napi/js_window.cpp similarity index 100% rename from interfaces/kits/napi/window_runtime/js_window.cpp rename to interfaces/kits/napi/window_runtime/window_napi/js_window.cpp diff --git a/interfaces/kits/napi/window_runtime/js_window.h b/interfaces/kits/napi/window_runtime/window_napi/js_window.h similarity index 100% rename from interfaces/kits/napi/window_runtime/js_window.h rename to interfaces/kits/napi/window_runtime/window_napi/js_window.h diff --git a/interfaces/kits/napi/window_runtime/js_window_listener.cpp b/interfaces/kits/napi/window_runtime/window_napi/js_window_listener.cpp similarity index 100% rename from interfaces/kits/napi/window_runtime/js_window_listener.cpp rename to interfaces/kits/napi/window_runtime/window_napi/js_window_listener.cpp diff --git a/interfaces/kits/napi/window_runtime/js_window_listener.h b/interfaces/kits/napi/window_runtime/window_napi/js_window_listener.h similarity index 100% rename from interfaces/kits/napi/window_runtime/js_window_listener.h rename to interfaces/kits/napi/window_runtime/window_napi/js_window_listener.h diff --git a/interfaces/kits/napi/window_runtime/js_window_utils.cpp b/interfaces/kits/napi/window_runtime/window_napi/js_window_utils.cpp similarity index 100% rename from interfaces/kits/napi/window_runtime/js_window_utils.cpp rename to interfaces/kits/napi/window_runtime/window_napi/js_window_utils.cpp diff --git a/interfaces/kits/napi/window_runtime/js_window_utils.h b/interfaces/kits/napi/window_runtime/window_napi/js_window_utils.h similarity index 97% rename from interfaces/kits/napi/window_runtime/js_window_utils.h rename to interfaces/kits/napi/window_runtime/window_napi/js_window_utils.h index 004e73ce7f..f3d6a79e43 100644 --- a/interfaces/kits/napi/window_runtime/js_window_utils.h +++ b/interfaces/kits/napi/window_runtime/window_napi/js_window_utils.h @@ -32,7 +32,6 @@ namespace { constexpr int32_t RGB_LENGTH = 7; constexpr int32_t RGBA_LENGTH = 8; } - NativeValue* GetRectAndConvertToJsValue(NativeEngine& engine, const Rect rect); NativeValue* CreateJsWindowPropertiesObject(NativeEngine& engine, sptr& window); bool SetSystemBarPropertiesFromJs(NativeEngine& engine, NativeObject* jsObject, diff --git a/wm/include/window_impl.h b/wm/include/window_impl.h index f8588782bf..4c748041b8 100644 --- a/wm/include/window_impl.h +++ b/wm/include/window_impl.h @@ -87,8 +87,6 @@ public: virtual WMError SetUIContent(const std::string& contentInfo, NativeEngine* engine, NativeValue* storage, bool isdistributed) override; - virtual WMError SetUIContent(std::shared_ptr context, - std::string& contentInfo, NativeEngine* engine, NativeValue* storage, bool isdistributed) override; virtual const std::string& GetContentInfo() override; private: diff --git a/wm/src/window_impl.cpp b/wm/src/window_impl.cpp index 9145cc9b7c..025a6d3d1f 100644 --- a/wm/src/window_impl.cpp +++ b/wm/src/window_impl.cpp @@ -204,24 +204,6 @@ WMError WindowImpl::SetWindowFlags(uint32_t flags) return ret; } -WMError WindowImpl::SetUIContent(std::shared_ptr context, - std::string& contentInfo, NativeEngine* engine, NativeValue* storage, bool isdistributed) -{ - WLOGFI("SetUIContent"); - WLOGFI("contentInfo: %{public}s, context:%{public}p", contentInfo.c_str(), context.get()); - uiContent_ = Ace::UIContent::Create(context.get(), engine); - if (uiContent_ == nullptr) { - WLOGFE("fail to SetUIContent id: %{public}d", property_->GetWindowId()); - return WMError::WM_ERROR_NULLPTR; - } - if (isdistributed) { - uiContent_->Restore(this, contentInfo, storage); - } else { - uiContent_->Initialize(this, contentInfo, storage); - } - return WMError::WM_OK; -} - WMError WindowImpl::SetUIContent(const std::string& contentInfo, NativeEngine* engine, NativeValue* storage, bool isdistributed) { -- Gitee From 900f8f524e55208e15175f977d62881423808176 Mon Sep 17 00:00:00 2001 From: chenqinxin Date: Fri, 14 Jan 2022 15:53:48 +0800 Subject: [PATCH 14/57] set display state callback to dms Signed-off-by: chenqinxin Change-Id: I3b3be3110f7b6d5f3d9b13b289e3a74a4bc3174e --- dm/include/display_manager_adapter.h | 4 +- dm/include/display_manager_agent.h | 1 + .../zidl/display_manager_agent_interface.h | 5 +- dm/include/zidl/display_manager_agent_proxy.h | 1 + dm/src/display_manager.cpp | 33 ++++- dm/src/display_manager_adapter.cpp | 21 +-- dm/src/display_manager_agent.cpp | 5 + dm/src/zidl/display_manager_agent_proxy.cpp | 20 +++ dm/src/zidl/display_manager_agent_stub.cpp | 5 + dmserver/BUILD.gn | 1 + .../display_manager_agent_controller.h | 46 +++++++ dmserver/include/display_manager_service.h | 28 +--- .../src/display_manager_agent_controller.cpp | 68 ++++++++++ dmserver/src/display_manager_service.cpp | 97 ++------------ dmserver/src/display_power_controller.cpp | 13 +- interfaces/innerkits/dm/display_manager.h | 3 + interfaces/innerkits/dm/dm_common.h | 13 +- utils/BUILD.gn | 1 + utils/include/agent_death_recipient.h | 34 +++++ utils/include/client_agent_container.h | 126 ++++++++++++++++++ utils/src/agent_death_recipient.cpp | 43 ++++++ wmserver/BUILD.gn | 2 + wmserver/include/window_controller.h | 5 - .../include/window_manager_agent_controller.h | 47 +++++++ wmserver/include/window_node_container.h | 13 +- wmserver/include/window_root.h | 39 +----- wmserver/src/window_controller.cpp | 12 -- .../src/window_manager_agent_controller.cpp | 63 +++++++++ wmserver/src/window_manager_service.cpp | 5 +- wmserver/src/window_node_container.cpp | 11 +- wmserver/src/window_root.cpp | 109 +-------------- 31 files changed, 549 insertions(+), 325 deletions(-) create mode 100644 dmserver/include/display_manager_agent_controller.h create mode 100644 dmserver/src/display_manager_agent_controller.cpp create mode 100644 utils/include/agent_death_recipient.h create mode 100644 utils/include/client_agent_container.h create mode 100644 utils/src/agent_death_recipient.cpp create mode 100644 wmserver/include/window_manager_agent_controller.h create mode 100644 wmserver/src/window_manager_agent_controller.cpp diff --git a/dm/include/display_manager_adapter.h b/dm/include/display_manager_adapter.h index c59de7b8a4..facdbcba80 100644 --- a/dm/include/display_manager_adapter.h +++ b/dm/include/display_manager_adapter.h @@ -50,7 +50,7 @@ public: bool SuspendBegin(PowerStateChangeReason reason); bool SuspendEnd(); bool SetScreenPowerForAll(DisplayPowerState state, PowerStateChangeReason reason); - bool SetDisplayState(DisplayState state, DisplayStateCallback callback); + bool SetDisplayState(DisplayState state); DisplayState GetDisplayState(uint64_t displayId); void NotifyDisplayEvent(DisplayEvent event); DMError AddMirror(ScreenId mainScreenId, ScreenId mirrorScreenId); @@ -60,7 +60,6 @@ private: DisplayManagerAdapter() = default; ~DisplayManagerAdapter() = default; bool InitDMSProxyLocked(); - void NotifyDisplayChange(DisplayState state); static inline SingletonDelegator delegator; @@ -69,7 +68,6 @@ private: sptr dmsDeath_ = nullptr; std::map> displayMap_; DisplayId defaultDisplayId_; - DisplayStateCallback callback_; }; } // namespace OHOS::Rosen #endif // FOUNDATION_DM_DISPLAY_MANAGER_ADAPTER_H diff --git a/dm/include/display_manager_agent.h b/dm/include/display_manager_agent.h index b36947b6b2..7753ab43b6 100644 --- a/dm/include/display_manager_agent.h +++ b/dm/include/display_manager_agent.h @@ -27,6 +27,7 @@ public: ~DisplayManagerAgent() = default; virtual void NotifyDisplayPowerEvent(DisplayPowerEvent event, EventStatus status) override; + virtual void NotifyDisplayStateChanged(DisplayState state) override; }; } } diff --git a/dm/include/zidl/display_manager_agent_interface.h b/dm/include/zidl/display_manager_agent_interface.h index 69f16e4501..0c068bad4f 100644 --- a/dm/include/zidl/display_manager_agent_interface.h +++ b/dm/include/zidl/display_manager_agent_interface.h @@ -22,7 +22,8 @@ namespace OHOS { namespace Rosen { enum class DisplayManagerAgentType : uint32_t { - DISPLAY_POWER_EVENT_LISTENER + DISPLAY_POWER_EVENT_LISTENER, + DISPLAY_STATE_LISTENER, }; class IDisplayManagerAgent : public IRemoteBroker { @@ -31,8 +32,10 @@ public: enum { TRANS_ID_NOTIFY_DISPLAY_POWER_EVENT = 1, + TRANS_ID_NOTIFY_DISPLAY_STATE_CHANGED, }; virtual void NotifyDisplayPowerEvent(DisplayPowerEvent event, EventStatus status) = 0; + virtual void NotifyDisplayStateChanged(DisplayState state) = 0; }; } // namespace Rosen } // namespace OHOS diff --git a/dm/include/zidl/display_manager_agent_proxy.h b/dm/include/zidl/display_manager_agent_proxy.h index cb725acf98..92c3d31123 100644 --- a/dm/include/zidl/display_manager_agent_proxy.h +++ b/dm/include/zidl/display_manager_agent_proxy.h @@ -27,6 +27,7 @@ public: ~DisplayManagerAgentProxy() = default; virtual void NotifyDisplayPowerEvent(DisplayPowerEvent event, EventStatus status) override; + virtual void NotifyDisplayStateChanged(DisplayState state) override; private: static inline BrokerDelegator delegator_; diff --git a/dm/src/display_manager.cpp b/dm/src/display_manager.cpp index bafc327433..cfcda3a0af 100644 --- a/dm/src/display_manager.cpp +++ b/dm/src/display_manager.cpp @@ -206,6 +206,7 @@ void DisplayManager::UnregisterDisplayPowerEventListener(sptr().UnregisterDisplayManagerAgent(powerEventListenerAgent_, DisplayManagerAgentType::DISPLAY_POWER_EVENT_LISTENER); + powerEventListenerAgent_ = nullptr; } WLOGFI("UnregisterDisplayPowerEventListener end"); } @@ -220,6 +221,23 @@ void DisplayManager::NotifyDisplayPowerEvent(DisplayPowerEvent event, EventStatu } } +void DisplayManager::NotifyDisplayStateChanged(DisplayState state) +{ + WLOGFI("state:%{public}u", state); + std::lock_guard lock(mutex_); + if (displayStateCallback_) { + displayStateCallback_(state); + displayStateCallback_ = nullptr; + if (displayStateAgent_ != nullptr) { + SingletonContainer::Get().UnregisterDisplayManagerAgent(displayStateAgent_, + DisplayManagerAgentType::DISPLAY_STATE_LISTENER); + displayStateAgent_ = nullptr; + } + return; + } + WLOGFW("callback_ target is not set!"); +} + bool DisplayManager::WakeUpBegin(PowerStateChangeReason reason) { return SingletonContainer::Get().WakeUpBegin(reason); @@ -278,7 +296,20 @@ DisplayPowerState DisplayManager::GetScreenPower(uint64_t screenId) bool DisplayManager::SetDisplayState(DisplayState state, DisplayStateCallback callback) { WLOGFI("state:%{public}u", state); - return SingletonContainer::Get().SetDisplayState(state, callback); + { + std::lock_guard lock(mutex_); + if (displayStateCallback_ != nullptr) { + WLOGFI("previous callback not called, can't reset"); + return false; + } + displayStateCallback_ = callback; + if (displayStateAgent_ == nullptr) { + displayStateAgent_ = new DisplayManagerAgent(); + SingletonContainer::Get().RegisterDisplayManagerAgent(displayStateAgent_, + DisplayManagerAgentType::DISPLAY_STATE_LISTENER); + } + } + return SingletonContainer::Get().SetDisplayState(state); } DisplayState DisplayManager::GetDisplayState(uint64_t displayId) diff --git a/dm/src/display_manager_adapter.cpp b/dm/src/display_manager_adapter.cpp index 2e81963a8f..2205b97548 100644 --- a/dm/src/display_manager_adapter.cpp +++ b/dm/src/display_manager_adapter.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -162,19 +162,13 @@ bool DisplayManagerAdapter::SetScreenPowerForAll(DisplayPowerState state, PowerS } -bool DisplayManagerAdapter::SetDisplayState(DisplayState state, DisplayStateCallback callback) +bool DisplayManagerAdapter::SetDisplayState(DisplayState state) { std::lock_guard lock(mutex_); if (!InitDMSProxyLocked()) { return false; } - callback_ = callback; - bool ret = displayManagerServiceProxy_->SetDisplayState(state); - if (state == DisplayState::OFF) { - NotifyDisplayChange(state); - } - // TODO: NotifyDisplayChange ON when keyguard is drawn - return ret; + return displayManagerServiceProxy_->SetDisplayState(state); } DisplayState DisplayManagerAdapter::GetDisplayState(uint64_t displayId) @@ -195,15 +189,6 @@ void DisplayManagerAdapter::NotifyDisplayEvent(DisplayEvent event) displayManagerServiceProxy_->NotifyDisplayEvent(event); } -void DisplayManagerAdapter::NotifyDisplayChange(DisplayState state) -{ - if (callback_) { - callback_(state); - return; - } - WLOGFW("callback_ target is not set!"); -} - bool DisplayManagerAdapter::InitDMSProxyLocked() { if (!displayManagerServiceProxy_) { diff --git a/dm/src/display_manager_agent.cpp b/dm/src/display_manager_agent.cpp index 9ca4be500e..135d78592d 100644 --- a/dm/src/display_manager_agent.cpp +++ b/dm/src/display_manager_agent.cpp @@ -23,5 +23,10 @@ void DisplayManagerAgent::NotifyDisplayPowerEvent(DisplayPowerEvent event, Event { SingletonContainer::Get().NotifyDisplayPowerEvent(event, status); } + +void DisplayManagerAgent::NotifyDisplayStateChanged(DisplayState state) +{ + SingletonContainer::Get().NotifyDisplayStateChanged(state); +} } // namespace Rosen } // namespace OHOS \ No newline at end of file diff --git a/dm/src/zidl/display_manager_agent_proxy.cpp b/dm/src/zidl/display_manager_agent_proxy.cpp index 8bf4a31173..609f042b57 100644 --- a/dm/src/zidl/display_manager_agent_proxy.cpp +++ b/dm/src/zidl/display_manager_agent_proxy.cpp @@ -47,6 +47,26 @@ void DisplayManagerAgentProxy::NotifyDisplayPowerEvent(DisplayPowerEvent event, WLOGFE("SendRequest failed"); } } + +void DisplayManagerAgentProxy::NotifyDisplayStateChanged(DisplayState state) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_ASYNC); + if (!data.WriteInterfaceToken(GetDescriptor())) { + WLOGFE("WriteInterfaceToken failed"); + return; + } + + if (!data.WriteUint32(static_cast(state))) { + WLOGFE("Write DisplayState failed"); + return; + } + + if (Remote()->SendRequest(TRANS_ID_NOTIFY_DISPLAY_STATE_CHANGED, data, reply, option) != ERR_NONE) { + WLOGFE("SendRequest failed"); + } +} } // namespace Rosen } // namespace OHOS diff --git a/dm/src/zidl/display_manager_agent_stub.cpp b/dm/src/zidl/display_manager_agent_stub.cpp index 0acc80ce5b..e6899531ee 100644 --- a/dm/src/zidl/display_manager_agent_stub.cpp +++ b/dm/src/zidl/display_manager_agent_stub.cpp @@ -38,6 +38,11 @@ int32_t DisplayManagerAgentStub::OnRemoteRequest(uint32_t code, MessageParcel& d NotifyDisplayPowerEvent(event, status); break; } + case TRANS_ID_NOTIFY_DISPLAY_STATE_CHANGED: { + DisplayState state = static_cast(data.ReadUint32()); + NotifyDisplayStateChanged(state); + break; + } default: break; } diff --git a/dmserver/BUILD.gn b/dmserver/BUILD.gn index ed23069e0a..853a11d99f 100644 --- a/dmserver/BUILD.gn +++ b/dmserver/BUILD.gn @@ -37,6 +37,7 @@ ohos_shared_library("libdms") { "src/abstract_display_controller.cpp", "src/abstract_screen.cpp", "src/abstract_screen_controller.cpp", + "src/display_manager_agent_controller.cpp", "src/display_manager_service.cpp", "src/display_manager_service_inner.cpp", "src/display_manager_stub.cpp", diff --git a/dmserver/include/display_manager_agent_controller.h b/dmserver/include/display_manager_agent_controller.h new file mode 100644 index 0000000000..dec0d87f9a --- /dev/null +++ b/dmserver/include/display_manager_agent_controller.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_ROSEN_DISPLAY_MANAGER_AGENT_CONTROLLER_H +#define OHOS_ROSEN_DISPLAY_MANAGER_AGENT_CONTROLLER_H + +#include +#include "wm_single_instance.h" +#include "client_agent_container.h" +#include "zidl/display_manager_agent_interface.h" + +namespace OHOS { +namespace Rosen { +class DisplayManagerAgentController { +WM_DECLARE_SINGLE_INSTANCE_BASE(DisplayManagerAgentController) +public: + void RegisterDisplayManagerAgent(const sptr& displayManagerAgent, + DisplayManagerAgentType type); + void UnregisterDisplayManagerAgent(const sptr& displayManagerAgent, + DisplayManagerAgentType type); + + bool NotifyDisplayPowerEvent(DisplayPowerEvent event, EventStatus status); + bool NotifyDisplayStateChanged(DisplayState state); + +private: + DisplayManagerAgentController() : dmAgentContainer_(mutex_) {} + virtual ~DisplayManagerAgentController() = default; + + std::mutex mutex_; + ClientAgentContainer dmAgentContainer_; +}; +} +} +#endif // OHOS_ROSEN_DISPLAY_MANAGER_AGENT_CONTROLLER_H diff --git a/dmserver/include/display_manager_service.h b/dmserver/include/display_manager_service.h index fbbefa7ae3..898c3cab4d 100644 --- a/dmserver/include/display_manager_service.h +++ b/dmserver/include/display_manager_service.h @@ -29,24 +29,11 @@ #include "abstract_screen_controller.h" #include "display_manager_stub.h" #include "display_power_controller.h" -#include "wm_single_instance.h" #include "singleton_delegator.h" namespace OHOS::Rosen { -class DMAgentDeathRecipient : public IRemoteObject::DeathRecipient { -public: - DMAgentDeathRecipient(std::function&)> callback) : callback_(callback) {} - ~DMAgentDeathRecipient() = default; - - virtual void OnRemoteDied(const wptr& wptrDeath) override; - -private: - std::function&)> callback_; -}; - class DisplayManagerService : public SystemAbility, public DisplayManagerStub { DECLARE_SYSTEM_ABILITY(DisplayManagerService); - WM_DECLARE_SINGLE_INSTANCE_BASE(DisplayManagerService); public: @@ -72,6 +59,7 @@ public: DisplayState GetDisplayState(uint64_t displayId) override; void NotifyDisplayEvent(DisplayEvent event) override; bool NotifyDisplayPowerEvent(DisplayPowerEvent event, EventStatus status); + sptr GetAbstractScreenController(); DMError AddMirror(ScreenId mainScreenId, ScreenId mirrorScreenId) override; @@ -81,27 +69,13 @@ private: bool Init(); DisplayId GetDisplayIdFromScreenId(ScreenId screenId); ScreenId GetScreenIdFromDisplayId(DisplayId displayId); - void RemoveDisplayManagerAgent(const sptr& remoteObject); - bool UnregisterDisplayManagerAgent(std::vector>& displayManagerAgents, - const sptr& displayManagerAgent); - struct finder_t { - finder_t(sptr remoteObject) : remoteObject_(remoteObject) {} - bool operator()(sptr displayManagerAgent) - { - return displayManagerAgent->AsObject() == remoteObject_; - } - sptr remoteObject_; - }; std::recursive_mutex mutex_; static inline SingletonDelegator delegator_; std::map> abstractDisplayMap_; sptr abstractScreenController_; sptr abstractDisplayController_; DisplayPowerController displayPowerController_; - std::map> > displayManagerAgentMap_; - sptr dmAgentDeath_ = new DMAgentDeathRecipient( - std::bind(&DisplayManagerService::RemoveDisplayManagerAgent, this, std::placeholders::_1)); std::map> displayNodeMap_; }; } // namespace OHOS::Rosen diff --git a/dmserver/src/display_manager_agent_controller.cpp b/dmserver/src/display_manager_agent_controller.cpp new file mode 100644 index 0000000000..ff46111ccf --- /dev/null +++ b/dmserver/src/display_manager_agent_controller.cpp @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "display_manager_agent_controller.h" +#include "window_manager_hilog.h" + +namespace OHOS { +namespace Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "DisplayManagerAgentController"}; +} +WM_IMPLEMENT_SINGLE_INSTANCE(DisplayManagerAgentController) + +void DisplayManagerAgentController::RegisterDisplayManagerAgent(const sptr& displayManagerAgent, + DisplayManagerAgentType type) +{ + std::lock_guard lock(mutex_); + dmAgentContainer_.RegisterAgentLocked(displayManagerAgent, type); +} + +void DisplayManagerAgentController::UnregisterDisplayManagerAgent(const sptr& displayManagerAgent, + DisplayManagerAgentType type) +{ + std::lock_guard lock(mutex_); + dmAgentContainer_.UnregisterAgentLocked(displayManagerAgent, type); +} + +bool DisplayManagerAgentController::NotifyDisplayPowerEvent(DisplayPowerEvent event, EventStatus status) +{ + std::lock_guard lock(mutex_); + auto agents = dmAgentContainer_.GetAgentsByType(DisplayManagerAgentType::DISPLAY_POWER_EVENT_LISTENER); + if (agents.empty()) { + return false; + } + WLOGFI("NotifyDisplayPowerEvent"); + for (auto& agent : agents) { + agent->NotifyDisplayPowerEvent(event, status); + } + return true; +} + +bool DisplayManagerAgentController::NotifyDisplayStateChanged(DisplayState state) +{ + std::lock_guard lock(mutex_); + auto agents = dmAgentContainer_.GetAgentsByType(DisplayManagerAgentType::DISPLAY_STATE_LISTENER); + if (agents.empty()) { + return false; + } + WLOGFI("NotifyDisplayStateChanged"); + for (auto& agent : agents) { + agent->NotifyDisplayStateChanged(state); + } + return true; +} +} +} \ No newline at end of file diff --git a/dmserver/src/display_manager_service.cpp b/dmserver/src/display_manager_service.cpp index 8c9e58bbd7..256290e13f 100644 --- a/dmserver/src/display_manager_service.cpp +++ b/dmserver/src/display_manager_service.cpp @@ -17,12 +17,9 @@ #include "window_manager_service.h" #include -#include - -#include #include #include - +#include "display_manager_agent_controller.h" #include "window_manager_hilog.h" #include "transaction/rs_interfaces.h" @@ -138,99 +135,49 @@ void DisplayManagerService::RegisterDisplayManagerAgent(const sptr lock(mutex_); - displayManagerAgentMap_[type].push_back(displayManagerAgent); - WLOGFI("agent registered"); - if (dmAgentDeath_ == nullptr) { - WLOGFI("death Recipient is nullptr"); - return; - } - if (!displayManagerAgent->AsObject()->AddDeathRecipient(dmAgentDeath_)) { - WLOGFI("failed to add death recipient"); - } + DisplayManagerAgentController::GetInstance().RegisterDisplayManagerAgent(displayManagerAgent, type); } void DisplayManagerService::UnregisterDisplayManagerAgent(const sptr& displayManagerAgent, DisplayManagerAgentType type) { - if (displayManagerAgent == nullptr || displayManagerAgentMap_.count(type) == 0) { + if ((displayManagerAgent == nullptr) || (displayManagerAgent->AsObject() == nullptr)) { WLOGFE("displayManagerAgent invalid"); return; } - std::lock_guard lock(mutex_); - auto& displayManagerAgents = displayManagerAgentMap_.at(type); - UnregisterDisplayManagerAgent(displayManagerAgents, displayManagerAgent->AsObject()); -} - -bool DisplayManagerService::UnregisterDisplayManagerAgent(std::vector>& displayManagerAgents, - const sptr& displayManagerAgent) -{ - auto iter = std::find_if(displayManagerAgents.begin(), displayManagerAgents.end(), - finder_t(displayManagerAgent)); - if (iter == displayManagerAgents.end()) { - WLOGFE("could not find this listener"); - return false; - } - displayManagerAgents.erase(iter); - WLOGFI("agent unregistered"); - return true; -} - -void DisplayManagerService::RemoveDisplayManagerAgent(const sptr& remoteObject) -{ - WLOGFI("RemoveDisplayManagerAgent"); - std::lock_guard lock(mutex_); - for (auto& elem : displayManagerAgentMap_) { - if (UnregisterDisplayManagerAgent(elem.second, remoteObject)) { - break; - } - } - remoteObject->RemoveDeathRecipient(dmAgentDeath_); -} - -bool DisplayManagerService::NotifyDisplayPowerEvent(DisplayPowerEvent event, EventStatus status) -{ - if (displayManagerAgentMap_.count(DisplayManagerAgentType::DISPLAY_POWER_EVENT_LISTENER) == 0) { - WLOGFI("no display power event agent registered!"); - return false; - } - WLOGFI("NotifyDisplayPowerEvent"); - for (auto& agent : displayManagerAgentMap_.at(DisplayManagerAgentType::DISPLAY_POWER_EVENT_LISTENER)) { - agent->NotifyDisplayPowerEvent(event, status); - } - return true; + DisplayManagerAgentController::GetInstance().UnregisterDisplayManagerAgent(displayManagerAgent, type); } bool DisplayManagerService::WakeUpBegin(PowerStateChangeReason reason) { - std::lock_guard lock(mutex_); - return NotifyDisplayPowerEvent(DisplayPowerEvent::WAKE_UP, EventStatus::BEGIN); + return DisplayManagerAgentController::GetInstance().NotifyDisplayPowerEvent(DisplayPowerEvent::WAKE_UP, + EventStatus::BEGIN); } bool DisplayManagerService::WakeUpEnd() { - std::lock_guard lock(mutex_); - return NotifyDisplayPowerEvent(DisplayPowerEvent::WAKE_UP, EventStatus::END); + return DisplayManagerAgentController::GetInstance().NotifyDisplayPowerEvent(DisplayPowerEvent::WAKE_UP, + EventStatus::END); } bool DisplayManagerService::SuspendBegin(PowerStateChangeReason reason) { - std::lock_guard lock(mutex_); displayPowerController_.SuspendBegin(reason); - return NotifyDisplayPowerEvent(DisplayPowerEvent::SLEEP, EventStatus::BEGIN); + return DisplayManagerAgentController::GetInstance().NotifyDisplayPowerEvent(DisplayPowerEvent::SLEEP, + EventStatus::BEGIN); } bool DisplayManagerService::SuspendEnd() { - std::lock_guard lock(mutex_); - return NotifyDisplayPowerEvent(DisplayPowerEvent::SLEEP, EventStatus::END); + return DisplayManagerAgentController::GetInstance().NotifyDisplayPowerEvent(DisplayPowerEvent::SLEEP, + EventStatus::END); } bool DisplayManagerService::SetScreenPowerForAll(DisplayPowerState state, PowerStateChangeReason reason) { WLOGFI("SetScreenPowerForAll"); - std::lock_guard lock(mutex_); - return NotifyDisplayPowerEvent(state == DisplayPowerState::POWER_ON ? DisplayPowerEvent::DISPLAY_ON : + return DisplayManagerAgentController::GetInstance().NotifyDisplayPowerEvent( + state == DisplayPowerState::POWER_ON ? DisplayPowerEvent::DISPLAY_ON : DisplayPowerEvent::DISPLAY_OFF, EventStatus::END); } @@ -257,22 +204,6 @@ sptr DisplayManagerService::GetAbstractScreenControlle return abstractScreenController_; } -void DMAgentDeathRecipient::OnRemoteDied(const wptr& wptrDeath) -{ - if (wptrDeath == nullptr) { - WLOGFE("wptrDeath is null"); - return; - } - - sptr object = wptrDeath.promote(); - if (!object) { - WLOGFE("object is null"); - return; - } - WLOGFI("call OnRemoteDied callback"); - callback_(object); -} - DMError DisplayManagerService::AddMirror(ScreenId mainScreenId, ScreenId mirrorScreenId) { if (mainScreenId == SCREEN_ID_INVALID) { diff --git a/dmserver/src/display_power_controller.cpp b/dmserver/src/display_power_controller.cpp index 6f7531da36..225c19aadd 100644 --- a/dmserver/src/display_power_controller.cpp +++ b/dmserver/src/display_power_controller.cpp @@ -14,8 +14,7 @@ */ #include "display_power_controller.h" -#include "display_manager_service.h" -//#include "window_manager_service_inner.h" +#include "display_manager_agent_controller.h" #include "window_manager_hilog.h" namespace OHOS { @@ -41,19 +40,23 @@ bool DisplayPowerController::SetDisplayState(DisplayState state) switch (state) { case DisplayState::ON: { // TODO: open vsync and SendSystemEvent to keyguard - DisplayManagerService::GetInstance().NotifyDisplayPowerEvent(DisplayPowerEvent::DISPLAY_ON, + displayState_ = state; + DisplayManagerAgentController::GetInstance().NotifyDisplayPowerEvent(DisplayPowerEvent::DISPLAY_ON, EventStatus::BEGIN); break; } case DisplayState::OFF: { displayState_ = state; - DisplayManagerService::GetInstance().NotifyDisplayPowerEvent(DisplayPowerEvent::DISPLAY_OFF, + DisplayManagerAgentController::GetInstance().NotifyDisplayPowerEvent(DisplayPowerEvent::DISPLAY_OFF, EventStatus::BEGIN); break; } - default: + default: { WLOGFW("unknown DisplayState!"); + return false; + } } + DisplayManagerAgentController::GetInstance().NotifyDisplayStateChanged(state); return true; } diff --git a/interfaces/innerkits/dm/display_manager.h b/interfaces/innerkits/dm/display_manager.h index cc202640b0..402f3181ec 100644 --- a/interfaces/innerkits/dm/display_manager.h +++ b/interfaces/innerkits/dm/display_manager.h @@ -67,12 +67,15 @@ private: bool CheckRectValid(const Media::Rect &rect, int32_t oriHeight, int32_t oriWidth) const; bool CheckSizeValid(const Media::Size &size, int32_t oriHeight, int32_t oriWidth); void NotifyDisplayPowerEvent(DisplayPowerEvent event, EventStatus status); + void NotifyDisplayStateChanged(DisplayState state); static inline SingletonDelegator delegator; const int32_t MAX_RESOLUTION_SIZE_SCREENSHOT = 15360; // max resolution, 16K std::mutex mutex_; std::vector> powerEventListeners_; sptr powerEventListenerAgent_; + sptr displayStateAgent_; + DisplayStateCallback displayStateCallback_; }; } // namespace OHOS::Rosen diff --git a/interfaces/innerkits/dm/dm_common.h b/interfaces/innerkits/dm/dm_common.h index aacbca50fc..d1ae64824e 100644 --- a/interfaces/innerkits/dm/dm_common.h +++ b/interfaces/innerkits/dm/dm_common.h @@ -22,7 +22,7 @@ namespace OHOS { namespace Rosen { constexpr int32_t INVALID_DISPLAY_ID = -1; enum class PowerStateChangeReason : uint32_t { - POWER_BUTTON + POWER_BUTTON, }; enum class DisplayPowerState : uint32_t { @@ -31,17 +31,18 @@ enum class DisplayPowerState : uint32_t { POWER_SUSPEND, POWER_OFF, POWER_BUTT, - INVALID_STATE + INVALID_STATE, }; enum class DisplayState : uint32_t { ON, OFF, - UNKNOWN + UNKNOWN, }; enum class DisplayEvent : uint32_t { - UNLOCK + UNLOCK, + KEYGUARD_DRAWN, }; enum class DMError : int32_t { @@ -64,12 +65,12 @@ enum class DisplayPowerEvent : uint32_t { SLEEP, DISPLAY_ON, DISPLAY_OFF, - DESKTOP_READY + DESKTOP_READY, }; enum class EventStatus : uint32_t { BEGIN, - END + END, }; class IDisplayPowerEventListener : public RefBase { diff --git a/utils/BUILD.gn b/utils/BUILD.gn index f8a56ff343..cacd977f3c 100644 --- a/utils/BUILD.gn +++ b/utils/BUILD.gn @@ -29,6 +29,7 @@ config("libwmutil_public_config") { ## Build libwmutil.so ohos_shared_library("libwmutil") { sources = [ + "src/agent_death_recipient.cpp", "src/display_info.cpp", "src/singleton_container.cpp", "src/window_property.cpp", diff --git a/utils/include/agent_death_recipient.h b/utils/include/agent_death_recipient.h new file mode 100644 index 0000000000..88865d1562 --- /dev/null +++ b/utils/include/agent_death_recipient.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef OHOS_ROSEN_AGENT_DEATH_RECIPIENT_H +#define OHOS_ROSEN_AGENT_DEATH_RECIPIENT_H + +#include + +namespace OHOS { +namespace Rosen { +class AgentDeathRecipient : public IRemoteObject::DeathRecipient { +public: + AgentDeathRecipient(std::function&)> callback = nullptr) : callback_(callback) {} + ~AgentDeathRecipient() = default; + + virtual void OnRemoteDied(const wptr& wptrDeath) override; + +private: + std::function&)> callback_; +}; +} +} +#endif // OHOS_ROSEN_AGENT_DEATH_RECIPIENT_H \ No newline at end of file diff --git a/utils/include/client_agent_container.h b/utils/include/client_agent_container.h new file mode 100644 index 0000000000..3d46b4f920 --- /dev/null +++ b/utils/include/client_agent_container.h @@ -0,0 +1,126 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_ROSEN_CLIENT_AGENT_MANAGER_H +#define OHOS_ROSEN_CLIENT_AGENT_MANAGER_H + +#include +#include +#include +#include "agent_death_recipient.h" +#include "window_manager_hilog.h" + +namespace OHOS { +namespace Rosen { +template +class ClientAgentContainer { +public: + ClientAgentContainer(std::mutex& mutex); + virtual ~ClientAgentContainer() = default; + + void RegisterAgentLocked(const sptr& agent, T2 type); + void UnregisterAgentLocked(const sptr& agent, T2 type); + std::vector> GetAgentsByType(T2 type); + +private: + void RemoveAgent(const sptr& remoteObject); + bool UnregisterAgentLocked(std::vector>& agents, const sptr& agent); + + struct finder_t { + finder_t(sptr remoteObject) : remoteObject_(remoteObject) {} + + bool operator()(sptr agent) + { + return agent->AsObject() == remoteObject_; + } + + sptr remoteObject_; + }; + + std::mutex& mutex_; + std::map>> agentMap_; + sptr deathRecipient_; +}; + +template +ClientAgentContainer::ClientAgentContainer(std::mutex& mutex) + : mutex_(mutex), deathRecipient_(new AgentDeathRecipient( + std::bind(&ClientAgentContainer::RemoveAgent, this, std::placeholders::_1))) {} + +template +void ClientAgentContainer::RegisterAgentLocked(const sptr& agent, T2 type) +{ + agentMap_[type].push_back(agent); + WLOG_I("ClientAgentContainer agent registered type:%{public}u", type); + if (deathRecipient_ == nullptr) { + WLOG_I("death Recipient is nullptr"); + return; + } + if (!agent->AsObject()->AddDeathRecipient(deathRecipient_)) { + WLOG_I("ClientAgentContainer failed to add death recipient"); + } +} + +template +void ClientAgentContainer::UnregisterAgentLocked(const sptr& agent, T2 type) +{ + if (agent == nullptr || agentMap_.count(type) == 0) { + WLOG_E("ClientAgentContainer agent or type is invalid"); + return; + } + auto& agents = agentMap_.at(type); + UnregisterAgentLocked(agents, agent->AsObject()); + agent->AsObject()->RemoveDeathRecipient(deathRecipient_); +} + +template +std::vector> ClientAgentContainer::GetAgentsByType(T2 type) +{ + if (agentMap_.count(type) == 0) { + WLOG_E("no such type of agent registered! type:%{public}u", type); + return std::vector>(); + } + return agentMap_.at(type); +} + +template +bool ClientAgentContainer::UnregisterAgentLocked(std::vector>& agents, + const sptr& agent) +{ + auto iter = std::find_if(agents.begin(), agents.end(), finder_t(agent)); + if (iter == agents.end()) { + WLOG_W("ClientAgentContainer could not find this agent"); + return false; + } + agents.erase(iter); + WLOG_I("ClientAgentContainer agent unregistered"); + return true; +} + +template +void ClientAgentContainer::RemoveAgent(const sptr& remoteObject) +{ + WLOG_I("ClientAgentContainer RemoveAgent"); + std::lock_guard lock(mutex_); + for (auto& elem : agentMap_) { + if (UnregisterAgentLocked(elem.second, remoteObject)) { + break; + } + } + remoteObject->RemoveDeathRecipient(deathRecipient_); +} +} +} +#endif // OHOS_ROSEN_CLIENT_AGENT_MANAGER_H diff --git a/utils/src/agent_death_recipient.cpp b/utils/src/agent_death_recipient.cpp new file mode 100644 index 0000000000..917c1517af --- /dev/null +++ b/utils/src/agent_death_recipient.cpp @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "agent_death_recipient.h" +#include "window_manager_hilog.h" + +namespace OHOS { +namespace Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "AgentDeathRecipient"}; +} + +void AgentDeathRecipient::OnRemoteDied(const wptr& wptrDeath) +{ + if (wptrDeath == nullptr) { + WLOGFE("wptrDeath is null"); + return; + } + + sptr object = wptrDeath.promote(); + if (!object) { + WLOGFE("object is null"); + return; + } + if (callback_ != nullptr) { + WLOGFI("call OnRemoteDied callback"); + callback_(object); + } +} +} +} \ No newline at end of file diff --git a/wmserver/BUILD.gn b/wmserver/BUILD.gn index 7182f9bdc2..461710915c 100644 --- a/wmserver/BUILD.gn +++ b/wmserver/BUILD.gn @@ -37,6 +37,7 @@ ohos_shared_library("libwms") { "../dmserver/src/abstract_display_controller.cpp", "../dmserver/src/abstract_screen.cpp", "../dmserver/src/abstract_screen_controller.cpp", + "../dmserver/src/display_manager_agent_controller.cpp", "../dmserver/src/display_manager_service.cpp", "../dmserver/src/display_manager_service_inner.cpp", "../dmserver/src/display_manager_stub.cpp", @@ -49,6 +50,7 @@ ohos_shared_library("libwms") { "src/window_controller.cpp", "src/window_inner_manager.cpp", "src/window_layout_policy.cpp", + "src/window_manager_agent_controller.cpp", "src/window_manager_service.cpp", "src/window_manager_service_inner.cpp", "src/window_manager_stub.cpp", diff --git a/wmserver/include/window_controller.h b/wmserver/include/window_controller.h index c40fc70164..83d6aa8215 100644 --- a/wmserver/include/window_controller.h +++ b/wmserver/include/window_controller.h @@ -43,11 +43,6 @@ public: std::vector GetAvoidAreaByType(uint32_t windowId, AvoidAreaType avoidAreaType); WMError MinimizeAllAppNodeAbility(uint32_t windowId); - void RegisterWindowManagerAgent(WindowManagerAgentType type, - const sptr& windowManagerAgent); - void UnregisterWindowManagerAgent(WindowManagerAgentType type, - const sptr& windowManagerAgent); - private: uint32_t GenWindowId(); diff --git a/wmserver/include/window_manager_agent_controller.h b/wmserver/include/window_manager_agent_controller.h new file mode 100644 index 0000000000..eacf785982 --- /dev/null +++ b/wmserver/include/window_manager_agent_controller.h @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_ROSEN_WINDOW_MANAGER_AGENT_CONTROLLER_H +#define OHOS_ROSEN_WINDOW_MANAGER_AGENT_CONTROLLER_H + +#include +#include "client_agent_container.h" +#include "wm_single_instance.h" +#include "zidl/window_manager_agent_interface.h" + +namespace OHOS { +namespace Rosen { +class WindowManagerAgentController { +WM_DECLARE_SINGLE_INSTANCE_BASE(WindowManagerAgentController) +public: + void RegisterWindowManagerAgent(const sptr& windowManagerAgent, + WindowManagerAgentType type); + void UnregisterWindowManagerAgent(const sptr& windowManagerAgent, + WindowManagerAgentType type); + + void UpdateFocusStatus(uint32_t windowId, const sptr& abilityToken, WindowType windowType, + int32_t displayId, bool focused); + void UpdateSystemBarProperties(uint64_t displayId, const SystemBarProps& props); + +private: + WindowManagerAgentController() : wmAgentContainer_(mutex_) {} + virtual ~WindowManagerAgentController() = default; + + std::mutex mutex_; + ClientAgentContainer wmAgentContainer_; +}; +} +} +#endif // OHOS_ROSEN_WINDOW_MANAGER_AGENT_CONTROLLER_H diff --git a/wmserver/include/window_node_container.h b/wmserver/include/window_node_container.h index b6a335ac51..cbaf17dbb3 100644 --- a/wmserver/include/window_node_container.h +++ b/wmserver/include/window_node_container.h @@ -25,18 +25,9 @@ namespace OHOS { namespace Rosen { -using UpdateFocusStatusFunc = std::function& abilityToken, - WindowType windowType, int32_t displayId, bool focused)>; -using UpdateSystemBarPropsFunc = std::function; - -struct WindowNodeContainerCallbacks { - UpdateFocusStatusFunc focusStatusCallBack_; - UpdateSystemBarPropsFunc systemBarChangedCallBack_; -}; - class WindowNodeContainer : public RefBase { public: - WindowNodeContainer(uint64_t screenId, uint32_t width, uint32_t height, WindowNodeContainerCallbacks callbacks); + WindowNodeContainer(uint64_t screenId, uint32_t width, uint32_t height); ~WindowNodeContainer(); WMError AddWindowNode(sptr& node, sptr& parentNode); WMError RemoveWindowNode(sptr& node); @@ -119,8 +110,6 @@ private: uint32_t zOrder_ { 0 }; uint32_t focusedWindow_ { 0 }; uint64_t screenId_ = 0; - UpdateFocusStatusFunc focusStatusCallBack_; - WindowNodeContainerCallbacks callbacks_; void DumpScreenWindowTree(); struct WindowPairInfo { diff --git a/wmserver/include/window_root.h b/wmserver/include/window_root.h index 0054e99e2f..dd261feb32 100644 --- a/wmserver/include/window_root.h +++ b/wmserver/include/window_root.h @@ -17,34 +17,14 @@ #include #include + +#include "agent_death_recipient.h" #include "display_manager_service_inner.h" #include "window_node_container.h" #include "zidl/window_manager_agent_interface.h" namespace OHOS { namespace Rosen { -class WindowDeathRecipient : public IRemoteObject::DeathRecipient { -public: - WindowDeathRecipient(std::function&)> callback) : callback_(callback) {} - ~WindowDeathRecipient() = default; - - virtual void OnRemoteDied(const wptr& wptrDeath) override; - -private: - std::function&)> callback_; -}; - -class WindowManagerAgentDeathRecipient : public IRemoteObject::DeathRecipient { -public: - WindowManagerAgentDeathRecipient(std::function&)> callback) : callback_(callback) {} - ~WindowManagerAgentDeathRecipient() = default; - - virtual void OnRemoteDied(const wptr& wptrDeath) override; - -private: - std::function&)> callback_; -}; - enum class Event : uint32_t { REMOTE_DIED, }; @@ -73,21 +53,10 @@ public: std::vector GetAvoidAreaByType(uint32_t windowId, AvoidAreaType avoidAreaType); WMError MinimizeAllAppNodeAbility(sptr& node); WMError HandleSplitWindowModeChange(sptr& node, bool isChangeToSplit); - - void RegisterWindowManagerAgent(WindowManagerAgentType type, - const sptr& windowManagerAgent); - void UnregisterWindowManagerAgent(WindowManagerAgentType type, - const sptr& windowManagerAgent); - std::shared_ptr GetSurfaceNodeByAbilityToken(const sptr& abilityToken) const; private: void OnRemoteDied(const sptr& remoteObject); - void ClearWindowManagerAgent(const sptr& remoteObject); - void UnregisterWindowManagerAgent(const sptr& object); - void UpdateFocusStatus(uint32_t windowId, const sptr& abilityToken, WindowType windowType, - int32_t displayId, bool focused); - void UpdateSystemBarProperties(uint64_t displayId, const SystemBarProps& props); WMError DestroyWindowInner(sptr& node); bool CheckDisplayInfo(const sptr& display); @@ -98,10 +67,8 @@ private: std::map>> windowManagerAgents_; - sptr windowDeath_ = new WindowDeathRecipient(std::bind(&WindowRoot::OnRemoteDied, + sptr windowDeath_ = new AgentDeathRecipient(std::bind(&WindowRoot::OnRemoteDied, this, std::placeholders::_1)); - sptr windowManagerAgentDeath_ = new WindowManagerAgentDeathRecipient( - std::bind(&WindowRoot::ClearWindowManagerAgent, this, std::placeholders::_1)); Callback callback_; }; } diff --git a/wmserver/src/window_controller.cpp b/wmserver/src/window_controller.cpp index 963bb30517..66436fa05a 100644 --- a/wmserver/src/window_controller.cpp +++ b/wmserver/src/window_controller.cpp @@ -261,17 +261,5 @@ std::vector WindowController::GetAvoidAreaByType(uint32_t windowId, AvoidA std::vector avoidArea = windowRoot_->GetAvoidAreaByType(windowId, avoidAreaType); return avoidArea; } - -void WindowController::RegisterWindowManagerAgent(WindowManagerAgentType type, - const sptr& windowManagerAgent) -{ - windowRoot_->RegisterWindowManagerAgent(type, windowManagerAgent); -} - -void WindowController::UnregisterWindowManagerAgent(WindowManagerAgentType type, - const sptr& windowManagerAgent) -{ - windowRoot_->UnregisterWindowManagerAgent(type, windowManagerAgent); -} } } diff --git a/wmserver/src/window_manager_agent_controller.cpp b/wmserver/src/window_manager_agent_controller.cpp new file mode 100644 index 0000000000..998ea6e974 --- /dev/null +++ b/wmserver/src/window_manager_agent_controller.cpp @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "window_manager_agent_controller.h" +#include "window_manager_hilog.h" + +namespace OHOS { +namespace Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowManagerAgentController"}; +} +WM_IMPLEMENT_SINGLE_INSTANCE(WindowManagerAgentController) + +void WindowManagerAgentController::RegisterWindowManagerAgent(const sptr& windowManagerAgent, + WindowManagerAgentType type) +{ + std::lock_guard lock(mutex_); + wmAgentContainer_.RegisterAgentLocked(windowManagerAgent, type); +} + +void WindowManagerAgentController::UnregisterWindowManagerAgent(const sptr& windowManagerAgent, + WindowManagerAgentType type) +{ + std::lock_guard lock(mutex_); + wmAgentContainer_.UnregisterAgentLocked(windowManagerAgent, type); +} + +void WindowManagerAgentController::UpdateFocusStatus(uint32_t windowId, const sptr& abilityToken, + WindowType windowType, int32_t displayId, bool focused) +{ + std::lock_guard lock(mutex_); + WLOGFI("UpdateFocusStatus"); + for (auto& agent : wmAgentContainer_.GetAgentsByType(WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_FOCUS)) { + agent->UpdateFocusStatus(windowId, abilityToken, windowType, displayId, focused); + } +} + +void WindowManagerAgentController::UpdateSystemBarProperties(uint64_t displayId, const SystemBarProps& props) +{ + if (props.empty()) { + return; + } + std::lock_guard lock(mutex_); + WLOGFI("UpdateSystemBarProperties"); + for (auto& agent : wmAgentContainer_.GetAgentsByType( + WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_SYSTEM_BAR)) { + agent->UpdateSystemBarProperties(displayId, props); + } +} +} +} \ No newline at end of file diff --git a/wmserver/src/window_manager_service.cpp b/wmserver/src/window_manager_service.cpp index a3cd2840bd..00cb0be3c2 100644 --- a/wmserver/src/window_manager_service.cpp +++ b/wmserver/src/window_manager_service.cpp @@ -23,6 +23,7 @@ #include "dm_common.h" #include "singleton_container.h" +#include "window_manager_agent_controller.h" #include "window_inner_manager.h" #include "window_manager_hilog.h" #include "wm_trace.h" @@ -229,7 +230,7 @@ void WindowManagerService::RegisterWindowManagerAgent(WindowManagerAgentType typ return; } std::lock_guard lock(mutex_); - windowController_->RegisterWindowManagerAgent(type, windowManagerAgent); + WindowManagerAgentController::GetInstance().RegisterWindowManagerAgent(windowManagerAgent, type); } void WindowManagerService::UnregisterWindowManagerAgent(WindowManagerAgentType type, @@ -240,7 +241,7 @@ void WindowManagerService::UnregisterWindowManagerAgent(WindowManagerAgentType t return; } std::lock_guard lock(mutex_); - windowController_->UnregisterWindowManagerAgent(type, windowManagerAgent); + WindowManagerAgentController::GetInstance().UnregisterWindowManagerAgent(windowManagerAgent, type); } std::shared_ptr WindowManagerService::GetDisplayNode(int32_t displayId) const diff --git a/wmserver/src/window_node_container.cpp b/wmserver/src/window_node_container.cpp index fb771bc996..43e86ba5ec 100644 --- a/wmserver/src/window_node_container.cpp +++ b/wmserver/src/window_node_container.cpp @@ -20,6 +20,7 @@ #include #include "window_helper.h" +#include "window_manager_agent_controller.h" #include "window_inner_manager.h" #include "window_manager_hilog.h" #include "wm_trace.h" @@ -31,9 +32,7 @@ namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowNodeContainer"}; } -WindowNodeContainer::WindowNodeContainer(uint64_t screenId, uint32_t width, uint32_t height, - WindowNodeContainerCallbacks callbacks) - : screenId_(screenId), callbacks_(callbacks) +WindowNodeContainer::WindowNodeContainer(uint64_t screenId, uint32_t width, uint32_t height) : screenId_(screenId) { struct RSDisplayNodeConfig config = {screenId}; displayNode_ = RSDisplayNode::Create(config); @@ -323,8 +322,8 @@ void WindowNodeContainer::UpdateFocusStatus(uint32_t id, bool focused) const if (node->abilityToken_ == nullptr) { WLOGFI("abilityToken is null, window : %{public}d", id); } - callbacks_.focusStatusCallBack_(node->GetWindowId(), node->abilityToken_, node->GetWindowType(), - node->GetDisplayId(), focused); + WindowManagerAgentController::GetInstance().UpdateFocusStatus( + node->GetWindowId(), node->abilityToken_, node->GetWindowType(), node->GetDisplayId(), focused); } } @@ -439,7 +438,7 @@ void WindowNodeContainer::NotifySystemBarIfChanged() props.emplace_back(item); } } - callbacks_.systemBarChangedCallBack_(screenId_, props); + WindowManagerAgentController::GetInstance().UpdateSystemBarProperties(screenId_, props); } void WindowNodeContainer::TraverseContainer(std::vector>& windowNodes) diff --git a/wmserver/src/window_root.cpp b/wmserver/src/window_root.cpp index 6b226a6963..6bfa3aef5b 100644 --- a/wmserver/src/window_root.cpp +++ b/wmserver/src/window_root.cpp @@ -44,18 +44,8 @@ sptr WindowRoot::GetOrCreateWindowNodeContainer(int32_t dis WLOGFI("create new window node container display width:%{public}d, height:%{public}d, screenId:%{public}" PRIu64"", abstractDisplay->GetWidth(), abstractDisplay->GetHeight(), abstractDisplay->GetId()); - - UpdateFocusStatusFunc focusStatusFunc = std::bind(&WindowRoot::UpdateFocusStatus, this, std::placeholders::_1, - std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5); - UpdateSystemBarPropsFunc sysBarUpdateFunc = std::bind(&WindowRoot::UpdateSystemBarProperties, this, - std::placeholders::_1, std::placeholders::_2); - WindowNodeContainerCallbacks callbacks = { - focusStatusFunc, - sysBarUpdateFunc - }; sptr container = new WindowNodeContainer(abstractDisplay->GetId(), - static_cast(abstractDisplay->GetWidth()), static_cast(abstractDisplay->GetHeight()), - callbacks); + static_cast(abstractDisplay->GetWidth()), static_cast(abstractDisplay->GetHeight())); windowNodeContainerMap_.insert({ displayId, container }); return container; } @@ -298,50 +288,6 @@ WMError WindowRoot::RequestFocus(uint32_t windowId) return container->SetFocusWindow(windowId); } -void WindowRoot::RegisterWindowManagerAgent(WindowManagerAgentType type, - const sptr& windowManagerAgent) -{ - WLOGFI("RegisterWindowManagerAgent Type:%{public}u", static_cast(type)); - windowManagerAgents_[type].push_back(windowManagerAgent); - if (windowManagerAgentDeath_ == nullptr) { - WLOGFI("failed to create death Recipient ptr WindowManagerAgentDeathRecipient"); - return; - } - if (!windowManagerAgent->AsObject()->AddDeathRecipient(windowManagerAgentDeath_)) { - WLOGFI("failed to add death recipient"); - } -} - -void WindowRoot::UnregisterWindowManagerAgent(WindowManagerAgentType type, - const sptr& windowManagerAgent) -{ - auto iter = std::find(windowManagerAgents_[type].begin(), windowManagerAgents_[type].end(), windowManagerAgent); - if (iter == windowManagerAgents_[type].end()) { - WLOGFE("could not find this listener"); - return; - } - windowManagerAgents_[type].erase(iter); -} - -void WindowRoot::UnregisterWindowManagerAgent(const sptr& object) -{ - for (auto agents : windowManagerAgents_) { - for (auto iter = agents.second.begin(); iter < agents.second.end(); ++iter) { - if ((*iter)->AsObject() != nullptr && (*iter)->AsObject() == object) { - iter = agents.second.erase(iter); - } - } - } -} - -void WindowRoot::UpdateFocusStatus(uint32_t windowId, const sptr& abilityToken, WindowType windowType, - int32_t displayId, bool focused) -{ - for (auto& windowManagerAgent : windowManagerAgents_[WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_FOCUS]) { - windowManagerAgent->UpdateFocusStatus(windowId, abilityToken, windowType, displayId, focused); - } -} - std::shared_ptr WindowRoot::GetSurfaceNodeByAbilityToken(const sptr &abilityToken) const { for (auto iter = windowNodeMap_.begin(); iter != windowNodeMap_.end(); iter++) { @@ -354,16 +300,6 @@ std::shared_ptr WindowRoot::GetSurfaceNodeByAbilityToken(const sp return nullptr; } -void WindowRoot::UpdateSystemBarProperties(uint64_t displayId, const SystemBarProps& props) -{ - if (props.empty()) { - return; - } - for (auto& agent : windowManagerAgents_[WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_SYSTEM_BAR]) { - agent->UpdateSystemBarProperties(displayId, props); - } -} - void WindowRoot::OnRemoteDied(const sptr& remoteObject) { std::lock_guard lock(mutex_); @@ -375,48 +311,5 @@ void WindowRoot::OnRemoteDied(const sptr& remoteObject) uint32_t windowId = iter->second; callback_(Event::REMOTE_DIED, windowId); } - -void WindowRoot::ClearWindowManagerAgent(const sptr& remoteObject) -{ - if (remoteObject == nullptr) { - WLOGFI("remoteObject is null"); - return; - } - std::lock_guard lock(mutex_); - UnregisterWindowManagerAgent(remoteObject); - remoteObject->RemoveDeathRecipient(windowManagerAgentDeath_); -} - -void WindowDeathRecipient::OnRemoteDied(const wptr& wptrDeath) -{ - if (wptrDeath == nullptr) { - WLOGFE("wptrDeath is null"); - return; - } - - sptr object = wptrDeath.promote(); - if (!object) { - WLOGFE("object is null"); - return; - } - WLOGFI("WindowDeathRecipient callback"); - callback_(object); -} - -void WindowManagerAgentDeathRecipient::OnRemoteDied(const wptr& wptrDeath) -{ - if (wptrDeath == nullptr) { - WLOGFE("wptrDeath is null"); - return; - } - - sptr object = wptrDeath.promote(); - if (!object) { - WLOGFE("object is null"); - return; - } - WLOGFI("WindowManagerAgentDeathRecipient callback"); - callback_(object); -} } } -- Gitee From 119d4e06c249c678078d71a32abf068416de51c1 Mon Sep 17 00:00:00 2001 From: shiyueeee Date: Mon, 17 Jan 2022 22:16:46 +0800 Subject: [PATCH 15/57] Modify dmadaptor methods as virtual type for gmock. Add unit test of snapshot Signed-off-by: shiyueeee Change-Id: I16a629ff803f74a647542bdc7193c8a4e0da14d1 --- dm/include/display_manager_adapter.h | 38 +++-- dm/test/BUILD.gn | 5 +- dm/test/unittest/BUILD.gn | 74 ++++++++++ .../unittest/mock_display_manager_adapter.h | 36 +++++ dm/test/unittest/singleton_mocker.h | 46 +++++++ dm/test/unittest/snapshot_utils_test.cpp | 130 ++++++++++++++++++ dm/test/unittest/snapshot_utils_test.h | 36 +++++ 7 files changed, 344 insertions(+), 21 deletions(-) create mode 100644 dm/test/unittest/BUILD.gn create mode 100644 dm/test/unittest/mock_display_manager_adapter.h create mode 100644 dm/test/unittest/singleton_mocker.h create mode 100644 dm/test/unittest/snapshot_utils_test.cpp create mode 100644 dm/test/unittest/snapshot_utils_test.h diff --git a/dm/include/display_manager_adapter.h b/dm/include/display_manager_adapter.h index facdbcba80..7ea1e65546 100644 --- a/dm/include/display_manager_adapter.h +++ b/dm/include/display_manager_adapter.h @@ -32,33 +32,31 @@ public: }; class DisplayManagerAdapter { -WM_DECLARE_SINGLE_INSTANCE_BASE(DisplayManagerAdapter); +WM_DECLARE_SINGLE_INSTANCE(DisplayManagerAdapter); public: - DisplayId GetDefaultDisplayId(); - sptr GetDisplayById(DisplayId displayId); + virtual DisplayId GetDefaultDisplayId(); + virtual sptr GetDisplayById(DisplayId displayId); - ScreenId CreateVirtualScreen(VirtualScreenOption option); - DMError DestroyVirtualScreen(ScreenId screenId); - std::shared_ptr GetDisplaySnapshot(DisplayId displayId); + virtual ScreenId CreateVirtualScreen(VirtualScreenOption option); + virtual DMError DestroyVirtualScreen(ScreenId screenId); + virtual std::shared_ptr GetDisplaySnapshot(DisplayId displayId); - void RegisterDisplayManagerAgent(const sptr& displayManagerAgent, + virtual void RegisterDisplayManagerAgent(const sptr& displayManagerAgent, DisplayManagerAgentType type); - void UnregisterDisplayManagerAgent(const sptr& displayManagerAgent, + virtual void UnregisterDisplayManagerAgent(const sptr& displayManagerAgent, DisplayManagerAgentType type); - bool WakeUpBegin(PowerStateChangeReason reason); - bool WakeUpEnd(); - bool SuspendBegin(PowerStateChangeReason reason); - bool SuspendEnd(); - bool SetScreenPowerForAll(DisplayPowerState state, PowerStateChangeReason reason); - bool SetDisplayState(DisplayState state); - DisplayState GetDisplayState(uint64_t displayId); - void NotifyDisplayEvent(DisplayEvent event); - DMError AddMirror(ScreenId mainScreenId, ScreenId mirrorScreenId); - void Clear(); + virtual bool WakeUpBegin(PowerStateChangeReason reason); + virtual bool WakeUpEnd(); + virtual bool SuspendBegin(PowerStateChangeReason reason); + virtual bool SuspendEnd(); + virtual bool SetScreenPowerForAll(DisplayPowerState state, PowerStateChangeReason reason); + virtual bool SetDisplayState(DisplayState state); + virtual DisplayState GetDisplayState(uint64_t displayId); + virtual void NotifyDisplayEvent(DisplayEvent event); + virtual DMError AddMirror(ScreenId mainScreenId, ScreenId mirrorScreenId); + virtual void Clear(); private: - DisplayManagerAdapter() = default; - ~DisplayManagerAdapter() = default; bool InitDMSProxyLocked(); static inline SingletonDelegator delegator; diff --git a/dm/test/BUILD.gn b/dm/test/BUILD.gn index db8ed45937..8a9bb5e499 100644 --- a/dm/test/BUILD.gn +++ b/dm/test/BUILD.gn @@ -13,5 +13,8 @@ group("test") { testonly = true - deps = [ "systemtest:systemtest" ] + deps = [ + "systemtest:systemtest", + "unittest:unittest", + ] } diff --git a/dm/test/unittest/BUILD.gn b/dm/test/unittest/BUILD.gn new file mode 100644 index 0000000000..c523562cc3 --- /dev/null +++ b/dm/test/unittest/BUILD.gn @@ -0,0 +1,74 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/test.gni") + +module_out_path = "window_manager/dm" + +group("unittest") { + testonly = true + + deps = [ ":dm_snapshot_utils_test" ] +} + +## UnitTest dm_snapshot_utils_test {{{ +ohos_unittest("dm_snapshot_utils_test") { + module_out_path = module_out_path + + sources = [ + "//foundation/windowmanager/snapshot/snapshot_utils.cpp", + "snapshot_utils_test.cpp", + ] + + deps = [ ":dm_unittest_common" ] +} + +## UnitTest dm_snapshot_utils_test }}} + +## Build dm_unittest_common.a {{{ +config("dm_unittest_common_public_config") { + include_dirs = [ + "//foundation/windowmanager/dm/include", + "//foundation/windowmanager/dmserver/include", + "//foundation/windowmanager/snapshot", + "//foundation/windowmanager/interfaces/innerkits/dm", + "//foundation/windowmanager/utils/include", + ] +} + +ohos_static_library("dm_unittest_common") { + visibility = [ ":*" ] + testonly = true + + public_configs = [ ":dm_unittest_common_public_config" ] + + public_deps = [ + "//foundation/multimedia/image_standard/interfaces/innerkits:image_native", # PixelMap + "//foundation/multimodalinput/input/frameworks/proxy:libmmi-client", + "//foundation/windowmanager/dm:libdm", + "//foundation/windowmanager/snapshot:snapshot_display", + "//foundation/windowmanager/utils:libwmutil", + "//foundation/windowmanager/wm:libwm", + "//foundation/windowmanager/wmserver:libwms", + "//third_party/googletest:gmock", + "//third_party/googletest:gtest_main", + "//third_party/libpng:libpng", # png + "//utils/native/base:utils", + ] + + external_deps = [ + "hilog_native:libhilog", + "ipc:ipc_core", + ] +} +## Build wm_unittest_common.a }}} diff --git a/dm/test/unittest/mock_display_manager_adapter.h b/dm/test/unittest/mock_display_manager_adapter.h new file mode 100644 index 0000000000..97310c7773 --- /dev/null +++ b/dm/test/unittest/mock_display_manager_adapter.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FRAMEWORKS_WM_TEST_UT_MOCK_DISPLAY_MANAGER_ADAPTER_H +#define FRAMEWORKS_WM_TEST_UT_MOCK_DISPLAY_MANAGER_ADAPTER_H +#include + +#include "display_manager_adapter.h" + +namespace OHOS { +namespace Rosen { +class MockDisplayManagerAdapter : public DisplayManagerAdapter { +public: + MOCK_METHOD0(GetDefaultDisplayId, DisplayId()); + MOCK_METHOD1(GetDisplayById, sptr(DisplayId displayId)); + MOCK_METHOD1(CreateVirtualScreen, ScreenId(VirtualScreenOption option)); + MOCK_METHOD1(DestroyVirtualScreen, DMError(ScreenId screenId)); + MOCK_METHOD1(GetDisplaySnapshot, std::shared_ptr(DisplayId displayId)); + MOCK_METHOD0(Clear, void()); +}; +} +} // namespace OHOS + +#endif // FRAMEWORKS_WM_TEST_UT_MOCK_DISPLAY_MANAGER_ADAPTER_H \ No newline at end of file diff --git a/dm/test/unittest/singleton_mocker.h b/dm/test/unittest/singleton_mocker.h new file mode 100644 index 0000000000..022d22e961 --- /dev/null +++ b/dm/test/unittest/singleton_mocker.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FRAMEWORKS_DM_TEST_UT_SINGLETON_MOCKER_H +#define FRAMEWORKS_DM_TEST_UT_SINGLETON_MOCKER_H + +#include "singleton_container.h" +namespace OHOS { +namespace Rosen { +template +class SingletonMocker { +public: + SingletonMocker() + { + SingletonContainer::Set(mock); + } + + ~SingletonMocker() + { + SingletonContainer::Set(T::GetInstance()); + } + + MockT& Mock() + { + return mock; + } + +private: + MockT mock; +}; +} // namespace Rosen +} // namespace OHOS + +#endif // FRAMEWORKS_DM_TEST_UT_SINGLETON_MOCKER_H diff --git a/dm/test/unittest/snapshot_utils_test.cpp b/dm/test/unittest/snapshot_utils_test.cpp new file mode 100644 index 0000000000..b0d9502d43 --- /dev/null +++ b/dm/test/unittest/snapshot_utils_test.cpp @@ -0,0 +1,130 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "snapshot_utils_test.h" +#include "mock_display_manager_adapter.h" +#include "singleton_mocker.h" +#include "snapshot_utils.h" + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { +namespace Rosen { +using Mocker = SingletonMocker; +void SnapshotUtilsTest::SetUpTestCase() +{ +} + +void SnapshotUtilsTest::TearDownTestCase() +{ +} + +void SnapshotUtilsTest::SetUp() +{ +} + +void SnapshotUtilsTest::TearDown() +{ +} + +namespace { +/** + * @tc.name: Check01 + * @tc.desc: Check if default png is valid file names + * @tc.type: FUNC + */ +HWTEST_F(SnapshotUtilsTest, Check01, Function | SmallTest | Level3) +{ + ASSERT_EQ(true, SnapShotUtils::CheckFileNameValid(defaultFile_)); +} + +/** + * @tc.name: Check02 + * @tc.desc: Check custom png is valid file names + * @tc.type: FUNC + */ +HWTEST_F(SnapshotUtilsTest, Check02, Function | SmallTest | Level3) +{ + std::string fileName = "/data/test.png"; + ASSERT_EQ(true, SnapShotUtils::CheckFileNameValid(fileName)); +} + +/** + * @tc.name: Check03 + * @tc.desc: Check random path is invalid file names + * @tc.type: FUNC + */ +HWTEST_F(SnapshotUtilsTest, Check03, Function | SmallTest | Level3) +{ + std::string fileName = "/path/to/test/1.png"; + ASSERT_EQ(false, SnapShotUtils::CheckFileNameValid(fileName)); +} + +/** + * @tc.name: Write01 + * @tc.desc: Write default png using valid file names and valid PixelMap + * @tc.type: FUNC + */ +HWTEST_F(SnapshotUtilsTest, Write01, Function | SmallTest | Level3) +{ + DisplayId id = DisplayManager::GetInstance().GetDefaultDisplayId(); + std::shared_ptr pixelMap = DisplayManager::GetInstance().GetScreenshot(id); + ASSERT_NE(nullptr, pixelMap); + ASSERT_EQ(true, SnapShotUtils::WriteToPngWithPixelMap(defaultFile_, *pixelMap)); +} + +/** + * @tc.name: Write02 + * @tc.desc: Write default png using valid file names and valid WriteToPngParam + * @tc.type: FUNC + */ +HWTEST_F(SnapshotUtilsTest, Write02, Function | SmallTest | Level3) +{ + DisplayId id = DisplayManager::GetInstance().GetDefaultDisplayId(); + std::shared_ptr pixelMap = DisplayManager::GetInstance().GetScreenshot(id); + ASSERT_NE(nullptr, pixelMap); + WriteToPngParam param = { + .width = pixelMap->GetWidth(), + .height = pixelMap->GetHeight(), + .data = pixelMap->GetPixels(), + .stride = pixelMap->GetRowBytes(), + .bitDepth = defaultBitDepth_ + }; + ASSERT_EQ(true, SnapShotUtils::WriteToPng(defaultFile_, param)); +} + +/** + * @tc.name: Write03 + * @tc.desc: Write custom png using valid file names and valid WriteToPngParam + * @tc.type: FUNC + */ +HWTEST_F(SnapshotUtilsTest, Write03, Function | SmallTest | Level3) +{ + DisplayId id = DisplayManager::GetInstance().GetDefaultDisplayId(); + std::shared_ptr pixelMap = DisplayManager::GetInstance().GetScreenshot(id); + ASSERT_NE(nullptr, pixelMap); + WriteToPngParam param = { + .width = (pixelMap->GetWidth() / 2), + .height = (pixelMap->GetWidth() / 2), + .data = pixelMap->GetPixels(), + .stride = pixelMap->GetRowBytes(), + .bitDepth = defaultBitDepth_ + }; + ASSERT_EQ(true, SnapShotUtils::WriteToPng(defaultFile_, param)); +} +} +} // namespace Rosen +} // namespace OHOS \ No newline at end of file diff --git a/dm/test/unittest/snapshot_utils_test.h b/dm/test/unittest/snapshot_utils_test.h new file mode 100644 index 0000000000..9a59091a50 --- /dev/null +++ b/dm/test/unittest/snapshot_utils_test.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FRAMEWORKS_DM_TEST_UT_SNAPSHOT_UTILS_TEST_H +#define FRAMEWORKS_DM_TEST_UT_SNAPSHOT_UTILS_TEST_H + +#include +#include "display.h" + +namespace OHOS { +namespace Rosen { +class SnapshotUtilsTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + virtual void SetUp() override; + virtual void TearDown() override; + const std::string defaultFile_ = "/data/snapshot_display_1.png"; + const int defaultBitDepth_ = 8; +}; +} // namespace Rosen +} // namespace OHOS + +#endif // FRAMEWORKS_DM_TEST_UT_SNAPSHOT_UTILS_TEST_H \ No newline at end of file -- Gitee From 12a19e0f5550c19b2614f04760b1df49e32bc3ed Mon Sep 17 00:00:00 2001 From: lu Date: Tue, 18 Jan 2022 08:59:04 +0800 Subject: [PATCH 16/57] Set virtualPixelRatio for '3516' Signed-off-by: lu Change-Id: I77839d4188a838942c8d1e4db98ba2c144f71514 --- dm/BUILD.gn | 3 ++- wm/BUILD.gn | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/dm/BUILD.gn b/dm/BUILD.gn index 00c8bd8e5b..241c5900a0 100644 --- a/dm/BUILD.gn +++ b/dm/BUILD.gn @@ -22,7 +22,8 @@ config("libdm_private_config") { ] if (defined(product_name) && - (product_name == "rk3566" || product_name == "rk3568")) { + (product_name == "rk3566" || product_name == "rk3568" || + product_name == "Hi3516DV300")) { defines = [ "PRODUCT_RK" ] } } diff --git a/wm/BUILD.gn b/wm/BUILD.gn index eeb36209d6..10ad0cde6c 100644 --- a/wm/BUILD.gn +++ b/wm/BUILD.gn @@ -48,7 +48,8 @@ config("libwm_config") { ] if (defined(product_name) && - (product_name == "rk3566" || product_name == "rk3568")) { + (product_name == "rk3566" || product_name == "rk3568" || + product_name == "Hi3516DV300")) { defines = [ "PRODUCT_RK" ] } } -- Gitee From 25758ee3e6a629aa2352c22575668fc7c538384f Mon Sep 17 00:00:00 2001 From: maojiangping Date: Tue, 18 Jan 2022 10:15:25 +0800 Subject: [PATCH 17/57] remove adapter for weston window Signed-off-by: maojiangping Change-Id: I14e731071dbadf74ffd4134b67b4229fc00a32b5 --- adapter/BUILD.gn | 91 -------- adapter/include/adapter.h | 63 ------ adapter/src/adapter.cpp | 327 ---------------------------- bundle.json | 1 - dmserver/include/rs_adapter.h | 48 ---- dmserver/src/rs_adapter.cpp | 97 --------- interfaces/innerkits/wm/wm_common.h | 8 - wm/BUILD.gn | 13 -- wm/src/window_impl.cpp | 54 ----- wm/src/window_scene.cpp | 26 --- wmtest/BUILD.gn | 1 - 11 files changed, 729 deletions(-) delete mode 100644 adapter/BUILD.gn delete mode 100644 adapter/include/adapter.h delete mode 100644 adapter/src/adapter.cpp delete mode 100644 dmserver/include/rs_adapter.h delete mode 100644 dmserver/src/rs_adapter.cpp diff --git a/adapter/BUILD.gn b/adapter/BUILD.gn deleted file mode 100644 index f1ceabcd94..0000000000 --- a/adapter/BUILD.gn +++ /dev/null @@ -1,91 +0,0 @@ -# Copyright (c) 2021 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import("//build/ohos.gni") - -## Build libwmadapter.so {{{ -config("libwmadapter_config") { - visibility = [ ":*" ] - - include_dirs = [ - "include", - "//utils/system/safwk/native/include", - "//foundation/windowmanager/wmserver/include", - "//foundation/windowmanager/interfaces/innerkits/wm", - "//foundation/windowmanager/wm/include", - "//foundation/windowmanager/utils/include", - "//foundation/graphic/standard/interfaces/innerkits/wmclient", - "//foundation/graphic/standard/interfaces/innerkits/common", - "//foundation/graphic/standard/interfaces/innerkits/surface", - - # for abilityContext - "//foundation/aafwk/standard/frameworks/kits/ability/ability_runtime/include", - "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_base/include", - "//base/global/resmgr_standard/interfaces/innerkits/include", - "//third_party/node/deps/icu-small/source/common", - "//foundation/aafwk/standard/interfaces/innerkits/ability_manager/include", - "//foundation/aafwk/standard/interfaces/innerkits/want/include/ohos/aafwk/content", - "//foundation/distributedschedule/dmsfwk/services/dtbschedmgr/include", - "//foundation/aafwk/standard/interfaces/innerkits/base/include", - "//third_party/jsoncpp/include", - "//third_party/json/include", - ] -} - -config("libwmadapter_public_config") { - include_dirs = [ - "//foundation/graphic/standard/interfaces/innerkits/wmclient", - "//foundation/windowmanager/interfaces/innerkits/wm", - "//foundation/multimodalinput/input/interfaces/native/innerkits/proxy/include", - "//foundation/multimodalinput/input/interfaces/native/innerkits/event/include", - "//foundation/multimodalinput/input/common/include", - ] -} - -ohos_shared_library("libwmadapter") { - sources = [ "src/adapter.cpp" ] - - configs = [ ":libwmadapter_config" ] - - public_configs = [ ":libwmadapter_public_config" ] - - deps = [ - "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog", - "//foundation/graphic/standard:libwmclient", - "//utils/native/base:utils", - - # RSSurface - "//foundation/graphic/standard/rosen/modules/render_service_base:librender_service_base", - "//foundation/graphic/standard/rosen/modules/render_service_client:librender_service_client", - - # native value - "//foundation/ace/napi:ace_napi", - - # ace - "//foundation/ace/ace_engine/interfaces/innerkits/ace:ace_uicontent", - ] - - public_deps = [ - "//foundation/communication/ipc/interfaces/innerkits/ipc_core:ipc_core", - "//foundation/graphic/standard:libsurface", - "//foundation/graphic/standard/utils:promise", - "//utils/native/base:utils", - - # IMS - "//foundation/multimodalinput/input/frameworks/proxy:libmmi-client", - "//foundation/multimodalinput/input/frameworks/proxy:libmmi-common", - ] - - part_name = "window_manager" - subsystem_name = "window" -} diff --git a/adapter/include/adapter.h b/adapter/include/adapter.h deleted file mode 100644 index 229c9dd6d6..0000000000 --- a/adapter/include/adapter.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OHOS_ROSEN_WINDOW_ADAPTER_H -#define OHOS_ROSEN_WINDOW_ADAPTER_H -#define _NEW_RENDERSERVER_ -#include -#include -#include -#include -#include -#include -#include -#include "foundation/windowmanager/interfaces/innerkits/wm/window_option.h" -#include "wm_common.h" -#include "window.h" -#include "foundation/graphic/standard/interfaces/innerkits/wmclient/window_option.h" -#include "foundation/graphic/standard/interfaces/innerkits/wmclient/window_manager.h" -#include "window_manager_hilog.h" - -namespace OHOS { -namespace Rosen { -class Adapter { -public: - Adapter(); - ~Adapter(); - - static WMError Init(); - static bool CreateWestonWindow(sptr& option); - static void DestroyWestonWindow(); - static bool GetMainWindowRect(OHOS::Rosen::Rect &rect); - static OHOS::Rosen::WMError Show(); - static OHOS::Rosen::WMError Hide(); - static OHOS::Rosen::WMError MoveTo(int32_t x, int32_t y); - static OHOS::Rosen::WMError Resize(uint32_t width, uint32_t height); - -private: - static bool WindowOptionConvertToWeston(sptr& option, - sptr& config); - static bool GetSurfaceBuffer(sptr &surface, - sptr &buffer, - OHOS::BufferRequestConfig &rconfig); - static void WriteDataToSurface(); - static void ColorDraw(void *vaddr, uint32_t width, uint32_t height, uint32_t count); - static void BlackDraw(void *vaddr, uint32_t width, uint32_t height, uint32_t count); - static void FlushDraw(void *vaddr, uint32_t width, uint32_t height, uint32_t count); - static void set(void *vaddr, char ch, size_t len); -}; -} -} -#endif // OHOS_ROSEN_WINDOW_ADAPTER_H diff --git a/adapter/src/adapter.cpp b/adapter/src/adapter.cpp deleted file mode 100644 index f705b49023..0000000000 --- a/adapter/src/adapter.cpp +++ /dev/null @@ -1,327 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "adapter.h" -#include "window_impl.h" - -namespace OHOS { -namespace Rosen { - -constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, 0, "Adapter" }; - -static inline sptr westonMainWindow_ = nullptr; - -Adapter::Adapter() -{ -} - -Adapter::~Adapter() -{ -} - -OHOS::Rosen::WMError Adapter::Init() -{ - // "AbilityWindow::Init()" - auto wmi = WindowManager::GetInstance(); - if (wmi == nullptr) { - WLOGFE("Adapter::Init WindowManager::GetInstance() is nullptr."); - return OHOS::Rosen::WMError::WM_ERROR_WINDOWMANAGER_GETINSTANCE; - } - - auto wret = wmi->Init(); - if (wret != OHOS::WM_OK) { - WLOGFE("Adapter::Init WindowManager::Init() return %d", wret); - return OHOS::Rosen::WMError::WM_ERROR_WINDOWMANAGER_INIT; - } - WLOGFI("%{public}s end.", __func__); - return OHOS::Rosen::WMError::WM_OK; -} - -bool Adapter::CreateWestonWindow(sptr& option) -{ - sptr config = OHOS::WindowOption::Get(); - if (!WindowOptionConvertToWeston(option, config)) { - WLOGFE("Adapter::CreateWindow convert windowOption fail"); - return false; - } - - auto wmi = OHOS::WindowManager::GetInstance(); - if (wmi == nullptr) { - WLOGFE("Adapter::ConvertToWindowOption WindowManager::GetInstance() is nullptr."); - return false; - } - - WLOGFI("%{public}s begin wms->CreateWindow.", __func__); - auto retvalCreate = wmi->CreateWindow(westonMainWindow_, config); - WLOGFI("%{public}s end wms->CreateWindow.", __func__); - - WriteDataToSurface(); - - if (retvalCreate != OHOS::WMError::WM_OK) { - WLOGFE("Adapter::ConvertToWindowOption WindowManager::CreateWindow() return %d", retvalCreate); - return false; - } - return true; -} - -void Adapter::DestroyWestonWindow() -{ - if (westonMainWindow_ != nullptr) { - OHOS::WMError err = westonMainWindow_->Destroy(); - westonMainWindow_ = nullptr; - if (err == OHOS::WMError::WM_OK) { - WLOGFI("DestroyWestonWindow OK"); - return; - } - WLOGFE("DestroyWestonWindow errorcode=%d", static_cast(err)); - } - WLOGFE("DestroyWestonWindow westonMainWindow_ is null"); -} - -bool Adapter::WindowOptionConvertToWeston(sptr& option, sptr& config) -{ - // window type - config->SetWindowType(OHOS::WindowType::WINDOW_TYPE_NORMAL); - config->SetWindowMode(OHOS::WindowMode::WINDOW_MODE_FULL); - return true; -} - -bool Adapter::GetMainWindowRect(OHOS::Rosen::Rect &rect) -{ - if (westonMainWindow_ == nullptr) { - return false; - } - rect.posX_ = westonMainWindow_->GetX(); - rect.posY_ = westonMainWindow_->GetY(); - rect.width_ = westonMainWindow_->GetWidth(); - rect.height_ = westonMainWindow_->GetHeight(); - return true; -} - -static inline bool hide = false; - -OHOS::Rosen::WMError Adapter::Show() -{ - if (westonMainWindow_ == nullptr) { - WLOGFE("Adapter::Show westonMainWindow_ is null"); - return OHOS::Rosen::WMError::WM_ERROR_WINDOWMANAGER_SHOW; - } - - if (!hide) { - auto promise = westonMainWindow_->Show(); - if (promise == nullptr) { - WLOGFE("Adapter::Show Show error"); - return OHOS::Rosen::WMError::WM_ERROR_WINDOWMANAGER_SHOW; - } - auto error = promise->Await(); - if (error != OHOS::WMError::WM_OK) { - WLOGFE("Adapter::Show Show error=%d", static_cast(error)); - return OHOS::Rosen::WMError::WM_ERROR_WINDOWMANAGER_SHOW; - } - } - - auto promise2 = westonMainWindow_->SwitchTop(); - if (promise2 == nullptr) { - WLOGFE("Adapter::Show SwitchTop error"); - return OHOS::Rosen::WMError::WM_ERROR_WINDOWMANAGER_SHOW; - } - auto error2 = promise2->Await(); - if (error2 != OHOS::WMError::WM_OK) { - WLOGFE("Adapter::Show SwitchTop error=%d", static_cast(error2)); - return OHOS::Rosen::WMError::WM_ERROR_WINDOWMANAGER_SHOW; - } - - return OHOS::Rosen::WMError::WM_OK; -} - -void Adapter::WriteDataToSurface() -{ - /* write data to surface */ - sptr surface = westonMainWindow_->GetSurface(); - sptr buffer; - BufferRequestConfig rconfig; - if (GetSurfaceBuffer(surface, buffer, rconfig)) { - BlackDraw(buffer->GetVirAddr(), rconfig.width, rconfig.height, 1); - } else { - WLOGFE("Adapter::WriteDataToSurface GetSurfaceBuffer fail"); - } - BufferFlushConfig fconfig = { - .damage = { - .w = rconfig.width, - .h = rconfig.height, - }, - }; - surface->FlushBuffer(buffer, -1, fconfig); -} - -OHOS::Rosen::WMError Adapter::Hide() -{ - if (westonMainWindow_ == nullptr) { - WLOGFE("Adapter::Hide westonMainWindow_ is null"); - return OHOS::Rosen::WMError::WM_ERROR_WINDOWMANAGER_HIDE; - } - auto promise = westonMainWindow_->Hide(); - if (promise == nullptr) { - WLOGFE("Adapter::Hide Hide error"); - return OHOS::Rosen::WMError::WM_ERROR_WINDOWMANAGER_HIDE; - } - auto error = promise->Await(); - if (error != OHOS::WMError::WM_OK) { - WLOGFE("Adapter::Hide Hide error=%d", static_cast(error)); - return OHOS::Rosen::WMError::WM_ERROR_WINDOWMANAGER_HIDE; - } - hide = true; - return OHOS::Rosen::WMError::WM_OK; -} - -OHOS::Rosen::WMError Adapter::MoveTo(int32_t x, int32_t y) -{ - if (westonMainWindow_ == nullptr) { - WLOGFE("Adapter::MoveTo westonMainWindow_ is null"); - return OHOS::Rosen::WMError::WM_ERROR_WINDOWMANAGER_MOVE; - } - auto promise = westonMainWindow_->Move(x, y); - if (promise == nullptr) { - WLOGFE("Adapter::MoveTo promise is null"); - return OHOS::Rosen::WMError::WM_ERROR_WINDOWMANAGER_MOVE; - } - return OHOS::Rosen::WMError::WM_OK; -} - -OHOS::Rosen::WMError Adapter::Resize(uint32_t width, uint32_t height) -{ - if (westonMainWindow_ == nullptr) { - WLOGFE("Adapter::Resize westonMainWindow_ is null"); - return OHOS::Rosen::WMError::WM_ERROR_WINDOWMANAGER_RESIZE; - } - auto promise = westonMainWindow_->Resize(width, height); - if (promise == nullptr) { - WLOGFE("Adapter::Resize promise is null"); - return OHOS::Rosen::WMError::WM_ERROR_WINDOWMANAGER_RESIZE; - } - return OHOS::Rosen::WMError::WM_OK; -} - -bool Adapter::GetSurfaceBuffer(sptr &surface, sptr &buffer, BufferRequestConfig &rconfig) -{ - int32_t releaseFence; - rconfig = { - .width = surface->GetDefaultWidth(), - .height = surface->GetDefaultHeight(), - .strideAlignment = 0x8, - .format = 12, // PIXEL_FMT_RGBA_8888, - .usage = surface->GetDefaultUsage(), - .timeout = 0, - }; - OHOS::SurfaceError ret = surface->RequestBuffer(buffer, releaseFence, rconfig); - if (ret == 40601000) { // OHOS::SurfaceError::SURFACE_ERROR_NO_BUFFER - WLOGFE("Adapter::GetSurfaceBuffer RequestBuffer error=%d", static_cast(ret)); - return false; - } else if (ret != 0) { // OHOS::SurfaceError::SURFACE_ERROR_OK - WLOGFE("Adapter::GetSurfaceBuffer RequestBuffer is NG error=%d", static_cast(ret)); - return false; - } else if (buffer == nullptr) { - WLOGFE("Adapter::GetSurfaceBuffer buffer is nullptr"); - return false; - } - return true; -} - -void Adapter::ColorDraw(void *vaddr, uint32_t width, uint32_t height, uint32_t count) -{ - auto addr = static_cast(vaddr); - if (addr == nullptr) { - return; - } - - constexpr uint32_t wdiv = 2; - constexpr uint32_t colorTable[][wdiv] = { - {0xffff0000, 0xffff00ff}, - {0xffff0000, 0xffffff00}, - {0xff00ff00, 0xffffff00}, - {0xff00ff00, 0xff00ffff}, - {0xff0000ff, 0xff00ffff}, - {0xff0000ff, 0xffff00ff}, - {0xff777777, 0xff777777}, - {0xff777777, 0xff777777}, - }; - const uint32_t hdiv = sizeof(colorTable) / sizeof(*colorTable); - - for (uint32_t i = 0; i < height; i++) { - auto table = colorTable[i / (height / hdiv)]; - for (uint32_t j = 0; j < wdiv; j++) { - auto color = table[j]; - for (uint32_t k = j * width / wdiv; k < (j + 1) * width / wdiv; k++) { - addr[i * width + k] = color; - } - } - } -} - -void Adapter::BlackDraw(void *vaddr, uint32_t width, uint32_t height, uint32_t count) -{ - auto addr = static_cast(vaddr); - if (addr == nullptr) { - return; - } - - for (uint32_t i = 0; i < width * height; i++) { - addr[i] = 0xff00ff00; - } -} - -void Adapter::FlushDraw(void *vaddr, uint32_t width, uint32_t height, uint32_t count) -{ - auto addr = static_cast(vaddr); - if (addr == nullptr) { - return; - } - - constexpr uint32_t bpp = 4; - constexpr uint32_t color1 = 0xff / 3 * 0; - constexpr uint32_t color2 = 0xff / 3 * 1; - constexpr uint32_t color3 = 0xff / 3 * 2; - constexpr uint32_t color4 = 0xff / 3 * 3; - constexpr uint32_t bigDiv = 7; - constexpr uint32_t smallDiv = 10; - uint32_t c = count % (bigDiv * smallDiv); - uint32_t stride = width * bpp; - uint32_t beforeCount = height * c / bigDiv / smallDiv; - uint32_t afterCount = height - beforeCount - 1; - - size_t len = ((stride * height) < (beforeCount * stride) ? (stride * height) : (beforeCount * stride)); - set(addr, color3, len); - - len = ((stride * height) < (afterCount * stride) ? (stride * height) : (afterCount * stride)); - set(addr + (beforeCount + 1) * stride, color1, len); - - for (uint32_t i = 0; i < bigDiv; i++) { - len = ((stride * height) < (stride) ? (stride * height) : (stride)); - set(addr + (i * height / bigDiv) * stride, color4, len); - } - - len = ((stride * height) < (stride) ? (stride * height) : (stride)); - set(addr + beforeCount * stride, color2, len); -} - -void Adapter::set(void *vaddr, char ch, size_t len) -{ - char *ptr = static_cast(vaddr); - for (size_t i = 0; i < len; i++) { - ptr[i] = ch; - } -} -} -} diff --git a/bundle.json b/bundle.json index d19896de86..a3037e7ac3 100644 --- a/bundle.json +++ b/bundle.json @@ -19,7 +19,6 @@ "sub_component": [ "//foundation/windowmanager/interfaces/kits/js/declaration:window", "//foundation/windowmanager/sa_profile:wms_sa_profile", - "//foundation/windowmanager/adapter:libwmadapter", "//foundation/windowmanager/dm:libdm", "//foundation/windowmanager/dmserver:libdms", "//foundation/windowmanager/wm:libwm", diff --git a/dmserver/include/rs_adapter.h b/dmserver/include/rs_adapter.h deleted file mode 100644 index 307d054dbb..0000000000 --- a/dmserver/include/rs_adapter.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef FOUNDATION_DMSERVER_RS_ADAPTER_H -#define FOUNDATION_DMSERVER_RS_ADAPTER_H - -#include -#include - -#include - -#include "wm_single_instance.h" - -namespace OHOS::Rosen { -class DMSDeathRecipient : public IRemoteObject::DeathRecipient { -public: - virtual void OnRemoteDied(const wptr& wptrDeath) override; -private: - sptr& rsAdatper_; -}; - -class RsAdapter : public RefBase { - WM_DECLARE_SINGLE_INSTANCE_BASE(RsAdapter); -public: - void Clear(); -private: - RsAdapter() = default; - ~RsAdapter() = default; - bool InitRSProxyLocked(); - - std::mutex mutex_; - sptr rsProxy_ = nullptr; - sptr rsDeath_ = nullptr; -}; -} // namespace OHOS::Rosen -#endif // FOUNDATION_DMSERVER_RS_ADAPTER_H diff --git a/dmserver/src/rs_adapter.cpp b/dmserver/src/rs_adapter.cpp deleted file mode 100644 index cf56bcb414..0000000000 --- a/dmserver/src/rs_adapter.cpp +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "rs_adapter.h" - -#include -#include -#include - -#include "window_manager_hilog.h" - -namespace OHOS::Rosen { -namespace { - constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "RsAdapter"}; -} -WM_IMPLEMENT_SINGLE_INSTANCE(RsAdapter) -bool RsAdapter::InitRSProxyLocked() -{ - WLOGFI("InitRProxy"); - if (!rsProxy_) { - sptr systemAbilityManager = - SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); - if (!systemAbilityManager) { - WLOGFE("Failed to get system ability mgr."); - return false; - } - - sptr remoteObject - = systemAbilityManager->GetSystemAbility(); - if (!remoteObject) { - WLOGFE("Failed to get display manager service."); - return false; - } - - rsProxy_ = iface_cast(remoteObject); - if ((!rsProxy_) || (!rsProxy_->AsObject())) { - WLOGFE("Failed to get system display manager services"); - return false; - } - - rsDeath_ = new RSDeathRecipient(this); - if (!rsDeath_) { - WLOGFE("Failed to create death Recipient ptr RSDeathRecipient"); - return false; - } - if (!remoteObject->AddDeathRecipient(rsDeath_)) { - WLOGFE("Failed to add death recipient"); - return false; - } - } - return true; -} - -RSDeathRecipient::RSDeathRecipient(sptr& rsAdapter) -{ - rsAdatper_ = rsAdapter; -} - -void RSDeathRecipient::OnRemoteDied(const wptr& wptrDeath) -{ - if (wptrDeath == nullptr) { - WLOGFE("wptrDeath is null"); - return; - } - - sptr object = wptrDeath.promote(); - if (!object) { - WLOGFE("object is null"); - return; - } - if (rsAdapter_ != null) { - rsAdatper_.Clear(); - rsAdatper_ = nullptr; - } -} - -void RsAdapter::Clear() -{ - std::lock_guard lock(mutex_); - if ((rsProxy_ != nullptr) && (rsProxy_->AsObject() != nullptr)) { - rsProxy_->AsObject()->RemoveDeathRecipient(rsDeath_); - } - rsProxy_ = nullptr; -} -} // namespace OHOS::Rosen diff --git a/interfaces/innerkits/wm/wm_common.h b/interfaces/innerkits/wm/wm_common.h index 34f5ca6768..6fa15d1ca2 100644 --- a/interfaces/innerkits/wm/wm_common.h +++ b/interfaces/innerkits/wm/wm_common.h @@ -78,14 +78,6 @@ enum class WMError : int32_t { WM_ERROR_INVALID_WINDOW = 160, WM_ERROR_INVALID_OPERATION = 170, WM_ERROR_UNKNOWN, - - /* weston adater */ - WM_ERROR_WINDOWMANAGER_GETINSTANCE = 100000, - WM_ERROR_WINDOWMANAGER_INIT = 100001, - WM_ERROR_WINDOWMANAGER_SHOW = 100002, - WM_ERROR_WINDOWMANAGER_HIDE = 100003, - WM_ERROR_WINDOWMANAGER_MOVE = 100004, - WM_ERROR_WINDOWMANAGER_RESIZE = 100005, }; enum class WindowFlag : uint32_t { diff --git a/wm/BUILD.gn b/wm/BUILD.gn index eeb36209d6..4d2a9c7c93 100644 --- a/wm/BUILD.gn +++ b/wm/BUILD.gn @@ -36,13 +36,6 @@ config("libwm_config") { # abilityContext end - # weston adapter - "//foundation/windowmanager/adapter/include", - "//foundation/graphic/standard/interfaces/innerkits", - "//foundation/graphic/standard/interfaces/innerkits/wm", - "//foundation/graphic/standard/interfaces/innerkits/common", - - # weston adapter end "//third_party/jsoncpp/include", "//third_party/json/include", ] @@ -109,9 +102,6 @@ ohos_shared_library("libwm") { "//foundation/windowmanager/utils:libwmutil", "//utils/native/base:utils", - # weston adapter - "//foundation/windowmanager/adapter:libwmadapter", - # ace "//foundation/ace/ace_engine/interfaces/innerkits/ace:ace_uicontent", "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_core:appexecfwk_core", @@ -134,9 +124,6 @@ ohos_shared_library("libwm") { "//foundation/multimodalinput/input/frameworks/proxy:libmmi-client", "//foundation/multimodalinput/input/frameworks/proxy:libmmi-common", - # weston adapter - "//foundation/windowmanager/adapter:libwmadapter", - # context "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_base:appexecfwk_base", diff --git a/wm/src/window_impl.cpp b/wm/src/window_impl.cpp index 42ac8afb25..822f31745b 100644 --- a/wm/src/window_impl.cpp +++ b/wm/src/window_impl.cpp @@ -22,9 +22,6 @@ #include "window_agent.h" #include "window_helper.h" #include "window_manager_hilog.h" -#ifndef _NEW_RENDERSERVER_ -#include "adapter.h" -#endif namespace OHOS { namespace Rosen { @@ -53,10 +50,8 @@ WindowImpl::WindowImpl(const sptr& option) name_ = option->GetWindowName(); callback_->onCallback = std::bind(&WindowImpl::OnVsync, this, std::placeholders::_1); -#ifdef _NEW_RENDERSERVER_ struct RSSurfaceNodeConfig rsSurfaceNodeConfig; surfaceNode_ = RSSurfaceNode::Create(rsSurfaceNodeConfig); -#endif } WindowImpl::~WindowImpl() @@ -261,7 +256,6 @@ WMError WindowImpl::SetSystemBarProperty(WindowType type, const SystemBarPropert WMError WindowImpl::Create(const std::string& parentName, const std::shared_ptr& context) { WLOGFI("[Client] Window Create"); -#ifdef _NEW_RENDERSERVER_ // check window name, same window names are forbidden if (windowMap_.find(name_) != windowMap_.end()) { WLOGFE("WindowName(%{public}s) already exists.", name_.c_str()); @@ -306,16 +300,11 @@ WMError WindowImpl::Create(const std::string& parentName, const std::shared_ptr< state_ = STATE_CREATED; InputTransferStation::GetInstance().AddInputWindow(this); return ret; -#else - /* weston adapter */ - return WMError::WM_OK; -#endif } WMError WindowImpl::Destroy() { NotifyBeforeDestroy(); -#ifdef _NEW_RENDERSERVER_ WLOGFI("[Client] Window %{public}d Destroy", property_->GetWindowId()); // should destroy surface here if (!IsWindowValid()) { @@ -338,16 +327,10 @@ WMError WindowImpl::Destroy() state_ = STATE_DESTROYED; InputTransferStation::GetInstance().RemoveInputWindow(this); return ret; -#else - InputTransferStation::GetInstance().RemoveInputWindow(this); - Adapter::DestroyWestonWindow(); -#endif - return WMError::WM_OK; } WMError WindowImpl::Show() { -#ifdef _NEW_RENDERSERVER_ WLOGFI("[Client] Window %{public}d Show", property_->GetWindowId()); if (!IsWindowValid()) { WLOGFI("window is already destroyed or not created! id: %{public}d", property_->GetWindowId()); @@ -375,24 +358,10 @@ WMError WindowImpl::Show() WLOGFE("show errCode:%{public}d for winId:%{public}d", static_cast(ret), property_->GetWindowId()); } return ret; -#else - /* weston adapter */ - WMError rtn = Adapter::Show(); - if (rtn == WMError::WM_OK) { - NotifyAfterForeground(); - NotifyAfterFocused(); - WLOGFI("Show AfterForeground was invoked"); - } else { - WLOGFE("Show error=%d", static_cast(rtn)); - } - InputTransferStation::GetInstance().AddInputWindow(this); - return rtn; -#endif } WMError WindowImpl::Hide() { -#ifdef _NEW_RENDERSERVER_ WLOGFI("[Client] Window %{public}d Hide", property_->GetWindowId()); if (!IsWindowValid()) { WLOGFI("window is already destroyed or not created! id: %{public}d", property_->GetWindowId()); @@ -410,25 +379,10 @@ WMError WindowImpl::Hide() state_ = STATE_HIDDEN; NotifyAfterBackground(); return ret; -#else - /* weston adapter */ - WMError rtn = Adapter::Hide(); - if (rtn == WMError::WM_OK) { - NotifyAfterUnFocused(); - NotifyAfterBackground(); - WLOGFI("WindowImpl::Show AfterBackground was ivoked"); - } else { - WLOGFE("WindowImpl::Show error=%d", static_cast(rtn)); - } - InputTransferStation::GetInstance().RemoveInputWindow(this); - return rtn; -#endif } WMError WindowImpl::MoveTo(int32_t x, int32_t y) { - /* weston adapter */ -#ifdef _NEW_RENDERSERVER_ if (!IsWindowValid()) { WLOGFI("window is already destroyed or not created! id: %{public}d", property_->GetWindowId()); return WMError::WM_ERROR_INVALID_WINDOW; @@ -441,15 +395,10 @@ WMError WindowImpl::MoveTo(int32_t x, int32_t y) return WMError::WM_OK; } return SingletonContainer::Get().MoveTo(property_->GetWindowId(), x, y); -#else - return Adapter::MoveTo(x, y); -#endif } WMError WindowImpl::Resize(uint32_t width, uint32_t height) { - /* weston adapter */ -#ifdef _NEW_RENDERSERVER_ if (!IsWindowValid()) { WLOGFI("window is already destroyed or not created! id: %{public}d", property_->GetWindowId()); return WMError::WM_ERROR_INVALID_WINDOW; @@ -462,9 +411,6 @@ WMError WindowImpl::Resize(uint32_t width, uint32_t height) return WMError::WM_OK; } return SingletonContainer::Get().Resize(property_->GetWindowId(), width, height); -#else - return Adapter::Resize(width, height); -#endif } WMError WindowImpl::RequestFocus() const diff --git a/wm/src/window_scene.cpp b/wm/src/window_scene.cpp index c316443246..24e1480666 100644 --- a/wm/src/window_scene.cpp +++ b/wm/src/window_scene.cpp @@ -17,9 +17,6 @@ #include "static_call.h" #include "window_impl.h" #include "window_manager_hilog.h" -#ifndef _NEW_RENDERSERVER_ -#include "adapter.h" -#endif namespace OHOS { namespace Rosen { @@ -47,14 +44,8 @@ WMError WindowScene::Init(int32_t displayId, const std::shared_ptrSetDisplayId(displayId); -#ifndef _NEW_RENDERSERVER_ - /* weston adapter */ - Adapter::Init(); - mainWindow_ = CreateWindow(MAIN_WINDOW_ID, option); -#else mainWindow_ = SingletonContainer::Get().CreateWindow( MAIN_WINDOW_ID + std::to_string(count++), option, context); -#endif if (mainWindow_ == nullptr) { return WMError::WM_ERROR_NULLPTR; } @@ -65,29 +56,12 @@ WMError WindowScene::Init(int32_t displayId, const std::shared_ptr WindowScene::CreateWindow(const std::string& windowName, sptr& option) const { -#ifdef _NEW_RENDERSERVER_ if (windowName.empty() || mainWindow_ == nullptr || option == nullptr) { WLOGFE("WindowScene Name: %{public}s", windowName.c_str()); return nullptr; } option->SetParentName(mainWindow_->GetWindowName()); return SingletonContainer::Get().CreateWindow(windowName, option); -#else - /* weston adapter */ - if (!Adapter::CreateWestonWindow(option)) { - WLOGFE("WindowScene::CreateWindow fail to CreateWestonWindow"); - return nullptr; - } - Rect rect; - if (!Adapter::GetMainWindowRect(rect)) { - WLOGFE("WindowScene::CreateWindow fail to GetMainWindowRect"); - return nullptr; - } - option->SetWindowName(windowName); - option->SetWindowRect(rect); - sptr window = new WindowImpl(option); - return window; -#endif } const sptr& WindowScene::GetMainWindow() const diff --git a/wmtest/BUILD.gn b/wmtest/BUILD.gn index 5332058f88..96dbe550da 100644 --- a/wmtest/BUILD.gn +++ b/wmtest/BUILD.gn @@ -59,7 +59,6 @@ ohos_executable("rosenwmtest") { "//foundation/graphic/standard:libvsync_client", "//foundation/graphic/standard:libwmclient", "//foundation/graphic/standard:libwmservice", - "//foundation/windowmanager/adapter:libwmadaptertest", "//foundation/windowmanager/utils:libwmutil", "//foundation/windowmanager/wm:libwm", "//foundation/windowmanager/wmserver:libwms", -- Gitee From bb684d1359a4d24652a06d48dcb81833aafc05b8 Mon Sep 17 00:00:00 2001 From: youqijing Date: Mon, 17 Jan 2022 21:43:54 +0800 Subject: [PATCH 18/57] Add screenshot JS interface save(ScreenshotOptions) Signed-off-by: youqijing Change-Id: Ia0a99d6fdee26891aeeaf920515c7b518a3d995b --- .../declaration}/api/@ohos.sceenshot.d.ts | 18 -- .../screenshot/native_screenshot_module.cpp | 174 ++++++++++++++++-- 2 files changed, 154 insertions(+), 38 deletions(-) rename interfaces/kits/{napi/screenshot => js/declaration}/api/@ohos.sceenshot.d.ts (73%) diff --git a/interfaces/kits/napi/screenshot/api/@ohos.sceenshot.d.ts b/interfaces/kits/js/declaration/api/@ohos.sceenshot.d.ts similarity index 73% rename from interfaces/kits/napi/screenshot/api/@ohos.sceenshot.d.ts rename to interfaces/kits/js/declaration/api/@ohos.sceenshot.d.ts index c0337cb9bd..94f912c243 100644 --- a/interfaces/kits/napi/screenshot/api/@ohos.sceenshot.d.ts +++ b/interfaces/kits/js/declaration/api/@ohos.sceenshot.d.ts @@ -23,24 +23,6 @@ import image from './@ohos.multimedia.image'; * @since 7 */ declare namespace screenshot { - /** - * Takes a screenshot and saves it as a PixelMap object - * @param options Screenshot options, which consist of screenRect, imageSize, and rotation. You need to set these parameters - * @devices tv, phone, tablet, wearable, car - * @permission ohos.permission.CAPTURE_SCREEN - * @since 7 - */ - function save(options: ScreenshotOptions, callback: AsyncCallback): void; - - /** - * Takes a screenshot and saves it as a PixelMap object - * @param options Screenshot options, which consist of screenRect, imageSize, and rotation. You need to set these parameters - * @devices tv, phone, tablet, wearable, car - * @permission ohos.permission.CAPTURE_SCREEN - * @since 7 - */ - function save(callback: AsyncCallback): void; - /** * Takes a screenshot and saves it as a PixelMap object * @param options Screenshot options, which consist of screenRect, imageSize, and rotation. You need to set these parameters diff --git a/interfaces/kits/napi/screenshot/native_screenshot_module.cpp b/interfaces/kits/napi/screenshot/native_screenshot_module.cpp index 85a84bf807..9fa8fe88f2 100644 --- a/interfaces/kits/napi/screenshot/native_screenshot_module.cpp +++ b/interfaces/kits/napi/screenshot/native_screenshot_module.cpp @@ -24,35 +24,145 @@ namespace OHOS { namespace Rosen { namespace save { -struct Rect { - int32_t left = 0; - int32_t top = 0; - int32_t width = 0; - int32_t height = 0; -}; - -struct Size { - int32_t width = 0; - int32_t height = 0; -}; - struct Option { - Rect rect; - Size size; + Media::Rect rect; + Media::Size size; int rotation = 0; DisplayId displayId = 0; }; struct Param { WMError wret; - Option screenshotOptions; + Option option; std::shared_ptr image; }; -void Async(napi_env env, std::unique_ptr ¶m) +static napi_valuetype GetType(napi_env env, napi_value root) +{ + napi_valuetype res = napi_undefined; + napi_typeof(env, root, &res); + return res; +} + +static void GetDisplayId(napi_env env, std::unique_ptr ¶m, napi_value &argv) +{ + GNAPI_LOG("Get Screenshot Option: GetDisplayId"); + napi_value displayId; + NAPI_CALL_RETURN_VOID(env, napi_get_named_property(env, argv, "displayId", &displayId)); + if (displayId != nullptr && GetType(env, displayId) == napi_number) { + int64_t dispId; + NAPI_CALL_RETURN_VOID(env, napi_get_value_int64(env, displayId, &dispId)); + param->option.displayId = static_cast(dispId); + GNAPI_LOG("GetDisplayId success, displayId = %{public}" PRIu64"", param->option.displayId); + } else { + GNAPI_LOG("GetDisplayId failed, invalid param, use default displayId = 0"); + } +} + +static void GetRotation(napi_env env, std::unique_ptr ¶m, napi_value &argv) +{ + GNAPI_LOG("Get Screenshot Option: GetRotation"); + napi_value rotation; + NAPI_CALL_RETURN_VOID(env, napi_get_named_property(env, argv, "rotation", &rotation)); + if (rotation != nullptr && GetType(env, rotation) == napi_number) { + NAPI_CALL_RETURN_VOID(env, napi_get_value_int32(env, rotation, ¶m->option.rotation)); + GNAPI_LOG("GetRotation success, rotation = %{public}d", param->option.rotation); + } else { + GNAPI_LOG("GetRotation failed, invalid param, use default rotation = 0"); + } +} + +static void GetScreenRect(napi_env env, std::unique_ptr ¶m, napi_value &argv) +{ + GNAPI_LOG("Get Screenshot Option: GetScreenRect"); + napi_value screenRect; + NAPI_CALL_RETURN_VOID(env, napi_get_named_property(env, argv, "screenRect", &screenRect)); + if (screenRect != nullptr && GetType(env, screenRect) == napi_object) { + GNAPI_LOG("get ScreenRect success"); + + napi_value left; + NAPI_CALL_RETURN_VOID(env, napi_get_named_property(env, screenRect, "left", &left)); + if (left != nullptr && GetType(env, left) == napi_number) { + NAPI_CALL_RETURN_VOID(env, napi_get_value_int32(env, left, ¶m->option.rect.left)); + GNAPI_LOG("get ScreenRect.left success, left = %{public}d", param->option.rect.left); + } else { + GNAPI_LOG("get ScreenRect.left failed, invalid param, use default left = 0"); + } + + napi_value top; + NAPI_CALL_RETURN_VOID(env, napi_get_named_property(env, screenRect, "top", &top)); + if (top != nullptr && GetType(env, top) == napi_number) { + NAPI_CALL_RETURN_VOID(env, napi_get_value_int32(env, top, ¶m->option.rect.top)); + GNAPI_LOG("get ScreenRect.top success, top = %{public}d", param->option.rect.top); + } else { + GNAPI_LOG("get ScreenRect.top failed, invalid param, use default top = 0"); + } + + napi_value width; + NAPI_CALL_RETURN_VOID(env, napi_get_named_property(env, screenRect, "width", &width)); + if (width != nullptr && GetType(env, width) == napi_number) { + NAPI_CALL_RETURN_VOID(env, napi_get_value_int32(env, width, ¶m->option.rect.width)); + GNAPI_LOG("get ScreenRect.width success, width = %{public}d", param->option.rect.width); + } else { + GNAPI_LOG("get ScreenRect.width failed, invalid param, use default width = 0"); + } + + napi_value height; + NAPI_CALL_RETURN_VOID(env, napi_get_named_property(env, screenRect, "height", &height)); + if (height != nullptr && GetType(env, height) == napi_number) { + NAPI_CALL_RETURN_VOID(env, napi_get_value_int32(env, height, ¶m->option.rect.height)); + GNAPI_LOG("get ScreenRect.height success, height = %{public}d", param->option.rect.height); + } else { + GNAPI_LOG("get ScreenRect.height failed, invalid param, use default height = 0"); + } + } else { + GNAPI_LOG("get ScreenRect failed, use default ScreenRect param"); + } +} + +static void GetImageSize(napi_env env, std::unique_ptr ¶m, napi_value &argv) +{ + GNAPI_LOG("Get Screenshot Option: ImageSize"); + napi_value imageSize; + NAPI_CALL_RETURN_VOID(env, napi_get_named_property(env, argv, "imageSize", &imageSize)); + if (imageSize != nullptr && GetType(env, imageSize) == napi_object) { + napi_value width; + NAPI_CALL_RETURN_VOID(env, napi_get_named_property(env, imageSize, "width", &width)); + if (width != nullptr && GetType(env, width) == napi_number) { + NAPI_CALL_RETURN_VOID(env, napi_get_value_int32(env, width, ¶m->option.size.width)); + GNAPI_LOG("get ImageSize.width success, width = %{public}d", param->option.size.width); + } else { + GNAPI_LOG("get ImageSize.width failed, invalid param, use default width = 0"); + } + + napi_value height; + NAPI_CALL_RETURN_VOID(env, napi_get_named_property(env, imageSize, "height", &height)); + if (height != nullptr && GetType(env, height) == napi_number) { + NAPI_CALL_RETURN_VOID(env, napi_get_value_int32(env, height, ¶m->option.size.height)); + GNAPI_LOG("get ImageSize.height success, height = %{public}d", param->option.size.height); + } else { + GNAPI_LOG("get ImageSize.height failed, invalid param, use default height = 0"); + } + } +} + +static void AsyncGetScreenshotByDisplayId(napi_env env, std::unique_ptr ¶m) { - param->screenshotOptions.displayId = DisplayManager::GetInstance().GetDefaultDisplayId(); - param->image = DisplayManager::GetInstance().GetScreenshot(param->screenshotOptions.displayId); + GNAPI_LOG("Get Screenshot by displayId"); + param->image = DisplayManager::GetInstance().GetScreenshot(param->option.displayId); + if (param->image == nullptr) { + GNAPI_LOG("Get Screenshot failed!"); + param->wret = WMError::WM_ERROR_NULLPTR; + return; + } + param->wret = WMError::WM_OK; +} + +static void AsyncGetScreenshotByOption(napi_env env, std::unique_ptr ¶m) +{ + GNAPI_LOG("Get Screenshot by option"); + param->image = DisplayManager::GetInstance().GetScreenshot(param->option.displayId, + param->option.rect, param->option.size, param->option.rotation); if (param->image == nullptr) { GNAPI_LOG("Get Screenshot failed!"); param->wret = WMError::WM_ERROR_NULLPTR; @@ -78,9 +188,33 @@ napi_value Resolve(napi_env env, std::unique_ptr ¶m) napi_value MainFunc(napi_env env, napi_callback_info info) { GNAPI_LOG("%{public}s called", __PRETTY_FUNCTION__); - + napi_value argv[1] = {0}; + size_t argc = 1; + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr)); auto param = std::make_unique(); - return CreatePromise(env, __PRETTY_FUNCTION__, Async, Resolve, param); + param->option.displayId = DisplayManager::GetInstance().GetDefaultDisplayId(); + + if (argc == 0) { + GNAPI_LOG("argc == 0"); + return CreatePromise(env, __PRETTY_FUNCTION__, AsyncGetScreenshotByDisplayId, Resolve, param); + } else if (argc == 1) { + GNAPI_LOG("argc == 1"); + if (GetType(env, argv[0]) == napi_object) { + GNAPI_LOG("argv[0]'s type is napi_object"); + GetDisplayId(env, param, argv[0]); + GetRotation(env, param, argv[0]); + GetScreenRect(env, param, argv[0]); + GetImageSize(env, param, argv[0]); + return CreatePromise(env, __PRETTY_FUNCTION__, AsyncGetScreenshotByOption, Resolve, param); + } + GNAPI_LOG("argv[0]'s type is not napi_object"); + return nullptr; + } else { + GNAPI_LOG("argc number missmatch"); + return nullptr; + } + GNAPI_LOG("argc number missmatch"); + return nullptr; } } // namespace save -- Gitee From d47115beae168551934f3584caecde70248fd0fe Mon Sep 17 00:00:00 2001 From: fanby01 Date: Tue, 18 Jan 2022 13:09:16 +0800 Subject: [PATCH 19/57] add check file name for snapshot_display Change-Id: I7147b0846bce5e2c0acbdb07ac69f4b3ae4833b4 Signed-off-by: fanby01 --- snapshot/snapshot_utils.cpp | 47 +++++++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/snapshot/snapshot_utils.cpp b/snapshot/snapshot_utils.cpp index a973ddc4e8..9232357279 100644 --- a/snapshot/snapshot_utils.cpp +++ b/snapshot/snapshot_utils.cpp @@ -24,6 +24,10 @@ using namespace OHOS::Rosen; namespace OHOS { constexpr int BITMAP_DEPTH = 8; +constexpr int BPP = 4; +constexpr int MAX_RESOLUTION_SIZE = 15360; +const char *VALID_SNAPSHOT_PATH = "/data"; +const char *VALID_SNAPSHOT_SUFFIX = ".png"; void SnapShotUtils::PrintUsage(const std::string &cmdLine) { @@ -32,17 +36,52 @@ void SnapShotUtils::PrintUsage(const std::string &cmdLine) bool SnapShotUtils::CheckFileNameValid(const std::string &fileName) { + if (fileName.length() < strlen(VALID_SNAPSHOT_SUFFIX)) { + printf("error: fileName %s invalid, file length too short!\n", fileName.c_str()); + return false; + } + // check file path std::string fileDir = fileName; auto pos = fileDir.find_last_of("/"); if (pos != std::string::npos) { fileDir.erase(pos + 1); } else { - fileDir = "."; + fileDir = "."; // current work dir } char resolvedPath[PATH_MAX] = { 0 }; char *realPath = realpath(fileDir.c_str(), resolvedPath); if (realPath == nullptr) { - printf("error: fileName %s invalid, nullptr!\n", fileName.c_str()); + printf("error: fileName %s invalid, realpath nullptr!\n", fileName.c_str()); + return false; + } + if (strncmp(realPath, VALID_SNAPSHOT_PATH, strlen(VALID_SNAPSHOT_PATH)) != 0) { + printf("error: fileName %s invalid, realpath %s must dump at dir: %s \n", + fileName.c_str(), realPath, VALID_SNAPSHOT_PATH); + return false; + } + + // check file suffix + pos = fileName.find_last_of(VALID_SNAPSHOT_SUFFIX); + if (pos + 1 == fileName.length()) { + return true; // valid suffix + } + + printf("error: fileName %s invalid, suffix must be %s\n", fileName.c_str(), VALID_SNAPSHOT_SUFFIX); + return false; +} + +static bool CheckParamValid(const WriteToPngParam ¶m) +{ + if (param.width > MAX_RESOLUTION_SIZE) { + return false; + } + if (param.height > MAX_RESOLUTION_SIZE) { + return false; + } + if (param.stride < BPP * param.width) { + return false; + } + if (param.data == nullptr) { return false; } return true; @@ -53,6 +92,10 @@ bool SnapShotUtils::WriteToPng(const std::string &fileName, const WriteToPngPara if (!CheckFileNameValid(fileName)) { return false; } + if (!CheckParamValid(param)) { + return false; + } + png_structp pngStruct = png_create_write_struct(PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr); if (pngStruct == nullptr) { printf("error: png_create_write_struct nullptr!\n"); -- Gitee From e5a850369b30549b630b7df0df30abdbea0f336d Mon Sep 17 00:00:00 2001 From: wangxinpeng Date: Mon, 17 Jan 2022 20:02:06 +0800 Subject: [PATCH 20/57] raise input method window priority when invoked on lock screen Signed-off-by: wangxinpeng Change-Id: I98a2eeacc16c0ad05719fe586ca1ff9092feaffb --- wmserver/include/window_node_container.h | 2 ++ wmserver/src/window_node_container.cpp | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/wmserver/include/window_node_container.h b/wmserver/include/window_node_container.h index b6a335ac51..a209de1b7f 100644 --- a/wmserver/include/window_node_container.h +++ b/wmserver/include/window_node_container.h @@ -129,6 +129,8 @@ private: }; std::unordered_map pairedWindowMap_; sptr displayRects_ = new DisplayRects(); + void RaiseInputMethodWindowPriorityIfNeeded(const sptr& node) const; + const int32_t WINDOW_TYPE_RAISED_INPUT_METHOD = 113; }; } } diff --git a/wmserver/src/window_node_container.cpp b/wmserver/src/window_node_container.cpp index fb771bc996..14ed4b7b12 100644 --- a/wmserver/src/window_node_container.cpp +++ b/wmserver/src/window_node_container.cpp @@ -155,6 +155,7 @@ void WindowNodeContainer::UpdateWindowTree(sptr& node) { WM_FUNCTION_TRACE(); node->priority_ = zorderPolicy_->GetWindowPriority(node->GetWindowType()); + RaiseInputMethodWindowPriorityIfNeeded(node); auto parentNode = node->parent_; auto position = parentNode->children_.end(); for (auto iter = parentNode->children_.begin(); iter < parentNode->children_.end(); ++iter) { @@ -746,5 +747,20 @@ WMError WindowNodeContainer::UpdateWindowPairInfo(sptr& triggerNode, SingletonContainer::Get().SendMessage(INNER_WM_CREATE_DIVIDER, screenId_, dividerRect); return WMError::WM_OK; } + +void WindowNodeContainer::RaiseInputMethodWindowPriorityIfNeeded(const sptr& node) const +{ + if (node->GetWindowType() != WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT) { + return; + } + auto iter = std::find_if(aboveAppWindowNode_->children_.begin(), aboveAppWindowNode_->children_.end(), + [](sptr node) { + return node->GetWindowType() == WindowType::WINDOW_TYPE_KEYGUARD; + }); + if (iter != aboveAppWindowNode_->children_.end()) { + WLOGFI("raise input method float window priority."); + node->priority_ = WINDOW_TYPE_RAISED_INPUT_METHOD; + } } } +} \ No newline at end of file -- Gitee From fdebc11971b5d62b523ca23922d90fc81eeede65 Mon Sep 17 00:00:00 2001 From: Klaus_q Date: Tue, 18 Jan 2022 16:06:17 +0800 Subject: [PATCH 21/57] add window snapshot unittest Signed-off-by: Klaus_q Change-Id: Icc7d3fb8e7dd312812b7f800a455889a798f634c --- wm/test/unittest/BUILD.gn | 14 +++++ wm/test/unittest/window_snapshot_test.cpp | 54 +++++++++++++++++++ wm/test/unittest/window_snapshot_test.h | 34 ++++++++++++ .../window_snapshot/snapshot_controller.h | 2 + .../window_snapshot/snapshot_controller.cpp | 11 ++++ 5 files changed, 115 insertions(+) create mode 100644 wm/test/unittest/window_snapshot_test.cpp create mode 100644 wm/test/unittest/window_snapshot_test.h diff --git a/wm/test/unittest/BUILD.gn b/wm/test/unittest/BUILD.gn index 60e4f70f82..fc996b04a0 100644 --- a/wm/test/unittest/BUILD.gn +++ b/wm/test/unittest/BUILD.gn @@ -24,6 +24,7 @@ group("unittest") { ":wm_window_option_test", ":wm_window_scene_test", ":wm_window_test", + ":wms_window_snapshot_test", ] } @@ -93,11 +94,23 @@ ohos_unittest("wm_window_test") { ## UnitTest wm_window_test }}} +## UnitTest wms_window_snapshot_test {{{ +ohos_unittest("wms_window_snapshot_test") { + module_out_path = module_out_path + + sources = [ "window_snapshot_test.cpp" ] + + deps = [ ":wm_unittest_common" ] +} + +## UnitTest wm_window_impl_test }}} + ## Build wm_unittest_common.a {{{ config("wm_unittest_common_public_config") { include_dirs = [ "//foundation/windowmanager/wm/include", "//foundation/windowmanager/wmserver/include", + "//foundation/windowmanager/wmserver/include/window_snapshot", "//foundation/windowmanager/interfaces/innerkits/wm", "//foundation/windowmanager/utils/include", "//utils/native/base/include", @@ -136,6 +149,7 @@ ohos_static_library("wm_unittest_common") { public_deps = [ "//foundation/ace/ace_engine/interfaces/innerkits/ace:ace_uicontent", + "//foundation/distributedschedule/safwk/interfaces/innerkits/safwk:system_ability_fwk", "//foundation/multimodalinput/input/frameworks/proxy:libmmi-client", "//foundation/windowmanager/utils:libwmutil", "//foundation/windowmanager/wm:libwm", diff --git a/wm/test/unittest/window_snapshot_test.cpp b/wm/test/unittest/window_snapshot_test.cpp new file mode 100644 index 0000000000..9dd40249e5 --- /dev/null +++ b/wm/test/unittest/window_snapshot_test.cpp @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "window_snapshot_test.h" +#include "wm_common.h" + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { +namespace Rosen { +void WindowSnapshotTest::SetUpTestCase() +{ +} + +void WindowSnapshotTest::TearDownTestCase() +{ +} + +void WindowSnapshotTest::SetUp() +{ +} + +void WindowSnapshotTest::TearDown() +{ +} + +namespace { +/** + * @tc.name: GetSnapshot + * @tc.desc: GetSnapshot when parameter abilityToken is nullptr + * @tc.type: FUNC + */ +HWTEST_F(WindowSnapshotTest, GetSnapshot, Function | SmallTest | Level3) +{ + sptr snapshotController_ = new SnapshotController(); + AAFwk::Snapshot snapshot_; + ASSERT_EQ(static_cast(WMError::WM_ERROR_NULLPTR), snapshotController_->GetSnapshot(nullptr, snapshot_)); +} +} +} // namespace Rosen +} // namespace OHOS diff --git a/wm/test/unittest/window_snapshot_test.h b/wm/test/unittest/window_snapshot_test.h new file mode 100644 index 0000000000..df25346d47 --- /dev/null +++ b/wm/test/unittest/window_snapshot_test.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FRAMEWORKS_WMSERVER_TEST_UT_WINDOW_SNAPSHOT_TEST_H +#define FRAMEWORKS_WMSERVER_TEST_UT_WINDOW_SNAPSHOT_TEST_H + +#include +#include "snapshot_controller.h" + +namespace OHOS { +namespace Rosen { +class WindowSnapshotTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + virtual void SetUp() override; + virtual void TearDown() override; +}; +} // namespace ROSEN +} // namespace OHOS + +#endif // FRAMEWORKS_WMSERVER_TEST_UT_WINDOW_SNAPSHOT_TEST_H \ No newline at end of file diff --git a/wmserver/include/window_snapshot/snapshot_controller.h b/wmserver/include/window_snapshot/snapshot_controller.h index 49ef2d52a5..2f5ce9adda 100644 --- a/wmserver/include/window_snapshot/snapshot_controller.h +++ b/wmserver/include/window_snapshot/snapshot_controller.h @@ -27,7 +27,9 @@ namespace Rosen { class SnapshotController : public SnapshotStub { public: SnapshotController(sptr& root) : windowRoot_(root), rsInterface_(RSInterfaces::GetInstance()) {}; + SnapshotController() : windowRoot_(nullptr), rsInterface_(RSInterfaces::GetInstance()) {}; ~SnapshotController() = default; + void Init(sptr& root); int32_t GetSnapshot(const sptr &token, AAFwk::Snapshot& snapshot) override; diff --git a/wmserver/src/window_snapshot/snapshot_controller.cpp b/wmserver/src/window_snapshot/snapshot_controller.cpp index 5f6cffb15f..d4b289567b 100644 --- a/wmserver/src/window_snapshot/snapshot_controller.cpp +++ b/wmserver/src/window_snapshot/snapshot_controller.cpp @@ -16,6 +16,7 @@ #include "snapshot_controller.h" #include "window_manager_hilog.h" #include "wm_common.h" +#include "wm_trace.h" namespace OHOS { namespace Rosen { @@ -23,6 +24,11 @@ namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "SnapshotController"}; } +void SnapshotController::Init(sptr& root) +{ + windowRoot_ = root; +} + WMError SnapshotController::TakeSnapshot(const std::shared_ptr& surfaceNode, Snapshot& snapshot) { std::shared_ptr callback = std::make_shared(); @@ -49,6 +55,11 @@ WMError SnapshotController::TakeSnapshot(const std::shared_ptr& s int32_t SnapshotController::GetSnapshot(const sptr &token, Snapshot& snapshot) { + WM_SCOPED_TRACE("wms:GetSnapshot"); + if (token == nullptr) { + WLOGFE("Get ailityToken failed!"); + return static_cast(WMError::WM_ERROR_NULLPTR); + } std::shared_ptr surfaceNode = windowRoot_->GetSurfaceNodeByAbilityToken(token); if (surfaceNode == nullptr) { WLOGFE("Get surfaceNode failed!"); -- Gitee From 493f3abd85794fec034d704539ab207e850399df Mon Sep 17 00:00:00 2001 From: chenqinxin Date: Tue, 18 Jan 2022 18:55:48 +0800 Subject: [PATCH 22/57] add display power system test Signed-off-by: chenqinxin Change-Id: Idd88944f96be1893514e3b3bdbc72f603fc5fda5 --- dm/src/display_manager.cpp | 46 ++-- dm/test/systemtest/BUILD.gn | 12 + dm/test/systemtest/display_power_test.cpp | 297 ++++++++++++++++++++++ dmserver/src/display_power_controller.cpp | 4 +- interfaces/innerkits/dm/display_manager.h | 1 + 5 files changed, 339 insertions(+), 21 deletions(-) create mode 100644 dm/test/systemtest/display_power_test.cpp diff --git a/dm/src/display_manager.cpp b/dm/src/display_manager.cpp index cfcda3a0af..cc65ae82c2 100644 --- a/dm/src/display_manager.cpp +++ b/dm/src/display_manager.cpp @@ -227,17 +227,22 @@ void DisplayManager::NotifyDisplayStateChanged(DisplayState state) std::lock_guard lock(mutex_); if (displayStateCallback_) { displayStateCallback_(state); - displayStateCallback_ = nullptr; - if (displayStateAgent_ != nullptr) { - SingletonContainer::Get().UnregisterDisplayManagerAgent(displayStateAgent_, - DisplayManagerAgentType::DISPLAY_STATE_LISTENER); - displayStateAgent_ = nullptr; - } + ClearDisplayStateCallback(); return; } WLOGFW("callback_ target is not set!"); } +void DisplayManager::ClearDisplayStateCallback() +{ + displayStateCallback_ = nullptr; + if (displayStateAgent_ != nullptr) { + SingletonContainer::Get().UnregisterDisplayManagerAgent(displayStateAgent_, + DisplayManagerAgentType::DISPLAY_STATE_LISTENER); + displayStateAgent_ = nullptr; + } +} + bool DisplayManager::WakeUpBegin(PowerStateChangeReason reason) { return SingletonContainer::Get().WakeUpBegin(reason); @@ -296,20 +301,23 @@ DisplayPowerState DisplayManager::GetScreenPower(uint64_t screenId) bool DisplayManager::SetDisplayState(DisplayState state, DisplayStateCallback callback) { WLOGFI("state:%{public}u", state); - { - std::lock_guard lock(mutex_); - if (displayStateCallback_ != nullptr) { - WLOGFI("previous callback not called, can't reset"); - return false; - } - displayStateCallback_ = callback; - if (displayStateAgent_ == nullptr) { - displayStateAgent_ = new DisplayManagerAgent(); - SingletonContainer::Get().RegisterDisplayManagerAgent(displayStateAgent_, - DisplayManagerAgentType::DISPLAY_STATE_LISTENER); - } + std::lock_guard lock(mutex_); + if (displayStateCallback_ != nullptr) { + WLOGFI("previous callback not called, can't reset"); + return false; + } + displayStateCallback_ = callback; + if (displayStateAgent_ == nullptr) { + displayStateAgent_ = new DisplayManagerAgent(); + SingletonContainer::Get().RegisterDisplayManagerAgent(displayStateAgent_, + DisplayManagerAgentType::DISPLAY_STATE_LISTENER); + } + + bool ret = SingletonContainer::Get().SetDisplayState(state); + if (!ret) { + ClearDisplayStateCallback(); } - return SingletonContainer::Get().SetDisplayState(state); + return ret; } DisplayState DisplayManager::GetDisplayState(uint64_t displayId) diff --git a/dm/test/systemtest/BUILD.gn b/dm/test/systemtest/BUILD.gn index 538148102e..65ebd6218f 100644 --- a/dm/test/systemtest/BUILD.gn +++ b/dm/test/systemtest/BUILD.gn @@ -20,6 +20,7 @@ group("systemtest") { deps = [ ":dm_display_minimal_test", + ":dm_display_power_test", ":dm_screenshot_cmd_test", ":dm_screenshot_test", ] @@ -34,6 +35,15 @@ ohos_systemtest("dm_display_minimal_test") { deps = [ ":dm_systemtest_common" ] } +## SystemTest dm_display_power_test {{{ +ohos_systemtest("dm_display_power_test") { + module_out_path = module_out_path + + sources = [ "display_power_test.cpp" ] + + deps = [ ":dm_systemtest_common" ] +} + ## SystemTest dm_display_minimal_test }}} ## SystemTest dm_screenshot_test {{{ @@ -78,6 +88,8 @@ ohos_static_library("dm_systemtest_common") { public_deps = [ "//foundation/multimodalinput/input/frameworks/proxy:libmmi-client", + "//foundation/windowmanager/dm:libdm", + "//foundation/windowmanager/dmserver:libdms", "//foundation/windowmanager/utils:libwmutil", "//foundation/windowmanager/wm:libwm", "//foundation/windowmanager/wmserver:libwms", diff --git a/dm/test/systemtest/display_power_test.cpp b/dm/test/systemtest/display_power_test.cpp new file mode 100644 index 0000000000..6ee344f780 --- /dev/null +++ b/dm/test/systemtest/display_power_test.cpp @@ -0,0 +1,297 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "display_manager.h" +#include "window_manager_hilog.h" + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { +namespace Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "ScreenshotCmdTest"}; +} + +class DisplayPowerEventListener : public IDisplayPowerEventListener { +public: + virtual void OnDisplayPowerEvent(DisplayPowerEvent event, EventStatus status) + { + isCallbackCalled_ = true; + event_ = event; + status_ = status; + } + DisplayPowerEvent event_; + EventStatus status_; + bool isCallbackCalled_ { false }; +}; + +class DisplayPowerTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + virtual void SetUp() override; + virtual void TearDown() override; + static inline DisplayId defaultId_; + static sptr listener_; + DisplayState state_ { DisplayState::ON }; + bool isDisplayStateCallbackCalled_ { false }; + DisplayStateCallback callback_ = [this](DisplayState state) { + isDisplayStateCallbackCalled_ = true; + state_ = state; + }; +}; + +sptr DisplayPowerTest::listener_ = new DisplayPowerEventListener(); + +void DisplayPowerTest::SetUpTestCase() +{ + defaultId_ = DisplayManager::GetInstance().GetDefaultDisplayId(); + if (defaultId_ == INVALID_DISPLAY_ID) { + WLOGFE("GetDefaultDisplayId failed!"); + } + DisplayManager::GetInstance().RegisterDisplayPowerEventListener(listener_); +} + +void DisplayPowerTest::TearDownTestCase() +{ + DisplayManager::GetInstance().UnregisterDisplayPowerEventListener(listener_); +} + +void DisplayPowerTest::SetUp() +{ + isDisplayStateCallbackCalled_ = false; + state_ = DisplayState::UNKNOWN; + + listener_->isCallbackCalled_ = false; + listener_->event_ = static_cast(-1); + listener_->status_ = static_cast(-1); +} + +void DisplayPowerTest::TearDown() +{ +} + +namespace { +/** + * @tc.name: SetDisplayStateValid + * @tc.desc: Call SetDisplayState and check if it the state set is the same as calling GetDisplayState + * @tc.type: FUNC + */ +HWTEST_F(DisplayPowerTest, SetDisplayStateValid01, Function | MediumTest | Level2) +{ + DisplayState initialState = DisplayManager::GetInstance().GetDisplayState(defaultId_); + DisplayState stateToSet = (initialState == DisplayState::OFF ? DisplayState::ON : DisplayState::OFF); + bool ret = DisplayManager::GetInstance().SetDisplayState(stateToSet, callback_); + ASSERT_EQ(true, ret); + DisplayState stateGet = DisplayManager::GetInstance().GetDisplayState(defaultId_); + ASSERT_EQ(stateGet, stateToSet); +} + +/** + * @tc.name: SetDisplayStateValid + * @tc.desc: Call SetDisplayState to set a value already set and check the return value + * @tc.type: FUNC + */ +HWTEST_F(DisplayPowerTest, SetDisplayStateValid02, Function | MediumTest | Level2) +{ + DisplayState initialState = DisplayManager::GetInstance().GetDisplayState(defaultId_); + bool ret = DisplayManager::GetInstance().SetDisplayState(initialState, callback_); + ASSERT_EQ(false, ret); + DisplayState stateGet = DisplayManager::GetInstance().GetDisplayState(defaultId_); + ASSERT_EQ(stateGet, initialState); + ASSERT_EQ(false, isDisplayStateCallbackCalled_); +} + +/** + * @tc.name: SetDisplayStateCallbackValid + * @tc.desc: Call SetDisplayState and check if callback state is correct + * @tc.type: FUNC + */ +HWTEST_F(DisplayPowerTest, SetDisplayStateCallbackValid01, Function | MediumTest | Level2) +{ + DisplayState initialState = DisplayManager::GetInstance().GetDisplayState(defaultId_); + DisplayState stateToSet = (initialState == DisplayState::OFF ? DisplayState::ON : DisplayState::OFF); + DisplayManager::GetInstance().SetDisplayState(stateToSet, callback_); + sleep(1); + ASSERT_EQ(true, isDisplayStateCallbackCalled_); + ASSERT_EQ(state_, stateToSet); +} + +/** + * @tc.name: SetDisplayStateCallbackValid + * @tc.desc: Call SetDisplayState to set a value already set and check the DisplayStateCallback + * @tc.type: FUNC + */ +HWTEST_F(DisplayPowerTest, SetDisplayStateCallbackValid02, Function | MediumTest | Level2) +{ + DisplayState initialState = DisplayManager::GetInstance().GetDisplayState(defaultId_); + DisplayManager::GetInstance().SetDisplayState(initialState, callback_); + ASSERT_EQ(false, isDisplayStateCallbackCalled_); +} + +/** + * @tc.name: WakeUpBeginCallbackValid + * @tc.desc: Call WakeUpBegin and check the OnDisplayPowerEvent callback is called + * @tc.type: FUNC + */ +HWTEST_F(DisplayPowerTest, WakeUpBeginCallbackValid01, Function | MediumTest | Level2) +{ + bool ret = DisplayManager::GetInstance().WakeUpBegin(PowerStateChangeReason::POWER_BUTTON); + ASSERT_EQ(true, ret); + sleep(1); + ASSERT_EQ(true, listener_->isCallbackCalled_); + ASSERT_EQ(DisplayPowerEvent::WAKE_UP, listener_->event_); + ASSERT_EQ(EventStatus::BEGIN, listener_->status_); +} + +/** + * @tc.name: WakeUpEndCallbackValid + * @tc.desc: Call WakeUpBegin and check the OnDisplayPowerEvent callback is called + * @tc.type: FUNC + */ +HWTEST_F(DisplayPowerTest, WakeUpEndCallbackValid01, Function | MediumTest | Level2) +{ + bool ret = DisplayManager::GetInstance().WakeUpEnd(); + ASSERT_EQ(true, ret); + sleep(1); + ASSERT_EQ(true, listener_->isCallbackCalled_); + ASSERT_EQ(DisplayPowerEvent::WAKE_UP, listener_->event_); + ASSERT_EQ(EventStatus::END, listener_->status_); +} + +/** + * @tc.name: SuspendBeginCallbackValid + * @tc.desc: Call SuspendBegin and check the OnDisplayPowerEvent callback is called + * @tc.type: FUNC + */ +HWTEST_F(DisplayPowerTest, SuspendBeginCallbackValid01, Function | MediumTest | Level2) +{ + bool ret = DisplayManager::GetInstance().SuspendBegin(PowerStateChangeReason::POWER_BUTTON); + ASSERT_EQ(true, ret); + sleep(1); + ASSERT_EQ(true, listener_->isCallbackCalled_); + ASSERT_EQ(DisplayPowerEvent::SLEEP, listener_->event_); + ASSERT_EQ(EventStatus::BEGIN, listener_->status_); +} + +/** +* @tc.name: SuspendEndCallbackValid +* @tc.desc: Call SuspendEnd and check the OnDisplayPowerEvent callback is called +* @tc.type: FUNC +*/ +HWTEST_F(DisplayPowerTest, SuspendEndCallbackValid01, Function | MediumTest | Level2) +{ + bool ret = DisplayManager::GetInstance().SuspendEnd(); + ASSERT_EQ(true, ret); + sleep(1); + ASSERT_EQ(true, listener_->isCallbackCalled_); + ASSERT_EQ(DisplayPowerEvent::SLEEP, listener_->event_); + ASSERT_EQ(EventStatus::END, listener_->status_); +} + +/** +* @tc.name: SetScreenPowerForAllCallbackValid +* @tc.desc: Call SetScreenPowerForAll OFF and check the OnDisplayPowerEvent callback is called +* @tc.type: FUNC +*/ +HWTEST_F(DisplayPowerTest, SetScreenPowerForAllCallbackValid01, Function | MediumTest | Level2) +{ + bool ret = DisplayManager::GetInstance().SetScreenPowerForAll(DisplayPowerState::POWER_OFF, + PowerStateChangeReason::POWER_BUTTON); + ASSERT_EQ(true, ret); + sleep(1); + ASSERT_EQ(true, listener_->isCallbackCalled_); + ASSERT_EQ(DisplayPowerEvent::DISPLAY_OFF, listener_->event_); + ASSERT_EQ(EventStatus::END, listener_->status_); +} + +/** +* @tc.name: SetScreenPowerForAllCallbackValid +* @tc.desc: Call SetScreenPowerForAll ON and check the OnDisplayPowerEvent callback is called +* @tc.type: FUNC +*/ +HWTEST_F(DisplayPowerTest, SetScreenPowerForAllCallbackValid02, Function | MediumTest | Level2) +{ + bool ret = DisplayManager::GetInstance().SetScreenPowerForAll(DisplayPowerState::POWER_ON, + PowerStateChangeReason::POWER_BUTTON); + ASSERT_EQ(true, ret); + sleep(1); + ASSERT_EQ(true, listener_->isCallbackCalled_); + ASSERT_EQ(DisplayPowerEvent::DISPLAY_ON, listener_->event_); + ASSERT_EQ(EventStatus::END, listener_->status_); +} + +/** +* @tc.name: SetDisplayStatePowerCallbackValid +* @tc.desc: Call SetScreenPowerForAll OFF and check the OnDisplayPowerEvent callback is called +* @tc.type: FUNC +*/ +HWTEST_F(DisplayPowerTest, SetDisplayStatePowerCallbackValid01, Function | MediumTest | Level2) +{ + bool ret = DisplayManager::GetInstance().SetDisplayState(DisplayState::OFF, callback_); + ASSERT_EQ(true, ret); + sleep(1); + ASSERT_EQ(true, listener_->isCallbackCalled_); + ASSERT_EQ(DisplayPowerEvent::DISPLAY_OFF, listener_->event_); + ASSERT_EQ(EventStatus::BEGIN, listener_->status_); +} + +/** +* @tc.name: SetDisplayStatePowerCallbackValid +* @tc.desc: Call SetScreenPowerForAll ON and check the OnDisplayPowerEvent callback is called +* @tc.type: FUNC +*/ +HWTEST_F(DisplayPowerTest, SetDisplayStatePowerCallbackValid02, Function | MediumTest | Level2) +{ + bool ret = DisplayManager::GetInstance().SetDisplayState(DisplayState::ON, callback_); + ASSERT_EQ(true, ret); + sleep(1); + ASSERT_EQ(true, listener_->isCallbackCalled_); + ASSERT_EQ(DisplayPowerEvent::DISPLAY_ON, listener_->event_); + ASSERT_EQ(EventStatus::BEGIN, listener_->status_); +} + +/** +* @tc.name: SetScreenPowerForAllValid +* @tc.desc: Call SetScreenPowerForAll OFF and check the GetScreenPower return value +* @tc.type: FUNC +*/ +HWTEST_F(DisplayPowerTest, SetScreenPowerForAllValid01, Function | MediumTest | Level2) +{ + DisplayPowerState stateToSet = DisplayPowerState::POWER_OFF; + bool ret = DisplayManager::GetInstance().SetScreenPowerForAll(stateToSet, PowerStateChangeReason::POWER_BUTTON); + ASSERT_EQ(true, ret); + DisplayPowerState stateGet = DisplayManager::GetInstance().GetScreenPower(defaultId_); + ASSERT_EQ(stateGet, stateToSet); +} + +/** +* @tc.name: SetScreenPowerForAllValid +* @tc.desc: Call SetScreenPowerForAll ON and check the GetScreenPower return value +* @tc.type: FUNC +*/ +HWTEST_F(DisplayPowerTest, SetScreenPowerForAllValid02, Function | MediumTest | Level2) +{ + DisplayPowerState stateToSet = DisplayPowerState::POWER_ON; + bool ret = DisplayManager::GetInstance().SetScreenPowerForAll(stateToSet, PowerStateChangeReason::POWER_BUTTON); + ASSERT_EQ(true, ret); + DisplayPowerState stateGet = DisplayManager::GetInstance().GetScreenPower(defaultId_); + ASSERT_EQ(stateGet, stateToSet); +} +} // namespace +} // namespace Rosen +} // namespace OHOS \ No newline at end of file diff --git a/dmserver/src/display_power_controller.cpp b/dmserver/src/display_power_controller.cpp index 225c19aadd..f93b75dd6b 100644 --- a/dmserver/src/display_power_controller.cpp +++ b/dmserver/src/display_power_controller.cpp @@ -34,8 +34,8 @@ bool DisplayPowerController::SetDisplayState(DisplayState state) { WLOGFI("state:%{public}u", state); if (displayState_ == state) { - WLOGFI("state is already set"); - return true; + WLOGFE("state is already set"); + return false; } switch (state) { case DisplayState::ON: { diff --git a/interfaces/innerkits/dm/display_manager.h b/interfaces/innerkits/dm/display_manager.h index 402f3181ec..465a437616 100644 --- a/interfaces/innerkits/dm/display_manager.h +++ b/interfaces/innerkits/dm/display_manager.h @@ -68,6 +68,7 @@ private: bool CheckSizeValid(const Media::Size &size, int32_t oriHeight, int32_t oriWidth); void NotifyDisplayPowerEvent(DisplayPowerEvent event, EventStatus status); void NotifyDisplayStateChanged(DisplayState state); + void ClearDisplayStateCallback(); static inline SingletonDelegator delegator; const int32_t MAX_RESOLUTION_SIZE_SCREENSHOT = 15360; // max resolution, 16K -- Gitee From 1cbaa5439cd462e0df815081a9e4915b80eca4f8 Mon Sep 17 00:00:00 2001 From: youqijing Date: Tue, 18 Jan 2022 20:23:09 +0800 Subject: [PATCH 23/57] Fix sceenshot.d.ts file name Signed-off-by: youqijing Change-Id: I0a377b67ee2b124fef7e48e555566f5e56c87619 --- .../api/{@ohos.sceenshot.d.ts => @ohos.screenshot.d.ts} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename interfaces/kits/js/declaration/api/{@ohos.sceenshot.d.ts => @ohos.screenshot.d.ts} (100%) diff --git a/interfaces/kits/js/declaration/api/@ohos.sceenshot.d.ts b/interfaces/kits/js/declaration/api/@ohos.screenshot.d.ts similarity index 100% rename from interfaces/kits/js/declaration/api/@ohos.sceenshot.d.ts rename to interfaces/kits/js/declaration/api/@ohos.screenshot.d.ts -- Gitee From 27e5b3cac839802a52ecbc3fd3cb640c496bbdbd Mon Sep 17 00:00:00 2001 From: luwei Date: Tue, 18 Jan 2022 16:44:42 +0800 Subject: [PATCH 24/57] add screenshot unittest and modify screenshot Signed-off-by: luwei Change-Id: I37afde27885e405ae4af723d8a08b2156f88c03b --- dm/src/display_manager.cpp | 2 +- dm/test/unittest/BUILD.gn | 16 ++- dm/test/unittest/screenshot_test.cpp | 118 ++++++++++++++++++ dm/test/unittest/screenshot_test.h | 35 ++++++ .../include/abstract_display_controller.h | 2 +- dmserver/src/abstract_display_controller.cpp | 2 +- dmserver/src/display_manager_service.cpp | 3 +- interfaces/innerkits/dm/display_manager.h | 2 +- 8 files changed, 173 insertions(+), 7 deletions(-) create mode 100644 dm/test/unittest/screenshot_test.cpp create mode 100644 dm/test/unittest/screenshot_test.h diff --git a/dm/src/display_manager.cpp b/dm/src/display_manager.cpp index cfcda3a0af..219c34bc7f 100644 --- a/dm/src/display_manager.cpp +++ b/dm/src/display_manager.cpp @@ -85,7 +85,7 @@ bool DisplayManager::CheckRectValid(const Media::Rect &rect, int32_t oriHeight, return true; } -bool DisplayManager::CheckSizeValid(const Media::Size &size, int32_t oriHeight, int32_t oriWidth) +bool DisplayManager::CheckSizeValid(const Media::Size &size, int32_t oriHeight, int32_t oriWidth) const { if (!((size.width > 0) and (size.height > 0))) { if (!((size.width == 0) and (size.height == 0))) { diff --git a/dm/test/unittest/BUILD.gn b/dm/test/unittest/BUILD.gn index c523562cc3..aa6313958c 100644 --- a/dm/test/unittest/BUILD.gn +++ b/dm/test/unittest/BUILD.gn @@ -18,7 +18,10 @@ module_out_path = "window_manager/dm" group("unittest") { testonly = true - deps = [ ":dm_snapshot_utils_test" ] + deps = [ + ":dm_screenshot_test", + ":dm_snapshot_utils_test", + ] } ## UnitTest dm_snapshot_utils_test {{{ @@ -35,6 +38,17 @@ ohos_unittest("dm_snapshot_utils_test") { ## UnitTest dm_snapshot_utils_test }}} +## UnitTest dm_screenshot_test {{{ +ohos_unittest("dm_screenshot_test") { + module_out_path = module_out_path + + sources = [ "screenshot_test.cpp" ] + + deps = [ ":dm_unittest_common" ] +} + +## UnitTest dm_screenshot_test }}} + ## Build dm_unittest_common.a {{{ config("dm_unittest_common_public_config") { include_dirs = [ diff --git a/dm/test/unittest/screenshot_test.cpp b/dm/test/unittest/screenshot_test.cpp new file mode 100644 index 0000000000..d1b0427c4a --- /dev/null +++ b/dm/test/unittest/screenshot_test.cpp @@ -0,0 +1,118 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include "mock_display_manager_adapter.h" +#include "singleton_mocker.h" +#include "screenshot_test.h" + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { +namespace Rosen { +constexpr int32_t TEST_IMAGE_HEIGHT = 1080; +constexpr int32_t TEST_IMAGE_WIDTH = 1920; +using Mocker = SingletonMocker; +void ScreenshotTest::SetUpTestCase() +{ +} + +void ScreenshotTest::TearDownTestCase() +{ +} + +void ScreenshotTest::SetUp() +{ +} + +void ScreenshotTest::TearDown() +{ +} + +namespace { +static std::shared_ptr CreatePixelMap() +{ + // pixel_map testing code + Media::InitializationOptions opt; + opt.size.width = TEST_IMAGE_WIDTH; + opt.size.height = TEST_IMAGE_HEIGHT; + opt.pixelFormat = Media::PixelFormat::RGBA_8888; + opt.alphaType = Media::AlphaType::IMAGE_ALPHA_TYPE_OPAQUE; + opt.scaleMode = Media::ScaleMode::FIT_TARGET_SIZE; + opt.editable = false; + opt.useSourceIfMatch = false; + + const int bitmapDepth = 8; // color depth + const int bpp = 4; // bytes per pixel + const int pixelValue = 125; + + const int voulumeSize = opt.size.width * opt.size.height * bpp; + auto data = (uint32_t *)malloc(voulumeSize); + if (data == nullptr) { + return nullptr; + } + + uint8_t *pic = (uint8_t *)data; + memset_s(pic, voulumeSize, pixelValue, voulumeSize); + + uint32_t colorLen = voulumeSize * bitmapDepth; + auto pixelMap = Media::PixelMap::Create(data, colorLen, opt); + if (pixelMap == nullptr) { + return nullptr; + } + std::shared_ptr pixelMap_(pixelMap.release()); + return pixelMap_; +} + +/** + * @tc.name: GetScreenshot_default + * @tc.desc: SetWindowRect/GetWindowRect + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(ScreenshotTest, GetScreenshot_default, Function | SmallTest | Level2) +{ + std::unique_ptr m = std::make_unique(); + + EXPECT_CALL(m->Mock(), GetDefaultDisplayId()).Times(1).WillOnce(Return(0ULL)); + + DisplayId displayId = DisplayManager::GetInstance().GetDefaultDisplayId(); + + EXPECT_CALL(m->Mock(), GetDisplaySnapshot(_)).Times(1).WillOnce(Return(nullptr)); + + ASSERT_EQ(nullptr, DisplayManager::GetInstance().GetScreenshot(displayId)); +} + +HWTEST_F(ScreenshotTest, GetScreenshot_01, Function | MediumTest | Level2) +{ + std::unique_ptr m = std::make_unique(); + + EXPECT_CALL(m->Mock(), GetDefaultDisplayId()).Times(1).WillOnce(Return(0ULL)); + DisplayId displayId = DisplayManager::GetInstance().GetDefaultDisplayId(); + + EXPECT_CALL(m->Mock(), GetDisplaySnapshot(_)).Times(1).WillOnce(Return(CreatePixelMap())); + auto screenshot = DisplayManager::GetInstance().GetScreenshot(displayId); + ASSERT_NE(nullptr, screenshot); + + uint32_t width = screenshot->GetWidth(); + uint32_t height = screenshot->GetHeight(); + ASSERT_EQ(width, TEST_IMAGE_WIDTH); + ASSERT_EQ(height, TEST_IMAGE_HEIGHT); +} +} +} // namespace Rosen +} // namespace OHOS diff --git a/dm/test/unittest/screenshot_test.h b/dm/test/unittest/screenshot_test.h new file mode 100644 index 0000000000..59d4b27de5 --- /dev/null +++ b/dm/test/unittest/screenshot_test.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FRAMEWORKS_WM_TEST_UT_WINDOW_OPTION_TEST_H +#define FRAMEWORKS_WM_TEST_UT_WINDOW_OPTION_TEST_H + +#include +#include "png.h" +#include "display_manager.h" +#include "pixel_map.h" + +namespace OHOS { +namespace Rosen { +class ScreenshotTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + virtual void SetUp() override; + virtual void TearDown() override; +}; +} // namespace ROSEN +} // namespace OHOS +#endif // FRAMEWORKS_WM_TEST_UT_WINDOW_OPTION_TEST_H diff --git a/dmserver/include/abstract_display_controller.h b/dmserver/include/abstract_display_controller.h index 5f1b113629..b8797603b9 100644 --- a/dmserver/include/abstract_display_controller.h +++ b/dmserver/include/abstract_display_controller.h @@ -37,7 +37,7 @@ public: ScreenId GetDefaultScreenId(); RSScreenModeInfo GetScreenActiveMode(ScreenId id); - std::shared_ptr GetScreenSnapshot(DisplayId displayId, ScreenId screenId); + std::shared_ptr GetScreenSnapshot(DisplayId displayId); private: void OnAbstractScreenConnected(sptr absScreen); diff --git a/dmserver/src/abstract_display_controller.cpp b/dmserver/src/abstract_display_controller.cpp index cc4e790897..45af6bd565 100644 --- a/dmserver/src/abstract_display_controller.cpp +++ b/dmserver/src/abstract_display_controller.cpp @@ -70,7 +70,7 @@ RSScreenModeInfo AbstractDisplayController::GetScreenActiveMode(ScreenId id) return rsInterface_->GetScreenActiveMode(id); } -std::shared_ptr AbstractDisplayController::GetScreenSnapshot(DisplayId displayId, ScreenId screenId) +std::shared_ptr AbstractDisplayController::GetScreenSnapshot(DisplayId displayId) { if (rsInterface_ == nullptr) { return nullptr; diff --git a/dmserver/src/display_manager_service.cpp b/dmserver/src/display_manager_service.cpp index 256290e13f..e133cf72a8 100644 --- a/dmserver/src/display_manager_service.cpp +++ b/dmserver/src/display_manager_service.cpp @@ -117,9 +117,8 @@ DMError DisplayManagerService::DestroyVirtualScreen(ScreenId screenId) std::shared_ptr DisplayManagerService::GetDispalySnapshot(DisplayId displayId) { - ScreenId screenId = GetScreenIdFromDisplayId(displayId); std::shared_ptr screenSnapshot - = abstractDisplayController_->GetScreenSnapshot(displayId, screenId); + = abstractDisplayController_->GetScreenSnapshot(displayId); return screenSnapshot; } diff --git a/interfaces/innerkits/dm/display_manager.h b/interfaces/innerkits/dm/display_manager.h index 402f3181ec..92d60fb5f2 100644 --- a/interfaces/innerkits/dm/display_manager.h +++ b/interfaces/innerkits/dm/display_manager.h @@ -65,7 +65,7 @@ private: DisplayManager(); ~DisplayManager(); bool CheckRectValid(const Media::Rect &rect, int32_t oriHeight, int32_t oriWidth) const; - bool CheckSizeValid(const Media::Size &size, int32_t oriHeight, int32_t oriWidth); + bool CheckSizeValid(const Media::Size &size, int32_t oriHeight, int32_t oriWidth) const; void NotifyDisplayPowerEvent(DisplayPowerEvent event, EventStatus status); void NotifyDisplayStateChanged(DisplayState state); -- Gitee From 4cbef60ff7265de13a3e9a5f1231a116b86b4807 Mon Sep 17 00:00:00 2001 From: l00574490 Date: Mon, 17 Jan 2022 21:31:01 +0800 Subject: [PATCH 25/57] add for split st Signed-off-by: l00574490 Change-Id: Id0d6277dcf753289b6d8ef95780cb5e1ca5af55a --- interfaces/innerkits/wm/wm_common.h | 1 + wm/test/systemtest/window_layout_test.cpp | 22 +-- wm/test/systemtest/window_split_test.cpp | 189 +++++++++++++++------- wm/test/systemtest/window_test_utils.cpp | 176 ++++++++++++++++++-- wm/test/systemtest/window_test_utils.h | 24 ++- wmserver/include/window_node_container.h | 1 - wmserver/src/window_node_container.cpp | 12 +- 7 files changed, 338 insertions(+), 87 deletions(-) diff --git a/interfaces/innerkits/wm/wm_common.h b/interfaces/innerkits/wm/wm_common.h index 34f5ca6768..8d69a0b9cb 100644 --- a/interfaces/innerkits/wm/wm_common.h +++ b/interfaces/innerkits/wm/wm_common.h @@ -104,6 +104,7 @@ struct Rect { namespace { constexpr uint32_t SYSTEM_COLOR_WHITE = 0xFFFFFFE5; constexpr uint32_t SYSTEM_COLOR_BLACK = 0x00000066; + constexpr float DEFAULT_SPLIT_RATIO = 0.5; } struct SystemBarProperty { diff --git a/wm/test/systemtest/window_layout_test.cpp b/wm/test/systemtest/window_layout_test.cpp index d495bf054d..41cf65f8c6 100644 --- a/wm/test/systemtest/window_layout_test.cpp +++ b/wm/test/systemtest/window_layout_test.cpp @@ -44,28 +44,28 @@ void WindowLayoutTest::SetUpTestCase() printf("GetDefaultDisplay: id %llu, w %d, h %d, fps %u\n", display->GetId(), display->GetWidth(), display->GetHeight(), display->GetFreshRate()); } - Rect screenRect = {0, 0, display->GetWidth(), display->GetHeight()}; - utils::InitByScreenRect(screenRect); + Rect displayRect = {0, 0, display->GetWidth(), display->GetHeight()}; + utils::InitByDisplayRect(displayRect); // calc expected rects Rect expected = { // 0. only statusBar 0, utils::statusBarRect_.height_, - utils::screenRect_.width_, - utils::screenRect_.height_ - utils::statusBarRect_.height_, + utils::displayRect_.width_, + utils::displayRect_.height_ - utils::statusBarRect_.height_, }; fullScreenExpecteds_.push_back(expected); expected = { // 1. both statusBar and naviBar 0, utils::statusBarRect_.height_, - utils::screenRect_.width_, - utils::screenRect_.height_ - utils::statusBarRect_.height_ - utils::naviBarRect_.height_, + utils::displayRect_.width_, + utils::displayRect_.height_ - utils::statusBarRect_.height_ - utils::naviBarRect_.height_, }; fullScreenExpecteds_.push_back(expected); expected = { // 2. only naviBar 0, 0, - utils::screenRect_.width_, - utils::screenRect_.height_ - utils::naviBarRect_.height_, + utils::displayRect_.width_, + utils::displayRect_.height_ - utils::naviBarRect_.height_, }; fullScreenExpecteds_.push_back(expected); } @@ -179,11 +179,11 @@ HWTEST_F(WindowLayoutTest, LayoutWindow06, Function | MediumTest | Level3) ASSERT_EQ(WMError::WM_OK, statBar->Show()); ASSERT_TRUE(utils::RectEqualTo(statBar, utils::statusBarRect_)); ASSERT_EQ(WMError::WM_OK, sysWin->Show()); - ASSERT_TRUE(utils::RectEqualTo(sysWin, utils::screenRect_)); + ASSERT_TRUE(utils::RectEqualTo(sysWin, utils::displayRect_)); ASSERT_EQ(WMError::WM_OK, naviBar->Show()); - ASSERT_TRUE(utils::RectEqualTo(sysWin, utils::screenRect_)); + ASSERT_TRUE(utils::RectEqualTo(sysWin, utils::displayRect_)); ASSERT_EQ(WMError::WM_OK, statBar->Hide()); - ASSERT_TRUE(utils::RectEqualTo(sysWin, utils::screenRect_)); + ASSERT_TRUE(utils::RectEqualTo(sysWin, utils::displayRect_)); } /** diff --git a/wm/test/systemtest/window_split_test.cpp b/wm/test/systemtest/window_split_test.cpp index 4f13551ebf..d1d6e2901b 100644 --- a/wm/test/systemtest/window_split_test.cpp +++ b/wm/test/systemtest/window_split_test.cpp @@ -29,6 +29,8 @@ public: virtual void SetUp() override; virtual void TearDown() override; std::vector> activeWindows_; + utils::TestWindowInfo fullInfo_; + utils::TestWindowInfo splitInfo_; private: static constexpr uint32_t SPLIT_TEST_SPEEP_S = 1; // split test spleep time @@ -44,6 +46,26 @@ void WindowSplitTest::TearDownTestCase() void WindowSplitTest::SetUp() { + fullInfo_ = { + .name = "", + .rect = utils::defaultAppRect_, + .type = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, + .mode = WindowMode::WINDOW_MODE_FULLSCREEN, + .needAvoid = true, + .parentLimit = false, + .parentName = "", + }; + + splitInfo_ = { + .name = "", + .rect = utils::defaultAppRect_, + .type = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, + .mode = WindowMode::WINDOW_MODE_FULLSCREEN, + .needAvoid = true, + .parentLimit = false, + .parentName = "", + }; + activeWindows_.clear(); } @@ -58,89 +80,132 @@ void WindowSplitTest::TearDown() namespace { /** * @tc.name: SplitWindow01 - * @tc.desc: one primary window and one fullscreen window + * @tc.desc: one primary window and one fullscreen window, test mode change * @tc.type: FUNC * @tc.require: AR000GGTV7 */ HWTEST_F(WindowSplitTest, SplitWindow01, Function | MediumTest | Level3) { - utils::TestWindowInfo infoFullScreen = { - .name = "fullscreen.1", - .rect = utils::defaultAppRect_, - .type = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, - .mode = WindowMode::WINDOW_MODE_FULLSCREEN, - .needAvoid = true, - .parentLimit = false, - .parentName = "", - }; - utils::TestWindowInfo infoPrimary = { - .name = "primary.1", - .rect = utils::defaultAppRect_, - .type = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, - .mode = WindowMode::WINDOW_MODE_SPLIT_PRIMARY, - .needAvoid = true, - .parentLimit = false, - .parentName = "", - }; - const sptr& windowFullScreen = utils::CreateTestWindow(infoFullScreen); - ASSERT_EQ(WMError::WM_OK, windowFullScreen->Show()); + fullInfo_.name = "fullscreen.1"; + splitInfo_.name = "primary.1"; + splitInfo_.mode = WindowMode::WINDOW_MODE_SPLIT_PRIMARY; + + const sptr& fullWindow = utils::CreateTestWindow(fullInfo_); + activeWindows_.push_back(fullWindow); + ASSERT_EQ(WMError::WM_OK, fullWindow->Show()); sleep(SPLIT_TEST_SPEEP_S); - activeWindows_.push_back(windowFullScreen); - const sptr& windowPrimary = utils::CreateTestWindow(infoPrimary); - ASSERT_EQ(WMError::WM_OK, windowPrimary->Show()); + + const sptr& priWindow = utils::CreateTestWindow(splitInfo_); + activeWindows_.push_back(priWindow); + ASSERT_EQ(WMError::WM_OK, priWindow->Show()); sleep(SPLIT_TEST_SPEEP_S); - ASSERT_EQ(WindowMode::WINDOW_MODE_SPLIT_PRIMARY, windowPrimary->GetMode()); - activeWindows_.push_back(windowPrimary); - // show one split primary window - ASSERT_EQ(WindowMode::WINDOW_MODE_SPLIT_SECONDARY, windowFullScreen->GetMode()); - ASSERT_EQ(WMError::WM_OK, windowPrimary->Hide()); + + ASSERT_EQ(WindowMode::WINDOW_MODE_SPLIT_PRIMARY, priWindow->GetMode()); + ASSERT_EQ(WindowMode::WINDOW_MODE_SPLIT_SECONDARY, fullWindow->GetMode()); + + ASSERT_EQ(WMError::WM_OK, priWindow->Hide()); sleep(SPLIT_TEST_SPEEP_S); - ASSERT_EQ(WindowMode::WINDOW_MODE_FULLSCREEN, windowFullScreen->GetMode()); - ASSERT_EQ(WMError::WM_OK, windowFullScreen->Hide()); + ASSERT_EQ(WindowMode::WINDOW_MODE_FULLSCREEN, fullWindow->GetMode()); + ASSERT_EQ(WMError::WM_OK, fullWindow->Hide()); sleep(SPLIT_TEST_SPEEP_S); } /** * @tc.name: SplitWindow02 - * @tc.desc: one secondary window and one fullscreen window + * @tc.desc: one secondary window and one fullscreen window, test mode change * @tc.type: FUNC * @tc.require: AR000GGTV7 */ HWTEST_F(WindowSplitTest, SplitWindow02, Function | MediumTest | Level3) { - utils::TestWindowInfo infoFullScreen = { - .name = "fullscreen.2", - .rect = utils::defaultAppRect_, - .type = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, - .mode = WindowMode::WINDOW_MODE_FULLSCREEN, - .needAvoid = true, - .parentLimit = false, - .parentName = "", - }; - utils::TestWindowInfo infoSecondary = { - .name = "secondary.2", - .rect = utils::defaultAppRect_, - .type = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, - .mode = WindowMode::WINDOW_MODE_SPLIT_SECONDARY, - .needAvoid = true, - .parentLimit = false, - .parentName = "", - }; - const sptr& windowFullScreen = utils::CreateTestWindow(infoFullScreen); - ASSERT_EQ(WMError::WM_OK, windowFullScreen->Show()); + fullInfo_.name = "fullscreen.2"; + splitInfo_.name = "secondary.2"; + splitInfo_.mode = WindowMode::WINDOW_MODE_SPLIT_SECONDARY; + + const sptr& fullWindow = utils::CreateTestWindow(fullInfo_); + activeWindows_.push_back(fullWindow); + ASSERT_EQ(WMError::WM_OK, fullWindow->Show()); + sleep(SPLIT_TEST_SPEEP_S); + const sptr& secWindow = utils::CreateTestWindow(splitInfo_); + activeWindows_.push_back(secWindow); + ASSERT_EQ(WMError::WM_OK, secWindow->Show()); + sleep(SPLIT_TEST_SPEEP_S); + + ASSERT_EQ(WindowMode::WINDOW_MODE_SPLIT_SECONDARY, secWindow->GetMode()); + ASSERT_EQ(WindowMode::WINDOW_MODE_SPLIT_PRIMARY, fullWindow->GetMode()); + + ASSERT_EQ(WMError::WM_OK, fullWindow->Hide()); + sleep(SPLIT_TEST_SPEEP_S); + ASSERT_EQ(WindowMode::WINDOW_MODE_FULLSCREEN, secWindow->GetMode()); + ASSERT_EQ(WMError::WM_OK, secWindow->Hide()); + sleep(SPLIT_TEST_SPEEP_S); +} + +/** + * @tc.name: SplitCreen03 + * @tc.desc: one primary window and one fullscreen window, test rects + * @tc.type: FUNC + * @tc.require: AR000GGTV7 + */ +HWTEST_F(WindowSplitTest, SplitCreen03, Function | MediumTest | Level3) +{ + fullInfo_.name = "fullscreen.3"; + splitInfo_.name = "primary.3"; + splitInfo_.mode = WindowMode::WINDOW_MODE_SPLIT_PRIMARY; + + utils::InitSplitRects(); + + const sptr& fullWindow = utils::CreateTestWindow(fullInfo_); + activeWindows_.push_back(fullWindow); + ASSERT_EQ(WMError::WM_OK, fullWindow->Show()); + sleep(SPLIT_TEST_SPEEP_S); + const sptr& priWindow = utils::CreateTestWindow(splitInfo_); + activeWindows_.push_back(priWindow); + ASSERT_EQ(WMError::WM_OK, priWindow->Show()); + sleep(SPLIT_TEST_SPEEP_S); + + utils::UpdateSplitRects(fullWindow); + + ASSERT_TRUE(utils::RectEqualTo(fullWindow, utils::splitRects_.secondaryRect)); + ASSERT_TRUE(utils::RectEqualTo(priWindow, utils::splitRects_.primaryRect)); + + ASSERT_EQ(WMError::WM_OK, fullWindow->Hide()); + sleep(SPLIT_TEST_SPEEP_S); + ASSERT_EQ(WMError::WM_OK, priWindow->Hide()); + sleep(SPLIT_TEST_SPEEP_S); +} + +/** + * @tc.name: SplitCreen04 + * @tc.desc: one secondary window and one fullscreen window, test rects + * @tc.type: FUNC + * @tc.require: AR000GGTV7 + */ +HWTEST_F(WindowSplitTest, SplitCreen04, Function | MediumTest | Level3) +{ + fullInfo_.name = "fullscreen.4"; + splitInfo_.name = "secondary.4"; + splitInfo_.mode = WindowMode::WINDOW_MODE_SPLIT_SECONDARY; + + utils::InitSplitRects(); + + const sptr& fullWindow = utils::CreateTestWindow(fullInfo_); + activeWindows_.push_back(fullWindow); + ASSERT_EQ(WMError::WM_OK, fullWindow->Show()); sleep(SPLIT_TEST_SPEEP_S); - activeWindows_.push_back(windowFullScreen); - const sptr& windowSecondary = utils::CreateTestWindow(infoSecondary); - ASSERT_EQ(WMError::WM_OK, windowSecondary->Show()); + const sptr& secWindow = utils::CreateTestWindow(splitInfo_); + activeWindows_.push_back(secWindow); + ASSERT_EQ(WMError::WM_OK, secWindow->Show()); sleep(SPLIT_TEST_SPEEP_S); - ASSERT_EQ(WindowMode::WINDOW_MODE_SPLIT_SECONDARY, windowSecondary->GetMode()); - activeWindows_.push_back(windowSecondary); - // show one split secondary window - ASSERT_EQ(WindowMode::WINDOW_MODE_SPLIT_PRIMARY, windowFullScreen->GetMode()); - ASSERT_EQ(WMError::WM_OK, windowFullScreen->Hide()); + + utils::UpdateSplitRects(fullWindow); + + ASSERT_TRUE(utils::RectEqualTo(fullWindow, utils::splitRects_.primaryRect)); + ASSERT_TRUE(utils::RectEqualTo(secWindow, utils::splitRects_.secondaryRect)); + + ASSERT_EQ(WMError::WM_OK, fullWindow->Hide()); sleep(SPLIT_TEST_SPEEP_S); - ASSERT_EQ(WindowMode::WINDOW_MODE_FULLSCREEN, windowSecondary->GetMode()); - ASSERT_EQ(WMError::WM_OK, windowSecondary->Hide()); + ASSERT_EQ(WMError::WM_OK, secWindow->Hide()); sleep(SPLIT_TEST_SPEEP_S); } } diff --git a/wm/test/systemtest/window_test_utils.cpp b/wm/test/systemtest/window_test_utils.cpp index 2a252e384a..111bd2c055 100644 --- a/wm/test/systemtest/window_test_utils.cpp +++ b/wm/test/systemtest/window_test_utils.cpp @@ -17,10 +17,17 @@ #include namespace OHOS { namespace Rosen { -Rect WindowTestUtils::screenRect_ = {0, 0, 0, 0}; -Rect WindowTestUtils::statusBarRect_ = {0, 0, 0, 0}; -Rect WindowTestUtils::naviBarRect_ = {0, 0, 0, 0}; -Rect WindowTestUtils::defaultAppRect_ = {0, 0, 0, 0}; +Rect WindowTestUtils::displayRect_ = {0, 0, 0, 0}; +Rect WindowTestUtils::statusBarRect_ = {0, 0, 0, 0}; +Rect WindowTestUtils::naviBarRect_ = {0, 0, 0, 0}; +Rect WindowTestUtils::defaultAppRect_ = {0, 0, 0, 0}; +Rect WindowTestUtils::limitDisplayRect_ = {0, 0, 0, 0}; +SplitRects WindowTestUtils::splitRects_ = { + .primaryRect = {0, 0, 0, 0}, + .secondaryRect = {0, 0, 0, 0}, + .dividerRect = {0, 0, 0, 0}, +}; +bool WindowTestUtils::isVerticalDisplay_ = false; sptr WindowTestUtils::CreateTestWindow(const TestWindowInfo& info) { @@ -83,14 +90,14 @@ sptr WindowTestUtils::CreateWindowScene() return scene; } -void WindowTestUtils::InitByScreenRect(const Rect& screenRect) +void WindowTestUtils::InitByDisplayRect(const Rect& displayRect) { const float barRatio = 0.07; const float appRation = 0.4; - screenRect_ = screenRect; - statusBarRect_ = {0, 0, screenRect_.width_, screenRect_.height_ * barRatio}; - naviBarRect_ = {0, screenRect_.height_ * (1 - barRatio), screenRect_.width_, screenRect_.height_ * barRatio}; - defaultAppRect_ = {0, 0, screenRect_.width_ * appRation, screenRect_.height_ * appRation}; + displayRect_ = displayRect; + statusBarRect_ = {0, 0, displayRect_.width_, displayRect_.height_ * barRatio}; + naviBarRect_ = {0, displayRect_.height_ * (1 - barRatio), displayRect_.width_, displayRect_.height_ * barRatio}; + defaultAppRect_ = {0, 0, displayRect_.width_ * appRation, displayRect_.height_ * appRation}; } bool WindowTestUtils::RectEqualTo(const sptr& window, const Rect& r) @@ -103,5 +110,156 @@ bool WindowTestUtils::RectEqualTo(const sptr& window, const Rect& r) } return res; } + +AvoidPosType WindowTestUtils::GetAvoidPosType(const Rect& rect) +{ + if (rect.width_ >= rect.height_) { + if (rect.posY_ == 0) { + return AvoidPosType::AVOID_POS_TOP; + } else { + return AvoidPosType::AVOID_POS_BOTTOM; + } + } else { + if (rect.posX_ == 0) { + return AvoidPosType::AVOID_POS_LEFT; + } else { + return AvoidPosType::AVOID_POS_RIGHT; + } + } + return AvoidPosType::AVOID_POS_UNKNOWN; +} + +void WindowTestUtils::InitSplitRects() +{ + auto display = DisplayManager::GetInstance().GetDisplayById(0); + if (display == nullptr) { + printf("GetDefaultDisplay: failed!\n"); + } else { + printf("GetDefaultDisplay: id %llu, w %d, h %d, fps %u\n", display->GetId(), display->GetWidth(), + display->GetHeight(), display->GetFreshRate()); + } + + Rect displayRect = {0, 0, display->GetWidth(), display->GetHeight()}; + displayRect_ = displayRect; + limitDisplayRect_ = displayRect; + + if (displayRect_.width_ < displayRect_.height_) { + isVerticalDisplay_ = true; + } + const uint32_t dividerWidth = 50; + if (isVerticalDisplay_) { + splitRects_.dividerRect = { 0, + static_cast((displayRect_.height_ - dividerWidth) * DEFAULT_SPLIT_RATIO), + displayRect_.width_, + dividerWidth, }; + } else { + splitRects_.dividerRect = { static_cast((displayRect_.width_ - dividerWidth) * DEFAULT_SPLIT_RATIO), + 0, + dividerWidth, + displayRect_.height_ }; + } +} + +void WindowTestUtils::UpdateSplitRects(const sptr& window) +{ + std::unique_ptr testUtils = std::make_unique(); + auto res = window->GetAvoidAreaByType(AvoidAreaType::TYPE_SYSTEM, testUtils->avoidArea_); + if (res != WMError::WM_OK) { + printf("Get avoid type failed\n"); + } + testUtils->UpdateLimitDisplayRect(testUtils->avoidArea_.leftRect); + testUtils->UpdateLimitDisplayRect(testUtils->avoidArea_.topRect); + testUtils->UpdateLimitDisplayRect(testUtils->avoidArea_.rightRect); + testUtils->UpdateLimitDisplayRect(testUtils->avoidArea_.bottomRect); + + if (isVerticalDisplay_) { + splitRects_.dividerRect.posY_ = limitDisplayRect_.posY_ + + static_cast((limitDisplayRect_.height_ - splitRects_.dividerRect.height_) * DEFAULT_SPLIT_RATIO); + testUtils->UpdateLimitSplitRects(splitRects_.dividerRect.posY_); + } else { + splitRects_.dividerRect.posX_ = limitDisplayRect_.posX_ + + static_cast((limitDisplayRect_.width_ - splitRects_.dividerRect.width_) * DEFAULT_SPLIT_RATIO); + testUtils->UpdateLimitSplitRects(splitRects_.dividerRect.posX_); + } +} + +void WindowTestUtils::UpdateLimitDisplayRect(Rect& avoidRect) +{ + if (((avoidRect.posX_ == 0) && (avoidRect.posY_ == 0) && + (avoidRect.width_ == 0) && (avoidRect.height_ == 0))) { + return; + } + auto avoidPosType = GetAvoidPosType(avoidRect); + int32_t offsetH = 0; + int32_t offsetW = 0; + switch (avoidPosType) { + case AvoidPosType::AVOID_POS_TOP: + offsetH = avoidRect.posY_ + avoidRect.height_ - limitDisplayRect_.posY_; + limitDisplayRect_.posY_ += offsetH; + limitDisplayRect_.height_ -= offsetH; + break; + case AvoidPosType::AVOID_POS_BOTTOM: + offsetH = limitDisplayRect_.posY_ + limitDisplayRect_.height_ - avoidRect.posY_; + limitDisplayRect_.height_ -= offsetH; + break; + case AvoidPosType::AVOID_POS_LEFT: + offsetW = avoidRect.posX_ + avoidRect.width_ - limitDisplayRect_.posX_; + limitDisplayRect_.posX_ += offsetW; + limitDisplayRect_.width_ -= offsetW; + break; + case AvoidPosType::AVOID_POS_RIGHT: + offsetW = limitDisplayRect_.posX_ + limitDisplayRect_.width_ - avoidRect.posX_; + limitDisplayRect_.width_ -= offsetW; + break; + default: + printf("invaild avoidPosType: %d\n", avoidPosType); + } +} + +void WindowTestUtils::UpdateLimitSplitRects(int32_t divPos) +{ + std::unique_ptr testUtils = std::make_unique(); + if (isVerticalDisplay_) { + splitRects_.dividerRect.posY_ = divPos; + + splitRects_.primaryRect.posX_ = displayRect_.posX_; + splitRects_.primaryRect.posY_ = displayRect_.posY_; + splitRects_.primaryRect.height_ = divPos; + splitRects_.primaryRect.width_ = displayRect_.width_; + + splitRects_.secondaryRect.posX_ = displayRect_.posX_; + splitRects_.secondaryRect.posY_ = splitRects_.dividerRect.posY_ + splitRects_.dividerRect.height_; + splitRects_.secondaryRect.height_ = displayRect_.height_ - splitRects_.secondaryRect.posY_; + splitRects_.secondaryRect.width_ = displayRect_.width_; + } else { + splitRects_.dividerRect.posX_ = divPos; + + splitRects_.primaryRect.posX_ = displayRect_.posX_; + splitRects_.primaryRect.posY_ = displayRect_.posY_; + splitRects_.primaryRect.width_ = divPos; + splitRects_.primaryRect.height_ = displayRect_.height_; + + splitRects_.secondaryRect.posX_ = splitRects_.dividerRect.posX_ + splitRects_.dividerRect.width_; + splitRects_.secondaryRect.posY_ = displayRect_.posY_; + splitRects_.secondaryRect.width_ = displayRect_.width_ - splitRects_.secondaryRect.posX_; + splitRects_.secondaryRect.height_ = displayRect_.height_; + } + + testUtils->UpdateLimitSplitRect(splitRects_.primaryRect); + testUtils->UpdateLimitSplitRect(splitRects_.secondaryRect); +} + +void WindowTestUtils::UpdateLimitSplitRect(Rect& limitSplitRect) +{ + Rect curLimitRect = limitSplitRect; + limitSplitRect.posX_ = std::max(limitDisplayRect_.posX_, curLimitRect.posX_); + limitSplitRect.posY_ = std::max(limitDisplayRect_.posY_, curLimitRect.posY_); + limitSplitRect.width_ = std::min(limitDisplayRect_.posX_ + limitDisplayRect_.width_, + curLimitRect.posX_ + curLimitRect.width_) - + limitSplitRect.posX_; + limitSplitRect.height_ = std::min(limitDisplayRect_.posY_ + limitDisplayRect_.height_, + curLimitRect.posY_ + curLimitRect.height_) - + limitSplitRect.posY_; +} } // namespace ROSEN } // namespace OHOS diff --git a/wm/test/systemtest/window_test_utils.h b/wm/test/systemtest/window_test_utils.h index a8998c6b37..f647b6c636 100644 --- a/wm/test/systemtest/window_test_utils.h +++ b/wm/test/systemtest/window_test_utils.h @@ -18,6 +18,7 @@ #include "display_manager.h" #include "window.h" +#include "window_layout_policy.h" #include "window_life_cycle_interface.h" #include "window_option.h" #include "window_scene.h" @@ -25,6 +26,12 @@ namespace OHOS { namespace Rosen { +struct SplitRects { + Rect primaryRect; + Rect secondaryRect; + Rect dividerRect; +}; + class WindowTestUtils { public: struct TestWindowInfo { @@ -36,16 +43,29 @@ public: bool parentLimit; std::string parentName; }; - static Rect screenRect_; + static Rect displayRect_; + static Rect limitDisplayRect_; static Rect statusBarRect_; static Rect naviBarRect_; static Rect defaultAppRect_; - static void InitByScreenRect(const Rect& screenRect); + static SplitRects splitRects_; + static bool isVerticalDisplay_; + + static void InitByDisplayRect(const Rect& screenRect); static sptr CreateTestWindow(const TestWindowInfo& info); static sptr CreateStatusBarWindow(); static sptr CreateNavigationBarWindow(); static sptr CreateWindowScene(); static bool RectEqualTo(const sptr& window, const Rect& r); + static void InitSplitRects(); + static void UpdateSplitRects(const sptr& window); + +private: + void UpdateLimitDisplayRect(Rect& avoidRect); + void UpdateLimitSplitRects(int32_t divPos); + void UpdateLimitSplitRect(Rect& limitSplitRect); + AvoidPosType GetAvoidPosType(const Rect& rect); + AvoidArea avoidArea_; }; } // namespace ROSEN } // namespace OHOS diff --git a/wmserver/include/window_node_container.h b/wmserver/include/window_node_container.h index cbaf17dbb3..a2354aa6a5 100644 --- a/wmserver/include/window_node_container.h +++ b/wmserver/include/window_node_container.h @@ -72,7 +72,6 @@ public: Rect displayRect_ = {0, 0, 0, 0}; Rect dividerRect_ = {0, 0, 0, 0}; }; - static constexpr float DEFAULT_SPLIT_RATIO = 0.5; private: void AssignZOrder(sptr& node); diff --git a/wmserver/src/window_node_container.cpp b/wmserver/src/window_node_container.cpp index 43e86ba5ec..ce6f3454ff 100644 --- a/wmserver/src/window_node_container.cpp +++ b/wmserver/src/window_node_container.cpp @@ -514,9 +514,11 @@ void WindowNodeContainer::DisplayRects::InitRect(Rect& oriDisplayRect) void WindowNodeContainer::DisplayRects::SetSplitRect(float ratio) { if (!isVertical_) { - dividerRect_.posX_ = displayDependRect_.posX_ + static_cast(displayDependRect_.width_ * ratio); + dividerRect_.posX_ = displayDependRect_.posX_ + + static_cast((displayDependRect_.width_ - dividerRect_.width_) * ratio); } else { - dividerRect_.posY_ = displayDependRect_.posY_ + static_cast(displayDependRect_.height_ * ratio); + dividerRect_.posY_ = displayDependRect_.posY_ + + static_cast((displayDependRect_.height_ - dividerRect_.height_) * ratio); } WLOGFI("set dividerRect :[%{public}d, %{public}d, %{public}d, %{public}d]", dividerRect_.posX_, dividerRect_.posY_, dividerRect_.width_, dividerRect_.height_); @@ -528,16 +530,22 @@ void WindowNodeContainer::DisplayRects::SetSplitRect(const Rect& divRect) dividerRect_.width_ = divRect.width_; dividerRect_.height_ = divRect.height_; if (!isVertical_) { + primaryRect_.posX_ = displayRect_.posX_; + primaryRect_.posY_ = displayRect_.posY_; primaryRect_.width_ = divRect.posX_; primaryRect_.height_ = displayRect_.height_; secondaryRect_.posX_ = divRect.posX_ + dividerRect_.width_; + secondaryRect_.posY_ = displayRect_.posY_; secondaryRect_.width_ = displayRect_.width_ - secondaryRect_.posX_; secondaryRect_.height_ = displayRect_.height_; } else { + primaryRect_.posX_ = displayRect_.posX_; + primaryRect_.posY_ = displayRect_.posY_; primaryRect_.height_ = divRect.posY_; primaryRect_.width_ = displayRect_.width_; + secondaryRect_.posX_ = displayRect_.posX_; secondaryRect_.posY_ = divRect.posY_ + dividerRect_.height_; secondaryRect_.height_ = displayRect_.height_ - secondaryRect_.posY_; secondaryRect_.width_ = displayRect_.width_; -- Gitee From 9a770ce422220c405d31b1d4de4642c6ac7c319a Mon Sep 17 00:00:00 2001 From: shiyueeee Date: Tue, 18 Jan 2022 11:04:58 +0800 Subject: [PATCH 26/57] Add dms and snapshot trace Signed-off-by: shiyueeee Change-Id: I5e0d5e505d883ff754a6396a2f6af4567ef0260a --- dmserver/src/display_manager_service.cpp | 9 +++++++-- snapshot/snapshot_utils.cpp | 5 +++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/dmserver/src/display_manager_service.cpp b/dmserver/src/display_manager_service.cpp index e133cf72a8..54a82468fe 100644 --- a/dmserver/src/display_manager_service.cpp +++ b/dmserver/src/display_manager_service.cpp @@ -19,10 +19,11 @@ #include #include #include -#include "display_manager_agent_controller.h" -#include "window_manager_hilog.h" +#include "display_manager_agent_controller.h" #include "transaction/rs_interfaces.h" +#include "window_manager_hilog.h" +#include "wm_trace.h" namespace OHOS::Rosen { namespace { @@ -90,6 +91,7 @@ DisplayInfo DisplayManagerService::GetDisplayInfoById(DisplayId displayId) ScreenId DisplayManagerService::CreateVirtualScreen(VirtualScreenOption option) { + WM_SCOPED_TRACE("dms:CreateVirtualScreen(%s)", option.name_.c_str()); ScreenId screenId = abstractScreenController_->CreateVirtualScreen(option); if (screenId == SCREEN_ID_INVALD) { WLOGFE("DisplayManagerService::CreateVirtualScreen: Get virtualScreenId failed"); @@ -105,6 +107,7 @@ DMError DisplayManagerService::DestroyVirtualScreen(ScreenId screenId) WLOGFE("DisplayManagerService: virtualScreenId is invalid"); return DMError::DM_ERROR_INVALID_PARAM; } + WM_SCOPED_TRACE("dms:DestroyVirtualScreen(%" PRIu64")", screenId); std::map>::iterator iter = displayNodeMap_.find(screenId); if (iter == displayNodeMap_.end()) { WLOGFE("DisplayManagerService: displayNode is nullptr"); @@ -117,6 +120,7 @@ DMError DisplayManagerService::DestroyVirtualScreen(ScreenId screenId) std::shared_ptr DisplayManagerService::GetDispalySnapshot(DisplayId displayId) { + WM_SCOPED_TRACE("dms:GetDispalySnapshot(%" PRIu64")", displayId); std::shared_ptr screenSnapshot = abstractDisplayController_->GetScreenSnapshot(displayId); return screenSnapshot; @@ -208,6 +212,7 @@ DMError DisplayManagerService::AddMirror(ScreenId mainScreenId, ScreenId mirrorS if (mainScreenId == SCREEN_ID_INVALID) { return DMError::DM_ERROR_INVALID_PARAM; } + WM_SCOPED_TRACE("dms:AddMirror"); std::shared_ptr displayNode = SingletonContainer::Get().GetDisplayNode(mainScreenId); if (displayNode == nullptr) { diff --git a/snapshot/snapshot_utils.cpp b/snapshot/snapshot_utils.cpp index 9232357279..90d1d9f12e 100644 --- a/snapshot/snapshot_utils.cpp +++ b/snapshot/snapshot_utils.cpp @@ -18,6 +18,7 @@ #include #include #include +#include "wm_trace.h" using namespace OHOS::Media; using namespace OHOS::Rosen; @@ -36,6 +37,7 @@ void SnapShotUtils::PrintUsage(const std::string &cmdLine) bool SnapShotUtils::CheckFileNameValid(const std::string &fileName) { + WM_SCOPED_TRACE("snapshot:CheckFileNameValid(%s)", fileName.c_str()); if (fileName.length() < strlen(VALID_SNAPSHOT_SUFFIX)) { printf("error: fileName %s invalid, file length too short!\n", fileName.c_str()); return false; @@ -95,6 +97,8 @@ bool SnapShotUtils::WriteToPng(const std::string &fileName, const WriteToPngPara if (!CheckParamValid(param)) { return false; } + + WM_SCOPED_TRACE("snapshot:WriteToPng(%s)", fileName.c_str()); png_structp pngStruct = png_create_write_struct(PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr); if (pngStruct == nullptr) { @@ -153,6 +157,7 @@ bool SnapShotUtils::WriteToPngWithPixelMap(const std::string &fileName, PixelMap static bool ProcessDisplayId(DisplayId &displayId) { + WM_SCOPED_TRACE("snapshot:ProcessDisplayId(%" PRIu64")", displayId); if (displayId == DISPLAY_ID_INVALD) { displayId = DisplayManager::GetInstance().GetDefaultDisplayId(); } else { -- Gitee From c5844a6467464e3b2435b54ee407aab306e3d060 Mon Sep 17 00:00:00 2001 From: Grady Date: Mon, 17 Jan 2022 21:30:59 +0800 Subject: [PATCH 27/57] add screen system testcase Signed-off-by: Grady Change-Id: I1fae58fa89ff8e20c76baf30dd2e3a57a1a0f3f4 --- dm/test/systemtest/BUILD.gn | 15 ++ dm/test/systemtest/display_test_utils.cpp | 92 ++++++++++- dm/test/systemtest/display_test_utils.h | 41 +++++ dm/test/systemtest/screen_manager_test.cpp | 176 +++++++++++++++++++++ dmserver/src/display_manager_service.cpp | 12 +- 5 files changed, 331 insertions(+), 5 deletions(-) create mode 100644 dm/test/systemtest/screen_manager_test.cpp diff --git a/dm/test/systemtest/BUILD.gn b/dm/test/systemtest/BUILD.gn index 65ebd6218f..fa19dfafcf 100644 --- a/dm/test/systemtest/BUILD.gn +++ b/dm/test/systemtest/BUILD.gn @@ -21,6 +21,7 @@ group("systemtest") { deps = [ ":dm_display_minimal_test", ":dm_display_power_test", + ":dm_screen_manager_test", ":dm_screenshot_cmd_test", ":dm_screenshot_test", ] @@ -68,6 +69,17 @@ ohos_systemtest("dm_screenshot_cmd_test") { ## SystemTest dm_screenshot_cmd_test }}} +## SystemTest dm_screen_manager_test {{{ +ohos_systemtest("dm_screen_manager_test") { + module_out_path = module_out_path + + sources = [ "screen_manager_test.cpp" ] + + deps = [ ":dm_systemtest_common" ] +} + +## SystemTest dm_screen_manager_test }}} + ## Build dm_systemtest_common.a {{{ config("dm_systemtest_common_public_config") { include_dirs = [ @@ -75,6 +87,9 @@ config("dm_systemtest_common_public_config") { "//foundation/windowmanager/dmserver/include", "//foundation/windowmanager/interfaces/innerkits/dm", "//foundation/windowmanager/utils/include", + + # RSSurface + "//foundation/graphic/standard/rosen/modules/render_service_client", ] } diff --git a/dm/test/systemtest/display_test_utils.cpp b/dm/test/systemtest/display_test_utils.cpp index fa3b46aa30..9d85305b89 100644 --- a/dm/test/systemtest/display_test_utils.cpp +++ b/dm/test/systemtest/display_test_utils.cpp @@ -21,6 +21,23 @@ namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "DisplayTestUtils"}; } +DisplayTestUtils::~DisplayTestUtils() +{ + if (prevBuffer_ != nullptr) { + SurfaceError ret = csurface_->ReleaseBuffer(prevBuffer_, -1); + if (ret != SURFACE_ERROR_OK) { + WLOGFE("buffer release failed"); + return; + } + WLOGFI("prevBuffer_ release success"); + } + csurface_ = nullptr; + psurface_ = nullptr; + listener_ = nullptr; + prevBuffer_ = nullptr; + bufferHandle_ = nullptr; +} + bool DisplayTestUtils::SizeEqualToDisplay(const sptr& display, const Media::Size cur) { int32_t dWidth = display->GetWidth(); @@ -28,7 +45,7 @@ bool DisplayTestUtils::SizeEqualToDisplay(const sptr& display, const Me bool res = ((cur.width == dWidth) && (cur.height == dHeight)); if (!res) { - WLOGFI("DisplaySize: %d %d, CurrentSize: %d %d\n", dWidth, dHeight, cur.width, cur.height); + WLOGFE("DisplaySize: %d %d, CurrentSize: %d %d", dWidth, dHeight, cur.width, cur.height); } return res; } @@ -37,9 +54,80 @@ bool DisplayTestUtils::SizeEqual(const Media::Size dst, const Media::Size cur) { bool res = ((cur.width == dst.width) && (cur.height == dst.height)); if (!res) { - WLOGFI("Desired Size: %d %d, Current Size: %d %d\n", dst.width, dst.height, cur.width, cur.height); + WLOGFE("Desired Size: %d %d, Current Size: %d %d", dst.width, dst.height, cur.width, cur.height); } return res; } + +bool DisplayTestUtils::CreateSurface() +{ + csurface_ = Surface::CreateSurfaceAsConsumer(); + if (csurface_ == nullptr) { + WLOGFE("csurface create failed"); + return false; + } + + auto producer = csurface_->GetProducer(); + psurface_ = Surface::CreateSurfaceAsProducer(producer); + if (psurface_ == nullptr) { + WLOGFE("csurface create failed"); + return false; + } + + listener_ = new BufferListener(*this); + SurfaceError ret = csurface_->RegisterConsumerListener(listener_); + if (ret != SURFACE_ERROR_OK) { + WLOGFE("listener register failed"); + return false; + } + return true; +} + +void DisplayTestUtils::OnVsync() +{ + std::lock_guard lock(mutex_); + WLOGFI("DisplayTestUtils::OnVsyn"); + sptr cbuffer = nullptr; + int32_t fence = -1; + int64_t timestamp = 0; + OHOS::Rect damage; + if (csurface_ == nullptr) { + WLOGFE("csurface_ is null"); + } + auto sret = csurface_->AcquireBuffer(cbuffer, fence, timestamp, damage); + UniqueFd fenceFd(fence); + if (cbuffer == nullptr || sret != OHOS::SURFACE_ERROR_OK) { + WLOGFE("acquire buffer failed"); + return; + } + bufferHandle_ = cbuffer->GetBufferHandle(); + if (bufferHandle_ == nullptr) { + WLOGFE("get bufferHandle failed"); + return; + } + if (defaultWidth_ == static_cast(bufferHandle_->width) && + defaultHeight_ == static_cast(bufferHandle_->height)) { + successCount_++; + WLOGFI("success count in OnVsync: %d", successCount_); + } else { + failCount_++; + } + if (cbuffer != prevBuffer_) { + if (prevBuffer_ != nullptr) { + SurfaceError ret = csurface_->ReleaseBuffer(prevBuffer_, -1); + if (ret != SURFACE_ERROR_OK) { + WLOGFE("buffer release failed"); + return; + } + } + prevBuffer_ = cbuffer; + } +} + +void DisplayTestUtils::SetDefaultWH(const sptr& display) +{ + defaultWidth_ = display->GetWidth(); + defaultHeight_ = display->GetHeight(); +} } // namespace ROSEN } // namespace OHOS \ No newline at end of file diff --git a/dm/test/systemtest/display_test_utils.h b/dm/test/systemtest/display_test_utils.h index d30204be0e..e78d255ad7 100644 --- a/dm/test/systemtest/display_test_utils.h +++ b/dm/test/systemtest/display_test_utils.h @@ -16,19 +16,60 @@ #ifndef FRAMEWORKS_DM_TEST_ST_DISPLAY_TEST_UTILS_H #define FRAMEWORKS_DM_TEST_ST_DISPLAY_TEST_UTILS_H +#include + #include "display_manager.h" +#include "screen_manager.h" #include "display_property.h" #include "display.h" +#include "screen.h" #include "display_info.h" #include "wm_common.h" +#include "dm_common.h" #include "window_manager_hilog.h" +#include "unique_fd.h" +#include "core/ui/rs_surface_node.h" +#include "core/ui/rs_display_node.h" namespace OHOS { namespace Rosen { class DisplayTestUtils { public: + ~DisplayTestUtils(); static bool SizeEqualToDisplay(const sptr& display, const Media::Size cur); static bool SizeEqual(const Media::Size dst, const Media::Size cur); + void init(); + bool CreateSurface(); + void SetDefaultWH(const sptr& display); + class BufferListener : public IBufferConsumerListener { + public: + explicit BufferListener(DisplayTestUtils &displayTestUtils): utils_(displayTestUtils) + { + } + ~BufferListener() noexcept override = default; + void OnBufferAvailable() override + { + utils_.OnVsync(); + } + + private: + DisplayTestUtils &utils_; + }; + friend class BufferListener; + + void OnVsync(); + uint32_t successCount_ = 0; + uint32_t failCount_ = 0; + uint32_t defaultWidth_ = 0; + uint32_t defaultHeight_ = 0; + sptr listener_ = nullptr; + sptr csurface_ = nullptr; // cosumer surface + sptr psurface_ = nullptr; // producer surface + sptr prevBuffer_ = nullptr; + BufferHandle *bufferHandle_ = nullptr; + +private: + std::mutex mutex_; }; } // namespace ROSEN } // namespace OHOS diff --git a/dm/test/systemtest/screen_manager_test.cpp b/dm/test/systemtest/screen_manager_test.cpp new file mode 100644 index 0000000000..fb163ce869 --- /dev/null +++ b/dm/test/systemtest/screen_manager_test.cpp @@ -0,0 +1,176 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// gtest +#include +#include "display_test_utils.h" +using namespace testing; +using namespace testing::ext; + +namespace OHOS { +namespace Rosen { +class ScreenManagerTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + virtual void SetUp() override; + virtual void TearDown() override; + static sptr defaultDisplay_; + static DisplayId defaultDisplayId_; + static std::string defaultName_; + static uint32_t defaultWidth_; + static uint32_t defaultHeight_; + static float defaultDensity_; + static int32_t defaultFlags_; + static VirtualScreenOption defaultoption_; + static uint32_t waitCount_; + const uint32_t sleepUs_ = 10 * 1000; + const uint32_t maxWaitCount_ = 2000; + const uint32_t execTimes_ = 10; +}; + +sptr ScreenManagerTest::defaultDisplay_ = nullptr; +DisplayId ScreenManagerTest::defaultDisplayId_ = DISPLAY_ID_INVALD; +std::string ScreenManagerTest::defaultName_ = "virtualScreen01"; +uint32_t ScreenManagerTest::defaultWidth_ = 480; +uint32_t ScreenManagerTest::defaultHeight_ = 320; +float ScreenManagerTest::defaultDensity_ = 2.0; +int32_t ScreenManagerTest::defaultFlags_ = 0; +VirtualScreenOption ScreenManagerTest::defaultoption_ = { + defaultName_, defaultWidth_, defaultHeight_, defaultDensity_, nullptr, defaultFlags_ +}; +uint32_t ScreenManagerTest::waitCount_ = 0; + +void ScreenManagerTest::SetUpTestCase() +{ + defaultDisplay_ = DisplayManager::GetInstance().GetDefaultDisplay(); + defaultDisplayId_ = defaultDisplay_->GetId(); + defaultWidth_ = defaultDisplay_->GetWidth(); + defaultHeight_ = defaultDisplay_->GetHeight(); + defaultoption_.width_ = defaultWidth_; + defaultoption_.height_ = defaultHeight_; +} + +void ScreenManagerTest::TearDownTestCase() +{ +} + +void ScreenManagerTest::SetUp() +{ +} + +void ScreenManagerTest::TearDown() +{ +} + +namespace { +/** + * @tc.name: ScreenManager01 + * @tc.desc: Create a virtual screen and destroy it + * @tc.type: FUNC + */ +HWTEST_F(ScreenManagerTest, ScreenManager01, Function | MediumTest | Level1) +{ + DisplayTestUtils utils; + ASSERT_TRUE(utils.CreateSurface()); + defaultoption_.surface_ = utils.psurface_; + ScreenId virtualScreenId = ScreenManager::GetInstance().CreateVirtualScreen(defaultoption_); + ASSERT_NE(SCREEN_ID_INVALD, virtualScreenId); + ASSERT_EQ(DMError::DM_OK, ScreenManager::GetInstance().DestroyVirtualScreen(virtualScreenId)); +} + +/** + * @tc.name: ScreenManager02 + * @tc.desc: Create a virtual screen as mirror of default screen, and destroy virtual screen + * @tc.type: FUNC + */ +HWTEST_F(ScreenManagerTest, ScreenManager02, Function | MediumTest | Level1) +{ + DisplayTestUtils utils; + ASSERT_TRUE(utils.CreateSurface()); + defaultoption_.surface_ = utils.psurface_; + ScreenId virtualScreenId = ScreenManager::GetInstance().CreateVirtualScreen(defaultoption_); + ScreenManager::GetInstance().AddMirror(defaultDisplayId_, virtualScreenId); + ASSERT_NE(SCREEN_ID_INVALD, virtualScreenId); + ASSERT_EQ(DMError::DM_OK, ScreenManager::GetInstance().DestroyVirtualScreen(virtualScreenId)); +} + +/** + * @tc.name: ScreenManager03 + * @tc.desc: Create a virtual screen and destroy it for 10 times + * @tc.type: FUNC + */ +HWTEST_F(ScreenManagerTest, ScreenManager03, Function | MediumTest | Level1) +{ + DisplayTestUtils utils; + ASSERT_TRUE(utils.CreateSurface()); + defaultoption_.surface_ = utils.psurface_; + for (uint32_t i = 0; i < execTimes_; i++) { + ScreenId virtualScreenId = ScreenManager::GetInstance().CreateVirtualScreen(defaultoption_); + ASSERT_NE(SCREEN_ID_INVALD, virtualScreenId); + ASSERT_EQ(DMError::DM_OK, ScreenManager::GetInstance().DestroyVirtualScreen(virtualScreenId)); + } +} + +/** + * @tc.name: ScreenManager04 + * @tc.desc: Create a virtual screen as mirror of default screen, and destroy virtual screen for 10 times + * @tc.type: FUNC + */ +HWTEST_F(ScreenManagerTest, ScreenManager04, Function | MediumTest | Level1) +{ + DisplayTestUtils utils; + ASSERT_TRUE(utils.CreateSurface()); + defaultoption_.surface_ = utils.psurface_; + for (uint32_t i = 0; i < execTimes_; i++) { + ScreenId virtualScreenId = ScreenManager::GetInstance().CreateVirtualScreen(defaultoption_); + ScreenManager::GetInstance().AddMirror(static_cast(defaultDisplayId_), virtualScreenId); + ASSERT_NE(SCREEN_ID_INVALD, virtualScreenId); + ASSERT_EQ(DMError::DM_OK, ScreenManager::GetInstance().DestroyVirtualScreen(virtualScreenId)); + } +} + +/** + * @tc.name: ScreenManager05 + * @tc.desc: Compare the length and width for recording screen + * @tc.type: FUNC + */ +HWTEST_F(ScreenManagerTest, ScreenManager05, Function | MediumTest | Level1) +{ + DisplayTestUtils utils; + utils.SetDefaultWH(defaultDisplay_); + ASSERT_TRUE(utils.CreateSurface()); + defaultoption_.surface_ = utils.psurface_; + ScreenId virtualScreenId = ScreenManager::GetInstance().CreateVirtualScreen(defaultoption_); + + ASSERT_NE(SCREEN_ID_INVALD, virtualScreenId); + uint32_t lastCount = -1u; + ScreenManager::GetInstance().AddMirror(static_cast(defaultDisplayId_), virtualScreenId); + while (utils.successCount_ <= execTimes_ && waitCount_ <= maxWaitCount_) { + if (lastCount != utils.successCount_) { + lastCount = utils.successCount_; + } + ASSERT_EQ(0, utils.failCount_); + waitCount_++; + usleep(sleepUs_); + } + ASSERT_GT(utils.successCount_, 0); + ASSERT_GT(maxWaitCount_, waitCount_); + + ASSERT_EQ(DMError::DM_OK, ScreenManager::GetInstance().DestroyVirtualScreen(virtualScreenId)); +} +} +} // namespace Rosen +} // namespace OHOS diff --git a/dmserver/src/display_manager_service.cpp b/dmserver/src/display_manager_service.cpp index 54a82468fe..f9bcf6ba9d 100644 --- a/dmserver/src/display_manager_service.cpp +++ b/dmserver/src/display_manager_service.cpp @@ -102,7 +102,7 @@ ScreenId DisplayManagerService::CreateVirtualScreen(VirtualScreenOption option) DMError DisplayManagerService::DestroyVirtualScreen(ScreenId screenId) { - WLOGFI("DisplayManagerService::DestroyVirtualScreen"); + WLOGFI("DestroyVirtualScreen::ScreenId: %{public}" PRIu64 "", screenId); if (screenId == SCREEN_ID_INVALID) { WLOGFE("DisplayManagerService: virtualScreenId is invalid"); return DMError::DM_ERROR_INVALID_PARAM; @@ -114,7 +114,12 @@ DMError DisplayManagerService::DestroyVirtualScreen(ScreenId screenId) return abstractScreenController_->DestroyVirtualScreen(screenId); } displayNodeMap_[screenId]->RemoveFromTree(); + WLOGFE("DisplayManagerService: displayNode remove from tree"); displayNodeMap_.erase(screenId); + auto transactionProxy = RSTransactionProxy::GetInstance(); + if (transactionProxy != nullptr) { + transactionProxy->FlushImplicitTransaction(); + } return abstractScreenController_->DestroyVirtualScreen(screenId); } @@ -209,10 +214,11 @@ sptr DisplayManagerService::GetAbstractScreenControlle DMError DisplayManagerService::AddMirror(ScreenId mainScreenId, ScreenId mirrorScreenId) { - if (mainScreenId == SCREEN_ID_INVALID) { + if (mainScreenId == SCREEN_ID_INVALID || mirrorScreenId == SCREEN_ID_INVALID) { return DMError::DM_ERROR_INVALID_PARAM; } WM_SCOPED_TRACE("dms:AddMirror"); + WLOGFI("AddMirror::ScreenId: %{public}" PRIu64 "", mirrorScreenId); std::shared_ptr displayNode = SingletonContainer::Get().GetDisplayNode(mainScreenId); if (displayNode == nullptr) { @@ -222,7 +228,7 @@ DMError DisplayManagerService::AddMirror(ScreenId mainScreenId, ScreenId mirrorS NodeId nodeId = displayNode->GetId(); struct RSDisplayNodeConfig config = {mirrorScreenId, true, nodeId}; - displayNodeMap_[mainScreenId] = RSDisplayNode::Create(config); + displayNodeMap_[mirrorScreenId] = RSDisplayNode::Create(config); auto transactionProxy = RSTransactionProxy::GetInstance(); transactionProxy->FlushImplicitTransaction(); WLOGFI("DisplayManagerService::AddMirror: NodeId: %{public}" PRIu64 "", nodeId >> 32); -- Gitee From 973b24c5fa57c2929edb3f341ae66bc4261af94c Mon Sep 17 00:00:00 2001 From: chenqinxin Date: Wed, 19 Jan 2022 08:26:43 +0800 Subject: [PATCH 28/57] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BA=AE=E7=81=AD?= =?UTF-8?q?=E5=B1=8Fsystemtest=20=E5=BC=82=E6=AD=A5=E5=9B=9E=E8=B0=83?= =?UTF-8?q?=E8=80=97=E6=97=B6=E4=B8=8D=E7=A1=AE=E5=AE=9A=E5=AF=BC=E8=87=B4?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B=E5=A4=B1=E8=B4=A5=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chenqinxin Change-Id: I4bf971a0e5e67fcd351f2e38a667fd173b76cec4 --- dm/test/systemtest/display_power_test.cpp | 70 +++++++++++++++++++---- 1 file changed, 59 insertions(+), 11 deletions(-) diff --git a/dm/test/systemtest/display_power_test.cpp b/dm/test/systemtest/display_power_test.cpp index 6ee344f780..06f64d731a 100644 --- a/dm/test/systemtest/display_power_test.cpp +++ b/dm/test/systemtest/display_power_test.cpp @@ -23,7 +23,8 @@ using namespace testing::ext; namespace OHOS { namespace Rosen { namespace { - constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "ScreenshotCmdTest"}; + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "DisplayPowerTest"}; + constexpr uint32_t MAX_TIME_WAITING_FOR_CALLBACK = 5; } class DisplayPowerEventListener : public IDisplayPowerEventListener { @@ -45,10 +46,17 @@ public: static void TearDownTestCase(); virtual void SetUp() override; virtual void TearDown() override; + + static void CheckDisplayStateCallback(bool valueExpected); + static void CheckDisplayPowerEventCallback(bool valueExpected); + static inline DisplayId defaultId_; + static inline uint32_t brightnessLevel_ = 80; + static inline uint32_t times_ = 0; + static inline bool isDisplayStateCallbackCalled_ = false; static sptr listener_; + DisplayState state_ { DisplayState::ON }; - bool isDisplayStateCallbackCalled_ { false }; DisplayStateCallback callback_ = [this](DisplayState state) { isDisplayStateCallbackCalled_ = true; state_ = state; @@ -73,6 +81,8 @@ void DisplayPowerTest::TearDownTestCase() void DisplayPowerTest::SetUp() { + times_ = 0; + isDisplayStateCallbackCalled_ = false; state_ = DisplayState::UNKNOWN; @@ -85,6 +95,28 @@ void DisplayPowerTest::TearDown() { } +void DisplayPowerTest::CheckDisplayStateCallback(bool valueExpected) +{ + do { + if (isDisplayStateCallbackCalled_ == valueExpected) { + return; + } + sleep(1); + ++times_; + } while (times_ <= MAX_TIME_WAITING_FOR_CALLBACK); +} + +void DisplayPowerTest::CheckDisplayPowerEventCallback(bool valueExpected) +{ + do { + if (listener_->isCallbackCalled_ == valueExpected) { + return; + } + sleep(1); + ++times_; + } while (times_ <= MAX_TIME_WAITING_FOR_CALLBACK); +} + namespace { /** * @tc.name: SetDisplayStateValid @@ -99,6 +131,7 @@ HWTEST_F(DisplayPowerTest, SetDisplayStateValid01, Function | MediumTest | Level ASSERT_EQ(true, ret); DisplayState stateGet = DisplayManager::GetInstance().GetDisplayState(defaultId_); ASSERT_EQ(stateGet, stateToSet); + CheckDisplayStateCallback(true); } /** @@ -113,6 +146,7 @@ HWTEST_F(DisplayPowerTest, SetDisplayStateValid02, Function | MediumTest | Level ASSERT_EQ(false, ret); DisplayState stateGet = DisplayManager::GetInstance().GetDisplayState(defaultId_); ASSERT_EQ(stateGet, initialState); + CheckDisplayStateCallback(false); ASSERT_EQ(false, isDisplayStateCallbackCalled_); } @@ -126,7 +160,7 @@ HWTEST_F(DisplayPowerTest, SetDisplayStateCallbackValid01, Function | MediumTest DisplayState initialState = DisplayManager::GetInstance().GetDisplayState(defaultId_); DisplayState stateToSet = (initialState == DisplayState::OFF ? DisplayState::ON : DisplayState::OFF); DisplayManager::GetInstance().SetDisplayState(stateToSet, callback_); - sleep(1); + CheckDisplayStateCallback(true); ASSERT_EQ(true, isDisplayStateCallbackCalled_); ASSERT_EQ(state_, stateToSet); } @@ -140,6 +174,7 @@ HWTEST_F(DisplayPowerTest, SetDisplayStateCallbackValid02, Function | MediumTest { DisplayState initialState = DisplayManager::GetInstance().GetDisplayState(defaultId_); DisplayManager::GetInstance().SetDisplayState(initialState, callback_); + CheckDisplayStateCallback(false); ASSERT_EQ(false, isDisplayStateCallbackCalled_); } @@ -152,7 +187,7 @@ HWTEST_F(DisplayPowerTest, WakeUpBeginCallbackValid01, Function | MediumTest | L { bool ret = DisplayManager::GetInstance().WakeUpBegin(PowerStateChangeReason::POWER_BUTTON); ASSERT_EQ(true, ret); - sleep(1); + CheckDisplayPowerEventCallback(true); ASSERT_EQ(true, listener_->isCallbackCalled_); ASSERT_EQ(DisplayPowerEvent::WAKE_UP, listener_->event_); ASSERT_EQ(EventStatus::BEGIN, listener_->status_); @@ -167,7 +202,7 @@ HWTEST_F(DisplayPowerTest, WakeUpEndCallbackValid01, Function | MediumTest | Lev { bool ret = DisplayManager::GetInstance().WakeUpEnd(); ASSERT_EQ(true, ret); - sleep(1); + CheckDisplayPowerEventCallback(true); ASSERT_EQ(true, listener_->isCallbackCalled_); ASSERT_EQ(DisplayPowerEvent::WAKE_UP, listener_->event_); ASSERT_EQ(EventStatus::END, listener_->status_); @@ -182,7 +217,7 @@ HWTEST_F(DisplayPowerTest, SuspendBeginCallbackValid01, Function | MediumTest | { bool ret = DisplayManager::GetInstance().SuspendBegin(PowerStateChangeReason::POWER_BUTTON); ASSERT_EQ(true, ret); - sleep(1); + CheckDisplayPowerEventCallback(true); ASSERT_EQ(true, listener_->isCallbackCalled_); ASSERT_EQ(DisplayPowerEvent::SLEEP, listener_->event_); ASSERT_EQ(EventStatus::BEGIN, listener_->status_); @@ -197,7 +232,7 @@ HWTEST_F(DisplayPowerTest, SuspendEndCallbackValid01, Function | MediumTest | Le { bool ret = DisplayManager::GetInstance().SuspendEnd(); ASSERT_EQ(true, ret); - sleep(1); + CheckDisplayPowerEventCallback(true); ASSERT_EQ(true, listener_->isCallbackCalled_); ASSERT_EQ(DisplayPowerEvent::SLEEP, listener_->event_); ASSERT_EQ(EventStatus::END, listener_->status_); @@ -213,7 +248,7 @@ HWTEST_F(DisplayPowerTest, SetScreenPowerForAllCallbackValid01, Function | Mediu bool ret = DisplayManager::GetInstance().SetScreenPowerForAll(DisplayPowerState::POWER_OFF, PowerStateChangeReason::POWER_BUTTON); ASSERT_EQ(true, ret); - sleep(1); + CheckDisplayPowerEventCallback(true); ASSERT_EQ(true, listener_->isCallbackCalled_); ASSERT_EQ(DisplayPowerEvent::DISPLAY_OFF, listener_->event_); ASSERT_EQ(EventStatus::END, listener_->status_); @@ -229,7 +264,7 @@ HWTEST_F(DisplayPowerTest, SetScreenPowerForAllCallbackValid02, Function | Mediu bool ret = DisplayManager::GetInstance().SetScreenPowerForAll(DisplayPowerState::POWER_ON, PowerStateChangeReason::POWER_BUTTON); ASSERT_EQ(true, ret); - sleep(1); + CheckDisplayPowerEventCallback(true); ASSERT_EQ(true, listener_->isCallbackCalled_); ASSERT_EQ(DisplayPowerEvent::DISPLAY_ON, listener_->event_); ASSERT_EQ(EventStatus::END, listener_->status_); @@ -244,7 +279,7 @@ HWTEST_F(DisplayPowerTest, SetDisplayStatePowerCallbackValid01, Function | Mediu { bool ret = DisplayManager::GetInstance().SetDisplayState(DisplayState::OFF, callback_); ASSERT_EQ(true, ret); - sleep(1); + CheckDisplayPowerEventCallback(true); ASSERT_EQ(true, listener_->isCallbackCalled_); ASSERT_EQ(DisplayPowerEvent::DISPLAY_OFF, listener_->event_); ASSERT_EQ(EventStatus::BEGIN, listener_->status_); @@ -259,7 +294,7 @@ HWTEST_F(DisplayPowerTest, SetDisplayStatePowerCallbackValid02, Function | Mediu { bool ret = DisplayManager::GetInstance().SetDisplayState(DisplayState::ON, callback_); ASSERT_EQ(true, ret); - sleep(1); + CheckDisplayPowerEventCallback(true); ASSERT_EQ(true, listener_->isCallbackCalled_); ASSERT_EQ(DisplayPowerEvent::DISPLAY_ON, listener_->event_); ASSERT_EQ(EventStatus::BEGIN, listener_->status_); @@ -292,6 +327,19 @@ HWTEST_F(DisplayPowerTest, SetScreenPowerForAllValid02, Function | MediumTest | DisplayPowerState stateGet = DisplayManager::GetInstance().GetScreenPower(defaultId_); ASSERT_EQ(stateGet, stateToSet); } + +/** +* @tc.name: SetScreenBrightnessValid +* @tc.desc: Call SetScreenBrightness and check the GetScreenBrightness return value +* @tc.type: FUNC +*/ +HWTEST_F(DisplayPowerTest, SetScreenBrightnessValid01, Function | MediumTest | Level2) +{ + bool ret = DisplayManager::GetInstance().SetScreenBrightness(defaultId_, brightnessLevel_); + ASSERT_EQ(true, ret); + uint32_t level = DisplayManager::GetInstance().GetScreenBrightness(defaultId_); + ASSERT_EQ(level, brightnessLevel_); +} } // namespace } // namespace Rosen } // namespace OHOS \ No newline at end of file -- Gitee From c90d8375d0232a59df97bb8861770ad915d77aca Mon Sep 17 00:00:00 2001 From: xingyanan Date: Wed, 19 Jan 2022 09:37:01 +0800 Subject: [PATCH 29/57] add window mode ut Signed-off-by: xingyanan Change-Id: I13c6be0158dad9dd598323d5611d824ed8b961c6 --- wm/test/unittest/window_impl_test.cpp | 92 +++++++++++++++++++++++++ wm/test/unittest/window_option_test.cpp | 65 +++++++++++++++++ wmserver/src/window_node_container.cpp | 2 +- 3 files changed, 158 insertions(+), 1 deletion(-) diff --git a/wm/test/unittest/window_impl_test.cpp b/wm/test/unittest/window_impl_test.cpp index cc4abc3be8..2294cef806 100644 --- a/wm/test/unittest/window_impl_test.cpp +++ b/wm/test/unittest/window_impl_test.cpp @@ -387,6 +387,98 @@ HWTEST_F(WindowImplTest, ShowHideWindow06, Function | SmallTest | Level3) EXPECT_CALL(m->Mock(), RemoveWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK)); ASSERT_EQ(WMError::WM_OK, window_->Hide()); } + +/** + * @tc.name: SetWindowMode02 + * @tc.desc: Set window mode to split primary + * @tc.type: FUNC + * @tc.require: AR000GGTV7 + */ +HWTEST_F(WindowImplTest, SetWindowMode02, Function | SmallTest | Level3) +{ + std::unique_ptr m = std::make_unique(); + sptr option = new WindowOption(); + option->SetWindowName(""); + option->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW); + option->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN); + sptr window = new WindowImpl(option); + EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK)); + ASSERT_EQ(WMError::WM_OK, window->Create("")); + ASSERT_EQ(WindowMode::WINDOW_MODE_FULLSCREEN, window->GetMode()); + ASSERT_EQ(WMError::WM_OK, window->SetWindowMode(WindowMode::WINDOW_MODE_SPLIT_PRIMARY)); + ASSERT_EQ(WindowMode::WINDOW_MODE_SPLIT_PRIMARY, window->GetMode()); + EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK)); + ASSERT_EQ(WMError::WM_OK, window->Destroy()); +} + +/** + * @tc.name: SetWindowMode03 + * @tc.desc: Set window mode to split secondary + * @tc.type: FUNC + * @tc.require: AR000GGTV7 + */ +HWTEST_F(WindowImplTest, SetWindowMode03, Function | SmallTest | Level3) +{ + std::unique_ptr m = std::make_unique(); + sptr option = new WindowOption(); + option->SetWindowName(""); + option->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW); + option->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN); + sptr window = new WindowImpl(option); + EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK)); + ASSERT_EQ(WMError::WM_OK, window->Create("")); + ASSERT_EQ(WindowMode::WINDOW_MODE_FULLSCREEN, window->GetMode()); + ASSERT_EQ(WMError::WM_OK, window->SetWindowMode(WindowMode::WINDOW_MODE_SPLIT_SECONDARY)); + ASSERT_EQ(WindowMode::WINDOW_MODE_SPLIT_SECONDARY, window->GetMode()); + EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK)); + ASSERT_EQ(WMError::WM_OK, window->Destroy()); +} + +/** + * @tc.name: SetWindowMode04 + * @tc.desc: Set window mode to floating + * @tc.type: FUNC + * @tc.require: AR000GGTV7 + */ +HWTEST_F(WindowImplTest, SetWindowMode04, Function | SmallTest | Level3) +{ + std::unique_ptr m = std::make_unique(); + sptr option = new WindowOption(); + option->SetWindowName(""); + option->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW); + option->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN); + sptr window = new WindowImpl(option); + EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK)); + ASSERT_EQ(WMError::WM_OK, window->Create("")); + ASSERT_EQ(WindowMode::WINDOW_MODE_FULLSCREEN, window->GetMode()); + ASSERT_EQ(WMError::WM_OK, window->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING)); + ASSERT_EQ(WindowMode::WINDOW_MODE_FLOATING, window->GetMode()); + EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK)); + ASSERT_EQ(WMError::WM_OK, window->Destroy()); +} + +/** + * @tc.name: SetWindowMode05 + * @tc.desc: Set window mode to pip + * @tc.type: FUNC + * @tc.require: AR000GGTV7 + */ +HWTEST_F(WindowImplTest, SetWindowMode05, Function | SmallTest | Level3) +{ + std::unique_ptr m = std::make_unique(); + sptr option = new WindowOption(); + option->SetWindowName(""); + option->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW); + option->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN); + sptr window = new WindowImpl(option); + EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK)); + ASSERT_EQ(WMError::WM_OK, window->Create("")); + ASSERT_EQ(WindowMode::WINDOW_MODE_FULLSCREEN, window->GetMode()); + ASSERT_EQ(WMError::WM_OK, window->SetWindowMode(WindowMode::WINDOW_MODE_PIP)); + ASSERT_EQ(WindowMode::WINDOW_MODE_PIP, window->GetMode()); + EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK)); + ASSERT_EQ(WMError::WM_OK, window->Destroy()); +} } } // namespace Rosen } // namespace OHOS diff --git a/wm/test/unittest/window_option_test.cpp b/wm/test/unittest/window_option_test.cpp index fcf6156014..3bdfa84b6f 100644 --- a/wm/test/unittest/window_option_test.cpp +++ b/wm/test/unittest/window_option_test.cpp @@ -81,6 +81,71 @@ HWTEST_F(WindowOptionTest, WindowMode01, Function | SmallTest | Level2) ASSERT_EQ(WindowMode::WINDOW_MODE_FULLSCREEN, option->GetWindowMode()); } +/** + * @tc.name: WindowMode02 + * @tc.desc: SetWindowMode/GetWindowMode + * @tc.type: FUNC + * @tc.require: AR000GGTV7 + */ +HWTEST_F(WindowOptionTest, WindowMode02, Function | SmallTest | Level2) +{ + sptr option = new WindowOption(); + WindowMode defaultMode = option->GetWindowMode(); + option->SetWindowMode(WindowMode::WINDOW_MODE_UNDEFINED); + ASSERT_EQ(defaultMode, option->GetWindowMode()); +} + +/** + * @tc.name: WindowMode03 + * @tc.desc: SetWindowMode/GetWindowMode + * @tc.type: FUNC + * @tc.require: AR000GGTV7 + */ +HWTEST_F(WindowOptionTest, WindowMode03, Function | SmallTest | Level2) +{ + sptr option = new WindowOption(); + option->SetWindowMode(WindowMode::WINDOW_MODE_SPLIT_PRIMARY); + ASSERT_EQ(WindowMode::WINDOW_MODE_SPLIT_PRIMARY, option->GetWindowMode()); +} + +/** + * @tc.name: WindowMode04 + * @tc.desc: SetWindowMode/GetWindowMode + * @tc.type: FUNC + * @tc.require: AR000GGTV7 + */ +HWTEST_F(WindowOptionTest, WindowMode04, Function | SmallTest | Level2) +{ + sptr option = new WindowOption(); + option->SetWindowMode(WindowMode::WINDOW_MODE_SPLIT_SECONDARY); + ASSERT_EQ(WindowMode::WINDOW_MODE_SPLIT_SECONDARY, option->GetWindowMode()); +} + +/** + * @tc.name: WindowMode05 + * @tc.desc: SetWindowMode/GetWindowMode + * @tc.type: FUNC + * @tc.require: AR000GGTV7 + */ +HWTEST_F(WindowOptionTest, WindowMode05, Function | SmallTest | Level2) +{ + sptr option = new WindowOption(); + option->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING); + ASSERT_EQ(WindowMode::WINDOW_MODE_FLOATING, option->GetWindowMode()); +} + +/** + * @tc.name: WindowMode06 + * @tc.desc: SetWindowMode/GetWindowMode + * @tc.type: FUNC + * @tc.require: AR000GGTV7 + */ +HWTEST_F(WindowOptionTest, WindowMode06, Function | SmallTest | Level2) +{ + sptr option = new WindowOption(); + option->SetWindowMode(WindowMode::WINDOW_MODE_PIP); + ASSERT_EQ(WindowMode::WINDOW_MODE_PIP, option->GetWindowMode()); +} /** * @tc.name: Focusable01 * @tc.desc: SetFocusable/GetFocusable diff --git a/wmserver/src/window_node_container.cpp b/wmserver/src/window_node_container.cpp index 2df339753c..730b94ab91 100644 --- a/wmserver/src/window_node_container.cpp +++ b/wmserver/src/window_node_container.cpp @@ -650,7 +650,6 @@ sptr WindowNodeContainer::FindSplitPairNode(sptr& trigge WMError WindowNodeContainer::HandleModeChangeToSplit(sptr& triggerNode) { - WM_FUNCTION_TRACE(); WLOGFI("HandleModeChangeToSplit %{public}d", triggerNode->GetWindowId()); auto pairNode = FindSplitPairNode(triggerNode); displayRects_->displayDependRect_ = layoutPolicy_->GetDependDisplayRects(); // get depend display rect for split @@ -700,6 +699,7 @@ WMError WindowNodeContainer::HandleModeChangeFromSplit(sptr& trigger WMError WindowNodeContainer::HandleSplitWindowModeChange(sptr& triggerNode, bool isChangeToSplit) { + WM_FUNCTION_TRACE(); return isChangeToSplit ? HandleModeChangeToSplit(triggerNode) : HandleModeChangeFromSplit(triggerNode); } -- Gitee From e8e29bb93d0be0d4c602806bccd0f1e3262d9eff Mon Sep 17 00:00:00 2001 From: jincanran Date: Tue, 18 Jan 2022 20:52:35 +0800 Subject: [PATCH 30/57] SystemBarProps setting unit test Signed-off-by: jincanran Change-Id: I70577c332c76288d7b3aa317d16a5bde351bf037 --- wm/src/window_manager.cpp | 2 + wm/test/systemtest/window_immersive_test.cpp | 2 + wm/test/unittest/mock_window_adapter.h | 1 + wm/test/unittest/window_impl_test.cpp | 180 +++++++++++++------ wm/test/unittest/window_impl_test.h | 4 + wm/test/unittest/window_option_test.cpp | 54 ++++++ wmserver/src/window_node_container.cpp | 1 + 7 files changed, 192 insertions(+), 52 deletions(-) diff --git a/wm/src/window_manager.cpp b/wm/src/window_manager.cpp index 9221ce70b3..e3a1f05829 100644 --- a/wm/src/window_manager.cpp +++ b/wm/src/window_manager.cpp @@ -116,6 +116,7 @@ void WindowManager::UnregisterFocusChangedListener(const sptrfocusChangedListeners_.empty() && pImpl_->focusChangedListenerAgent_ != nullptr) { SingletonContainer::Get().UnregisterWindowManagerAgent( WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_FOCUS, pImpl_->focusChangedListenerAgent_); + pImpl_->focusChangedListenerAgent_ = nullptr; } } @@ -153,6 +154,7 @@ void WindowManager::UnregisterSystemBarChangedListener(const sptrsystemBarChangedListeners_.empty() && pImpl_->systemBarChangedListenerAgent_ != nullptr) { SingletonContainer::Get().UnregisterWindowManagerAgent( WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_SYSTEM_BAR, pImpl_->systemBarChangedListenerAgent_); + pImpl_->systemBarChangedListenerAgent_ = nullptr; } } diff --git a/wm/test/systemtest/window_immersive_test.cpp b/wm/test/systemtest/window_immersive_test.cpp index d4ed9f190a..4ab076a408 100644 --- a/wm/test/systemtest/window_immersive_test.cpp +++ b/wm/test/systemtest/window_immersive_test.cpp @@ -97,6 +97,8 @@ void WindowImmersiveTest::DumpFailedInfo(const SystemBarProps& expect) bool WindowImmersiveTest::SystemBarPropsEqualsTo(const SystemBarProps& expect) { + const int SLEEP_US = 100000; + usleep(SLEEP_US); auto act = testSystemBarChangedListener_->props_; if (act.size() != expect.size()) { DumpFailedInfo(expect); diff --git a/wm/test/unittest/mock_window_adapter.h b/wm/test/unittest/mock_window_adapter.h index fc5d523c81..117dfea6af 100644 --- a/wm/test/unittest/mock_window_adapter.h +++ b/wm/test/unittest/mock_window_adapter.h @@ -30,6 +30,7 @@ public: MOCK_METHOD0(ClearWindowAdapter, void()); MOCK_METHOD1(DestroyWindow, WMError(uint32_t windowId)); MOCK_METHOD2(SaveAbilityToken, WMError(const sptr& abilityToken, uint32_t windowId)); + MOCK_METHOD3(SetSystemBarProperty, WMError(uint32_t windowId, WindowType type, const SystemBarProperty& property)); }; } } // namespace OHOS diff --git a/wm/test/unittest/window_impl_test.cpp b/wm/test/unittest/window_impl_test.cpp index cc4abc3be8..754f267529 100644 --- a/wm/test/unittest/window_impl_test.cpp +++ b/wm/test/unittest/window_impl_test.cpp @@ -14,15 +14,12 @@ */ #include "window_impl_test.h" -#include "mock_window_adapter.h" -#include "singleton_mocker.h" using namespace testing; using namespace testing::ext; namespace OHOS { namespace Rosen { -using Mocker = SingletonMocker; void WindowImplTest::SetUpTestCase() { option_ = new WindowOption(); @@ -30,15 +27,14 @@ void WindowImplTest::SetUpTestCase() window_ = new WindowImpl(option_); abilityContext_ = std::make_shared(); - std::unique_ptr m = std::make_unique(); - EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK)); + m_ = std::make_unique(); + EXPECT_CALL(m_->Mock(), CreateWindow(_, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK)); window_->Create(""); } void WindowImplTest::TearDownTestCase() { - std::unique_ptr m = std::make_unique(); - EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK)); + EXPECT_CALL(m_->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK)); window_->Destroy(); } @@ -59,16 +55,14 @@ namespace { */ HWTEST_F(WindowImplTest, CreateWindow01, Function | SmallTest | Level2) { - std::unique_ptr m = std::make_unique(); - sptr option = new WindowOption(); option->SetWindowName("CreateWindow01"); sptr window = new WindowImpl(option); - EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK)); + EXPECT_CALL(m_->Mock(), CreateWindow(_, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK)); ASSERT_EQ(WMError::WM_OK, window->Create("")); - EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK)); + EXPECT_CALL(m_->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK)); ASSERT_EQ(WMError::WM_OK, window->Destroy()); } @@ -80,13 +74,11 @@ HWTEST_F(WindowImplTest, CreateWindow01, Function | SmallTest | Level2) */ HWTEST_F(WindowImplTest, CreateWindow02, Function | SmallTest | Level2) { - std::unique_ptr m = std::make_unique(); - sptr option = new WindowOption(); option->SetWindowName("CreateWindow02"); sptr window = new WindowImpl(option); - EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _)).Times(1).WillOnce(Return(WMError::WM_ERROR_SAMGR)); + EXPECT_CALL(m_->Mock(), CreateWindow(_, _, _, _)).Times(1).WillOnce(Return(WMError::WM_ERROR_SAMGR)); ASSERT_EQ(WMError::WM_ERROR_SAMGR, window->Create("")); } @@ -127,16 +119,14 @@ HWTEST_F(WindowImplTest, CreateWindow04, Function | SmallTest | Level2) */ HWTEST_F(WindowImplTest, CreateWindow05, Function | SmallTest | Level2) { - std::unique_ptr m = std::make_unique(); - sptr option = new WindowOption(); option->SetWindowName("CreateWindow05"); sptr window = new WindowImpl(option); - EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK)); + EXPECT_CALL(m_->Mock(), CreateWindow(_, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK)); ASSERT_EQ(WMError::WM_OK, window->Create("WindowImplTest")); - EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK)); + EXPECT_CALL(m_->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK)); ASSERT_EQ(WMError::WM_OK, window->Destroy()); } @@ -148,8 +138,6 @@ HWTEST_F(WindowImplTest, CreateWindow05, Function | SmallTest | Level2) */ HWTEST_F(WindowImplTest, CreateWindow06, Function | SmallTest | Level2) { - std::unique_ptr m = std::make_unique(); - sptr option = new WindowOption(); option->SetWindowName("CreateWindow06"); struct Rect rect = {1, 2, 3u, 4u}; @@ -158,7 +146,7 @@ HWTEST_F(WindowImplTest, CreateWindow06, Function | SmallTest | Level2) option->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN); sptr window = new WindowImpl(option); - EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK)); + EXPECT_CALL(m_->Mock(), CreateWindow(_, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK)); ASSERT_EQ(WMError::WM_OK, window->Create("")); ASSERT_EQ(1, window->GetRect().posX_); @@ -169,7 +157,7 @@ HWTEST_F(WindowImplTest, CreateWindow06, Function | SmallTest | Level2) ASSERT_EQ(WindowMode::WINDOW_MODE_FULLSCREEN, window->GetMode()); ASSERT_EQ("CreateWindow06", window->GetWindowName()); - EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK)); + EXPECT_CALL(m_->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK)); ASSERT_EQ(WMError::WM_OK, window->Destroy()); } @@ -181,14 +169,12 @@ HWTEST_F(WindowImplTest, CreateWindow06, Function | SmallTest | Level2) */ HWTEST_F(WindowImplTest, CreateWindow07, Function | SmallTest | Level2) { - std::unique_ptr m = std::make_unique(); - sptr option = new WindowOption(); option->SetWindowName("CreateWindow07"); sptr window = new WindowImpl(option); - EXPECT_CALL(m->Mock(), SaveAbilityToken(_, _)).Times(1).WillOnce(Return(WMError::WM_OK)); - EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK)); + EXPECT_CALL(m_->Mock(), SaveAbilityToken(_, _)).Times(1).WillOnce(Return(WMError::WM_OK)); + EXPECT_CALL(m_->Mock(), CreateWindow(_, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK)); ASSERT_EQ(WMError::WM_OK, window->Create("", abilityContext_)); } @@ -200,14 +186,12 @@ HWTEST_F(WindowImplTest, CreateWindow07, Function | SmallTest | Level2) */ HWTEST_F(WindowImplTest, CreateWindow08, Function | SmallTest | Level2) { - std::unique_ptr m = std::make_unique(); - sptr option = new WindowOption(); option->SetWindowName("CreateWindow08"); sptr window = new WindowImpl(option); - EXPECT_CALL(m->Mock(), SaveAbilityToken(_, _)).Times(1).WillOnce(Return(WMError::WM_ERROR_NULLPTR)); - EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK)); + EXPECT_CALL(m_->Mock(), SaveAbilityToken(_, _)).Times(1).WillOnce(Return(WMError::WM_ERROR_NULLPTR)); + EXPECT_CALL(m_->Mock(), CreateWindow(_, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK)); ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window->Create("", abilityContext_)); } @@ -230,20 +214,18 @@ HWTEST_F(WindowImplTest, FindWindow01, Function | SmallTest | Level2) */ HWTEST_F(WindowImplTest, FindWindow02, Function | SmallTest | Level2) { - std::unique_ptr m = std::make_unique(); - sptr option = new WindowOption(); option->SetWindowName("FindWindow02"); sptr window = new WindowImpl(option); - EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK)); + EXPECT_CALL(m_->Mock(), CreateWindow(_, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK)); ASSERT_EQ(WMError::WM_OK, window->Create("")); ASSERT_NE(nullptr, WindowImpl::Find("WindowImplTest")); ASSERT_NE(nullptr, WindowImpl::Find("FindWindow02")); - EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK)); + EXPECT_CALL(m_->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK)); ASSERT_EQ(WMError::WM_OK, window->Destroy()); } @@ -310,11 +292,9 @@ HWTEST_F(WindowImplTest, SetWindowMode01, Function | SmallTest | Level2) */ HWTEST_F(WindowImplTest, ShowHideWindow01, Function | SmallTest | Level2) { - std::unique_ptr m = std::make_unique(); - - EXPECT_CALL(m->Mock(), AddWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK)); + EXPECT_CALL(m_->Mock(), AddWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK)); ASSERT_EQ(WMError::WM_OK, window_->Show()); - EXPECT_CALL(m->Mock(), RemoveWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK)); + EXPECT_CALL(m_->Mock(), RemoveWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK)); ASSERT_EQ(WMError::WM_OK, window_->Hide()); } @@ -326,9 +306,7 @@ HWTEST_F(WindowImplTest, ShowHideWindow01, Function | SmallTest | Level2) */ HWTEST_F(WindowImplTest, ShowHideWindow02, Function | SmallTest | Level2) { - std::unique_ptr m = std::make_unique(); - - EXPECT_CALL(m->Mock(), AddWindow(_)).Times(1).WillOnce(Return(WMError::WM_ERROR_SAMGR)); + EXPECT_CALL(m_->Mock(), AddWindow(_)).Times(1).WillOnce(Return(WMError::WM_ERROR_SAMGR)); ASSERT_EQ(WMError::WM_ERROR_SAMGR, window_->Show()); } @@ -340,9 +318,7 @@ HWTEST_F(WindowImplTest, ShowHideWindow02, Function | SmallTest | Level2) */ HWTEST_F(WindowImplTest, ShowHideWindow03, Function | SmallTest | Level3) { - std::unique_ptr m = std::make_unique(); - - EXPECT_CALL(m->Mock(), AddWindow(_)).Times(1).WillOnce(Return(WMError::WM_ERROR_IPC_FAILED)); + EXPECT_CALL(m_->Mock(), AddWindow(_)).Times(1).WillOnce(Return(WMError::WM_ERROR_IPC_FAILED)); ASSERT_EQ(WMError::WM_ERROR_IPC_FAILED, window_->Show()); } @@ -354,11 +330,9 @@ HWTEST_F(WindowImplTest, ShowHideWindow03, Function | SmallTest | Level3) */ HWTEST_F(WindowImplTest, ShowHideWindow04, Function | SmallTest | Level3) { - std::unique_ptr m = std::make_unique(); - - EXPECT_CALL(m->Mock(), AddWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK)); + EXPECT_CALL(m_->Mock(), AddWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK)); ASSERT_EQ(WMError::WM_OK, window_->Show()); - EXPECT_CALL(m->Mock(), RemoveWindow(_)).Times(1).WillOnce(Return(WMError::WM_ERROR_SAMGR)); + EXPECT_CALL(m_->Mock(), RemoveWindow(_)).Times(1).WillOnce(Return(WMError::WM_ERROR_SAMGR)); ASSERT_EQ(WMError::WM_ERROR_SAMGR, window_->Hide()); } @@ -370,8 +344,7 @@ HWTEST_F(WindowImplTest, ShowHideWindow04, Function | SmallTest | Level3) */ HWTEST_F(WindowImplTest, ShowHideWindow05, Function | SmallTest | Level3) { - std::unique_ptr m = std::make_unique(); - EXPECT_CALL(m->Mock(), RemoveWindow(_)).Times(1).WillOnce(Return(WMError::WM_ERROR_IPC_FAILED)); + EXPECT_CALL(m_->Mock(), RemoveWindow(_)).Times(1).WillOnce(Return(WMError::WM_ERROR_IPC_FAILED)); ASSERT_EQ(WMError::WM_ERROR_IPC_FAILED, window_->Hide()); } @@ -383,10 +356,113 @@ HWTEST_F(WindowImplTest, ShowHideWindow05, Function | SmallTest | Level3) */ HWTEST_F(WindowImplTest, ShowHideWindow06, Function | SmallTest | Level3) { - std::unique_ptr m = std::make_unique(); - EXPECT_CALL(m->Mock(), RemoveWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK)); + EXPECT_CALL(m_->Mock(), RemoveWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK)); ASSERT_EQ(WMError::WM_OK, window_->Hide()); } + +/** + * @tc.name: SetSystemBarProperty01 + * @tc.desc: SetSystemBarProperty with default param + * @tc.type: FUNC + * @tc.require: AR000GGTVD + */ +HWTEST_F(WindowImplTest, SetSystemBarProperty01, Function | SmallTest | Level3) +{ + WindowType type = WindowType::WINDOW_TYPE_STATUS_BAR; + SystemBarProperty prop; + ASSERT_EQ(WMError::WM_OK, window_->SetSystemBarProperty(type, prop)); +} + +/** + * @tc.name: SetSystemBarProperty02 + * @tc.desc: SetSystemBarProperty with adapter return WM_ERROR_SAMGR + * @tc.type: FUNC + * @tc.require: AR000GGTVD + */ +HWTEST_F(WindowImplTest, SetSystemBarProperty02, Function | SmallTest | Level3) +{ + EXPECT_CALL(m_->Mock(), AddWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK)); + window_->Show(); + EXPECT_CALL(m_->Mock(), SetSystemBarProperty(_, _, _)).Times(1).WillOnce(Return(WMError::WM_ERROR_SAMGR)); + WindowType type = WindowType::WINDOW_TYPE_STATUS_BAR; + const SystemBarProperty SYS_BAR_PROP(false, 0xE5222222, 0xE5333333); + ASSERT_EQ(WMError::WM_ERROR_SAMGR, window_->SetSystemBarProperty(type, SYS_BAR_PROP)); + EXPECT_CALL(m_->Mock(), RemoveWindow(_)).Times(1).WillOnce(Return(WMError::WM_ERROR_IPC_FAILED)); + window_->Hide(); +} + +/** + * @tc.name: SetSystemBarProperty03 + * @tc.desc: SetSystemBarProperty to invalid window + * @tc.type: FUNC + * @tc.require: AR000GGTVD + */ +HWTEST_F(WindowImplTest, SetSystemBarProperty03, Function | SmallTest | Level3) +{ + sptr option = new WindowOption(); + option->SetWindowName("SetSystemBarPropertyWin03"); + sptr window = new WindowImpl(option); + WindowType type = WindowType::WINDOW_TYPE_STATUS_BAR; + SystemBarProperty prop; + ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->SetSystemBarProperty(type, prop)); +} + +/** + * @tc.name: GetSystemBarPropertyByType01 + * @tc.desc: GetSystemBarPropertyByType with exist key + * @tc.type: FUNC + * @tc.require: AR000GGTVD + */ +HWTEST_F(WindowImplTest, GetSystemBarPropertyByType01, Function | SmallTest | Level3) +{ + EXPECT_CALL(m_->Mock(), AddWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK)); + window_->Show(); + EXPECT_CALL(m_->Mock(), SetSystemBarProperty(_, _, _)).Times(1).WillOnce(Return(WMError::WM_OK)); + WindowType type = WindowType::WINDOW_TYPE_STATUS_BAR; + const SystemBarProperty SYS_BAR_PROP(false, 0xE5222222, 0xE5333333); + ASSERT_EQ(WMError::WM_OK, window_->SetSystemBarProperty(type, SYS_BAR_PROP)); + ASSERT_EQ(SYS_BAR_PROP, window_->GetSystemBarPropertyByType(type)); + EXPECT_CALL(m_->Mock(), RemoveWindow(_)).Times(1).WillOnce(Return(WMError::WM_ERROR_IPC_FAILED)); + window_->Hide(); +} + +/** + * @tc.name: GetSystemBarPropertyByType02 + * @tc.desc: GetSystemBarPropertyByType with nonexist key + * @tc.type: FUNC + * @tc.require: AR000GGTVD + */ +HWTEST_F(WindowImplTest, GetSystemBarPropertyByType02, Function | SmallTest | Level3) +{ + EXPECT_CALL(m_->Mock(), AddWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK)); + window_->Show(); + EXPECT_CALL(m_->Mock(), SetSystemBarProperty(_, _, _)).Times(1).WillOnce(Return(WMError::WM_OK)); + const SystemBarProperty SYS_BAR_PROP(false, 0xE5222222, 0xE5333333); + const SystemBarProperty DEFAULT_PROP; + ASSERT_EQ(WMError::WM_OK, window_->SetSystemBarProperty(WindowType::WINDOW_TYPE_STATUS_BAR, SYS_BAR_PROP)); + ASSERT_EQ(DEFAULT_PROP, window_->GetSystemBarPropertyByType(WindowType::WINDOW_TYPE_NAVIGATION_BAR)); + EXPECT_CALL(m_->Mock(), RemoveWindow(_)).Times(1).WillOnce(Return(WMError::WM_ERROR_IPC_FAILED)); + window_->Hide(); +} + +/** + * @tc.name: GetSystemBarPropertyByType03 + * @tc.desc: GetSystemBarPropertyByType with not systemBar type + * @tc.type: FUNC + * @tc.require: AR000GGTVD + */ +HWTEST_F(WindowImplTest, GetSystemBarPropertyByType03, Function | SmallTest | Level3) +{ + EXPECT_CALL(m_->Mock(), AddWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK)); + window_->Show(); + EXPECT_CALL(m_->Mock(), SetSystemBarProperty(_, _, _)).Times(1).WillOnce(Return(WMError::WM_OK)); + const SystemBarProperty SYS_BAR_PROP(false, 0xE5222222, 0xE5333333); + const SystemBarProperty DEFAULT_PROP; + ASSERT_EQ(WMError::WM_OK, window_->SetSystemBarProperty(WindowType::WINDOW_TYPE_STATUS_BAR, SYS_BAR_PROP)); + ASSERT_EQ(DEFAULT_PROP, window_->GetSystemBarPropertyByType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW)); + EXPECT_CALL(m_->Mock(), RemoveWindow(_)).Times(1).WillOnce(Return(WMError::WM_ERROR_IPC_FAILED)); + window_->Hide(); +} } } // namespace Rosen } // namespace OHOS diff --git a/wm/test/unittest/window_impl_test.h b/wm/test/unittest/window_impl_test.h index a22bd18b27..1b8af0f0c6 100644 --- a/wm/test/unittest/window_impl_test.h +++ b/wm/test/unittest/window_impl_test.h @@ -18,10 +18,13 @@ #include #include "ability_context_impl.h" +#include "mock_window_adapter.h" +#include "singleton_mocker.h" #include "window_impl.h" namespace OHOS { namespace Rosen { +using Mocker = SingletonMocker; class WindowImplTest : public testing::Test { public: static void SetUpTestCase(); @@ -32,6 +35,7 @@ public: static inline sptr window_ = nullptr; static inline sptr option_ = nullptr; static inline std::shared_ptr abilityContext_; + static inline std::unique_ptr m_; }; } // namespace ROSEN } // namespace OHOS diff --git a/wm/test/unittest/window_option_test.cpp b/wm/test/unittest/window_option_test.cpp index fcf6156014..a7d8199a98 100644 --- a/wm/test/unittest/window_option_test.cpp +++ b/wm/test/unittest/window_option_test.cpp @@ -20,6 +20,20 @@ using namespace testing::ext; namespace OHOS { namespace Rosen { +namespace { + const SystemBarProperty SYS_BAR_PROP_DEFAULT; + const SystemBarProperty SYS_BAR_PROP_1(true, 0xE5111111, 0xE5222222); + const SystemBarProperty SYS_BAR_PROP_2(false, 0xE5222222, 0xE5333333); + const std::unordered_map& SYS_BAR_PROPS_TEST = { + { WindowType::WINDOW_TYPE_STATUS_BAR, SYS_BAR_PROP_1 }, + { WindowType::WINDOW_TYPE_NAVIGATION_BAR, SYS_BAR_PROP_2 }, + }; + const std::unordered_map& SYS_BAR_PROPS_DEFAULT = { + { WindowType::WINDOW_TYPE_STATUS_BAR, SYS_BAR_PROP_DEFAULT }, + { WindowType::WINDOW_TYPE_NAVIGATION_BAR, SYS_BAR_PROP_DEFAULT }, + }; +} + void WindowOptionTest::SetUpTestCase() { } @@ -186,6 +200,46 @@ HWTEST_F(WindowOptionTest, WindowFlag03, Function | SmallTest | Level2) option->RemoveWindowFlag(WindowFlag::WINDOW_FLAG_NEED_AVOID); ASSERT_EQ(static_cast(WindowFlag::WINDOW_FLAG_PARENT_LIMIT), option->GetWindowFlags()); } + +/** + * @tc.name: SetGetSystemBarProperty01 + * @tc.desc: SetSystemBarProperty with test param and get + * @tc.type: FUNC + * @tc.require: AR000GGTVD + */ +HWTEST_F(WindowOptionTest, SetGetSystemBarProperty01, Function | SmallTest | Level3) +{ + sptr option = new WindowOption(); + option->SetSystemBarProperty(WindowType::WINDOW_TYPE_STATUS_BAR, SYS_BAR_PROP_1); + option->SetSystemBarProperty(WindowType::WINDOW_TYPE_NAVIGATION_BAR, SYS_BAR_PROP_2); + ASSERT_EQ(SYS_BAR_PROPS_TEST, option->GetSystemBarProperty()); +} + +/** + * @tc.name: SetGetSystemBarProperty02 + * @tc.desc: SetSystemBarProperty with invalid type and get + * @tc.type: FUNC + * @tc.require: AR000GGTVD + */ +HWTEST_F(WindowOptionTest, SetGetSystemBarProperty02, Function | SmallTest | Level3) +{ + sptr option = new WindowOption(); + option->SetSystemBarProperty(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, SYS_BAR_PROP_1); + option->SetSystemBarProperty(WindowType::WINDOW_TYPE_MEDIA, SYS_BAR_PROP_2); + ASSERT_EQ(SYS_BAR_PROPS_DEFAULT, option->GetSystemBarProperty()); +} + +/** + * @tc.name: SetGetSystemBarProperty03 + * @tc.desc: GetSystemBarProperty with no set + * @tc.type: FUNC + * @tc.require: AR000GGTVD + */ +HWTEST_F(WindowOptionTest, SetGetSystemBarProperty03, Function | SmallTest | Level3) +{ + sptr option = new WindowOption(); + ASSERT_EQ(SYS_BAR_PROPS_DEFAULT, option->GetSystemBarProperty()); +} } } // namespace Rosen } // namespace OHOS diff --git a/wmserver/src/window_node_container.cpp b/wmserver/src/window_node_container.cpp index 2df339753c..c916c8da9e 100644 --- a/wmserver/src/window_node_container.cpp +++ b/wmserver/src/window_node_container.cpp @@ -407,6 +407,7 @@ sptr WindowNodeContainer::GetTopImmersiveNode() const void WindowNodeContainer::NotifySystemBarIfChanged() { DumpScreenWindowTree(); + WM_FUNCTION_TRACE(); auto node = GetTopImmersiveNode(); SystemBarProps props; if (node == nullptr) { // use default system bar -- Gitee From 87963886bfd93fdf8d643fcc522ff62122db07e1 Mon Sep 17 00:00:00 2001 From: Grady Date: Wed, 19 Jan 2022 10:47:18 +0800 Subject: [PATCH 31/57] modify testcase param Signed-off-by: Grady Change-Id: I0881ff7f3e8f881c3e1ce5bbb0f77f95b6804dd5 --- dm/test/systemtest/display_test_utils.cpp | 2 +- dm/test/systemtest/screen_manager_test.cpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/dm/test/systemtest/display_test_utils.cpp b/dm/test/systemtest/display_test_utils.cpp index 9d85305b89..da8dd8ca04 100644 --- a/dm/test/systemtest/display_test_utils.cpp +++ b/dm/test/systemtest/display_test_utils.cpp @@ -108,7 +108,7 @@ void DisplayTestUtils::OnVsync() if (defaultWidth_ == static_cast(bufferHandle_->width) && defaultHeight_ == static_cast(bufferHandle_->height)) { successCount_++; - WLOGFI("success count in OnVsync: %d", successCount_); + WLOGFI("compareWH is successful in onVsync: %d", successCount_); } else { failCount_++; } diff --git a/dm/test/systemtest/screen_manager_test.cpp b/dm/test/systemtest/screen_manager_test.cpp index fb163ce869..76068e0d79 100644 --- a/dm/test/systemtest/screen_manager_test.cpp +++ b/dm/test/systemtest/screen_manager_test.cpp @@ -39,6 +39,7 @@ public: const uint32_t sleepUs_ = 10 * 1000; const uint32_t maxWaitCount_ = 2000; const uint32_t execTimes_ = 10; + const uint32_t acquireFrames_ = 1; }; sptr ScreenManagerTest::defaultDisplay_ = nullptr; @@ -158,7 +159,7 @@ HWTEST_F(ScreenManagerTest, ScreenManager05, Function | MediumTest | Level1) ASSERT_NE(SCREEN_ID_INVALD, virtualScreenId); uint32_t lastCount = -1u; ScreenManager::GetInstance().AddMirror(static_cast(defaultDisplayId_), virtualScreenId); - while (utils.successCount_ <= execTimes_ && waitCount_ <= maxWaitCount_) { + while (utils.successCount_ < acquireFrames_ && waitCount_ <= maxWaitCount_) { if (lastCount != utils.successCount_) { lastCount = utils.successCount_; } @@ -166,10 +167,9 @@ HWTEST_F(ScreenManagerTest, ScreenManager05, Function | MediumTest | Level1) waitCount_++; usleep(sleepUs_); } + ASSERT_EQ(DMError::DM_OK, ScreenManager::GetInstance().DestroyVirtualScreen(virtualScreenId)); ASSERT_GT(utils.successCount_, 0); ASSERT_GT(maxWaitCount_, waitCount_); - - ASSERT_EQ(DMError::DM_OK, ScreenManager::GetInstance().DestroyVirtualScreen(virtualScreenId)); } } } // namespace Rosen -- Gitee From 8028bff21a3e557b9a0373e00e955555b40d81b1 Mon Sep 17 00:00:00 2001 From: lu Date: Tue, 18 Jan 2022 21:08:13 +0800 Subject: [PATCH 32/57] Map display to the first screen Signed-off-by: lu Change-Id: I8fd55ff98a580e8ffdb83a8f8fdd641cd58b9f52 --- dmserver/include/abstract_display.h | 23 ++++++-- .../include/abstract_display_controller.h | 6 +- dmserver/include/abstract_screen.h | 10 +++- dmserver/include/abstract_screen_controller.h | 3 +- dmserver/include/display_manager_service.h | 1 - dmserver/src/abstract_display.cpp | 57 +++++++++++++++++++ dmserver/src/abstract_display_controller.cpp | 45 +++++++++++++-- dmserver/src/abstract_screen.cpp | 43 +++++++++++++- dmserver/src/abstract_screen_controller.cpp | 31 ++++++---- 9 files changed, 189 insertions(+), 30 deletions(-) diff --git a/dmserver/include/abstract_display.h b/dmserver/include/abstract_display.h index ef288bfa72..b6959f4a6a 100644 --- a/dmserver/include/abstract_display.h +++ b/dmserver/include/abstract_display.h @@ -17,29 +17,44 @@ #define FOUNDATION_DMSERVER_ABSTRACT_DISPLAY_H #include + +#include "abstract_screen.h" #include "display_info.h" namespace OHOS::Rosen { +using DisplayId = uint64_t; + class AbstractDisplay : public RefBase { public: + constexpr static int32_t DEFAULT_WIDTH = 720; + constexpr static int32_t DEFAULT_HIGHT = 1280; + constexpr static float DEFAULT_VIRTUAL_PIXEL_RATIO = 1.0; + constexpr static uint32_t DEFAULT_FRESH_RATE = 60; AbstractDisplay(const DisplayInfo& info); + AbstractDisplay(DisplayId id, ScreenId screenId, int32_t width, int32_t height, uint32_t freshRate); ~AbstractDisplay() = default; DisplayId GetId() const; int32_t GetWidth() const; int32_t GetHeight() const; uint32_t GetFreshRate() const; + float GetVirtualPixelRatio() const; + ScreenId GetAbstractScreenId() const; + bool BindAbstractScreenId(ScreenId dmsScreenId); void SetId(DisplayId displayId); void SetWidth(int32_t width); void SetHeight(int32_t height); void SetFreshRate(uint32_t freshRate); + void SetVirtualPixelRatio(float virtualPixelRatio); private: - DisplayId id_ {DISPLAY_ID_INVALD}; - int32_t width_ {0}; - int32_t height_ {0}; - uint32_t freshRate_ {0}; + DisplayId id_ { DISPLAY_ID_INVALD }; + ScreenId screenId_ { SCREEN_ID_INVALID }; + int32_t width_ { 0 }; + int32_t height_ { 0 }; + uint32_t freshRate_ { 0 }; + float virtualPixelRatio_ { 1.0 }; }; } // namespace OHOS::Rosen #endif // FOUNDATION_DMSERVER_ABSTRACT_DISPLAY_H \ No newline at end of file diff --git a/dmserver/include/abstract_display_controller.h b/dmserver/include/abstract_display_controller.h index 5f1b113629..91f0b64204 100644 --- a/dmserver/include/abstract_display_controller.h +++ b/dmserver/include/abstract_display_controller.h @@ -43,10 +43,12 @@ private: void OnAbstractScreenConnected(sptr absScreen); void OnAbstractScreenDisconnected(sptr absScreen); void OnAbstractScreenChanged(sptr absScreen); - void CreateAndBindDisplayLocked(sptr absScreen); + void BindAloneScreenLocked(sptr absScreen); + void AddScreenToMirrorLocked(sptr group, sptr realAbsScreen); std::recursive_mutex& mutex_; - volatile DisplayId displayCount_; + std::atomic displayCount_ { 0 }; + sptr dummyDisplay_; std::map> abstractDisplayMap_; sptr abstractScreenController_; sptr abstractScreenCallback_; diff --git a/dmserver/include/abstract_screen.h b/dmserver/include/abstract_screen.h index 517ccbb947..8137727f61 100644 --- a/dmserver/include/abstract_screen.h +++ b/dmserver/include/abstract_screen.h @@ -20,6 +20,7 @@ #include #include #include +#include #include "screen.h" @@ -50,14 +51,16 @@ public: AbstractScreen(ScreenId dmsId, ScreenId rsId); AbstractScreen() = delete; ~AbstractScreen(); - + sptr GetActiveScreenInfo() const; sptr GetGroup() const; ScreenId dmsId_; ScreenId rsId_; + std::shared_ptr rsDisplayNode_; ScreenId groupDmsId_; ScreenType type_ { ScreenType::REAL }; int32_t activeIdx_; + float virtualPixelRatio = { 1.0 }; std::vector> infos_ = {}; }; @@ -67,14 +70,15 @@ public: AbstractScreenGroup() = delete; ~AbstractScreenGroup(); - void AddChild(ScreenCombination combination, sptr& dmsScreen, Point& startPoint); - void AddChild(ScreenCombination combination, + bool AddChild(ScreenCombination combination, sptr& dmsScreen, Point& startPoint); + bool AddChild(ScreenCombination combination, std::vector>& dmsScreens, std::vector& startPoints); std::vector> GetChildren() const; std::vector GetChildrenPosition() const; ScreenCombination combination_ { ScreenCombination::SCREEN_ALONE }; + std::vector> children_; }; } // namespace OHOS::Rosen #endif // FOUNDATION_DMSERVER_ABSTRACT_SCREEN_H \ No newline at end of file diff --git a/dmserver/include/abstract_screen_controller.h b/dmserver/include/abstract_screen_controller.h index 13996ebffa..b4d7b5388a 100644 --- a/dmserver/include/abstract_screen_controller.h +++ b/dmserver/include/abstract_screen_controller.h @@ -44,6 +44,7 @@ public: std::vector GetAllScreenIds(); sptr GetAbstractScreen(ScreenId dmsScreenId); sptr GetAbstractScreenGroup(ScreenId dmsScreenId); + ScreenId GetMainAbstractScreenId(); ScreenId ConvertToRsScreenId(ScreenId dmsScreenId); ScreenId ConvertToDmsScreenId(ScreenId rsScreenId); void RegisterAbstractScreenCallback(sptr cb); @@ -67,7 +68,7 @@ private: std::map dms2RsScreenIdMap_; std::map> dmsScreenMap_; std::map> dmsScreenGroupMap_; - ScreenId defaultDmsScreenId_ { SCREEN_ID_INVALID }; + ScreenId primaryDmsScreenId_ { SCREEN_ID_INVALID }; sptr abstractScreenCallback_; }; } // namespace OHOS::Rosen diff --git a/dmserver/include/display_manager_service.h b/dmserver/include/display_manager_service.h index 898c3cab4d..7439be5595 100644 --- a/dmserver/include/display_manager_service.h +++ b/dmserver/include/display_manager_service.h @@ -72,7 +72,6 @@ private: std::recursive_mutex mutex_; static inline SingletonDelegator delegator_; - std::map> abstractDisplayMap_; sptr abstractScreenController_; sptr abstractDisplayController_; DisplayPowerController displayPowerController_; diff --git a/dmserver/src/abstract_display.cpp b/dmserver/src/abstract_display.cpp index 32d748df43..c900f648a7 100644 --- a/dmserver/src/abstract_display.cpp +++ b/dmserver/src/abstract_display.cpp @@ -15,7 +15,15 @@ #include "abstract_display.h" +#include "abstract_screen_controller.h" +#include "display_manager_service.h" +#include "window_manager_hilog.h" + namespace OHOS::Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "AbstractDisplay"}; +} + AbstractDisplay::AbstractDisplay(const DisplayInfo& info) : id_(info.id_), width_(info.width_), @@ -24,6 +32,15 @@ AbstractDisplay::AbstractDisplay(const DisplayInfo& info) { } +AbstractDisplay::AbstractDisplay(DisplayId id, ScreenId screenId, int32_t width, int32_t height, uint32_t freshRate) + : id_(id), + screenId_(screenId), + width_(width), + height_(height), + freshRate_(freshRate) +{ +} + DisplayId AbstractDisplay::GetId() const { return id_; @@ -44,6 +61,11 @@ uint32_t AbstractDisplay::GetFreshRate() const return freshRate_; } +float AbstractDisplay::GetVirtualPixelRatio() const +{ + return virtualPixelRatio_; +} + void AbstractDisplay::SetWidth(int32_t width) { width_ = width; @@ -59,8 +81,43 @@ void AbstractDisplay::SetFreshRate(uint32_t freshRate) freshRate_ = freshRate; } +void AbstractDisplay::SetVirtualPixelRatio(float virtualPixelRatio) +{ + virtualPixelRatio_ = virtualPixelRatio; +} + void AbstractDisplay::SetId(DisplayId id) { id_ = id; } + +bool AbstractDisplay::BindAbstractScreenId(ScreenId dmsScreenId) +{ + sptr screenController + = DisplayManagerService::GetInstance().GetAbstractScreenController(); + sptr screen = screenController->GetAbstractScreen(dmsScreenId); + if (screen == nullptr) { + WLOGE("display bind screen error, cannot get screen. display:%{public}" PRIu64", screen:%{public}" PRIu64"", + id_, dmsScreenId); + return false; + } + // TODO: screen->rsDisplayNode_->SetScreenId(rsScreenId); + sptr info = screen->GetActiveScreenInfo(); + if (info == nullptr) { + WLOGE("display bind screen error, cannot get info. display:%{public}" PRIu64", screen:%{public}" PRIu64"", + id_, dmsScreenId); + return false; + } + width_ = info->width_; + height_ = info->height_; + freshRate_ = info->freshRate_; + screenId_ = dmsScreenId; + WLOGD("display bound to screen. display:%{public}" PRIu64", screen:%{public}" PRIu64"", id_, dmsScreenId); + return true; +} + +ScreenId AbstractDisplay::GetAbstractScreenId() const +{ + return screenId_; +} } // namespace OHOS::Rosen \ No newline at end of file diff --git a/dmserver/src/abstract_display_controller.cpp b/dmserver/src/abstract_display_controller.cpp index cc4e790897..1a5422fb7d 100644 --- a/dmserver/src/abstract_display_controller.cpp +++ b/dmserver/src/abstract_display_controller.cpp @@ -51,6 +51,15 @@ void AbstractDisplayController::Init(sptr abstractScre abstractScreenCallback_->onChanged_ = std::bind(&AbstractDisplayController::OnAbstractScreenChanged, this, std::placeholders::_1); abstractScreenController->RegisterAbstractScreenCallback(abstractScreenCallback_); + + // TODO: Active the code after "rsDisplayNode_->SetScreenId(rsScreenId)" is provided. + /*std::lock_guard lock(mutex_); + if (dummyDisplay_ == nullptr) { + sptr display = new AbstractDisplay(displayCount_.fetch_add(1), SCREEN_ID_INVALID, + AbstractDisplay::DEFAULT_WIDTH, AbstractDisplay::DEFAULT_HIGHT, AbstractDisplay::DEFAULT_FRESH_RATE); + abstractDisplayMap_.insert((std::make_pair(display->GetId(), display))); + dummyDisplay_ = display; + }*/ } ScreenId AbstractDisplayController::GetDefaultScreenId() @@ -110,9 +119,9 @@ void AbstractDisplayController::OnAbstractScreenConnected(sptr a return; } if (group->combination_ == ScreenCombination::SCREEN_ALONE) { - CreateAndBindDisplayLocked(absScreen); + BindAloneScreenLocked(absScreen); } else if (group->combination_ == ScreenCombination::SCREEN_MIRROR) { - WLOGE("support in future. combination:%{public}ud", group->combination_); + AddScreenToMirrorLocked(group, absScreen); } else { WLOGE("support in future. combination:%{public}ud", group->combination_); } @@ -127,9 +136,35 @@ void AbstractDisplayController::OnAbstractScreenChanged(sptr abs { } -void AbstractDisplayController::CreateAndBindDisplayLocked(sptr absScreen) +void AbstractDisplayController::BindAloneScreenLocked(sptr realAbsScreen) +{ + ScreenId mainScreenId = abstractScreenController_->GetMainAbstractScreenId(); + if (mainScreenId == SCREEN_ID_INVALID) { + if (dummyDisplay_ == nullptr) { + sptr info = realAbsScreen->GetActiveScreenInfo(); + if (info == nullptr) { + WLOGE("bind alone screen error, cannot get info."); + return; + } + sptr display = new AbstractDisplay(displayCount_.fetch_add(1), + realAbsScreen->dmsId_, info->width_, info->height_, info->freshRate_); + abstractDisplayMap_.insert((std::make_pair(display->GetId(), display))); + WLOGI("create display for new screen. screen:%{public}" PRIu64", display:%{public}" PRIu64"", + realAbsScreen->dmsId_, display->GetId()); + } else { + WLOGI("bind display for new screen. screen:%{public}" PRIu64", display:%{public}" PRIu64"", + realAbsScreen->dmsId_, dummyDisplay_->GetId()); + dummyDisplay_->BindAbstractScreenId(realAbsScreen->dmsId_); + dummyDisplay_ = nullptr; + } + } else { + WLOGE("the succedent real screen should be ALONE. %{public}" PRIu64"", realAbsScreen->dmsId_); + } +} + +void AbstractDisplayController::AddScreenToMirrorLocked(sptr group, + sptr realAbsScreen) { - WLOGI("create display for new screen id:%{public}" PRIu64"", absScreen->dmsId_); - displayCount_++; + WLOGI("bind screen to mirror. screen:%{public}" PRIu64"", realAbsScreen->dmsId_); } } // namespace OHOS::Rosen \ No newline at end of file diff --git a/dmserver/src/abstract_screen.cpp b/dmserver/src/abstract_screen.cpp index 20983f6ab4..983c1d503d 100644 --- a/dmserver/src/abstract_screen.cpp +++ b/dmserver/src/abstract_screen.cpp @@ -17,8 +17,12 @@ #include "abstract_screen_controller.h" #include "display_manager_service.h" +#include "window_manager_hilog.h" namespace OHOS::Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "AbstractScreen"}; +} AbstractScreen::AbstractScreen(ScreenId dmsId, ScreenId rsId) : dmsId_(dmsId), rsId_(rsId) { @@ -28,6 +32,15 @@ AbstractScreen::~AbstractScreen() { } +sptr AbstractScreen::GetActiveScreenInfo() const +{ + if (activeIdx_ < 0 && activeIdx_ >= infos_.size()) { + WLOGE("active mode index is wrong: %{public}d", activeIdx_); + return nullptr; + } + return infos_[activeIdx_]; +} + sptr AbstractScreen::GetGroup() const { return DisplayManagerService::GetInstance().GetAbstractScreenController()->GetAbstractScreenGroup(groupDmsId_); @@ -40,16 +53,40 @@ AbstractScreenGroup::AbstractScreenGroup(ScreenId dmsId, ScreenId rsId) : Abstra AbstractScreenGroup::~AbstractScreenGroup() { + rsDisplayNode_ = nullptr; + children_.clear(); } -void AbstractScreenGroup::AddChild(ScreenCombination type, sptr& dmsScreen, Point& startPoint) -{ +bool AbstractScreenGroup::AddChild(ScreenCombination type, sptr& dmsScreen, Point& startPoint) +{ + struct RSDisplayNodeConfig config; + switch (combination_) { + case ScreenCombination::SCREEN_ALONE: + case ScreenCombination::SCREEN_EXPAND: + config = { dmsScreen->rsId_ }; + break; + case ScreenCombination::SCREEN_MIRROR: + WLOGE("The feature will be supported in the future"); + return false; + default: + WLOGE("fail to add child. invalid group combination:%{public}u", combination_); + return false; + } + std::shared_ptr rsDisplayNode = RSDisplayNode::Create(config); + if (rsDisplayNode == nullptr) { + WLOGE("fail to add child. create rsDisplayNode fail!"); + return false; + } + children_.push_back(dmsScreen); + dmsScreen->rsDisplayNode_ = rsDisplayNode; + return true; } -void AbstractScreenGroup::AddChild(ScreenCombination type, +bool AbstractScreenGroup::AddChild(ScreenCombination type, std::vector>& dmsScreens, std::vector& startPoints) { + return true; } std::vector> AbstractScreenGroup::GetChildren() const diff --git a/dmserver/src/abstract_screen_controller.cpp b/dmserver/src/abstract_screen_controller.cpp index 52c0515e41..733fd25c2e 100644 --- a/dmserver/src/abstract_screen_controller.cpp +++ b/dmserver/src/abstract_screen_controller.cpp @@ -41,8 +41,8 @@ void AbstractScreenController::Init() { WLOGFD("screen controller init"); dmsScreenCount_ = 0; - if (rsInterface_ != nullptr) { - WLOGFE("rsInterface_ is nullptr, init failed"); + if (rsInterface_ == nullptr) { + WLOGFE("rsInterface is null, init failed"); } else { rsInterface_->SetScreenChangeCallback( std::bind(&AbstractScreenController::OnRsScreenChange, this, std::placeholders::_1, std::placeholders::_2)); @@ -77,6 +77,11 @@ sptr AbstractScreenController::GetAbstractScreenGroup(Scree return screen; } +ScreenId AbstractScreenController::GetMainAbstractScreenId() +{ + return primaryDmsScreenId_; +} + ScreenId AbstractScreenController::ConvertToRsScreenId(ScreenId dmsScreenId) { std::lock_guard lock(mutex_); @@ -98,12 +103,12 @@ void AbstractScreenController::RegisterAbstractScreenCallback(sptr(screenEvent)); - ScreenId dmsScreenId = INVALID_SCREEN_ID; + ScreenId dmsScreenId = SCREEN_ID_INVALID; std::lock_guard lock(mutex_); if (screenEvent == ScreenEvent::CONNECTED) { auto iter = rs2DmsScreenIdMap_.find(rsScreenId); if (iter == rs2DmsScreenIdMap_.end()) { - WLOGFD("connect new screen. dmsId:%{public}" PRIu64"", dmsScreenId); + WLOGFD("connect new screen"); dmsScreenId = dmsScreenCount_; sptr absScreen = new AbstractScreen(dmsScreenId, rsScreenId); if (!FillAbstractScreen(absScreen, rsScreenId)) { @@ -117,6 +122,7 @@ void AbstractScreenController::OnRsScreenChange(ScreenId rsScreenId, ScreenEvent if (screenGroup != nullptr && abstractScreenCallback_ != nullptr) { abstractScreenCallback_->onConnected_(absScreen); } + primaryDmsScreenId_ = dmsScreenId; } else { WLOGE("reconnect screen, screenId=%{public}" PRIu64"", rsScreenId); } @@ -159,8 +165,8 @@ bool AbstractScreenController::FillAbstractScreen(sptr& absScree sptr AbstractScreenController::AddToGroupLocked(sptr newScreen) { - if (defaultDmsScreenId_ == SCREEN_ID_INVALID) { - WLOGE("connect the first screen"); + if (primaryDmsScreenId_ == SCREEN_ID_INVALID) { + WLOGI("connect the first screen"); return AddAsFirstScreenLocked(newScreen); } else { AddAsSuccedentScreenLocked(newScreen); @@ -170,11 +176,14 @@ sptr AbstractScreenController::AddToGroupLocked(sptr AbstractScreenController::AddAsFirstScreenLocked(sptr newScreen) { - // TODO: Create default display - ScreenId dmsGroupScreenId = dmsScreenCount_.fetch_add(1); + ScreenId dmsGroupScreenId = dmsScreenCount_.load(); sptr sreenGroup = new AbstractScreenGroup(dmsGroupScreenId, SCREEN_ID_INVALID); Point point; - sreenGroup->AddChild(ScreenCombination::SCREEN_ALONE, newScreen, point); + if (!sreenGroup->AddChild(ScreenCombination::SCREEN_ALONE, newScreen, point)) { + WLOGE("fail to add screen to group. screen=%{public}" PRIu64"", newScreen->dmsId_); + return nullptr; + } + dmsScreenCount_++; newScreen->groupDmsId_ = dmsGroupScreenId; auto iter = dmsScreenGroupMap_.find(dmsGroupScreenId); if (iter != dmsScreenGroupMap_.end()) { @@ -183,14 +192,14 @@ sptr AbstractScreenController::AddAsFirstScreenLocked(sptr< } dmsScreenGroupMap_.insert(std::make_pair(dmsGroupScreenId, sreenGroup)); dmsScreenMap_.insert(std::make_pair(dmsGroupScreenId, sreenGroup)); - WLOGI("connect new group screen. id=%{public}" PRIu64"/%{public}" PRIu64", combination:%{public}ud", + WLOGI("connect new group screen. id=%{public}" PRIu64"/%{public}" PRIu64", combination:%{public}u", newScreen->dmsId_, dmsGroupScreenId, newScreen->type_); return sreenGroup; } void AbstractScreenController::AddAsSuccedentScreenLocked(sptr newScreen) { - // TODO: Mirror to default screen + // TODO: Mirror to main screen } ScreenId AbstractScreenController::CreateVirtualScreen(VirtualScreenOption option) -- Gitee From bcfdbbc18bd8f7af54763ac833d15608dc471667 Mon Sep 17 00:00:00 2001 From: c00471419 Date: Tue, 18 Jan 2022 23:45:30 +0800 Subject: [PATCH 33/57] Js Find Bugfix Signed-off-by: c00471419 Change-Id: If17b1725a87603c8490bfdcd8fc7641c8392e76d Signed-off-by: c00471419 --- interfaces/innerkits/wm/window.h | 2 +- .../window_manager_napi/js_window_manager.cpp | 15 +++--- .../window_runtime/window_napi/js_window.cpp | 51 ++++++++++++++++--- .../window_runtime/window_napi/js_window.h | 5 +- .../window_napi/js_window_listener.cpp | 4 +- .../window_napi/js_window_listener.h | 2 +- wm/src/window_impl.cpp | 5 ++ 7 files changed, 65 insertions(+), 19 deletions(-) diff --git a/interfaces/innerkits/wm/window.h b/interfaces/innerkits/wm/window.h index 09493ff2d7..a130be9675 100644 --- a/interfaces/innerkits/wm/window.h +++ b/interfaces/innerkits/wm/window.h @@ -48,7 +48,7 @@ public: class IAvoidAreaChangedListener : virtual public RefBase { public: - virtual void OnAvoidAreaChanged(const std::vector avoidAreas) = 0; + virtual void OnAvoidAreaChanged(std::vector avoidAreas) = 0; }; class Window : public RefBase { diff --git a/interfaces/kits/napi/window_runtime/window_manager_napi/js_window_manager.cpp b/interfaces/kits/napi/window_runtime/window_manager_napi/js_window_manager.cpp index fe3c393062..f07d308298 100644 --- a/interfaces/kits/napi/window_runtime/window_manager_napi/js_window_manager.cpp +++ b/interfaces/kits/napi/window_runtime/window_manager_napi/js_window_manager.cpp @@ -68,6 +68,9 @@ public: private: std::weak_ptr context_; + std::map, sptr>> jsCbMap_; + std::mutex mtx_; + bool GetNativeContext(NativeValue* nativeContext) { if (nativeContext != nullptr) { @@ -82,12 +85,9 @@ private: return true; } - std::map, sptr>> jsCbMap_; - std::mutex mtx_; - NativeValue* OnCreateWindow(NativeEngine& engine, NativeCallbackInfo& info) { - WLOGFI("JsOnCreateWindow is called"); + WLOGFI("JsWindowManager::JsOnCreateWindow is called"); if (info.argc <= 0) { WLOGFE("parames num not match!"); return engine.CreateUndefined(); @@ -140,6 +140,7 @@ private: NativeValue* OnFindWindow(NativeEngine& engine, NativeCallbackInfo& info) { + WLOGFI("JsWindowManager::JsOnFindWindow is called"); std::string windowName; if (!ConvertFromJsValue(engine, info.argv[0], windowName)) { WLOGFE("Failed to convert parameter to windowName"); @@ -148,9 +149,9 @@ private: AsyncTask::CompleteCallback complete = [windowName](NativeEngine& engine, AsyncTask& task, int32_t status) { - sptr window = Window::Find(windowName); - if (window != nullptr) { - task.Resolve(engine, CreateJsWindowObject(engine, window)); + std::shared_ptr jsWindowObj = FindJsWindowObject(windowName); + if (jsWindowObj != nullptr && jsWindowObj->Get() != nullptr) { + task.Resolve(engine, jsWindowObj->Get()); WLOGFI("JsWindowManager::OnFindWindow success"); } else { task.Reject(engine, CreateJsError(engine, diff --git a/interfaces/kits/napi/window_runtime/window_napi/js_window.cpp b/interfaces/kits/napi/window_runtime/window_napi/js_window.cpp index 3dd83d36d8..3d6dbe8d66 100644 --- a/interfaces/kits/napi/window_runtime/window_napi/js_window.cpp +++ b/interfaces/kits/napi/window_runtime/window_napi/js_window.cpp @@ -26,14 +26,34 @@ namespace { constexpr Rect EMPTY_RECT = {0, 0, 0, 0}; +static std::map> g_jsWindowMap; JsWindow::JsWindow(const sptr& window) : windowToken_(window) { } +JsWindow::~JsWindow() +{ + WLOGFI("JsWindow::~JsWindow is called"); +} + +std::string JsWindow::GetWindowName() +{ + if (windowToken_ == nullptr) { + return ""; + } + return windowToken_->GetWindowName(); +} + void JsWindow::Finalizer(NativeEngine* engine, void* data, void* hint) { WLOGFI("JsWindow::Finalizer is called"); - std::unique_ptr(static_cast(data)); + auto jsWin = std::unique_ptr(static_cast(data)); + std::string windowName = jsWin->GetWindowName(); + WLOGFI("JsWindow::Finalizer windowName : %{public}s", windowName.c_str()); + if (g_jsWindowMap.find(windowName) != g_jsWindowMap.end()) { + WLOGFI("JsWindow::windowName %{public}s is destroyed", windowName.c_str()); + g_jsWindowMap.erase(windowName); + } } NativeValue* JsWindow::Show(NativeEngine* engine, NativeCallbackInfo* info) @@ -183,13 +203,18 @@ NativeValue* JsWindow::OnDestroy(NativeEngine& engine, NativeCallbackInfo& info) AsyncTask::CompleteCallback complete = [this](NativeEngine& engine, AsyncTask& task, int32_t status) { WMError ret = windowToken_->Destroy(); - windowToken_ = nullptr; - if (ret == WMError::WM_OK) { - task.Resolve(engine, engine.CreateUndefined()); - WLOGFI("JsWindow::OnDestroy success"); - } else { + if (ret != WMError::WM_OK) { task.Reject(engine, CreateJsError(engine, static_cast(ret), "JsWindow::OnDestroy failed.")); + return; + } + std::string windowName = windowToken_->GetWindowName(); + if (g_jsWindowMap.find(windowName) != g_jsWindowMap.end()) { + g_jsWindowMap.erase(windowName); + WLOGFI("JsWindow::OnDestroy windowName %{public}s is destroyed", windowName.c_str()); } + // FIX ME: windowToken = nullptr in aync task and don't affect other async task + task.Resolve(engine, engine.CreateUndefined()); + WLOGFI("JsWindow::OnDestroy success"); }; NativeValue* lastParam = (info.argc == 0) ? nullptr : info.argv[0]; @@ -789,6 +814,16 @@ NativeValue* JsWindow::OnGetAvoidArea(NativeEngine& engine, NativeCallbackInfo& return result; } +std::shared_ptr FindJsWindowObject(std::string windowName) +{ + WLOGFI("JsWindow::FindJsWindowObject is called"); + if (g_jsWindowMap.find(windowName) == g_jsWindowMap.end()) { + WLOGFI("JsWindow::FindJsWindowObject window %{public}s not exist!", windowName.c_str()); + return nullptr; + } + return g_jsWindowMap[windowName]; +} + NativeValue* CreateJsWindowObject(NativeEngine& engine, sptr& window) { WLOGFI("JsWindow::CreateJsWindow is called"); @@ -814,6 +849,10 @@ NativeValue* CreateJsWindowObject(NativeEngine& engine, sptr& window) BindNativeFunction(engine, *object, "setSystemBarEnable", JsWindow::SetSystemBarEnable); BindNativeFunction(engine, *object, "setSystemBarProperties", JsWindow::SetSystemBarProperties); BindNativeFunction(engine, *object, "getAvoidArea", JsWindow::GetAvoidArea); + std::shared_ptr jsWindowRef; + jsWindowRef.reset(engine.CreateReference(objValue, 1)); + std::string windowName = window->GetWindowName(); + g_jsWindowMap[windowName] = jsWindowRef; return objValue; } } // namespace Rosen diff --git a/interfaces/kits/napi/window_runtime/window_napi/js_window.h b/interfaces/kits/napi/window_runtime/window_napi/js_window.h index d2de111637..9ad4bcbc2a 100644 --- a/interfaces/kits/napi/window_runtime/window_napi/js_window.h +++ b/interfaces/kits/napi/window_runtime/window_napi/js_window.h @@ -24,11 +24,11 @@ namespace OHOS { namespace Rosen { NativeValue* CreateJsWindowObject(NativeEngine& engine, sptr& window); - +std::shared_ptr FindJsWindowObject(std::string windowName); class JsWindow final { public: explicit JsWindow(const sptr& window); - ~JsWindow() = default; + ~JsWindow(); static void Finalizer(NativeEngine* engine, void* data, void* hint); static NativeValue* Show(NativeEngine* engine, NativeCallbackInfo* info); static NativeValue* Destroy(NativeEngine* engine, NativeCallbackInfo* info); @@ -52,6 +52,7 @@ private: void RegisterWindowListenerWithType(NativeEngine& engine, std::string type, NativeValue* value); void UnregisterWindowListenerWithType(std::string type, NativeValue* value); void UnregisterAllWindowListenerWithType(std::string type); + std::string GetWindowName(); NativeValue* OnShow(NativeEngine& engine, NativeCallbackInfo& info); NativeValue* OnDestroy(NativeEngine& engine, NativeCallbackInfo& info); NativeValue* OnHide(NativeEngine& engine, NativeCallbackInfo& info); diff --git a/interfaces/kits/napi/window_runtime/window_napi/js_window_listener.cpp b/interfaces/kits/napi/window_runtime/window_napi/js_window_listener.cpp index 94a022cf85..2483ca486f 100644 --- a/interfaces/kits/napi/window_runtime/window_napi/js_window_listener.cpp +++ b/interfaces/kits/napi/window_runtime/window_napi/js_window_listener.cpp @@ -27,12 +27,12 @@ constexpr uint32_t AVOID_AREA_NUM = 4; void JsWindowListener::AddCallback(NativeValue* jsListenerObject) { - WLOGFI("JsWindowListener::AddCallbackAndRegister is called"); + WLOGFI("JsWindowListener::AddCallback is called"); std::lock_guard lock(mtx_); std::unique_ptr callbackRef; callbackRef.reset(engine_->CreateReference(jsListenerObject, 1)); jsCallBack_.push_back(std::move(callbackRef)); - WLOGFI("JsWindowListener::AddCallbackAndRegister success jsCallBack_ size: %{public}d!", + WLOGFI("JsWindowListener::AddCallback success jsCallBack_ size: %{public}d!", static_cast(jsCallBack_.size())); return; } diff --git a/interfaces/kits/napi/window_runtime/window_napi/js_window_listener.h b/interfaces/kits/napi/window_runtime/window_napi/js_window_listener.h index 599a5c3c2d..5a93e853ab 100644 --- a/interfaces/kits/napi/window_runtime/window_napi/js_window_listener.h +++ b/interfaces/kits/napi/window_runtime/window_napi/js_window_listener.h @@ -39,7 +39,7 @@ public: void RemoveCallback(NativeValue* jsListenerObject); void OnSystemBarPropertyChange(uint64_t displayId, SystemBarProps props) override; void OnSizeChange(Rect rect) override; - void OnAvoidAreaChanged(const std::vector avoidAreas) override; + void OnAvoidAreaChanged(std::vector avoidAreas) override; private: void CallJsMethod(const char* methodName, NativeValue* const* argv = nullptr, size_t argc = 0); diff --git a/wm/src/window_impl.cpp b/wm/src/window_impl.cpp index 822f31745b..13a29108db 100644 --- a/wm/src/window_impl.cpp +++ b/wm/src/window_impl.cpp @@ -646,6 +646,11 @@ void WindowImpl::SetDefaultOption() property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING); break; } + case WindowType::WINDOW_TYPE_KEYGUARD: { + RemoveWindowFlag(WindowFlag::WINDOW_FLAG_NEED_AVOID); + property_->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN); + break; + } case WindowType::WINDOW_TYPE_DRAGGING_EFFECT: { property_->SetWindowFlags(0); break; -- Gitee From d834bd91d93fea35740694ef751713aff0d454d2 Mon Sep 17 00:00:00 2001 From: chenqinxin Date: Wed, 19 Jan 2022 12:41:02 +0800 Subject: [PATCH 34/57] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=AE=E7=81=AD?= =?UTF-8?q?=E5=B1=8F=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chenqinxin Change-Id: Id9b4cd1b0e9a0792d84884affd68af7e3af0d75b --- dm/include/display_manager_adapter.h | 4 +- dm/src/display_manager.cpp | 37 +- dm/src/display_manager_adapter.cpp | 8 +- dm/test/systemtest/display_power_test.cpp | 142 ++++++-- dm/test/unittest/BUILD.gn | 12 + dm/test/unittest/display_power_unit_test.cpp | 334 ++++++++++++++++++ .../unittest/mock_display_manager_adapter.h | 11 + .../display_manager_agent_controller.h | 4 +- dmserver/include/display_manager_interface.h | 4 +- dmserver/include/display_manager_proxy.h | 4 +- dmserver/include/display_manager_service.h | 4 +- .../src/display_manager_agent_controller.cpp | 8 +- dmserver/src/display_manager_proxy.cpp | 20 +- dmserver/src/display_manager_service.cpp | 12 +- dmserver/src/display_manager_stub.cpp | 4 +- interfaces/innerkits/dm/display_manager.h | 4 +- utils/include/client_agent_container.h | 20 +- 17 files changed, 537 insertions(+), 95 deletions(-) create mode 100644 dm/test/unittest/display_power_unit_test.cpp diff --git a/dm/include/display_manager_adapter.h b/dm/include/display_manager_adapter.h index 7ea1e65546..8e194e8f68 100644 --- a/dm/include/display_manager_adapter.h +++ b/dm/include/display_manager_adapter.h @@ -41,9 +41,9 @@ public: virtual DMError DestroyVirtualScreen(ScreenId screenId); virtual std::shared_ptr GetDisplaySnapshot(DisplayId displayId); - virtual void RegisterDisplayManagerAgent(const sptr& displayManagerAgent, + virtual bool RegisterDisplayManagerAgent(const sptr& displayManagerAgent, DisplayManagerAgentType type); - virtual void UnregisterDisplayManagerAgent(const sptr& displayManagerAgent, + virtual bool UnregisterDisplayManagerAgent(const sptr& displayManagerAgent, DisplayManagerAgentType type); virtual bool WakeUpBegin(PowerStateChangeReason reason); virtual bool WakeUpEnd(); diff --git a/dm/src/display_manager.cpp b/dm/src/display_manager.cpp index 7b6f824b91..108ef0bbef 100644 --- a/dm/src/display_manager.cpp +++ b/dm/src/display_manager.cpp @@ -26,6 +26,7 @@ namespace OHOS::Rosen { namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "DisplayManager"}; + constexpr uint32_t MAX_SCREEN_BRIGHTNESS_VALUE = 100; } WM_IMPLEMENT_SINGLE_INSTANCE(DisplayManager) @@ -173,42 +174,50 @@ std::vector> DisplayManager::GetAllDisplays() return res; } -void DisplayManager::RegisterDisplayPowerEventListener(sptr listener) +bool DisplayManager::RegisterDisplayPowerEventListener(sptr listener) { if (listener == nullptr) { WLOGFE("listener is nullptr"); - return; + return false; } std::lock_guard lock(mutex_); powerEventListeners_.push_back(listener); + bool ret = true; if (powerEventListenerAgent_ == nullptr) { powerEventListenerAgent_ = new DisplayManagerAgent(); - SingletonContainer::Get().RegisterDisplayManagerAgent(powerEventListenerAgent_, + ret = SingletonContainer::Get().RegisterDisplayManagerAgent(powerEventListenerAgent_, DisplayManagerAgentType::DISPLAY_POWER_EVENT_LISTENER); + if (!ret) { + WLOGFW("RegisterDisplayManagerAgent failed ! remove listener!"); + powerEventListeners_.pop_back(); + } } WLOGFI("RegisterDisplayPowerEventListener end"); + return ret; } -void DisplayManager::UnregisterDisplayPowerEventListener(sptr listener) +bool DisplayManager::UnregisterDisplayPowerEventListener(sptr listener) { if (listener == nullptr) { WLOGFE("listener is nullptr"); - return; + return false; } std::lock_guard lock(mutex_); auto iter = std::find(powerEventListeners_.begin(), powerEventListeners_.end(), listener); if (iter == powerEventListeners_.end()) { WLOGFE("could not find this listener"); - return; + return false; } powerEventListeners_.erase(iter); + bool ret = true; if (powerEventListeners_.empty() && powerEventListenerAgent_ != nullptr) { - SingletonContainer::Get().UnregisterDisplayManagerAgent(powerEventListenerAgent_, + ret = SingletonContainer::Get().UnregisterDisplayManagerAgent(powerEventListenerAgent_, DisplayManagerAgentType::DISPLAY_POWER_EVENT_LISTENER); powerEventListenerAgent_ = nullptr; } WLOGFI("UnregisterDisplayPowerEventListener end"); + return ret; } void DisplayManager::NotifyDisplayPowerEvent(DisplayPowerEvent event, EventStatus status) @@ -302,18 +311,19 @@ bool DisplayManager::SetDisplayState(DisplayState state, DisplayStateCallback ca { WLOGFI("state:%{public}u", state); std::lock_guard lock(mutex_); - if (displayStateCallback_ != nullptr) { - WLOGFI("previous callback not called, can't reset"); + if (displayStateCallback_ != nullptr || callback == nullptr) { + WLOGFI("previous callback not called or callback invalid"); return false; } displayStateCallback_ = callback; + bool ret = true; if (displayStateAgent_ == nullptr) { displayStateAgent_ = new DisplayManagerAgent(); - SingletonContainer::Get().RegisterDisplayManagerAgent(displayStateAgent_, + ret = SingletonContainer::Get().RegisterDisplayManagerAgent(displayStateAgent_, DisplayManagerAgentType::DISPLAY_STATE_LISTENER); } - bool ret = SingletonContainer::Get().SetDisplayState(state); + ret &= SingletonContainer::Get().SetDisplayState(state); if (!ret) { ClearDisplayStateCallback(); } @@ -328,6 +338,11 @@ DisplayState DisplayManager::GetDisplayState(uint64_t displayId) bool DisplayManager::SetScreenBrightness(uint64_t screenId, uint32_t level) { WLOGFI("screenId:%{public}" PRIu64", level:%{public}u,", screenId, level); + if (level > MAX_SCREEN_BRIGHTNESS_VALUE) { + level = MAX_SCREEN_BRIGHTNESS_VALUE; + WLOGFW("level:%{public}u, exceed max value!", level); + return false; + } RSInterfaces::GetInstance().SetScreenBacklight(screenId, level); return true; } diff --git a/dm/src/display_manager_adapter.cpp b/dm/src/display_manager_adapter.cpp index 2205b97548..441b0f2e40 100644 --- a/dm/src/display_manager_adapter.cpp +++ b/dm/src/display_manager_adapter.cpp @@ -96,22 +96,22 @@ DMError DisplayManagerAdapter::DestroyVirtualScreen(ScreenId screenId) return displayManagerServiceProxy_->DestroyVirtualScreen(screenId); } -void DisplayManagerAdapter::RegisterDisplayManagerAgent(const sptr& displayManagerAgent, +bool DisplayManagerAdapter::RegisterDisplayManagerAgent(const sptr& displayManagerAgent, DisplayManagerAgentType type) { std::lock_guard lock(mutex_); if (!InitDMSProxyLocked()) { - return; + return false; } return displayManagerServiceProxy_->RegisterDisplayManagerAgent(displayManagerAgent, type); } -void DisplayManagerAdapter::UnregisterDisplayManagerAgent(const sptr& displayManagerAgent, +bool DisplayManagerAdapter::UnregisterDisplayManagerAgent(const sptr& displayManagerAgent, DisplayManagerAgentType type) { std::lock_guard lock(mutex_); if (!InitDMSProxyLocked()) { - return; + return false; } return displayManagerServiceProxy_->UnregisterDisplayManagerAgent(displayManagerAgent, type); } diff --git a/dm/test/systemtest/display_power_test.cpp b/dm/test/systemtest/display_power_test.cpp index 06f64d731a..5308157d07 100644 --- a/dm/test/systemtest/display_power_test.cpp +++ b/dm/test/systemtest/display_power_test.cpp @@ -24,7 +24,8 @@ namespace OHOS { namespace Rosen { namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "DisplayPowerTest"}; - constexpr uint32_t MAX_TIME_WAITING_FOR_CALLBACK = 5; + constexpr uint32_t MAX_TIME_WAITING_FOR_CALLBACK = 40; + constexpr uint32_t SLEEP_TIME_IN_US = 50000; } class DisplayPowerEventListener : public IDisplayPowerEventListener { @@ -52,6 +53,7 @@ public: static inline DisplayId defaultId_; static inline uint32_t brightnessLevel_ = 80; + static inline uint32_t invalidBrightnessLevel_ = 180; static inline uint32_t times_ = 0; static inline bool isDisplayStateCallbackCalled_ = false; static sptr listener_; @@ -101,7 +103,7 @@ void DisplayPowerTest::CheckDisplayStateCallback(bool valueExpected) if (isDisplayStateCallbackCalled_ == valueExpected) { return; } - sleep(1); + usleep(SLEEP_TIME_IN_US); ++times_; } while (times_ <= MAX_TIME_WAITING_FOR_CALLBACK); } @@ -112,18 +114,41 @@ void DisplayPowerTest::CheckDisplayPowerEventCallback(bool valueExpected) if (listener_->isCallbackCalled_ == valueExpected) { return; } - sleep(1); + usleep(SLEEP_TIME_IN_US); ++times_; } while (times_ <= MAX_TIME_WAITING_FOR_CALLBACK); } namespace { /** - * @tc.name: SetDisplayStateValid + * @tc.name: register_display_power_event_listener_001 + * @tc.desc: call RegisterDisplayPowerEventListener with a valid listener and check return value + * @tc.type: FUNC + */ +HWTEST_F(DisplayPowerTest, register_display_power_event_listener_001, Function | SmallTest | Level2) +{ + sptr listener = new DisplayPowerEventListener(); + bool ret = DisplayManager::GetInstance().RegisterDisplayPowerEventListener(listener); + ASSERT_EQ(true, ret); +} + +/** + * @tc.name: register_display_power_event_listener_002 + * @tc.desc: call RegisterDisplayPowerEventListener with an invalid listener and check return value + * @tc.type: FUNC + */ +HWTEST_F(DisplayPowerTest, register_display_power_event_listener_002, Function | SmallTest | Level2) +{ + bool ret = DisplayManager::GetInstance().RegisterDisplayPowerEventListener(nullptr); + ASSERT_EQ(false, ret); +} + +/** + * @tc.name: set_display_state_001 * @tc.desc: Call SetDisplayState and check if it the state set is the same as calling GetDisplayState * @tc.type: FUNC */ -HWTEST_F(DisplayPowerTest, SetDisplayStateValid01, Function | MediumTest | Level2) +HWTEST_F(DisplayPowerTest, set_display_state_001, Function | MediumTest | Level2) { DisplayState initialState = DisplayManager::GetInstance().GetDisplayState(defaultId_); DisplayState stateToSet = (initialState == DisplayState::OFF ? DisplayState::ON : DisplayState::OFF); @@ -135,11 +160,11 @@ HWTEST_F(DisplayPowerTest, SetDisplayStateValid01, Function | MediumTest | Level } /** - * @tc.name: SetDisplayStateValid + * @tc.name: set_display_state_002 * @tc.desc: Call SetDisplayState to set a value already set and check the return value * @tc.type: FUNC */ -HWTEST_F(DisplayPowerTest, SetDisplayStateValid02, Function | MediumTest | Level2) +HWTEST_F(DisplayPowerTest, set_display_state_002, Function | MediumTest | Level2) { DisplayState initialState = DisplayManager::GetInstance().GetDisplayState(defaultId_); bool ret = DisplayManager::GetInstance().SetDisplayState(initialState, callback_); @@ -151,11 +176,26 @@ HWTEST_F(DisplayPowerTest, SetDisplayStateValid02, Function | MediumTest | Level } /** - * @tc.name: SetDisplayStateCallbackValid + * @tc.name: set_display_state_003 + * @tc.desc: Call SetDisplayState with an invalid value and check the return value + * @tc.type: FUNC + */ +HWTEST_F(DisplayPowerTest, set_display_state_003, Function | MediumTest | Level2) +{ + bool ret = DisplayManager::GetInstance().SetDisplayState(DisplayState::UNKNOWN, callback_); + ASSERT_EQ(false, ret); + CheckDisplayStateCallback(false); + ASSERT_EQ(false, isDisplayStateCallbackCalled_); + CheckDisplayPowerEventCallback(false); + ASSERT_EQ(false, listener_->isCallbackCalled_); +} + +/** + * @tc.name: set_display_state_callback_001 * @tc.desc: Call SetDisplayState and check if callback state is correct * @tc.type: FUNC */ -HWTEST_F(DisplayPowerTest, SetDisplayStateCallbackValid01, Function | MediumTest | Level2) +HWTEST_F(DisplayPowerTest, set_display_state_callback_001, Function | MediumTest | Level2) { DisplayState initialState = DisplayManager::GetInstance().GetDisplayState(defaultId_); DisplayState stateToSet = (initialState == DisplayState::OFF ? DisplayState::ON : DisplayState::OFF); @@ -166,11 +206,11 @@ HWTEST_F(DisplayPowerTest, SetDisplayStateCallbackValid01, Function | MediumTest } /** - * @tc.name: SetDisplayStateCallbackValid + * @tc.name: set_display_state_callback_002 * @tc.desc: Call SetDisplayState to set a value already set and check the DisplayStateCallback * @tc.type: FUNC */ -HWTEST_F(DisplayPowerTest, SetDisplayStateCallbackValid02, Function | MediumTest | Level2) +HWTEST_F(DisplayPowerTest, set_display_state_callback_002, Function | MediumTest | Level2) { DisplayState initialState = DisplayManager::GetInstance().GetDisplayState(defaultId_); DisplayManager::GetInstance().SetDisplayState(initialState, callback_); @@ -179,11 +219,11 @@ HWTEST_F(DisplayPowerTest, SetDisplayStateCallbackValid02, Function | MediumTest } /** - * @tc.name: WakeUpBeginCallbackValid + * @tc.name: wake_up_begin_callback_001 * @tc.desc: Call WakeUpBegin and check the OnDisplayPowerEvent callback is called * @tc.type: FUNC */ -HWTEST_F(DisplayPowerTest, WakeUpBeginCallbackValid01, Function | MediumTest | Level2) +HWTEST_F(DisplayPowerTest, wake_up_begin_callback_001, Function | MediumTest | Level2) { bool ret = DisplayManager::GetInstance().WakeUpBegin(PowerStateChangeReason::POWER_BUTTON); ASSERT_EQ(true, ret); @@ -194,11 +234,11 @@ HWTEST_F(DisplayPowerTest, WakeUpBeginCallbackValid01, Function | MediumTest | L } /** - * @tc.name: WakeUpEndCallbackValid - * @tc.desc: Call WakeUpBegin and check the OnDisplayPowerEvent callback is called + * @tc.name: wake_up_end_callback_001 + * @tc.desc: Call WakeUpEnd and check the OnDisplayPowerEvent callback is called * @tc.type: FUNC */ -HWTEST_F(DisplayPowerTest, WakeUpEndCallbackValid01, Function | MediumTest | Level2) +HWTEST_F(DisplayPowerTest, wake_up_end_callback_001, Function | MediumTest | Level2) { bool ret = DisplayManager::GetInstance().WakeUpEnd(); ASSERT_EQ(true, ret); @@ -209,11 +249,11 @@ HWTEST_F(DisplayPowerTest, WakeUpEndCallbackValid01, Function | MediumTest | Lev } /** - * @tc.name: SuspendBeginCallbackValid + * @tc.name: suspend_begin_callback_001 * @tc.desc: Call SuspendBegin and check the OnDisplayPowerEvent callback is called * @tc.type: FUNC */ -HWTEST_F(DisplayPowerTest, SuspendBeginCallbackValid01, Function | MediumTest | Level2) +HWTEST_F(DisplayPowerTest, suspend_begin_callback_001, Function | MediumTest | Level2) { bool ret = DisplayManager::GetInstance().SuspendBegin(PowerStateChangeReason::POWER_BUTTON); ASSERT_EQ(true, ret); @@ -224,11 +264,11 @@ HWTEST_F(DisplayPowerTest, SuspendBeginCallbackValid01, Function | MediumTest | } /** -* @tc.name: SuspendEndCallbackValid +* @tc.name: suspend_end_callback_001 * @tc.desc: Call SuspendEnd and check the OnDisplayPowerEvent callback is called * @tc.type: FUNC */ -HWTEST_F(DisplayPowerTest, SuspendEndCallbackValid01, Function | MediumTest | Level2) +HWTEST_F(DisplayPowerTest, suspend_end_callback_001, Function | MediumTest | Level2) { bool ret = DisplayManager::GetInstance().SuspendEnd(); ASSERT_EQ(true, ret); @@ -239,11 +279,11 @@ HWTEST_F(DisplayPowerTest, SuspendEndCallbackValid01, Function | MediumTest | Le } /** -* @tc.name: SetScreenPowerForAllCallbackValid +* @tc.name: set_screen_power_for_all_001 * @tc.desc: Call SetScreenPowerForAll OFF and check the OnDisplayPowerEvent callback is called * @tc.type: FUNC */ -HWTEST_F(DisplayPowerTest, SetScreenPowerForAllCallbackValid01, Function | MediumTest | Level2) +HWTEST_F(DisplayPowerTest, set_screen_power_for_all_001, Function | MediumTest | Level2) { bool ret = DisplayManager::GetInstance().SetScreenPowerForAll(DisplayPowerState::POWER_OFF, PowerStateChangeReason::POWER_BUTTON); @@ -255,11 +295,11 @@ HWTEST_F(DisplayPowerTest, SetScreenPowerForAllCallbackValid01, Function | Mediu } /** -* @tc.name: SetScreenPowerForAllCallbackValid +* @tc.name: set_screen_power_for_all_002 * @tc.desc: Call SetScreenPowerForAll ON and check the OnDisplayPowerEvent callback is called * @tc.type: FUNC */ -HWTEST_F(DisplayPowerTest, SetScreenPowerForAllCallbackValid02, Function | MediumTest | Level2) +HWTEST_F(DisplayPowerTest, set_screen_power_for_all_002, Function | MediumTest | Level2) { bool ret = DisplayManager::GetInstance().SetScreenPowerForAll(DisplayPowerState::POWER_ON, PowerStateChangeReason::POWER_BUTTON); @@ -271,11 +311,25 @@ HWTEST_F(DisplayPowerTest, SetScreenPowerForAllCallbackValid02, Function | Mediu } /** -* @tc.name: SetDisplayStatePowerCallbackValid -* @tc.desc: Call SetScreenPowerForAll OFF and check the OnDisplayPowerEvent callback is called +* @tc.name: set_screen_power_for_all_003 +* @tc.desc: Call SetScreenPowerForAll with an invalid value and check the return value * @tc.type: FUNC */ -HWTEST_F(DisplayPowerTest, SetDisplayStatePowerCallbackValid01, Function | MediumTest | Level2) +HWTEST_F(DisplayPowerTest, set_screen_power_for_all_003, Function | MediumTest | Level2) +{ + bool ret = DisplayManager::GetInstance().SetScreenPowerForAll(DisplayPowerState::INVALID_STATE, + PowerStateChangeReason::POWER_BUTTON); + ASSERT_EQ(false, ret); + CheckDisplayPowerEventCallback(true); + ASSERT_EQ(false, listener_->isCallbackCalled_); +} + +/** +* @tc.name: set_display_state_power_event_callback_001 +* @tc.desc: Call SetDisplayState OFF and check the OnDisplayPowerEvent callback is called +* @tc.type: FUNC +*/ +HWTEST_F(DisplayPowerTest, set_display_state_power_event_callback_001, Function | MediumTest | Level2) { bool ret = DisplayManager::GetInstance().SetDisplayState(DisplayState::OFF, callback_); ASSERT_EQ(true, ret); @@ -286,11 +340,11 @@ HWTEST_F(DisplayPowerTest, SetDisplayStatePowerCallbackValid01, Function | Mediu } /** -* @tc.name: SetDisplayStatePowerCallbackValid -* @tc.desc: Call SetScreenPowerForAll ON and check the OnDisplayPowerEvent callback is called +* @tc.name: set_display_state_power_event_callback_002 +* @tc.desc: Call SetDisplayState ON and check the OnDisplayPowerEvent callback is called * @tc.type: FUNC */ -HWTEST_F(DisplayPowerTest, SetDisplayStatePowerCallbackValid02, Function | MediumTest | Level2) +HWTEST_F(DisplayPowerTest, set_display_state_power_event_callback_002, Function | MediumTest | Level2) { bool ret = DisplayManager::GetInstance().SetDisplayState(DisplayState::ON, callback_); ASSERT_EQ(true, ret); @@ -301,11 +355,11 @@ HWTEST_F(DisplayPowerTest, SetDisplayStatePowerCallbackValid02, Function | Mediu } /** -* @tc.name: SetScreenPowerForAllValid +* @tc.name: get_display_power_001 * @tc.desc: Call SetScreenPowerForAll OFF and check the GetScreenPower return value * @tc.type: FUNC */ -HWTEST_F(DisplayPowerTest, SetScreenPowerForAllValid01, Function | MediumTest | Level2) +HWTEST_F(DisplayPowerTest, get_display_power_001, Function | MediumTest | Level2) { DisplayPowerState stateToSet = DisplayPowerState::POWER_OFF; bool ret = DisplayManager::GetInstance().SetScreenPowerForAll(stateToSet, PowerStateChangeReason::POWER_BUTTON); @@ -315,11 +369,11 @@ HWTEST_F(DisplayPowerTest, SetScreenPowerForAllValid01, Function | MediumTest | } /** -* @tc.name: SetScreenPowerForAllValid +* @tc.name: get_display_power_002 * @tc.desc: Call SetScreenPowerForAll ON and check the GetScreenPower return value * @tc.type: FUNC */ -HWTEST_F(DisplayPowerTest, SetScreenPowerForAllValid02, Function | MediumTest | Level2) +HWTEST_F(DisplayPowerTest, get_display_power_002, Function | MediumTest | Level2) { DisplayPowerState stateToSet = DisplayPowerState::POWER_ON; bool ret = DisplayManager::GetInstance().SetScreenPowerForAll(stateToSet, PowerStateChangeReason::POWER_BUTTON); @@ -329,17 +383,31 @@ HWTEST_F(DisplayPowerTest, SetScreenPowerForAllValid02, Function | MediumTest | } /** -* @tc.name: SetScreenBrightnessValid -* @tc.desc: Call SetScreenBrightness and check the GetScreenBrightness return value +* @tc.name: set_screen_brightness_001 +* @tc.desc: Call SetScreenBrightness with a valid value and check the GetScreenBrightness return value * @tc.type: FUNC */ -HWTEST_F(DisplayPowerTest, SetScreenBrightnessValid01, Function | MediumTest | Level2) +HWTEST_F(DisplayPowerTest, set_screen_brightness_001, Function | MediumTest | Level2) { bool ret = DisplayManager::GetInstance().SetScreenBrightness(defaultId_, brightnessLevel_); ASSERT_EQ(true, ret); uint32_t level = DisplayManager::GetInstance().GetScreenBrightness(defaultId_); ASSERT_EQ(level, brightnessLevel_); } + +/** +* @tc.name: set_screen_brightness_002 +* @tc.desc: Call SetScreenBrightness with an invalid value and check the GetScreenBrightness return value +* @tc.type: FUNC +*/ +HWTEST_F(DisplayPowerTest, set_screen_brightness_002, Function | MediumTest | Level2) +{ + uint32_t initialLevel = DisplayManager::GetInstance().GetScreenBrightness(defaultId_); + bool ret = DisplayManager::GetInstance().SetScreenBrightness(defaultId_, invalidBrightnessLevel_); + ASSERT_EQ(false, ret); + uint32_t level = DisplayManager::GetInstance().GetScreenBrightness(defaultId_); + ASSERT_EQ(level, initialLevel); +} } // namespace } // namespace Rosen } // namespace OHOS \ No newline at end of file diff --git a/dm/test/unittest/BUILD.gn b/dm/test/unittest/BUILD.gn index aa6313958c..ce638248aa 100644 --- a/dm/test/unittest/BUILD.gn +++ b/dm/test/unittest/BUILD.gn @@ -19,11 +19,23 @@ group("unittest") { testonly = true deps = [ + ":dm_display_power_unit_test", ":dm_screenshot_test", ":dm_snapshot_utils_test", ] } +## UnitTest dm_display_power_unit_test {{{ +ohos_unittest("dm_display_power_unit_test") { + module_out_path = module_out_path + + sources = [ "display_power_unit_test.cpp" ] + + deps = [ ":dm_unittest_common" ] +} + +## UnitTest dm_snapshot_utils_test }}} + ## UnitTest dm_snapshot_utils_test {{{ ohos_unittest("dm_snapshot_utils_test") { module_out_path = module_out_path diff --git a/dm/test/unittest/display_power_unit_test.cpp b/dm/test/unittest/display_power_unit_test.cpp new file mode 100644 index 0000000000..11cc693ee0 --- /dev/null +++ b/dm/test/unittest/display_power_unit_test.cpp @@ -0,0 +1,334 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "display_manager.h" +#include "mock_display_manager_adapter.h" +#include "singleton_mocker.h" + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { +namespace Rosen { +using Mocker = SingletonMocker; + +class DisplayPowerEventListener : public IDisplayPowerEventListener { +public: + virtual void OnDisplayPowerEvent(DisplayPowerEvent event, EventStatus status) {} +}; + +class DisplayPowerUnitTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + virtual void SetUp() override; + virtual void TearDown() override; + static inline sptr listener_ = new DisplayPowerEventListener(); + static inline DisplayId defaultId_ = 0; + static inline uint32_t brightnessLevel_ = 80; + static inline uint32_t invalidBrightnessLevel_ = 180; + static inline DisplayPowerState initialPowerState_; + static inline DisplayState initialState_; +}; + +void DisplayPowerUnitTest::SetUpTestCase() +{ +} + +void DisplayPowerUnitTest::TearDownTestCase() +{ +} + +void DisplayPowerUnitTest::SetUp() +{ + initialPowerState_ = DisplayManager::GetInstance().GetScreenPower(defaultId_); + initialState_ = DisplayManager::GetInstance().GetDisplayState(defaultId_); +} + +void DisplayPowerUnitTest::TearDown() +{ + DisplayManager::GetInstance().SetScreenPowerForAll(initialPowerState_, PowerStateChangeReason::POWER_BUTTON); + DisplayStateCallback callback; + DisplayManager::GetInstance().SetDisplayState(initialState_, callback); +} + +namespace { +/** + * @tc.name: register_display_power_event_listener_001 + * @tc.desc: call Register/UnregisterDisplayPowerEventListener with a valid listener and check return value + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(DisplayPowerUnitTest, register_display_power_event_listener_001, Function | SmallTest | Level2) +{ + Mocker m; + + EXPECT_CALL(m.Mock(), RegisterDisplayManagerAgent(_, DisplayManagerAgentType::DISPLAY_POWER_EVENT_LISTENER)) + .Times(1).WillOnce(Return(true)); + bool ret = DisplayManager::GetInstance().RegisterDisplayPowerEventListener(listener_); + ASSERT_EQ(true, ret); + + EXPECT_CALL(m.Mock(), UnregisterDisplayManagerAgent(_, DisplayManagerAgentType::DISPLAY_POWER_EVENT_LISTENER)) + .Times(1).WillOnce(Return(true)); + ret = DisplayManager::GetInstance().UnregisterDisplayPowerEventListener(listener_); + ASSERT_EQ(true, ret); +} + +/** + * @tc.name: register_display_power_event_listener_002 + * @tc.desc: call Register/UnregisterDisplayPowerEventListener with nullptr and check return value + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(DisplayPowerUnitTest, register_display_power_event_listener_002, Function | SmallTest | Level2) +{ + Mocker m; + EXPECT_CALL(m.Mock(), RegisterDisplayManagerAgent(_, DisplayManagerAgentType::DISPLAY_POWER_EVENT_LISTENER)) + .Times(0); + bool ret = DisplayManager::GetInstance().RegisterDisplayPowerEventListener(nullptr); + ASSERT_EQ(false, ret); + + EXPECT_CALL(m.Mock(), UnregisterDisplayManagerAgent(_, DisplayManagerAgentType::DISPLAY_POWER_EVENT_LISTENER)) + .Times(0); + ret = DisplayManager::GetInstance().UnregisterDisplayPowerEventListener(nullptr); + ASSERT_EQ(false, ret); +} + +/** + * @tc.name: register_display_power_event_listener_003 + * @tc.desc: call Register/UnregisterDisplayPowerEventListener with ipc failed and check return value + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(DisplayPowerUnitTest, register_display_power_event_listener_003, Function | SmallTest | Level2) +{ + Mocker m; + EXPECT_CALL(m.Mock(), RegisterDisplayManagerAgent(_, DisplayManagerAgentType::DISPLAY_POWER_EVENT_LISTENER)) + .Times(1).WillOnce(Return(false)); + bool ret = DisplayManager::GetInstance().RegisterDisplayPowerEventListener(listener_); + ASSERT_EQ(false, ret); + + EXPECT_CALL(m.Mock(), UnregisterDisplayManagerAgent(_, DisplayManagerAgentType::DISPLAY_POWER_EVENT_LISTENER)) + .Times(0); + ret = DisplayManager::GetInstance().UnregisterDisplayPowerEventListener(listener_); + ASSERT_EQ(false, ret); +} + +/** + * @tc.name: unregister_display_power_event_listener_001 + * @tc.desc: call UnregisterDisplayPowerEventListener with a listener never registered and check return value + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(DisplayPowerUnitTest, unregister_display_power_event_listener_001, Function | SmallTest | Level2) +{ + Mocker m; + EXPECT_CALL(m.Mock(), UnregisterDisplayManagerAgent(_, DisplayManagerAgentType::DISPLAY_POWER_EVENT_LISTENER)) + .Times(0); + bool ret = DisplayManager::GetInstance().UnregisterDisplayPowerEventListener(listener_); + ASSERT_EQ(false, ret); +} + +/** + * @tc.name: unregister_display_power_event_listener_002 + * @tc.desc: call UnregisterDisplayPowerEventListener with nullptr and check return value + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(DisplayPowerUnitTest, unregister_display_power_event_listener_002, Function | SmallTest | Level2) +{ + Mocker m; + EXPECT_CALL(m.Mock(), UnregisterDisplayManagerAgent(_, DisplayManagerAgentType::DISPLAY_POWER_EVENT_LISTENER)) + .Times(0); + bool ret = DisplayManager::GetInstance().UnregisterDisplayPowerEventListener(nullptr); + ASSERT_EQ(false, ret); +} + +/** + * @tc.name: wake_up_begin_001 + * @tc.desc: call WakeUpBegin and check return value + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(DisplayPowerUnitTest, wake_up_begin_001, Function | SmallTest | Level2) +{ + Mocker m; + EXPECT_CALL(m.Mock(), WakeUpBegin(PowerStateChangeReason::POWER_BUTTON)).Times(1).WillOnce(Return(true));; + bool ret = DisplayManager::GetInstance().WakeUpBegin(PowerStateChangeReason::POWER_BUTTON); + ASSERT_EQ(true, ret); + + EXPECT_CALL(m.Mock(), WakeUpBegin(PowerStateChangeReason::POWER_BUTTON)).Times(1).WillOnce(Return(false));; + ret = DisplayManager::GetInstance().WakeUpBegin(PowerStateChangeReason::POWER_BUTTON); + ASSERT_EQ(false, ret); +} + +/** + * @tc.name: wake_up_end_001 + * @tc.desc: call WakeUpEnd and check return value + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(DisplayPowerUnitTest, wake_up_end_001, Function | SmallTest | Level2) +{ + Mocker m; + EXPECT_CALL(m.Mock(), WakeUpEnd()).Times(1).WillOnce(Return(true)); + bool ret = DisplayManager::GetInstance().WakeUpEnd(); + ASSERT_EQ(true, ret); + + EXPECT_CALL(m.Mock(), WakeUpEnd()).Times(1).WillOnce(Return(false)); + ret = DisplayManager::GetInstance().WakeUpEnd(); + ASSERT_EQ(false, ret); +} + +/** + * @tc.name: suspend_begin_001 + * @tc.desc: call SuspendBegin and check return value + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(DisplayPowerUnitTest, suspend_begin_001, Function | SmallTest | Level2) +{ + Mocker m; + EXPECT_CALL(m.Mock(), SuspendBegin(PowerStateChangeReason::POWER_BUTTON)).Times(1).WillOnce(Return(true));; + bool ret = DisplayManager::GetInstance().SuspendBegin(PowerStateChangeReason::POWER_BUTTON); + ASSERT_EQ(true, ret); + + EXPECT_CALL(m.Mock(), SuspendBegin(PowerStateChangeReason::POWER_BUTTON)).Times(1).WillOnce(Return(false));; + ret = DisplayManager::GetInstance().SuspendBegin(PowerStateChangeReason::POWER_BUTTON); + ASSERT_EQ(false, ret); +} + +/** +* @tc.name: suspend_end_001 +* @tc.desc: call SuspendEnd and check return value +* @tc.type: FUNC +* @tc.require: +*/ +HWTEST_F(DisplayPowerUnitTest, suspend_end_001, Function | SmallTest | Level2) +{ + Mocker m; + EXPECT_CALL(m.Mock(), SuspendEnd()).Times(1).WillOnce(Return(true)); + bool ret = DisplayManager::GetInstance().SuspendEnd(); + ASSERT_EQ(true, ret); + + EXPECT_CALL(m.Mock(), SuspendEnd()).Times(1).WillOnce(Return(false)); + ret = DisplayManager::GetInstance().SuspendEnd(); + ASSERT_EQ(false, ret); +} + +/** +* @tc.name: set_screen_brightness_001 +* @tc.desc: Call SetScreenBrightness with a valid value and check the GetScreenBrightness return value +* @tc.type: FUNC +*/ +HWTEST_F(DisplayPowerUnitTest, set_screen_brightness_001, Function | MediumTest | Level2) +{ + bool ret = DisplayManager::GetInstance().SetScreenBrightness(defaultId_, brightnessLevel_); + ASSERT_EQ(true, ret); + uint32_t level = DisplayManager::GetInstance().GetScreenBrightness(defaultId_); + ASSERT_EQ(level, brightnessLevel_); +} + +/** +* @tc.name: set_screen_brightness_002 +* @tc.desc: Call SetScreenBrightness with an invalid value and check the GetScreenBrightness return value +* @tc.type: FUNC +*/ +HWTEST_F(DisplayPowerUnitTest, set_screen_brightness_002, Function | MediumTest | Level2) +{ + uint32_t initialLevel = DisplayManager::GetInstance().GetScreenBrightness(defaultId_); + bool ret = DisplayManager::GetInstance().SetScreenBrightness(defaultId_, invalidBrightnessLevel_); + ASSERT_EQ(false, ret); + uint32_t level = DisplayManager::GetInstance().GetScreenBrightness(defaultId_); + ASSERT_EQ(level, initialLevel); +} + +/** +* @tc.name: set_screen_power_for_all_001 +* @tc.desc: Call SetScreenPowerForAll with valid value and check the GetScreenPower return value +* @tc.type: FUNC +*/ +HWTEST_F(DisplayPowerUnitTest, set_screen_power_for_all_001, Function | MediumTest | Level2) +{ + Mocker m; + EXPECT_CALL(m.Mock(), GetDefaultDisplayId()).Times(1).WillOnce(Return(defaultId_)); + EXPECT_CALL(m.Mock(), SetScreenPowerForAll(_, PowerStateChangeReason::POWER_BUTTON)) + .Times(1).WillOnce(Return(true)); + + bool ret = DisplayManager::GetInstance().SetScreenPowerForAll(DisplayPowerState::POWER_OFF, + PowerStateChangeReason::POWER_BUTTON); + ASSERT_EQ(true, ret); + + DisplayPowerState state = DisplayManager::GetInstance().GetScreenPower(defaultId_); + ASSERT_EQ(state, DisplayPowerState::POWER_OFF); +} + +/** +* @tc.name: set_screen_power_for_all_002 +* @tc.desc: Call SetScreenPowerForAll with invalid value and check the GetScreenPower return value +* @tc.type: FUNC +*/ +HWTEST_F(DisplayPowerUnitTest, set_screen_power_for_all_002, Function | MediumTest | Level2) +{ + Mocker m; + EXPECT_CALL(m.Mock(), GetDefaultDisplayId()).Times(1).WillOnce(Return(defaultId_)); + EXPECT_CALL(m.Mock(), SetScreenPowerForAll(_, PowerStateChangeReason::POWER_BUTTON)).Times(0); + + bool ret = DisplayManager::GetInstance().SetScreenPowerForAll(DisplayPowerState::INVALID_STATE, + PowerStateChangeReason::POWER_BUTTON); + ASSERT_EQ(false, ret); + + DisplayPowerState state = DisplayManager::GetInstance().GetScreenPower(defaultId_); + ASSERT_EQ(state, initialPowerState_); +} + +/** +* @tc.name: set_display_state_001 +* @tc.desc: Call SetDisplayState with valid value and check the GetDisplayState return value +* @tc.type: FUNC +*/ +HWTEST_F(DisplayPowerUnitTest, set_display_state_001, Function | MediumTest | Level2) +{ + DisplayState stateToSet = (initialState_ == DisplayState::OFF ? DisplayState::ON : DisplayState::OFF); + Mocker m; + EXPECT_CALL(m.Mock(), RegisterDisplayManagerAgent(_, DisplayManagerAgentType::DISPLAY_STATE_LISTENER)) + .Times(1).WillOnce(Return(true)); + EXPECT_CALL(m.Mock(), SetDisplayState(stateToSet)).Times(1).WillOnce(Return(true)); + DisplayStateCallback callback = [](DisplayState state) {}; + bool ret = DisplayManager::GetInstance().SetDisplayState(stateToSet, callback); + ASSERT_EQ(true, ret); + + EXPECT_CALL(m.Mock(), GetDisplayState(defaultId_)).Times(1).WillOnce(Return(stateToSet)); + DisplayState state = DisplayManager::GetInstance().GetDisplayState(defaultId_); + ASSERT_EQ(state, stateToSet); +} + +/** +* @tc.name: set_display_state_002 +* @tc.desc: Call SetDisplayState with invalid callback and check the GetDisplayState return value +* @tc.type: FUNC +*/ +HWTEST_F(DisplayPowerUnitTest, set_display_state_002, Function | MediumTest | Level2) +{ + Mocker m; + EXPECT_CALL(m.Mock(), SetDisplayState(_)).Times(0); + DisplayState stateToSet = (initialState_ == DisplayState::OFF ? DisplayState::ON : DisplayState::OFF); + bool ret = DisplayManager::GetInstance().SetDisplayState(stateToSet, nullptr); + ASSERT_EQ(false, ret); +} +} +} +} \ No newline at end of file diff --git a/dm/test/unittest/mock_display_manager_adapter.h b/dm/test/unittest/mock_display_manager_adapter.h index 97310c7773..ae01aae8dc 100644 --- a/dm/test/unittest/mock_display_manager_adapter.h +++ b/dm/test/unittest/mock_display_manager_adapter.h @@ -29,6 +29,17 @@ public: MOCK_METHOD1(DestroyVirtualScreen, DMError(ScreenId screenId)); MOCK_METHOD1(GetDisplaySnapshot, std::shared_ptr(DisplayId displayId)); MOCK_METHOD0(Clear, void()); + MOCK_METHOD2(RegisterDisplayManagerAgent, bool(const sptr& displayManagerAgent, + DisplayManagerAgentType type)); + MOCK_METHOD2(UnregisterDisplayManagerAgent, bool(const sptr& displayManagerAgent, + DisplayManagerAgentType type)); + MOCK_METHOD1(WakeUpBegin, bool(PowerStateChangeReason reason)); + MOCK_METHOD0(WakeUpEnd, bool()); + MOCK_METHOD1(SuspendBegin, bool(PowerStateChangeReason reason)); + MOCK_METHOD0(SuspendEnd, bool()); + MOCK_METHOD2(SetScreenPowerForAll, bool(DisplayPowerState state, PowerStateChangeReason reason)); + MOCK_METHOD1(SetDisplayState, bool(DisplayState state)); + MOCK_METHOD1(GetDisplayState, DisplayState(uint64_t displayId)); }; } } // namespace OHOS diff --git a/dmserver/include/display_manager_agent_controller.h b/dmserver/include/display_manager_agent_controller.h index dec0d87f9a..c5f4e92afc 100644 --- a/dmserver/include/display_manager_agent_controller.h +++ b/dmserver/include/display_manager_agent_controller.h @@ -26,9 +26,9 @@ namespace Rosen { class DisplayManagerAgentController { WM_DECLARE_SINGLE_INSTANCE_BASE(DisplayManagerAgentController) public: - void RegisterDisplayManagerAgent(const sptr& displayManagerAgent, + bool RegisterDisplayManagerAgent(const sptr& displayManagerAgent, DisplayManagerAgentType type); - void UnregisterDisplayManagerAgent(const sptr& displayManagerAgent, + bool UnregisterDisplayManagerAgent(const sptr& displayManagerAgent, DisplayManagerAgentType type); bool NotifyDisplayPowerEvent(DisplayPowerEvent event, EventStatus status); diff --git a/dmserver/include/display_manager_interface.h b/dmserver/include/display_manager_interface.h index 4c889daf3c..743602d6d2 100644 --- a/dmserver/include/display_manager_interface.h +++ b/dmserver/include/display_manager_interface.h @@ -56,9 +56,9 @@ public: virtual DMError DestroyVirtualScreen(ScreenId screenId) = 0; virtual std::shared_ptr GetDispalySnapshot(DisplayId displayId) = 0; - virtual void RegisterDisplayManagerAgent(const sptr& displayManagerAgent, + virtual bool RegisterDisplayManagerAgent(const sptr& displayManagerAgent, DisplayManagerAgentType type) = 0; - virtual void UnregisterDisplayManagerAgent(const sptr& displayManagerAgent, + virtual bool UnregisterDisplayManagerAgent(const sptr& displayManagerAgent, DisplayManagerAgentType type) = 0; virtual bool WakeUpBegin(PowerStateChangeReason reason) = 0; virtual bool WakeUpEnd() = 0; diff --git a/dmserver/include/display_manager_proxy.h b/dmserver/include/display_manager_proxy.h index dd1232fba0..a3c33988c1 100644 --- a/dmserver/include/display_manager_proxy.h +++ b/dmserver/include/display_manager_proxy.h @@ -38,9 +38,9 @@ public: DMError DestroyVirtualScreen(ScreenId screenId) override; std::shared_ptr GetDispalySnapshot(DisplayId displayId) override; - void RegisterDisplayManagerAgent(const sptr& displayManagerAgent, + bool RegisterDisplayManagerAgent(const sptr& displayManagerAgent, DisplayManagerAgentType type) override; - void UnregisterDisplayManagerAgent(const sptr& displayManagerAgent, + bool UnregisterDisplayManagerAgent(const sptr& displayManagerAgent, DisplayManagerAgentType type) override; bool WakeUpBegin(PowerStateChangeReason reason) override; bool WakeUpEnd() override; diff --git a/dmserver/include/display_manager_service.h b/dmserver/include/display_manager_service.h index 898c3cab4d..989a9601d4 100644 --- a/dmserver/include/display_manager_service.h +++ b/dmserver/include/display_manager_service.h @@ -46,9 +46,9 @@ public: DisplayInfo GetDisplayInfoById(DisplayId displayId) override; std::shared_ptr GetDispalySnapshot(DisplayId displayId) override; - void RegisterDisplayManagerAgent(const sptr& displayManagerAgent, + bool RegisterDisplayManagerAgent(const sptr& displayManagerAgent, DisplayManagerAgentType type) override; - void UnregisterDisplayManagerAgent(const sptr& displayManagerAgent, + bool UnregisterDisplayManagerAgent(const sptr& displayManagerAgent, DisplayManagerAgentType type) override; bool WakeUpBegin(PowerStateChangeReason reason) override; bool WakeUpEnd() override; diff --git a/dmserver/src/display_manager_agent_controller.cpp b/dmserver/src/display_manager_agent_controller.cpp index ff46111ccf..dd00f4a534 100644 --- a/dmserver/src/display_manager_agent_controller.cpp +++ b/dmserver/src/display_manager_agent_controller.cpp @@ -23,18 +23,18 @@ namespace { } WM_IMPLEMENT_SINGLE_INSTANCE(DisplayManagerAgentController) -void DisplayManagerAgentController::RegisterDisplayManagerAgent(const sptr& displayManagerAgent, +bool DisplayManagerAgentController::RegisterDisplayManagerAgent(const sptr& displayManagerAgent, DisplayManagerAgentType type) { std::lock_guard lock(mutex_); - dmAgentContainer_.RegisterAgentLocked(displayManagerAgent, type); + return dmAgentContainer_.RegisterAgentLocked(displayManagerAgent, type); } -void DisplayManagerAgentController::UnregisterDisplayManagerAgent(const sptr& displayManagerAgent, +bool DisplayManagerAgentController::UnregisterDisplayManagerAgent(const sptr& displayManagerAgent, DisplayManagerAgentType type) { std::lock_guard lock(mutex_); - dmAgentContainer_.UnregisterAgentLocked(displayManagerAgent, type); + return dmAgentContainer_.UnregisterAgentLocked(displayManagerAgent, type); } bool DisplayManagerAgentController::NotifyDisplayPowerEvent(DisplayPowerEvent event, EventStatus status) diff --git a/dmserver/src/display_manager_proxy.cpp b/dmserver/src/display_manager_proxy.cpp index b8d3906bcd..8ff32975a6 100644 --- a/dmserver/src/display_manager_proxy.cpp +++ b/dmserver/src/display_manager_proxy.cpp @@ -171,7 +171,7 @@ std::shared_ptr DisplayManagerProxy::GetDispalySnapshot(Display return pixelMap; } -void DisplayManagerProxy::RegisterDisplayManagerAgent(const sptr& displayManagerAgent, +bool DisplayManagerProxy::RegisterDisplayManagerAgent(const sptr& displayManagerAgent, DisplayManagerAgentType type) { MessageParcel data; @@ -179,25 +179,27 @@ void DisplayManagerProxy::RegisterDisplayManagerAgent(const sptrAsObject())) { WLOGFE("Write IDisplayManagerAgent failed"); - return; + return false; } if (!data.WriteUint32(static_cast(type))) { WLOGFE("Write DisplayManagerAgent type failed"); - return; + return false; } if (Remote()->SendRequest(TRANS_ID_REGISTER_DISPLAY_MANAGER_AGENT, data, reply, option) != ERR_NONE) { WLOGFE("SendRequest failed"); + return false; } + return reply.ReadBool(); } -void DisplayManagerProxy::UnregisterDisplayManagerAgent(const sptr& displayManagerAgent, +bool DisplayManagerProxy::UnregisterDisplayManagerAgent(const sptr& displayManagerAgent, DisplayManagerAgentType type) { MessageParcel data; @@ -205,22 +207,24 @@ void DisplayManagerProxy::UnregisterDisplayManagerAgent(const sptrAsObject())) { WLOGFE("Write IWindowManagerAgent failed"); - return; + return false; } if (!data.WriteUint32(static_cast(type))) { WLOGFE("Write DisplayManagerAgent type failed"); - return; + return false; } if (Remote()->SendRequest(TRANS_ID_UNREGISTER_DISPLAY_MANAGER_AGENT, data, reply, option) != ERR_NONE) { WLOGFE("SendRequest failed"); + return false; } + return reply.ReadBool(); } bool DisplayManagerProxy::WakeUpBegin(PowerStateChangeReason reason) diff --git a/dmserver/src/display_manager_service.cpp b/dmserver/src/display_manager_service.cpp index f9bcf6ba9d..1809fe8a20 100644 --- a/dmserver/src/display_manager_service.cpp +++ b/dmserver/src/display_manager_service.cpp @@ -136,24 +136,24 @@ void DisplayManagerService::OnStop() WLOGFI("ready to stop display service."); } -void DisplayManagerService::RegisterDisplayManagerAgent(const sptr& displayManagerAgent, +bool DisplayManagerService::RegisterDisplayManagerAgent(const sptr& displayManagerAgent, DisplayManagerAgentType type) { if ((displayManagerAgent == nullptr) || (displayManagerAgent->AsObject() == nullptr)) { WLOGFE("displayManagerAgent invalid"); - return; + return false; } - DisplayManagerAgentController::GetInstance().RegisterDisplayManagerAgent(displayManagerAgent, type); + return DisplayManagerAgentController::GetInstance().RegisterDisplayManagerAgent(displayManagerAgent, type); } -void DisplayManagerService::UnregisterDisplayManagerAgent(const sptr& displayManagerAgent, +bool DisplayManagerService::UnregisterDisplayManagerAgent(const sptr& displayManagerAgent, DisplayManagerAgentType type) { if ((displayManagerAgent == nullptr) || (displayManagerAgent->AsObject() == nullptr)) { WLOGFE("displayManagerAgent invalid"); - return; + return false; } - DisplayManagerAgentController::GetInstance().UnregisterDisplayManagerAgent(displayManagerAgent, type); + return DisplayManagerAgentController::GetInstance().UnregisterDisplayManagerAgent(displayManagerAgent, type); } bool DisplayManagerService::WakeUpBegin(PowerStateChangeReason reason) diff --git a/dmserver/src/display_manager_stub.cpp b/dmserver/src/display_manager_stub.cpp index 7e089ace0b..927bd23230 100644 --- a/dmserver/src/display_manager_stub.cpp +++ b/dmserver/src/display_manager_stub.cpp @@ -87,13 +87,13 @@ int32_t DisplayManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, case TRANS_ID_REGISTER_DISPLAY_MANAGER_AGENT: { auto agent = iface_cast(data.ReadRemoteObject()); auto type = static_cast(data.ReadUint32()); - RegisterDisplayManagerAgent(agent, type); + reply.WriteBool(RegisterDisplayManagerAgent(agent, type)); break; } case TRANS_ID_UNREGISTER_DISPLAY_MANAGER_AGENT: { auto agent = iface_cast(data.ReadRemoteObject()); auto type = static_cast(data.ReadUint32()); - UnregisterDisplayManagerAgent(agent, type); + reply.WriteBool(UnregisterDisplayManagerAgent(agent, type)); break; } case TRANS_ID_WAKE_UP_BEGIN: { diff --git a/interfaces/innerkits/dm/display_manager.h b/interfaces/innerkits/dm/display_manager.h index 617633238f..aa09f768f0 100644 --- a/interfaces/innerkits/dm/display_manager.h +++ b/interfaces/innerkits/dm/display_manager.h @@ -47,8 +47,8 @@ public: std::shared_ptr GetScreenshot(DisplayId displayId, const Media::Rect &rect, const Media::Size &size, int rotation); - void RegisterDisplayPowerEventListener(sptr listener); - void UnregisterDisplayPowerEventListener(sptr listener); + bool RegisterDisplayPowerEventListener(sptr listener); + bool UnregisterDisplayPowerEventListener(sptr listener); bool WakeUpBegin(PowerStateChangeReason reason); bool WakeUpEnd(); bool SuspendBegin(PowerStateChangeReason reason); diff --git a/utils/include/client_agent_container.h b/utils/include/client_agent_container.h index 3d46b4f920..5fbe72d228 100644 --- a/utils/include/client_agent_container.h +++ b/utils/include/client_agent_container.h @@ -30,8 +30,8 @@ public: ClientAgentContainer(std::mutex& mutex); virtual ~ClientAgentContainer() = default; - void RegisterAgentLocked(const sptr& agent, T2 type); - void UnregisterAgentLocked(const sptr& agent, T2 type); + bool RegisterAgentLocked(const sptr& agent, T2 type); + bool UnregisterAgentLocked(const sptr& agent, T2 type); std::vector> GetAgentsByType(T2 type); private: @@ -60,29 +60,27 @@ ClientAgentContainer::ClientAgentContainer(std::mutex& mutex) std::bind(&ClientAgentContainer::RemoveAgent, this, std::placeholders::_1))) {} template -void ClientAgentContainer::RegisterAgentLocked(const sptr& agent, T2 type) +bool ClientAgentContainer::RegisterAgentLocked(const sptr& agent, T2 type) { agentMap_[type].push_back(agent); WLOG_I("ClientAgentContainer agent registered type:%{public}u", type); - if (deathRecipient_ == nullptr) { - WLOG_I("death Recipient is nullptr"); - return; - } - if (!agent->AsObject()->AddDeathRecipient(deathRecipient_)) { + if (deathRecipient_ == nullptr || !agent->AsObject()->AddDeathRecipient(deathRecipient_)) { WLOG_I("ClientAgentContainer failed to add death recipient"); } + return true; } template -void ClientAgentContainer::UnregisterAgentLocked(const sptr& agent, T2 type) +bool ClientAgentContainer::UnregisterAgentLocked(const sptr& agent, T2 type) { if (agent == nullptr || agentMap_.count(type) == 0) { WLOG_E("ClientAgentContainer agent or type is invalid"); - return; + return false; } auto& agents = agentMap_.at(type); - UnregisterAgentLocked(agents, agent->AsObject()); + bool ret = UnregisterAgentLocked(agents, agent->AsObject()); agent->AsObject()->RemoveDeathRecipient(deathRecipient_); + return ret; } template -- Gitee From 377360970f84664d63a3fba826f4dcd0b4621989 Mon Sep 17 00:00:00 2001 From: huandong Date: Wed, 19 Jan 2022 00:43:51 +0800 Subject: [PATCH 35/57] =?UTF-8?q?=E6=B7=BB=E5=8A=A0avoid=5Farea=5Fcontroll?= =?UTF-8?q?er=E7=9B=B8=E5=85=B3=E7=9A=84=E7=B3=BB=E7=BB=9F=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E5=92=8C=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Ifa93e66032a62c9482adecfff4bac326c7a0a599 Signed-off-by: huandong --- wm/test/systemtest/window_immersive_test.cpp | 278 ++++++++++-- wm/test/systemtest/window_test_utils.cpp | 29 +- wm/test/systemtest/window_test_utils.h | 1 + wm/test/unittest/BUILD.gn | 12 + .../unittest/avoid_area_controller_test.cpp | 403 ++++++++++++++++++ wm/test/unittest/avoid_area_controller_test.h | 40 ++ 6 files changed, 713 insertions(+), 50 deletions(-) create mode 100644 wm/test/unittest/avoid_area_controller_test.cpp create mode 100644 wm/test/unittest/avoid_area_controller_test.h diff --git a/wm/test/systemtest/window_immersive_test.cpp b/wm/test/systemtest/window_immersive_test.cpp index 4ab076a408..2dd0505d7e 100644 --- a/wm/test/systemtest/window_immersive_test.cpp +++ b/wm/test/systemtest/window_immersive_test.cpp @@ -23,6 +23,8 @@ using namespace testing::ext; namespace OHOS { namespace Rosen { namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowImmersiveTest"}; + const SystemBarProperty SYS_BAR_PROP_DEFAULT; const SystemBarProperty SYS_BAR_PROP_1(true, 0xE5111111, 0xE5222222); const SystemBarProperty SYS_BAR_PROP_2(false, 0xE5222222, 0xE5333333); @@ -46,14 +48,26 @@ namespace { const SystemBarProps TEST_DIFF_PROPS_2_1 = { { WindowType::WINDOW_TYPE_NAVIGATION_BAR, SYS_BAR_PROP_2 }, }; + + const Rect EMPTY_RECT = {0, 0, 0, 0}; + const float RATIO = 0.3; } + using utils = WindowTestUtils; +const int WAIT_ASYNC_US = 100000; // 100000us + class TestSystemBarChangedListener : public ISystemBarChangedListener { public: SystemBarProps props_; void OnSystemBarPropertyChange(uint64_t displayId, SystemBarProps props) override; }; +class TestAvoidAreaChangedListener : public IAvoidAreaChangedListener { +public: + std::vector avoidAreas_; + void OnAvoidAreaChanged(std::vector avoidAreas) override; +}; + class WindowImmersiveTest : public testing::Test { public: static void SetUpTestCase(); @@ -67,11 +81,20 @@ public: std::vector> activeWindows_; static vector fullScreenExpecteds_; static sptr testSystemBarChangedListener_; + static sptr testAvoidAreaChangedListener_; + utils::TestWindowInfo fullScreenAppinfo_; + utils::TestWindowInfo avoidBarInfo_; + uint32_t leftAvoidW_; + uint32_t leftAvoidH_; + uint32_t topAvoidW_; + uint32_t topAvoidH_; }; vector WindowImmersiveTest::fullScreenExpecteds_; sptr WindowImmersiveTest::testSystemBarChangedListener_ = new TestSystemBarChangedListener(); +sptr WindowImmersiveTest::testAvoidAreaChangedListener_ = + new TestAvoidAreaChangedListener(); void WindowImmersiveTest::SetWindowSystemProps(const sptr& window, const SystemBarProps& props) { @@ -83,22 +106,23 @@ void WindowImmersiveTest::SetWindowSystemProps(const sptr& window, const void WindowImmersiveTest::DumpFailedInfo(const SystemBarProps& expect) { auto act = testSystemBarChangedListener_->props_; - printf("WindowImmersiveTest Expected: \n"); + WLOGFI("WindowImmersiveTest Expected:"); for (auto prop : expect) { - printf("WindowType: %4d, Enable: %4d, Color: %x | %x\n", static_cast(prop.first), - prop.second.enable_, prop.second.backgroundColor_, prop.second.contentColor_); + WLOGFI("WindowType: %{public}4d, Enable: %{public}4d, Color: %{public}x | %{public}x", + static_cast(prop.first), prop.second.enable_, prop.second.backgroundColor_, + prop.second.contentColor_); } - printf("WindowImmersiveTest Act: \n"); + WLOGFI("WindowImmersiveTest Act: "); for (auto prop : act) { - printf("WindowType: %4d, Enable: %4d, Color: %x | %x\n", static_cast(prop.first), - prop.second.enable_, prop.second.backgroundColor_, prop.second.contentColor_); + WLOGFI("WindowType: %{public}4d, Enable: %{public}4d, Color: %{public}x | %{public}x", + static_cast(prop.first), prop.second.enable_, prop.second.backgroundColor_, + prop.second.contentColor_); } } bool WindowImmersiveTest::SystemBarPropsEqualsTo(const SystemBarProps& expect) { - const int SLEEP_US = 100000; - usleep(SLEEP_US); + usleep(WAIT_ASYNC_US); auto act = testSystemBarChangedListener_->props_; if (act.size() != expect.size()) { DumpFailedInfo(expect); @@ -115,12 +139,26 @@ bool WindowImmersiveTest::SystemBarPropsEqualsTo(const SystemBarProps& expect) void TestSystemBarChangedListener::OnSystemBarPropertyChange(uint64_t displayId, SystemBarProps props) { - printf("TestSystemBarChangedListener Display ID: %llu\n", displayId); + WLOGFI("TestSystemBarChangedListener Display ID: %{public}" PRIu64"", displayId); props_ = props; } +void TestAvoidAreaChangedListener::OnAvoidAreaChanged(std::vector avoidAreas) +{ + avoidAreas_ = avoidAreas; +} + void WindowImmersiveTest::SetUpTestCase() { + auto display = DisplayManager::GetInstance().GetDisplayById(0); + if (display == nullptr) { + WLOGFE("GetDefaultDisplay: failed!"); + } else { + WLOGFI("GetDefaultDisplay: id %{public}" PRIu64", w %{public}d, h %{public}d, fps %{public}u", + display->GetId(), display->GetWidth(), display->GetHeight(), display->GetFreshRate()); + } + Rect displayRect = {0, 0, display->GetWidth(), display->GetHeight()}; + utils::InitByDisplayRect(displayRect); } void WindowImmersiveTest::TearDownTestCase() @@ -129,6 +167,28 @@ void WindowImmersiveTest::TearDownTestCase() void WindowImmersiveTest::SetUp() { + fullScreenAppinfo_ = { + .name = "main", + .rect = utils::defaultAppRect_, + .type = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, + .mode = WindowMode::WINDOW_MODE_FULLSCREEN, // immersive setting + .needAvoid = false, // immersive setting + .parentLimit = false, + .parentName = "", + }; + avoidBarInfo_ = { + .name = "LeftAvoidTest", + .rect = EMPTY_RECT, + .type = WindowType::WINDOW_TYPE_STATUS_BAR, + .mode = WindowMode::WINDOW_MODE_FLOATING, + }; + // makesure left avoid win w < h + leftAvoidW_ = std::min(utils::displayRect_.width_, static_cast(utils::displayRect_.height_ * RATIO)); + leftAvoidH_ = utils::displayRect_.height_; + // makesure top avoid win h < w + topAvoidW_ = utils::displayRect_.width_; + topAvoidH_ = std::min(utils::displayRect_.height_, static_cast(utils::displayRect_.width_ * RATIO)); + WindowManager::GetInstance().RegisterSystemBarChangedListener(testSystemBarChangedListener_); activeWindows_.clear(); } @@ -151,16 +211,7 @@ namespace { */ HWTEST_F(WindowImmersiveTest, ImmersiveTest01, Function | MediumTest | Level3) { - utils::TestWindowInfo info = { - .name = "main", - .rect = utils::defaultAppRect_, - .type = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, - .mode = WindowMode::WINDOW_MODE_FULLSCREEN, // immersive setting - .needAvoid = false, // immersive setting - .parentLimit = false, - .parentName = "", - }; - const sptr& window = utils::CreateTestWindow(info); + const sptr& window = utils::CreateTestWindow(fullScreenAppinfo_); activeWindows_.push_back(window); SetWindowSystemProps(window, TEST_PROPS_1); ASSERT_EQ(WMError::WM_OK, window->Show()); @@ -177,20 +228,11 @@ HWTEST_F(WindowImmersiveTest, ImmersiveTest01, Function | MediumTest | Level3) */ HWTEST_F(WindowImmersiveTest, ImmersiveTest02, Function | MediumTest | Level3) { - utils::TestWindowInfo info = { - .name = "main", - .rect = utils::defaultAppRect_, - .type = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, - .mode = WindowMode::WINDOW_MODE_FULLSCREEN, // immersive setting - .needAvoid = false, // immersive setting - .parentLimit = false, - .parentName = "", - }; - const sptr& window1 = utils::CreateTestWindow(info); + const sptr& window1 = utils::CreateTestWindow(fullScreenAppinfo_); activeWindows_.push_back(window1); SetWindowSystemProps(window1, TEST_PROPS_1); - info.name = "main2"; - const sptr& window2 = utils::CreateTestWindow(info); + fullScreenAppinfo_.name = "main2"; + const sptr& window2 = utils::CreateTestWindow(fullScreenAppinfo_); activeWindows_.push_back(window2); SetWindowSystemProps(window2, TEST_PROPS_2); ASSERT_EQ(WMError::WM_OK, window1->Show()); @@ -212,21 +254,12 @@ HWTEST_F(WindowImmersiveTest, ImmersiveTest02, Function | MediumTest | Level3) */ HWTEST_F(WindowImmersiveTest, ImmersiveTest03, Function | MediumTest | Level3) { - utils::TestWindowInfo info = { - .name = "main", - .rect = utils::defaultAppRect_, - .type = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, - .mode = WindowMode::WINDOW_MODE_FULLSCREEN, // immersive setting - .needAvoid = false, // immersive setting - .parentLimit = false, - .parentName = "", - }; - const sptr& window1 = utils::CreateTestWindow(info); + const sptr& window1 = utils::CreateTestWindow(fullScreenAppinfo_); activeWindows_.push_back(window1); SetWindowSystemProps(window1, TEST_PROPS_1); - info.name = "main2"; - info.needAvoid = true; // no immersive setting - const sptr& window2 = utils::CreateTestWindow(info); + fullScreenAppinfo_.name = "main2"; + fullScreenAppinfo_.needAvoid = true; // no immersive setting + const sptr& window2 = utils::CreateTestWindow(fullScreenAppinfo_); activeWindows_.push_back(window2); SetWindowSystemProps(window2, TEST_PROPS_2); ASSERT_EQ(WMError::WM_OK, window1->Show()); @@ -236,6 +269,163 @@ HWTEST_F(WindowImmersiveTest, ImmersiveTest03, Function | MediumTest | Level3) ASSERT_EQ(WMError::WM_OK, window1->Hide()); ASSERT_TRUE(SystemBarPropsEqualsTo(TEST_PROPS_DEFAULT)); } + +/** + * @tc.name: GetAvoidAreaByTypeTest01 + * @tc.desc: Test GetAvoidArea use unsupport Type(TYPE_CUTOUT). + * @tc.type: FUNC + * @tc.require: AR000GGTVD + */ +HWTEST_F(WindowImmersiveTest, GetAvoidAreaByTypeTest01, Function | MediumTest | Level3) +{ + // Add full screenwindow for call GetAvoidArea, and push_back in activeWindows_ + const sptr& win = utils::CreateTestWindow(fullScreenAppinfo_); + activeWindows_.push_back(win); + + // Test GetAvoidArea + AvoidArea avoidarea; + WMError ret = win->GetAvoidAreaByType(AvoidAreaType::TYPE_CUTOUT, avoidarea); + ASSERT_EQ(WMError::WM_OK, ret); + ASSERT_TRUE(utils::RectEqualToRect(EMPTY_RECT, avoidarea.leftRect)); + ASSERT_TRUE(utils::RectEqualToRect(EMPTY_RECT, avoidarea.rightRect)); + ASSERT_TRUE(utils::RectEqualToRect(EMPTY_RECT, avoidarea.topRect)); + ASSERT_TRUE(utils::RectEqualToRect(EMPTY_RECT, avoidarea.bottomRect)); +} + +/** + * @tc.name: GetAvoidAreaByTypeTest02 + * @tc.desc: Add SystemBar left avoid. And Test GetAvoidArea. + * @tc.type: FUNC + * @tc.require: AR000GGTVD + */ +HWTEST_F(WindowImmersiveTest, GetAvoidAreaByTypeTest02, Function | MediumTest | Level3) +{ + // Add full screenwindow for call GetAvoidArea, and push_back in activeWindows_ + const sptr& win = utils::CreateTestWindow(fullScreenAppinfo_); + activeWindows_.push_back(win); + + // Add a unexist leftAvoid + avoidBarInfo_.rect = {0, 0, leftAvoidW_, leftAvoidH_}; + const sptr& left = utils::CreateTestWindow(avoidBarInfo_); + activeWindows_.push_back(left); + ASSERT_EQ(WMError::WM_OK, left->Show()); + ASSERT_EQ(WMError::WM_OK, left->Resize(leftAvoidW_, leftAvoidH_)); + + // Test GetAvoidArea + AvoidArea avoidarea; + WMError ret = win->GetAvoidAreaByType(AvoidAreaType::TYPE_SYSTEM, avoidarea); + ASSERT_EQ(WMError::WM_OK, ret); + ASSERT_TRUE(utils::RectEqualTo(left, avoidarea.leftRect)); +} + +/** + * @tc.name: GetAvoidAreaByTypeTest03 + * @tc.desc: Add SystemBar top avoid. And Test GetAvoidArea. + * @tc.type: FUNC + * @tc.require: AR000GGTVD + */ +HWTEST_F(WindowImmersiveTest, GetAvoidAreaByTypeTest03, Function | MediumTest | Level3) +{ + // Add full screenwindow for call GetAvoidArea, and push_back in activeWindows_ + const sptr& win = utils::CreateTestWindow(fullScreenAppinfo_); + activeWindows_.push_back(win); + + // Add a unexist topAvoid + avoidBarInfo_.name = "TopAvoidTest"; + avoidBarInfo_.rect = {0, 0, topAvoidW_, topAvoidH_}; + const sptr& top = utils::CreateTestWindow(avoidBarInfo_); + activeWindows_.push_back(top); + ASSERT_EQ(WMError::WM_OK, top->Show()); + ASSERT_EQ(WMError::WM_OK, top->Resize(topAvoidW_, topAvoidH_)); + + // Tesr GetAvoidArea + AvoidArea avoidarea; + WMError ret = win->GetAvoidAreaByType(AvoidAreaType::TYPE_SYSTEM, avoidarea); + ASSERT_EQ(WMError::WM_OK, ret); + ASSERT_TRUE(utils::RectEqualTo(top, avoidarea.topRect)); +} + +/** + * @tc.name: OnAvoidAreaChangedTest01 + * @tc.desc: Add unexistavoid and Update this avoid. Test OnAvoidAreaChanged listener + * @tc.type: FUNC + * @tc.require: AR000GGTVD + */ +HWTEST_F(WindowImmersiveTest, OnAvoidAreaChangedTest01, Function | MediumTest | Level3) +{ + // Add full screenwindow for RegisterAvoidAreaChangeListener + const sptr& window = utils::CreateTestWindow(fullScreenAppinfo_); + sptr thisListener(testAvoidAreaChangedListener_); + window->RegisterAvoidAreaChangeListener(thisListener); + activeWindows_.push_back(window); + ASSERT_EQ(WMError::WM_OK, window->Show()); + + // Add a unexist topAvoid + avoidBarInfo_.name = "TopAvoidTest"; + avoidBarInfo_.rect = {0, 0, topAvoidW_, topAvoidH_}; + const sptr& top = utils::CreateTestWindow(avoidBarInfo_); + activeWindows_.push_back(top); + ASSERT_EQ(WMError::WM_OK, top->Show()); + ASSERT_EQ(WMError::WM_OK, top->Resize(topAvoidW_, topAvoidH_)); + + // Await 100ms and get callback result in listener. Compare current avoidArea + usleep(WAIT_ASYNC_US); + std::vector avoidArea = testAvoidAreaChangedListener_->avoidAreas_; + ASSERT_EQ(4u, static_cast(avoidArea.size())); // 4: avoidAreaNum(left, top, right, bottom) + ASSERT_TRUE(utils::RectEqualToRect(avoidBarInfo_.rect, avoidArea[1])); // 1: left Rect + + // Update topavoid. Enlarge topAvoidH_ + uint32_t bigHeight = std::min(static_cast(utils::displayRect_.height_), + static_cast(utils::displayRect_.width_ * 0.5)); // 0.5 : just use bigger height for update + Rect bigTopRect = {0, 0, topAvoidW_, bigHeight}; + ASSERT_EQ(WMError::WM_OK, top->Resize(topAvoidW_, bigHeight)); + + // Await 100ms and get callback result in listener. Compare current avoidArea + usleep(WAIT_ASYNC_US); + std::vector avoidArea2 = testAvoidAreaChangedListener_->avoidAreas_; + ASSERT_TRUE(utils::RectEqualToRect(bigTopRect, avoidArea2[1])); + + window->UnregisterAvoidAreaChangeListener(); +} + +/** + * @tc.name: OnAvoidAreaChangedTest02 + * @tc.desc: Add unexistavoid and remove this avoid. Test OnAvoidAreaChanged listener + * @tc.type: FUNC + * @tc.require: AR000GGTVD + */ +HWTEST_F(WindowImmersiveTest, OnAvoidAreaChangedTest02, Function | MediumTest | Level3) +{ + // Add full screenwindow for call UpdateAvoidChange + const sptr& window = utils::CreateTestWindow(fullScreenAppinfo_); + sptr thisListener(testAvoidAreaChangedListener_); + window->RegisterAvoidAreaChangeListener(thisListener); + activeWindows_.push_back(window); + ASSERT_EQ(WMError::WM_OK, window->Show()); + + // Add a unexist leftAvoid + avoidBarInfo_.rect = {0, 0, leftAvoidW_, leftAvoidH_}; + const sptr& left = utils::CreateTestWindow(avoidBarInfo_); + activeWindows_.push_back(left); + ASSERT_EQ(WMError::WM_OK, left->Show()); + ASSERT_EQ(WMError::WM_OK, left->Resize(leftAvoidW_, leftAvoidH_)); + + // Await 100ms and get callback result in listener. Compare current avoidArea + usleep(WAIT_ASYNC_US); + std::vector avoidArea = testAvoidAreaChangedListener_->avoidAreas_; + ASSERT_EQ(4u, static_cast(avoidArea.size())); // 4: avoidAreaNum(left, top, right, bottom) + ASSERT_TRUE(utils::RectEqualToRect(avoidBarInfo_.rect, avoidArea[0])); // 0: left Rect + + // Remove left avoid. + ASSERT_EQ(WMError::WM_OK, left->Hide()); + + // Await 100ms and get callback result in listener. Compare current avoidArea + usleep(WAIT_ASYNC_US); + std::vector avoidArea2 = testAvoidAreaChangedListener_->avoidAreas_; + ASSERT_TRUE(utils::RectEqualToRect(EMPTY_RECT, avoidArea2[0])); // 0: left Rect + + window->UnregisterAvoidAreaChangeListener(); +} } } // namespace Rosen } // namespace OHOS diff --git a/wm/test/systemtest/window_test_utils.cpp b/wm/test/systemtest/window_test_utils.cpp index 111bd2c055..ed5d0a0946 100644 --- a/wm/test/systemtest/window_test_utils.cpp +++ b/wm/test/systemtest/window_test_utils.cpp @@ -17,6 +17,10 @@ #include namespace OHOS { namespace Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowTestUtils"}; +} + Rect WindowTestUtils::displayRect_ = {0, 0, 0, 0}; Rect WindowTestUtils::statusBarRect_ = {0, 0, 0, 0}; Rect WindowTestUtils::naviBarRect_ = {0, 0, 0, 0}; @@ -27,6 +31,7 @@ SplitRects WindowTestUtils::splitRects_ = { .secondaryRect = {0, 0, 0, 0}, .dividerRect = {0, 0, 0, 0}, }; + bool WindowTestUtils::isVerticalDisplay_ = false; sptr WindowTestUtils::CreateTestWindow(const TestWindowInfo& info) @@ -105,7 +110,19 @@ bool WindowTestUtils::RectEqualTo(const sptr& window, const Rect& r) Rect l = window->GetRect(); bool res = ((l.posX_ == r.posX_) && (l.posY_ == r.posY_) && (l.width_ == r.width_) && (l.height_ == r.height_)); if (!res) { - printf("GetLayoutRect: %d %d %d %d, Expect: %d %d %d %d\n", l.posX_, l.posY_, l.width_, l.height_, + WLOGFE("GetLayoutRect: %{public}d %{public}d %{public}d %{public}d, " \ + "Expect: %{public}d %{public}d %{public}d %{public}d", l.posX_, l.posY_, l.width_, l.height_, + r.posX_, r.posY_, r.width_, r.height_); + } + return res; +} + +bool WindowTestUtils::RectEqualToRect(const Rect& l, const Rect& r) +{ + bool res = ((l.posX_ == r.posX_) && (l.posY_ == r.posY_) && (l.width_ == r.width_) && (l.height_ == r.height_)); + if (!res) { + WLOGFE("GetLayoutRect: %{public}d %{public}d %{public}d %{public}d, " \ + "Expect: %{public}d %{public}d %{public}d %{public}d", l.posX_, l.posY_, l.width_, l.height_, r.posX_, r.posY_, r.width_, r.height_); } return res; @@ -133,10 +150,10 @@ void WindowTestUtils::InitSplitRects() { auto display = DisplayManager::GetInstance().GetDisplayById(0); if (display == nullptr) { - printf("GetDefaultDisplay: failed!\n"); + WLOGFE("GetDefaultDisplay: failed!"); } else { - printf("GetDefaultDisplay: id %llu, w %d, h %d, fps %u\n", display->GetId(), display->GetWidth(), - display->GetHeight(), display->GetFreshRate()); + WLOGFI("GetDefaultDisplay: id %{public}" PRIu64", w %{public}d, h %{public}d, fps %{public}u", + display->GetId(), display->GetWidth(), display->GetHeight(), display->GetFreshRate()); } Rect displayRect = {0, 0, display->GetWidth(), display->GetHeight()}; @@ -165,7 +182,7 @@ void WindowTestUtils::UpdateSplitRects(const sptr& window) std::unique_ptr testUtils = std::make_unique(); auto res = window->GetAvoidAreaByType(AvoidAreaType::TYPE_SYSTEM, testUtils->avoidArea_); if (res != WMError::WM_OK) { - printf("Get avoid type failed\n"); + WLOGFE("Get avoid type failed"); } testUtils->UpdateLimitDisplayRect(testUtils->avoidArea_.leftRect); testUtils->UpdateLimitDisplayRect(testUtils->avoidArea_.topRect); @@ -212,7 +229,7 @@ void WindowTestUtils::UpdateLimitDisplayRect(Rect& avoidRect) limitDisplayRect_.width_ -= offsetW; break; default: - printf("invaild avoidPosType: %d\n", avoidPosType); + WLOGFE("invaild avoidPosType: %{public}d", avoidPosType); } } diff --git a/wm/test/systemtest/window_test_utils.h b/wm/test/systemtest/window_test_utils.h index f647b6c636..d39271df40 100644 --- a/wm/test/systemtest/window_test_utils.h +++ b/wm/test/systemtest/window_test_utils.h @@ -59,6 +59,7 @@ public: static bool RectEqualTo(const sptr& window, const Rect& r); static void InitSplitRects(); static void UpdateSplitRects(const sptr& window); + static bool RectEqualToRect(const Rect& l, const Rect& r); private: void UpdateLimitDisplayRect(Rect& avoidRect); diff --git a/wm/test/unittest/BUILD.gn b/wm/test/unittest/BUILD.gn index fc996b04a0..4a0136bde3 100644 --- a/wm/test/unittest/BUILD.gn +++ b/wm/test/unittest/BUILD.gn @@ -18,6 +18,7 @@ group("unittest") { testonly = true deps = [ + ":avoid_area_controller_test", ":wm_input_transfer_station_test", ":wm_window_impl_test", ":wm_window_input_channel_test", @@ -28,6 +29,17 @@ group("unittest") { ] } +## UnitTest avoid_area_controller_test {{{ +ohos_unittest("avoid_area_controller_test") { + module_out_path = module_out_path + + sources = [ "avoid_area_controller_test.cpp" ] + + deps = [ ":wm_unittest_common" ] +} + +## UnitTest avoid_area_controller_test }}} + ## UnitTest wm_window_impl_test {{{ ohos_unittest("wm_window_impl_test") { module_out_path = module_out_path diff --git a/wm/test/unittest/avoid_area_controller_test.cpp b/wm/test/unittest/avoid_area_controller_test.cpp new file mode 100644 index 0000000000..f1812f0adf --- /dev/null +++ b/wm/test/unittest/avoid_area_controller_test.cpp @@ -0,0 +1,403 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "avoid_area_controller_test.h" +#include "avoid_area_controller.h" +#include "display_manager.h" +#include "mock_window_adapter.h" +#include "singleton_mocker.h" +#include "window_node.h" + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { +namespace Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "AvoidAreaControllerTest"}; + + const Rect EMPTY_RECT = {0, 0, 0, 0}; + const uint32_t LEFT = 0; + const uint32_t TOP = 1; + const uint32_t RIGHT = 2; + const uint32_t BOTTOM = 3; + const float BARRATIO = 0.3; +} + +Rect AvoidAreaControllerTest::topAvoidRect_ = EMPTY_RECT; +Rect AvoidAreaControllerTest::leftAvoidRect_ = EMPTY_RECT; + +static bool RectEqualToRect(const Rect& l, const Rect& r) +{ + bool res = ((l.posX_ == r.posX_) && (l.posY_ == r.posY_) && (l.width_ == r.width_) && (l.height_ == r.height_)); + if (!res) { + WLOGFE(" [ x y w h]"); + WLOGFE("Expect:%{public}4d %{public}4d %{public}4u %{public}4u ", l.posX_, l.posY_, l.width_, l.height_); + WLOGFE("Get: %{public}4d %{public}4d %{public}4u %{public}4u ", r.posX_, r.posY_, r.width_, r.height_); + } + return res; +} + +void AvoidAreaControllerTest::InitByScreenRect(const Rect& screenRect) +{ + topAvoidRect_ = {0, 0, screenRect.width_, + std::min(static_cast(screenRect.height_), static_cast(screenRect.width_ * BARRATIO))}; + // make sure leftAvoidRect h > w and w < screen.width. And use a bigger ratio to cover origin topAvoid + leftAvoidRect_ = {0, 0, + std::min(static_cast(screenRect.width_), static_cast(screenRect.height_ * BARRATIO)), + screenRect.height_}; +} + +void AvoidAreaControllerTest::SetUpTestCase() +{ + auto display = DisplayManager::GetInstance().GetDisplayById(0); + if (display == nullptr) { + WLOGFE("GetDefaultDisplay: failed!"); + } else { + WLOGFI("GetDefaultDisplay: id %{public}" PRIu64", w %{public}d, h %{public}d, fps %{public}u", + display->GetId(), display->GetWidth(), display->GetHeight(), display->GetFreshRate()); + } + Rect screenRect = {0, 0, display->GetWidth(), display->GetHeight()}; + AvoidAreaControllerTest::InitByScreenRect(screenRect); +} + +void AvoidAreaControllerTest::TearDownTestCase() +{ +} + +void AvoidAreaControllerTest::SetUp() +{ +} + +void AvoidAreaControllerTest::TearDown() +{ +} + +namespace { +/** + * @tc.name: IsAvoidAreaNode01 + * @tc.desc: Create a APP Window. Test IsAvoidAreaNode + * @tc.type: FUNC + * @tc.require: AR000GGTVD + */ +HWTEST_F(AvoidAreaControllerTest, IsAvoidAreaNode01, Function | SmallTest | Level2) +{ + auto avoidAreaController = new AvoidAreaController(nullptr); + + sptr node = new WindowNode(); + sptr property = new WindowProperty(); + property->SetWindowId(100u); + property->SetWindowType(WindowType::APP_WINDOW_BASE); + node->SetWindowProperty(property); + + ASSERT_EQ(false, avoidAreaController->IsAvoidAreaNode(node)); +} + +/** + * @tc.name: IsAvoidAreaNode02 + * @tc.desc: Create a Status Bar Window. Test IsAvoidAreaNode + * @tc.type: FUNC + * @tc.require: AR000GGTVD + */ +HWTEST_F(AvoidAreaControllerTest, IsAvoidAreaNode02, Function | SmallTest | Level2) +{ + auto avoidAreaController = new AvoidAreaController(nullptr); + + sptr node = new WindowNode(); + sptr property = new WindowProperty(); + property->SetWindowType(WindowType::WINDOW_TYPE_STATUS_BAR); + node->SetWindowProperty(property); + + ASSERT_TRUE(avoidAreaController->IsAvoidAreaNode(node)); +} + +/** + * @tc.name: AddAvoidAreaNode01 + * @tc.desc: Add a new avoid area Node + * @tc.type: FUNC + * @tc.require: AR000GGTVD + */ +HWTEST_F(AvoidAreaControllerTest, AddAvoidAreaNode01, Function | SmallTest | Level2) +{ + sptr node = new WindowNode(); + + sptr property = new WindowProperty(); + property->SetWindowId(100u); + property->SetWindowType(WindowType::WINDOW_TYPE_STATUS_BAR); + node->SetWindowProperty(property); + node->SetLayoutRect(topAvoidRect_); + + sptr avoidAreaController = new AvoidAreaController(nullptr); + ASSERT_EQ(WMError::WM_OK, avoidAreaController->AddAvoidAreaNode(node)); +} + +/** + * @tc.name: AddAvoidAreaNode02 + * @tc.desc: Add a exist avoid area Node + * @tc.type: FUNC + * @tc.require: AR000GGTVD + */ +HWTEST_F(AvoidAreaControllerTest, AddAvoidAreaNode02, Function | SmallTest | Level2) +{ + sptr avoidAreaController = new AvoidAreaController(nullptr); + + sptr node1 = new WindowNode(); + sptr property1 = new WindowProperty(); + property1->SetWindowId(100u); + property1->SetWindowType(WindowType::WINDOW_TYPE_STATUS_BAR); + property1->SetWindowRect(topAvoidRect_); + node1->SetWindowProperty(property1); + node1->SetLayoutRect(topAvoidRect_); + ASSERT_EQ(WMError::WM_OK, avoidAreaController->AddAvoidAreaNode(node1)); + + sptr node2 = new WindowNode(); + sptr property2 = new WindowProperty(); + property2->SetWindowId(100u); + property2->SetWindowType(WindowType::WINDOW_TYPE_STATUS_BAR); + node2->SetWindowProperty(property2); + node2->SetLayoutRect(topAvoidRect_); + ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, avoidAreaController->AddAvoidAreaNode(node2)); +} + +/** + * @tc.name: AddAvoidAreaNode03 + * @tc.desc: Add two new avoid area Nodes + * @tc.type: FUNC + * @tc.require: AR000GGTVD + */ +HWTEST_F(AvoidAreaControllerTest, AddAvoidAreaNode03, Function | SmallTest | Level2) +{ + sptr avoidAreaController = new AvoidAreaController(nullptr); + + sptr node1 = new WindowNode(); + sptr property1 = new WindowProperty(); + property1->SetWindowId(100u); + property1->SetWindowType(WindowType::WINDOW_TYPE_STATUS_BAR); + node1->SetWindowProperty(property1); + node1->SetLayoutRect(topAvoidRect_); + ASSERT_EQ(WMError::WM_OK, avoidAreaController->AddAvoidAreaNode(node1)); + + sptr node2 = new WindowNode(); + sptr property2 = new WindowProperty(); + property2->SetWindowId(101u); + property2->SetWindowType(WindowType::WINDOW_TYPE_STATUS_BAR); + node2->SetWindowProperty(property2); + node2->SetLayoutRect(leftAvoidRect_); + ASSERT_EQ(WMError::WM_OK, avoidAreaController->AddAvoidAreaNode(node2)); +} + +/** + * @tc.name: RemoveAvoidAreaNode01 + * @tc.desc: Add a new avoid area. And Remove this. + * @tc.type: FUNC + * @tc.require: AR000GGTVD + */ +HWTEST_F(AvoidAreaControllerTest, RemoveAvoidAreaNode01, Function | SmallTest | Level2) +{ + sptr avoidAreaController = new AvoidAreaController(nullptr); + + sptr node1 = new WindowNode(); + sptr property1 = new WindowProperty(); + property1->SetWindowId(100u); + property1->SetWindowType(WindowType::WINDOW_TYPE_STATUS_BAR); + node1->SetWindowProperty(property1); + node1->SetLayoutRect(leftAvoidRect_); + ASSERT_EQ(WMError::WM_OK, avoidAreaController->AddAvoidAreaNode(node1)); + + ASSERT_EQ(WMError::WM_OK, avoidAreaController->RemoveAvoidAreaNode(node1)); +} + +/** + * @tc.name: RemoveAvoidAreaNode02 + * @tc.desc: Remove a unexist avoid area. + * @tc.type: FUNC + * @tc.require: AR000GGTVD + */ +HWTEST_F(AvoidAreaControllerTest, RemoveAvoidAreaNode02, Function | SmallTest | Level2) +{ + sptr avoidAreaController = new AvoidAreaController(nullptr); + + sptr node = new WindowNode(); + sptr property = new WindowProperty(); + property->SetWindowId(100u); + property->SetWindowType(WindowType::WINDOW_TYPE_STATUS_BAR); + node->SetLayoutRect(topAvoidRect_); + node->SetWindowProperty(property); + ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, avoidAreaController->RemoveAvoidAreaNode(node)); +} + +/** + * @tc.name: UpdateAvoidAreaNode01 + * @tc.desc: Add a new avoid area node and update this + * @tc.type: FUNC + * @tc.require: AR000GGTVD + */ +HWTEST_F(AvoidAreaControllerTest, UpdateAvoidAreaNode01, Function | SmallTest | Level2) +{ + sptr avoidAreaController = new AvoidAreaController(nullptr); + + sptr node = new WindowNode(); + sptr property = new WindowProperty(); + property->SetWindowId(100u); + property->SetWindowType(WindowType::WINDOW_TYPE_STATUS_BAR); + node->SetWindowProperty(property); + node->SetLayoutRect(topAvoidRect_); + ASSERT_EQ(WMError::WM_OK, avoidAreaController->AddAvoidAreaNode(node)); + + property->SetWindowRect(leftAvoidRect_); + ASSERT_EQ(WMError::WM_OK, avoidAreaController->UpdateAvoidAreaNode(node)); +} + +/** + * @tc.name: UpdateAvoidAreaNode02 + * @tc.desc: update a unexist avoid area node + * @tc.type: FUNC + * @tc.require: AR000GGTVD + */ +HWTEST_F(AvoidAreaControllerTest, UpdateAvoidAreaNode02, Function | SmallTest | Level2) +{ + sptr avoidAreaController = new AvoidAreaController(nullptr); + + sptr node = new WindowNode(); + sptr property = new WindowProperty(); + property->SetWindowId(100u); + property->SetWindowType(WindowType::WINDOW_TYPE_STATUS_BAR); + node->SetWindowProperty(property); + node->SetLayoutRect(topAvoidRect_); + + ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, avoidAreaController->UpdateAvoidAreaNode(node)); +} + +/** + * @tc.name: GetAvoidArea01 + * @tc.desc: GetAvoidArea + * @tc.type: FUNC + * @tc.require: AR000GGTVD + */ +HWTEST_F(AvoidAreaControllerTest, GetAvoidArea01, Function | SmallTest | Level2) +{ + sptr avoidAreaController = new AvoidAreaController(nullptr); + + std::vector avoidArea = avoidAreaController->GetAvoidArea(); + ASSERT_EQ(4u, static_cast(avoidArea.size())); + ASSERT_TRUE(RectEqualToRect(EMPTY_RECT, avoidArea[LEFT])); + ASSERT_TRUE(RectEqualToRect(EMPTY_RECT, avoidArea[TOP])); + ASSERT_TRUE(RectEqualToRect(EMPTY_RECT, avoidArea[RIGHT])); + ASSERT_TRUE(RectEqualToRect(EMPTY_RECT, avoidArea[BOTTOM])); +} + +/** + * @tc.name: GetAvoidArea02 + * @tc.desc: Add a new node. And GetAvoidArea + * @tc.type: FUNC + * @tc.require: AR000GGTVD + */ +HWTEST_F(AvoidAreaControllerTest, GetAvoidArea02, Function | SmallTest | Level2) +{ + sptr avoidAreaController = new AvoidAreaController(nullptr); + + sptr node = new WindowNode(); + sptr property = new WindowProperty(); + property->SetWindowId(100u); + property->SetWindowType(WindowType::WINDOW_TYPE_STATUS_BAR); + node->SetWindowProperty(property); + node->SetLayoutRect(topAvoidRect_); + ASSERT_EQ(WMError::WM_OK, avoidAreaController->AddAvoidAreaNode(node)); + + std::vector avoidArea = avoidAreaController->GetAvoidArea(); + ASSERT_EQ(4u, static_cast(avoidArea.size())); + ASSERT_TRUE(RectEqualToRect(EMPTY_RECT, avoidArea[LEFT])); + ASSERT_TRUE(RectEqualToRect(topAvoidRect_, avoidArea[TOP])); + ASSERT_TRUE(RectEqualToRect(EMPTY_RECT, avoidArea[RIGHT])); + ASSERT_TRUE(RectEqualToRect(EMPTY_RECT, avoidArea[BOTTOM])); +} + +/** + * @tc.name: GetAvoidArea03 + * @tc.desc: Add a new node. Update this node. And GetAvoidArea + * @tc.type: FUNC + * @tc.require: AR000GGTVD + */ +HWTEST_F(AvoidAreaControllerTest, GetAvoidArea03, Function | SmallTest | Level2) +{ + sptr avoidAreaController = new AvoidAreaController(nullptr); + + sptr node = new WindowNode(); + sptr property = new WindowProperty(); + property->SetWindowId(100u); + property->SetWindowType(WindowType::WINDOW_TYPE_STATUS_BAR); + node->SetWindowProperty(property); + node->SetLayoutRect(topAvoidRect_); + ASSERT_EQ(WMError::WM_OK, avoidAreaController->AddAvoidAreaNode(node)); + + node->SetLayoutRect(leftAvoidRect_); + ASSERT_EQ(WMError::WM_OK, avoidAreaController->UpdateAvoidAreaNode(node)); + + std::vector avoidArea = avoidAreaController->GetAvoidArea(); + ASSERT_EQ(4u, static_cast(avoidArea.size())); + ASSERT_TRUE(RectEqualToRect(leftAvoidRect_, avoidArea[LEFT])); + ASSERT_TRUE(RectEqualToRect(EMPTY_RECT, avoidArea[TOP])); + ASSERT_TRUE(RectEqualToRect(EMPTY_RECT, avoidArea[RIGHT])); + ASSERT_TRUE(RectEqualToRect(EMPTY_RECT, avoidArea[BOTTOM])); +} + +/** + * @tc.name: GetAvoidAreaByType01 + * @tc.desc: Search a unexist AvoidAreaType. And GetAvoidAreaByType + * @tc.type: FUNC + * @tc.require: AR000GGTVD + */ +HWTEST_F(AvoidAreaControllerTest, GetAvoidAreaByType01, Function | SmallTest | Level2) +{ + sptr avoidAreaController = new AvoidAreaController(nullptr); + + std::vector avoidArea = avoidAreaController->GetAvoidAreaByType(AvoidAreaType::TYPE_CUTOUT); + + ASSERT_EQ(4u, static_cast(avoidArea.size())); + ASSERT_TRUE(RectEqualToRect(EMPTY_RECT, avoidArea[LEFT])); + ASSERT_TRUE(RectEqualToRect(EMPTY_RECT, avoidArea[TOP])); + ASSERT_TRUE(RectEqualToRect(EMPTY_RECT, avoidArea[RIGHT])); + ASSERT_TRUE(RectEqualToRect(EMPTY_RECT, avoidArea[BOTTOM])); +} + +/** + * @tc.name: GetAvoidAreaByType02 + * @tc.desc: Search a unexist AvoidAreaType. And GetAvoidAreaByType + * @tc.type: FUNC + * @tc.require: AR000GGTVD + */ +HWTEST_F(AvoidAreaControllerTest, GetAvoidAreaByType02, Function | SmallTest | Level2) +{ + sptr avoidAreaController = new AvoidAreaController(nullptr); + + sptr node = new WindowNode(); + sptr property = new WindowProperty(); + property->SetWindowId(100u); + property->SetWindowType(WindowType::WINDOW_TYPE_STATUS_BAR); + node->SetWindowProperty(property); + node->SetLayoutRect(topAvoidRect_); + ASSERT_EQ(WMError::WM_OK, avoidAreaController->AddAvoidAreaNode(node)); + + std::vector avoidArea = avoidAreaController->GetAvoidAreaByType(AvoidAreaType::TYPE_SYSTEM); + + ASSERT_EQ(4u, static_cast(avoidArea.size())); + ASSERT_TRUE(RectEqualToRect(EMPTY_RECT, avoidArea[LEFT])); + ASSERT_TRUE(RectEqualToRect(topAvoidRect_, avoidArea[TOP])); + ASSERT_TRUE(RectEqualToRect(EMPTY_RECT, avoidArea[RIGHT])); + ASSERT_TRUE(RectEqualToRect(EMPTY_RECT, avoidArea[BOTTOM])); +} +} +} // namespace Rosen +} // namespace OHOS diff --git a/wm/test/unittest/avoid_area_controller_test.h b/wm/test/unittest/avoid_area_controller_test.h new file mode 100644 index 0000000000..d1126424e0 --- /dev/null +++ b/wm/test/unittest/avoid_area_controller_test.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FRAMEWORKS_WM_TEST_UT_AVOID_AREA_CONTROLLER_TEST_H +#define FRAMEWORKS_WM_TEST_UT_AVOID_AREA_CONTROLLER_TEST_H + +#include +#include "wm_common.h" + +namespace OHOS { +namespace Rosen { +class AvoidAreaControllerTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + virtual void SetUp() override; + virtual void TearDown() override; + + static Rect topAvoidRect_; + static Rect leftAvoidRect_; + +private: + static void InitByScreenRect(const Rect& screenRect); +}; +} // namespace ROSEN +} // namespace OHOS + +#endif // FRAMEWORKS_WM_TEST_UT_AVOID_AREA_CONTROLLER_TEST_H \ No newline at end of file -- Gitee From 0049897144d3f61454a191a6f6f30e12ef49c677 Mon Sep 17 00:00:00 2001 From: njupthan Date: Wed, 19 Jan 2022 08:42:24 +0000 Subject: [PATCH 36/57] Fix atomic ability part name change Signed-off-by: njupthan --- interfaces/innerkits/wm/window.h | 2 +- interfaces/kits/napi/screenshot/BUILD.gn | 2 +- interfaces/kits/napi/window/BUILD.gn | 2 +- interfaces/kits/napi/window_runtime/BUILD.gn | 8 ++++---- wm/BUILD.gn | 5 +++-- wm/test/systemtest/BUILD.gn | 2 +- wm/test/unittest/BUILD.gn | 2 +- 7 files changed, 12 insertions(+), 11 deletions(-) diff --git a/interfaces/innerkits/wm/window.h b/interfaces/innerkits/wm/window.h index 09493ff2d7..70f6b416ce 100644 --- a/interfaces/innerkits/wm/window.h +++ b/interfaces/innerkits/wm/window.h @@ -24,7 +24,7 @@ #include #include #include -#include "foundation/appexecfwk/standard/kits/appkit/native/ability_runtime/context/context.h" +#include "foundation/aafwk/standard/frameworks/kits/appkit/native/ability_runtime/context/context.h" #include "wm_common.h" #include "window_option.h" #include "window_life_cycle_interface.h" diff --git a/interfaces/kits/napi/screenshot/BUILD.gn b/interfaces/kits/napi/screenshot/BUILD.gn index 4fddfe6d1e..53726a5139 100644 --- a/interfaces/kits/napi/screenshot/BUILD.gn +++ b/interfaces/kits/napi/screenshot/BUILD.gn @@ -24,7 +24,7 @@ ohos_shared_library("screenshot") { ] external_deps = [ - "aafwk_standard:runtime", + "ability_runtime:runtime", "hiviewdfx_hilog_native:libhilog", "napi:ace_napi", "window_manager:libwm", diff --git a/interfaces/kits/napi/window/BUILD.gn b/interfaces/kits/napi/window/BUILD.gn index 449bfb7fb4..93c5e88f38 100644 --- a/interfaces/kits/napi/window/BUILD.gn +++ b/interfaces/kits/napi/window/BUILD.gn @@ -28,7 +28,7 @@ ohos_shared_library("window") { deps = [ "../common:wm_napi_common", "//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native", - "//foundation/appexecfwk/standard/kits:appkit_native", + "//foundation/aafwk/standard/frameworks/kits/appkit:appkit_native", "//foundation/windowmanager/wm:libwm", "//foundation/windowmanager/wmserver:libwms", ] diff --git a/interfaces/kits/napi/window_runtime/BUILD.gn b/interfaces/kits/napi/window_runtime/BUILD.gn index 6ba32f61cb..71420a23eb 100644 --- a/interfaces/kits/napi/window_runtime/BUILD.gn +++ b/interfaces/kits/napi/window_runtime/BUILD.gn @@ -52,7 +52,7 @@ ohos_shared_library("window_native_kit") { ] external_deps = [ - "aafwk_standard:runtime", + "ability_runtime:runtime", "hiviewdfx_hilog_native:libhilog", "napi:ace_napi", ] @@ -71,15 +71,15 @@ ohos_shared_library("windowmanager_napi") { deps = [ ":window_native_kit", "//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native", - "//foundation/appexecfwk/standard/kits:app_context", - "//foundation/appexecfwk/standard/kits:appkit_native", + "//foundation/aafwk/standard/frameworks/kits/appkit:app_context", + "//foundation/aafwk/standard/frameworks/kits/appkit:appkit_native", "//foundation/windowmanager/utils:libwmutil", "//foundation/windowmanager/wm:libwm", "//foundation/windowmanager/wmserver:libwms", ] external_deps = [ - "aafwk_standard:runtime", + "ability_runtime:runtime", "hiviewdfx_hilog_native:libhilog", "napi:ace_napi", ] diff --git a/wm/BUILD.gn b/wm/BUILD.gn index b76389b08f..d2874a7821 100644 --- a/wm/BUILD.gn +++ b/wm/BUILD.gn @@ -26,6 +26,7 @@ config("libwm_config") { # for abilityContext "//foundation/aafwk/standard/frameworks/kits/ability/ability_runtime/include", + "//foundation/aafwk/standard/interfaces/innerkits/app_manager/include/appmgr", "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_base/include", "//base/global/resmgr_standard/interfaces/innerkits/include", "//third_party/node/deps/icu-small/source/common", @@ -127,12 +128,12 @@ ohos_shared_library("libwm") { # context + "//foundation/aafwk/standard/frameworks/kits/appkit:app_context", "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_base:appexecfwk_base", - "//foundation/appexecfwk/standard/kits:app_context", ] external_deps = [ - "aafwk_standard:ability_context_native", + "ability_runtime:ability_context_native", "bytrace_standard:bytrace_core", "inputmethod_native:inputmethod_client", "ipc:ipc_core", diff --git a/wm/test/systemtest/BUILD.gn b/wm/test/systemtest/BUILD.gn index e60a6e5c53..0717277c15 100644 --- a/wm/test/systemtest/BUILD.gn +++ b/wm/test/systemtest/BUILD.gn @@ -136,6 +136,6 @@ ohos_static_library("wm_systemtest_common") { "//utils/native/base:utils", ] - external_deps = [ "aafwk_standard:ability_context_native" ] + external_deps = [ "ability_runtime:ability_context_native" ] } ## Build wm_systemtest_common.a }}} diff --git a/wm/test/unittest/BUILD.gn b/wm/test/unittest/BUILD.gn index fc996b04a0..fc1fc3d0c3 100644 --- a/wm/test/unittest/BUILD.gn +++ b/wm/test/unittest/BUILD.gn @@ -159,6 +159,6 @@ ohos_static_library("wm_unittest_common") { "//utils/native/base:utils", ] - external_deps = [ "aafwk_standard:ability_context_native" ] + external_deps = [ "ability_runtime:ability_context_native" ] } ## Build wm_unittest_common.a }}} -- Gitee From bec6c4f5841a60e77d0e54470e547a80b6c9fbe5 Mon Sep 17 00:00:00 2001 From: shiyueeee Date: Tue, 18 Jan 2022 21:46:01 +0800 Subject: [PATCH 37/57] Add screen manager unittest Signed-off-by: shiyueeee Change-Id: Ic3feffc4752a61214f0c91e26cc91fce404beb8a --- dm/test/unittest/BUILD.gn | 17 +++++ dm/test/unittest/screen_manager_test.cpp | 93 +++++++++++++++++++++++ dm/test/unittest/screen_manager_test.h | 42 ++++++++++ dm/test/unittest/screen_manager_utils.cpp | 41 ++++++++++ dm/test/unittest/screen_manager_utils.h | 46 +++++++++++ 5 files changed, 239 insertions(+) create mode 100644 dm/test/unittest/screen_manager_test.cpp create mode 100644 dm/test/unittest/screen_manager_test.h create mode 100644 dm/test/unittest/screen_manager_utils.cpp create mode 100644 dm/test/unittest/screen_manager_utils.h diff --git a/dm/test/unittest/BUILD.gn b/dm/test/unittest/BUILD.gn index ce638248aa..55505d8907 100644 --- a/dm/test/unittest/BUILD.gn +++ b/dm/test/unittest/BUILD.gn @@ -20,6 +20,7 @@ group("unittest") { deps = [ ":dm_display_power_unit_test", + ":dm_screen_manager_test", ":dm_screenshot_test", ":dm_snapshot_utils_test", ] @@ -61,6 +62,20 @@ ohos_unittest("dm_screenshot_test") { ## UnitTest dm_screenshot_test }}} +## UnitTest dm_screen_manager_test {{{ +ohos_unittest("dm_screen_manager_test") { + module_out_path = module_out_path + + sources = [ + "screen_manager_test.cpp", + "screen_manager_utils.cpp", + ] + + deps = [ ":dm_unittest_common" ] +} + +## UnitTest dm_screen_manager_test }}} + ## Build dm_unittest_common.a {{{ config("dm_unittest_common_public_config") { include_dirs = [ @@ -69,6 +84,7 @@ config("dm_unittest_common_public_config") { "//foundation/windowmanager/snapshot", "//foundation/windowmanager/interfaces/innerkits/dm", "//foundation/windowmanager/utils/include", + "//foundation/graphic/standard/rosen/modules/render_service_client", # RSSurface ] } @@ -82,6 +98,7 @@ ohos_static_library("dm_unittest_common") { "//foundation/multimedia/image_standard/interfaces/innerkits:image_native", # PixelMap "//foundation/multimodalinput/input/frameworks/proxy:libmmi-client", "//foundation/windowmanager/dm:libdm", + "//foundation/windowmanager/dmserver:libdms", "//foundation/windowmanager/snapshot:snapshot_display", "//foundation/windowmanager/utils:libwmutil", "//foundation/windowmanager/wm:libwm", diff --git a/dm/test/unittest/screen_manager_test.cpp b/dm/test/unittest/screen_manager_test.cpp new file mode 100644 index 0000000000..3ddd5c6540 --- /dev/null +++ b/dm/test/unittest/screen_manager_test.cpp @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "screen_manager_test.h" +#include "mock_display_manager_adapter.h" +#include "singleton_mocker.h" + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { +namespace Rosen { +using Mocker = SingletonMocker; + +sptr ScreenManagerTest::defaultDisplay_ = nullptr; +DisplayId ScreenManagerTest::defaultDisplayId_ = DISPLAY_ID_INVALD; +uint32_t ScreenManagerTest::defaultWidth_ = 480; +uint32_t ScreenManagerTest::defaultHeight_ = 320; + +void ScreenManagerTest::SetUpTestCase() +{ + defaultDisplay_ = DisplayManager::GetInstance().GetDefaultDisplay(); + defaultDisplayId_ = defaultDisplay_->GetId(); + defaultWidth_ = defaultDisplay_->GetWidth(); + defaultHeight_ = defaultDisplay_->GetHeight(); +} + +void ScreenManagerTest::TearDownTestCase() +{ +} + +void ScreenManagerTest::SetUp() +{ +} + +void ScreenManagerTest::TearDown() +{ +} + +namespace { +/** + * @tc.name: CreateAndDestory01 + * @tc.desc: CreateVirtualScreen with invalid option and return invalid screen id + * @tc.type: FUNC + */ +HWTEST_F(ScreenManagerTest, CreateAndDestory01, Function | SmallTest | Level1) +{ + VirtualScreenOption wrongOption = {defaultName_, defaultWidth_, defaultHeight_, + defaultDensity_, nullptr, defaultFlags_}; + std::unique_ptr m = std::make_unique(); + EXPECT_CALL(m->Mock(), CreateVirtualScreen(_)).Times(1).WillOnce(Return(SCREEN_ID_INVALD)); + EXPECT_CALL(m->Mock(), DestroyVirtualScreen(_)).Times(1).WillOnce(Return(DMError::DM_ERROR_INVALID_PARAM)); + ScreenId id = ScreenManager::GetInstance().CreateVirtualScreen(wrongOption); + DMError ret = ScreenManager::GetInstance().DestroyVirtualScreen(id); + ASSERT_EQ(SCREEN_ID_INVALD, id); + ASSERT_EQ(DMError::DM_ERROR_INVALID_PARAM, ret); +} + +/** + * @tc.name: CreateAndDestory02 + * @tc.desc: CreateVirtualScreen with valid option and return valid screen id + * @tc.type: FUNC + */ +HWTEST_F(ScreenManagerTest, CreateAndDestory02, Function | SmallTest | Level1) +{ + ScreenManagerUtils utils; + ASSERT_TRUE(utils.CreateSurface()); + VirtualScreenOption defaultOption = {defaultName_, defaultWidth_, defaultHeight_, + defaultDensity_, utils.psurface_, defaultFlags_}; + ScreenId validId = 0; + std::unique_ptr m = std::make_unique(); + EXPECT_CALL(m->Mock(), CreateVirtualScreen(_)).Times(1).WillOnce(Return(validId)); + EXPECT_CALL(m->Mock(), DestroyVirtualScreen(_)).Times(1).WillOnce(Return(DMError::DM_OK)); + ScreenId id = ScreenManager::GetInstance().CreateVirtualScreen(defaultOption); + DMError ret = ScreenManager::GetInstance().DestroyVirtualScreen(id); + ASSERT_EQ(validId, id); + ASSERT_EQ(DMError::DM_OK, ret); +} +} +} // namespace Rosen +} // namespace OHOS \ No newline at end of file diff --git a/dm/test/unittest/screen_manager_test.h b/dm/test/unittest/screen_manager_test.h new file mode 100644 index 0000000000..32d4ad04d3 --- /dev/null +++ b/dm/test/unittest/screen_manager_test.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FRAMEWORKS_DM_TEST_UT_SCREEN_MANAGER_TEST_H +#define FRAMEWORKS_DM_TEST_UT_SCREEN_MANAGER_TEST_H + +#include +#include "screen_manager_utils.h" + +namespace OHOS { +namespace Rosen { +class ScreenManagerTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + virtual void SetUp() override; + virtual void TearDown() override; + + const std::string defaultName_ = "virtualScreen01"; + const float defaultDensity_ = 2.0; + const int32_t defaultFlags_ = 0; + static sptr defaultDisplay_; + static DisplayId defaultDisplayId_; + static uint32_t defaultWidth_; + static uint32_t defaultHeight_; +}; +} // namespace Rosen +} // namespace OHOS + +#endif // FRAMEWORKS_DM_TEST_UT_SCREEN_MANAGER_TEST_H \ No newline at end of file diff --git a/dm/test/unittest/screen_manager_utils.cpp b/dm/test/unittest/screen_manager_utils.cpp new file mode 100644 index 0000000000..230952321b --- /dev/null +++ b/dm/test/unittest/screen_manager_utils.cpp @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "screen_manager_utils.h" + +namespace OHOS { +namespace Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "ScreenManagerUtils"}; +} + +bool ScreenManagerUtils::CreateSurface() +{ + csurface_ = Surface::CreateSurfaceAsConsumer(); + if (csurface_ == nullptr) { + WLOGFE("csurface create failed"); + return false; + } + + auto producer = csurface_->GetProducer(); + psurface_ = Surface::CreateSurfaceAsProducer(producer); + if (psurface_ == nullptr) { + WLOGFE("csurface create failed"); + return false; + } + return true; +} +} // namespace ROSEN +} // namespace OHOS \ No newline at end of file diff --git a/dm/test/unittest/screen_manager_utils.h b/dm/test/unittest/screen_manager_utils.h new file mode 100644 index 0000000000..8621f09069 --- /dev/null +++ b/dm/test/unittest/screen_manager_utils.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FRAMEWORKS_DM_TEST_UT_SCREEN_MANAGER_UTILS_H +#define FRAMEWORKS_DM_TEST_UT_SCREEN_MANAGER_UTILS_H + +#include + +#include "display.h" +#include "display_manager.h" +#include "dm_common.h" +#include "screen.h" +#include "screen_manager.h" +#include "window_manager_hilog.h" +#include "unique_fd.h" +#include "core/ui/rs_surface_node.h" +#include "core/ui/rs_display_node.h" + +namespace OHOS { +namespace Rosen { +class ScreenManagerUtils { +public: + bool CreateSurface(); + + const std::string defaultName_ = "virtualScreen01"; + sptr csurface_ = nullptr; // cosumer surface + sptr psurface_ = nullptr; // producer surface + const float defaultDensity_ = 2.0; + const int32_t defaultFlags_ = 0; +}; +} // namespace Rosen +} // namespace OHOS + +#endif // FRAMEWORKS_DM_TEST_UT_SCREEN_MANAGER_UTILS_H \ No newline at end of file -- Gitee From dd056e009e768745f6371d3db7b57623ff7bddb1 Mon Sep 17 00:00:00 2001 From: chenqinxin Date: Wed, 19 Jan 2022 16:55:31 +0800 Subject: [PATCH 38/57] =?UTF-8?q?=E4=BF=AE=E6=94=B9dms=20wms=E5=90=AF?= =?UTF-8?q?=E5=8A=A8=E4=BC=98=E5=85=88=E7=BA=A7=EF=BC=8C=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E6=AD=BB=E4=BA=A1=E7=9B=91=E5=90=AC=E6=B7=BB=E5=8A=A0=E5=88=A4?= =?UTF-8?q?=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chenqinxin Change-Id: I4b22323b00dbccc20bbb282a872baf3a5eeba8b8 --- dm/src/display_manager.cpp | 1 - dm/src/display_manager_adapter.cpp | 2 +- sa_profile/4606.xml | 1 + sa_profile/4607.xml | 1 + wm/src/window_adapter.cpp | 5 +++-- 5 files changed, 6 insertions(+), 4 deletions(-) diff --git a/dm/src/display_manager.cpp b/dm/src/display_manager.cpp index 108ef0bbef..3da629680f 100644 --- a/dm/src/display_manager.cpp +++ b/dm/src/display_manager.cpp @@ -339,7 +339,6 @@ bool DisplayManager::SetScreenBrightness(uint64_t screenId, uint32_t level) { WLOGFI("screenId:%{public}" PRIu64", level:%{public}u,", screenId, level); if (level > MAX_SCREEN_BRIGHTNESS_VALUE) { - level = MAX_SCREEN_BRIGHTNESS_VALUE; WLOGFW("level:%{public}u, exceed max value!", level); return false; } diff --git a/dm/src/display_manager_adapter.cpp b/dm/src/display_manager_adapter.cpp index 441b0f2e40..9173f2db47 100644 --- a/dm/src/display_manager_adapter.cpp +++ b/dm/src/display_manager_adapter.cpp @@ -217,7 +217,7 @@ bool DisplayManagerAdapter::InitDMSProxyLocked() WLOGFE("Failed to create death Recipient ptr DMSDeathRecipient"); return false; } - if (!remoteObject->AddDeathRecipient(dmsDeath_)) { + if (remoteObject->IsProxyObject() && !remoteObject->AddDeathRecipient(dmsDeath_)) { WLOGFE("Failed to add death recipient"); return false; } diff --git a/sa_profile/4606.xml b/sa_profile/4606.xml index 7a02c334da..051a71d0ea 100644 --- a/sa_profile/4606.xml +++ b/sa_profile/4606.xml @@ -22,5 +22,6 @@ true false 1 + CoreStartPhase diff --git a/sa_profile/4607.xml b/sa_profile/4607.xml index 79bb9b4df0..dcfed13b0d 100644 --- a/sa_profile/4607.xml +++ b/sa_profile/4607.xml @@ -22,5 +22,6 @@ true false 1 + CoreStartPhase \ No newline at end of file diff --git a/wm/src/window_adapter.cpp b/wm/src/window_adapter.cpp index a58c700d3e..9823b93f6c 100644 --- a/wm/src/window_adapter.cpp +++ b/wm/src/window_adapter.cpp @@ -205,8 +205,9 @@ bool WindowAdapter::InitWMSProxyLocked() WLOGFE("Failed to create death Recipient ptr WMSDeathRecipient"); return false; } - if (!remoteObject->AddDeathRecipient(wmsDeath_)) { - WLOGFI("Failed to add death recipient"); + if (remoteObject->IsProxyObject() && !remoteObject->AddDeathRecipient(wmsDeath_)) { + WLOGFE("Failed to add death recipient"); + return false; } } return true; -- Gitee From f1486703496a68039ddb43ced0120b0ca0c8e177 Mon Sep 17 00:00:00 2001 From: xiaojianfeng Date: Tue, 18 Jan 2022 20:13:38 +0800 Subject: [PATCH 39/57] add code for screen Signed-off-by: xiaojianfeng Change-Id: I5a292caea692676369a866adfa50fdcc813471da --- dmserver/include/abstract_screen.h | 14 +-- dmserver/include/abstract_screen_controller.h | 4 +- dmserver/src/abstract_screen.cpp | 73 ++++++++++--- dmserver/src/abstract_screen_controller.cpp | 102 +++++++++++++++--- 4 files changed, 159 insertions(+), 34 deletions(-) diff --git a/dmserver/include/abstract_screen.h b/dmserver/include/abstract_screen.h index 8137727f61..cdce4a91d3 100644 --- a/dmserver/include/abstract_screen.h +++ b/dmserver/include/abstract_screen.h @@ -18,6 +18,7 @@ #include +#include #include #include #include @@ -66,19 +67,20 @@ public: class AbstractScreenGroup : public AbstractScreen { public: - AbstractScreenGroup(ScreenId dmsId, ScreenId rsId); + AbstractScreenGroup(ScreenId dmsId, ScreenId rsId, ScreenCombination combination); AbstractScreenGroup() = delete; ~AbstractScreenGroup(); - bool AddChild(ScreenCombination combination, sptr& dmsScreen, Point& startPoint); - bool AddChild(ScreenCombination combination, - std::vector>& dmsScreens, - std::vector& startPoints); + bool AddChild(sptr& dmsScreen, Point& startPoint); + bool AddChildren(std::vector>& dmsScreens, std::vector& startPoints); + bool RemoveChild(sptr& dmsScreen); std::vector> GetChildren() const; std::vector GetChildrenPosition() const; + size_t GetChildCount() const; ScreenCombination combination_ { ScreenCombination::SCREEN_ALONE }; - std::vector> children_; +private: + std::map, Point>> abstractScreenMap_; }; } // namespace OHOS::Rosen #endif // FOUNDATION_DMSERVER_ABSTRACT_SCREEN_H \ No newline at end of file diff --git a/dmserver/include/abstract_screen_controller.h b/dmserver/include/abstract_screen_controller.h index b4d7b5388a..dd8b09ef9f 100644 --- a/dmserver/include/abstract_screen_controller.h +++ b/dmserver/include/abstract_screen_controller.h @@ -55,10 +55,12 @@ public: private: void OnRsScreenChange(ScreenId rsScreenId, ScreenEvent screenEvent); + void ProcessScreenDisconnected(ScreenId rsScreenId); bool FillAbstractScreen(sptr& absScreen, ScreenId rsScreenId); sptr AddToGroupLocked(sptr newScreen); + sptr RemoveFromGroupLocked(sptr newScreen); sptr AddAsFirstScreenLocked(sptr newScreen); - void AddAsSuccedentScreenLocked(sptr newScreen); + sptr AddAsSuccedentScreenLocked(sptr newScreen); std::recursive_mutex& mutex_; OHOS::Rosen::RSInterfaces *rsInterface_; diff --git a/dmserver/src/abstract_screen.cpp b/dmserver/src/abstract_screen.cpp index 983c1d503d..04507517f9 100644 --- a/dmserver/src/abstract_screen.cpp +++ b/dmserver/src/abstract_screen.cpp @@ -21,8 +21,9 @@ namespace OHOS::Rosen { namespace { - constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "AbstractScreen"}; + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "AbstractScreenGroup"}; } + AbstractScreen::AbstractScreen(ScreenId dmsId, ScreenId rsId) : dmsId_(dmsId), rsId_(rsId) { @@ -46,7 +47,8 @@ sptr AbstractScreen::GetGroup() const return DisplayManagerService::GetInstance().GetAbstractScreenController()->GetAbstractScreenGroup(groupDmsId_); } -AbstractScreenGroup::AbstractScreenGroup(ScreenId dmsId, ScreenId rsId) : AbstractScreen(dmsId, rsId) +AbstractScreenGroup::AbstractScreenGroup(ScreenId dmsId, ScreenId rsId, ScreenCombination combination) + : AbstractScreen(dmsId, rsId), combination_(combination) { type_ = ScreenType::UNDEFINE; } @@ -54,11 +56,22 @@ AbstractScreenGroup::AbstractScreenGroup(ScreenId dmsId, ScreenId rsId) : Abstra AbstractScreenGroup::~AbstractScreenGroup() { rsDisplayNode_ = nullptr; - children_.clear(); + abstractScreenMap_.clear(); } -bool AbstractScreenGroup::AddChild(ScreenCombination type, sptr& dmsScreen, Point& startPoint) -{ +bool AbstractScreenGroup::AddChild(sptr& dmsScreen, Point& startPoint) +{ + if (dmsScreen == nullptr) { + WLOGE("AddChild, dmsScreen is nullptr."); + return false; + } + ScreenId screenId = dmsScreen->dmsId_; + auto iter = abstractScreenMap_.find(screenId); + if (iter != abstractScreenMap_.end()) { + WLOGE("AddChild, abstractScreenMap_ has dmsScreen:%{public}" PRIu64"", screenId); + return false; + } + struct RSDisplayNodeConfig config; switch (combination_) { case ScreenCombination::SCREEN_ALONE: @@ -77,27 +90,59 @@ bool AbstractScreenGroup::AddChild(ScreenCombination type, sptr& WLOGE("fail to add child. create rsDisplayNode fail!"); return false; } - children_.push_back(dmsScreen); dmsScreen->rsDisplayNode_ = rsDisplayNode; + abstractScreenMap_.insert(std::make_pair(screenId, std::make_pair(dmsScreen, startPoint))); return true; } -bool AbstractScreenGroup::AddChild(ScreenCombination type, - std::vector>& dmsScreens, - std::vector& startPoints) +bool AbstractScreenGroup::AddChildren(std::vector>& dmsScreens, std::vector& startPoints) { - return true; + size_t size = dmsScreens.size(); + if (size != startPoints.size()) { + WLOGE("AddChildren, unequal size."); + return false; + } + bool res = true; + for (size_t i = 0; i < size; i++) { + res &= AddChild(dmsScreens[i], startPoints[i]); + } + return res; +} + +bool AbstractScreenGroup::RemoveChild(sptr& dmsScreen) +{ + if (dmsScreen == nullptr) { + WLOGE("RemoveChild, dmsScreen is nullptr."); + return false; + } + ScreenId screenId = dmsScreen->dmsId_; + bool res = abstractScreenMap_.erase(screenId); + if (abstractScreenMap_.size() == 1) { + combination_ = ScreenCombination::SCREEN_ALONE; + } + return res; } std::vector> AbstractScreenGroup::GetChildren() const { - std::vector> tmp; - return tmp; + std::vector> res; + for (auto iter = abstractScreenMap_.begin(); iter != abstractScreenMap_.end(); iter++) { + res.push_back(iter->second.first); + } + return res; } std::vector AbstractScreenGroup::GetChildrenPosition() const { - std::vector tmp; - return tmp; + std::vector res; + for (auto iter = abstractScreenMap_.begin(); iter != abstractScreenMap_.end(); iter++) { + res.push_back(iter->second.second); + } + return res; +} + +size_t AbstractScreenGroup::GetChildCount() const +{ + return abstractScreenMap_.size(); } } // namespace OHOS::Rosen \ No newline at end of file diff --git a/dmserver/src/abstract_screen_controller.cpp b/dmserver/src/abstract_screen_controller.cpp index 733fd25c2e..f99a1c987f 100644 --- a/dmserver/src/abstract_screen_controller.cpp +++ b/dmserver/src/abstract_screen_controller.cpp @@ -42,7 +42,7 @@ void AbstractScreenController::Init() WLOGFD("screen controller init"); dmsScreenCount_ = 0; if (rsInterface_ == nullptr) { - WLOGFE("rsInterface is null, init failed"); + WLOGFE("rsInterface_ is nullptr, init failed"); } else { rsInterface_->SetScreenChangeCallback( std::bind(&AbstractScreenController::OnRsScreenChange, this, std::placeholders::_1, std::placeholders::_2)); @@ -59,7 +59,7 @@ sptr AbstractScreenController::GetAbstractScreen(ScreenId dmsScr { auto iter = dmsScreenMap_.find(dmsScreenId); if (iter == dmsScreenMap_.end()) { - WLOGE("didnot find screen:%{public}" PRIu64"", dmsScreenId); + WLOGI("didnot find screen:%{public}" PRIu64"", dmsScreenId); return nullptr; } sptr screen = iter->second; @@ -127,12 +127,40 @@ void AbstractScreenController::OnRsScreenChange(ScreenId rsScreenId, ScreenEvent WLOGE("reconnect screen, screenId=%{public}" PRIu64"", rsScreenId); } } else if (screenEvent == ScreenEvent::DISCONNECTED) { - WLOGI("connect screen"); + ProcessScreenDisconnected(rsScreenId); } else { WLOGE("unknow message:%{public}ud", static_cast(screenEvent)); } } +void AbstractScreenController::ProcessScreenDisconnected(ScreenId rsScreenId) +{ + WLOGI("disconnect screen, screenId=%{public}" PRIu64"", rsScreenId); + ScreenId dmsScreenId = INVALID_SCREEN_ID; + auto iter = rs2DmsScreenIdMap_.find(rsScreenId); + if (iter == rs2DmsScreenIdMap_.end()) { + WLOGE("disconnect screen, screenId=%{public}" PRIu64" is not in rs2DmsScreenIdMap_", rsScreenId); + return; + } + dmsScreenId = iter->second; + auto dmsScreenMapIter = dmsScreenMap_.find(dmsScreenId); + if (dmsScreenMapIter != dmsScreenMap_.end()) { + sptr screenGroup = RemoveFromGroupLocked(dmsScreenMapIter->second); + if (screenGroup != nullptr && abstractScreenCallback_ != nullptr) { + abstractScreenCallback_->onDisconnected_(dmsScreenMapIter->second); + } + dmsScreenMap_.erase(dmsScreenMapIter); + auto firstIter = dmsScreenMap_.begin(); + if (firstIter == dmsScreenMap_.end()) { + primaryDmsScreenId_ = SCREEN_ID_INVALID; + } else { + primaryDmsScreenId_ = firstIter->second->dmsId_; + } + } + rs2DmsScreenIdMap_.erase(iter); + dms2RsScreenIdMap_.erase(dmsScreenId); +} + bool AbstractScreenController::FillAbstractScreen(sptr& absScreen, ScreenId rsScreenId) { if (rsInterface_ == nullptr) { @@ -165,41 +193,89 @@ bool AbstractScreenController::FillAbstractScreen(sptr& absScree sptr AbstractScreenController::AddToGroupLocked(sptr newScreen) { - if (primaryDmsScreenId_ == SCREEN_ID_INVALID) { - WLOGI("connect the first screen"); + if (dmsScreenGroupMap_.empty()) { + WLOGE("connect the first screen"); return AddAsFirstScreenLocked(newScreen); - } else { - AddAsSuccedentScreenLocked(newScreen); + } + return AddAsSuccedentScreenLocked(newScreen); +} + +sptr AbstractScreenController::RemoveFromGroupLocked(sptr newScreen) +{ + WLOGI("RemoveFromGroupLocked."); + auto groupDmsId = newScreen->groupDmsId_; + auto iter = dmsScreenGroupMap_.find(groupDmsId); + if (iter == dmsScreenGroupMap_.end()) { + WLOGE("RemoveFromGroupLocked. groupDmsId:%{public}" PRIu64"is not in dmsScreenGroupMap_.", groupDmsId); + return nullptr; + } + sptr screenGroup = iter->second; + bool res = screenGroup->RemoveChild(newScreen); + if (!res) { + WLOGE("RemoveFromGroupLocked. remove screen:%{public}" PRIu64" failed from screenGroup:%{public}" PRIu64".", + newScreen->dmsId_, groupDmsId); return nullptr; } + if (screenGroup->GetChildCount() == 0) { + // Group removed, need to do something. + dmsScreenGroupMap_.erase(screenGroup->dmsId_); + dmsScreenMap_.erase(screenGroup->dmsId_); + } + return screenGroup; } sptr AbstractScreenController::AddAsFirstScreenLocked(sptr newScreen) { ScreenId dmsGroupScreenId = dmsScreenCount_.load(); - sptr sreenGroup = new AbstractScreenGroup(dmsGroupScreenId, SCREEN_ID_INVALID); + sptr screenGroup = + new AbstractScreenGroup(dmsGroupScreenId, SCREEN_ID_INVALID, ScreenCombination::SCREEN_ALONE); Point point; - if (!sreenGroup->AddChild(ScreenCombination::SCREEN_ALONE, newScreen, point)) { + if (!screenGroup->AddChild(newScreen, point)) { WLOGE("fail to add screen to group. screen=%{public}" PRIu64"", newScreen->dmsId_); return nullptr; } dmsScreenCount_++; newScreen->groupDmsId_ = dmsGroupScreenId; + primaryDmsScreenId_ = newScreen->dmsId_; auto iter = dmsScreenGroupMap_.find(dmsGroupScreenId); if (iter != dmsScreenGroupMap_.end()) { WLOGE("group screen existed. id=%{public}" PRIu64"", dmsGroupScreenId); dmsScreenGroupMap_.erase(iter); } - dmsScreenGroupMap_.insert(std::make_pair(dmsGroupScreenId, sreenGroup)); - dmsScreenMap_.insert(std::make_pair(dmsGroupScreenId, sreenGroup)); + dmsScreenGroupMap_.insert(std::make_pair(dmsGroupScreenId, screenGroup)); + dmsScreenMap_.insert(std::make_pair(dmsGroupScreenId, screenGroup)); WLOGI("connect new group screen. id=%{public}" PRIu64"/%{public}" PRIu64", combination:%{public}u", newScreen->dmsId_, dmsGroupScreenId, newScreen->type_); - return sreenGroup; + return screenGroup; } -void AbstractScreenController::AddAsSuccedentScreenLocked(sptr newScreen) +sptr AbstractScreenController::AddAsSuccedentScreenLocked(sptr newScreen) { + auto screenIter = dmsScreenMap_.find(newScreen->dmsId_); + if (screenIter != dmsScreenMap_.end()) { + WLOGE("AddAsSuccedentScreenLocked. screen:%{public}" PRIu64" is already in dmsScreenMap_.", + newScreen->dmsId_); + return nullptr; + } // TODO: Mirror to main screen + auto iter = dmsScreenMap_.find(primaryDmsScreenId_); + if (iter == dmsScreenMap_.end()) { + WLOGE("AddAsSuccedentScreenLocked. primaryDmsScreenId_:%{public}" PRIu64" is not in dmsScreenMap_.", + primaryDmsScreenId_); + return nullptr; + } + auto screen = iter->second; + auto screenGroupIter = dmsScreenGroupMap_.find(screen->groupDmsId_); + if (screenGroupIter == dmsScreenGroupMap_.end()) { + WLOGE("AddAsSuccedentScreenLocked. groupDmsId:%{public}" PRIu64" is not in dmsScreenGroupMap_.", + screen->groupDmsId_); + return nullptr; + } + auto screenGroup = screenGroupIter->second; + Point point; + screenGroup->AddChild(newScreen, point); + newScreen->groupDmsId_ = screenGroup->dmsId_; + return screenGroup; } ScreenId AbstractScreenController::CreateVirtualScreen(VirtualScreenOption option) -- Gitee From 96b5f3cfd03b0475c3a2fee66b3e037eb7f4bb88 Mon Sep 17 00:00:00 2001 From: xingyanan Date: Wed, 19 Jan 2022 17:28:34 +0800 Subject: [PATCH 40/57] split screen back bug fix Signed-off-by: xingyanan Change-Id: Ib680123fd838ab72d0b5fc1e1da062d40130bc80 --- wmserver/src/window_controller.cpp | 1 + wmserver/src/window_inner_manager.cpp | 1 + 2 files changed, 2 insertions(+) diff --git a/wmserver/src/window_controller.cpp b/wmserver/src/window_controller.cpp index 66436fa05a..6b3986a0b8 100644 --- a/wmserver/src/window_controller.cpp +++ b/wmserver/src/window_controller.cpp @@ -161,6 +161,7 @@ WMError WindowController::RequestFocus(uint32_t windowId) WMError WindowController::SetWindowMode(uint32_t windowId, WindowMode dstMode) { + WM_FUNCTION_TRACE(); auto node = windowRoot_->GetWindowNode(windowId); WindowMode srcMode = node->GetWindowMode(); if (node == nullptr) { diff --git a/wmserver/src/window_inner_manager.cpp b/wmserver/src/window_inner_manager.cpp index 29b71e7476..b8a90f29f8 100644 --- a/wmserver/src/window_inner_manager.cpp +++ b/wmserver/src/window_inner_manager.cpp @@ -96,6 +96,7 @@ sptr WindowInnerManager::CreateWindow(uint32_t displayId, const WindowTy sptr divWindowOp = new WindowOption(); divWindowOp->SetWindowRect(rect); divWindowOp->SetWindowType(type); + divWindowOp->SetFocusable(false); divWindowOp->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING); window = Window::Create("divider" + std::to_string(displayId), divWindowOp); if (window == nullptr) { -- Gitee From 085566135a82d96737b7d16a8ba0b75547ecfb0e Mon Sep 17 00:00:00 2001 From: hanhaibin Date: Wed, 19 Jan 2022 18:37:34 +0800 Subject: [PATCH 41/57] Fix codex Signed-off-by: hanhaibin --- wm/test/unittest/BUILD.gn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wm/test/unittest/BUILD.gn b/wm/test/unittest/BUILD.gn index fc1fc3d0c3..4e1628ac9a 100644 --- a/wm/test/unittest/BUILD.gn +++ b/wm/test/unittest/BUILD.gn @@ -121,7 +121,7 @@ config("wm_unittest_common_public_config") { # for abilityContext "//foundation/aafwk/standard/frameworks/kits/ability/ability_runtime/include", "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_base/include", - "//foundation/appexecfwk/standard/kits/appkit/native/ability_runtime/context", + "//foundation/aafwk/standard/frameworks/kits/appkit/native/ability_runtime/context", "//base/global/resmgr_standard/interfaces/innerkits/include", "//third_party/node/deps/icu-small/source/common", "//foundation/aafwk/standard/interfaces/innerkits/ability_manager/include", -- Gitee From 405e36244c80e949ea175a0a50f04a04934afeb1 Mon Sep 17 00:00:00 2001 From: hanhaibin Date: Wed, 19 Jan 2022 18:49:12 +0800 Subject: [PATCH 42/57] Fix codex Signed-off-by: hanhaibin --- wm/test/systemtest/BUILD.gn | 2 +- wm/test/unittest/mock_static_call.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/wm/test/systemtest/BUILD.gn b/wm/test/systemtest/BUILD.gn index 0717277c15..7079daf061 100644 --- a/wm/test/systemtest/BUILD.gn +++ b/wm/test/systemtest/BUILD.gn @@ -97,7 +97,7 @@ config("wm_systemtest_common_public_config") { # for abilityContext "//foundation/aafwk/standard/frameworks/kits/ability/ability_runtime/include", "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_base/include", - "//foundation/appexecfwk/standard/kits/appkit/native/ability_runtime/context", + "//foundation/aafwk/standard/frameworks/kits/appkit/native/ability_runtime/context", "//base/global/resmgr_standard/interfaces/innerkits/include", "//third_party/node/deps/icu-small/source/common", "//foundation/aafwk/standard/interfaces/innerkits/ability_manager/include", diff --git a/wm/test/unittest/mock_static_call.h b/wm/test/unittest/mock_static_call.h index ec0518dda4..2946135af0 100644 --- a/wm/test/unittest/mock_static_call.h +++ b/wm/test/unittest/mock_static_call.h @@ -18,7 +18,7 @@ #include #include "ability_context_impl.h" -#include "foundation/appexecfwk/standard/kits/appkit/native/ability_runtime/context/context.h" +#include "foundation/aafwk/standard/frameworks/kits/appkit/native/ability_runtime/context/context.h" #include "static_call.h" namespace OHOS { -- Gitee From b8f451bfc594a6451d808ccd8740cb94bd259fb3 Mon Sep 17 00:00:00 2001 From: wangxinpeng Date: Wed, 19 Jan 2022 19:25:44 +0800 Subject: [PATCH 43/57] input method window ST Signed-off-by: wangxinpeng Change-Id: I6c5bc1ffa1fafea084afae5ea13f2a91fae4802b --- wm/test/systemtest/BUILD.gn | 12 ++ .../systemtest/window_input_method_test.cpp | 128 ++++++++++++++++++ 2 files changed, 140 insertions(+) create mode 100644 wm/test/systemtest/window_input_method_test.cpp diff --git a/wm/test/systemtest/BUILD.gn b/wm/test/systemtest/BUILD.gn index e60a6e5c53..9b6a9563e7 100644 --- a/wm/test/systemtest/BUILD.gn +++ b/wm/test/systemtest/BUILD.gn @@ -20,6 +20,7 @@ group("systemtest") { deps = [ ":wm_window_immersive_test", + ":wm_window_input_method_test", ":wm_window_layout_test", ":wm_window_multi_ability_test", ":wm_window_split_test", @@ -82,6 +83,17 @@ ohos_systemtest("wm_window_split_test") { ## SystemTest wm_window_split_test }}} +## SystemTest window_input_method_test {{{ +ohos_systemtest("wm_window_input_method_test") { + module_out_path = module_out_path + + sources = [ "window_input_method_test.cpp" ] + + deps = [ ":wm_systemtest_common" ] +} + +## SystemTest window_input_method_test }}} + ## Build wm_systemtest_common.a {{{ config("wm_systemtest_common_public_config") { include_dirs = [ diff --git a/wm/test/systemtest/window_input_method_test.cpp b/wm/test/systemtest/window_input_method_test.cpp new file mode 100644 index 0000000000..63b164ce28 --- /dev/null +++ b/wm/test/systemtest/window_input_method_test.cpp @@ -0,0 +1,128 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// gtest +#include +#include "window_test_utils.h" +using namespace testing; +using namespace testing::ext; + +namespace OHOS { +namespace Rosen { +using utils = WindowTestUtils; +class WindowInputMethodTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + virtual void SetUp() override; + virtual void TearDown() override; + utils::TestWindowInfo inputMethodWindowInfo_; + utils::TestWindowInfo keyGuardWindowInfo_; +}; + +void WindowInputMethodTest::SetUpTestCase() +{ + auto display = DisplayManager::GetInstance().GetDisplayById(0); + if (display == nullptr) { + printf("GetDefaultDisplay: failed!\n"); + } else { + printf("GetDefaultDisplay: id %llu, w %d, h %d, fps %u\n", display->GetId(), display->GetWidth(), + display->GetHeight(), display->GetFreshRate()); + } + Rect displayRect = {0, 0, display->GetWidth(), display->GetHeight()}; + utils::InitByDisplayRect(displayRect); +} + +void WindowInputMethodTest::TearDownTestCase() +{ +} + +void WindowInputMethodTest::SetUp() +{ + inputMethodWindowInfo_ = { + .name = "", + .rect = utils::defaultAppRect_, + .type = WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT, + .mode = WindowMode::WINDOW_MODE_FLOATING, + .needAvoid = false, + .parentLimit = false, + .parentName = "", + }; + keyGuardWindowInfo_ = { + .name = "", + .rect = utils::defaultAppRect_, + .type = WindowType::WINDOW_TYPE_KEYGUARD, + .mode = WindowMode::WINDOW_MODE_FULLSCREEN, + .needAvoid = false, + .parentLimit = false, + .parentName = "", + }; +} + +void WindowInputMethodTest::TearDown() +{ +} + +namespace { +/** + * @tc.name: InputMethodWindow01 + * @tc.desc: One InputMethod Floating Window + * @tc.type: FUNC + * @tc.require: AR000GGTUT + */ +HWTEST_F(WindowInputMethodTest, InputMethodWindow01, Function | MediumTest | Level3) +{ + inputMethodWindowInfo_.name = "input_method.1"; + const sptr& window = utils::CreateTestWindow(inputMethodWindowInfo_); + ASSERT_EQ(WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT, window->GetType()); + ASSERT_EQ(WMError::WM_OK, window->Show()); + ASSERT_EQ(WMError::WM_OK, window->Hide()); +} + +/** + * @tc.name: InputMethodWindow02 + * @tc.desc: One KeyGuard Window + * @tc.type: FUNC + * @tc.require: AR000GGTUT + */ +HWTEST_F(WindowInputMethodTest, InputMethodWindow02, Function | MediumTest | Level3) +{ + keyGuardWindowInfo_.name = "keyGuard.1"; + const sptr& window = utils::CreateTestWindow(keyGuardWindowInfo_); + ASSERT_EQ(WindowType::WINDOW_TYPE_KEYGUARD, window->GetType()); + ASSERT_EQ(WMError::WM_OK, window->Show()); + ASSERT_EQ(WMError::WM_OK, window->Hide()); +} + +/** + * @tc.name: InputMethodWindow03 + * @tc.desc: One InputMethod Floating Window & One KeyGuard Window + * @tc.type: FUNC + * @tc.require: AR000GGTUU + */ +HWTEST_F(WindowInputMethodTest, InputMethodWindow03, Function | MediumTest | Level3) +{ + inputMethodWindowInfo_.name = "input_method.2"; + keyGuardWindowInfo_.name = "keyGuard.2"; + const sptr& inputMethodWindow = utils::CreateTestWindow(inputMethodWindowInfo_); + const sptr& keyGuardWindow = utils::CreateTestWindow(keyGuardWindowInfo_); + keyGuardWindow->Show(); + inputMethodWindow->Show(); + ASSERT_TRUE(utils::RectEqualTo(keyGuardWindow, utils::displayRect_)); + ASSERT_TRUE(utils::RectEqualTo(inputMethodWindow, utils::defaultAppRect_)); +} +} // namespace +} // namespace Rosen +} // namespace OHOS -- Gitee From 19c8ca1eb812eb30a3f4a575877ba61e43610ec9 Mon Sep 17 00:00:00 2001 From: chenqinxin Date: Thu, 20 Jan 2022 09:17:59 +0800 Subject: [PATCH 44/57] =?UTF-8?q?=E8=A1=A5=E5=85=85=E4=BA=AE=E7=81=AD?= =?UTF-8?q?=E5=B1=8F=E9=81=97=E6=BC=8F=E7=9A=84systemtest?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chenqinxin Change-Id: I298314f76026200368681f2c23cb90f4748c7b42 --- dm/test/systemtest/display_power_test.cpp | 37 +++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/dm/test/systemtest/display_power_test.cpp b/dm/test/systemtest/display_power_test.cpp index 5308157d07..d03be7623e 100644 --- a/dm/test/systemtest/display_power_test.cpp +++ b/dm/test/systemtest/display_power_test.cpp @@ -130,6 +130,7 @@ HWTEST_F(DisplayPowerTest, register_display_power_event_listener_001, Function | sptr listener = new DisplayPowerEventListener(); bool ret = DisplayManager::GetInstance().RegisterDisplayPowerEventListener(listener); ASSERT_EQ(true, ret); + DisplayManager::GetInstance().UnregisterDisplayPowerEventListener(listener); } /** @@ -143,6 +144,42 @@ HWTEST_F(DisplayPowerTest, register_display_power_event_listener_002, Function | ASSERT_EQ(false, ret); } +/** + * @tc.name: unregister_display_power_event_listener_001 + * @tc.desc: call UnregisterDisplayPowerEventListener with a valid listener and check return value + * @tc.type: FUNC + */ +HWTEST_F(DisplayPowerTest, unregister_display_power_event_listener_001, Function | SmallTest | Level2) +{ + sptr listener = new DisplayPowerEventListener(); + DisplayManager::GetInstance().RegisterDisplayPowerEventListener(listener); + bool ret = DisplayManager::GetInstance().UnregisterDisplayPowerEventListener(listener); + ASSERT_EQ(true, ret); +} + +/** +* @tc.name: unregister_display_power_event_listener_002 +* @tc.desc: call UnregisterDisplayPowerEventListener with nullptr and check return value +* @tc.type: FUNC +*/ +HWTEST_F(DisplayPowerTest, unregister_display_power_event_listener_002, Function | SmallTest | Level2) +{ + bool ret = DisplayManager::GetInstance().UnregisterDisplayPowerEventListener(nullptr); + ASSERT_EQ(false, ret); +} + +/** +* @tc.name: unregister_display_power_event_listener_003 +* @tc.desc: call UnregisterDisplayPowerEventListener with an invalid listener and check return value +* @tc.type: FUNC +*/ +HWTEST_F(DisplayPowerTest, unregister_display_power_event_listener_003, Function | SmallTest | Level2) +{ + sptr listener = new DisplayPowerEventListener(); + bool ret = DisplayManager::GetInstance().UnregisterDisplayPowerEventListener(listener); + ASSERT_EQ(false, ret); +} + /** * @tc.name: set_display_state_001 * @tc.desc: Call SetDisplayState and check if it the state set is the same as calling GetDisplayState -- Gitee From be7bc16c6a78b9c202ce542e2b6470ad1976a177 Mon Sep 17 00:00:00 2001 From: huandong Date: Thu, 20 Jan 2022 12:07:22 +0800 Subject: [PATCH 45/57] =?UTF-8?q?AvoidAreaController=E4=B8=8B=20add=20remo?= =?UTF-8?q?ve=20update=E5=A2=9E=E5=8A=A0Trace?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: If64676f11df4ae43d721b416d7e2c3eb4cbdbef8 Signed-off-by: huandong --- wmserver/src/avoid_area_controller.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/wmserver/src/avoid_area_controller.cpp b/wmserver/src/avoid_area_controller.cpp index fd7ef17eb1..077bf8c3a3 100644 --- a/wmserver/src/avoid_area_controller.cpp +++ b/wmserver/src/avoid_area_controller.cpp @@ -15,6 +15,7 @@ #include "avoid_area_controller.h" #include "window_manager_hilog.h" +#include "wm_trace.h" namespace OHOS { namespace Rosen { @@ -52,6 +53,7 @@ static AvoidPos GetAvoidPosType(const Rect& rect) WMError AvoidAreaController::AddAvoidAreaNode(const sptr& node) { + WM_FUNCTION_TRACE(); uint32_t windowId = node->GetWindowId(); auto iter = avoidNodes_.find(windowId); if (iter != avoidNodes_.end()) { @@ -72,6 +74,7 @@ WMError AvoidAreaController::AddAvoidAreaNode(const sptr& node) WMError AvoidAreaController::RemoveAvoidAreaNode(const sptr& node) { + WM_FUNCTION_TRACE(); uint32_t windowId = node->GetWindowId(); auto iter = avoidNodes_.find(windowId); if (iter == avoidNodes_.end()) { @@ -92,6 +95,7 @@ WMError AvoidAreaController::RemoveAvoidAreaNode(const sptr& node) WMError AvoidAreaController::UpdateAvoidAreaNode(const sptr& node) { + WM_FUNCTION_TRACE(); uint32_t windowId = node->GetWindowId(); auto iter = avoidNodes_.find(windowId); if (iter == avoidNodes_.end()) { -- Gitee From 5b6efd20a5d7975968983e81dc7951f16cfc7b95 Mon Sep 17 00:00:00 2001 From: c00471419 Date: Thu, 20 Jan 2022 12:21:39 +0800 Subject: [PATCH 46/57] add getTopWindow for newNapi Signed-off-by: c00471419 Change-Id: Ia541ccbd5f37bb1e2ecb2355b5248ecae1f2ad50 Signed-off-by: c00471419 --- .../kits/js/declaration/api/@ohos.window.d.ts | 79 ------ interfaces/kits/napi/BUILD.gn | 3 +- interfaces/kits/napi/window/BUILD.gn | 40 --- .../kits/napi/window/native_window_module.cpp | 263 ------------------ .../kits/napi/window/native_window_module.h | 19 -- interfaces/kits/napi/window_runtime/BUILD.gn | 4 +- .../napi/window_runtime/api/@ohos.window.d.ts | 4 +- .../window_manager_napi/js_window_manager.cpp | 85 ++++++ .../window_manager_module.cpp | 4 +- 9 files changed, 92 insertions(+), 409 deletions(-) delete mode 100644 interfaces/kits/js/declaration/api/@ohos.window.d.ts delete mode 100644 interfaces/kits/napi/window/BUILD.gn delete mode 100644 interfaces/kits/napi/window/native_window_module.cpp delete mode 100644 interfaces/kits/napi/window/native_window_module.h diff --git a/interfaces/kits/js/declaration/api/@ohos.window.d.ts b/interfaces/kits/js/declaration/api/@ohos.window.d.ts deleted file mode 100644 index 3872e90048..0000000000 --- a/interfaces/kits/js/declaration/api/@ohos.window.d.ts +++ /dev/null @@ -1,79 +0,0 @@ -/* -* Copyright (c) 2021 Huawei Device Co., Ltd. -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/** - * Window manager. - * @devices tv, phone, tablet, wearable. -*/ -declare namespace window { - /** - * Obtain the top window of the current application. - * @devices tv, phone, tablet, wearable. - */ - function getTopWindow(): Promise; - - /** - * The type of a window. - * @devices tv, phone, tablet, wearable. - */ - enum WindowType { - /** - * App. - */ - TYPE_APP = 0, - /** - * System alert. - */ - TYPE_SYSTEM_ALERT = 30, - /** - * System volume. - */ - TYPE_SYSTEM_VOLUME = 70, - /** - * System panel. - */ - TYPE_SYSTEM_PANEL = 90, - } - - /** - * The interface of window. - */ - interface Window { - /** - * Set the position of a window. - * @param x Indicate the X-coordinate of the window. - * @param y Indicate the Y-coordinate of the window. - * @devices tv, phone, tablet, wearable, liteWearable. - */ - moveTo(x: number, y: number): Promise; - - /** - * Set the size of a window . - * @param width Indicates the width of the window. - * @param height Indicates the height of the window. - * @devices tv, phone, tablet, wearable, liteWearable. - */ - resetSize(width: number, height: number): Promise; - - /** - * Set the type of a window. - * @param type Indicate the type of a window. - * @devices tv, phone, tablet, wearable, liteWearable. - */ - setWindowType(type: WindowType): Promise; - } -} - -export default window; diff --git a/interfaces/kits/napi/BUILD.gn b/interfaces/kits/napi/BUILD.gn index eead3210c0..9fea4f66f4 100644 --- a/interfaces/kits/napi/BUILD.gn +++ b/interfaces/kits/napi/BUILD.gn @@ -54,8 +54,7 @@ group("napi_packages") { deps = [ "display:display", "screenshot:screenshot", - "window:window", + "window_runtime:window_napi", "window_runtime:window_native_kit", - "window_runtime:windowmanager_napi", ] } diff --git a/interfaces/kits/napi/window/BUILD.gn b/interfaces/kits/napi/window/BUILD.gn deleted file mode 100644 index 93c5e88f38..0000000000 --- a/interfaces/kits/napi/window/BUILD.gn +++ /dev/null @@ -1,40 +0,0 @@ -# Copyright (c) 2021 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import("//build/ohos.gni") - -## Build window.so {{{ -ohos_shared_library("window") { - sources = [ "native_window_module.cpp" ] - - configs = [ - "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_core:bundlemgr_sdk_config", - "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_base:appexecfwk_base_sdk_config", - "//foundation/aafwk/standard/interfaces/innerkits/want:want_public_config", - "//foundation/aafwk/standard/interfaces/innerkits/ability_manager:ability_manager_public_config", - "//foundation/aafwk/standard/services/abilitymgr:abilityms_config", - ] - - deps = [ - "../common:wm_napi_common", - "//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native", - "//foundation/aafwk/standard/frameworks/kits/appkit:appkit_native", - "//foundation/windowmanager/wm:libwm", - "//foundation/windowmanager/wmserver:libwms", - ] - - relative_install_dir = "module" - part_name = "window_manager" - subsystem_name = "window" -} -## Build window.so }}} diff --git a/interfaces/kits/napi/window/native_window_module.cpp b/interfaces/kits/napi/window/native_window_module.cpp deleted file mode 100644 index 28f0e1cd7b..0000000000 --- a/interfaces/kits/napi/window/native_window_module.cpp +++ /dev/null @@ -1,263 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -#include "native_window_module.h" -#include "window.h" -#include "window_scene.h" -#include "wm_common.h" -#include "wm_napi_common.h" - -namespace OHOS { -namespace Rosen { -namespace { -thread_local napi_value g_classWindow; -napi_status GetAbility(napi_env env, napi_callback_info info, AppExecFwk::Ability* &pAbility) -{ - napi_value global; - GNAPI_INNER(napi_get_global(env, &global)); - - napi_value jsAbility; - GNAPI_INNER(napi_get_named_property(env, global, "ability", &jsAbility)); - - GNAPI_INNER(napi_get_value_external(env, jsAbility, reinterpret_cast(&pAbility))); - - return napi_ok; -} -} // namespace - - -namespace NAPIWindow { -napi_value WindowConstructor(napi_env env, napi_callback_info info) -{ - napi_value jsthis = nullptr; - NAPI_CALL(env, napi_get_cb_info(env, info, nullptr, nullptr, &jsthis, nullptr)); - return jsthis; -} - -namespace ResetSize { -struct Param { - ::OHOS::AppExecFwk::Ability *ability; - WMError wret; - int width; - int height; -}; - -void Async(napi_env env, std::unique_ptr& param) -{ - if (param == nullptr || param->ability == nullptr || param->ability->GetWindow() == nullptr) { - GNAPI_LOG("Error, use nullptr!)"); - param->wret = WMError::WM_ERROR_NULLPTR; - return; - } - param->wret = param->ability->GetWindow()->Resize(param->width, param->height); -} - -napi_value MainFunc(napi_env env, napi_callback_info info) -{ - GNAPI_LOG("Window Interface: ResetSize()"); - GNAPI_LOG("%{public}s called", __PRETTY_FUNCTION__); - constexpr int argumentSize = 2; - size_t argc = argumentSize; - napi_value argv[argc]; - - NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr)); - - GNAPI_ASSERT(env, argc < argumentSize, "ResetSize need %{public}d arguments", argumentSize); - - auto param = std::make_unique(); - NAPI_CALL(env, GetAbility(env, info, param->ability)); - NAPI_CALL(env, napi_get_value_int32(env, argv[0], ¶m->width)); - NAPI_CALL(env, napi_get_value_int32(env, argv[1], ¶m->height)); - - return CreatePromise(env, __PRETTY_FUNCTION__, Async, nullptr, param); -} -} // namespace ResetSize - -namespace MoveTo { -struct Param { - ::OHOS::AppExecFwk::Ability *ability; - WMError wret; - int x; - int y; -}; - -void Async(napi_env env, std::unique_ptr& param) -{ - if (param == nullptr || param->ability == nullptr || param->ability->GetWindow() == nullptr) { - GNAPI_LOG("Error, use nullptr!)"); - param->wret = WMError::WM_ERROR_NULLPTR; - return; - } - param->wret = param->ability->GetWindow()->MoveTo(param->x, param->y); -} - -napi_value MainFunc(napi_env env, napi_callback_info info) -{ - GNAPI_LOG("Window Interface: MoveTo()"); - GNAPI_LOG("%{public}s called", __PRETTY_FUNCTION__); - constexpr int argumentSize = 2; - size_t argc = argumentSize; - napi_value argv[argc]; - - NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr)); - - GNAPI_ASSERT(env, argc < argumentSize, "MoveTo need %{public}d arguments", argumentSize); - - auto param = std::make_unique(); - NAPI_CALL(env, GetAbility(env, info, param->ability)); - NAPI_CALL(env, napi_get_value_int32(env, argv[0], ¶m->x)); - NAPI_CALL(env, napi_get_value_int32(env, argv[1], ¶m->y)); - - return CreatePromise(env, __PRETTY_FUNCTION__, Async, nullptr, param); -} -} // namespace MoveTo - -namespace SetWindowType { -struct Param { - ::OHOS::AppExecFwk::Ability *ability; - WMError wret; - int windowType; -}; - -std::map windowTypeMap { - { 0, WindowType::WINDOW_TYPE_APP_MAIN_WINDOW }, // 0 is TYPE_APP - { 30, WindowType::WINDOW_TYPE_SYSTEM_ALARM_WINDOW }, // 30 is TYPE_SYSTEM_ALERT - { 70, WindowType::WINDOW_TYPE_VOLUME_OVERLAY }, // 70 is TYPE_SYSTEM_VOLUME - { 90, WindowType::WINDOW_TYPE_PANEL }, // 90 is TYPE_SYSTEM_PANEL -}; - -void Async(napi_env env, std::unique_ptr& param) -{ - if (param == nullptr || param->ability == nullptr || param->ability->GetWindow() == nullptr) { - GNAPI_LOG("Error, use nullptr!)"); - return; - } - if (windowTypeMap.count(param->windowType) == 0) { - GNAPI_LOG("invalid window type"); - param->wret = WMError::WM_ERROR_INVALID_PARAM; - return; - } - param->wret = param->ability->GetWindow()->SetWindowType(windowTypeMap.at(param->windowType)); -} - -void CreateWindowTypeObject(napi_env env, napi_value value) -{ - SetMemberInt32(env, value, "TYPE_APP", static_cast(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW)); - SetMemberInt32(env, value, "TYPE_SYSTEM_ALERT", static_cast(WindowType::WINDOW_TYPE_SYSTEM_ALARM_WINDOW)); - SetMemberInt32(env, value, "TYPE_SYSTEM_VOLUME", static_cast(WindowType::WINDOW_TYPE_VOLUME_OVERLAY)); - SetMemberInt32(env, value, "TYPE_SYSTEM_PANEL", static_cast(WindowType::WINDOW_TYPE_PANEL)); -} - -napi_value MainFunc(napi_env env, napi_callback_info info) -{ - GNAPI_LOG("Window Interface: SetWindowType()"); - GNAPI_LOG("%{public}s called", __PRETTY_FUNCTION__); - constexpr int argumentSize = 1; - size_t argc = argumentSize; - napi_value argv[argc]; - - NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr)); - - GNAPI_ASSERT(env, argc < argumentSize, "SetWindowType need %{public}d arguments", argumentSize); - - auto param = std::make_unique(); - NAPI_CALL(env, GetAbility(env, info, param->ability)); - NAPI_CALL(env, napi_get_value_int32(env, argv[0], ¶m->windowType)); - - return CreatePromise(env, __PRETTY_FUNCTION__, Async, nullptr, param); -} -} // namespace SetWindowType -} // namespace NAPIWindow - -namespace getTopWindow { -struct Param { - ::OHOS::AppExecFwk::Ability *ability; - WMError wret; - sptr window; -}; - -void Async(napi_env env, std::unique_ptr ¶m) -{ - if (param == nullptr || param->ability == nullptr) { - GNAPI_LOG("Get top window failed!"); - param->wret = WMError::WM_ERROR_NULLPTR; - return; - } - param->window = param->ability->GetWindow(); - param->wret = WMError::WM_OK; -} - -napi_value Resolve(napi_env env, std::unique_ptr& userdata) -{ - napi_value ret; - NAPI_CALL(env, napi_new_instance(env, g_classWindow, 0, nullptr, &ret)); - return ret; -} - -napi_value MainFunc(napi_env env, napi_callback_info info) -{ - GNAPI_LOG("Window Interface: getTopWindow()"); - GNAPI_LOG("%{public}s called", __PRETTY_FUNCTION__); - auto param = std::make_unique(); - NAPI_CALL(env, GetAbility(env, info, param->ability)); - return CreatePromise(env, __PRETTY_FUNCTION__, Async, Resolve, param); -} -} // namespace getTopWindow - -napi_value WindowModuleInit(napi_env env, napi_value exports) -{ - GNAPI_LOG("%{public}s called", __PRETTY_FUNCTION__); - - napi_value nWindowType = nullptr; - NAPI_CALL(env, napi_create_object(env, &nWindowType)); - NAPIWindow::SetWindowType::CreateWindowTypeObject(env, nWindowType); - - napi_property_descriptor desc[] = { - DECLARE_NAPI_FUNCTION("resetSize", NAPIWindow::ResetSize::MainFunc), - DECLARE_NAPI_FUNCTION("moveTo", NAPIWindow::MoveTo::MainFunc), - DECLARE_NAPI_FUNCTION("setWindowType", NAPIWindow::SetWindowType::MainFunc), - }; - - NAPI_CALL(env, napi_define_class(env, "Window", NAPI_AUTO_LENGTH, - NAPIWindow::WindowConstructor, nullptr, - sizeof(desc) / sizeof(*desc), desc, &g_classWindow)); - - napi_property_descriptor exportFuncs[] = { - DECLARE_NAPI_FUNCTION("getTopWindow", getTopWindow::MainFunc), - DECLARE_NAPI_PROPERTY("WindowType", nWindowType), - DECLARE_NAPI_PROPERTY("Window", g_classWindow), - }; - - NAPI_CALL(env, napi_define_properties(env, - exports, sizeof(exportFuncs) / sizeof(*exportFuncs), exportFuncs)); - return exports; -} -} // namespace Rosen -} // namespace OHOS - -extern "C" __attribute__((constructor)) void RegisterModule(void) -{ - napi_module windowModule = { - .nm_version = 1, // NAPI v1 - .nm_flags = 0, // normal - .nm_filename = nullptr, - .nm_register_func = OHOS::Rosen::WindowModuleInit, - .nm_modname = "window", - .nm_priv = nullptr, - }; - napi_module_register(&windowModule); -} diff --git a/interfaces/kits/napi/window/native_window_module.h b/interfaces/kits/napi/window/native_window_module.h deleted file mode 100644 index c4a21c440c..0000000000 --- a/interfaces/kits/napi/window/native_window_module.h +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef INTERFACES_KITS_NAPI_GRAPHIC_WINDOW_NATIVE_WINDOW_MODULE_H -#define INTERFACES_KITS_NAPI_GRAPHIC_WINDOW_NATIVE_WINDOW_MODULE_H - -#endif // INTERFACES_KITS_NAPI_GRAPHIC_WINDOW_NATIVE_WINDOW_MODULE_H diff --git a/interfaces/kits/napi/window_runtime/BUILD.gn b/interfaces/kits/napi/window_runtime/BUILD.gn index 71420a23eb..cca6c25e45 100644 --- a/interfaces/kits/napi/window_runtime/BUILD.gn +++ b/interfaces/kits/napi/window_runtime/BUILD.gn @@ -61,7 +61,7 @@ ohos_shared_library("window_native_kit") { subsystem_name = "window" } -ohos_shared_library("windowmanager_napi") { +ohos_shared_library("window_napi") { sources = [ "window_manager_napi/js_window_manager.cpp", "window_manager_napi/window_manager_module.cpp", @@ -84,7 +84,7 @@ ohos_shared_library("windowmanager_napi") { "napi:ace_napi", ] - relative_install_dir = "module/application" + relative_install_dir = "module" part_name = "window_manager" subsystem_name = "window" diff --git a/interfaces/kits/napi/window_runtime/api/@ohos.window.d.ts b/interfaces/kits/napi/window_runtime/api/@ohos.window.d.ts index 98bc1ed796..151d9e413b 100644 --- a/interfaces/kits/napi/window_runtime/api/@ohos.window.d.ts +++ b/interfaces/kits/napi/window_runtime/api/@ohos.window.d.ts @@ -18,7 +18,7 @@ import { Context } from './app/context'; * Window manager. * @devices tv, phone, tablet, wearable. */ -declare namespace windowmanager { +declare namespace window { enum WindowType { APP_WINDOW_BASE = 1, APP_MAIN_WINDOW_BASE = APP_WINDOW_BASE, @@ -100,7 +100,7 @@ declare namespace windowmanager { WINDOW_MODE_PIP } - interface WindowManager { + interface Window { /** * Create a sub window with a specific id and type. * @param id Indicates window id. diff --git a/interfaces/kits/napi/window_runtime/window_manager_napi/js_window_manager.cpp b/interfaces/kits/napi/window_runtime/window_manager_napi/js_window_manager.cpp index f07d308298..9b1b03effc 100644 --- a/interfaces/kits/napi/window_runtime/window_manager_napi/js_window_manager.cpp +++ b/interfaces/kits/napi/window_runtime/window_manager_napi/js_window_manager.cpp @@ -13,6 +13,7 @@ * limitations under the License. */ #include "js_window_manager.h" +#include #include "js_runtime_utils.h" #include "js_window.h" #include "js_window_listener.h" @@ -66,7 +67,13 @@ public: return (me != nullptr) ? me->OnUnregisterWindowManagerCallback(*engine, *info) : nullptr; } + static NativeValue* GetTopWindow(NativeEngine* engine, NativeCallbackInfo* info) + { + JsWindowManager* me = CheckParamsAndGetThis(engine, info); + return (me != nullptr) ? me->OnGetTopWindow(*engine, *info) : nullptr; + } private: + bool isNewApi_ = true; std::weak_ptr context_; std::map, sptr>> jsCbMap_; std::mutex mtx_; @@ -304,6 +311,83 @@ private: } return engine.CreateUndefined(); } + + bool GetAPI7Ability(NativeEngine& engine, AppExecFwk::Ability* &ability) + { + napi_value global; + auto env = reinterpret_cast(&engine); + if (napi_get_global(env, &global) != napi_ok) { + WLOGFI("JsWindowManager::GetAPI7Ability get global failed"); + return false; + } + napi_value jsAbility; + if (napi_get_named_property(env, global, "ability", &jsAbility) != napi_ok) { + WLOGFI("JsWindowManager::GetAPI7Ability get global failed"); + return false; + } + if (napi_get_value_external(env, jsAbility, reinterpret_cast(&ability)) != napi_ok) { + WLOGFI("JsWindowManager::GetAPI7Ability get global failed"); + return false; + } + if (ability == nullptr) { + return false; + } else { + WLOGE("JsWindowManager::GetAPI7Ability ability is %{public}p!", ability); + } + return true; + } + + NativeValue* OnGetTopWindow(NativeEngine& engine, NativeCallbackInfo& info) + { + NativeValue* nativeContext = nullptr; + NativeValue* nativeCallback = nullptr; + if (info.argc > 0 && info.argv[0]->TypeOf() == NATIVE_OBJECT) { // (context, callback?) + isNewApi_ = true; + nativeContext = info.argv[0]; + nativeCallback = (info.argc == ARGC_ONE) ? nullptr : info.argv[1]; + } else { // (callback?) + isNewApi_ = false; + nativeCallback = (info.argc == 0) ? nullptr : info.argv[0]; + } + + AsyncTask::CompleteCallback complete = + [this, weak = context_](NativeEngine& engine, AsyncTask& task, int32_t status) { + AppExecFwk::Ability* ability = nullptr; + if (!isNewApi_) { + if (!GetAPI7Ability(engine, ability)) { + task.Reject(engine, CreateJsError(engine, + static_cast(WMError::WM_ERROR_NULLPTR), "JsWindow::onGetTopWindow failed.")); + WLOGE("JsWindowManager get top windowfailed"); + return; + } + sptr window = ability->GetWindow(); + if (window == nullptr) { + task.Reject(engine, CreateJsError(engine, + static_cast(WMError::WM_ERROR_NULLPTR), "JsWindow::onGetTopWindow failed.")); + return; + } + auto windowName = window->GetWindowName(); + std::shared_ptr jsWindowObj = FindJsWindowObject(windowName); + if (jsWindowObj != nullptr && jsWindowObj->Get() != nullptr) { + task.Resolve(engine, jsWindowObj->Get()); + } else { + task.Resolve(engine, CreateJsWindowObject(engine, window)); + } + WLOGFI("JsWindowManager::OnGetTopWindow success"); + } else { + auto context = weak.lock(); + if (context == nullptr) { + task.Reject(engine, CreateJsError(engine, + static_cast(WMError::WM_ERROR_NULLPTR), + "JsWindow::onGetTopWindow newAPI failed.")); + } + } + }; + NativeValue* result = nullptr; + AsyncTask::Schedule( + engine, CreateAsyncTaskWithLastParam(engine, nativeCallback, nullptr, std::move(complete), &result)); + return result; + } }; NativeValue* JsWindowManagerInit(NativeEngine* engine, NativeValue* exportObj) @@ -328,6 +412,7 @@ NativeValue* JsWindowManagerInit(NativeEngine* engine, NativeValue* exportObj) BindNativeFunction(*engine, *object, "find", JsWindowManager::FindWindow); BindNativeFunction(*engine, *object, "on", JsWindowManager::RegisterWindowManagerCallback); BindNativeFunction(*engine, *object, "off", JsWindowManager::UnregisterWindowMangerCallback); + BindNativeFunction(*engine, *object, "getTopWindow", JsWindowManager::GetTopWindow); return engine->CreateUndefined(); } } // namespace Rosen diff --git a/interfaces/kits/napi/window_runtime/window_manager_napi/window_manager_module.cpp b/interfaces/kits/napi/window_runtime/window_manager_napi/window_manager_module.cpp index 6f099b4052..ea7ea384be 100644 --- a/interfaces/kits/napi/window_runtime/window_manager_napi/window_manager_module.cpp +++ b/interfaces/kits/napi/window_runtime/window_manager_napi/window_manager_module.cpp @@ -20,8 +20,8 @@ extern "C" __attribute__((constructor)) void NAPI_application_windowmanager_Auto { auto moduleManager = NativeModuleManager::GetInstance(); NativeModule newModuleInfo = { - .name = "application.windowmanager", - .fileName = "application/libwindowmanager_napi.so/windowmanager.js", + .name = "window", + .fileName = "module/libwindow_napi.so/window.js", .registerCallback = OHOS::Rosen::JsWindowManagerInit, }; -- Gitee From bd7e8183481ad2828084510f252ad3f5f85d48e1 Mon Sep 17 00:00:00 2001 From: qianlf Date: Thu, 20 Jan 2022 10:00:53 +0800 Subject: [PATCH 47/57] raise keyguard zorder Signed-off-by: qianlf Change-Id: Ib73b960de4c77ce868b85b4990217ecfc34d0d81 --- wmserver/include/window_node_container.h | 2 +- wmserver/include/window_zorder_policy.h | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/wmserver/include/window_node_container.h b/wmserver/include/window_node_container.h index e45ffe6f72..e30d0fa974 100644 --- a/wmserver/include/window_node_container.h +++ b/wmserver/include/window_node_container.h @@ -118,7 +118,7 @@ private: std::unordered_map pairedWindowMap_; sptr displayRects_ = new DisplayRects(); void RaiseInputMethodWindowPriorityIfNeeded(const sptr& node) const; - const int32_t WINDOW_TYPE_RAISED_INPUT_METHOD = 113; + const int32_t WINDOW_TYPE_RAISED_INPUT_METHOD = 115; }; } } diff --git a/wmserver/include/window_zorder_policy.h b/wmserver/include/window_zorder_policy.h index 4b41705d25..2fa776718d 100644 --- a/wmserver/include/window_zorder_policy.h +++ b/wmserver/include/window_zorder_policy.h @@ -51,9 +51,9 @@ private: { WindowType::WINDOW_TYPE_TOAST, 109 }, { WindowType::WINDOW_TYPE_STATUS_BAR, 110 }, { WindowType::WINDOW_TYPE_PANEL, 111 }, - { WindowType::WINDOW_TYPE_KEYGUARD, 112 }, - { WindowType::WINDOW_TYPE_VOLUME_OVERLAY, 113 }, - { WindowType::WINDOW_TYPE_NAVIGATION_BAR, 114 }, + { WindowType::WINDOW_TYPE_VOLUME_OVERLAY, 112 }, + { WindowType::WINDOW_TYPE_NAVIGATION_BAR, 113 }, + { WindowType::WINDOW_TYPE_KEYGUARD, 114 }, { WindowType::WINDOW_TYPE_DRAGGING_EFFECT, 115 }, { WindowType::WINDOW_TYPE_POINTER, 116 }, }; -- Gitee From dd7540a2b38f0ab061e377e5f847451152a3c38b Mon Sep 17 00:00:00 2001 From: l00574490 Date: Thu, 20 Jan 2022 14:46:13 +0800 Subject: [PATCH 48/57] modify divider touch region Signed-off-by: l00574490 Change-Id: I8264e409f86008921c651a37983836755512f2f8 --- interfaces/innerkits/wm/wm_common.h | 1 + wm/test/systemtest/window_test_utils.cpp | 9 ++++----- wmserver/src/input_window_monitor.cpp | 10 ++++++++++ wmserver/src/window_node_container.cpp | 9 ++++----- 4 files changed, 19 insertions(+), 10 deletions(-) diff --git a/interfaces/innerkits/wm/wm_common.h b/interfaces/innerkits/wm/wm_common.h index 453007fd5d..c893b4e9f7 100644 --- a/interfaces/innerkits/wm/wm_common.h +++ b/interfaces/innerkits/wm/wm_common.h @@ -97,6 +97,7 @@ namespace { constexpr uint32_t SYSTEM_COLOR_WHITE = 0xFFFFFFE5; constexpr uint32_t SYSTEM_COLOR_BLACK = 0x00000066; constexpr float DEFAULT_SPLIT_RATIO = 0.5; + constexpr uint32_t DIVIDER_WIDTH = 8; } struct SystemBarProperty { diff --git a/wm/test/systemtest/window_test_utils.cpp b/wm/test/systemtest/window_test_utils.cpp index 111bd2c055..602f05fbb0 100644 --- a/wm/test/systemtest/window_test_utils.cpp +++ b/wm/test/systemtest/window_test_utils.cpp @@ -146,16 +146,15 @@ void WindowTestUtils::InitSplitRects() if (displayRect_.width_ < displayRect_.height_) { isVerticalDisplay_ = true; } - const uint32_t dividerWidth = 50; if (isVerticalDisplay_) { splitRects_.dividerRect = { 0, - static_cast((displayRect_.height_ - dividerWidth) * DEFAULT_SPLIT_RATIO), + static_cast((displayRect_.height_ - DIVIDER_WIDTH) * DEFAULT_SPLIT_RATIO), displayRect_.width_, - dividerWidth, }; + DIVIDER_WIDTH, }; } else { - splitRects_.dividerRect = { static_cast((displayRect_.width_ - dividerWidth) * DEFAULT_SPLIT_RATIO), + splitRects_.dividerRect = { static_cast((displayRect_.width_ - DIVIDER_WIDTH) * DEFAULT_SPLIT_RATIO), 0, - dividerWidth, + DIVIDER_WIDTH, displayRect_.height_ }; } } diff --git a/wmserver/src/input_window_monitor.cpp b/wmserver/src/input_window_monitor.cpp index c84454342f..64847cf3e1 100644 --- a/wmserver/src/input_window_monitor.cpp +++ b/wmserver/src/input_window_monitor.cpp @@ -147,6 +147,16 @@ void InputWindowMonitor::TraverseWindowNodes(const std::vector> .displayId = windowNode->GetDisplayId(), .agentWindowId = static_cast(windowNode->GetWindowId()), }; + if (windowNode->GetWindowType() == WindowType::WINDOW_TYPE_DOCK_SLICE) { + const int32_t divTouchRegion = 20; + if (windowInfo.width < windowInfo.height) { + windowInfo.topLeftX -= divTouchRegion; + windowInfo.width += (divTouchRegion + divTouchRegion); + } else { + windowInfo.topLeftY -= divTouchRegion; + windowInfo.height += (divTouchRegion + divTouchRegion); + } + } iter->windowsInfo_.emplace_back(windowInfo); } } diff --git a/wmserver/src/window_node_container.cpp b/wmserver/src/window_node_container.cpp index 5c3f45fc05..eb2215b439 100644 --- a/wmserver/src/window_node_container.cpp +++ b/wmserver/src/window_node_container.cpp @@ -500,13 +500,12 @@ void WindowNodeContainer::DisplayRects::InitRect(Rect& oriDisplayRect) isVertical_ = true; } displayRect_ = oriDisplayRect; - const uint32_t dividerWidth = 50; if (!isVertical_) { - dividerRect_ = { static_cast((displayRect_.width_ - dividerWidth) * DEFAULT_SPLIT_RATIO), 0, - dividerWidth, displayRect_.height_ }; + dividerRect_ = { static_cast((displayRect_.width_ - DIVIDER_WIDTH) * DEFAULT_SPLIT_RATIO), 0, + DIVIDER_WIDTH, displayRect_.height_ }; } else { - dividerRect_ = { 0, static_cast((displayRect_.height_ - dividerWidth) * DEFAULT_SPLIT_RATIO), - displayRect_.width_, dividerWidth }; + dividerRect_ = { 0, static_cast((displayRect_.height_ - DIVIDER_WIDTH) * DEFAULT_SPLIT_RATIO), + displayRect_.width_, DIVIDER_WIDTH }; } WLOGFI("init dividerRect :[%{public}d, %{public}d, %{public}d, %{public}d]", dividerRect_.posX_, dividerRect_.posY_, dividerRect_.width_, dividerRect_.height_); -- Gitee From 0a40af48ec199108e08d03df11b24270a8957b08 Mon Sep 17 00:00:00 2001 From: chenqinxin Date: Thu, 20 Jan 2022 15:06:00 +0800 Subject: [PATCH 49/57] =?UTF-8?q?=E4=BF=AE=E6=94=B9mutex=E4=B8=BArecursive?= =?UTF-8?q?=5Fmutex=20=E9=98=B2=E6=AD=A2=E5=90=8C=E8=BF=9B=E7=A8=8B?= =?UTF-8?q?=E8=B0=83=E7=94=A8=E6=97=B6=E6=97=A0=E6=B3=95=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E5=88=B0=E9=94=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chenqinxin Change-Id: I86aa44b78fbe1e1696d8d6bbb5c956475e7c7c0c --- dm/include/display_manager_adapter.h | 3 +- dm/src/display_manager.cpp | 15 +++++---- dm/src/display_manager_adapter.cpp | 28 ++++++++-------- dm/test/systemtest/display_power_test.cpp | 25 ++++----------- .../display_manager_agent_controller.h | 2 +- dmserver/include/display_power_controller.h | 2 +- .../src/display_manager_agent_controller.cpp | 8 ++--- dmserver/src/display_power_controller.cpp | 2 ++ interfaces/innerkits/dm/display_manager.h | 2 +- utils/include/client_agent_container.h | 8 ++--- wm/include/window_adapter.h | 2 +- wm/src/window_adapter.cpp | 32 +++++++++---------- wm/src/window_manager.cpp | 10 +++--- .../include/window_manager_agent_controller.h | 2 +- .../src/window_manager_agent_controller.cpp | 8 ++--- 15 files changed, 72 insertions(+), 77 deletions(-) diff --git a/dm/include/display_manager_adapter.h b/dm/include/display_manager_adapter.h index 8e194e8f68..b9de904315 100644 --- a/dm/include/display_manager_adapter.h +++ b/dm/include/display_manager_adapter.h @@ -17,6 +17,7 @@ #define FOUNDATION_DM_DISPLAY_MANAGER_ADAPTER_H #include +#include #include #include "display.h" @@ -61,7 +62,7 @@ private: static inline SingletonDelegator delegator; - std::mutex mutex_; + std::recursive_mutex mutex_; sptr displayManagerServiceProxy_ = nullptr; sptr dmsDeath_ = nullptr; std::map> displayMap_; diff --git a/dm/src/display_manager.cpp b/dm/src/display_manager.cpp index 3da629680f..2a7f9fa9fa 100644 --- a/dm/src/display_manager.cpp +++ b/dm/src/display_manager.cpp @@ -180,7 +180,7 @@ bool DisplayManager::RegisterDisplayPowerEventListener(sptr lock(mutex_); + std::lock_guard lock(mutex_); powerEventListeners_.push_back(listener); bool ret = true; if (powerEventListenerAgent_ == nullptr) { @@ -203,7 +203,7 @@ bool DisplayManager::UnregisterDisplayPowerEventListener(sptr lock(mutex_); + std::lock_guard lock(mutex_); auto iter = std::find(powerEventListeners_.begin(), powerEventListeners_.end(), listener); if (iter == powerEventListeners_.end()) { WLOGFE("could not find this listener"); @@ -224,7 +224,7 @@ void DisplayManager::NotifyDisplayPowerEvent(DisplayPowerEvent event, EventStatu { WLOGFI("NotifyDisplayPowerEvent event:%{public}u, status:%{public}u, size:%{public}zu", event, status, powerEventListeners_.size()); - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); for (auto& listener : powerEventListeners_) { listener->OnDisplayPowerEvent(event, status); } @@ -233,9 +233,10 @@ void DisplayManager::NotifyDisplayPowerEvent(DisplayPowerEvent event, EventStatu void DisplayManager::NotifyDisplayStateChanged(DisplayState state) { WLOGFI("state:%{public}u", state); - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); if (displayStateCallback_) { displayStateCallback_(state); + WLOGFW("displayStateCallback_ end"); ClearDisplayStateCallback(); return; } @@ -276,11 +277,12 @@ bool DisplayManager::SuspendEnd() bool DisplayManager::SetScreenPowerForAll(DisplayPowerState state, PowerStateChangeReason reason) { // TODO: should get all screen ids + WLOGFI("state:%{public}u, reason:%{public}u", state, reason); ScreenId defaultId = GetDefaultDisplayId(); if (defaultId == DISPLAY_ID_INVALD) { + WLOGFI("defaultId invalid!"); return false; } - WLOGFI("state:%{public}u, reason:%{public}u, defaultId:%{public}" PRIu64".", state, reason, defaultId); ScreenPowerStatus status; switch (state) { case DisplayPowerState::POWER_ON: { @@ -297,6 +299,7 @@ bool DisplayManager::SetScreenPowerForAll(DisplayPowerState state, PowerStateCha } } RSInterfaces::GetInstance().SetScreenPowerStatus(defaultId, status); + WLOGFI("SetScreenPowerStatus end"); return SingletonContainer::Get().SetScreenPowerForAll(state, reason); } @@ -310,7 +313,7 @@ DisplayPowerState DisplayManager::GetScreenPower(uint64_t screenId) bool DisplayManager::SetDisplayState(DisplayState state, DisplayStateCallback callback) { WLOGFI("state:%{public}u", state); - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); if (displayStateCallback_ != nullptr || callback == nullptr) { WLOGFI("previous callback not called or callback invalid"); return false; diff --git a/dm/src/display_manager_adapter.cpp b/dm/src/display_manager_adapter.cpp index 9173f2db47..4c01ccf593 100644 --- a/dm/src/display_manager_adapter.cpp +++ b/dm/src/display_manager_adapter.cpp @@ -29,7 +29,7 @@ WM_IMPLEMENT_SINGLE_INSTANCE(DisplayManagerAdapter) DisplayId DisplayManagerAdapter::GetDefaultDisplayId() { - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); if (defaultDisplayId_ != DISPLAY_ID_INVALD) { return defaultDisplayId_; @@ -45,7 +45,7 @@ DisplayId DisplayManagerAdapter::GetDefaultDisplayId() sptr DisplayManagerAdapter::GetDisplayById(DisplayId displayId) { - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); auto iter = displayMap_.find(displayId); if (iter != displayMap_.end()) { @@ -66,7 +66,7 @@ sptr DisplayManagerAdapter::GetDisplayById(DisplayId displayId) std::shared_ptr DisplayManagerAdapter::GetDisplaySnapshot(DisplayId displayId) { - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); if (!InitDMSProxyLocked()) { WLOGFE("displayManagerAdapter::GetDisplaySnapshot: InitDMSProxyLocked failed!"); @@ -99,7 +99,7 @@ DMError DisplayManagerAdapter::DestroyVirtualScreen(ScreenId screenId) bool DisplayManagerAdapter::RegisterDisplayManagerAgent(const sptr& displayManagerAgent, DisplayManagerAgentType type) { - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); if (!InitDMSProxyLocked()) { return false; } @@ -109,7 +109,7 @@ bool DisplayManagerAdapter::RegisterDisplayManagerAgent(const sptr& displayManagerAgent, DisplayManagerAgentType type) { - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); if (!InitDMSProxyLocked()) { return false; } @@ -118,7 +118,7 @@ bool DisplayManagerAdapter::UnregisterDisplayManagerAgent(const sptr lock(mutex_); + std::lock_guard lock(mutex_); if (!InitDMSProxyLocked()) { return false; } @@ -127,7 +127,7 @@ bool DisplayManagerAdapter::WakeUpBegin(PowerStateChangeReason reason) bool DisplayManagerAdapter::WakeUpEnd() { - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); if (!InitDMSProxyLocked()) { return false; } @@ -136,7 +136,7 @@ bool DisplayManagerAdapter::WakeUpEnd() bool DisplayManagerAdapter::SuspendBegin(PowerStateChangeReason reason) { - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); if (!InitDMSProxyLocked()) { return false; } @@ -145,7 +145,7 @@ bool DisplayManagerAdapter::SuspendBegin(PowerStateChangeReason reason) bool DisplayManagerAdapter::SuspendEnd() { - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); if (!InitDMSProxyLocked()) { return false; } @@ -154,7 +154,7 @@ bool DisplayManagerAdapter::SuspendEnd() bool DisplayManagerAdapter::SetScreenPowerForAll(DisplayPowerState state, PowerStateChangeReason reason) { - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); if (!InitDMSProxyLocked()) { return false; } @@ -164,7 +164,7 @@ bool DisplayManagerAdapter::SetScreenPowerForAll(DisplayPowerState state, PowerS bool DisplayManagerAdapter::SetDisplayState(DisplayState state) { - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); if (!InitDMSProxyLocked()) { return false; } @@ -173,7 +173,7 @@ bool DisplayManagerAdapter::SetDisplayState(DisplayState state) DisplayState DisplayManagerAdapter::GetDisplayState(uint64_t displayId) { - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); if (!InitDMSProxyLocked()) { return DisplayState::UNKNOWN; } @@ -182,7 +182,7 @@ DisplayState DisplayManagerAdapter::GetDisplayState(uint64_t displayId) void DisplayManagerAdapter::NotifyDisplayEvent(DisplayEvent event) { - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); if (!InitDMSProxyLocked()) { return; } @@ -243,7 +243,7 @@ void DMSDeathRecipient::OnRemoteDied(const wptr& wptrDeath) void DisplayManagerAdapter::Clear() { - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); if ((displayManagerServiceProxy_ != nullptr) && (displayManagerServiceProxy_->AsObject() != nullptr)) { displayManagerServiceProxy_->AsObject()->RemoveDeathRecipient(dmsDeath_); } diff --git a/dm/test/systemtest/display_power_test.cpp b/dm/test/systemtest/display_power_test.cpp index d03be7623e..be5bad70ed 100644 --- a/dm/test/systemtest/display_power_test.cpp +++ b/dm/test/systemtest/display_power_test.cpp @@ -363,31 +363,20 @@ HWTEST_F(DisplayPowerTest, set_screen_power_for_all_003, Function | MediumTest | /** * @tc.name: set_display_state_power_event_callback_001 -* @tc.desc: Call SetDisplayState OFF and check the OnDisplayPowerEvent callback is called +* @tc.desc: Call SetDisplayState with a valid value and check the OnDisplayPowerEvent callback is called * @tc.type: FUNC */ HWTEST_F(DisplayPowerTest, set_display_state_power_event_callback_001, Function | MediumTest | Level2) { - bool ret = DisplayManager::GetInstance().SetDisplayState(DisplayState::OFF, callback_); - ASSERT_EQ(true, ret); - CheckDisplayPowerEventCallback(true); - ASSERT_EQ(true, listener_->isCallbackCalled_); - ASSERT_EQ(DisplayPowerEvent::DISPLAY_OFF, listener_->event_); - ASSERT_EQ(EventStatus::BEGIN, listener_->status_); -} - -/** -* @tc.name: set_display_state_power_event_callback_002 -* @tc.desc: Call SetDisplayState ON and check the OnDisplayPowerEvent callback is called -* @tc.type: FUNC -*/ -HWTEST_F(DisplayPowerTest, set_display_state_power_event_callback_002, Function | MediumTest | Level2) -{ - bool ret = DisplayManager::GetInstance().SetDisplayState(DisplayState::ON, callback_); + DisplayState initialState = DisplayManager::GetInstance().GetDisplayState(defaultId_); + DisplayState stateToSet = (initialState == DisplayState::OFF ? DisplayState::ON : DisplayState::OFF); + bool ret = DisplayManager::GetInstance().SetDisplayState(stateToSet, callback_); ASSERT_EQ(true, ret); CheckDisplayPowerEventCallback(true); ASSERT_EQ(true, listener_->isCallbackCalled_); - ASSERT_EQ(DisplayPowerEvent::DISPLAY_ON, listener_->event_); + DisplayPowerEvent expectedEvent = (stateToSet == DisplayState::OFF ? DisplayPowerEvent::DISPLAY_OFF : + DisplayPowerEvent::DISPLAY_ON); + ASSERT_EQ(expectedEvent, listener_->event_); ASSERT_EQ(EventStatus::BEGIN, listener_->status_); } diff --git a/dmserver/include/display_manager_agent_controller.h b/dmserver/include/display_manager_agent_controller.h index c5f4e92afc..2bb18cb179 100644 --- a/dmserver/include/display_manager_agent_controller.h +++ b/dmserver/include/display_manager_agent_controller.h @@ -38,7 +38,7 @@ private: DisplayManagerAgentController() : dmAgentContainer_(mutex_) {} virtual ~DisplayManagerAgentController() = default; - std::mutex mutex_; + std::recursive_mutex mutex_; ClientAgentContainer dmAgentContainer_; }; } diff --git a/dmserver/include/display_power_controller.h b/dmserver/include/display_power_controller.h index 79b4a983b0..26830bf7ff 100644 --- a/dmserver/include/display_power_controller.h +++ b/dmserver/include/display_power_controller.h @@ -33,7 +33,7 @@ public: void NotifyDisplayEvent(DisplayEvent event); private: - DisplayState displayState_ { DisplayState::ON }; + DisplayState displayState_ { DisplayState::UNKNOWN }; }; } } diff --git a/dmserver/src/display_manager_agent_controller.cpp b/dmserver/src/display_manager_agent_controller.cpp index dd00f4a534..c624daf960 100644 --- a/dmserver/src/display_manager_agent_controller.cpp +++ b/dmserver/src/display_manager_agent_controller.cpp @@ -26,20 +26,20 @@ WM_IMPLEMENT_SINGLE_INSTANCE(DisplayManagerAgentController) bool DisplayManagerAgentController::RegisterDisplayManagerAgent(const sptr& displayManagerAgent, DisplayManagerAgentType type) { - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); return dmAgentContainer_.RegisterAgentLocked(displayManagerAgent, type); } bool DisplayManagerAgentController::UnregisterDisplayManagerAgent(const sptr& displayManagerAgent, DisplayManagerAgentType type) { - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); return dmAgentContainer_.UnregisterAgentLocked(displayManagerAgent, type); } bool DisplayManagerAgentController::NotifyDisplayPowerEvent(DisplayPowerEvent event, EventStatus status) { - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); auto agents = dmAgentContainer_.GetAgentsByType(DisplayManagerAgentType::DISPLAY_POWER_EVENT_LISTENER); if (agents.empty()) { return false; @@ -53,7 +53,7 @@ bool DisplayManagerAgentController::NotifyDisplayPowerEvent(DisplayPowerEvent ev bool DisplayManagerAgentController::NotifyDisplayStateChanged(DisplayState state) { - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); auto agents = dmAgentContainer_.GetAgentsByType(DisplayManagerAgentType::DISPLAY_STATE_LISTENER); if (agents.empty()) { return false; diff --git a/dmserver/src/display_power_controller.cpp b/dmserver/src/display_power_controller.cpp index f93b75dd6b..74aa0a3f85 100644 --- a/dmserver/src/display_power_controller.cpp +++ b/dmserver/src/display_power_controller.cpp @@ -70,6 +70,8 @@ void DisplayPowerController::NotifyDisplayEvent(DisplayEvent event) if (event == DisplayEvent::UNLOCK) { WLOGFI("DisplayEvent UNLOCK"); // TODO: WindowManagerServiceInner::GetInstance().RestoreSuspendedWindows(); + DisplayManagerAgentController::GetInstance().NotifyDisplayPowerEvent(DisplayPowerEvent::DESKTOP_READY, + EventStatus::BEGIN); return; } // TODO: set displayState_ ON when keyguard is drawn diff --git a/interfaces/innerkits/dm/display_manager.h b/interfaces/innerkits/dm/display_manager.h index aa09f768f0..87a178aaf6 100644 --- a/interfaces/innerkits/dm/display_manager.h +++ b/interfaces/innerkits/dm/display_manager.h @@ -72,7 +72,7 @@ private: static inline SingletonDelegator delegator; const int32_t MAX_RESOLUTION_SIZE_SCREENSHOT = 15360; // max resolution, 16K - std::mutex mutex_; + std::recursive_mutex mutex_; std::vector> powerEventListeners_; sptr powerEventListenerAgent_; sptr displayStateAgent_; diff --git a/utils/include/client_agent_container.h b/utils/include/client_agent_container.h index 5fbe72d228..7c824cde3f 100644 --- a/utils/include/client_agent_container.h +++ b/utils/include/client_agent_container.h @@ -27,7 +27,7 @@ namespace Rosen { template class ClientAgentContainer { public: - ClientAgentContainer(std::mutex& mutex); + ClientAgentContainer(std::recursive_mutex& mutex); virtual ~ClientAgentContainer() = default; bool RegisterAgentLocked(const sptr& agent, T2 type); @@ -49,13 +49,13 @@ private: sptr remoteObject_; }; - std::mutex& mutex_; + std::recursive_mutex& mutex_; std::map>> agentMap_; sptr deathRecipient_; }; template -ClientAgentContainer::ClientAgentContainer(std::mutex& mutex) +ClientAgentContainer::ClientAgentContainer(std::recursive_mutex& mutex) : mutex_(mutex), deathRecipient_(new AgentDeathRecipient( std::bind(&ClientAgentContainer::RemoveAgent, this, std::placeholders::_1))) {} @@ -111,7 +111,7 @@ template void ClientAgentContainer::RemoveAgent(const sptr& remoteObject) { WLOG_I("ClientAgentContainer RemoveAgent"); - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); for (auto& elem : agentMap_) { if (UnregisterAgentLocked(elem.second, remoteObject)) { break; diff --git a/wm/include/window_adapter.h b/wm/include/window_adapter.h index 590949c815..7b1d628276 100644 --- a/wm/include/window_adapter.h +++ b/wm/include/window_adapter.h @@ -60,7 +60,7 @@ private: static inline SingletonDelegator delegator; bool InitWMSProxyLocked(); - std::mutex mutex_; + std::recursive_mutex mutex_; sptr windowManagerServiceProxy_ = nullptr; sptr wmsDeath_ = nullptr; }; diff --git a/wm/src/window_adapter.cpp b/wm/src/window_adapter.cpp index 9823b93f6c..58765849dd 100644 --- a/wm/src/window_adapter.cpp +++ b/wm/src/window_adapter.cpp @@ -28,7 +28,7 @@ WM_IMPLEMENT_SINGLE_INSTANCE(WindowAdapter) WMError WindowAdapter::SaveAbilityToken(const sptr& abilityToken, uint32_t windowId) { - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); if (!InitWMSProxyLocked()) { return WMError::WM_ERROR_SAMGR; @@ -39,7 +39,7 @@ WMError WindowAdapter::SaveAbilityToken(const sptr& abilityToken, WMError WindowAdapter::CreateWindow(sptr& window, sptr& windowProperty, std::shared_ptr surfaceNode, uint32_t& windowId) { - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); if (!InitWMSProxyLocked()) { return WMError::WM_ERROR_SAMGR; @@ -49,7 +49,7 @@ WMError WindowAdapter::CreateWindow(sptr& window, sptr& WMError WindowAdapter::AddWindow(sptr& windowProperty) { - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); if (!InitWMSProxyLocked()) { return WMError::WM_ERROR_SAMGR; @@ -59,7 +59,7 @@ WMError WindowAdapter::AddWindow(sptr& windowProperty) WMError WindowAdapter::RemoveWindow(uint32_t windowId) { - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); if (!InitWMSProxyLocked()) { return WMError::WM_ERROR_SAMGR; @@ -69,7 +69,7 @@ WMError WindowAdapter::RemoveWindow(uint32_t windowId) WMError WindowAdapter::DestroyWindow(uint32_t windowId) { - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); if (!InitWMSProxyLocked()) { return WMError::WM_ERROR_SAMGR; @@ -79,7 +79,7 @@ WMError WindowAdapter::DestroyWindow(uint32_t windowId) WMError WindowAdapter::MoveTo(uint32_t windowId, int32_t x, int32_t y) { - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); if (!InitWMSProxyLocked()) { return WMError::WM_ERROR_SAMGR; @@ -89,7 +89,7 @@ WMError WindowAdapter::MoveTo(uint32_t windowId, int32_t x, int32_t y) WMError WindowAdapter::Resize(uint32_t windowId, uint32_t width, uint32_t height) { - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); if (!InitWMSProxyLocked()) { return WMError::WM_ERROR_SAMGR; @@ -99,7 +99,7 @@ WMError WindowAdapter::Resize(uint32_t windowId, uint32_t width, uint32_t height WMError WindowAdapter::RequestFocus(uint32_t windowId) { - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); if (!InitWMSProxyLocked()) { return WMError::WM_ERROR_SAMGR; @@ -109,7 +109,7 @@ WMError WindowAdapter::RequestFocus(uint32_t windowId) WMError WindowAdapter::SetWindowFlags(uint32_t windowId, uint32_t flags) { - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); if (!InitWMSProxyLocked()) { return WMError::WM_ERROR_SAMGR; @@ -119,7 +119,7 @@ WMError WindowAdapter::SetWindowFlags(uint32_t windowId, uint32_t flags) WMError WindowAdapter::SetSystemBarProperty(uint32_t windowId, WindowType type, const SystemBarProperty& property) { - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); if (!InitWMSProxyLocked()) { return WMError::WM_ERROR_SAMGR; @@ -130,7 +130,7 @@ WMError WindowAdapter::SetSystemBarProperty(uint32_t windowId, WindowType type, void WindowAdapter::RegisterWindowManagerAgent(WindowManagerAgentType type, const sptr& windowManagerAgent) { - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); if (!InitWMSProxyLocked()) { return; @@ -141,7 +141,7 @@ void WindowAdapter::RegisterWindowManagerAgent(WindowManagerAgentType type, void WindowAdapter::UnregisterWindowManagerAgent(WindowManagerAgentType type, const sptr& windowManagerAgent) { - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); if (!InitWMSProxyLocked()) { return; @@ -151,7 +151,7 @@ void WindowAdapter::UnregisterWindowManagerAgent(WindowManagerAgentType type, WMError WindowAdapter::GetAvoidAreaByType(uint32_t windowId, AvoidAreaType type, std::vector& avoidRect) { - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); if (!InitWMSProxyLocked()) { return WMError::WM_ERROR_SAMGR; @@ -162,7 +162,7 @@ WMError WindowAdapter::GetAvoidAreaByType(uint32_t windowId, AvoidAreaType type, WMError WindowAdapter::SetWindowMode(uint32_t windowId, WindowMode mode) { - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); if (!InitWMSProxyLocked()) { return WMError::WM_ERROR_SAMGR; } @@ -171,7 +171,7 @@ WMError WindowAdapter::SetWindowMode(uint32_t windowId, WindowMode mode) WMError WindowAdapter::MinimizeAllAppNodeAbility(uint32_t windowId) { - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); if (!InitWMSProxyLocked()) { return WMError::WM_ERROR_SAMGR; } @@ -215,7 +215,7 @@ bool WindowAdapter::InitWMSProxyLocked() void WindowAdapter::ClearWindowAdapter() { - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); if ((windowManagerServiceProxy_ != nullptr) && (windowManagerServiceProxy_->AsObject() != nullptr)) { windowManagerServiceProxy_->AsObject()->RemoveDeathRecipient(wmsDeath_); } diff --git a/wm/src/window_manager.cpp b/wm/src/window_manager.cpp index e3a1f05829..2ae1db500a 100644 --- a/wm/src/window_manager.cpp +++ b/wm/src/window_manager.cpp @@ -36,7 +36,7 @@ public: void NotifySystemBarChanged(uint64_t displayId, const SystemBarProps& props) const; static inline SingletonDelegator delegator_; - std::mutex mutex_; + std::recursive_mutex mutex_; std::vector> focusChangedListeners_; sptr focusChangedListenerAgent_; std::vector> systemBarChangedListeners_; @@ -90,7 +90,7 @@ void WindowManager::RegisterFocusChangedListener(const sptr lock(pImpl_->mutex_); + std::lock_guard lock(pImpl_->mutex_); pImpl_->focusChangedListeners_.push_back(listener); if (pImpl_->focusChangedListenerAgent_ == nullptr) { pImpl_->focusChangedListenerAgent_ = new WindowManagerAgent(); @@ -106,7 +106,7 @@ void WindowManager::UnregisterFocusChangedListener(const sptr lock(pImpl_->mutex_); + std::lock_guard lock(pImpl_->mutex_); auto iter = std::find(pImpl_->focusChangedListeners_.begin(), pImpl_->focusChangedListeners_.end(), listener); if (iter == pImpl_->focusChangedListeners_.end()) { WLOGFE("could not find this listener"); @@ -127,7 +127,7 @@ void WindowManager::RegisterSystemBarChangedListener(const sptr lock(pImpl_->mutex_); + std::lock_guard lock(pImpl_->mutex_); pImpl_->systemBarChangedListeners_.push_back(listener); if (pImpl_->systemBarChangedListenerAgent_ == nullptr) { pImpl_->systemBarChangedListenerAgent_ = new WindowManagerAgent(); @@ -143,7 +143,7 @@ void WindowManager::UnregisterSystemBarChangedListener(const sptr lock(pImpl_->mutex_); + std::lock_guard lock(pImpl_->mutex_); auto iter = std::find(pImpl_->systemBarChangedListeners_.begin(), pImpl_->systemBarChangedListeners_.end(), listener); if (iter == pImpl_->systemBarChangedListeners_.end()) { diff --git a/wmserver/include/window_manager_agent_controller.h b/wmserver/include/window_manager_agent_controller.h index eacf785982..515f433196 100644 --- a/wmserver/include/window_manager_agent_controller.h +++ b/wmserver/include/window_manager_agent_controller.h @@ -39,7 +39,7 @@ private: WindowManagerAgentController() : wmAgentContainer_(mutex_) {} virtual ~WindowManagerAgentController() = default; - std::mutex mutex_; + std::recursive_mutex mutex_; ClientAgentContainer wmAgentContainer_; }; } diff --git a/wmserver/src/window_manager_agent_controller.cpp b/wmserver/src/window_manager_agent_controller.cpp index 998ea6e974..3a48a47440 100644 --- a/wmserver/src/window_manager_agent_controller.cpp +++ b/wmserver/src/window_manager_agent_controller.cpp @@ -26,21 +26,21 @@ WM_IMPLEMENT_SINGLE_INSTANCE(WindowManagerAgentController) void WindowManagerAgentController::RegisterWindowManagerAgent(const sptr& windowManagerAgent, WindowManagerAgentType type) { - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); wmAgentContainer_.RegisterAgentLocked(windowManagerAgent, type); } void WindowManagerAgentController::UnregisterWindowManagerAgent(const sptr& windowManagerAgent, WindowManagerAgentType type) { - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); wmAgentContainer_.UnregisterAgentLocked(windowManagerAgent, type); } void WindowManagerAgentController::UpdateFocusStatus(uint32_t windowId, const sptr& abilityToken, WindowType windowType, int32_t displayId, bool focused) { - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); WLOGFI("UpdateFocusStatus"); for (auto& agent : wmAgentContainer_.GetAgentsByType(WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_FOCUS)) { agent->UpdateFocusStatus(windowId, abilityToken, windowType, displayId, focused); @@ -52,7 +52,7 @@ void WindowManagerAgentController::UpdateSystemBarProperties(uint64_t displayId, if (props.empty()) { return; } - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); WLOGFI("UpdateSystemBarProperties"); for (auto& agent : wmAgentContainer_.GetAgentsByType( WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_SYSTEM_BAR)) { -- Gitee From d93649cb49c4bf1e7f353e9094738296c49f1243 Mon Sep 17 00:00:00 2001 From: xiahaiqin Date: Wed, 19 Jan 2022 16:42:47 +0800 Subject: [PATCH 50/57] split dm from libwm Signed-off-by: xiahaiqin Change-Id: Ie85820c79b1d6fe9e551f34346b6b3beb362deda --- bundle.json | 3 +- dm/BUILD.gn | 5 +- dmserver/BUILD.gn | 4 +- interfaces/innerkits/dm/display_manager.h | 2 - interfaces/innerkits/wm/window.h | 16 ++--- interfaces/kits/napi/display/BUILD.gn | 1 + interfaces/kits/napi/screenshot/BUILD.gn | 4 +- .../window_napi/js_window_utils.h | 1 + snapshot/BUILD.gn | 1 + wm/BUILD.gn | 71 ++++--------------- wm/include/window_impl.h | 2 + wm/include/window_input_channel.h | 2 + wm/src/window_impl.cpp | 2 + wm/test/systemtest/BUILD.gn | 5 ++ wm/test/unittest/BUILD.gn | 5 ++ 15 files changed, 53 insertions(+), 71 deletions(-) diff --git a/bundle.json b/bundle.json index a3037e7ac3..ea062df3a2 100644 --- a/bundle.json +++ b/bundle.json @@ -2,13 +2,14 @@ "name": "@openharmony/window_manager", "version": "3.1.0", "description": "window_manager", - "author": {}, "repository": "", "license": "Apache License 2.0", "component": { "name": "window_manager", "subsystem": "window", "adapted_system_type": [ "standard" ], + "rom": {}, + "ram": {}, "deps": { "components": [ ], diff --git a/dm/BUILD.gn b/dm/BUILD.gn index 241c5900a0..87b80a6334 100644 --- a/dm/BUILD.gn +++ b/dm/BUILD.gn @@ -29,7 +29,10 @@ config("libdm_private_config") { } config("libdm_public_config") { - include_dirs = [ "../interfaces/innerkits/dm" ] + include_dirs = [ + "../interfaces/innerkits/dm", + "../utils/include", + ] } ## Build libdm.so diff --git a/dmserver/BUILD.gn b/dmserver/BUILD.gn index 853a11d99f..3fffd2f135 100644 --- a/dmserver/BUILD.gn +++ b/dmserver/BUILD.gn @@ -52,12 +52,13 @@ ohos_shared_library("libdms") { deps = [ "//foundation/distributedschedule/safwk/interfaces/innerkits/safwk:system_ability_fwk", "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", + "//foundation/windowmanager/dm:libdm", "//foundation/windowmanager/utils:libwmutil", "//utils/native/base:utils", # RSSurface "//foundation/graphic/standard:libsurface", - "//foundation/graphic/standard/rosen/modules/render_service_base:librender_service_base", + "//foundation/graphic/standard/rosen/modules/render_service_client:librender_service_client", # todo need delete it "//foundation/windowmanager/wmserver:libwms", @@ -67,7 +68,6 @@ ohos_shared_library("libdms") { "bytrace_standard:bytrace_core", "hilog_native:libhilog", "ipc:ipc_core", - "window_manager:libdm", ] part_name = "window_manager" diff --git a/interfaces/innerkits/dm/display_manager.h b/interfaces/innerkits/dm/display_manager.h index aa09f768f0..bf49ecf562 100644 --- a/interfaces/innerkits/dm/display_manager.h +++ b/interfaces/innerkits/dm/display_manager.h @@ -19,14 +19,12 @@ #include #include #include -#include #include "display.h" #include "dm_common.h" #include "singleton_delegator.h" // #include "wm_common.h" - namespace OHOS::Rosen { class DisplayManagerAdapter; class DisplayManagerAgent; diff --git a/interfaces/innerkits/wm/window.h b/interfaces/innerkits/wm/window.h index d1427f4148..bdce754292 100644 --- a/interfaces/innerkits/wm/window.h +++ b/interfaces/innerkits/wm/window.h @@ -16,31 +16,31 @@ #ifndef OHOS_ROSEN_WINDOW_H #define OHOS_ROSEN_WINDOW_H -#include -#include -#include #include -#include -#include -#include -#include -#include "foundation/aafwk/standard/frameworks/kits/appkit/native/ability_runtime/context/context.h" + #include "wm_common.h" #include "window_option.h" #include "window_life_cycle_interface.h" class NativeValue; class NativeEngine; +namespace OHOS::MMI { + struct IInputEventConsumer; + class PointerEvent; + class KeyEvent; +} namespace OHOS::AppExecFwk { class Configuration; } namespace OHOS::AbilityRuntime { class AbilityContext; + class Context; } namespace OHOS { namespace Rosen { +class RSSurfaceNode; class IWindowChangeListener : virtual public RefBase { public: virtual void OnSizeChange(Rect rect) = 0; diff --git a/interfaces/kits/napi/display/BUILD.gn b/interfaces/kits/napi/display/BUILD.gn index 574ecb8a1c..02c1708dba 100644 --- a/interfaces/kits/napi/display/BUILD.gn +++ b/interfaces/kits/napi/display/BUILD.gn @@ -19,6 +19,7 @@ ohos_shared_library("display") { deps = [ "../common:wm_napi_common", + "//foundation/windowmanager/dm:libdm", "//foundation/windowmanager/wm:libwm", "//foundation/windowmanager/wmserver:libwms", ] diff --git a/interfaces/kits/napi/screenshot/BUILD.gn b/interfaces/kits/napi/screenshot/BUILD.gn index 53726a5139..78eb7cd50d 100644 --- a/interfaces/kits/napi/screenshot/BUILD.gn +++ b/interfaces/kits/napi/screenshot/BUILD.gn @@ -20,14 +20,16 @@ ohos_shared_library("screenshot") { deps = [ "../common:wm_napi_common", "//foundation/multimedia/image_standard/interfaces/innerkits:image", + "//foundation/multimedia/image_standard/interfaces/innerkits:image_native", + "//foundation/windowmanager/dm:libdm", "//foundation/windowmanager/utils:libwmutil", + "//foundation/windowmanager/wm:libwm", ] external_deps = [ "ability_runtime:runtime", "hiviewdfx_hilog_native:libhilog", "napi:ace_napi", - "window_manager:libwm", ] relative_install_dir = "module" diff --git a/interfaces/kits/napi/window_runtime/window_napi/js_window_utils.h b/interfaces/kits/napi/window_runtime/window_napi/js_window_utils.h index f3d6a79e43..5cd4624e2d 100644 --- a/interfaces/kits/napi/window_runtime/window_napi/js_window_utils.h +++ b/interfaces/kits/napi/window_runtime/window_napi/js_window_utils.h @@ -15,6 +15,7 @@ #ifndef OHOS_JS_WINDOW_UTILS_H #define OHOS_JS_WINDOW_UTILS_H +#include #include "native_engine/native_engine.h" #include "native_engine/native_value.h" #include "window.h" diff --git a/snapshot/BUILD.gn b/snapshot/BUILD.gn index 43dc106c83..aa2543d377 100644 --- a/snapshot/BUILD.gn +++ b/snapshot/BUILD.gn @@ -33,6 +33,7 @@ ohos_executable("snapshot_display") { "//foundation/windowmanager/utils:libwmutil", "//foundation/windowmanager/wm:libwm", "//third_party/libpng:libpng", # png + "//utils/native/base:utils", ] part_name = "window_manager" diff --git a/wm/BUILD.gn b/wm/BUILD.gn index d2874a7821..6dfaad1dc9 100644 --- a/wm/BUILD.gn +++ b/wm/BUILD.gn @@ -13,30 +13,17 @@ import("//build/ohos.gni") -config("libwm_config") { +config("libwm_private_config") { visibility = [ ":*" ] include_dirs = [ "include", - "//utils/system/safwk/native/include", - "//foundation/windowmanager/wmserver/include", - "//foundation/windowmanager/dm/include", - "//foundation/windowmanager/dmserver/include", - "//foundation/windowmanager/utils/include", + "../wmserver/include", - # for abilityContext + # todo for abilitycontext need delete it "//foundation/aafwk/standard/frameworks/kits/ability/ability_runtime/include", - "//foundation/aafwk/standard/interfaces/innerkits/app_manager/include/appmgr", - "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_base/include", - "//base/global/resmgr_standard/interfaces/innerkits/include", - "//third_party/node/deps/icu-small/source/common", "//foundation/aafwk/standard/interfaces/innerkits/ability_manager/include", - "//foundation/aafwk/standard/interfaces/innerkits/want/include/ohos/aafwk/content", - "//foundation/distributedschedule/dmsfwk/services/dtbschedmgr/include", - "//foundation/aafwk/standard/interfaces/innerkits/base/include", - - # abilityContext end - + "//foundation/aafwk/standard/interfaces/innerkits/app_manager/include/appmgr", "//third_party/jsoncpp/include", "//third_party/json/include", ] @@ -50,31 +37,14 @@ config("libwm_config") { config("libwm_public_config") { include_dirs = [ - "//foundation/windowmanager/interfaces/innerkits/wm", - "//foundation/windowmanager/wmserver/include", - "//foundation/windowmanager/dm/include", - "//foundation/windowmanager/dmserver/include", - "//foundation/windowmanager/utils/include", - "../interfaces/innerkits/dm", + "../interfaces/innerkits/wm", + "../utils/include", ] } -config("libwm_public_config_test") { - include_dirs = [ "//foundation/windowmanager/interfaces/innerkits" ] -} - ## Build libwm.so ohos_shared_library("libwm") { sources = [ - "../dm/src/display.cpp", - "../dm/src/display_manager.cpp", - "../dm/src/display_manager_adapter.cpp", - "../dm/src/display_manager_agent.cpp", - "../dm/src/screen.cpp", - "../dm/src/screen_group.cpp", - "../dm/src/screen_manager.cpp", - "../dm/src/zidl/display_manager_agent_stub.cpp", - "../dmserver/src/display_manager_proxy.cpp", "../wmserver/src/window_manager_proxy.cpp", "src/input_transfer_station.cpp", "src/static_call.cpp", @@ -92,12 +62,11 @@ ohos_shared_library("libwm") { "src/zidl/window_manager_agent_stub.cpp", ] - configs = [ ":libwm_config" ] + configs = [ ":libwm_private_config" ] public_configs = [ ":libwm_public_config" ] deps = [ - "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog", "//foundation/distributedschedule/safwk/interfaces/innerkits/safwk:system_ability_fwk", "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", "//foundation/multimedia/image_standard/interfaces/innerkits:image_native", @@ -108,35 +77,25 @@ ohos_shared_library("libwm") { "//foundation/ace/ace_engine/interfaces/innerkits/ace:ace_uicontent", "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_core:appexecfwk_core", "//foundation/graphic/standard:libsurface", - "//foundation/multimedia/image_standard/interfaces/innerkits:image_native", - ] - - public_deps = [ - # native value - # RSSurface - "//foundation/ace/napi:ace_napi", - "//foundation/graphic/standard:libsurface", + "//foundation/graphic/standard/rosen/modules/render_service_client:librender_service_client", # vsync "//foundation/graphic/standard:libvsync_client", - "//foundation/graphic/standard/rosen/modules/render_service_base:librender_service_base", - "//foundation/graphic/standard/rosen/modules/render_service_client:librender_service_client", - - # IMS - "//foundation/multimodalinput/input/frameworks/proxy:libmmi-client", - "//foundation/multimodalinput/input/frameworks/proxy:libmmi-common", - # context - - "//foundation/aafwk/standard/frameworks/kits/appkit:app_context", - "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_base:appexecfwk_base", + # todo need delete it for abilitycontext + "//foundation/ace/napi:ace_napi", ] external_deps = [ "ability_runtime:ability_context_native", + "ability_runtime:want", + "appexecfwk_standard:appexecfwk_base", "bytrace_standard:bytrace_core", + "hilog_native:libhilog", "inputmethod_native:inputmethod_client", "ipc:ipc_core", + "multimedia_image_standard:image_native", + "multimodalinput_base:libmmi-client", "window_manager:libdm", ] diff --git a/wm/include/window_impl.h b/wm/include/window_impl.h index 4c748041b8..c2770d97b9 100644 --- a/wm/include/window_impl.h +++ b/wm/include/window_impl.h @@ -17,6 +17,8 @@ #define OHOS_ROSEN_WINDOW_IMPL_H #include #include +#include +#include #include #include #include "input_transfer_station.h" diff --git a/wm/include/window_input_channel.h b/wm/include/window_input_channel.h index c58acb6f95..30a9b7ab8a 100644 --- a/wm/include/window_input_channel.h +++ b/wm/include/window_input_channel.h @@ -14,6 +14,8 @@ */ #include +#include +#include #include "refbase.h" #include "vsync_station.h" #ifndef OHOS_WINDOW_INPUT_CHANNEL diff --git a/wm/src/window_impl.cpp b/wm/src/window_impl.cpp index 13a29108db..bb89609ba3 100644 --- a/wm/src/window_impl.cpp +++ b/wm/src/window_impl.cpp @@ -16,6 +16,8 @@ #include "window_impl.h" #include +#include + #include "display_manager.h" #include "singleton_container.h" #include "window_adapter.h" diff --git a/wm/test/systemtest/BUILD.gn b/wm/test/systemtest/BUILD.gn index 9b3ee8a262..677279899a 100644 --- a/wm/test/systemtest/BUILD.gn +++ b/wm/test/systemtest/BUILD.gn @@ -139,7 +139,12 @@ ohos_static_library("wm_systemtest_common") { public_deps = [ "//foundation/ace/ace_engine/interfaces/innerkits/ace:ace_uicontent", + + # todo need delete it for abilitycontext + "//foundation/ace/napi:ace_napi", "//foundation/multimodalinput/input/frameworks/proxy:libmmi-client", + "//foundation/windowmanager/dm:libdm", + "//foundation/windowmanager/dmserver:libdms", "//foundation/windowmanager/utils:libwmutil", "//foundation/windowmanager/wm:libwm", "//foundation/windowmanager/wmserver:libwms", diff --git a/wm/test/unittest/BUILD.gn b/wm/test/unittest/BUILD.gn index 872273a3c2..062ff5145b 100644 --- a/wm/test/unittest/BUILD.gn +++ b/wm/test/unittest/BUILD.gn @@ -161,8 +161,13 @@ ohos_static_library("wm_unittest_common") { public_deps = [ "//foundation/ace/ace_engine/interfaces/innerkits/ace:ace_uicontent", + + # todo need delete it for abilitycontext + "//foundation/ace/napi:ace_napi", "//foundation/distributedschedule/safwk/interfaces/innerkits/safwk:system_ability_fwk", "//foundation/multimodalinput/input/frameworks/proxy:libmmi-client", + "//foundation/windowmanager/dm:libdm", + "//foundation/windowmanager/dmserver:libdms", "//foundation/windowmanager/utils:libwmutil", "//foundation/windowmanager/wm:libwm", "//foundation/windowmanager/wmserver:libwms", -- Gitee From c675578af4faf495ec9ccd2bfa901e3444b15df7 Mon Sep 17 00:00:00 2001 From: jincanran Date: Thu, 20 Jan 2022 20:41:33 +0800 Subject: [PATCH 51/57] notify region change to systemBar calback Change-Id: I5c72873a5d558e9a81c00d4003e01b9efba28260 Signed-off-by: jincanran --- interfaces/innerkits/wm/window_manager.h | 14 +++- interfaces/innerkits/wm/wm_common.h | 6 +- .../window_napi/js_window_listener.cpp | 4 +- .../window_napi/js_window_listener.h | 2 +- .../window_napi/js_window_utils.cpp | 26 +++---- .../window_napi/js_window_utils.h | 3 +- wm/include/window_manager_agent.h | 2 +- .../zidl/window_manager_agent_interface.h | 3 +- wm/include/zidl/window_manager_agent_proxy.h | 2 +- wm/src/window_impl.cpp | 4 + wm/src/window_manager.cpp | 20 ++--- wm/src/window_manager_agent.cpp | 4 +- wm/src/zidl/window_manager_agent_proxy.cpp | 22 ++++-- wm/src/zidl/window_manager_agent_stub.cpp | 9 ++- wm/test/systemtest/window_immersive_test.cpp | 77 +++++++++++-------- wmserver/include/window_layout_policy.h | 5 +- .../include/window_manager_agent_controller.h | 2 +- wmserver/include/window_node_container.h | 10 ++- .../src/window_manager_agent_controller.cpp | 8 +- wmserver/src/window_node_container.cpp | 64 ++++++++++----- 20 files changed, 177 insertions(+), 110 deletions(-) diff --git a/interfaces/innerkits/wm/window_manager.h b/interfaces/innerkits/wm/window_manager.h index 37221d1e2c..e7581c438c 100644 --- a/interfaces/innerkits/wm/window_manager.h +++ b/interfaces/innerkits/wm/window_manager.h @@ -25,6 +25,16 @@ namespace OHOS { namespace Rosen { +struct SystemBarRegionTint { + WindowType type_; + SystemBarProperty prop_; + Rect region_; + SystemBarRegionTint() : prop_(SystemBarProperty()) {} + SystemBarRegionTint(WindowType type, SystemBarProperty prop, Rect region) + : type_(type), prop_(prop), region_(region) {} +}; +using SystemBarRegionTints = std::vector; + class IFocusChangedListener : public RefBase { public: virtual void OnFocused(uint32_t windowId, sptr abilityToken, @@ -36,7 +46,7 @@ public: class ISystemBarChangedListener : virtual public RefBase { public: - virtual void OnSystemBarPropertyChange(uint64_t displayId, SystemBarProps props) = 0; + virtual void OnSystemBarPropertyChange(uint64_t displayId, const SystemBarRegionTints& tints) = 0; }; class WindowManager { @@ -56,7 +66,7 @@ private: void UpdateFocusStatus(uint32_t windowId, const sptr& abilityToken, WindowType windowType, int32_t displayId, bool focused) const; - void UpdateSystemBarProperties(uint64_t displayId, const SystemBarProps& props) const; + void UpdateSystemBarRegionTints(uint64_t displayId, const SystemBarRegionTints& tints) const; }; } // namespace Rosen } // namespace OHOS diff --git a/interfaces/innerkits/wm/wm_common.h b/interfaces/innerkits/wm/wm_common.h index c893b4e9f7..a7b6a764dc 100644 --- a/interfaces/innerkits/wm/wm_common.h +++ b/interfaces/innerkits/wm/wm_common.h @@ -91,6 +91,10 @@ struct Rect { int32_t posY_; uint32_t width_; uint32_t height_; + bool operator == (const Rect& a) const + { + return (posX_ == a.posX_ && posY_ == a.posY_ && width_ == a.width_ && height_ == a.height_); + } }; namespace { @@ -113,8 +117,6 @@ struct SystemBarProperty { } }; -using SystemBarProps = std::vector>; - enum class AvoidAreaType : uint32_t { TYPE_SYSTEM, // area of SystemUI TYPE_CUTOUT, // cutout of screen diff --git a/interfaces/kits/napi/window_runtime/window_napi/js_window_listener.cpp b/interfaces/kits/napi/window_runtime/window_napi/js_window_listener.cpp index 2483ca486f..6c17bb424d 100644 --- a/interfaces/kits/napi/window_runtime/window_napi/js_window_listener.cpp +++ b/interfaces/kits/napi/window_runtime/window_napi/js_window_listener.cpp @@ -96,7 +96,7 @@ void JsWindowListener::OnSizeChange(Rect rect) CallJsMethod("windowSizeChange", argv, ArraySize(argv)); } -void JsWindowListener::OnSystemBarPropertyChange(uint64_t displayId, SystemBarProps props) +void JsWindowListener::OnSystemBarPropertyChange(uint64_t displayId, const SystemBarRegionTints& tints) { std::lock_guard lock(mtx_); WLOGFI("JsWindowListener::OnSystemBarPropertyChange is called"); @@ -111,7 +111,7 @@ void JsWindowListener::OnSystemBarPropertyChange(uint64_t displayId, SystemBarPr return; } object->SetProperty("displayId", CreateJsValue(*engine_, static_cast(displayId))); - object->SetProperty("regionTint", CreateJsSystemBarRegionTintArrayObject(*engine_, props)); + object->SetProperty("regionTint", CreateJsSystemBarRegionTintArrayObject(*engine_, tints)); NativeValue* argv[] = {propertyValue}; CallJsMethod("systemUiTintChange", argv, ArraySize(argv)); } diff --git a/interfaces/kits/napi/window_runtime/window_napi/js_window_listener.h b/interfaces/kits/napi/window_runtime/window_napi/js_window_listener.h index 5a93e853ab..5bff0c025e 100644 --- a/interfaces/kits/napi/window_runtime/window_napi/js_window_listener.h +++ b/interfaces/kits/napi/window_runtime/window_napi/js_window_listener.h @@ -37,7 +37,7 @@ public: void AddCallback(NativeValue* jsListenerObject); void RemoveAllCallback(); void RemoveCallback(NativeValue* jsListenerObject); - void OnSystemBarPropertyChange(uint64_t displayId, SystemBarProps props) override; + void OnSystemBarPropertyChange(uint64_t displayId, const SystemBarRegionTints& tints) override; void OnSizeChange(Rect rect) override; void OnAvoidAreaChanged(std::vector avoidAreas) override; diff --git a/interfaces/kits/napi/window_runtime/window_napi/js_window_utils.cpp b/interfaces/kits/napi/window_runtime/window_napi/js_window_utils.cpp index 82c8092de1..9c9ef1a9e0 100644 --- a/interfaces/kits/napi/window_runtime/window_napi/js_window_utils.cpp +++ b/interfaces/kits/napi/window_runtime/window_napi/js_window_utils.cpp @@ -73,8 +73,7 @@ static std::string GetHexColor(uint32_t color) return finalColor; } -static NativeValue* CreateJsSystemBarRegionTintObject(NativeEngine& engine, - WindowType type, const SystemBarProperty& prop) +static NativeValue* CreateJsSystemBarRegionTintObject(NativeEngine& engine, const SystemBarRegionTint& tint) { WLOGFI("JsWindowUtils::CreateJsSystemBarRegionTintObject is called"); @@ -84,35 +83,36 @@ static NativeValue* CreateJsSystemBarRegionTintObject(NativeEngine& engine, WLOGFE("Failed to convert SystemBarProperty to jsObject"); return nullptr; } - object->SetProperty("type", CreateJsValue(engine, static_cast(type))); - object->SetProperty("isEnable", CreateJsValue(engine, prop.enable_)); - std::string bkgColor = GetHexColor(prop.backgroundColor_); + object->SetProperty("type", CreateJsValue(engine, static_cast(tint.type_))); + object->SetProperty("isEnable", CreateJsValue(engine, tint.prop_.enable_)); + std::string bkgColor = GetHexColor(tint.prop_.backgroundColor_); WLOGFI("JsWindowUtils::CreateJsSystemBarRegionTintObject backgroundColir: %{public}s", bkgColor.c_str()); object->SetProperty("backgroundColor", CreateJsValue(engine, bkgColor)); - std::string contentColor = GetHexColor(prop.contentColor_); + std::string contentColor = GetHexColor(tint.prop_.contentColor_); WLOGFI("JsWindowUtils::CreateJsSystemBarRegionTintObject contentColor: %{public}s", contentColor.c_str()); object->SetProperty("contentColor", CreateJsValue(engine, contentColor)); - Rect rect = {0, 0, 0, 0}; // to fix on next version + Rect rect = tint.region_; object->SetProperty("region", GetRectAndConvertToJsValue(engine, rect)); + WLOGFI("JsWindowUtils::CreateJsSystemBarRegionTintObject rect: [%{public}d %{public}d %{public}d %{public}d]", + rect.posX_, rect.posY_, rect.width_, rect.height_); return objValue; } -NativeValue* CreateJsSystemBarRegionTintArrayObject(NativeEngine& engine, - const SystemBarProps& props) +NativeValue* CreateJsSystemBarRegionTintArrayObject(NativeEngine& engine, const SystemBarRegionTints& tints) { WLOGFI("JsWindowUtils::CreateJsSystemBarRegionTintArrayObject is called"); - if (props.empty()) { + if (tints.empty()) { return nullptr; } - NativeValue* objValue = engine.CreateArray(props.size()); + NativeValue* objValue = engine.CreateArray(tints.size()); NativeArray* array = ConvertNativeValueTo(objValue); if (array == nullptr) { WLOGFE("Failed to convert SystemBarPropertys to jsArrayObject"); return nullptr; } uint32_t index = 0; - for (size_t i = 0; i < props.size(); i++) { - array->SetElement(index++, CreateJsSystemBarRegionTintObject(engine, props[i].first, props[i].second)); + for (size_t i = 0; i < tints.size(); i++) { + array->SetElement(index++, CreateJsSystemBarRegionTintObject(engine, tints[i])); } return objValue; } diff --git a/interfaces/kits/napi/window_runtime/window_napi/js_window_utils.h b/interfaces/kits/napi/window_runtime/window_napi/js_window_utils.h index f3d6a79e43..cab4543370 100644 --- a/interfaces/kits/napi/window_runtime/window_napi/js_window_utils.h +++ b/interfaces/kits/napi/window_runtime/window_napi/js_window_utils.h @@ -18,6 +18,7 @@ #include "native_engine/native_engine.h" #include "native_engine/native_value.h" #include "window.h" +#include "window_manager.h" #include "window_option.h" #include "wm_common.h" namespace OHOS { @@ -39,7 +40,7 @@ namespace { bool GetSystemBarStatus(std::map& systemBarProperties, NativeEngine& engine, NativeCallbackInfo& info, sptr& window); NativeValue* CreateJsSystemBarRegionTintArrayObject(NativeEngine& engine, - const SystemBarProps& props); + const SystemBarRegionTints& tints); NativeValue* ChangeAvoidAreaToJsValue(NativeEngine& engine, const AvoidArea& avoidArea); } } diff --git a/wm/include/window_manager_agent.h b/wm/include/window_manager_agent.h index dd4717b4cd..6d730c48f2 100644 --- a/wm/include/window_manager_agent.h +++ b/wm/include/window_manager_agent.h @@ -27,7 +27,7 @@ public: void UpdateFocusStatus(uint32_t windowId, const sptr& abilityToken, WindowType windowType, int32_t displayId, bool focused) override; - void UpdateSystemBarProperties(uint64_t displayId, const SystemBarProps& props) override; + void UpdateSystemBarRegionTints(uint64_t displayId, const SystemBarRegionTints& props) override; }; } // namespace Rosen } // namespace OHOS diff --git a/wm/include/zidl/window_manager_agent_interface.h b/wm/include/zidl/window_manager_agent_interface.h index 2ea3127931..81d7640655 100644 --- a/wm/include/zidl/window_manager_agent_interface.h +++ b/wm/include/zidl/window_manager_agent_interface.h @@ -18,6 +18,7 @@ #include #include "wm_common.h" +#include "window_manager.h" namespace OHOS { namespace Rosen { @@ -37,7 +38,7 @@ public: virtual void UpdateFocusStatus(uint32_t windowId, const sptr& abilityToken, WindowType windowType, int32_t displayId, bool focused) = 0; - virtual void UpdateSystemBarProperties(uint64_t displayId, const SystemBarProps& props) = 0; + virtual void UpdateSystemBarRegionTints(uint64_t displayId, const SystemBarRegionTints& tints) = 0; }; } // namespace Rosen } // namespace OHOS diff --git a/wm/include/zidl/window_manager_agent_proxy.h b/wm/include/zidl/window_manager_agent_proxy.h index e3011faaf8..f0857f2e87 100644 --- a/wm/include/zidl/window_manager_agent_proxy.h +++ b/wm/include/zidl/window_manager_agent_proxy.h @@ -29,7 +29,7 @@ public: void UpdateFocusStatus(uint32_t windowId, const sptr& abilityToken, WindowType windowType, int32_t displayId, bool focused) override; - void UpdateSystemBarProperties(uint64_t displayId, const SystemBarProps& props) override; + void UpdateSystemBarRegionTints(uint64_t displayId, const SystemBarRegionTints& tints) override; private: static inline BrokerDelegator delegator_; diff --git a/wm/src/window_impl.cpp b/wm/src/window_impl.cpp index 13a29108db..d2b676b25a 100644 --- a/wm/src/window_impl.cpp +++ b/wm/src/window_impl.cpp @@ -233,6 +233,10 @@ const std::string& WindowImpl::GetContentInfo() WMError WindowImpl::SetSystemBarProperty(WindowType type, const SystemBarProperty& property) { + WLOGFI("[Client] Window %{public}d SetSystemBarProperty type %{public}d " \ + "enable:%{public}d, backgroundColor:%{public}x, contentColor:%{public}x ", + property_->GetWindowId(), static_cast(type), property.enable_, + property.backgroundColor_, property.contentColor_); if (!IsWindowValid()) { WLOGFI("window is already destroyed or not created! id: %{public}d", property_->GetWindowId()); return WMError::WM_ERROR_INVALID_WINDOW; diff --git a/wm/src/window_manager.cpp b/wm/src/window_manager.cpp index 2ae1db500a..0e9e208588 100644 --- a/wm/src/window_manager.cpp +++ b/wm/src/window_manager.cpp @@ -33,7 +33,7 @@ public: WindowType windowType, int32_t displayId) const; void NotifyUnfocused(uint32_t windowId, const sptr& abilityToken, WindowType windowType, int32_t displayId) const; - void NotifySystemBarChanged(uint64_t displayId, const SystemBarProps& props) const; + void NotifySystemBarChanged(uint64_t displayId, const SystemBarRegionTints& tints) const; static inline SingletonDelegator delegator_; std::recursive_mutex mutex_; @@ -63,15 +63,17 @@ void WindowManager::Impl::NotifyUnfocused(uint32_t windowId, const sptrOnSystemBarPropertyChange(displayId, props); + listener->OnSystemBarPropertyChange(displayId, tints); } } @@ -169,10 +171,10 @@ void WindowManager::UpdateFocusStatus(uint32_t windowId, const sptrNotifySystemBarChanged(displayId, props); + pImpl_->NotifySystemBarChanged(displayId, tints); } } // namespace Rosen } // namespace OHOS \ No newline at end of file diff --git a/wm/src/window_manager_agent.cpp b/wm/src/window_manager_agent.cpp index 6767bb60eb..c6be41fd44 100644 --- a/wm/src/window_manager_agent.cpp +++ b/wm/src/window_manager_agent.cpp @@ -25,9 +25,9 @@ void WindowManagerAgent::UpdateFocusStatus(uint32_t windowId, const sptr().UpdateFocusStatus(windowId, abilityToken, windowType, displayId, focused); } -void WindowManagerAgent::UpdateSystemBarProperties(uint64_t displayId, const SystemBarProps& props) +void WindowManagerAgent::UpdateSystemBarRegionTints(uint64_t displayId, const SystemBarRegionTints& tints) { - SingletonContainer::Get().UpdateSystemBarProperties(displayId, props); + SingletonContainer::Get().UpdateSystemBarRegionTints(displayId, tints); } } // namespace Rosen } // namespace OHOS diff --git a/wm/src/zidl/window_manager_agent_proxy.cpp b/wm/src/zidl/window_manager_agent_proxy.cpp index 774ae60c92..198d26f2bb 100644 --- a/wm/src/zidl/window_manager_agent_proxy.cpp +++ b/wm/src/zidl/window_manager_agent_proxy.cpp @@ -63,7 +63,7 @@ void WindowManagerAgentProxy::UpdateFocusStatus(uint32_t windowId, const sptr(size))) { WLOGFE("Write vector size failed"); return; } - for (auto it : props) { + for (auto it : tints) { // write key(type) - if (!data.WriteUint32(static_cast(it.first))) { + if (!data.WriteUint32(static_cast(it.type_))) { WLOGFE("Write type failed"); return; } - // write val(sysBarProps) - if (!(data.WriteBool(it.second.enable_) && data.WriteUint32(it.second.backgroundColor_) && - data.WriteUint32(it.second.contentColor_))) { - WLOGFE("Write sysBarProp failed"); + // write val(prop) + if (!(data.WriteBool(it.prop_.enable_) && data.WriteUint32(it.prop_.backgroundColor_) && + data.WriteUint32(it.prop_.contentColor_))) { + WLOGFE("Write prop failed"); + return; + } + // write val(region) + if (!(data.WriteInt32(it.region_.posX_) && data.WriteInt32(it.region_.posY_) && + data.WriteInt32(it.region_.width_) && data.WriteInt32(it.region_.height_))) { + WLOGFE("Write region failed"); return; } } diff --git a/wm/src/zidl/window_manager_agent_stub.cpp b/wm/src/zidl/window_manager_agent_stub.cpp index 943aa26ae3..5997a1012c 100644 --- a/wm/src/zidl/window_manager_agent_stub.cpp +++ b/wm/src/zidl/window_manager_agent_stub.cpp @@ -44,15 +44,16 @@ int WindowManagerAgentStub::OnRemoteRequest(uint32_t code, MessageParcel& data, } case TRANS_ID_UPDATE_SYSTEM_BAR_PROPS: { uint64_t displayId = data.ReadUint64(); - SystemBarProps props; + SystemBarRegionTints tints; uint32_t size = data.ReadUint32(); for (uint32_t i = 0; i < size; i++) { WindowType type = static_cast(data.ReadUint32()); SystemBarProperty prop = { data.ReadBool(), data.ReadUint32(), data.ReadUint32() }; - std::pair item = { type, prop }; - props.emplace_back(item); + Rect region = { data.ReadInt32(), data.ReadInt32(), data.ReadUint32(), data.ReadUint32() }; + SystemBarRegionTint tint(type, prop, region); + tints.emplace_back(tint); } - UpdateSystemBarProperties(displayId, props); + UpdateSystemBarRegionTints(displayId, tints); break; } default: diff --git a/wm/test/systemtest/window_immersive_test.cpp b/wm/test/systemtest/window_immersive_test.cpp index 2dd0505d7e..cb0aab30c3 100644 --- a/wm/test/systemtest/window_immersive_test.cpp +++ b/wm/test/systemtest/window_immersive_test.cpp @@ -25,28 +25,29 @@ namespace Rosen { namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowImmersiveTest"}; + const Rect SYS_BAR_REGION_NULL = { 0, 0, 0, 0 }; const SystemBarProperty SYS_BAR_PROP_DEFAULT; const SystemBarProperty SYS_BAR_PROP_1(true, 0xE5111111, 0xE5222222); const SystemBarProperty SYS_BAR_PROP_2(false, 0xE5222222, 0xE5333333); const SystemBarProperty SYS_BAR_PROP_3(false, 0xE5333333, 0xE5444444); const SystemBarProperty SYS_BAR_PROP_4(true, 0xE5444444, 0x66555555); - const SystemBarProps TEST_PROPS_DEFAULT = { - { WindowType::WINDOW_TYPE_STATUS_BAR, SYS_BAR_PROP_DEFAULT }, - { WindowType::WINDOW_TYPE_NAVIGATION_BAR, SYS_BAR_PROP_DEFAULT }, + const SystemBarRegionTints TEST_PROPS_DEFAULT = { + { WindowType::WINDOW_TYPE_STATUS_BAR, SYS_BAR_PROP_DEFAULT, SYS_BAR_REGION_NULL }, + { WindowType::WINDOW_TYPE_NAVIGATION_BAR, SYS_BAR_PROP_DEFAULT, SYS_BAR_REGION_NULL }, }; - const SystemBarProps TEST_PROPS_1 = { - { WindowType::WINDOW_TYPE_STATUS_BAR, SYS_BAR_PROP_1 }, - { WindowType::WINDOW_TYPE_NAVIGATION_BAR, SYS_BAR_PROP_2 }, + const SystemBarRegionTints TEST_PROPS_1 = { + { WindowType::WINDOW_TYPE_STATUS_BAR, SYS_BAR_PROP_1, SYS_BAR_REGION_NULL }, + { WindowType::WINDOW_TYPE_NAVIGATION_BAR, SYS_BAR_PROP_2, SYS_BAR_REGION_NULL }, }; - const SystemBarProps TEST_PROPS_2 = { - { WindowType::WINDOW_TYPE_STATUS_BAR, SYS_BAR_PROP_1 }, - { WindowType::WINDOW_TYPE_NAVIGATION_BAR, SYS_BAR_PROP_3 }, + const SystemBarRegionTints TEST_PROPS_2 = { + { WindowType::WINDOW_TYPE_STATUS_BAR, SYS_BAR_PROP_1, SYS_BAR_REGION_NULL }, + { WindowType::WINDOW_TYPE_NAVIGATION_BAR, SYS_BAR_PROP_3, SYS_BAR_REGION_NULL }, }; - const SystemBarProps TEST_DIFF_PROPS_1_2 = { - { WindowType::WINDOW_TYPE_NAVIGATION_BAR, SYS_BAR_PROP_3 }, + const SystemBarRegionTints TEST_DIFF_PROPS_1_2 = { + { WindowType::WINDOW_TYPE_NAVIGATION_BAR, SYS_BAR_PROP_3, SYS_BAR_REGION_NULL }, }; - const SystemBarProps TEST_DIFF_PROPS_2_1 = { - { WindowType::WINDOW_TYPE_NAVIGATION_BAR, SYS_BAR_PROP_2 }, + const SystemBarRegionTints TEST_DIFF_PROPS_2_1 = { + { WindowType::WINDOW_TYPE_NAVIGATION_BAR, SYS_BAR_PROP_2, SYS_BAR_REGION_NULL }, }; const Rect EMPTY_RECT = {0, 0, 0, 0}; @@ -58,8 +59,8 @@ const int WAIT_ASYNC_US = 100000; // 100000us class TestSystemBarChangedListener : public ISystemBarChangedListener { public: - SystemBarProps props_; - void OnSystemBarPropertyChange(uint64_t displayId, SystemBarProps props) override; + SystemBarRegionTints tints_; + void OnSystemBarPropertyChange(uint64_t displayId, const SystemBarRegionTints& tints) override; }; class TestAvoidAreaChangedListener : public IAvoidAreaChangedListener { @@ -74,9 +75,9 @@ public: static void TearDownTestCase(); virtual void SetUp() override; virtual void TearDown() override; - void SetWindowSystemProps(const sptr& window, const SystemBarProps& props); - bool SystemBarPropsEqualsTo(const SystemBarProps& expect); - void DumpFailedInfo(const SystemBarProps& expect); + void SetWindowSystemProps(const sptr& window, const SystemBarRegionTints& props); + bool SystemBarPropsEqualsTo(const SystemBarRegionTints& expect); + void DumpFailedInfo(const SystemBarRegionTints& expect); int displayId_ = 0; std::vector> activeWindows_; static vector fullScreenExpecteds_; @@ -96,51 +97,59 @@ sptr WindowImmersiveTest::testSystemBarChangedList sptr WindowImmersiveTest::testAvoidAreaChangedListener_ = new TestAvoidAreaChangedListener(); -void WindowImmersiveTest::SetWindowSystemProps(const sptr& window, const SystemBarProps& props) +void WindowImmersiveTest::SetWindowSystemProps(const sptr& window, const SystemBarRegionTints& tints) { - for (auto prop : props) { - window->SetSystemBarProperty(prop.first, prop.second); + for (auto tint : tints) { + window->SetSystemBarProperty(tint.type_, tint.prop_); } } -void WindowImmersiveTest::DumpFailedInfo(const SystemBarProps& expect) +void WindowImmersiveTest::DumpFailedInfo(const SystemBarRegionTints& expect) { - auto act = testSystemBarChangedListener_->props_; + auto act = testSystemBarChangedListener_->tints_; WLOGFI("WindowImmersiveTest Expected:"); - for (auto prop : expect) { + for (auto tint : expect) { WLOGFI("WindowType: %{public}4d, Enable: %{public}4d, Color: %{public}x | %{public}x", - static_cast(prop.first), prop.second.enable_, prop.second.backgroundColor_, - prop.second.contentColor_); + static_cast(tint.type_), tint.prop_.enable_, + tint.prop_.backgroundColor_, tint.prop_.contentColor_); } WLOGFI("WindowImmersiveTest Act: "); - for (auto prop : act) { + for (auto tint : act) { WLOGFI("WindowType: %{public}4d, Enable: %{public}4d, Color: %{public}x | %{public}x", - static_cast(prop.first), prop.second.enable_, prop.second.backgroundColor_, - prop.second.contentColor_); + static_cast(tint.type_), tint.prop_.enable_, + tint.prop_.backgroundColor_, tint.prop_.contentColor_); } } -bool WindowImmersiveTest::SystemBarPropsEqualsTo(const SystemBarProps& expect) +bool WindowImmersiveTest::SystemBarPropsEqualsTo(const SystemBarRegionTints& expect) { usleep(WAIT_ASYNC_US); - auto act = testSystemBarChangedListener_->props_; + auto act = testSystemBarChangedListener_->tints_; if (act.size() != expect.size()) { DumpFailedInfo(expect); return false; } for (auto item : expect) { - if (std::find(act.begin(), act.end(), item) == act.end()) { + bool check = false; + for (auto tint : act) { + if (item.prop_ == tint.prop_ && item.type_ == tint.type_) { + check = true; + break; + } + } + if (!check) { DumpFailedInfo(expect); return false; } + check = false; } return true; } -void TestSystemBarChangedListener::OnSystemBarPropertyChange(uint64_t displayId, SystemBarProps props) +void TestSystemBarChangedListener::OnSystemBarPropertyChange(uint64_t displayId, const SystemBarRegionTints& tints) { WLOGFI("TestSystemBarChangedListener Display ID: %{public}" PRIu64"", displayId); - props_ = props; + tints_ = tints; } void TestAvoidAreaChangedListener::OnAvoidAreaChanged(std::vector avoidAreas) diff --git a/wmserver/include/window_layout_policy.h b/wmserver/include/window_layout_policy.h index b83d5f0c3c..c63ee4b056 100644 --- a/wmserver/include/window_layout_policy.h +++ b/wmserver/include/window_layout_policy.h @@ -64,7 +64,10 @@ private: WindowType::WINDOW_TYPE_STATUS_BAR, WindowType::WINDOW_TYPE_NAVIGATION_BAR, }; - + std::unordered_map sysBarPropMap_ { + { WindowType::WINDOW_TYPE_STATUS_BAR, SystemBarProperty() }, + { WindowType::WINDOW_TYPE_NAVIGATION_BAR, SystemBarProperty() }, + }; void UpdateFloatingLayoutRect(Rect& limitRect, Rect& winRect); void UpdateSplitLimitRect(const Rect& limitRect, Rect& limitSplitRect); void UpdateLimitRect(const sptr& node, Rect& limitRect); diff --git a/wmserver/include/window_manager_agent_controller.h b/wmserver/include/window_manager_agent_controller.h index 515f433196..5ad0811864 100644 --- a/wmserver/include/window_manager_agent_controller.h +++ b/wmserver/include/window_manager_agent_controller.h @@ -33,7 +33,7 @@ public: void UpdateFocusStatus(uint32_t windowId, const sptr& abilityToken, WindowType windowType, int32_t displayId, bool focused); - void UpdateSystemBarProperties(uint64_t displayId, const SystemBarProps& props); + void UpdateSystemBarRegionTints(uint64_t displayId, const SystemBarRegionTints& tints); private: WindowManagerAgentController() : wmAgentContainer_(mutex_) {} diff --git a/wmserver/include/window_node_container.h b/wmserver/include/window_node_container.h index e30d0fa974..74a734fea5 100644 --- a/wmserver/include/window_node_container.h +++ b/wmserver/include/window_node_container.h @@ -19,6 +19,7 @@ #include #include "avoid_area_controller.h" #include "window_layout_policy.h" +#include "window_manager.h" #include "window_node.h" #include "window_zorder_policy.h" #include "wm_common.h" @@ -44,7 +45,6 @@ public: uint64_t GetScreenId() const; Rect GetDisplayRect() const; sptr GetTopImmersiveNode() const; - void NotifySystemBarIfChanged(); WMError HandleSplitWindowModeChange(sptr& triggerNode, bool isChangeToSplit); void OnAvoidAreaChange(const std::vector& avoidAreas); @@ -88,6 +88,8 @@ private: WMError HandleModeChangeToSplit(sptr& triggerNode); WMError HandleModeChangeFromSplit(sptr& triggerNode); WMError UpdateWindowPairInfo(sptr& triggerNode, sptr& pairNode); + void NotifyIfSystemBarTintChanged(); + void NotifyIfSystemBarRegionChanged(); sptr avoidController_; sptr zorderPolicy_ = new WindowZorderPolicy(); @@ -102,9 +104,9 @@ private: { WindowType::WINDOW_TYPE_STATUS_BAR, nullptr }, { WindowType::WINDOW_TYPE_NAVIGATION_BAR, nullptr }, }; - std::unordered_map sysBarPropMap_ { - { WindowType::WINDOW_TYPE_STATUS_BAR, SystemBarProperty() }, - { WindowType::WINDOW_TYPE_NAVIGATION_BAR, SystemBarProperty() }, + std::unordered_map sysBarTintMap_ { + { WindowType::WINDOW_TYPE_STATUS_BAR, SystemBarRegionTint() }, + { WindowType::WINDOW_TYPE_NAVIGATION_BAR, SystemBarRegionTint() }, }; uint32_t zOrder_ { 0 }; uint32_t focusedWindow_ { 0 }; diff --git a/wmserver/src/window_manager_agent_controller.cpp b/wmserver/src/window_manager_agent_controller.cpp index 3a48a47440..9fbfd53b74 100644 --- a/wmserver/src/window_manager_agent_controller.cpp +++ b/wmserver/src/window_manager_agent_controller.cpp @@ -47,16 +47,16 @@ void WindowManagerAgentController::UpdateFocusStatus(uint32_t windowId, const sp } } -void WindowManagerAgentController::UpdateSystemBarProperties(uint64_t displayId, const SystemBarProps& props) +void WindowManagerAgentController::UpdateSystemBarRegionTints(uint64_t displayId, const SystemBarRegionTints& tints) { - if (props.empty()) { + if (tints.empty()) { return; } std::lock_guard lock(mutex_); - WLOGFI("UpdateSystemBarProperties"); + WLOGFI("UpdateSystemBarRegionTints"); for (auto& agent : wmAgentContainer_.GetAgentsByType( WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_SYSTEM_BAR)) { - agent->UpdateSystemBarProperties(displayId, props); + agent->UpdateSystemBarRegionTints(displayId, tints); } } } diff --git a/wmserver/src/window_node_container.cpp b/wmserver/src/window_node_container.cpp index eb2215b439..739c7064e7 100644 --- a/wmserver/src/window_node_container.cpp +++ b/wmserver/src/window_node_container.cpp @@ -129,8 +129,10 @@ WMError WindowNodeContainer::AddWindowNode(sptr& node, sptrIsAvoidAreaNode(node)) { avoidController_->AddAvoidAreaNode(node); + NotifyIfSystemBarRegionChanged(); } - NotifySystemBarIfChanged(); + NotifyIfSystemBarTintChanged(); + DumpScreenWindowTree(); WLOGFI("AddWindowNode windowId: %{public}d end", node->GetWindowId()); return WMError::WM_OK; } @@ -144,8 +146,10 @@ WMError WindowNodeContainer::UpdateWindowNode(sptr& node) layoutPolicy_->UpdateWindowNode(node); if (avoidController_->IsAvoidAreaNode(node)) { avoidController_->UpdateAvoidAreaNode(node); + NotifyIfSystemBarRegionChanged(); } - NotifySystemBarIfChanged(); + NotifyIfSystemBarTintChanged(); + DumpScreenWindowTree(); WLOGFI("UpdateWindowNode windowId: %{public}d end", node->GetWindowId()); return WMError::WM_OK; } @@ -248,8 +252,10 @@ WMError WindowNodeContainer::RemoveWindowNode(sptr& node) layoutPolicy_->RemoveWindowNode(node); if (avoidController_->IsAvoidAreaNode(node)) { avoidController_->RemoveAvoidAreaNode(node); + NotifyIfSystemBarRegionChanged(); } - NotifySystemBarIfChanged(); + NotifyIfSystemBarTintChanged(); + DumpScreenWindowTree(); WLOGFI("RemoveWindowNode windowId: %{public}d end", node->GetWindowId()); return WMError::WM_OK; } @@ -404,43 +410,63 @@ sptr WindowNodeContainer::GetTopImmersiveNode() const return nullptr; } -void WindowNodeContainer::NotifySystemBarIfChanged() +void WindowNodeContainer::NotifyIfSystemBarTintChanged() { - DumpScreenWindowTree(); WM_FUNCTION_TRACE(); auto node = GetTopImmersiveNode(); - SystemBarProps props; + SystemBarRegionTints tints; if (node == nullptr) { // use default system bar WLOGFI("no immersive window on top"); - for (auto it : sysBarPropMap_) { - if (it.second == SystemBarProperty()) { + for (auto it : sysBarTintMap_) { + if (it.second.prop_ == SystemBarProperty()) { continue; } - sysBarPropMap_[it.first] = SystemBarProperty(); - std::pair item = { it.first, SystemBarProperty() }; - props.emplace_back(item); + WLOGFI("system bar prop change to default"); + sysBarTintMap_[it.first].prop_ = SystemBarProperty(); + sysBarTintMap_[it.first].type_ = it.first; + tints.emplace_back(sysBarTintMap_[it.first]); } } else { // use node-defined system bar WLOGFI("top immersive window id: %{public}d", node->GetWindowId()); auto& sysBarPropMap = node->GetSystemBarProperty(); - for (auto it : sysBarPropMap_) { + for (auto it : sysBarTintMap_) { if (sysBarPropMap.find(it.first) == sysBarPropMap.end()) { - return; + continue; } auto& prop = sysBarPropMap.find(it.first)->second; - if (it.second == prop) { + if (it.second.prop_ == prop) { continue; } - WLOGFI("Set systemBar prop winId: %{public}d, type: %{public}d" \ + WLOGFI("system bar prop update winId: %{public}d, type: %{public}d" \ "visible: %{public}d, Color: %{public}x | %{public}x", node->GetWindowId(), static_cast(it.first), prop.enable_, prop.backgroundColor_, prop.contentColor_); - sysBarPropMap_[it.first] = prop; - std::pair item = { it.first, prop }; - props.emplace_back(item); + sysBarTintMap_[it.first].prop_ = prop; + sysBarTintMap_[it.first].type_ = it.first; + tints.emplace_back(sysBarTintMap_[it.first]); } } - WindowManagerAgentController::GetInstance().UpdateSystemBarProperties(screenId_, props); + WindowManagerAgentController::GetInstance().UpdateSystemBarRegionTints(screenId_, tints); +} + +void WindowNodeContainer::NotifyIfSystemBarRegionChanged() +{ + WM_FUNCTION_TRACE(); + SystemBarRegionTints tints; + for (auto it : sysBarTintMap_) { // split screen mode not support yet + auto sysNode = sysBarNodeMap_[it.first]; + if (sysNode == nullptr || it.second.region_ == sysNode->GetLayoutRect()) { + continue; + } + auto& newRegion = sysNode->GetLayoutRect(); + sysBarTintMap_[it.first].region_ = newRegion; + sysBarTintMap_[it.first].type_ = it.first; + tints.emplace_back(sysBarTintMap_[it.first]); + WLOGFI("system bar region update, type: %{public}d" \ + "region: [%{public}d, %{public}d, %{public}d, %{public}d]", + static_cast(it.first), newRegion.posX_, newRegion.posY_, newRegion.width_, newRegion.height_); + } + WindowManagerAgentController::GetInstance().UpdateSystemBarRegionTints(screenId_, tints); } void WindowNodeContainer::TraverseContainer(std::vector>& windowNodes) -- Gitee From a190e7a8a7e9e3ab86ed5a1ac6b3f79fb52f14fb Mon Sep 17 00:00:00 2001 From: leafly2021 Date: Thu, 20 Jan 2022 23:12:12 +0800 Subject: [PATCH 52/57] add decor function Signed-off-by: leafly2021 Change-Id: Ic2b6dae128e51598fdaa825c92eedc10e6cd499b Signed-off-by: leafly2021 --- interfaces/innerkits/wm/window.h | 6 +++ wm/BUILD.gn | 1 + wm/include/window_impl.h | 7 ++++ wm/src/window_impl.cpp | 72 ++++++++++++++++++++++++++++++++ 4 files changed, 86 insertions(+) diff --git a/interfaces/innerkits/wm/window.h b/interfaces/innerkits/wm/window.h index bdce754292..7e2d70aab1 100644 --- a/interfaces/innerkits/wm/window.h +++ b/interfaces/innerkits/wm/window.h @@ -96,6 +96,12 @@ public: virtual WMError SetUIContent(const std::string& contentInfo, NativeEngine* engine, NativeValue* storage, bool isdistributed = false) = 0; virtual const std::string& GetContentInfo() = 0; + + virtual bool IsDecorEnable() = 0; + virtual WMError Maximize() = 0; + virtual WMError Minimize() = 0; + virtual WMError Recover() = 0; + virtual WMError Close() = 0; }; } } diff --git a/wm/BUILD.gn b/wm/BUILD.gn index 6dfaad1dc9..2852ff4bba 100644 --- a/wm/BUILD.gn +++ b/wm/BUILD.gn @@ -74,6 +74,7 @@ ohos_shared_library("libwm") { "//utils/native/base:utils", # ace + "//foundation/aafwk/standard/interfaces/innerkits/ability_manager:ability_manager", "//foundation/ace/ace_engine/interfaces/innerkits/ace:ace_uicontent", "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_core:appexecfwk_core", "//foundation/graphic/standard:libsurface", diff --git a/wm/include/window_impl.h b/wm/include/window_impl.h index c2770d97b9..1169bcdabb 100644 --- a/wm/include/window_impl.h +++ b/wm/include/window_impl.h @@ -69,6 +69,12 @@ public: virtual WMError MoveTo(int32_t x, int32_t y) override; virtual WMError Resize(uint32_t width, uint32_t height) override; + virtual bool IsDecorEnable() override; + virtual WMError Maximize() override; + virtual WMError Minimize() override; + virtual WMError Recover() override; + virtual WMError Close() override; + virtual WMError RequestFocus() const override; virtual void AddInputEventListener(std::shared_ptr& inputEventListener) override; @@ -141,6 +147,7 @@ private: std::unique_ptr uiContent_; std::shared_ptr abilityContext_; // give up when context offer getToken std::shared_ptr context_; + bool isDecorEnable_ = false; const float STATUS_BAR_RATIO = 0.07; const float NAVIGATION_BAR_RATIO = 0.07; const float SYSTEM_ALARM_WINDOW_WIDTH_RATIO = 0.8; diff --git a/wm/src/window_impl.cpp b/wm/src/window_impl.cpp index 5e9a308603..7474192665 100644 --- a/wm/src/window_impl.cpp +++ b/wm/src/window_impl.cpp @@ -25,6 +25,8 @@ #include "window_helper.h" #include "window_manager_hilog.h" +#include + namespace OHOS { namespace Rosen { namespace { @@ -215,6 +217,11 @@ WMError WindowImpl::SetUIContent(const std::string& contentInfo, WLOGFE("fail to SetUIContent id: %{public}d", property_->GetWindowId()); return WMError::WM_ERROR_NULLPTR; } + if (WindowHelper::IsMainWindow(property_->GetWindowType())) { + isDecorEnable_ = true; + } else { + isDecorEnable_ = false; + } if (isdistributed) { uiContent_->Restore(this, contentInfo, storage); } else { @@ -419,6 +426,71 @@ WMError WindowImpl::Resize(uint32_t width, uint32_t height) return SingletonContainer::Get().Resize(property_->GetWindowId(), width, height); } +bool WindowImpl::IsDecorEnable() +{ + return isDecorEnable_; +} + +WMError WindowImpl::Maximize() +{ + WLOGFI("[Client] Window %{public}d Maximize", property_->GetWindowId()); + if (!IsWindowValid()) { + WLOGFI("window is already destroyed or not created! id: %{public}d", property_->GetWindowId()); + return WMError::WM_ERROR_INVALID_WINDOW; + } + if (WindowHelper::IsMainWindow(property_->GetWindowType())) { + SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN); + } + return WMError::WM_OK; +} + +WMError WindowImpl::Minimize() +{ + WLOGFI("[Client] Window %{public}d Minimize", property_->GetWindowId()); + if (!IsWindowValid()) { + WLOGFI("window is already destroyed or not created! id: %{public}d", property_->GetWindowId()); + return WMError::WM_ERROR_INVALID_WINDOW; + } + if (WindowHelper::IsMainWindow(property_->GetWindowType())) { + if (abilityContext_ != nullptr) { + AAFwk::AbilityManagerClient::GetInstance()->MinimizeAbility(abilityContext_->GetAbilityToken()); + } else { + Hide(); + } + } + return WMError::WM_OK; +} + +WMError WindowImpl::Recover() +{ + WLOGFI("[Client] Window %{public}d Normalize", property_->GetWindowId()); + if (!IsWindowValid()) { + WLOGFI("window is already destroyed or not created! id: %{public}d", property_->GetWindowId()); + return WMError::WM_ERROR_INVALID_WINDOW; + } + if (WindowHelper::IsMainWindow(property_->GetWindowType())) { + SetWindowMode(WindowMode::WINDOW_MODE_FLOATING); + } + return WMError::WM_OK; +} + +WMError WindowImpl::Close() +{ + WLOGFI("[Client] Window %{public}d Close", property_->GetWindowId()); + if (!IsWindowValid()) { + WLOGFI("window is already destroyed or not created! id: %{public}d", property_->GetWindowId()); + return WMError::WM_ERROR_INVALID_WINDOW; + } + if (WindowHelper::IsMainWindow(property_->GetWindowType())) { + if (abilityContext_ != nullptr) { + abilityContext_->TerminateSelf(); + } else { + Destroy(); + } + } + return WMError::WM_OK; +} + WMError WindowImpl::RequestFocus() const { if (!IsWindowValid()) { -- Gitee From 24b7747603e1dead9f0933647d3752ff3fd92cfd Mon Sep 17 00:00:00 2001 From: l00574490 Date: Thu, 20 Jan 2022 22:16:06 +0800 Subject: [PATCH 53/57] add for draw divider on gpu Change-Id: I12ee79088ac8d955cb69c9883fa535035f796d13 Signed-off-by: l00574490 --- wmserver/BUILD.gn | 7 +++++++ wmserver/src/window_inner_manager.cpp | 1 + 2 files changed, 8 insertions(+) diff --git a/wmserver/BUILD.gn b/wmserver/BUILD.gn index 461710915c..b7dba15563 100644 --- a/wmserver/BUILD.gn +++ b/wmserver/BUILD.gn @@ -28,6 +28,13 @@ config("libwms_config") { "//foundation/windowmanager/dm/include", "//foundation/windowmanager/dmserver/include", ] + + if ("${product_name}" == "rk3566" || "${product_name}" == "rk3568" || + "${product_name}" == "Hi3516DV300" || "${product_name}" == "ohos-arm64") { + defines = [ "ACE_DISABLE_GL" ] + } else { + defines = [ "ACE_ENABLE_GL" ] + } } ohos_shared_library("libwms") { diff --git a/wmserver/src/window_inner_manager.cpp b/wmserver/src/window_inner_manager.cpp index b8a90f29f8..43ff314404 100644 --- a/wmserver/src/window_inner_manager.cpp +++ b/wmserver/src/window_inner_manager.cpp @@ -123,6 +123,7 @@ void WindowInnerManager::CreateAndShowDivider() } #ifdef ACE_ENABLE_GL + WLOGFI("Draw divider on gpu"); // init render context static bool hasInitRC = false; if (!hasInitRC) { -- Gitee From 39c5cecb5a7d7add77680dd8afbb55cfebaa5941 Mon Sep 17 00:00:00 2001 From: leafly2021 Date: Fri, 21 Jan 2022 13:05:54 +0800 Subject: [PATCH 54/57] add isDecorEnable to prop Signed-off-by: leafly2021 Change-Id: I301c36b4d986c57d68c441e10e2916d893253646 --- interfaces/innerkits/wm/window.h | 2 +- utils/include/window_property.h | 3 +++ utils/src/window_property.cpp | 16 ++++++++++++++++ wm/include/window_impl.h | 3 +-- wm/src/window_impl.cpp | 8 ++++---- 5 files changed, 25 insertions(+), 7 deletions(-) diff --git a/interfaces/innerkits/wm/window.h b/interfaces/innerkits/wm/window.h index 7e2d70aab1..93406adcdb 100644 --- a/interfaces/innerkits/wm/window.h +++ b/interfaces/innerkits/wm/window.h @@ -97,7 +97,7 @@ public: NativeValue* storage, bool isdistributed = false) = 0; virtual const std::string& GetContentInfo() = 0; - virtual bool IsDecorEnable() = 0; + virtual bool IsDecorEnable() const = 0; virtual WMError Maximize() = 0; virtual WMError Minimize() = 0; virtual WMError Recover() = 0; diff --git a/utils/include/window_property.h b/utils/include/window_property.h index 10ca0bba0f..11c9e0e851 100644 --- a/utils/include/window_property.h +++ b/utils/include/window_property.h @@ -44,6 +44,7 @@ public: void SetParentId(uint32_t parentId); void SetWindowFlags(uint32_t flags); void SetSystemBarProperty(WindowType type, const SystemBarProperty& state); + void SetDecorEnable(bool decorEnable); Rect GetWindowRect() const; WindowType GetWindowType() const; @@ -59,6 +60,7 @@ public: uint32_t GetParentId() const; uint32_t GetWindowFlags() const; const std::unordered_map& GetSystemBarProperty() const; + bool GetDecorEnable() const; virtual bool Marshalling(Parcel& parcel) const override; static sptr Unmarshalling(Parcel& parcel); @@ -81,6 +83,7 @@ private: { WindowType::WINDOW_TYPE_STATUS_BAR, SystemBarProperty() }, { WindowType::WINDOW_TYPE_NAVIGATION_BAR, SystemBarProperty() }, }; + bool isDecorEnable_ { false }; bool MapMarshalling(Parcel& parcel) const; static void MapUnmarshalling(Parcel& parcel, sptr& property); }; diff --git a/utils/src/window_property.cpp b/utils/src/window_property.cpp index f04d0554e8..c112ffa753 100644 --- a/utils/src/window_property.cpp +++ b/utils/src/window_property.cpp @@ -86,6 +86,11 @@ void WindowProperty::SetSystemBarProperty(WindowType type, const SystemBarProper } } +void WindowProperty::SetDecorEnable(bool decorEnable) +{ + isDecorEnable_ = decorEnable; +} + void WindowProperty::ResumeLastWindowMode() { mode_ = lastMode_; @@ -151,6 +156,11 @@ const std::unordered_map& WindowProperty::GetSyst return sysBarPropMap_; } +bool WindowProperty::GetDecorEnable() const +{ + return isDecorEnable_; +} + // TODO void WindowProperty::SetWindowId(uint32_t windowId) { @@ -272,6 +282,11 @@ bool WindowProperty::Marshalling(Parcel& parcel) const if (!MapMarshalling(parcel)) { return false; } + + // write isDecorEnable_ + if (!parcel.WriteBool(isDecorEnable_)) { + return false; + } return true; } @@ -293,6 +308,7 @@ sptr WindowProperty::Unmarshalling(Parcel& parcel) property->SetWindowId(parcel.ReadUint32()); property->SetParentId(parcel.ReadUint32()); MapUnmarshalling(parcel, property); + property->SetDecorEnable(parcel.ReadBool()); return property; } } diff --git a/wm/include/window_impl.h b/wm/include/window_impl.h index 1169bcdabb..40377cd7f6 100644 --- a/wm/include/window_impl.h +++ b/wm/include/window_impl.h @@ -69,7 +69,7 @@ public: virtual WMError MoveTo(int32_t x, int32_t y) override; virtual WMError Resize(uint32_t width, uint32_t height) override; - virtual bool IsDecorEnable() override; + virtual bool IsDecorEnable() const override; virtual WMError Maximize() override; virtual WMError Minimize() override; virtual WMError Recover() override; @@ -147,7 +147,6 @@ private: std::unique_ptr uiContent_; std::shared_ptr abilityContext_; // give up when context offer getToken std::shared_ptr context_; - bool isDecorEnable_ = false; const float STATUS_BAR_RATIO = 0.07; const float NAVIGATION_BAR_RATIO = 0.07; const float SYSTEM_ALARM_WINDOW_WIDTH_RATIO = 0.8; diff --git a/wm/src/window_impl.cpp b/wm/src/window_impl.cpp index 7474192665..3bda4f56e9 100644 --- a/wm/src/window_impl.cpp +++ b/wm/src/window_impl.cpp @@ -218,9 +218,9 @@ WMError WindowImpl::SetUIContent(const std::string& contentInfo, return WMError::WM_ERROR_NULLPTR; } if (WindowHelper::IsMainWindow(property_->GetWindowType())) { - isDecorEnable_ = true; + property_->SetDecorEnable(true); } else { - isDecorEnable_ = false; + property_->SetDecorEnable(false); } if (isdistributed) { uiContent_->Restore(this, contentInfo, storage); @@ -426,9 +426,9 @@ WMError WindowImpl::Resize(uint32_t width, uint32_t height) return SingletonContainer::Get().Resize(property_->GetWindowId(), width, height); } -bool WindowImpl::IsDecorEnable() +bool WindowImpl::IsDecorEnable() const { - return isDecorEnable_; + return property_->GetDecorEnable(); } WMError WindowImpl::Maximize() -- Gitee From 478d028d883d4a2184df809ef9be784bec50c451 Mon Sep 17 00:00:00 2001 From: xiahaiqin Date: Fri, 21 Jan 2022 17:40:09 +0800 Subject: [PATCH 55/57] modify deps to external deps Signed-off-by: xiahaiqin Change-Id: Ifdb1d31e3b2ec1bafe532059c4059cf0e87dfd6c --- bundle.json | 17 +++++++++++ dm/BUILD.gn | 12 +++----- dm/test/systemtest/BUILD.gn | 1 + dm/test/unittest/BUILD.gn | 1 + dmserver/BUILD.gn | 11 ++++--- interfaces/innerkits/wm/window_scene.h | 5 ++- interfaces/kits/napi/display/BUILD.gn | 3 ++ interfaces/kits/napi/screenshot/BUILD.gn | 4 +-- interfaces/kits/napi/window_runtime/BUILD.gn | 2 ++ snapshot/BUILD.gn | 7 +++-- utils/BUILD.gn | 3 +- wm/BUILD.gn | 25 ++++++--------- wm/src/window_scene.cpp | 2 ++ wm/test/systemtest/BUILD.gn | 5 +-- wm/test/unittest/BUILD.gn | 4 +++ wmserver/BUILD.gn | 32 ++++++++------------ wmtest/BUILD.gn | 3 +- 17 files changed, 81 insertions(+), 56 deletions(-) diff --git a/bundle.json b/bundle.json index ea062df3a2..deca69d432 100644 --- a/bundle.json +++ b/bundle.json @@ -12,6 +12,23 @@ "ram": {}, "deps": { "components": [ + "libhilog", + "ipc_core", + "system_ability_fwk", + "samgr_proxy", + "image_native", + "utils", + "bytrace_core", + "surface", + "ability_context_native", + "ability_manager", + "want", + "ace_uicontent", + "appexecfwk_base", + "appexecfwk_core", + "inputmethod_client", + "libmmi-client", + "ace_napi" ], "third_party": [ ] diff --git a/dm/BUILD.gn b/dm/BUILD.gn index 87b80a6334..fe792c4ca9 100644 --- a/dm/BUILD.gn +++ b/dm/BUILD.gn @@ -14,8 +14,6 @@ import("//build/ohos.gni") config("libdm_private_config") { - visibility = [ ":*" ] - include_dirs = [ "include", "../dmserver/include", @@ -54,19 +52,17 @@ ohos_shared_library("libdm") { public_configs = [ ":libdm_public_config" ] deps = [ - # RSSurface - "//foundation/distributedschedule/safwk/interfaces/innerkits/safwk:system_ability_fwk", - "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", - "//foundation/graphic/standard/rosen/modules/render_service_base:librender_service_base", "//foundation/graphic/standard/rosen/modules/render_service_client:librender_service_client", - "//foundation/multimedia/image_standard/interfaces/innerkits:image_native", "//foundation/windowmanager/utils:libwmutil", - "//utils/native/base:utils", ] external_deps = [ "hilog_native:libhilog", "ipc:ipc_core", + "multimedia_image_standard:image_native", + "safwk:system_ability_fwk", + "samgr_standard:samgr_proxy", + "utils_base:utils", ] part_name = "window_manager" diff --git a/dm/test/systemtest/BUILD.gn b/dm/test/systemtest/BUILD.gn index fa19dfafcf..baaf7cb5d8 100644 --- a/dm/test/systemtest/BUILD.gn +++ b/dm/test/systemtest/BUILD.gn @@ -102,6 +102,7 @@ ohos_static_library("dm_systemtest_common") { public_configs = [ ":dm_systemtest_common_public_config" ] public_deps = [ + "//foundation/graphic/standard/rosen/modules/render_service_client:librender_service_client", "//foundation/multimodalinput/input/frameworks/proxy:libmmi-client", "//foundation/windowmanager/dm:libdm", "//foundation/windowmanager/dmserver:libdms", diff --git a/dm/test/unittest/BUILD.gn b/dm/test/unittest/BUILD.gn index 55505d8907..cbf24f394f 100644 --- a/dm/test/unittest/BUILD.gn +++ b/dm/test/unittest/BUILD.gn @@ -95,6 +95,7 @@ ohos_static_library("dm_unittest_common") { public_configs = [ ":dm_unittest_common_public_config" ] public_deps = [ + "//foundation/graphic/standard/rosen/modules/render_service_client:librender_service_client", "//foundation/multimedia/image_standard/interfaces/innerkits:image_native", # PixelMap "//foundation/multimodalinput/input/frameworks/proxy:libmmi-client", "//foundation/windowmanager/dm:libdm", diff --git a/dmserver/BUILD.gn b/dmserver/BUILD.gn index 3fffd2f135..7677e14f24 100644 --- a/dmserver/BUILD.gn +++ b/dmserver/BUILD.gn @@ -50,24 +50,27 @@ ohos_shared_library("libdms") { public_configs = [ ":libdms_public_config" ] deps = [ - "//foundation/distributedschedule/safwk/interfaces/innerkits/safwk:system_ability_fwk", - "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", "//foundation/windowmanager/dm:libdm", "//foundation/windowmanager/utils:libwmutil", - "//utils/native/base:utils", # RSSurface - "//foundation/graphic/standard:libsurface", "//foundation/graphic/standard/rosen/modules/render_service_client:librender_service_client", # todo need delete it + "//foundation/aafwk/standard/interfaces/innerkits/ability_manager:ability_manager", "//foundation/windowmanager/wmserver:libwms", + + # need delete end ] external_deps = [ "bytrace_standard:bytrace_core", + "graphic_standard:surface", "hilog_native:libhilog", "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr_standard:samgr_proxy", + "utils_base:utils", ] part_name = "window_manager" diff --git a/interfaces/innerkits/wm/window_scene.h b/interfaces/innerkits/wm/window_scene.h index 073ec4718c..30eac7456f 100644 --- a/interfaces/innerkits/wm/window_scene.h +++ b/interfaces/innerkits/wm/window_scene.h @@ -18,11 +18,14 @@ #include #include -#include #include "window.h" #include "window_option.h" +namespace OHOS::AppExecFwk { + class Configuration; +} + namespace OHOS { namespace Rosen { class WindowScene : public RefBase { diff --git a/interfaces/kits/napi/display/BUILD.gn b/interfaces/kits/napi/display/BUILD.gn index 02c1708dba..26840d2650 100644 --- a/interfaces/kits/napi/display/BUILD.gn +++ b/interfaces/kits/napi/display/BUILD.gn @@ -20,10 +20,13 @@ ohos_shared_library("display") { deps = [ "../common:wm_napi_common", "//foundation/windowmanager/dm:libdm", + "//foundation/windowmanager/utils:libwmutil", "//foundation/windowmanager/wm:libwm", "//foundation/windowmanager/wmserver:libwms", ] + external_deps = [ "multimedia_image_standard:image_native" ] + relative_install_dir = "module" part_name = "window_manager" subsystem_name = "window" diff --git a/interfaces/kits/napi/screenshot/BUILD.gn b/interfaces/kits/napi/screenshot/BUILD.gn index 78eb7cd50d..f1aa66f338 100644 --- a/interfaces/kits/napi/screenshot/BUILD.gn +++ b/interfaces/kits/napi/screenshot/BUILD.gn @@ -19,8 +19,6 @@ ohos_shared_library("screenshot") { deps = [ "../common:wm_napi_common", - "//foundation/multimedia/image_standard/interfaces/innerkits:image", - "//foundation/multimedia/image_standard/interfaces/innerkits:image_native", "//foundation/windowmanager/dm:libdm", "//foundation/windowmanager/utils:libwmutil", "//foundation/windowmanager/wm:libwm", @@ -29,6 +27,8 @@ ohos_shared_library("screenshot") { external_deps = [ "ability_runtime:runtime", "hiviewdfx_hilog_native:libhilog", + "multimedia_image_standard:image", + "multimedia_image_standard:image_native", "napi:ace_napi", ] diff --git a/interfaces/kits/napi/window_runtime/BUILD.gn b/interfaces/kits/napi/window_runtime/BUILD.gn index cca6c25e45..09abf8ac67 100644 --- a/interfaces/kits/napi/window_runtime/BUILD.gn +++ b/interfaces/kits/napi/window_runtime/BUILD.gn @@ -73,12 +73,14 @@ ohos_shared_library("window_napi") { "//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native", "//foundation/aafwk/standard/frameworks/kits/appkit:app_context", "//foundation/aafwk/standard/frameworks/kits/appkit:appkit_native", + "//foundation/aafwk/standard/interfaces/innerkits/want:want", "//foundation/windowmanager/utils:libwmutil", "//foundation/windowmanager/wm:libwm", "//foundation/windowmanager/wmserver:libwms", ] external_deps = [ + "ability_runtime:ability_manager", "ability_runtime:runtime", "hiviewdfx_hilog_native:libhilog", "napi:ace_napi", diff --git a/snapshot/BUILD.gn b/snapshot/BUILD.gn index aa2543d377..859799ef82 100644 --- a/snapshot/BUILD.gn +++ b/snapshot/BUILD.gn @@ -28,12 +28,15 @@ ohos_executable("snapshot_display") { configs = [ ":snapshot_config" ] deps = [ - "//foundation/multimedia/image_standard/interfaces/innerkits:image_native", # PixelMap "//foundation/windowmanager/dm:libdm", "//foundation/windowmanager/utils:libwmutil", "//foundation/windowmanager/wm:libwm", "//third_party/libpng:libpng", # png - "//utils/native/base:utils", + ] + + external_deps = [ + "multimedia_image_standard:image_native", + "utils_base:utils", ] part_name = "window_manager" diff --git a/utils/BUILD.gn b/utils/BUILD.gn index cacd977f3c..b68368d92a 100644 --- a/utils/BUILD.gn +++ b/utils/BUILD.gn @@ -40,12 +40,11 @@ ohos_shared_library("libwmutil") { public_configs = [ ":libwmutil_public_config" ] - deps = [ "//utils/native/base:utils" ] - external_deps = [ "bytrace_standard:bytrace_core", "hilog_native:libhilog", "ipc:ipc_core", + "utils_base:utils", ] part_name = "window_manager" diff --git a/wm/BUILD.gn b/wm/BUILD.gn index 2852ff4bba..ea9522a2c0 100644 --- a/wm/BUILD.gn +++ b/wm/BUILD.gn @@ -67,37 +67,32 @@ ohos_shared_library("libwm") { public_configs = [ ":libwm_public_config" ] deps = [ - "//foundation/distributedschedule/safwk/interfaces/innerkits/safwk:system_ability_fwk", - "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", - "//foundation/multimedia/image_standard/interfaces/innerkits:image_native", - "//foundation/windowmanager/utils:libwmutil", - "//utils/native/base:utils", - - # ace - "//foundation/aafwk/standard/interfaces/innerkits/ability_manager:ability_manager", - "//foundation/ace/ace_engine/interfaces/innerkits/ace:ace_uicontent", - "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_core:appexecfwk_core", - "//foundation/graphic/standard:libsurface", "//foundation/graphic/standard/rosen/modules/render_service_client:librender_service_client", + "//foundation/windowmanager/dm:libdm", + "//foundation/windowmanager/utils:libwmutil", # vsync "//foundation/graphic/standard:libvsync_client", - - # todo need delete it for abilitycontext - "//foundation/ace/napi:ace_napi", ] external_deps = [ "ability_runtime:ability_context_native", + "ability_runtime:ability_manager", "ability_runtime:want", + "ace_engine_standard:ace_uicontent", "appexecfwk_standard:appexecfwk_base", + "appexecfwk_standard:appexecfwk_core", "bytrace_standard:bytrace_core", + "graphic_standard:surface", "hilog_native:libhilog", "inputmethod_native:inputmethod_client", "ipc:ipc_core", "multimedia_image_standard:image_native", "multimodalinput_base:libmmi-client", - "window_manager:libdm", + "napi:ace_napi", + "safwk:system_ability_fwk", + "samgr_standard:samgr_proxy", + "utils_base:utils", ] part_name = "window_manager" diff --git a/wm/src/window_scene.cpp b/wm/src/window_scene.cpp index 24e1480666..01b3f6ccfa 100644 --- a/wm/src/window_scene.cpp +++ b/wm/src/window_scene.cpp @@ -14,6 +14,8 @@ */ #include "window_scene.h" +#include + #include "static_call.h" #include "window_impl.h" #include "window_manager_hilog.h" diff --git a/wm/test/systemtest/BUILD.gn b/wm/test/systemtest/BUILD.gn index 677279899a..85559989a3 100644 --- a/wm/test/systemtest/BUILD.gn +++ b/wm/test/systemtest/BUILD.gn @@ -116,6 +116,8 @@ config("wm_systemtest_common_public_config") { "//foundation/aafwk/standard/interfaces/innerkits/want/include/ohos/aafwk/content", "//foundation/distributedschedule/dmsfwk/services/dtbschedmgr/include", "//foundation/aafwk/standard/interfaces/innerkits/base/include", + "//third_party/jsoncpp/include", + "//third_party/json/include", # abilityContext end ] @@ -142,6 +144,7 @@ ohos_static_library("wm_systemtest_common") { # todo need delete it for abilitycontext "//foundation/ace/napi:ace_napi", + "//foundation/graphic/standard/rosen/modules/render_service_client:librender_service_client", "//foundation/multimodalinput/input/frameworks/proxy:libmmi-client", "//foundation/windowmanager/dm:libdm", "//foundation/windowmanager/dmserver:libdms", @@ -152,7 +155,5 @@ ohos_static_library("wm_systemtest_common") { "//third_party/googletest:gtest_main", "//utils/native/base:utils", ] - - external_deps = [ "ability_runtime:ability_context_native" ] } ## Build wm_systemtest_common.a }}} diff --git a/wm/test/unittest/BUILD.gn b/wm/test/unittest/BUILD.gn index 062ff5145b..9b37f01d54 100644 --- a/wm/test/unittest/BUILD.gn +++ b/wm/test/unittest/BUILD.gn @@ -140,6 +140,8 @@ config("wm_unittest_common_public_config") { "//foundation/aafwk/standard/interfaces/innerkits/want/include/ohos/aafwk/content", "//foundation/distributedschedule/dmsfwk/services/dtbschedmgr/include", "//foundation/aafwk/standard/interfaces/innerkits/base/include", + "//third_party/jsoncpp/include", + "//third_party/json/include", # abilityContext end ] @@ -163,8 +165,10 @@ ohos_static_library("wm_unittest_common") { "//foundation/ace/ace_engine/interfaces/innerkits/ace:ace_uicontent", # todo need delete it for abilitycontext + "//foundation/aafwk/standard/interfaces/innerkits/ability_manager:ability_manager", "//foundation/ace/napi:ace_napi", "//foundation/distributedschedule/safwk/interfaces/innerkits/safwk:system_ability_fwk", + "//foundation/graphic/standard/rosen/modules/render_service_client:librender_service_client", "//foundation/multimodalinput/input/frameworks/proxy:libmmi-client", "//foundation/windowmanager/dm:libdm", "//foundation/windowmanager/dmserver:libdms", diff --git a/wmserver/BUILD.gn b/wmserver/BUILD.gn index 461710915c..74b1042bd3 100644 --- a/wmserver/BUILD.gn +++ b/wmserver/BUILD.gn @@ -66,35 +66,29 @@ ohos_shared_library("libwms") { configs = [ ":libwms_config" ] deps = [ - "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog", - "//base/notification/ces_standard/frameworks/native:cesfwk_innerkits", - "//foundation/distributedschedule/safwk/interfaces/innerkits/safwk:system_ability_fwk", - "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", - "//foundation/graphic/standard:libsurface", - "//foundation/graphic/standard/rosen/modules/render_service_base:librender_service_base", + "//foundation/ace/ace_engine/build/external_config/flutter/skia:ace_skia_ohos", + "//foundation/graphic/standard/rosen/modules/render_service_client:librender_service_client", + "//foundation/windowmanager/utils:libwmutil", "//foundation/windowmanager/wm:libwm", - "//utils/native/base:utils", ] public_deps = [ - # ability manager - "//foundation/aafwk/standard/interfaces/innerkits/ability_manager:ability_manager", - "//foundation/aafwk/standard/interfaces/innerkits/want:want", - "//foundation/graphic/standard:libsurface", - "//foundation/graphic/standard/rosen/modules/render_service_base:librender_service_base", - - # RSSurface - "//foundation/ace/ace_engine/build/external_config/flutter/skia:ace_skia_ohos", - "//foundation/graphic/standard/rosen/modules/render_service_client:librender_service_client", - - # IMS + # IMS libdms need delete it "//foundation/multimodalinput/input/frameworks/proxy:libmmi-client", - "//foundation/windowmanager/utils:libwmutil", ] external_deps = [ + "ability_runtime:ability_manager", + "ability_runtime:want", "bytrace_standard:bytrace_core", + "ces_standard:cesfwk_innerkits", + "graphic_standard:surface", + "hilog_native:libhilog", "ipc:ipc_core", + "multimodalinput_base:libmmi-client", + "safwk:system_ability_fwk", + "samgr_standard:samgr_proxy", + "utils_base:utils", ] part_name = "window_manager" diff --git a/wmtest/BUILD.gn b/wmtest/BUILD.gn index 96dbe550da..f91fd2eb3c 100644 --- a/wmtest/BUILD.gn +++ b/wmtest/BUILD.gn @@ -55,7 +55,6 @@ ohos_executable("rosenwmtest") { configs = [ ":rosenwmtest_config" ] deps = [ - "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", "//foundation/graphic/standard:libvsync_client", "//foundation/graphic/standard:libwmclient", "//foundation/graphic/standard:libwmservice", @@ -70,6 +69,8 @@ ohos_executable("rosenwmtest") { "//foundation/ace/napi:ace_napi", ] + external_deps = [ "samgr_standard:samgr_proxy" ] + part_name = "window_manager" subsystem_name = "window" } -- Gitee From f5e7a578cedf1831ac8d11f3c781f17fea4998cd Mon Sep 17 00:00:00 2001 From: c00471419 Date: Thu, 20 Jan 2022 12:21:39 +0800 Subject: [PATCH 56/57] add getTopWindow for newNapi Signed-off-by: c00471419 Change-Id: Ia541ccbd5f37bb1e2ecb2355b5248ecae1f2ad50 Signed-off-by: c00471419 --- getTopWindow.patch | 138 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 138 insertions(+) create mode 100644 getTopWindow.patch diff --git a/getTopWindow.patch b/getTopWindow.patch new file mode 100644 index 0000000000..427c2a1f30 --- /dev/null +++ b/getTopWindow.patch @@ -0,0 +1,138 @@ +diff --git a/interfaces/kits/napi/window_runtime/BUILD.gn b/interfaces/kits/napi/window_runtime/BUILD.gn +index 4c58fe3..1a58c35 100644 +--- a/interfaces/kits/napi/window_runtime/BUILD.gn ++++ b/interfaces/kits/napi/window_runtime/BUILD.gn +@@ -9,7 +9,7 @@ + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and +-# limitations under the License. ++# limitations under the License. + + import("//ark/ts2abc/ts2panda/ts2abc_config.gni") + import("//build/ohos.gni") +@@ -23,6 +23,7 @@ config("window_manager_napi_config") { + "//foundation/windowmanager/interfaces/innerkits/dm", + "//foundation/windowmanager/wm/include", + "//foundation/windowmanager/utils/include", ++ "//foundation/appexecfwk/standard/kits/appkit/native/ability_runtime/context", + ] + } + +@@ -40,6 +41,9 @@ ohos_shared_library("windowmanager_napi") { + "//foundation/windowmanager/wm:libwm", + "//foundation/windowmanager/wm:libwmutil", + "//foundation/windowmanager/wmserver:libwms", ++ "//foundation/appexecfwk/standard/kits:appkit_native", ++ "//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native", ++ "//foundation/appexecfwk/standard/kits:app_context", + ] + + external_deps = [ +diff --git a/interfaces/kits/napi/window_runtime/js_window_manager.cpp b/interfaces/kits/napi/window_runtime/js_window_manager.cpp +index 1e883ac..fc45601 100644 +--- a/interfaces/kits/napi/window_runtime/js_window_manager.cpp ++++ b/interfaces/kits/napi/window_runtime/js_window_manager.cpp +@@ -13,6 +13,8 @@ + * limitations under the License. + */ + #include "js_window_manager.h" ++#include ++#include "context.h" + #include "js_runtime_utils.h" + #include "js_window.h" + #include "js_window_utils.h" +@@ -50,8 +52,15 @@ public: + return (me != nullptr) ? me->OnFindWindow(*engine, *info) : nullptr; + } + +-private: ++ static NativeValue* GetTopWindow(NativeEngine* engine, NativeCallbackInfo* info) ++ { ++ JsWindowManager* me = CheckParamsAndGetThis(engine, info); ++ return (me != nullptr) ? me->OnGetTopWindow(*engine, *info) : nullptr; ++ } + ++private: ++ bool isNewApi_ = true; ++ std::weak_ptr context_; + NativeValue* OnCreateWindow(NativeEngine& engine, NativeCallbackInfo& info) + { + WLOGFI("JsOnCreateWindow is called"); +@@ -120,6 +129,67 @@ private: + engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result)); + return result; + } ++ ++ bool GetAPI7Ability(NativeEngine& engine, AppExecFwk::Ability* ability) ++ { ++ napi_value global; ++ auto env = reinterpret_cast(&engine); ++ if (napi_get_global(env, &global) != napi_ok) { ++ WLOGFI("JsWindowManager::GetAPI7Ability get global failed"); ++ return false; ++ } ++ napi_value jsAbility; ++ if (napi_get_named_property(env, global, "ability", &jsAbility) != napi_ok) { ++ WLOGFI("JsWindowManager::GetAPI7Ability get global failed"); ++ return false; ++ } ++ if (napi_get_value_external(env, jsAbility, reinterpret_cast(&ability)) != napi_ok) { ++ WLOGFI("JsWindowManager::GetAPI7Ability get global failed"); ++ return false; ++ } ++ return true; ++ } ++ ++ NativeValue* OnGetTopWindow(NativeEngine& engine, NativeCallbackInfo& info) ++ { ++ NativeValue* nativeContext = nullptr; ++ NativeValue* nativeCallback = nullptr; ++ if (info.argv[0]->TypeOf() == NATIVE_OBJECT) { // (context, callback?) ++ isNewApi_ = true; ++ nativeContext = info.argv[0]; ++ nativeCallback = (info.argc == ARGC_ONE) ? nullptr : info.argv[1]; ++ } else { // (callback?) ++ isNewApi_ = false; ++ nativeCallback = (info.argc == ARGC_ONE) ? nullptr : info.argv[1]; ++ } ++ ++ ++ AsyncTask::CompleteCallback complete = ++ [this, weak = context_](NativeEngine& engine, AsyncTask& task, int32_t status) { ++ AppExecFwk::Ability* ability = nullptr; ++ if (!isNewApi_) { ++ if (!GetAPI7Ability(engine, ability) || ability == nullptr) { ++ task.Reject(engine, CreateJsError(engine, ++ static_cast(WMError::WM_ERROR_NULLPTR), "JsWindow::onGetTopWindow failed.")); ++ } ++ sptr window = ability->GetWindow(); ++ task.Resolve(engine, CreateJsWindowObject(engine, window)); ++ WLOGFI("JsWindowManager::OnGetTopWindow success"); ++ } else { ++ auto context = weak.lock(); ++ if (context != nullptr) { ++ WLOGFI("JsWindowManager::OnGetTopWindow success"); ++ } else { ++ task.Reject(engine, CreateJsError(engine, ++ static_cast(WMError::WM_ERROR_NULLPTR), "JsWindow::onGetTopWindow newAPI failed.")); ++ } ++ } ++ }; ++ NativeValue* result = nullptr; ++ AsyncTask::Schedule( ++ engine, CreateAsyncTaskWithLastParam(engine, nativeCallback, nullptr, std::move(complete), &result)); ++ return result; ++ } + }; + + NativeValue* JsWindowManagerInit(NativeEngine* engine, NativeValue* exportObj) +@@ -142,7 +212,7 @@ NativeValue* JsWindowManagerInit(NativeEngine* engine, NativeValue* exportObj) + + BindNativeFunction(*engine, *object, "create", JsWindowManager::CreateWindow); + BindNativeFunction(*engine, *object, "find", JsWindowManager::FindWindow); +- ++ BindNativeFunction(*engine, *object, "getTopWindow", JsWindowManager::GetTopWindow); + return engine->CreateUndefined(); + } + } // namespace Rosen -- Gitee From 9a78b1c967024ef7718e246c93a343e1dc57f7e1 Mon Sep 17 00:00:00 2001 From: c00471419 Date: Sat, 22 Jan 2022 13:45:28 +0800 Subject: [PATCH 57/57] add jscreate limit Signed-off-by: c00471419 Change-Id: Ie89cdc419cd7a7033461db2c248ee70be0115206 --- getTopWindow.patch | 138 ------------------ interfaces/innerkits/wm/window.h | 10 +- .../napi/window_runtime/api/@ohos.window.d.ts | 68 ++++----- .../window_manager_napi/js_window_manager.cpp | 48 ++++-- .../window_runtime/window_napi/js_window.cpp | 65 +++++++++ .../window_runtime/window_napi/js_window.h | 5 +- .../window_napi/js_window_utils.cpp | 4 + wm/include/window_impl.h | 9 +- wm/src/window_impl.cpp | 45 +++++- 9 files changed, 193 insertions(+), 199 deletions(-) delete mode 100644 getTopWindow.patch diff --git a/getTopWindow.patch b/getTopWindow.patch deleted file mode 100644 index 427c2a1f30..0000000000 --- a/getTopWindow.patch +++ /dev/null @@ -1,138 +0,0 @@ -diff --git a/interfaces/kits/napi/window_runtime/BUILD.gn b/interfaces/kits/napi/window_runtime/BUILD.gn -index 4c58fe3..1a58c35 100644 ---- a/interfaces/kits/napi/window_runtime/BUILD.gn -+++ b/interfaces/kits/napi/window_runtime/BUILD.gn -@@ -9,7 +9,7 @@ - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and --# limitations under the License. -+# limitations under the License. - - import("//ark/ts2abc/ts2panda/ts2abc_config.gni") - import("//build/ohos.gni") -@@ -23,6 +23,7 @@ config("window_manager_napi_config") { - "//foundation/windowmanager/interfaces/innerkits/dm", - "//foundation/windowmanager/wm/include", - "//foundation/windowmanager/utils/include", -+ "//foundation/appexecfwk/standard/kits/appkit/native/ability_runtime/context", - ] - } - -@@ -40,6 +41,9 @@ ohos_shared_library("windowmanager_napi") { - "//foundation/windowmanager/wm:libwm", - "//foundation/windowmanager/wm:libwmutil", - "//foundation/windowmanager/wmserver:libwms", -+ "//foundation/appexecfwk/standard/kits:appkit_native", -+ "//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native", -+ "//foundation/appexecfwk/standard/kits:app_context", - ] - - external_deps = [ -diff --git a/interfaces/kits/napi/window_runtime/js_window_manager.cpp b/interfaces/kits/napi/window_runtime/js_window_manager.cpp -index 1e883ac..fc45601 100644 ---- a/interfaces/kits/napi/window_runtime/js_window_manager.cpp -+++ b/interfaces/kits/napi/window_runtime/js_window_manager.cpp -@@ -13,6 +13,8 @@ - * limitations under the License. - */ - #include "js_window_manager.h" -+#include -+#include "context.h" - #include "js_runtime_utils.h" - #include "js_window.h" - #include "js_window_utils.h" -@@ -50,8 +52,15 @@ public: - return (me != nullptr) ? me->OnFindWindow(*engine, *info) : nullptr; - } - --private: -+ static NativeValue* GetTopWindow(NativeEngine* engine, NativeCallbackInfo* info) -+ { -+ JsWindowManager* me = CheckParamsAndGetThis(engine, info); -+ return (me != nullptr) ? me->OnGetTopWindow(*engine, *info) : nullptr; -+ } - -+private: -+ bool isNewApi_ = true; -+ std::weak_ptr context_; - NativeValue* OnCreateWindow(NativeEngine& engine, NativeCallbackInfo& info) - { - WLOGFI("JsOnCreateWindow is called"); -@@ -120,6 +129,67 @@ private: - engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result)); - return result; - } -+ -+ bool GetAPI7Ability(NativeEngine& engine, AppExecFwk::Ability* ability) -+ { -+ napi_value global; -+ auto env = reinterpret_cast(&engine); -+ if (napi_get_global(env, &global) != napi_ok) { -+ WLOGFI("JsWindowManager::GetAPI7Ability get global failed"); -+ return false; -+ } -+ napi_value jsAbility; -+ if (napi_get_named_property(env, global, "ability", &jsAbility) != napi_ok) { -+ WLOGFI("JsWindowManager::GetAPI7Ability get global failed"); -+ return false; -+ } -+ if (napi_get_value_external(env, jsAbility, reinterpret_cast(&ability)) != napi_ok) { -+ WLOGFI("JsWindowManager::GetAPI7Ability get global failed"); -+ return false; -+ } -+ return true; -+ } -+ -+ NativeValue* OnGetTopWindow(NativeEngine& engine, NativeCallbackInfo& info) -+ { -+ NativeValue* nativeContext = nullptr; -+ NativeValue* nativeCallback = nullptr; -+ if (info.argv[0]->TypeOf() == NATIVE_OBJECT) { // (context, callback?) -+ isNewApi_ = true; -+ nativeContext = info.argv[0]; -+ nativeCallback = (info.argc == ARGC_ONE) ? nullptr : info.argv[1]; -+ } else { // (callback?) -+ isNewApi_ = false; -+ nativeCallback = (info.argc == ARGC_ONE) ? nullptr : info.argv[1]; -+ } -+ -+ -+ AsyncTask::CompleteCallback complete = -+ [this, weak = context_](NativeEngine& engine, AsyncTask& task, int32_t status) { -+ AppExecFwk::Ability* ability = nullptr; -+ if (!isNewApi_) { -+ if (!GetAPI7Ability(engine, ability) || ability == nullptr) { -+ task.Reject(engine, CreateJsError(engine, -+ static_cast(WMError::WM_ERROR_NULLPTR), "JsWindow::onGetTopWindow failed.")); -+ } -+ sptr window = ability->GetWindow(); -+ task.Resolve(engine, CreateJsWindowObject(engine, window)); -+ WLOGFI("JsWindowManager::OnGetTopWindow success"); -+ } else { -+ auto context = weak.lock(); -+ if (context != nullptr) { -+ WLOGFI("JsWindowManager::OnGetTopWindow success"); -+ } else { -+ task.Reject(engine, CreateJsError(engine, -+ static_cast(WMError::WM_ERROR_NULLPTR), "JsWindow::onGetTopWindow newAPI failed.")); -+ } -+ } -+ }; -+ NativeValue* result = nullptr; -+ AsyncTask::Schedule( -+ engine, CreateAsyncTaskWithLastParam(engine, nativeCallback, nullptr, std::move(complete), &result)); -+ return result; -+ } - }; - - NativeValue* JsWindowManagerInit(NativeEngine* engine, NativeValue* exportObj) -@@ -142,7 +212,7 @@ NativeValue* JsWindowManagerInit(NativeEngine* engine, NativeValue* exportObj) - - BindNativeFunction(*engine, *object, "create", JsWindowManager::CreateWindow); - BindNativeFunction(*engine, *object, "find", JsWindowManager::FindWindow); -- -+ BindNativeFunction(*engine, *object, "getTopWindow", JsWindowManager::GetTopWindow); - return engine->CreateUndefined(); - } - } // namespace Rosen diff --git a/interfaces/innerkits/wm/window.h b/interfaces/innerkits/wm/window.h index 93406adcdb..597d7ef400 100644 --- a/interfaces/innerkits/wm/window.h +++ b/interfaces/innerkits/wm/window.h @@ -64,9 +64,13 @@ public: virtual WindowMode GetMode() const = 0; virtual const std::string& GetWindowName() const = 0; virtual uint32_t GetWindowId() = 0; - virtual uint32_t GetWindowFlags() = 0; - virtual SystemBarProperty GetSystemBarPropertyByType(WindowType type) = 0; - + virtual uint32_t GetWindowFlags() const = 0; + virtual bool GetShowState() const = 0; + virtual bool GetFocusable() const = 0; + virtual bool GetTouchable() const = 0; + virtual SystemBarProperty GetSystemBarPropertyByType(WindowType type) const = 0; + virtual bool IsFullScreen() const = 0; + virtual bool IsLayoutFullScreen() const = 0; virtual WMError SetWindowType(WindowType type) = 0; virtual WMError SetWindowMode(WindowMode mode) = 0; virtual WMError AddWindowFlag(WindowFlag flag) = 0; diff --git a/interfaces/kits/napi/window_runtime/api/@ohos.window.d.ts b/interfaces/kits/napi/window_runtime/api/@ohos.window.d.ts index 151d9e413b..d31a238562 100644 --- a/interfaces/kits/napi/window_runtime/api/@ohos.window.d.ts +++ b/interfaces/kits/napi/window_runtime/api/@ohos.window.d.ts @@ -20,40 +20,40 @@ import { Context } from './app/context'; */ declare namespace window { enum WindowType { - APP_WINDOW_BASE = 1, - APP_MAIN_WINDOW_BASE = APP_WINDOW_BASE, - WINDOW_TYPE_APP_MAIN_WINDOW = APP_MAIN_WINDOW_BASE, - APP_MAIN_WINDOW_END = WINDOW_TYPE_APP_MAIN_WINDOW, // equals last window type - - APP_SUB_WINDOW_BASE = 1000, - WINDOW_TYPE_MEDIA = APP_SUB_WINDOW_BASE, - WINDOW_TYPE_APP_SUB_WINDOW, - APP_SUB_WINDOW_END = WINDOW_TYPE_APP_SUB_WINDOW, // equals last window type - APP_WINDOW_END = APP_SUB_WINDOW_END, - - SYSTEM_WINDOW_BASE = 2000, - BELOW_APP_SYSTEM_WINDOW_BASE = SYSTEM_WINDOW_BASE, - WINDOW_TYPE_WALLPAPER = SYSTEM_WINDOW_BASE, - BELOW_APP_SYSTEM_WINDOW_END = WINDOW_TYPE_WALLPAPER, // equals last window type - - ABOVE_APP_SYSTEM_WINDOW_BASE = 2100, - WINDOW_TYPE_APP_LAUNCHING = ABOVE_APP_SYSTEM_WINDOW_BASE, - WINDOW_TYPE_DOCK_SLICE, - WINDOW_TYPE_INCOMING_CALL, - WINDOW_TYPE_SEARCHING_BAR, - WINDOW_TYPE_SYSTEM_ALARM_WINDOW, - WINDOW_TYPE_INPUT_METHOD_FLOAT, - WINDOW_TYPE_FLOAT, - WINDOW_TYPE_TOAST, - WINDOW_TYPE_STATUS_BAR, - WINDOW_TYPE_PANEL, - WINDOW_TYPE_KEYGUARD, - WINDOW_TYPE_VOLUME_OVERLAY, - WINDOW_TYPE_NAVIGATION_BAR, - WINDOW_TYPE_DRAGGING_EFFECT, - WINDOW_TYPE_POINTER, - ABOVE_APP_SYSTEM_WINDOW_END = WINDOW_TYPE_POINTER, // equals last window type - SYSTEM_WINDOW_END = ABOVE_APP_SYSTEM_WINDOW_END, + TYPE_APP_WINDOW_BASE = 1, + TYPE_APP_MAIN_WINDOW_BASE = TYPE_APP_WINDOW_BASE, + TYPE_APP = TYPE_APP_MAIN_WINDOW_BASE, + TYPE_APP_MAIN_WINDOW_END = TYPE_APP, // equals last window type + + TYPE_APP_SUB_WINDOW_BASE = 1000, + TYPE_MEDIA = TYPE_APP_SUB_WINDOW_BASE, + TYPE_APP_SUB_WINDOW, + TYPE_APP_SUB_WINDOW_END = TYPE_APP_SUB_WINDOW, // equals last window type + TYPE_APP_WINDOW_END = TYPE_APP_SUB_WINDOW_END, + + TYPE_SYSTEM_WINDOW_BASE = 2000, + TYPE_BELOW_APP_SYSTEM_WINDOW_BASE = TYPE_SYSTEM_WINDOW_BASE, + TYPE_WALLPAPER = TYPE_SYSTEM_WINDOW_BASE, + TYPE_BELOW_APP_SYSTEM_WINDOW_END = TYPE_WALLPAPER, // equals last window type + + TYPE_ABOVE_APP_SYSTEM_WINDOW_BASE = 2100, + TYPE_APP_LAUNCHING = TYPE_ABOVE_APP_SYSTEM_WINDOW_BASE, + TYPE_DOCK_SLICE, + TYPE_INCOMING_CALL, + TYPE_SEARCHING_BAR, + TYPE_SYSTEM_ALERT, + TYPE_INPUT_METHOD_FLOAT, + TYPE_FLOAT, + TYPE_TOAST, + TYPE_STATUS_BAR, + TYPE_PANEL, + TYPE_KEYGUARD, + TYPE_VOLUME_OVERLAY, + TYPE_NAVIGATION_BAR, + TYPE_DRAGGING_EFFECT, + TYPE_POINTER, + TYPE_ABOVE_APP_SYSTEM_WINDOW_END = TYPE_POINTER, // equals last window type + TYPE_SYSTEM_WINDOW_END = TYPE_ABOVE_APP_SYSTEM_WINDOW_END, } /** diff --git a/interfaces/kits/napi/window_runtime/window_manager_napi/js_window_manager.cpp b/interfaces/kits/napi/window_runtime/window_manager_napi/js_window_manager.cpp index 9b1b03effc..d01371b6aa 100644 --- a/interfaces/kits/napi/window_runtime/window_manager_napi/js_window_manager.cpp +++ b/interfaces/kits/napi/window_runtime/window_manager_napi/js_window_manager.cpp @@ -19,6 +19,7 @@ #include "js_window_listener.h" #include "js_window_utils.h" #include "native_engine/native_reference.h" +#include "window_helper.h" #include "window_manager.h" #include "window_manager_hilog.h" #include "window_option.h" @@ -84,6 +85,7 @@ private: // Parse info->argv[0] as abilitycontext auto objContext = AbilityRuntime::ConvertNativeValueTo(nativeContext); if (objContext == nullptr) { + WLOGFE("ConvertNativeValueTo Context Object failed"); return false; } auto context = static_cast*>(objContext->GetNativePointer()); @@ -92,21 +94,40 @@ private: return true; } + bool CheckJsWindowNameAndType(NativeEngine& engine, std::string& windowName, WindowType& winType, + NativeValue* nativeString, NativeValue* nativeType) + { + if (!ConvertFromJsValue(engine, nativeString, windowName)) { + WLOGFE("Failed to convert parameter to windowName"); + return false; + } + NativeNumber* type = ConvertNativeValueTo(nativeType); + if (type == nullptr) { + WLOGFE("Failed to convert parameter to windowType"); + return false; + } + winType = static_cast(static_cast(*type)); + if (!WindowHelper::IsSystemWindow(winType)) { + WLOGFE("Only SystemWindow support create!"); + return false; + } + return true; + } + NativeValue* OnCreateWindow(NativeEngine& engine, NativeCallbackInfo& info) { - WLOGFI("JsWindowManager::JsOnCreateWindow is called"); - if (info.argc <= 0) { - WLOGFE("parames num not match!"); + WLOGFI("JsWindowManager::OnCreateWindow is called"); + if (info.argc < ARGC_THREE) { + WLOGFE("JsWindowManager::OnCreateWindow params less than 3!"); return engine.CreateUndefined(); } NativeValue* nativeString = nullptr; NativeValue* nativeContext = nullptr; NativeValue* nativeType = nullptr; NativeValue* callback = nullptr; - if (info.argv[0]->TypeOf() == NATIVE_STRING) { - nativeString = info.argv[0]; - nativeType = info.argv[ARGC_ONE]; - callback = (info.argc == ARGC_TWO) ? nullptr : info.argv[INDEX_TWO]; + if (info.argv[0]->TypeOf() != NATIVE_OBJECT) { + WLOGFE("JsWindowManager::OnCreateWindow first should be context!"); + return engine.CreateUndefined(); } else { nativeContext = info.argv[0]; nativeString = info.argv[ARGC_ONE]; @@ -114,17 +135,13 @@ private: callback = (info.argc == ARGC_THREE) ? nullptr : info.argv[INDEX_THREE]; } std::string windowName; - if (!ConvertFromJsValue(engine, nativeString, windowName)) { - WLOGFE("Failed to convert parameter to windowName"); - return engine.CreateUndefined(); - } - NativeNumber* type = ConvertNativeValueTo(nativeType); - if (type == nullptr) { - WLOGFE("Failed to convert parameter to windowType"); + WindowType winType; + if (!CheckJsWindowNameAndType(engine, windowName, winType, nativeString, nativeType)) { + WLOGFE("JsWindowManager::OnCreateWindow CheckJsWindowNameAndType failed!"); return engine.CreateUndefined(); } - WindowType winType = static_cast(static_cast(*type)); if (!GetNativeContext(nativeContext)) { + WLOGFE("JsWindowManager::OnCreateWindow convert to context failed!"); return engine.CreateUndefined(); } AsyncTask::CompleteCallback complete = @@ -134,6 +151,7 @@ private: sptr window = Window::Create(windowName, windowOption, weak.lock()); if (window != nullptr) { task.Resolve(engine, CreateJsWindowObject(engine, window)); + WLOGFI("JsWindowManager::OnCreateWindow success"); } else { task.Reject(engine, CreateJsError(engine, static_cast(WMError::WM_ERROR_NULLPTR), "JsWindowManager::OnCreateWindow failed.")); diff --git a/interfaces/kits/napi/window_runtime/window_napi/js_window.cpp b/interfaces/kits/napi/window_runtime/window_napi/js_window.cpp index 3d6dbe8d66..d4a14209d4 100644 --- a/interfaces/kits/napi/window_runtime/window_napi/js_window.cpp +++ b/interfaces/kits/napi/window_runtime/window_napi/js_window.cpp @@ -27,6 +27,7 @@ namespace { constexpr Rect EMPTY_RECT = {0, 0, 0, 0}; static std::map> g_jsWindowMap; +std::recursive_mutex g_mutex; JsWindow::JsWindow(const sptr& window) : windowToken_(window) { } @@ -50,6 +51,7 @@ void JsWindow::Finalizer(NativeEngine* engine, void* data, void* hint) auto jsWin = std::unique_ptr(static_cast(data)); std::string windowName = jsWin->GetWindowName(); WLOGFI("JsWindow::Finalizer windowName : %{public}s", windowName.c_str()); + std::lock_guard lock(g_mutex); if (g_jsWindowMap.find(windowName) != g_jsWindowMap.end()) { WLOGFI("JsWindow::windowName %{public}s is destroyed", windowName.c_str()); g_jsWindowMap.erase(windowName); @@ -168,6 +170,20 @@ NativeValue* JsWindow::GetAvoidArea(NativeEngine* engine, NativeCallbackInfo* in return (me != nullptr) ? me->OnGetAvoidArea(*engine, *info) : nullptr; } +NativeValue* JsWindow::GetWindowMode(NativeEngine* engine, NativeCallbackInfo* info) +{ + WLOGFI("JsWindow::GetWindowMode is called"); + JsWindow* me = CheckParamsAndGetThis(engine, info); + return (me != nullptr) ? me->OnGetWindowMode(*engine, *info) : nullptr; +} + +NativeValue* JsWindow::IsShowing(NativeEngine* engine, NativeCallbackInfo* info) +{ + WLOGFI("JsWindow::IsShowing is called"); + JsWindow* me = CheckParamsAndGetThis(engine, info); + return (me != nullptr) ? me->OnIsShowing(*engine, *info) : nullptr; +} + NativeValue* JsWindow::OnShow(NativeEngine& engine, NativeCallbackInfo& info) { WLOGFI("JsWindow::OnShow is called"); @@ -208,6 +224,7 @@ NativeValue* JsWindow::OnDestroy(NativeEngine& engine, NativeCallbackInfo& info) return; } std::string windowName = windowToken_->GetWindowName(); + std::lock_guard lock(g_mutex); if (g_jsWindowMap.find(windowName) != g_jsWindowMap.end()) { g_jsWindowMap.erase(windowName); WLOGFI("JsWindow::OnDestroy windowName %{public}s is destroyed", windowName.c_str()); @@ -814,9 +831,54 @@ NativeValue* JsWindow::OnGetAvoidArea(NativeEngine& engine, NativeCallbackInfo& return result; } +NativeValue* JsWindow::OnGetWindowMode(NativeEngine& engine, NativeCallbackInfo& info) +{ + WLOGFI("JsWindow::OnGetWindowMode is called"); + AsyncTask::CompleteCallback complete = + [this](NativeEngine& engine, AsyncTask& task, int32_t status) { + if (windowToken_ == nullptr) { + task.Reject(engine, CreateJsError(engine, static_cast(WMError::WM_ERROR_NULLPTR), + "JsWindow::OnGetWindowMode failed.")); + WLOGFE("JsWindow windowToken_ is nullptr"); + return; + } + WindowMode mode = windowToken_->GetMode(); + task.Resolve(engine, CreateJsValue(engine, mode)); + }; + + NativeValue* lastParam = (info.argc == 0) ? nullptr : info.argv[0]; + NativeValue* result = nullptr; + AsyncTask::Schedule( + engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result)); + return result; +} + +NativeValue* JsWindow::OnIsShowing(NativeEngine& engine, NativeCallbackInfo& info) +{ + WLOGFI("JsWindow::OnIsShowing is called"); + AsyncTask::CompleteCallback complete = + [this](NativeEngine& engine, AsyncTask& task, int32_t status) { + if (windowToken_ == nullptr) { + task.Reject(engine, CreateJsError(engine, static_cast(WMError::WM_ERROR_NULLPTR), + "JsWindow::OnIsShowing failed.")); + WLOGFE("JsWindow windowToken_ is nullptr"); + return; + } + bool state = windowToken_->GetShowState(); + task.Resolve(engine, CreateJsValue(engine, state)); + }; + + NativeValue* lastParam = (info.argc == 0) ? nullptr : info.argv[0]; + NativeValue* result = nullptr; + AsyncTask::Schedule( + engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result)); + return result; +} + std::shared_ptr FindJsWindowObject(std::string windowName) { WLOGFI("JsWindow::FindJsWindowObject is called"); + std::lock_guard lock(g_mutex); if (g_jsWindowMap.find(windowName) == g_jsWindowMap.end()) { WLOGFI("JsWindow::FindJsWindowObject window %{public}s not exist!", windowName.c_str()); return nullptr; @@ -827,6 +889,7 @@ std::shared_ptr FindJsWindowObject(std::string windowName) NativeValue* CreateJsWindowObject(NativeEngine& engine, sptr& window) { WLOGFI("JsWindow::CreateJsWindow is called"); + std::lock_guard lock(g_mutex); NativeValue* objValue = engine.CreateObject(); NativeObject* object = ConvertNativeValueTo(objValue); @@ -849,6 +912,8 @@ NativeValue* CreateJsWindowObject(NativeEngine& engine, sptr& window) BindNativeFunction(engine, *object, "setSystemBarEnable", JsWindow::SetSystemBarEnable); BindNativeFunction(engine, *object, "setSystemBarProperties", JsWindow::SetSystemBarProperties); BindNativeFunction(engine, *object, "getAvoidArea", JsWindow::GetAvoidArea); + BindNativeFunction(engine, *object, "getWindowMode", JsWindow::GetWindowMode); + BindNativeFunction(engine, *object, "isShowing", JsWindow::IsShowing); std::shared_ptr jsWindowRef; jsWindowRef.reset(engine.CreateReference(objValue, 1)); std::string windowName = window->GetWindowName(); diff --git a/interfaces/kits/napi/window_runtime/window_napi/js_window.h b/interfaces/kits/napi/window_runtime/window_napi/js_window.h index 9ad4bcbc2a..1c4ccc98e5 100644 --- a/interfaces/kits/napi/window_runtime/window_napi/js_window.h +++ b/interfaces/kits/napi/window_runtime/window_napi/js_window.h @@ -46,6 +46,8 @@ public: static NativeValue* SetSystemBarEnable(NativeEngine* engine, NativeCallbackInfo* info); static NativeValue* SetSystemBarProperties(NativeEngine* engine, NativeCallbackInfo* info); static NativeValue* GetAvoidArea(NativeEngine* engine, NativeCallbackInfo* info); + static NativeValue* GetWindowMode(NativeEngine* engine, NativeCallbackInfo* info); + static NativeValue* IsShowing(NativeEngine* engine, NativeCallbackInfo* info); private: bool IfCallbackRegistered(std::string type, NativeValue* jsListenerObject); @@ -69,7 +71,8 @@ private: NativeValue* OnSetSystemBarProperties(NativeEngine& engine, NativeCallbackInfo& info); NativeValue* OnLoadContent(NativeEngine& engine, NativeCallbackInfo& info); NativeValue* OnGetAvoidArea(NativeEngine& engine, NativeCallbackInfo& info); - + NativeValue* OnGetWindowMode(NativeEngine& engine, NativeCallbackInfo& info); + NativeValue* OnIsShowing(NativeEngine& engine, NativeCallbackInfo& info); sptr windowToken_ = nullptr; std::map>> jsCallbackMap_; std::map> jsListenerMap_; diff --git a/interfaces/kits/napi/window_runtime/window_napi/js_window_utils.cpp b/interfaces/kits/napi/window_runtime/window_napi/js_window_utils.cpp index 9c9ef1a9e0..1d9a1fa3b4 100644 --- a/interfaces/kits/napi/window_runtime/window_napi/js_window_utils.cpp +++ b/interfaces/kits/napi/window_runtime/window_napi/js_window_utils.cpp @@ -57,6 +57,10 @@ NativeValue* CreateJsWindowPropertiesObject(NativeEngine& engine, sptr& } object->SetProperty("windowRect", rectObj); object->SetProperty("type", CreateJsValue(engine, window->GetType())); + object->SetProperty("isLayoutFullScreen", CreateJsValue(engine, window->IsLayoutFullScreen())); + object->SetProperty("isFullScreen", CreateJsValue(engine, window->IsFullScreen())); + object->SetProperty("touchable", CreateJsValue(engine, window->GetTouchable())); + object->SetProperty("focusable", CreateJsValue(engine, window->GetFocusable())); return objValue; } static std::string GetHexColor(uint32_t color) diff --git a/wm/include/window_impl.h b/wm/include/window_impl.h index 40377cd7f6..fcb8820a66 100644 --- a/wm/include/window_impl.h +++ b/wm/include/window_impl.h @@ -49,10 +49,15 @@ public: virtual Rect GetRect() const override; virtual WindowType GetType() const override; virtual WindowMode GetMode() const override; + virtual bool GetShowState() const override; + virtual bool GetFocusable() const override; + virtual bool GetTouchable() const override; virtual const std::string& GetWindowName() const override; virtual uint32_t GetWindowId() override; - virtual uint32_t GetWindowFlags() override; - virtual SystemBarProperty GetSystemBarPropertyByType(WindowType type) override; + virtual uint32_t GetWindowFlags() const override; + virtual SystemBarProperty GetSystemBarPropertyByType(WindowType type) const override; + virtual bool IsFullScreen() const override; + virtual bool IsLayoutFullScreen() const override; virtual WMError SetWindowType(WindowType type) override; virtual WMError SetWindowMode(WindowMode mode) override; virtual WMError AddWindowFlag(WindowFlag flag) override; diff --git a/wm/src/window_impl.cpp b/wm/src/window_impl.cpp index 3bda4f56e9..3bc0d7b32e 100644 --- a/wm/src/window_impl.cpp +++ b/wm/src/window_impl.cpp @@ -92,6 +92,21 @@ WindowMode WindowImpl::GetMode() const return property_->GetWindowMode(); } +bool WindowImpl::GetShowState() const +{ + return state_ == STATE_SHOWN; +} + +bool WindowImpl::GetFocusable() const +{ + return property_->GetFocusable(); +} + +bool WindowImpl::GetTouchable() const +{ + return property_->GetTouchable(); +} + const std::string& WindowImpl::GetWindowName() const { return name_; @@ -102,12 +117,12 @@ uint32_t WindowImpl::GetWindowId() return property_->GetWindowId(); } -uint32_t WindowImpl::GetWindowFlags() +uint32_t WindowImpl::GetWindowFlags() const { return property_->GetWindowFlags(); } -SystemBarProperty WindowImpl::GetSystemBarPropertyByType(WindowType type) +SystemBarProperty WindowImpl::GetSystemBarPropertyByType(WindowType type) const { auto curProperties = property_->GetSystemBarProperty(); return curProperties[type]; @@ -207,10 +222,6 @@ WMError WindowImpl::SetUIContent(const std::string& contentInfo, NativeEngine* engine, NativeValue* storage, bool isdistributed) { WLOGFI("SetUIContent"); - if (context_.get() == nullptr) { - WLOGFE("SetUIContent context_ is nullptr id: %{public}d", property_->GetWindowId()); - return WMError::WM_ERROR_NULLPTR; - } WLOGFI("contentInfo: %{public}s, context_:%{public}p", contentInfo.c_str(), context_.get()); uiContent_ = Ace::UIContent::Create(context_.get(), engine); if (uiContent_ == nullptr) { @@ -741,5 +752,27 @@ bool WindowImpl::IsWindowValid() const { return ((state_ > STATE_INITIAL) && (state_ < STATE_BOTTOM)); } + +bool WindowImpl::IsLayoutFullScreen() const +{ + uint32_t flags = GetWindowFlags(); + auto mode = GetMode(); + bool needAvoid = (flags & static_cast(WindowFlag::WINDOW_FLAG_NEED_AVOID)); + if (mode == WindowMode::WINDOW_MODE_FULLSCREEN && !needAvoid) { + return true; + } + return false; +} + +bool WindowImpl::IsFullScreen() const +{ + auto mode = GetMode(); + auto statusProperty = GetSystemBarPropertyByType(WindowType::WINDOW_TYPE_STATUS_BAR); + auto navProperty = GetSystemBarPropertyByType(WindowType::WINDOW_TYPE_NAVIGATION_BAR); + if (mode == WindowMode::WINDOW_MODE_FULLSCREEN && !statusProperty.enable_ && !navProperty.enable_) { + return true; + } + return false; +} } } -- Gitee