Delete and upload voicemail as deleted on the VM server

When a voicemail is deleted we mark it as deleted in the database. However to ensure that a voicemail gets deleted on the server, we need to upload it as well by forcing a upload sync, which we do after a successful marking it as deleted.

Bug: 73087132
Test: N/A
PiperOrigin-RevId: 185377828
Change-Id: Ia023cd7c5c283034c78022bcb6d4ce78e410de76
diff --git a/java/com/android/dialer/voicemail/listui/NewVoicemailAdapter.java b/java/com/android/dialer/voicemail/listui/NewVoicemailAdapter.java
index 044d8df..07a37c3 100644
--- a/java/com/android/dialer/voicemail/listui/NewVoicemailAdapter.java
+++ b/java/com/android/dialer/voicemail/listui/NewVoicemailAdapter.java
@@ -16,13 +16,16 @@
 package com.android.dialer.voicemail.listui;
 
 import android.app.FragmentManager;
+import android.content.ContentValues;
 import android.content.Context;
+import android.content.Intent;
 import android.database.Cursor;
 import android.media.MediaPlayer;
 import android.media.MediaPlayer.OnCompletionListener;
 import android.media.MediaPlayer.OnErrorListener;
 import android.media.MediaPlayer.OnPreparedListener;
 import android.net.Uri;
+import android.provider.VoicemailContract.Voicemails;
 import android.support.annotation.IntDef;
 import android.support.annotation.Nullable;
 import android.support.annotation.WorkerThread;
@@ -37,7 +40,6 @@
 import com.android.dialer.calllogutils.CallLogDates;
 import com.android.dialer.common.Assert;
 import com.android.dialer.common.LogUtil;
-import com.android.dialer.common.concurrent.DialerExecutor.SuccessListener;
 import com.android.dialer.common.concurrent.DialerExecutor.Worker;
 import com.android.dialer.common.concurrent.DialerExecutorComponent;
 import com.android.dialer.common.concurrent.ThreadUtil;
@@ -48,6 +50,7 @@
 import com.android.dialer.voicemail.listui.error.VoicemailErrorMessageCreator;
 import com.android.dialer.voicemail.listui.error.VoicemailStatus;
 import com.android.dialer.voicemail.model.VoicemailEntry;
+import com.android.voicemail.VoicemailClient;
 import com.google.common.collect.ImmutableList;
 import java.lang.annotation.Retention;
 import java.lang.annotation.RetentionPolicy;
@@ -637,32 +640,37 @@
 
     collapseExpandedViewHolder(expandedViewHolder);
 
-    Worker<Pair<Context, Uri>, Integer> deleteVoicemail = this::deleteVoicemail;
-    SuccessListener<Integer> deleteVoicemailCallBack = this::onVoicemailDeleted;
+    Worker<Pair<Context, Uri>, Void> deleteVoicemail = this::deleteVoicemail;
 
     DialerExecutorComponent.get(context)
         .dialerExecutorFactory()
-        .createUiTaskBuilder(fragmentManager, "delete_voicemail", deleteVoicemail)
-        .onSuccess(deleteVoicemailCallBack)
+        .createNonUiTaskBuilder(deleteVoicemail)
         .build()
         .executeSerial(new Pair<>(context, voicemailUri));
 
     notifyItemRemoved(expandedViewHolder.getAdapterPosition());
   }
 
-  private void onVoicemailDeleted(Integer integer) {
-    LogUtil.i("NewVoicemailAdapter.onVoicemailDeleted", "return value:%d", integer);
-    Assert.checkArgument(integer == 1, "voicemail delete was not successful");
-  }
-
   @WorkerThread
-  private Integer deleteVoicemail(Pair<Context, Uri> contextUriPair) {
+  private Void deleteVoicemail(Pair<Context, Uri> contextUriPair) {
     Assert.isWorkerThread();
     LogUtil.enterBlock("NewVoicemailAdapter.deleteVoicemail");
+
     Context context = contextUriPair.first;
     Uri uri = contextUriPair.second;
     LogUtil.i("NewVoicemailAdapter.deleteVoicemail", "deleting uri:%s", String.valueOf(uri));
-    return context.getContentResolver().delete(uri, null, null);
+    ContentValues values = new ContentValues();
+    values.put(Voicemails.DELETED, "1");
+
+    int numRowsUpdated = context.getContentResolver().update(uri, values, null, null);
+
+    LogUtil.i("NewVoicemailAdapter.onVoicemailDeleted", "return value:%d", numRowsUpdated);
+    Assert.checkArgument(numRowsUpdated == 1, "voicemail delete was not successful");
+
+    Intent intent = new Intent(VoicemailClient.ACTION_UPLOAD);
+    intent.setPackage(context.getPackageName());
+    context.sendBroadcast(intent);
+    return null;
   }
 
   /**