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

Commit 18b30a7e authored by Austin Borger's avatar Austin Borger
Browse files

libcameraservice: Provide flag for overriding camera output to portrait.

Apps commonly do not handle landscape orientation cameras correctly. In
order to prevent stretching and rotation issues in these apps, this
patch adds a flag to override the behavior of these landscape cameras
to produce a portrait image instead by changing the SENSOR_ORIENTATION
reported by CameraCharacteristics and applying a 90 degree rotate and
crop.

Bug: 250678880
Test: Ran on foldable device with several camera apps to verify behavior.
Merged-In: I64ed52812326edc11f1cdb6bfbdbe75fcb8b1fb8
Change-Id: Iea30befecf297cc5c6ab4af2424027e995190fed
parent f521e485
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -93,6 +93,7 @@ cc_library {
        "libgui",
        "libcamera_metadata",
        "libnativewindow",
        "lib-platform-compat-native-api",
    ],

    include_dirs: [
+2 −2
Original line number Diff line number Diff line
@@ -71,10 +71,10 @@ Camera::~Camera()
}

sp<Camera> Camera::connect(int cameraId, const String16& clientPackageName,
        int clientUid, int clientPid, int targetSdkVersion)
        int clientUid, int clientPid, int targetSdkVersion, bool overrideToPortrait)
{
    return CameraBaseT::connect(cameraId, clientPackageName, clientUid,
            clientPid, targetSdkVersion);
            clientPid, targetSdkVersion, overrideToPortrait);
}

status_t Camera::reconnect()
+7 −3
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@
#include <cutils/properties.h>

#include <android/hardware/ICameraService.h>
#include <com/android/internal/compat/IPlatformCompatNative.h>

#include <binder/IPCThreadState.h>
#include <binder/IServiceManager.h>
@@ -161,7 +162,8 @@ const sp<::android::hardware::ICameraService> CameraBase<TCam, TCamTraits>::getC
template <typename TCam, typename TCamTraits>
sp<TCam> CameraBase<TCam, TCamTraits>::connect(int cameraId,
                                               const String16& clientPackageName,
                                               int clientUid, int clientPid, int targetSdkVersion)
                                               int clientUid, int clientPid, int targetSdkVersion,
                                               bool overrideToPortrait)
{
    ALOGV("%s: connect", __FUNCTION__);
    sp<TCam> c = new TCam(cameraId);
@@ -171,8 +173,9 @@ sp<TCam> CameraBase<TCam, TCamTraits>::connect(int cameraId,
    binder::Status ret;
    if (cs != nullptr) {
        TCamConnectService fnConnectService = TCamTraits::fnConnectService;
        ALOGI("Connect camera (legacy API) - overrideToPortrait %d", overrideToPortrait);
        ret = (cs.get()->*fnConnectService)(cl, cameraId, clientPackageName, clientUid,
                                               clientPid, targetSdkVersion, /*out*/ &c->mCamera);
                clientPid, targetSdkVersion, overrideToPortrait, /*out*/ &c->mCamera);
    }
    if (ret.isOk() && c->mCamera != nullptr) {
        IInterface::asBinder(c->mCamera)->linkToDeath(c);
@@ -273,10 +276,11 @@ int CameraBase<TCam, TCamTraits>::getNumberOfCameras() {
// this can be in BaseCamera but it should be an instance method
template <typename TCam, typename TCamTraits>
status_t CameraBase<TCam, TCamTraits>::getCameraInfo(int cameraId,
        bool overrideToPortrait,
        struct hardware::CameraInfo* cameraInfo) {
    const sp<::android::hardware::ICameraService> cs = getCameraService();
    if (cs == 0) return UNKNOWN_ERROR;
    binder::Status res = cs->getCameraInfo(cameraId, cameraInfo);
    binder::Status res = cs->getCameraInfo(cameraId, overrideToPortrait, cameraInfo);
    return res.isOk() ? OK : res.serviceSpecificErrorCode();
}

+7 −4
Original line number Diff line number Diff line
@@ -67,7 +67,7 @@ interface ICameraService
    /**
     * Fetch basic camera information for a camera device
     */
    CameraInfo getCameraInfo(int cameraId);
    CameraInfo getCameraInfo(int cameraId, boolean overrideToPortrait);

    /**
     * Default UID/PID values for non-privileged callers of
@@ -83,7 +83,8 @@ interface ICameraService
            int cameraId,
            String opPackageName,
            int clientUid, int clientPid,
            int targetSdkVersion);
            int targetSdkVersion,
            boolean overrideToPortrait);

    /**
     * Open a camera device through the new camera API
@@ -94,7 +95,8 @@ interface ICameraService
            String opPackageName,
            @nullable String featureId,
            int clientUid, int oomScoreOffset,
            int targetSdkVersion);
            int targetSdkVersion,
            boolean overrideToPortrait);

    /**
     * Add listener for changes to camera device and flashlight state.
@@ -135,7 +137,8 @@ interface ICameraService
     * Read the static camera metadata for a camera device.
     * Only supported for device HAL versions >= 3.2
     */
    CameraMetadataNative getCameraCharacteristics(String cameraId, int targetSdkVersion);
    CameraMetadataNative getCameraCharacteristics(String cameraId, int targetSdkVersion,
            boolean overrideToPortrait);

    /**
     * Read in the vendor tag descriptors from the camera module HAL.
+3 −2
Original line number Diff line number Diff line
@@ -58,7 +58,7 @@ struct CameraTraits<Camera>
    typedef ::android::hardware::ICameraClient TCamCallbacks;
    typedef ::android::binder::Status(::android::hardware::ICameraService::*TCamConnectService)
        (const sp<::android::hardware::ICameraClient>&,
        int, const String16&, int, int, int,
        int, const String16&, int, int, int, bool,
        /*out*/
        sp<::android::hardware::ICamera>*);
    static TCamConnectService     fnConnectService;
@@ -81,7 +81,8 @@ public:
    static  sp<Camera>  create(const sp<::android::hardware::ICamera>& camera);
    static  sp<Camera>  connect(int cameraId,
                                const String16& clientPackageName,
                                int clientUid, int clientPid, int targetSdkVersion);
                                int clientUid, int clientPid, int targetSdkVersion,
                                bool overrideToPortrait);

            virtual     ~Camera();

Loading