Reset voicemail status to disabled for not supported phone accounts

In some cases a phone account might have already written to the status
table, but the feature is later removed through changes in
CarrierConfig. Previously the VVM client will just stop handling the
account and the status will be stuck in the table. Sometimes it would
leave a error that which will be shown to the user forever.

After this CL, if the phone account has no VVM support, the status
table entry will be reset to the disabled state, which will make the
UI ignore the account.

Bug: 30314643
Change-Id: I0b67decd62d021de90d7d0ff0f5209e7f3e624ee
diff --git a/src/com/android/phone/VoicemailStatus.java b/src/com/android/phone/VoicemailStatus.java
index 2d8bcc3..c5cd52c 100644
--- a/src/com/android/phone/VoicemailStatus.java
+++ b/src/com/android/phone/VoicemailStatus.java
@@ -120,6 +120,18 @@
         return new Editor(context, PhoneAccountHandleConverter.fromSubId(subId));
     }
 
+    /**
+     * Reset the status to the "disabled" state, which the UI should not show anything for this
+     * subId.
+     */
+    public static void disable(Context context, int subId) {
+        edit(context, subId)
+                .setConfigurationState(Status.CONFIGURATION_STATE_NOT_CONFIGURED)
+                .setDataChannelState(Status.DATA_CHANNEL_STATE_NO_CONNECTION)
+                .setNotificationChannelState(Status.NOTIFICATION_CHANNEL_STATE_NO_CONNECTION)
+                .apply();
+    }
+
     public static DeferredEditor deferredEdit(Context context, int subId) {
         return new DeferredEditor(context, PhoneAccountHandleConverter.fromSubId(subId));
     }
diff --git a/src/com/android/phone/vvm/omtp/ActivationTask.java b/src/com/android/phone/vvm/omtp/ActivationTask.java
index 5998950..aa262c0 100644
--- a/src/com/android/phone/vvm/omtp/ActivationTask.java
+++ b/src/com/android/phone/vvm/omtp/ActivationTask.java
@@ -127,6 +127,11 @@
         int subId = getSubId();
 
         OmtpVvmCarrierConfigHelper helper = new OmtpVvmCarrierConfigHelper(getContext(), subId);
+        if (!helper.isValid()) {
+            VvmLog.i(TAG, "VVM not supported on subId " + subId);
+            VoicemailStatus.disable(getContext(), subId);
+            return;
+        }
         PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
         if (!OmtpVvmSourceManager.getInstance(getContext())
                 .isVvmSourceRegistered(phoneAccountHandle)) {
diff --git a/src/com/android/phone/vvm/omtp/SimChangeReceiver.java b/src/com/android/phone/vvm/omtp/SimChangeReceiver.java
index 92bca53..ea7dfa6 100644
--- a/src/com/android/phone/vvm/omtp/SimChangeReceiver.java
+++ b/src/com/android/phone/vvm/omtp/SimChangeReceiver.java
@@ -29,6 +29,7 @@
 import com.android.internal.telephony.IccCardConstants;
 import com.android.internal.telephony.PhoneConstants;
 import com.android.internal.telephony.TelephonyIntents;
+import com.android.phone.VoicemailStatus;
 import com.android.phone.settings.VisualVoicemailSettingsUtil;
 import com.android.phone.vvm.omtp.sync.OmtpVvmSourceManager;
 import com.android.phone.vvm.omtp.utils.PhoneAccountHandleConverter;
@@ -109,6 +110,7 @@
             String mccMnc = context.getSystemService(TelephonyManager.class).getSimOperator(subId);
             VvmLog.d(TAG,
                     "visual voicemail not supported for carrier " + mccMnc + " on subId " + subId);
+            VoicemailStatus.disable(context, subId);
         }
     }