Implement getVisualVoicemailSettings()

This CL allow the system dialer to migrate voicemail settings from
telephony. The following values are provided:

"is_enabled": whether VVM is enabled before. The key will be
missing if the user never modified this setting and the default
should be used.

"default_old_pin": the voicemail PIN scrambled by the
provisioning process. For certain carriers the PIN must be set before
the voicemail feature can be used. Telephony had a automatic process
that will set a random PIN for the user and then prompt them to change
it. This must be migrated to the system dialer so the PIN will not be
lost after an upgrade.

Bug: 34093562
Test: N/A - pending dialer side changes to be implemented.

Change-Id: I037d1e7ec48eda7a0db282449b1c492e545e8930
diff --git a/src/com/android/phone/PhoneInterfaceManager.java b/src/com/android/phone/PhoneInterfaceManager.java
index 0e772ab..6b75ab5 100644
--- a/src/com/android/phone/PhoneInterfaceManager.java
+++ b/src/com/android/phone/PhoneInterfaceManager.java
@@ -19,7 +19,6 @@
 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;
@@ -95,7 +94,10 @@
 import com.android.internal.telephony.uicc.UiccController;
 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;
 
 import java.io.FileDescriptor;
@@ -2017,6 +2019,20 @@
     }
 
     @Override
+    public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
+        mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
+        String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage();
+        if (!TextUtils.equals(callingPackage, systemDialer)) {
+            throw new SecurityException("caller must be system dialer");
+        }
+        PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
+        if (phoneAccountHandle == null){
+            return null;
+        }
+        return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
+    }
+
+    @Override
     public String getVisualVoicemailPackageName(String callingPackage, int subId) {
         mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
         if (!canReadPhoneState(callingPackage, "getVisualVoicemailPackageName")) {
diff --git a/src/com/android/phone/vvm/VisualVoicemailSettingsUtil.java b/src/com/android/phone/vvm/VisualVoicemailSettingsUtil.java
index 6829daf..8215261 100644
--- a/src/com/android/phone/vvm/VisualVoicemailSettingsUtil.java
+++ b/src/com/android/phone/vvm/VisualVoicemailSettingsUtil.java
@@ -16,8 +16,9 @@
 package com.android.phone.vvm;
 
 import android.content.Context;
+import android.os.Bundle;
 import android.telecom.PhoneAccountHandle;
-import com.android.phone.R;
+import android.telephony.TelephonyManager;
 
 /**
  * Save whether or not a particular account is enabled in shared to be retrieved later.
@@ -26,39 +27,18 @@
 
     private static final String IS_ENABLED_KEY = "is_enabled";
 
+    private static final String DEFAULT_OLD_PIN_KEY = "default_old_pin";
 
-    public static void setEnabled(Context context, PhoneAccountHandle phoneAccount,
-            boolean isEnabled) {
-        new VisualVoicemailPreferences(context, phoneAccount).edit()
-                .putBoolean(IS_ENABLED_KEY, isEnabled)
-                .apply();
-    }
-
-    public static boolean isEnabled(Context context,
-            PhoneAccountHandle phoneAccount) {
-        if (phoneAccount == null) {
-            return false;
+    public static Bundle dump(Context context, PhoneAccountHandle phoneAccountHandle){
+        Bundle result = new Bundle();
+        VisualVoicemailPreferences prefs = new VisualVoicemailPreferences(context,
+                phoneAccountHandle);
+        if (prefs.contains(IS_ENABLED_KEY)) {
+            result.putBoolean(TelephonyManager.EXTRA_VISUAL_VOICEMAIL_ENABLED_BY_USER_BOOL,
+                    prefs.getBoolean(IS_ENABLED_KEY, false));
         }
-        if (!context.getResources().getBoolean(R.bool.allow_visual_voicemail)) {
-            return false;
-        }
-
-        VisualVoicemailPreferences prefs = new VisualVoicemailPreferences(context, phoneAccount);
-        return prefs.getBoolean(IS_ENABLED_KEY, false);
-    }
-
-    /**
-     * Whether the client enabled status is explicitly set by user or by default(Whether carrier VVM
-     * app is installed). This is used to determine whether to disable the client when the carrier
-     * VVM app is installed. If the carrier VVM app is installed the client should give priority to
-     * it if the settings are not touched.
-     */
-    public static boolean isEnabledUserSet(Context context,
-            PhoneAccountHandle phoneAccount) {
-        if (phoneAccount == null) {
-            return false;
-        }
-        VisualVoicemailPreferences prefs = new VisualVoicemailPreferences(context, phoneAccount);
-        return prefs.contains(IS_ENABLED_KEY);
+        result.putString(TelephonyManager.EXTRA_VOICEMAIL_SCRAMBLED_PIN_STRING,
+                prefs.getString(DEFAULT_OLD_PIN_KEY));
+        return result;
     }
 }