Merge commit '616b281b' into merge-conflict-TelephonySignal-Strength-cleanup
Wink Saville [Mon, 13 Aug 2012 19:22:51 +0000 (12:22 -0700)]
* commit '616b281b':
  Telephony: Signal Strength cleanup

Change-Id: I3c211a06c480169d90fb5bc2c1774bd509d91f87

src/java/com/android/internal/telephony/RIL.java
src/java/com/android/internal/telephony/ServiceStateTracker.java
src/java/com/android/internal/telephony/cdma/CdmaLteServiceStateTracker.java
src/java/com/android/internal/telephony/cdma/CdmaServiceStateTracker.java
src/java/com/android/internal/telephony/gsm/GsmServiceStateTracker.java

index 6746479..b64ec0d 100644 (file)
@@ -43,6 +43,7 @@ import android.os.SystemProperties;
 import android.os.PowerManager.WakeLock;
 import android.telephony.NeighboringCellInfo;
 import android.telephony.PhoneNumberUtils;
+import android.telephony.SignalStrength;
 import android.telephony.SmsManager;
 import android.telephony.SmsMessage;
 import android.text.TextUtils;
@@ -3346,16 +3347,8 @@ public final class RIL extends BaseCommands implements CommandsInterface {
 
     private Object
     responseSignalStrength(Parcel p) {
-        int numInts = 12;
-        int response[];
-
-        /* TODO: Add SignalStrength class to match RIL_SignalStrength */
-        response = new int[numInts];
-        for (int i = 0 ; i < numInts ; i++) {
-            response[i] = p.readInt();
-        }
-
-        return response;
+        SignalStrength signalStrength = new SignalStrength(p);
+        return signalStrength;
     }
 
     private ArrayList<CdmaInformationRecords>
index 354e138..5975b15 100644 (file)
@@ -220,26 +220,6 @@ public abstract class ServiceStateTracker extends Handler {
     }
 
     /**
-     * Set the mCellInfo.signalStrength to its default values
-     */
-    protected void setSignalStrengthDefaultValues() {
-        setSignalStrengthDefaultValues(mSignalStrength);
-    }
-
-    /**
-     * Set the signal strength default values
-     */
-    protected void setSignalStrengthDefaultValues(SignalStrength signalStrength) {
-        signalStrength.initialize(99, -1, -1, -1, -1, -1, -1,
-                -1, -1, -1, SignalStrength.INVALID_SNR, -1, isGsmSignalStrength());
-    }
-
-    /**
-     * Return true if this SST is a GSM category device.
-     */
-    protected abstract boolean isGsmSignalStrength();
-
-    /**
      * Registration point for combined roaming on
      * combined roaming is true when roaming is true and ONS differs SPN
      *
@@ -523,6 +503,30 @@ public abstract class ServiceStateTracker extends Handler {
     }
 
     /**
+     * send signal-strength-changed notification if changed Called both for
+     * solicited and unsolicited signal strength updates
+     *
+     * @return true if the signal strength changed and a notification was sent.
+     */
+    protected boolean onSignalStrengthResult(AsyncResult ar, boolean isGsm) {
+        SignalStrength oldSignalStrength = mSignalStrength;
+
+        // This signal is used for both voice and data radio signal so parse
+        // all fields
+
+        if ((ar.exception == null) && (ar.result != null)) {
+            mSignalStrength = (SignalStrength) ar.result;
+            mSignalStrength.validateInput();
+            mSignalStrength.setGsm(isGsm);
+        } else {
+            log("onSignalStrengthResult() Exception from RIL : " + ar.exception);
+            mSignalStrength = new SignalStrength(isGsm);
+        }
+
+        return notifySignalStrength();
+    }
+
+    /**
      * Hang up all voice call and turn off radio. Implemented by derived class.
      */
     protected abstract void hangupAndPowerOff();
index 29aa385..e82f07d 100644 (file)
@@ -16,6 +16,7 @@
 
 package com.android.internal.telephony.cdma;
 
+import com.android.internal.telephony.PhoneBase;
 import com.android.internal.telephony.TelephonyProperties;
 import com.android.internal.telephony.MccTable;
 import com.android.internal.telephony.EventLogTags;
@@ -210,11 +211,6 @@ public class CdmaLteServiceStateTracker extends CdmaServiceStateTracker {
     }
 
     @Override
-    protected boolean isGsmSignalStrength() {
-        return false;
-    }
-
-    @Override
     protected void pollState() {
         pollingContext = new int[1];
         pollingContext[0] = 0;
@@ -535,80 +531,31 @@ public class CdmaLteServiceStateTracker extends CdmaServiceStateTracker {
                 }
                 arrayCi.add(mCellInfo);
             }
-            phone.notifyCellInfo(arrayCi);
+            mPhoneBase.notifyCellInfo(arrayCi);
         }
     }
 
     @Override
