From 71e3abfa1eb41211a0afb5ce7bc2ea960526b2c3 Mon Sep 17 00:00:00 2001 From: xiaoxin Date: Mon, 5 Sep 2022 16:21:06 +0800 Subject: [PATCH] make sure mSurfaceLock.unlock can be executed in unlockCanvasAndPost When the program is run to unlockCanvasAndPost method, if mSurface.unlockCanvasAndPost throws an exception, the mSurfaceLock.unlock() will not getting the chance to execute. If an app executes unlockCanvasAndPost in a catch and does not handle the exception, it will remain locked for a long time after the next execution of mSurfacelock.lock. make sure the msurfacelock.unlock is executed after unlockCanvasAndPost bug:245050059 in partnerissuetracker Change-Id: Ib849c840c61ac261cfaab0daefa7ae2afdbfcba3 Signed-off-by: xiaoxin --- core/java/android/view/SurfaceView.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/core/java/android/view/SurfaceView.java b/core/java/android/view/SurfaceView.java index 536a0ac6403b6..05ff9f18af746 100644 --- a/core/java/android/view/SurfaceView.java +++ b/core/java/android/view/SurfaceView.java @@ -1626,8 +1626,11 @@ public class SurfaceView extends View implements ViewRootImpl.SurfaceChangedCall */ @Override public void unlockCanvasAndPost(Canvas canvas) { - mSurface.unlockCanvasAndPost(canvas); - mSurfaceLock.unlock(); + try { + mSurface.unlockCanvasAndPost(canvas); + } finally { + mSurfaceLock.unlock(); + } } @Override