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