summaryrefslogtreecommitdiff
path: root/location
diff options
context:
space:
mode:
authorSoonil Nagarkar <sooniln@google.com>2021-08-10 12:18:30 -0700
committerSoonil Nagarkar <sooniln@google.com>2021-08-10 14:25:39 -0700
commit271b907bab302ddc480a08551201b28b3a86e443 (patch)
tree69f4c61a10c25a0b85cf0548d1578beef9d85a26 /location
parentbc0c531069095115f5f9db7ebe3408f413641925 (diff)
Fix Location equals()
Should handle extras in a better manner. Bug: 196075248 Test: presubmits + manual Change-Id: I89e45c289b26ea97486c5a72feb0a805c8c1a950
Diffstat (limited to 'location')
-rw-r--r--location/java/android/location/Location.java18
1 files changed, 17 insertions, 1 deletions
diff --git a/location/java/android/location/Location.java b/location/java/android/location/Location.java
index 1e8b9521e41e..209903c57d90 100644
--- a/location/java/android/location/Location.java
+++ b/location/java/android/location/Location.java
@@ -1084,6 +1084,12 @@ public class Location implements Parcelable {
mExtras = (extras == null) ? null : new Bundle(extras);
}
+ /**
+ * Location equality is provided primarily for test purposes. Comparing locations for equality
+ * in production may indicate incorrect assumptions, and should be avoided whenever possible.
+ *
+ * <p>{@inheritDoc}
+ */
@Override
public boolean equals(Object o) {
if (this == o) {
@@ -1121,7 +1127,17 @@ public class Location implements Parcelable {
&& (!hasBearingAccuracy() || Float.compare(location.mBearingAccuracyDegrees,
mBearingAccuracyDegrees) == 0)
&& Objects.equals(mProvider, location.mProvider)
- && Objects.equals(mExtras, location.mExtras);
+ && areExtrasEqual(mExtras, location.mExtras);
+ }
+
+ private static boolean areExtrasEqual(@Nullable Bundle extras1, @Nullable Bundle extras2) {
+ if ((extras1 == null || extras1.isEmpty()) && (extras2 == null || extras2.isEmpty())) {
+ return true;
+ } else if (extras1 == null || extras2 == null) {
+ return false;
+ } else {
+ return extras1.kindofEquals(extras2);
+ }
}
@Override