Merge "Make OTASP an explicit option for carriers." into lmp-dev
diff --git a/res/values/config.xml b/res/values/config.xml
index cbf60f1..cd82234 100644
--- a/res/values/config.xml
+++ b/res/values/config.xml
@@ -146,4 +146,7 @@
 
     <!-- Show APN Settings for some CDMA carriers -->
     <bool name="config_show_apn_setting_cdma">false</bool>
+
+    <!-- Allows the telephony HFA logic to run even if we're not in setup wizard. -->
+    <bool name="config_allow_hfa_outside_of_setup_wizard">true</bool>
 </resources>
diff --git a/src/com/android/phone/CallNotifier.java b/src/com/android/phone/CallNotifier.java
index be1e3b2..f22913c 100644
--- a/src/com/android/phone/CallNotifier.java
+++ b/src/com/android/phone/CallNotifier.java
@@ -142,8 +142,6 @@
 
         callStateMonitor.addListener(this);
 
-        createSignalInfoToneGenerator();
-
         BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
         if (adapter != null) {
             adapter.getProfileProxy(mApplication.getApplicationContext(),
@@ -944,7 +942,7 @@
         @Override
         public void run() {
             log("SignalInfoTonePlayer.run(toneId = " + mToneId + ")...");
-
+            createSignalInfoToneGenerator();
             if (mSignalInfoToneGenerator != null) {
                 //First stop any ongoing SignalInfo tone
                 mSignalInfoToneGenerator.stopTone();
diff --git a/src/com/android/phone/EmergencyDialer.java b/src/com/android/phone/EmergencyDialer.java
index e29d4c8..a8de874 100644
--- a/src/com/android/phone/EmergencyDialer.java
+++ b/src/com/android/phone/EmergencyDialer.java
@@ -38,6 +38,7 @@
 import android.text.method.DialerKeyListener;
 import android.util.Log;
 import android.view.KeyEvent;
+import android.view.MenuItem;
 import android.view.View;
 import android.view.WindowManager;
 import android.view.accessibility.AccessibilityManager;
@@ -606,6 +607,16 @@
         }
     }
 
+    @Override
+    public boolean onOptionsItemSelected(MenuItem item) {
+        final int itemId = item.getItemId();
+        if (itemId == android.R.id.home) {
+            onBackPressed();
+            return true;
+        }
+        return super.onOptionsItemSelected(item);
+    }
+
     /**
      * Update the enabledness of the "Dial" and "Backspace" buttons if applicable.
      */
diff --git a/src/com/android/phone/InCallScreenShowActivation.java b/src/com/android/phone/InCallScreenShowActivation.java
index 7ace241..34710a1 100644
--- a/src/com/android/phone/InCallScreenShowActivation.java
+++ b/src/com/android/phone/InCallScreenShowActivation.java
@@ -187,28 +187,34 @@
      * Starts the HFA provisioning process by bringing up the HFA Activity.
      */
     private void startHfa() {
-        final Intent intent = new Intent();
+        boolean isWizardRunning = isWizardRunning(this);
+        // We always run our HFA logic if we're in setup wizard, but if we're outside of setup
+        // wizard then we have to check a config to see if we should still run HFA.
+        if (isWizardRunning ||
+                getResources().getBoolean(R.bool.config_allow_hfa_outside_of_setup_wizard)) {
 
-        final PendingIntent otaResponseIntent = getIntent().getParcelableExtra(
-                OtaUtils.EXTRA_OTASP_RESULT_CODE_PENDING_INTENT);
+            final Intent intent = new Intent();
 
-        final boolean showUi = !isWizardRunning(this);
+            final PendingIntent otaResponseIntent = getIntent().getParcelableExtra(
+                    OtaUtils.EXTRA_OTASP_RESULT_CODE_PENDING_INTENT);
 
-        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+            final boolean showUi = !isWizardRunning;
+            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
 
-        if (otaResponseIntent != null) {
-            intent.putExtra(OtaUtils.EXTRA_OTASP_RESULT_CODE_PENDING_INTENT, otaResponseIntent);
+            if (otaResponseIntent != null) {
+                intent.putExtra(OtaUtils.EXTRA_OTASP_RESULT_CODE_PENDING_INTENT, otaResponseIntent);
+            }
+
+            Log.v(LOG_TAG, "Starting hfa activation activity");
+            if (showUi) {
+                intent.setClassName(this, HfaActivity.class.getName());
+                startActivity(intent);
+            } else {
+                intent.setClassName(this, HfaService.class.getName());
+                startService(intent);
+            }
+
         }
-
-        Log.v(LOG_TAG, "Starting hfa activation activity");
-        if (showUi) {
-            intent.setClassName(this, HfaActivity.class.getName());
-            startActivity(intent);
-        } else {
-            intent.setClassName(this, HfaService.class.getName());
-            startService(intent);
-        }
-
         setResult(RESULT_OK);
     }
 }
diff --git a/src/com/android/phone/PhoneGlobals.java b/src/com/android/phone/PhoneGlobals.java
index 4dd8ee2..31337ee 100644
--- a/src/com/android/phone/PhoneGlobals.java
+++ b/src/com/android/phone/PhoneGlobals.java
@@ -434,12 +434,10 @@
             PhoneUtils.setAudioMode(mCM);
         }
 
-        if (TelephonyCapabilities.supportsOtasp(phone)) {
-            cdmaOtaProvisionData = new OtaUtils.CdmaOtaProvisionData();
-            cdmaOtaConfigData = new OtaUtils.CdmaOtaConfigData();
-            cdmaOtaScreenState = new OtaUtils.CdmaOtaScreenState();
-            cdmaOtaInCallScreenUiState = new OtaUtils.CdmaOtaInCallScreenUiState();
-        }
+        cdmaOtaProvisionData = new OtaUtils.CdmaOtaProvisionData();
+        cdmaOtaConfigData = new OtaUtils.CdmaOtaConfigData();
+        cdmaOtaScreenState = new OtaUtils.CdmaOtaScreenState();
+        cdmaOtaInCallScreenUiState = new OtaUtils.CdmaOtaInCallScreenUiState();
 
         // XXX pre-load the SimProvider so that it's ready
         resolver.getType(Uri.parse("content://icc/adn"));
@@ -759,21 +757,7 @@
             cdmaPhoneCallState = new CdmaPhoneCallState();
             cdmaPhoneCallState.CdmaPhoneCallStateInit();
         }
