Fixed the incorrect signal strength info displayed after call end.

We should query the signal stregnth information from the modem
when RAT family changes instead of relying on the next unsolicited
signal strength information indication coming from the modem,
which might take a long time to come or even not come. By proactively
querying the info, we can make sure the up-to-date signal strength
is showing up on the UI.

bug: 22724699
Change-Id: I4c80b281cffb28a871d4e754f43c43b9809244a4
diff --git a/src/java/com/android/internal/telephony/cdma/CdmaLteServiceStateTracker.java b/src/java/com/android/internal/telephony/cdma/CdmaLteServiceStateTracker.java
index 18689e2..248c914 100644
--- a/src/java/com/android/internal/telephony/cdma/CdmaLteServiceStateTracker.java
+++ b/src/java/com/android/internal/telephony/cdma/CdmaLteServiceStateTracker.java
@@ -159,7 +159,7 @@
                         states.length + " states=" + states);
             }
 
-            int type = 0;
+            int newDataRAT = ServiceState.RIL_RADIO_TECHNOLOGY_UNKNOWN;
             int regState = -1;
             if (states.length > 0) {
                 try {
@@ -167,7 +167,7 @@
 
                     // states[3] (if present) is the current radio technology
                     if (states.length >= 4 && states[3] != null) {
-                        type = Integer.parseInt(states[3]);
+                        newDataRAT = Integer.parseInt(states[3]);
                     }
                 } catch (NumberFormatException ex) {
                     loge("handlePollStateResultMessage: error parsing GprsRegistrationState: "
@@ -243,7 +243,24 @@
                 }
             }
 
-            mNewSS.setRilDataRadioTechnology(type);
+            // If the unsolicited signal strength comes just before data RAT family changes (i.e.
+            // from UNKNOWN to LTE, CDMA to LTE, LTE to CDMA), the signal bar might display
+            // the wrong information until the next unsolicited signal strength information coming
+            // from the modem, which might take a long time to come or even not come at all.
+            // In order to provide the best user experience, we query the latest signal
+            // information so it will show up on the UI on time.
+
+            int oldDataRAT = mSS.getRilDataRadioTechnology();
+            if ((oldDataRAT == ServiceState.RIL_RADIO_TECHNOLOGY_UNKNOWN &&
+                    newDataRAT != ServiceState.RIL_RADIO_TECHNOLOGY_UNKNOWN) ||
+                    (ServiceState.isCdma(oldDataRAT) &&
+                            newDataRAT == ServiceState.RIL_RADIO_TECHNOLOGY_LTE) ||
+                    (oldDataRAT == ServiceState.RIL_RADIO_TECHNOLOGY_LTE &&
+                            ServiceState.isCdma(newDataRAT))) {
+                mCi.getSignalStrength(obtainMessage(EVENT_GET_SIGNAL_STRENGTH));
+            }
+
+            mNewSS.setRilDataRadioTechnology(newDataRAT);
             int dataRegState = regCodeToServiceState(regState);
             mNewSS.setDataRegState(dataRegState);
             // voice roaming state in done while handling EVENT_POLL_STATE_REGISTRATION_CDMA
@@ -251,7 +268,7 @@
             if (DBG) {
                 log("handlPollStateResultMessage: CdmaLteSST setDataRegState=" + dataRegState
                         + " regState=" + regState
-                        + " dataRadioTechnology=" + type);
+                        + " dataRadioTechnology=" + newDataRAT);
             }
         } else {
             super.handlePollStateResultMessage(what, ar);
diff --git a/src/java/com/android/internal/telephony/cdma/CdmaServiceStateTracker.java b/src/java/com/android/internal/telephony/cdma/CdmaServiceStateTracker.java
index f5806e5..e6b0867 100644
--- a/src/java/com/android/internal/telephony/cdma/CdmaServiceStateTracker.java
+++ b/src/java/com/android/internal/telephony/cdma/CdmaServiceStateTracker.java
@@ -210,6 +210,12 @@
             mAutoTimeZoneObserver);
         setSignalStrengthDefaultValues();
 
+        // Query signal strength from the modem after service tracker is created (i.e. boot up,
+        // switching between GSM and CDMA phone), because the unsolicited signal strength
+        // information might come late or even never come. This will get the accurate signal
+        // strength information displayed on the UI.
+        mCi.getSignalStrength(obtainMessage(EVENT_GET_SIGNAL_STRENGTH));
+
         mHbpcdUtils = new HbpcdUtils(phone.getContext());
 
         // Reset OTASP state in case previously set by another service
diff --git a/src/java/com/android/internal/telephony/gsm/GsmServiceStateTracker.java b/src/java/com/android/internal/telephony/gsm/GsmServiceStateTracker.java
index 5e685fa..8d3a84d 100755
--- a/src/java/com/android/internal/telephony/gsm/GsmServiceStateTracker.java
+++ b/src/java/com/android/internal/telephony/gsm/GsmServiceStateTracker.java
@@ -238,6 +238,12 @@
 
         setSignalStrengthDefaultValues();
 
+        // Query signal strength from the modem after service tracker is created (i.e. boot up,
+        // switching between GSM and CDMA phone), because the unsolicited signal strength
+        // information might come late or even never come. This will get the accurate signal
+        // strength information displayed on the UI.
+        mCi.getSignalStrength(obtainMessage(EVENT_GET_SIGNAL_STRENGTH));
+
         // Monitor locale change
         IntentFilter filter = new IntentFilter();
         filter.addAction(Intent.ACTION_LOCALE_CHANGED);