2 * Copyright (C) 2012 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package android.telephony;
19 import android.os.Parcel;
20 import android.os.Parcelable;
21 import android.telephony.Rlog;
24 * LTE signal strength related information.
26 public final class CellSignalStrengthLte extends CellSignalStrength implements Parcelable {
28 private static final String LOG_TAG = "CellSignalStrengthLte";
29 private static final boolean DBG = false;
31 private int mSignalStrength;
36 private int mTimingAdvance;
43 public CellSignalStrengthLte() {
52 public CellSignalStrengthLte(int signalStrength, int rsrp, int rsrq, int rssnr, int cqi,
54 initialize(signalStrength, rsrp, rsrq, rssnr, cqi, timingAdvance);
60 * @param s Source SignalStrength
64 public CellSignalStrengthLte(CellSignalStrengthLte s) {
69 * Initialize all the values
71 * @param lteSignalStrength
79 public void initialize(int lteSignalStrength, int rsrp, int rsrq, int rssnr, int cqi,
81 mSignalStrength = lteSignalStrength;
86 mTimingAdvance = timingAdvance;
90 * Initialize from the SignalStrength structure.
96 public void initialize(SignalStrength ss, int timingAdvance) {
97 mSignalStrength = ss.getLteSignalStrength();
98 mRsrp = ss.getLteRsrp();
99 mRsrq = ss.getLteRsrq();
100 mRssnr = ss.getLteRssnr();
101 mCqi = ss.getLteCqi();
102 mTimingAdvance = timingAdvance;
108 protected void copyFrom(CellSignalStrengthLte s) {
109 mSignalStrength = s.mSignalStrength;
114 mTimingAdvance = s.mTimingAdvance;
121 public CellSignalStrengthLte copy() {
122 return new CellSignalStrengthLte(this);
127 public void setDefaultValues() {
128 mSignalStrength = Integer.MAX_VALUE;
129 mRsrp = Integer.MAX_VALUE;
130 mRsrq = Integer.MAX_VALUE;
131 mRssnr = Integer.MAX_VALUE;
132 mCqi = Integer.MAX_VALUE;
133 mTimingAdvance = Integer.MAX_VALUE;
137 * Get signal level as an int from 0..4
140 public int getLevel() {
144 if (mRsrp == Integer.MAX_VALUE) levelRsrp = 0;
145 else if (mRsrp >= -95) levelRsrp = SIGNAL_STRENGTH_GREAT;
146 else if (mRsrp >= -105) levelRsrp = SIGNAL_STRENGTH_GOOD;
147 else if (mRsrp >= -115) levelRsrp = SIGNAL_STRENGTH_MODERATE;
148 else levelRsrp = SIGNAL_STRENGTH_POOR;
150 // See RIL_LTE_SignalStrength in ril.h
151 if (mRssnr == Integer.MAX_VALUE) levelRssnr = 0;
152 else if (mRssnr >= 45) levelRssnr = SIGNAL_STRENGTH_GREAT;
153 else if (mRssnr >= 10) levelRssnr = SIGNAL_STRENGTH_GOOD;
154 else if (mRssnr >= -30) levelRssnr = SIGNAL_STRENGTH_MODERATE;
155 else levelRssnr = SIGNAL_STRENGTH_POOR;
158 if (mRsrp == Integer.MAX_VALUE)
160 else if (mRssnr == Integer.MAX_VALUE)
163 level = (levelRssnr < levelRsrp) ? levelRssnr : levelRsrp;
165 if (DBG) log("Lte rsrp level: " + levelRsrp
166 + " snr level: " + levelRssnr + " level: " + level);
171 * Get signal strength as dBm
174 public int getDbm() {
179 * Get the LTE signal level as an asu value between 0..97, 99 is unknown
180 * Asu is calculated based on 3GPP RSRP. Refer to 3GPP 27.007 (Ver 10.3.0) Sec 8.69
183 public int getAsuLevel() {
184 int lteAsuLevel = 99;
185 int lteDbm = getDbm();
186 if (lteDbm <= -140) lteAsuLevel = 0;
187 else if (lteDbm >= -43) lteAsuLevel = 97;
188 else lteAsuLevel = lteDbm + 140;
189 if (DBG) log("Lte Asu level: "+lteAsuLevel);
194 * Get the timing advance value for LTE.
197 public int getTimingAdvance() {
198 return mTimingAdvance;
202 public int hashCode() {
204 return (mSignalStrength * primeNum) + (mRsrp * primeNum)
205 + (mRsrq * primeNum) + (mRssnr * primeNum) + (mCqi * primeNum)
206 + (mTimingAdvance * primeNum);
210 public boolean equals (Object o) {
211 CellSignalStrengthLte s;
214 s = (CellSignalStrengthLte) o;
215 } catch (ClassCastException ex) {
223 return mSignalStrength == s.mSignalStrength
226 && mRssnr == s.mRssnr
228 && mTimingAdvance == s.mTimingAdvance;
232 * @return string representation.
235 public String toString() {
236 return "CellSignalStrengthLte:"
237 + " ss=" + mSignalStrength
242 + " ta=" + mTimingAdvance;
245 /** Implement the Parcelable interface */
247 public void writeToParcel(Parcel dest, int flags) {
248 if (DBG) log("writeToParcel(Parcel, int): " + toString());
249 dest.writeInt(mSignalStrength);
250 // Need to multiply rsrp and rsrq by -1
251 // to ensure consistency when reading values written here
252 dest.writeInt(mRsrp * -1);
253 dest.writeInt(mRsrq * -1);
254 dest.writeInt(mRssnr);
256 dest.writeInt(mTimingAdvance);
260 * Construct a SignalStrength object from the given parcel
261 * where the token is already been processed.
263 private CellSignalStrengthLte(Parcel in) {
264 mSignalStrength = in.readInt();
265 // rsrp and rsrq are written into the parcel as positive values.
266 // Need to convert into negative values
267 mRsrp = in.readInt() * -1;
268 mRsrq = in.readInt() * -1;
269 mRssnr = in.readInt();
271 mTimingAdvance = in.readInt();
272 if (DBG) log("CellSignalStrengthLte(Parcel): " + toString());
275 /** Implement the Parcelable interface */
277 public int describeContents() {
281 /** Implement the Parcelable interface */
282 @SuppressWarnings("hiding")
283 public static final Parcelable.Creator<CellSignalStrengthLte> CREATOR =
284 new Parcelable.Creator<CellSignalStrengthLte>() {
286 public CellSignalStrengthLte createFromParcel(Parcel in) {
287 return new CellSignalStrengthLte(in);
291 public CellSignalStrengthLte[] newArray(int size) {
292 return new CellSignalStrengthLte[size];
299 private static void log(String s) {