Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f23153f1 authored by Nathan Harold's avatar Nathan Harold
Browse files

Refactor SignalStrength

Refactor SignalStrength as a container of
individual CellSignalStrength objects for each
radio technology.

-Change SignalStrength to contain CellSignalStrength
 rather than individual measurements.
-Change the constructors for SignalStrength to take
 CellSignalStrength objects.
-Consolidate all the logic for calculating the getLevel()
 function to CellSignalStrength.
-Store the level value in SignalStrengths rather than
 compute it on the fly when needed.
-Add a few missing functions needed by SignalStrength:
     -CellSignalStrengthCdma#getEvdoAsuLevel()
     -CellSignalStrengthTdscdma#getRscp()
-Convert CellSignalStrength classes to take actual values
 instead of ASU values.

Bug: 25984037
Test: atest SignalStrengthTest
Change-Id: I302e7a8c6f68559dc69a3138061eec739ee7561f
parent bcf293c6
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -2000,6 +2000,8 @@ public class CarrierConfigManager {
     * Determine whether to use only RSRP for the number of LTE signal bars.
     * @hide
     */
    // FIXME: this key and related keys must not be exposed without a consistent philosophy for
    // all RATs.
    public static final String KEY_USE_ONLY_RSRP_FOR_LTE_SIGNAL_BAR_BOOL =
            "use_only_rsrp_for_lte_signal_bar_bool";

@@ -2243,6 +2245,8 @@ public class CarrierConfigManager {
     * Currently this only supports the value "rscp"
     * @hide
     */
    // FIXME: this key and related keys must not be exposed without a consistent philosophy for
    // all RATs.
    public static final String KEY_WCDMA_DEFAULT_SIGNAL_STRENGTH_MEASUREMENT_STRING =
            "wcdma_default_signal_strength_measurement_string";

+67 −0
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package android.telephony;

import android.os.PersistableBundle;

/**
 * Abstract base class for cell phone signal strength related information.
 */
@@ -80,9 +82,74 @@ public abstract class CellSignalStrength {
     */
    public abstract CellSignalStrength copy();

    /**
     * Checks and returns whether there are any non-default values in this CellSignalStrength.
     *
     * Checks all the values in the subclass of CellSignalStrength and returns true if any of them
     * have been set to a value other than their default.
     *
     * @hide
     */
    public abstract boolean isValid();

    @Override
    public abstract int hashCode();

    @Override
    public abstract boolean equals (Object o);

    /**
     * Calculate and set the carrier-influenced values such as the signal "Level".
     *
     * @hide
     */
    public abstract void updateLevel(PersistableBundle cc, ServiceState ss);

    // Range for RSSI in ASU (0-31, 99) as defined in TS 27.007 8.69
    /** @hide */
    protected static final int getRssiDbmFromAsu(int asu) {
        if (asu > 31 || asu < 0) return CellInfo.UNAVAILABLE;
        return -113 + (2 * asu);
    }

    // Range for RSSI in ASU (0-31, 99) as defined in TS 27.007 8.69
    /** @hide */
    protected static final int getAsuFromRssiDbm(int dbm) {
        if (dbm == CellInfo.UNAVAILABLE) return 99;
        return (dbm / 2) + 113;
    }

    // Range for RSCP in ASU (0-96, 255) as defined in TS 27.007 8.69
    /** @hide */
    protected static final int getRscpDbmFromAsu(int asu) {
        if (asu > 96 || asu < 0) return CellInfo.UNAVAILABLE;
        return asu - 120;
    }

    // Range for RSCP in ASU (0-96, 255) as defined in TS 27.007 8.69
    /** @hide */
    protected static final int getAsuFromRscpDbm(int dbm) {
        if (dbm == CellInfo.UNAVAILABLE) return 255;
        return dbm + 120;
    }

    // Range for SNR in ASU (0-49, 255) as defined in TS 27.007 8.69
    /** @hide */
    protected static final int getEcNoDbFromAsu(int asu) {
        if (asu > 49 || asu < 0) return CellInfo.UNAVAILABLE;
        return -24 + (asu / 2);
    }

    /** @hide */
    protected static final int inRangeOrUnavailable(int value, int rangeMin, int rangeMax) {
        if (value < rangeMin || value > rangeMax) return CellInfo.UNAVAILABLE;
        return value;
    }

    /** @hide */
    protected static final int inRangeOrUnavailable(
            int value, int rangeMin, int rangeMax, int special) {
        if ((value < rangeMin || value > rangeMax) && value != special) return CellInfo.UNAVAILABLE;
        return value;
    }
}
+136 −32
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package android.telephony;

import android.os.Parcel;
import android.os.Parcelable;
import android.os.PersistableBundle;
import android.telephony.Rlog;

import java.util.Objects;
@@ -35,6 +36,7 @@ public final class CellSignalStrengthCdma extends CellSignalStrength implements
    private int mEvdoDbm;   // This value is the EVDO RSSI value
    private int mEvdoEcio;  // This value is the EVDO Ec/Io
    private int mEvdoSnr;   // Valid values are 0-8.  8 is the highest signal to noise ratio
    private int mLevel;

    /** @hide */
    public CellSignalStrengthCdma() {
@@ -55,23 +57,29 @@ public final class CellSignalStrengthCdma extends CellSignalStrength implements
     * rather than left as -1, which is a departure from SignalStrength, which is stuck with the
     * values it currently reports.
     *
     * @param cdmaDbm negative of the CDMA signal strength value or -1 if invalid.
     * @param cdmaEcio negative of the CDMA pilot/noise ratio or -1 if invalid.
     * @param evdoDbm negative of the EvDO signal strength value or -1 if invalid.
     * @param evdoEcio negative of the EvDO pilot/noise ratio or -1 if invalid.
     * @param evdoSnr an SNR value 0..8 or -1 if invalid.
     * @param cdmaDbm CDMA signal strength value or CellInfo.UNAVAILABLE if invalid.
     * @param cdmaEcio CDMA pilot/noise ratio or CellInfo.UNAVAILABLE  if invalid.
     * @param evdoDbm negative of the EvDO signal strength value or CellInfo.UNAVAILABLE if invalid.
     * @param evdoEcio negative of the EvDO pilot/noise ratio or CellInfo.UNAVAILABLE if invalid.
     * @param evdoSnr an SNR value 0..8 or CellInfo.UNVAILABLE if invalid.
     * @hide
     */
    public CellSignalStrengthCdma(int cdmaDbm, int cdmaEcio, int evdoDbm, int evdoEcio,
            int evdoSnr) {
        // The values here were lifted from SignalStrength.validateInput()
        // FIXME: Combine all checking and setting logic between this and SignalStrength.
        mCdmaDbm = ((cdmaDbm > 0) && (cdmaDbm < 120))  ? -cdmaDbm : CellInfo.UNAVAILABLE;
        mCdmaEcio = ((cdmaEcio > 0) && (cdmaEcio < 160)) ? -cdmaEcio : CellInfo.UNAVAILABLE;
        mCdmaDbm = inRangeOrUnavailable(cdmaDbm, -120, 0);
        mCdmaEcio = inRangeOrUnavailable(cdmaEcio, -160, 0);
        mEvdoDbm = inRangeOrUnavailable(evdoDbm, -120, 0);
        mEvdoEcio = inRangeOrUnavailable(evdoEcio, -160, 0);
        mEvdoSnr = inRangeOrUnavailable(evdoSnr, 0, 8);

        mEvdoDbm = ((evdoDbm > 0) && (evdoDbm < 120)) ? -evdoDbm : CellInfo.UNAVAILABLE;
        mEvdoEcio = ((evdoEcio > 0) && (evdoEcio < 160)) ? -evdoEcio : CellInfo.UNAVAILABLE;
        mEvdoSnr = ((evdoSnr > 0) && (evdoSnr <= 8)) ? evdoSnr : CellInfo.UNAVAILABLE;
        updateLevel(null, null);
    }

    /** @hide */
    public CellSignalStrengthCdma(android.hardware.radio.V1_0.CdmaSignalStrength cdma,
            android.hardware.radio.V1_0.EvdoSignalStrength evdo) {
        // Convert from HAL values as part of construction.
        this(-cdma.dbm, -cdma.ecio, -evdo.dbm, -evdo.ecio, evdo.signalNoiseRatio);
    }

    /** @hide */
@@ -86,6 +94,7 @@ public final class CellSignalStrengthCdma extends CellSignalStrength implements
        mEvdoDbm = s.mEvdoDbm;
        mEvdoEcio = s.mEvdoEcio;
        mEvdoSnr = s.mEvdoSnr;
        mLevel = s.mLevel;
    }

    /** @hide */
@@ -102,6 +111,7 @@ public final class CellSignalStrengthCdma extends CellSignalStrength implements
        mEvdoDbm = CellInfo.UNAVAILABLE;
        mEvdoEcio = CellInfo.UNAVAILABLE;
        mEvdoSnr = CellInfo.UNAVAILABLE;
        mLevel = SIGNAL_STRENGTH_NONE_OR_UNKNOWN;
    }

    /**
@@ -112,26 +122,54 @@ public final class CellSignalStrengthCdma extends CellSignalStrength implements
     */
    @Override
    public int getLevel() {
        int level;
        return mLevel;
    }

    /** @hide */
    @Override
    public void updateLevel(PersistableBundle cc, ServiceState ss) {
        int cdmaLevel = getCdmaLevel();
        int evdoLevel = getEvdoLevel();
        if (evdoLevel == SIGNAL_STRENGTH_NONE_OR_UNKNOWN) {
            /* We don't know evdo, use cdma */
            level = getCdmaLevel();
            mLevel = getCdmaLevel();
        } else if (cdmaLevel == SIGNAL_STRENGTH_NONE_OR_UNKNOWN) {
            /* We don't know cdma, use evdo */
            level = getEvdoLevel();
            mLevel = getEvdoLevel();
        } else {
            /* We know both, use the lowest level */
            level = cdmaLevel < evdoLevel ? cdmaLevel : evdoLevel;
            mLevel = cdmaLevel < evdoLevel ? cdmaLevel : evdoLevel;
        }
        if (DBG) log("getLevel=" + level);
        return level;
    }

    /**
     * Get the signal level as an asu value between 0..97, 99 is unknown
     * Get the 1xRTT Level in (Android) ASU.
     *
     * There is no standard definition of ASU for CDMA; however, Android defines it as the
     * the lesser of the following two results (for 1xRTT):
     * <table>
     *     <thead><tr><th>RSSI Range (dBm)</th><th>ASU Value</th></tr><thead>
     *     <tbody>
     *         <tr><td>-75..</td><td>16</td></tr>
     *         <tr><td>-82..-76</td><td>8</td></tr>
     *         <tr><td>-90..-83</td><td>4</td></tr>
     *         <tr><td>-95..-91</td><td>2</td></tr>
     *         <tr><td>-100..-96</td><td>1</td></tr>
     *         <tr><td>..-101</td><td>99</td></tr>
     *     </tbody>
     * </table>
     * <table>
     *     <thead><tr><th>Ec/Io Range (dB)</th><th>ASU Value</th></tr><thead>
     *     <tbody>
     *         <tr><td>-90..</td><td>16</td></tr>
     *         <tr><td>-100..-91</td><td>8</td></tr>
     *         <tr><td>-115..-101</td><td>4</td></tr>
     *         <tr><td>-130..-116</td><td>2</td></tr>
     *         <tr><td>--150..-131</td><td>1</td></tr>
     *         <tr><td>..-151</td><td>99</td></tr>
     *     </tbody>
     * </table>
     * @return 1xRTT Level in Android ASU {1,2,4,8,16,99}
     */
    @Override
    public int getAsuLevel() {
@@ -219,6 +257,63 @@ public final class CellSignalStrengthCdma extends CellSignalStrength implements
        return level;
    }

    /**
     * Get the EVDO Level in (Android) ASU.
     *
     * There is no standard definition of ASU for CDMA; however, Android defines it as the
     * the lesser of the following two results (for EVDO):
     * <table>
     *     <thead><tr><th>RSSI Range (dBm)</th><th>ASU Value</th></tr><thead>
     *     <tbody>
     *         <tr><td>-65..</td><td>16</td></tr>
     *         <tr><td>-75..-66</td><td>8</td></tr>
     *         <tr><td>-85..-76</td><td>4</td></tr>
     *         <tr><td>-95..-86</td><td>2</td></tr>
     *         <tr><td>-105..-96</td><td>1</td></tr>
     *         <tr><td>..-106</td><td>99</td></tr>
     *     </tbody>
     * </table>
     * <table>
     *     <thead><tr><th>SNR Range (unitless)</th><th>ASU Value</th></tr><thead>
     *     <tbody>
     *         <tr><td>7..</td><td>16</td></tr>
     *         <tr><td>6</td><td>8</td></tr>
     *         <tr><td>5</td><td>4</td></tr>
     *         <tr><td>3..4</td><td>2</td></tr>
     *         <tr><td>1..2</td><td>1</td></tr>
     *         <tr><td>0</td><td>99</td></tr>
     *     </tbody>
     * </table>
     *
     * @return EVDO Level in Android ASU {1,2,4,8,16,99}
     *
     * @hide
     */
    public int getEvdoAsuLevel() {
        int evdoDbm = getEvdoDbm();
        int evdoSnr = getEvdoSnr();
        int levelEvdoDbm;
        int levelEvdoSnr;

        if (evdoDbm >= -65) levelEvdoDbm = 16;
        else if (evdoDbm >= -75) levelEvdoDbm = 8;
        else if (evdoDbm >= -85) levelEvdoDbm = 4;
        else if (evdoDbm >= -95) levelEvdoDbm = 2;
        else if (evdoDbm >= -105) levelEvdoDbm = 1;
        else levelEvdoDbm = 99;

        if (evdoSnr >= 7) levelEvdoSnr = 16;
        else if (evdoSnr >= 6) levelEvdoSnr = 8;
        else if (evdoSnr >= 5) levelEvdoSnr = 4;
        else if (evdoSnr >= 3) levelEvdoSnr = 2;
        else if (evdoSnr >= 1) levelEvdoSnr = 1;
        else levelEvdoSnr = 99;

        int level = (levelEvdoDbm < levelEvdoSnr) ? levelEvdoDbm : levelEvdoSnr;
        if (DBG) log("getEvdoAsuLevel=" + level);
        return level;
    }

    /**
     * Get the signal strength as dBm
     */
@@ -237,6 +332,7 @@ public final class CellSignalStrengthCdma extends CellSignalStrength implements
    public int getCdmaDbm() {
        return mCdmaDbm;
    }

    /** @hide */
    public void setCdmaDbm(int cdmaDbm) {
        mCdmaDbm = cdmaDbm;
@@ -248,6 +344,7 @@ public final class CellSignalStrengthCdma extends CellSignalStrength implements
    public int getCdmaEcio() {
        return mCdmaEcio;
    }

    /** @hide */
    public void setCdmaEcio(int cdmaEcio) {
        mCdmaEcio = cdmaEcio;
@@ -259,6 +356,7 @@ public final class CellSignalStrengthCdma extends CellSignalStrength implements
    public int getEvdoDbm() {
        return mEvdoDbm;
    }

    /** @hide */
    public void setEvdoDbm(int evdoDbm) {
        mEvdoDbm = evdoDbm;
@@ -270,6 +368,7 @@ public final class CellSignalStrengthCdma extends CellSignalStrength implements
    public int getEvdoEcio() {
        return mEvdoEcio;
    }

    /** @hide */
    public void setEvdoEcio(int evdoEcio) {
        mEvdoEcio = evdoEcio;
@@ -281,6 +380,7 @@ public final class CellSignalStrengthCdma extends CellSignalStrength implements
    public int getEvdoSnr() {
        return mEvdoSnr;
    }

    /** @hide */
    public void setEvdoSnr(int evdoSnr) {
        mEvdoSnr = evdoSnr;
@@ -288,28 +388,29 @@ public final class CellSignalStrengthCdma extends CellSignalStrength implements

    @Override
    public int hashCode() {
        return Objects.hash(mCdmaDbm, mCdmaEcio, mEvdoDbm, mEvdoEcio, mEvdoSnr);
        return Objects.hash(mCdmaDbm, mCdmaEcio, mEvdoDbm, mEvdoEcio, mEvdoSnr, mLevel);
    }

    private static final CellSignalStrengthCdma sInvalid = new CellSignalStrengthCdma();

    /** @hide */
    @Override
    public boolean isValid() {
        return !this.equals(sInvalid);
    }

    @Override
    public boolean equals (Object o) {
        CellSignalStrengthCdma s;

        try {
        if (!(o instanceof CellSignalStrengthCdma)) return false;
        s = (CellSignalStrengthCdma) o;
        } catch (ClassCastException ex) {
            return false;
        }

        if (o == null) {
            return false;
        }

        return mCdmaDbm == s.mCdmaDbm
                && mCdmaEcio == s.mCdmaEcio
                && mEvdoDbm == s.mEvdoDbm
                && mEvdoEcio == s.mEvdoEcio
                && mEvdoSnr == s.mEvdoSnr;
                && mEvdoSnr == s.mEvdoSnr
                && mLevel == s.mLevel;
    }

    /**
@@ -322,7 +423,8 @@ public final class CellSignalStrengthCdma extends CellSignalStrength implements
                + " cdmaEcio=" + mCdmaEcio
                + " evdoDbm=" + mEvdoDbm
                + " evdoEcio=" + mEvdoEcio
                + " evdoSnr=" + mEvdoSnr;
                + " evdoSnr=" + mEvdoSnr
                + " level=" + mLevel;
    }

    /** Implement the Parcelable interface */
@@ -334,6 +436,7 @@ public final class CellSignalStrengthCdma extends CellSignalStrength implements
        dest.writeInt(mEvdoDbm);
        dest.writeInt(mEvdoEcio);
        dest.writeInt(mEvdoSnr);
        dest.writeInt(mLevel);
    }

    /**
@@ -349,6 +452,7 @@ public final class CellSignalStrengthCdma extends CellSignalStrength implements
        mEvdoDbm = in.readInt();
        mEvdoEcio = in.readInt();
        mEvdoSnr = in.readInt();
        mLevel = in.readInt();
        if (DBG) log("CellSignalStrengthCdma(Parcel): " + toString());
    }

+71 −66
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package android.telephony;
import android.annotation.UnsupportedAppUsage;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.PersistableBundle;
import android.telephony.Rlog;

import java.util.Objects;
@@ -31,16 +32,18 @@ public final class CellSignalStrengthGsm extends CellSignalStrength implements P
    private static final String LOG_TAG = "CellSignalStrengthGsm";
    private static final boolean DBG = false;

    private static final int GSM_SIGNAL_STRENGTH_GREAT = 12;
    private static final int GSM_SIGNAL_STRENGTH_GOOD = 8;
    private static final int GSM_SIGNAL_STRENGTH_MODERATE = 5;
    private static final int GSM_RSSI_MAX = -51;
    private static final int GSM_RSSI_GREAT = -89;
    private static final int GSM_RSSI_GOOD = -97;
    private static final int GSM_RSSI_MODERATE = -103;
    private static final int GSM_RSSI_POOR = -107;

    private int mRssi; // in dBm [-113, -51] or UNAVAILABLE
    @UnsupportedAppUsage
    private int mSignalStrength; // in ASU; Valid values are (0-31, 99) as defined in TS 27.007 8.5
    @UnsupportedAppUsage
    private int mBitErrorRate;   // bit error rate (0-7, 99) as defined in TS 27.007 8.5
    @UnsupportedAppUsage
    private int mBitErrorRate; // bit error rate (0-7, 99) TS 27.007 8.5 or UNAVAILABLE
    @UnsupportedAppUsage(maxTargetSdk = android.os.Build.VERSION_CODES.O)
    private int mTimingAdvance; // range from 0-219 or CellInfo.UNAVAILABLE if unknown
    private int mLevel;

    /** @hide */
    @UnsupportedAppUsage
@@ -49,15 +52,17 @@ public final class CellSignalStrengthGsm extends CellSignalStrength implements P
    }

    /** @hide */
    public CellSignalStrengthGsm(int ss, int ber) {
        this(ss, ber, CellInfo.UNAVAILABLE);
    public CellSignalStrengthGsm(int rssi, int ber, int ta) {
        mRssi = inRangeOrUnavailable(rssi, -113, -51);
        mBitErrorRate = inRangeOrUnavailable(ber, 0, 7, 99);
        mTimingAdvance = inRangeOrUnavailable(ta, 0, 219);
        updateLevel(null, null);
    }

    /** @hide */
    public CellSignalStrengthGsm(int ss, int ber, int ta) {
        mSignalStrength = ss;
        mBitErrorRate = ber;
        mTimingAdvance = ta;
    public CellSignalStrengthGsm(android.hardware.radio.V1_0.GsmSignalStrength gsm) {
        // Convert from HAL values as part of construction.
        this(getRssiDbmFromAsu(gsm.signalStrength), gsm.bitErrorRate, gsm.timingAdvance);
    }

    /** @hide */
@@ -67,9 +72,10 @@ public final class CellSignalStrengthGsm extends CellSignalStrength implements P

    /** @hide */
    protected void copyFrom(CellSignalStrengthGsm s) {
        mSignalStrength = s.mSignalStrength;
        mRssi = s.mRssi;
        mBitErrorRate = s.mBitErrorRate;
        mTimingAdvance = s.mTimingAdvance;
        mLevel = s.mLevel;
    }

    /** @hide */
@@ -81,9 +87,10 @@ public final class CellSignalStrengthGsm extends CellSignalStrength implements P
    /** @hide */
    @Override
    public void setDefaultValues() {
        mSignalStrength = CellInfo.UNAVAILABLE;
        mRssi = CellInfo.UNAVAILABLE;
        mBitErrorRate = CellInfo.UNAVAILABLE;
        mTimingAdvance = CellInfo.UNAVAILABLE;
        mLevel = SIGNAL_STRENGTH_NONE_OR_UNKNOWN;
    }

    /**
@@ -94,20 +101,18 @@ public final class CellSignalStrengthGsm extends CellSignalStrength implements P
     */
    @Override
    public int getLevel() {
        int level;

        // ASU ranges from 0 to 31 - TS 27.007 Sec 8.5
        // asu = 0 (-113dB or less) is very weak
        // signal, its better to show 0 bars to the user in such cases.
        // asu = 99 is a special case, where the signal strength is unknown.
        int asu = mSignalStrength;
        if (asu <= 2 || asu == 99) level = SIGNAL_STRENGTH_NONE_OR_UNKNOWN;
        else if (asu >= GSM_SIGNAL_STRENGTH_GREAT) level = SIGNAL_STRENGTH_GREAT;
        else if (asu >= GSM_SIGNAL_STRENGTH_GOOD)  level = SIGNAL_STRENGTH_GOOD;
        else if (asu >= GSM_SIGNAL_STRENGTH_MODERATE)  level = SIGNAL_STRENGTH_MODERATE;
        else level = SIGNAL_STRENGTH_POOR;
        if (DBG) log("getLevel=" + level);
        return level;
        return mLevel;
    }

    /** @hide */
    @Override
    public void updateLevel(PersistableBundle cc, ServiceState ss) {
        if (mRssi > GSM_RSSI_MAX) mLevel = SIGNAL_STRENGTH_NONE_OR_UNKNOWN;
        else if (mRssi >= GSM_RSSI_GREAT) mLevel = SIGNAL_STRENGTH_GREAT;
        else if (mRssi >= GSM_RSSI_GOOD)  mLevel = SIGNAL_STRENGTH_GOOD;
        else if (mRssi >= GSM_RSSI_MODERATE)  mLevel = SIGNAL_STRENGTH_MODERATE;
        else if (mRssi >= GSM_RSSI_POOR) mLevel = SIGNAL_STRENGTH_POOR;
        else mLevel = SIGNAL_STRENGTH_NONE_OR_UNKNOWN;
    }

    /**
@@ -126,55 +131,52 @@ public final class CellSignalStrengthGsm extends CellSignalStrength implements P
     */
    @Override
    public int getDbm() {
        int dBm;

        int level = mSignalStrength;
        int asu = (level == 99 ? CellInfo.UNAVAILABLE : level);
        if (asu != CellInfo.UNAVAILABLE) {
            dBm = -113 + (2 * asu);
        } else {
            dBm = CellInfo.UNAVAILABLE;
        }
        if (DBG) log("getDbm=" + dBm);
        return dBm;
        return mRssi;
    }

    /**
     * Get the signal level as an asu value between 0..31, 99 is unknown
     * Get the RSSI in ASU.
     *
     * Asu is calculated based on 3GPP RSRP. Refer to 3GPP 27.007 (Ver 10.3.0) Sec 8.69
     *
     * @return RSSI in ASU 0..31, 99, or UNAVAILABLE
     */
    @Override
    public int getAsuLevel() {
        // ASU ranges from 0 to 31 - TS 27.007 Sec 8.5
        // asu = 0 (-113dB or less) is very weak
        // signal, its better to show 0 bars to the user in such cases.
        // asu = 99 is a special case, where the signal strength is unknown.
        int level = mSignalStrength;
        if (DBG) log("getAsuLevel=" + level);
        return level;
        return getAsuFromRssiDbm(mRssi);
    }

    /**
     * Return the Bit Error Rate
     * @returns the bit error rate (0-7, 99) as defined in TS 27.007 8.5 or UNAVAILABLE.
     * @hide
     */
    public int getBitErrorRate() {
        return mBitErrorRate;
    }

    @Override
    public int hashCode() {
        return Objects.hash(mSignalStrength, mBitErrorRate, mTimingAdvance);
        return Objects.hash(mRssi, mBitErrorRate, mTimingAdvance);
    }

    @Override
    public boolean equals (Object o) {
        CellSignalStrengthGsm s;
    private static final CellSignalStrengthGsm sInvalid = new CellSignalStrengthGsm();

        try {
            s = (CellSignalStrengthGsm) o;
        } catch (ClassCastException ex) {
            return false;
    /** @hide */
    @Override
    public boolean isValid() {
        return !this.equals(sInvalid);
    }

        if (o == null) {
            return false;
        }
    @Override
    public boolean equals(Object o) {
        if (!(o instanceof CellSignalStrengthGsm)) return false;
        CellSignalStrengthGsm s = (CellSignalStrengthGsm) o;

        return mSignalStrength == s.mSignalStrength && mBitErrorRate == s.mBitErrorRate &&
                        s.mTimingAdvance == mTimingAdvance;
        return mRssi == s.mRssi
                && mBitErrorRate == s.mBitErrorRate
                && mTimingAdvance == s.mTimingAdvance
                && mLevel == s.mLevel;
    }

    /**
@@ -183,18 +185,20 @@ public final class CellSignalStrengthGsm extends CellSignalStrength implements P
    @Override
    public String toString() {
        return "CellSignalStrengthGsm:"
                + " ss=" + mSignalStrength
                + " rssi=" + mRssi
                + " ber=" + mBitErrorRate
                + " mTa=" + mTimingAdvance;
                + " mTa=" + mTimingAdvance
                + " mLevel=" + mLevel;
    }

    /** Implement the Parcelable interface */
    @Override
    public void writeToParcel(Parcel dest, int flags) {
        if (DBG) log("writeToParcel(Parcel, int): " + toString());
        dest.writeInt(mSignalStrength);
        dest.writeInt(mRssi);
        dest.writeInt(mBitErrorRate);
        dest.writeInt(mTimingAdvance);
        dest.writeInt(mLevel);
    }

    /**
@@ -202,9 +206,10 @@ public final class CellSignalStrengthGsm extends CellSignalStrength implements P
     * where the token is already been processed.
     */
    private CellSignalStrengthGsm(Parcel in) {
        mSignalStrength = in.readInt();
        mRssi = in.readInt();
        mBitErrorRate = in.readInt();
        mTimingAdvance = in.readInt();
        mLevel = in.readInt();
        if (DBG) log("CellSignalStrengthGsm(Parcel): " + toString());
    }

+180 −70

File changed.

Preview size limit exceeded, changes collapsed.

Loading