From d746f0b8aa937f95f1211fb86fb2303344f97f5f Mon Sep 17 00:00:00 2001 From: Steve Elliott Date: Thu, 8 Oct 2020 13:42:50 -0400 Subject: [PATCH] Fix NPEs in SmartRepliesAndActionsInflater flows Fixes: 170366658 Test: atest PlatformScenarioTests:android.platform.test.scenario.sysui.notification.NotificationContent#notificationContentTest -- --abi arm64-v8a Change-Id: Ic04ce708f07e19fda271c1c8bd816ffc2333b3c9 --- .../collection/NotificationEntry.java | 4 +- .../policy/SmartRepliesAndActionsInflater.kt | 51 ++++++++++--------- .../policy/InflatedSmartRepliesTest.java | 3 +- 3 files changed, 31 insertions(+), 27 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/NotificationEntry.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/NotificationEntry.java index 789e78e336718..0e7a558f0ab4a 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/NotificationEntry.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/NotificationEntry.java @@ -329,11 +329,11 @@ public final class NotificationEntry extends ListEntry { return mRanking.canBubble(); } - public @NonNull List getSmartActions() { + public @Nullable List getSmartActions() { return mRanking.getSmartActions(); } - public @NonNull List getSmartReplies() { + public @Nullable List getSmartReplies() { return mRanking.getSmartReplies(); } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/SmartRepliesAndActionsInflater.kt b/packages/SystemUI/src/com/android/systemui/statusbar/policy/SmartRepliesAndActionsInflater.kt index b2c1f48400686..5ec57e2f02f39 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/SmartRepliesAndActionsInflater.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/SmartRepliesAndActionsInflater.kt @@ -86,7 +86,7 @@ interface SmartRepliesAndActionsInflater { sysuiContext: Context, notifPackageContext: Context, entry: NotificationEntry, - existingRepliesAndAction: SmartRepliesAndActions + existingRepliesAndAction: SmartRepliesAndActions? ): InflatedSmartReplies } @@ -103,7 +103,7 @@ interface SmartRepliesAndActionsInflater { sysuiContext: Context, notifPackageContext: Context, entry: NotificationEntry, - existingRepliesAndAction: SmartRepliesAndActions + existingRepliesAndAction: SmartRepliesAndActions? ): InflatedSmartReplies { val newRepliesAndActions = chooseSmartRepliesAndActions(entry) if (!shouldShowSmartReplyView(entry, newRepliesAndActions)) { @@ -204,27 +204,32 @@ interface SmartRepliesAndActionsInflater { } // Apps didn't provide any smart replies / actions, use those from NAS (if any). if (smartReplies == null && smartActions == null) { - if (entry.smartReplies.isNotEmpty() - && freeformRemoteInputActionPair != null - && freeformRemoteInputActionPair.second.allowGeneratedReplies - && freeformRemoteInputActionPair.second.actionIntent != null) { - smartReplies = SmartReplies( - entry.smartReplies, - freeformRemoteInputActionPair.first, - freeformRemoteInputActionPair.second.actionIntent, - true /* fromAssistant */) - } - if (entry.smartActions.isNotEmpty() - && notification.allowSystemGeneratedContextualActions) { - val systemGeneratedActions: List = 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(entry.smartActions) - else -> entry.smartActions - } - smartActions = SmartActions(systemGeneratedActions, true /* fromAssistant */) - } + 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 = 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 */) + } } return SmartRepliesAndActions(smartReplies, smartActions) } diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/InflatedSmartRepliesTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/InflatedSmartRepliesTest.java index e93c5dbdadc16..8ee15bb368348 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/InflatedSmartRepliesTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/InflatedSmartRepliesTest.java @@ -183,8 +183,7 @@ public class InflatedSmartRepliesTest extends SysuiTestCase { SmartRepliesAndActions repliesAndActions = mSmartRepliesInflater.chooseSmartRepliesAndActions(mEntry); - assertThat(repliesAndActions.smartReplies.choices).isEqualTo( - mEntry.getSmartReplies()); + assertThat(repliesAndActions.smartReplies.choices).isEqualTo(mEntry.getSmartReplies()); assertThat(repliesAndActions.smartReplies.fromAssistant).isTrue(); assertThat(repliesAndActions.smartActions).isNull(); }