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

Commit 3db15193 authored by Shuzhen Wang's avatar Shuzhen Wang
Browse files

Camera: Only call cacheDump for the current camera id

It's not necessary to call cacheDump on all active camera sessions.
We only need to call it for the caller's camera session.

The reason is that:
- The cached dump is cleared by any new `connect` call.
- The to-be closed session will be cached
- The current active session will either be cached when it's
  closed, or not cached which is okay because it will show up
  when dump() is called.

This change has the good side effect of addressing the NPE when 2
cameras are closed together. If 2 cameras are closed around the same
time, one camera's cacheDump could access pointers already deallocated
by the other camera's close call.

Flag: EXEMPT bugfix
Bug: 362645633
Bug: 413128173
Test: Open, close camera, and dumpsys
Change-Id: Ie9b7ba452106fb5f1773e6c65bad58eb311b1320
parent 14e69e69
Loading
Loading
Loading
Loading
+7 −11
Original line number Original line Diff line number Diff line
@@ -5534,7 +5534,7 @@ static bool tryLock(Mutex& mutex)
    return locked;
    return locked;
}
}


void CameraService::cacheDump() {
void CameraService::cacheDump(const std::string& cameraId) {
    if (mMemFd != -1) {
    if (mMemFd != -1) {
        const Vector<String16> args;
        const Vector<String16> args;
        ATRACE_CALL();
        ATRACE_CALL();
@@ -5542,10 +5542,7 @@ void CameraService::cacheDump() {
        // cacheDump will not be called during the second disconnect.
        // cacheDump will not be called during the second disconnect.
        Mutex::Autolock lock(mServiceLock);
        Mutex::Autolock lock(mServiceLock);


        Mutex::Autolock l(mCameraStatesLock);
        // Start collecting the info for calling camera Id and store it in temp file.
        // Start collecting the info for open sessions and store it in temp file.
        for (const auto& state : mCameraStates) {
            std::string cameraId = state.first;
        auto clientDescriptor = mActiveClientManager.get(cameraId);
        auto clientDescriptor = mActiveClientManager.get(cameraId);
        if (clientDescriptor != nullptr) {
        if (clientDescriptor != nullptr) {
            dprintf(mMemFd, "== Camera device %s dynamic info: ==\n", cameraId.c_str());
            dprintf(mMemFd, "== Camera device %s dynamic info: ==\n", cameraId.c_str());
@@ -5554,7 +5551,6 @@ void CameraService::cacheDump() {
        }
        }
    }
    }
}
}
}


status_t CameraService::dump(int fd, const Vector<String16>& args) {
status_t CameraService::dump(int fd, const Vector<String16>& args) {
    ATRACE_CALL();
    ATRACE_CALL();
+1 −1
Original line number Original line Diff line number Diff line
@@ -286,7 +286,7 @@ public:
    void                notifyMonitoredUids(const std::unordered_set<uid_t> &notifyUidSet);
    void                notifyMonitoredUids(const std::unordered_set<uid_t> &notifyUidSet);


    // Stores current open session device info in temp file.
    // Stores current open session device info in temp file.
    void cacheDump();
    void cacheDump(const std::string& cameraId);


    // Register an offline client for a given active camera id
    // Register an offline client for a given active camera id
    status_t addOfflineClient(const std::string &cameraId, sp<BasicClient> offlineClient);
    status_t addOfflineClient(const std::string &cameraId, sp<BasicClient> offlineClient);
+1 −1
Original line number Original line Diff line number Diff line
@@ -293,7 +293,7 @@ binder::Status Camera2ClientBase<TClientBase>::disconnectImpl() {
    // deadlock while acquiring service lock in cacheDump.
    // deadlock while acquiring service lock in cacheDump.
    if (!TClientBase::mDisconnected) {
    if (!TClientBase::mDisconnected) {
        ALOGD("Camera %s: start to cacheDump", TClientBase::mCameraIdStr.c_str());
        ALOGD("Camera %s: start to cacheDump", TClientBase::mCameraIdStr.c_str());
        Camera2ClientBase::getCameraService()->cacheDump();
        Camera2ClientBase::getCameraService()->cacheDump(TClientBase::mCameraIdStr);
    }
    }


    detachDevice();
    detachDevice();