summaryrefslogtreecommitdiffstats
path: root/camera
diff options
context:
space:
mode:
authorRuben Brunk <rubenbrunk@google.com>2013-08-08 13:07:18 -0700
committerRuben Brunk <rubenbrunk@google.com>2013-08-16 14:42:28 -0700
commit0f61d8f14aa368c9cd7076528e8096e10ed100a0 (patch)
treeed95cb70d56dd3a732f4e1909c96e7889b23ce94 /camera
parent75c16dde986e16ac5fd4d34b06b0cc6a90679866 (diff)
downloadframeworks_av-0f61d8f14aa368c9cd7076528e8096e10ed100a0.zip
frameworks_av-0f61d8f14aa368c9cd7076528e8096e10ed100a0.tar.gz
frameworks_av-0f61d8f14aa368c9cd7076528e8096e10ed100a0.tar.bz2
Refactor CameraService to handle errors properly.
Bug: 10361136 -Connect calls now return status_t error flags. Change-Id: Idca453b111e5df31327f6c99ebe853bb2e332b95
Diffstat (limited to 'camera')
-rw-r--r--camera/Camera.cpp3
-rw-r--r--camera/CameraBase.cpp11
-rw-r--r--camera/ICameraService.cpp81
-rw-r--r--camera/ProCamera.cpp4
4 files changed, 74 insertions, 25 deletions
diff --git a/camera/Camera.cpp b/camera/Camera.cpp
index fd78572..22016a9 100644
--- a/camera/Camera.cpp
+++ b/camera/Camera.cpp
@@ -39,6 +39,9 @@ Camera::Camera(int cameraId)
{
}
+CameraTraits<Camera>::TCamConnectService CameraTraits<Camera>::fnConnectService =
+ &ICameraService::connect;
+
// construct a camera client from an existing camera remote
sp<Camera> Camera::create(const sp<ICamera>& camera)
{
diff --git a/camera/CameraBase.cpp b/camera/CameraBase.cpp
index c25c5fd..55376b0 100644
--- a/camera/CameraBase.cpp
+++ b/camera/CameraBase.cpp
@@ -92,20 +92,25 @@ const sp<ICameraService>& CameraBase<TCam, TCamTraits>::getCameraService()
template <typename TCam, typename TCamTraits>
sp<TCam> CameraBase<TCam, TCamTraits>::connect(int cameraId,
- const String16& clientPackageName,
+ const String16& clientPackageName,
int clientUid)
{
ALOGV("%s: connect", __FUNCTION__);
sp<TCam> c = new TCam(cameraId);
sp<TCamCallbacks> cl = c;
+ status_t status = NO_ERROR;
const sp<ICameraService>& cs = getCameraService();
+
if (cs != 0) {
- c->mCamera = cs->connect(cl, cameraId, clientPackageName, clientUid);
+ TCamConnectService fnConnectService = TCamTraits::fnConnectService;
+ status = (cs.get()->*fnConnectService)(cl, cameraId, clientPackageName, clientUid,
+ /*out*/ c->mCamera);
}
- if (c->mCamera != 0) {
+ if (status == OK && c->mCamera != 0) {
c->mCamera->asBinder()->linkToDeath(c);
c->mStatus = NO_ERROR;
} else {
+ ALOGW("An error occurred while connecting to camera: %d", cameraId);
c.clear();
}
return c;
diff --git a/camera/ICameraService.cpp b/camera/ICameraService.cpp
index 876a2df..3debe22 100644
--- a/camera/ICameraService.cpp
+++ b/camera/ICameraService.cpp
@@ -120,8 +120,10 @@ public:
}
// connect to camera service (android.hardware.Camera)
- virtual sp<ICamera> connect(const sp<ICameraClient>& cameraClient, int cameraId,
- const String16 &clientPackageName, int clientUid)
+ virtual status_t connect(const sp<ICameraClient>& cameraClient, int cameraId,
+ const String16 &clientPackageName, int clientUid,
+ /*out*/
+ sp<ICamera>& device)
{
Parcel data, reply;
data.writeInterfaceToken(ICameraService::getInterfaceDescriptor());
@@ -131,13 +133,19 @@ public:
data.writeInt32(clientUid);
remote()->transact(BnCameraService::CONNECT, data, &reply);
- if (readExceptionCode(reply)) return NULL;
- return interface_cast<ICamera>(reply.readStrongBinder());
+ if (readExceptionCode(reply)) return -EPROTO;
+ status_t status = reply.readInt32();
+ if (reply.readInt32() != 0) {
+ device = interface_cast<ICamera>(reply.readStrongBinder());
+ }
+ return status;
}
// connect to camera service (pro client)
- virtual sp<IProCameraUser> connect(const sp<IProCameraCallbacks>& cameraCb, int cameraId,
- const String16 &clientPackageName, int clientUid)
+ virtual status_t connectPro(const sp<IProCameraCallbacks>& cameraCb, int cameraId,
+ const String16 &clientPackageName, int clientUid,
+ /*out*/
+ sp<IProCameraUser>& device)
{
Parcel data, reply;
data.writeInterfaceToken(ICameraService::getInterfaceDescriptor());
@@ -147,16 +155,22 @@ public:
data.writeInt32(clientUid);
remote()->transact(BnCameraService::CONNECT_PRO, data, &reply);
- if (readExceptionCode(reply)) return NULL;
- return interface_cast<IProCameraUser>(reply.readStrongBinder());
+ if (readExceptionCode(reply)) return -EPROTO;
+ status_t status = reply.readInt32();
+ if (reply.readInt32() != 0) {
+ device = interface_cast<IProCameraUser>(reply.readStrongBinder());
+ }
+ return status;
}
// connect to camera service (android.hardware.camera2.CameraDevice)
- virtual sp<ICameraDeviceUser> connect(
+ virtual status_t connectDevice(
const sp<ICameraDeviceCallbacks>& cameraCb,
int cameraId,
const String16& clientPackageName,
- int clientUid)
+ int clientUid,
+ /*out*/
+ sp<ICameraDeviceUser>& device)
{
Parcel data, reply;
data.writeInterfaceToken(ICameraService::getInterfaceDescriptor());
@@ -166,8 +180,12 @@ public:
data.writeInt32(clientUid);
remote()->transact(BnCameraService::CONNECT_DEVICE, data, &reply);
- if (readExceptionCode(reply)) return NULL;
- return interface_cast<ICameraDeviceUser>(reply.readStrongBinder());
+ if (readExceptionCode(reply)) return -EPROTO;
+ status_t status = reply.readInt32();
+ if (reply.readInt32() != 0) {
+ device = interface_cast<ICameraDeviceUser>(reply.readStrongBinder());
+ }
+ return status;
}
virtual status_t addListener(const sp<ICameraServiceListener>& listener)
@@ -228,10 +246,17 @@ status_t BnCameraService::onTransact(
int32_t cameraId = data.readInt32();
const String16 clientName = data.readString16();
int32_t clientUid = data.readInt32();
- sp<ICamera> camera = connect(cameraClient, cameraId,
- clientName, clientUid);
+ sp<ICamera> camera;
+ status_t status = connect(cameraClient, cameraId,
+ clientName, clientUid, /*out*/ camera);
reply->writeNoException();
- reply->writeStrongBinder(camera->asBinder());
+ reply->writeInt32(status);
+ if (camera != NULL) {
+ reply->writeInt32(1);
+ reply->writeStrongBinder(camera->asBinder());
+ } else {
+ reply->writeInt32(0);
+ }
return NO_ERROR;
} break;
case CONNECT_PRO: {
@@ -241,10 +266,17 @@ status_t BnCameraService::onTransact(
int32_t cameraId = data.readInt32();
const String16 clientName = data.readString16();
int32_t clientUid = data.readInt32();
- sp<IProCameraUser> camera = connect(cameraClient, cameraId,
- clientName, clientUid);
+ sp<IProCameraUser> camera;
+ status_t status = connectPro(cameraClient, cameraId,
+ clientName, clientUid, /*out*/ camera);
reply->writeNoException();
- reply->writeStrongBinder(camera->asBinder());
+ reply->writeInt32(status);
+ if (camera != NULL) {
+ reply->writeInt32(1);
+ reply->writeStrongBinder(camera->asBinder());
+ } else {
+ reply->writeInt32(0);
+ }
return NO_ERROR;
} break;
case CONNECT_DEVICE: {
@@ -254,10 +286,17 @@ status_t BnCameraService::onTransact(
int32_t cameraId = data.readInt32();
const String16 clientName = data.readString16();
int32_t clientUid = data.readInt32();
- sp<ICameraDeviceUser> camera = connect(cameraClient, cameraId,
- clientName, clientUid);
+ sp<ICameraDeviceUser> camera;
+ status_t status = connectDevice(cameraClient, cameraId,
+ clientName, clientUid, /*out*/ camera);
reply->writeNoException();
- reply->writeStrongBinder(camera->asBinder());
+ reply->writeInt32(status);
+ if (camera != NULL) {
+ reply->writeInt32(1);
+ reply->writeStrongBinder(camera->asBinder());
+ } else {
+ reply->writeInt32(0);
+ }
return NO_ERROR;
} break;
case ADD_LISTENER: {
diff --git a/camera/ProCamera.cpp b/camera/ProCamera.cpp
index f6c9ca1..577c760 100644
--- a/camera/ProCamera.cpp
+++ b/camera/ProCamera.cpp
@@ -26,7 +26,6 @@
#include <binder/IMemory.h>
#include <camera/ProCamera.h>
-#include <camera/ICameraService.h>
#include <camera/IProCameraUser.h>
#include <camera/IProCameraCallbacks.h>
@@ -47,6 +46,9 @@ ProCamera::ProCamera(int cameraId)
{
}
+CameraTraits<ProCamera>::TCamConnectService CameraTraits<ProCamera>::fnConnectService =
+ &ICameraService::connectPro;
+
ProCamera::~ProCamera()
{