• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2018 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include <gtest/gtest.h>
18 
19 #include <binder/Binder.h>
20 #include <binder/Parcel.h>
21 
22 #include <gui/WindowInfo.h>
23 
24 using std::chrono_literals::operator""s;
25 
26 namespace android {
27 
28 using gui::InputApplicationInfo;
29 using gui::TouchOcclusionMode;
30 using gui::WindowInfo;
31 using ui::Size;
32 
33 namespace test {
34 
TEST(WindowInfo,ParcellingWithoutToken)35 TEST(WindowInfo, ParcellingWithoutToken) {
36     WindowInfo i, i2;
37     i.token = nullptr;
38 
39     Parcel p;
40     ASSERT_EQ(OK, i.writeToParcel(&p));
41     p.setDataPosition(0);
42     i2.readFromParcel(&p);
43     ASSERT_EQ(i2.token, nullptr);
44 }
45 
TEST(WindowInfo,ParcellingWithoutCloneTransform)46 TEST(WindowInfo, ParcellingWithoutCloneTransform) {
47     WindowInfo i, i2;
48     i.cloneLayerStackTransform.reset();
49 
50     Parcel p;
51     ASSERT_EQ(OK, i.writeToParcel(&p));
52     p.setDataPosition(0);
53     i2.readFromParcel(&p);
54     ASSERT_EQ(i2.cloneLayerStackTransform, std::nullopt);
55 }
56 
TEST(WindowInfo,Parcelling)57 TEST(WindowInfo, Parcelling) {
58     sp<IBinder> touchableRegionCropHandle = new BBinder();
59     WindowInfo i;
60     i.token = new BBinder();
61     i.windowToken = new BBinder();
62     i.id = 1;
63     i.name = "Foobar";
64     i.layoutParamsFlags = WindowInfo::Flag::SLIPPERY;
65     i.layoutParamsType = WindowInfo::Type::INPUT_METHOD;
66     i.dispatchingTimeout = 12s;
67     i.frame = Rect(93, 34, 16, 19);
68     i.contentSize = Size(10, 40);
69     i.surfaceInset = 17;
70     i.globalScaleFactor = 0.3;
71     i.alpha = 0.7;
72     i.transform.set({0.4, -1, 100, 0.5, 0, 40, 0, 0, 1});
73     i.touchOcclusionMode = TouchOcclusionMode::ALLOW;
74     i.ownerPid = gui::Pid{19};
75     i.ownerUid = gui::Uid{24};
76     i.packageName = "com.example.package";
77     i.inputConfig = WindowInfo::InputConfig::NOT_FOCUSABLE;
78     i.displayId = ui::LogicalDisplayId{34};
79     i.replaceTouchableRegionWithCrop = true;
80     i.touchableRegionCropHandle = touchableRegionCropHandle;
81     i.applicationInfo.name = "ApplicationFooBar";
82     i.applicationInfo.token = new BBinder();
83     i.applicationInfo.dispatchingTimeoutMillis = 0x12345678ABCD;
84     i.focusTransferTarget = new BBinder();
85     i.cloneLayerStackTransform = ui::Transform();
86     i.cloneLayerStackTransform->set({5, -1, 100, 4, 0, 40, 0, 0, 1});
87 
88     Parcel p;
89     i.writeToParcel(&p);
90     p.setDataPosition(0);
91     WindowInfo i2;
92     i2.readFromParcel(&p);
93     ASSERT_EQ(i.token, i2.token);
94     ASSERT_EQ(i.windowToken, i2.windowToken);
95     ASSERT_EQ(i.id, i2.id);
96     ASSERT_EQ(i.name, i2.name);
97     ASSERT_EQ(i.layoutParamsFlags, i2.layoutParamsFlags);
98     ASSERT_EQ(i.layoutParamsType, i2.layoutParamsType);
99     ASSERT_EQ(i.dispatchingTimeout, i2.dispatchingTimeout);
100     ASSERT_EQ(i.frame, i2.frame);
101     ASSERT_EQ(i.contentSize, i2.contentSize);
102     ASSERT_EQ(i.surfaceInset, i2.surfaceInset);
103     ASSERT_EQ(i.globalScaleFactor, i2.globalScaleFactor);
104     ASSERT_EQ(i.alpha, i2.alpha);
105     ASSERT_EQ(i.transform, i2.transform);
106     ASSERT_EQ(i.touchOcclusionMode, i2.touchOcclusionMode);
107     ASSERT_EQ(i.ownerPid, i2.ownerPid);
108     ASSERT_EQ(i.ownerUid, i2.ownerUid);
109     ASSERT_EQ(i.packageName, i2.packageName);
110     ASSERT_EQ(i.inputConfig, i2.inputConfig);
111     ASSERT_EQ(i.displayId, i2.displayId);
112     ASSERT_EQ(i.replaceTouchableRegionWithCrop, i2.replaceTouchableRegionWithCrop);
113     ASSERT_EQ(i.touchableRegionCropHandle, i2.touchableRegionCropHandle);
114     ASSERT_EQ(i.applicationInfo, i2.applicationInfo);
115     ASSERT_EQ(i.focusTransferTarget, i2.focusTransferTarget);
116     ASSERT_EQ(i.cloneLayerStackTransform, i2.cloneLayerStackTransform);
117 }
118 
TEST(InputApplicationInfo,Parcelling)119 TEST(InputApplicationInfo, Parcelling) {
120     InputApplicationInfo i;
121     i.token = new BBinder();
122     i.name = "ApplicationFooBar";
123     i.dispatchingTimeoutMillis = 0x12345678ABCD;
124 
125     Parcel p;
126     ASSERT_EQ(i.writeToParcel(&p), OK);
127     p.setDataPosition(0);
128     InputApplicationInfo i2;
129     ASSERT_EQ(i2.readFromParcel(&p), OK);
130     ASSERT_EQ(i, i2);
131 }
132 
133 } // namespace test
134 } // namespace android
135