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

Commit 8a5c213c authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Add experiment flag for maximum number of smart actions per notification"

parents 7315e7c6 4bf5ff58
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -14107,6 +14107,7 @@ public final class Settings {
         * edit_choices_before_sending       (boolean)
         * show_in_heads_up                  (boolean)
         * min_num_system_generated_replies  (int)
         * max_num_actions                   (int)
         * </pre>
         * @see com.android.systemui.statusbar.policy.SmartReplyConstants
         * @hide
+4 −0
Original line number Diff line number Diff line
@@ -463,6 +463,10 @@
         show none. -->
    <integer name="config_smart_replies_in_notifications_min_num_system_generated_replies">0</integer>

    <!-- Smart replies in notifications: Maximum number of smart actions to show in notifications.
         -->
    <integer name="config_smart_replies_in_notifications_max_num_actions">-1</integer>

    <!-- Screenshot editing default activity.  Must handle ACTION_EDIT image/png intents.
         Blank sends the user to the Chooser first.
         This name is in the ComponentName flattened format (package/class)  -->
+14 −0
Original line number Diff line number Diff line
@@ -47,6 +47,7 @@ public final class SmartReplyConstants extends ContentObserver {
            "edit_choices_before_sending";
    private static final String KEY_SHOW_IN_HEADS_UP = "show_in_heads_up";
    private static final String KEY_MIN_NUM_REPLIES = "min_num_system_generated_replies";
    private static final String KEY_MAX_NUM_ACTIONS = "max_num_actions";

    private final boolean mDefaultEnabled;
    private final boolean mDefaultRequiresP;
@@ -54,6 +55,7 @@ public final class SmartReplyConstants extends ContentObserver {
    private final boolean mDefaultEditChoicesBeforeSending;
    private final boolean mDefaultShowInHeadsUp;
    private final int mDefaultMinNumSystemGeneratedReplies;
    private final int mDefaultMaxNumActions;

    private boolean mEnabled;
    private boolean mRequiresTargetingP;
@@ -61,6 +63,7 @@ public final class SmartReplyConstants extends ContentObserver {
    private boolean mEditChoicesBeforeSending;
    private boolean mShowInHeadsUp;
    private int mMinNumSystemGeneratedReplies;
    private int mMaxNumActions;

    private final Context mContext;
    private final KeyValueListParser mParser = new KeyValueListParser(',');
@@ -83,6 +86,8 @@ public final class SmartReplyConstants extends ContentObserver {
                R.bool.config_smart_replies_in_notifications_show_in_heads_up);
        mDefaultMinNumSystemGeneratedReplies = resources.getInteger(
                R.integer.config_smart_replies_in_notifications_min_num_system_generated_replies);
        mDefaultMaxNumActions = resources.getInteger(
                R.integer.config_smart_replies_in_notifications_max_num_actions);

        mContext.getContentResolver().registerContentObserver(
                Settings.Global.getUriFor(Settings.Global.SMART_REPLIES_IN_NOTIFICATIONS_FLAGS),
@@ -112,6 +117,7 @@ public final class SmartReplyConstants extends ContentObserver {
            mShowInHeadsUp = mParser.getBoolean(KEY_SHOW_IN_HEADS_UP, mDefaultShowInHeadsUp);
            mMinNumSystemGeneratedReplies =
                    mParser.getInt(KEY_MIN_NUM_REPLIES, mDefaultMinNumSystemGeneratedReplies);
            mMaxNumActions = mParser.getInt(KEY_MAX_NUM_ACTIONS, mDefaultMaxNumActions);
        }
    }

@@ -170,4 +176,12 @@ public final class SmartReplyConstants extends ContentObserver {
    public int getMinNumSystemGeneratedReplies() {
        return mMinNumSystemGeneratedReplies;
    }

    /**
     * Returns the maximum number smart actions to show in a notification, or -1 if there shouldn't
     * be a limit.
     */
    public int getMaxNumActions() {
        return mMaxNumActions;
    }
}
+12 −0
Original line number Diff line number Diff line
@@ -372,8 +372,17 @@ public class SmartReplyView extends ViewGroup {
        // reply button is added.
        SmartSuggestionMeasures actionsMeasures = null;

        final int maxNumActions = mConstants.getMaxNumActions();
        int numShownActions = 0;

        for (View child : smartSuggestions) {
            final LayoutParams lp = (LayoutParams) child.getLayoutParams();
            if (maxNumActions != -1 // -1 means 'no limit'
                    && lp.buttonType == SmartButtonType.ACTION
                    && numShownActions >= maxNumActions) {
                // We've reached the maximum number of actions, don't add another one!
                continue;
            }

            child.setPadding(accumulatedMeasures.mButtonPaddingHorizontal, child.getPaddingTop(),
                    accumulatedMeasures.mButtonPaddingHorizontal, child.getPaddingBottom());
@@ -457,6 +466,9 @@ public class SmartReplyView extends ViewGroup {

            lp.show = true;
            displayedChildCount++;
            if (lp.buttonType == SmartButtonType.ACTION) {
                numShownActions++;
            }
        }

        if (mSmartRepliesGeneratedByAssistant) {
+13 −0
Original line number Diff line number Diff line
@@ -176,6 +176,19 @@ public class SmartReplyConstantsTest extends SysuiTestCase {
        assertFalse(mConstants.getShowInHeadsUp());
    }

    @Test
    public void testMaxNumActionsWithNoConfig() {
        assertTrue(mConstants.isEnabled());
        assertEquals(-1, mConstants.getMaxNumActions());
    }

    @Test
    public void testMaxNumActionsSet() {
        overrideSetting("enabled=true,max_num_actions=10");
        triggerConstantsOnChange();
        assertEquals(10, mConstants.getMaxNumActions());
    }

    private void overrideSetting(String flags) {
        Settings.Global.putString(mContext.getContentResolver(),
                Settings.Global.SMART_REPLIES_IN_NOTIFICATIONS_FLAGS, flags);
Loading