Home | History | Annotate | Download | only in hdmi
      1 /*
      2  * Copyright (C) 2014 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.hdmi;
     18 
     19 import android.annotation.SystemApi;
     20 import android.os.Parcel;
     21 import android.os.Parcelable;
     22 
     23 /**
     24  * A class that describes the HDMI port hotplug event.
     25  *
     26  * @hide
     27  */
     28 @SystemApi
     29 public final class HdmiHotplugEvent implements Parcelable {
     30 
     31     private final int mPort;
     32     private final boolean mConnected;
     33 
     34     /**
     35      * Constructor.
     36      *
     37      * <p>Marked as hidden so only system can create the instance.
     38      *
     39      * @hide
     40      */
     41     public HdmiHotplugEvent(int port, boolean connected) {
     42         mPort = port;
     43         mConnected = connected;
     44     }
     45 
     46     /**
     47      * Returns the port number for which the event occurred.
     48      *
     49      * @return port number
     50      */
     51     public int getPort() {
     52         return mPort;
     53     }
     54 
     55     /**
     56      * Returns the connection status associated with this event
     57      *
     58      * @return true if the device gets connected; otherwise false
     59      */
     60     public boolean isConnected() {
     61         return mConnected;
     62     }
     63 
     64     /**
     65      * Describes the kinds of special objects contained in this Parcelable's
     66      * marshalled representation.
     67      */
     68     @Override
     69     public int describeContents() {
     70         return 0;
     71     }
     72 
     73     /**
     74      * Flattens this object in to a Parcel.
     75      *
     76      * @param dest The Parcel in which the object should be written.
     77      * @param flags Additional flags about how the object should be written.
     78      *        May be 0 or {@link Parcelable#PARCELABLE_WRITE_RETURN_VALUE}.
     79      */
     80     @Override
     81     public void writeToParcel(Parcel dest, int flags) {
     82         dest.writeInt(mPort);
     83         dest.writeByte((byte) (mConnected ? 1 : 0));
     84     }
     85 
     86     public static final Parcelable.Creator<HdmiHotplugEvent> CREATOR
     87             = new Parcelable.Creator<HdmiHotplugEvent>() {
     88         /**
     89          * Rebuilds a {@link HdmiHotplugEvent} previously stored with
     90          * {@link Parcelable#writeToParcel(Parcel, int)}.
     91          *
     92          * @param p {@link HdmiHotplugEvent} object to read the Rating from
     93          * @return a new {@link HdmiHotplugEvent} created from the data in the parcel
     94          */
     95         @Override
     96         public HdmiHotplugEvent createFromParcel(Parcel p) {
     97             int port = p.readInt();
     98             boolean connected = p.readByte() == 1;
     99             return new HdmiHotplugEvent(port, connected);
    100         }
    101         @Override
    102         public HdmiHotplugEvent[] newArray(int size) {
    103             return new HdmiHotplugEvent[size];
    104         }
    105     };
    106 }
    107