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

Commit 07d3bfcf authored by Avichal Rakesh's avatar Avichal Rakesh
Browse files

libcameraservice: Reduce unnecessary nesting.

This CL simply re-formats some of the logic to return early instead
of nesting code in large if blocks. There is no functional change
from this CL.

Bug: 319735068
Test: n/a. No functional change.
Change-Id: I217f503fe86fba7886c2eb9d403a804471149bb2
parent 53388990
Loading
Loading
Loading
Loading
+40 −37
Original line number Diff line number Diff line
@@ -275,22 +275,29 @@ const std::shared_ptr<ICameraProvider> AidlProviderInfo::startProviderInterface(
    if (mSavedInterface != nullptr) {
        return mSavedInterface;
    }

    if (!kEnableLazyHal) {
        ALOGE("Bad provider state! Should not be here on a non-lazy HAL!");
        return nullptr;
    }

    auto interface = mActiveInterface.lock();
    if (interface == nullptr) {
    if (interface != nullptr) {
        ALOGV("Camera provider (%s) already in use. Re-using instance.", mProviderName.c_str());
        return interface;
    }

    // Try to get service without starting
        interface =
                    ICameraProvider::fromBinder(
    interface = ICameraProvider::fromBinder(
            ndk::SpAIBinder(AServiceManager_checkService(mProviderName.c_str())));
        if (interface == nullptr) {
            ALOGV("Camera provider actually needs restart, calling getService(%s)",
                  mProviderName.c_str());
            interface = mManager->mAidlServiceProxy->getAidlService(mProviderName.c_str());
    if (interface != nullptr) {
        // Service is already running. Cache and return.
        mActiveInterface = interface;
        return interface;
    }

    ALOGV("Camera provider actually needs restart, calling getService(%s)", mProviderName.c_str());
    interface = mManager->mAidlServiceProxy->getAidlService(mProviderName.c_str());
    if (interface == nullptr) {
        ALOGD("%s: %s service not started", __FUNCTION__, mProviderName.c_str());
        return nullptr;
@@ -316,12 +323,8 @@ const std::shared_ptr<ICameraProvider> AidlProviderInfo::startProviderInterface(

    // Send current device state
    interface->notifyDeviceStateChange(mDeviceState);
        }
    // Cache interface to return early for future calls.
    mActiveInterface = interface;
    } else {
        ALOGV("Camera provider (%s) already in use. Re-using instance.",
              mProviderName.c_str());
    }

    return interface;
}