hidl: sensors: 1.0: Standardize xiaomi pickup sensor

* use standard sensor type
 * ignore non-wakeup sensor variant
 * ignore events that do not properly match a pickup

Change-Id: I32bb097afb33603190dfd00a21202301a56bda08
This commit is contained in:
Cosmin Tanislav 2021-09-21 02:43:52 +03:00 committed by Sebastiano Barezzi
parent 004947ec9f
commit 3d946592e6
No known key found for this signature in database
GPG Key ID: 763BD3AE91A7A13F
4 changed files with 71 additions and 18 deletions

View File

@ -103,18 +103,7 @@ status_t Sensors::initCheck() const {
} }
Return<void> Sensors::getSensorsList(getSensorsList_cb _hidl_cb) { Return<void> Sensors::getSensorsList(getSensorsList_cb _hidl_cb) {
sensor_t const* list; hidl_vec<SensorInfo> out = getFixedUpSensorList();
size_t count = mSensorModule->get_sensors_list(mSensorModule, &list);
hidl_vec<SensorInfo> out;
out.resize(count);
for (size_t i = 0; i < count; ++i) {
const sensor_t* src = &list[i];
SensorInfo* dst = &out[i];
convertFromSensor(*src, dst);
}
_hidl_cb(out); _hidl_cb(out);
@ -206,8 +195,9 @@ Return<void> Sensors::poll(int32_t maxCount, poll_cb _hidl_cb) {
dynamicSensorsAdded[numDynamicSensors] = info; dynamicSensorsAdded[numDynamicSensors] = info;
} }
out.resize(count); std::vector<Event> events;
convertFromSensorEvents(err, data.get(), &out); convertFromSensorEvents(err, data.get(), events, getFixedUpSensorList());
out = events;
_hidl_cb(Result::OK, out, dynamicSensorsAdded); _hidl_cb(Result::OK, out, dynamicSensorsAdded);
@ -299,14 +289,53 @@ Return<void> Sensors::configDirectReport(int32_t sensorHandle, int32_t channelHa
return Void(); return Void();
} }
std::vector<SensorInfo> Sensors::getFixedUpSensorList() {
std::vector<SensorInfo> sensors;
sensor_t const* list;
size_t count = mSensorModule->get_sensors_list(mSensorModule, &list);
for (size_t i = 0; i < count; ++i) {
const sensor_t* src = &list[i];
SensorInfo sensor;
convertFromSensor(*src, &sensor);
bool keep = patchXiaomiPickupSensor(sensor);
if (keep) {
sensors.push_back(sensor);
}
}
return sensors;
};
// static // static
void Sensors::convertFromSensorEvents(size_t count, const sensors_event_t* srcArray, void Sensors::convertFromSensorEvents(size_t count, const sensors_event_t* srcArray,
hidl_vec<Event>* dstVec) { std::vector<Event>& dstVec,
std::vector<SensorInfo> sensorsList) {
for (size_t i = 0; i < count; ++i) { for (size_t i = 0; i < count; ++i) {
const sensors_event_t& src = srcArray[i]; const sensors_event_t& src = srcArray[i];
Event* dst = &(*dstVec)[i]; Event event;
convertFromSensorEvent(src, dst); convertFromSensorEvent(src, &event);
SensorInfo* sensor = nullptr;
for (auto& s : sensorsList) {
if (s.sensorHandle == event.sensorHandle) {
sensor = &s;
break;
}
}
if (sensor && sensor->type == SensorType::PICK_UP_GESTURE) {
if (event.u.scalar != 1) {
continue;
}
event.sensorType = SensorType::PICK_UP_GESTURE;
}
dstVec.push_back(event);
} }
} }

View File

@ -20,6 +20,7 @@
#include <android/hardware/sensors/1.0/ISensors.h> #include <android/hardware/sensors/1.0/ISensors.h>
#include <hardware/sensors.h> #include <hardware/sensors.h>
#include <mutex> #include <mutex>
#include <vector>
namespace android { namespace android {
namespace hardware { namespace hardware {
@ -63,9 +64,11 @@ struct Sensors : public ::android::hardware::sensors::V1_0::ISensors {
std::mutex mPollLock; std::mutex mPollLock;
int getHalDeviceVersion() const; int getHalDeviceVersion() const;
std::vector<SensorInfo> getFixedUpSensorList();
static void convertFromSensorEvents(size_t count, const sensors_event_t* src, static void convertFromSensorEvents(size_t count, const sensors_event_t* src,
hidl_vec<Event>* dst); std::vector<Event>& dst,
std::vector<SensorInfo> sensorsList);
DISALLOW_COPY_AND_ASSIGN(Sensors); DISALLOW_COPY_AND_ASSIGN(Sensors);
}; };

View File

@ -374,6 +374,25 @@ int convertFromRateLevel(RateLevel rate) {
} }
} }
bool patchXiaomiPickupSensor(SensorInfo& sensor) {
if (sensor.typeAsString != "xiaomi.sensor.pickup") {
return true;
}
/*
* Implement only the wake-up version of this sensor.
*/
if (!(sensor.flags & SensorFlagBits::WAKE_UP)) {
return false;
}
sensor.type = SensorType::PICK_UP_GESTURE;
sensor.typeAsString = SENSOR_STRING_TYPE_PICK_UP_GESTURE;
sensor.maxRange = 1;
return true;
}
} // namespace implementation } // namespace implementation
} // namespace V1_0 } // namespace V1_0
} // namespace sensors } // namespace sensors

View File

@ -34,6 +34,8 @@ void convertToSensorEvent(const Event& src, sensors_event_t* dst);
bool convertFromSharedMemInfo(const SharedMemInfo& memIn, sensors_direct_mem_t* memOut); bool convertFromSharedMemInfo(const SharedMemInfo& memIn, sensors_direct_mem_t* memOut);
int convertFromRateLevel(RateLevel rate); int convertFromRateLevel(RateLevel rate);
bool patchXiaomiPickupSensor(SensorInfo& sensor);
} // namespace implementation } // namespace implementation
} // namespace V1_0 } // namespace V1_0
} // namespace sensors } // namespace sensors