Do not reset the focus if next snapshot is pending.

+ Suupose autofocus is focusing and a picture will be taken when
  focus callback arrives. Remeber the next snapshot request if
  the shutter button is clicked.

bug:5589632

Change-Id: Ice8df7145f68996bd307fa5914e1c672bc624239
diff --git a/src/com/android/camera/Camera.java b/src/com/android/camera/Camera.java
index 1fad8a8..ff98f4a 100644
--- a/src/com/android/camera/Camera.java
+++ b/src/com/android/camera/Camera.java
@@ -1402,8 +1402,10 @@
 
         // If the user wants to do a snapshot while the previous one is still
         // in progress, remember the fact and do it after we finish the previous
-        // one and re-start the preview.
-        if (mCameraState == SNAPSHOT_IN_PROGRESS) {
+        // one and re-start the preview. Snapshot in progress also includes the
+        // state that autofocus is focusing and a picture will be taken when
+        // focus callback arrives.
+        if (mFocusManager.isFocusingSnapOnFinish() || mCameraState == SNAPSHOT_IN_PROGRESS) {
             mSnapshotOnIdle = true;
             return;
         }
@@ -1765,13 +1767,15 @@
         setPreviewDisplay(mSurfaceHolder);
         setDisplayOrientation();
 
-        mFocusManager.setAeAwbLock(false); // Unlock AE and AWB.
-        setCameraParameters(UPDATE_PARAM_ALL);
-        // If the focus mode is continuous autofocus, call cancelAutoFocus to
-        // resume it because it may have been paused by autoFocus call.
-        if (Parameters.FOCUS_MODE_CONTINUOUS_PICTURE.equals(mParameters.getFocusMode())) {
-            mCameraDevice.cancelAutoFocus();
+        if (!mSnapshotOnIdle) {
+            // If the focus mode is continuous autofocus, call cancelAutoFocus to
+            // resume it because it may have been paused by autoFocus call.
+            if (Parameters.FOCUS_MODE_CONTINUOUS_PICTURE.equals(mFocusManager.getFocusMode())) {
+                mCameraDevice.cancelAutoFocus();
+            }
+            mFocusManager.setAeAwbLock(false); // Unlock AE and AWB.
         }
+        setCameraParameters(UPDATE_PARAM_ALL);
 
         // Inform the mainthread to go on the UI initialization.
         if (mCameraPreviewThread != null) {
diff --git a/src/com/android/camera/FocusManager.java b/src/com/android/camera/FocusManager.java
index bdf4766..76a8737 100644
--- a/src/com/android/camera/FocusManager.java
+++ b/src/com/android/camera/FocusManager.java
@@ -471,6 +471,10 @@
         return mState == STATE_SUCCESS || mState == STATE_FAIL;
     }
 
+    public boolean isFocusingSnapOnFinish() {
+        return mState == STATE_FOCUSING_SNAP_ON_FINISH;
+    }
+
     public void removeMessages() {
         mHandler.removeMessages(RESET_TOUCH_FOCUS);
     }