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

Commit cda765dd authored by Aurélien Pomini's avatar Aurélien Pomini
Browse files

Lock mSurfaceHolder=null in ImageWallpaper

There is a race condition where WallpaperEngine#onSurfaceDestroyed is
being triggered right before the image is drawn in
ImageWallpaper#drawFrameOnCanvas. Adding synchronization makes sure the
null check in drawFrameInternal avoids this.

Flag: NA
Bug: 279589555
Test: atest ImageWallpaperTest
Test: atest WallpaperLocalColorExtractorTest
Test: atest WallpaperManagerTest
Test: manual (check picker basic user journeys)

Change-Id: I650bd31faed96383258105335b5ad92448a840f3
parent 4a8491e5
Loading
Loading
Loading
Loading
+8 −2
Original line number Diff line number Diff line
@@ -210,8 +210,14 @@ public class ImageWallpaper extends WallpaperService {
            if (DEBUG) {
                Log.i(TAG, "onSurfaceDestroyed");
            }
            mLongExecutor.execute(this::onSurfaceDestroyedSynchronized);
        }

        private void onSurfaceDestroyedSynchronized() {
            synchronized (mLock) {
                mSurfaceHolder = null;
            }
        }

        @Override
        public void onSurfaceCreated(SurfaceHolder holder) {
@@ -241,7 +247,7 @@ public class ImageWallpaper extends WallpaperService {

        private void drawFrameInternal() {
            if (mSurfaceHolder == null) {
                Log.e(TAG, "attempt to draw a frame without a valid surface");
                Log.i(TAG, "attempt to draw a frame without a valid surface");
                return;
            }