Skip to content

Commit

Permalink
Zero uninitialized field in conversion and fix vts bug
Browse files Browse the repository at this point in the history
Zero uninitialized sensor event field to zero to avoid undefined
value being passed to framework.

Correct sensor report type check bug in vts.

Bug: 37793558
Bug: 37710268
Test: sensor vts passes
Change-Id: I5042975fea8fe28ae130367ba083a4e4f4e5657e
  • Loading branch information
Peng Xu committed Jun 19, 2017
1 parent 55f3ddf commit 36665b1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
22 changes: 12 additions & 10 deletions sensors/1.0/default/convert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,11 @@ void convertFromSensorEvent(const sensors_event_t &src, Event *dst) {
typedef ::android::hardware::sensors::V1_0::SensorType SensorType;
typedef ::android::hardware::sensors::V1_0::MetaDataEventType MetaDataEventType;

dst->sensorHandle = src.sensor;
dst->sensorType = (SensorType)src.type;
dst->timestamp = src.timestamp;
*dst = {
.sensorHandle = src.sensor,
.sensorType = (SensorType)src.type,
.timestamp = src.timestamp
};

switch (dst->sensorType) {
case SensorType::META_DATA:
Expand Down Expand Up @@ -206,13 +208,13 @@ void convertFromSensorEvent(const sensors_event_t &src, Event *dst) {
}

void convertToSensorEvent(const Event &src, sensors_event_t *dst) {
dst->version = sizeof(sensors_event_t);
dst->sensor = src.sensorHandle;
dst->type = (int32_t)src.sensorType;
dst->reserved0 = 0;
dst->timestamp = src.timestamp;
dst->flags = 0;
dst->reserved1[0] = dst->reserved1[1] = dst->reserved1[2] = 0;
*dst = {
.version = sizeof(sensors_event_t),
.sensor = src.sensorHandle,
.type = (int32_t)src.sensorType,
.reserved0 = 0,
.timestamp = src.timestamp
};

switch (src.sensorType) {
case SensorType::META_DATA:
Expand Down
4 changes: 3 additions & 1 deletion sensors/1.0/vts/functional/VtsHalSensorsV1_0TargetTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,7 @@ void SensorsHidlTest::assertDelayMatchReportMode(
SensorFlagBits SensorsHidlTest::expectedReportModeForType(SensorType type) {
switch (type) {
case SensorType::ACCELEROMETER:
case SensorType::ACCELEROMETER_UNCALIBRATED:
case SensorType::GYROSCOPE:
case SensorType::MAGNETIC_FIELD:
case SensorType::ORIENTATION:
Expand All @@ -719,7 +720,6 @@ SensorFlagBits SensorsHidlTest::expectedReportModeForType(SensorType type) {
case SensorType::AMBIENT_TEMPERATURE:
case SensorType::HEART_RATE:
case SensorType::DEVICE_ORIENTATION:
case SensorType::MOTION_DETECT:
case SensorType::STEP_COUNTER:
case SensorType::LOW_LATENCY_OFFBODY_DETECT:
return SensorFlagBits::ON_CHANGE_MODE;
Expand All @@ -728,6 +728,8 @@ SensorFlagBits SensorsHidlTest::expectedReportModeForType(SensorType type) {
case SensorType::WAKE_GESTURE:
case SensorType::GLANCE_GESTURE:
case SensorType::PICK_UP_GESTURE:
case SensorType::MOTION_DETECT:
case SensorType::STATIONARY_DETECT:
return SensorFlagBits::ONE_SHOT_MODE;

case SensorType::STEP_DETECTOR:
Expand Down

0 comments on commit 36665b1

Please sign in to comment.