Update signal strength on ServiceState in service

Test: make RunSettingsRobotTests
Bug: 167643728
Change-Id: Ibf69f9e9ec2acafef1316069d37b8d2a27d7d4d7
Merged-In: Ibf69f9e9ec2acafef1316069d37b8d2a27d7d4d7
(cherry picked from commit 3b3704d693caf720ef0cc258750f8dacedd10583)
diff --git a/src/com/android/settings/deviceinfo/simstatus/SimStatusDialogController.java b/src/com/android/settings/deviceinfo/simstatus/SimStatusDialogController.java
index 370bdfb..61f0ad6 100644
--- a/src/com/android/settings/deviceinfo/simstatus/SimStatusDialogController.java
+++ b/src/com/android/settings/deviceinfo/simstatus/SimStatusDialogController.java
@@ -140,6 +140,7 @@
 
     private SubscriptionInfo mSubscriptionInfo;
     private TelephonyDisplayInfo mTelephonyDisplayInfo;
+    private ServiceState mPreviousServiceState;
 
     private final int mSlotIndex;
     private TelephonyManager mTelephonyManager;
@@ -425,6 +426,9 @@
         final int state = Utils.getCombinedServiceState(serviceState);
         if (!Utils.isInService(serviceState)) {
             resetSignalStrength();
+        } else if (!Utils.isInService(mPreviousServiceState)) {
+            // If ServiceState changed from out of service -> in service, update signal strength.
+            updateSignalStrength(mTelephonyManager.getSignalStrength());
         }
 
         String serviceStateValue;
@@ -472,7 +476,7 @@
         }
 
         ServiceState serviceState = mTelephonyManager.getServiceState();
-        if (serviceState == null || !Utils.isInService(serviceState)) {
+        if (!Utils.isInService(serviceState)) {
             return;
         }
 
@@ -755,6 +759,7 @@
                 updateNetworkProvider();
                 updateServiceState(serviceState);
                 updateRoamingStatus(serviceState);
+                mPreviousServiceState = serviceState;
             }
 
             @Override
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/simstatus/SimStatusDialogControllerTest.java b/tests/robotests/src/com/android/settings/deviceinfo/simstatus/SimStatusDialogControllerTest.java
index bbab259..a854c04 100644
--- a/tests/robotests/src/com/android/settings/deviceinfo/simstatus/SimStatusDialogControllerTest.java
+++ b/tests/robotests/src/com/android/settings/deviceinfo/simstatus/SimStatusDialogControllerTest.java
@@ -42,6 +42,7 @@
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.never;
 import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 import static org.robolectric.Shadows.shadowOf;
@@ -293,7 +294,7 @@
 
         final String signalStrengthString =
                 mContext.getString(R.string.sim_signal_strength, lteDbm, lteAsu);
-        verify(mDialog).setText(SIGNAL_STRENGTH_VALUE_ID, signalStrengthString);
+        verify(mDialog, times(2)).setText(SIGNAL_STRENGTH_VALUE_ID, signalStrengthString);
     }
 
     @Test
@@ -310,7 +311,7 @@
 
         final String signalStrengthString =
                 mContext.getString(R.string.sim_signal_strength, lteDbm, lteAsu);
-        verify(mDialog).setText(SIGNAL_STRENGTH_VALUE_ID, signalStrengthString);
+        verify(mDialog, times(2)).setText(SIGNAL_STRENGTH_VALUE_ID, signalStrengthString);
     }
 
     @Test
@@ -330,7 +331,7 @@
 
         final String signalStrengthString =
                 mContext.getString(R.string.sim_signal_strength, lteDbm, lteAsu);
-        verify(mDialog).setText(SIGNAL_STRENGTH_VALUE_ID, signalStrengthString);
+        verify(mDialog, times(2)).setText(SIGNAL_STRENGTH_VALUE_ID, signalStrengthString);
     }
 
     @Test
@@ -394,8 +395,8 @@
 
         mController.initialize();
 
-        verify(mDialog).removeSettingFromScreen(SIGNAL_STRENGTH_LABEL_ID);
-        verify(mDialog).removeSettingFromScreen(SIGNAL_STRENGTH_VALUE_ID);
+        verify(mDialog, times(2)).removeSettingFromScreen(SIGNAL_STRENGTH_LABEL_ID);
+        verify(mDialog, times(2)).removeSettingFromScreen(SIGNAL_STRENGTH_VALUE_ID);
     }
 
     @Test
@@ -405,7 +406,7 @@
 
         mController.initialize();
 
-        verify(mDialog).setText(eq(SIGNAL_STRENGTH_VALUE_ID), any());
+        verify(mDialog, times(2)).setText(eq(SIGNAL_STRENGTH_VALUE_ID), any());
         verify(mDialog).removeSettingFromScreen(ICCID_INFO_LABEL_ID);
         verify(mDialog).removeSettingFromScreen(ICCID_INFO_VALUE_ID);
     }