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

Commit 38284526 authored by Rucha Katakwar's avatar Rucha Katakwar
Browse files

Camera: Add support for torch strength control.

This change consists of support to control flashunit brightness level
and getting the current brightness level for the flash unit associated
with camera device.

Test: Flashlight CTS
Bug: 200174275
Change-Id: I7f0b4c826e6ccef157ec22a3b3b8cf75a6b2152d
parent 0cbec133
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -173,6 +173,13 @@ interface ICameraService

    void setTorchMode(String cameraId, boolean enabled, IBinder clientBinder);

    // Change the brightness level of the flash unit associated with cameraId to strengthLevel.
    // If the torch is in OFF state and strengthLevel > 0 then the torch will also be turned ON.
    void turnOnTorchWithStrengthLevel(String cameraId, int strengthLevel, IBinder clientBinder);

    // Get the brightness level of the flash unit associated with cameraId.
    int getTorchStrengthLevel(String cameraId);

    /**
     * Notify the camera service of a system event.  Should only be called from system_server.
     *
+2 −0
Original line number Diff line number Diff line
@@ -83,6 +83,8 @@ interface ICameraServiceListener

    oneway void onTorchStatusChanged(int status, String cameraId);

    oneway void onTorchStrengthLevelChanged(String cameraId, int newTorchStrength);

    /**
     * Notify registered clients about camera access priority changes.
     * Clients which were previously unable to open a certain camera device
+3 −0
Original line number Diff line number Diff line
@@ -95,6 +95,9 @@ class CameraManagerGlobal final : public RefBase {
        virtual binder::Status onTorchStatusChanged(int32_t, const String16&) {
            return binder::Status::ok();
        }
        virtual binder::Status onTorchStrengthLevelChanged(const String16&, int32_t) {
            return binder::Status::ok();
        }

        virtual binder::Status onCameraAccessPrioritiesChanged();
        virtual binder::Status onCameraOpened(const String16&, const String16&) {
+6 −0
Original line number Diff line number Diff line
@@ -96,6 +96,12 @@ public:
        return binder::Status::ok();
    };

    virtual binder::Status onTorchStrengthLevelChanged(const String16& /*cameraId*/,
            int32_t /*torchStrength*/) {
        // No op
        return binder::Status::ok();
    }

    virtual binder::Status onCameraAccessPrioritiesChanged() {
        // No op
        return binder::Status::ok();
+69 −0
Original line number Diff line number Diff line
@@ -119,6 +119,59 @@ status_t CameraFlashlight::setTorchMode(const String8& cameraId, bool enabled) {
    return res;
}

status_t CameraFlashlight::turnOnTorchWithStrengthLevel(const String8& cameraId,
            int32_t torchStrength) {
    if (!mFlashlightMapInitialized) {
        ALOGE("%s: findFlashUnits() must be called before this method.",
               __FUNCTION__);
        return NO_INIT;
    }

    ALOGV("%s: set torch strength of camera %s to %d", __FUNCTION__,
            cameraId.string(), torchStrength);
    status_t res = OK;
    Mutex::Autolock l(mLock);

    if (mOpenedCameraIds.indexOf(cameraId) != NAME_NOT_FOUND) {
        ALOGE("%s: Camera device %s is in use, cannot be turned ON.",
                __FUNCTION__, cameraId.string());
        return -EBUSY;
    }

    if (mFlashControl == NULL) {
        res = createFlashlightControl(cameraId);
        if (res) {
            return res;
        }
    }

    res = mFlashControl->turnOnTorchWithStrengthLevel(cameraId, torchStrength);
    return res;
}


status_t CameraFlashlight::getTorchStrengthLevel(const String8& cameraId,
            int32_t* torchStrength) {
    status_t res = OK;
    if (!mFlashlightMapInitialized) {
        ALOGE("%s: findFlashUnits() must be called before this method.",
            __FUNCTION__);
        return false;
    }

    Mutex::Autolock l(mLock);

    if (mFlashControl == NULL) {
        res = createFlashlightControl(cameraId);
        if (res) {
            return res;
        }
    }

    res = mFlashControl->getTorchStrengthLevel(cameraId, torchStrength);
    return res;
}

status_t CameraFlashlight::findFlashUnits() {
    Mutex::Autolock l(mLock);
    status_t res;
@@ -306,6 +359,22 @@ status_t ProviderFlashControl::setTorchMode(const String8& cameraId, bool enable

    return mProviderManager->setTorchMode(cameraId.string(), enabled);
}

status_t ProviderFlashControl::turnOnTorchWithStrengthLevel(const String8& cameraId,
            int32_t torchStrength) {
    ALOGV("%s: change torch strength level of camera %s to %d", __FUNCTION__,
            cameraId.string(), torchStrength);

    return mProviderManager->turnOnTorchWithStrengthLevel(cameraId.string(), torchStrength);
}

status_t ProviderFlashControl::getTorchStrengthLevel(const String8& cameraId,
            int32_t* torchStrength) {
    ALOGV("%s: get torch strength level of camera %s", __FUNCTION__,
            cameraId.string());

    return mProviderManager->getTorchStrengthLevel(cameraId.string(), torchStrength);
}
// ProviderFlashControl implementation ends

}
Loading