diff --git a/src/com/android/settings/notification/app/ConversationListPreferenceController.java b/src/com/android/settings/notification/app/ConversationListPreferenceController.java index afb965f2477..948a3611cb7 100644 --- a/src/com/android/settings/notification/app/ConversationListPreferenceController.java +++ b/src/com/android/settings/notification/app/ConversationListPreferenceController.java @@ -163,8 +163,16 @@ public abstract class ConversationListPreferenceController extends AbstractPrefe return o1.getNotificationChannel().getId().compareTo( o2.getNotificationChannel().getId()); } - return sCollator.compare(o1.getShortcutInfo().getLabel(), - o2.getShortcutInfo().getLabel()); + if (o1.getShortcutInfo().getLabel() == null + && o2.getShortcutInfo().getLabel() != null) { + return 1; + } + if (o1.getShortcutInfo().getLabel() != null + && o2.getShortcutInfo().getLabel() == null) { + return -1; + } + return sCollator.compare(o1.getShortcutInfo().getLabel().toString(), + o2.getShortcutInfo().getLabel().toString()); } }; } diff --git a/tests/robotests/src/com/android/settings/notification/app/ConversationListPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/app/ConversationListPreferenceControllerTest.java index 6714031e73a..8113f22826e 100644 --- a/tests/robotests/src/com/android/settings/notification/app/ConversationListPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/notification/app/ConversationListPreferenceControllerTest.java @@ -33,6 +33,12 @@ import android.content.pm.ShortcutInfo; import android.os.Bundle; import android.provider.Settings; import android.service.notification.ConversationChannelWrapper; +import android.text.SpannableStringBuilder; +import android.text.Spanned; +import android.text.style.BulletSpan; +import android.text.style.QuoteSpan; +import android.text.style.SubscriptSpan; +import android.text.style.UnderlineSpan; import androidx.preference.Preference; import androidx.preference.PreferenceCategory; @@ -211,6 +217,29 @@ public class ConversationListPreferenceControllerTest { ccw.getNotificationChannel().getConversationId()); } + @Test + public void testCompareSpans() { + ConversationChannelWrapper one = new ConversationChannelWrapper(); + String text1 = "one one"; + SpannableStringBuilder builder1 = new SpannableStringBuilder(text1); + Object first1 = new SubscriptSpan(); + builder1.setSpan(first1, 2, 4, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); + ShortcutInfo s1 = new ShortcutInfo.Builder(mContext, "one").setShortLabel( + builder1).build(); + one.setShortcutInfo(s1); + + ConversationChannelWrapper two = new ConversationChannelWrapper(); + String text2 = "two two"; + SpannableStringBuilder builder2 = new SpannableStringBuilder(text2); + Object first2 = new SubscriptSpan(); + builder2.setSpan(first2, 2, 4, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); + ShortcutInfo s2 = new ShortcutInfo.Builder(mContext, "two").setShortLabel( + builder2).build(); + two.setShortcutInfo(s2); + + assertThat(mController.mConversationComparator.compare(one, two)).isLessThan(0); + } + private final class TestPreferenceController extends ConversationListPreferenceController { private TestPreferenceController(Context context, NotificationBackend backend) {