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