-    protected void onSignalStrengthResult(AsyncResult ar) {
-        if (ar.exception != null) {
-            // Most likely radio is resetting/disconnected change to default values.
-            setSignalStrengthDefaultValues();
-        } else {
-            int[] ints = (int[])ar.result;
-
-            int lteRssi = -1;
-            int lteRsrp = -1;
-            int lteRsrq = -1;
-            int lteRssnr = SignalStrength.INVALID_SNR;
-            int lteCqi = -1;
-
-            int offset = 2;
-            int cdmaDbm = (ints[offset] > 0) ? -ints[offset] : -120;
-            int cdmaEcio = (ints[offset + 1] > 0) ? -ints[offset + 1] : -160;
-            int evdoRssi = (ints[offset + 2] > 0) ? -ints[offset + 2] : -120;
-            int evdoEcio = (ints[offset + 3] > 0) ? -ints[offset + 3] : -1;
-            int evdoSnr = ((ints[offset + 4] > 0) && (ints[offset + 4] <= 8)) ? ints[offset + 4]
-                    : -1;
-
-            if (mRilRadioTechnology == ServiceState.RIL_RADIO_TECHNOLOGY_LTE) {
-                lteRssi = ints[offset+5];
-                lteRsrp = ints[offset+6];
-                lteRsrq = ints[offset+7];
-                lteRssnr = ints[offset+8];
-                lteCqi = ints[offset+9];
-            }
-
-            synchronized (mCellInfo) {
-                if (mRilRadioTechnology != ServiceState.RIL_RADIO_TECHNOLOGY_LTE) {
-                    mSignalStrength.initialize(99, -1, cdmaDbm, cdmaEcio, evdoRssi,
-                            evdoEcio, evdoSnr, false);
-                } else {
-                    mCellInfoLte.setTimeStamp(SystemClock.elapsedRealtime() * 1000);
-                    mCellInfoLte.setTimeStampType(CellInfo.TIMESTAMP_TYPE_JAVA_RIL);
-                    mCellInfoLte.getCellSignalStrength().initialize(lteRssi, lteRsrp, lteRsrq,
-                            lteRssnr, lteCqi, Integer.MAX_VALUE);
-                    mSignalStrength.initialize(99, -1, cdmaDbm, cdmaEcio, evdoRssi,
-                            evdoEcio, evdoSnr, lteRssi, lteRsrp, lteRsrq, lteRssnr, lteCqi, true);
-                }
-            }
+    protected boolean onSignalStrengthResult(AsyncResult ar, boolean isGsm) {
+        if (mRilRadioTechnology == ServiceState.RIL_RADIO_TECHNOLOGY_LTE) {
+            isGsm = true;
         }
+        boolean ssChanged = super.onSignalStrengthResult(ar, isGsm);
 
-        boolean ssChanged = notifySignalStrength();
-        if (ssChanged) {
-            synchronized(mCellInfo) {
-                if (mCellInfoLte.getCellIdentity() != null) {
-                    ArrayList<CellInfo> arrayCi = new ArrayList<CellInfo>();
-                    arrayCi.add(mCellInfoLte);
-                    phone.notifyCellInfo(arrayCi);
-                }
+        synchronized (mCellInfo) {
+            if (mRilRadioTechnology == ServiceState.RIL_RADIO_TECHNOLOGY_LTE) {
+                mCellInfoLte.setTimeStamp(SystemClock.elapsedRealtime() * 1000);
+                mCellInfoLte.setTimeStampType(CellInfo.TIMESTAMP_TYPE_JAVA_RIL);
+                mCellInfoLte.getCellSignalStrength()
+                                .initialize(mSignalStrength,SignalStrength.INVALID);
             }
-        }
-    }
-
-    /**
-     * Set the mCellInfo.signalStrength to its default values
-     */
-    @Override
-    protected void setSignalStrengthDefaultValues() {
-        super.setSignalStrengthDefaultValues();
-        synchronized(mCellInfo) {
-            if (mCellInfoLte != null) {
-                mCellInfoLte.getCellSignalStrength().setDefaultValues();
-                mCellInfoLte.setTimeStamp(Long.MAX_VALUE);
-                mCellInfoLte.setTimeStampType(CellInfo.TIMESTAMP_TYPE_UNKNOWN);
+            if (mCellInfoLte.getCellIdentity() != null) {
+                ArrayList<CellInfo> arrayCi = new ArrayList<CellInfo>();
+                arrayCi.add(mCellInfoLte);
+                mPhoneBase.notifyCellInfo(arrayCi);
             }
         }
+        return ssChanged;
     }
 
     @Override
index fafb0c1..5c91983 100755 (executable)
@@ -326,7 +326,7 @@ public class CdmaServiceStateTracker extends ServiceStateTracker {
                 return;
             }
             ar = (AsyncResult) msg.obj;
-            onSignalStrengthResult(ar);
+            onSignalStrengthResult(ar, false);
             queueNextSignalStrengthPoll();
 
             break;
@@ -447,7 +447,7 @@ public class CdmaServiceStateTracker extends ServiceStateTracker {
             // so we don't have to ask it.
             dontPollSignalStrength = true;
 
-            onSignalStrengthResult(ar);
+            onSignalStrengthResult(ar, false);
             break;
 
         case EVENT_RUIM_RECORDS_LOADED:
@@ -811,9 +811,8 @@ public class CdmaServiceStateTracker extends ServiceStateTracker {
 
     }
 
-    @Override
-    protected boolean isGsmSignalStrength() {
-        return false;
+    protected void setSignalStrengthDefaultValues() {
+        mSignalStrength = new SignalStrength( false);
     }
 
     /**
@@ -1134,33 +1133,6 @@ public class CdmaServiceStateTracker extends ServiceStateTracker {
         sendMessageDelayed(msg, POLL_PERIOD_MILLIS);
     }
 
-    /**
-     *  send signal-strength-changed notification if changed
-     *  Called both for solicited and unsolicited signal strength updates
-     */
-    protected void onSignalStrengthResult(AsyncResult ar) {
-        if (ar.exception != null) {
-            // Most likely radio is resetting/disconnected change to default values.
-            setSignalStrengthDefaultValues();
-        } else {
-            int[] ints = (int[])ar.result;
-            int offset = 2;
-            int cdmaDbm = (ints[offset] > 0) ? -ints[offset] : -120;
-            int cdmaEcio = (ints[offset+1] > 0) ? -ints[offset+1] : -160;
-            int evdoRssi = (ints[offset+2] > 0) ? -ints[offset+2] : -120;
-            int evdoEcio = (ints[offset+3] > 0) ? -ints[offset+3] : -1;
-            int evdoSnr  = ((ints[offset+4] > 0) && (ints[offset+4] <= 8)) ? ints[offset+4] : -1;
-
-            synchronized(mCellInfo) {
-                mSignalStrength.initialize(99, -1, cdmaDbm, cdmaEcio, evdoRssi, evdoEcio, evdoSnr,
-                        false);
-            }
-        }
-
-        notifySignalStrength();
-    }
-
-
     protected int radioTechnologyToDataServiceState(int code) {
         int retVal = ServiceState.STATE_OUT_OF_SERVICE;
         switch(code) {
index 49c1fd1..1821139 100644 (file)
@@ -309,7 +309,7 @@ final class GsmServiceStateTracker extends ServiceStateTracker {
                     return;
                 }
                 ar = (AsyncResult) msg.obj;
-                onSignalStrengthResult(ar);
+                onSignalStrengthResult(ar, true);
                 queueNextSignalStrengthPoll();
 
                 break;
@@ -376,7 +376,7 @@ final class GsmServiceStateTracker extends ServiceStateTracker {
                 // we don't have to ask it
                 dontPollSignalStrength = true;
 
-                onSignalStrengthResult(ar);
+                onSignalStrengthResult(ar, true);
                 break;
 
             case EVENT_SIM_RECORDS_LOADED:
@@ -667,9 +667,8 @@ final class GsmServiceStateTracker extends ServiceStateTracker {
         }
     }
 
-    @Override
-    protected boolean isGsmSignalStrength() {
-        return true;
+    private void setSignalStrengthDefaultValues() {
+        mSignalStrength = new SignalStrength(true);
     }
 
     /**
@@ -1068,47 +1067,6 @@ final class GsmServiceStateTracker extends ServiceStateTracker {
     }
 
     /**
-     *  Send signal-strength-changed notification if changed.
-     *  Called both for solicited and unsolicited signal strength updates.
-     */
-    private void onSignalStrengthResult(AsyncResult ar) {
-        SignalStrength signalStrength = new SignalStrength();
-        int rssi = 99;
-        int lteSignalStrength = -1;
-        int lteRsrp = -1;
-        int lteRsrq = -1;
-        int lteRssnr = SignalStrength.INVALID_SNR;
-        int lteCqi = -1;
-
-        if (ar.exception != null) {
-            // -1 = unknown
-            // most likely radio is resetting/disconnected
-            setSignalStrengthDefaultValues(signalStrength);
-        } else {
-            int[] ints = (int[])ar.result;
-
-            // bug 658816 seems to be a case where the result is 0-length
-            if (ints.length != 0) {
-                rssi = ints[0];
-                lteSignalStrength = ints[7];
-                lteRsrp = ints[8];
-                lteRsrq = ints[9];
-                lteRssnr = ints[10];
-                lteCqi = ints[11];
-            } else {
-                loge("Bogus signal strength response");
-                rssi = 99;
-            }
-            synchronized(mCellInfo) {
-                mSignalStrength.initialize(rssi, -1, -1, -1,
-                        -1, -1, -1, lteSignalStrength, lteRsrp, lteRsrq, lteRssnr, lteCqi, true);
-            }
-        }
-
-        notifySignalStrength();
-    }
-
-    /**
      * Set restricted state based on the OnRestrictedStateChanged notification
      * If any voice or packet restricted state changes, trigger a UI
      * notification and notify registrants when sim is ready.