From 507994d0312f89127562a1401f118439f810e751 Mon Sep 17 00:00:00 2001 From: Igor Murashkin Date: Fri, 5 Oct 2012 10:44:57 -0700 Subject: [PATCH] Camera2: Don't promote weak IBinder ptrs to strong ones The Binder driver does not support promoting weak pointers into strong pointers. Occassionally the system would lock up when trying to do this (when closing the camera app). Bug: 7289040 Change-Id: I8bc0b5c48616bf0b7f4eed1878ad4994ee635871 --- services/camera/libcameraservice/CameraService.cpp | 22 ++++++++++++---------- services/camera/libcameraservice/CameraService.h | 4 ++-- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/services/camera/libcameraservice/CameraService.cpp b/services/camera/libcameraservice/CameraService.cpp index 4d48d8d74e..6fbd6edb6a 100644 --- a/services/camera/libcameraservice/CameraService.cpp +++ b/services/camera/libcameraservice/CameraService.cpp @@ -227,7 +227,7 @@ void CameraService::removeClient(const sp& cameraClient) { Mutex::Autolock lock(mServiceLock); int outIndex; - sp client = findClientUnsafe(cameraClient, outIndex); + sp client = findClientUnsafe(cameraClient->asBinder(), outIndex); if (client != 0) { // Found our camera, clear and leave. @@ -241,7 +241,7 @@ void CameraService::removeClient(const sp& cameraClient) { } sp CameraService::findClientUnsafe( - const sp& cameraClient, int& outIndex) { + const wp& cameraClient, int& outIndex) { sp client; for (int i = 0; i < mNumberOfCameras; i++) { @@ -260,7 +260,7 @@ sp CameraService::findClientUnsafe( continue; } - if (cameraClient->asBinder() == client->getCameraClient()->asBinder()) { + if (cameraClient == client->getCameraClient()->asBinder()) { // Found our camera outIndex = i; return client; @@ -281,8 +281,8 @@ Mutex* CameraService::getClientLockById(int cameraId) { return &mClientLock[cameraId]; } -/*virtual*/sp CameraService::getClientByRemote( - const sp& cameraClient) { +sp CameraService::getClientByRemote( + const wp& cameraClient) { // Declare this before the lock to make absolutely sure the // destructor won't be called with the lock held. @@ -557,18 +557,20 @@ status_t CameraService::dump(int fd, const Vector& args) { /*virtual*/void CameraService::binderDied( const wp &who) { + /** + * While tempting to promote the wp into a sp, + * it's actually not supported by the binder driver + */ + ALOGV("java clients' binder died"); - sp whoStrong = who.promote(); + sp cameraClient = getClientByRemote(who); - if (whoStrong == 0) { + if (cameraClient == 0) { ALOGV("java clients' binder death already cleaned up (normal case)"); return; } - sp iCamClient = interface_cast(whoStrong); - - sp cameraClient = getClientByRemote(iCamClient); ALOGW("Disconnecting camera client %p since the binder for it " "died (this pid %d)", cameraClient.get(), getCallingPid()); diff --git a/services/camera/libcameraservice/CameraService.h b/services/camera/libcameraservice/CameraService.h index f1e7df6498..4dab340dec 100644 --- a/services/camera/libcameraservice/CameraService.h +++ b/services/camera/libcameraservice/CameraService.h @@ -55,7 +55,7 @@ public: virtual Client* getClientByIdUnsafe(int cameraId); virtual Mutex* getClientLockById(int cameraId); - virtual sp getClientByRemote(const sp& cameraClient); + virtual sp getClientByRemote(const wp& cameraClient); virtual status_t dump(int fd, const Vector& args); virtual status_t onTransact(uint32_t code, const Parcel& data, @@ -143,7 +143,7 @@ private: int mNumberOfCameras; // needs to be called with mServiceLock held - sp findClientUnsafe(const sp& cameraClient, int& outIndex); + sp findClientUnsafe(const wp& cameraClient, int& outIndex); // atomics to record whether the hardware is allocated to some client. volatile int32_t mBusy[MAX_CAMERAS]; -- 2.11.0