/*
**
** Copyright 2013, Samsung Electronics Co. LTD
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
**     http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/


/* #define LOG_NDEBUG 0 */
#define LOG_TAG "ExynosCameraActivityControl"

#include "ExynosCameraActivityControl.h"

namespace android {

ExynosCameraActivityControl::ExynosCameraActivityControl(__unused int cameraId)
{
    flagAutoFocusRunning = false;
    touchAFMode = false;
    touchAFModeForFlash = false;

    m_autofocusMgr = new ExynosCameraActivityAutofocus();
    m_flashMgr = new ExynosCameraActivityFlash();
    m_specialCaptureMgr = new ExynosCameraActivitySpecialCapture();
    m_uctlMgr = new ExynosCameraActivityUCTL();
    m_focusMode = FOCUS_MODE_AUTO;
    m_fpsValue = 1;
    m_halVersion = IS_HAL_VER_1_0;
}

ExynosCameraActivityControl::~ExynosCameraActivityControl()
{
    if (m_autofocusMgr != NULL) {
        delete m_autofocusMgr;
        m_autofocusMgr = NULL;
    }

    if (m_flashMgr != NULL) {
        delete m_flashMgr;
        m_flashMgr = NULL;
    }

    if (m_specialCaptureMgr != NULL) {
        delete m_specialCaptureMgr;
        m_specialCaptureMgr = NULL;
    }

    if (m_uctlMgr != NULL) {
        delete m_uctlMgr;
        m_uctlMgr = NULL;
    }
}

bool ExynosCameraActivityControl::autoFocus(int focusMode, int focusType, bool flagStartFaceDetection, int numOfFace)
{
    bool ret = true;
    int newfocusMode = 0;
    int currentAutofocusState = ExynosCameraActivityAutofocus::AUTOFOCUS_STATE_NONE;
    int newMgrAutofocusMode = ExynosCameraActivityAutofocus::AUTOFOCUS_MODE_BASE;
    int oldMgrAutofocusMode = ExynosCameraActivityAutofocus::AUTOFOCUS_MODE_BASE;
    bool flagAutoFocusTringger = false;
    bool flagPreFlash = false;
    bool flagLockFocus = false;

    if (focusType == AUTO_FOCUS_SERVICE) {
        m_flashMgr->updateAeState();
    }
    ALOGD("DEBUG(%s[%d]):NeedCaptureFlash=%d", __FUNCTION__, __LINE__, m_flashMgr->getNeedCaptureFlash());
    if (m_flashMgr->getNeedCaptureFlash() == true) {
        /* start Pre-flash */
        if (startPreFlash(this->getAutoFocusMode()) != NO_ERROR)
            ALOGE("ERR(%s[%d]):start Pre-flash Fail", __FUNCTION__, __LINE__);
    }

    if (focusType == AUTO_FOCUS_HAL
#ifdef SAMSUNG_MANUAL_FOCUS
        && this->getAutoFocusMode() != FOCUS_MODE_MANUAL
#endif
        )
        newfocusMode = FOCUS_MODE_AUTO;
    else
        newfocusMode = this->getAutoFocusMode();

    oldMgrAutofocusMode = m_autofocusMgr->getAutofocusMode();
    ALOGD("DEBUG(%s[%d]):newfocusMode=%d", __FUNCTION__, __LINE__, newfocusMode);

    switch (newfocusMode) {
    case FOCUS_MODE_AUTO:
        if (touchAFMode == true)
            newMgrAutofocusMode = ExynosCameraActivityAutofocus::AUTOFOCUS_MODE_TOUCH;
        else
            newMgrAutofocusMode = ExynosCameraActivityAutofocus::AUTOFOCUS_MODE_AUTO;
        break;
    case FOCUS_MODE_INFINITY:
        newMgrAutofocusMode = ExynosCameraActivityAutofocus::AUTOFOCUS_MODE_INFINITY;
        break;
    case FOCUS_MODE_MACRO:
        newMgrAutofocusMode = ExynosCameraActivityAutofocus::AUTOFOCUS_MODE_MACRO;
        break;
    case FOCUS_MODE_CONTINUOUS_VIDEO:
        newMgrAutofocusMode = ExynosCameraActivityAutofocus::AUTOFOCUS_MODE_CONTINUOUS_VIDEO;
        break;
    case FOCUS_MODE_CONTINUOUS_PICTURE:
        newMgrAutofocusMode = ExynosCameraActivityAutofocus::AUTOFOCUS_MODE_CONTINUOUS_PICTURE;
        break;
    case FOCUS_MODE_CONTINUOUS_PICTURE_MACRO:
        newMgrAutofocusMode = ExynosCameraActivityAutofocus::AUTOFOCUS_MODE_CONTINUOUS_PICTURE_MACRO;
        break;
    case FOCUS_MODE_TOUCH:
        newMgrAutofocusMode = ExynosCameraActivityAutofocus::AUTOFOCUS_MODE_TOUCH;
        break;
    case FOCUS_MODE_FIXED:
        newMgrAutofocusMode = ExynosCameraActivityAutofocus::AUTOFOCUS_MODE_FIXED;
        break;
    case FOCUS_MODE_EDOF:
        newMgrAutofocusMode = ExynosCameraActivityAutofocus::AUTOFOCUS_MODE_EDOF;
        break;
#ifdef SAMSUNG_MANUAL_FOCUS
    case FOCUS_MODE_MANUAL:
        newMgrAutofocusMode = ExynosCameraActivityAutofocus::AUTOFOCUS_MODE_MANUAL;
        break;
#endif
    default:
        ALOGE("ERR(%s):Unsupported focusMode=%d", __FUNCTION__, newfocusMode);
        return false;
        break;
    }

    if (focusMode == newfocusMode) {
        switch (newMgrAutofocusMode) {
        case ExynosCameraActivityAutofocus::AUTOFOCUS_MODE_FIXED:
        case ExynosCameraActivityAutofocus::AUTOFOCUS_MODE_EDOF:
        case ExynosCameraActivityAutofocus::AUTOFOCUS_MODE_CONTINUOUS_VIDEO:
        case ExynosCameraActivityAutofocus::AUTOFOCUS_MODE_CONTINUOUS_PICTURE:
        case ExynosCameraActivityAutofocus::AUTOFOCUS_MODE_CONTINUOUS_PICTURE_MACRO:
            flagLockFocus = true;
            break;
        default:
            break;
        }
    }

    /*
    * Applications can call autoFocus(AutoFocusCallback) in this mode.
    * If the autofocus is in the middle of scanning,
    * the focus callback will return when it completes
    * If the autofocus is not scanning,
    * the focus callback will immediately return with a boolean
    * that indicates whether the focus is sharp or not.
    */

    /*
     * But, When Continuous af is running,
     * auto focus api can be triggered,
     * and then, af will be lock. (af lock)
     */
    switch (newMgrAutofocusMode) {
    case ExynosCameraActivityAutofocus::AUTOFOCUS_MODE_FIXED:
    case ExynosCameraActivityAutofocus::AUTOFOCUS_MODE_EDOF:
    case ExynosCameraActivityAutofocus::AUTOFOCUS_MODE_CONTINUOUS_VIDEO:
    case ExynosCameraActivityAutofocus::AUTOFOCUS_MODE_CONTINUOUS_PICTURE:
    case ExynosCameraActivityAutofocus::AUTOFOCUS_MODE_CONTINUOUS_PICTURE_MACRO:
#ifdef SAMSUNG_MANUAL_FOCUS
    case ExynosCameraActivityAutofocus::AUTOFOCUS_MODE_MANUAL:
#endif
        flagAutoFocusTringger = false;
        break;
    default:
        switch(oldMgrAutofocusMode) {
        case ExynosCameraActivityAutofocus::AUTOFOCUS_MODE_FIXED:
        case ExynosCameraActivityAutofocus::AUTOFOCUS_MODE_EDOF:
        case ExynosCameraActivityAutofocus::AUTOFOCUS_MODE_CONTINUOUS_VIDEO:
        case ExynosCameraActivityAutofocus::AUTOFOCUS_MODE_CONTINUOUS_PICTURE:
        case ExynosCameraActivityAutofocus::AUTOFOCUS_MODE_CONTINUOUS_PICTURE_MACRO:
            flagAutoFocusTringger = true;
            break;
        default:
            if (oldMgrAutofocusMode == newMgrAutofocusMode) {
                currentAutofocusState = m_autofocusMgr->getCurrentState();

                if (currentAutofocusState != ExynosCameraActivityAutofocus::AUTOFOCUS_STATE_SCANNING)
                    flagAutoFocusTringger = true;
                else
                    flagAutoFocusTringger = false;
            } else {
                flagAutoFocusTringger = true;
            }
            break;
        }
        break;
    }

    if (flagAutoFocusTringger == true) {
        if (m_autofocusMgr->flagAutofocusStart() == true)
            m_autofocusMgr->stopAutofocus();

        m_autofocusMgr->setAutofocusMode(newMgrAutofocusMode);

        m_autofocusMgr->startAutofocus();
    } else {
        m_autofocusMgr->setAutofocusMode(newMgrAutofocusMode);

        switch (newMgrAutofocusMode) {
        case ExynosCameraActivityAutofocus::AUTOFOCUS_MODE_FIXED:
        case ExynosCameraActivityAutofocus::AUTOFOCUS_MODE_EDOF:
            ret = false;
            goto done;
            break;
        case ExynosCameraActivityAutofocus::AUTOFOCUS_MODE_CONTINUOUS_VIDEO:
        case ExynosCameraActivityAutofocus::AUTOFOCUS_MODE_CONTINUOUS_PICTURE:
        case ExynosCameraActivityAutofocus::AUTOFOCUS_MODE_CONTINUOUS_PICTURE_MACRO:
            currentAutofocusState = m_autofocusMgr->getCurrentState();

            if (m_autofocusMgr->flagLockAutofocus() == true &&
                currentAutofocusState != ExynosCameraActivityAutofocus::AUTOFOCUS_STATE_SUCCEESS) {
                /* for make it fail */
                currentAutofocusState = ExynosCameraActivityAutofocus::AUTOFOCUS_STATE_FAIL;
            }

            if (currentAutofocusState == ExynosCameraActivityAutofocus::AUTOFOCUS_STATE_SUCCEESS) {
                ret = true;
                goto done;
            } else if (currentAutofocusState == ExynosCameraActivityAutofocus::AUTOFOCUS_STATE_FAIL) {
                ret = false;
                goto done;
            }

            break;
#ifdef SAMSUNG_MANUAL_FOCUS
        case ExynosCameraActivityAutofocus::AUTOFOCUS_MODE_MANUAL:
            ret = true;
            goto done;
#endif
        default:
            break;
        }
    }

    ret = m_autofocusMgr->getAutofocusResult(flagLockFocus, flagStartFaceDetection, numOfFace);

done :
    /* The focus position is locked after autoFocus call with CAF
    * But, the focus position is not locked when cancelAutoFocus after TAF is called
    * CF) If cancelAutoFocus is called when TAF, the focusMode is changed from TAF to CAF */

    if (flagLockFocus) {
        m_autofocusMgr->lockAutofocus();
    }

    /* Stop pre flash */
    stopPreFlash();

    return ret;
}

bool ExynosCameraActivityControl::cancelAutoFocus(void)
{
    /*
     * Cancels any auto-focus function in progress.
     * Whether or not auto-focus is currently in progress,
     * this function will return the focus position to the default.
     * If the camera does not support auto-focus, this is a no-op.
     */

    touchAFMode = false;
    touchAFModeForFlash = false;
    int mode = m_autofocusMgr->getAutofocusMode();

    switch (m_autofocusMgr->getAutofocusMode()) {
    /*  If applications want to resume the continuous focus, cancelAutoFocus must be called */
    case ExynosCameraActivityAutofocus::AUTOFOCUS_MODE_CONTINUOUS_VIDEO:
    case ExynosCameraActivityAutofocus::AUTOFOCUS_MODE_CONTINUOUS_PICTURE:
    case ExynosCameraActivityAutofocus::AUTOFOCUS_MODE_CONTINUOUS_PICTURE_MACRO:
        if (m_autofocusMgr->flagLockAutofocus() == true) {
            m_autofocusMgr->unlockAutofocus();

            if (m_autofocusMgr->flagAutofocusStart() == false)
                m_autofocusMgr->startAutofocus();
        }
        break;
    default:
        if (m_autofocusMgr->flagLockAutofocus() == true)
            m_autofocusMgr->unlockAutofocus();

        if (m_autofocusMgr->flagAutofocusStart() == true)
            m_autofocusMgr->stopAutofocus();

        break;
    }

    enum ExynosCameraActivityFlash::FLASH_TRIGGER triggerPath;
    m_flashMgr->getFlashTrigerPath(&triggerPath);

    if ((triggerPath == ExynosCameraActivityFlash::FLASH_TRIGGER_LONG_BUTTON) ||
        ((m_flashMgr->getNeedCaptureFlash() == true) && (m_flashMgr->getFlashStatus() != AA_FLASHMODE_OFF)))
        this->cancelFlash();
    else
        m_flashMgr->setFlashStep(ExynosCameraActivityFlash::FLASH_STEP_OFF);

    m_flashMgr->setFlashTrigerPath(ExynosCameraActivityFlash::FLASH_TRIGGER_OFF);

    return true;
}

void ExynosCameraActivityControl::setAutoFocusMode(int focusMode)
{
    int newMgrAutofocusMode = 0;
    int oldMgrAutofocusMode = m_autofocusMgr->getAutofocusMode();

    m_focusMode = focusMode;

    ALOGD("DEBUG(%s[%d]):m_focusMode=%d", __FUNCTION__, __LINE__, m_focusMode);

    switch (m_focusMode) {
    case FOCUS_MODE_INFINITY:
        newMgrAutofocusMode = ExynosCameraActivityAutofocus::AUTOFOCUS_MODE_INFINITY;
        break;
    case FOCUS_MODE_FIXED:
        newMgrAutofocusMode = ExynosCameraActivityAutofocus::AUTOFOCUS_MODE_FIXED;
        break;
    case FOCUS_MODE_EDOF:
        newMgrAutofocusMode = ExynosCameraActivityAutofocus::AUTOFOCUS_MODE_EDOF;
        break;
    case FOCUS_MODE_CONTINUOUS_VIDEO:
        newMgrAutofocusMode = ExynosCameraActivityAutofocus::AUTOFOCUS_MODE_CONTINUOUS_VIDEO;
        break;
    case FOCUS_MODE_CONTINUOUS_PICTURE:
        newMgrAutofocusMode = ExynosCameraActivityAutofocus::AUTOFOCUS_MODE_CONTINUOUS_PICTURE;
        break;
    case FOCUS_MODE_CONTINUOUS_PICTURE_MACRO:
        newMgrAutofocusMode = ExynosCameraActivityAutofocus::AUTOFOCUS_MODE_CONTINUOUS_PICTURE_MACRO;
        break;
#ifdef SAMSUNG_OT
    case FOCUS_MODE_OBJECT_TRACKING_PICTURE:
        newMgrAutofocusMode = ExynosCameraActivityAutofocus::AUTOFOCUS_MODE_OBJECT_TRACKING_PICTURE;
        break;
    case FOCUS_MODE_OBJECT_TRACKING_VIDEO:
        newMgrAutofocusMode = ExynosCameraActivityAutofocus::AUTOFOCUS_MODE_OBJECT_TRACKING_VIDEO;
        break;
#endif
#ifdef SAMSUNG_MANUAL_FOCUS
    case FOCUS_MODE_MANUAL:
        newMgrAutofocusMode = ExynosCameraActivityAutofocus::AUTOFOCUS_MODE_MANUAL;
        break;
#endif
    default:
        break;
    }

    ALOGD("DEBUG(%s[%d]):newMgrAutofocusMode=%d, oldMgrAutofocusMode=%d",
           __FUNCTION__, __LINE__, newMgrAutofocusMode, oldMgrAutofocusMode);

    if (oldMgrAutofocusMode != newMgrAutofocusMode) {
        if (m_autofocusMgr->flagLockAutofocus() == true)
            m_autofocusMgr->unlockAutofocus();
    }

    if (newMgrAutofocusMode) { /* Continuous autofocus, infinity, fixed ... */
        /*
         * If applications want to resume the continuous focus,
         * cancelAutoFocus must be called.
         * Restarting the preview will not resume the continuous autofocus.
         * To stop continuous focus, applications should change the focus mode to other modes.
         */
        bool flagRestartAutofocus = false;

        if (oldMgrAutofocusMode == newMgrAutofocusMode) {
            if (m_autofocusMgr->flagAutofocusStart() == false &&
                m_autofocusMgr->flagLockAutofocus() == false)
                flagRestartAutofocus = true;
            else
                flagRestartAutofocus = false;
        } else {
            flagRestartAutofocus = true;
        }

        if (flagRestartAutofocus == true &&
            m_autofocusMgr->flagAutofocusStart() == true)
            m_autofocusMgr->stopAutofocus();

        if (oldMgrAutofocusMode != newMgrAutofocusMode)
            if (m_autofocusMgr->setAutofocusMode(newMgrAutofocusMode) == false)
                ALOGE("ERR(%s):setAutofocusMode fail", __FUNCTION__);

        if (flagRestartAutofocus == true)
            m_autofocusMgr->startAutofocus();

        enum ExynosCameraActivityFlash::FLASH_TRIGGER triggerPath;
        m_flashMgr->getFlashTrigerPath(&triggerPath);

        if ((triggerPath == ExynosCameraActivityFlash::FLASH_TRIGGER_LONG_BUTTON) ||
            ((m_flashMgr->getNeedCaptureFlash() == true) && (m_flashMgr->getFlashStatus() != AA_FLASHMODE_OFF)))
            this->cancelFlash();
        else
            m_flashMgr->setFlashStep(ExynosCameraActivityFlash::FLASH_STEP_OFF);

        m_flashMgr->setFlashTrigerPath(ExynosCameraActivityFlash::FLASH_TRIGGER_OFF);

    } else { /* single autofocus */
        switch (oldMgrAutofocusMode) {
        case ExynosCameraActivityAutofocus::AUTOFOCUS_MODE_INFINITY:
        case ExynosCameraActivityAutofocus::AUTOFOCUS_MODE_FIXED:
        case ExynosCameraActivityAutofocus::AUTOFOCUS_MODE_EDOF:
        case ExynosCameraActivityAutofocus::AUTOFOCUS_MODE_CONTINUOUS_VIDEO:
        case ExynosCameraActivityAutofocus::AUTOFOCUS_MODE_CONTINUOUS_PICTURE:
        case ExynosCameraActivityAutofocus::AUTOFOCUS_MODE_CONTINUOUS_PICTURE_MACRO:
#ifdef SAMSUNG_OT
        case ExynosCameraActivityAutofocus::AUTOFOCUS_MODE_OBJECT_TRACKING_PICTURE:
        case ExynosCameraActivityAutofocus::AUTOFOCUS_MODE_OBJECT_TRACKING_VIDEO:
#endif
#ifdef SAMSUNG_MANUAL_FOCUS
        case ExynosCameraActivityAutofocus::AUTOFOCUS_MODE_MANUAL:
#endif
            if (m_autofocusMgr->flagAutofocusStart() == true)
                m_autofocusMgr->stopAutofocus();

            break;
        default:
            break;
        }
    }
}

int ExynosCameraActivityControl::getAutoFocusMode(void)
{
    return m_focusMode;
}

void ExynosCameraActivityControl::setAutoFcousArea(ExynosRect2 rect, int weight)
{
    m_autofocusMgr->setFocusAreas(rect, weight);
}

void ExynosCameraActivityControl::setAutoFocusMacroPosition(
        int oldAutoFocusMacroPosition,
        int autoFocusMacroPosition)
{
    int macroPosition = ExynosCameraActivityAutofocus::AUTOFOCUS_MACRO_POSITION_BASE;

    switch (autoFocusMacroPosition) {
    case 1:
        macroPosition = ExynosCameraActivityAutofocus::AUTOFOCUS_MACRO_POSITION_CENTER;
        break;
    case 2:
        macroPosition = ExynosCameraActivityAutofocus::AUTOFOCUS_MACRO_POSITION_CENTER_UP;
        break;
    default:
        break;
    }

    m_autofocusMgr->setMacroPosition(macroPosition);

    /* if macro option change, we need to restart CAF */
    if (oldAutoFocusMacroPosition != autoFocusMacroPosition) {
        if ((m_autofocusMgr->getAutofocusMode() == ExynosCameraActivityAutofocus::AUTOFOCUS_MODE_CONTINUOUS_PICTURE ||
            m_autofocusMgr->getAutofocusMode() == ExynosCameraActivityAutofocus::AUTOFOCUS_MODE_CONTINUOUS_VIDEO ||
            m_autofocusMgr->getAutofocusMode() == ExynosCameraActivityAutofocus::AUTOFOCUS_MODE_CONTINUOUS_PICTURE_MACRO) &&
            m_autofocusMgr->flagAutofocusStart() == true &&
            m_autofocusMgr->flagLockAutofocus() == false) {
            m_autofocusMgr->stopAutofocus();
            m_autofocusMgr->startAutofocus();
        }
    }
}

int ExynosCameraActivityControl::getCAFResult(void)
{
    return m_autofocusMgr->getCAFResult();
}

void ExynosCameraActivityControl::stopAutoFocus(void)
{
    if (m_autofocusMgr->flagLockAutofocus() == true)
        m_autofocusMgr->unlockAutofocus();
    if (m_autofocusMgr->flagAutofocusStart() == true)
        m_autofocusMgr->stopAutofocus();
}

bool ExynosCameraActivityControl::setFlashMode(int flashMode)
{
    enum flash_mode m_flashMode;
    enum aa_ae_flashmode aeflashMode;

    switch (flashMode) {
    case FLASH_MODE_OFF:
        m_flashMode   = ::CAM2_FLASH_MODE_OFF;
        aeflashMode = ::AA_FLASHMODE_OFF;

        m_flashMgr->setFlashReq(ExynosCameraActivityFlash::FLASH_REQ_OFF);
        break;
    case FLASH_MODE_AUTO:
        m_flashMode   = ::CAM2_FLASH_MODE_SINGLE;
        /* aeflashMode = ::AA_FLASHMODE_AUTO; */
        aeflashMode = ::AA_FLASHMODE_CAPTURE;

        m_flashMgr->setFlashReq(ExynosCameraActivityFlash::FLASH_REQ_AUTO);
        break;
    case FLASH_MODE_ON:
        m_flashMode   = ::CAM2_FLASH_MODE_SINGLE;
        /* aeflashMode = ::AA_FLASHMODE_ON; */
        aeflashMode = ::AA_FLASHMODE_ON_ALWAYS;

        m_flashMgr->setFlashReq(ExynosCameraActivityFlash::FLASH_REQ_ON);
        break;
    case FLASH_MODE_TORCH:
        m_flashMode   = ::CAM2_FLASH_MODE_TORCH;
        aeflashMode = ::AA_FLASHMODE_ON_ALWAYS;

        m_flashMgr->setFlashReq(ExynosCameraActivityFlash::FLASH_REQ_TORCH);
        break;
    case FLASH_MODE_RED_EYE:
    default:
        ALOGE("ERR(%s):Unsupported value(%d)", __FUNCTION__, flashMode);
        return false;
        break;
    }
    return true;
}

status_t ExynosCameraActivityControl::startPreFlash(int focusMode)
{
    enum ExynosCameraActivityFlash::FLASH_TRIGGER triggerPath;
    bool flagPreFlash = false;
    int ret = NO_ERROR;

    if (m_flashMgr->getFlashWaitCancel() == true)
        m_flashMgr->setFlashWaitCancel(false);

    m_flashMgr->setCaptureStatus(true);
    m_flashMgr->setMainFlashFiring(false);
    m_flashMgr->getFlashTrigerPath(&triggerPath);

    if (touchAFModeForFlash == false && triggerPath != ExynosCameraActivityFlash::FLASH_TRIGGER_SHORT_BUTTON) {
        if (focusMode == FOCUS_MODE_AUTO) {
           m_flashMgr->setFlashTrigerPath(ExynosCameraActivityFlash::FLASH_TRIGGER_LONG_BUTTON);
           ALOGD("DEBUG(%s):FLASH_TRIGGER_LONG_BUTTON !!!", __FUNCTION__);
           flagPreFlash = true;
        } else {
           m_flashMgr->setFlashTrigerPath(ExynosCameraActivityFlash::FLASH_TRIGGER_SHORT_BUTTON);
           ALOGD("DEBUG(%s):FLASH_TRIGGER_SHORT_BUTTON !!!", __FUNCTION__);
           flagPreFlash = false;
        }
    } else {
        m_flashMgr->setFlashTrigerPath(ExynosCameraActivityFlash::FLASH_TRIGGER_TOUCH_DISPLAY);
        ALOGD("DEBUG(%s):FLASH_TRIGGER_TOUCH_DISPLAY !!!", __FUNCTION__);
        flagPreFlash = true;
    }

    if (flagPreFlash == true) {
        m_flashMgr->setFlashStep(ExynosCameraActivityFlash::FLASH_STEP_PRE_START);

        if (m_flashMgr->waitAeDone() == false) {
            ALOGE("ERR(%s):waitAeDone() fail", __FUNCTION__);
            ret = INVALID_OPERATION;
        }
    }

    return ret;
}

bool ExynosCameraActivityControl::flagFocusing(struct camera2_shot_ext *shot_ext, int focusMode)
{
    bool ret = false;

    if (shot_ext == NULL) {
        ALOGE("ERR(%s):shot_ext === NULL", __func__);
        return false;
    }

    switch (focusMode) {
    case FOCUS_MODE_INFINITY:
    case FOCUS_MODE_MACRO:
    case FOCUS_MODE_FIXED:
    case FOCUS_MODE_EDOF:
    case FOCUS_MODE_CONTINUOUS_VIDEO:
        return false;
    default:
        break;
    }

    if (shot_ext == NULL) {
        ALOGE("ERR(%s):shot_ext is NULL", __func__);
        return false;
    }

    ExynosCameraActivityAutofocus::AUTOFOCUS_STATE autoFocusState = m_autofocusMgr->afState2AUTOFOCUS_STATE(shot_ext->shot.dm.aa.afState);
    switch(autoFocusState) {
    case ExynosCameraActivityAutofocus::AUTOFOCUS_STATE_SCANNING:
        ret = true;
        break;
    case ExynosCameraActivityAutofocus::AUTOFOCUS_STATE_NONE:
    case ExynosCameraActivityAutofocus::AUTOFOCUS_STATE_SUCCEESS:
    case ExynosCameraActivityAutofocus::AUTOFOCUS_STATE_FAIL:
        ret = false;
        break;
    default:
        ALOGD("DEBUG(%s):invalid autoFocusState(%d)", __func__, autoFocusState);
        ret = false;
        break;
    }

    return ret;
}

void ExynosCameraActivityControl::stopPreFlash(void)
{
    enum ExynosCameraActivityFlash::FLASH_STEP flashStep;
    m_flashMgr->getFlashStep(&flashStep);

    if (flashStep == ExynosCameraActivityFlash::FLASH_STEP_PRE_START)
    m_flashMgr->setFlashStep(ExynosCameraActivityFlash::FLASH_STEP_PRE_DONE);
}

bool ExynosCameraActivityControl::waitFlashMainReady()
{
    return m_flashMgr->waitMainReady();
}

int ExynosCameraActivityControl::startMainFlash(void)
{
    int totalWaitingTime = 0;
    int waitCount = 0;
    unsigned int shotFcount = 0;
    enum ExynosCameraActivityFlash::FLASH_TRIGGER triggerPath;
    enum ExynosCameraActivityFlash::FLASH_STEP flashStep;

    m_flashMgr->getFlashTrigerPath(&triggerPath);

    /* check preflash to prevent FW lock-up */
    do {
        usleep(FLASH_WAITING_SLEEP_TIME);
        totalWaitingTime += FLASH_WAITING_SLEEP_TIME;
    } while ((totalWaitingTime <= FLASH_WAITING_SLEEP_TIME * 30) && (m_flashMgr->checkPreFlash() == false));

    if (m_flashMgr->checkPreFlash() == false) {
        ALOGD("DEBUG(%s): preflash is not done : m_flashMgr->checkPreFlash(%d)", __FUNCTION__, m_flashMgr->checkPreFlash());
        return -1;
    }

    if (m_flashMgr->waitMainReady() == false)
        ALOGW("WARN(%s):waitMainReady() timeout", __FUNCTION__);

    if (m_flashMgr->getFlashWaitCancel() == true) {
        ALOGD("DEBUG(%s): getFlashWaitCancel(%d)", __FUNCTION__, m_flashMgr->getFlashWaitCancel());
        return -1;
    }

    m_flashMgr->getFlashStep(&flashStep);
    if (flashStep == ExynosCameraActivityFlash::FLASH_STEP_OFF) {
        ALOGD("DEBUG(%s): getFlashStep is changed FLASH_STEP_OFF", __FUNCTION__);
        return -1;
    }

    m_flashMgr->setMainFlashFiring(true);
    m_flashMgr->setFlashStep(ExynosCameraActivityFlash::FLASH_STEP_MAIN_START);

    /* get best shot frame count */
    totalWaitingTime = 0;
    waitCount = 0;
    m_flashMgr->resetShotFcount();
    do {
        waitCount = m_flashMgr->getWaitingCount();
        if (0 < waitCount) {
            usleep(FLASH_WAITING_SLEEP_TIME);
            totalWaitingTime += FLASH_WAITING_SLEEP_TIME;
        }
    } while (0 < waitCount && totalWaitingTime <= FLASH_MAX_WAITING_TIME);

    if (0 < waitCount || FLASH_MAX_WAITING_TIME < totalWaitingTime)
        ALOGE("ERR(%s):waiting too much (%d msec)", __FUNCTION__, totalWaitingTime);

    shotFcount = m_flashMgr->getShotFcount();

    return shotFcount;
}

void ExynosCameraActivityControl::stopMainFlash(void)
{
    m_flashMgr->setCaptureStatus(false);
    m_flashMgr->setMainFlashFiring(false);

    m_flashMgr->setFlashTrigerPath(ExynosCameraActivityFlash::FLASH_TRIGGER_OFF);
    m_flashMgr->setFlashStep(ExynosCameraActivityFlash::FLASH_STEP_OFF);
}

void ExynosCameraActivityControl::cancelFlash(void)
{
    ALOGI("INFO(%s[%d])", __FUNCTION__, __LINE__);

    m_flashMgr->setFlashStep(ExynosCameraActivityFlash::FLASH_STEP_CANCEL);
    m_flashMgr->setFlashWaitCancel(true);
}

void ExynosCameraActivityControl::setHdrMode(bool hdrMode)
{
    if (hdrMode)
        m_specialCaptureMgr->setCaptureMode(ExynosCameraActivitySpecialCapture::SCAPTURE_MODE_HDR);
    else
        m_specialCaptureMgr->setCaptureMode(ExynosCameraActivitySpecialCapture::SCAPTURE_MODE_NONE);
}

#ifdef OIS_CAPTURE
void ExynosCameraActivityControl::setOISCaptureMode(bool oisMode)
{
    if (oisMode)
        m_specialCaptureMgr->setCaptureMode(ExynosCameraActivitySpecialCapture::SCAPTURE_MODE_OIS);
    else
        m_specialCaptureMgr->setCaptureMode(ExynosCameraActivitySpecialCapture::SCAPTURE_MODE_NONE);
}
#endif

int ExynosCameraActivityControl::getHdrFcount(int index)
{
    int startFcount = 0;
    int totalWaitingTime = 0;
    unsigned int shotFcount = 0;

    do {
        startFcount = m_specialCaptureMgr->getHdrStartFcount(index);
        if (startFcount == 0) {
            usleep(HDR_WAITING_SLEEP_TIME);
            totalWaitingTime += HDR_WAITING_SLEEP_TIME;
        }
    } while (startFcount == 0 && totalWaitingTime <= HDR_MAX_WAITING_TIME);

    if (startFcount == 0 || totalWaitingTime >= HDR_MAX_WAITING_TIME)
        ALOGE("ERR(%s):waiting too much (%d msec)", __FUNCTION__, totalWaitingTime);

    shotFcount = startFcount + m_specialCaptureMgr->getHdrWaitFcount();

    return shotFcount;
}

void ExynosCameraActivityControl::activityBeforeExecFunc(int pipeId, void *args)
{
    switch(pipeId) {
    case PIPE_FLITE:
        m_autofocusMgr->execFunction(ExynosCameraActivityBase::CALLBACK_TYPE_SENSOR_BEFORE, args);
        m_flashMgr->execFunction(ExynosCameraActivityBase::CALLBACK_TYPE_SENSOR_BEFORE, args);
        m_specialCaptureMgr->execFunction(ExynosCameraActivityBase::CALLBACK_TYPE_SENSOR_BEFORE, args);
        m_uctlMgr->execFunction(ExynosCameraActivityBase::CALLBACK_TYPE_SENSOR_BEFORE, args);
        break;
    case PIPE_3AA:
    case PIPE_3AA_ISP:
        if (m_halVersion != IS_HAL_VER_3_2) {
            m_autofocusMgr->execFunction(ExynosCameraActivityBase::CALLBACK_TYPE_3A_BEFORE, args);
            m_flashMgr->execFunction(ExynosCameraActivityBase::CALLBACK_TYPE_3A_BEFORE, args);
        } else {
            m_flashMgr->execFunction(ExynosCameraActivityBase::CALLBACK_TYPE_3A_BEFORE_HAL3, args);
        }
        m_specialCaptureMgr->execFunction(ExynosCameraActivityBase::CALLBACK_TYPE_3A_BEFORE, args);
        /* Added it for FD-AF. 2015/05/04*/
        m_uctlMgr->execFunction(ExynosCameraActivityBase::CALLBACK_TYPE_3A_BEFORE, args);
        break;
    /* to set metadata of ISP buffer */
    case PIPE_POST_3AA_ISP:
        m_uctlMgr->execFunction(ExynosCameraActivityBase::CALLBACK_TYPE_3A_BEFORE, args);
        break;
    /* TO DO : seperate 3aa & isp pipe */
/*
    case PIPE_3AA:
    case PIPE_3AA_ISP:
        m_autofocusMgr->execFunction(ExynosCameraActivityBase::CALLBACK_TYPE_ISP_BEFORE, args);
        m_flashMgr->execFunction(ExynosCameraActivityBase::CALLBACK_TYPE_ISP_BEFORE, args);
        m_specialCaptureMgr->execFunction(ExynosCameraActivityBase::CALLBACK_TYPE_ISP_BEFORE, args);
        break;
*/
    case PIPE_ISPC:
    case PIPE_SCC:
        if (m_halVersion != IS_HAL_VER_3_2)
            m_autofocusMgr->execFunction(ExynosCameraActivityBase::CALLBACK_TYPE_SCC_BEFORE, args);
        m_flashMgr->execFunction(ExynosCameraActivityBase::CALLBACK_TYPE_SCC_BEFORE, args);
        m_specialCaptureMgr->execFunction(ExynosCameraActivityBase::CALLBACK_TYPE_SCC_BEFORE, args);
        m_uctlMgr->execFunction(ExynosCameraActivityBase::CALLBACK_TYPE_SCC_BEFORE, args);
        break;
    case PIPE_SCP:
        if (m_halVersion != IS_HAL_VER_3_2)
            m_autofocusMgr->execFunction(ExynosCameraActivityBase::CALLBACK_TYPE_SCP_BEFORE, args);
        m_flashMgr->execFunction(ExynosCameraActivityBase::CALLBACK_TYPE_SCP_BEFORE, args);
        m_specialCaptureMgr->execFunction(ExynosCameraActivityBase::CALLBACK_TYPE_SCP_BEFORE, args);
        m_uctlMgr->execFunction(ExynosCameraActivityBase::CALLBACK_TYPE_SCP_BEFORE, args);
        break;
    /* HW FD Orientation is enabled 2014/04/28 */
    case PIPE_ISP:
    case PIPE_DIS:
        m_uctlMgr->execFunction(ExynosCameraActivityBase::CALLBACK_TYPE_3A_BEFORE, args);
        break;
    default:
        break;
    }
}

void ExynosCameraActivityControl::activityAfterExecFunc(int pipeId, void *args)
{
    switch(pipeId) {
    case PIPE_FLITE:
        m_autofocusMgr->execFunction(ExynosCameraActivityBase::CALLBACK_TYPE_SENSOR_AFTER, args);
        m_flashMgr->execFunction(ExynosCameraActivityBase::CALLBACK_TYPE_SENSOR_AFTER, args);
        m_specialCaptureMgr->execFunction(ExynosCameraActivityBase::CALLBACK_TYPE_SENSOR_AFTER, args);
        m_uctlMgr->execFunction(ExynosCameraActivityBase::CALLBACK_TYPE_SENSOR_AFTER, args);
        break;
    case PIPE_3AA:
    case PIPE_3AA_ISP:
        if (m_halVersion != IS_HAL_VER_3_2) {
            m_autofocusMgr->execFunction(ExynosCameraActivityBase::CALLBACK_TYPE_3A_AFTER, args);
            m_flashMgr->execFunction(ExynosCameraActivityBase::CALLBACK_TYPE_3A_AFTER, args);
        } else {
            m_flashMgr->execFunction(ExynosCameraActivityBase::CALLBACK_TYPE_3A_AFTER_HAL3, args);
        }
        m_specialCaptureMgr->execFunction(ExynosCameraActivityBase::CALLBACK_TYPE_3A_AFTER, args);
        break;
    case PIPE_POST_3AA_ISP:
        m_uctlMgr->execFunction(ExynosCameraActivityBase::CALLBACK_TYPE_3A_AFTER, args);
        break;
    /* TO DO : seperate 3aa & isp pipe
    case PIPE_3AA:
    case PIPE_3AA_ISP:
        m_autofocusMgr->execFunction(ExynosCameraActivityBase::CALLBACK_TYPE_ISP_AFTER, args);
        m_flashMgr->execFunction(ExynosCameraActivityBase::CALLBACK_TYPE_ISP_AFTER, args);
        m_specialCaptureMgr->execFunction(ExynosCameraActivityBase::CALLBACK_TYPE_ISP_AFTER, args);
        break;
    */
    case PIPE_ISPC:
    case PIPE_SCC:
        m_autofocusMgr->execFunction(ExynosCameraActivityBase::CALLBACK_TYPE_SCC_AFTER, args);
        m_flashMgr->execFunction(ExynosCameraActivityBase::CALLBACK_TYPE_SCC_AFTER, args);
        m_specialCaptureMgr->execFunction(ExynosCameraActivityBase::CALLBACK_TYPE_SCC_AFTER, args);
        m_uctlMgr->execFunction(ExynosCameraActivityBase::CALLBACK_TYPE_SCC_AFTER, args);
        break;
    case PIPE_SCP:
        m_autofocusMgr->execFunction(ExynosCameraActivityBase::CALLBACK_TYPE_SCP_AFTER, args);
        m_flashMgr->execFunction(ExynosCameraActivityBase::CALLBACK_TYPE_SCP_AFTER, args);
        m_specialCaptureMgr->execFunction(ExynosCameraActivityBase::CALLBACK_TYPE_SCP_AFTER, args);
        m_uctlMgr->execFunction(ExynosCameraActivityBase::CALLBACK_TYPE_SCP_AFTER, args);
        break;
    default:
        break;
    }
}

ExynosCameraActivityFlash *ExynosCameraActivityControl::getFlashMgr(void)
{
    return m_flashMgr;
}

ExynosCameraActivitySpecialCapture *ExynosCameraActivityControl::getSpecialCaptureMgr(void)
{
    return m_specialCaptureMgr;
}

ExynosCameraActivityAutofocus*ExynosCameraActivityControl::getAutoFocusMgr(void)
{
    return m_autofocusMgr;
}

ExynosCameraActivityUCTL*ExynosCameraActivityControl::getUCTLMgr(void)
{
    return m_uctlMgr;
}

void ExynosCameraActivityControl::setFpsValue(int fpsValue)
{
    m_fpsValue = fpsValue;

    m_autofocusMgr->setFpsValue(m_fpsValue);
    m_flashMgr->setFpsValue(m_fpsValue);

    ALOGI("INFO(%s[%d]): m_fpsValue(%d)", __FUNCTION__, __LINE__, m_fpsValue);
}

int ExynosCameraActivityControl::getFpsValue()
{
    return m_fpsValue;
}

void ExynosCameraActivityControl::setHalVersion(int halVersion)
{
    m_halVersion = halVersion;
    ALOGI("INFO(%s[%d]): m_halVersion(%d)", __FUNCTION__, __LINE__, m_halVersion);

    return;
}
}; /* namespace android */

