sm8350-common: sensors: standardize xiaomi pickup sensor

* use standard sensor type
 * ignore non-wakeup sensor variant
 * ignore events that do not properly match a pickup
This commit is contained in:
Cosmin Tanislav 2021-09-21 02:43:52 +03:00
parent b6d092bc8b
commit b7bca78611
2 changed files with 31 additions and 1 deletions

View File

@ -81,6 +81,25 @@ int64_t msFromNs(int64_t nanos) {
return nanos / nanosecondsInAMillsecond;
}
bool patchXiaomiPickupSensor(V2_1::SensorInfo& sensor) {
if (sensor.typeAsString != "xiaomi.sensor.pickup") {
return true;
}
/*
* Implement only the wake-up version of this sensor.
*/
if (!(sensor.flags & V1_0::SensorFlagBits::WAKE_UP)) {
return false;
}
sensor.type = V2_1::SensorType::PICK_UP_GESTURE;
sensor.typeAsString = SENSOR_STRING_TYPE_PICK_UP_GESTURE;
sensor.maxRange = 1;
return true;
}
HalProxy::HalProxy() {
const char* kMultiHalConfigFile = "/vendor/etc/sensors/hals.conf";
initializeSubHalListFromConfigFile(kMultiHalConfigFile);
@ -480,6 +499,11 @@ void HalProxy::initializeSensorList() {
ALOGV("Loaded sensor: %s", sensor.name.c_str());
sensor.sensorHandle = setSubHalIndex(sensor.sensorHandle, subHalIndex);
setDirectChannelFlags(&sensor, mSubHalList[subHalIndex]);
bool keep = patchXiaomiPickupSensor(sensor);
if (!keep) {
continue;
}
mSensors[sensor.sensorHandle] = sensor;
}
}

View File

@ -68,11 +68,17 @@ std::vector<V2_1::Event> HalProxyCallbackBase::processEvents(const std::vector<V
std::vector<V2_1::Event> eventsOut;
for (V2_1::Event event : events) {
event.sensorHandle = setSubHalIndex(event.sensorHandle, mSubHalIndex);
eventsOut.push_back(event);
const V2_1::SensorInfo& sensor = mCallback->getSensorInfo(event.sensorHandle);
if (sensor.type == V2_1::SensorType::PICK_UP_GESTURE
&& event.u.scalar != 1) {
continue;
}
if ((sensor.flags & V1_0::SensorFlagBits::WAKE_UP) != 0) {
(*numWakeupEvents)++;
}
eventsOut.push_back(event);
}
return eventsOut;
}