Merge "Import translations. DO NOT MERGE"
diff --git a/src/com/android/phone/CallFeaturesSetting.java b/src/com/android/phone/CallFeaturesSetting.java
index a6d54ef..81e893e 100644
--- a/src/com/android/phone/CallFeaturesSetting.java
+++ b/src/com/android/phone/CallFeaturesSetting.java
@@ -25,7 +25,9 @@
 import android.content.Context;
 import android.content.DialogInterface;
 import android.content.Intent;
+import android.content.pm.ApplicationInfo;
 import android.content.pm.PackageManager;
+import android.content.pm.PackageManager.NameNotFoundException;
 import android.content.pm.ResolveInfo;
 import android.os.Bundle;
 import android.os.PersistableBundle;
@@ -230,6 +232,8 @@
         mVoicemailSettingsScreen.setIntent(mSubscriptionInfoHelper.getIntent(
                 VoicemailSettingsActivity.class));
 
+        maybeHideVoicemailSettings();
+
         mButtonAutoRetry = (CheckBoxPreference) findPreference(BUTTON_RETRY_KEY);
 
         mEnableVideoCalling = (CheckBoxPreference) findPreference(ENABLE_VIDEO_CALLING_KEY);
@@ -350,6 +354,38 @@
         }
     }
 
+    /**
+     * Hides the top level voicemail settings entry point if the default dialer contains a
+     * particular manifest metadata key. This is required when the default dialer wants to display
+     * its own version of voicemail settings.
+     */
+    private void maybeHideVoicemailSettings() {
+        String defaultDialer = getSystemService(TelecomManager.class).getDefaultDialerPackage();
+        if (defaultDialer == null) {
+            return;
+        }
+        try {
+            Bundle metadata = getPackageManager()
+                    .getApplicationInfo(defaultDialer, PackageManager.GET_META_DATA).metaData;
+            if (!metadata
+                    .getBoolean(TelephonyManager.METADATA_HIDE_VOICEMAIL_SETTINGS_MENU, false)) {
+                if (DBG) {
+                    log("maybeHideVoicemailSettings(): not disabled by default dialer");
+                }
+                return;
+            }
+            getPreferenceScreen().removePreference(mVoicemailSettingsScreen);
+            if (DBG) {
+                log("maybeHideVoicemailSettings(): disabled by default dialer");
+            }
+        } catch (NameNotFoundException e) {
+            // do nothing
+            if (DBG) {
+                log("maybeHideVoicemailSettings(): not controlled by default dialer");
+            }
+        }
+    }
+
     @Override
     protected void onNewIntent(Intent newIntent) {
         setIntent(newIntent);
diff --git a/src/com/android/phone/PhoneInterfaceManager.java b/src/com/android/phone/PhoneInterfaceManager.java
index 0e4361a..81e6abc 100644
--- a/src/com/android/phone/PhoneInterfaceManager.java
+++ b/src/com/android/phone/PhoneInterfaceManager.java
@@ -19,6 +19,7 @@
 import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
 
 import android.Manifest.permission;
+import android.annotation.Nullable;
 import android.app.ActivityManager;
 import android.app.AppOpsManager;
 import android.app.PendingIntent;
@@ -1968,6 +1969,17 @@
     }
 
     @Override
