From b10cdadf0fb945e23ca77008d4af76584bd0e39a Mon Sep 17 00:00:00 2001 From: Zhijun He Date: Mon, 16 Jun 2014 16:38:35 -0700 Subject: cameraservice: Implement HAL1 and higher HAL API coexistence A higher hal version device like HAL3.2 can be opened as HAL1.0 device if HAL supports it. This only applies to camera API1. Change-Id: I4ae9f59f4317158cc1bd7ed7726e4032cdd1fa07 --- camera/Camera.cpp | 26 ++++++++++++++++++++++++++ camera/ICameraService.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) (limited to 'camera') diff --git a/camera/Camera.cpp b/camera/Camera.cpp index 22199fa..85f44f0 100644 --- a/camera/Camera.cpp +++ b/camera/Camera.cpp @@ -77,6 +77,32 @@ sp Camera::connect(int cameraId, const String16& clientPackageName, return CameraBaseT::connect(cameraId, clientPackageName, clientUid); } +status_t Camera::connectLegacy(int cameraId, int halVersion, + const String16& clientPackageName, + int clientUid, + sp& camera) +{ + ALOGV("%s: connect legacy camera device", __FUNCTION__); + sp c = new Camera(cameraId); + sp cl = c; + status_t status = NO_ERROR; + const sp& cs = CameraBaseT::getCameraService(); + + if (cs != 0) { + status = cs.get()->connectLegacy(cl, cameraId, halVersion, clientPackageName, + clientUid, /*out*/c->mCamera); + } + if (status == OK && c->mCamera != 0) { + c->mCamera->asBinder()->linkToDeath(c); + c->mStatus = NO_ERROR; + camera = c; + } else { + ALOGW("An error occurred while connecting to camera: %d", cameraId); + c.clear(); + } + return status; +} + status_t Camera::reconnect() { ALOGV("reconnect"); diff --git a/camera/ICameraService.cpp b/camera/ICameraService.cpp index 79c33f9..5485205 100644 --- a/camera/ICameraService.cpp +++ b/camera/ICameraService.cpp @@ -186,6 +186,29 @@ public: return status; } + // connect to camera service (android.hardware.Camera) + virtual status_t connectLegacy(const sp& cameraClient, int cameraId, + int halVersion, + const String16 &clientPackageName, int clientUid, + /*out*/sp& device) + { + Parcel data, reply; + data.writeInterfaceToken(ICameraService::getInterfaceDescriptor()); + data.writeStrongBinder(cameraClient->asBinder()); + data.writeInt32(cameraId); + data.writeInt32(halVersion); + data.writeString16(clientPackageName); + data.writeInt32(clientUid); + remote()->transact(BnCameraService::CONNECT_LEGACY, data, &reply); + + if (readExceptionCode(reply)) return -EPROTO; + status_t status = reply.readInt32(); + if (reply.readInt32() != 0) { + device = interface_cast(reply.readStrongBinder()); + } + return status; + } + // connect to camera service (pro client) virtual status_t connectPro(const sp& cameraCb, int cameraId, const String16 &clientPackageName, int clientUid, @@ -446,6 +469,27 @@ status_t BnCameraService::onTransact( reply->writeInt32(supportsCameraApi(cameraId, apiVersion)); return NO_ERROR; } break; + case CONNECT_LEGACY: { + CHECK_INTERFACE(ICameraService, data, reply); + sp cameraClient = + interface_cast(data.readStrongBinder()); + int32_t cameraId = data.readInt32(); + int32_t halVersion = data.readInt32(); + const String16 clientName = data.readString16(); + int32_t clientUid = data.readInt32(); + sp camera; + status_t status = connectLegacy(cameraClient, cameraId, halVersion, + clientName, clientUid, /*out*/camera); + reply->writeNoException(); + reply->writeInt32(status); + if (camera != NULL) { + reply->writeInt32(1); + reply->writeStrongBinder(camera->asBinder()); + } else { + reply->writeInt32(0); + } + return NO_ERROR; + } break; default: return BBinder::onTransact(code, data, reply, flags); } -- cgit v1.1