}
struct camera_info info;
- status_t rc = mModule->get_camera_info(cameraId, &info);
+ status_t rc = filterGetInfoErrorCode(
+ mModule->get_camera_info(cameraId, &info));
cameraInfo->facing = info.facing;
cameraInfo->orientation = info.orientation;
return rc;
* Normal HAL 2.1+ codepath.
*/
struct camera_info info;
- ret = mModule->get_camera_info(cameraId, &info);
+ ret = filterGetInfoErrorCode(mModule->get_camera_info(cameraId, &info));
*cameraInfo = info.static_camera_characteristics;
}
return deviceVersion;
}
-bool CameraService::isValidCameraId(int cameraId) {
- int facing;
- int deviceVersion = getDeviceVersion(cameraId, &facing);
-
- switch(deviceVersion) {
- case CAMERA_DEVICE_API_VERSION_1_0:
- case CAMERA_DEVICE_API_VERSION_2_0:
- case CAMERA_DEVICE_API_VERSION_2_1:
- case CAMERA_DEVICE_API_VERSION_3_0:
- case CAMERA_DEVICE_API_VERSION_3_1:
- case CAMERA_DEVICE_API_VERSION_3_2:
- return true;
- default:
- return false;
+status_t CameraService::filterOpenErrorCode(status_t err) {
+ switch(err) {
+ case NO_ERROR:
+ case -EBUSY:
+ case -EINVAL:
+ case -EUSERS:
+ return err;
+ default:
+ break;
}
+ return -ENODEV;
+}
- return false;
+status_t CameraService::filterGetInfoErrorCode(status_t err) {
+ switch(err) {
+ case NO_ERROR:
+ case -EINVAL:
+ return err;
+ default:
+ break;
+ }
+ return -ENODEV;
}
bool CameraService::setUpVendorTags() {
int facing = -1;
int deviceVersion = getDeviceVersion(cameraId, &facing);
- // If there are other non-exclusive users of the camera,
- // this will tear them down before we can reuse the camera
- if (isValidCameraId(cameraId)) {
- // transition from PRESENT -> NOT_AVAILABLE
- updateStatus(ICameraServiceListener::STATUS_NOT_AVAILABLE,
- cameraId);
- }
-
if (halVersion < 0 || halVersion == deviceVersion) {
// Default path: HAL version is unspecified by caller, create CameraClient
// based on device version reported by the HAL.
status_t status = connectFinishUnsafe(client, client->getRemote());
if (status != OK) {
// this is probably not recoverable.. maybe the client can try again
- // OK: we can only get here if we were originally in PRESENT state
- updateStatus(ICameraServiceListener::STATUS_PRESENT, cameraId);
return status;
}
int facing = -1;
int deviceVersion = getDeviceVersion(cameraId, &facing);
- // If there are other non-exclusive users of the camera,
- // this will tear them down before we can reuse the camera
- if (isValidCameraId(cameraId)) {
- // transition from PRESENT -> NOT_AVAILABLE
- updateStatus(ICameraServiceListener::STATUS_NOT_AVAILABLE,
- cameraId);
- }
-
switch(deviceVersion) {
case CAMERA_DEVICE_API_VERSION_1_0:
ALOGW("Camera using old HAL version: %d", deviceVersion);
status_t status = connectFinishUnsafe(client, client->getRemote());
if (status != OK) {
// this is probably not recoverable.. maybe the client can try again
- // OK: we can only get here if we were originally in PRESENT state
- updateStatus(ICameraServiceListener::STATUS_PRESENT, cameraId);
return status;
}
void CameraService::BasicClient::disconnect() {
ALOGV("BasicClient::disconnect");
mCameraService->removeClientByRemote(mRemoteBinder);
+
+ finishCameraOps();
// client shouldn't be able to call into us anymore
mClientPid = 0;
}
status_t CameraService::BasicClient::startCameraOps() {
int32_t res;
-
+ // Notify app ops that the camera is not available
mOpsCallback = new OpsCallback(this);
{
mCameraId, String8(mClientPackageName).string());
return PERMISSION_DENIED;
}
+
mOpsActive = true;
+
+ // Transition device availability listeners from PRESENT -> NOT_AVAILABLE
+ mCameraService->updateStatus(ICameraServiceListener::STATUS_NOT_AVAILABLE,
+ mCameraId);
+
return OK;
}
status_t CameraService::BasicClient::finishCameraOps() {
+ // Check if startCameraOps succeeded, and if so, finish the camera op
if (mOpsActive) {
+ // Notify app ops that the camera is available again
mAppOpsManager.finishOp(AppOpsManager::OP_CAMERA, mClientUid,
mClientPackageName);
mOpsActive = false;
+
+ // Notify device availability listeners that this camera is available
+ // again
+
+ StatusVector rejectSourceStates;
+ rejectSourceStates.push_back(ICameraServiceListener::STATUS_NOT_PRESENT);
+ rejectSourceStates.push_back(ICameraServiceListener::STATUS_ENUMERATING);
+
+ // Transition to PRESENT if the camera is not in either of above 2
+ // states
+ mCameraService->updateStatus(ICameraServiceListener::STATUS_PRESENT,
+ mCameraId,
+ &rejectSourceStates);
+
}
+ // Always stop watching, even if no camera op is active
mAppOpsManager.stopWatchingMode(mOpsCallback);
mOpsCallback.clear();
ALOGV("Client::disconnect");
BasicClient::disconnect();
mCameraService->setCameraFree(mCameraId);
-
- StatusVector rejectSourceStates;
- rejectSourceStates.push_back(ICameraServiceListener::STATUS_NOT_PRESENT);
- rejectSourceStates.push_back(ICameraServiceListener::STATUS_ENUMERATING);
-
- // Transition to PRESENT if the camera is not in either of above 2 states
- mCameraService->updateStatus(ICameraServiceListener::STATUS_PRESENT,
- mCameraId,
- &rejectSourceStates);
}
CameraService::Client::OpsCallback::OpsCallback(wp<BasicClient> client):
// CameraDeviceFactory functionality
int getDeviceVersion(int cameraId, int* facing = NULL);
+ /////////////////////////////////////////////////////////////////////
+ // Shared utilities
+ static status_t filterOpenErrorCode(status_t err);
+ static status_t filterGetInfoErrorCode(status_t err);
/////////////////////////////////////////////////////////////////////
// CameraClient functionality
class BasicClient : public virtual RefBase {
public:
- virtual status_t initialize(camera_module_t *module) = 0;
-
- virtual void disconnect() = 0;
+ virtual status_t initialize(camera_module_t *module) = 0;
+ virtual void disconnect();
// because we can't virtually inherit IInterface, which breaks
// virtual inheritance
virtual sp<IBinder> asBinderWrapper() = 0;
// Return the remote callback binder object (e.g. IProCameraCallbacks)
- sp<IBinder> getRemote() {
+ sp<IBinder> getRemote() {
return mRemoteBinder;
}
- virtual status_t dump(int fd, const Vector<String16>& args) = 0;
+ virtual status_t dump(int fd, const Vector<String16>& args) = 0;
protected:
BasicClient(const sp<CameraService>& cameraService,