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
This commit is contained in:
@@ -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<InputDeviceIdentifier> CREATOR =
|
||||
new Parcelable.Creator<InputDeviceIdentifier>() {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user