Fix 5326463: rework sim state handling in lockscreen

Previously it was possible to get an inconsistent state because there
were two paths that updated the lock screen sim state.  This reworks
the data flow to ensure the same path is always used to update the state.

KeyguardUpdateMonitor now correctly updates the entire state of the callee
whenever a new callback is registered.

In addition, KeyguardUpdateMonitor now caches the phone state in order
to avoid a round-trip binder call in updateEmergencyCallButtonState().
This avoids a condition that could make lockscreen unresponsive while
updating the emergency call button state.

KeyguardStatusViewManager also ensures the TransportControlView is
hidden when created to ensure we don't inappropriately update the carrier
line while waiting for the first callbacks to update the status lines.

Change-Id: I6b3975b703a7d90bac8d0fe29fbc0f1d9c5e0e7d
diff --git a/core/java/com/android/internal/widget/LockPatternUtils.java b/core/java/com/android/internal/widget/LockPatternUtils.java
index e3a4df9..c6b2cc7 100644
--- a/core/java/com/android/internal/widget/LockPatternUtils.java
+++ b/core/java/com/android/internal/widget/LockPatternUtils.java
@@ -936,10 +936,15 @@
      *
      * If there's currently a call in progress, the button will take them to the call
      * @param button the button to update
+     * @param the phone state:
+     *  {@link TelephonyManager#CALL_STATE_IDLE}
+     *  {@link TelephonyManager#CALL_STATE_RINGING}
+     *  {@link TelephonyManager#CALL_STATE_OFFHOOK}
      * @param showIfCapable indicates whether the button should be shown if emergency calls are
      *                      possible on the device
      */
-    public void updateEmergencyCallButtonState(Button button, boolean showIfCapable) {
+    public void updateEmergencyCallButtonState(Button button, int  phoneState,
+            boolean showIfCapable) {
         if (isEmergencyCallCapable() && showIfCapable) {
             button.setVisibility(View.VISIBLE);
         } else {
@@ -947,9 +952,8 @@
             return;
         }
 
-        int newState = TelephonyManager.getDefault().getCallState();
         int textId;
-        if (newState == TelephonyManager.CALL_STATE_OFFHOOK) {
+        if (phoneState == TelephonyManager.CALL_STATE_OFFHOOK) {
             // show "return to call" text and show phone icon
             textId = R.string.lockscreen_return_to_call;
             int phoneCallIcon = R.drawable.stat_sys_phone_call;
@@ -979,22 +983,4 @@
         }
         return false;
     }
-
-    /**
-     * Performs concentenation of PLMN/SPN
-     * @param plmn
-     * @param spn
-     * @return
-     */
-    public static CharSequence getCarrierString(CharSequence plmn, CharSequence spn) {
-        if (plmn != null && spn == null) {
-            return plmn;
-        } else if (plmn != null && spn != null) {
-            return plmn + "|" + spn;
-        } else if (plmn == null && spn != null) {
-            return spn;
-        } else {
-            return "";
-        }
-    }
 }