Set WIFI icon for connection based on connection extra.

Previous methodology looked for changes in the Ims feature availability
in the ImsPhoneCallTracker.  I.e. there was an assumption made that if
the IMS stack had VoWIFI enabled that we were using it.

A new extra was added for the 3 nexus devices,
ImsCallProfile.EXTRA_CALL_RAT_TYPE.  This determines the radio technology
in use for a call, which we can then use to accurately show the WIFI
calling icon.

Bug: 20144385
Change-Id: I5aee9a571c7458f576a9208b81bed9781046a39a
diff --git a/src/java/com/android/internal/telephony/imsphone/ImsPhoneConnection.java b/src/java/com/android/internal/telephony/imsphone/ImsPhoneConnection.java
index 8b72a63..da0771f 100644
--- a/src/java/com/android/internal/telephony/imsphone/ImsPhoneConnection.java
+++ b/src/java/com/android/internal/telephony/imsphone/ImsPhoneConnection.java
@@ -32,6 +32,7 @@
 import android.telephony.DisconnectCause;
 import android.telephony.PhoneNumberUtils;
 import android.telephony.Rlog;
+import android.telephony.ServiceState;
 import android.text.TextUtils;
 
 import com.android.ims.ImsException;
@@ -92,6 +93,16 @@
 
     private boolean mIsEmergency = false;
 
+    /**
+     * Used to indicate whether the wifi state is based on
+     * {@link com.android.ims.ImsConnectionStateListener#
+     *      onFeatureCapabilityChanged(int, int[], int[])} callbacks, or values received via the
+     * {@link ImsCallProfile#EXTRA_CALL_RAT_TYPE} extra.  Util we receive a value via the extras,
+     * we will use the wifi state based on the {@code onFeatureCapabilityChanged}.  Once a value
+     * is received via the extras, we will prefer those values going forward.
+     */
+    private boolean mIsWifiStateFromExtras = false;
+
     //***** Event Constants
     private static final int EVENT_DTMF_DONE = 1;
     private static final int EVENT_PAUSE_DONE = 2;
@@ -161,8 +172,6 @@
         mCreateTime = System.currentTimeMillis();
         mUusInfo = null;
 
-        //mIndex = index;
-
         updateWifiState();
 
         // Ensure any extras set on the ImsCallProfile at the start of the call are cached locally
@@ -819,6 +828,13 @@
      * @return Whether the ImsPhoneCallTracker's usage of wifi has been changed.
      */
     public boolean updateWifiState() {
+        // If we've received the wifi state via the ImsCallProfile.EXTRA_CALL_RAT_TYPE extra, we
+        // will no longer use state updates which are based on the onFeatureCapabilityChanged
+        // callback.
+        if (mIsWifiStateFromExtras) {
+            return false;
+        }
+
         Rlog.d(LOG_TAG, "updateWifiState: " + mOwner.isVowifiEnabled());
         if (isWifi() != mOwner.isVowifiEnabled()) {
             setWifi(mOwner.isVowifiEnabled());
@@ -828,6 +844,38 @@
     }
 
     /**
+     * Updates the wifi state based on the {@link ImsCallProfile#EXTRA_CALL_RAT_TYPE}.
+     * The call is considered to be a WIFI call if the extra value is
+     * {@link ServiceState#RIL_RADIO_TECHNOLOGY_IWLAN}.
+     *
+     * @param extras The ImsCallProfile extras.
+     */
+    private void updateWifiStateFromExtras(Bundle extras) {
+        if (extras.containsKey(ImsCallProfile.EXTRA_CALL_RAT_TYPE)) {
+            // The RIL (sadly) sends us the EXTRA_CALL_RAT_TYPE as a string extra, rather than an
+            // integer extra, so we need to parse it.
+            int radioTechnology;
+            try {
+                radioTechnology = Integer.parseInt(extras.getString(
+                        ImsCallProfile.EXTRA_CALL_RAT_TYPE));
+            } catch (NumberFormatException nfe) {
+                radioTechnology = ServiceState.RIL_RADIO_TECHNOLOGY_UNKNOWN;
+            }
+
+            // We've received the extra indicating the radio technology, so we will continue to
+            // prefer the radio technology received via this extra going forward.
+            mIsWifiStateFromExtras = true;
+
+            boolean isWifi = radioTechnology == ServiceState.RIL_RADIO_TECHNOLOGY_IWLAN;
+
+            // Report any changes
+            if (isWifi() != isWifi) {
+                setWifi(isWifi);
+            }
+        }
+    }
+
+    /**
      * Check for a change in call extras of {@link ImsCall}, and
      * update the {@link ImsPhoneConnection} accordingly.
      *
@@ -847,6 +895,8 @@
 
         final boolean changed = !areBundlesEqual(extras, mExtras);
         if (changed) {
+            updateWifiStateFromExtras(extras);
+
             mExtras.clear();
             mExtras.putAll(extras);
             setConnectionExtras(mExtras);