Loading Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -581,6 +581,7 @@ java_library { "android.hardware.vibrator-V1.1-java", "android.hardware.vibrator-V1.2-java", "android.hardware.vibrator-V1.3-java", "android.hardware.vibrator-V2-java", "android.security.apc-java", "android.security.authorization-java", "android.security.usermanager-java", Loading core/java/android/os/VibrationEffect.java +16 −2 Original line number Diff line number Diff line Loading @@ -502,6 +502,20 @@ public abstract class VibrationEffect implements Parcelable { } } /** @hide */ public static String effectStrengthToString(int effectStrength) { switch (effectStrength) { case EFFECT_STRENGTH_LIGHT: return "LIGHT"; case EFFECT_STRENGTH_MEDIUM: return "MEDIUM"; case EFFECT_STRENGTH_STRONG: return "STRONG"; default: return Integer.toString(effectStrength); } } /** @hide */ @TestApi public static class OneShot extends VibrationEffect implements Parcelable { Loading Loading @@ -936,8 +950,8 @@ public abstract class VibrationEffect implements Parcelable { @Override public String toString() { return "Prebaked{mEffectId=" + mEffectId + ", mEffectStrength=" + mEffectStrength return "Prebaked{mEffectId=" + effectIdToString(mEffectId) + ", mEffectStrength=" + effectStrengthToString(mEffectStrength) + ", mFallback=" + mFallback + ", mFallbackEffect=" + mFallbackEffect + "}"; Loading core/java/android/os/VibratorInfo.java +23 −20 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ package android.os; import android.annotation.NonNull; import android.annotation.Nullable; import android.hardware.vibrator.IVibrator; import android.util.SparseBooleanArray; import java.util.ArrayList; Loading @@ -33,20 +34,7 @@ import java.util.Objects; * @hide */ public final class VibratorInfo implements Parcelable { /** * Capability to set amplitude values to vibrations. * @hide */ // Internally this maps to the HAL constant IVibrator::CAP_AMPLITUDE_CONTROL public static final int CAPABILITY_AMPLITUDE_CONTROL = 4; /** * Capability to compose primitives into a single effect. * @hide */ // Internally this maps to the HAL constant IVibrator::CAP_COMPOSE_EFFECTS public static final int CAPABILITY_COMPOSE_EFFECTS = 32; private static final String TAG = "VibratorInfo"; private final int mId; private final long mCapabilities; Loading Loading @@ -108,7 +96,7 @@ public final class VibratorInfo implements Parcelable { return "VibratorInfo{" + "mId=" + mId + ", mCapabilities=" + Arrays.toString(getCapabilitiesNames()) + ", mCapabilities flags=" + mCapabilities + ", mCapabilities flags=" + Long.toBinaryString(mCapabilities) + ", mSupportedEffects=" + Arrays.toString(getSupportedEffectsNames()) + ", mSupportedPrimitives=" + Arrays.toString(getSupportedPrimitivesNames()) + '}'; Loading @@ -125,7 +113,7 @@ public final class VibratorInfo implements Parcelable { * @return True if the hardware can control the amplitude of the vibrations, otherwise false. */ public boolean hasAmplitudeControl() { return hasCapability(CAPABILITY_AMPLITUDE_CONTROL); return hasCapability(IVibrator.CAP_AMPLITUDE_CONTROL); } /** Loading Loading @@ -153,7 +141,7 @@ public final class VibratorInfo implements Parcelable { * @return Whether the primitive is supported. */ public boolean isPrimitiveSupported(@VibrationEffect.Composition.Primitive int primitiveId) { return hasCapability(CAPABILITY_COMPOSE_EFFECTS) && mSupportedPrimitives != null return hasCapability(IVibrator.CAP_COMPOSE_EFFECTS) && mSupportedPrimitives != null && mSupportedPrimitives.get(primitiveId, false); } Loading @@ -170,12 +158,27 @@ public final class VibratorInfo implements Parcelable { private String[] getCapabilitiesNames() { List<String> names = new ArrayList<>(); if (hasCapability(CAPABILITY_AMPLITUDE_CONTROL)) { names.add("AMPLITUDE_CONTROL"); if (hasCapability(IVibrator.CAP_ON_CALLBACK)) { names.add("ON_CALLBACK"); } if (hasCapability(IVibrator.CAP_PERFORM_CALLBACK)) { names.add("PERFORM_CALLBACK"); } if (hasCapability(CAPABILITY_COMPOSE_EFFECTS)) { if (hasCapability(IVibrator.CAP_COMPOSE_EFFECTS)) { names.add("COMPOSE_EFFECTS"); } if (hasCapability(IVibrator.CAP_ALWAYS_ON_CONTROL)) { names.add("ALWAYS_ON_CONTROL"); } if (hasCapability(IVibrator.CAP_AMPLITUDE_CONTROL)) { names.add("AMPLITUDE_CONTROL"); } if (hasCapability(IVibrator.CAP_EXTERNAL_CONTROL)) { names.add("EXTERNAL_CONTROL"); } if (hasCapability(IVibrator.CAP_EXTERNAL_AMPLITUDE_CONTROL)) { names.add("EXTERNAL_AMPLITUDE_CONTROL"); } return names.toArray(new String[names.size()]); } Loading core/tests/coretests/src/android/os/VibratorInfoTest.java +15 −14 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertFalse; import static junit.framework.Assert.assertTrue; import android.hardware.vibrator.IVibrator; import android.platform.test.annotations.Presubmit; import org.junit.Test; Loading @@ -33,16 +34,16 @@ public class VibratorInfoTest { @Test public void testHasAmplitudeControl() { assertFalse(createInfo(/* capabilities= */ 0).hasAmplitudeControl()); assertTrue(createInfo(VibratorInfo.CAPABILITY_COMPOSE_EFFECTS | VibratorInfo.CAPABILITY_AMPLITUDE_CONTROL).hasAmplitudeControl()); assertTrue(createInfo(IVibrator.CAP_COMPOSE_EFFECTS | IVibrator.CAP_AMPLITUDE_CONTROL).hasAmplitudeControl()); } @Test public void testHasCapabilities() { assertTrue(createInfo(VibratorInfo.CAPABILITY_COMPOSE_EFFECTS) .hasCapability(VibratorInfo.CAPABILITY_COMPOSE_EFFECTS)); assertFalse(createInfo(VibratorInfo.CAPABILITY_COMPOSE_EFFECTS) .hasCapability(VibratorInfo.CAPABILITY_AMPLITUDE_CONTROL)); assertTrue(createInfo(IVibrator.CAP_COMPOSE_EFFECTS) .hasCapability(IVibrator.CAP_COMPOSE_EFFECTS)); assertFalse(createInfo(IVibrator.CAP_COMPOSE_EFFECTS) .hasCapability(IVibrator.CAP_AMPLITUDE_CONTROL)); } @Test Loading @@ -59,7 +60,7 @@ public class VibratorInfoTest { @Test public void testIsPrimitiveSupported() { VibratorInfo info = new VibratorInfo(/* id= */ 0, VibratorInfo.CAPABILITY_COMPOSE_EFFECTS, VibratorInfo info = new VibratorInfo(/* id= */ 0, IVibrator.CAP_COMPOSE_EFFECTS, null, new int[]{VibrationEffect.Composition.PRIMITIVE_CLICK}); assertTrue(info.isPrimitiveSupported(VibrationEffect.Composition.PRIMITIVE_CLICK)); assertFalse(info.isPrimitiveSupported(VibrationEffect.Composition.PRIMITIVE_TICK)); Loading @@ -73,30 +74,30 @@ public class VibratorInfoTest { @Test public void testEquals() { VibratorInfo empty = new VibratorInfo(1, 0, null, null); VibratorInfo complete = new VibratorInfo(1, VibratorInfo.CAPABILITY_AMPLITUDE_CONTROL, VibratorInfo complete = new VibratorInfo(1, IVibrator.CAP_AMPLITUDE_CONTROL, new int[]{VibrationEffect.EFFECT_CLICK}, new int[]{VibrationEffect.Composition.PRIMITIVE_CLICK}); assertEquals(complete, complete); assertEquals(complete, new VibratorInfo(1, VibratorInfo.CAPABILITY_AMPLITUDE_CONTROL, assertEquals(complete, new VibratorInfo(1, IVibrator.CAP_AMPLITUDE_CONTROL, new int[]{VibrationEffect.EFFECT_CLICK}, new int[]{VibrationEffect.Composition.PRIMITIVE_CLICK})); assertFalse(empty.equals(new VibratorInfo(1, 0, new int[]{}, new int[]{}))); assertFalse(complete.equals(new VibratorInfo(1, VibratorInfo.CAPABILITY_COMPOSE_EFFECTS, assertFalse(complete.equals(new VibratorInfo(1, IVibrator.CAP_COMPOSE_EFFECTS, new int[]{VibrationEffect.EFFECT_CLICK}, new int[]{VibrationEffect.Composition.PRIMITIVE_CLICK}))); assertFalse(complete.equals(new VibratorInfo(1, VibratorInfo.CAPABILITY_AMPLITUDE_CONTROL, assertFalse(complete.equals(new VibratorInfo(1, IVibrator.CAP_AMPLITUDE_CONTROL, new int[]{}, new int[]{}))); assertFalse(complete.equals(new VibratorInfo(1, VibratorInfo.CAPABILITY_AMPLITUDE_CONTROL, assertFalse(complete.equals(new VibratorInfo(1, IVibrator.CAP_AMPLITUDE_CONTROL, null, new int[]{VibrationEffect.Composition.PRIMITIVE_CLICK}))); assertFalse(complete.equals(new VibratorInfo(1, VibratorInfo.CAPABILITY_AMPLITUDE_CONTROL, assertFalse(complete.equals(new VibratorInfo(1, IVibrator.CAP_AMPLITUDE_CONTROL, new int[]{VibrationEffect.EFFECT_CLICK}, null))); } @Test public void testSerialization() { VibratorInfo original = new VibratorInfo(1, VibratorInfo.CAPABILITY_COMPOSE_EFFECTS, VibratorInfo original = new VibratorInfo(1, IVibrator.CAP_COMPOSE_EFFECTS, new int[]{VibrationEffect.EFFECT_CLICK}, null); Parcel parcel = Parcel.obtain(); Loading services/core/java/com/android/server/vibrator/Vibration.java +3 −1 Original line number Diff line number Diff line Loading @@ -120,7 +120,9 @@ final class Vibration { if (newEffect.equals(mEffect)) { return; } if (mOriginalEffect == null) { mOriginalEffect = mEffect; } mEffect = newEffect; } Loading Loading
Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -581,6 +581,7 @@ java_library { "android.hardware.vibrator-V1.1-java", "android.hardware.vibrator-V1.2-java", "android.hardware.vibrator-V1.3-java", "android.hardware.vibrator-V2-java", "android.security.apc-java", "android.security.authorization-java", "android.security.usermanager-java", Loading
core/java/android/os/VibrationEffect.java +16 −2 Original line number Diff line number Diff line Loading @@ -502,6 +502,20 @@ public abstract class VibrationEffect implements Parcelable { } } /** @hide */ public static String effectStrengthToString(int effectStrength) { switch (effectStrength) { case EFFECT_STRENGTH_LIGHT: return "LIGHT"; case EFFECT_STRENGTH_MEDIUM: return "MEDIUM"; case EFFECT_STRENGTH_STRONG: return "STRONG"; default: return Integer.toString(effectStrength); } } /** @hide */ @TestApi public static class OneShot extends VibrationEffect implements Parcelable { Loading Loading @@ -936,8 +950,8 @@ public abstract class VibrationEffect implements Parcelable { @Override public String toString() { return "Prebaked{mEffectId=" + mEffectId + ", mEffectStrength=" + mEffectStrength return "Prebaked{mEffectId=" + effectIdToString(mEffectId) + ", mEffectStrength=" + effectStrengthToString(mEffectStrength) + ", mFallback=" + mFallback + ", mFallbackEffect=" + mFallbackEffect + "}"; Loading
core/java/android/os/VibratorInfo.java +23 −20 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ package android.os; import android.annotation.NonNull; import android.annotation.Nullable; import android.hardware.vibrator.IVibrator; import android.util.SparseBooleanArray; import java.util.ArrayList; Loading @@ -33,20 +34,7 @@ import java.util.Objects; * @hide */ public final class VibratorInfo implements Parcelable { /** * Capability to set amplitude values to vibrations. * @hide */ // Internally this maps to the HAL constant IVibrator::CAP_AMPLITUDE_CONTROL public static final int CAPABILITY_AMPLITUDE_CONTROL = 4; /** * Capability to compose primitives into a single effect. * @hide */ // Internally this maps to the HAL constant IVibrator::CAP_COMPOSE_EFFECTS public static final int CAPABILITY_COMPOSE_EFFECTS = 32; private static final String TAG = "VibratorInfo"; private final int mId; private final long mCapabilities; Loading Loading @@ -108,7 +96,7 @@ public final class VibratorInfo implements Parcelable { return "VibratorInfo{" + "mId=" + mId + ", mCapabilities=" + Arrays.toString(getCapabilitiesNames()) + ", mCapabilities flags=" + mCapabilities + ", mCapabilities flags=" + Long.toBinaryString(mCapabilities) + ", mSupportedEffects=" + Arrays.toString(getSupportedEffectsNames()) + ", mSupportedPrimitives=" + Arrays.toString(getSupportedPrimitivesNames()) + '}'; Loading @@ -125,7 +113,7 @@ public final class VibratorInfo implements Parcelable { * @return True if the hardware can control the amplitude of the vibrations, otherwise false. */ public boolean hasAmplitudeControl() { return hasCapability(CAPABILITY_AMPLITUDE_CONTROL); return hasCapability(IVibrator.CAP_AMPLITUDE_CONTROL); } /** Loading Loading @@ -153,7 +141,7 @@ public final class VibratorInfo implements Parcelable { * @return Whether the primitive is supported. */ public boolean isPrimitiveSupported(@VibrationEffect.Composition.Primitive int primitiveId) { return hasCapability(CAPABILITY_COMPOSE_EFFECTS) && mSupportedPrimitives != null return hasCapability(IVibrator.CAP_COMPOSE_EFFECTS) && mSupportedPrimitives != null && mSupportedPrimitives.get(primitiveId, false); } Loading @@ -170,12 +158,27 @@ public final class VibratorInfo implements Parcelable { private String[] getCapabilitiesNames() { List<String> names = new ArrayList<>(); if (hasCapability(CAPABILITY_AMPLITUDE_CONTROL)) { names.add("AMPLITUDE_CONTROL"); if (hasCapability(IVibrator.CAP_ON_CALLBACK)) { names.add("ON_CALLBACK"); } if (hasCapability(IVibrator.CAP_PERFORM_CALLBACK)) { names.add("PERFORM_CALLBACK"); } if (hasCapability(CAPABILITY_COMPOSE_EFFECTS)) { if (hasCapability(IVibrator.CAP_COMPOSE_EFFECTS)) { names.add("COMPOSE_EFFECTS"); } if (hasCapability(IVibrator.CAP_ALWAYS_ON_CONTROL)) { names.add("ALWAYS_ON_CONTROL"); } if (hasCapability(IVibrator.CAP_AMPLITUDE_CONTROL)) { names.add("AMPLITUDE_CONTROL"); } if (hasCapability(IVibrator.CAP_EXTERNAL_CONTROL)) { names.add("EXTERNAL_CONTROL"); } if (hasCapability(IVibrator.CAP_EXTERNAL_AMPLITUDE_CONTROL)) { names.add("EXTERNAL_AMPLITUDE_CONTROL"); } return names.toArray(new String[names.size()]); } Loading
core/tests/coretests/src/android/os/VibratorInfoTest.java +15 −14 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertFalse; import static junit.framework.Assert.assertTrue; import android.hardware.vibrator.IVibrator; import android.platform.test.annotations.Presubmit; import org.junit.Test; Loading @@ -33,16 +34,16 @@ public class VibratorInfoTest { @Test public void testHasAmplitudeControl() { assertFalse(createInfo(/* capabilities= */ 0).hasAmplitudeControl()); assertTrue(createInfo(VibratorInfo.CAPABILITY_COMPOSE_EFFECTS | VibratorInfo.CAPABILITY_AMPLITUDE_CONTROL).hasAmplitudeControl()); assertTrue(createInfo(IVibrator.CAP_COMPOSE_EFFECTS | IVibrator.CAP_AMPLITUDE_CONTROL).hasAmplitudeControl()); } @Test public void testHasCapabilities() { assertTrue(createInfo(VibratorInfo.CAPABILITY_COMPOSE_EFFECTS) .hasCapability(VibratorInfo.CAPABILITY_COMPOSE_EFFECTS)); assertFalse(createInfo(VibratorInfo.CAPABILITY_COMPOSE_EFFECTS) .hasCapability(VibratorInfo.CAPABILITY_AMPLITUDE_CONTROL)); assertTrue(createInfo(IVibrator.CAP_COMPOSE_EFFECTS) .hasCapability(IVibrator.CAP_COMPOSE_EFFECTS)); assertFalse(createInfo(IVibrator.CAP_COMPOSE_EFFECTS) .hasCapability(IVibrator.CAP_AMPLITUDE_CONTROL)); } @Test Loading @@ -59,7 +60,7 @@ public class VibratorInfoTest { @Test public void testIsPrimitiveSupported() { VibratorInfo info = new VibratorInfo(/* id= */ 0, VibratorInfo.CAPABILITY_COMPOSE_EFFECTS, VibratorInfo info = new VibratorInfo(/* id= */ 0, IVibrator.CAP_COMPOSE_EFFECTS, null, new int[]{VibrationEffect.Composition.PRIMITIVE_CLICK}); assertTrue(info.isPrimitiveSupported(VibrationEffect.Composition.PRIMITIVE_CLICK)); assertFalse(info.isPrimitiveSupported(VibrationEffect.Composition.PRIMITIVE_TICK)); Loading @@ -73,30 +74,30 @@ public class VibratorInfoTest { @Test public void testEquals() { VibratorInfo empty = new VibratorInfo(1, 0, null, null); VibratorInfo complete = new VibratorInfo(1, VibratorInfo.CAPABILITY_AMPLITUDE_CONTROL, VibratorInfo complete = new VibratorInfo(1, IVibrator.CAP_AMPLITUDE_CONTROL, new int[]{VibrationEffect.EFFECT_CLICK}, new int[]{VibrationEffect.Composition.PRIMITIVE_CLICK}); assertEquals(complete, complete); assertEquals(complete, new VibratorInfo(1, VibratorInfo.CAPABILITY_AMPLITUDE_CONTROL, assertEquals(complete, new VibratorInfo(1, IVibrator.CAP_AMPLITUDE_CONTROL, new int[]{VibrationEffect.EFFECT_CLICK}, new int[]{VibrationEffect.Composition.PRIMITIVE_CLICK})); assertFalse(empty.equals(new VibratorInfo(1, 0, new int[]{}, new int[]{}))); assertFalse(complete.equals(new VibratorInfo(1, VibratorInfo.CAPABILITY_COMPOSE_EFFECTS, assertFalse(complete.equals(new VibratorInfo(1, IVibrator.CAP_COMPOSE_EFFECTS, new int[]{VibrationEffect.EFFECT_CLICK}, new int[]{VibrationEffect.Composition.PRIMITIVE_CLICK}))); assertFalse(complete.equals(new VibratorInfo(1, VibratorInfo.CAPABILITY_AMPLITUDE_CONTROL, assertFalse(complete.equals(new VibratorInfo(1, IVibrator.CAP_AMPLITUDE_CONTROL, new int[]{}, new int[]{}))); assertFalse(complete.equals(new VibratorInfo(1, VibratorInfo.CAPABILITY_AMPLITUDE_CONTROL, assertFalse(complete.equals(new VibratorInfo(1, IVibrator.CAP_AMPLITUDE_CONTROL, null, new int[]{VibrationEffect.Composition.PRIMITIVE_CLICK}))); assertFalse(complete.equals(new VibratorInfo(1, VibratorInfo.CAPABILITY_AMPLITUDE_CONTROL, assertFalse(complete.equals(new VibratorInfo(1, IVibrator.CAP_AMPLITUDE_CONTROL, new int[]{VibrationEffect.EFFECT_CLICK}, null))); } @Test public void testSerialization() { VibratorInfo original = new VibratorInfo(1, VibratorInfo.CAPABILITY_COMPOSE_EFFECTS, VibratorInfo original = new VibratorInfo(1, IVibrator.CAP_COMPOSE_EFFECTS, new int[]{VibrationEffect.EFFECT_CLICK}, null); Parcel parcel = Parcel.obtain(); Loading
services/core/java/com/android/server/vibrator/Vibration.java +3 −1 Original line number Diff line number Diff line Loading @@ -120,7 +120,9 @@ final class Vibration { if (newEffect.equals(mEffect)) { return; } if (mOriginalEffect == null) { mOriginalEffect = mEffect; } mEffect = newEffect; } Loading