diff --git a/sensors/HalProxy.cpp b/sensors/HalProxy.cpp index fe3fc84..1a73265 100644 --- a/sensors/HalProxy.cpp +++ b/sensors/HalProxy.cpp @@ -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; } } diff --git a/sensors/HalProxyCallback.cpp b/sensors/HalProxyCallback.cpp index 3c1b17c..122c382 100644 --- a/sensors/HalProxyCallback.cpp +++ b/sensors/HalProxyCallback.cpp @@ -68,11 +68,17 @@ std::vector HalProxyCallbackBase::processEvents(const std::vector 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; }