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

Commit a7552662 authored by Yin-Chia Yeh's avatar Yin-Chia Yeh Committed by android-build-merger
Browse files

Merge "CameraService: Update camera and torch state lists also at runtime" am: 900596ac

am: 5eeb6b1e

Change-Id: Ie7decb502cbe7b0e6ac0f4aa5d8b82615d32de34
parents 3ede3626 5eeb6b1e
Loading
Loading
Loading
Loading
+37 −23
Original line number Diff line number Diff line
@@ -243,29 +243,10 @@ status_t CameraService::enumerateProviders() {
        }

        if (!cameraFound) {
            hardware::camera::common::V1_0::CameraResourceCost cost;
            res = mCameraProviderManager->getResourceCost(cameraId, &cost);
            if (res != OK) {
                ALOGE("Failed to query device resource cost: %s (%d)", strerror(-res), res);
                continue;
            }
            std::set<String8> conflicting;
            for (size_t i = 0; i < cost.conflictingDevices.size(); i++) {
                conflicting.emplace(String8(cost.conflictingDevices[i].c_str()));
            }

            {
                Mutex::Autolock lock(mCameraStatesLock);
                mCameraStates.emplace(id8,
                    std::make_shared<CameraState>(id8, cost.resourceCost, conflicting));
            }
            addStates(id8);
        }

        onDeviceStatusChanged(id8, CameraDeviceStatus::PRESENT);

        if (mFlashlight->hasFlashUnit(id8)) {
            mTorchStatusMap.add(id8, TorchModeStatus::AVAILABLE_OFF);
        }
    }

    return OK;
@@ -300,6 +281,31 @@ void CameraService::onNewProviderRegistered() {
    enumerateProviders();
}

void CameraService::addStates(const String8 id) {
    std::string cameraId(id.c_str());
    hardware::camera::common::V1_0::CameraResourceCost cost;
    status_t res = mCameraProviderManager->getResourceCost(cameraId, &cost);
    if (res != OK) {
        ALOGE("Failed to query device resource cost: %s (%d)", strerror(-res), res);
        return;
    }
    std::set<String8> conflicting;
    for (size_t i = 0; i < cost.conflictingDevices.size(); i++) {
        conflicting.emplace(String8(cost.conflictingDevices[i].c_str()));
    }

    {
        Mutex::Autolock lock(mCameraStatesLock);
        mCameraStates.emplace(id, std::make_shared<CameraState>(id, cost.resourceCost,
                                                                conflicting));
    }

    if (mFlashlight->hasFlashUnit(id)) {
        mTorchStatusMap.add(id, TorchModeStatus::AVAILABLE_OFF);
    }
    logDeviceAdded(id, "Device added");
}

void CameraService::onDeviceStatusChanged(const String8& id,
        CameraDeviceStatus newHalStatus) {
    ALOGI("%s: Status changed for cameraId=%s, newStatus=%d", __FUNCTION__,
@@ -311,8 +317,13 @@ void CameraService::onDeviceStatusChanged(const String8& id,

    if (state == nullptr) {
        if (newStatus == StatusInternal::PRESENT) {
            ALOGW("%s: Unknown camera ID %s, probably newly registered?",
            ALOGI("%s: Unknown camera ID %s, a new camera is added",
                    __FUNCTION__, id.string());

            // First add as absent to make sure clients are notified below
            addStates(id);

            updateStatus(newStatus, id);
        } else {
            ALOGE("%s: Bad camera ID %s", __FUNCTION__, id.string());
        }
@@ -2229,8 +2240,11 @@ status_t CameraService::BasicClient::finishCameraOps() {
                mClientPackageName);
        mOpsActive = false;

        // This function is called when a client disconnects. This should
        // release the camera, but actually only if it was in a proper
        // functional state, i.e. with status NOT_AVAILABLE
        std::initializer_list<StatusInternal> rejected = {StatusInternal::PRESENT,
                StatusInternal::ENUMERATING};
                StatusInternal::ENUMERATING, StatusInternal::NOT_PRESENT};

        // Transition to PRESENT if the camera is not in either of the rejected states
        sCameraService->updateStatus(StatusInternal::PRESENT,
@@ -2322,7 +2336,7 @@ void CameraService::Client::OpsCallback::opChanged(int32_t op,

CameraService::CameraState::CameraState(const String8& id, int cost,
        const std::set<String8>& conflicting) : mId(id),
        mStatus(StatusInternal::PRESENT), mCost(cost), mConflicting(conflicting) {}
        mStatus(StatusInternal::NOT_PRESENT), mCost(cost), mConflicting(conflicting) {}

CameraService::CameraState::~CameraState() {}

+3 −0
Original line number Diff line number Diff line
@@ -512,6 +512,9 @@ private:
    // Eumerate all camera providers in the system
    status_t enumerateProviders();

    // Add a new camera to camera and torch state lists
    void addStates(const String8 id);

    // Check if we can connect, before we acquire the service lock.
    // The returned originalClientPid is the PID of the original process that wants to connect to
    // camera.