From: Milo Sredkov Date: Fri, 1 Feb 2019 12:23:24 +0000 (+0000) Subject: Add logging for tap-to-edit smart replies X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=13d88111c31c108664bc41d87fb303ac5353b52d;p=android-x86%2Fframeworks-base.git Add logging for tap-to-edit smart replies Log the status of getEditChoicesBeforeSending with the SMART_REPLY_VISIBLE and SMART_REPLY_ACTION events. Log whether the reply was changed before sending with the SMART_REPLY_ACTION event. Bug: 123407240 Test: atest NotificationManagerServiceTest SmartReplyControllerTest SmartReplyViewTest NotificationContentViewTest RemoteInputViewTest SmartReplyViewTest Change-Id: I92bf9b9486f023e7a1ab553c24a9d021dc2f3133 --- diff --git a/core/java/com/android/internal/statusbar/IStatusBarService.aidl b/core/java/com/android/internal/statusbar/IStatusBarService.aidl index 9df37ada7701..bfb50848df26 100644 --- a/core/java/com/android/internal/statusbar/IStatusBarService.aidl +++ b/core/java/com/android/internal/statusbar/IStatusBarService.aidl @@ -69,8 +69,9 @@ interface IStatusBarService void onNotificationExpansionChanged(in String key, in boolean userAction, in boolean expanded, in int notificationLocation); void onNotificationDirectReplied(String key); void onNotificationSmartSuggestionsAdded(String key, int smartReplyCount, int smartActionCount, - boolean generatedByAsssistant); - void onNotificationSmartReplySent(in String key, in int replyIndex, in CharSequence reply, boolean generatedByAssistant, in int notificationLocation); + boolean generatedByAsssistant, boolean editBeforeSending); + void onNotificationSmartReplySent(in String key, in int replyIndex, in CharSequence reply, + in int notificationLocation, boolean modifiedBeforeSending); void onNotificationSettingsViewed(String key); void setSystemUiVisibility(int displayId, int vis, int mask, String cause); diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationRemoteInputManager.java b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationRemoteInputManager.java index 31d16211f521..491f310cedf2 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationRemoteInputManager.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationRemoteInputManager.java @@ -54,6 +54,7 @@ import com.android.systemui.Dumpable; import com.android.systemui.statusbar.notification.NotificationEntryListener; import com.android.systemui.statusbar.notification.NotificationEntryManager; import com.android.systemui.statusbar.notification.collection.NotificationEntry; +import com.android.systemui.statusbar.notification.collection.NotificationEntry.EditedSuggestionInfo; import com.android.systemui.statusbar.notification.logging.NotificationLogger; import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow; import com.android.systemui.statusbar.phone.ShadeController; @@ -231,7 +232,8 @@ public class NotificationRemoteInputManager implements Dumpable { return false; } - return activateRemoteInput(view, inputs, input, pendingIntent); + return activateRemoteInput(view, inputs, input, pendingIntent, + null /* editedSuggestionInfo */); } }; @@ -291,6 +293,19 @@ public class NotificationRemoteInputManager implements Dumpable { } try { mBarService.onNotificationDirectReplied(entry.notification.getKey()); + if (entry.editedSuggestionInfo != null) { + boolean modifiedBeforeSending = + !TextUtils.equals(entry.remoteInputText, + entry.editedSuggestionInfo.originalText); + mBarService.onNotificationSmartReplySent( + entry.notification.getKey(), + entry.editedSuggestionInfo.index, + entry.editedSuggestionInfo.originalText, + NotificationLogger + .getNotificationLocation(entry) + .toMetricsEventEnum(), + modifiedBeforeSending); + } } catch (RemoteException e) { // Nothing to do, system going down } @@ -310,10 +325,12 @@ public class NotificationRemoteInputManager implements Dumpable { * @param inputs The remote inputs that need to be sent to the app. * @param input The remote input that needs to be activated. * @param pendingIntent The pending intent to be sent to the app. + * @param editedSuggestionInfo The smart reply that should be inserted in the remote input, or + * {@code null} if the user is not editing a smart reply. * @return Whether the {@link RemoteInput} was activated. */ public boolean activateRemoteInput(View view, RemoteInput[] inputs, RemoteInput input, - PendingIntent pendingIntent) { + PendingIntent pendingIntent, @Nullable EditedSuggestionInfo editedSuggestionInfo) { ViewParent p = view.getParent(); RemoteInputView riv = null; @@ -386,7 +403,7 @@ public class NotificationRemoteInputManager implements Dumpable { riv.setRevealParameters(cx, cy, r); riv.setPendingIntent(pendingIntent); - riv.setRemoteInput(inputs, input); + riv.setRemoteInput(inputs, input, editedSuggestionInfo); riv.focusAnimated(); return true; diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/SmartReplyController.java b/packages/SystemUI/src/com/android/systemui/statusbar/SmartReplyController.java index 5a8f71d6627d..736b9ebea5c3 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/SmartReplyController.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/SmartReplyController.java @@ -56,13 +56,12 @@ public class SmartReplyController { * Notifies StatusBarService a smart reply is sent. */ public void smartReplySent(NotificationEntry entry, int replyIndex, CharSequence reply, - boolean generatedByAssistant, int notificationLocation) { + int notificationLocation, boolean modifiedBeforeSending) { mCallback.onSmartReplySent(entry, reply); mSendingKeys.add(entry.key); try { - mBarService.onNotificationSmartReplySent( - entry.notification.getKey(), replyIndex, reply, generatedByAssistant, - notificationLocation); + mBarService.onNotificationSmartReplySent(entry.notification.getKey(), replyIndex, reply, + notificationLocation, modifiedBeforeSending); } catch (RemoteException e) { // Nothing to do, system going down } @@ -100,10 +99,10 @@ public class SmartReplyController { * Smart Replies and Actions have been added to the UI. */ public void smartSuggestionsAdded(final NotificationEntry entry, int replyCount, - int actionCount, boolean generatedByAssistant) { + int actionCount, boolean generatedByAssistant, boolean editBeforeSending) { try { - mBarService.onNotificationSmartSuggestionsAdded( - entry.notification.getKey(), replyCount, actionCount, generatedByAssistant); + mBarService.onNotificationSmartSuggestionsAdded(entry.notification.getKey(), replyCount, + actionCount, generatedByAssistant, editBeforeSending); } catch (RemoteException e) { // Nothing to do, system going down } 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 db9fcc89f4a9..9f1693c71459 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 @@ -105,6 +105,14 @@ public final class NotificationEntry { /** Smart replies provided by the NotificationAssistantService. */ @NonNull public CharSequence[] systemGeneratedSmartReplies = new CharSequence[0]; + + /** + * If {@link android.app.RemoteInput#getEditChoicesBeforeSending} is enabled, and the user is + * currently editing a choice (smart reply), then this field contains the information about the + * suggestion being edited. Otherwise null. + */ + public EditedSuggestionInfo editedSuggestionInfo; + @VisibleForTesting public int suppressedVisualEffects; public boolean suspended; @@ -746,4 +754,23 @@ public final class NotificationEntry { private static boolean isCategory(String category, Notification n) { return Objects.equals(n.category, category); } + + /** Information about a suggestion that is being edited. */ + public static class EditedSuggestionInfo { + + /** + * The value of the suggestion (before any user edits). + */ + public final CharSequence originalText; + + /** + * The index of the suggestion that is being edited. + */ + public final int index; + + public EditedSuggestionInfo(CharSequence originalText, int index) { + this.originalText = originalText; + this.index = index; + } + } } 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 878d533e91a6..80956159c20b 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 @@ -1509,8 +1509,13 @@ public class NotificationContentView extends FrameLayout { boolean fromAssistant = smartRepliesAndActions.smartReplies == null ? smartRepliesAndActions.smartActions.fromAssistant : smartRepliesAndActions.smartReplies.fromAssistant; + boolean editBeforeSending = smartRepliesAndActions.smartReplies != null + && mSmartReplyConstants.getEffectiveEditChoicesBeforeSending( + smartRepliesAndActions.smartReplies.remoteInput + .getEditChoicesBeforeSending()); + mSmartReplyController.smartSuggestionsAdded(entry, numSmartReplies, - numSmartActions, fromAssistant); + numSmartActions, fromAssistant, editBeforeSending); } } } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/RemoteInputView.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/RemoteInputView.java index 7881df97df2a..1e090630efdb 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/RemoteInputView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/RemoteInputView.java @@ -18,6 +18,7 @@ package com.android.systemui.statusbar.policy; import android.animation.Animator; import android.animation.AnimatorListenerAdapter; +import android.annotation.Nullable; import android.app.ActivityManager; import android.app.Notification; import android.app.PendingIntent; @@ -59,6 +60,7 @@ import com.android.systemui.Interpolators; import com.android.systemui.R; import com.android.systemui.statusbar.RemoteInputController; import com.android.systemui.statusbar.notification.collection.NotificationEntry; +import com.android.systemui.statusbar.notification.collection.NotificationEntry.EditedSuggestionInfo; import com.android.systemui.statusbar.notification.row.wrapper.NotificationViewWrapper; import com.android.systemui.statusbar.notification.stack.StackStateAnimator; @@ -269,10 +271,24 @@ public class RemoteInputView extends LinearLayout implements View.OnClickListene mPendingIntent = pendingIntent; } - public void setRemoteInput(RemoteInput[] remoteInputs, RemoteInput remoteInput) { + /** + * Sets the remote input for this view. + * + * @param remoteInputs The remote inputs that need to be sent to the app. + * @param remoteInput The remote input that needs to be activated. + * @param editedSuggestionInfo The smart reply that should be inserted in the remote input, or + * {@code null} if the user is not editing a smart reply. + */ + public void setRemoteInput(RemoteInput[] remoteInputs, RemoteInput remoteInput, + @Nullable EditedSuggestionInfo editedSuggestionInfo) { mRemoteInputs = remoteInputs; mRemoteInput = remoteInput; mEditText.setHint(mRemoteInput.getLabel()); + + mEntry.editedSuggestionInfo = editedSuggestionInfo; + if (editedSuggestionInfo != null) { + mEntry.remoteInputText = editedSuggestionInfo.originalText; + } } public void focusAnimated() { @@ -389,7 +405,7 @@ public class RemoteInputView extends LinearLayout implements View.OnClickListene public void stealFocusFrom(RemoteInputView other) { other.close(); setPendingIntent(other.mPendingIntent); - setRemoteInput(other.mRemoteInputs, other.mRemoteInput); + setRemoteInput(other.mRemoteInputs, other.mRemoteInput, mEntry.editedSuggestionInfo); setRevealParameters(other.mRevealCx, other.mRevealCy, other.mRevealR); focus(); } @@ -429,7 +445,7 @@ public class RemoteInputView extends LinearLayout implements View.OnClickListene continue; } setPendingIntent(a.actionIntent); - setRemoteInput(inputs, input); + setRemoteInput(inputs, input, null /* editedSuggestionInfo*/); return true; } return false; diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/SmartReplyView.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/SmartReplyView.java index 1d2d6f784620..45d215ef309c 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/SmartReplyView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/SmartReplyView.java @@ -38,6 +38,7 @@ import com.android.systemui.statusbar.NotificationRemoteInputManager; import com.android.systemui.statusbar.SmartReplyController; import com.android.systemui.statusbar.notification.NotificationUtils; import com.android.systemui.statusbar.notification.collection.NotificationEntry; +import com.android.systemui.statusbar.notification.collection.NotificationEntry.EditedSuggestionInfo; import com.android.systemui.statusbar.notification.logging.NotificationLogger; import com.android.systemui.statusbar.phone.KeyguardDismissUtil; @@ -252,16 +253,17 @@ public class SmartReplyView extends ViewGroup { OnDismissAction action = () -> { if (mConstants.getEffectiveEditChoicesBeforeSending( smartReplies.remoteInput.getEditChoicesBeforeSending())) { - entry.remoteInputText = choice; + EditedSuggestionInfo editedSuggestionInfo = + new EditedSuggestionInfo(choice, replyIndex); mRemoteInputManager.activateRemoteInput(b, new RemoteInput[] { smartReplies.remoteInput }, smartReplies.remoteInput, - smartReplies.pendingIntent); + smartReplies.pendingIntent, editedSuggestionInfo); return false; } smartReplyController.smartReplySent(entry, replyIndex, b.getText(), - smartReplies.fromAssistant, - NotificationLogger.getNotificationLocation(entry).toMetricsEventEnum()); + NotificationLogger.getNotificationLocation(entry).toMetricsEventEnum(), + false /* modifiedBeforeSending */); Bundle results = new Bundle(); results.putString(smartReplies.remoteInput.getResultKey(), choice.toString()); Intent intent = new Intent().addFlags(Intent.FLAG_RECEIVER_FOREGROUND); 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 f34e1a6b01e7..31cd28019ea9 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/SmartReplyControllerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/SmartReplyControllerTest.java @@ -98,8 +98,8 @@ public class SmartReplyControllerTest extends SysuiTestCase { @Test public void testSendSmartReply_updatesRemoteInput() { - mSmartReplyController.smartReplySent(mEntry, TEST_CHOICE_INDEX, TEST_CHOICE_TEXT, false, - MetricsEvent.LOCATION_UNKNOWN); + mSmartReplyController.smartReplySent(mEntry, TEST_CHOICE_INDEX, TEST_CHOICE_TEXT, + MetricsEvent.LOCATION_UNKNOWN, false /* modifiedBeforeSending */); // Sending smart reply should make calls to NotificationEntryManager // to update the notification with reply and spinner. @@ -109,48 +109,49 @@ public class SmartReplyControllerTest extends SysuiTestCase { @Test public void testSendSmartReply_logsToStatusBar() throws RemoteException { - mSmartReplyController.smartReplySent(mEntry, TEST_CHOICE_INDEX, TEST_CHOICE_TEXT, false, - MetricsEvent.LOCATION_UNKNOWN); + mSmartReplyController.smartReplySent(mEntry, TEST_CHOICE_INDEX, TEST_CHOICE_TEXT, + MetricsEvent.LOCATION_UNKNOWN, false /* modifiedBeforeSending */); // Check we log the result to the status bar service. verify(mIStatusBarService).onNotificationSmartReplySent(mSbn.getKey(), - TEST_CHOICE_INDEX, TEST_CHOICE_TEXT, false, MetricsEvent.LOCATION_UNKNOWN); + TEST_CHOICE_INDEX, TEST_CHOICE_TEXT, MetricsEvent.LOCATION_UNKNOWN, false); } @Test - public void testSendSmartReply_logsToStatusBar_generatedByAssistant() throws RemoteException { - mSmartReplyController.smartReplySent(mEntry, TEST_CHOICE_INDEX, TEST_CHOICE_TEXT, true, - MetricsEvent.LOCATION_UNKNOWN); + public void testSendSmartReply_logsToStatusBar_modifiedBeforeSending() throws RemoteException { + mSmartReplyController.smartReplySent(mEntry, TEST_CHOICE_INDEX, TEST_CHOICE_TEXT, + MetricsEvent.LOCATION_UNKNOWN, true /* modifiedBeforeSending */); // Check we log the result to the status bar service. verify(mIStatusBarService).onNotificationSmartReplySent(mSbn.getKey(), - TEST_CHOICE_INDEX, TEST_CHOICE_TEXT, true, MetricsEvent.LOCATION_UNKNOWN); + TEST_CHOICE_INDEX, TEST_CHOICE_TEXT, MetricsEvent.LOCATION_UNKNOWN, true); } @Test public void testShowSmartSuggestions_logsToStatusBar() throws RemoteException { final boolean generatedByAsssistant = true; + final boolean editBeforeSending = true; mSmartReplyController.smartSuggestionsAdded(mEntry, TEST_CHOICE_COUNT, TEST_ACTION_COUNT, - generatedByAsssistant); + generatedByAsssistant, editBeforeSending); // Check we log the result to the status bar service. verify(mIStatusBarService).onNotificationSmartSuggestionsAdded(mSbn.getKey(), - TEST_CHOICE_COUNT, TEST_ACTION_COUNT, generatedByAsssistant); + TEST_CHOICE_COUNT, TEST_ACTION_COUNT, generatedByAsssistant, editBeforeSending); } @Test public void testSendSmartReply_reportsSending() { - mSmartReplyController.smartReplySent(mEntry, TEST_CHOICE_INDEX, TEST_CHOICE_TEXT, false, - MetricsEvent.LOCATION_UNKNOWN); + mSmartReplyController.smartReplySent(mEntry, TEST_CHOICE_INDEX, TEST_CHOICE_TEXT, + MetricsEvent.LOCATION_UNKNOWN, false /* modifiedBeforeSending */); assertTrue(mSmartReplyController.isSendingSmartReply(mSbn.getKey())); } @Test public void testSendingSmartReply_afterRemove_shouldReturnFalse() { - mSmartReplyController.smartReplySent(mEntry, TEST_CHOICE_INDEX, TEST_CHOICE_TEXT, false, - MetricsEvent.LOCATION_UNKNOWN); + mSmartReplyController.smartReplySent(mEntry, TEST_CHOICE_INDEX, TEST_CHOICE_TEXT, + MetricsEvent.LOCATION_UNKNOWN, false /* modifiedBeforeSending */); mSmartReplyController.stopSending(mEntry); assertFalse(mSmartReplyController.isSendingSmartReply(mSbn.getKey())); diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/RemoteInputViewTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/RemoteInputViewTest.java index ed98c62502a4..568ff55f6d34 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/RemoteInputViewTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/RemoteInputViewTest.java @@ -96,7 +96,7 @@ public class RemoteInputViewTest extends SysuiTestCase { RemoteInput input = new RemoteInput.Builder(TEST_RESULT_KEY).build(); view.setPendingIntent(pendingIntent); - view.setRemoteInput(new RemoteInput[]{input}, input); + view.setRemoteInput(new RemoteInput[]{input}, input, null /* editedSuggestionInfo */); } @Test diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/SmartReplyViewTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/SmartReplyViewTest.java index 55701225af71..6793ecaabdd7 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/SmartReplyViewTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/SmartReplyViewTest.java @@ -191,15 +191,7 @@ public class SmartReplyViewTest extends SysuiTestCase { setSmartReplies(TEST_CHOICES); mView.getChildAt(2).performClick(); verify(mLogger).smartReplySent(mEntry, 2, TEST_CHOICES[2], - false /* generatedByAsssitant */, MetricsEvent.LOCATION_UNKNOWN); - } - - @Test - public void testSendSmartReply_controllerCalled_generatedByAssistant() { - setSmartReplies(TEST_CHOICES, true); - mView.getChildAt(2).performClick(); - verify(mLogger).smartReplySent(mEntry, 2, TEST_CHOICES[2], - true /* generatedByAsssitant */, MetricsEvent.LOCATION_UNKNOWN); + MetricsEvent.LOCATION_UNKNOWN, false /* modifiedBeforeSending */); } @Test diff --git a/proto/src/metrics_constants/metrics_constants.proto b/proto/src/metrics_constants/metrics_constants.proto index 76bb24d81e21..eb8710d6759d 100644 --- a/proto/src/metrics_constants/metrics_constants.proto +++ b/proto/src/metrics_constants/metrics_constants.proto @@ -6936,6 +6936,19 @@ message MetricsEvent { // OS: Q ACTION_SET_NEW_PARENT_PROFILE_PASSWORD = 1646; + // Tagged data for SMART_REPLY_VISIBLE and SMART_REPLY_ACTION. + // Whether the smart reply was / is to be sent via direct reply because + // getEditChoicesBeforeSending was enabled. + // OS: Q + NOTIFICATION_SMART_REPLY_EDIT_BEFORE_SENDING = 1647; + + // Tagged data for SMART_REPLY_ACTION. + // Whether the smart reply was modified by the user via the direct reply field (implies that + // getEditChoicesBeforeSending was enabled). + // actions/replies. + // OS: Q + NOTIFICATION_SMART_REPLY_MODIFIED_BEFORE_SENDING = 1648; + // ---- End Q Constants, all Q constants go above this line ---- // Add new aosp constants above this line. // END OF AOSP CONSTANTS diff --git a/services/core/java/com/android/server/notification/NotificationDelegate.java b/services/core/java/com/android/server/notification/NotificationDelegate.java index be15fdaf5abe..b85abd98b00f 100644 --- a/services/core/java/com/android/server/notification/NotificationDelegate.java +++ b/services/core/java/com/android/server/notification/NotificationDelegate.java @@ -51,7 +51,7 @@ public interface NotificationDelegate { * Notifies that smart replies and actions have been added to the UI. */ void onNotificationSmartSuggestionsAdded(String key, int smartReplyCount, int smartActionCount, - boolean generatedByAssistant); + boolean generatedByAssistant, boolean editBeforeSending); /** * Notifies a smart reply is sent. @@ -59,9 +59,9 @@ public interface NotificationDelegate { * @param key the notification key * @param clickedIndex the index of clicked reply * @param reply the reply that is sent - * @param generatedByAssistant specifies is the reply generated by NAS * @param notificationLocation the location of the notification containing the smart reply + * @param modifiedBeforeSending whether the user changed the smart reply before sending */ void onNotificationSmartReplySent(String key, int clickedIndex, CharSequence reply, - boolean generatedByAssistant, int notificationLocation); + int notificationLocation, boolean modifiedBeforeSending); } diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java index ba187c0884b9..34a6663c4352 100644 --- a/services/core/java/com/android/server/notification/NotificationManagerService.java +++ b/services/core/java/com/android/server/notification/NotificationManagerService.java @@ -917,20 +917,21 @@ public class NotificationManagerService extends SystemService { @Override public void onNotificationSmartSuggestionsAdded(String key, int smartReplyCount, - int smartActionCount, boolean generatedByAssistant) { + int smartActionCount, boolean generatedByAssistant, boolean editBeforeSending) { synchronized (mNotificationLock) { NotificationRecord r = mNotificationsByKey.get(key); if (r != null) { r.setNumSmartRepliesAdded(smartReplyCount); r.setNumSmartActionsAdded(smartActionCount); r.setSuggestionsGeneratedByAssistant(generatedByAssistant); + r.setEditChoicesBeforeSending(editBeforeSending); } } } @Override public void onNotificationSmartReplySent(String key, int replyIndex, CharSequence reply, - boolean generatedByAssistant, int notificationLocation) { + int notificationLocation, boolean modifiedBeforeSending) { synchronized (mNotificationLock) { NotificationRecord r = mNotificationsByKey.get(key); @@ -940,14 +941,20 @@ public class NotificationManagerService extends SystemService { .setSubtype(replyIndex) .addTaggedData( MetricsEvent.NOTIFICATION_SMART_SUGGESTION_ASSISTANT_GENERATED, - generatedByAssistant ? 1 : 0) + r.getSuggestionsGeneratedByAssistant() ? 1 : 0) .addTaggedData(MetricsEvent.NOTIFICATION_LOCATION, - notificationLocation); + notificationLocation) + .addTaggedData( + MetricsEvent.NOTIFICATION_SMART_REPLY_EDIT_BEFORE_SENDING, + r.getEditChoicesBeforeSending() ? 1 : 0) + .addTaggedData( + MetricsEvent.NOTIFICATION_SMART_REPLY_MODIFIED_BEFORE_SENDING, + modifiedBeforeSending ? 1 : 0); mMetricsLogger.write(logMaker); // Treat clicking on a smart reply as a user interaction. reportUserInteraction(r); mAssistants.notifyAssistantSuggestedReplySent( - r.sbn, reply, generatedByAssistant); + r.sbn, reply, r.getSuggestionsGeneratedByAssistant()); } } } @@ -981,7 +988,10 @@ public class NotificationManagerService extends SystemService { r.getSuggestionsGeneratedByAssistant() ? 1 : 0) // The fields in the NotificationVisibility.NotificationLocation enum map // directly to the fields in the MetricsEvent.NotificationLocation enum. - .addTaggedData(MetricsEvent.NOTIFICATION_LOCATION, notificationLocation); + .addTaggedData(MetricsEvent.NOTIFICATION_LOCATION, notificationLocation) + .addTaggedData( + MetricsEvent.NOTIFICATION_SMART_REPLY_EDIT_BEFORE_SENDING, + r.getEditChoicesBeforeSending() ? 1 : 0); mMetricsLogger.write(logMaker); } } diff --git a/services/core/java/com/android/server/notification/NotificationRecord.java b/services/core/java/com/android/server/notification/NotificationRecord.java index ab49ebb66fbf..b3394b4c599f 100644 --- a/services/core/java/com/android/server/notification/NotificationRecord.java +++ b/services/core/java/com/android/server/notification/NotificationRecord.java @@ -178,6 +178,7 @@ public final class NotificationRecord { private int mNumberOfSmartRepliesAdded; private int mNumberOfSmartActionsAdded; private boolean mSuggestionsGeneratedByAssistant; + private boolean mEditChoicesBeforeSending; private boolean mHasSeenSmartReplies; /** * Whether this notification (and its channels) should be considered user locked. Used in @@ -1136,6 +1137,14 @@ public final class NotificationRecord { return mSuggestionsGeneratedByAssistant; } + public boolean getEditChoicesBeforeSending() { + return mEditChoicesBeforeSending; + } + + public void setEditChoicesBeforeSending(boolean editChoicesBeforeSending) { + mEditChoicesBeforeSending = editChoicesBeforeSending; + } + 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 d932a4040cb0..0493ae908f12 100644 --- a/services/core/java/com/android/server/statusbar/StatusBarManagerService.java +++ b/services/core/java/com/android/server/statusbar/StatusBarManagerService.java @@ -1280,12 +1280,12 @@ public class StatusBarManagerService extends IStatusBarService.Stub implements D @Override public void onNotificationSmartSuggestionsAdded(String key, int smartReplyCount, - int smartActionCount, boolean generatedByAssistant) { + int smartActionCount, boolean generatedByAssistant, boolean editBeforeSending) { enforceStatusBarService(); long identity = Binder.clearCallingIdentity(); try { mNotificationDelegate.onNotificationSmartSuggestionsAdded(key, smartReplyCount, - smartActionCount, generatedByAssistant); + smartActionCount, generatedByAssistant, editBeforeSending); } finally { Binder.restoreCallingIdentity(identity); } @@ -1293,13 +1293,13 @@ public class StatusBarManagerService extends IStatusBarService.Stub implements D @Override public void onNotificationSmartReplySent( - String key, int replyIndex, CharSequence reply, boolean generatedByAssistant, - int notificationLocation) throws RemoteException { + String key, int replyIndex, CharSequence reply, int notificationLocation, + boolean modifiedBeforeSending) throws RemoteException { enforceStatusBarService(); long identity = Binder.clearCallingIdentity(); try { mNotificationDelegate.onNotificationSmartReplySent(key, replyIndex, reply, - generatedByAssistant, notificationLocation); + notificationLocation, modifiedBeforeSending); } finally { Binder.restoreCallingIdentity(identity); } diff --git a/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java b/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java index 4cae3b3f9ae7..72aa0f2ba09e 100644 --- a/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +++ b/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java @@ -3925,13 +3925,16 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { public void testOnNotificationSmartReplySent() { final int replyIndex = 2; final String reply = "Hello"; + final boolean modifiedBeforeSending = true; final boolean generatedByAssistant = true; NotificationRecord r = generateNotificationRecord(mTestNotificationChannel); + r.setSuggestionsGeneratedByAssistant(generatedByAssistant); mService.addNotification(r); mService.mNotificationDelegate.onNotificationSmartReplySent( - r.getKey(), replyIndex, reply, generatedByAssistant, NOTIFICATION_LOCATION_UNKNOWN); + r.getKey(), replyIndex, reply, NOTIFICATION_LOCATION_UNKNOWN, + modifiedBeforeSending); verify(mAssistants).notifyAssistantSuggestedReplySent( eq(r.sbn), eq(reply), eq(generatedByAssistant)); }