-        if (TelephonyCapabilities.supportsOtasp(phone)) {
-            //create instances of CDMA OTA data classes
-            if (cdmaOtaProvisionData == null) {
-                cdmaOtaProvisionData = new OtaUtils.CdmaOtaProvisionData();
-            }
-            if (cdmaOtaConfigData == null) {
-                cdmaOtaConfigData = new OtaUtils.CdmaOtaConfigData();
-            }
-            if (cdmaOtaScreenState == null) {
-                cdmaOtaScreenState = new OtaUtils.CdmaOtaScreenState();
-            }
-            if (cdmaOtaInCallScreenUiState == null) {
-                cdmaOtaInCallScreenUiState = new OtaUtils.CdmaOtaInCallScreenUiState();
-            }
-        } else {
+        if (!TelephonyCapabilities.supportsOtasp(phone)) {
             //Clean up OTA data in GSM/UMTS. It is valid only for CDMA
             clearOtaState();
         }
diff --git a/src/com/android/phone/settings/PhoneAccountSettingsFragment.java b/src/com/android/phone/settings/PhoneAccountSettingsFragment.java
index 97430b0..c48812c 100644
--- a/src/com/android/phone/settings/PhoneAccountSettingsFragment.java
+++ b/src/com/android/phone/settings/PhoneAccountSettingsFragment.java
@@ -105,8 +105,17 @@
                     ? R.array.sip_call_options_wifi_only_entries
                     : R.array.sip_call_options_entries);
             mUseSipCalling.setOnPreferenceChangeListener(this);
-            mUseSipCalling.setValueIndex(
-                    mUseSipCalling.findIndexOfValue(mSipSharedPreferences.getSipCallOption()));
+
+            int optionsValueIndex =
+                    mUseSipCalling.findIndexOfValue(mSipSharedPreferences.getSipCallOption());
+            if (optionsValueIndex == -1) {
+                // If the option is invalid (eg. deprecated value), default to SIP_ADDRESS_ONLY.
+                mSipSharedPreferences.setSipCallOption(
+                        getResources().getString(R.string.sip_address_only));
+                optionsValueIndex =
+                        mUseSipCalling.findIndexOfValue(mSipSharedPreferences.getSipCallOption());
+            }
+            mUseSipCalling.setValueIndex(optionsValueIndex);
             mUseSipCalling.setSummary(mUseSipCalling.getEntry());
 
             mSipReceiveCallsPreference = (CheckBoxPreference)
diff --git a/src/com/android/services/telephony/CdmaConnection.java b/src/com/android/services/telephony/CdmaConnection.java
index 5d470ab..1915fe0 100644
--- a/src/com/android/services/telephony/CdmaConnection.java
+++ b/src/com/android/services/telephony/CdmaConnection.java
@@ -79,7 +79,6 @@
             EmergencyTonePlayer emergencyTonePlayer,
             boolean allowMute,
             boolean isOutgoing) {
-
         super(connection);
         mEmergencyTonePlayer = emergencyTonePlayer;
         mAllowMute = allowMute;
diff --git a/src/com/android/services/telephony/TelephonyConnection.java b/src/com/android/services/telephony/TelephonyConnection.java
index f7c6510..1cc6ad6 100644
--- a/src/com/android/services/telephony/TelephonyConnection.java
+++ b/src/com/android/services/telephony/TelephonyConnection.java
@@ -387,7 +387,7 @@
         setVideoProvider(mOriginalConnection.getVideoProvider());
         setAudioQuality(mOriginalConnection.getAudioQuality());
 
-        updateState();
+        updateAddress();
     }
 
     protected void hangup(int telephonyDisconnectCode) {
@@ -485,7 +485,7 @@
         return true;
     }
 
-    protected void updateState() {
+    void updateState() {
         if (mOriginalConnection == null) {
             return;
         }
diff --git a/src/com/android/services/telephony/TelephonyConnectionService.java b/src/com/android/services/telephony/TelephonyConnectionService.java
index e3b78d4..e8c148a 100644
--- a/src/com/android/services/telephony/TelephonyConnectionService.java
+++ b/src/com/android/services/telephony/TelephonyConnectionService.java
@@ -278,14 +278,14 @@
             return Connection.createCanceledConnection();
         }
 
-        Connection connection =
+        TelephonyConnection connection =
                 createConnectionFor(phone, unknownConnection,
                         !unknownConnection.isIncoming() /* isOutgoing */);
 
         if (connection == null) {
-            connection = Connection.createCanceledConnection();
             return Connection.createCanceledConnection();
         } else {
+            connection.updateState();
             return connection;
         }
     }