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

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

Merge "Disable color extraction for media" into pi-dev am: 20ebb0a6

am: 0ce5fae4

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


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


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


        Drawable artworkDrawable = null;
        Drawable artworkDrawable = null;
        if (mediaMetadata != null) {
        if (mediaMetadata != null) {
            Bitmap artworkBitmap = null;
            Bitmap artworkBitmap = mediaMetadata.getBitmap(MediaMetadata.METADATA_KEY_ART);
            artworkBitmap = mediaMetadata.getBitmap(MediaMetadata.METADATA_KEY_ART);
            if (artworkBitmap == null) {
            if (artworkBitmap == null) {
                artworkBitmap = mediaMetadata.getBitmap(MediaMetadata.METADATA_KEY_ALBUM_ART);
                artworkBitmap = mediaMetadata.getBitmap(MediaMetadata.METADATA_KEY_ALBUM_ART);
                // might still be null
                // might still be null
@@ -1633,6 +1632,7 @@ public class StatusBar extends SystemUI implements DemoMode,
                    mBackdrop.setAlpha(1f);
                    mBackdrop.setAlpha(1f);
                }
                }
                mStatusBarWindowManager.setBackdropShowing(true);
                mStatusBarWindowManager.setBackdropShowing(true);
                mColorExtractor.setMediaBackdropVisible(true);
                metaDataChanged = true;
                metaDataChanged = true;
                if (DEBUG_MEDIA) {
                if (DEBUG_MEDIA) {
                    Log.v(TAG, "DEBUG_MEDIA: Fading in album artwork");
                    Log.v(TAG, "DEBUG_MEDIA: Fading in album artwork");
@@ -1684,6 +1684,7 @@ public class StatusBar extends SystemUI implements DemoMode,
                if (DEBUG_MEDIA) {
                if (DEBUG_MEDIA) {
                    Log.v(TAG, "DEBUG_MEDIA: Fading out album artwork");
                    Log.v(TAG, "DEBUG_MEDIA: Fading out album artwork");
                }
                }
                mColorExtractor.setMediaBackdropVisible(false);
                boolean cannotAnimateDoze = mDozing && !ScrimState.AOD.getAnimateChange();
                boolean cannotAnimateDoze = mDozing && !ScrimState.AOD.getAnimateChange();
                if (mFingerprintUnlockController.getMode()
                if (mFingerprintUnlockController.getMode()
                        == FingerprintUnlockController.MODE_WAKE_AND_UNLOCK_PULSING
                        == FingerprintUnlockController.MODE_WAKE_AND_UNLOCK_PULSING
+21 −0
Original line number Original line 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) {
    private SysuiColorExtractor getTestableExtractor(ColorExtractor.GradientColors colors) {
        return new SysuiColorExtractor(getContext(),
        return new SysuiColorExtractor(getContext(),
                (inWallpaperColors, outGradientColorsNormal, outGradientColorsDark,
                (inWallpaperColors, outGradientColorsNormal, outGradientColorsDark,