Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e19c1af8 authored by Vijayashree Channiah Sondekoppa's avatar Vijayashree Channiah Sondekoppa Committed by Steve Kondik
Browse files

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
parent fe3360ad
Loading
Loading
Loading
Loading
+11 −3
Original line number Diff line number Diff line
@@ -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;
            }
        }
    }