Add a recycle check in WallpaperLocalColorExtractor
Alternative to ag/24403729. First, this CL makes ImageWallpaper and WallpaperLocalColorExtractor share the same lock. Sharing the same lock simplifies the concurrency logic. Since both ImageWallpaper and WallpaperLocalColorExtractor use the same single-threaded @LongExecutor for their long operations, their operations are already atomic but this is rather implicit. We make this explicit by sharing the same lock. Second, we add a recycle() check before calling createScaledBitmap in WallpaperLocalColorExtractor, to avoid a concurrency bug where a new image is loaded by ImageWallpaper before the color extraction of the previous image could take place. By sharing the lock, ImageWallpaper does (recycle(), mBitmap=newBitmap, startColorExtraction(mBitmap)) atomically with regard to WallpaperLocalColorExtractor. So when trying to extract colors, we are guaranteed that either the bitmap is the most recent one, either it is recycled. Bug: 292492981 Test: atest ImageWallpaperTest Test: atest WallpaperLocalColorExtractorTest Change-Id: Ib5bccaaa7ebb4371feccfc7f5c8407410b8ba59b
Loading
Please register or sign in to comment