camera: Fix setting of HDR mode

In HDR mode, number of JPEG callbacks is set to 2, whereas it's set
to 1 in non-HDR mode. When switching between different camera modes
(camera, photosphere, panorama), make sure HDR mode is set correctly.

Bug: 18692917
Change-Id: I82056fc4d7e605f94bde9f126754d7f3536b2114
diff --git a/camera/QCameraHWI.h b/camera/QCameraHWI.h
index f7e58ef..4fbb9c0 100755
--- a/camera/QCameraHWI.h
+++ b/camera/QCameraHWI.h
@@ -1,5 +1,5 @@
 /*
-** Copyright (c) 2011-2012 The Linux Foundation. All rights reserved.
+** Copyright (c) 2011-2012, 2015, The Linux Foundation. All rights reserved.
 **
 ** Licensed under the Apache License, Version 2.0 (the "License");
 ** you may not use this file except in compliance with the License.
@@ -453,7 +453,6 @@
     void processEvent(mm_camera_event_t *);
     int  getJpegQuality() const;
     int  getNumOfSnapshots(void) const;
-    int  getNumOfSnapshots(const QCameraParameters& params);
     int  getThumbSizesFromAspectRatio(uint32_t aspect_ratio,
                                      int *picture_width,
                                      int *picture_height);
@@ -579,7 +578,7 @@
     status_t setVideoSize(const QCameraParameters& params);
     status_t setPictureSize(const QCameraParameters& params);
     status_t setJpegQuality(const QCameraParameters& params);
-    status_t setNumOfSnapshot(const QCameraParameters& params);
+    status_t setNumOfSnapshot();
     status_t setJpegRotation(int isZSL);
     int getJpegRotation(void);
     int getISOSpeedValue();
diff --git a/camera/QCameraHWI_Parm.cpp b/camera/QCameraHWI_Parm.cpp
index 69c8d2b..e35763c 100644
--- a/camera/QCameraHWI_Parm.cpp
+++ b/camera/QCameraHWI_Parm.cpp
@@ -1,5 +1,5 @@
 /*
-** Copyright (c) 2011-2012 The Linux Foundation. All rights reserved.
+** Copyright (c) 2011-2012, 2015, The Linux Foundation. All rights reserved.
 **
 ** Licensed under the Apache License, Version 2.0 (the "License");
 ** you may not use this file except in compliance with the License.
@@ -1411,13 +1411,12 @@
     } else {
       mParameters.set("capture-burst-exposures", str_val);
     }
-    mParameters.set("num-snaps-per-shutter", params.get("num-snaps-per-shutter"));
 
     if ((rc = setAEBracket(params)))              final_rc = rc;
     //    if ((rc = setDenoise(params)))                final_rc = rc;
     if ((rc = setPreviewFpsRange(params)))              final_rc = rc;
     if((rc = setRecordingHint(params)))                 final_rc = rc;
-    if ((rc = setNumOfSnapshot(params)))                final_rc = rc;
+    if ((rc = setNumOfSnapshot()))                      final_rc = rc;
     if ((rc = setAecAwbLock(params)))                   final_rc = rc;
     if ((rc = setWhiteBalance(params)))                 final_rc = rc;
     const char *str = params.get(QCameraParameters::KEY_SCENE_MODE);
@@ -2167,6 +2166,14 @@
             if(strcmp(str,oldstr)) {
                 ALOGV("%s: valued changed from %s to %s",__func__,oldstr, str);
 
+                if (!strcmp(str, "hdr")) {
+                    ALOGV("%s: setting num-snaps-per-shutter to 2", __func__);
+                    mParameters.set("num-snaps-per-shutter", 2);
+                } else {
+                    ALOGV("%s: setting num-snaps-per-shutter to 1", __func__);
+                    mParameters.set("num-snaps-per-shutter", 1);
+                }
+
                 /* Check if we are either transitioning to/from HDR state
                    if yes preview needs restart*/
                 if(!strcmp(str, "hdr") || !strcmp(oldstr, "hdr") ) {
@@ -2180,8 +2187,10 @@
                         pausePreviewForZSL();
                     }
                 }
+
             }
 
+
             mParameters.set(QCameraParameters::KEY_SCENE_MODE, str);
             bool ret = native_set_parms(MM_CAMERA_PARM_BESTSHOT_MODE, sizeof(value),
                                        (void *)&value);
@@ -2849,16 +2858,10 @@
 }
 
 status_t QCameraHardwareInterface::
-setNumOfSnapshot(const QCameraParameters& params) {
+setNumOfSnapshot() {
     status_t rc = NO_ERROR;
 
-    int num_of_snapshot = getNumOfSnapshots(params);
-
-    if (num_of_snapshot <= 0) {
-        num_of_snapshot = 1;
-    }
-    ALOGV("number of snapshots = %d", num_of_snapshot);
-    mParameters.set("num-snaps-per-shutter", num_of_snapshot);
+    int num_of_snapshot = getNumOfSnapshots();
 
     bool result = native_set_parms(MM_CAMERA_PARM_SNAPSHOT_BURST_NUM,
                                    sizeof(int),
@@ -3188,7 +3191,7 @@
     if(!strcmp(str2, "hdr")) {
         str="HDR";
     }   else {
-        str = params.get(QCameraParameters::KEY_AE_BRACKET_HDR);
+        str=QCameraParameters::AE_BRACKET_HDR_OFF;
     }
 
     if (str != NULL) {
@@ -3571,22 +3574,6 @@
     }
 }
 
-int QCameraHardwareInterface::getNumOfSnapshots(const QCameraParameters& params)
-{
-    char prop[PROPERTY_VALUE_MAX];
-    memset(prop, 0, sizeof(prop));
-    property_get("persist.camera.snapshot.number", prop, "0");
-    ALOGV("%s: prop enable/disable = %d", __func__, atoi(prop));
-    if (atoi(prop)) {
-        ALOGV("%s: Reading maximum no of snapshots = %d"
-             "from properties", __func__, atoi(prop));
-        return atoi(prop);
-    } else {
-        return params.getInt("num-snaps-per-shutter");
-    }
-
-}
-
 int QCameraHardwareInterface::
 getThumbSizesFromAspectRatio(uint32_t aspect_ratio,
                              int *picture_width,