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

Commit e3a089d5 authored by Sravank's avatar Sravank Committed by Steve Kondik
Browse files

Camera : Clean up old camera client properly

Terminate the old client connection properly when an ANR occurs and
the user requests to re-launch the camera application.

CRs-fixed: 250354

Change-Id: I9989aa32ff1ecd1a3a49a3155a27d02a18a5a87d
parent e080c01b
Loading
Loading
Loading
Loading
+14 −4
Original line number Diff line number Diff line
@@ -81,6 +81,8 @@ static int getCallingPid() {
    return IPCThreadState::self()->getCallingPid();
}

static bool cleanOldclient = false;

// ----------------------------------------------------------------------------

void CameraService::instantiate() {
@@ -129,8 +131,14 @@ sp<ICamera> CameraService::connect(const sp<ICameraClient>& cameraClient)
                    currentClient->mClientPid, currentCameraClient->asBinder().get());
                if (kill(currentClient->mClientPid, 0) == -1 && errno == ESRCH) {
                    LOGV("The old client is dead!");
                    LOGE("forcefully terminating old client.. ref count ", currentClient->getStrongCount());
                    cleanOldclient = true;
                    mServiceLock.unlock();

                    currentClient->disconnect();
                    cleanOldclient = false;
                }
                return client;
                else return client;
            }
        } else {
            // can't promote, the previous client has died...
@@ -144,7 +152,7 @@ sp<ICamera> CameraService::connect(const sp<ICameraClient>& cameraClient)
        LOGV("Still have client, rejected");
        return client;
    }

    LOGV("creating new client");
    // create a new Client object
    client = new Client(this, cameraClient, callingPid);
    mClient = client;
@@ -396,12 +404,14 @@ void CameraService::Client::disconnect()
    LOGV("Client::disconnect() E (pid %d client %p)",
            callingPid, getCameraClient()->asBinder().get());

    if(!cleanOldclient)
        Mutex::Autolock lock(mLock);

    if (mClientPid <= 0) {
        LOGV("camera is unlocked (mClientPid = %d), don't tear down hardware", mClientPid);
        return;
    }
    if (checkPid() != NO_ERROR) {
    if (!cleanOldclient && checkPid() != NO_ERROR) {
        LOGV("Different client - don't disconnect");
        return;
    }