summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2021-12-04 02:07:09 +0000
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2021-12-04 02:07:09 +0000
commitfcafef0ab6d0ca861a3d772447f3409c27722ad9 (patch)
tree76b9cbb0e9a203b1ae1fc9b9a6d07a4e64f17b5d
parentbefe5c9111096f45499448c6671415a363200e83 (diff)
parentdbf2545214d16eaed5901bd41c8c8e8871ef0168 (diff)
downloadlibhardware-fcafef0ab6d0ca861a3d772447f3409c27722ad9.tar.gz
Snap for 7968112 from dbf2545214d16eaed5901bd41c8c8e8871ef0168 to sc-v2-release
Change-Id: Ib997e88b6354740fc623037cca0bc8e30c1b1d80
-rw-r--r--modules/sensors/dynamic_sensor/HidRawSensor.cpp59
-rw-r--r--modules/sensors/dynamic_sensor/HidRawSensor.h8
2 files changed, 50 insertions, 17 deletions
diff --git a/modules/sensors/dynamic_sensor/HidRawSensor.cpp b/modules/sensors/dynamic_sensor/HidRawSensor.cpp
index 531ab9d5..8aaf2d4f 100644
--- a/modules/sensors/dynamic_sensor/HidRawSensor.cpp
+++ b/modules/sensors/dynamic_sensor/HidRawSensor.cpp
@@ -492,13 +492,8 @@ bool HidRawSensor::populateFeatureValueFromFeatureReport(
}
break;
case SENSOR_DESCRIPTION:
- if (!r.isByteAligned() || r.bitSize != 16 || r.count < 1
- || (r.bitOffset / 8 + r.count * 2) > buffer.size() ) {
- // invalid description
- break;
- }
if (decodeString(r, buffer, &str)) {
- mFeatureInfo.isAndroidCustom = detectAndroidCustomSensor(str);
+ detectSensorFromDescription(str);
}
break;
default:
@@ -583,26 +578,34 @@ bool HidRawSensor::validateFeatureValueAndBuildSensor() {
bool HidRawSensor::decodeString(
const HidParser::ReportItem &report, const std::vector<uint8_t> &buffer, std::string *d) {
- if (!report.isByteAligned() || report.bitSize != 16 || report.count < 1) {
+ if (!report.isByteAligned() ||
+ (report.bitSize != 8 && report.bitSize != 16) || report.count < 1) {
return false;
}
+ size_t charSize = report.bitSize / 8;
size_t offset = report.bitOffset / 8;
- if (offset + report.count * 2 > buffer.size()) {
+ if (offset + report.count * charSize > buffer.size()) {
return false;
}
- std::vector<uint16_t> data(report.count);
- auto i = data.begin();
- auto j = buffer.begin() + offset;
- for ( ; i != data.end(); ++i, j += sizeof(uint16_t)) {
- // hid specified little endian
- *i = *j + (*(j + 1) << 8);
+ if (charSize == 1) {
+ *d = std::string(buffer.begin() + offset,
+ buffer.begin() + offset + report.count);
+ } else {
+ std::vector<uint16_t> data(report.count);
+ auto i = data.begin();
+ auto j = buffer.begin() + offset;
+ for ( ; i != data.end(); ++i, j += sizeof(uint16_t)) {
+ // hid specified little endian
+ *i = *j + (*(j + 1) << 8);
+ }
+ std::wstring wstr(data.begin(), data.end());
+
+ std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t> converter;
+ *d = converter.to_bytes(wstr);
}
- std::wstring wstr(data.begin(), data.end());
- std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t> converter;
- *d = converter.to_bytes(wstr);
return true;
}
@@ -621,6 +624,28 @@ std::vector<std::string> split(const std::string &text, char sep) {
return tokens;
}
+void HidRawSensor::detectSensorFromDescription(const std::string &description) {
+ if (detectAndroidHeadTrackerSensor(description) ||
+ detectAndroidCustomSensor(description)) {
+ mFeatureInfo.isAndroidCustom = true;
+ }
+}
+
+bool HidRawSensor::detectAndroidHeadTrackerSensor(
+ const std::string &description) {
+ if (description.find("#AndroidHeadTracker#1.") != 0) {
+ return false;
+ }
+
+ mFeatureInfo.type = SENSOR_TYPE_DEVICE_PRIVATE_BASE;
+ mFeatureInfo.typeString = CUSTOM_TYPE_PREFIX + "headtracker";
+ mFeatureInfo.reportModeFlag = SENSOR_FLAG_CONTINUOUS_MODE;
+ mFeatureInfo.permission = "";
+ mFeatureInfo.isWakeUp = false;
+
+ return true;
+}
+
bool HidRawSensor::detectAndroidCustomSensor(const std::string &description) {
size_t nullPosition = description.find('\0');
if (nullPosition == std::string::npos) {
diff --git a/modules/sensors/dynamic_sensor/HidRawSensor.h b/modules/sensors/dynamic_sensor/HidRawSensor.h
index 99ddfe30..0989651f 100644
--- a/modules/sensors/dynamic_sensor/HidRawSensor.h
+++ b/modules/sensors/dynamic_sensor/HidRawSensor.h
@@ -121,6 +121,14 @@ private:
// helper function to find sensor control feature usage from packets
bool findSensorControlUsage(const std::vector<HidParser::ReportPacket> &packets);
+ // try to parse sensor description feature value to see if it matches any
+ // known sensors
+ void detectSensorFromDescription(const std::string &description);
+
+ // try to parse sensor description feature value to see if it matches the
+ // Android header tracker sensor
+ bool detectAndroidHeadTrackerSensor(const std::string &description);
+
// try to parse sensor description feature value to see if it matches
// android specified custom sensor definition.
bool detectAndroidCustomSensor(const std::string &description);