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

Commit 0b74f4bf authored by Lucas Dupin's avatar Lucas Dupin Committed by android-build-merger
Browse files

Merge "Fix flaky test" into qt-r1-dev

am: 7bfbb7e0

Change-Id: I78842caa898ca19b7a0ba27f255d7ee27e906eac
parents c857a3d0 7bfbb7e0
Loading
Loading
Loading
Loading
+6 −10
Original line number Diff line number Diff line
@@ -53,11 +53,13 @@ public class ColorExtractor implements WallpaperManager.OnColorsChangedListener
    protected WallpaperColors mLockColors;

    public ColorExtractor(Context context) {
        this(context, new Tonal(context), true /* immediately */);
        this(context, new Tonal(context), true /* immediately */,
                context.getSystemService(WallpaperManager.class));
    }

    @VisibleForTesting
    public ColorExtractor(Context context, ExtractionType extractionType, boolean immediately) {
    public ColorExtractor(Context context, ExtractionType extractionType, boolean immediately,
            WallpaperManager wallpaperManager) {
        mContext = context;
        mExtractionType = extractionType;

@@ -71,15 +73,9 @@ public class ColorExtractor implements WallpaperManager.OnColorsChangedListener
        }

        mOnColorsChangedListeners = new ArrayList<>();

        WallpaperManager wallpaperManager = mContext.getSystemService(WallpaperManager.class);
        if (wallpaperManager == null) {
            Log.w(TAG, "Can't listen to color changes!");
        } else {
        wallpaperManager.addOnColorsChangedListener(this, null /* handler */);
        initExtractColors(wallpaperManager, immediately);
    }
    }

    private void initExtractColors(WallpaperManager wallpaperManager, boolean immediately) {
        if (immediately) {
+9 −10
Original line number Diff line number Diff line
@@ -59,13 +59,15 @@ public class SysuiColorExtractor extends ColorExtractor implements Dumpable,

    @Inject
    public SysuiColorExtractor(Context context, ConfigurationController configurationController) {
        this(context, new Tonal(context), configurationController, true);
        this(context, new Tonal(context), configurationController, true,
                context.getSystemService(WallpaperManager.class));
    }

    @VisibleForTesting
    public SysuiColorExtractor(Context context, ExtractionType type,
            ConfigurationController configurationController, boolean registerVisibility) {
        super(context, type, false /* immediately */);
            ConfigurationController configurationController, boolean registerVisibility,
            WallpaperManager wallpaperManager) {
        super(context, type, false /* immediately */, wallpaperManager);
        mTonal = type instanceof Tonal ? (Tonal) type : new Tonal(context);
        mWpHiddenColors = new GradientColors();
        configurationController.addCallback(this);
@@ -91,14 +93,11 @@ public class SysuiColorExtractor extends ColorExtractor implements Dumpable,
            }
        }

        WallpaperManager wallpaperManager = context.getSystemService(WallpaperManager.class);
        if (wallpaperManager != null) {
        // Listen to all users instead of only the current one.
        wallpaperManager.removeOnColorsChangedListener(this);
        wallpaperManager.addOnColorsChangedListener(this, null /* handler */,
                UserHandle.USER_ALL);
    }
    }

    private void updateDefaultGradients(WallpaperColors colors) {
        mTonal.applyFallback(colors, mWpHiddenColors);
+5 −2
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@ import com.android.systemui.statusbar.policy.ConfigurationController;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

/**
@@ -57,6 +58,8 @@ public class SysuiColorExtractorTests extends SysuiTestCase {
            ColorExtractor.TYPE_DARK,
            ColorExtractor.TYPE_EXTRA_DARK};

    @Mock
    private WallpaperManager mWallpaperManager;
    private ColorExtractor.GradientColors mColors;
    private SysuiColorExtractor mColorExtractor;

@@ -72,7 +75,7 @@ public class SysuiColorExtractorTests extends SysuiTestCase {
                    outGradientColorsNormal.set(mColors);
                    outGradientColorsDark.set(mColors);
                    outGradientColorsExtraDark.set(mColors);
                }, mock(ConfigurationController.class), false);
                }, mock(ConfigurationController.class), false, mWallpaperManager);
    }

    @Test
@@ -127,7 +130,7 @@ public class SysuiColorExtractorTests extends SysuiTestCase {
        Tonal tonal = mock(Tonal.class);
        ConfigurationController configurationController = mock(ConfigurationController.class);
        SysuiColorExtractor sysuiColorExtractor = new SysuiColorExtractor(getContext(),
                tonal, configurationController, false /* registerVisibility */);
                tonal, configurationController, false /* registerVisibility */, mWallpaperManager);
        verify(configurationController).addCallback(eq(sysuiColorExtractor));

        reset(tonal);
+7 −4
Original line number Diff line number Diff line
@@ -47,17 +47,19 @@ import org.junit.runner.RunWith;
@RunWith(AndroidJUnit4.class)
public class ColorExtractorTest {

    Context mContext;
    private Context mContext;
    private WallpaperManager mWallpaperManager;

    @Before
    public void setup() {
        mContext = InstrumentationRegistry.getContext();
        mWallpaperManager = mock(WallpaperManager.class);
    }

    @Test
    public void ColorExtractor_extractWhenInitialized() {
        ExtractionType type = mock(Tonal.class);
        new ColorExtractor(mContext, type, true);
        new ColorExtractor(mContext, type, true, mWallpaperManager);
        // 1 for lock and 1 for system
        verify(type, times(2))
                .extractInto(any(), any(), any(), any());
@@ -84,7 +86,7 @@ public class ColorExtractorTest {
                    outGradientColorsDark.set(colorsExpectedDark);
                    outGradientColorsExtraDark.set(colorsExpectedExtraDark);
                };
        ColorExtractor extractor = new ColorExtractor(mContext, type, true);
        ColorExtractor extractor = new ColorExtractor(mContext, type, true, mWallpaperManager);

        GradientColors colors = extractor.getColors(WallpaperManager.FLAG_SYSTEM,
                ColorExtractor.TYPE_NORMAL);
@@ -99,7 +101,8 @@ public class ColorExtractorTest {
    public void addOnColorsChangedListener_invokesListener() {
        ColorExtractor.OnColorsChangedListener mockedListeners =
                mock(ColorExtractor.OnColorsChangedListener.class);
        ColorExtractor extractor = new ColorExtractor(mContext, new Tonal(mContext), true);
        ColorExtractor extractor = new ColorExtractor(mContext, new Tonal(mContext), true,
                mWallpaperManager);
        extractor.addOnColorsChangedListener(mockedListeners);

        extractor.onColorsChanged(new WallpaperColors(Color.valueOf(Color.RED), null, null),