Add a fake step counter sensor HAL
This is done by extending the original sensor HAL for Cuttlefish.
Bug: 124355112
Test: $ lunch aosp_cf_x86_64_gsi-userdebug
$ m -j32
$ find $OUT/vendor -name *stepcounter.xml # It exists.
# Launch the built image
$ atest DeviceHealthTests:com.android.devicehealth.tests.SensorsBootCheck
Change-Id: Ia440cc306ac2aefff59187ecb7c396069ad2d6d8
diff --git a/guest/hals/sensors/sensors.cpp b/guest/hals/sensors/sensors.cpp
index eb1dda6..609606c 100644
--- a/guest/hals/sensors/sensors.cpp
+++ b/guest/hals/sensors/sensors.cpp
@@ -195,4 +195,17 @@
flags);
}
+SensorInfo StepCounterSensor() {
+ uint32_t flags = sc::kStepCounterReportingMode |
+ (sc::kStepCounterIsWakeup ? SENSOR_FLAG_WAKE_UP : 0);
+
+ return SensorInfo(sc::kStepCounterName, sc::kVendor, sc::kVersion,
+ sc::kStepCounterHandle, SENSOR_TYPE_STEP_COUNTER,
+ sc::kStepCounterMaxRange, sc::kStepCounterResolution,
+ sc::kStepCounterPower, sc::kStepCounterMinDelay,
+ sc::kFifoReservedEventCount, sc::kFifoMaxEventCount,
+ sc::kStepCounterStringType, sc::kRequiredPermission,
+ sc::kMaxDelay, flags);
+}
+
} // namespace cvd
diff --git a/guest/hals/sensors/sensors.h b/guest/hals/sensors/sensors.h
index c4305ce..c94b14f 100644
--- a/guest/hals/sensors/sensors.h
+++ b/guest/hals/sensors/sensors.h
@@ -47,6 +47,7 @@
friend SensorInfo AmbientTempSensor();
friend SensorInfo DeviceTempSensor();
friend SensorInfo RelativeHumiditySensor();
+ friend SensorInfo StepCounterSensor();
};
SensorInfo AccelerometerSensor();
@@ -58,6 +59,7 @@
SensorInfo AmbientTempSensor();
SensorInfo DeviceTempSensor();
SensorInfo RelativeHumiditySensor();
+SensorInfo StepCounterSensor();
// Stores the current state of a sensor.
class SensorState {
@@ -111,6 +113,7 @@
const char kAmbientTempName[] = "ambient_temp";
const char kDeviceTempName[] = "device_temp";
const char kRelativeHumidityName[] = "relative_humidity";
+const char kStepCounterName[] = "step_counter";
// Handle that identifies the sensor. This is used as an array index,
// so must be unique in the range [0, # sensors)
@@ -124,6 +127,7 @@
const int kAmbientTempHandle = 6;
const int kDeviceTempHandle = 7;
const int kRelativeHumidityHandle = 8;
+const int kStepCounterHandle = 9;
// For continuous sensors, minimum sample period (in microseconds).
// On-Change (0), One-shot (-1), and special (0).
@@ -136,6 +140,7 @@
const int32_t kAmbientTempMinDelay = 4444;
const int32_t kDeviceTempMinDelay = 4444;
const int32_t kRelativeHumidityMinDelay = 4444;
+const int32_t kStepCounterMinDelay = 0;
// Maximum range of this sensor's value in SI units.
const float kAccelerometerMaxRange = 39.226593f;
@@ -147,6 +152,7 @@
const float kAmbientTempMaxRange = 80.0f;
const float kDeviceTempMaxRange = 80.0f;
const float kRelativeHumidityMaxRange = 100;
+const float kStepCounterMaxRange = 1.0f;
// Smallest difference between two values reported by this sensor.
const float kAccelerometerResolution = 0.45f;
@@ -158,6 +164,7 @@
const float kAmbientTempResolution = 1.0f;
const float kDeviceTempResolution = 1.0f;
const float kRelativeHumidityResolution = 1.0f;
+const float kStepCounterResolution = 1.0f;
// Rough estimate of this sensor's power consumption in mA.
const float kAccelerometerPower = 0.45f;
@@ -169,6 +176,7 @@
const float kAmbientTempPower = 1.0f;
const float kDeviceTempPower = 1.0f;
const float kRelativeHumidityPower = 1.0f;
+const float kStepCounterPower = 0.1f;
// Type of this sensor, represented as a string.
@@ -182,6 +190,7 @@
const char kAmbientTempStringType[] = SENSOR_STRING_TYPE_AMBIENT_TEMPERATURE;
const char kDeviceTempStringType[] = SENSOR_STRING_TYPE_TEMPERATURE;
const char kRelativeHumidityStringType[] = SENSOR_STRING_TYPE_RELATIVE_HUMIDITY;
+const char kStepCounterStringType[] = SENSOR_STRING_TYPE_STEP_COUNTER;
#else
const char kAccelerometerStringType[] = "";
const char kGyroscopeStringType[] = "";
@@ -192,6 +201,7 @@
const char kAmbientTempStringType[] = "";
const char kDeviceTempStringType[] = "";
const char kRelativeHumidityStringType[] = "";
+const char kStepCounterStringType[] = "";
#endif
#if VSOC_SENSORS_DEVICE_API_VERSION_ATLEAST(1_3)
@@ -204,6 +214,7 @@
const uint32_t kAmbientTempReportingMode = SENSOR_FLAG_ON_CHANGE_MODE;
const uint32_t kDeviceTempReportingMode = SENSOR_FLAG_ON_CHANGE_MODE;
const uint32_t kRelativeHumidityReportingMode = SENSOR_FLAG_ON_CHANGE_MODE;
+const uint32_t kStepCounterReportingMode = SENSOR_FLAG_ON_CHANGE_MODE;
#else
const uint32_t kAccelerometerReportingMode = 0;
const uint32_t kGyroscopeReportingMode = 0;
@@ -214,6 +225,7 @@
const uint32_t kAmbientTempReportingMode = 0;
const uint32_t kDeviceTempReportingMode = 0;
const uint32_t kRelativeHumidityReportingMode = 0;
+const uint32_t kStepCounterReportingMode = 0;
#endif
const bool kAccelerometerIsWakeup = false;
@@ -225,6 +237,7 @@
const bool kAmbientTempIsWakeup = false;
const bool kDeviceTempIsWakeup = false;
const bool kRelativeHumidityIsWakeup = false;
+const bool kStepCounterIsWakeup = false;
} // namespace sensors_constants
} // namespace cvd
diff --git a/guest/hals/sensors/vsoc_sensors.cpp b/guest/hals/sensors/vsoc_sensors.cpp
index 336cd65..f318ec6 100644
--- a/guest/hals/sensors/vsoc_sensors.cpp
+++ b/guest/hals/sensors/vsoc_sensors.cpp
@@ -491,7 +491,7 @@
if (total_sensor_count_ != -1) {
return -1;
}
- total_sensor_count_ = 9;
+ total_sensor_count_ = 10;
sensor_infos_ = new SensorInfo[total_sensor_count_];
sensor_infos_[sensors_constants::kAccelerometerHandle] =
AccelerometerSensor();
@@ -505,6 +505,7 @@
sensor_infos_[sensors_constants::kDeviceTempHandle] = DeviceTempSensor();
sensor_infos_[sensors_constants::kRelativeHumidityHandle] =
RelativeHumiditySensor();
+ sensor_infos_[sensors_constants::kStepCounterHandle] = StepCounterSensor();
int i;
for (i = 0; i < total_sensor_count_; i++) {
D("Found sensor %s with handle %d", sensor_infos_[i].name,