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

Commit e2385b0f authored by Avichal Rakesh's avatar Avichal Rakesh Committed by Android (Google) Code Review
Browse files

Merge changes from topics "calculate_pref_override_during_session_support",...

Merge changes from topics "calculate_pref_override_during_session_support", "check_session_support_before_session_char" into main

* changes:
  cameraservice: check performance class override in isSessionConfigurationWithParametersSupported
  cameraservice: Check for session support before getting session characteristics
parents 011618d2 caf179b3
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -383,6 +383,7 @@ interface ICameraService
     * has camera device support.
     *
     * @param cameraId The camera id to query session configuration for
     * @param targetSdkVersion the target sdk level of the application calling this function.
     * @param sessionConfiguration Specific session configuration to be verified.
     * @param deviceId The device id of the context associated with the caller.
     * @param devicePolicy The camera policy of the device of the associated context (default
@@ -393,13 +394,17 @@ interface ICameraService
     *         false - in case there is no device support.
     */
    boolean isSessionConfigurationWithParametersSupported(@utf8InCpp String cameraId,
            in SessionConfiguration sessionConfiguration, int deviceId, int devicePolicy);
            int targetSdkVersion, in SessionConfiguration sessionConfiguration,
            int deviceId, int devicePolicy);

    /**
     * Get the camera characteristics for a particular session configuration for
     * the given camera device.
     *
     * @param cameraId ID of the device for which the session characteristics must be fetched.
     * @param targetSdkVersion the target sdk level of the application calling this function.
     * @param overrideToPortrait Whether to override the sensor orientation information to
     *                           correspond to portrait.
     * @param sessionConfiguration Session configuration for which the characteristics
     *                             must be fetched.
     * @param deviceId The device id of the context associated with the caller.
+20 −0
Original line number Diff line number Diff line
@@ -190,3 +190,23 @@ flag {
       purpose: PURPOSE_BUGFIX
     }
}

flag {
     namespace: "camera_platform"
     name: "check_session_support_before_session_char"
     description: "Validate that a SessionConfiguration is supported before fetching SessionCharacteristics."
     bug: "327008530"
     metadata {
       purpose: PURPOSE_BUGFIX
     }
}

flag {
     namespace: "camera_platform"
     name: "calculate_perf_override_during_session_support"
     description: "Dynamically calulate whether perf class override should be set in isSessionConfigurationWithParametersSupported."
     bug: "332975108"
     metadata {
       purpose: PURPOSE_BUGFIX
     }
}
+60 −20
Original line number Diff line number Diff line
@@ -915,11 +915,10 @@ Status CameraService::createDefaultRequest(const std::string& unresolvedCameraId
}

Status CameraService::isSessionConfigurationWithParametersSupported(
        const std::string& unresolvedCameraId,
        const std::string& unresolvedCameraId, int targetSdkVersion,
        const SessionConfiguration& sessionConfiguration,
        int32_t deviceId, int32_t devicePolicy,
        /*out*/
        bool* supported) {
        /*out*/ bool* supported) {
    ATRACE_CALL();

    if (!flags::feature_combination_query()) {
@@ -955,34 +954,57 @@ Status CameraService::isSessionConfigurationWithParametersSupported(
                cameraId.c_str());
    }

    bool overrideForPerfClass = flags::calculate_perf_override_during_session_support() &&
                                SessionConfigurationUtils::targetPerfClassPrimaryCamera(
                                        mPerfClassPrimaryCameraIds, cameraId, targetSdkVersion);

    return isSessionConfigurationWithParametersSupportedUnsafe(cameraId, sessionConfiguration,
                                                               overrideForPerfClass, supported);
}

