From b0f39361b566f403630c54e522bef2300988c3d8 Mon Sep 17 00:00:00 2001 From: Robert Carr Date: Wed, 14 Mar 2018 13:52:25 -0700 Subject: [PATCH] Distinguish between createSurface error codes. Thusly preventing killing applications in the case of a missing parent. Bug: 73664284 Test: Manual. go/wm-smoke. Change-Id: Iafcd578765fa8fcf603c3f5a6a546e6986f297e8 --- core/java/android/view/SurfaceControl.java | 2 +- core/jni/android_view_SurfaceControl.cpp | 10 +++++++--- .../com/android/server/wm/WindowStateAnimator.java | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/core/java/android/view/SurfaceControl.java b/core/java/android/view/SurfaceControl.java index b7524fb1a5220..7ff4f21dd26fe 100644 --- a/core/java/android/view/SurfaceControl.java +++ b/core/java/android/view/SurfaceControl.java @@ -566,7 +566,7 @@ public class SurfaceControl implements Parcelable { */ private SurfaceControl(SurfaceSession session, String name, int w, int h, int format, int flags, SurfaceControl parent, int windowType, int ownerUid) - throws OutOfResourcesException { + throws OutOfResourcesException, IllegalArgumentException { if (session == null) { throw new IllegalArgumentException("session must not be null"); } diff --git a/core/jni/android_view_SurfaceControl.cpp b/core/jni/android_view_SurfaceControl.cpp index 8ca506254f740..4ee3724d554d4 100644 --- a/core/jni/android_view_SurfaceControl.cpp +++ b/core/jni/android_view_SurfaceControl.cpp @@ -115,9 +115,13 @@ static jlong nativeCreate(JNIEnv* env, jclass clazz, jobject sessionObj, ScopedUtfChars name(env, nameStr); sp client(android_view_SurfaceSession_getClient(env, sessionObj)); SurfaceControl *parent = reinterpret_cast(parentObject); - sp surface = client->createSurface( - String8(name.c_str()), w, h, format, flags, parent, windowType, ownerUid); - if (surface == NULL) { + sp surface; + status_t err = client->createSurfaceChecked( + String8(name.c_str()), w, h, format, &surface, flags, parent, windowType, ownerUid); + if (err == NAME_NOT_FOUND) { + jniThrowException(env, "java/lang/IllegalArgumentException", NULL); + return 0; + } else if (err != NO_ERROR) { jniThrowException(env, OutOfResourcesException, NULL); return 0; } diff --git a/services/core/java/com/android/server/wm/WindowStateAnimator.java b/services/core/java/com/android/server/wm/WindowStateAnimator.java index 13f05e088cb1e..eb055accbbaa1 100644 --- a/services/core/java/com/android/server/wm/WindowStateAnimator.java +++ b/services/core/java/com/android/server/wm/WindowStateAnimator.java @@ -507,7 +507,7 @@ class WindowStateAnimator { mDrawState = NO_SURFACE; return null; } catch (Exception e) { - Slog.e(TAG, "Exception creating surface", e); + Slog.e(TAG, "Exception creating surface (parent dead?)", e); mDrawState = NO_SURFACE; return null; }