Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5390e7d7 authored by Selim Cinek's avatar Selim Cinek
Browse files

Fixed issues with legacy usages of notification people

Change-Id: Iac0caf2c97532913a7072a18af91791d2888bfd8
Fixes: 72110655
Test: runtest -x tests/app/src/android/app/cts/NotificationTest.java
parent 4e69759e
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -1217,6 +1217,7 @@ public abstract class NotificationListenerService extends Service {
                // 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 " +
+27 −6
Original line number Diff line number Diff line
@@ -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.Set;
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 @@ public class ValidateNotificationPeople implements NotificationSignalExtractor {

    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 @@ public class ValidateNotificationPeople implements NotificationSignalExtractor {
        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 @@ public class ValidateNotificationPeople implements NotificationSignalExtractor {

    // 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 @@ public class ValidateNotificationPeople implements NotificationSignalExtractor {

        @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) {