diff options
| author | 2021-08-11 02:21:10 +0000 | |
|---|---|---|
| committer | 2021-08-11 02:21:10 +0000 | |
| commit | 16ddb33a0497191592ef8f03e6a5a497c284c858 (patch) | |
| tree | 01550172d6184f04410b6cae28de2e975f87f04d /location/java/android | |
| parent | 13f71d796f6c1cbf1289e56ff3d4f065de632013 (diff) | |
| parent | eed95743b1e2b8ca434cba56a16f3ab67a9aadf2 (diff) | |
Merge "Fix Location equals()" into sc-dev am: b42181c3be am: eed95743b1
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/15519010
Change-Id: Ia246af3a63cfa3726f0ab13b1f0c00b56ac08386
Diffstat (limited to 'location/java/android')
| -rw-r--r-- | location/java/android/location/Location.java | 18 |
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 |