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

Commit 467b8196 authored by Steve Elliott's avatar Steve Elliott
Browse files

Fix Ranking#getSmartReplies/Actions methods to actually be @NonNull

Test: atest, manual
Change-Id: I4d4305127c4f0f041c7e9a0d8b50faf5d295ceeb
parent b5d5fedc
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -64,6 +64,7 @@ import com.android.internal.os.SomeArgs;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

@@ -1802,7 +1803,7 @@ public abstract class NotificationListenerService extends Service {
         * {@link NotificationAssistantService}
         */
        public @NonNull List<Notification.Action> getSmartActions() {
            return mSmartActions;
            return mSmartActions == null ? Collections.emptyList() : mSmartActions;
        }

        /**
@@ -1810,7 +1811,7 @@ public abstract class NotificationListenerService extends Service {
         * {@link NotificationAssistantService}
         */
        public @NonNull List<CharSequence> getSmartReplies() {
            return mSmartReplies;
            return mSmartReplies == null ? Collections.emptyList() : mSmartReplies;
        }

        /**
+2 −2
Original line number Diff line number Diff line
@@ -329,11 +329,11 @@ public final class NotificationEntry extends ListEntry {
        return mRanking.canBubble();
    }

    public @Nullable List<Notification.Action> getSmartActions() {
    public @NonNull List<Notification.Action> getSmartActions() {
        return mRanking.getSmartActions();
    }

    public @Nullable List<CharSequence> getSmartReplies() {
    public @NonNull List<CharSequence> getSmartReplies() {
        return mRanking.getSmartReplies();
    }

+23 −26
Original line number Diff line number Diff line
@@ -204,31 +204,28 @@ interface SmartRepliesAndActionsInflater {
        }
        // Apps didn't provide any smart replies / actions, use those from NAS (if any).
        if (smartReplies == null && smartActions == null) {
            smartReplies = entry.smartReplies
                    ?.takeIf { it.isNotEmpty() }
                    ?.let { entryReplies -> freeformRemoteInputActionPair
                            ?.takeIf {
                                it.second.allowGeneratedReplies && it.second.actionIntent != null
                            }?.let { freeformPair -> SmartReplies(
            val entryReplies = entry.smartReplies
            val entryActions = entry.smartActions
            if (entryReplies.isNotEmpty()
                    && freeformRemoteInputActionPair != null
                    && freeformRemoteInputActionPair.second.allowGeneratedReplies
                    && freeformRemoteInputActionPair.second.actionIntent != null) {
                smartReplies = SmartReplies(
                        entryReplies,
                                    freeformPair.first,
                                    freeformPair.second.actionIntent,
                        freeformRemoteInputActionPair.first,
                        freeformRemoteInputActionPair.second.actionIntent,
                        true /* fromAssistant */)
            }
                    }
            smartActions = entry.smartActions
                    ?.takeIf {
                        it.isNotEmpty() && notification.allowSystemGeneratedContextualActions
                    }?.let { entryActions ->
            if (entryActions.isNotEmpty()
                    && notification.allowSystemGeneratedContextualActions) {
                val systemGeneratedActions: List<Notification.Action> = when {
                    activityManagerWrapper.isLockTaskKioskModeActive ->
                                // Filter actions if we're in kiosk-mode - we don't care about
                                // screen pinning mode, since notifications aren't shown there
                                // anyway.
                        // Filter actions if we're in kiosk-mode - we don't care about screen
                        // pinning mode, since notifications aren't shown there anyway.
                        filterAllowlistedLockTaskApps(entryActions)
                    else -> entryActions
                }
                        SmartActions(systemGeneratedActions, true /* fromAssistant */)
                smartActions = SmartActions(systemGeneratedActions, true /* fromAssistant */)
            }
        }
        return SmartRepliesAndActions(smartReplies, smartActions)
+3 −1
Original line number Diff line number Diff line
@@ -21,6 +21,8 @@ import static android.service.notification.NotificationListenerService.REASON_CA

import static com.android.systemui.statusbar.notification.NotificationEntryManager.UNDEFINED_DISMISS_REASON;

import static com.google.common.truth.Truth.assertThat;

import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertNull;
import static junit.framework.Assert.assertTrue;
@@ -346,7 +348,7 @@ public class NotificationEntryManagerTest extends SysuiTestCase {
        setSmartActions(mEntry.getKey(), null);

        mEntryManager.updateNotificationRanking(mRankingMap);
        assertNull(mEntry.getSmartActions());
        assertThat(mEntry.getSmartActions()).isEmpty();
    }

    @Test