dynamic_sensor: Support recognizing head tracker sensor.
Bug: 207008609 Test: Verified dynamic sensor sampling with proposed standard Android head tracker. Test: Verified dynamic sensor sampling with custom Android sensor. Change-Id: Ia9b991d4a8f7de132cb8509bcc84c51f62e56b31
This commit is contained in:
@@ -492,13 +492,8 @@ bool HidRawSensor::populateFeatureValueFromFeatureReport(
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case SENSOR_DESCRIPTION:
|
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)) {
|
if (decodeString(r, buffer, &str)) {
|
||||||
mFeatureInfo.isAndroidCustom = detectAndroidCustomSensor(str);
|
detectSensorFromDescription(str);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@@ -583,26 +578,34 @@ bool HidRawSensor::validateFeatureValueAndBuildSensor() {
|
|||||||
|
|
||||||
bool HidRawSensor::decodeString(
|
bool HidRawSensor::decodeString(
|
||||||
const HidParser::ReportItem &report, const std::vector<uint8_t> &buffer, std::string *d) {
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t charSize = report.bitSize / 8;
|
||||||
size_t offset = report.bitOffset / 8;
|
size_t offset = report.bitOffset / 8;
|
||||||
if (offset + report.count * 2 > buffer.size()) {
|
if (offset + report.count * charSize > buffer.size()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<uint16_t> data(report.count);
|
if (charSize == 1) {
|
||||||
auto i = data.begin();
|
*d = std::string(buffer.begin() + offset,
|
||||||
auto j = buffer.begin() + offset;
|
buffer.begin() + offset + report.count);
|
||||||
for ( ; i != data.end(); ++i, j += sizeof(uint16_t)) {
|
} else {
|
||||||
// hid specified little endian
|
std::vector<uint16_t> data(report.count);
|
||||||
*i = *j + (*(j + 1) << 8);
|
auto i = data.begin();
|
||||||
}
|
auto j = buffer.begin() + offset;
|
||||||
std::wstring wstr(data.begin(), data.end());
|
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_convert<std::codecvt_utf8<wchar_t>, wchar_t> converter;
|
|
||||||
*d = converter.to_bytes(wstr);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -621,6 +624,28 @@ std::vector<std::string> split(const std::string &text, char sep) {
|
|||||||
return tokens;
|
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) {
|
bool HidRawSensor::detectAndroidCustomSensor(const std::string &description) {
|
||||||
size_t nullPosition = description.find('\0');
|
size_t nullPosition = description.find('\0');
|
||||||
if (nullPosition == std::string::npos) {
|
if (nullPosition == std::string::npos) {
|
||||||
|
|||||||
@@ -121,6 +121,14 @@ private:
|
|||||||
// helper function to find sensor control feature usage from packets
|
// helper function to find sensor control feature usage from packets
|
||||||
bool findSensorControlUsage(const std::vector<HidParser::ReportPacket> &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
|
// try to parse sensor description feature value to see if it matches
|
||||||
// android specified custom sensor definition.
|
// android specified custom sensor definition.
|
||||||
bool detectAndroidCustomSensor(const std::string &description);
|
bool detectAndroidCustomSensor(const std::string &description);
|
||||||
|
|||||||
Reference in New Issue
Block a user