cameraserver: Add watchdog timer for disconnect.

Bug: 228641945

Test: Add artifical delay of 2 seconds in disconnectImpl, see tombstone

Change-Id: I11254e04d9d883e839dc1a7eee309e249613957e
Signed-off-by: Jayant Chowdhary <jchowdhary@google.com>
(cherry picked from commit 48162a773f8a62f3f131a2740e6bed51a6be6e75)
diff --git a/services/camera/libcameraservice/common/Camera2ClientBase.cpp b/services/camera/libcameraservice/common/Camera2ClientBase.cpp
index 633746a..53a9b7e 100644
--- a/services/camera/libcameraservice/common/Camera2ClientBase.cpp
+++ b/services/camera/libcameraservice/common/Camera2ClientBase.cpp
@@ -39,6 +39,9 @@
 #include "utils/CameraThreadState.h"
 
 namespace android {
+
+const static size_t kDisconnectTimeoutMs = 2500;
+
 using namespace camera2;
 
 // Interface used by CameraService
@@ -145,6 +148,10 @@
     wp<NotificationListener> weakThis(this);
     res = mDevice->setNotifyCallback(weakThis);
 
+    /** Start watchdog thread */
+    mCameraServiceWatchdog = new CameraServiceWatchdog();
+    mCameraServiceWatchdog->run("Camera2ClientBaseWatchdog");
+
     return OK;
 }
 
@@ -239,9 +246,14 @@
 
 // ICameraClient2BaseUser interface
 
-
 template <typename TClientBase>
 binder::Status Camera2ClientBase<TClientBase>::disconnect() {
+    return mCameraServiceWatchdog->WATCH_CUSTOM_TIMER(disconnectImpl(),
+            kDisconnectTimeoutMs / kCycleLengthMs, kCycleLengthMs);
+}
+
+template <typename TClientBase>
+binder::Status Camera2ClientBase<TClientBase>::disconnectImpl() {
     ATRACE_CALL();
     ALOGD("Camera %s: start to disconnect", TClientBase::mCameraIdStr.string());
     Mutex::Autolock icl(mBinderSerializationLock);