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

Commit 49f03240 authored by Yeabkal Wubshit's avatar Yeabkal Wubshit Committed by Android (Google) Code Review
Browse files

Merge "Create VibratorInfo#areVibrationFeaturesSupported" into main

parents 17cd343b 2675de39
Loading
Loading
Loading
Loading
+6 −6
Original line number Original line Diff line number Diff line
@@ -525,14 +525,14 @@ public abstract class VibrationEffect implements Parcelable {
    public abstract long getDuration();
    public abstract long getDuration();


    /**
    /**
     * Checks if a given {@link Vibrator} can play this effect as intended.
     * Checks if a vibrator with a given {@link VibratorInfo} can play this effect as intended.
     *
     *
     * <p>See @link Vibrator#areVibrationFeaturesSupported(VibrationEffect)} for more information
     * <p>See {@link VibratorInfo#areVibrationFeaturesSupported(VibrationEffect)} for more
     * about what counts as supported by a vibrator, and what counts as not.
     * information about what counts as supported by a vibrator, and what counts as not.
     *
     *
     * @hide
     * @hide
     */
     */
    public abstract boolean areVibrationFeaturesSupported(@NonNull Vibrator vibrator);
    public abstract boolean areVibrationFeaturesSupported(@NonNull VibratorInfo vibratorInfo);


    /**
    /**
     * Returns true if this effect could represent a touch haptic feedback.
     * Returns true if this effect could represent a touch haptic feedback.
@@ -813,9 +813,9 @@ public abstract class VibrationEffect implements Parcelable {


        /** @hide */
        /** @hide */
        @Override
        @Override
        public boolean areVibrationFeaturesSupported(@NonNull Vibrator vibrator) {
        public boolean areVibrationFeaturesSupported(@NonNull VibratorInfo vibratorInfo) {
            for (VibrationEffectSegment segment : mSegments) {
            for (VibrationEffectSegment segment : mSegments) {
                if (!segment.areVibrationFeaturesSupported(vibrator)) {
                if (!segment.areVibrationFeaturesSupported(vibratorInfo)) {
                    return false;
                    return false;
                }
                }
            }
            }
+2 −4
Original line number Original line Diff line number Diff line
@@ -216,9 +216,7 @@ public abstract class Vibrator {
     */
     */
    @TestApi
    @TestApi
    public boolean hasFrequencyControl() {
    public boolean hasFrequencyControl() {
        // We currently can only control frequency of the vibration using the compose PWLE method.
        return getInfo().hasFrequencyControl();
        return getInfo().hasCapability(
                IVibrator.CAP_FREQUENCY_CONTROL | IVibrator.CAP_COMPOSE_PWLE_EFFECTS);
    }
    }


    /**
    /**
@@ -240,7 +238,7 @@ public abstract class Vibrator {
     * @hide
     * @hide
     */
     */
    public boolean areVibrationFeaturesSupported(@NonNull VibrationEffect effect) {
    public boolean areVibrationFeaturesSupported(@NonNull VibrationEffect effect) {
        return effect.areVibrationFeaturesSupported(this);
        return getInfo().areVibrationFeaturesSupported(effect);
    }
    }


    /**
    /**
+28 −0
Original line number Original line Diff line number Diff line
@@ -241,6 +241,17 @@ public class VibratorInfo implements Parcelable {
        return hasCapability(IVibrator.CAP_AMPLITUDE_CONTROL);
        return hasCapability(IVibrator.CAP_AMPLITUDE_CONTROL);
    }
    }


    /**
     * Check whether the vibrator has frequency control.
     *
     * @return True if the hardware can control the frequency of the vibrations, otherwise false.
     */
    public boolean hasFrequencyControl() {
        // We currently can only control frequency of the vibration using the compose PWLE method.
        return hasCapability(
                IVibrator.CAP_FREQUENCY_CONTROL | IVibrator.CAP_COMPOSE_PWLE_EFFECTS);
    }

    /**
    /**
     * Returns a default value to be applied to composed PWLE effects for braking.
     * Returns a default value to be applied to composed PWLE effects for braking.
     *
     *
@@ -322,6 +333,23 @@ public class VibratorInfo implements Parcelable {
                && (mSupportedPrimitives.indexOfKey(primitiveId) >= 0);
                && (mSupportedPrimitives.indexOfKey(primitiveId) >= 0);
    }
    }


    /**
     * Query whether or not the vibrator supports all components of a given {@link VibrationEffect}
     * (i.e. the vibrator can play the given effect as intended).
     *
     * <p>See {@link Vibrator#areVibrationFeaturesSupported(VibrationEffect)} for more
     * information on how the vibrator support is determined.
     *
     * @param effect the {@link VibrationEffect} to check if it is supported
     * @return {@code true} if the vibrator can play the given {@code effect} as intended,
     *         {@code false} otherwise.
     *
     * @hide
     */
    public boolean areVibrationFeaturesSupported(@NonNull VibrationEffect effect) {
        return effect.areVibrationFeaturesSupported(this);
    }

    /**
    /**
     * Query the estimated duration of given primitive.
     * Query the estimated duration of given primitive.
     *
     *
+3 −2
Original line number Original line Diff line number Diff line
@@ -23,6 +23,7 @@ import android.os.Parcel;
import android.os.Parcelable;
import android.os.Parcelable;
import android.os.VibrationEffect;
import android.os.VibrationEffect;
import android.os.Vibrator;
import android.os.Vibrator;
import android.os.VibratorInfo;


import java.util.Objects;
import java.util.Objects;


@@ -77,8 +78,8 @@ public final class PrebakedSegment extends VibrationEffectSegment {


    /** @hide */
    /** @hide */
    @Override
    @Override
    public boolean areVibrationFeaturesSupported(@NonNull Vibrator vibrator) {
    public boolean areVibrationFeaturesSupported(@NonNull VibratorInfo vibratorInfo) {
        if (vibrator.areAllEffectsSupported(mEffectId) == Vibrator.VIBRATION_EFFECT_SUPPORT_YES) {
        if (vibratorInfo.isEffectSupported(mEffectId) == Vibrator.VIBRATION_EFFECT_SUPPORT_YES) {
            return true;
            return true;
        }
        }
        if (!mFallback) {
        if (!mFallback) {
+3 −3
Original line number Original line Diff line number Diff line
@@ -22,7 +22,7 @@ import android.annotation.TestApi;
import android.os.Parcel;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.Parcelable;
import android.os.VibrationEffect;
import android.os.VibrationEffect;
import android.os.Vibrator;
import android.os.VibratorInfo;


import com.android.internal.util.Preconditions;
import com.android.internal.util.Preconditions;


@@ -77,8 +77,8 @@ public final class PrimitiveSegment extends VibrationEffectSegment {


    /** @hide */
    /** @hide */
    @Override
    @Override
    public boolean areVibrationFeaturesSupported(@NonNull Vibrator vibrator) {
    public boolean areVibrationFeaturesSupported(@NonNull VibratorInfo vibratorInfo) {
        return vibrator.areAllPrimitivesSupported(mPrimitiveId);
        return vibratorInfo.isPrimitiveSupported(mPrimitiveId);
    }
    }


    /** @hide */
    /** @hide */
Loading