Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1ee9c9d0 authored by Gustav Sennton's avatar Gustav Sennton
Browse files

Make the smart-replies 'enabled' key control both actions and replies.

The key named 'enabled' in the flag SMART_REPLIES_IN_NOTIFICATIONS_FLAGS
currently only controls whether app-generated smart replies will be
shown in the system UI.
With this change that key controls both replies and actions from both
the system (the assistant) and the app. So if the flag is turned off
users won't see any smart suggestions at all.

Bug: 122506860
Test: atest SystemUITests
Test: 'adb shell settings put global
    smart_replies_in_notifications_flags enabled=X' for different
    values of X and ensure smart suggestions are turned on/off
    accordingly.
Change-Id: Id6b1072f11bf1ec4e0b68ef2cefb7e28bb65746e
parent ffcf6e54
Loading
Loading
Loading
Loading
+9 −4
Original line number Diff line number Diff line
@@ -1314,16 +1314,21 @@ public class NotificationContentView extends FrameLayout {
    static SmartRepliesAndActions chooseSmartRepliesAndActions(
            SmartReplyConstants smartReplyConstants,
            final NotificationEntry entry) {
        boolean enableAppGeneratedSmartReplies = (smartReplyConstants.isEnabled()
                && (!smartReplyConstants.requiresTargetingP()
                || entry.targetSdk >= Build.VERSION_CODES.P));

        Notification notification = entry.notification.getNotification();
        Pair<RemoteInput, Notification.Action> remoteInputActionPair =
                notification.findRemoteInputActionPair(false /* freeform */);
        Pair<RemoteInput, Notification.Action> freeformRemoteInputActionPair =
                notification.findRemoteInputActionPair(true /* freeform */);

        if (!smartReplyConstants.isEnabled()) {
            return new SmartRepliesAndActions(null, null, freeformRemoteInputActionPair != null);
        }
        // Only use smart replies from the app if they target P or above. We have this check because
        // the smart reply API has been used for other things (Wearables) in the past. The API to
        // add smart actions is new in Q so it doesn't require a target-sdk check.
        boolean enableAppGeneratedSmartReplies = (!smartReplyConstants.requiresTargetingP()
                || entry.targetSdk >= Build.VERSION_CODES.P);

        boolean appGeneratedSmartRepliesExist =
                enableAppGeneratedSmartReplies
                        && remoteInputActionPair != null
+20 −2
Original line number Diff line number Diff line
@@ -193,14 +193,32 @@ public class NotificationContentViewTest extends SysuiTestCase {
    }

    @Test
    public void chooseSmartRepliesAndActions_smartRepliesOff_noAppGeneratedSmartReplies() {
        setupAppGeneratedReplies(new String[] {"Reply1", "Reply2"});
    public void chooseSmartRepliesAndActions_smartRepliesOff_noAppGeneratedSmartSuggestions() {
        CharSequence[] smartReplies = new String[] {"Reply1", "Reply2"};
        List<Notification.Action> smartActions =
                createActions(new String[] {"Test Action 1", "Test Action 2"});
        setupAppGeneratedSuggestions(smartReplies, smartActions);
        when(mSmartReplyConstants.isEnabled()).thenReturn(false);

        NotificationContentView.SmartRepliesAndActions repliesAndActions =
                NotificationContentView.chooseSmartRepliesAndActions(mSmartReplyConstants, mEntry);

        assertThat(repliesAndActions.smartReplies).isNull();
        assertThat(repliesAndActions.smartActions).isNull();
    }

    @Test
    public void chooseSmartRepliesAndActions_smartRepliesOff_noSystemGeneratedSmartSuggestions() {
        mEntry.smartReplies = new String[] {"Sys Smart Reply 1", "Sys Smart Reply 2"};
        mEntry.systemGeneratedSmartActions =
                createActions(new String[] {"Sys Smart Action 1", "Sys Smart Action 2"});
        when(mSmartReplyConstants.isEnabled()).thenReturn(false);

        NotificationContentView.SmartRepliesAndActions repliesAndActions =
                NotificationContentView.chooseSmartRepliesAndActions(mSmartReplyConstants, mEntry);

        assertThat(repliesAndActions.smartReplies).isNull();
        assertThat(repliesAndActions.smartActions).isNull();
    }

    @Test