From 41bf871e8e11df37deec902a0fcd6fe860ce7e11 Mon Sep 17 00:00:00 2001 From: Tony Mak Date: Tue, 29 Jan 2019 12:39:21 +0000 Subject: [PATCH] Fix logging in ExtServices for Q Beta Two issues: 1. The notification key -> logging id mapping should be removed whenever suggest() is called as the session is considered to be ended. 2. We were only storing the key -> logging id mapping when suggestConversationActions generated some replies. Thus, when only smart actions are generated from generateLinks, we didn't log it (as the mapping is missing) So, we now always cache the ID after calling suggestConversationActions. Remove the mapping when we find that neither actions or replies are generated. PS: We have a CL (ag/6033786) to switch to suggestConversationActions, fix for #2 is no longer needed once it is in. But that change won't be in before Android Beta as the model side change is not done. BUG: 120803809 Test: Manual. Send a message with URL, observer subsequent events (e.g: clicked) are logged. Test: atest SmartActionHelperTest Change-Id: Iea1a46466846ef99d51316dcbb294bfe0cf33653 --- .../ext/services/notification/Assistant.java | 6 ++-- .../notification/SmartActionsHelper.java | 31 ++++++++++++++++++- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/packages/ExtServices/src/android/ext/services/notification/Assistant.java b/packages/ExtServices/src/android/ext/services/notification/Assistant.java index f346b00f85b88..d70c19fe5620a 100644 --- a/packages/ExtServices/src/android/ext/services/notification/Assistant.java +++ b/packages/ExtServices/src/android/ext/services/notification/Assistant.java @@ -215,9 +215,9 @@ public class Assistant extends NotificationAssistantService { return null; } NotificationEntry entry = new NotificationEntry(mPackageManager, sbn, channel); - ArrayList actions = mSmartActionsHelper.suggestActions(entry); - ArrayList replies = mSmartActionsHelper.suggestReplies(entry); - return createEnqueuedNotificationAdjustment(entry, actions, replies); + SmartActionsHelper.SmartSuggestions suggestions = mSmartActionsHelper.suggest(entry); + return createEnqueuedNotificationAdjustment( + entry, suggestions.actions, suggestions.replies); } /** A convenience helper for creating an adjustment for an SBN. */ diff --git a/packages/ExtServices/src/android/ext/services/notification/SmartActionsHelper.java b/packages/ExtServices/src/android/ext/services/notification/SmartActionsHelper.java index 5acf4fbaa5cbe..48a3974e913be 100644 --- a/packages/ExtServices/src/android/ext/services/notification/SmartActionsHelper.java +++ b/packages/ExtServices/src/android/ext/services/notification/SmartActionsHelper.java @@ -92,6 +92,23 @@ public class SmartActionsHelper { mSettings = settings; } + @NonNull + SmartSuggestions suggest(@NonNull NotificationEntry entry) { + // Whenever suggest() is called on a notification, its previous session is ended. + mNotificationKeyToResultIdCache.remove(entry.getSbn().getKey()); + + ArrayList actions = suggestActions(entry); + ArrayList replies = suggestReplies(entry); + + // Not logging subsequent events of this notification if we didn't generate any suggestion + // for it. + if (replies.isEmpty() && actions.isEmpty()) { + mNotificationKeyToResultIdCache.remove(entry.getSbn().getKey()); + } + + return new SmartSuggestions(replies, actions); + } + /** * Adds action adjustments based on the notification contents. */ @@ -115,6 +132,7 @@ public class SmartActionsHelper { messages.get(messages.size() - 1).getText(), MAX_SMART_ACTIONS); } + @NonNull ArrayList suggestReplies(@NonNull NotificationEntry entry) { if (!mSettings.mGenerateReplies) { return EMPTY_REPLY_LIST; @@ -146,7 +164,7 @@ public class SmartActionsHelper { .collect(Collectors.toCollection(ArrayList::new)); String resultId = conversationActionsResult.getId(); - if (resultId != null && !replies.isEmpty()) { + if (resultId != null) { mNotificationKeyToResultIdCache.put(entry.getSbn().getKey(), resultId); } return replies; @@ -385,4 +403,15 @@ public class SmartActionsHelper { } return actions; } + + static class SmartSuggestions { + public final ArrayList replies; + public final ArrayList actions; + + SmartSuggestions( + ArrayList replies, ArrayList actions) { + this.replies = replies; + this.actions = actions; + } + } }