Fix the text direction of the conversation group name.

- The direction of the conversation group name should be based on its content to make sure it renders properly. However, the direction of the whole notification string (sender + delimiter + group name) should be based on the locale to make sure it appears correctly according to the system layout.
- Used isolate to make sure sender name, conversation title or the
delimitter do not impact each other in terms of text direction since we
have no control over their content.

Bug: 161947712
Test: Manual

Change-Id: I0437171fcf35e1dc20a0cb6e38454dad5f77b956
diff --git a/car-messenger-common/src/com/android/car/messenger/common/Utils.java b/car-messenger-common/src/com/android/car/messenger/common/Utils.java
index 68ed3aa..c52cc56 100644
--- a/car-messenger-common/src/com/android/car/messenger/common/Utils.java
+++ b/car-messenger-common/src/com/android/car/messenger/common/Utils.java
@@ -373,9 +373,9 @@
     public static String constructGroupConversationHeader(String senderName, String groupName,
             String delimiter, BidiFormatter bidiFormatter) {
         String formattedSenderName = bidiFormatter.unicodeWrap(senderName,
-                TextDirectionHeuristics.FIRSTSTRONG_LTR);
+                TextDirectionHeuristics.FIRSTSTRONG_LTR, /* isolate= */ true);
         String formattedGroupName = bidiFormatter.unicodeWrap(groupName,
-                TextDirectionHeuristics.LOCALE);
+                TextDirectionHeuristics.FIRSTSTRONG_LTR, /* isolate= */ true);
         String title = String.join(delimiter, formattedSenderName, formattedGroupName);
         return bidiFormatter.unicodeWrap(title, TextDirectionHeuristics.LOCALE);
     }
diff --git a/car-messenger-common/tests/unit/src/com.android.car.messenger.common/UtilsTest.java b/car-messenger-common/tests/unit/src/com.android.car.messenger.common/UtilsTest.java
index acdffbd..c64703a 100644
--- a/car-messenger-common/tests/unit/src/com.android.car.messenger.common/UtilsTest.java
+++ b/car-messenger-common/tests/unit/src/com.android.car.messenger.common/UtilsTest.java
@@ -200,4 +200,17 @@
 
         assertThat(actual).isEqualTo(expected);
     }
+
+    @Test
+    public void testTitleConstructorRtl_withTrailingPunctuation() {
+        String actual = Utils.constructGroupConversationHeader("Christopher",
+                "Abcd!!!", TITLE_DELIMITER, /* isRtl */
+                RTL_FORMATTER).trim();
+
+        String expected =
+                "\u200F\u202A\u200F\u202AChristopher\u202C\u200F : \u200F\u202AAbcd!!!"
+                        + "\u202C\u200F\u202C\u200F";
+
+        assertThat(actual).isEqualTo(expected);
+    }
 }