OSDN Git Service

Stability: call stopPreview() before switching off video module.
authorSenpo Hu <senpo@google.com>
Tue, 30 Sep 2014 01:49:10 +0000 (18:49 -0700)
committerSenpo Hu <senpo@google.com>
Tue, 30 Sep 2014 05:32:15 +0000 (05:32 +0000)
If the preview is not stopped, the following camera operations posted
by other modules such as "apply settings" will turn camera object
in turmoil. The camera object could start throwing exception and eventually
hang.

Bug: 16300704
Bug: 17403384
Change-Id: Idd2360869d51b9dfc06309f8ac185a65add8d0c9
(cherry picked from commit 36e045a43d9b8949d9a219b84cf894cf21f8e98a)

src/com/android/camera/VideoModule.java

index f855d95..73e5548 100644 (file)
@@ -699,7 +699,9 @@ public class VideoModule extends CameraModule
             startVideoRecording();
         }
         mAppController.setShutterEnabled(false);
-        mFocusManager.onShutterUp(mCameraSettings.getCurrentFocusMode());
+        if (mCameraSettings != null) {
+            mFocusManager.onShutterUp(mCameraSettings.getCurrentFocusMode());
+        }
 
         // Keep the shutter button disabled when in video capture intent
         // mode and recording is stopped. It'll be re-enabled when
@@ -950,9 +952,16 @@ public class VideoModule extends CameraModule
 
     @Override
     public void stopPreview() {
-        if (!mPreviewing || mCameraDevice == null) {
+        if (!mPreviewing) {
+            Log.v(TAG, "Skip stopPreview since it's not mPreviewing");
+            return;
+        }
+        if (mCameraDevice == null) {
+            Log.v(TAG, "Skip stopPreview since mCameraDevice is null");
             return;
         }
+
+        Log.v(TAG, "stopPreview");
         mCameraDevice.stopPreview();
         if (mFocusManager != null) {
             mFocusManager.onPreviewStopped();
@@ -1400,14 +1409,14 @@ public class VideoModule extends CameraModule
     }
 
     private boolean stopVideoRecording() {
-        Log.i(TAG, "stopVideoRecording");
-
         // Do nothing if camera device is still capturing photo. Monkey test can trigger app crashes
         // (b/17313985) without this check. Crash could also be reproduced by continuously tapping
         // on shutter button and preview with two fingers.
         if (mSnapshotInProgress) {
+            Log.v(TAG, "Skip stopVideoRecording since snapshot in progress");
             return true;
         }
+        Log.v(TAG, "stopVideoRecording");
 
         mUI.setSwipingEnabled(true);
         mUI.showFocusUI(true);
@@ -1438,6 +1447,10 @@ public class VideoModule extends CameraModule
             // during recording. Release the camera as soon as possible because
             // face unlock or other applications may need to use the camera.
             if (mPaused) {
+                // b/16300704: Monkey is fast so it could pause the module while recording.
+                // stopPreview should definitely be called before switching off.
+                stopPreview();
+
                 closeCamera();
             }