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

Commit b48171d3 authored by Vladimir Komsiyski's avatar Vladimir Komsiyski
Browse files

Address SensorAdditionalInfo API feedback

Fix: 403591392
Test: presubmit
Flag: android.companion.virtualdevice.flags.virtual_sensor_additional_info
Change-Id: I77c271d7ce0a39aa1314c91b21a4883dcbe28ee4
parent cc219cbe
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -174,7 +174,7 @@ public final class VirtualSensor implements Parcelable {
    @FlaggedApi(Flags.FLAG_VIRTUAL_SENSOR_ADDITIONAL_INFO)
    public void sendAdditionalInfo(@NonNull VirtualSensorAdditionalInfo info) {
        if (!Flags.virtualSensorAdditionalInfo()) {
            return;
            throw new UnsupportedOperationException("Sensor additional info not supported.");
        }
        if ((mFlags & VirtualSensorConfig.ADDITIONAL_INFO_MASK) == 0) {
            throw new UnsupportedOperationException("Sensor additional info not supported.");
+27 −8
Original line number Diff line number Diff line
@@ -90,6 +90,7 @@ public final class VirtualSensorAdditionalInfo implements Parcelable {
     *
     * @see SensorAdditionalInfo#type
     */
    @VirtualSensorAdditionalInfo.Type
    public int getType() {
        return mType;
    }
@@ -114,6 +115,21 @@ public final class VirtualSensorAdditionalInfo implements Parcelable {
        @NonNull
        private final ArrayList<float[]> mValues = new ArrayList<>();

        /** Payload size for {@link SensorAdditionalInfo#TYPE_SAMPLING} */
        private static final int TYPE_SAMPLING_PLAYLOAD_SIZE = 2;

        /** Payload size for {@link SensorAdditionalInfo#TYPE_UNTRACKED_DELAY} */
        private static final int TYPE_UNTRACKED_DELAY_PAYLOAD_SIZE = 2;

        /** Payload size for {@link SensorAdditionalInfo#TYPE_INTERNAL_TEMPERATURE} */
        private static final int TYPE_INTERNAL_TEMPERATURE_PLAYLOAD_SIZE = 1;

        /** Payload size for {@link SensorAdditionalInfo#TYPE_VEC3_CALIBRATION} */
        private static final int TYPE_VEC3_CALIBRATION_PAYLOAD_SIZE = 12;

        /** Payload size for {@link SensorAdditionalInfo#TYPE_SENSOR_PLACEMENT} */
        private static final int TYPE_SENSOR_PLACEMENT_PAYLOAD_SIZE = 12;

        /**
         * Creates a new builder.
         *
@@ -135,28 +151,31 @@ public final class VirtualSensorAdditionalInfo implements Parcelable {
        }

        /**
         * Additional info payload data represented in float values. Depending on the type of
         * information, this may be null.
         * Additional info payload data represented in float values.
         *
         * @param values the float values of this additional info frame.
         * @throws IllegalArgumentException if the payload size doesn't match the expectation
         *   for the given type, as documented in {@link SensorAdditionalInfo}.
         * @see SensorAdditionalInfo#floatValues
         */
        @NonNull
        public Builder addValues(@NonNull float[] values) {
            if (values.length > 14) {
                throw new IllegalArgumentException("Maximum payload value size is 14.");
            }
            if (mValues.isEmpty()) {
                switch (mType) {
                    case SensorAdditionalInfo.TYPE_UNTRACKED_DELAY:
                        assertValuesLength(values, TYPE_UNTRACKED_DELAY_PAYLOAD_SIZE);
                        break;
                    case SensorAdditionalInfo.TYPE_SAMPLING:
                        assertValuesLength(values, 2);
                        assertValuesLength(values, TYPE_SAMPLING_PLAYLOAD_SIZE);
                        break;
                    case SensorAdditionalInfo.TYPE_INTERNAL_TEMPERATURE:
                        assertValuesLength(values, 1);
                        assertValuesLength(values, TYPE_INTERNAL_TEMPERATURE_PLAYLOAD_SIZE);
                        break;
                    case SensorAdditionalInfo.TYPE_VEC3_CALIBRATION:
                        assertValuesLength(values, TYPE_VEC3_CALIBRATION_PAYLOAD_SIZE);
                        break;
                    case SensorAdditionalInfo.TYPE_SENSOR_PLACEMENT:
                        assertValuesLength(values, 11);
                        assertValuesLength(values, TYPE_SENSOR_PLACEMENT_PAYLOAD_SIZE);
                        break;
                }
            } else if (values.length != mValues.getFirst().length) {