summaryrefslogtreecommitdiffstats
path: root/hal/sensors/2.0/SensorsSubHal.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'hal/sensors/2.0/SensorsSubHal.cpp')
-rw-r--r--hal/sensors/2.0/SensorsSubHal.cpp93
1 files changed, 66 insertions, 27 deletions
diff --git a/hal/sensors/2.0/SensorsSubHal.cpp b/hal/sensors/2.0/SensorsSubHal.cpp
index 93fc948..4d80d9f 100644
--- a/hal/sensors/2.0/SensorsSubHal.cpp
+++ b/hal/sensors/2.0/SensorsSubHal.cpp
@@ -13,6 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+#define LOG_TAG "GoogleIIOSensorSubHal"
+
#include "SensorsSubHal.h"
#include <android/hardware/sensors/2.0/types.h>
#include <log/log.h>
@@ -32,59 +34,87 @@ namespace implementation {
using ::android::hardware::Void;
using ::android::hardware::sensors::V1_0::Event;
-using ::android::hardware::sensors::V1_0::OperationMode;
using ::android::hardware::sensors::V1_0::RateLevel;
-using ::android::hardware::sensors::V1_0::Result;
using ::android::hardware::sensors::V1_0::SharedMemInfo;
using ::android::hardware::sensors::V2_0::SensorTimeout;
using ::android::hardware::sensors::V2_0::WakeLockQueueFlagBits;
using ::android::hardware::sensors::V2_0::implementation::ScopedWakelock;
+using ::sensor::hal::configuration::V1_0::Sensor;
+using ::sensor::hal::configuration::V1_0::SensorHalConfiguration;
#define SENSOR_SUPPORTED(SENSOR_NAME, SENSOR_TYPE) \
{ .name = SENSOR_NAME, .type = SENSOR_TYPE, }
+#define SENSOR_XML_CONFIG_FILE_NAME "sensor_hal_configuration.xml"
+static const char* gSensorConfigLocationList[] = {"/odm/etc/sensors/", "/vendor/etc/sensors/"};
+static const int gSensorConfigLocationListSize =
+ (sizeof(gSensorConfigLocationList) / sizeof(gSensorConfigLocationList[0]));
+
+#define MODULE_NAME "android.hardware.sensors@2.0-Google-IIO-Subhal"
+
static const std::vector<sensors_supported_hal> sensors_supported = {
SENSOR_SUPPORTED("scmi.iio.accel", SensorType::ACCELEROMETER),
SENSOR_SUPPORTED("scmi.iio.gyro", SensorType::GYROSCOPE),
};
+static std::optional<std::vector<Sensor>> readSensorsConfigFromXml() {
+ for (int i = 0; i < gSensorConfigLocationListSize; i++) {
+ const auto sensor_config_file =
+ std::string(gSensorConfigLocationList[i]) + SENSOR_XML_CONFIG_FILE_NAME;
+ auto sensorConfig = ::sensor::hal::configuration::V1_0::read(sensor_config_file.c_str());
+ if (sensorConfig) {
+ auto modulesList = sensorConfig->getFirstModules()->get_module();
+ for (auto module : modulesList) {
+ if (module.getHalName().compare(MODULE_NAME) == 0) {
+ return module.getFirstSensors()->getSensor();
+ }
+ }
+ }
+ }
+ ALOGI("Could not find the sensors configuration for module %s", MODULE_NAME);
+ return std::nullopt;
+}
+
+static std::optional<std::vector<Configuration>> getSensorConfiguration(
+ const std::vector<Sensor>& sensor_list, const std::string& name, SensorType type) {
+ for (auto sensor : sensor_list) {
+ if ((name.compare(sensor.getName()) == 0) && (type == (SensorType)sensor.getType())) {
+ return sensor.getConfiguration();
+ }
+ }
+ ALOGI("Could not find the sensor configuration for %s ", name.c_str());
+ return std::nullopt;
+}
+
SensorsSubHal::SensorsSubHal() : mCallback(nullptr), mNextHandle(1) {
int err;
std::vector<iio_device_data> iio_devices;
+ const auto sensors_config_list = readSensorsConfigFromXml();
err = load_iio_devices(&iio_devices, sensors_supported);
if (err == 0) {
- for (auto i = 0u; i < iio_devices.size(); i++) {
- err = scan_elements(iio_devices[i].sysfspath, &iio_devices[i]);
+ for (auto& iio_device : iio_devices) {
+ err = scan_elements(iio_device.sysfspath, &iio_device);
if (err == 0) {
- err = enable_sensor(iio_devices[i].sysfspath, false);
+ err = enable_sensor(iio_device.sysfspath, false);
if (err == 0) {
- switch (iio_devices[i].type) {
- case SensorType::ACCELEROMETER:
- if (iio_devices[i].channelInfo.size() == NUM_OF_CHANNEL_SUPPORTED) {
- AddSensor<Accelerometer>(iio_devices[i]);
- } else {
- ALOGE("Unexpected number of channels for Accelerometer");
- }
- break;
-
- case SensorType::GYROSCOPE:
- if (iio_devices[i].channelInfo.size() == NUM_OF_CHANNEL_SUPPORTED) {
- AddSensor<Gyroscope>(iio_devices[i]);
- } else {
- ALOGE("Unexpected number fo channels for Gyroscope");
- }
- break;
-
- default:
- break;
+ std::optional<std::vector<Configuration>> sensor_configuration = std::nullopt;
+ if (sensors_config_list)
+ sensor_configuration = getSensorConfiguration(
+ *sensors_config_list, iio_device.name, iio_device.type);
+
+ if (iio_device.channelInfo.size() == NUM_OF_CHANNEL_SUPPORTED) {
+ AddSensor(iio_device, sensor_configuration);
+ } else {
+ ALOGE("SensorsSubHal(): Unexpected number of channels for sensor %s",
+ iio_device.sysfspath.c_str());
}
} else {
ALOGE("SensorsSubHal(): Error in enabling_sensor %s to %d error code %d",
- iio_devices[i].sysfspath.c_str(), false, err);
+ iio_device.sysfspath.c_str(), false, err);
}
} else {
ALOGE("SensorsSubHal(): Error in scanning channels for IIO device %s error code %d",
- iio_devices[i].sysfspath.c_str(), err);
+ iio_device.sysfspath.c_str(), err);
}
}
} else {
@@ -185,7 +215,7 @@ Return<void> SensorsSubHal::debug(const hidl_handle& fd, const hidl_vec<hidl_str
stream << "handle: " << info.sensorHandle << std::endl;
stream << "resolution: " << info.resolution << " minDelay: " << info.minDelay
<< " maxDelay:" << info.maxDelay << std::endl;
- stream << "iio path" << hwSensor->miio_data.sysfspath << std::endl;
+ stream << "iio path" << hwSensor->mIioData.sysfspath << std::endl;
}
stream << std::endl;
@@ -206,6 +236,15 @@ void SensorsSubHal::postEvents(const std::vector<Event>& events, bool wakeup) {
ScopedWakelock wakelock = mCallback->createScopedWakelock(wakeup);
mCallback->postEvents(events, std::move(wakelock));
}
+void SensorsSubHal::AddSensor(const struct iio_device_data& iio_data,
+ const std::optional<std::vector<Configuration>>& config) {
+ HWSensorBase* sensor = HWSensorBase::buildSensor(mNextHandle++ /* sensorHandle */,
+ this /* callback */, iio_data, config);
+ if (sensor != nullptr)
+ mSensors[sensor->getSensorInfo().sensorHandle] = std::unique_ptr<SensorBase>(sensor);
+ else
+ ALOGE("Unable to add sensor %s as buildSensor returned null", iio_data.name.c_str());
+}
} // namespace implementation
} // namespace subhal