Status CameraService::isSessionConfigurationWithParametersSupportedUnsafe(
        const std::string& cameraId, const SessionConfiguration& sessionConfiguration,
        bool overrideForPerfClass, /*out*/ bool* supported) {
    *supported = false;
    status_t ret = mCameraProviderManager->isSessionConfigurationSupported(cameraId.c_str(),
            sessionConfiguration, /*mOverrideForPerfClass*/false, /*checkSessionParams*/true,
            supported);
    status_t ret = mCameraProviderManager->isSessionConfigurationSupported(
            cameraId, sessionConfiguration, overrideForPerfClass,
            /*checkSessionParams=*/true, supported);
    binder::Status res;
    switch (ret) {
        case OK:
            // Expected, do nothing.
            break;
            // Expected. Do Nothing.
            return Status::ok();
        case INVALID_OPERATION: {
                std::string msg = fmt::sprintf(
                        "Camera %s: Session configuration query not supported!",
                        "Camera %s: Session configuration with parameters supported query not "
                        "supported!",
                        cameraId.c_str());
                ALOGD("%s: %s", __FUNCTION__, msg.c_str());
                res = STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.c_str());
                ALOGW("%s: %s", __FUNCTION__, msg.c_str());
                logServiceError(msg, CameraService::ERROR_INVALID_OPERATION);
                *supported = false;
                return STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.c_str());
            }
            break;
        case NAME_NOT_FOUND: {
                std::string msg = fmt::sprintf("Camera %s: Unknown camera ID.", cameraId.c_str());
                ALOGW("%s: %s", __FUNCTION__, msg.c_str());
                logServiceError(msg, CameraService::ERROR_ILLEGAL_ARGUMENT);
                *supported = false;
                return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
            }

            break;
        default: {
                std::string msg = fmt::sprintf( "Camera %s: Error: %s (%d)", cameraId.c_str(),
                        strerror(-ret), ret);
                std::string msg = fmt::sprintf(
                        "Unable to retrieve session configuration support for camera "
                        "device %s: Error: %s (%d)",
                        cameraId.c_str(), strerror(-ret), ret);
                ALOGE("%s: %s", __FUNCTION__, msg.c_str());
                res = STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
                        msg.c_str());
                logServiceError(msg, CameraService::ERROR_ILLEGAL_ARGUMENT);
                *supported = false;
                return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
            }
            break;
    }

    return res;
}

Status CameraService::getSessionCharacteristics(const std::string& unresolvedCameraId,
@@ -1023,6 +1045,24 @@ Status CameraService::getSessionCharacteristics(const std::string& unresolvedCam

    bool overrideForPerfClass = SessionConfigurationUtils::targetPerfClassPrimaryCamera(
            mPerfClassPrimaryCameraIds, cameraId, targetSdkVersion);
    if (flags::check_session_support_before_session_char()) {
        bool sessionConfigSupported;
        Status res = isSessionConfigurationWithParametersSupportedUnsafe(
                cameraId, sessionConfiguration, overrideForPerfClass, &sessionConfigSupported);
        if (!res.isOk()) {
            // isSessionConfigurationWithParametersSupportedUnsafe should log what went wrong and
            // report the correct Status to send to the client. Simply forward the error to
            // the client.
            outMetadata->clear();
            return res;
        }
        if (!sessionConfigSupported) {
            std::string msg = fmt::sprintf(
                    "Session configuration not supported for camera device %s.", cameraId.c_str());
            outMetadata->clear();
            return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
        }
    }

    status_t ret = mCameraProviderManager->getSessionCharacteristics(
            cameraId, sessionConfiguration, overrideForPerfClass, overrideToPortrait, outMetadata);
@@ -1035,7 +1075,7 @@ Status CameraService::getSessionCharacteristics(const std::string& unresolvedCam
                std::string msg = fmt::sprintf(
                        "Camera %s: Session characteristics query not supported!",
                        cameraId.c_str());
                ALOGD("%s: %s", __FUNCTION__, msg.c_str());
                ALOGW("%s: %s", __FUNCTION__, msg.c_str());
                logServiceError(msg, CameraService::ERROR_INVALID_OPERATION);
                outMetadata->clear();
                return STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.c_str());
@@ -1045,7 +1085,7 @@ Status CameraService::getSessionCharacteristics(const std::string& unresolvedCam
                std::string msg = fmt::sprintf(
                        "Camera %s: Unknown camera ID.",
                        cameraId.c_str());
                ALOGD("%s: %s", __FUNCTION__, msg.c_str());
                ALOGW("%s: %s", __FUNCTION__, msg.c_str());
                logServiceError(msg, CameraService::ERROR_ILLEGAL_ARGUMENT);
                outMetadata->clear();
                return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.c_str());
+6 −3
Original line number Diff line number Diff line
@@ -256,11 +256,10 @@ public:
            hardware::camera2::impl::CameraMetadataNative* request);

    virtual binder::Status isSessionConfigurationWithParametersSupported(
            const std::string& cameraId,
            const std::string& cameraId, int targetSdkVersion,
            const SessionConfiguration& sessionConfiguration,
            int32_t deviceId, int32_t devicePolicy,
            /*out*/
            bool* supported);
            /*out*/ bool* supported);

    virtual binder::Status getSessionCharacteristics(
            const std::string& cameraId, int targetSdkVersion, bool overrideToPortrait,
@@ -1031,6 +1030,10 @@ private:
    // Adds client logs during closed session to the file pointed by fd.
    void dumpClosedSessionClientLogs(int fd, const std::string& cameraId);

    binder::Status isSessionConfigurationWithParametersSupportedUnsafe(
            const std::string& cameraId, const SessionConfiguration& sessionConfiguration,
            bool overrideForPerfClass, /*out*/ bool* supported);

    // Mapping from camera ID -> state for each device, map is protected by mCameraStatesLock
    std::map<std::string, std::shared_ptr<CameraState>> mCameraStates;