diff options
| -rw-r--r-- | services/sensorservice/SensorService.cpp | 4 | ||||
| -rw-r--r-- | services/sensorservice/SensorService.h | 16 |
2 files changed, 19 insertions, 1 deletions
diff --git a/services/sensorservice/SensorService.cpp b/services/sensorservice/SensorService.cpp index 942b7ae76a..9955cdb080 100644 --- a/services/sensorservice/SensorService.cpp +++ b/services/sensorservice/SensorService.cpp @@ -2129,12 +2129,14 @@ status_t SensorService::adjustRateLevelBasedOnMicAndPermission(int* requestedRat } void SensorService::SensorPrivacyPolicy::registerSelf() { + AutoCallerClear acc; SensorPrivacyManager spm; mSensorPrivacyEnabled = spm.isSensorPrivacyEnabled(); spm.addSensorPrivacyListener(this); } void SensorService::SensorPrivacyPolicy::unregisterSelf() { + AutoCallerClear acc; SensorPrivacyManager spm; spm.removeSensorPrivacyListener(this); } @@ -2167,7 +2169,7 @@ binder::Status SensorService::SensorPrivacyPolicy::onSensorPrivacyChanged(bool e status_t SensorService::SensorPrivacyPolicy::registerSelfForIndividual(int userId) { Mutex::Autolock _l(mSensorPrivacyLock); - + AutoCallerClear acc; SensorPrivacyManager spm; status_t err = spm.addIndividualSensorPrivacyListener(userId, SensorPrivacyManager::INDIVIDUAL_SENSOR_MICROPHONE, this); diff --git a/services/sensorservice/SensorService.h b/services/sensorservice/SensorService.h index 9c5060a577..a563a60607 100644 --- a/services/sensorservice/SensorService.h +++ b/services/sensorservice/SensorService.h @@ -242,6 +242,22 @@ private: userid_t mUserId; }; + // A class automatically clearing and restoring binder caller identity inside + // a code block (scoped variable). + // Declare one systematically before calling SensorPrivacyManager methods so that they are + // executed with the same level of privilege as the SensorService process. + class AutoCallerClear { + public: + AutoCallerClear() : + mToken(IPCThreadState::self()->clearCallingIdentity()) {} + ~AutoCallerClear() { + IPCThreadState::self()->restoreCallingIdentity(mToken); + } + + private: + const int64_t mToken; + }; + enum Mode { // The regular operating mode where any application can register/unregister/call flush on // sensors. |