Implement VVM Task Scheduling

Before CL multiple activate events will be fired during boot and each
one of them will be processed, which is redundant. The activation will
also trigger multiple sync events. During the initial download of
multiple voicemails an upload will also be trigger for each voicemail.
The flood of connections is know to have the client banned by the
server. Codes exists for retrying, but does not actually do anything.

In this CL TaskSchedulerService is implemented which will prevent
duplicated tasks from being queued, throttle requests, and handle
retries.

"Activate" event is not in scheduling yet.

- OmtpVvmSyncService is no longer a service. It will be renamed later.
  It can now be called to sync voicemail in a single threaded manner.

Fixes: 28729940
Bug: 28730056

Change-Id: I3678d8a16326e9a181bb401c003574928f02ae00
diff --git a/src/com/android/phone/Assert.java b/src/com/android/phone/Assert.java
index d4233b2..143e66f 100644
--- a/src/com/android/phone/Assert.java
+++ b/src/com/android/phone/Assert.java
@@ -24,17 +24,39 @@
  */
 public class Assert {
 
+    private static Boolean sIsMainThreadForTest;
+
     public static void isTrue(boolean condition) {
         if (!condition) {
             throw new AssertionError("Expected condition to be true");
         }
     }
 
+    public static void isMainThread() {
+        if (sIsMainThreadForTest != null) {
+            isTrue(sIsMainThreadForTest);
+            return;
+        }
+        isTrue(Looper.getMainLooper().equals(Looper.myLooper()));
+    }
+
     public static void isNotMainThread() {
+        if (sIsMainThreadForTest != null) {
+            isTrue(!sIsMainThreadForTest);
+            return;
+        }
         isTrue(!Looper.getMainLooper().equals(Looper.myLooper()));
     }
 
     public static void fail() {
         throw new AssertionError("Fail");
     }
+
+    /**
+     * Override the main thread status for tests. Set to null to revert to normal behavior
+     */
+    @NeededForTesting
+    public static void setIsMainThreadForTesting(Boolean isMainThread) {
+        sIsMainThreadForTest = isMainThread;
+    }
 }