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

Commit ac9637d2 authored by Jyoti Bhayana's avatar Jyoti Bhayana
Browse files

Fix the race condition around onIdle callback

Flag: com.android.internal.camera.flags.camera_multi_client
Bug: 392933426
Test: Run CTS test SharedCameraTest
Change-Id: I02be4602206813fbae87e8b4032b3c20de55ab00
parent d832a53f
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -2676,6 +2676,7 @@ void CameraDeviceClient::onResultAvailable(const CaptureResult& result) {
}

void CameraDeviceClient::markClientActive() {
    Mutex::Autolock l(mDevice->mSharedDeviceActiveLock);
    if (mDeviceActive) {
        // Already in active state.
        return;
@@ -2689,6 +2690,7 @@ void CameraDeviceClient::markClientActive() {
}

void CameraDeviceClient::markClientIdle() {
    Mutex::Autolock l(mDevice->mSharedDeviceActiveLock);
    if (!mDeviceActive) {
        // Already in idle state.
        return;
+3 −0
Original line number Diff line number Diff line
@@ -594,6 +594,9 @@ class CameraDeviceBase : public virtual FrameProducer {
    virtual status_t injectSessionParams(
        const CameraMetadata& sessionParams) = 0;

    // Lock to synchronize onDeviceActive and onDeviceIdle callbacks when camera
    // has been opened in shared mode.
    mutable Mutex mSharedDeviceActiveLock;
protected:
    bool mImageDumpMask = 0;
    std::vector<int64_t> mStreamUseCaseOverrides;
+2 −0
Original line number Diff line number Diff line
@@ -591,6 +591,7 @@ void AidlCamera3SharedDevice::notifyError(
}

status_t AidlCamera3SharedDevice::notifyActive(float maxPreviewFps) {
    Mutex::Autolock l(mSharedDeviceActiveLock);
    for (auto activeClient : mClientRequestIds) {
        sp<NotificationListener> listener =  mClientListeners[activeClient.first].promote();
        if (listener != NULL) {
@@ -605,6 +606,7 @@ void AidlCamera3SharedDevice::notifyIdle(int64_t requestCount, int64_t resultEr
                                     bool deviceError,
                                     std::pair<int32_t, int32_t> mostRequestedFpsRange,
                                     const std::vector<hardware::CameraStreamStats>& stats) {
    Mutex::Autolock l(mSharedDeviceActiveLock);
    for (auto clientListener : mClientListeners) {
        sp<NotificationListener> listener =  clientListener.second.promote();
        if (listener != NULL) {