Don't recycle the bitmap on CanvasEngine.onDestroy
A crash was possible due to race conditions if CanvasEngine.onDestroy is called before drawFrame has enough time to finish drawing. We don't want to recycle the bitmap when onDestroy is called. The bitmap will be automatically recycled after loading, once the frame is drawn. We simply wait for the automatic recycling. This is similar to what was done in GLEngine.onDestroy: a message is queued to destroy the GL context, so the GLEngine first waits that other operations (i.e. drawFrame) are finished before unloading. Bug: 255920551 Test: manual Test: atest ImageWallpaperTest Change-Id: I45b99f572dd89926ccdc1632abb20442bafcf854
This commit is contained in:
@@ -599,7 +599,6 @@ public class ImageWallpaper extends WallpaperService {
|
||||
getDisplayContext().getSystemService(DisplayManager.class)
|
||||
.unregisterDisplayListener(this);
|
||||
mWallpaperLocalColorExtractor.cleanUp();
|
||||
unloadBitmap();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -677,9 +676,14 @@ public class ImageWallpaper extends WallpaperService {
|
||||
void drawFrameOnCanvas(Bitmap bitmap) {
|
||||
Trace.beginSection("ImageWallpaper.CanvasEngine#drawFrame");
|
||||
Surface surface = mSurfaceHolder.getSurface();
|
||||
Canvas canvas = mWideColorGamut
|
||||
? surface.lockHardwareWideColorGamutCanvas()
|
||||
: surface.lockHardwareCanvas();
|
||||
Canvas canvas = null;
|
||||
try {
|
||||
canvas = mWideColorGamut
|
||||
? surface.lockHardwareWideColorGamutCanvas()
|
||||
: surface.lockHardwareCanvas();
|
||||
} catch (IllegalStateException e) {
|
||||
Log.w(TAG, "Unable to lock canvas", e);
|
||||
}
|
||||
if (canvas != null) {
|
||||
Rect dest = mSurfaceHolder.getSurfaceFrame();
|
||||
try {
|
||||
@@ -710,17 +714,6 @@ public class ImageWallpaper extends WallpaperService {
|
||||
}
|
||||
}
|
||||
|
||||
private void unloadBitmap() {
|
||||
mBackgroundExecutor.execute(this::unloadBitmapSynchronized);
|
||||
}
|
||||
|
||||
private void unloadBitmapSynchronized() {
|
||||
synchronized (mLock) {
|
||||
mBitmapUsages = 0;
|
||||
unloadBitmapInternal();
|
||||
}
|
||||
}
|
||||
|
||||
private void unloadBitmapInternal() {
|
||||
Trace.beginSection("ImageWallpaper.CanvasEngine#unloadBitmap");
|
||||
if (mBitmap != null) {
|
||||
|
||||
Reference in New Issue
Block a user