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/CameraServiceWatchdog.cpp b/services/camera/libcameraservice/CameraServiceWatchdog.cpp
index 950da6a..e101dd3 100644
--- a/services/camera/libcameraservice/CameraServiceWatchdog.cpp
+++ b/services/camera/libcameraservice/CameraServiceWatchdog.cpp
@@ -41,8 +41,10 @@
tidToCycleCounterMap[currentThreadId]++;
if (tidToCycleCounterMap[currentThreadId] >= mMaxCycles) {
- ALOGW("CameraServiceWatchdog triggering kill for pid: %d", getpid());
- kill(getpid(), SIGKILL);
+ ALOGW("CameraServiceWatchdog triggering abort for pid: %d", getpid());
+ // We use abort here so we can get a tombstone for better
+ // debugging.
+ abort();
}
}
}
diff --git a/services/camera/libcameraservice/CameraServiceWatchdog.h b/services/camera/libcameraservice/CameraServiceWatchdog.h
index f7c90a9..e55fa28 100644
--- a/services/camera/libcameraservice/CameraServiceWatchdog.h
+++ b/services/camera/libcameraservice/CameraServiceWatchdog.h
@@ -28,7 +28,7 @@
* To disable/enable:
* - adb shell cmd media.camera set-cameraservice-watchdog [0/1]
*/
-
+#pragma once
#include <chrono>
#include <thread>
#include <time.h>
@@ -67,7 +67,7 @@
/** Used to wrap monitored calls in start and stop functions using custom timer values */
template<typename T>
auto watchThread(T func, uint32_t tid, uint32_t cycles, uint32_t cycleLength) {
- auto res = NULL;
+ decltype(func()) res;
if (cycles != mMaxCycles || cycleLength != mCycleLengthMs) {
// Create another instance of the watchdog to prevent disruption
@@ -95,10 +95,9 @@
/** Used to wrap monitored calls in start and stop functions using class timer values */
template<typename T>
auto watchThread(T func, uint32_t tid) {
+ decltype(func()) res;
AutoMutex _l(mEnabledLock);
- auto res = NULL;
-
if (mEnabled) {
start(tid);
res = func();
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);
diff --git a/services/camera/libcameraservice/common/Camera2ClientBase.h b/services/camera/libcameraservice/common/Camera2ClientBase.h
index 0dad50f..6e37589 100644
--- a/services/camera/libcameraservice/common/Camera2ClientBase.h
+++ b/services/camera/libcameraservice/common/Camera2ClientBase.h
@@ -20,6 +20,7 @@
#include "common/CameraDeviceBase.h"
#include "camera/CaptureResult.h"
#include "utils/CameraServiceProxyWrapper.h"
+#include "CameraServiceWatchdog.h"
namespace android {
@@ -176,6 +177,12 @@
private:
template<typename TProviderPtr>
status_t initializeImpl(TProviderPtr providerPtr, const String8& monitorTags);
+
+ binder::Status disconnectImpl();
+
+ // Watchdog thread
+ sp<CameraServiceWatchdog> mCameraServiceWatchdog;
+
};
}; // namespace android