Home | History | Annotate | Download | only in property
      1 /*
      2  * Copyright (C) 2016 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.car.hardware.property;
     18 
     19 import android.car.hardware.CarPropertyValue;
     20 import android.os.Parcel;
     21 import android.os.Parcelable;
     22 
     23 /** @hide */
     24 public class CarPropertyEvent implements Parcelable {
     25     public static final int PROPERTY_EVENT_PROPERTY_CHANGE = 0;
     26     public static final int PROPERTY_EVENT_ERROR = 1;
     27 
     28     /**
     29      * EventType of this message
     30      */
     31     private final int mEventType;
     32     private final CarPropertyValue<?> mCarPropertyValue;
     33 
     34     // Getters.
     35 
     36     /**
     37      * @return EventType field
     38      */
     39     public int getEventType() { return mEventType; }
     40 
     41     /**
     42      * Returns {@link CarPropertyValue} associated with this event.
     43      */
     44     public CarPropertyValue<?> getCarPropertyValue() { return mCarPropertyValue; }
     45 
     46     @Override
     47     public int describeContents() {
     48         return 0;
     49     }
     50 
     51     @Override
     52     public void writeToParcel(Parcel dest, int flags) {
     53         dest.writeInt(mEventType);
     54         dest.writeParcelable(mCarPropertyValue, flags);
     55     }
     56 
     57     public static final Parcelable.Creator<CarPropertyEvent> CREATOR
     58             = new Parcelable.Creator<CarPropertyEvent>() {
     59         public CarPropertyEvent createFromParcel(Parcel in) {
     60             return new CarPropertyEvent(in);
     61         }
     62 
     63         public CarPropertyEvent[] newArray(int size) {
     64             return new CarPropertyEvent[size];
     65         }
     66     };
     67 
     68     /**
     69      * Constructor for {@link CarPropertyEvent}.
     70      */
     71     public CarPropertyEvent(int eventType, CarPropertyValue<?> carPropertyValue) {
     72         mEventType  = eventType;
     73         mCarPropertyValue = carPropertyValue;
     74     }
     75 
     76     private CarPropertyEvent(Parcel in) {
     77         mEventType  = in.readInt();
     78         mCarPropertyValue = in.readParcelable(CarPropertyValue.class.getClassLoader());
     79     }
     80 
     81     @Override
     82     public String toString() {
     83         return "CarPropertyEvent{" +
     84                 "mEventType=" + mEventType +
     85                 ", mCarPropertyValue=" + mCarPropertyValue +
     86                 '}';
     87     }
     88 }
     89