Add missing sensors to Sensors 2.0
Bug: 123380869 Test: atest com.android.devicehealthchecks.SensorsBootCheck#checkSensors passes on Cuttlefish Change-Id: I08a8406b3932469878da981add61f60b7774a377
This commit is contained in:
parent
543d779efa
commit
a2d16bbc44
4 changed files with 262 additions and 9 deletions
|
@ -131,9 +131,9 @@ std::vector<Event> Sensor::readEvents() {
|
||||||
event.sensorHandle = mSensorInfo.sensorHandle;
|
event.sensorHandle = mSensorInfo.sensorHandle;
|
||||||
event.sensorType = mSensorInfo.type;
|
event.sensorType = mSensorInfo.type;
|
||||||
event.timestamp = ::android::elapsedRealtimeNano();
|
event.timestamp = ::android::elapsedRealtimeNano();
|
||||||
event.u.vec3.x = 1;
|
event.u.vec3.x = 0;
|
||||||
event.u.vec3.y = 2;
|
event.u.vec3.y = 0;
|
||||||
event.u.vec3.z = 3;
|
event.u.vec3.z = 0;
|
||||||
event.u.vec3.status = SensorStatus::ACCURACY_HIGH;
|
event.u.vec3.status = SensorStatus::ACCURACY_HIGH;
|
||||||
events.push_back(event);
|
events.push_back(event);
|
||||||
return events;
|
return events;
|
||||||
|
@ -166,6 +166,31 @@ Result Sensor::injectEvent(const Event& event) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
OnChangeSensor::OnChangeSensor(ISensorsEventCallback* callback)
|
||||||
|
: Sensor(callback), mPreviousEventSet(false) {}
|
||||||
|
|
||||||
|
void OnChangeSensor::activate(bool enable) {
|
||||||
|
Sensor::activate(enable);
|
||||||
|
if (!enable) {
|
||||||
|
mPreviousEventSet = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<Event> OnChangeSensor::readEvents() {
|
||||||
|
std::vector<Event> events = Sensor::readEvents();
|
||||||
|
std::vector<Event> outputEvents;
|
||||||
|
|
||||||
|
for (auto iter = events.begin(); iter != events.end(); ++iter) {
|
||||||
|
Event ev = *iter;
|
||||||
|
if (ev.u.vec3 != mPreviousEvent.u.vec3 || !mPreviousEventSet) {
|
||||||
|
outputEvents.push_back(ev);
|
||||||
|
mPreviousEvent = ev;
|
||||||
|
mPreviousEventSet = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return outputEvents;
|
||||||
|
}
|
||||||
|
|
||||||
AccelSensor::AccelSensor(int32_t sensorHandle, ISensorsEventCallback* callback) : Sensor(callback) {
|
AccelSensor::AccelSensor(int32_t sensorHandle, ISensorsEventCallback* callback) : Sensor(callback) {
|
||||||
mSensorInfo.sensorHandle = sensorHandle;
|
mSensorInfo.sensorHandle = sensorHandle;
|
||||||
mSensorInfo.name = "Accel Sensor";
|
mSensorInfo.name = "Accel Sensor";
|
||||||
|
@ -181,10 +206,162 @@ AccelSensor::AccelSensor(int32_t sensorHandle, ISensorsEventCallback* callback)
|
||||||
mSensorInfo.fifoReservedEventCount = 0;
|
mSensorInfo.fifoReservedEventCount = 0;
|
||||||
mSensorInfo.fifoMaxEventCount = 0;
|
mSensorInfo.fifoMaxEventCount = 0;
|
||||||
mSensorInfo.requiredPermission = "";
|
mSensorInfo.requiredPermission = "";
|
||||||
mSensorInfo.flags =
|
mSensorInfo.flags = static_cast<uint32_t>(SensorFlagBits::DATA_INJECTION);
|
||||||
static_cast<uint32_t>(SensorFlagBits::WAKE_UP | SensorFlagBits::DATA_INJECTION);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
PressureSensor::PressureSensor(int32_t sensorHandle, ISensorsEventCallback* callback)
|
||||||
|
: Sensor(callback) {
|
||||||
|
mSensorInfo.sensorHandle = sensorHandle;
|
||||||
|
mSensorInfo.name = "Pressure Sensor";
|
||||||
|
mSensorInfo.vendor = "Vendor String";
|
||||||
|
mSensorInfo.version = 1;
|
||||||
|
mSensorInfo.type = SensorType::PRESSURE;
|
||||||
|
mSensorInfo.typeAsString = "";
|
||||||
|
mSensorInfo.maxRange = 1100.0f; // hPa
|
||||||
|
mSensorInfo.resolution = 1.0f; // hPa
|
||||||
|
mSensorInfo.power = 0.001f; // mA
|
||||||
|
mSensorInfo.minDelay = 28571.0f; // microseconds
|
||||||
|
mSensorInfo.maxDelay = 0.0f; // microseconds
|
||||||
|
mSensorInfo.fifoReservedEventCount = 0;
|
||||||
|
mSensorInfo.fifoMaxEventCount = 0;
|
||||||
|
mSensorInfo.requiredPermission = "";
|
||||||
|
mSensorInfo.flags = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
MagnetometerSensor::MagnetometerSensor(int32_t sensorHandle, ISensorsEventCallback* callback)
|
||||||
|
: Sensor(callback) {
|
||||||
|
mSensorInfo.sensorHandle = sensorHandle;
|
||||||
|
mSensorInfo.name = "Magnetic Field Sensor";
|
||||||
|
mSensorInfo.vendor = "Vendor String";
|
||||||
|
mSensorInfo.version = 1;
|
||||||
|
mSensorInfo.type = SensorType::MAGNETIC_FIELD;
|
||||||
|
mSensorInfo.typeAsString = "";
|
||||||
|
mSensorInfo.maxRange = 4911.0f;
|
||||||
|
mSensorInfo.resolution = 1.00f;
|
||||||
|
mSensorInfo.power = 0.001f; // mA
|
||||||
|
mSensorInfo.minDelay = 14284.0f; // microseconds
|
||||||
|
mSensorInfo.maxDelay = 0.0f; // microseconds
|
||||||
|
mSensorInfo.fifoReservedEventCount = 0;
|
||||||
|
mSensorInfo.fifoMaxEventCount = 0;
|
||||||
|
mSensorInfo.requiredPermission = "";
|
||||||
|
mSensorInfo.flags = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
LightSensor::LightSensor(int32_t sensorHandle, ISensorsEventCallback* callback)
|
||||||
|
: OnChangeSensor(callback) {
|
||||||
|
mSensorInfo.sensorHandle = sensorHandle;
|
||||||
|
mSensorInfo.name = "Light Sensor";
|
||||||
|
mSensorInfo.vendor = "Vendor String";
|
||||||
|
mSensorInfo.version = 1;
|
||||||
|
mSensorInfo.type = SensorType::LIGHT;
|
||||||
|
mSensorInfo.typeAsString = "";
|
||||||
|
mSensorInfo.maxRange = 10000.0f;
|
||||||
|
mSensorInfo.resolution = 10.0f;
|
||||||
|
mSensorInfo.power = 0.001f; // mA
|
||||||
|
mSensorInfo.minDelay = 20.0f * 1000; // microseconds
|
||||||
|
mSensorInfo.maxDelay = 0; // microseconds
|
||||||
|
mSensorInfo.fifoReservedEventCount = 0;
|
||||||
|
mSensorInfo.fifoMaxEventCount = 0;
|
||||||
|
mSensorInfo.requiredPermission = "";
|
||||||
|
mSensorInfo.flags = static_cast<uint32_t>(SensorFlagBits::ON_CHANGE_MODE);
|
||||||
|
};
|
||||||
|
|
||||||
|
ProximitySensor::ProximitySensor(int32_t sensorHandle, ISensorsEventCallback* callback)
|
||||||
|
: OnChangeSensor(callback) {
|
||||||
|
mSensorInfo.sensorHandle = sensorHandle;
|
||||||
|
mSensorInfo.name = "Proximity Sensor";
|
||||||
|
mSensorInfo.vendor = "Vendor String";
|
||||||
|
mSensorInfo.version = 1;
|
||||||
|
mSensorInfo.type = SensorType::PROXIMITY;
|
||||||
|
mSensorInfo.typeAsString = "";
|
||||||
|
mSensorInfo.maxRange = 5.0f;
|
||||||
|
mSensorInfo.resolution = 1.0f;
|
||||||
|
mSensorInfo.power = 0.012f; // mA
|
||||||
|
mSensorInfo.minDelay = 500; // microseconds
|
||||||
|
mSensorInfo.maxDelay = 2 * mSensorInfo.minDelay;
|
||||||
|
mSensorInfo.fifoReservedEventCount = 0;
|
||||||
|
mSensorInfo.fifoMaxEventCount = 0;
|
||||||
|
mSensorInfo.requiredPermission = "";
|
||||||
|
mSensorInfo.flags =
|
||||||
|
static_cast<uint32_t>(SensorFlagBits::ON_CHANGE_MODE | SensorFlagBits::WAKE_UP);
|
||||||
|
};
|
||||||
|
|
||||||
|
GyroSensor::GyroSensor(int32_t sensorHandle, ISensorsEventCallback* callback) : Sensor(callback) {
|
||||||
|
mSensorInfo.sensorHandle = sensorHandle;
|
||||||
|
mSensorInfo.name = "Gyro Sensor";
|
||||||
|
mSensorInfo.vendor = "Vendor String";
|
||||||
|
mSensorInfo.version = 1;
|
||||||
|
mSensorInfo.type = SensorType::GYROSCOPE;
|
||||||
|
mSensorInfo.typeAsString = "";
|
||||||
|
mSensorInfo.maxRange = 8.726639f;
|
||||||
|
mSensorInfo.resolution = 1.0f;
|
||||||
|
mSensorInfo.power = 0.001f;
|
||||||
|
mSensorInfo.minDelay = 4444; // microseonds
|
||||||
|
mSensorInfo.maxDelay = 0; // microseconds
|
||||||
|
mSensorInfo.fifoReservedEventCount = 0;
|
||||||
|
mSensorInfo.fifoMaxEventCount = 0;
|
||||||
|
mSensorInfo.requiredPermission = "";
|
||||||
|
mSensorInfo.flags = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
AmbientTempSensor::AmbientTempSensor(int32_t sensorHandle, ISensorsEventCallback* callback)
|
||||||
|
: OnChangeSensor(callback) {
|
||||||
|
mSensorInfo.sensorHandle = sensorHandle;
|
||||||
|
mSensorInfo.name = "Ambient Temp Sensor";
|
||||||
|
mSensorInfo.vendor = "Vendor String";
|
||||||
|
mSensorInfo.version = 1;
|
||||||
|
mSensorInfo.type = SensorType::AMBIENT_TEMPERATURE;
|
||||||
|
mSensorInfo.typeAsString = "";
|
||||||
|
mSensorInfo.maxRange = 80.0f;
|
||||||
|
mSensorInfo.resolution = 1.0f;
|
||||||
|
mSensorInfo.power = 0.001f;
|
||||||
|
mSensorInfo.minDelay = 4444; // microseonds
|
||||||
|
mSensorInfo.maxDelay = 0; // microseconds
|
||||||
|
mSensorInfo.fifoReservedEventCount = 0;
|
||||||
|
mSensorInfo.fifoMaxEventCount = 0;
|
||||||
|
mSensorInfo.requiredPermission = "";
|
||||||
|
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 = 1.0f;
|
||||||
|
mSensorInfo.power = 0.001f;
|
||||||
|
mSensorInfo.minDelay = 4444; // microseonds
|
||||||
|
mSensorInfo.maxDelay = 0; // microseconds
|
||||||
|
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) {
|
||||||
|
mSensorInfo.sensorHandle = sensorHandle;
|
||||||
|
mSensorInfo.name = "Relative Humidity Sensor";
|
||||||
|
mSensorInfo.vendor = "Vendor String";
|
||||||
|
mSensorInfo.version = 1;
|
||||||
|
mSensorInfo.type = SensorType::RELATIVE_HUMIDITY;
|
||||||
|
mSensorInfo.typeAsString = "";
|
||||||
|
mSensorInfo.maxRange = 100.0f;
|
||||||
|
mSensorInfo.resolution = 1.0f;
|
||||||
|
mSensorInfo.power = 0.001f;
|
||||||
|
mSensorInfo.minDelay = 4444; // microseonds
|
||||||
|
mSensorInfo.maxDelay = 0; // microseconds
|
||||||
|
mSensorInfo.fifoReservedEventCount = 0;
|
||||||
|
mSensorInfo.fifoMaxEventCount = 0;
|
||||||
|
mSensorInfo.requiredPermission = "";
|
||||||
|
mSensorInfo.flags = static_cast<uint32_t>(SensorFlagBits::ON_CHANGE_MODE);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace implementation
|
} // namespace implementation
|
||||||
} // namespace V2_0
|
} // namespace V2_0
|
||||||
} // namespace sensors
|
} // namespace sensors
|
||||||
|
|
|
@ -50,7 +50,7 @@ class Sensor {
|
||||||
|
|
||||||
const SensorInfo& getSensorInfo() const;
|
const SensorInfo& getSensorInfo() const;
|
||||||
void batch(int32_t samplingPeriodNs);
|
void batch(int32_t samplingPeriodNs);
|
||||||
void activate(bool enable);
|
virtual void activate(bool enable);
|
||||||
Result flush();
|
Result flush();
|
||||||
|
|
||||||
void setOperationMode(OperationMode mode);
|
void setOperationMode(OperationMode mode);
|
||||||
|
@ -79,11 +79,65 @@ class Sensor {
|
||||||
OperationMode mMode;
|
OperationMode mMode;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class OnChangeSensor : public Sensor {
|
||||||
|
public:
|
||||||
|
OnChangeSensor(ISensorsEventCallback* callback);
|
||||||
|
|
||||||
|
virtual void activate(bool enable) override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual std::vector<Event> readEvents() override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
Event mPreviousEvent;
|
||||||
|
bool mPreviousEventSet;
|
||||||
|
};
|
||||||
|
|
||||||
class AccelSensor : public Sensor {
|
class AccelSensor : public Sensor {
|
||||||
public:
|
public:
|
||||||
AccelSensor(int32_t sensorHandle, ISensorsEventCallback* callback);
|
AccelSensor(int32_t sensorHandle, ISensorsEventCallback* callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class GyroSensor : public Sensor {
|
||||||
|
public:
|
||||||
|
GyroSensor(int32_t sensorHandle, ISensorsEventCallback* callback);
|
||||||
|
};
|
||||||
|
|
||||||
|
class AmbientTempSensor : public OnChangeSensor {
|
||||||
|
public:
|
||||||
|
AmbientTempSensor(int32_t sensorHandle, ISensorsEventCallback* callback);
|
||||||
|
};
|
||||||
|
|
||||||
|
class DeviceTempSensor : public OnChangeSensor {
|
||||||
|
public:
|
||||||
|
DeviceTempSensor(int32_t sensorHandle, ISensorsEventCallback* callback);
|
||||||
|
};
|
||||||
|
|
||||||
|
class PressureSensor : public Sensor {
|
||||||
|
public:
|
||||||
|
PressureSensor(int32_t sensorHandle, ISensorsEventCallback* callback);
|
||||||
|
};
|
||||||
|
|
||||||
|
class MagnetometerSensor : public Sensor {
|
||||||
|
public:
|
||||||
|
MagnetometerSensor(int32_t sensorHandle, ISensorsEventCallback* callback);
|
||||||
|
};
|
||||||
|
|
||||||
|
class LightSensor : public OnChangeSensor {
|
||||||
|
public:
|
||||||
|
LightSensor(int32_t sensorHandle, ISensorsEventCallback* callback);
|
||||||
|
};
|
||||||
|
|
||||||
|
class ProximitySensor : public OnChangeSensor {
|
||||||
|
public:
|
||||||
|
ProximitySensor(int32_t sensorHandle, ISensorsEventCallback* callback);
|
||||||
|
};
|
||||||
|
|
||||||
|
class RelativeHumiditySensor : public OnChangeSensor {
|
||||||
|
public:
|
||||||
|
RelativeHumiditySensor(int32_t sensorHandle, ISensorsEventCallback* callback);
|
||||||
|
};
|
||||||
|
|
||||||
} // namespace implementation
|
} // namespace implementation
|
||||||
} // namespace V2_0
|
} // namespace V2_0
|
||||||
} // namespace sensors
|
} // namespace sensors
|
||||||
|
|
|
@ -37,13 +37,20 @@ constexpr const char* kWakeLockName = "SensorsHAL_WAKEUP";
|
||||||
|
|
||||||
Sensors::Sensors()
|
Sensors::Sensors()
|
||||||
: mEventQueueFlag(nullptr),
|
: mEventQueueFlag(nullptr),
|
||||||
|
mNextHandle(1),
|
||||||
mOutstandingWakeUpEvents(0),
|
mOutstandingWakeUpEvents(0),
|
||||||
mReadWakeLockQueueRun(false),
|
mReadWakeLockQueueRun(false),
|
||||||
mAutoReleaseWakeLockTime(0),
|
mAutoReleaseWakeLockTime(0),
|
||||||
mHasWakeLock(false) {
|
mHasWakeLock(false) {
|
||||||
std::shared_ptr<AccelSensor> accel =
|
AddSensor<AccelSensor>();
|
||||||
std::make_shared<AccelSensor>(1 /* sensorHandle */, this /* callback */);
|
AddSensor<GyroSensor>();
|
||||||
mSensors[accel->getSensorInfo().sensorHandle] = accel;
|
AddSensor<AmbientTempSensor>();
|
||||||
|
AddSensor<DeviceTempSensor>();
|
||||||
|
AddSensor<PressureSensor>();
|
||||||
|
AddSensor<MagnetometerSensor>();
|
||||||
|
AddSensor<LightSensor>();
|
||||||
|
AddSensor<ProximitySensor>();
|
||||||
|
AddSensor<RelativeHumiditySensor>();
|
||||||
}
|
}
|
||||||
|
|
||||||
Sensors::~Sensors() {
|
Sensors::~Sensors() {
|
||||||
|
|
|
@ -86,6 +86,16 @@ struct Sensors : public ISensors, public ISensorsEventCallback {
|
||||||
void postEvents(const std::vector<Event>& events, bool wakeup) override;
|
void postEvents(const std::vector<Event>& events, bool wakeup) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
/**
|
||||||
|
* Add a new sensor
|
||||||
|
*/
|
||||||
|
template <class SensorType>
|
||||||
|
void AddSensor() {
|
||||||
|
std::shared_ptr<SensorType> sensor =
|
||||||
|
std::make_shared<SensorType>(mNextHandle++ /* sensorHandle */, this /* callback */);
|
||||||
|
mSensors[sensor->getSensorInfo().sensorHandle] = sensor;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility function to delete the Event Flag
|
* Utility function to delete the Event Flag
|
||||||
*/
|
*/
|
||||||
|
@ -131,6 +141,11 @@ struct Sensors : public ISensors, public ISensorsEventCallback {
|
||||||
*/
|
*/
|
||||||
std::map<int32_t, std::shared_ptr<Sensor>> mSensors;
|
std::map<int32_t, std::shared_ptr<Sensor>> mSensors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The next available sensor handle
|
||||||
|
*/
|
||||||
|
int32_t mNextHandle;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lock to protect writes to the FMQs
|
* Lock to protect writes to the FMQs
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in a new issue