Loading services/sensorservice/SensorDirectConnection.cpp +2 −3 Original line number Diff line number Diff line Loading @@ -32,7 +32,6 @@ SensorService::SensorDirectConnection::SensorDirectConnection(const sp<SensorSer : mService(service), mUid(uid), mMem(*mem), mHalChannelHandle(halChannelHandle), mOpPackageName(opPackageName), mDestroyed(false) { mIsRateCappedBasedOnPermission = mService->isRateCappedBasedOnPermission(mOpPackageName); mUserId = multiuser_get_user_id(mUid); ALOGD_IF(DEBUG_CONNECTIONS, "Created SensorDirectConnection"); } Loading Loading @@ -197,8 +196,8 @@ int32_t SensorService::SensorDirectConnection::configureChannel(int handle, int if (mService->isSensorInCappedSet(s.getType())) { // Back up the rates that the app is allowed to have if the mic toggle is off // This is used in the uncapRates() function. if (!mIsRateCappedBasedOnPermission || requestedRateLevel <= SENSOR_SERVICE_CAPPED_SAMPLING_RATE_LEVEL) { if ((requestedRateLevel <= SENSOR_SERVICE_CAPPED_SAMPLING_RATE_LEVEL) || !isRateCappedBasedOnPermission()) { mMicRateBackup[handle] = requestedRateLevel; } else { mMicRateBackup[handle] = SENSOR_SERVICE_CAPPED_SAMPLING_RATE_LEVEL; Loading services/sensorservice/SensorDirectConnection.h +11 −1 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ #ifndef ANDROID_SENSOR_DIRECT_CONNECTION_H #define ANDROID_SENSOR_DIRECT_CONNECTION_H #include <optional> #include <stdint.h> #include <sys/types.h> Loading Loading @@ -100,10 +101,19 @@ private: std::unordered_map<int, int> mActivatedBackup; std::unordered_map<int, int> mMicRateBackup; std::atomic_bool mIsRateCappedBasedOnPermission; mutable Mutex mDestroyLock; bool mDestroyed; userid_t mUserId; std::optional<bool> mIsRateCappedBasedOnPermission; bool isRateCappedBasedOnPermission() { if (!mIsRateCappedBasedOnPermission.has_value()) { mIsRateCappedBasedOnPermission = mService->isRateCappedBasedOnPermission(mOpPackageName); } return mIsRateCappedBasedOnPermission.value(); } }; } // namepsace android Loading services/sensorservice/SensorEventConnection.cpp +4 −5 Original line number Diff line number Diff line Loading @@ -44,7 +44,6 @@ SensorService::SensorEventConnection::SensorEventConnection( mCacheSize(0), mMaxCacheSize(0), mTimeOfLastEventDrop(0), mEventsDropped(0), mPackageName(packageName), mOpPackageName(opPackageName), mAttributionTag(attributionTag), mTargetSdk(kTargetSdkUnknown), mDestroyed(false) { mIsRateCappedBasedOnPermission = mService->isRateCappedBasedOnPermission(mOpPackageName); mUserId = multiuser_get_user_id(mUid); mChannel = new BitTube(mService->mSocketBufferSize); #if DEBUG_CONNECTIONS Loading Loading @@ -706,8 +705,8 @@ status_t SensorService::SensorEventConnection::enableDisable( err = mService->enable(this, handle, samplingPeriodNs, maxBatchReportLatencyNs, reservedFlags, mOpPackageName); if (err == OK && isSensorCapped) { if (!mIsRateCappedBasedOnPermission || requestedSamplingPeriodNs >= SENSOR_SERVICE_CAPPED_SAMPLING_PERIOD_NS) { if ((requestedSamplingPeriodNs >= SENSOR_SERVICE_CAPPED_SAMPLING_PERIOD_NS) || !isRateCappedBasedOnPermission()) { mMicSamplingPeriodBackup[handle] = requestedSamplingPeriodNs; } else { mMicSamplingPeriodBackup[handle] = SENSOR_SERVICE_CAPPED_SAMPLING_PERIOD_NS; Loading Loading @@ -745,8 +744,8 @@ status_t SensorService::SensorEventConnection::setEventRate(int handle, nsecs_t } status_t ret = mService->setEventRate(this, handle, samplingPeriodNs, mOpPackageName); if (ret == OK && isSensorCapped) { if (!mIsRateCappedBasedOnPermission || requestedSamplingPeriodNs >= SENSOR_SERVICE_CAPPED_SAMPLING_PERIOD_NS) { if ((requestedSamplingPeriodNs >= SENSOR_SERVICE_CAPPED_SAMPLING_PERIOD_NS) || !isRateCappedBasedOnPermission()) { mMicSamplingPeriodBackup[handle] = requestedSamplingPeriodNs; } else { mMicSamplingPeriodBackup[handle] = SENSOR_SERVICE_CAPPED_SAMPLING_PERIOD_NS; Loading services/sensorservice/SensorEventConnection.h +11 −1 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ #define ANDROID_SENSOR_EVENT_CONNECTION_H #include <atomic> #include <optional> #include <stdint.h> #include <sys/types.h> #include <unordered_map> Loading Loading @@ -148,7 +149,6 @@ private: sp<SensorService> const mService; sp<BitTube> mChannel; uid_t mUid; std::atomic_bool mIsRateCappedBasedOnPermission; mutable Mutex mConnectionLock; // Number of events from wake up sensors which are still pending and haven't been delivered to // the corresponding application. It is incremented by one unit for each write to the socket. Loading Loading @@ -201,6 +201,16 @@ private: // Mapping of sensor handles to its rate before being capped by the mic toggle. std::unordered_map<int, nsecs_t> mMicSamplingPeriodBackup; userid_t mUserId; std::optional<bool> mIsRateCappedBasedOnPermission; bool isRateCappedBasedOnPermission() { if (!mIsRateCappedBasedOnPermission.has_value()) { mIsRateCappedBasedOnPermission = mService->isRateCappedBasedOnPermission(mOpPackageName); } return mIsRateCappedBasedOnPermission.value(); } }; } // namepsace android Loading services/sensorservice/SensorService.cpp +2 −3 Original line number Diff line number Diff line Loading @@ -2190,10 +2190,10 @@ bool SensorService::isSensorInCappedSet(int sensorType) { status_t SensorService::adjustSamplingPeriodBasedOnMicAndPermission(nsecs_t* requestedPeriodNs, const String16& opPackageName) { uid_t uid = IPCThreadState::self()->getCallingUid(); bool shouldCapBasedOnPermission = isRateCappedBasedOnPermission(opPackageName); if (*requestedPeriodNs >= SENSOR_SERVICE_CAPPED_SAMPLING_PERIOD_NS) { return OK; } bool shouldCapBasedOnPermission = isRateCappedBasedOnPermission(opPackageName); if (shouldCapBasedOnPermission) { *requestedPeriodNs = SENSOR_SERVICE_CAPPED_SAMPLING_PERIOD_NS; if (isPackageDebuggable(opPackageName)) { Loading @@ -2211,11 +2211,10 @@ status_t SensorService::adjustSamplingPeriodBasedOnMicAndPermission(nsecs_t* req status_t SensorService::adjustRateLevelBasedOnMicAndPermission(int* requestedRateLevel, const String16& opPackageName) { uid_t uid = IPCThreadState::self()->getCallingUid(); bool shouldCapBasedOnPermission = isRateCappedBasedOnPermission(opPackageName); if (*requestedRateLevel <= SENSOR_SERVICE_CAPPED_SAMPLING_RATE_LEVEL) { return OK; } bool shouldCapBasedOnPermission = isRateCappedBasedOnPermission(opPackageName); if (shouldCapBasedOnPermission) { *requestedRateLevel = SENSOR_SERVICE_CAPPED_SAMPLING_RATE_LEVEL; if (isPackageDebuggable(opPackageName)) { Loading Loading
services/sensorservice/SensorDirectConnection.cpp +2 −3 Original line number Diff line number Diff line Loading @@ -32,7 +32,6 @@ SensorService::SensorDirectConnection::SensorDirectConnection(const sp<SensorSer : mService(service), mUid(uid), mMem(*mem), mHalChannelHandle(halChannelHandle), mOpPackageName(opPackageName), mDestroyed(false) { mIsRateCappedBasedOnPermission = mService->isRateCappedBasedOnPermission(mOpPackageName); mUserId = multiuser_get_user_id(mUid); ALOGD_IF(DEBUG_CONNECTIONS, "Created SensorDirectConnection"); } Loading Loading @@ -197,8 +196,8 @@ int32_t SensorService::SensorDirectConnection::configureChannel(int handle, int if (mService->isSensorInCappedSet(s.getType())) { // Back up the rates that the app is allowed to have if the mic toggle is off // This is used in the uncapRates() function. if (!mIsRateCappedBasedOnPermission || requestedRateLevel <= SENSOR_SERVICE_CAPPED_SAMPLING_RATE_LEVEL) { if ((requestedRateLevel <= SENSOR_SERVICE_CAPPED_SAMPLING_RATE_LEVEL) || !isRateCappedBasedOnPermission()) { mMicRateBackup[handle] = requestedRateLevel; } else { mMicRateBackup[handle] = SENSOR_SERVICE_CAPPED_SAMPLING_RATE_LEVEL; Loading
services/sensorservice/SensorDirectConnection.h +11 −1 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ #ifndef ANDROID_SENSOR_DIRECT_CONNECTION_H #define ANDROID_SENSOR_DIRECT_CONNECTION_H #include <optional> #include <stdint.h> #include <sys/types.h> Loading Loading @@ -100,10 +101,19 @@ private: std::unordered_map<int, int> mActivatedBackup; std::unordered_map<int, int> mMicRateBackup; std::atomic_bool mIsRateCappedBasedOnPermission; mutable Mutex mDestroyLock; bool mDestroyed; userid_t mUserId; std::optional<bool> mIsRateCappedBasedOnPermission; bool isRateCappedBasedOnPermission() { if (!mIsRateCappedBasedOnPermission.has_value()) { mIsRateCappedBasedOnPermission = mService->isRateCappedBasedOnPermission(mOpPackageName); } return mIsRateCappedBasedOnPermission.value(); } }; } // namepsace android Loading
services/sensorservice/SensorEventConnection.cpp +4 −5 Original line number Diff line number Diff line Loading @@ -44,7 +44,6 @@ SensorService::SensorEventConnection::SensorEventConnection( mCacheSize(0), mMaxCacheSize(0), mTimeOfLastEventDrop(0), mEventsDropped(0), mPackageName(packageName), mOpPackageName(opPackageName), mAttributionTag(attributionTag), mTargetSdk(kTargetSdkUnknown), mDestroyed(false) { mIsRateCappedBasedOnPermission = mService->isRateCappedBasedOnPermission(mOpPackageName); mUserId = multiuser_get_user_id(mUid); mChannel = new BitTube(mService->mSocketBufferSize); #if DEBUG_CONNECTIONS Loading Loading @@ -706,8 +705,8 @@ status_t SensorService::SensorEventConnection::enableDisable( err = mService->enable(this, handle, samplingPeriodNs, maxBatchReportLatencyNs, reservedFlags, mOpPackageName); if (err == OK && isSensorCapped) { if (!mIsRateCappedBasedOnPermission || requestedSamplingPeriodNs >= SENSOR_SERVICE_CAPPED_SAMPLING_PERIOD_NS) { if ((requestedSamplingPeriodNs >= SENSOR_SERVICE_CAPPED_SAMPLING_PERIOD_NS) || !isRateCappedBasedOnPermission()) { mMicSamplingPeriodBackup[handle] = requestedSamplingPeriodNs; } else { mMicSamplingPeriodBackup[handle] = SENSOR_SERVICE_CAPPED_SAMPLING_PERIOD_NS; Loading Loading @@ -745,8 +744,8 @@ status_t SensorService::SensorEventConnection::setEventRate(int handle, nsecs_t } status_t ret = mService->setEventRate(this, handle, samplingPeriodNs, mOpPackageName); if (ret == OK && isSensorCapped) { if (!mIsRateCappedBasedOnPermission || requestedSamplingPeriodNs >= SENSOR_SERVICE_CAPPED_SAMPLING_PERIOD_NS) { if ((requestedSamplingPeriodNs >= SENSOR_SERVICE_CAPPED_SAMPLING_PERIOD_NS) || !isRateCappedBasedOnPermission()) { mMicSamplingPeriodBackup[handle] = requestedSamplingPeriodNs; } else { mMicSamplingPeriodBackup[handle] = SENSOR_SERVICE_CAPPED_SAMPLING_PERIOD_NS; Loading
services/sensorservice/SensorEventConnection.h +11 −1 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ #define ANDROID_SENSOR_EVENT_CONNECTION_H #include <atomic> #include <optional> #include <stdint.h> #include <sys/types.h> #include <unordered_map> Loading Loading @@ -148,7 +149,6 @@ private: sp<SensorService> const mService; sp<BitTube> mChannel; uid_t mUid; std::atomic_bool mIsRateCappedBasedOnPermission; mutable Mutex mConnectionLock; // Number of events from wake up sensors which are still pending and haven't been delivered to // the corresponding application. It is incremented by one unit for each write to the socket. Loading Loading @@ -201,6 +201,16 @@ private: // Mapping of sensor handles to its rate before being capped by the mic toggle. std::unordered_map<int, nsecs_t> mMicSamplingPeriodBackup; userid_t mUserId; std::optional<bool> mIsRateCappedBasedOnPermission; bool isRateCappedBasedOnPermission() { if (!mIsRateCappedBasedOnPermission.has_value()) { mIsRateCappedBasedOnPermission = mService->isRateCappedBasedOnPermission(mOpPackageName); } return mIsRateCappedBasedOnPermission.value(); } }; } // namepsace android Loading
services/sensorservice/SensorService.cpp +2 −3 Original line number Diff line number Diff line Loading @@ -2190,10 +2190,10 @@ bool SensorService::isSensorInCappedSet(int sensorType) { status_t SensorService::adjustSamplingPeriodBasedOnMicAndPermission(nsecs_t* requestedPeriodNs, const String16& opPackageName) { uid_t uid = IPCThreadState::self()->getCallingUid(); bool shouldCapBasedOnPermission = isRateCappedBasedOnPermission(opPackageName); if (*requestedPeriodNs >= SENSOR_SERVICE_CAPPED_SAMPLING_PERIOD_NS) { return OK; } bool shouldCapBasedOnPermission = isRateCappedBasedOnPermission(opPackageName); if (shouldCapBasedOnPermission) { *requestedPeriodNs = SENSOR_SERVICE_CAPPED_SAMPLING_PERIOD_NS; if (isPackageDebuggable(opPackageName)) { Loading @@ -2211,11 +2211,10 @@ status_t SensorService::adjustSamplingPeriodBasedOnMicAndPermission(nsecs_t* req status_t SensorService::adjustRateLevelBasedOnMicAndPermission(int* requestedRateLevel, const String16& opPackageName) { uid_t uid = IPCThreadState::self()->getCallingUid(); bool shouldCapBasedOnPermission = isRateCappedBasedOnPermission(opPackageName); if (*requestedRateLevel <= SENSOR_SERVICE_CAPPED_SAMPLING_RATE_LEVEL) { return OK; } bool shouldCapBasedOnPermission = isRateCappedBasedOnPermission(opPackageName); if (shouldCapBasedOnPermission) { *requestedRateLevel = SENSOR_SERVICE_CAPPED_SAMPLING_RATE_LEVEL; if (isPackageDebuggable(opPackageName)) { Loading