Merge "Block USSD requests via TelephonyManager when carrier does not allow it." into oc-dev
diff --git a/res/values-es/strings.xml b/res/values-es/strings.xml
index 94706c1..89255f5 100644
--- a/res/values-es/strings.xml
+++ b/res/values-es/strings.xml
@@ -225,7 +225,7 @@
     <string name="gsm_umts_options" msgid="6538311689850981686">"Opciones GSM/UMTS"</string>
     <string name="cdma_options" msgid="4016822858172249884">"Opciones de CDMA"</string>
     <string name="throttle_data_usage" msgid="3715677828160555808">"Uso de datos"</string>
-    <string name="throttle_current_usage" msgid="8762280193043815361">"Datos del período actual"</string>
+    <string name="throttle_current_usage" msgid="8762280193043815361">"Datos del periodo actual"</string>
     <string name="throttle_time_frame" msgid="1915198770363734685">"Período uso datos"</string>
     <string name="throttle_rate" msgid="4710388992676803508">"Política velocidad datos"</string>
     <string name="throttle_help" msgid="243651091785169900">"Más información"</string>
@@ -236,7 +236,7 @@
     <!-- no translation found for throttle_data_usage_subtext (6029276011123694701) -->
     <skip />
     <string name="throttle_data_rate_reduced_subtext" msgid="7492763592720107737">"Máx de <xliff:g id="USED_0">%1$s</xliff:g> superado.\nFrec datos reducida a <xliff:g id="USED_1">%2$d</xliff:g> Kb/s"</string>
-    <string name="throttle_time_frame_subtext" msgid="7732763021560399960">"<xliff:g id="USED_0">%1$d</xliff:g>% del ciclo transcurrido.\nPróx período en <xliff:g id="USED_1">%2$d</xliff:g> días (<xliff:g id="USED_2">%3$s</xliff:g>)"</string>
+    <string name="throttle_time_frame_subtext" msgid="7732763021560399960">"<xliff:g id="USED_0">%1$d</xliff:g>% del ciclo transcurrido.\nPróx periodo en <xliff:g id="USED_1">%2$d</xliff:g> días (<xliff:g id="USED_2">%3$s</xliff:g>)"</string>
     <string name="throttle_rate_subtext" msgid="2149102656120726855">"Frec datos se reduce a <xliff:g id="USED">%1$d</xliff:g> Kb/s si se supera límite uso datos"</string>
     <string name="throttle_help_subtext" msgid="5217706521499010816">"Más información sobre política de uso de datos móviles de tu operador"</string>
     <string name="cell_broadcast_sms" msgid="5584192824053625842">"SMS de difusión móvil"</string>
diff --git a/res/values-th/strings.xml b/res/values-th/strings.xml
index e937887..4ac8e26 100644
--- a/res/values-th/strings.xml
+++ b/res/values-th/strings.xml
@@ -131,7 +131,7 @@
     <string name="stk_cc_ss_to_dial_error" msgid="2816779198916570502">"คำขอ SS ที่แก้ไขเป็นคำขอ DIAL"</string>
     <string name="stk_cc_ss_to_ussd_error" msgid="7490626178582654236">"คำขอ SS ที่แก้ไขเป็นคำขอ USSD"</string>
     <string name="stk_cc_ss_to_ss_error" msgid="5057846756489053759">"คำขอ SS ที่แก้ไขเป็นคำขอ SS ใหม่"</string>
