dynamic_sensor: Support report and power usage collections. am: f99f73ceeb am: 2978c08ef0

Original change: https://googleplex-android-review.googlesource.com/c/platform/hardware/libhardware/+/16323898

Change-Id: I45025e510e2a836b6f43949fea7955dafd601755
This commit is contained in:
Erik Staats 2021-11-23 14:14:18 +00:00 committed by Automerger Merge Worker
commit 82bbf6dc12
5 changed files with 79 additions and 25 deletions

View file

@ -784,8 +784,9 @@ bool HidRawSensor::detectAndroidCustomSensor(const std::string &description) {
}
bool HidRawSensor::findSensorControlUsage(const std::vector<HidParser::ReportPacket> &packets) {
using namespace Hid::Sensor::PowerStateUsage;
using namespace Hid::Sensor::PropertyUsage;
using namespace Hid::Sensor::RawMinMax;
using namespace Hid::Sensor::ReportingStateUsage;
//REPORTING_STATE
const HidParser::ReportItem *reportingState
@ -793,13 +794,31 @@ bool HidRawSensor::findSensorControlUsage(const std::vector<HidParser::ReportPac
if (reportingState == nullptr
|| !reportingState->isByteAligned()
|| reportingState->bitSize != 8
|| reportingState->minRaw != REPORTING_STATE_MIN
|| reportingState->maxRaw != REPORTING_STATE_MAX) {
|| reportingState->bitSize != 8) {
LOG_W << "Cannot find valid reporting state feature" << LOG_ENDL;
} else {
mReportingStateId = reportingState->id;
mReportingStateOffset = reportingState->bitOffset / 8;
mReportingStateDisableIndex = -1;
mReportingStateEnableIndex = -1;
for (unsigned i = 0; i < reportingState->usageVector.size(); ++i) {
if (reportingState->usageVector[i] == REPORTING_STATE_NO_EVENTS) {
mReportingStateDisableIndex = i;
}
if (reportingState->usageVector[i] == REPORTING_STATE_ALL_EVENTS) {
mReportingStateEnableIndex = i;
}
}
if (mReportingStateDisableIndex < 0) {
LOG_W << "Cannot find reporting state to disable sensor"
<< LOG_ENDL;
mReportingStateId = -1;
}
if (mReportingStateEnableIndex < 0) {
LOG_W << "Cannot find reporting state to enable sensor" << LOG_ENDL;
mReportingStateId = -1;
}
}
//POWER_STATE
@ -807,13 +826,31 @@ bool HidRawSensor::findSensorControlUsage(const std::vector<HidParser::ReportPac
= find(packets, POWER_STATE, HidParser::REPORT_TYPE_FEATURE);
if (powerState == nullptr
|| !powerState->isByteAligned()
|| powerState->bitSize != 8
|| powerState->minRaw != POWER_STATE_MIN
|| powerState->maxRaw != POWER_STATE_MAX) {
|| powerState->bitSize != 8) {
LOG_W << "Cannot find valid power state feature" << LOG_ENDL;
} else {
mPowerStateId = powerState->id;
mPowerStateOffset = powerState->bitOffset / 8;
mPowerStateOffIndex = -1;
mPowerStateOnIndex = -1;
for (unsigned i = 0; i < powerState->usageVector.size(); ++i) {
if (powerState->usageVector[i] == POWER_STATE_D4_POWER_OFF) {
mPowerStateOffIndex = i;
}
if (powerState->usageVector[i] == POWER_STATE_D0_FULL_POWER) {
mPowerStateOnIndex = i;
}
}
if (mPowerStateOffIndex < 0) {
LOG_W << "Cannot find power state to power off sensor"
<< LOG_ENDL;
mPowerStateId = -1;
}
if (mPowerStateOnIndex < 0) {
LOG_W << "Cannot find power state to power on sensor" << LOG_ENDL;
mPowerStateId = -1;
}
}
//REPORT_INTERVAL
@ -846,7 +883,6 @@ void HidRawSensor::getUuid(uint8_t* uuid) const {
}
int HidRawSensor::enable(bool enable) {
using namespace Hid::Sensor::StateValue;
SP(HidDevice) device = PROMOTE(mDevice);
if (device == nullptr) {
@ -864,7 +900,8 @@ int HidRawSensor::enable(bool enable) {
uint8_t id = static_cast<uint8_t>(mPowerStateId);
if (device->getFeature(id, &buffer)
&& buffer.size() > mPowerStateOffset) {
buffer[mPowerStateOffset] = enable ? POWER_STATE_FULL_POWER : POWER_STATE_POWER_OFF;
buffer[mPowerStateOffset] =
enable ? mPowerStateOnIndex : mPowerStateOffIndex;
setPowerOk = device->setFeature(id, buffer);
} else {
LOG_E << "enable: changing POWER STATE failed" << LOG_ENDL;
@ -878,7 +915,8 @@ int HidRawSensor::enable(bool enable) {
if (device->getFeature(id, &buffer)
&& buffer.size() > mReportingStateOffset) {
buffer[mReportingStateOffset]
= enable ? REPORTING_STATE_ALL_EVENT : REPORTING_STATE_NO_EVENT;
= enable ? mReportingStateEnableIndex :
mReportingStateDisableIndex;
setReportingOk = device->setFeature(id, buffer);
} else {
LOG_E << "enable: changing REPORTING STATE failed" << LOG_ENDL;
@ -1019,7 +1057,10 @@ std::string HidRawSensor::dump() const {
ss << " Power state ";
if (mPowerStateId >= 0) {
ss << "found, id: " << mPowerStateId
<< " offset: " << mPowerStateOffset << LOG_ENDL;
<< " offset: " << mPowerStateOffset
<< " power off index: " << mPowerStateOffIndex
<< " power on index: " << mPowerStateOnIndex
<< LOG_ENDL;
} else {
ss << "not found" << LOG_ENDL;
}
@ -1027,7 +1068,10 @@ std::string HidRawSensor::dump() const {
ss << " Reporting state ";
if (mReportingStateId >= 0) {
ss << "found, id: " << mReportingStateId
<< " offset: " << mReportingStateOffset << LOG_ENDL;
<< " offset: " << mReportingStateOffset
<< " disable index: " << mReportingStateDisableIndex
<< " enable index: " << mReportingStateEnableIndex
<< LOG_ENDL;
} else {
ss << "not found" << LOG_ENDL;
}

View file

@ -138,9 +138,13 @@ private:
// Features for control sensor
int mReportingStateId;
unsigned int mReportingStateOffset;
int mReportingStateDisableIndex;
int mReportingStateEnableIndex;
int mPowerStateId;
unsigned int mPowerStateOffset;
int mPowerStateOffIndex;
int mPowerStateOnIndex;
int mReportIntervalId;
unsigned int mReportIntervalOffset;

View file

@ -77,24 +77,28 @@ enum {
};
} // namespace ReportUsage
namespace RawMinMax {
namespace ReportingStateUsage {
enum {
REPORTING_STATE_MIN = 0,
REPORTING_STATE_MAX = 5,
POWER_STATE_MIN = 0,
POWER_STATE_MAX = 5,
REPORTING_STATE_NO_EVENTS = 0x0840,
REPORTING_STATE_ALL_EVENTS = 0x0841,
REPORTING_STATE_REPORT_THRESHOLD_EVENTS = 0x0842,
REPORTING_STATE_REPORT_WAKE_ON_NO_EVENTS = 0x0843,
REPORTING_STATE_REPORT_WAKE_ON_ALL_EVENTS = 0x0844,
REPORTING_STATE_REPORT_WAKE_ON_THRESHOLD_EVENTS = 0x0845,
};
} // namespace RawMinMax
} // namespace ReportingStateUsage
namespace StateValue {
namespace PowerStateUsage {
enum {
POWER_STATE_FULL_POWER = 1,
POWER_STATE_POWER_OFF = 5,
REPORTING_STATE_ALL_EVENT = 1,
REPORTING_STATE_NO_EVENT = 0,
POWER_STATE_UNDEFINED = 0x0850,
POWER_STATE_D0_FULL_POWER = 0x0851,
POWER_STATE_D1_LOW_POWER = 0x0852,
POWER_STATE_D2_STANDBY_POWER_WITH_WAKEUP = 0x0853,
POWER_STATE_D3_SLEEP_WITH_WAKEUP = 0x0854,
POWER_STATE_D4_POWER_OFF = 0x0855,
};
} // StateValue
} // namespace PowerStateUsage
} // namespace Sensor
} // namespace Hid
#endif // HID_SENSOR_DEF_H_

View file

@ -248,6 +248,7 @@ std::vector<HidParser::ReportPacket> HidParser::convertGroupToPacket(
ReportItem digest = {
.usage = r.getFullUsage(),
.id = id,
.usageVector = r.getUsageVector(),
.minRaw = logical.first,
.maxRaw = logical.second,
.a = scale,

View file

@ -89,6 +89,7 @@ struct HidParser::ReportItem {
unsigned int usage;
unsigned int id;
int type; // feature, input or output
std::vector<unsigned int> usageVector;
int64_t minRaw;
int64_t maxRaw;