Camera: Remove thread that keeps HAL service alive for extra delay
hwservicemanager now guarantees clients will be held for ~5s before the
callback onClients(false) is called and they are allowed to exit.
Test: On walleye_svelte, manually observe camera behavior and the
lifetime of the lazy camera service process.
Change-Id: Iafbdd73f439da3a4f0fecb069e356d30aa2732b5
diff --git a/services/camera/libcameraservice/common/CameraProviderManager.cpp b/services/camera/libcameraservice/common/CameraProviderManager.cpp
index 3059b07..7c32e84 100644
--- a/services/camera/libcameraservice/common/CameraProviderManager.cpp
+++ b/services/camera/libcameraservice/common/CameraProviderManager.cpp
@@ -50,14 +50,6 @@
const std::string kLegacyProviderName("legacy/0");
const std::string kExternalProviderName("external/0");
const bool kEnableLazyHal(property_get_bool("ro.camera.enableLazyHal", false));
-
-// The extra amount of time to hold a reference to an ICameraProvider after it is no longer needed.
-// Hold the reference for this extra time so that if the camera is unreferenced and then referenced
-// again quickly, we do not let the HAL exit and then need to immediately restart it. An example
-// when this could happen is switching from a front-facing to a rear-facing camera. If the HAL were
-// to exit during the camera switch, the camera could appear janky to the user.
-const std::chrono::system_clock::duration kCameraKeepAliveDelay = 3s;
-
} // anonymous namespace
const float CameraProviderManager::kDepthARTolerance = .1f;
@@ -399,12 +391,15 @@
std::lock_guard<std::mutex> lock(mProviderInterfaceMapLock);
auto search = providerMap->find(cameraId.c_str());
if (search != providerMap->end()) {
- auto ptr = search->second;
- auto future = std::async(std::launch::async, [ptr] {
- std::this_thread::sleep_for(kCameraKeepAliveDelay);
- IPCThreadState::self()->flushCommands();
- });
+ // Drop the reference to this ICameraProvider. This is safe to do immediately (without an
+ // added delay) because hwservicemanager guarantees to hold the reference for at least five
+ // more seconds. We depend on this behavior so that if the provider is unreferenced and
+ // then referenced again quickly, we do not let the HAL exit and then need to immediately
+ // restart it. An example when this could happen is switching from a front-facing to a
+ // rear-facing camera. If the HAL were to exit during the camera switch, the camera could
+ // appear janky to the user.
providerMap->erase(cameraId.c_str());
+ IPCThreadState::self()->flushCommands();
} else {
ALOGE("%s: Asked to remove reference for camera %s, but no reference to it was found. This "
"could mean removeRef was called twice for the same camera ID.", __FUNCTION__,