Loading services/sensorservice/SensorEventConnection.cpp +13 −2 Original line number Diff line number Diff line Loading @@ -285,8 +285,9 @@ status_t SensorService::SensorEventConnection::sendEvents( scratch[count++] = buffer[i]; } } else { // Regular sensor event, just copy it to the scratch buffer. if (hasSensorAccess()) { // Regular sensor event, just copy it to the scratch buffer after checking // the AppOp. if (hasSensorAccess() && noteOpIfRequired(buffer[i])) { scratch[count++] = buffer[i]; } } Loading Loading @@ -386,6 +387,16 @@ bool SensorService::SensorEventConnection::hasSensorAccess() { return mHasSensorAccess && !mService->mSensorPrivacyPolicy->isSensorPrivacyEnabled(); } bool SensorService::SensorEventConnection::noteOpIfRequired(const sensors_event_t& event) { bool success = true; const auto iter = mHandleToAppOp.find(event.sensor); if (iter != mHandleToAppOp.end()) { int32_t appOpMode = mService->sAppOpsManager.noteOp((*iter).second, mUid, mOpPackageName); success = (appOpMode == AppOpsManager::MODE_ALLOWED); } return success; } void SensorService::SensorEventConnection::reAllocateCacheLocked(sensors_event_t const* scratch, int count) { sensors_event_t *eventCache_new; Loading services/sensorservice/SensorEventConnection.h +8 −0 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ #include <stdint.h> #include <sys/types.h> #include <unordered_map> #include <utils/Vector.h> #include <utils/SortedVector.h> Loading Loading @@ -134,6 +135,9 @@ private: // privacy not being enabled. bool hasSensorAccess(); // Call noteOp for the sensor if the sensor requires a permission bool noteOpIfRequired(const sensors_event_t& event); sp<SensorService> const mService; sp<BitTube> mChannel; uid_t mUid; Loading Loading @@ -181,6 +185,10 @@ private: mutable Mutex mDestroyLock; bool mDestroyed; bool mHasSensorAccess; // Store a mapping of sensor handles to required AppOp for a sensor. This map only contains a // valid mapping for sensors that require a permission in order to reduce the lookup time. std::unordered_map<int32_t, int32_t> mHandleToAppOp; }; } // namepsace android Loading services/sensorservice/SensorService.cpp +4 −0 Original line number Diff line number Diff line Loading @@ -1550,6 +1550,10 @@ status_t SensorService::enable(const sp<SensorEventConnection>& connection, if (err == NO_ERROR) { connection->updateLooperRegistration(mLooper); if (sensor->getSensor().getRequiredPermission().size() > 0) { connection->mHandleToAppOp[handle] = sensor->getSensor().getRequiredAppOp(); } mLastNSensorRegistrations.editItemAt(mNextSensorRegIndex) = SensorRegistrationInfo(handle, connection->getPackageName(), samplingPeriodNs, maxBatchReportLatencyNs, true); Loading Loading
services/sensorservice/SensorEventConnection.cpp +13 −2 Original line number Diff line number Diff line Loading @@ -285,8 +285,9 @@ status_t SensorService::SensorEventConnection::sendEvents( scratch[count++] = buffer[i]; } } else { // Regular sensor event, just copy it to the scratch buffer. if (hasSensorAccess()) { // Regular sensor event, just copy it to the scratch buffer after checking // the AppOp. if (hasSensorAccess() && noteOpIfRequired(buffer[i])) { scratch[count++] = buffer[i]; } } Loading Loading @@ -386,6 +387,16 @@ bool SensorService::SensorEventConnection::hasSensorAccess() { return mHasSensorAccess && !mService->mSensorPrivacyPolicy->isSensorPrivacyEnabled(); } bool SensorService::SensorEventConnection::noteOpIfRequired(const sensors_event_t& event) { bool success = true; const auto iter = mHandleToAppOp.find(event.sensor); if (iter != mHandleToAppOp.end()) { int32_t appOpMode = mService->sAppOpsManager.noteOp((*iter).second, mUid, mOpPackageName); success = (appOpMode == AppOpsManager::MODE_ALLOWED); } return success; } void SensorService::SensorEventConnection::reAllocateCacheLocked(sensors_event_t const* scratch, int count) { sensors_event_t *eventCache_new; Loading
services/sensorservice/SensorEventConnection.h +8 −0 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ #include <stdint.h> #include <sys/types.h> #include <unordered_map> #include <utils/Vector.h> #include <utils/SortedVector.h> Loading Loading @@ -134,6 +135,9 @@ private: // privacy not being enabled. bool hasSensorAccess(); // Call noteOp for the sensor if the sensor requires a permission bool noteOpIfRequired(const sensors_event_t& event); sp<SensorService> const mService; sp<BitTube> mChannel; uid_t mUid; Loading Loading @@ -181,6 +185,10 @@ private: mutable Mutex mDestroyLock; bool mDestroyed; bool mHasSensorAccess; // Store a mapping of sensor handles to required AppOp for a sensor. This map only contains a // valid mapping for sensors that require a permission in order to reduce the lookup time. std::unordered_map<int32_t, int32_t> mHandleToAppOp; }; } // namepsace android Loading
services/sensorservice/SensorService.cpp +4 −0 Original line number Diff line number Diff line Loading @@ -1550,6 +1550,10 @@ status_t SensorService::enable(const sp<SensorEventConnection>& connection, if (err == NO_ERROR) { connection->updateLooperRegistration(mLooper); if (sensor->getSensor().getRequiredPermission().size() > 0) { connection->mHandleToAppOp[handle] = sensor->getSensor().getRequiredAppOp(); } mLastNSensorRegistrations.editItemAt(mNextSensorRegIndex) = SensorRegistrationInfo(handle, connection->getPackageName(), samplingPeriodNs, maxBatchReportLatencyNs, true); Loading