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

Commit 76dd5dcb authored by Eva Chen's avatar Eva Chen Committed by Android (Google) Code Review
Browse files

Merge changes from topic "heading_api_native"

* changes:
  Add XML files used to declare TYPE_HEADING sensor support.
  Add TYPE_HEADING sensor type to sensor NDK.
parents 9dfca764 0156af48
Loading
Loading
Loading
Loading
+20 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2022 The Android Open Source Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->

<!-- Feature for devices with a heading sensor. -->
<permissions>
    <feature name="android.hardware.sensor.heading" />
</permissions>
+26 −0
Original line number Diff line number Diff line
@@ -301,6 +301,14 @@ enum {
     * supported and a value of 0 means not supported.
     */
    ASENSOR_TYPE_GYROSCOPE_LIMITED_AXES_UNCALIBRATED = 41,
    /**
     * {@link ASENSOR_TYPE_HEADING}
     * reporting-mode: continuous
     *
     * A heading sensor measures the direction in which the device is pointing
     * relative to true north in degrees.
     */
    ASENSOR_TYPE_HEADING = 42,
};

/**
@@ -563,6 +571,23 @@ typedef struct ALimitedAxesImuUncalibratedEvent {
    };
} ALimitedAxesImuUncalibratedEvent;

typedef struct AHeadingEvent {
    /**
     * The direction in which the device is pointing relative to true north in
     * degrees. The value must be between 0.0 (inclusive) and 360.0 (exclusive),
     * with 0 indicating north, 90 east, 180 south, and 270 west.
     */
    float heading;
    /**
     * Accuracy is defined at 68% confidence. In the case where the underlying
     * distribution is assumed Gaussian normal, this would be considered one
     * standard deviation. For example, if the heading returns 60 degrees, and
     * accuracy returns 10 degrees, then there is a 68 percent probability of
     * the true heading being between 50 degrees and 70 degrees.
     */
    float accuracy;
} AHeadingEvent;

/**
 * Information that describes a sensor event, refer to
 * <a href="/reference/android/hardware/SensorEvent">SensorEvent</a> for additional
@@ -602,6 +627,7 @@ typedef struct ASensorEvent {
            AHeadTrackerEvent head_tracker;
            ALimitedAxesImuEvent limited_axes_imu;
            ALimitedAxesImuUncalibratedEvent limited_axes_imu_uncalibrated;
            AHeadingEvent heading;
        };
        union {
            uint64_t        data[8];
+4 −0
Original line number Diff line number Diff line
@@ -296,6 +296,10 @@ Sensor::Sensor(struct sensor_t const& hwSensor, const uuid_t& uuid, int halVersi
        mStringType = SENSOR_STRING_TYPE_GYROSCOPE_LIMITED_AXES_UNCALIBRATED;
        mFlags |= SENSOR_FLAG_CONTINUOUS_MODE;
        break;
    case SENSOR_TYPE_HEADING:
        mStringType = SENSOR_STRING_TYPE_HEADING;
        mFlags |= SENSOR_FLAG_CONTINUOUS_MODE;
        break;
    default:
        // Only pipe the stringType, requiredPermission and flags for custom sensors.
        if (halVersion > SENSORS_DEVICE_API_VERSION_1_0 && hwSensor.stringType) {
+3 −0
Original line number Diff line number Diff line
@@ -67,6 +67,9 @@ size_t eventSizeBySensorType(int type) {
        case SENSOR_TYPE_HEAD_TRACKER:
            return 7;

        case SENSOR_TYPE_HEADING:
            return 2;

        default:
            return 3;
    }