From ecf17e82505fdb60d59e00b6dd59036df93de655 Mon Sep 17 00:00:00 2001 From: Igor Murashkin Date: Tue, 2 Oct 2012 16:05:11 -0700 Subject: Camera2: Handle client processes dying by closing camera resources CameraService now subscribes to binder death notifications for each client, and disconnects the client if the death happened without cleanly shutting down the client first. Bug: 7258314 Change-Id: I7803836b589fd8f0dfe00f6c28a707b82012e751 --- services/camera/libcameraservice/Camera2Client.cpp | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'services/camera/libcameraservice/Camera2Client.cpp') diff --git a/services/camera/libcameraservice/Camera2Client.cpp b/services/camera/libcameraservice/Camera2Client.cpp index 59ec6b6..948b59f 100644 --- a/services/camera/libcameraservice/Camera2Client.cpp +++ b/services/camera/libcameraservice/Camera2Client.cpp @@ -47,9 +47,10 @@ Camera2Client::Camera2Client(const sp& cameraService, const sp& cameraClient, int cameraId, int cameraFacing, - int clientPid): + int clientPid, + int servicePid): Client(cameraService, cameraClient, - cameraId, cameraFacing, clientPid), + cameraId, cameraFacing, clientPid, servicePid), mSharedCameraClient(cameraClient), mParameters(cameraId, cameraFacing) { @@ -64,10 +65,10 @@ Camera2Client::Camera2Client(const sp& cameraService, status_t Camera2Client::checkPid(const char* checkLocation) const { int callingPid = getCallingPid(); - if (callingPid == mClientPid) return NO_ERROR; + if (callingPid == mClientPid || callingPid == mServicePid) return NO_ERROR; ALOGE("%s: attempt to use a locked camera from a different process" - " (old pid %d, new pid %d)", checkLocation, mClientPid, callingPid); + " (old pid %d, new pid %d, servicePid %d)", checkLocation, mClientPid, callingPid, mServicePid); return PERMISSION_DENIED; } @@ -138,8 +139,15 @@ Camera2Client::~Camera2Client() { mDestructionStarted = true; - SharedParameters::Lock l(mParameters); - if (l.mParameters.state != Parameters::DISCONNECTED) { + Parameters::State state; + // warning: + // holding on to locks more than necessary may be hazardous to your health + { + SharedParameters::Lock l(mParameters); + state = l.mParameters.state; + } + + if (state != Parameters::DISCONNECTED) { // Rewrite mClientPid to allow shutdown by CameraService mClientPid = getCallingPid(); disconnect(); -- cgit v1.1