summaryrefslogtreecommitdiff
path: root/services/sensorservice
diff options
context:
space:
mode:
authorAlexey Polyudov <apolyudov@google.com>2017-05-23 19:54:04 -0700
committerPeng Xu <pengxu@google.com>2017-09-20 17:23:43 -0700
commitaec078f627923a12402206eed313812e26f4f6a0 (patch)
tree9e26f0979218e3d239e95987d0c9d3e601a88c23 /services/sensorservice
parent057222281abed93f0ed3ee9e8191751951a063a0 (diff)
downloadnative-aec078f627923a12402206eed313812e26f4f6a0.tar.gz
sensors: pass sensor handle along with injected event
Change-Id: Ifa5825b08d5b809865f9066c7a763202cebb987f Merged-In: Ifa5825b08d5b809865f9066c7a763202cebb987f
Diffstat (limited to 'services/sensorservice')
-rw-r--r--services/sensorservice/SensorService.cpp27
-rw-r--r--services/sensorservice/SensorService.h2
2 files changed, 21 insertions, 8 deletions
diff --git a/services/sensorservice/SensorService.cpp b/services/sensorservice/SensorService.cpp
index d60768c98d..eb7826c01a 100644
--- a/services/sensorservice/SensorService.cpp
+++ b/services/sensorservice/SensorService.cpp
@@ -1032,17 +1032,16 @@ sp<ISensorEventConnection> SensorService::createSensorDirectConnection(
}
int SensorService::setOperationParameter(
- int32_t type, const Vector<float> &floats, const Vector<int32_t> &ints) {
+ int32_t handle, int32_t type,
+ const Vector<float> &floats, const Vector<int32_t> &ints) {
Mutex::Autolock _l(mLock);
- // check permission
- int32_t uid;
- bool hasPermission = checkCallingPermission(sLocationHardwarePermission, nullptr, &uid);
- if (!hasPermission || (uid != 1000 && uid != 0)) {
+ if (!checkCallingPermission(sLocationHardwarePermission, nullptr, nullptr)) {
return PERMISSION_DENIED;
}
bool isFloat = true;
+ bool isCustom = false;
size_t expectSize = INT32_MAX;
switch (type) {
case AINFO_LOCAL_GEOMAGNETIC_FIELD:
@@ -1060,7 +1059,21 @@ int SensorService::setOperationParameter(
expectSize = 1;
break;
default:
- return BAD_VALUE;
+ // CUSTOM events must only contain float data; it may have variable size
+ if (type < AINFO_CUSTOM_START || type >= AINFO_DEBUGGING_START ||
+ ints.size() ||
+ sizeof(additional_info_event_t::data_float)/sizeof(float) < floats.size() ||
+ handle < 0) {
+ return BAD_VALUE;
+ }
+ isFloat = true;
+ isCustom = true;
+ expectSize = floats.size();
+ break;
+ }
+
+ if (!isCustom && handle != -1) {
+ return BAD_VALUE;
}
// three events: first one is begin tag, last one is end tag, the one in the middle
@@ -1070,7 +1083,7 @@ int SensorService::setOperationParameter(
for (sensors_event_t* i = event; i < event + 3; i++) {
*i = (sensors_event_t) {
.version = sizeof(sensors_event_t),
- .sensor = SENSORS_HANDLE_BASE - 1, // sensor that never exists
+ .sensor = handle,
.type = SENSOR_TYPE_ADDITIONAL_INFO,
.timestamp = timestamp++,
.additional_info = (additional_info_event_t) {
diff --git a/services/sensorservice/SensorService.h b/services/sensorservice/SensorService.h
index 2a9d6e86ba..3e183942ff 100644
--- a/services/sensorservice/SensorService.h
+++ b/services/sensorservice/SensorService.h
@@ -159,7 +159,7 @@ private:
virtual sp<ISensorEventConnection> createSensorDirectConnection(const String16& opPackageName,
uint32_t size, int32_t type, int32_t format, const native_handle *resource);
virtual int setOperationParameter(
- int32_t type, const Vector<float> &floats, const Vector<int32_t> &ints);
+ int32_t handle, int32_t type, const Vector<float> &floats, const Vector<int32_t> &ints);
virtual status_t dump(int fd, const Vector<String16>& args);
String8 getSensorName(int handle) const;