+    public String getVisualVoicemailPackageName(String callingPackage,
+            @Nullable PhoneAccountHandle phoneAccountHandle) {
+        mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
+        if (!canReadPhoneState(callingPackage, "getVisualVoicemailPackageName")) {
+            return null;
+        }
+        int subId = PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
+        return RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId).getPackageName();
+    }
+
+    @Override
     public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
             VisualVoicemailSmsFilterSettings settings) {
         mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
diff --git a/src/com/android/phone/settings/VoicemailSettingsActivity.java b/src/com/android/phone/settings/VoicemailSettingsActivity.java
index 6bb481f..a911be6 100644
--- a/src/com/android/phone/settings/VoicemailSettingsActivity.java
+++ b/src/com/android/phone/settings/VoicemailSettingsActivity.java
@@ -31,6 +31,7 @@
 import android.preference.SwitchPreference;
 import android.provider.ContactsContract.CommonDataKinds;
 import android.telecom.PhoneAccountHandle;
+import android.telephony.TelephonyManager;
 import android.text.BidiFormatter;
 import android.text.TextDirectionHeuristics;
 import android.text.TextUtils;
@@ -264,6 +265,8 @@
                 getResources().getString(R.string.voicemail_notification_vibrate_key));
         mVoicemailNotificationVibrate.setOnPreferenceChangeListener(this);
 
+        maybeHidePublicSettings();
+
         mVoicemailVisualVoicemail = (SwitchPreference) findPreference(
                 getResources().getString(R.string.voicemail_visual_voicemail_key));
 
@@ -318,6 +321,23 @@
                 VoicemailNotificationSettingsUtil.isVibrationEnabled(mPhone));
     }
 
+    /**
+     * Hides a subset of voicemail settings if required by the intent extra. This is used by the
+     * default dialer to show "advanced" voicemail settings from its own custom voicemail settings
+     * UI.
+     */
+    private void maybeHidePublicSettings() {
+        if(!getIntent().getBooleanExtra(TelephonyManager.EXTRA_HIDE_PUBLIC_SETTINGS, false)){
+            return;
+        }
+        if (DBG) {
+            log("maybeHidePublicSettings: settings hidden by EXTRA_HIDE_PUBLIC_SETTINGS");
+        }
+        PreferenceScreen preferenceScreen = getPreferenceScreen();
+        preferenceScreen.removePreference(mVoicemailNotificationRingtone);
+        preferenceScreen.removePreference(mVoicemailNotificationVibrate);
+    }
+
     @Override
     public void onPause() {
         super.onPause();
diff --git a/src/com/android/phone/vvm/RemoteVvmTaskManager.java b/src/com/android/phone/vvm/RemoteVvmTaskManager.java
index 49b0a1c..f48fc7e 100644
--- a/src/com/android/phone/vvm/RemoteVvmTaskManager.java
+++ b/src/com/android/phone/vvm/RemoteVvmTaskManager.java
@@ -104,6 +104,7 @@
         return getRemotePackage(context, subId) != null;
     }
 
+    @Nullable
     public static ComponentName getRemotePackage(Context context, int subId) {
         Intent bindIntent = newBindIntent(context);
 
diff --git a/src/com/android/services/telephony/CdmaConferenceController.java b/src/com/android/services/telephony/CdmaConferenceController.java
index 0a7c18b..846df61 100644
--- a/src/com/android/services/telephony/CdmaConferenceController.java
+++ b/src/com/android/services/telephony/CdmaConferenceController.java
@@ -122,8 +122,18 @@
                 }
             }, ADD_OUTGOING_CONNECTION_DELAY_MILLIS);
         } else {
-            // This is the first connection, or it is incoming, so let it flow through.
-            addInternal(connection);
+            // Post the call to addInternal to the handler with no delay.
+            // Why you ask?  In TelephonyConnectionService#
+            // onCreateIncomingConnection(PhoneAccountHandle, ConnectionRequest) or
+            // TelephonyConnectionService#onCreateOutgoingConnection(PhoneAccountHandle,
+            // ConnectionRequest) we can create a new connection it will trigger a call to
+            // TelephonyConnectionService#addConnectionToConferenceController, which will cause us
+            // to get here.  HOWEVER, at this point ConnectionService#addConnection has not yet run,
+            // so if we end up calling ConnectionService#addConference, the connection service will
+            // not yet know about the new connection, so it won't get added to the conference.
+            // Posting to the handler ensures addConnection has a chance to happen before we add the
+            // conference.
+            mHandler.post(() -> addInternal(connection));
         }
     }