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