Fix Ranking#getSmartReplies/Actions methods to actually be @NonNull
Test: atest, manual Change-Id: I4d4305127c4f0f041c7e9a0d8b50faf5d295ceeb
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -204,32 +204,29 @@ 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(
|
||||
entryReplies,
|
||||
freeformPair.first,
|
||||
freeformPair.second.actionIntent,
|
||||
true /* fromAssistant */)
|
||||
}
|
||||
}
|
||||
smartActions = entry.smartActions
|
||||
?.takeIf {
|
||||
it.isNotEmpty() && notification.allowSystemGeneratedContextualActions
|
||||
}?.let { entryActions ->
|
||||
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.
|
||||
filterAllowlistedLockTaskApps(entryActions)
|
||||
else -> entryActions
|
||||
}
|
||||
SmartActions(systemGeneratedActions, true /* fromAssistant */)
|
||||
}
|
||||
val entryReplies = entry.smartReplies
|
||||
val entryActions = entry.smartActions
|
||||
if (entryReplies.isNotEmpty()
|
||||
&& freeformRemoteInputActionPair != null
|
||||
&& freeformRemoteInputActionPair.second.allowGeneratedReplies
|
||||
&& freeformRemoteInputActionPair.second.actionIntent != null) {
|
||||
smartReplies = SmartReplies(
|
||||
entryReplies,
|
||||
freeformRemoteInputActionPair.first,
|
||||
freeformRemoteInputActionPair.second.actionIntent,
|
||||
true /* fromAssistant */)
|
||||
}
|
||||
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.
|
||||
filterAllowlistedLockTaskApps(entryActions)
|
||||
else -> entryActions
|
||||
}
|
||||
smartActions = SmartActions(systemGeneratedActions, true /* fromAssistant */)
|
||||
}
|
||||
}
|
||||
return SmartRepliesAndActions(smartReplies, smartActions)
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user