diff options
8 files changed, 78 insertions, 21 deletions
diff --git a/core/java/com/android/internal/statusbar/IStatusBarService.aidl b/core/java/com/android/internal/statusbar/IStatusBarService.aidl index 5118e5f0473e..9087dd219d97 100644 --- a/core/java/com/android/internal/statusbar/IStatusBarService.aidl +++ b/core/java/com/android/internal/statusbar/IStatusBarService.aidl @@ -67,7 +67,8 @@ interface IStatusBarService in NotificationVisibility[] noLongerVisibleKeys); void onNotificationExpansionChanged(in String key, in boolean userAction, in boolean expanded); void onNotificationDirectReplied(String key); - void onNotificationSmartRepliesAdded(in String key, in int replyCount); + void onNotificationSmartSuggestionsAdded(String key, int smartReplyCount, int smartActionCount, + boolean generatedByAsssistant); void onNotificationSmartReplySent(in String key, in int replyIndex, in CharSequence reply, boolean generatedByAssistant); void onNotificationSettingsViewed(String key); void setSystemUiVisibility(int displayId, int vis, int mask, String cause); diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/SmartReplyController.java b/packages/SystemUI/src/com/android/systemui/statusbar/SmartReplyController.java index f5d6904a1543..e31f90d5a92e 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/SmartReplyController.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/SmartReplyController.java @@ -88,10 +88,14 @@ public class SmartReplyController { return mSendingKeys.contains(key); } - public void smartRepliesAdded(final NotificationData.Entry entry, int replyCount) { + /** + * Smart Replies and Actions have been added to the UI. + */ + public void smartSuggestionsAdded(final NotificationData.Entry entry, int replyCount, + int actionCount, boolean generatedByAssistant) { try { - mBarService.onNotificationSmartRepliesAdded(entry.notification.getKey(), - replyCount); + mBarService.onNotificationSmartSuggestionsAdded( + entry.notification.getKey(), replyCount, actionCount, generatedByAssistant); } catch (RemoteException e) { // Nothing to do, system going down } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationContentView.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationContentView.java index 6bc39c82f8bf..02a310c29379 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationContentView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationContentView.java @@ -1474,9 +1474,19 @@ public class NotificationContentView extends FrameLayout { if (mExpandedChild != null) { mExpandedSmartReplyView = applySmartReplyView(mExpandedChild, smartRepliesAndActions, entry); - if (mExpandedSmartReplyView != null && smartRepliesAndActions.smartReplies != null) { - mSmartReplyController.smartRepliesAdded( - entry, smartRepliesAndActions.smartReplies.choices.length); + if (mExpandedSmartReplyView != null) { + if (smartRepliesAndActions.smartReplies != null + || smartRepliesAndActions.smartActions != null) { + int numSmartReplies = smartRepliesAndActions.smartReplies == null + ? 0 : smartRepliesAndActions.smartReplies.choices.length; + int numSmartActions = smartRepliesAndActions.smartActions == null + ? 0 : smartRepliesAndActions.smartActions.actions.size(); + boolean fromAssistant = smartRepliesAndActions.smartReplies == null + ? smartRepliesAndActions.smartActions.fromAssistant + : smartRepliesAndActions.smartReplies.fromAssistant; + mSmartReplyController.smartSuggestionsAdded(entry, numSmartReplies, + numSmartActions, fromAssistant); + } } } if (mHeadsUpChild != null) { diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/SmartReplyControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/SmartReplyControllerTest.java index 8d52ccd71808..14e611a26b4c 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/SmartReplyControllerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/SmartReplyControllerTest.java @@ -51,6 +51,7 @@ public class SmartReplyControllerTest extends SysuiTestCase { private static final String TEST_CHOICE_TEXT = "A Reply"; private static final int TEST_CHOICE_INDEX = 2; private static final int TEST_CHOICE_COUNT = 4; + private static final int TEST_ACTION_COUNT = 3; private Notification mNotification; private NotificationData.Entry mEntry; @@ -117,12 +118,14 @@ public class SmartReplyControllerTest extends SysuiTestCase { } @Test - public void testShowSmartReply_logsToStatusBar() throws RemoteException { - mSmartReplyController.smartRepliesAdded(mEntry, TEST_CHOICE_COUNT); + public void testShowSmartSuggestions_logsToStatusBar() throws RemoteException { + final boolean generatedByAsssistant = true; + mSmartReplyController.smartSuggestionsAdded(mEntry, TEST_CHOICE_COUNT, TEST_ACTION_COUNT, + generatedByAsssistant); // Check we log the result to the status bar service. - verify(mIStatusBarService).onNotificationSmartRepliesAdded(mSbn.getKey(), - TEST_CHOICE_COUNT); + verify(mIStatusBarService).onNotificationSmartSuggestionsAdded(mSbn.getKey(), + TEST_CHOICE_COUNT, TEST_ACTION_COUNT, generatedByAsssistant); } @Test diff --git a/services/core/java/com/android/server/notification/NotificationDelegate.java b/services/core/java/com/android/server/notification/NotificationDelegate.java index 84bb13ec92d3..ee60daa20837 100644 --- a/services/core/java/com/android/server/notification/NotificationDelegate.java +++ b/services/core/java/com/android/server/notification/NotificationDelegate.java @@ -45,7 +45,12 @@ public interface NotificationDelegate { void onNotificationExpansionChanged(String key, boolean userAction, boolean expanded); void onNotificationDirectReplied(String key); void onNotificationSettingsViewed(String key); - void onNotificationSmartRepliesAdded(String key, int replyCount); + + /** + * Notifies that smart replies and actions have been added to the UI. + */ + void onNotificationSmartSuggestionsAdded(String key, int smartReplyCount, int smartActionCount, + boolean generatedByAssistant); /** * Notifies a smart reply is sent. diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java index bad259bafeb8..405edd216f0f 100644 --- a/services/core/java/com/android/server/notification/NotificationManagerService.java +++ b/services/core/java/com/android/server/notification/NotificationManagerService.java @@ -762,7 +762,13 @@ public class NotificationManagerService extends SystemService { .setType(MetricsEvent.TYPE_ACTION) .setSubtype(actionIndex) .addTaggedData(MetricsEvent.NOTIFICATION_SHADE_INDEX, nv.rank) - .addTaggedData(MetricsEvent.NOTIFICATION_SHADE_COUNT, nv.count)); + .addTaggedData(MetricsEvent.NOTIFICATION_SHADE_COUNT, nv.count) + .addTaggedData(MetricsEvent.NOTIFICATION_ACTION_IS_SMART, + (Notification.Action.SEMANTIC_ACTION_CONTEXTUAL_SUGGESTION + == action.getSemanticAction()) ? 1 : 0) + .addTaggedData( + MetricsEvent.NOTIFICATION_SMART_SUGGESTION_ASSISTANT_GENERATED, + generatedByAssistant ? 1 : 0)); EventLogTags.writeNotificationActionClicked(key, actionIndex, r.getLifespanMs(now), r.getFreshnessMs(now), r.getExposureMs(now), nv.rank, nv.count); @@ -837,15 +843,20 @@ public class NotificationManagerService extends SystemService { if (DBG) Slog.d(TAG, "Marking notification as visible " + nv.key); reportSeen(r); - // If the newly visible notification has smart replies + // If the newly visible notification has smart suggestions // then log that the user has seen them. - if (r.getNumSmartRepliesAdded() > 0 + if ((r.getNumSmartRepliesAdded() > 0 || r.getNumSmartActionsAdded() > 0) && !r.hasSeenSmartReplies()) { r.setSeenSmartReplies(true); LogMaker logMaker = r.getLogMaker() .setCategory(MetricsEvent.SMART_REPLY_VISIBLE) .addTaggedData(MetricsEvent.NOTIFICATION_SMART_REPLY_COUNT, - r.getNumSmartRepliesAdded()); + r.getNumSmartRepliesAdded()) + .addTaggedData(MetricsEvent.NOTIFICATION_SMART_ACTION_COUNT, + r.getNumSmartActionsAdded()) + .addTaggedData( + MetricsEvent.NOTIFICATION_SMART_SUGGESTION_ASSISTANT_GENERATED, + r.getSuggestionsGeneratedByAssistant()); mMetricsLogger.write(logMaker); } } @@ -908,11 +919,14 @@ public class NotificationManagerService extends SystemService { } @Override - public void onNotificationSmartRepliesAdded(String key, int replyCount) { + public void onNotificationSmartSuggestionsAdded(String key, int smartReplyCount, + int smartActionCount, boolean generatedByAssistant) { synchronized (mNotificationLock) { NotificationRecord r = mNotificationsByKey.get(key); if (r != null) { - r.setNumSmartRepliesAdded(replyCount); + r.setNumSmartRepliesAdded(smartReplyCount); + r.setNumSmartActionsAdded(smartActionCount); + r.setSuggestionsGeneratedByAssistant(generatedByAssistant); } } } @@ -920,6 +934,7 @@ public class NotificationManagerService extends SystemService { @Override public void onNotificationSmartReplySent(String key, int replyIndex, CharSequence reply, boolean generatedByAssistant) { + synchronized (mNotificationLock) { NotificationRecord r = mNotificationsByKey.get(key); if (r != null) { diff --git a/services/core/java/com/android/server/notification/NotificationRecord.java b/services/core/java/com/android/server/notification/NotificationRecord.java index 39451d40a97e..89ec38db99e5 100644 --- a/services/core/java/com/android/server/notification/NotificationRecord.java +++ b/services/core/java/com/android/server/notification/NotificationRecord.java @@ -178,6 +178,8 @@ public final class NotificationRecord { private boolean mTextChanged; private boolean mRecordedInterruption; private int mNumberOfSmartRepliesAdded; + private int mNumberOfSmartActionsAdded; + private boolean mSuggestionsGeneratedByAssistant; private boolean mHasSeenSmartReplies; /** * Whether this notification (and its channels) should be considered user locked. Used in @@ -1140,6 +1142,22 @@ public final class NotificationRecord { return mNumberOfSmartRepliesAdded; } + public void setNumSmartActionsAdded(int noActions) { + mNumberOfSmartActionsAdded = noActions; + } + + public int getNumSmartActionsAdded() { + return mNumberOfSmartActionsAdded; + } + + public void setSuggestionsGeneratedByAssistant(boolean generatedByAssistant) { + mSuggestionsGeneratedByAssistant = generatedByAssistant; + } + + public boolean getSuggestionsGeneratedByAssistant() { + return mSuggestionsGeneratedByAssistant; + } + public boolean hasSeenSmartReplies() { return mHasSeenSmartReplies; } diff --git a/services/core/java/com/android/server/statusbar/StatusBarManagerService.java b/services/core/java/com/android/server/statusbar/StatusBarManagerService.java index 6e4c00eed181..02d8c0bcb584 100644 --- a/services/core/java/com/android/server/statusbar/StatusBarManagerService.java +++ b/services/core/java/com/android/server/statusbar/StatusBarManagerService.java @@ -1254,12 +1254,13 @@ public class StatusBarManagerService extends IStatusBarService.Stub implements D } @Override - public void onNotificationSmartRepliesAdded(String key, int replyCount) - throws RemoteException { + public void onNotificationSmartSuggestionsAdded(String key, int smartReplyCount, + int smartActionCount, boolean generatedByAssistant) { enforceStatusBarService(); long identity = Binder.clearCallingIdentity(); try { - mNotificationDelegate.onNotificationSmartRepliesAdded(key, replyCount); + mNotificationDelegate.onNotificationSmartSuggestionsAdded(key, smartReplyCount, + smartActionCount, generatedByAssistant); } finally { Binder.restoreCallingIdentity(identity); } |