diff options
author | Selim Cinek <cinek@google.com> | 2019-08-20 23:40:41 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2019-08-20 23:40:41 +0000 |
commit | aec6b618165eb24311239bceda76e3e283f104c7 (patch) | |
tree | fa5e67364b97bca49424dd1a2680a7aafd41d19b | |
parent | f3395734e815e37fb8f41ed120c320e1305f97cf (diff) | |
parent | a6fe7543491974ecb3d00c9fb9190cd22332051c (diff) | |
download | base-aec6b618165eb24311239bceda76e3e283f104c7.tar.gz |
Merge "EglDisplay may be null and cause Null point exception" into qt-r1-dev
-rw-r--r-- | packages/SystemUI/src/com/android/systemui/glwallpaper/EglHelper.java | 28 | ||||
-rw-r--r-- | packages/SystemUI/tests/src/com/android/systemui/glwallpaper/EglHelperTest.java | 67 |
2 files changed, 92 insertions, 3 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/glwallpaper/EglHelper.java b/packages/SystemUI/src/com/android/systemui/glwallpaper/EglHelper.java index d74112608491..aac721e3cb56 100644 --- a/packages/SystemUI/src/com/android/systemui/glwallpaper/EglHelper.java +++ b/packages/SystemUI/src/com/android/systemui/glwallpaper/EglHelper.java @@ -146,7 +146,13 @@ public class EglHelper { * @return true if EglSurface is ready. */ public boolean createEglSurface(SurfaceHolder surfaceHolder) { - mEglSurface = eglCreateWindowSurface(mEglDisplay, mEglConfig, surfaceHolder, null, 0); + if (hasEglDisplay()) { + mEglSurface = eglCreateWindowSurface(mEglDisplay, mEglConfig, surfaceHolder, null, 0); + } else { + Log.w(TAG, "mEglDisplay is null"); + return false; + } + if (mEglSurface == null || mEglSurface == EGL_NO_SURFACE) { Log.w(TAG, "createWindowSurface failed: " + GLUtils.getEGLErrorString(eglGetError())); return false; @@ -186,7 +192,13 @@ public class EglHelper { public boolean createEglContext() { int[] attrib_list = new int[] {EGL_CONTEXT_CLIENT_VERSION, 2, EGL_CONTEXT_PRIORITY_LEVEL_IMG, EGL_CONTEXT_PRIORITY_LOW_IMG, EGL_NONE}; - mEglContext = eglCreateContext(mEglDisplay, mEglConfig, EGL_NO_CONTEXT, attrib_list, 0); + if (hasEglDisplay()) { + mEglContext = eglCreateContext(mEglDisplay, mEglConfig, EGL_NO_CONTEXT, attrib_list, 0); + } else { + Log.w(TAG, "mEglDisplay is null"); + return false; + } + if (mEglContext == EGL_NO_CONTEXT) { Log.w(TAG, "eglCreateContext failed: " + GLUtils.getEGLErrorString(eglGetError())); return false; @@ -213,6 +225,14 @@ public class EglHelper { } /** + * Check if we have EglDisplay. + * @return true if EglDisplay is ready. + */ + public boolean hasEglDisplay() { + return mEglDisplay != null; + } + + /** * Swap buffer to display. * @return true if swap successfully. */ @@ -235,7 +255,9 @@ public class EglHelper { if (hasEglContext()) { destroyEglContext(); } - eglTerminate(mEglDisplay); + if (hasEglDisplay()) { + eglTerminate(mEglDisplay); + } mEglReady = false; } diff --git a/packages/SystemUI/tests/src/com/android/systemui/glwallpaper/EglHelperTest.java b/packages/SystemUI/tests/src/com/android/systemui/glwallpaper/EglHelperTest.java new file mode 100644 index 000000000000..b4a60d642cb0 --- /dev/null +++ b/packages/SystemUI/tests/src/com/android/systemui/glwallpaper/EglHelperTest.java @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.systemui.glwallpaper; + +import static org.junit.Assert.*; +import static org.mockito.Mockito.RETURNS_DEFAULTS; +import static org.mockito.Mockito.mock; + +import android.testing.AndroidTestingRunner; +import android.testing.TestableLooper; +import android.view.SurfaceHolder; + +import androidx.test.filters.SmallTest; + +import com.android.systemui.SysuiTestCase; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; + + +@SmallTest +@RunWith(AndroidTestingRunner.class) +@TestableLooper.RunWithLooper +public class EglHelperTest extends SysuiTestCase { + + @Mock + private EglHelper mEglHelper; + @Mock + private SurfaceHolder mSurfaceHolder; + + @Before + public void setUp() throws Exception { + mEglHelper = mock(EglHelper.class, RETURNS_DEFAULTS); + mSurfaceHolder = mock(SurfaceHolder.class, RETURNS_DEFAULTS); + } + + @Test + public void testInit_finish() { + mEglHelper.init(mSurfaceHolder); + mEglHelper.finish(); + } + + @Test + public void testFinish_shouldNotCrash() { + assertFalse(mEglHelper.hasEglDisplay()); + assertFalse(mEglHelper.hasEglSurface()); + assertFalse(mEglHelper.hasEglContext()); + + mEglHelper.finish(); + } +} |