Camera: Don't cancel AF when the device is disconnected
Under some conditions camera clients may be able to
call 'cancelAutoFocus' immediately after the
Camera2Client disconnects from the Camera3Device.
The device instance will remain valid but some
of the internal resources like the request thread
will be released.
Avoid possible invalid access by checking the
client parameter state and return appropriate
error status in case we are disconnected.
Bug: 323947800
Test: atest -c -d cts/tests/camera/src/android/hardware/cts/
Change-Id: I6e777212168ac92a28cc7b1bc16c7a0eeb7dbb2d
diff --git a/services/camera/libcameraservice/api1/Camera2Client.cpp b/services/camera/libcameraservice/api1/Camera2Client.cpp
index caa6424..05c7e51 100644
--- a/services/camera/libcameraservice/api1/Camera2Client.cpp
+++ b/services/camera/libcameraservice/api1/Camera2Client.cpp
@@ -1460,6 +1460,11 @@
int triggerId;
{
SharedParameters::Lock l(mParameters);
+ if (l.mParameters.state == Parameters::DISCONNECTED) {
+ ALOGE("%s: Camera %d has been disconnected.", __FUNCTION__, mCameraId);
+ return INVALID_OPERATION;
+ }
+
// Canceling does nothing in FIXED or INFINITY modes
if (l.mParameters.focusMode == Parameters::FOCUS_MODE_FIXED ||
l.mParameters.focusMode == Parameters::FOCUS_MODE_INFINITY) {