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

Commit d8d34fcb authored by yyhua's avatar yyhua
Browse files

[AnimatedAction] Fix the issue so that only text replied (the choice text...

[AnimatedAction] Fix the issue so that only text replied (the choice text without attribution text) appears after the animated reply button is clicked.

change:
- If the tapped button is animated reply, then use the choice pure text (should not use button.text as it includes attribution text).
- Otherwise, keep the existing behavior(use button.text ).

Bug: 383567383
Test: atest SmartReplyViewTest
Flag: com.android.systemui.notification_animated_actions_treatment
Change-Id: I97d02cd5027619420064b0f24a65b2af334fed78
parent 87651110
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -597,7 +597,7 @@ constructor(
                smartReplyController.smartReplySent(
                    entry,
                    replyIndex,
                    button.text,
                    if (Flags.notificationAnimatedActionsTreatment()) choice else button.text,
                    NotificationLogger.getNotificationLocation(entry).toMetricsEventEnum(),
                    false, /* modifiedBeforeSending */
                )
+45 −0
Original line number Diff line number Diff line
@@ -36,8 +36,12 @@ import android.content.IntentFilter;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.Icon;
import android.platform.test.annotations.EnableFlags;
import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper;
import android.text.Annotation;
import android.text.Spannable;
import android.text.SpannableString;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
@@ -47,6 +51,7 @@ import androidx.test.filters.SmallTest;

import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.keyguard.KeyguardUpdateMonitor;
import com.android.systemui.Flags;
import com.android.systemui.SysuiTestCase;
import com.android.systemui.plugins.ActivityStarter;
import com.android.systemui.plugins.ActivityStarter.OnDismissAction;
@@ -266,6 +271,27 @@ public class SmartReplyViewTest extends SysuiTestCase {
        assertEquals(View.GONE, mContainer.getVisibility());
    }

    @Test
    @EnableFlags(Flags.FLAG_NOTIFICATION_ANIMATED_ACTIONS_TREATMENT)
    public void testSendSmartReply_controllerCalledForSmartReply() {
        CharSequence[] testChoices = createChoicesWithAnimatedReply();
        setSmartReplies(testChoices);
        mView.getChildAt(2).performClick();
        verify(mSmartReplyController).smartReplySent(mEntry, 2, testChoices[2],
                MetricsEvent.LOCATION_UNKNOWN, false /* modifiedBeforeSending */);
    }

    @Test
    @EnableFlags(Flags.FLAG_NOTIFICATION_ANIMATED_ACTIONS_TREATMENT)
    public void testSendSmartReply_controllerCalledForAnimatedReply() {
        CharSequence[] testChoices = createChoicesWithAnimatedReply();
        setSmartReplies(testChoices);
        mView.getChildAt(0).performClick();
        // Verify the reply to display after button tap is the choice text without attribution text.
        verify(mSmartReplyController).smartReplySent(mEntry, 0, testChoices[0],
                MetricsEvent.LOCATION_UNKNOWN, false /* modifiedBeforeSending */);
    }

    @Test
    public void testTapSmartReply_beforeInitDelay_blocked() throws InterruptedException {
        // 100 seconds is easily enough for our click to always be blocked.
@@ -539,6 +565,25 @@ public class SmartReplyViewTest extends SysuiTestCase {
                        mView, mEntry, smartReplies, idx, choices[idx], useDelayedOnClickListener));
    }

    private CharSequence[] createChoicesWithAnimatedReply() {
        CharSequence choice1 = addAnnotationToChoice("Hello", true, "attr2");
        CharSequence choice2 = "What's up?";
        CharSequence choice3 = "I'm here";
        return new CharSequence[]{choice1, choice2, choice3};
    }

    private SpannableString addAnnotationToChoice(CharSequence choice, boolean isAnimatedReply,
            String attrText) {
        SpannableString spannableString = new SpannableString(choice);
        if (isAnimatedReply) {
            spannableString.setSpan(new Annotation("isAnimatedReply", "1"), 0, choice.length(),
                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
        spannableString.setSpan(new Annotation("attributionText", attrText), 0, choice.length(),
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        return spannableString;
    }

    private Notification.Action createAction(String actionTitle) {
        PendingIntent pendingIntent = PendingIntent.getBroadcast(mContext, 0,
                new Intent(TEST_ACTION).setPackage(mContext.getPackageName()),