summaryrefslogtreecommitdiff
path: root/sensors/common/default/2.X/Sensor.cpp
diff options
context:
space:
mode:
authorKarthik Bharadwaj <karthikmb@google.com>2020-11-10 04:14:48 +0000
committerKarthik Bharadwaj <karthikmb@google.com>2020-11-13 00:19:24 +0000
commit534d9358afa32824291ae1ed87487ff4153ad40a (patch)
treebe092c85965904b30c4c93630bf42979b3893eac /sensors/common/default/2.X/Sensor.cpp
parent7bfe3131a61491c511a38f9d21029ff39d3db2c8 (diff)
Fix VTS SensorsHidl Test Failures
This CL fixes test failures by: - Remove the deprecated 'Device Temperature' sensor from the sensor list - Ignoring the deprecated 'Device Temperature' sensor type for tests - Only accessing shared memory buffer if the shared memory type is supported - Return a default z-axis data value for the accel sensor type. - Update the batch() functions argument to take an int64 timestamp to adhere to the interface Bug: 171940270 Test: run vts -a x86 -m VtsHalSensorsV2_0TargetTest Change-Id: I88fe8746030f42edd620f9891aa44bc228a73426
Diffstat (limited to 'sensors/common/default/2.X/Sensor.cpp')
-rw-r--r--sensors/common/default/2.X/Sensor.cpp36
1 files changed, 11 insertions, 25 deletions
diff --git a/sensors/common/default/2.X/Sensor.cpp b/sensors/common/default/2.X/Sensor.cpp
index 1841dffe2e..870980fa75 100644
--- a/sensors/common/default/2.X/Sensor.cpp
+++ b/sensors/common/default/2.X/Sensor.cpp
@@ -57,11 +57,11 @@ const SensorInfo& Sensor::getSensorInfo() const {
return mSensorInfo;
}
-void Sensor::batch(int32_t samplingPeriodNs) {
- if (samplingPeriodNs < mSensorInfo.minDelay * 1000) {
- samplingPeriodNs = mSensorInfo.minDelay * 1000;
- } else if (samplingPeriodNs > mSensorInfo.maxDelay * 1000) {
- samplingPeriodNs = mSensorInfo.maxDelay * 1000;
+void Sensor::batch(int64_t samplingPeriodNs) {
+ if (samplingPeriodNs < mSensorInfo.minDelay * 1000ll) {
+ samplingPeriodNs = mSensorInfo.minDelay * 1000ll;
+ } else if (samplingPeriodNs > mSensorInfo.maxDelay * 1000ll) {
+ samplingPeriodNs = mSensorInfo.maxDelay * 1000ll;
}
if (mSamplingPeriodNs != samplingPeriodNs) {
@@ -133,6 +133,11 @@ bool Sensor::isWakeUpSensor() {
}
std::vector<Event> Sensor::readEvents() {
+ // For an accelerometer sensor type, default the z-direction
+ // value to -9.8
+ float zValue = (mSensorInfo.type == SensorType::ACCELEROMETER)
+ ? -9.8 : 0.0;
+
std::vector<Event> events;
Event event;
event.sensorHandle = mSensorInfo.sensorHandle;
@@ -140,7 +145,7 @@ std::vector<Event> Sensor::readEvents() {
event.timestamp = ::android::elapsedRealtimeNano();
event.u.vec3.x = 0;
event.u.vec3.y = 0;
- event.u.vec3.z = 0;
+ event.u.vec3.z = zValue;
event.u.vec3.status = SensorStatus::ACCURACY_HIGH;
events.push_back(event);
return events;
@@ -330,25 +335,6 @@ AmbientTempSensor::AmbientTempSensor(int32_t sensorHandle, ISensorsEventCallback
mSensorInfo.flags = static_cast<uint32_t>(SensorFlagBits::ON_CHANGE_MODE);
};
-DeviceTempSensor::DeviceTempSensor(int32_t sensorHandle, ISensorsEventCallback* callback)
- : OnChangeSensor(callback) {
- mSensorInfo.sensorHandle = sensorHandle;
- mSensorInfo.name = "Device Temp Sensor";
- mSensorInfo.vendor = "Vendor String";
- mSensorInfo.version = 1;
- mSensorInfo.type = SensorType::TEMPERATURE;
- mSensorInfo.typeAsString = "";
- mSensorInfo.maxRange = 80.0f;
- mSensorInfo.resolution = 0.01f;
- mSensorInfo.power = 0.001f;
- mSensorInfo.minDelay = 40 * 1000; // microseconds
- mSensorInfo.maxDelay = kDefaultMaxDelayUs;
- mSensorInfo.fifoReservedEventCount = 0;
- mSensorInfo.fifoMaxEventCount = 0;
- mSensorInfo.requiredPermission = "";
- mSensorInfo.flags = static_cast<uint32_t>(SensorFlagBits::ON_CHANGE_MODE);
-}
-
RelativeHumiditySensor::RelativeHumiditySensor(int32_t sensorHandle,
ISensorsEventCallback* callback)
: OnChangeSensor(callback) {