Loading libs/sensor/ISensorEventConnection.cpp +18 −2 Original line number Diff line number Diff line Loading @@ -36,7 +36,8 @@ enum { ENABLE_DISABLE, SET_EVENT_RATE, FLUSH_SENSOR, CONFIGURE_CHANNEL CONFIGURE_CHANNEL, DESTROY, }; class BpSensorEventConnection : public BpInterface<ISensorEventConnection> Loading Loading @@ -96,6 +97,17 @@ public: remote()->transact(CONFIGURE_CHANNEL, data, &reply); return reply.readInt32(); } virtual void onLastStrongRef(const void* id) { destroy(); BpInterface<ISensorEventConnection>::onLastStrongRef(id); } protected: virtual void destroy() { Parcel data, reply; remote()->transact(DESTROY, data, &reply); } }; // Out-of-line virtual method definition to trigger vtable emission in this Loading Loading @@ -150,6 +162,10 @@ status_t BnSensorEventConnection::onTransact( reply->writeInt32(result); return NO_ERROR; } case DESTROY: { destroy(); return NO_ERROR; } } return BBinder::onTransact(code, data, reply, flags); Loading libs/sensor/include/sensor/ISensorEventConnection.h +2 −0 Original line number Diff line number Diff line Loading @@ -42,6 +42,8 @@ public: virtual status_t setEventRate(int handle, nsecs_t ns) = 0; virtual status_t flush() = 0; virtual int32_t configureChannel(int32_t handle, int32_t rateLevel) = 0; protected: virtual void destroy() = 0; // synchronously release resource hold by remote object }; // ---------------------------------------------------------------------------- Loading services/sensorservice/SensorDirectConnection.cpp +11 −1 Original line number Diff line number Diff line Loading @@ -27,12 +27,21 @@ SensorService::SensorDirectConnection::SensorDirectConnection(const sp<SensorSer const String16& opPackageName) : mService(service), mUid(uid), mMem(*mem), mHalChannelHandle(halChannelHandle), mOpPackageName(opPackageName) { mOpPackageName(opPackageName), mDestroyed(false) { ALOGD_IF(DEBUG_CONNECTIONS, "Created SensorDirectConnection"); } SensorService::SensorDirectConnection::~SensorDirectConnection() { ALOGD_IF(DEBUG_CONNECTIONS, "~SensorDirectConnection %p", this); destroy(); } void SensorService::SensorDirectConnection::destroy() { Mutex::Autolock _l(mDestroyLock); // destroy once only if (mDestroyed) { return; } stopAll(); mService->cleanupConnection(this); Loading @@ -40,6 +49,7 @@ SensorService::SensorDirectConnection::~SensorDirectConnection() { native_handle_close(mMem.handle); native_handle_delete(const_cast<struct native_handle*>(mMem.handle)); } mDestroyed = true; } void SensorService::SensorDirectConnection::onFirstRef() { Loading services/sensorservice/SensorDirectConnection.h +5 −2 Original line number Diff line number Diff line Loading @@ -47,7 +47,7 @@ public: // stop all active sensor report. if backupRecord is set to false, // those report can be recovered by recoverAll // called by SensorService when enter restricted mode void stopAll(bool clearRecord = false); void stopAll(bool backupRecord = false); // recover sensor reports previously stopped by stopAll(true) // called by SensorService when return to NORMAL mode. Loading @@ -63,7 +63,7 @@ protected: virtual status_t setEventRate(int handle, nsecs_t samplingPeriodNs); virtual status_t flush(); virtual int32_t configureChannel(int handle, int rateLevel); virtual void destroy(); private: const sp<SensorService> mService; const uid_t mUid; Loading @@ -74,6 +74,9 @@ private: mutable Mutex mConnectionLock; std::unordered_map<int, int> mActivated; std::unordered_map<int, int> mActivatedBackup; mutable Mutex mDestroyLock; bool mDestroyed; }; } // namepsace android Loading services/sensorservice/SensorEventConnection.cpp +14 −1 Original line number Diff line number Diff line Loading @@ -32,7 +32,8 @@ SensorService::SensorEventConnection::SensorEventConnection( 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; Loading @@ -42,10 +43,22 @@ SensorService::SensorEventConnection::SensorEventConnection( 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() { Loading Loading
libs/sensor/ISensorEventConnection.cpp +18 −2 Original line number Diff line number Diff line Loading @@ -36,7 +36,8 @@ enum { ENABLE_DISABLE, SET_EVENT_RATE, FLUSH_SENSOR, CONFIGURE_CHANNEL CONFIGURE_CHANNEL, DESTROY, }; class BpSensorEventConnection : public BpInterface<ISensorEventConnection> Loading Loading @@ -96,6 +97,17 @@ public: remote()->transact(CONFIGURE_CHANNEL, data, &reply); return reply.readInt32(); } virtual void onLastStrongRef(const void* id) { destroy(); BpInterface<ISensorEventConnection>::onLastStrongRef(id); } protected: virtual void destroy() { Parcel data, reply; remote()->transact(DESTROY, data, &reply); } }; // Out-of-line virtual method definition to trigger vtable emission in this Loading Loading @@ -150,6 +162,10 @@ status_t BnSensorEventConnection::onTransact( reply->writeInt32(result); return NO_ERROR; } case DESTROY: { destroy(); return NO_ERROR; } } return BBinder::onTransact(code, data, reply, flags); Loading
libs/sensor/include/sensor/ISensorEventConnection.h +2 −0 Original line number Diff line number Diff line Loading @@ -42,6 +42,8 @@ public: virtual status_t setEventRate(int handle, nsecs_t ns) = 0; virtual status_t flush() = 0; virtual int32_t configureChannel(int32_t handle, int32_t rateLevel) = 0; protected: virtual void destroy() = 0; // synchronously release resource hold by remote object }; // ---------------------------------------------------------------------------- Loading
services/sensorservice/SensorDirectConnection.cpp +11 −1 Original line number Diff line number Diff line Loading @@ -27,12 +27,21 @@ SensorService::SensorDirectConnection::SensorDirectConnection(const sp<SensorSer const String16& opPackageName) : mService(service), mUid(uid), mMem(*mem), mHalChannelHandle(halChannelHandle), mOpPackageName(opPackageName) { mOpPackageName(opPackageName), mDestroyed(false) { ALOGD_IF(DEBUG_CONNECTIONS, "Created SensorDirectConnection"); } SensorService::SensorDirectConnection::~SensorDirectConnection() { ALOGD_IF(DEBUG_CONNECTIONS, "~SensorDirectConnection %p", this); destroy(); } void SensorService::SensorDirectConnection::destroy() { Mutex::Autolock _l(mDestroyLock); // destroy once only if (mDestroyed) { return; } stopAll(); mService->cleanupConnection(this); Loading @@ -40,6 +49,7 @@ SensorService::SensorDirectConnection::~SensorDirectConnection() { native_handle_close(mMem.handle); native_handle_delete(const_cast<struct native_handle*>(mMem.handle)); } mDestroyed = true; } void SensorService::SensorDirectConnection::onFirstRef() { Loading
services/sensorservice/SensorDirectConnection.h +5 −2 Original line number Diff line number Diff line Loading @@ -47,7 +47,7 @@ public: // stop all active sensor report. if backupRecord is set to false, // those report can be recovered by recoverAll // called by SensorService when enter restricted mode void stopAll(bool clearRecord = false); void stopAll(bool backupRecord = false); // recover sensor reports previously stopped by stopAll(true) // called by SensorService when return to NORMAL mode. Loading @@ -63,7 +63,7 @@ protected: virtual status_t setEventRate(int handle, nsecs_t samplingPeriodNs); virtual status_t flush(); virtual int32_t configureChannel(int handle, int rateLevel); virtual void destroy(); private: const sp<SensorService> mService; const uid_t mUid; Loading @@ -74,6 +74,9 @@ private: mutable Mutex mConnectionLock; std::unordered_map<int, int> mActivated; std::unordered_map<int, int> mActivatedBackup; mutable Mutex mDestroyLock; bool mDestroyed; }; } // namepsace android Loading
services/sensorservice/SensorEventConnection.cpp +14 −1 Original line number Diff line number Diff line Loading @@ -32,7 +32,8 @@ SensorService::SensorEventConnection::SensorEventConnection( 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; Loading @@ -42,10 +43,22 @@ SensorService::SensorEventConnection::SensorEventConnection( 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() { Loading