• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <iostream>
17 #include <refbase.h>
18 
19 #include "window.h"
20 #include "wm_common.h"
21 #include "window_option.h"
22 #include "window_manager.h"
23 #include "common_test_utils.h"
24 #include "future.h"
25 
26 namespace OHOS {
27 namespace Rosen {
28 class SystemSubWindowFuture : public IVisibilityChangedListener {
29 using VisibleInfos = std::vector<sptr<WindowVisibilityInfo>>;
30 public:
OnWindowVisibilityChanged(const std::vector<sptr<WindowVisibilityInfo>> & windowVisibilityInfo)31     void OnWindowVisibilityChanged(const std::vector<sptr<WindowVisibilityInfo>>& windowVisibilityInfo) override
32     {
33         future_.SetValue(1);
34     };
35     RunnableFuture<int32_t> future_;
36     static constexpr long WAIT_TIME = 20000;
37 };
38 }
39 }
40 
41 using namespace OHOS;
42 using namespace OHOS::Rosen;
43 
OutputWindowInfos(const std::vector<sptr<AccessibilityWindowInfo>> & infos)44 void OutputWindowInfos(const std::vector<sptr<AccessibilityWindowInfo>>& infos)
45 {
46     std::cout << "window tree infos length :" << infos.size() << std::endl;
47     std::cout << "windowId -- windowType -- displayId" << std::endl;
48     for (auto info: infos) {
49         std::cout << "  " << info->wid_;
50         std::cout << " -- " << static_cast<int32_t>(info->type_);
51         std::cout << " -- " << std::to_string(info->displayId_);
52         std::cout << std::endl;
53     }
54 }
55 
main(int argc,char * argv[])56 int main(int argc, char* argv[])
57 {
58     std::cout << "===========================Start===========================" << std::endl;
59     std::cout << "Wait 20s, The Windows will close itself" << std::endl;
60 
61     std::vector<sptr<AccessibilityWindowInfo>> infos;
62     WindowManager::GetInstance().GetAccessibilityWindowInfo(infos);
63     std::cout << "before add window " << std::endl;
64     OutputWindowInfos(infos);
65 
66     CommonTestUtils::GuaranteeFloatWindowPermission("demo_system_sub_window");
67     Rect baseWindowRect = { 150, 150, 400, 600 };
68     sptr<WindowOption> baseOp = new WindowOption();
69     baseOp->SetWindowType(WindowType::WINDOW_TYPE_FLOAT);
70     baseOp->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
71     baseOp->SetWindowRect(baseWindowRect);
72 
73     sptr<Window> window = Window::Create("Demo_SSW_BaseWindow", baseOp, nullptr);
74     window->Show();
75     std::cout << "base window id = " << window->GetWindowId() << std::endl;
76 
77     Rect subWindowRect = { 200, 200, 150, 150 };
78     sptr<WindowOption> subWindowOp = new WindowOption();
79     subWindowOp->SetWindowType(WindowType::WINDOW_TYPE_SYSTEM_SUB_WINDOW);
80     subWindowOp->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
81     subWindowOp->SetWindowRect(subWindowRect);
82     subWindowOp->SetParentId(window->GetWindowId());
83 
84     sptr<Window> subWindow = Window::Create("Demo_SSW_SubWindow", subWindowOp, nullptr);
85     subWindow->Show();
86     std::cout << "sub window id = " << subWindow->GetWindowId() << std::endl;
87 
88     infos.clear();
89     WindowManager::GetInstance().GetAccessibilityWindowInfo(infos);
90     std::cout << "after add window:" << std::endl;
91     OutputWindowInfos(infos);
92 
93     std::cout << std::endl;
94     std::cout << "please check hidump to makesure the sub window node is on window tree" << std::endl;
95     sptr<SystemSubWindowFuture> listener = new SystemSubWindowFuture();
96     listener->future_.Reset(0);
97     listener->future_.GetResult(SystemSubWindowFuture::WAIT_TIME);
98 
99     subWindow->Hide();
100     window->Hide();
101 
102     subWindow->Destroy();
103     window->Destroy();
104 
105     infos.clear();
106     WindowManager::GetInstance().GetAccessibilityWindowInfo(infos);
107     std::cout << "after destroy window:" << std::endl;
108     OutputWindowInfos(infos);
109 
110     std::cout << "============================End============================" << std::endl;
111     return 0;
112 }