1 /* 2 * Copyright (C) 2013 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.hardware.input; 18 19 import android.annotation.NonNull; 20 import android.annotation.Nullable; 21 import android.annotation.TestApi; 22 import android.os.Parcel; 23 import android.os.Parcelable; 24 import android.text.TextUtils; 25 26 import java.util.Objects; 27 28 /** 29 * Wrapper for passing identifying information for input devices. 30 * 31 * @hide 32 */ 33 @TestApi 34 public final class InputDeviceIdentifier implements Parcelable { 35 private final String mDescriptor; 36 private final int mVendorId; 37 private final int mProductId; 38 InputDeviceIdentifier(@onNull String descriptor, int vendorId, int productId)39 public InputDeviceIdentifier(@NonNull String descriptor, int vendorId, int productId) { 40 this.mDescriptor = descriptor; 41 this.mVendorId = vendorId; 42 this.mProductId = productId; 43 } 44 InputDeviceIdentifier(Parcel src)45 private InputDeviceIdentifier(Parcel src) { 46 mDescriptor = src.readString(); 47 mVendorId = src.readInt(); 48 mProductId = src.readInt(); 49 } 50 51 @Override describeContents()52 public int describeContents() { 53 return 0; 54 } 55 56 @Override writeToParcel(@onNull Parcel dest, int flags)57 public void writeToParcel(@NonNull Parcel dest, int flags) { 58 dest.writeString(mDescriptor); 59 dest.writeInt(mVendorId); 60 dest.writeInt(mProductId); 61 } 62 63 @NonNull getDescriptor()64 public String getDescriptor() { 65 return mDescriptor; 66 } 67 getVendorId()68 public int getVendorId() { 69 return mVendorId; 70 } 71 getProductId()72 public int getProductId() { 73 return mProductId; 74 } 75 76 @Override equals(@ullable Object o)77 public boolean equals(@Nullable Object o) { 78 if (this == o) return true; 79 if (o == null || !(o instanceof InputDeviceIdentifier)) return false; 80 81 final InputDeviceIdentifier that = (InputDeviceIdentifier) o; 82 return ((mVendorId == that.mVendorId) && (mProductId == that.mProductId) 83 && TextUtils.equals(mDescriptor, that.mDescriptor)); 84 } 85 86 @Override hashCode()87 public int hashCode() { 88 return Objects.hash(mDescriptor, mVendorId, mProductId); 89 } 90 91 @Override toString()92 public String toString() { 93 return "InputDeviceIdentifier: vendorId: " + mVendorId + ", productId: " + mProductId 94 + ", descriptor: " + mDescriptor; 95 } 96 97 public static final @android.annotation.NonNull Parcelable.Creator<InputDeviceIdentifier> CREATOR = 98 new Parcelable.Creator<InputDeviceIdentifier>() { 99 100 @Override 101 public InputDeviceIdentifier createFromParcel(Parcel source) { 102 return new InputDeviceIdentifier(source); 103 } 104 105 @Override 106 public InputDeviceIdentifier[] newArray(int size) { 107 return new InputDeviceIdentifier[size]; 108 } 109 110 }; 111 } 112