Fix VVM Activation

In ag/1337726 ActivationTask.mData was misused to carry the flag to
register the content providers. mData's purpose is solely to store the
data from the status SMS, and if it is null a new status SMS will be
requested. Putting the content provider flag in it caused the 0status
SMS never to be requested and broke the activation process.

In this CL, docs and field names are updated to clarify this, and the
content provider registration will be done on every activation since it
should usually be a relatively cheap process.

Fixes: 31350221
Change-Id: I36cc08cac60df77c2b77dc7fdb5a96eeaf8e8052
diff --git a/src/com/android/phone/vvm/omtp/ActivationTask.java b/src/com/android/phone/vvm/omtp/ActivationTask.java
index 00dd49e..eb43073 100644
--- a/src/com/android/phone/vvm/omtp/ActivationTask.java
+++ b/src/com/android/phone/vvm/omtp/ActivationTask.java
@@ -62,14 +62,12 @@
 
     private static final String EXTRA_MESSAGE_DATA_BUNDLE = "extra_message_data_bundle";
 
-    public static final String EXTRA_REGISTER_CONTENT_PROVIDER = "extra_register_content_provider";
-
     @Nullable
     private static DeviceProvisionedObserver sDeviceProvisionedObserver;
 
     private final RetryPolicy mRetryPolicy;
 
-    private Bundle mData;
+    private Bundle mMessageData;
 
     public ActivationTask() {
         super(TASK_ACTIVATION);
@@ -85,7 +83,12 @@
             context.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) == 1;
     }
 
-    public static void start(Context context, int subId, @Nullable Bundle data) {
+    /**
+     * @param messageData The optional bundle from {@link android.provider.VoicemailContract#
+     * EXTRA_VOICEMAIL_SMS_FIELDS}, if the task is initiated by a status SMS. If null the task will
+     * request a status SMS itself.
+     */
+    public static void start(Context context, int subId, @Nullable Bundle messageData) {
         if (!isDeviceProvisioned(context)) {
             VvmLog.i(TAG, "Activation requested while device is not provisioned, postponing");
             // Activation might need information such as system language to be set, so wait until
@@ -105,21 +108,21 @@
         }
 
         Intent intent = BaseTask.createIntent(context, ActivationTask.class, subId);
-        if (data != null) {
-            intent.putExtra(EXTRA_MESSAGE_DATA_BUNDLE, data);
+        if (messageData != null) {
+            intent.putExtra(EXTRA_MESSAGE_DATA_BUNDLE, messageData);
         }
         context.startService(intent);
     }
 
     public void onCreate(Context context, Intent intent, int flags, int startId) {
         super.onCreate(context, intent, flags, startId);
-        mData = intent.getParcelableExtra(EXTRA_MESSAGE_DATA_BUNDLE);
+        mMessageData = intent.getParcelableExtra(EXTRA_MESSAGE_DATA_BUNDLE);
     }
 
     @Override
     public Intent createRestartIntent() {
         Intent intent = super.createRestartIntent();
-        // mData is discarded, request a fresh STATUS SMS for retries.
+        // mMessageData is discarded, request a fresh STATUS SMS for retries.
         return intent;
     }
 
@@ -143,19 +146,17 @@
             return;
         }
 
-        if (mData != null && mData.getBoolean(EXTRA_REGISTER_CONTENT_PROVIDER)) {
-            // OmtmVvmCarrierConfigHelper can start the activation process; it will pass in a vvm
-            // content provider URI which we will use.  On some occasions, setting that URI will
-            // fail, so we will perform a few attempts to ensure that the vvm content provider has
-            // a good chance of being started up.
-            if (!VoicemailStatus.edit(getContext(), phoneAccountHandle)
-                    .setType(helper.getVvmType())
-                    .apply()) {
-                VvmLog.e(TAG, "Failed to configure content provider - " + helper.getVvmType());
-                fail();
-            }
-            VvmLog.i(TAG, "VVM content provider configured - " + helper.getVvmType());
+        // OmtpVvmCarrierConfigHelper can start the activation process; it will pass in a vvm
+        // content provider URI which we will use.  On some occasions, setting that URI will
+        // fail, so we will perform a few attempts to ensure that the vvm content provider has
+        // a good chance of being started up.
+        if (!VoicemailStatus.edit(getContext(), phoneAccountHandle)
+            .setType(helper.getVvmType())
+            .apply()) {
+            VvmLog.e(TAG, "Failed to configure content provider - " + helper.getVvmType());
+            fail();
         }
+        VvmLog.i(TAG, "VVM content provider configured - " + helper.getVvmType());
 
         if (!OmtpVvmSourceManager.getInstance(getContext())
                 .isVvmSourceRegistered(phoneAccountHandle)) {
@@ -183,10 +184,10 @@
         VisualVoicemailProtocol protocol = helper.getProtocol();
 
         Bundle data;
-        if (mData != null) {
+        if (mMessageData != null) {
             // The content of STATUS SMS is provided to launch this task, no need to request it
             // again.
-            data = mData;
+            data = mMessageData;
         } else {
             try (StatusSmsFetcher fetcher = new StatusSmsFetcher(getContext(), subId)) {
                 protocol.startActivation(helper);
diff --git a/src/com/android/phone/vvm/omtp/OmtpVvmCarrierConfigHelper.java b/src/com/android/phone/vvm/omtp/OmtpVvmCarrierConfigHelper.java
index 4d6c63c..147eaf1 100644
--- a/src/com/android/phone/vvm/omtp/OmtpVvmCarrierConfigHelper.java
+++ b/src/com/android/phone/vvm/omtp/OmtpVvmCarrierConfigHelper.java
@@ -328,9 +328,7 @@
         activateSmsFilter();
 
         if (mProtocol != null) {
-            Bundle extras = new Bundle();
-            extras.putBoolean(ActivationTask.EXTRA_REGISTER_CONTENT_PROVIDER, true);
-            ActivationTask.start(mContext, mSubId, extras);
+            ActivationTask.start(mContext, mSubId, null);
         }
     }