-    <string name="fdn_check_failure" msgid="18200614306525434">"เนื่องจากมีการเปิดใช้การตั้งค่าการจำกัดหมายเลขโทรออกของแอปโทรศัพท์ จึงเป็นผลให้คุณลักษณะที่เกี่ยวกับการโทรบางอย่างไม่ทำงาน"</string>
+    <string name="fdn_check_failure" msgid="18200614306525434">"เนื่องจากมีการเปิดใช้การตั้งค่าการจำกัดหมายเลขโทรออกของแอปโทรศัพท์ จึงเป็นผลให้ฟีเจอร์ที่เกี่ยวกับการโทรบางอย่างไม่ทำงาน"</string>
     <string name="radio_off_error" msgid="2304459933248513376">"เปิดวิทยุก่อนดูการตั้งค่าเหล่านี้"</string>
     <string name="close_dialog" msgid="2365884406356986917">"ตกลง"</string>
     <string name="enable" msgid="7248657275000173526">"เปิด"</string>
diff --git a/res/values-uz/strings.xml b/res/values-uz/strings.xml
index f6d3934..f2d09d9 100644
--- a/res/values-uz/strings.xml
+++ b/res/values-uz/strings.xml
@@ -432,7 +432,7 @@
     <string name="card_title_dialing" msgid="5769417478498348054">"Chaqiruv"</string>
     <string name="card_title_redialing" msgid="8253487008234167266">"Qayta terilmoqda"</string>
     <string name="card_title_conf_call" msgid="1162980346189744501">"Konferensiya qo‘ng‘irog‘i"</string>
-    <string name="card_title_incoming_call" msgid="7364539451234646909">"Kiruvchi qo‘ng‘iroq"</string>
+    <string name="card_title_incoming_call" msgid="7364539451234646909">"Kiruvchi chaqiruv"</string>
     <string name="card_title_call_ended" msgid="5544730338889702298">"Chaqiruv tugadi"</string>
     <string name="card_title_on_hold" msgid="821463117892339942">"Kutish holatida"</string>
     <string name="card_title_hanging_up" msgid="3999101620995182450">"Suhbat tugatilmoqda"</string>
diff --git a/src/com/android/phone/MMIDialogActivity.java b/src/com/android/phone/MMIDialogActivity.java
index 165118b..4afa6be 100644
--- a/src/com/android/phone/MMIDialogActivity.java
+++ b/src/com/android/phone/MMIDialogActivity.java
@@ -32,6 +32,7 @@
 import com.android.internal.telephony.Phone;
 import com.android.internal.telephony.PhoneConstants;
 
+import java.util.ArrayList;
 import java.util.List;
 
 /**
@@ -88,7 +89,11 @@
     }
 
     private void showMMIDialog() {
-        final List<? extends MmiCode> codes = mPhone.getPendingMmiCodes();
+        final List<MmiCode> codes = new ArrayList<>(mPhone.getPendingMmiCodes());
+        // If the phone has an IMS phone, also get pending imS MMIsl.
+        if (mPhone.getImsPhone() != null) {
+            codes.addAll(mPhone.getImsPhone().getPendingMmiCodes());
+        }
         if (codes.size() > 0) {
             final MmiCode mmiCode = codes.get(0);
             final Message message = Message.obtain(mHandler, PhoneGlobals.MMI_CANCEL);
diff --git a/src/com/android/phone/NotificationMgr.java b/src/com/android/phone/NotificationMgr.java
index bc67fd5..31bca92 100644
--- a/src/com/android/phone/NotificationMgr.java
+++ b/src/com/android/phone/NotificationMgr.java
@@ -81,6 +81,15 @@
     private static final String MWI_SHOULD_CHECK_VVM_CONFIGURATION_KEY_PREFIX =
             "mwi_should_check_vvm_configuration_state_";
 
+    /**
+     * Boolean value representing whether the {@link
+     * TelephonyManager#ACTION_SHOW_VOICEMAIL_NOTIFICATION} is new or a refresh of an existing
+     * notification.
+     *
+     * TODO(b/62202833): make public
+     */
+    private static final String EXTRA_IS_REFRESH = "is_refresh";
+
     // notification types
     static final int MMI_NOTIFICATION = 1;
     static final int NETWORK_SELECTION_NOTIFICATION = 2;
