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

Commit b38b53fb authored by Shuzhen Wang's avatar Shuzhen Wang
Browse files

Camera: Fix race condition for filterSPerfClassCharacteristics

1. enumerateProviders may be called from different threads: from
  cameraserver startup, and from the provider's onRegistration.
  When enumerateProviders calls filterSPerfClassCharacteristics,
  mServiceLock needs to be held.
2. onRegistration can be called with preexisting set to TRUE. In that
  case, do not call onNewProviderRegistered() to avoid unnecessary
  enumerateProviders.

Test: vendor testing, camera CTS
Bug: 193796282
Change-Id: I596a047cb36a9926014de232a6639a32da4f214c
parent 2a3ca76a
Loading
Loading
Loading
Loading
+10 −4
Original line number Diff line number Diff line
@@ -240,7 +240,13 @@ status_t CameraService::enumerateProviders() {
    // Derive primary rear/front cameras, and filter their charactierstics.
    // This needs to be done after all cameras are enumerated and camera ids are sorted.
    if (SessionConfigurationUtils::IS_PERF_CLASS) {
        filterSPerfClassCharacteristics();
        // Assume internal cameras are advertised from the same
        // provider. If multiple providers are registered at different time,
        // and each provider contains multiple internal color cameras, the current
        // logic may filter the characteristics of more than one front/rear color
        // cameras.
        Mutex::Autolock l(mServiceLock);
        filterSPerfClassCharacteristicsLocked();
    }

    return OK;
@@ -313,7 +319,7 @@ void CameraService::updateCameraNumAndIds() {
    filterAPI1SystemCameraLocked(mNormalDeviceIds);
}

void CameraService::filterSPerfClassCharacteristics() {
void CameraService::filterSPerfClassCharacteristicsLocked() {
    // To claim to be S Performance primary cameras, the cameras must be
    // backward compatible. So performance class primary camera Ids must be API1
    // compatible.
+3 −2
Original line number Diff line number Diff line
@@ -945,9 +945,10 @@ private:
    void updateCameraNumAndIds();

    /**
     * Filter camera characteristics for S Performance class primary cameras
     * Filter camera characteristics for S Performance class primary cameras.
     * mServiceLock should be locked.
     */
    void filterSPerfClassCharacteristics();
    void filterSPerfClassCharacteristicsLocked();

    // File descriptor to temp file used for caching previous open
    // session dumpsys info.
+3 −2
Original line number Diff line number Diff line
@@ -476,15 +476,16 @@ hardware::Return<void> CameraProviderManager::onRegistration(
        const hardware::hidl_string& /*fqName*/,
        const hardware::hidl_string& name,
        bool preexisting) {
    status_t res = OK;
    std::lock_guard<std::mutex> providerLock(mProviderLifecycleLock);
    {
        std::lock_guard<std::mutex> lock(mInterfaceMutex);

        addProviderLocked(name, preexisting);
        res = addProviderLocked(name, preexisting);
    }

    sp<StatusListener> listener = getStatusListener();
    if (nullptr != listener.get()) {
    if (nullptr != listener.get() && res == OK) {
        listener->onNewProviderRegistered();
    }