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

Commit cde49421 authored by Vladimir Komsiyski's avatar Vladimir Komsiyski Committed by Automerger Merge Worker
Browse files

Merge "Add support for more VirtualSensor properties." into udc-dev am: b8b16486

parents 211c8077 b8b16486
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -3333,7 +3333,12 @@ package android.companion.virtual.sensor {
    method public int describeContents();
    method public int getDirectChannelTypesSupported();
    method public int getHighestDirectReportRateLevel();
    method public int getMaxDelay();
    method public float getMaximumRange();
    method public int getMinDelay();
    method @NonNull public String getName();
    method public float getPower();
    method public float getResolution();
    method public int getType();
    method @Nullable public String getVendor();
    method public void writeToParcel(@NonNull android.os.Parcel, int);
@@ -3345,6 +3350,11 @@ package android.companion.virtual.sensor {
    method @NonNull public android.companion.virtual.sensor.VirtualSensorConfig build();
    method @NonNull public android.companion.virtual.sensor.VirtualSensorConfig.Builder setDirectChannelTypesSupported(int);
    method @NonNull public android.companion.virtual.sensor.VirtualSensorConfig.Builder setHighestDirectReportRateLevel(int);
    method @NonNull public android.companion.virtual.sensor.VirtualSensorConfig.Builder setMaxDelay(int);
    method @NonNull public android.companion.virtual.sensor.VirtualSensorConfig.Builder setMaximumRange(float);
    method @NonNull public android.companion.virtual.sensor.VirtualSensorConfig.Builder setMinDelay(int);
    method @NonNull public android.companion.virtual.sensor.VirtualSensorConfig.Builder setPower(float);
    method @NonNull public android.companion.virtual.sensor.VirtualSensorConfig.Builder setResolution(float);
    method @NonNull public android.companion.virtual.sensor.VirtualSensorConfig.Builder setVendor(@Nullable String);
  }
+119 −1
Original line number Diff line number Diff line
@@ -50,14 +50,25 @@ public final class VirtualSensorConfig implements Parcelable {
    private final String mName;
    @Nullable
    private final String mVendor;
    private final float mMaximumRange;
    private final float mResolution;
    private final float mPower;
    private final int mMinDelay;
    private final int mMaxDelay;

    private final int mFlags;

    private VirtualSensorConfig(int type, @NonNull String name, @Nullable String vendor,
            float maximumRange, float resolution, float power, int minDelay, int maxDelay,
            int flags) {
        mType = type;
        mName = name;
        mVendor = vendor;
        mMaximumRange = maximumRange;
        mResolution = resolution;
        mPower = power;
        mMinDelay = minDelay;
        mMaxDelay = maxDelay;
        mFlags = flags;
    }

@@ -65,6 +76,11 @@ public final class VirtualSensorConfig implements Parcelable {
        mType = parcel.readInt();
        mName = parcel.readString8();
        mVendor = parcel.readString8();
        mMaximumRange = parcel.readFloat();
        mResolution = parcel.readFloat();
        mPower = parcel.readFloat();
        mMinDelay = parcel.readInt();
        mMaxDelay = parcel.readInt();
        mFlags = parcel.readInt();
    }

@@ -78,6 +94,11 @@ public final class VirtualSensorConfig implements Parcelable {
        parcel.writeInt(mType);
        parcel.writeString8(mName);
        parcel.writeString8(mVendor);
        parcel.writeFloat(mMaximumRange);
        parcel.writeFloat(mResolution);
        parcel.writeFloat(mPower);
        parcel.writeInt(mMinDelay);
        parcel.writeInt(mMaxDelay);
        parcel.writeInt(mFlags);
    }

@@ -108,6 +129,47 @@ public final class VirtualSensorConfig implements Parcelable {
        return mVendor;
    }

    /**
     * Returns maximum range of the sensor in the sensor's unit.
     * @see Sensor#getMaximumRange
     */
    public float getMaximumRange() {
        return mMaximumRange;
    }

    /**
     * Returns The resolution of the sensor in the sensor's unit.
     * @see Sensor#getResolution
     */
    public float getResolution() {
        return mResolution;
    }

    /**
     * Returns The power in mA used by this sensor while in use.
     * @see Sensor#getPower
     */
    public float getPower() {
        return mPower;
    }

    /**
     * Returns The minimum delay allowed between two events in microseconds, or zero depending on
     * the sensor type.
     * @see Sensor#getMinDelay
     */
    public int getMinDelay() {
        return mMinDelay;
    }

    /**
     * Returns The maximum delay between two sensor events in microseconds.
     * @see Sensor#getMaxDelay
     */
    public int getMaxDelay() {
        return mMaxDelay;
    }

    /**
     * Returns the highest supported direct report mode rate level of the sensor.
     *
@@ -157,6 +219,11 @@ public final class VirtualSensorConfig implements Parcelable {
        private final String mName;
        @Nullable
        private String mVendor;
        private float mMaximumRange;
        private float mResolution;
        private float mPower;
        private int mMinDelay;
        private int mMaxDelay;
        private int mFlags;
        @SensorDirectChannel.RateLevel
        int mHighestDirectReportRateLevel;
@@ -193,7 +260,8 @@ public final class VirtualSensorConfig implements Parcelable {
                throw new IllegalArgumentException("Highest direct report rate level is "
                        + "required for sensors with direct channel support.");
            }
            return new VirtualSensorConfig(mType, mName, mVendor, mFlags);
            return new VirtualSensorConfig(mType, mName, mVendor, mMaximumRange, mResolution,
                    mPower, mMinDelay, mMaxDelay, mFlags);
        }

        /**
@@ -205,6 +273,56 @@ public final class VirtualSensorConfig implements Parcelable {
            return this;
        }

        /**
         * Sets the maximum range of the sensor in the sensor's unit.
         * @see Sensor#getMaximumRange
         */
        @NonNull
        public VirtualSensorConfig.Builder setMaximumRange(float maximumRange) {
            mMaximumRange = maximumRange;
            return this;
        }

        /**
         * Sets the resolution of the sensor in the sensor's unit.
         * @see Sensor#getResolution
         */
        @NonNull
        public VirtualSensorConfig.Builder setResolution(float resolution) {
            mResolution = resolution;
            return this;
        }

        /**
         * Sets the power in mA used by this sensor while in use.
         * @see Sensor#getPower
         */
        @NonNull
        public VirtualSensorConfig.Builder setPower(float power) {
            mPower = power;
            return this;
        }

        /**
         * Sets the minimum delay allowed between two events in microseconds.
         * @see Sensor#getMinDelay
         */
        @NonNull
        public VirtualSensorConfig.Builder setMinDelay(int minDelay) {
            mMinDelay = minDelay;
            return this;
        }

        /**
         * Sets the maximum delay between two sensor events in microseconds.
         * @see Sensor#getMaxDelay
         */
        @NonNull
        public VirtualSensorConfig.Builder setMaxDelay(int maxDelay) {
            mMaxDelay = maxDelay;
            return this;
        }

        /**
         * Sets the highest supported rate level for direct sensor report.
         *
+3 −2
Original line number Diff line number Diff line
@@ -104,8 +104,9 @@ public class SensorController {
        }
        final int handle = mSensorManagerInternal.createRuntimeSensor(mVirtualDeviceId,
                config.getType(), config.getName(),
                config.getVendor() == null ? "" : config.getVendor(), config.getFlags(),
                mRuntimeSensorCallback);
                config.getVendor() == null ? "" : config.getVendor(), config.getMaximumRange(),
                config.getResolution(), config.getPower(), config.getMinDelay(),
                config.getMaxDelay(), config.getFlags(), mRuntimeSensorCallback);
        if (handle <= 0) {
            throw new SensorCreationException("Received an invalid virtual sensor handle.");
        }
+2 −1
Original line number Diff line number Diff line
@@ -60,7 +60,8 @@ public abstract class SensorManagerInternal {
     * @return The sensor handle.
     */
    public abstract int createRuntimeSensor(int deviceId, int type, @NonNull String name,
            @NonNull String vendor, int flags, @NonNull RuntimeSensorCallback callback);
            @NonNull String vendor, float maximumRange, float resolution, float power,
            int minDelay, int maxDelay, int flags, @NonNull RuntimeSensorCallback callback);

    /**
     * Unregisters the sensor with the given handle from the framework.
+6 −4
Original line number Diff line number Diff line
@@ -56,7 +56,8 @@ public class SensorService extends SystemService {
    private static native void unregisterProximityActiveListenerNative(long ptr);

    private static native int registerRuntimeSensorNative(long ptr, int deviceId, int type,
            String name, String vendor, int flags,
            String name, String vendor, float maximumRange, float resolution, float power,
            int minDelay, int maxDelay, int flags,
            SensorManagerInternal.RuntimeSensorCallback callback);
    private static native void unregisterRuntimeSensorNative(long ptr, int handle);
    private static native boolean sendRuntimeSensorEventNative(long ptr, int handle, int type,
@@ -96,10 +97,11 @@ public class SensorService extends SystemService {
    class LocalService extends SensorManagerInternal {
        @Override
        public int createRuntimeSensor(int deviceId, int type, @NonNull String name,
                @NonNull String vendor, int flags, @NonNull RuntimeSensorCallback callback) {
                @NonNull String vendor, float maximumRange, float resolution, float power,
                int minDelay, int maxDelay, int flags, @NonNull RuntimeSensorCallback callback) {
            synchronized (mLock) {
                int handle = registerRuntimeSensorNative(mPtr, deviceId, type, name, vendor, flags,
                        callback);
                int handle = registerRuntimeSensorNative(mPtr, deviceId, type, name, vendor,
                        maximumRange, resolution, power, minDelay, maxDelay, flags, callback);
                mRuntimeSensorHandles.add(handle);
                return handle;
            }
Loading