summaryrefslogtreecommitdiffstats
path: root/telephony/java/android/telephony/CellInfo.java
diff options
context:
space:
mode:
Diffstat (limited to 'telephony/java/android/telephony/CellInfo.java')
-rw-r--r--telephony/java/android/telephony/CellInfo.java253
1 files changed, 117 insertions, 136 deletions
diff --git a/telephony/java/android/telephony/CellInfo.java b/telephony/java/android/telephony/CellInfo.java
index 9bea30c..1946b5d 100644
--- a/telephony/java/android/telephony/CellInfo.java
+++ b/telephony/java/android/telephony/CellInfo.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2008 The Android Open Source Project
+ * Copyright (C) 2012 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,194 +20,175 @@ import android.os.Parcel;
import android.os.Parcelable;
/**
- * Represent one snapshot observation of one cell info
- * which contains the time of observation.
- *
- * @hide Pending API review
+ * Immutable cell information from a point in time.
*/
-public final class CellInfo implements Parcelable {
- // Type to distinguish where time stamp gets recorded.
- public static final int CELL_INFO_TIMESTAMP_TYPE_UNKNOWN = 0;
- public static final int CELL_INFO_TIMESTAMP_TYPE_ANTENNA = 1;
- public static final int CELL_INFO_TIMESTAMP_TYPE_MODEM = 2;
- public static final int CELL_INFO_TIMESTAMP_TYPE_OEM_RIL = 3;
- public static final int CELL_INFO_TIMESTAMP_TYPE_JAVA_RIL = 4;
-
- // Observation time stamped as type in nanoseconds since boot
- private final long mTimeStamp;
- // Where time stamp gets recorded.
- // Value of CELL_INFO_TIMESTAMP_TYPE_XXXX
- private final int mTimeStampType;
+public class CellInfo implements Parcelable {
- private final boolean mRegistered;
+ // Type fields for parceling
+ /** @hide */
+ protected static final int TYPE_GSM = 1;
+ /** @hide */
+ protected static final int TYPE_CDMA = 2;
+ /** @hide */
+ protected static final int TYPE_LTE = 3;
- private final SignalStrength mStrength;
- private final long mTimingAdvance;
-
- private final int mCellIdentityType;
- private final CellIdentity mCellIdentity;
+ // Type to distinguish where time stamp gets recorded.
- /**
- * Public constructor
- * @param timeStampType is one of CELL_INFO_TIMESTAMP_TYPE_XXXX
- * @param timeStamp is observation time in nanoseconds since boot
- * @param timingAdv is observed timing advance
- * @param registered is true when register to this cellIdentity
- * @param strength is observed signal strength
- * @param cellIdentity is observed mobile cell
- */
- public CellInfo(int timeStampType, long timeStamp, long timingAdv,
- boolean registered, SignalStrength strength,
- CellIdentity cellIdentity) {
+ /** @hide */
+ public static final int TIMESTAMP_TYPE_UNKNOWN = 0;
+ /** @hide */
+ public static final int TIMESTAMP_TYPE_ANTENNA = 1;
+ /** @hide */
+ public static final int TIMESTAMP_TYPE_MODEM = 2;
+ /** @hide */
+ public static final int TIMESTAMP_TYPE_OEM_RIL = 3;
+ /** @hide */
+ public static final int TIMESTAMP_TYPE_JAVA_RIL = 4;
- if (timeStampType < CELL_INFO_TIMESTAMP_TYPE_UNKNOWN ||
- timeStampType > CELL_INFO_TIMESTAMP_TYPE_JAVA_RIL) {
- mTimeStampType = CELL_INFO_TIMESTAMP_TYPE_UNKNOWN;
- } else {
- mTimeStampType = timeStampType;
- }
+ // True if device is mRegistered to the mobile network
+ private boolean mRegistered;
- mRegistered = registered;
- mTimeStamp = timeStamp;
- mTimingAdvance = timingAdv;
- mStrength = new SignalStrength(strength);
+ // Observation time stamped as type in nanoseconds since boot
+ private long mTimeStamp;
- mCellIdentityType = cellIdentity.getCellIdType();
- // TODO: make defense copy
- mCellIdentity = cellIdentity;
+ // Where time stamp gets recorded.
+ // Value of TIMESTAMP_TYPE_XXXX
+ private int mTimeStampType;
+
+ /** @hide */
+ protected CellInfo() {
+ this.mRegistered = false;
+ this.mTimeStampType = TIMESTAMP_TYPE_UNKNOWN;
+ this.mTimeStamp = Long.MAX_VALUE;
}
- public CellInfo(CellInfo ci) {
- this.mTimeStampType = ci.mTimeStampType;
+ /** @hide */
+ protected CellInfo(CellInfo ci) {
this.mRegistered = ci.mRegistered;
+ this.mTimeStampType = ci.mTimeStampType;
this.mTimeStamp = ci.mTimeStamp;
- this.mTimingAdvance = ci.mTimingAdvance;
- this.mCellIdentityType = ci.mCellIdentityType;
- this.mStrength = new SignalStrength(ci.mStrength);
- switch(mCellIdentityType) {
- case CellIdentity.CELLID_TYPE_GSM:
- mCellIdentity = new GsmCellIdentity((GsmCellIdentity)ci.mCellIdentity);
- break;
- default:
- mCellIdentity = null;
- }
}
- private CellInfo(Parcel in) {
- mTimeStampType = in.readInt();
- mRegistered = (in.readInt() == 1) ? true : false;
- mTimeStamp = in.readLong();
- mTimingAdvance = in.readLong();
- mCellIdentityType = in.readInt();
- mStrength = SignalStrength.CREATOR.createFromParcel(in);
- switch(mCellIdentityType) {
- case CellIdentity.CELLID_TYPE_GSM:
- mCellIdentity = GsmCellIdentity.CREATOR.createFromParcel(in);
- break;
- default:
- mCellIdentity = null;
- }
+ /** True if this cell is registered to the mobile network */
+ public boolean isRegistered() {
+ return mRegistered;
+ }
+ /** @hide */
+ public void setRegisterd(boolean registered) {
+ mRegistered = registered;
}
- /**
- * @return the observation time in nanoseconds since boot
- */
+ /** Approximate time of this cell information in nanos since boot */
public long getTimeStamp() {
return mTimeStamp;
}
+ /** @hide */
+ public void setTimeStamp(long timeStamp) {
+ mTimeStamp = timeStamp;
+ }
/**
- * @return Where time stamp gets recorded.
- * one of CELL_INFO_TIMESTAMP_TYPE_XXXX
+ * Where time stamp gets recorded.
+ * @return one of TIMESTAMP_TYPE_XXXX
+ *
+ * @hide
*/
public int getTimeStampType() {
return mTimeStampType;
}
-
- /**
- * @return true when register to this cellIdentity
- */
- public boolean isRegistered() {
- return mRegistered;
- }
-
- /**
- * @return observed timing advance
- */
- public long getTimingAdvance() {
- return mTimingAdvance;
- }
-
- /**
- * @return observed signal strength
- */
- public SignalStrength getSignalStrength() {
- // make a defense copy
- return new SignalStrength(mStrength);
+ /** @hide */
+ public void setTimeStampType(int timeStampType) {
+ if (timeStampType < TIMESTAMP_TYPE_UNKNOWN || timeStampType > TIMESTAMP_TYPE_JAVA_RIL) {
+ mTimeStampType = TIMESTAMP_TYPE_UNKNOWN;
+ } else {
+ mTimeStampType = timeStampType;
+ }
}
- /**
- * @return observed cell identity
- */
- public CellIdentity getCellIdentity() {
- // TODO: make a defense copy
- return mCellIdentity;
+ @Override
+ public int hashCode() {
+ int primeNum = 31;
+ return ((mRegistered ? 0 : 1) * primeNum) + ((int)(mTimeStamp / 1000) * primeNum)
+ + (mTimeStampType * primeNum);
}
@Override
- public String toString() {
- StringBuffer sb = new StringBuffer();
+ 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;
+ } catch (ClassCastException e) {
+ return false;
+ }
+ }
- sb.append("TimeStampType: ");
- switch(mTimeStampType) {
+ private static String timeStampTypeToString(int type) {
+ switch (type) {
case 1:
- sb.append("antenna");
- break;
+ return "antenna";
case 2:
- sb.append("modem");
- break;
+ return "modem";
case 3:
- sb.append("oem_ril");
- break;
+ return "oem_ril";
case 4:
- sb.append("java_ril");
- break;
+ return "java_ril";
default:
- sb.append("unknown");
+ return "unknown";
}
- sb.append(", TimeStamp: ").append(mTimeStamp).append(" ns");
- sb.append(", Registered: ").append(mRegistered ? "YES" : "NO");
- sb.append(", TimingAdvance: ").append(mTimingAdvance);
- sb.append(", Strength : " + mStrength);
- sb.append(", Cell Iden: " + mCellIdentity);
+ }
+
+ @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");
return sb.toString();
}
- /** Implement the Parcelable interface {@hide} */
+ /** Implement the Parcelable interface */
@Override
public int describeContents() {
return 0;
}
- /** Implement the Parcelable interface {@hide} */
+ /** Implement the Parcelable interface */
@Override
public void writeToParcel(Parcel dest, int flags) {
- dest.writeInt(mTimeStampType);
dest.writeInt(mRegistered ? 1 : 0);
+ dest.writeInt(mTimeStampType);
dest.writeLong(mTimeStamp);
- dest.writeLong(mTimingAdvance);
- dest.writeInt(mCellIdentityType);
- mStrength.writeToParcel(dest, flags);
- mCellIdentity.writeToParcel(dest, flags);
}
- /** Implement the Parcelable interface {@hide} */
- public static final Creator<CellInfo> CREATOR =
- new Creator<CellInfo>() {
+ /** @hide */
+ protected CellInfo(Parcel in) {
+ mRegistered = (in.readInt() == 1) ? true : false;
+ mTimeStampType = in.readInt();
+ mTimeStamp = in.readLong();
+ }
+
+ /** Implement the Parcelable interface */
+ public static final Creator<CellInfo> CREATOR = new Creator<CellInfo>() {
@Override
public CellInfo createFromParcel(Parcel in) {
- return new CellInfo(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);
+ default: throw new RuntimeException("Bad CellInfo Parcel");
+ }
}
@Override