Camera: Synchronize between provider removal and registration
Because onDeviceStatusChanged is reenterable, in the case of camera
provider process crash, the following race condition could happen:
1. Camera provider crashes, onDeviceStatusChanged is called with
NOT_PRESENT. camera service calls disconnect to disconnect from
CameraDevice.
2. Camera provider comes back online, and onDeviceStatusChanged is
called to change the state back to PRESENT.
3. disconnect returns, and the camera state is deleted, resulting in
cameraservice to be in bad state.
This change synchronizes onRegistration and removeProvider to avoid
aforementioned race condition.
Test: Camera CTS
Test: Add delay in removeProvider and kill provider process while camera
is running.
Bug: 110837617
Change-Id: I472f1bfebf770d8eb0b2d7eb5f4a0fa26566bdea
diff --git a/services/camera/libcameraservice/common/CameraProviderManager.h b/services/camera/libcameraservice/common/CameraProviderManager.h
index b8b8b8c..c523c2d 100644
--- a/services/camera/libcameraservice/common/CameraProviderManager.h
+++ b/services/camera/libcameraservice/common/CameraProviderManager.h
@@ -246,6 +246,9 @@
wp<StatusListener> mListener;
ServiceInteractionProxy* mServiceProxy;
+ // mProviderLifecycleLock is locked during onRegistration and removeProvider
+ mutable std::mutex mProviderLifecycleLock;
+
static HardwareServiceInteractionProxy sHardwareServiceInteractionProxy;
struct ProviderInfo :