Loading services/sensorservice/SensorDevice.cpp +1 −1 Original line number Original line Diff line number Diff line Loading @@ -89,7 +89,7 @@ void SensorDevice::dump(String8& result) result.appendFormat("handle=0x%08x, active-count=%zu, batch_period(ms)={ ", list[i].handle, result.appendFormat("handle=0x%08x, active-count=%zu, batch_period(ms)={ ", list[i].handle, info.batchParams.size()); info.batchParams.size()); for (size_t j = 0; j < info.batchParams.size(); j++) { for (size_t j = 0; j < info.batchParams.size(); j++) { BatchParams params = info.batchParams.valueAt(j); const BatchParams& params = info.batchParams.valueAt(j); result.appendFormat("%4.1f%s", params.batchDelay / 1e6f, result.appendFormat("%4.1f%s", params.batchDelay / 1e6f, j < info.batchParams.size() - 1 ? ", " : ""); j < info.batchParams.size() - 1 ? ", " : ""); } } Loading services/sensorservice/SensorService.cpp +110 −21 Original line number Original line Diff line number Diff line Loading @@ -195,9 +195,14 @@ void SensorService::onFirstRef() mMapFlushEventsToConnections = new SensorEventConnection const * [minBufferSize]; mMapFlushEventsToConnections = new SensorEventConnection const * [minBufferSize]; mCurrentOperatingMode = NORMAL; mCurrentOperatingMode = NORMAL; mNextSensorRegIndex = 0; for (int i = 0; i < SENSOR_REGISTRATIONS_BUF_SIZE; ++i) { mLastNSensorRegistrations.push(); } mInitCheck = NO_ERROR; mAckReceiver = new SensorEventAckReceiver(this); mAckReceiver = new SensorEventAckReceiver(this); mAckReceiver->run("SensorEventAckReceiver", PRIORITY_URGENT_DISPLAY); mAckReceiver->run("SensorEventAckReceiver", PRIORITY_URGENT_DISPLAY); mInitCheck = NO_ERROR; run("SensorService", PRIORITY_URGENT_DISPLAY); run("SensorService", PRIORITY_URGENT_DISPLAY); } } } } Loading Loading @@ -322,12 +327,15 @@ status_t SensorService::dump(int fd, const Vector<String16>& args) result.appendFormat("non-wakeUp | "); result.appendFormat("non-wakeUp | "); } } const CircularBuffer* buf = mLastEventSeen.valueFor(s.getHandle()); int bufIndex = mLastEventSeen.indexOfKey(s.getHandle()); if (bufIndex >= 0) { const CircularBuffer* buf = mLastEventSeen.valueAt(bufIndex); if (buf != NULL && s.getRequiredPermission().isEmpty()) { if (buf != NULL && s.getRequiredPermission().isEmpty()) { buf->printBuffer(result); buf->printBuffer(result); } else { } else { result.append("last=<> \n"); result.append("last=<> \n"); } } } result.append("\n"); result.append("\n"); } } SensorFusion::getInstance().dump(result); SensorFusion::getInstance().dump(result); Loading @@ -344,7 +352,8 @@ status_t SensorService::dump(int fd, const Vector<String16>& args) result.appendFormat("Socket Buffer size = %d events\n", result.appendFormat("Socket Buffer size = %d events\n", mSocketBufferSize/sizeof(sensors_event_t)); mSocketBufferSize/sizeof(sensors_event_t)); result.appendFormat("WakeLock Status: %s \n", mWakeLockAcquired ? "acquired" : "not held"); result.appendFormat("WakeLock Status: %s \n", mWakeLockAcquired ? "acquired" : "not held"); result.appendFormat("Mode :"); result.appendFormat("Mode :"); switch(mCurrentOperatingMode) { switch(mCurrentOperatingMode) { case NORMAL: case NORMAL: Loading @@ -365,6 +374,34 @@ status_t SensorService::dump(int fd, const Vector<String16>& args) connection->dump(result); connection->dump(result); } } } } result.appendFormat("Previous Registrations:\n"); // Log in the reverse chronological order. int currentIndex = (mNextSensorRegIndex - 1 + SENSOR_REGISTRATIONS_BUF_SIZE) % SENSOR_REGISTRATIONS_BUF_SIZE; const int startIndex = currentIndex; do { const SensorRegistrationInfo& reg_info = mLastNSensorRegistrations[currentIndex]; if (SensorRegistrationInfo::isSentinel(reg_info)) { // Ignore sentinel, proceed to next item. currentIndex = (currentIndex - 1 + SENSOR_REGISTRATIONS_BUF_SIZE) % SENSOR_REGISTRATIONS_BUF_SIZE; continue; } if (reg_info.mActivated) { result.appendFormat("%02d:%02d:%02d activated package=%s handle=0x%08x " "samplingRate=%dus maxReportLatency=%dus\n", reg_info.mHour, reg_info.mMin, reg_info.mSec, reg_info.mPackageName.string(), reg_info.mSensorHandle, reg_info.mSamplingRateUs, reg_info.mMaxReportLatencyUs); } else { result.appendFormat("%02d:%02d:%02d de-activated package=%s handle=0x%08x\n", reg_info.mHour, reg_info.mMin, reg_info.mSec, reg_info.mPackageName.string(), reg_info.mSensorHandle); } currentIndex = (currentIndex - 1 + SENSOR_REGISTRATIONS_BUF_SIZE) % SENSOR_REGISTRATIONS_BUF_SIZE; } while(startIndex != currentIndex); } } } } write(fd, result.string(), result.size()); write(fd, result.string(), result.size()); Loading Loading @@ -888,6 +925,19 @@ status_t SensorService::enable(const sp<SensorEventConnection>& connection, if (err == NO_ERROR) { if (err == NO_ERROR) { connection->updateLooperRegistration(mLooper); connection->updateLooperRegistration(mLooper); SensorRegistrationInfo ®_info = mLastNSensorRegistrations.editItemAt(mNextSensorRegIndex); reg_info.mSensorHandle = handle; reg_info.mSamplingRateUs = samplingPeriodNs/1000; reg_info.mMaxReportLatencyUs = maxBatchReportLatencyNs/1000; reg_info.mActivated = true; reg_info.mPackageName = connection->getPackageName(); time_t rawtime = time(NULL); struct tm * timeinfo = localtime(&rawtime); reg_info.mHour = timeinfo->tm_hour; reg_info.mMin = timeinfo->tm_min; reg_info.mSec = timeinfo->tm_sec; mNextSensorRegIndex = (mNextSensorRegIndex + 1) % SENSOR_REGISTRATIONS_BUF_SIZE; } } if (err != NO_ERROR) { if (err != NO_ERROR) { Loading @@ -908,6 +958,20 @@ status_t SensorService::disable(const sp<SensorEventConnection>& connection, if (err == NO_ERROR) { if (err == NO_ERROR) { SensorInterface* sensor = mSensorMap.valueFor(handle); SensorInterface* sensor = mSensorMap.valueFor(handle); err = sensor ? sensor->activate(connection.get(), false) : status_t(BAD_VALUE); err = sensor ? sensor->activate(connection.get(), false) : status_t(BAD_VALUE); } if (err == NO_ERROR) { SensorRegistrationInfo ®_info = mLastNSensorRegistrations.editItemAt(mNextSensorRegIndex); reg_info.mActivated = false; reg_info.mPackageName= connection->getPackageName(); reg_info.mSensorHandle = handle; time_t rawtime = time(NULL); struct tm * timeinfo = localtime(&rawtime); reg_info.mHour = timeinfo->tm_hour; reg_info.mMin = timeinfo->tm_min; reg_info.mSec = timeinfo->tm_sec; mNextSensorRegIndex = (mNextSensorRegIndex + 1) % SENSOR_REGISTRATIONS_BUF_SIZE; } } return err; return err; } } Loading Loading @@ -1180,14 +1244,38 @@ void SensorService::SensorRecord::clearAllPendingFlushConnections() { mPendingFlushConnections.clear(); mPendingFlushConnections.clear(); } } // --------------------------------------------------------------------------- SensorService::TrimmedSensorEvent::TrimmedSensorEvent(int sensorType) { mTimestamp = -1; const int numData = SensorService::getNumEventsForSensorType(sensorType); if (sensorType == SENSOR_TYPE_STEP_COUNTER) { mStepCounter = 0; } else { mData = new float[numData]; for (int i = 0; i < numData; ++i) { mData[i] = -1.0; } } mHour = mMin = mSec = INT32_MIN; } bool SensorService::TrimmedSensorEvent::isSentinel(const TrimmedSensorEvent& event) { return (event.mHour == INT32_MIN && event.mMin == INT32_MIN && event.mSec == INT32_MIN); } // -------------------------------------------------------------------------- // -------------------------------------------------------------------------- SensorService::CircularBuffer::CircularBuffer(int sensor_event_type) { SensorService::CircularBuffer::CircularBuffer(int sensor_event_type) { mNextInd = 0; mNextInd = 0; mTrimmedSensorEventArr = new TrimmedSensorEvent *[CIRCULAR_BUF_SIZE]; mBufSize = CIRCULAR_BUF_SIZE; if (sensor_event_type == SENSOR_TYPE_STEP_COUNTER || sensor_event_type == SENSOR_TYPE_SIGNIFICANT_MOTION || sensor_event_type == SENSOR_TYPE_ACCELEROMETER) { mBufSize = CIRCULAR_BUF_SIZE * 5; } mTrimmedSensorEventArr = new TrimmedSensorEvent *[mBufSize]; mSensorType = sensor_event_type; mSensorType = sensor_event_type; const int numData = SensorService::getNumEventsForSensorType(mSensorType); for (int i = 0; i < mBufSize; ++i) { for (int i = 0; i < CIRCULAR_BUF_SIZE; ++i) { mTrimmedSensorEventArr[i] = new TrimmedSensorEvent(mSensorType); mTrimmedSensorEventArr[i] = new TrimmedSensorEvent(numData, mSensorType); } } } } Loading @@ -1205,17 +1293,17 @@ void SensorService::CircularBuffer::addEvent(const sensors_event_t& sensor_event curr_event->mHour = timeinfo->tm_hour; curr_event->mHour = timeinfo->tm_hour; curr_event->mMin = timeinfo->tm_min; curr_event->mMin = timeinfo->tm_min; curr_event->mSec = timeinfo->tm_sec; curr_event->mSec = timeinfo->tm_sec; mNextInd = (mNextInd + 1) % CIRCULAR_BUF_SIZE; mNextInd = (mNextInd + 1) % mBufSize; } } void SensorService::CircularBuffer::printBuffer(String8& result) const { void SensorService::CircularBuffer::printBuffer(String8& result) const { const int numData = SensorService::getNumEventsForSensorType(mSensorType); const int numData = SensorService::getNumEventsForSensorType(mSensorType); int i = mNextInd, eventNum = 1; int i = mNextInd, eventNum = 1; result.appendFormat("last %d events = < ", CIRCULAR_BUF_SIZE); result.appendFormat("last %d events = < ", mBufSize); do { do { if (mTrimmedSensorEventArr[i]->mTimestamp == -1) { if (TrimmedSensorEvent::isSentinel(*mTrimmedSensorEventArr[i])) { // Sentinel, ignore. // Sentinel, ignore. i = (i + 1) % CIRCULAR_BUF_SIZE; i = (i + 1) % mBufSize; continue; continue; } } result.appendFormat("%d) ", eventNum++); result.appendFormat("%d) ", eventNum++); Loading @@ -1229,15 +1317,15 @@ void SensorService::CircularBuffer::printBuffer(String8& result) const { result.appendFormat("%lld %02d:%02d:%02d ", mTrimmedSensorEventArr[i]->mTimestamp, result.appendFormat("%lld %02d:%02d:%02d ", mTrimmedSensorEventArr[i]->mTimestamp, mTrimmedSensorEventArr[i]->mHour, mTrimmedSensorEventArr[i]->mMin, mTrimmedSensorEventArr[i]->mHour, mTrimmedSensorEventArr[i]->mMin, mTrimmedSensorEventArr[i]->mSec); mTrimmedSensorEventArr[i]->mSec); i = (i + 1) % CIRCULAR_BUF_SIZE; i = (i + 1) % mBufSize; } while (i != mNextInd); } while (i != mNextInd); result.appendFormat(">\n"); result.appendFormat(">\n"); } } bool SensorService::CircularBuffer::populateLastEvent(sensors_event_t *event) { bool SensorService::CircularBuffer::populateLastEvent(sensors_event_t *event) { int lastEventInd = (mNextInd - 1 + CIRCULAR_BUF_SIZE) % CIRCULAR_BUF_SIZE; int lastEventInd = (mNextInd - 1 + mBufSize) % mBufSize; // Check if the buffer is empty. // Check if the buffer is empty. if (mTrimmedSensorEventArr[lastEventInd]->mTimestamp == -1) { if (TrimmedSensorEvent::isSentinel(*mTrimmedSensorEventArr[lastEventInd])) { return false; return false; } } event->version = sizeof(sensors_event_t); event->version = sizeof(sensors_event_t); Loading @@ -1253,7 +1341,7 @@ bool SensorService::CircularBuffer::populateLastEvent(sensors_event_t *event) { } } SensorService::CircularBuffer::~CircularBuffer() { SensorService::CircularBuffer::~CircularBuffer() { for (int i = 0; i < CIRCULAR_BUF_SIZE; ++i) { for (int i = 0; i < mBufSize; ++i) { delete mTrimmedSensorEventArr[i]; delete mTrimmedSensorEventArr[i]; } } delete [] mTrimmedSensorEventArr; delete [] mTrimmedSensorEventArr; Loading Loading @@ -1299,8 +1387,9 @@ void SensorService::SensorEventConnection::resetWakeLockRefCount() { void SensorService::SensorEventConnection::dump(String8& result) { void SensorService::SensorEventConnection::dump(String8& result) { Mutex::Autolock _l(mConnectionLock); Mutex::Autolock _l(mConnectionLock); result.appendFormat("Operating Mode: %s\n", mDataInjectionMode ? "DATA_INJECTION" : "NORMAL"); result.appendFormat("Operating Mode: %s\n", mDataInjectionMode ? "DATA_INJECTION" : "NORMAL"); result.appendFormat("\t%s | WakeLockRefCount %d | uid %d | cache size %d | max cache size %d\n", result.appendFormat("\t %s | WakeLockRefCount %d | uid %d | cache size %d | " mPackageName.string(), mWakeLockRefCount, mUid, mCacheSize, mMaxCacheSize); "max cache size %d\n", mPackageName.string(), mWakeLockRefCount, mUid, mCacheSize, mMaxCacheSize); for (size_t i = 0; i < mSensorInfo.size(); ++i) { for (size_t i = 0; i < mSensorInfo.size(); ++i) { const FlushInfo& flushInfo = mSensorInfo.valueAt(i); const FlushInfo& flushInfo = mSensorInfo.valueAt(i); result.appendFormat("\t %s 0x%08x | status: %s | pending flush events %d \n", result.appendFormat("\t %s 0x%08x | status: %s | pending flush events %d \n", Loading services/sensorservice/SensorService.h +25 −12 Original line number Original line Diff line number Diff line Loading @@ -54,6 +54,7 @@ #define SOCKET_BUFFER_SIZE_NON_BATCHED 4 * 1024 #define SOCKET_BUFFER_SIZE_NON_BATCHED 4 * 1024 #define CIRCULAR_BUF_SIZE 10 #define CIRCULAR_BUF_SIZE 10 #define SENSOR_REGISTRATIONS_BUF_SIZE 20 struct sensors_poll_device_t; struct sensors_poll_device_t; struct sensors_module_t; struct sensors_module_t; Loading Loading @@ -272,18 +273,8 @@ class SensorService : // for debugging. // for debugging. int32_t mHour, mMin, mSec; int32_t mHour, mMin, mSec; TrimmedSensorEvent(int numData, int sensorType) { TrimmedSensorEvent(int sensorType); mTimestamp = -1; static bool isSentinel(const TrimmedSensorEvent& event); if (sensorType == SENSOR_TYPE_STEP_COUNTER) { mStepCounter = 0; } else { mData = new float[numData]; for (int i = 0; i < numData; ++i) { mData[i] = -1.0; } } mHour = mMin = mSec = 0; } ~TrimmedSensorEvent() { ~TrimmedSensorEvent() { delete [] mData; delete [] mData; Loading @@ -297,6 +288,7 @@ class SensorService : class CircularBuffer { class CircularBuffer { int mNextInd; int mNextInd; int mSensorType; int mSensorType; int mBufSize; TrimmedSensorEvent ** mTrimmedSensorEventArr; TrimmedSensorEvent ** mTrimmedSensorEventArr; public: public: CircularBuffer(int sensor_event_type); CircularBuffer(int sensor_event_type); Loading @@ -306,6 +298,25 @@ class SensorService : ~CircularBuffer(); ~CircularBuffer(); }; }; struct SensorRegistrationInfo { int32_t mSensorHandle; String8 mPackageName; bool mActivated; int32_t mSamplingRateUs; int32_t mMaxReportLatencyUs; int32_t mHour, mMin, mSec; SensorRegistrationInfo() : mPackageName() { mSensorHandle = mSamplingRateUs = mMaxReportLatencyUs = INT32_MIN; mHour = mMin = mSec = INT32_MIN; mActivated = false; } static bool isSentinel(const SensorRegistrationInfo& info) { return (info.mHour == INT32_MIN && info.mMin == INT32_MIN && info.mSec == INT32_MIN); } }; static int getNumEventsForSensorType(int sensor_event_type); static int getNumEventsForSensorType(int sensor_event_type); String8 getSensorName(int handle) const; String8 getSensorName(int handle) const; bool isVirtualSensor(int handle) const; bool isVirtualSensor(int handle) const; Loading Loading @@ -387,6 +398,8 @@ class SensorService : // The size of this vector is constant, only the items are mutable // The size of this vector is constant, only the items are mutable KeyedVector<int32_t, CircularBuffer *> mLastEventSeen; KeyedVector<int32_t, CircularBuffer *> mLastEventSeen; int mNextSensorRegIndex; Vector<SensorRegistrationInfo> mLastNSensorRegistrations; public: public: void cleanupConnection(SensorEventConnection* connection); void cleanupConnection(SensorEventConnection* connection); status_t enable(const sp<SensorEventConnection>& connection, int handle, status_t enable(const sp<SensorEventConnection>& connection, int handle, Loading Loading
services/sensorservice/SensorDevice.cpp +1 −1 Original line number Original line Diff line number Diff line Loading @@ -89,7 +89,7 @@ void SensorDevice::dump(String8& result) result.appendFormat("handle=0x%08x, active-count=%zu, batch_period(ms)={ ", list[i].handle, result.appendFormat("handle=0x%08x, active-count=%zu, batch_period(ms)={ ", list[i].handle, info.batchParams.size()); info.batchParams.size()); for (size_t j = 0; j < info.batchParams.size(); j++) { for (size_t j = 0; j < info.batchParams.size(); j++) { BatchParams params = info.batchParams.valueAt(j); const BatchParams& params = info.batchParams.valueAt(j); result.appendFormat("%4.1f%s", params.batchDelay / 1e6f, result.appendFormat("%4.1f%s", params.batchDelay / 1e6f, j < info.batchParams.size() - 1 ? ", " : ""); j < info.batchParams.size() - 1 ? ", " : ""); } } Loading
services/sensorservice/SensorService.cpp +110 −21 Original line number Original line Diff line number Diff line Loading @@ -195,9 +195,14 @@ void SensorService::onFirstRef() mMapFlushEventsToConnections = new SensorEventConnection const * [minBufferSize]; mMapFlushEventsToConnections = new SensorEventConnection const * [minBufferSize]; mCurrentOperatingMode = NORMAL; mCurrentOperatingMode = NORMAL; mNextSensorRegIndex = 0; for (int i = 0; i < SENSOR_REGISTRATIONS_BUF_SIZE; ++i) { mLastNSensorRegistrations.push(); } mInitCheck = NO_ERROR; mAckReceiver = new SensorEventAckReceiver(this); mAckReceiver = new SensorEventAckReceiver(this); mAckReceiver->run("SensorEventAckReceiver", PRIORITY_URGENT_DISPLAY); mAckReceiver->run("SensorEventAckReceiver", PRIORITY_URGENT_DISPLAY); mInitCheck = NO_ERROR; run("SensorService", PRIORITY_URGENT_DISPLAY); run("SensorService", PRIORITY_URGENT_DISPLAY); } } } } Loading Loading @@ -322,12 +327,15 @@ status_t SensorService::dump(int fd, const Vector<String16>& args) result.appendFormat("non-wakeUp | "); result.appendFormat("non-wakeUp | "); } } const CircularBuffer* buf = mLastEventSeen.valueFor(s.getHandle()); int bufIndex = mLastEventSeen.indexOfKey(s.getHandle()); if (bufIndex >= 0) { const CircularBuffer* buf = mLastEventSeen.valueAt(bufIndex); if (buf != NULL && s.getRequiredPermission().isEmpty()) { if (buf != NULL && s.getRequiredPermission().isEmpty()) { buf->printBuffer(result); buf->printBuffer(result); } else { } else { result.append("last=<> \n"); result.append("last=<> \n"); } } } result.append("\n"); result.append("\n"); } } SensorFusion::getInstance().dump(result); SensorFusion::getInstance().dump(result); Loading @@ -344,7 +352,8 @@ status_t SensorService::dump(int fd, const Vector<String16>& args) result.appendFormat("Socket Buffer size = %d events\n", result.appendFormat("Socket Buffer size = %d events\n", mSocketBufferSize/sizeof(sensors_event_t)); mSocketBufferSize/sizeof(sensors_event_t)); result.appendFormat("WakeLock Status: %s \n", mWakeLockAcquired ? "acquired" : "not held"); result.appendFormat("WakeLock Status: %s \n", mWakeLockAcquired ? "acquired" : "not held"); result.appendFormat("Mode :"); result.appendFormat("Mode :"); switch(mCurrentOperatingMode) { switch(mCurrentOperatingMode) { case NORMAL: case NORMAL: Loading @@ -365,6 +374,34 @@ status_t SensorService::dump(int fd, const Vector<String16>& args) connection->dump(result); connection->dump(result); } } } } result.appendFormat("Previous Registrations:\n"); // Log in the reverse chronological order. int currentIndex = (mNextSensorRegIndex - 1 + SENSOR_REGISTRATIONS_BUF_SIZE) % SENSOR_REGISTRATIONS_BUF_SIZE; const int startIndex = currentIndex; do { const SensorRegistrationInfo& reg_info = mLastNSensorRegistrations[currentIndex]; if (SensorRegistrationInfo::isSentinel(reg_info)) { // Ignore sentinel, proceed to next item. currentIndex = (currentIndex - 1 + SENSOR_REGISTRATIONS_BUF_SIZE) % SENSOR_REGISTRATIONS_BUF_SIZE; continue; } if (reg_info.mActivated) { result.appendFormat("%02d:%02d:%02d activated package=%s handle=0x%08x " "samplingRate=%dus maxReportLatency=%dus\n", reg_info.mHour, reg_info.mMin, reg_info.mSec, reg_info.mPackageName.string(), reg_info.mSensorHandle, reg_info.mSamplingRateUs, reg_info.mMaxReportLatencyUs); } else { result.appendFormat("%02d:%02d:%02d de-activated package=%s handle=0x%08x\n", reg_info.mHour, reg_info.mMin, reg_info.mSec, reg_info.mPackageName.string(), reg_info.mSensorHandle); } currentIndex = (currentIndex - 1 + SENSOR_REGISTRATIONS_BUF_SIZE) % SENSOR_REGISTRATIONS_BUF_SIZE; } while(startIndex != currentIndex); } } } } write(fd, result.string(), result.size()); write(fd, result.string(), result.size()); Loading Loading @@ -888,6 +925,19 @@ status_t SensorService::enable(const sp<SensorEventConnection>& connection, if (err == NO_ERROR) { if (err == NO_ERROR) { connection->updateLooperRegistration(mLooper); connection->updateLooperRegistration(mLooper); SensorRegistrationInfo ®_info = mLastNSensorRegistrations.editItemAt(mNextSensorRegIndex); reg_info.mSensorHandle = handle; reg_info.mSamplingRateUs = samplingPeriodNs/1000; reg_info.mMaxReportLatencyUs = maxBatchReportLatencyNs/1000; reg_info.mActivated = true; reg_info.mPackageName = connection->getPackageName(); time_t rawtime = time(NULL); struct tm * timeinfo = localtime(&rawtime); reg_info.mHour = timeinfo->tm_hour; reg_info.mMin = timeinfo->tm_min; reg_info.mSec = timeinfo->tm_sec; mNextSensorRegIndex = (mNextSensorRegIndex + 1) % SENSOR_REGISTRATIONS_BUF_SIZE; } } if (err != NO_ERROR) { if (err != NO_ERROR) { Loading @@ -908,6 +958,20 @@ status_t SensorService::disable(const sp<SensorEventConnection>& connection, if (err == NO_ERROR) { if (err == NO_ERROR) { SensorInterface* sensor = mSensorMap.valueFor(handle); SensorInterface* sensor = mSensorMap.valueFor(handle); err = sensor ? sensor->activate(connection.get(), false) : status_t(BAD_VALUE); err = sensor ? sensor->activate(connection.get(), false) : status_t(BAD_VALUE); } if (err == NO_ERROR) { SensorRegistrationInfo ®_info = mLastNSensorRegistrations.editItemAt(mNextSensorRegIndex); reg_info.mActivated = false; reg_info.mPackageName= connection->getPackageName(); reg_info.mSensorHandle = handle; time_t rawtime = time(NULL); struct tm * timeinfo = localtime(&rawtime); reg_info.mHour = timeinfo->tm_hour; reg_info.mMin = timeinfo->tm_min; reg_info.mSec = timeinfo->tm_sec; mNextSensorRegIndex = (mNextSensorRegIndex + 1) % SENSOR_REGISTRATIONS_BUF_SIZE; } } return err; return err; } } Loading Loading @@ -1180,14 +1244,38 @@ void SensorService::SensorRecord::clearAllPendingFlushConnections() { mPendingFlushConnections.clear(); mPendingFlushConnections.clear(); } } // --------------------------------------------------------------------------- SensorService::TrimmedSensorEvent::TrimmedSensorEvent(int sensorType) { mTimestamp = -1; const int numData = SensorService::getNumEventsForSensorType(sensorType); if (sensorType == SENSOR_TYPE_STEP_COUNTER) { mStepCounter = 0; } else { mData = new float[numData]; for (int i = 0; i < numData; ++i) { mData[i] = -1.0; } } mHour = mMin = mSec = INT32_MIN; } bool SensorService::TrimmedSensorEvent::isSentinel(const TrimmedSensorEvent& event) { return (event.mHour == INT32_MIN && event.mMin == INT32_MIN && event.mSec == INT32_MIN); } // -------------------------------------------------------------------------- // -------------------------------------------------------------------------- SensorService::CircularBuffer::CircularBuffer(int sensor_event_type) { SensorService::CircularBuffer::CircularBuffer(int sensor_event_type) { mNextInd = 0; mNextInd = 0; mTrimmedSensorEventArr = new TrimmedSensorEvent *[CIRCULAR_BUF_SIZE]; mBufSize = CIRCULAR_BUF_SIZE; if (sensor_event_type == SENSOR_TYPE_STEP_COUNTER || sensor_event_type == SENSOR_TYPE_SIGNIFICANT_MOTION || sensor_event_type == SENSOR_TYPE_ACCELEROMETER) { mBufSize = CIRCULAR_BUF_SIZE * 5; } mTrimmedSensorEventArr = new TrimmedSensorEvent *[mBufSize]; mSensorType = sensor_event_type; mSensorType = sensor_event_type; const int numData = SensorService::getNumEventsForSensorType(mSensorType); for (int i = 0; i < mBufSize; ++i) { for (int i = 0; i < CIRCULAR_BUF_SIZE; ++i) { mTrimmedSensorEventArr[i] = new TrimmedSensorEvent(mSensorType); mTrimmedSensorEventArr[i] = new TrimmedSensorEvent(numData, mSensorType); } } } } Loading @@ -1205,17 +1293,17 @@ void SensorService::CircularBuffer::addEvent(const sensors_event_t& sensor_event curr_event->mHour = timeinfo->tm_hour; curr_event->mHour = timeinfo->tm_hour; curr_event->mMin = timeinfo->tm_min; curr_event->mMin = timeinfo->tm_min; curr_event->mSec = timeinfo->tm_sec; curr_event->mSec = timeinfo->tm_sec; mNextInd = (mNextInd + 1) % CIRCULAR_BUF_SIZE; mNextInd = (mNextInd + 1) % mBufSize; } } void SensorService::CircularBuffer::printBuffer(String8& result) const { void SensorService::CircularBuffer::printBuffer(String8& result) const { const int numData = SensorService::getNumEventsForSensorType(mSensorType); const int numData = SensorService::getNumEventsForSensorType(mSensorType); int i = mNextInd, eventNum = 1; int i = mNextInd, eventNum = 1; result.appendFormat("last %d events = < ", CIRCULAR_BUF_SIZE); result.appendFormat("last %d events = < ", mBufSize); do { do { if (mTrimmedSensorEventArr[i]->mTimestamp == -1) { if (TrimmedSensorEvent::isSentinel(*mTrimmedSensorEventArr[i])) { // Sentinel, ignore. // Sentinel, ignore. i = (i + 1) % CIRCULAR_BUF_SIZE; i = (i + 1) % mBufSize; continue; continue; } } result.appendFormat("%d) ", eventNum++); result.appendFormat("%d) ", eventNum++); Loading @@ -1229,15 +1317,15 @@ void SensorService::CircularBuffer::printBuffer(String8& result) const { result.appendFormat("%lld %02d:%02d:%02d ", mTrimmedSensorEventArr[i]->mTimestamp, result.appendFormat("%lld %02d:%02d:%02d ", mTrimmedSensorEventArr[i]->mTimestamp, mTrimmedSensorEventArr[i]->mHour, mTrimmedSensorEventArr[i]->mMin, mTrimmedSensorEventArr[i]->mHour, mTrimmedSensorEventArr[i]->mMin, mTrimmedSensorEventArr[i]->mSec); mTrimmedSensorEventArr[i]->mSec); i = (i + 1) % CIRCULAR_BUF_SIZE; i = (i + 1) % mBufSize; } while (i != mNextInd); } while (i != mNextInd); result.appendFormat(">\n"); result.appendFormat(">\n"); } } bool SensorService::CircularBuffer::populateLastEvent(sensors_event_t *event) { bool SensorService::CircularBuffer::populateLastEvent(sensors_event_t *event) { int lastEventInd = (mNextInd - 1 + CIRCULAR_BUF_SIZE) % CIRCULAR_BUF_SIZE; int lastEventInd = (mNextInd - 1 + mBufSize) % mBufSize; // Check if the buffer is empty. // Check if the buffer is empty. if (mTrimmedSensorEventArr[lastEventInd]->mTimestamp == -1) { if (TrimmedSensorEvent::isSentinel(*mTrimmedSensorEventArr[lastEventInd])) { return false; return false; } } event->version = sizeof(sensors_event_t); event->version = sizeof(sensors_event_t); Loading @@ -1253,7 +1341,7 @@ bool SensorService::CircularBuffer::populateLastEvent(sensors_event_t *event) { } } SensorService::CircularBuffer::~CircularBuffer() { SensorService::CircularBuffer::~CircularBuffer() { for (int i = 0; i < CIRCULAR_BUF_SIZE; ++i) { for (int i = 0; i < mBufSize; ++i) { delete mTrimmedSensorEventArr[i]; delete mTrimmedSensorEventArr[i]; } } delete [] mTrimmedSensorEventArr; delete [] mTrimmedSensorEventArr; Loading Loading @@ -1299,8 +1387,9 @@ void SensorService::SensorEventConnection::resetWakeLockRefCount() { void SensorService::SensorEventConnection::dump(String8& result) { void SensorService::SensorEventConnection::dump(String8& result) { Mutex::Autolock _l(mConnectionLock); Mutex::Autolock _l(mConnectionLock); result.appendFormat("Operating Mode: %s\n", mDataInjectionMode ? "DATA_INJECTION" : "NORMAL"); result.appendFormat("Operating Mode: %s\n", mDataInjectionMode ? "DATA_INJECTION" : "NORMAL"); result.appendFormat("\t%s | WakeLockRefCount %d | uid %d | cache size %d | max cache size %d\n", result.appendFormat("\t %s | WakeLockRefCount %d | uid %d | cache size %d | " mPackageName.string(), mWakeLockRefCount, mUid, mCacheSize, mMaxCacheSize); "max cache size %d\n", mPackageName.string(), mWakeLockRefCount, mUid, mCacheSize, mMaxCacheSize); for (size_t i = 0; i < mSensorInfo.size(); ++i) { for (size_t i = 0; i < mSensorInfo.size(); ++i) { const FlushInfo& flushInfo = mSensorInfo.valueAt(i); const FlushInfo& flushInfo = mSensorInfo.valueAt(i); result.appendFormat("\t %s 0x%08x | status: %s | pending flush events %d \n", result.appendFormat("\t %s 0x%08x | status: %s | pending flush events %d \n", Loading
services/sensorservice/SensorService.h +25 −12 Original line number Original line Diff line number Diff line Loading @@ -54,6 +54,7 @@ #define SOCKET_BUFFER_SIZE_NON_BATCHED 4 * 1024 #define SOCKET_BUFFER_SIZE_NON_BATCHED 4 * 1024 #define CIRCULAR_BUF_SIZE 10 #define CIRCULAR_BUF_SIZE 10 #define SENSOR_REGISTRATIONS_BUF_SIZE 20 struct sensors_poll_device_t; struct sensors_poll_device_t; struct sensors_module_t; struct sensors_module_t; Loading Loading @@ -272,18 +273,8 @@ class SensorService : // for debugging. // for debugging. int32_t mHour, mMin, mSec; int32_t mHour, mMin, mSec; TrimmedSensorEvent(int numData, int sensorType) { TrimmedSensorEvent(int sensorType); mTimestamp = -1; static bool isSentinel(const TrimmedSensorEvent& event); if (sensorType == SENSOR_TYPE_STEP_COUNTER) { mStepCounter = 0; } else { mData = new float[numData]; for (int i = 0; i < numData; ++i) { mData[i] = -1.0; } } mHour = mMin = mSec = 0; } ~TrimmedSensorEvent() { ~TrimmedSensorEvent() { delete [] mData; delete [] mData; Loading @@ -297,6 +288,7 @@ class SensorService : class CircularBuffer { class CircularBuffer { int mNextInd; int mNextInd; int mSensorType; int mSensorType; int mBufSize; TrimmedSensorEvent ** mTrimmedSensorEventArr; TrimmedSensorEvent ** mTrimmedSensorEventArr; public: public: CircularBuffer(int sensor_event_type); CircularBuffer(int sensor_event_type); Loading @@ -306,6 +298,25 @@ class SensorService : ~CircularBuffer(); ~CircularBuffer(); }; }; struct SensorRegistrationInfo { int32_t mSensorHandle; String8 mPackageName; bool mActivated; int32_t mSamplingRateUs; int32_t mMaxReportLatencyUs; int32_t mHour, mMin, mSec; SensorRegistrationInfo() : mPackageName() { mSensorHandle = mSamplingRateUs = mMaxReportLatencyUs = INT32_MIN; mHour = mMin = mSec = INT32_MIN; mActivated = false; } static bool isSentinel(const SensorRegistrationInfo& info) { return (info.mHour == INT32_MIN && info.mMin == INT32_MIN && info.mSec == INT32_MIN); } }; static int getNumEventsForSensorType(int sensor_event_type); static int getNumEventsForSensorType(int sensor_event_type); String8 getSensorName(int handle) const; String8 getSensorName(int handle) const; bool isVirtualSensor(int handle) const; bool isVirtualSensor(int handle) const; Loading Loading @@ -387,6 +398,8 @@ class SensorService : // The size of this vector is constant, only the items are mutable // The size of this vector is constant, only the items are mutable KeyedVector<int32_t, CircularBuffer *> mLastEventSeen; KeyedVector<int32_t, CircularBuffer *> mLastEventSeen; int mNextSensorRegIndex; Vector<SensorRegistrationInfo> mLastNSensorRegistrations; public: public: void cleanupConnection(SensorEventConnection* connection); void cleanupConnection(SensorEventConnection* connection); status_t enable(const sp<SensorEventConnection>& connection, int handle, status_t enable(const sp<SensorEventConnection>& connection, int handle, Loading