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