camera: Migrate ndk_vendor client implementation to AIDL.
With HIDL deprecated, cameraservice's vndk client interfaces have been
updated to using AIDL. This CL drops support for the HIDL vndk client
interface.
When vendor partition is rebuilt for future version of android, it
should automatically pick up the new new client implementation.
Cameraservice will continue to support both HIDL and AIDL vndk clients.
The changes are simple 1:1 mapping of HIDL interface logic with AIDL
interface logic.
Bug: 243593375
Test: atest ACameraNdkVendorTest
Change-Id: Ic03bbf4e275bb3eddc4ca4e322adc84fdf03f482
diff --git a/camera/ndk/impl/ACameraCaptureSession.cpp b/camera/ndk/impl/ACameraCaptureSession.cpp
index 68db233..110d47a 100644
--- a/camera/ndk/impl/ACameraCaptureSession.cpp
+++ b/camera/ndk/impl/ACameraCaptureSession.cpp
@@ -23,7 +23,11 @@
ACameraCaptureSession::~ACameraCaptureSession() {
ALOGV("~ACameraCaptureSession: %p notify device end of life", this);
+#ifdef __ANDROID_VNDK__
+ std::shared_ptr<acam::CameraDevice> dev = getDevicePtr();
+#else
sp<acam::CameraDevice> dev = getDeviceSp();
+#endif
if (dev != nullptr && !dev->isClosed()) {
dev->lockDeviceForSessionOps();
{
@@ -50,7 +54,11 @@
mClosedByApp = true;
}
+#ifdef __ANDROID_VNDK__
+ std::shared_ptr<acam::CameraDevice> dev = getDevicePtr();
+#else
sp<acam::CameraDevice> dev = getDeviceSp();
+#endif
if (dev != nullptr) {
dev->lockDeviceForSessionOps();
}
@@ -75,7 +83,11 @@
camera_status_t
ACameraCaptureSession::stopRepeating() {
+#ifdef __ANDROID_VNDK__
+ std::shared_ptr<acam::CameraDevice> dev = getDevicePtr();
+#else
sp<acam::CameraDevice> dev = getDeviceSp();
+#endif
if (dev == nullptr) {
ALOGE("Error: Device associated with session %p has been closed!", this);
return ACAMERA_ERROR_SESSION_CLOSED;
@@ -93,7 +105,11 @@
camera_status_t
ACameraCaptureSession::abortCaptures() {
+#ifdef __ANDROID_VNDK__
+ std::shared_ptr<acam::CameraDevice> dev = getDevicePtr();
+#else
sp<acam::CameraDevice> dev = getDeviceSp();
+#endif
if (dev == nullptr) {
ALOGE("Error: Device associated with session %p has been closed!", this);
return ACAMERA_ERROR_SESSION_CLOSED;
@@ -110,7 +126,11 @@
}
camera_status_t ACameraCaptureSession::updateOutputConfiguration(ACaptureSessionOutput *output) {
+#ifdef __ANDROID_VNDK__
+ std::shared_ptr<acam::CameraDevice> dev = getDevicePtr();
+#else
sp<acam::CameraDevice> dev = getDeviceSp();
+#endif
if (dev == nullptr) {
ALOGE("Error: Device associated with session %p has been closed!", this);
return ACAMERA_ERROR_SESSION_CLOSED;
@@ -129,7 +149,11 @@
ACameraDevice*
ACameraCaptureSession::getDevice() {
Mutex::Autolock _l(mSessionLock);
+#ifdef __ANDROID_VNDK__
+ std::shared_ptr<acam::CameraDevice> dev = getDevicePtr();
+#else
sp<acam::CameraDevice> dev = getDeviceSp();
+#endif
if (dev == nullptr) {
ALOGE("Error: Device associated with session %p has been closed!", this);
return nullptr;
@@ -143,6 +167,17 @@
mIsClosed = true;
}
+#ifdef __ANDROID_VNDK__
+std::shared_ptr<acam::CameraDevice>
+ACameraCaptureSession::getDevicePtr() {
+ std::shared_ptr<acam::CameraDevice> device = mDevice.lock();
+ if (device == nullptr || device->isClosed()) {
+ ALOGW("Device is closed but session %d is not notified", mId);
+ return nullptr;
+ }
+ return device;
+}
+#else
sp<acam::CameraDevice>
ACameraCaptureSession::getDeviceSp() {
sp<acam::CameraDevice> device = mDevice.promote();
@@ -152,5 +187,4 @@
}
return device;
}
-
-
+#endif
diff --git a/camera/ndk/impl/ACameraCaptureSession.h b/camera/ndk/impl/ACameraCaptureSession.h
index 08a9226..cd65e8c 100644
--- a/camera/ndk/impl/ACameraCaptureSession.h
+++ b/camera/ndk/impl/ACameraCaptureSession.h
@@ -47,6 +47,21 @@
return mWindow > other.mWindow;
}
+ inline bool isWindowEqual(ACameraWindowType* window) const {
+ return mWindow == window;
+ }
+
+ // returns true if the window was successfully added, false otherwise.
+ inline bool addSharedWindow(ACameraWindowType* window) {
+ auto ret = mSharedWindows.insert(window);
+ return ret.second;
+ }
+
+ // returns the number of elements removed.
+ inline size_t removeSharedWindow(ACameraWindowType* window) {
+ return mSharedWindows.erase(window);
+ }
+
ACameraWindowType* mWindow;
std::set<ACameraWindowType *> mSharedWindows;
bool mIsShared;
@@ -65,6 +80,15 @@
*/
struct ACameraCaptureSession : public RefBase {
public:
+#ifdef __ANDROID_VNDK__
+ ACameraCaptureSession(
+ int id,
+ const ACaptureSessionOutputContainer* outputs,
+ const ACameraCaptureSession_stateCallbacks* cb,
+ std::weak_ptr<android::acam::CameraDevice> device) :
+ mId(id), mOutput(*outputs), mUserSessionCallback(*cb),
+ mDevice(std::move(device)) {}
+#else
ACameraCaptureSession(
int id,
const ACaptureSessionOutputContainer* outputs,
@@ -72,6 +96,7 @@
android::acam::CameraDevice* device) :
mId(id), mOutput(*outputs), mUserSessionCallback(*cb),
mDevice(device) {}
+#endif
// This can be called in app calling close() or after some app callback is finished
// Make sure the caller does not hold device or session lock!
@@ -114,12 +139,21 @@
// or a new session is replacing this session.
void closeByDevice();
+#ifdef __ANDROID_VNDK__
+ std::shared_ptr<android::acam::CameraDevice> getDevicePtr();
+#else
sp<android::acam::CameraDevice> getDeviceSp();
+#endif
const int mId;
const ACaptureSessionOutputContainer mOutput;
const ACameraCaptureSession_stateCallbacks mUserSessionCallback;
+#ifdef __ANDROID_VNDK__
+ const std::weak_ptr<android::acam::CameraDevice> mDevice;
+#else
const wp<android::acam::CameraDevice> mDevice;
+#endif
+
bool mIsClosed = false;
bool mClosedByApp = false;
Mutex mSessionLock;
diff --git a/camera/ndk/impl/ACameraCaptureSession.inc b/camera/ndk/impl/ACameraCaptureSession.inc
index 86bf8a5..da535f8 100644
--- a/camera/ndk/impl/ACameraCaptureSession.inc
+++ b/camera/ndk/impl/ACameraCaptureSession.inc
@@ -15,9 +15,8 @@
*/
#include "ACameraCaptureSession.h"
-
#ifdef __ANDROID_VNDK__
-#include "ndk_vendor/impl/ACameraDeviceVendor.inc"
+#include <ndk_vendor/impl/ACameraDeviceVendor.inc>
#else
#include "ACameraDevice.inc"
#endif
@@ -30,7 +29,11 @@
/*optional*/T* cbs,
int numRequests, ACaptureRequest** requests,
/*optional*/int* captureSequenceId) {
+#ifdef __ANDROID_VNDK__
+ std::shared_ptr<acam::CameraDevice> dev = getDevicePtr();
+#else
sp<acam::CameraDevice> dev = getDeviceSp();
+#endif
if (dev == nullptr) {
ALOGE("Error: Device associated with session %p has been closed!", this);
return ACAMERA_ERROR_SESSION_CLOSED;
@@ -52,7 +55,11 @@
/*optional*/T* cbs,
int numRequests, ACaptureRequest** requests,
/*optional*/int* captureSequenceId) {
+#ifdef __ANDROID_VNDK__
+ std::shared_ptr<acam::CameraDevice> dev = getDevicePtr();
+#else
sp<acam::CameraDevice> dev = getDeviceSp();
+#endif
if (dev == nullptr) {
ALOGE("Error: Device associated with session %p has been closed!", this);
return ACAMERA_ERROR_SESSION_CLOSED;
diff --git a/camera/ndk/impl/ACameraDevice.cpp b/camera/ndk/impl/ACameraDevice.cpp
index 7997768..536055b 100644
--- a/camera/ndk/impl/ACameraDevice.cpp
+++ b/camera/ndk/impl/ACameraDevice.cpp
@@ -1412,7 +1412,6 @@
while (it != mSequenceLastFrameNumberMap.end()) {
int sequenceId = it->first;
int64_t lastFrameNumber = it->second.lastFrameNumber;
- bool hasCallback = true;
if (mRemote == nullptr) {
ALOGW("Camera %s closed while checking sequence complete", getId());
@@ -1425,7 +1424,6 @@
// This should not happen because we always register callback (with nullptr inside)
if (mSequenceCallbackMap.count(sequenceId) == 0) {
ALOGW("No callback found for sequenceId %d", sequenceId);
- hasCallback = false;
}
if (lastFrameNumber <= completedFrameNumber) {
diff --git a/camera/ndk/impl/ACameraManager.cpp b/camera/ndk/impl/ACameraManager.cpp
index 23d90cc..9dc262f 100644
--- a/camera/ndk/impl/ACameraManager.cpp
+++ b/camera/ndk/impl/ACameraManager.cpp
@@ -38,17 +38,16 @@
const char* CameraManagerGlobal::kContextKey = "CallbackContext";
const nsecs_t CameraManagerGlobal::kCallbackDrainTimeout = 5000000; // 5 ms
Mutex CameraManagerGlobal::sLock;
-CameraManagerGlobal* CameraManagerGlobal::sInstance = nullptr;
+wp<CameraManagerGlobal> CameraManagerGlobal::sInstance = nullptr;
-CameraManagerGlobal&
-CameraManagerGlobal::getInstance() {
+sp<CameraManagerGlobal> CameraManagerGlobal::getInstance() {
Mutex::Autolock _l(sLock);
- CameraManagerGlobal* instance = sInstance;
+ sp<CameraManagerGlobal> instance = sInstance.promote();
if (instance == nullptr) {
instance = new CameraManagerGlobal();
sInstance = instance;
}
- return *instance;
+ return instance;
}
CameraManagerGlobal::~CameraManagerGlobal() {
@@ -637,7 +636,7 @@
Mutex::Autolock _l(mLock);
std::vector<String8> idList;
- CameraManagerGlobal::getInstance().getCameraIdList(&idList);
+ CameraManagerGlobal::getInstance()->getCameraIdList(&idList);
int numCameras = idList.size();
ACameraIdList *out = new ACameraIdList;
@@ -687,7 +686,7 @@
const char* cameraIdStr, sp<ACameraMetadata>* characteristics) {
Mutex::Autolock _l(mLock);
- sp<hardware::ICameraService> cs = CameraManagerGlobal::getInstance().getCameraService();
+ sp<hardware::ICameraService> cs = CameraManagerGlobal::getInstance()->getCameraService();
if (cs == nullptr) {
ALOGE("%s: Cannot reach camera service!", __FUNCTION__);
return ACAMERA_ERROR_CAMERA_DISCONNECTED;
@@ -733,7 +732,7 @@
ACameraDevice* device = new ACameraDevice(cameraId, callback, chars);
- sp<hardware::ICameraService> cs = CameraManagerGlobal::getInstance().getCameraService();
+ sp<hardware::ICameraService> cs = CameraManagerGlobal::getInstance()->getCameraService();
if (cs == nullptr) {
ALOGE("%s: Cannot reach camera service!", __FUNCTION__);
delete device;
diff --git a/camera/ndk/impl/ACameraManager.h b/camera/ndk/impl/ACameraManager.h
index d53d809..0dd79da 100644
--- a/camera/ndk/impl/ACameraManager.h
+++ b/camera/ndk/impl/ACameraManager.h
@@ -46,7 +46,7 @@
*/
class CameraManagerGlobal final : public RefBase {
public:
- static CameraManagerGlobal& getInstance();
+ static sp<CameraManagerGlobal> getInstance();
sp<hardware::ICameraService> getCameraService();
void registerAvailabilityCallback(
@@ -257,7 +257,7 @@
// For the singleton instance
static Mutex sLock;
- static CameraManagerGlobal* sInstance;
+ static wp<CameraManagerGlobal> sInstance;
CameraManagerGlobal() {};
~CameraManagerGlobal();
};
@@ -271,7 +271,7 @@
*/
struct ACameraManager {
ACameraManager() :
- mGlobalManager(&(android::acam::CameraManagerGlobal::getInstance())) {}
+ mGlobalManager(android::acam::CameraManagerGlobal::getInstance()) {}
~ACameraManager();
camera_status_t getCameraIdList(ACameraIdList** cameraIdList);
static void deleteCameraIdList(ACameraIdList* cameraIdList);