OSDN Git Service

Do not extract colors of live wallpapers.
authorLucas Dupin <dupin@google.com>
Fri, 23 Jun 2017 22:28:41 +0000 (15:28 -0700)
committerLucas Dupin <dupin@google.com>
Mon, 26 Jun 2017 20:50:16 +0000 (13:50 -0700)
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

services/core/java/com/android/server/wallpaper/WallpaperManagerService.java

index 929f28d..dfcc166 100644 (file)
@@ -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()) {
-                    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());
+            if (imageWallpaper && wallpaper.cropFile != null && wallpaper.cropFile.exists()) {
+                cropFile = wallpaper.cropFile.getAbsolutePath();
             }
-
             wallpaperId = wallpaper.wallpaperId;
         }
 
         WallpaperColors colors = null;
         if (cropFile != null) {
             Bitmap bitmap = BitmapFactory.decodeFile(cropFile);
-            colors = WallpaperColors.fromBitmap(bitmap);
-            bitmap.recycle();
-        } else if (thumbnail != null) {
-            colors = WallpaperColors.fromDrawable(thumbnail);
+            if (bitmap != null) {
+                colors = WallpaperColors.fromBitmap(bitmap);
+                bitmap.recycle();
+            }
         }
 
         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;