Fix several issues related to CircularIconsPreference

* Sometimes would cause an unending stream of accessibility events (particularly if starting off-screen). This would break TalkBack and anything that depends on UiAutomator (although the system itself took it like a champ).
* Sometimes would not load images (because the ViewTreeObserver would never fire onGlobalLayout after being added because measured width was 0, even though a new width was calculated later).
* Would not recalculate the number of icons that fit if the width changes after the first layout.

Combining ViewHolders with waiting for measuring and/or ViewTreeObservers was always a wonky approach, even though it should've worked in theory. This should be more robust.

Also fixes the unwanted animation on mode screen load related to the absence of the header name being applied a tad too late.

Fixes: 359948417
Fixes: 360072876
Fixes: 360328804
Test: atest SettingsRoboTests + manual + adb shell uiautomator events
Flag: android.app.modes_ui
Change-Id: I7e5dfbdab220d1ebc1c68e5e87ce544ee86b6a65
This commit is contained in:
Matías Hernández
2024-08-16 15:15:00 +02:00
parent 195c698cdf
commit b676ca3a62
13 changed files with 414 additions and 299 deletions

View File

@@ -62,8 +62,7 @@ public class CircularIconsPreferenceTest {
private Context mContext;
private CircularIconsPreference mPreference;
private PreferenceViewHolder mViewHolder;
private ViewGroup mContainer;
private CircularIconsView mContainer;
private int mOneIconWidth;
@@ -73,179 +72,211 @@ public class CircularIconsPreferenceTest {
mContext = RuntimeEnvironment.application;
CircularIconSet.sExecutorService = MoreExecutors.newDirectExecutorService();
mPreference = new TestableCircularIconsPreference(mContext);
// Tests should call bindAndMeasureViewHolder() so that icons can be added.
// Tests should call bindAndLayoutViewHolder() so that icons can be added.
Resources res = mContext.getResources();
mOneIconWidth = res.getDimensionPixelSize(R.dimen.zen_mode_circular_icon_diameter)
+ res.getDimensionPixelSize(R.dimen.zen_mode_circular_icon_margin_between);
}
private void bindAndMeasureViewHolder(int viewWidth) {
private void bindAndLayoutViewHolder(int viewWidth) {
bindViewHolder();
measureViewHolder(viewWidth);
layoutViewHolder(viewWidth);
}
private void bindViewHolder() {
View preferenceView = LayoutInflater.from(mContext).inflate(mPreference.getLayoutResource(),
null);
mContainer = checkNotNull(preferenceView.findViewById(R.id.circles_container));
mViewHolder = PreferenceViewHolder.createInstanceForTests(preferenceView);
mPreference.onBindViewHolder(mViewHolder);
mContainer.setUiExecutor(MoreExecutors.directExecutor());
PreferenceViewHolder viewHolder = PreferenceViewHolder.createInstanceForTests(
preferenceView);
mPreference.onBindViewHolder(viewHolder);
}
private void measureViewHolder(int viewWidth) {
private void layoutViewHolder(int viewWidth) {
checkState(mContainer != null, "Call bindViewHolder() first!");
mContainer.measure(makeMeasureSpec(viewWidth, View.MeasureSpec.EXACTLY),
makeMeasureSpec(1000, View.MeasureSpec.EXACTLY));
mContainer.getViewTreeObserver().dispatchOnGlobalLayout();
mContainer.layout(0, 0, viewWidth, 1000);
}
@Test
public void displayIcons_loadsIcons() {
public void setIcons_loadsIcons() {
CircularIconSet<Integer> iconSet = new CircularIconSet<>(ImmutableList.of(1, 2),
ColorDrawable::new);
bindAndMeasureViewHolder(VIEW_WIDTH);
mPreference.displayIcons(iconSet);
bindAndLayoutViewHolder(VIEW_WIDTH);
mPreference.setIcons(iconSet);
assertThat(getIcons(mContainer)).hasSize(2);
assertThat(((ColorDrawable) getIcons(mContainer).get(0)).getColor()).isEqualTo(1);
assertThat(((ColorDrawable) getIcons(mContainer).get(1)).getColor()).isEqualTo(2);
assertThat(getDrawables(mContainer)).hasSize(2);
assertThat(((ColorDrawable) getDrawables(mContainer).get(0)).getColor()).isEqualTo(1);
assertThat(((ColorDrawable) getDrawables(mContainer).get(1)).getColor()).isEqualTo(2);
assertThat(getPlusText(mContainer)).isNull();
}
@Test
public void displayIcons_noIcons_hidesRow() {
public void setIcons_noIcons_hidesRow() {
CircularIconSet<Integer> iconSet = new CircularIconSet<>(ImmutableList.of(),
ColorDrawable::new);
bindAndMeasureViewHolder(VIEW_WIDTH);
mPreference.displayIcons(iconSet);
bindAndLayoutViewHolder(VIEW_WIDTH);
mPreference.setIcons(iconSet);
assertThat(mContainer.getVisibility()).isEqualTo(View.GONE);
}
@Test
public void displayIcons_exactlyMaxIcons_loadsAllIcons() throws Exception {
public void setIcons_exactlyMaxIcons_loadsAllIcons() throws Exception {
int width = 300;
int fittingCircles = width / mOneIconWidth;
CircularIconSet<Integer> iconSet = new CircularIconSet<>(
IntStream.range(0, fittingCircles).boxed().toList(),
ColorDrawable::new);
bindAndMeasureViewHolder(width);
mPreference.displayIcons(iconSet);
bindAndLayoutViewHolder(width);
mPreference.setIcons(iconSet);
assertThat(getIcons(mContainer)).hasSize(fittingCircles);
assertThat(getIcons(mContainer)).containsExactlyElementsIn(
assertThat(getDrawables(mContainer)).hasSize(fittingCircles);
assertThat(getDrawables(mContainer)).containsExactlyElementsIn(
Futures.allAsList(iconSet.getIcons()).get()).inOrder();
assertThat(getPlusText(mContainer)).isNull();
}
@Test
public void displayIcons_tooManyIcons_loadsFirstNAndPlusIcon() throws Exception {
public void setIcons_tooManyIcons_loadsFirstNAndPlusIcon() throws Exception {
int width = 300;
int fittingCircles = width / mOneIconWidth;
CircularIconSet<Integer> iconSet = new CircularIconSet<>(
IntStream.range(0, fittingCircles + 5).boxed().toList(),
ColorDrawable::new);
bindAndMeasureViewHolder(width);
mPreference.displayIcons(iconSet);
bindAndLayoutViewHolder(width);
mPreference.setIcons(iconSet);
// N-1 icons, plus (+6) text.
assertThat(getIcons(mContainer)).hasSize(fittingCircles - 1);
assertThat(getIcons(mContainer)).containsExactlyElementsIn(
assertThat(getDrawables(mContainer)).hasSize(fittingCircles - 1);
assertThat(getDrawables(mContainer)).containsExactlyElementsIn(
Futures.allAsList(iconSet.getIcons(fittingCircles - 1)).get())
.inOrder();
assertThat(getPlusText(mContainer)).isEqualTo("+6");
}
@Test
public void displayIcons_teenyTinySpace_showsPlusIcon_noCrash() {
public void setIcons_teenyTinySpace_showsPlusIcon_noCrash() {
CircularIconSet<Integer> iconSet = new CircularIconSet<>(ImmutableList.of(1, 2),
ColorDrawable::new);
bindAndMeasureViewHolder(1);
mPreference.displayIcons(iconSet);
bindAndLayoutViewHolder(1);
mPreference.setIcons(iconSet);
assertThat(getIcons(mContainer)).isEmpty();
assertThat(getDrawables(mContainer)).isEmpty();
assertThat(getPlusText(mContainer)).isEqualTo("+2");
}
@Test
public void displayIcons_beforeBind_loadsIconsOnBindAndMeasure() {
public void setIcons_beforeBind_loadsIconsOnBindAndMeasure() {
CircularIconSet<Integer> iconSet = new CircularIconSet<>(ImmutableList.of(1, 2, 3),
ColorDrawable::new);
mPreference.displayIcons(iconSet);
assertThat(mPreference.getLoadedIcons()).isNull(); // Hold...
mPreference.setIcons(iconSet);
assertThat(mContainer).isNull(); // Hold...
bindViewHolder();
assertThat(mPreference.getLoadedIcons()).isNull(); // Hooooold...
assertThat(getDrawables(mContainer)).hasSize(0); // Hooooold...
measureViewHolder(VIEW_WIDTH);
assertThat(mPreference.getLoadedIcons().icons()).hasSize(3);
assertThat(getIcons(mContainer)).hasSize(3);
layoutViewHolder(VIEW_WIDTH);
assertThat(getDrawables(mContainer)).hasSize(3);
}
@Test
public void displayIcons_beforeMeasure_loadsIconsOnMeasure() {
public void setIcons_beforeMeasure_loadsIconsOnMeasure() {
CircularIconSet<Integer> iconSet = new CircularIconSet<>(ImmutableList.of(1, 2, 3),
ColorDrawable::new);
bindViewHolder();
mPreference.displayIcons(iconSet);
assertThat(mPreference.getLoadedIcons()).isNull();
mPreference.setIcons(iconSet);
assertThat(getDrawables(mContainer)).hasSize(0);
measureViewHolder(VIEW_WIDTH);
assertThat(getIcons(mContainer)).hasSize(3);
layoutViewHolder(VIEW_WIDTH);
assertThat(getDrawables(mContainer)).hasSize(3);
}
@Test
public void displayIcons_calledAgain_reloadsIcons() {
public void setIcons_calledAgain_reloadsIcons() {
CircularIconSet<Integer> threeIcons = new CircularIconSet<>(ImmutableList.of(1, 2, 3),
ColorDrawable::new);
CircularIconSet<Integer> twoIcons = new CircularIconSet<>(ImmutableList.of(1, 2),
ColorDrawable::new);
CircularIconSet<Integer> fourIcons = new CircularIconSet<>(ImmutableList.of(1, 2, 3, 4),
ColorDrawable::new);
bindAndMeasureViewHolder(VIEW_WIDTH);
bindAndLayoutViewHolder(VIEW_WIDTH);
mPreference.displayIcons(threeIcons);
assertThat(mPreference.getLoadedIcons()).isNotNull();
assertThat(getIcons(mContainer)).hasSize(3);
mPreference.setIcons(threeIcons);
assertThat(getDrawables(mContainer)).hasSize(3);
mPreference.displayIcons(twoIcons);
assertThat(mPreference.getLoadedIcons()).isNotNull();
assertThat(getIcons(mContainer)).hasSize(2);
mPreference.setIcons(twoIcons);
assertThat(getDrawables(mContainer)).hasSize(2);
mPreference.displayIcons(fourIcons);
assertThat(mPreference.getLoadedIcons()).isNotNull();
assertThat(getIcons(mContainer)).hasSize(4);
mPreference.setIcons(fourIcons);
assertThat(getDrawables(mContainer)).hasSize(4);
}
@Test
public void displayIcons_sameSet_doesNotReloadIcons() {
public void setIcons_sameSet_doesNotReloadIcons() {
CircularIconSet<Integer> one = new CircularIconSet<>(ImmutableList.of(1, 2, 3),
ColorDrawable::new);
CircularIconSet<Integer> same = Mockito.spy(new CircularIconSet<>(ImmutableList.of(1, 2, 3),
ColorDrawable::new));
when(same.getIcons()).thenThrow(new RuntimeException("Shouldn't be called!"));
bindAndMeasureViewHolder(VIEW_WIDTH);
bindAndLayoutViewHolder(VIEW_WIDTH);
mPreference.displayIcons(one);
mPreference.setIcons(one);
mPreference.displayIcons(same); // if no exception, wasn't called.
mPreference.setIcons(same); // if no exception, wasn't called.
}
@Test
public void sizeChanged_reloadsIconsIfDifferentFit() {
CircularIconSet<Integer> largeIconSet = new CircularIconSet<>(
IntStream.range(0, 100).boxed().toList(),
ColorDrawable::new);
mPreference.setIcons(largeIconSet);
// Base space -> some icons
int firstWidth = 600;
int firstFittingCircles = firstWidth / mOneIconWidth;
bindAndLayoutViewHolder(firstWidth);
assertThat(getDrawables(mContainer)).hasSize(firstFittingCircles - 1);
assertThat(getPlusText(mContainer)).isEqualTo("+" + (100 - (firstFittingCircles - 1)));
// More space -> more icons
int secondWidth = 1000;
int secondFittingCircles = secondWidth / mOneIconWidth;
assertThat(secondFittingCircles).isGreaterThan(firstFittingCircles);
bindAndLayoutViewHolder(secondWidth);
assertThat(getDrawables(mContainer)).hasSize(secondFittingCircles - 1);
assertThat(getPlusText(mContainer)).isEqualTo("+" + (100 - (secondFittingCircles - 1)));
// Less space -> fewer icons
int thirdWidth = 600;
int thirdFittingCircles = thirdWidth / mOneIconWidth;
bindAndLayoutViewHolder(thirdWidth);
assertThat(getDrawables(mContainer)).hasSize(thirdFittingCircles - 1);
assertThat(getPlusText(mContainer)).isEqualTo("+" + (100 - (thirdFittingCircles - 1)));
}
@Test
public void onBindViewHolder_withDifferentView_reloadsIconsCorrectly() {
View preferenceViewOne = LayoutInflater.from(mContext).inflate(
mPreference.getLayoutResource(), null);
ViewGroup containerOne = preferenceViewOne.findViewById(R.id.circles_container);
CircularIconsView containerOne = preferenceViewOne.findViewById(R.id.circles_container);
containerOne.setUiExecutor(MoreExecutors.directExecutor());
PreferenceViewHolder viewHolderOne = PreferenceViewHolder.createInstanceForTests(
preferenceViewOne);
containerOne.measure(makeMeasureSpec(1000, View.MeasureSpec.EXACTLY),
@@ -253,7 +284,8 @@ public class CircularIconsPreferenceTest {
View preferenceViewTwo = LayoutInflater.from(mContext).inflate(
mPreference.getLayoutResource(), null);
ViewGroup containerTwo = preferenceViewTwo.findViewById(R.id.circles_container);
CircularIconsView containerTwo = preferenceViewTwo.findViewById(R.id.circles_container);
containerTwo.setUiExecutor(MoreExecutors.directExecutor());
PreferenceViewHolder viewHolderTwo = PreferenceViewHolder.createInstanceForTests(
preferenceViewTwo);
containerTwo.measure(makeMeasureSpec(1000, View.MeasureSpec.EXACTLY),
@@ -265,25 +297,25 @@ public class CircularIconsPreferenceTest {
ColorDrawable::new);
mPreference.onBindViewHolder(viewHolderOne);
mPreference.displayIcons(iconSetOne);
assertThat(getIcons(containerOne)).hasSize(3);
mPreference.setIcons(iconSetOne);
assertThat(getDrawables(containerOne)).hasSize(3);
mPreference.onBindViewHolder(viewHolderTwo);
assertThat(getIcons(containerTwo)).hasSize(3);
assertThat(getDrawables(containerTwo)).hasSize(3);
mPreference.displayIcons(iconSetTwo);
mPreference.setIcons(iconSetTwo);
// The second view is updated and the first view is unaffected.
assertThat(getIcons(containerTwo)).hasSize(2);
assertThat(getIcons(containerOne)).hasSize(3);
assertThat(getDrawables(containerTwo)).hasSize(2);
assertThat(getDrawables(containerOne)).hasSize(3);
}
@Test
public void setEnabled_afterDisplayIcons_showsEnabledOrDisabledImages() {
public void setEnabled_afterSetIcons_showsEnabledOrDisabledImages() {
CircularIconSet<Integer> iconSet = new CircularIconSet<>(ImmutableList.of(1, 2),
ColorDrawable::new);
bindAndMeasureViewHolder(VIEW_WIDTH);
mPreference.displayIcons(iconSet);
bindAndLayoutViewHolder(VIEW_WIDTH);
mPreference.setIcons(iconSet);
assertThat(getViews(mContainer)).hasSize(2);
mPreference.setEnabled(false);
@@ -294,13 +326,13 @@ public class CircularIconsPreferenceTest {
}
@Test
public void setEnabled_beforeDisplayIcons_showsEnabledOrDisabledImages() {
public void setEnabled_beforeSetIcons_showsEnabledOrDisabledImages() {
CircularIconSet<Integer> iconSet = new CircularIconSet<>(ImmutableList.of(1, 2),
ColorDrawable::new);
mPreference.setEnabled(false);
bindAndMeasureViewHolder(VIEW_WIDTH);
mPreference.displayIcons(iconSet);
bindAndLayoutViewHolder(VIEW_WIDTH);
mPreference.setIcons(iconSet);
assertThat(getViews(mContainer)).hasSize(2);
assertThat(getViews(mContainer).get(0).getAlpha()).isLessThan(1f);
@@ -314,7 +346,7 @@ public class CircularIconsPreferenceTest {
return views;
}
private static List<Drawable> getIcons(ViewGroup container) {
private static List<Drawable> getDrawables(ViewGroup container) {
ArrayList<Drawable> drawables = new ArrayList<>();
for (int i = 0; i < container.getChildCount(); i++) {
if (container.getChildAt(i) instanceof ImageView imageView) {

View File

@@ -20,14 +20,12 @@ import android.content.Context;
import androidx.preference.PreferenceViewHolder;
import com.google.common.util.concurrent.MoreExecutors;
class TestableCircularIconsPreference extends CircularIconsPreference {
private PreferenceViewHolder mLastViewHolder;
TestableCircularIconsPreference(Context context) {
super(context, MoreExecutors.directExecutor());
super(context);
}
@Override

View File

@@ -19,6 +19,7 @@ package com.android.settings.notification.modes;
import static android.app.NotificationManager.INTERRUPTION_FILTER_PRIORITY;
import static android.provider.Settings.EXTRA_AUTOMATIC_ZEN_RULE_ID;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
@@ -51,6 +52,7 @@ import android.view.View;
import androidx.fragment.app.Fragment;
import androidx.preference.PreferenceViewHolder;
import com.android.settings.R;
import com.android.settings.SettingsActivity;
import com.android.settingslib.applications.ApplicationsState;
import com.android.settingslib.applications.ApplicationsState.AppEntry;
@@ -81,6 +83,7 @@ public final class ZenModeAppsLinkPreferenceControllerTest {
private ZenModeAppsLinkPreferenceController mController;
private CircularIconsPreference mPreference;
private CircularIconsView mIconsView;
private Context mContext;
@Mock
@@ -113,6 +116,8 @@ public final class ZenModeAppsLinkPreferenceControllerTest {
// Ensure the preference view is bound & measured (needed to add child ImageViews).
View preferenceView = LayoutInflater.from(mContext).inflate(mPreference.getLayoutResource(),
null);
mIconsView = checkNotNull(preferenceView.findViewById(R.id.circles_container));
mIconsView.setUiExecutor(MoreExecutors.directExecutor());
preferenceView.measure(View.MeasureSpec.makeMeasureSpec(1000, View.MeasureSpec.EXACTLY),
View.MeasureSpec.makeMeasureSpec(1000, View.MeasureSpec.EXACTLY));
PreferenceViewHolder holder = PreferenceViewHolder.createInstanceForTests(preferenceView);
@@ -272,7 +277,7 @@ public final class ZenModeAppsLinkPreferenceControllerTest {
appEntries.add(createAppEntry("test2", mContext.getUserId()));
mController.mAppSessionCallbacks.onRebuildComplete(appEntries);
assertThat(mPreference.getLoadedIcons().icons()).hasSize(2);
assertThat(mIconsView.getDisplayedIcons().icons()).hasSize(2);
}
@Test
@@ -312,7 +317,7 @@ public final class ZenModeAppsLinkPreferenceControllerTest {
mController.updateState(mPreference, zenModeWithNone);
assertThat(mPreference.getLoadedIcons().icons()).hasSize(0);
assertThat(mIconsView.getDisplayedIcons().icons()).hasSize(0);
verifyNoMoreInteractions(mApplicationsState);
verifyNoMoreInteractions(mSession);
@@ -321,7 +326,7 @@ public final class ZenModeAppsLinkPreferenceControllerTest {
verify(mApplicationsState).newSession(any(), any());
verify(mSession).rebuild(any(), any(), anyBoolean());
mController.mAppSessionCallbacks.onRebuildComplete(appEntries);
assertThat(mPreference.getLoadedIcons().icons()).hasSize(1);
assertThat(mIconsView.getDisplayedIcons().icons()).hasSize(1);
}
@Test
@@ -342,11 +347,11 @@ public final class ZenModeAppsLinkPreferenceControllerTest {
verify(mApplicationsState).newSession(any(), any());
verify(mSession).rebuild(any(), any(), anyBoolean());
mController.mAppSessionCallbacks.onRebuildComplete(appEntries);
assertThat(mPreference.getLoadedIcons().icons()).hasSize(1);
assertThat(mIconsView.getDisplayedIcons().icons()).hasSize(1);
mController.updateState(mPreference, zenModeWithNone);
assertThat(mPreference.getLoadedIcons().icons()).hasSize(0);
assertThat(mIconsView.getDisplayedIcons().icons()).hasSize(0);
verify(mSession).deactivateSession();
verifyNoMoreInteractions(mSession);
verifyNoMoreInteractions(mApplicationsState);
@@ -355,7 +360,7 @@ public final class ZenModeAppsLinkPreferenceControllerTest {
// updateState()) is ignored.
mController.mAppSessionCallbacks.onRebuildComplete(appEntries);
assertThat(mPreference.getLoadedIcons().icons()).hasSize(0);
assertThat(mIconsView.getDisplayedIcons().icons()).hasSize(0);
}
@Test

View File

@@ -95,7 +95,7 @@ public final class ZenModeOtherLinkPreferenceControllerTest {
mController.updateState(pref, mode);
verify(pref).displayIcons(argThat(iconSet -> iconSet.size() == 3));
verify(pref).setIcons(argThat(iconSet -> iconSet.size() == 3));
}
@Test
@@ -107,7 +107,7 @@ public final class ZenModeOtherLinkPreferenceControllerTest {
mController.updateState(pref, mode);
verify(pref).displayIcons(argThat(iconSet ->
verify(pref).setIcons(argThat(iconSet ->
iconSet.size() == ZenModeSummaryHelper.OTHER_SOUND_CATEGORIES.size()));
}
}

View File

@@ -22,6 +22,7 @@ import static android.service.notification.ZenPolicy.PEOPLE_TYPE_CONTACTS;
import static android.service.notification.ZenPolicy.PEOPLE_TYPE_NONE;
import static android.service.notification.ZenPolicy.PEOPLE_TYPE_STARRED;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
@@ -50,6 +51,7 @@ import android.view.View;
import androidx.preference.PreferenceViewHolder;
import com.android.settings.R;
import com.android.settings.notification.modes.ZenHelperBackend.Contact;
import com.android.settingslib.notification.ConversationIconFactory;
import com.android.settingslib.notification.modes.TestModeBuilder;
@@ -76,6 +78,7 @@ public final class ZenModePeopleLinkPreferenceControllerTest {
private ZenModePeopleLinkPreferenceController mController;
private CircularIconsPreference mPreference;
private CircularIconsView mIconsView;
@Rule
public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
@@ -94,6 +97,8 @@ public final class ZenModePeopleLinkPreferenceControllerTest {
// Ensure the preference view is bound & measured (needed to add icons).
View preferenceView = LayoutInflater.from(mContext).inflate(mPreference.getLayoutResource(),
null);
mIconsView = checkNotNull(preferenceView.findViewById(R.id.circles_container));
mIconsView.setUiExecutor(MoreExecutors.directExecutor());
preferenceView.measure(View.MeasureSpec.makeMeasureSpec(1000, View.MeasureSpec.EXACTLY),
View.MeasureSpec.makeMeasureSpec(1000, View.MeasureSpec.EXACTLY));
PreferenceViewHolder holder = PreferenceViewHolder.createInstanceForTests(preferenceView);
@@ -142,9 +147,9 @@ public final class ZenModePeopleLinkPreferenceControllerTest {
mController.updateState(mPreference, mode);
assertThat(mPreference.getLoadedIcons()).isNotNull();
assertThat(mPreference.getLoadedIcons().icons()).hasSize(2);
assertThat(mPreference.getLoadedIcons().icons().stream()
assertThat(mIconsView.getDisplayedIcons()).isNotNull();
assertThat(mIconsView.getDisplayedIcons().icons()).hasSize(2);
assertThat(mIconsView.getDisplayedIcons().icons().stream()
.map(ColorDrawable.class::cast)
.map(d -> d.getColor()).toList())
.containsExactly(2, 3).inOrder();
@@ -162,9 +167,9 @@ public final class ZenModePeopleLinkPreferenceControllerTest {
mController.updateState(mPreference, mode);
assertThat(mPreference.getLoadedIcons()).isNotNull();
assertThat(mPreference.getLoadedIcons().icons()).hasSize(4);
assertThat(mPreference.getLoadedIcons().icons().stream()
assertThat(mIconsView.getDisplayedIcons()).isNotNull();
assertThat(mIconsView.getDisplayedIcons().icons()).hasSize(4);
assertThat(mIconsView.getDisplayedIcons().icons().stream()
.map(ColorDrawable.class::cast)
.map(d -> d.getColor()).toList())
.containsExactly(1, 2, 3, 4).inOrder();
@@ -182,8 +187,8 @@ public final class ZenModePeopleLinkPreferenceControllerTest {
mController.updateState(mPreference, mode);
assertThat(mPreference.getLoadedIcons()).isNotNull();
assertThat(mPreference.getLoadedIcons().icons()).hasSize(1);
assertThat(mIconsView.getDisplayedIcons()).isNotNull();
assertThat(mIconsView.getDisplayedIcons().icons()).hasSize(1);
verify(mHelperBackend, never()).getContactPhoto(any());
}
@@ -201,8 +206,8 @@ public final class ZenModePeopleLinkPreferenceControllerTest {
mController.updateState(mPreference, mode);
assertThat(mPreference.getLoadedIcons()).isNotNull();
assertThat(mPreference.getLoadedIcons().icons()).hasSize(3);
assertThat(mIconsView.getDisplayedIcons()).isNotNull();
assertThat(mIconsView.getDisplayedIcons().icons()).hasSize(3);
verify(mConversationIconFactory, times(3)).getConversationDrawable((ShortcutInfo) any(),
any(), anyInt(), anyBoolean());
}