summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Ats Jenk <atsjenk@google.com> 2024-10-29 18:32:45 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2024-10-29 18:32:45 +0000
commitae63222f95585a2048be91bb128558472221bfd9 (patch)
tree1479633651c5efa42d9fd303c0676feca740de75
parentc624da5f065168e46a47190b984329cbcb135133 (diff)
parente90f7753eeaff0ec6fecaaf6751826e99cceade7 (diff)
Merge "Override hashCode in AnimatableScaleMatrix" into main
-rw-r--r--libs/WindowManager/Shell/multivalentTests/src/com/android/wm/shell/bubbles/animation/AnimatableScaleMatrixTest.kt53
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/animation/AnimatableScaleMatrix.java6
2 files changed, 59 insertions, 0 deletions
diff --git a/libs/WindowManager/Shell/multivalentTests/src/com/android/wm/shell/bubbles/animation/AnimatableScaleMatrixTest.kt b/libs/WindowManager/Shell/multivalentTests/src/com/android/wm/shell/bubbles/animation/AnimatableScaleMatrixTest.kt
new file mode 100644
index 000000000000..3ed360461c25
--- /dev/null
+++ b/libs/WindowManager/Shell/multivalentTests/src/com/android/wm/shell/bubbles/animation/AnimatableScaleMatrixTest.kt
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2024 The Android Open Source Project
+ *
+ * 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.
+ */
+
+package com.android.wm.shell.bubbles.animation
+
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import androidx.test.filters.SmallTest
+import com.google.common.truth.Truth.assertThat
+import org.junit.Test
+import org.junit.runner.RunWith
+
+/** Tests for [AnimatableScaleMatrix] */
+@SmallTest
+@RunWith(AndroidJUnit4::class)
+class AnimatableScaleMatrixTest {
+
+ @Test
+ fun test_equals_matricesWithSameValuesAreNotEqual() {
+ val matrix1 = AnimatableScaleMatrix().apply { setScale(0.5f, 0.5f) }
+ val matrix2 = AnimatableScaleMatrix().apply { setScale(0.5f, 0.5f) }
+ assertThat(matrix1).isNotEqualTo(matrix2)
+ }
+
+ @Test
+ fun test_hashCode_remainsSameIfMatrixUpdates() {
+ val matrix = AnimatableScaleMatrix().apply { setScale(0.5f, 0.5f) }
+ val hash1 = matrix.hashCode()
+ matrix.setScale(0.75f, 0.75f)
+ val hash2 = matrix.hashCode()
+
+ assertThat(hash1).isEqualTo(hash2)
+ }
+
+ @Test
+ fun test_hashCode_matricesWithSameValuesHaveDiffHashCode() {
+ val matrix1 = AnimatableScaleMatrix().apply { setScale(0.5f, 0.5f) }
+ val matrix2 = AnimatableScaleMatrix().apply { setScale(0.5f, 0.5f) }
+ assertThat(matrix1.hashCode()).isNotEqualTo(matrix2.hashCode())
+ }
+}
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/animation/AnimatableScaleMatrix.java b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/animation/AnimatableScaleMatrix.java
index 2612b81aae00..e577c3e0b1b2 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/animation/AnimatableScaleMatrix.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/animation/AnimatableScaleMatrix.java
@@ -141,4 +141,10 @@ public class AnimatableScaleMatrix extends Matrix {
// PhysicsAnimator's animator caching).
return obj == this;
}
+
+ @Override
+ public int hashCode() {
+ // Make sure equals and hashCode work in a similar way. Rely on object identity for both.
+ return System.identityHashCode(this);
+ }
}