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

Commit 56f949b4 authored by Chien-Yu Chen's avatar Chien-Yu Chen Committed by Android (Google) Code Review
Browse files

Merge changes I4588e7da,Ic4a70a1b into nyc-dev

* changes:
  Fix Emulator CTS tests for Camera, Location, Sensors, Telephony
  Camera: Disconnect camera after checking flash unit
parents 35443e32 3d1c478f
Loading
Loading
Loading
Loading
+29 −6
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;
}

@@ -869,9 +888,13 @@ status_t CameraHardwareInterfaceFlashControl::disconnectCameraDevice() {
        return OK;
    }

    if (mParameters.get(CameraParameters::KEY_FLASH_MODE)) {
        // There is a flash, turn if off.
        // (If there isn't one, leave the parameter null)
        mParameters.set(CameraParameters::KEY_FLASH_MODE,
                CameraParameters::FLASH_MODE_OFF);
        mDevice->setParameters(mParameters);
    }
    mDevice->stopPreview();
    status_t res = native_window_api_disconnect(mSurface.get(),
            NATIVE_WINDOW_API_CAMERA);
+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;