Disable MWI suppression if VVM cannot be activated

MWI is the traditional voicemail notification which should be suppressed
if visual voicemail is active. NotificationMgr.updateMwi() currently
checks the CONFIGURATION_STATE to suppress the MWI, but there are several
issues. b/31229016 is a bug that when the device boots the configuration
state will be cleared and the MWI for voicemail that arrives when the
device is offline will be cleared, even if the account cannot be
activated. A full solution will be adding a setMwiEnabled() method and
stop checking the configuration state, but that is too risky at this
moment (ag/1467545). This is a temporary workaround to shut down the
configuration state check if visual voicemail cannot be activated.

+ Don't clear MWI when signal is restored. Checking the notification
  state to hide MWI is obsolete in ag/1333776

Change-Id: I03b7e5cde2aa7ad4c1a31526eaf63d6832717e0a
Fixes: 31229016
diff --git a/src/com/android/phone/NotificationMgr.java b/src/com/android/phone/NotificationMgr.java
index 9504f34..d40b08e 100644
--- a/src/com/android/phone/NotificationMgr.java
+++ b/src/com/android/phone/NotificationMgr.java
@@ -47,11 +47,13 @@
 import android.util.ArrayMap;
 import android.util.Log;
 import android.widget.Toast;
+
 import com.android.internal.telephony.Phone;
 import com.android.internal.telephony.TelephonyCapabilities;
 import com.android.phone.settings.VoicemailNotificationSettingsUtil;
 import com.android.phone.settings.VoicemailSettingsActivity;
 import com.android.phone.vvm.omtp.sync.VoicemailStatusQueryHelper;
+
 import java.util.Iterator;
 import java.util.List;
 import java.util.Set;
@@ -72,6 +74,9 @@
     // Do not check in with VDBG = true, since that may write PII to the system log.
     private static final boolean VDBG = false;
 
+    private static final String MWI_SHOULD_CHECK_VVM_CONFIGURATION_KEY_PREFIX =
+            "mwi_should_check_vvm_configuration_state_";
+
     // notification types
     static final int MMI_NOTIFICATION = 1;
     static final int NETWORK_SELECTION_NOTIFICATION = 2;
@@ -201,6 +206,27 @@
         }
     }
 
+    public void setShouldCheckVisualVoicemailConfigurationForMwi(int subId, boolean enabled) {
+        if (!SubscriptionManager.isValidSubscriptionId(subId)) {
+            Log.e(LOG_TAG, "setShouldCheckVisualVoicemailConfigurationForMwi: invalid subId"
+                    + subId);
+            return;
+        }
+
+        PreferenceManager.getDefaultSharedPreferences(mContext).edit()
+                .putBoolean(MWI_SHOULD_CHECK_VVM_CONFIGURATION_KEY_PREFIX + subId, enabled)
+                .apply();
+    }
+
+    private boolean shouldCheckVisualVoicemailConfigurationForMwi(int subId) {
+        if (!SubscriptionManager.isValidSubscriptionId(subId)) {
+            Log.e(LOG_TAG, "shouldCheckVisualVoicemailConfigurationForMwi: invalid subId" + subId);
+            return true;
+        }
+        return PreferenceManager
+                .getDefaultSharedPreferences(mContext)
+                .getBoolean(MWI_SHOULD_CHECK_VVM_CONFIGURATION_KEY_PREFIX + subId, true);
+    }
     /**
      * Updates the message waiting indicator (voicemail) notification.
      *
@@ -226,7 +252,7 @@
         }
 
         Phone phone = PhoneGlobals.getPhone(subId);
-        if (visible && phone != null) {
+        if (visible && phone != null && shouldCheckVisualVoicemailConfigurationForMwi(subId)) {
             VoicemailStatusQueryHelper queryHelper = new VoicemailStatusQueryHelper(mContext);
             PhoneAccountHandle phoneAccount = PhoneUtils.makePstnPhoneAccountHandle(phone);
             if (queryHelper.isVoicemailSourceConfigured(phoneAccount)) {