status_t Camera2Client::checkPid(const char* checkLocation) const {
int callingPid = getCallingPid();
- if (callingPid == mClientPid || callingPid == mServicePid) return NO_ERROR;
+ if (callingPid == mClientPid) return NO_ERROR;
ALOGE("%s: attempt to use a locked camera from a different process"
- " (old pid %d, new pid %d, servicePid %d)", checkLocation, mClientPid, callingPid, mServicePid);
+ " (old pid %d, new pid %d)", checkLocation, mClientPid, callingPid);
return PERMISSION_DENIED;
}
mDestructionStarted = true;
- 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();
- }
+ disconnect();
ALOGI("Camera %d: Closed", mCameraId);
}
ATRACE_CALL();
Mutex::Autolock icl(mICameraLock);
status_t res;
- if ( (res = checkPid(__FUNCTION__) ) != OK) return;
+
+ // Allow both client and the media server to disconnect at all times
+ int callingPid = getCallingPid();
+ if (callingPid != mClientPid && callingPid != mServicePid) return;
if (mDevice == 0) return;
{
SharedParameters::Lock l(mParameters);
+ if (l.mParameters.state == Parameters::DISCONNECTED) return;
l.mParameters.state = Parameters::DISCONNECTED;
}
int callingPid = getCallingPid();
LOG1("CameraClient::~CameraClient E (pid %d, this %p)", callingPid, this);
- // set mClientPid to let disconnet() tear down the hardware
- mClientPid = callingPid;
disconnect();
LOG1("CameraClient::~CameraClient X (pid %d, this %p)", callingPid, this);
}
status_t CameraClient::checkPid() const {
int callingPid = getCallingPid();
- if (callingPid == mClientPid || callingPid == mServicePid) return NO_ERROR;
+ if (callingPid == mClientPid) return NO_ERROR;
ALOGW("attempt to use a locked camera from a different process"
" (old pid %d, new pid %d)", mClientPid, callingPid);
LOG1("disconnect E (pid %d)", callingPid);
Mutex::Autolock lock(mLock);
- if (checkPid() != NO_ERROR) {
+ // Allow both client and the media server to disconnect at all times
+ if (callingPid != mClientPid && callingPid != mServicePid) {
ALOGW("different client - don't disconnect");
return;
}