@@ -196,7 +205,7 @@
         if (mMwiVisible.containsKey(subId)) {
             boolean mwiVisible = mMwiVisible.get(subId);
             if (mwiVisible) {
-                updateMwi(subId, mwiVisible, false /* enableNotificationSound */);
+                updateMwi(subId, mwiVisible, true /* isRefresh */);
             }
         }
     }
@@ -228,7 +237,7 @@
      * @param visible true if there are messages waiting
      */
     /* package */ void updateMwi(int subId, boolean visible) {
-        updateMwi(subId, visible, true /* enableNotificationSound */);
+        updateMwi(subId, visible, false /* isRefresh */);
     }
 
     /**
@@ -236,9 +245,10 @@
      *
      * @param subId the subId to update.
      * @param visible true if there are messages waiting
-     * @param enableNotificationSound {@code true} if the notification sound should be played.
+     * @param isRefresh {@code true} if the notification is a refresh and the user should not be
+     * notified again.
      */
-    void updateMwi(int subId, boolean visible, boolean enableNotificationSound) {
+    void updateMwi(int subId, boolean visible, boolean isRefresh) {
         if (!PhoneGlobals.sVoiceCapable) {
             // Do not show the message waiting indicator on devices which are not voice capable.
             // These events *should* be blocked at the telephony layer for such devices.
@@ -345,7 +355,8 @@
                     .setColor(res.getColor(R.color.dialer_theme_color))
                     .setOngoing(carrierConfig.getBoolean(
                             CarrierConfigManager.KEY_VOICEMAIL_NOTIFICATION_PERSISTENT_BOOL))
-                    .setChannel(NotificationChannelController.CHANNEL_ID_VOICE_MAIL);
+                    .setChannel(NotificationChannelController.CHANNEL_ID_VOICE_MAIL)
+                    .setOnlyAlertOnce(isRefresh);
 
             final Notification notification = builder.build();
             List<UserInfo> users = mUserManager.getUsers(true);
@@ -356,7 +367,7 @@
                         UserManager.DISALLOW_OUTGOING_CALLS, userHandle)
                         && !user.isManagedProfile()) {
                     if (!maybeSendVoicemailNotificationUsingDefaultDialer(phone, vmCount, vmNumber,
-                            pendingIntent, isSettingsIntent, userHandle)) {
+                            pendingIntent, isSettingsIntent, userHandle, isRefresh)) {
                         mNotificationManager.notifyAsUser(
                                 Integer.toString(subId) /* tag */,
                                 VOICEMAIL_NOTIFICATION,
@@ -374,7 +385,7 @@
                         UserManager.DISALLOW_OUTGOING_CALLS, userHandle)
                         && !user.isManagedProfile()) {
                     if (!maybeSendVoicemailNotificationUsingDefaultDialer(phone, 0, null, null,
-                            false, userHandle)) {
+                            false, userHandle, isRefresh)) {
                         mNotificationManager.cancelAsUser(
                                 Integer.toString(subId) /* tag */,
                                 VOICEMAIL_NOTIFICATION,
@@ -403,7 +414,7 @@
      */
     private boolean maybeSendVoicemailNotificationUsingDefaultDialer(Phone phone, Integer count,
             String number, PendingIntent pendingIntent, boolean isSettingsIntent,
-            UserHandle userHandle) {
+            UserHandle userHandle, boolean isRefresh) {
 
         if (shouldManageNotificationThroughDefaultDialer(userHandle)) {
             Intent intent = getShowVoicemailIntentForDefaultDialer(userHandle);
@@ -411,6 +422,7 @@
             intent.setAction(TelephonyManager.ACTION_SHOW_VOICEMAIL_NOTIFICATION);
             intent.putExtra(TelephonyManager.EXTRA_PHONE_ACCOUNT_HANDLE,
                     PhoneUtils.makePstnPhoneAccountHandle(phone));
+            intent.putExtra(EXTRA_IS_REFRESH, isRefresh);
             if (count != null) {
                 intent.putExtra(TelephonyManager.EXTRA_NOTIFICATION_COUNT, count);
             }
diff --git a/src/com/android/phone/PhoneInterfaceManager.java b/src/com/android/phone/PhoneInterfaceManager.java
index cf80a11..92da36f 100644
--- a/src/com/android/phone/PhoneInterfaceManager.java
+++ b/src/com/android/phone/PhoneInterfaceManager.java
@@ -96,11 +96,10 @@
 import com.android.internal.telephony.uicc.UiccCard;
 import com.android.internal.telephony.uicc.UiccCardApplication;
 import com.android.internal.telephony.uicc.UiccController;
+import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
 import com.android.internal.util.HexDump;
-import com.android.phone.settings.VoicemailNotificationSettingsUtil;
 import com.android.phone.vvm.PhoneAccountHandleConverter;
 import com.android.phone.vvm.RemoteVvmTaskManager;
-import com.android.phone.vvm.VisualVoicemailPreferences;
 import com.android.phone.vvm.VisualVoicemailSettingsUtil;
 import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
 
@@ -3456,7 +3455,7 @@
             phone = mPhone;
         }
 
-        return VoicemailNotificationSettingsUtil.getRingtoneUri(phone);
+        return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
     }
 
     /**
@@ -3483,7 +3482,7 @@
         if (phone == null){
            phone = mPhone;
         }
-        VoicemailNotificationSettingsUtil.setRingtoneUri(phone, uri);
+        VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
     }
 
     /**
@@ -3500,7 +3499,7 @@
             phone = mPhone;
         }
 
-        return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone);
+        return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
     }
 
     /**
@@ -3528,7 +3527,7 @@
         if (phone == null){
             phone = mPhone;
         }
-        VoicemailNotificationSettingsUtil.setVibrationEnabled(phone, enabled);
+        VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
     }
 
     /**
diff --git a/src/com/android/phone/settings/VoicemailNotificationSettingsUtil.java b/src/com/android/phone/settings/VoicemailNotificationSettingsUtil.java
deleted file mode 100644
index fb7baf5..0000000
--- a/src/com/android/phone/settings/VoicemailNotificationSettingsUtil.java
+++ /dev/null
@@ -1,148 +0,0 @@
-/*
- * Copyright (C) 2014 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.phone.settings;
-
-import android.app.NotificationChannel;
-import android.content.SharedPreferences;
-import android.net.Uri;
-import android.preference.PreferenceManager;
-import android.telephony.TelephonyManager;
-
-import com.android.internal.telephony.Phone;
-import com.android.internal.telephony.util.NotificationChannelController;
-import com.android.phone.R;
-
-public class VoicemailNotificationSettingsUtil {
-    private static final String VOICEMAIL_NOTIFICATION_RINGTONE_SHARED_PREFS_KEY_PREFIX =
-            "voicemail_notification_ringtone_";
-    private static final String VOICEMAIL_NOTIFICATION_VIBRATION_SHARED_PREFS_KEY_PREFIX =
-            "voicemail_notification_vibrate_";
-
-    // Old voicemail notification vibration string constants used for migration.
-    private static final String OLD_VOICEMAIL_NOTIFICATION_RINGTONE_SHARED_PREFS_KEY =
-            "button_voicemail_notification_ringtone_key";
-    private static final String OLD_VOICEMAIL_NOTIFICATION_VIBRATION_SHARED_PREFS_KEY =
-            "button_voicemail_notification_vibrate_key";
-    private static final String OLD_VOICEMAIL_VIBRATE_WHEN_SHARED_PREFS_KEY =
-            "button_voicemail_notification_vibrate_when_key";
-    private static final String OLD_VOICEMAIL_RINGTONE_SHARED_PREFS_KEY =
-            "button_voicemail_notification_ringtone_key";
-    private static final String OLD_VOICEMAIL_VIBRATION_ALWAYS = "always";
-    private static final String OLD_VOICEMAIL_VIBRATION_NEVER = "never";
-
-    public static void setVibrationEnabled(Phone phone, boolean isEnabled) {
-        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(phone.getContext());
-        SharedPreferences.Editor editor = prefs.edit();
-        editor.putBoolean(getVoicemailVibrationSharedPrefsKey(phone), isEnabled);
-        editor.commit();
-    }
-
-    public static boolean isVibrationEnabled(Phone phone) {
-        final NotificationChannel channel = NotificationChannelController.getChannel(
-                NotificationChannelController.CHANNEL_ID_VOICE_MAIL, phone.getContext());
-        return (channel != null) ? channel.shouldVibrate() : false;
-    }
-
-   public static void setRingtoneUri(Phone phone, Uri ringtoneUri) {
-        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(phone.getContext());
-        String ringtoneUriStr = ringtoneUri != null ? ringtoneUri.toString() : "";
-
-        SharedPreferences.Editor editor = prefs.edit();
-        editor.putString(getVoicemailRingtoneSharedPrefsKey(phone), ringtoneUriStr);
-        editor.commit();
-    }
-
-    public static Uri getRingtoneUri(Phone phone) {
-        final NotificationChannel channel = NotificationChannelController.getChannel(
-                NotificationChannelController.CHANNEL_ID_VOICE_MAIL, phone.getContext());
-        return (channel != null) ? channel.getSound() : null;
-    }
-
-    /**
-     * Migrate voicemail settings from {@link #OLD_VIBRATE_WHEN_KEY} or
-     * {@link #OLD_VOICEMAIL_NOTIFICATION_VIBRATE_KEY}.
-     *
-     * TODO: Add helper which migrates settings from old version to new version.
-     */
-    private static void migrateVoicemailVibrationSettingsIfNeeded(
-            Phone phone, SharedPreferences prefs) {
-        String key = getVoicemailVibrationSharedPrefsKey(phone);
-        TelephonyManager telephonyManager = TelephonyManager.from(phone.getContext());
-
-        // Skip if a preference exists, or if phone is MSIM.
-        if (prefs.contains(key) || telephonyManager.getPhoneCount() != 1) {
-            return;
-        }
-
-        if (prefs.contains(OLD_VOICEMAIL_NOTIFICATION_VIBRATION_SHARED_PREFS_KEY)) {
-            boolean voicemailVibrate = prefs.getBoolean(
-                    OLD_VOICEMAIL_NOTIFICATION_VIBRATION_SHARED_PREFS_KEY, false /* defValue */);
-
-            SharedPreferences.Editor editor = prefs.edit();
-            editor.putBoolean(key, voicemailVibrate)
-                    .remove(OLD_VOICEMAIL_VIBRATE_WHEN_SHARED_PREFS_KEY)
-                    .commit();
-        }
-
-        if (prefs.contains(OLD_VOICEMAIL_VIBRATE_WHEN_SHARED_PREFS_KEY)) {
-            // If vibrateWhen is always, then voicemailVibrate should be true.
-            // If it is "only in silent mode", or "never", then voicemailVibrate should be false.
-            String vibrateWhen = prefs.getString(
-                    OLD_VOICEMAIL_VIBRATE_WHEN_SHARED_PREFS_KEY, OLD_VOICEMAIL_VIBRATION_NEVER);
-            boolean voicemailVibrate = vibrateWhen.equals(OLD_VOICEMAIL_VIBRATION_ALWAYS);
-
-            SharedPreferences.Editor editor = prefs.edit();
-            editor.putBoolean(key, voicemailVibrate)
-                    .remove(OLD_VOICEMAIL_NOTIFICATION_VIBRATION_SHARED_PREFS_KEY)
-                    .commit();
-        }
-    }
-
-    /**
-     * Migrate voicemail settings from OLD_VOICEMAIL_NOTIFICATION_RINGTONE_SHARED_PREFS_KEY.
-     *
-     * TODO: Add helper which migrates settings from old version to new version.
-     */
-    private static void migrateVoicemailRingtoneSettingsIfNeeded(
-            Phone phone, SharedPreferences prefs) {
-        String key = getVoicemailRingtoneSharedPrefsKey(phone);
-        TelephonyManager telephonyManager = TelephonyManager.from(phone.getContext());
-
-        // Skip if a preference exists, or if phone is MSIM.
-        if (prefs.contains(key) || telephonyManager.getPhoneCount() != 1) {
-            return;
-        }
-
-        if (prefs.contains(OLD_VOICEMAIL_NOTIFICATION_RINGTONE_SHARED_PREFS_KEY)) {
-            String uriString = prefs.getString(
-                    OLD_VOICEMAIL_NOTIFICATION_RINGTONE_SHARED_PREFS_KEY, null /* defValue */);
-
-            SharedPreferences.Editor editor = prefs.edit();
-            editor.putString(key, uriString)
-                    .remove(OLD_VOICEMAIL_NOTIFICATION_RINGTONE_SHARED_PREFS_KEY)
-                    .commit();
-        }
-    }
-
-    private static String getVoicemailVibrationSharedPrefsKey(Phone phone) {
-        return VOICEMAIL_NOTIFICATION_VIBRATION_SHARED_PREFS_KEY_PREFIX + phone.getSubId();
-    }
-
-    public static String getVoicemailRingtoneSharedPrefsKey(Phone phone) {
-        return VOICEMAIL_NOTIFICATION_RINGTONE_SHARED_PREFS_KEY_PREFIX + phone.getSubId();
-    }
-}
diff --git a/src/com/android/services/telephony/CdmaConnection.java b/src/com/android/services/telephony/CdmaConnection.java
index 29ccc6c..ffa9dbc 100644
--- a/src/com/android/services/telephony/CdmaConnection.java
+++ b/src/com/android/services/telephony/CdmaConnection.java
@@ -65,7 +65,6 @@
      * {@code True} if the CDMA connection should allow mute.
      */
     private boolean mAllowMute;
-    private final boolean mIsOutgoing;
     // Queue of pending short-DTMF characters.
     private final Queue<Character> mDtmfQueue = new LinkedList<>();
     private final EmergencyTonePlayer mEmergencyTonePlayer;
@@ -80,10 +79,9 @@
             boolean allowMute,
             boolean isOutgoing,
             String telecomCallId) {
-        super(connection, telecomCallId);
+        super(connection, telecomCallId, isOutgoing);
         mEmergencyTonePlayer = emergencyTonePlayer;
         mAllowMute = allowMute;
-        mIsOutgoing = isOutgoing;
         mIsCallWaiting = connection != null && connection.getState() == Call.State.WAITING;
         boolean isImsCall = getOriginalConnection() instanceof ImsPhoneConnection;
         // Start call waiting timer for CDMA waiting call.
diff --git a/src/com/android/services/telephony/GsmConnection.java b/src/com/android/services/telephony/GsmConnection.java
index c480baa..ca547fa 100644
--- a/src/com/android/services/telephony/GsmConnection.java
+++ b/src/com/android/services/telephony/GsmConnection.java
@@ -22,8 +22,8 @@
  * Manages a single phone call handled by GSM.
  */
 final class GsmConnection extends TelephonyConnection {
-    GsmConnection(Connection connection, String telecomCallId) {
-        super(connection, telecomCallId);
+    GsmConnection(Connection connection, String telecomCallId, boolean isOutgoing) {
+        super(connection, telecomCallId, isOutgoing);
     }
 
     /**
@@ -36,7 +36,7 @@
     @Override
     public TelephonyConnection cloneConnection() {
         GsmConnection gsmConnection = new GsmConnection(getOriginalConnection(),
-                getTelecomCallId());
+                getTelecomCallId(), mIsOutgoing);
         return gsmConnection;
     }
 
diff --git a/src/com/android/services/telephony/ImsConference.java b/src/com/android/services/telephony/ImsConference.java
index c5a0896..603c3f4 100644
--- a/src/com/android/services/telephony/ImsConference.java
+++ b/src/com/android/services/telephony/ImsConference.java
@@ -879,7 +879,8 @@
 
             if (mConferenceHost.getPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_GSM) {
                 Log.i(this,"handleOriginalConnectionChange : SRVCC to GSM");
-                GsmConnection c = new GsmConnection(originalConnection, getTelecomCallId());
+                GsmConnection c = new GsmConnection(originalConnection, getTelecomCallId(),
+                        mConferenceHost.isOutgoingCall());
                 // This is a newly created conference connection as a result of SRVCC
                 c.setConferenceSupported(true);
                 c.addCapability(Connection.CAPABILITY_CONFERENCE_HAS_NO_CHILDREN);
diff --git a/src/com/android/services/telephony/PstnPhoneCapabilitiesNotifier.java b/src/com/android/services/telephony/PstnPhoneCapabilitiesNotifier.java
index eb6f7f6..e557919 100644
--- a/src/com/android/services/telephony/PstnPhoneCapabilitiesNotifier.java
+++ b/src/com/android/services/telephony/PstnPhoneCapabilitiesNotifier.java
@@ -90,10 +90,10 @@
     private void handleVideoCapabilitesChanged(AsyncResult ar) {
         try {
             boolean isVideoCapable = (Boolean) ar.result;
-            Log.d(this, "handleVideoCapabilitesChanged. Video capability - " + isVideoCapable);
+            Log.i(this, "handleVideoCapabilitesChanged. Video capability - " + isVideoCapable);
             mListener.onVideoCapabilitiesChanged(isVideoCapable);
         } catch (Exception e) {
-            Log.d(this, "handleVideoCapabilitesChanged. Exception=" + e);
+            Log.w(this, "handleVideoCapabilitesChanged. Exception=" + e);
         }
     }
 
diff --git a/src/com/android/services/telephony/TelephonyConnection.java b/src/com/android/services/telephony/TelephonyConnection.java
index 5ae1a26..66a858a 100644
--- a/src/com/android/services/telephony/TelephonyConnection.java
+++ b/src/com/android/services/telephony/TelephonyConnection.java
@@ -151,7 +151,8 @@
                     break;
                 case MSG_SUPP_SERVICE_NOTIFY:
                     Log.v(TelephonyConnection.this, "MSG_SUPP_SERVICE_NOTIFY on phoneId : "
-                            +getPhone().getPhoneId());
+                            + getPhone() != null ? Integer.toString(getPhone().getPhoneId())
+                            : "null");
                     SuppServiceNotification mSsNotification = null;
                     if (msg.obj != null && ((AsyncResult) msg.obj).result != null) {
                         mSsNotification =
@@ -484,13 +485,19 @@
     private boolean mIsCdmaVoicePrivacyEnabled;
 
     /**
+     * Indicates whether this call is an outgoing call.
+     */
+    protected final boolean mIsOutgoing;
+
+    /**
      * Listeners to our TelephonyConnection specific callbacks
      */
     private final Set<TelephonyConnectionListener> mTelephonyListeners = Collections.newSetFromMap(
             new ConcurrentHashMap<TelephonyConnectionListener, Boolean>(8, 0.9f, 1));
 
     protected TelephonyConnection(com.android.internal.telephony.Connection originalConnection,
-            String callId) {
+            String callId, boolean isOutgoingCall) {
+        mIsOutgoing = isOutgoingCall;
         setTelecomCallId(callId);
         if (originalConnection != null) {
             setOriginalConnection(originalConnection);
@@ -1513,6 +1520,13 @@
     }
 
     /**
+     * @return {@code true} if this is an outgoing call, {@code false} otherwise.
+     */
+    boolean isOutgoingCall() {
+        return mIsOutgoing;
+    }
+
+    /**
      * Sets the current call audio quality. Used during rebuild of the properties
      * to set or unset the {@link Connection#PROPERTY_HIGH_DEF_AUDIO} property.
      *
@@ -1701,7 +1715,7 @@
         boolean isVoWifiEnabled = false;
         if (isIms) {
             ImsPhone imsPhone = (ImsPhone) phone;
-            isVoWifiEnabled = imsPhone.isWifiCallingEnabled();
+            isVoWifiEnabled = ImsUtil.isWfcEnabled(phone.getContext());
         }
         PhoneAccountHandle phoneAccountHandle = isIms ? PhoneUtils
                 .makePstnPhoneAccountHandle(phone.getDefaultPhone())
diff --git a/src/com/android/services/telephony/TelephonyConnectionService.java b/src/com/android/services/telephony/TelephonyConnectionService.java
index d25cebe..b9d0196 100644
--- a/src/com/android/services/telephony/TelephonyConnectionService.java
+++ b/src/com/android/services/telephony/TelephonyConnectionService.java
@@ -963,7 +963,7 @@
         TelephonyConnection returnConnection = null;
         int phoneType = phone.getPhoneType();
         if (phoneType == TelephonyManager.PHONE_TYPE_GSM) {
-            returnConnection = new GsmConnection(originalConnection, telecomCallId);
+            returnConnection = new GsmConnection(originalConnection, telecomCallId, isOutgoing);
         } else if (phoneType == TelephonyManager.PHONE_TYPE_CDMA) {
             boolean allowsMute = allowsMute(phone);
             returnConnection = new CdmaConnection(originalConnection, mEmergencyTonePlayer,
@@ -1250,12 +1250,22 @@
                 TelecomManager.TTY_MODE_OFF) != TelecomManager.TTY_MODE_OFF);
     }
 
+    /**
+     * For outgoing dialed calls, potentially send a ConnectionEvent if the user is on WFC and is
+     * dialing an international number.
+     * @param telephonyConnection The connection.
+     */
     private void maybeSendInternationalCallEvent(TelephonyConnection telephonyConnection) {
+        if (telephonyConnection == null || telephonyConnection.getPhone() == null ||
+                telephonyConnection.getPhone().getDefaultPhone() == null) {
+            return;
+        }
         Phone phone = telephonyConnection.getPhone().getDefaultPhone();
         if (phone instanceof GsmCdmaPhone) {
             GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
-            if (gsmCdmaPhone.isNotificationOfWfcCallRequired(
-                    telephonyConnection.getOriginalConnection().getOrigDialString())) {
+            if (telephonyConnection.isOutgoingCall() &&
+                    gsmCdmaPhone.isNotificationOfWfcCallRequired(
+                            telephonyConnection.getOriginalConnection().getOrigDialString())) {
                 // Send connection event to InCall UI to inform the user of the fact they
                 // are potentially placing an international call on WFC.
                 Log.i(this, "placeOutgoingConnection - sending international call on WFC " +
diff --git a/tests/src/com/android/services/telephony/MockTelephonyConnection.java b/tests/src/com/android/services/telephony/MockTelephonyConnection.java
index b2d6ed8..634cbb5 100644
--- a/tests/src/com/android/services/telephony/MockTelephonyConnection.java
+++ b/tests/src/com/android/services/telephony/MockTelephonyConnection.java
@@ -45,7 +45,7 @@
     }
 
     public MockTelephonyConnection() {
-        super(null, null);
+        super(null, null, false);
         MockitoAnnotations.initMocks(this);
 
         // Set up mMockRadioConnection and mMockPhone to contain an active call