package android.telephony;
import android.annotation.IntDef;
import android.os.Parcel;
import android.os.Parcelable;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
public abstract class CellInfo implements Parcelable {
protected static final int TYPE_GSM = 1;
protected static final int TYPE_CDMA = 2;
protected static final int TYPE_LTE = 3;
protected static final int TYPE_WCDMA = 4;
public static final int TIMESTAMP_TYPE_UNKNOWN = 0;
public static final int TIMESTAMP_TYPE_ANTENNA = 1;
public static final int TIMESTAMP_TYPE_MODEM = 2;
public static final int TIMESTAMP_TYPE_OEM_RIL = 3;
public static final int TIMESTAMP_TYPE_JAVA_RIL = 4;
@Retention(RetentionPolicy.SOURCE)
@IntDef({
CONNECTION_NONE,
CONNECTION_PRIMARY_SERVING,
CONNECTION_SECONDARY_SERVING,
CONNECTION_UNKNOWN
})
public @interface CellConnectionStatus {}
public static final int CONNECTION_NONE = 0;
public static final int CONNECTION_PRIMARY_SERVING = 1;
public static final int CONNECTION_SECONDARY_SERVING = 2;
public static final int CONNECTION_UNKNOWN = Integer.MAX_VALUE;
private int mCellConnectionStatus = CONNECTION_NONE;
private boolean mRegistered;
private long mTimeStamp;
private int mTimeStampType;
protected CellInfo() {
this.mRegistered = false;
this.mTimeStampType = TIMESTAMP_TYPE_UNKNOWN;
this.mTimeStamp = Long.MAX_VALUE;
}
protected CellInfo(CellInfo ci) {
this.mRegistered = ci.mRegistered;
this.mTimeStampType = ci.mTimeStampType;
this.mTimeStamp = ci.mTimeStamp;
this.mCellConnectionStatus = ci.mCellConnectionStatus;
}
public boolean isRegistered() {
return mRegistered;
}
public void setRegistered(boolean registered) {
mRegistered = registered;
}
public long getTimeStamp() {
return mTimeStamp;
}
public void setTimeStamp(long timeStamp) {
mTimeStamp = timeStamp;
}
@CellConnectionStatus
public int getCellConnectionStatus() {
return mCellConnectionStatus;
}
public void setCellConnectionStatus(@CellConnectionStatus int cellConnectionStatus) {
mCellConnectionStatus = cellConnectionStatus;
}
public int getTimeStampType() {
return mTimeStampType;
}
public void setTimeStampType(int timeStampType) {
if (timeStampType < TIMESTAMP_TYPE_UNKNOWN || timeStampType > TIMESTAMP_TYPE_JAVA_RIL) {
mTimeStampType = TIMESTAMP_TYPE_UNKNOWN;
} else {
mTimeStampType = timeStampType;
}
}
@Override
public int hashCode() {
int primeNum = 31;
return ((mRegistered ? 0 : 1) * primeNum) + ((int)(mTimeStamp / 1000) * primeNum)
+ (mTimeStampType * primeNum) + (mCellConnectionStatus * primeNum);
}
@Override
public boolean equals(Object other) {
if (other == null) {
return false;
}
if (this == other) {
return true;
}
try {
CellInfo o = (CellInfo) other;
return mRegistered == o.mRegistered
&& mTimeStamp == o.mTimeStamp
&& mTimeStampType == o.mTimeStampType
&& mCellConnectionStatus == o.mCellConnectionStatus;
} catch (ClassCastException e) {
return false;
}
}
private static String timeStampTypeToString(int type) {
switch (type) {
case 1:
return "antenna";
case 2:
return "modem";
case 3:
return "oem_ril";
case 4:
return "java_ril";
default:
return "unknown";
}
}
@Override
public String toString() {
StringBuffer sb = new StringBuffer();
String timeStampType;
sb.append("mRegistered=").append(mRegistered ? "YES" : "NO");
timeStampType = timeStampTypeToString(mTimeStampType);
sb.append(" mTimeStampType=").append(timeStampType);
sb.append(" mTimeStamp=").append(mTimeStamp).append("ns");
sb.append(" mCellConnectionStatus=").append(mCellConnectionStatus);
return sb.toString();
}
@Override
public int describeContents() {
return 0;
}
@Override
public abstract void writeToParcel(Parcel dest, int flags);
protected void writeToParcel(Parcel dest, int flags, int type) {
dest.writeInt(type);
dest.writeInt(mRegistered ? 1 : 0);
dest.writeInt(mTimeStampType);
dest.writeLong(mTimeStamp);
dest.writeInt(mCellConnectionStatus);
}
protected CellInfo(Parcel in) {
mRegistered = (in.readInt() == 1) ? true : false;
mTimeStampType = in.readInt();
mTimeStamp = in.readLong();
mCellConnectionStatus = in.readInt();
}
public static final Creator<CellInfo> CREATOR = new Creator<CellInfo>() {
@Override
public CellInfo createFromParcel(Parcel in) {
int type = in.readInt();
switch (type) {
case TYPE_GSM: return CellInfoGsm.createFromParcelBody(in);
case TYPE_CDMA: return CellInfoCdma.createFromParcelBody(in);
case TYPE_LTE: return CellInfoLte.createFromParcelBody(in);
case TYPE_WCDMA: return CellInfoWcdma.createFromParcelBody(in);
default: throw new RuntimeException("Bad CellInfo Parcel");
}
}
@Override
public CellInfo[] newArray(int size) {
return new CellInfo[size];
}
};
}