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

Commit 20ebb0a6 authored by Lucas Dupin's avatar Lucas Dupin Committed by Android (Google) Code Review
Browse files

Merge "Disable color extraction for media" into pi-dev

parents 847446d7 3ec5928c
Loading
Loading
Loading
Loading
+19 −6
Original line number Diff line number Diff line
@@ -46,6 +46,7 @@ import java.util.Arrays;
public class SysuiColorExtractor extends ColorExtractor implements Dumpable {
    private static final String TAG = "SysuiColorExtractor";
    private boolean mWallpaperVisible;
    private boolean mMediaBackdropVisible;
    // Colors to return when the wallpaper isn't visible
    private final GradientColors mWpHiddenColors;

@@ -157,14 +158,19 @@ public class SysuiColorExtractor extends ColorExtractor implements Dumpable {
    public GradientColors getColors(int which, int type, boolean ignoreWallpaperVisibility) {
        // mWallpaperVisible only handles the "system wallpaper" and will be always set to false
        // if we have different lock and system wallpapers.
        if (which == WallpaperManager.FLAG_LOCK) {
            ignoreWallpaperVisibility = true;
        }
        if (which == WallpaperManager.FLAG_SYSTEM) {
            if (mWallpaperVisible || ignoreWallpaperVisibility) {
                return super.getColors(which, type);
            } else {
                return mWpHiddenColors;
            }
        } else {
            if (mMediaBackdropVisible) {
                return mWpHiddenColors;
            } else {
                return super.getColors(which, type);
            }
        }
    }

    @VisibleForTesting
@@ -175,6 +181,13 @@ public class SysuiColorExtractor extends ColorExtractor implements Dumpable {
        }
    }

    public void setMediaBackdropVisible(boolean visible) {
        if (mMediaBackdropVisible != visible) {
            mMediaBackdropVisible = visible;
            triggerColorsChanged(WallpaperManager.FLAG_LOCK);
        }
    }

    @Override
    public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
        pw.println("SysuiColorExtractor:");
+3 −2
Original line number Diff line number Diff line
@@ -1589,8 +1589,7 @@ public class StatusBar extends SystemUI implements DemoMode,

        Drawable artworkDrawable = null;
        if (mediaMetadata != null) {
            Bitmap artworkBitmap = null;
            artworkBitmap = mediaMetadata.getBitmap(MediaMetadata.METADATA_KEY_ART);
            Bitmap artworkBitmap = mediaMetadata.getBitmap(MediaMetadata.METADATA_KEY_ART);
            if (artworkBitmap == null) {
                artworkBitmap = mediaMetadata.getBitmap(MediaMetadata.METADATA_KEY_ALBUM_ART);
                // might still be null
@@ -1633,6 +1632,7 @@ public class StatusBar extends SystemUI implements DemoMode,
                    mBackdrop.setAlpha(1f);
                }
                mStatusBarWindowManager.setBackdropShowing(true);
                mColorExtractor.setMediaBackdropVisible(true);
                metaDataChanged = true;
                if (DEBUG_MEDIA) {
                    Log.v(TAG, "DEBUG_MEDIA: Fading in album artwork");
@@ -1684,6 +1684,7 @@ public class StatusBar extends SystemUI implements DemoMode,
                if (DEBUG_MEDIA) {
                    Log.v(TAG, "DEBUG_MEDIA: Fading out album artwork");
                }
                mColorExtractor.setMediaBackdropVisible(false);
                boolean cannotAnimateDoze = mDozing && !ScrimState.AOD.getAnimateChange();
                if (mFingerprintUnlockController.getMode()
                        == FingerprintUnlockController.MODE_WAKE_AND_UNLOCK_PULSING
+21 −0
Original line number Diff line number Diff line
@@ -84,6 +84,27 @@ public class SysuiColorExtractorTests extends SysuiTestCase {
        }
    }

    @Test
    public void getColors_fallbackWhenMediaIsVisible() {
        ColorExtractor.GradientColors colors = new ColorExtractor.GradientColors();
        colors.setMainColor(Color.RED);
        colors.setSecondaryColor(Color.RED);

        SysuiColorExtractor extractor = getTestableExtractor(colors);
        simulateEvent(extractor);
        extractor.setWallpaperVisible(true);
        extractor.setMediaBackdropVisible(true);

        ColorExtractor.GradientColors fallbackColors = extractor.getFallbackColors();

        for (int type : sTypes) {
            assertEquals("Not using fallback!",
                    extractor.getColors(WallpaperManager.FLAG_LOCK, type), fallbackColors);
            assertNotEquals("Media visibility should not affect system wallpaper.",
                    extractor.getColors(WallpaperManager.FLAG_SYSTEM, type), fallbackColors);
        }
    }

    private SysuiColorExtractor getTestableExtractor(ColorExtractor.GradientColors colors) {
        return new SysuiColorExtractor(getContext(),
                (inWallpaperColors, outGradientColorsNormal, outGradientColorsDark,