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

Commit c3047020 authored by Lais Andrade's avatar Lais Andrade
Browse files

Allow hardware feedback on low battery mode.

Fix: 232807530
Test: VibrationSettingsTest
Change-Id: I0cee422b3cc92ad73fbd8d0f5cc52dbe3f68059e
parent 6a45e90f
Loading
Loading
Loading
Loading
+3 −1
Original line number Original line Diff line number Diff line
@@ -98,7 +98,9 @@ final class VibrationSettings {
            Arrays.asList(
            Arrays.asList(
                    USAGE_RINGTONE,
                    USAGE_RINGTONE,
                    USAGE_ALARM,
                    USAGE_ALARM,
                    USAGE_COMMUNICATION_REQUEST));
                    USAGE_COMMUNICATION_REQUEST,
                    USAGE_PHYSICAL_EMULATION,
                    USAGE_HARDWARE_FEEDBACK));


    /**
    /**
     * Usage allowed for vibrations when {@link Settings.System#VIBRATE_ON} is disabled.
     * Usage allowed for vibrations when {@link Settings.System#VIBRATE_ON} is disabled.
+22 −40
Original line number Original line Diff line number Diff line
@@ -81,6 +81,10 @@ import org.mockito.Mock;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
import org.mockito.junit.MockitoRule;


import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

/**
/**
 * Tests for {@link VibrationSettings}.
 * Tests for {@link VibrationSettings}.
 *
 *
@@ -199,37 +203,26 @@ public class VibrationSettingsTest {


    @Test
    @Test
    public void shouldIgnoreVibration_fromBackground_doesNotIgnoreUsagesFromAllowlist() {
    public void shouldIgnoreVibration_fromBackground_doesNotIgnoreUsagesFromAllowlist() {
        int[] expectedAllowedVibrations = new int[] {
        Set<Integer> expectedAllowedVibrations = new HashSet<>(Arrays.asList(
                USAGE_RINGTONE,
                USAGE_RINGTONE,
                USAGE_ALARM,
                USAGE_ALARM,
                USAGE_NOTIFICATION,
                USAGE_NOTIFICATION,
                USAGE_COMMUNICATION_REQUEST,
                USAGE_COMMUNICATION_REQUEST,
                USAGE_HARDWARE_FEEDBACK,
                USAGE_HARDWARE_FEEDBACK,
                USAGE_PHYSICAL_EMULATION,
                USAGE_PHYSICAL_EMULATION
        };
        ));


        mVibrationSettings.mUidObserver.onUidStateChanged(
        mVibrationSettings.mUidObserver.onUidStateChanged(
                UID, ActivityManager.PROCESS_STATE_IMPORTANT_BACKGROUND, 0, 0);
                UID, ActivityManager.PROCESS_STATE_IMPORTANT_BACKGROUND, 0, 0);


        for (int usage : expectedAllowedVibrations) {
        for (int usage : ALL_USAGES) {
            if (expectedAllowedVibrations.contains(usage)) {
                assertVibrationNotIgnoredForUsage(usage);
                assertVibrationNotIgnoredForUsage(usage);
        }
            } else {
    }

    @Test
    public void shouldIgnoreVibration_fromBackground_ignoresUsagesNotInAllowlist() {
        int[] expectedIgnoredVibrations = new int[] {
                USAGE_TOUCH,
                USAGE_UNKNOWN,
        };

        mVibrationSettings.mUidObserver.onUidStateChanged(
                UID, ActivityManager.PROCESS_STATE_IMPORTANT_BACKGROUND, 0, 0);

        for (int usage : expectedIgnoredVibrations) {
                assertVibrationIgnoredForUsage(usage, Vibration.Status.IGNORED_BACKGROUND);
                assertVibrationIgnoredForUsage(usage, Vibration.Status.IGNORED_BACKGROUND);
            }
            }
        }
        }
    }


    @Test
    @Test
    public void shouldIgnoreVibration_fromForeground_allowsAnyUsage() {
    public void shouldIgnoreVibration_fromForeground_allowsAnyUsage() {
@@ -243,35 +236,24 @@ public class VibrationSettingsTest {


    @Test
    @Test
    public void shouldIgnoreVibration_inBatterySaverMode_doesNotIgnoreUsagesFromAllowlist() {
    public void shouldIgnoreVibration_inBatterySaverMode_doesNotIgnoreUsagesFromAllowlist() {
        int[] expectedAllowedVibrations = new int[] {
        Set<Integer> expectedAllowedVibrations = new HashSet<>(Arrays.asList(
                USAGE_RINGTONE,
                USAGE_RINGTONE,
                USAGE_ALARM,
                USAGE_ALARM,
                USAGE_COMMUNICATION_REQUEST,
                USAGE_COMMUNICATION_REQUEST,
        };

        mRegisteredPowerModeListener.onLowPowerModeChanged(LOW_POWER_STATE);

        for (int usage : expectedAllowedVibrations) {
            assertVibrationNotIgnoredForUsage(usage);
        }
    }

    @Test
    public void shouldIgnoreVibration_inBatterySaverMode_ignoresUsagesNotInAllowlist() {
        int[] expectedIgnoredVibrations = new int[] {
                USAGE_NOTIFICATION,
                USAGE_HARDWARE_FEEDBACK,
                USAGE_PHYSICAL_EMULATION,
                USAGE_PHYSICAL_EMULATION,
                USAGE_TOUCH,
                USAGE_HARDWARE_FEEDBACK
                USAGE_UNKNOWN,
        ));
        };


        mRegisteredPowerModeListener.onLowPowerModeChanged(LOW_POWER_STATE);
        mRegisteredPowerModeListener.onLowPowerModeChanged(LOW_POWER_STATE);


        for (int usage : expectedIgnoredVibrations) {
        for (int usage : ALL_USAGES) {
            if (expectedAllowedVibrations.contains(usage)) {
                assertVibrationNotIgnoredForUsage(usage);
            } else {
                assertVibrationIgnoredForUsage(usage, Vibration.Status.IGNORED_FOR_POWER);
                assertVibrationIgnoredForUsage(usage, Vibration.Status.IGNORED_FOR_POWER);
            }
            }
        }
        }
    }


    @Test
    @Test
    public void shouldIgnoreVibration_notInBatterySaverMode_allowsAnyUsage() {
    public void shouldIgnoreVibration_notInBatterySaverMode_allowsAnyUsage() {