Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6dcc706b authored by Chien-Yu Chen's avatar Chien-Yu Chen
Browse files

Camera: Disconnect camera after checking flash unit

Disconnect camera device after opening it just to check if
it has a flash unit. Leave it open if torch is being turned on.

Bug: 28170202

Change-Id: Ic4a70a1b4be28625449ed52cbf6c5d214089adb7
parent e8c535e8
Loading
Loading
Loading
Loading
+22 −3
Original line number Diff line number Diff line
@@ -679,7 +679,8 @@ status_t CameraHardwareInterfaceFlashControl::setTorchMode(
    status_t res;
    if (enabled) {
        bool hasFlash = false;
        res = hasFlashUnitLocked(cameraId, &hasFlash);
        // Check if it has a flash unit and leave camera device open.
        res = hasFlashUnitLocked(cameraId, &hasFlash, /*keepDeviceOpen*/true);
        // invalid camera?
        if (res) {
            // hasFlashUnitLocked() returns BAD_INDEX if mDevice is connected to
@@ -688,6 +689,8 @@ status_t CameraHardwareInterfaceFlashControl::setTorchMode(
        }
        // no flash unit?
        if (!hasFlash) {
            // Disconnect camera device if it has no flash.
            disconnectCameraDevice();
            return -ENOSYS;
        }
    } else if (mDevice == NULL || cameraId != mCameraId) {
@@ -716,21 +719,28 @@ status_t CameraHardwareInterfaceFlashControl::setTorchMode(
status_t CameraHardwareInterfaceFlashControl::hasFlashUnit(
        const String8& cameraId, bool *hasFlash) {
    Mutex::Autolock l(mLock);
    return hasFlashUnitLocked(cameraId, hasFlash);
    // Close device after checking if it has a flash unit.
    return hasFlashUnitLocked(cameraId, hasFlash, /*keepDeviceOpen*/false);
}

status_t CameraHardwareInterfaceFlashControl::hasFlashUnitLocked(
        const String8& cameraId, bool *hasFlash) {
        const String8& cameraId, bool *hasFlash, bool keepDeviceOpen) {
    bool closeCameraDevice = false;

    if (!hasFlash) {
        return BAD_VALUE;
    }

    status_t res;
    if (mDevice == NULL) {
        // Connect to camera device to query if it has a flash unit.
        res = connectCameraDevice(cameraId);
        if (res) {
            return res;
        }
        // Close camera device only when it is just opened and the caller doesn't want to keep
        // the camera device open.
        closeCameraDevice = !keepDeviceOpen;
    }

    if (cameraId != mCameraId) {
@@ -745,6 +755,15 @@ status_t CameraHardwareInterfaceFlashControl::hasFlashUnitLocked(
        *hasFlash = false;
    }

    if (closeCameraDevice) {
        res = disconnectCameraDevice();
        if (res != OK) {
            ALOGE("%s: Failed to disconnect camera device. %s (%d)", __FUNCTION__,
                    strerror(-res), res);
            return res;
        }
    }

    return OK;
}

+5 −1
Original line number Diff line number Diff line
@@ -203,7 +203,11 @@ class CameraHardwareInterfaceFlashControl : public FlashControlBase {
        status_t getSmallestSurfaceSize(int32_t *width, int32_t *height);

        // protected by mLock
        status_t hasFlashUnitLocked(const String8& cameraId, bool *hasFlash);
        // If this function opens camera device in order to check if it has a flash unit, the
        // camera device will remain open if keepDeviceOpen is true and the camera device will be
        // closed if keepDeviceOpen is false. If camera device is already open when calling this
        // function, keepDeviceOpen is ignored.
        status_t hasFlashUnitLocked(const String8& cameraId, bool *hasFlash, bool keepDeviceOpen);

        CameraModule *mCameraModule;
        const camera_module_callbacks_t *mCallbacks;