Loading core/java/android/os/VibrationEffect.java +22 −0 Original line number Diff line number Diff line Loading @@ -28,6 +28,7 @@ import android.content.Context; import android.hardware.vibrator.V1_0.EffectStrength; import android.hardware.vibrator.V1_3.Effect; import android.net.Uri; import android.os.Vibrator; import android.os.vibrator.PrebakedSegment; import android.os.vibrator.PrimitiveSegment; import android.os.vibrator.RampSegment; Loading Loading @@ -514,6 +515,16 @@ public abstract class VibrationEffect implements Parcelable { @TestApi public abstract long getDuration(); /** * Checks if a given {@link Vibrator} can play this effect as intended. * * <p>See @link Vibrator#areVibrationFeaturesSupported(VibrationEffect)} for more information * about what counts as supported by a vibrator, and what counts as not. * * @hide */ public abstract boolean areVibrationFeaturesSupported(@NonNull Vibrator vibrator); /** * Returns true if this effect could represent a touch haptic feedback. * Loading Loading @@ -756,6 +767,17 @@ public abstract class VibrationEffect implements Parcelable { return totalDuration; } /** @hide */ @Override public boolean areVibrationFeaturesSupported(@NonNull Vibrator vibrator) { for (VibrationEffectSegment segment : mSegments) { if (!segment.areVibrationFeaturesSupported(vibrator)) { return false; } } return true; } /** @hide */ @Override public boolean isHapticFeedbackCandidate() { Loading core/java/android/os/Vibrator.java +22 −0 Original line number Diff line number Diff line Loading @@ -221,6 +221,28 @@ public abstract class Vibrator { IVibrator.CAP_FREQUENCY_CONTROL | IVibrator.CAP_COMPOSE_PWLE_EFFECTS); } /** * Checks 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>If this method returns {@code true}, then the VibrationEffect should play as expected. * If {@code false}, playing the VibrationEffect might still make a vibration, but the vibration * may be significantly degraded from the intention. * * <p>This method aggregates the results of feature check methods such as * {@link #hasAmplitudeControl}, {@link #areAllPrimitivesSupported(int...)}, etc, depending * on the features that are actually used by the VibrationEffect. * * @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); } /** * Check whether the vibrator can be controlled by an external service with the * {@link IExternalVibratorService}. Loading core/java/android/os/vibrator/PrebakedSegment.java +26 −0 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ import android.annotation.TestApi; import android.os.Parcel; import android.os.Parcelable; import android.os.VibrationEffect; import android.os.Vibrator; import java.util.Objects; Loading Loading @@ -67,6 +68,31 @@ public final class PrebakedSegment extends VibrationEffectSegment { return -1; } /** @hide */ @Override public boolean areVibrationFeaturesSupported(@NonNull Vibrator vibrator) { if (vibrator.areAllEffectsSupported(mEffectId) == Vibrator.VIBRATION_EFFECT_SUPPORT_YES) { return true; } if (!mFallback) { // If the Vibrator's support is not `VIBRATION_EFFECT_SUPPORT_YES`, and this effect does // not support fallbacks, the effect is considered not supported by the vibrator. return false; } // The vibrator does not have hardware support for the effect, but the effect has fallback // support. Check if a fallback will be available for the effect ID. switch (mEffectId) { case VibrationEffect.EFFECT_CLICK: case VibrationEffect.EFFECT_DOUBLE_CLICK: case VibrationEffect.EFFECT_HEAVY_CLICK: case VibrationEffect.EFFECT_TICK: // Any of these effects are always supported via some form of fallback. return true; default: return false; } } /** @hide */ @Override public boolean isHapticFeedbackCandidate() { Loading core/java/android/os/vibrator/PrimitiveSegment.java +7 −0 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ import android.annotation.TestApi; import android.os.Parcel; import android.os.Parcelable; import android.os.VibrationEffect; import android.os.Vibrator; import com.android.internal.util.Preconditions; Loading Loading @@ -67,6 +68,12 @@ public final class PrimitiveSegment extends VibrationEffectSegment { return -1; } /** @hide */ @Override public boolean areVibrationFeaturesSupported(@NonNull Vibrator vibrator) { return vibrator.areAllPrimitivesSupported(mPrimitiveId); } /** @hide */ @Override public boolean isHapticFeedbackCandidate() { Loading core/java/android/os/vibrator/RampSegment.java +24 −0 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ import android.annotation.NonNull; import android.annotation.TestApi; import android.os.Parcel; import android.os.VibrationEffect; import android.os.Vibrator; import com.android.internal.util.Preconditions; Loading Loading @@ -93,6 +94,29 @@ public final class RampSegment extends VibrationEffectSegment { return mDuration; } /** @hide */ @Override public boolean areVibrationFeaturesSupported(@NonNull Vibrator vibrator) { boolean areFeaturesSupported = true; // If the start/end frequencies are not the same, require frequency control since we need to // ramp up/down the frequency. if ((mStartFrequencyHz != mEndFrequencyHz) // If there is no frequency ramping, make sure that the one frequency used does not // require frequency control. || frequencyRequiresFrequencyControl(mStartFrequencyHz)) { areFeaturesSupported &= vibrator.hasFrequencyControl(); } // If the start/end amplitudes are not the same, require amplitude control since we need to // ramp up/down the amplitude. if ((mStartAmplitude != mEndAmplitude) // If there is no amplitude ramping, make sure that the amplitude used does not // require amplitude control. || amplitudeRequiresAmplitudeControl(mStartAmplitude)) { areFeaturesSupported &= vibrator.hasAmplitudeControl(); } return areFeaturesSupported; } /** @hide */ @Override public boolean isHapticFeedbackCandidate() { Loading Loading
core/java/android/os/VibrationEffect.java +22 −0 Original line number Diff line number Diff line Loading @@ -28,6 +28,7 @@ import android.content.Context; import android.hardware.vibrator.V1_0.EffectStrength; import android.hardware.vibrator.V1_3.Effect; import android.net.Uri; import android.os.Vibrator; import android.os.vibrator.PrebakedSegment; import android.os.vibrator.PrimitiveSegment; import android.os.vibrator.RampSegment; Loading Loading @@ -514,6 +515,16 @@ public abstract class VibrationEffect implements Parcelable { @TestApi public abstract long getDuration(); /** * Checks if a given {@link Vibrator} can play this effect as intended. * * <p>See @link Vibrator#areVibrationFeaturesSupported(VibrationEffect)} for more information * about what counts as supported by a vibrator, and what counts as not. * * @hide */ public abstract boolean areVibrationFeaturesSupported(@NonNull Vibrator vibrator); /** * Returns true if this effect could represent a touch haptic feedback. * Loading Loading @@ -756,6 +767,17 @@ public abstract class VibrationEffect implements Parcelable { return totalDuration; } /** @hide */ @Override public boolean areVibrationFeaturesSupported(@NonNull Vibrator vibrator) { for (VibrationEffectSegment segment : mSegments) { if (!segment.areVibrationFeaturesSupported(vibrator)) { return false; } } return true; } /** @hide */ @Override public boolean isHapticFeedbackCandidate() { Loading
core/java/android/os/Vibrator.java +22 −0 Original line number Diff line number Diff line Loading @@ -221,6 +221,28 @@ public abstract class Vibrator { IVibrator.CAP_FREQUENCY_CONTROL | IVibrator.CAP_COMPOSE_PWLE_EFFECTS); } /** * Checks 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>If this method returns {@code true}, then the VibrationEffect should play as expected. * If {@code false}, playing the VibrationEffect might still make a vibration, but the vibration * may be significantly degraded from the intention. * * <p>This method aggregates the results of feature check methods such as * {@link #hasAmplitudeControl}, {@link #areAllPrimitivesSupported(int...)}, etc, depending * on the features that are actually used by the VibrationEffect. * * @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); } /** * Check whether the vibrator can be controlled by an external service with the * {@link IExternalVibratorService}. Loading
core/java/android/os/vibrator/PrebakedSegment.java +26 −0 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ import android.annotation.TestApi; import android.os.Parcel; import android.os.Parcelable; import android.os.VibrationEffect; import android.os.Vibrator; import java.util.Objects; Loading Loading @@ -67,6 +68,31 @@ public final class PrebakedSegment extends VibrationEffectSegment { return -1; } /** @hide */ @Override public boolean areVibrationFeaturesSupported(@NonNull Vibrator vibrator) { if (vibrator.areAllEffectsSupported(mEffectId) == Vibrator.VIBRATION_EFFECT_SUPPORT_YES) { return true; } if (!mFallback) { // If the Vibrator's support is not `VIBRATION_EFFECT_SUPPORT_YES`, and this effect does // not support fallbacks, the effect is considered not supported by the vibrator. return false; } // The vibrator does not have hardware support for the effect, but the effect has fallback // support. Check if a fallback will be available for the effect ID. switch (mEffectId) { case VibrationEffect.EFFECT_CLICK: case VibrationEffect.EFFECT_DOUBLE_CLICK: case VibrationEffect.EFFECT_HEAVY_CLICK: case VibrationEffect.EFFECT_TICK: // Any of these effects are always supported via some form of fallback. return true; default: return false; } } /** @hide */ @Override public boolean isHapticFeedbackCandidate() { Loading
core/java/android/os/vibrator/PrimitiveSegment.java +7 −0 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ import android.annotation.TestApi; import android.os.Parcel; import android.os.Parcelable; import android.os.VibrationEffect; import android.os.Vibrator; import com.android.internal.util.Preconditions; Loading Loading @@ -67,6 +68,12 @@ public final class PrimitiveSegment extends VibrationEffectSegment { return -1; } /** @hide */ @Override public boolean areVibrationFeaturesSupported(@NonNull Vibrator vibrator) { return vibrator.areAllPrimitivesSupported(mPrimitiveId); } /** @hide */ @Override public boolean isHapticFeedbackCandidate() { Loading
core/java/android/os/vibrator/RampSegment.java +24 −0 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ import android.annotation.NonNull; import android.annotation.TestApi; import android.os.Parcel; import android.os.VibrationEffect; import android.os.Vibrator; import com.android.internal.util.Preconditions; Loading Loading @@ -93,6 +94,29 @@ public final class RampSegment extends VibrationEffectSegment { return mDuration; } /** @hide */ @Override public boolean areVibrationFeaturesSupported(@NonNull Vibrator vibrator) { boolean areFeaturesSupported = true; // If the start/end frequencies are not the same, require frequency control since we need to // ramp up/down the frequency. if ((mStartFrequencyHz != mEndFrequencyHz) // If there is no frequency ramping, make sure that the one frequency used does not // require frequency control. || frequencyRequiresFrequencyControl(mStartFrequencyHz)) { areFeaturesSupported &= vibrator.hasFrequencyControl(); } // If the start/end amplitudes are not the same, require amplitude control since we need to // ramp up/down the amplitude. if ((mStartAmplitude != mEndAmplitude) // If there is no amplitude ramping, make sure that the amplitude used does not // require amplitude control. || amplitudeRequiresAmplitudeControl(mStartAmplitude)) { areFeaturesSupported &= vibrator.hasAmplitudeControl(); } return areFeaturesSupported; } /** @hide */ @Override public boolean isHapticFeedbackCandidate() { Loading