From 07ff292dcd1611a503b1a2fbe01920eebd712451 Mon Sep 17 00:00:00 2001 From: Keisuke Kuroyanagi Date: Sun, 17 Apr 2016 21:43:56 +0900 Subject: [PATCH] Define equals and hashCode for InputDeviceIdentifier. This CL fixes that physical keyboard layout is not changed when user changes it in settings. This happened because we compare InputDeviceIdentifier instances by using Object#equals to choose specified input device. However, one of them has been serialized and deserialized, so it never be true. Bug: 27747115 Change-Id: Ied84c510ccb8e2de919ba8bb326e0355a065e604 --- .../hardware/input/InputDeviceIdentifier.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/core/java/android/hardware/input/InputDeviceIdentifier.java b/core/java/android/hardware/input/InputDeviceIdentifier.java index 5e832e38eb1a8..801da8815e9c5 100644 --- a/core/java/android/hardware/input/InputDeviceIdentifier.java +++ b/core/java/android/hardware/input/InputDeviceIdentifier.java @@ -16,8 +16,11 @@ package android.hardware.input; +import java.util.Objects; + import android.os.Parcel; import android.os.Parcelable; +import android.text.TextUtils; /** * Wrapper for passing identifying information for input devices. @@ -65,6 +68,21 @@ public final class InputDeviceIdentifier implements Parcelable { return mProductId; } + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || !(o instanceof InputDeviceIdentifier)) return false; + + final InputDeviceIdentifier that = (InputDeviceIdentifier) o; + return ((mVendorId == that.mVendorId) && (mProductId == that.mProductId) + && TextUtils.equals(mDescriptor, that.mDescriptor)); + } + + @Override + public int hashCode() { + return Objects.hash(mDescriptor, mVendorId, mProductId); + } + public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {