Home | History | Annotate | Download | only in telephony
      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.telephony;
     18 
     19 import android.os.Parcel;
     20 import android.os.Parcelable;
     21 
     22 /**
     23  * Data connection real time information
     24  *
     25  * TODO: How to handle multiple subscriptions?
     26  * @hide
     27  */
     28 public class DataConnectionRealTimeInfo implements Parcelable {
     29     private long mTime;             // Time the info was collected since boot in nanos;
     30 
     31     public static final int DC_POWER_STATE_LOW
     32             = TelephonyProtoEnums.DATA_CONNECTION_POWER_STATE_LOW ; // = 1
     33     public static final int DC_POWER_STATE_MEDIUM
     34             = TelephonyProtoEnums.DATA_CONNECTION_POWER_STATE_MEDIUM; // = 2
     35     public static final int DC_POWER_STATE_HIGH
     36             = TelephonyProtoEnums.DATA_CONNECTION_POWER_STATE_HIGH; // = 3
     37     public static final int DC_POWER_STATE_UNKNOWN
     38             = TelephonyProtoEnums.DATA_CONNECTION_POWER_STATE_UNKNOWN; // = Integer.MAX_VALUE
     39 
     40     private int mDcPowerState;      // DC_POWER_STATE_[LOW | MEDIUM | HIGH | UNKNOWN]
     41 
     42     /**
     43      * Constructor
     44      *
     45      * @hide
     46      */
     47     public DataConnectionRealTimeInfo(long time, int dcPowerState) {
     48         mTime = time;
     49         mDcPowerState = dcPowerState;
     50     }
     51 
     52     /**
     53      * Constructor
     54      *
     55      * @hide
     56      */
     57     public DataConnectionRealTimeInfo() {
     58         mTime = Long.MAX_VALUE;
     59         mDcPowerState = DC_POWER_STATE_UNKNOWN;
     60     }
     61 
     62     /**
     63      * Construct a PreciseCallState object from the given parcel.
     64      */
     65     private DataConnectionRealTimeInfo(Parcel in) {
     66         mTime = in.readLong();
     67         mDcPowerState = in.readInt();
     68     }
     69 
     70     /**
     71      * @return time the information was collected or Long.MAX_VALUE if unknown
     72      */
     73     public long getTime() {
     74         return mTime;
     75     }
     76 
     77     /**
     78      * @return DC_POWER_STATE_[LOW | MEDIUM | HIGH | UNKNOWN]
     79      */
     80     public int getDcPowerState() {
     81         return mDcPowerState;
     82     }
     83 
     84     @Override
     85     public int describeContents() {
     86         return 0;
     87     }
     88 
     89     @Override
     90     public void writeToParcel(Parcel out, int flags) {
     91         out.writeLong(mTime);
     92         out.writeInt(mDcPowerState);
     93     }
     94 
     95     public static final Parcelable.Creator<DataConnectionRealTimeInfo> CREATOR
     96             = new Parcelable.Creator<DataConnectionRealTimeInfo>() {
     97 
     98         @Override
     99         public DataConnectionRealTimeInfo createFromParcel(Parcel in) {
    100             return new DataConnectionRealTimeInfo(in);
    101         }
    102 
    103         @Override
    104         public DataConnectionRealTimeInfo[] newArray(int size) {
    105             return new DataConnectionRealTimeInfo[size];
    106         }
    107     };
    108 
    109     @Override
    110     public int hashCode() {
    111         final long prime = 17;
    112         long result = 1;
    113         result = (prime * result) + mTime;
    114         result += (prime * result) + mDcPowerState;
    115         return (int)result;
    116     }
    117 
    118     @Override
    119     public boolean equals(Object obj) {
    120         if (this == obj) {
    121             return true;
    122         }
    123         if (obj == null) {
    124             return false;
    125         }
    126         if (getClass() != obj.getClass()) {
    127             return false;
    128         }
    129         DataConnectionRealTimeInfo other = (DataConnectionRealTimeInfo) obj;
    130         return (mTime == other.mTime)
    131                 && (mDcPowerState == other.mDcPowerState);
    132     }
    133 
    134     @Override
    135     public String toString() {
    136         StringBuffer sb = new StringBuffer();
    137 
    138         sb.append("mTime=").append(mTime);
    139         sb.append(" mDcPowerState=").append(mDcPowerState);
    140 
    141         return sb.toString();
    142     }
    143 }
    144