Fixed issues with legacy usages of notification people

Change-Id: Iac0caf2c97532913a7072a18af91791d2888bfd8
Fixes: 72110655
Test: runtest -x tests/app/src/android/app/cts/NotificationTest.java
diff --git a/core/java/android/service/notification/NotificationListenerService.java b/core/java/android/service/notification/NotificationListenerService.java
index 422e36b..148bdaa 100644
--- a/core/java/android/service/notification/NotificationListenerService.java
+++ b/core/java/android/service/notification/NotificationListenerService.java
@@ -1217,6 +1217,7 @@
                 // convert icon metadata to legacy format for older clients
                 createLegacyIconExtras(sbn.getNotification());
                 maybePopulateRemoteViews(sbn.getNotification());
+                maybePopulatePeople(sbn.getNotification());
             } catch (IllegalArgumentException e) {
                 // warn and drop corrupt notification
                 Log.w(TAG, "onNotificationPosted: can't rebuild notification from " +
diff --git a/services/core/java/com/android/server/notification/ValidateNotificationPeople.java b/services/core/java/com/android/server/notification/ValidateNotificationPeople.java
index 896480f..c0c66b2 100644
--- a/services/core/java/com/android/server/notification/ValidateNotificationPeople.java
+++ b/services/core/java/com/android/server/notification/ValidateNotificationPeople.java
@@ -16,6 +16,7 @@
 
 package com.android.server.notification;
 
+import android.annotation.Nullable;
 import android.app.Notification;
 import android.content.Context;
 import android.content.pm.PackageManager;
@@ -45,8 +46,6 @@
 import java.util.concurrent.Semaphore;
 import java.util.concurrent.TimeUnit;
 
-import android.os.SystemClock;
-
 /**
  * This {@link NotificationSignalExtractor} attempts to validate
  * people references. Also elevates the priority of real people.
@@ -231,7 +230,6 @@
 
     private PeopleRankingReconsideration validatePeople(Context context, String key, Bundle extras,
             List<String> peopleOverride, float[] affinityOut) {
-        long start = SystemClock.elapsedRealtime();
         float affinity = NONE;
         if (extras == null) {
             return null;
@@ -239,7 +237,7 @@
         final Set<String> people = new ArraySet<>(peopleOverride);
         final String[] notificationPeople = getExtraPeople(extras);
         if (notificationPeople != null ) {
-            people.addAll(Arrays.asList(getExtraPeople(extras)));
+            people.addAll(Arrays.asList(notificationPeople));
         }
 
         if (VERBOSE) Slog.i(TAG, "Validating: " + key + " for " + context.getUserId());
@@ -283,7 +281,31 @@
 
     // VisibleForTesting
     public static String[] getExtraPeople(Bundle extras) {
-        Object people = extras.get(Notification.EXTRA_PEOPLE_LIST);
+        String[] peopleList = getExtraPeopleForKey(extras, Notification.EXTRA_PEOPLE_LIST);
+        String[] legacyPeople = getExtraPeopleForKey(extras, Notification.EXTRA_PEOPLE);
+        return combineLists(legacyPeople, peopleList);
+    }
+
+    private static String[] combineLists(String[] first, String[] second) {
+        if (first == null) {
+            return second;
+        }
+        if (second == null) {
+            return first;
+        }
+        ArraySet<String> people = new ArraySet<>(first.length + second.length);
+        for (String person: first) {
+            people.add(person);
+        }
+        for (String person: second) {
+            people.add(person);
+        }
+        return (String[]) people.toArray();
+    }
+
+    @Nullable
+    private static String[] getExtraPeopleForKey(Bundle extras, String key) {
+        Object people = extras.get(key);
         if (people instanceof String[]) {
             return (String[]) people;
         }
@@ -458,7 +480,6 @@
 
         @Override
         public void work() {
-            long start = SystemClock.elapsedRealtime();
             if (VERBOSE) Slog.i(TAG, "Executing: validation for: " + mKey);
             long timeStartMs = System.currentTimeMillis();
             for (final String handle: mPendingLookups) {