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

Commit 284836b0 authored by Lucas Dupin's avatar Lucas Dupin
Browse files

Do not extract colors of live wallpapers.

Not extracting colors from live wallpaper thumbanils
since they might not represent the actual colors
being displayed.

Bug: 62019730
Test: Manual. Set live wallpaper, scrim is grey.
Change-Id: Ida652cab069beb1ee5fe36eb7862cc21e8edbc2e
parent c84cd09d
Loading
Loading
Loading
Loading
+10 −43
Original line number Diff line number Diff line
@@ -379,54 +379,31 @@ public class WallpaperManagerService extends IWallpaperManager.Stub {

    /**
     * We can easily extract colors from an ImageWallpaper since it's only a bitmap.
     * In this case, using the crop is more than enough.
     *
     * In case of a live wallpaper, the best we can do is to extract colors from its
     * preview image. Anyway, the live wallpaper can also implement the wallpaper colors API
     * to report when colors change.
     * In this case, using the crop is more than enough. Live wallpapers are just ignored.
     *
     * @param wallpaper a wallpaper representation
     */
    private void extractColors(WallpaperData wallpaper) {
        String cropFile = null;
        Drawable thumbnail = null;
        // This represents a maximum pixel count in an image.
        // It prevents color extraction on big bitmaps.
        int wallpaperId = -1;
        int wallpaperId;

        boolean imageWallpaper = false;
        synchronized (mLock) {
            imageWallpaper = mImageWallpaper.equals(wallpaper.wallpaperComponent)
            // Not having a wallpaperComponent means it's a lock screen wallpaper.
            final boolean imageWallpaper = mImageWallpaper.equals(wallpaper.wallpaperComponent)
                    || wallpaper.wallpaperComponent == null;
            if (imageWallpaper) {
                if (wallpaper.cropFile != null && wallpaper.cropFile.exists()) {
            if (imageWallpaper && wallpaper.cropFile != null && wallpaper.cropFile.exists()) {
                cropFile = wallpaper.cropFile.getAbsolutePath();
            }
            } else {
                if (wallpaper.connection == null) {
                    Slog.w(TAG, "Can't extract colors, wallpaper not connected. " +
                            wallpaper.wallpaperId);
                    return;
                }
                WallpaperInfo info = wallpaper.connection.mInfo;
                if (info == null) {
                    Slog.w(TAG, "Something is really wrong, live wallpaper doesn't have " +
                           "a WallpaperInfo object! " + wallpaper.wallpaperId);
                    return;
                }
                thumbnail = info.loadThumbnail(mContext.getPackageManager());
            }

            wallpaperId = wallpaper.wallpaperId;
        }

        WallpaperColors colors = null;
        if (cropFile != null) {
            Bitmap bitmap = BitmapFactory.decodeFile(cropFile);
            if (bitmap != null) {
                colors = WallpaperColors.fromBitmap(bitmap);
                bitmap.recycle();
        } else if (thumbnail != null) {
            colors = WallpaperColors.fromDrawable(thumbnail);
            }
        }

        if (colors == null) {
@@ -434,16 +411,6 @@ public class WallpaperManagerService extends IWallpaperManager.Stub {
            return;
        }

        // Even though we can extract colors from live wallpaper thumbnails,
        // it's risky to assume that it might support dark text on top of it:
        //    • Thumbnail might not be accurate.
        //    • Colors might change over time.
        if (!imageWallpaper) {
            int colorHints = colors.getColorHints();
            colorHints &= ~WallpaperColors.HINT_SUPPORTS_DARK_TEXT;
            colors.setColorHints(colorHints);
        }

        synchronized (mLock) {
            if (wallpaper.wallpaperId == wallpaperId) {
                wallpaper.primaryColors = colors;