Synchronous resource recover mechanism for ISensorEventConnection
Add synchronous destroy() function to recover resource used by
remote ISensorEventConnection object.
Bug: 63542033
Test: SensorDirectReportTest pass
Change-Id: If98782ee12c7b1a733eb15a2fd8d7c5dacde243b
diff --git a/services/sensorservice/SensorEventConnection.cpp b/services/sensorservice/SensorEventConnection.cpp
index bfe4c09..0a05dd1 100644
--- a/services/sensorservice/SensorEventConnection.cpp
+++ b/services/sensorservice/SensorEventConnection.cpp
@@ -32,7 +32,8 @@
const String16& opPackageName)
: mService(service), mUid(uid), mWakeLockRefCount(0), mHasLooperCallbacks(false),
mDead(false), mDataInjectionMode(isDataInjectionMode), mEventCache(NULL),
- mCacheSize(0), mMaxCacheSize(0), mPackageName(packageName), mOpPackageName(opPackageName) {
+ mCacheSize(0), mMaxCacheSize(0), mPackageName(packageName), mOpPackageName(opPackageName),
+ mDestroyed(false) {
mChannel = new BitTube(mService->mSocketBufferSize);
#if DEBUG_CONNECTIONS
mEventsReceived = mEventsSentFromCache = mEventsSent = 0;
@@ -42,10 +43,22 @@
SensorService::SensorEventConnection::~SensorEventConnection() {
ALOGD_IF(DEBUG_CONNECTIONS, "~SensorEventConnection(%p)", this);
+ destroy();
+}
+
+void SensorService::SensorEventConnection::destroy() {
+ Mutex::Autolock _l(mDestroyLock);
+
+ // destroy once only
+ if (mDestroyed) {
+ return;
+ }
+
mService->cleanupConnection(this);
if (mEventCache != NULL) {
delete mEventCache;
}
+ mDestroyed = true;
}
void SensorService::SensorEventConnection::onFirstRef() {