From a489e380036b047daba972115b6a2fd872098b5f Mon Sep 17 00:00:00 2001 From: George Mount Date: Mon, 14 Jan 2013 17:44:41 -0800 Subject: Fixed ANR in VideoModule. Bug 7990250 Any intent that launched the VideoModule before the PhotoModule was causing the VideoModule to deadlock. The VideoModule can now complete its own initialization. Likewise, when resuming, it no longer starts the preview on the UI thread, causing a deadlock. Change-Id: I91ce1a437e57379f83dd48ffc96a0c49bf2dc5b7 --- src/com/android/camera/VideoModule.java | 43 +++++++++++++++++---------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/src/com/android/camera/VideoModule.java b/src/com/android/camera/VideoModule.java index cdfdff10..0fecca63 100644 --- a/src/com/android/camera/VideoModule.java +++ b/src/com/android/camera/VideoModule.java @@ -462,14 +462,13 @@ public class VideoModule implements CameraModule, // ignore } - Thread startPreviewThread = new Thread(new Runnable() { + readVideoPreferences(); + new Thread(new Runnable() { @Override public void run() { - readVideoPreferences(); startPreview(); } - }); - startPreviewThread.start(); + }).start(); initializeControlByIntent(); initializeOverlay(); @@ -481,20 +480,6 @@ public class VideoModule implements CameraModule, setOrientationIndicator(0, false); setDisplayOrientation(); - // Make sure preview is started. - try { - startPreviewThread.join(); - if (mActivity.mOpenCameraFail) { - Util.showErrorAndFinish(mActivity, R.string.cannot_connect_camera); - return; - } else if (mActivity.mCameraDisabled) { - Util.showErrorAndFinish(mActivity, R.string.camera_disabled); - return; - } - } catch (InterruptedException ex) { - // ignore - } - showTimeLapseUI(mCaptureTimeLapse); initializeVideoSnapshot(); resizeForPreviewAspectRatio(); @@ -844,7 +829,12 @@ public class VideoModule implements CameraModule, } readVideoPreferences(); resizeForPreviewAspectRatio(); - startPreview(); + new Thread(new Runnable() { + @Override + public void run() { + startPreview(); + } + }).start(); } // Initializing it here after the preview is started. @@ -892,6 +882,8 @@ public class VideoModule implements CameraModule, } } + mPreviewing = true; + setDisplayOrientation(); mActivity.mCameraDevice.setDisplayOrientation(mCameraDisplayOrientation); setCameraParameters(); @@ -912,9 +904,18 @@ public class VideoModule implements CameraModule, } catch (Throwable ex) { closeCamera(); throw new RuntimeException("startPreview failed", ex); + } finally { + mActivity.runOnUiThread(new Runnable() { + @Override + public void run() { + if (mActivity.mOpenCameraFail) { + Util.showErrorAndFinish(mActivity, R.string.cannot_connect_camera); + } else if (mActivity.mCameraDisabled) { + Util.showErrorAndFinish(mActivity, R.string.camera_disabled); + } + } + }); } - - mPreviewing = true; } private void stopPreview() { -- cgit v1.2.3