Home | History | Annotate | Download | only in input
      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 java.util.Objects;
     20 
     21 import android.os.Parcel;
     22 import android.os.Parcelable;
     23 import android.text.TextUtils;
     24 
     25 /**
     26  * Wrapper for passing identifying information for input devices.
     27  *
     28  * @hide
     29  */
     30 public final class InputDeviceIdentifier implements Parcelable {
     31     private final String mDescriptor;
     32     private final int mVendorId;
     33     private final int mProductId;
     34 
     35     public InputDeviceIdentifier(String descriptor, int vendorId, int productId) {
     36         this.mDescriptor = descriptor;
     37         this.mVendorId = vendorId;
     38         this.mProductId = productId;
     39     }
     40 
     41     private InputDeviceIdentifier(Parcel src) {
     42         mDescriptor = src.readString();
     43         mVendorId = src.readInt();
     44         mProductId = src.readInt();
     45     }
     46 
     47     @Override
     48     public int describeContents() {
     49         return 0;
     50     }
     51 
     52     @Override
     53     public void writeToParcel(Parcel dest, int flags) {
     54         dest.writeString(mDescriptor);
     55         dest.writeInt(mVendorId);
     56         dest.writeInt(mProductId);
     57     }
     58 
     59     public String getDescriptor() {
     60         return mDescriptor;
     61     }
     62 
     63     public int getVendorId() {
     64         return mVendorId;
     65     }
     66 
     67     public int getProductId() {
     68         return mProductId;
     69     }
     70 
     71     @Override
     72     public boolean equals(Object o) {
     73         if (this == o) return true;
     74         if (o == null || !(o instanceof InputDeviceIdentifier)) return false;
     75 
     76         final InputDeviceIdentifier that = (InputDeviceIdentifier) o;
     77         return ((mVendorId == that.mVendorId) && (mProductId == that.mProductId)
     78                 && TextUtils.equals(mDescriptor, that.mDescriptor));
     79     }
     80 
     81     @Override
     82     public int hashCode() {
     83         return Objects.hash(mDescriptor, mVendorId, mProductId);
     84     }
     85 
     86     public static final Parcelable.Creator<InputDeviceIdentifier> CREATOR =
     87             new Parcelable.Creator<InputDeviceIdentifier>() {
     88 
     89         @Override
     90         public InputDeviceIdentifier createFromParcel(Parcel source) {
     91             return new InputDeviceIdentifier(source);
     92         }
     93 
     94         @Override
     95         public InputDeviceIdentifier[] newArray(int size) {
     96             return new InputDeviceIdentifier[size];
     97         }
     98 
     99     };
    100 }
    101