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

Commit 1e01943f authored by Jean-Baptiste Queru's avatar Jean-Baptiste Queru Committed by Android Git Automerger
Browse files

am ae311f4c: am 17548b3c: Revert "be more robust with handling unknown sensors"

* commit 'ae311f4c':
  Revert "be more robust with handling unknown sensors"
parents 1f8eddbe ae311f4c
Loading
Loading
Loading
Loading
+22 −56
Original line number Original line Diff line number Diff line
@@ -204,71 +204,37 @@ public final class Sensor {
    // TODO(): The following arrays are fragile and error-prone. This needs to be refactored.
    // TODO(): The following arrays are fragile and error-prone. This needs to be refactored.


    // Note: This needs to be updated, whenever a new sensor is added.
    // Note: This needs to be updated, whenever a new sensor is added.
    // Holds the reporting mode and maximum length of the values array
    private static int[] sSensorReportingModes = {
    // associated with
            REPORTING_MODE_CONTINUOUS, REPORTING_MODE_CONTINUOUS, REPORTING_MODE_CONTINUOUS,
    // {@link SensorEvent} or {@link TriggerEvent} for the Sensor
            REPORTING_MODE_CONTINUOUS, REPORTING_MODE_ON_CHANGE, REPORTING_MODE_CONTINUOUS,
    private static final int[] sSensorReportingModes = {
            REPORTING_MODE_ON_CHANGE, REPORTING_MODE_ON_CHANGE, REPORTING_MODE_CONTINUOUS,
            0, 0, // padding because sensor types start at 1
            REPORTING_MODE_CONTINUOUS, REPORTING_MODE_CONTINUOUS, REPORTING_MODE_ON_CHANGE,
            REPORTING_MODE_CONTINUOUS, 3, // SENSOR_TYPE_ACCELEROMETER
            REPORTING_MODE_ON_CHANGE, REPORTING_MODE_CONTINUOUS, REPORTING_MODE_CONTINUOUS,
            REPORTING_MODE_CONTINUOUS, 3, // SENSOR_TYPE_GEOMAGNETIC_FIELD
            REPORTING_MODE_CONTINUOUS, REPORTING_MODE_ONE_SHOT };
            REPORTING_MODE_CONTINUOUS, 3, // SENSOR_TYPE_ORIENTATION

            REPORTING_MODE_CONTINUOUS, 3, // SENSOR_TYPE_GYROSCOPE
    // Note: This needs to be updated, whenever a new sensor is added.
            REPORTING_MODE_ON_CHANGE,  3, // SENSOR_TYPE_LIGHT
    // Holds the maximum length of the values array associated with {@link SensorEvent} or
            REPORTING_MODE_CONTINUOUS, 3, // SENSOR_TYPE_PRESSURE
    // {@link TriggerEvent} for the Sensor
            REPORTING_MODE_ON_CHANGE,  3, // SENSOR_TYPE_TEMPERATURE
    private static int[] sMaxLengthValuesArray = {
            REPORTING_MODE_ON_CHANGE,  3, // SENSOR_TYPE_PROXIMITY
            3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 5, 3, 3,
            REPORTING_MODE_CONTINUOUS, 3, // SENSOR_TYPE_GRAVITY
            6, 4, 6, 1 };
            REPORTING_MODE_CONTINUOUS, 3, // SENSOR_TYPE_LINEAR_ACCELERATION
            REPORTING_MODE_CONTINUOUS, 5, // SENSOR_TYPE_ROTATION_VECTOR
            REPORTING_MODE_ON_CHANGE,  3, // SENSOR_TYPE_RELATIVE_HUMIDITY
            REPORTING_MODE_ON_CHANGE,  3, // SENSOR_TYPE_AMBIENT_TEMPERATURE
            REPORTING_MODE_CONTINUOUS, 6, // SENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED
            REPORTING_MODE_CONTINUOUS, 4, // SENSOR_TYPE_GAME_ROTATION_VECTOR
            REPORTING_MODE_CONTINUOUS, 6, // SENSOR_TYPE_GYROSCOPE_UNCALIBRATED
            REPORTING_MODE_ONE_SHOT,   1, // SENSOR_TYPE_SIGNIFICANT_MOTION
            // added post 4.3
            REPORTING_MODE_ON_CHANGE,  1, // SENSOR_TYPE_STEP_DETECTOR
            REPORTING_MODE_ON_CHANGE,  1, // SENSOR_TYPE_STEP_COUNTER
            REPORTING_MODE_CONTINUOUS, 5  // SENSOR_TYPE_GEOMAGNETIC_ROTATION_VECTOR
    };


    static int getReportingMode(Sensor sensor) {
    static int getReportingMode(Sensor sensor) {
        int offset = sensor.mType * 2;
        // mType starts from offset 1.
        if (offset >= sSensorReportingModes.length) {
        return sSensorReportingModes[sensor.mType - 1];
            // we don't know about this sensor, so this is probably a
            // vendor-defined sensor, in that case, we figure out the reporting
            // mode from the sensor meta-data.
            int minDelay = sensor.mMinDelay;
            if (minDelay == 0) {
                return REPORTING_MODE_ON_CHANGE;
            } else if (minDelay < 0) {
                return REPORTING_MODE_ONE_SHOT;
            } else {
                return REPORTING_MODE_CONTINUOUS;
            }
        }
        return sSensorReportingModes[offset];
    }
    }


    static int getMaxLengthValuesArray(Sensor sensor, int sdkLevel) {
    static int getMaxLengthValuesArray(Sensor sensor, int sdkLevel) {
        int type = sensor.mType;
        // mType starts from offset 1.
        int len = sMaxLengthValuesArray[sensor.mType - 1];

        // RotationVector length has changed to 3 to 5 for API level 18
        // RotationVector length has changed to 3 to 5 for API level 18
        // Set it to 3 for backward compatibility.
        // Set it to 3 for backward compatibility.
        if (type == Sensor.TYPE_ROTATION_VECTOR &&
        if (sensor.getType() == Sensor.TYPE_ROTATION_VECTOR &&
                sdkLevel <= Build.VERSION_CODES.JELLY_BEAN_MR1) {
                sdkLevel <= Build.VERSION_CODES.JELLY_BEAN_MR1) {
            return 3;
            len = 3;
        }
        int offset = type * 2 + 1;
        if (offset >= sSensorReportingModes.length) {
            // we don't know about this sensor, so this is probably a
            // vendor-defined sensor, in that case, we don't know how many value
            // it has
            // so we return the maximum and assume the app will know.
            // FIXME: sensor HAL should advertise how much data is returned per
            // sensor
            return 16;
        }
        }
        return sSensorReportingModes[offset];
        return len;
    }
    }


    /* Some of these fields are set only by the native bindings in
    /* Some of these fields are set only by the native bindings in
+1 −7
Original line number Original line Diff line number Diff line
@@ -142,13 +142,7 @@ private:
        while ((n = q->read(buffer, 16)) > 0) {
        while ((n = q->read(buffer, 16)) > 0) {
            for (int i=0 ; i<n ; i++) {
            for (int i=0 ; i<n ; i++) {


                if (buffer[i].type == SENSOR_TYPE_STEP_COUNTER) {
                    // step-counter returns a uint64, but the java API only deals with floats
                    float value = float(buffer[i].u64.step_counter);
                    env->SetFloatArrayRegion(mScratch, 0, 1, &value);
                } else {
                env->SetFloatArrayRegion(mScratch, 0, 16, buffer[i].data);
                env->SetFloatArrayRegion(mScratch, 0, 16, buffer[i].data);
                }


                env->CallVoidMethod(mReceiverObject,
                env->CallVoidMethod(mReceiverObject,
                        gBaseEventQueueClassInfo.dispatchSensorEvent,
                        gBaseEventQueueClassInfo.dispatchSensorEvent,