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

Commit c17b99d1 authored by Ahmad Khalil's avatar Ahmad Khalil
Browse files

Renaming Frequency Profile APIs

To prepare for the implementation of PWLE v2, which requires a new FrequencyProfile, we're renaming the existing profile to avoid naming conflicts:
- VibratorFrequencyProfile -> VibratorFrequencyProfileLegacy
- VibratorInfo.FrequencyProfile -> VibratorInfo.FrequencyProfileLegacy

The legacy APIs were never made part of the public API, so this renaming
should not affect external developers.

Bug: 347034419
Flag: android.os.vibrator.normalized_pwle_effects
Test: atest FrameworksVibratorCoreTests
Change-Id: I57bd2768d1253537a4a7cfeef00f111fa3989457
parent 79e00d91
Loading
Loading
Loading
Loading
+2 −2
Original line number Original line Diff line number Diff line
@@ -2603,7 +2603,7 @@ package android.os {


  public abstract class Vibrator {
  public abstract class Vibrator {
    method public int getDefaultVibrationIntensity(int);
    method public int getDefaultVibrationIntensity(int);
    method @Nullable public android.os.vibrator.VibratorFrequencyProfile getFrequencyProfile();
    method @Nullable public android.os.vibrator.VibratorFrequencyProfileLegacy getFrequencyProfileLegacy();
    method public boolean hasFrequencyControl();
    method public boolean hasFrequencyControl();
    field public static final int VIBRATION_INTENSITY_HIGH = 3; // 0x3
    field public static final int VIBRATION_INTENSITY_HIGH = 3; // 0x3
    field public static final int VIBRATION_INTENSITY_LOW = 1; // 0x1
    field public static final int VIBRATION_INTENSITY_LOW = 1; // 0x1
@@ -2793,7 +2793,7 @@ package android.os.vibrator {
    field @NonNull public static final android.os.Parcelable.Creator<android.os.vibrator.VibrationEffectSegment> CREATOR;
    field @NonNull public static final android.os.Parcelable.Creator<android.os.vibrator.VibrationEffectSegment> CREATOR;
  }
  }


  public final class VibratorFrequencyProfile {
  public final class VibratorFrequencyProfileLegacy {
    method public float getMaxAmplitudeMeasurementInterval();
    method public float getMaxAmplitudeMeasurementInterval();
    method @FloatRange(from=0, to=1) @NonNull public float[] getMaxAmplitudeMeasurements();
    method @FloatRange(from=0, to=1) @NonNull public float[] getMaxAmplitudeMeasurements();
    method public float getMaxFrequency();
    method public float getMaxFrequency();
+3 −2
Original line number Original line Diff line number Diff line
@@ -40,6 +40,7 @@ import android.os.vibrator.PrimitiveSegment;
import android.os.vibrator.RampSegment;
import android.os.vibrator.RampSegment;
import android.os.vibrator.StepSegment;
import android.os.vibrator.StepSegment;
import android.os.vibrator.VibrationEffectSegment;
import android.os.vibrator.VibrationEffectSegment;
import android.os.vibrator.VibratorFrequencyProfileLegacy;
import android.util.MathUtils;
import android.util.MathUtils;


import com.android.internal.util.Preconditions;
import com.android.internal.util.Preconditions;
@@ -1761,7 +1762,7 @@ public abstract class VibrationEffect implements Parcelable {
         * new value as fast as possible.
         * new value as fast as possible.
         *
         *
         * <p>Vibration parameter values will be truncated to conform to the device capabilities
         * <p>Vibration parameter values will be truncated to conform to the device capabilities
         * according to the {@link android.os.vibrator.VibratorFrequencyProfile}.
         * according to the {@link VibratorFrequencyProfileLegacy}.
         *
         *
         * @param duration        The length of time this transition should take. Value must be
         * @param duration        The length of time this transition should take. Value must be
         *                        non-negative and will be truncated to milliseconds.
         *                        non-negative and will be truncated to milliseconds.
@@ -1792,7 +1793,7 @@ public abstract class VibrationEffect implements Parcelable {
         * new values as fast as possible.
         * new values as fast as possible.
         *
         *
         * <p>Vibration parameters values will be truncated to conform to the device capabilities
         * <p>Vibration parameters values will be truncated to conform to the device capabilities
         * according to the {@link android.os.vibrator.VibratorFrequencyProfile}.
         * according to the {@link VibratorFrequencyProfileLegacy}.
         *
         *
         * @param duration         The length of time this transition should take. Value must be
         * @param duration         The length of time this transition should take. Value must be
         *                         non-negative and will be truncated to milliseconds.
         *                         non-negative and will be truncated to milliseconds.
+7 −4
Original line number Original line Diff line number Diff line
@@ -22,6 +22,7 @@ import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.Nullable;
import android.annotation.RequiresPermission;
import android.annotation.RequiresPermission;
import android.annotation.SuppressLint;
import android.annotation.SystemApi;
import android.annotation.SystemApi;
import android.annotation.SystemService;
import android.annotation.SystemService;
import android.annotation.TestApi;
import android.annotation.TestApi;
@@ -33,7 +34,7 @@ import android.hardware.vibrator.IVibrator;
import android.media.AudioAttributes;
import android.media.AudioAttributes;
import android.os.vibrator.Flags;
import android.os.vibrator.Flags;
import android.os.vibrator.VibrationConfig;
import android.os.vibrator.VibrationConfig;
import android.os.vibrator.VibratorFrequencyProfile;
import android.os.vibrator.VibratorFrequencyProfileLegacy;
import android.util.Log;
import android.util.Log;
import android.view.HapticFeedbackConstants;
import android.view.HapticFeedbackConstants;


@@ -290,13 +291,15 @@ public abstract class Vibrator {
     * @hide
     * @hide
     */
     */
    @TestApi
    @TestApi
    @SuppressLint("UnflaggedApi")
    @Nullable
    @Nullable
    public VibratorFrequencyProfile getFrequencyProfile() {
    public VibratorFrequencyProfileLegacy getFrequencyProfileLegacy() {
        VibratorInfo.FrequencyProfile frequencyProfile = getInfo().getFrequencyProfile();
        VibratorInfo.FrequencyProfileLegacy frequencyProfile =
                getInfo().getFrequencyProfileLegacy();
        if (frequencyProfile.isEmpty()) {
        if (frequencyProfile.isEmpty()) {
            return null;
            return null;
        }
        }
        return new VibratorFrequencyProfile(frequencyProfile);
        return new VibratorFrequencyProfileLegacy(frequencyProfile);
    }
    }


    /**
    /**
+32 −32
Original line number Original line Diff line number Diff line
@@ -59,7 +59,7 @@ public class VibratorInfo implements Parcelable {
    private final int mPwlePrimitiveDurationMax;
    private final int mPwlePrimitiveDurationMax;
    private final int mPwleSizeMax;
    private final int mPwleSizeMax;
    private final float mQFactor;
    private final float mQFactor;
    private final FrequencyProfile mFrequencyProfile;
    private final FrequencyProfileLegacy mFrequencyProfileLegacy;
    private final int mMaxEnvelopeEffectSize;
    private final int mMaxEnvelopeEffectSize;
    private final int mMinEnvelopeEffectControlPointDurationMillis;
    private final int mMinEnvelopeEffectControlPointDurationMillis;
    private final int mMaxEnvelopeEffectControlPointDurationMillis;
    private final int mMaxEnvelopeEffectControlPointDurationMillis;
@@ -75,7 +75,7 @@ public class VibratorInfo implements Parcelable {
        mPwlePrimitiveDurationMax = in.readInt();
        mPwlePrimitiveDurationMax = in.readInt();
        mPwleSizeMax = in.readInt();
        mPwleSizeMax = in.readInt();
        mQFactor = in.readFloat();
        mQFactor = in.readFloat();
        mFrequencyProfile = FrequencyProfile.CREATOR.createFromParcel(in);
        mFrequencyProfileLegacy = FrequencyProfileLegacy.CREATOR.createFromParcel(in);
        mMaxEnvelopeEffectSize = in.readInt();
        mMaxEnvelopeEffectSize = in.readInt();
        mMinEnvelopeEffectControlPointDurationMillis = in.readInt();
        mMinEnvelopeEffectControlPointDurationMillis = in.readInt();
        mMaxEnvelopeEffectControlPointDurationMillis = in.readInt();
        mMaxEnvelopeEffectControlPointDurationMillis = in.readInt();
@@ -86,7 +86,7 @@ public class VibratorInfo implements Parcelable {
                baseVibratorInfo.mSupportedBraking, baseVibratorInfo.mSupportedPrimitives,
                baseVibratorInfo.mSupportedBraking, baseVibratorInfo.mSupportedPrimitives,
                baseVibratorInfo.mPrimitiveDelayMax, baseVibratorInfo.mCompositionSizeMax,
                baseVibratorInfo.mPrimitiveDelayMax, baseVibratorInfo.mCompositionSizeMax,
                baseVibratorInfo.mPwlePrimitiveDurationMax, baseVibratorInfo.mPwleSizeMax,
                baseVibratorInfo.mPwlePrimitiveDurationMax, baseVibratorInfo.mPwleSizeMax,
                baseVibratorInfo.mQFactor, baseVibratorInfo.mFrequencyProfile,
                baseVibratorInfo.mQFactor, baseVibratorInfo.mFrequencyProfileLegacy,
                baseVibratorInfo.mMaxEnvelopeEffectSize,
                baseVibratorInfo.mMaxEnvelopeEffectSize,
                baseVibratorInfo.mMinEnvelopeEffectControlPointDurationMillis,
                baseVibratorInfo.mMinEnvelopeEffectControlPointDurationMillis,
                baseVibratorInfo.mMaxEnvelopeEffectControlPointDurationMillis);
                baseVibratorInfo.mMaxEnvelopeEffectControlPointDurationMillis);
@@ -112,7 +112,7 @@ public class VibratorInfo implements Parcelable {
     * @param pwleSizeMax              The maximum number of primitives supported by a PWLE
     * @param pwleSizeMax              The maximum number of primitives supported by a PWLE
     *                                 composition.
     *                                 composition.
     * @param qFactor                  The vibrator quality factor.
     * @param qFactor                  The vibrator quality factor.
     * @param frequencyProfile         The description of the vibrator supported frequencies and max
     * @param frequencyProfileLegacy   The description of the vibrator supported frequencies and max
     *                                 amplitude mappings.
     *                                 amplitude mappings.
     * @hide
     * @hide
     */
     */
@@ -120,11 +120,11 @@ public class VibratorInfo implements Parcelable {
            @Nullable SparseBooleanArray supportedBraking,
            @Nullable SparseBooleanArray supportedBraking,
            @NonNull SparseIntArray supportedPrimitives, int primitiveDelayMax,
            @NonNull SparseIntArray supportedPrimitives, int primitiveDelayMax,
            int compositionSizeMax, int pwlePrimitiveDurationMax, int pwleSizeMax,
            int compositionSizeMax, int pwlePrimitiveDurationMax, int pwleSizeMax,
            float qFactor, @NonNull FrequencyProfile frequencyProfile,
            float qFactor, @NonNull FrequencyProfileLegacy frequencyProfileLegacy,
            int maxEnvelopeEffectSize, int minEnvelopeEffectControlPointDurationMillis,
            int maxEnvelopeEffectSize, int minEnvelopeEffectControlPointDurationMillis,
            int maxEnvelopeEffectControlPointDurationMillis) {
            int maxEnvelopeEffectControlPointDurationMillis) {
        Preconditions.checkNotNull(supportedPrimitives);
        Preconditions.checkNotNull(supportedPrimitives);
        Preconditions.checkNotNull(frequencyProfile);
        Preconditions.checkNotNull(frequencyProfileLegacy);
        mId = id;
        mId = id;
        mCapabilities = capabilities;
        mCapabilities = capabilities;
        mSupportedEffects = supportedEffects == null ? null : supportedEffects.clone();
        mSupportedEffects = supportedEffects == null ? null : supportedEffects.clone();
@@ -135,7 +135,7 @@ public class VibratorInfo implements Parcelable {
        mPwlePrimitiveDurationMax = pwlePrimitiveDurationMax;
        mPwlePrimitiveDurationMax = pwlePrimitiveDurationMax;
        mPwleSizeMax = pwleSizeMax;
        mPwleSizeMax = pwleSizeMax;
        mQFactor = qFactor;
        mQFactor = qFactor;
        mFrequencyProfile = frequencyProfile;
        mFrequencyProfileLegacy = frequencyProfileLegacy;
        mMaxEnvelopeEffectSize = maxEnvelopeEffectSize;
        mMaxEnvelopeEffectSize = maxEnvelopeEffectSize;
        mMinEnvelopeEffectControlPointDurationMillis =
        mMinEnvelopeEffectControlPointDurationMillis =
                minEnvelopeEffectControlPointDurationMillis;
                minEnvelopeEffectControlPointDurationMillis;
@@ -155,7 +155,7 @@ public class VibratorInfo implements Parcelable {
        dest.writeInt(mPwlePrimitiveDurationMax);
        dest.writeInt(mPwlePrimitiveDurationMax);
        dest.writeInt(mPwleSizeMax);
        dest.writeInt(mPwleSizeMax);
        dest.writeFloat(mQFactor);
        dest.writeFloat(mQFactor);
        mFrequencyProfile.writeToParcel(dest, flags);
        mFrequencyProfileLegacy.writeToParcel(dest, flags);
        dest.writeInt(mMaxEnvelopeEffectSize);
        dest.writeInt(mMaxEnvelopeEffectSize);
        dest.writeInt(mMinEnvelopeEffectControlPointDurationMillis);
        dest.writeInt(mMinEnvelopeEffectControlPointDurationMillis);
        dest.writeInt(mMaxEnvelopeEffectControlPointDurationMillis);
        dest.writeInt(mMaxEnvelopeEffectControlPointDurationMillis);
@@ -205,7 +205,7 @@ public class VibratorInfo implements Parcelable {
                && Objects.equals(mSupportedEffects, that.mSupportedEffects)
                && Objects.equals(mSupportedEffects, that.mSupportedEffects)
                && Objects.equals(mSupportedBraking, that.mSupportedBraking)
                && Objects.equals(mSupportedBraking, that.mSupportedBraking)
                && Objects.equals(mQFactor, that.mQFactor)
                && Objects.equals(mQFactor, that.mQFactor)
                && Objects.equals(mFrequencyProfile, that.mFrequencyProfile)
                && Objects.equals(mFrequencyProfileLegacy, that.mFrequencyProfileLegacy)
                && mMaxEnvelopeEffectSize == that.mMaxEnvelopeEffectSize
                && mMaxEnvelopeEffectSize == that.mMaxEnvelopeEffectSize
                && mMinEnvelopeEffectControlPointDurationMillis
                && mMinEnvelopeEffectControlPointDurationMillis
                == that.mMinEnvelopeEffectControlPointDurationMillis
                == that.mMinEnvelopeEffectControlPointDurationMillis
@@ -216,7 +216,7 @@ public class VibratorInfo implements Parcelable {
    @Override
    @Override
    public int hashCode() {
    public int hashCode() {
        int hashCode = Objects.hash(mId, mCapabilities, mSupportedEffects, mSupportedBraking,
        int hashCode = Objects.hash(mId, mCapabilities, mSupportedEffects, mSupportedBraking,
                mQFactor, mFrequencyProfile);
                mQFactor, mFrequencyProfileLegacy);
        for (int i = 0; i < mSupportedPrimitives.size(); i++) {
        for (int i = 0; i < mSupportedPrimitives.size(); i++) {
            hashCode = 31 * hashCode + mSupportedPrimitives.keyAt(i);
            hashCode = 31 * hashCode + mSupportedPrimitives.keyAt(i);
            hashCode = 31 * hashCode + mSupportedPrimitives.valueAt(i);
            hashCode = 31 * hashCode + mSupportedPrimitives.valueAt(i);
@@ -238,7 +238,7 @@ public class VibratorInfo implements Parcelable {
                + ", mPwlePrimitiveDurationMax=" + mPwlePrimitiveDurationMax
                + ", mPwlePrimitiveDurationMax=" + mPwlePrimitiveDurationMax
                + ", mPwleSizeMax=" + mPwleSizeMax
                + ", mPwleSizeMax=" + mPwleSizeMax
                + ", mQFactor=" + mQFactor
                + ", mQFactor=" + mQFactor
                + ", mFrequencyProfile=" + mFrequencyProfile
                + ", mFrequencyProfileLegacy=" + mFrequencyProfileLegacy
                + ", mMaxEnvelopeEffectSize=" + mMaxEnvelopeEffectSize
                + ", mMaxEnvelopeEffectSize=" + mMaxEnvelopeEffectSize
                + ", mMinEnvelopeEffectControlPointDurationMillis="
                + ", mMinEnvelopeEffectControlPointDurationMillis="
                + mMinEnvelopeEffectControlPointDurationMillis
                + mMinEnvelopeEffectControlPointDurationMillis
@@ -262,7 +262,7 @@ public class VibratorInfo implements Parcelable {
        pw.println("pwlePrimitiveDurationMax = " + mPwlePrimitiveDurationMax);
        pw.println("pwlePrimitiveDurationMax = " + mPwlePrimitiveDurationMax);
        pw.println("pwleSizeMax = " + mPwleSizeMax);
        pw.println("pwleSizeMax = " + mPwleSizeMax);
        pw.println("q-factor = " + mQFactor);
        pw.println("q-factor = " + mQFactor);
        pw.println("frequencyProfile = " + mFrequencyProfile);
        pw.println("frequencyProfileLegacy = " + mFrequencyProfileLegacy);
        pw.println("mMaxEnvelopeEffectSize = " + mMaxEnvelopeEffectSize);
        pw.println("mMaxEnvelopeEffectSize = " + mMaxEnvelopeEffectSize);
        pw.println("mMinEnvelopeEffectControlPointDurationMillis = "
        pw.println("mMinEnvelopeEffectControlPointDurationMillis = "
                + mMinEnvelopeEffectControlPointDurationMillis);
                + mMinEnvelopeEffectControlPointDurationMillis);
@@ -517,7 +517,7 @@ public class VibratorInfo implements Parcelable {
     * this vibrator is a composite of multiple physical devices.
     * this vibrator is a composite of multiple physical devices.
     */
     */
    public float getResonantFrequencyHz() {
    public float getResonantFrequencyHz() {
        return mFrequencyProfile.mResonantFrequencyHz;
        return mFrequencyProfileLegacy.mResonantFrequencyHz;
    }
    }


    /**
    /**
@@ -537,8 +537,8 @@ public class VibratorInfo implements Parcelable {
     * <p>If the devices does not have frequency control then the profile should be empty.
     * <p>If the devices does not have frequency control then the profile should be empty.
     */
     */
    @NonNull
    @NonNull
    public FrequencyProfile getFrequencyProfile() {
    public FrequencyProfileLegacy getFrequencyProfileLegacy() {
        return mFrequencyProfile;
        return mFrequencyProfileLegacy;
    }
    }


    /** Returns a single int representing all the capabilities of the vibrator. */
    /** Returns a single int representing all the capabilities of the vibrator. */
@@ -640,7 +640,7 @@ public class VibratorInfo implements Parcelable {
     *
     *
     * @hide
     * @hide
     */
     */
    public static final class FrequencyProfile implements Parcelable {
    public static final class FrequencyProfileLegacy implements Parcelable {
        @Nullable
        @Nullable
        private final Range<Float> mFrequencyRangeHz;
        private final Range<Float> mFrequencyRangeHz;
        private final float mMinFrequencyHz;
        private final float mMinFrequencyHz;
@@ -648,7 +648,7 @@ public class VibratorInfo implements Parcelable {
        private final float mFrequencyResolutionHz;
        private final float mFrequencyResolutionHz;
        private final float[] mMaxAmplitudes;
        private final float[] mMaxAmplitudes;


        FrequencyProfile(Parcel in) {
        FrequencyProfileLegacy(Parcel in) {
            this(in.readFloat(), in.readFloat(), in.readFloat(), in.createFloatArray());
            this(in.readFloat(), in.readFloat(), in.readFloat(), in.createFloatArray());
        }
        }


@@ -664,7 +664,7 @@ public class VibratorInfo implements Parcelable {
         *                              resolution.
         *                              resolution.
         * @hide
         * @hide
         */
         */
        public FrequencyProfile(float resonantFrequencyHz, float minFrequencyHz,
        public FrequencyProfileLegacy(float resonantFrequencyHz, float minFrequencyHz,
                float frequencyResolutionHz, float[] maxAmplitudes) {
                float frequencyResolutionHz, float[] maxAmplitudes) {
            mMinFrequencyHz = minFrequencyHz;
            mMinFrequencyHz = minFrequencyHz;
            mResonantFrequencyHz = resonantFrequencyHz;
            mResonantFrequencyHz = resonantFrequencyHz;
@@ -776,10 +776,10 @@ public class VibratorInfo implements Parcelable {
            if (this == o) {
            if (this == o) {
                return true;
                return true;
            }
            }
            if (!(o instanceof FrequencyProfile)) {
            if (!(o instanceof FrequencyProfileLegacy)) {
                return false;
                return false;
            }
            }
            FrequencyProfile that = (FrequencyProfile) o;
            FrequencyProfileLegacy that = (FrequencyProfileLegacy) o;
            return Float.compare(mMinFrequencyHz, that.mMinFrequencyHz) == 0
            return Float.compare(mMinFrequencyHz, that.mMinFrequencyHz) == 0
                    && Float.compare(mResonantFrequencyHz, that.mResonantFrequencyHz) == 0
                    && Float.compare(mResonantFrequencyHz, that.mResonantFrequencyHz) == 0
                    && Float.compare(mFrequencyResolutionHz, that.mFrequencyResolutionHz) == 0
                    && Float.compare(mFrequencyResolutionHz, that.mFrequencyResolutionHz) == 0
@@ -796,7 +796,7 @@ public class VibratorInfo implements Parcelable {


        @Override
        @Override
        public String toString() {
        public String toString() {
            return "FrequencyProfile{"
            return "FrequencyProfileLegacy{"
                    + "mFrequencyRange=" + mFrequencyRangeHz
                    + "mFrequencyRange=" + mFrequencyRangeHz
                    + ", mMinFrequency=" + mMinFrequencyHz
                    + ", mMinFrequency=" + mMinFrequencyHz
                    + ", mResonantFrequency=" + mResonantFrequencyHz
                    + ", mResonantFrequency=" + mResonantFrequencyHz
@@ -806,16 +806,16 @@ public class VibratorInfo implements Parcelable {
        }
        }


        @NonNull
        @NonNull
        public static final Creator<FrequencyProfile> CREATOR =
        public static final Creator<FrequencyProfileLegacy> CREATOR =
                new Creator<FrequencyProfile>() {
                new Creator<FrequencyProfileLegacy>() {
                    @Override
                    @Override
                    public FrequencyProfile createFromParcel(Parcel in) {
                    public FrequencyProfileLegacy createFromParcel(Parcel in) {
                        return new FrequencyProfile(in);
                        return new FrequencyProfileLegacy(in);
                    }
                    }


                    @Override
                    @Override
                    public FrequencyProfile[] newArray(int size) {
                    public FrequencyProfileLegacy[] newArray(int size) {
                        return new FrequencyProfile[size];
                        return new FrequencyProfileLegacy[size];
                    }
                    }
                };
                };
    }
    }
@@ -832,8 +832,8 @@ public class VibratorInfo implements Parcelable {
        private int mPwlePrimitiveDurationMax;
        private int mPwlePrimitiveDurationMax;
        private int mPwleSizeMax;
        private int mPwleSizeMax;
        private float mQFactor = Float.NaN;
        private float mQFactor = Float.NaN;
        private FrequencyProfile mFrequencyProfile =
        private FrequencyProfileLegacy mFrequencyProfileLegacy =
                new FrequencyProfile(Float.NaN, Float.NaN, Float.NaN, null);
                new FrequencyProfileLegacy(Float.NaN, Float.NaN, Float.NaN, null);
        private int mMaxEnvelopeEffectSize;
        private int mMaxEnvelopeEffectSize;
        private int mMinEnvelopeEffectControlPointDurationMillis;
        private int mMinEnvelopeEffectControlPointDurationMillis;
        private int mMaxEnvelopeEffectControlPointDurationMillis;
        private int mMaxEnvelopeEffectControlPointDurationMillis;
@@ -908,8 +908,8 @@ public class VibratorInfo implements Parcelable {


        /** Configure the vibrator frequency information like resonant frequency and bandwidth. */
        /** Configure the vibrator frequency information like resonant frequency and bandwidth. */
        @NonNull
        @NonNull
        public Builder setFrequencyProfile(@NonNull FrequencyProfile frequencyProfile) {
        public Builder setFrequencyProfileLegacy(@NonNull FrequencyProfileLegacy frequencyProfile) {
            mFrequencyProfile = frequencyProfile;
            mFrequencyProfileLegacy = frequencyProfile;
            return this;
            return this;
        }
        }


@@ -950,7 +950,7 @@ public class VibratorInfo implements Parcelable {
        public VibratorInfo build() {
        public VibratorInfo build() {
            return new VibratorInfo(mId, mCapabilities, mSupportedEffects, mSupportedBraking,
            return new VibratorInfo(mId, mCapabilities, mSupportedEffects, mSupportedBraking,
                    mSupportedPrimitives, mPrimitiveDelayMax, mCompositionSizeMax,
                    mSupportedPrimitives, mPrimitiveDelayMax, mCompositionSizeMax,
                    mPwlePrimitiveDurationMax, mPwleSizeMax, mQFactor, mFrequencyProfile,
                    mPwlePrimitiveDurationMax, mPwleSizeMax, mQFactor, mFrequencyProfileLegacy,
                    mMaxEnvelopeEffectSize, mMinEnvelopeEffectControlPointDurationMillis,
                    mMaxEnvelopeEffectSize, mMinEnvelopeEffectControlPointDurationMillis,
                    mMaxEnvelopeEffectControlPointDurationMillis);
                    mMaxEnvelopeEffectControlPointDurationMillis);
        }
        }
+10 −10
Original line number Original line Diff line number Diff line
@@ -48,7 +48,7 @@ public final class MultiVibratorInfo extends VibratorInfo {
    }
    }


    private MultiVibratorInfo(
    private MultiVibratorInfo(
            int id, VibratorInfo[] vibrators, VibratorInfo.FrequencyProfile mergedProfile) {
            int id, VibratorInfo[] vibrators, FrequencyProfileLegacy mergedProfile) {
        super(id,
        super(id,
                capabilitiesIntersection(vibrators, mergedProfile.isEmpty()),
                capabilitiesIntersection(vibrators, mergedProfile.isEmpty()),
                supportedEffectsIntersection(vibrators),
                supportedEffectsIntersection(vibrators),
@@ -209,15 +209,15 @@ public final class MultiVibratorInfo extends VibratorInfo {
    }
    }


    @NonNull
    @NonNull
    private static FrequencyProfile frequencyProfileIntersection(VibratorInfo[] infos) {
    private static FrequencyProfileLegacy frequencyProfileIntersection(VibratorInfo[] infos) {
        float freqResolution = floatPropertyIntersection(infos,
        float freqResolution = floatPropertyIntersection(infos,
                info -> info.getFrequencyProfile().getFrequencyResolutionHz());
                info -> info.getFrequencyProfileLegacy().getFrequencyResolutionHz());
        float resonantFreq = floatPropertyIntersection(infos,
        float resonantFreq = floatPropertyIntersection(infos,
                VibratorInfo::getResonantFrequencyHz);
                VibratorInfo::getResonantFrequencyHz);
        Range<Float> freqRange = frequencyRangeIntersection(infos, freqResolution);
        Range<Float> freqRange = frequencyRangeIntersection(infos, freqResolution);


        if ((freqRange == null) || Float.isNaN(freqResolution)) {
        if ((freqRange == null) || Float.isNaN(freqResolution)) {
            return new FrequencyProfile(resonantFreq, Float.NaN, freqResolution, null);
            return new FrequencyProfileLegacy(resonantFreq, Float.NaN, freqResolution, null);
        }
        }


        int amplitudeCount =
        int amplitudeCount =
@@ -230,8 +230,8 @@ public final class MultiVibratorInfo extends VibratorInfo {
        Arrays.fill(maxAmplitudes, Float.MAX_VALUE);
        Arrays.fill(maxAmplitudes, Float.MAX_VALUE);


        for (VibratorInfo info : infos) {
        for (VibratorInfo info : infos) {
            Range<Float> vibratorFreqRange = info.getFrequencyProfile().getFrequencyRangeHz();
            Range<Float> vibratorFreqRange = info.getFrequencyProfileLegacy().getFrequencyRangeHz();
            float[] vibratorMaxAmplitudes = info.getFrequencyProfile().getMaxAmplitudes();
            float[] vibratorMaxAmplitudes = info.getFrequencyProfileLegacy().getMaxAmplitudes();
            int vibratorStartIdx = Math.round(
            int vibratorStartIdx = Math.round(
                    (freqRange.getLower() - vibratorFreqRange.getLower()) / freqResolution);
                    (freqRange.getLower() - vibratorFreqRange.getLower()) / freqResolution);
            int vibratorEndIdx = vibratorStartIdx + maxAmplitudes.length - 1;
            int vibratorEndIdx = vibratorStartIdx + maxAmplitudes.length - 1;
@@ -240,7 +240,7 @@ public final class MultiVibratorInfo extends VibratorInfo {
                Slog.w(TAG, "Error calculating the intersection of vibrator frequency"
                Slog.w(TAG, "Error calculating the intersection of vibrator frequency"
                        + " profiles: attempted to fetch from vibrator "
                        + " profiles: attempted to fetch from vibrator "
                        + info.getId() + " max amplitude with bad index " + vibratorStartIdx);
                        + info.getId() + " max amplitude with bad index " + vibratorStartIdx);
                return new FrequencyProfile(resonantFreq, Float.NaN, Float.NaN, null);
                return new FrequencyProfileLegacy(resonantFreq, Float.NaN, Float.NaN, null);
            }
            }


            for (int i = 0; i < maxAmplitudes.length; i++) {
            for (int i = 0; i < maxAmplitudes.length; i++) {
@@ -249,14 +249,14 @@ public final class MultiVibratorInfo extends VibratorInfo {
            }
            }
        }
        }


        return new FrequencyProfile(resonantFreq, freqRange.getLower(),
        return new FrequencyProfileLegacy(resonantFreq, freqRange.getLower(),
                freqResolution, maxAmplitudes);
                freqResolution, maxAmplitudes);
    }
    }


    @Nullable
    @Nullable
    private static Range<Float> frequencyRangeIntersection(VibratorInfo[] infos,
    private static Range<Float> frequencyRangeIntersection(VibratorInfo[] infos,
            float frequencyResolution) {
            float frequencyResolution) {
        Range<Float> firstRange = infos[0].getFrequencyProfile().getFrequencyRangeHz();
        Range<Float> firstRange = infos[0].getFrequencyProfileLegacy().getFrequencyRangeHz();
        if (firstRange == null) {
        if (firstRange == null) {
            // If one vibrator is undefined then the intersection is undefined.
            // If one vibrator is undefined then the intersection is undefined.
            return null;
            return null;
@@ -268,7 +268,7 @@ public final class MultiVibratorInfo extends VibratorInfo {
        // min supported frequencies are aligned w.r.t. the frequency resolution.
        // min supported frequencies are aligned w.r.t. the frequency resolution.


        for (int i = 1; i < infos.length; i++) {
        for (int i = 1; i < infos.length; i++) {
            Range<Float> vibratorRange = infos[i].getFrequencyProfile().getFrequencyRangeHz();
            Range<Float> vibratorRange = infos[i].getFrequencyProfileLegacy().getFrequencyRangeHz();
            if (vibratorRange == null) {
            if (vibratorRange == null) {
                // If one vibrator is undefined then the intersection is undefined.
                // If one vibrator is undefined then the intersection is undefined.
                return null;
                return null;
Loading