Fix issue where work profiles cause missed calls to not show after boot.

When a user with a work profile reboots their device, Telecom tracks the
user which is pending reload of the missed call notification and defers
the process until boot complete.

This is problematic as there is only one user tracked, and during boot
the work profile user ends up overwriting the primary user.

To fix this, now tracking a list of users to load after boot complete so
that the work profile and primary work profile both reload the missed
call notification, not just the work profile user.

Test: Manually reproduced bug and verified Missed Call notification now
shows up.
Fixes: 73164872
Merged-In: I0cb35881992fcd6c23f9efe76cf365fef1f5acdd
Change-Id: I0cb35881992fcd6c23f9efe76cf365fef1f5acdd
(cherry picked from commit 0208a04eeeb91986acb5ee9153e5f2c97fdd62ab)
diff --git a/src/com/android/server/telecom/ui/MissedCallNotifierImpl.java b/src/com/android/server/telecom/ui/MissedCallNotifierImpl.java
index e02fd56..ec80911 100644
--- a/src/com/android/server/telecom/ui/MissedCallNotifierImpl.java
+++ b/src/com/android/server/telecom/ui/MissedCallNotifierImpl.java
@@ -66,6 +66,7 @@
 
 import java.lang.Override;
 import java.lang.String;
+import java.util.ArrayList;
 import java.util.List;
 import java.util.Locale;
 import java.util.Objects;
@@ -134,7 +135,7 @@
     // Used to track the number of missed calls.
     private ConcurrentMap<UserHandle, AtomicInteger> mMissedCallCounts;
 
-    private UserHandle userToLoadAfterBootComplete;
+    private List<UserHandle> mUsersToLoadAfterBootComplete = new ArrayList<>();
 
     public MissedCallNotifierImpl(Context context, PhoneAccountRegistrar phoneAccountRegistrar,
             DefaultDialerCache defaultDialerCache) {
@@ -271,7 +272,7 @@
     }
 
     private void showMissedCallNotification(@NonNull CallInfo callInfo, UserHandle userHandle) {
-        Log.i(this, "showMissedCallNotification()");
+        Log.i(this, "showMissedCallNotification: userHandle=%d", userHandle.getIdentifier());
         mMissedCallCounts.putIfAbsent(userHandle, new AtomicInteger(0));
         int missCallCounts = mMissedCallCounts.get(userHandle).incrementAndGet();
 
@@ -537,10 +538,14 @@
     @Override
     public void reloadAfterBootComplete(final CallerInfoLookupHelper callerInfoLookupHelper,
             CallInfoFactory callInfoFactory) {
-        if (userToLoadAfterBootComplete != null) {
-            reloadFromDatabase(callerInfoLookupHelper,
-                    callInfoFactory, userToLoadAfterBootComplete);
-            userToLoadAfterBootComplete = null;
+        if (!mUsersToLoadAfterBootComplete.isEmpty()) {
+            for (UserHandle handle : mUsersToLoadAfterBootComplete) {
+                Log.i(this, "reloadAfterBootComplete: user=%d", handle.getIdentifier());
+                reloadFromDatabase(callerInfoLookupHelper, callInfoFactory, handle);
+            }
+            mUsersToLoadAfterBootComplete.clear();
+        } else {
+            Log.i(this, "reloadAfterBootComplete: no user(s) to check; skipping reload.");
         }
     }
     /**
@@ -549,11 +554,12 @@
     @Override
     public void reloadFromDatabase(final CallerInfoLookupHelper callerInfoLookupHelper,
             CallInfoFactory callInfoFactory, final UserHandle userHandle) {
-        Log.d(this, "reloadFromDatabase()...");
+        Log.d(this, "reloadFromDatabase: user=%d", userHandle.getIdentifier());
         if (TelecomSystem.getInstance() == null || !TelecomSystem.getInstance().isBootComplete()) {
-            Log.i(this, "Boot not yet complete -- call log db may not be available. Deferring " +
-                    "loading until boot complete.");
-            userToLoadAfterBootComplete = userHandle;
+            Log.i(this, "reloadFromDatabase: Boot not yet complete -- call log db may not be "
+                    + "available. Deferring loading until boot complete for user %d",
+                    userHandle.getIdentifier());
+            mUsersToLoadAfterBootComplete.add(userHandle);
             return;
         }