Loading services/core/java/com/android/server/wallpaper/WallpaperManagerService.java +38 −38 Original line number Diff line number Diff line Loading @@ -474,7 +474,13 @@ public class WallpaperManagerService extends IWallpaperManager.Stub int wallpaperId; if (wallpaper.equals(mFallbackWallpaper)) { extractDefaultImageWallpaperColors(); synchronized (mLock) { if (mFallbackWallpaper.primaryColors != null) return; } final WallpaperColors colors = extractDefaultImageWallpaperColors(); synchronized (mLock) { mFallbackWallpaper.primaryColors = colors; } return; } Loading @@ -499,23 +505,7 @@ public class WallpaperManagerService extends IWallpaperManager.Stub } } else if (defaultImageWallpaper) { // There is no crop and source file because this is default image wallpaper. try (final InputStream is = WallpaperManager.openDefaultWallpaper(mContext, FLAG_SYSTEM)) { if (is != null) { try { final BitmapFactory.Options options = new BitmapFactory.Options(); final Bitmap bitmap = BitmapFactory.decodeStream(is, null, options); if (bitmap != null) { colors = WallpaperColors.fromBitmap(bitmap); bitmap.recycle(); } } catch (OutOfMemoryError e) { Slog.w(TAG, "Can't decode default wallpaper stream", e); } } } catch (IOException e) { Slog.w(TAG, "Can't close default wallpaper stream", e); } colors = extractDefaultImageWallpaperColors(); } if (colors == null) { Loading @@ -535,16 +525,20 @@ public class WallpaperManagerService extends IWallpaperManager.Stub } } private void extractDefaultImageWallpaperColors() { private WallpaperColors extractDefaultImageWallpaperColors() { if (DEBUG) Slog.d(TAG, "Extract default image wallpaper colors"); synchronized (mLock) { if (mFallbackWallpaper.primaryColors != null) return; if (mCacheDefaultImageWallpaperColors != null) return mCacheDefaultImageWallpaperColors; } if (DEBUG) Slog.d(TAG, "Extract default image wallpaper colors"); WallpaperColors colors = null; final InputStream is = WallpaperManager.openDefaultWallpaper(mContext, FLAG_SYSTEM); if (is != null) { try { try (InputStream is = WallpaperManager.openDefaultWallpaper(mContext, FLAG_SYSTEM)) { if (is == null) { Slog.w(TAG, "Can't open default wallpaper stream"); return null; } final BitmapFactory.Options options = new BitmapFactory.Options(); final Bitmap bitmap = BitmapFactory.decodeStream(is, null, options); if (bitmap != null) { Loading @@ -553,21 +547,21 @@ public class WallpaperManagerService extends IWallpaperManager.Stub } } catch (OutOfMemoryError e) { Slog.w(TAG, "Can't decode default wallpaper stream", e); } finally { IoUtils.closeQuietly(is); } } catch (IOException e) { Slog.w(TAG, "Can't close default wallpaper stream", e); } if (colors == null) { Slog.e(TAG, "Extract default image wallpaper colors failed"); return; } } else { synchronized (mLock) { mFallbackWallpaper.primaryColors = colors; mCacheDefaultImageWallpaperColors = colors; } } return colors; } /** * Once a new wallpaper has been written via setWallpaper(...), it needs to be cropped * for display. Loading Loading @@ -814,6 +808,12 @@ public class WallpaperManagerService extends IWallpaperManager.Stub */ private final ComponentName mImageWallpaper; /** * Default image wallpaper shall never changed after system service started, caching it when we * first read the image file. */ private WallpaperColors mCacheDefaultImageWallpaperColors; /** * Name of the default wallpaper component; might be different from mImageWallpaper */ Loading Loading
services/core/java/com/android/server/wallpaper/WallpaperManagerService.java +38 −38 Original line number Diff line number Diff line Loading @@ -474,7 +474,13 @@ public class WallpaperManagerService extends IWallpaperManager.Stub int wallpaperId; if (wallpaper.equals(mFallbackWallpaper)) { extractDefaultImageWallpaperColors(); synchronized (mLock) { if (mFallbackWallpaper.primaryColors != null) return; } final WallpaperColors colors = extractDefaultImageWallpaperColors(); synchronized (mLock) { mFallbackWallpaper.primaryColors = colors; } return; } Loading @@ -499,23 +505,7 @@ public class WallpaperManagerService extends IWallpaperManager.Stub } } else if (defaultImageWallpaper) { // There is no crop and source file because this is default image wallpaper. try (final InputStream is = WallpaperManager.openDefaultWallpaper(mContext, FLAG_SYSTEM)) { if (is != null) { try { final BitmapFactory.Options options = new BitmapFactory.Options(); final Bitmap bitmap = BitmapFactory.decodeStream(is, null, options); if (bitmap != null) { colors = WallpaperColors.fromBitmap(bitmap); bitmap.recycle(); } } catch (OutOfMemoryError e) { Slog.w(TAG, "Can't decode default wallpaper stream", e); } } } catch (IOException e) { Slog.w(TAG, "Can't close default wallpaper stream", e); } colors = extractDefaultImageWallpaperColors(); } if (colors == null) { Loading @@ -535,16 +525,20 @@ public class WallpaperManagerService extends IWallpaperManager.Stub } } private void extractDefaultImageWallpaperColors() { private WallpaperColors extractDefaultImageWallpaperColors() { if (DEBUG) Slog.d(TAG, "Extract default image wallpaper colors"); synchronized (mLock) { if (mFallbackWallpaper.primaryColors != null) return; if (mCacheDefaultImageWallpaperColors != null) return mCacheDefaultImageWallpaperColors; } if (DEBUG) Slog.d(TAG, "Extract default image wallpaper colors"); WallpaperColors colors = null; final InputStream is = WallpaperManager.openDefaultWallpaper(mContext, FLAG_SYSTEM); if (is != null) { try { try (InputStream is = WallpaperManager.openDefaultWallpaper(mContext, FLAG_SYSTEM)) { if (is == null) { Slog.w(TAG, "Can't open default wallpaper stream"); return null; } final BitmapFactory.Options options = new BitmapFactory.Options(); final Bitmap bitmap = BitmapFactory.decodeStream(is, null, options); if (bitmap != null) { Loading @@ -553,21 +547,21 @@ public class WallpaperManagerService extends IWallpaperManager.Stub } } catch (OutOfMemoryError e) { Slog.w(TAG, "Can't decode default wallpaper stream", e); } finally { IoUtils.closeQuietly(is); } } catch (IOException e) { Slog.w(TAG, "Can't close default wallpaper stream", e); } if (colors == null) { Slog.e(TAG, "Extract default image wallpaper colors failed"); return; } } else { synchronized (mLock) { mFallbackWallpaper.primaryColors = colors; mCacheDefaultImageWallpaperColors = colors; } } return colors; } /** * Once a new wallpaper has been written via setWallpaper(...), it needs to be cropped * for display. Loading Loading @@ -814,6 +808,12 @@ public class WallpaperManagerService extends IWallpaperManager.Stub */ private final ComponentName mImageWallpaper; /** * Default image wallpaper shall never changed after system service started, caching it when we * first read the image file. */ private WallpaperColors mCacheDefaultImageWallpaperColors; /** * Name of the default wallpaper component; might be different from mImageWallpaper */ Loading