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

Commit 9f2edc78 authored by Yeabkal Wubshit's avatar Yeabkal Wubshit
Browse files

Flag OEM Haptic Vibration Customization

Bug: 291128479
Test: atest HapticFeedbackVibrationProviderTest
Test: atest VibratorManagerServiceTest
Change-Id: I8e1b8d85b995a2d5e6e573b0883fc05344213e38
parent 50847e32
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -27,3 +27,13 @@ flag {
    description: "Enables the APIs for vibration serialization/deserialization."
    bug: "245129509"
}

flag {
    namespace: "haptics"
    name: "haptic_feedback_vibration_oem_customization_enabled"
    description: "Enables OEMs/devices to customize vibrations for haptic feedback"
    # Make read only. This is because the flag is used only once, and this could happen before
    # the read-write flag values propagate to the device.
    is_fixed_read_only: true
    bug: "291128479"
}
+5 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.server.vibrator;
import android.annotation.Nullable;
import android.content.res.Resources;
import android.os.VibrationEffect;
import android.os.vibrator.Flags;
import android.os.VibratorInfo;
import android.os.vibrator.persistence.ParsedVibration;
import android.os.vibrator.persistence.VibrationXmlParser;
@@ -127,6 +128,10 @@ final class HapticFeedbackCustomization {
                    VibrationXmlParser.VibrationXmlParserException,
                    XmlParserException,
                    XmlPullParserException {
        if (!Flags.hapticFeedbackVibrationOemCustomizationEnabled()) {
            Slog.d(TAG, "Haptic feedback customization feature is not enabled.");
            return null;
        }
        String customizationFile =
                res.getString(
                        com.android.internal.R.string.config_hapticFeedbackCustomizationFile);
+1 −0
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ android_test {
        "androidx.test.runner",
        "androidx.test.rules",
        "androidx.test.ext.junit",
        "flag-junit",
        "frameworks-base-testutils",
        "frameworks-services-vibrator-testutils",
        "junit",
+20 −0
Original line number Diff line number Diff line
@@ -31,6 +31,8 @@ import static org.mockito.Mockito.when;
import android.content.res.Resources;
import android.os.VibrationEffect;
import android.os.VibratorInfo;
import android.os.vibrator.Flags;
import android.platform.test.flag.junit.SetFlagsRule;
import android.util.AtomicFile;
import android.util.SparseArray;

@@ -49,6 +51,8 @@ import java.io.File;
import java.io.FileOutputStream;

public class HapticFeedbackCustomizationTest {
    @Rule public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();

    @Rule public MockitoRule rule = MockitoJUnit.rule();

    // Pairs of valid vibration XML along with their equivalent VibrationEffect.
@@ -77,6 +81,7 @@ public class HapticFeedbackCustomizationTest {
    @Before
    public void setUp() {
        when(mVibratorInfoMock.areVibrationFeaturesSupported(any())).thenReturn(true);
        mSetFlagsRule.enableFlags(Flags.FLAG_HAPTIC_FEEDBACK_VIBRATION_OEM_CUSTOMIZATION_ENABLED);
    }

    @Test
@@ -86,6 +91,21 @@ public class HapticFeedbackCustomizationTest {
                /* expectedCustomizations= */ new SparseArray<>());
    }

    @Test
    public void testParseCustomizations_featureFlagDisabled_returnsNull() throws Exception {
        mSetFlagsRule.disableFlags(Flags.FLAG_HAPTIC_FEEDBACK_VIBRATION_OEM_CUSTOMIZATION_ENABLED);
        // Valid customization XML.
        String xml = "<haptic-feedback-constants>"
                + "<constant id=\"10\">"
                + COMPOSITION_VIBRATION_XML
                + "</constant>"
                + "</haptic-feedback-constants>";
        setupCustomizationFile(xml);

        assertThat(HapticFeedbackCustomization.loadVibrations(mResourcesMock, mVibratorInfoMock))
                .isNull();
    }

    @Test
    public void testParseCustomizations_oneVibrationCustomization_success() throws Exception {
        String xml = "<haptic-feedback-constants>"