Handle alternative form VVM SMS as legacy notification if the account is not activated yet.

On VVM3 if subscription failed, the alternative form SMS will still be sent by the carrier. In this state dialer should fallback to legacy voicemail notification.

TEST=manual - disable auto subscription in code, check legacy voicemail notification functionality.
Bug: 109896901
Test: manual - disable auto subscription in code, check legacy voicemail notification functionality.
PiperOrigin-RevId: 200113818
Change-Id: I55b70e7a8b2cd3d8b40864fa03b2ba209037f4e8
diff --git a/java/com/android/voicemail/impl/OmtpConstants.java b/java/com/android/voicemail/impl/OmtpConstants.java
index d94e361..c04f5e2 100644
--- a/java/com/android/voicemail/impl/OmtpConstants.java
+++ b/java/com/android/voicemail/impl/OmtpConstants.java
@@ -244,4 +244,9 @@
   private static final String truncate(String string, int length) {
     return string.substring(0, Math.min(length, string.length()));
   }
+
+  // Alternative form of sync message: MBOXUPDATE?m=<new_message_count>;<key>=<value>;
+
+  public static final String ALTERNATIVE_MAILBOX_UPDATE = "MBOXUPDATE";
+  public static final String ALTERNATIVE_NUM_MESSAGE_COUNT = "m";
 }
diff --git a/java/com/android/voicemail/impl/sms/LegacyModeSmsHandler.java b/java/com/android/voicemail/impl/sms/LegacyModeSmsHandler.java
index 3608c36..29d376b 100644
--- a/java/com/android/voicemail/impl/sms/LegacyModeSmsHandler.java
+++ b/java/com/android/voicemail/impl/sms/LegacyModeSmsHandler.java
@@ -62,11 +62,21 @@
         case OmtpConstants.NEW_MESSAGE:
         case OmtpConstants.MAILBOX_UPDATE:
           sendLegacyVoicemailNotification(context, handle, message.getNewMessageCount());
-
           break;
         default:
           break;
       }
+    } else if (OmtpConstants.ALTERNATIVE_MAILBOX_UPDATE.equals(eventType)) {
+      VvmLog.w(TAG, "receiving alternative VVM SMS on non-activated account");
+      int messageCount = 0;
+      try {
+        messageCount =
+            Integer.parseInt(
+                sms.getFields().getString(OmtpConstants.ALTERNATIVE_NUM_MESSAGE_COUNT));
+      } catch (NumberFormatException e) {
+        VvmLog.e(TAG, "missing message count");
+      }
+      sendLegacyVoicemailNotification(context, handle, messageCount);
     }
   }
 
diff --git a/java/com/android/voicemail/impl/sms/OmtpMessageReceiver.java b/java/com/android/voicemail/impl/sms/OmtpMessageReceiver.java
index eae990a..0f22c3d 100644
--- a/java/com/android/voicemail/impl/sms/OmtpMessageReceiver.java
+++ b/java/com/android/voicemail/impl/sms/OmtpMessageReceiver.java
@@ -38,6 +38,7 @@
 import com.android.voicemail.impl.sync.SyncOneTask;
 import com.android.voicemail.impl.sync.SyncTask;
 import com.android.voicemail.impl.sync.VoicemailsQueryHelper;
+import com.android.voicemail.impl.sync.VvmAccountManager;
 import com.android.voicemail.impl.utils.VoicemailDatabaseUtil;
 
 /** Receive SMS messages and send for processing by the OMTP visual voicemail source. */
@@ -69,6 +70,12 @@
       return;
     }
 
+    if (!VvmAccountManager.isAccountActivated(context, phone)) {
+      VvmLog.i(TAG, "Received message on non-activated account");
+      LegacyModeSmsHandler.handle(context, sms);
+      return;
+    }
+
     OmtpVvmCarrierConfigHelper helper = new OmtpVvmCarrierConfigHelper(this.context, phone);
     if (!helper.isValid()) {
       VvmLog.e(TAG, "vvm config no longer valid");