Add test to call setInputWindows twice
Currently, I'm observing some strange behaviour, where calling
setInputWindows twice results in the touchable region becoming empty.
Add this test to R to see what's going on, and potentially bisect on
this.
Bug: 143459140
Test: atest inputflinger_tests
Change-Id: Ia0acef5d4ee4acc29d20174fe44c9f94172ccd96
diff --git a/libs/ui/Region.cpp b/libs/ui/Region.cpp
index 82ce757..e01309b 100644
--- a/libs/ui/Region.cpp
+++ b/libs/ui/Region.cpp
@@ -224,6 +224,11 @@
validate(*this, "this->operator=");
validate(rhs, "rhs.operator=");
#endif
+ if (this == &rhs) {
+ // Already equal to itself
+ return *this;
+ }
+
mStorage.clear();
mStorage.insert(mStorage.begin(), rhs.mStorage.begin(), rhs.mStorage.end());
return *this;
diff --git a/libs/ui/tests/Region_test.cpp b/libs/ui/tests/Region_test.cpp
index b104a46..c6b826d 100644
--- a/libs/ui/tests/Region_test.cpp
+++ b/libs/ui/tests/Region_test.cpp
@@ -152,5 +152,20 @@
}
}
+TEST_F(RegionTest, EqualsToSelf) {
+ Region touchableRegion;
+ touchableRegion.orSelf(Rect(0, 0, 100, 100));
+
+ ASSERT_TRUE(touchableRegion.contains(50, 50));
+
+ // Compiler prevents us from directly calling 'touchableRegion = touchableRegion'
+ Region& referenceTouchableRegion = touchableRegion;
+ touchableRegion = referenceTouchableRegion;
+
+ ASSERT_FALSE(touchableRegion.isEmpty());
+
+ ASSERT_TRUE(touchableRegion.contains(50, 50));
+}
+
}; // namespace android