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

Commit 3ec5928c authored by Lucas Dupin's avatar Lucas Dupin
Browse files

Disable color extraction for media

Overlaying an album with wallpaper colors isn't optimal.
Using the album extracted color also isn't optimal, the color probably
won't meet accessibility guidelines and will have to be stretched
according to the current lock screen theme - which can be even worse.

Test: atest packages/SystemUI/tests/src/com/android/systemui/colorextraction/SysuiColorExtractorTests.java
Change-Id: I53d08713716bd76ee0975c2b4bba5b933201f999
parent ac263ac4
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,