Call noteOp for sensor events
Call noteOp whenever a sensor event that requires a permission is
received in the sensor framework.
Bug: 130640415
Test: Builds
Test: Verified 'adb shell appops get PACKAGE_NAME' shows updated time
whenever Step Counter or Step Detector events are received
Test: Verified AppOp is not called for sensors that do not require
permission.
Change-Id: Ia5601e896bebdb9e20e6e3364e6e5f7424962b3b
diff --git a/services/sensorservice/SensorEventConnection.h b/services/sensorservice/SensorEventConnection.h
index 7077880..fd881cb 100644
--- a/services/sensorservice/SensorEventConnection.h
+++ b/services/sensorservice/SensorEventConnection.h
@@ -19,6 +19,7 @@
#include <stdint.h>
#include <sys/types.h>
+#include <unordered_map>
#include <utils/Vector.h>
#include <utils/SortedVector.h>
@@ -134,6 +135,9 @@
// 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;
@@ -181,6 +185,10 @@
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