From e19c1af861efbc00a524f8f61a23c97876af9f99 Mon Sep 17 00:00:00 2001 From: Vijayashree Channiah Sondekoppa Date: Fri, 30 Aug 2013 11:52:03 +0530 Subject: Camera App: return after synchronized block For some boundary condition when surface allocated is null, due to return within synchronization block it is giving ANR. This change will ensure that return take place outside synchronization block. It will also ensure to notify an object if already in wait state before invoking wait on it. CRs-Fixed: 529666 Change-Id: I8532aa410840785923388a879701be9e98b0154f --- src/com/android/camera/CameraScreenNail.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/com/android/camera/CameraScreenNail.java b/src/com/android/camera/CameraScreenNail.java index b770a9a34..a03c103cc 100644 --- a/src/com/android/camera/CameraScreenNail.java +++ b/src/com/android/camera/CameraScreenNail.java @@ -67,6 +67,7 @@ public class CameraScreenNail extends SurfaceTextureScreenNail { // sure some code are atomic. For example, requestRender and setting // mAnimState. private Object mLock = new Object(); + private boolean mWaitFlag = false; private OnFrameDrawnListener mOneTimeFrameDrawnListener; private int mRenderWidth; @@ -429,7 +430,10 @@ public class CameraScreenNail extends SurfaceTextureScreenNail { // as the origin (0, 0). canvas.translate(0, height); canvas.scale(1, -1, 1); - getSurfaceTexture().getTransformMatrix(mTextureTransformMatrix); + SurfaceTexture surfaceT = getSurfaceTexture(); + if (surfaceT != null) { + surfaceT.getTransformMatrix(mTextureTransformMatrix); + } updateTransformMatrix(mTextureTransformMatrix); canvas.drawTexture(mExtTexture, mTextureTransformMatrix, 0, 0, width, height); canvas.endRenderTarget(); @@ -488,18 +492,21 @@ public class CameraScreenNail extends SurfaceTextureScreenNail { @Override public SurfaceTexture getSurfaceTexture() { + SurfaceTexture surfaceTexture = null; synchronized (mLock) { - SurfaceTexture surfaceTexture = super.getSurfaceTexture(); + surfaceTexture = super.getSurfaceTexture(); if (surfaceTexture == null && mAcquireTexture) { try { + if (mWaitFlag) mLock.notifyAll(); + mWaitFlag = true; mLock.wait(); surfaceTexture = super.getSurfaceTexture(); } catch (InterruptedException e) { Log.w(TAG, "unexpected interruption"); } } - return surfaceTexture; } + return surfaceTexture; } private void allocateTextureIfRequested(GLCanvas canvas) { @@ -508,6 +515,7 @@ public class CameraScreenNail extends SurfaceTextureScreenNail { super.acquireSurfaceTexture(canvas); mAcquireTexture = false; mLock.notifyAll(); + mWaitFlag = false; } } } -- cgit v1.2.3