camera: fix flashlight implementation for HAL v2
Update torch availability when the camera device availability changes.
For device HAL v2 and v3 implementation, notify torch unavailable for
all camera devices with a flash unit when a camera device is opened.
Notify torch available for all camera devices with flash unit when
all camera devices are closed.
Don't invoke torch status callback in camera service. Invoke torch
status callback in HAL or FlashControlBase implementations to avoid
race condition.
Clean up previous CL.
Bug: 2682206
Change-Id: I24f5478f467b2c680565fe98f112eef33e2547a1
diff --git a/services/camera/libcameraservice/CameraService.h b/services/camera/libcameraservice/CameraService.h
index 84bcdb8..74b3623 100644
--- a/services/camera/libcameraservice/CameraService.h
+++ b/services/camera/libcameraservice/CameraService.h
@@ -72,7 +72,7 @@
// HAL Callbacks
virtual void onDeviceStatusChanged(int cameraId,
int newStatus);
- virtual void onTorchStatusChanged(const String16& cameraId,
+ virtual void onTorchStatusChanged(const String8& cameraId,
ICameraServiceListener::TorchStatus
newStatus);
@@ -418,28 +418,33 @@
// flashlight control
sp<CameraFlashlight> mFlashlight;
- // guard mTorchStatusMap and mTorchClientMap
+ // guard mTorchStatusMap
Mutex mTorchStatusMutex;
+ // guard mTorchClientMap
+ Mutex mTorchClientMapMutex;
// camera id -> torch status
- KeyedVector<String16, ICameraServiceListener::TorchStatus> mTorchStatusMap;
+ KeyedVector<String8, ICameraServiceListener::TorchStatus> mTorchStatusMap;
// camera id -> torch client binder
// only store the last client that turns on each camera's torch mode
- KeyedVector<String16, sp<IBinder> > mTorchClientMap;
+ KeyedVector<String8, sp<IBinder> > mTorchClientMap;
// check and handle if torch client's process has died
void handleTorchClientBinderDied(const wp<IBinder> &who);
// handle torch mode status change and invoke callbacks. mTorchStatusMutex
// should be locked.
- void onTorchStatusChangedLocked(const String16& cameraId,
+ void onTorchStatusChangedLocked(const String8& cameraId,
ICameraServiceListener::TorchStatus newStatus);
+ // validate the camera id for use of setting a torch mode.
+ bool validCameraIdForSetTorchMode(const String8& cameraId);
+
// get a camera's torch status. mTorchStatusMutex should be locked.
- ICameraServiceListener::TorchStatus getTorchStatusLocked(
- const String16 &cameraId) const;
+ status_t getTorchStatusLocked(const String8 &cameraId,
+ ICameraServiceListener::TorchStatus *status) const;
// set a camera's torch status. mTorchStatusMutex should be locked.
- status_t setTorchStatusLocked(const String16 &cameraId,
+ status_t setTorchStatusLocked(const String8 &cameraId,
ICameraServiceListener::TorchStatus status);
// IBinder::DeathRecipient implementation