Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0c3dc88d authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Revert "Use resolution to round sensor event values"" into rvc-dev am:...

Merge "Revert "Use resolution to round sensor event values"" into rvc-dev am: d838f693 am: 66d56f8d

Change-Id: I6925f740243040993aa77216d242b4c05f0095f8
parents cced7079 66d56f8d
Loading
Loading
Loading
Loading
+2 −29
Original line number Original line Diff line number Diff line
@@ -143,14 +143,6 @@ void SensorDevice::initializeSensorList() {
                for (size_t i=0 ; i < count; i++) {
                for (size_t i=0 ; i < count; i++) {
                    sensor_t sensor;
                    sensor_t sensor;
                    convertToSensor(convertToOldSensorInfo(list[i]), &sensor);
                    convertToSensor(convertToOldSensorInfo(list[i]), &sensor);

                    if (sensor.resolution == 0) {
                        // Don't crash here or the device will go into a crashloop.
                        ALOGE("%s must have a non-zero resolution", sensor.name);
                        // For simple algos, map their resolution to 1 if it's not specified
                        sensor.resolution = SensorDeviceUtils::defaultResolutionForType(sensor.type);
                    }

                    // Sanity check and clamp power if it is 0 (or close)
                    // Sanity check and clamp power if it is 0 (or close)
                    if (sensor.power < minPowerMa) {
                    if (sensor.power < minPowerMa) {
                        ALOGI("Reported power %f not deemed sane, clamping to %f",
                        ALOGI("Reported power %f not deemed sane, clamping to %f",
@@ -516,7 +508,7 @@ ssize_t SensorDevice::pollHal(sensors_event_t* buffer, size_t count) {
                    const auto &events,
                    const auto &events,
                    const auto &dynamicSensorsAdded) {
                    const auto &dynamicSensorsAdded) {
                    if (result == Result::OK) {
                    if (result == Result::OK) {
                        convertToSensorEventsAndQuantize(convertToNewEvents(events),
                        convertToSensorEvents(convertToNewEvents(events),
                                convertToNewSensorInfos(dynamicSensorsAdded), buffer);
                                convertToNewSensorInfos(dynamicSensorsAdded), buffer);
                        err = (ssize_t)events.size();
                        err = (ssize_t)events.size();
                    } else {
                    } else {
@@ -579,8 +571,6 @@ ssize_t SensorDevice::pollFmq(sensors_event_t* buffer, size_t maxNumEventsToRead


            for (size_t i = 0; i < eventsToRead; i++) {
            for (size_t i = 0; i < eventsToRead; i++) {
                convertToSensorEvent(mEventBuffer[i], &buffer[i]);
                convertToSensorEvent(mEventBuffer[i], &buffer[i]);
                android::SensorDeviceUtils::quantizeSensorEventValues(&buffer[i],
                        getResolutionForSensor(buffer[i].sensor));
            }
            }
            eventsRead = eventsToRead;
            eventsRead = eventsToRead;
        } else {
        } else {
@@ -1087,7 +1077,7 @@ void SensorDevice::convertToSensorEvent(
    }
    }
}
}


void SensorDevice::convertToSensorEventsAndQuantize(
void SensorDevice::convertToSensorEvents(
        const hidl_vec<Event> &src,
        const hidl_vec<Event> &src,
        const hidl_vec<SensorInfo> &dynamicSensorsAdded,
        const hidl_vec<SensorInfo> &dynamicSensorsAdded,
        sensors_event_t *dst) {
        sensors_event_t *dst) {
@@ -1098,24 +1088,7 @@ void SensorDevice::convertToSensorEventsAndQuantize(


    for (size_t i = 0; i < src.size(); ++i) {
    for (size_t i = 0; i < src.size(); ++i) {
        V2_1::implementation::convertToSensorEvent(src[i], &dst[i]);
        V2_1::implementation::convertToSensorEvent(src[i], &dst[i]);
        android::SensorDeviceUtils::quantizeSensorEventValues(&dst[i],
                getResolutionForSensor(dst[i].sensor));
    }
}

float SensorDevice::getResolutionForSensor(int sensorHandle) {
    for (size_t i = 0; i < mSensorList.size(); i++) {
      if (sensorHandle == mSensorList[i].handle) {
        return mSensorList[i].resolution;
      }
    }

    auto it = mConnectedDynamicSensors.find(sensorHandle);
    if (it != mConnectedDynamicSensors.end()) {
      return it->second->resolution;
    }
    }

    return 0;
}
}


void SensorDevice::handleHidlDeath(const std::string & detail) {
void SensorDevice::handleHidlDeath(const std::string & detail) {
+1 −3
Original line number Original line Diff line number Diff line
@@ -233,13 +233,11 @@ private:


    void convertToSensorEvent(const Event &src, sensors_event_t *dst);
    void convertToSensorEvent(const Event &src, sensors_event_t *dst);


    void convertToSensorEventsAndQuantize(
    void convertToSensorEvents(
            const hardware::hidl_vec<Event> &src,
            const hardware::hidl_vec<Event> &src,
            const hardware::hidl_vec<SensorInfo> &dynamicSensorsAdded,
            const hardware::hidl_vec<SensorInfo> &dynamicSensorsAdded,
            sensors_event_t *dst);
            sensors_event_t *dst);


    float getResolutionForSensor(int sensorHandle);

    bool mIsDirectReportSupported;
    bool mIsDirectReportSupported;


    typedef hardware::MessageQueue<uint32_t, hardware::kSynchronizedReadWrite> WakeLockQueue;
    typedef hardware::MessageQueue<uint32_t, hardware::kSynchronizedReadWrite> WakeLockQueue;
+0 −96
Original line number Original line Diff line number Diff line
@@ -17,112 +17,16 @@
#include "SensorDeviceUtils.h"
#include "SensorDeviceUtils.h"


#include <android/hardware/sensors/1.0/ISensors.h>
#include <android/hardware/sensors/1.0/ISensors.h>
#include <android/hardware/sensors/2.1/ISensors.h>
#include <utils/Log.h>
#include <utils/Log.h>


#include <chrono>
#include <chrono>
#include <cmath>
#include <thread>
#include <thread>


using ::android::hardware::Void;
using ::android::hardware::Void;
using SensorTypeV2_1 = android::hardware::sensors::V2_1::SensorType;
using namespace android::hardware::sensors::V1_0;
using namespace android::hardware::sensors::V1_0;


namespace android {
namespace android {
namespace SensorDeviceUtils {
namespace SensorDeviceUtils {
namespace {

inline void quantizeValue(float *value, double resolution) {
    // Increase the value of the sensor's nominal resolution to ensure that
    // sensor accuracy improvements, like runtime calibration, are not masked
    // during requantization.
    double incRes = 0.25 * resolution;
    *value = round(static_cast<double>(*value) / incRes) * incRes;
}

}  // namespace

void quantizeSensorEventValues(sensors_event_t *event, float resolution) {
    LOG_FATAL_IF(resolution == 0, "Resolution must be specified for all sensors!");
    if (resolution == 0) {
        return;
    }

    size_t axes = 0;
    switch ((SensorTypeV2_1)event->type) {
        case SensorTypeV2_1::ACCELEROMETER:
        case SensorTypeV2_1::MAGNETIC_FIELD:
        case SensorTypeV2_1::ORIENTATION:
        case SensorTypeV2_1::GYROSCOPE:
        case SensorTypeV2_1::GRAVITY:
        case SensorTypeV2_1::LINEAR_ACCELERATION:
        case SensorTypeV2_1::MAGNETIC_FIELD_UNCALIBRATED:
        case SensorTypeV2_1::GYROSCOPE_UNCALIBRATED:
        case SensorTypeV2_1::ACCELEROMETER_UNCALIBRATED:
            axes = 3;
            break;
        case SensorTypeV2_1::GAME_ROTATION_VECTOR:
            axes = 4;
            break;
        case SensorTypeV2_1::ROTATION_VECTOR:
        case SensorTypeV2_1::GEOMAGNETIC_ROTATION_VECTOR:
            axes = 5;
            break;
        case SensorTypeV2_1::DEVICE_ORIENTATION:
        case SensorTypeV2_1::LIGHT:
        case SensorTypeV2_1::PRESSURE:
        case SensorTypeV2_1::TEMPERATURE:
        case SensorTypeV2_1::PROXIMITY:
        case SensorTypeV2_1::RELATIVE_HUMIDITY:
        case SensorTypeV2_1::AMBIENT_TEMPERATURE:
        case SensorTypeV2_1::SIGNIFICANT_MOTION:
        case SensorTypeV2_1::STEP_DETECTOR:
        case SensorTypeV2_1::TILT_DETECTOR:
        case SensorTypeV2_1::WAKE_GESTURE:
        case SensorTypeV2_1::GLANCE_GESTURE:
        case SensorTypeV2_1::PICK_UP_GESTURE:
        case SensorTypeV2_1::WRIST_TILT_GESTURE:
        case SensorTypeV2_1::STATIONARY_DETECT:
        case SensorTypeV2_1::MOTION_DETECT:
        case SensorTypeV2_1::HEART_BEAT:
        case SensorTypeV2_1::LOW_LATENCY_OFFBODY_DETECT:
        case SensorTypeV2_1::HINGE_ANGLE:
            axes = 1;
            break;
        case SensorTypeV2_1::POSE_6DOF:
            axes = 15;
            break;
        default:
            // No other sensors have data that needs to be rounded.
            break;
    }

    // sensor_event_t is a union so we're able to perform the same quanitization action for most
    // sensors by only knowing the number of axes their output data has.
    for (size_t i = 0; i < axes; i++) {
        quantizeValue(&event->data[i], resolution);
    }
}

float defaultResolutionForType(int type) {
    switch ((SensorTypeV2_1)type) {
        case SensorTypeV2_1::SIGNIFICANT_MOTION:
        case SensorTypeV2_1::STEP_DETECTOR:
        case SensorTypeV2_1::STEP_COUNTER:
        case SensorTypeV2_1::TILT_DETECTOR:
        case SensorTypeV2_1::WAKE_GESTURE:
        case SensorTypeV2_1::GLANCE_GESTURE:
        case SensorTypeV2_1::PICK_UP_GESTURE:
        case SensorTypeV2_1::WRIST_TILT_GESTURE:
        case SensorTypeV2_1::STATIONARY_DETECT:
        case SensorTypeV2_1::MOTION_DETECT:
            return 1.0f;
        default:
            // fall through and return 0 for all other types
            break;
    }
    return 0.0f;
}


HidlServiceRegistrationWaiter::HidlServiceRegistrationWaiter() {
HidlServiceRegistrationWaiter::HidlServiceRegistrationWaiter() {
}
}
+0 −7
Original line number Original line Diff line number Diff line
@@ -18,7 +18,6 @@
#define ANDROID_SENSOR_DEVICE_UTIL
#define ANDROID_SENSOR_DEVICE_UTIL


#include <android/hidl/manager/1.0/IServiceNotification.h>
#include <android/hidl/manager/1.0/IServiceNotification.h>
#include <hardware/sensors.h>


#include <condition_variable>
#include <condition_variable>
#include <thread>
#include <thread>
@@ -30,12 +29,6 @@ using ::android::hidl::manager::V1_0::IServiceNotification;
namespace android {
namespace android {
namespace SensorDeviceUtils {
namespace SensorDeviceUtils {


// Ensures a sensor event doesn't provide values finer grained than its sensor resolution allows.
void quantizeSensorEventValues(sensors_event_t *event, float resolution);

// Provides a default resolution for simple sensor types if one wasn't provided by the HAL.
float defaultResolutionForType(int type);

class HidlServiceRegistrationWaiter : public IServiceNotification {
class HidlServiceRegistrationWaiter : public IServiceNotification {
public:
public: