OSDN Git Service

DO NOT MERGE Prevent ImageWallpaper from keeping crashing
authorAhan Wu <ahanwu@google.com>
Tue, 2 Jun 2020 20:21:45 +0000 (04:21 +0800)
committerVasyl Gello <vasek.gello@gmail.com>
Wed, 5 Aug 2020 02:43:44 +0000 (02:43 +0000)
GLUtil.texImage2D may throw exception that indicates bad image format.
We should catch this exception, otherwise, systemui may keep crashing.

Bug: 156087409
Test: Set a 16-bit rgb image as wallpaper
Test: Systemui shouldn't keep crashing
Change-Id: I6c9715c049b7848ecd5559ab76612a98dcd4ee6f
(cherry picked from commit a3bff94e184590351fd95f630e8b8313d1d2053b)

packages/SystemUI/src/com/android/systemui/ImageWallpaper.java

index f76a68c..a93ee19 100644 (file)
@@ -578,7 +578,16 @@ public class ImageWallpaper extends WallpaperService {
 
             final FloatBuffer triangleVertices = createMesh(left, top, right, bottom);
 
-            final int texture = loadTexture(mBackground);
+            int texture = 0;
+            try {
+                texture = loadTexture(mBackground);
+            } catch (IllegalArgumentException e) {
+                mEgl.eglMakeCurrent(mEglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
+                mEgl.eglDestroySurface(mEglDisplay, mEglSurface);
+                mEgl.eglDestroyContext(mEglDisplay, mEglContext);
+                mEgl.eglTerminate(mEglDisplay);
+                return false;
+            }
             final int program = buildProgram(sSimpleVS, sSimpleFS);
 
             final int attribPosition = glGetAttribLocation(program, "position");