Avoid ImageWallpaper IllegalStateException

It's possible that WallpaperService calls surface.release() between
lockCanvas and unlockCanvasAndPost, which gives the exception from
b/337287154 (IllegalStateException: surface has already been released).

To avoid that, we use a second lock that synchronizes the drawing and
the onSurfaceDestroyed method. This makes sure that we are done drawing
(or haven't started drawing) when we exit onSurfaceDestroyed().

Flag: aconfig com.android.systemui.fix_image_wallpaper_crash_surface_already_released DEVELOPMENT
Bug: 337287154
Test: treehugger
Test: crash cluster will be monitored
Change-Id: I3579e928fa9a115ecad7fa1e9fc4f15a0dc5ea68
diff --git a/packages/SystemUI/aconfig/systemui.aconfig b/packages/SystemUI/aconfig/systemui.aconfig
index 582b6a1..7a02b4f 100644
--- a/packages/SystemUI/aconfig/systemui.aconfig
+++ b/packages/SystemUI/aconfig/systemui.aconfig
@@ -398,6 +398,16 @@
 }
 
 flag {
+  name: "fix_image_wallpaper_crash_surface_already_released"
+  namespace: "systemui"
+  description: "Make sure ImageWallpaper doesn't return from OnSurfaceDestroyed until any drawing is finished"
+  bug: "337287154"
+  metadata {
+    purpose: PURPOSE_BUGFIX
+  }
+}
+
+flag {
    name: "activity_transition_use_largest_window"
    namespace: "systemui"
    description: "Target largest opening window during activity transitions."