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

Commit aa6636ff authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Fix VibrationEffect creation from parcel" into main

parents bc5ae315 4bcf419a
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -1024,6 +1024,7 @@ public abstract class VibrationEffect implements Parcelable {
                new Creator<Composed>() {
                    @Override
                    public Composed createFromParcel(Parcel in) {
                        in.readInt(); // Skip the parcel type token
                        return new Composed(in);
                    }

@@ -1298,6 +1299,7 @@ public abstract class VibrationEffect implements Parcelable {
                new Creator<VendorEffect>() {
                    @Override
                    public VendorEffect createFromParcel(Parcel in) {
                        in.readInt(); // Skip the parcel type token
                        return new VendorEffect(in);
                    }

+21 −0
Original line number Diff line number Diff line
@@ -1071,6 +1071,27 @@ public class VibrationEffectTest {
                .isHapticFeedbackCandidate());
    }

    @Test
    public void testParcelingComposed() {
        Parcel p = Parcel.obtain();
        VibrationEffect effect = VibrationEffect.createPredefined(VibrationEffect.EFFECT_CLICK);
        effect.writeToParcel(p, 0);
        p.setDataPosition(0);
        VibrationEffect parceledEffect = VibrationEffect.Composed.CREATOR.createFromParcel(p);
        assertThat(parceledEffect).isEqualTo(effect);
    }

    @Test
    @RequiresFlagsEnabled(android.os.vibrator.Flags.FLAG_VENDOR_VIBRATION_EFFECTS)
    public void testParcelingVendorEffect() {
        Parcel p = Parcel.obtain();
        VibrationEffect effect = VibrationEffect.createVendorEffect(createNonEmptyBundle());
        effect.writeToParcel(p, 0);
        p.setDataPosition(0);
        VibrationEffect parceledEffect = VibrationEffect.VendorEffect.CREATOR.createFromParcel(p);
        assertThat(parceledEffect).isEqualTo(effect);
    }

    private void assertArrayEq(long[] expected, long[] actual) {
        assertTrue(
                String.format("Expected pattern %s, but was %s",