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

Commit 6bcc34ca authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Allow hardware feedback on low battery mode." into tm-dev

parents 426c815c c3047020
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -98,7 +98,9 @@ final class VibrationSettings {
            Arrays.asList(
                    USAGE_RINGTONE,
                    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.
+22 −40
Original line number Diff line number Diff line
@@ -81,6 +81,10 @@ import org.mockito.Mock;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;

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

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

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

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

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

    @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) {
            } else {
                assertVibrationIgnoredForUsage(usage, Vibration.Status.IGNORED_BACKGROUND);
            }
        }
    }

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

    @Test
    public void shouldIgnoreVibration_inBatterySaverMode_doesNotIgnoreUsagesFromAllowlist() {
        int[] expectedAllowedVibrations = new int[] {
        Set<Integer> expectedAllowedVibrations = new HashSet<>(Arrays.asList(
                USAGE_RINGTONE,
                USAGE_ALARM,
                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_TOUCH,
                USAGE_UNKNOWN,
        };
                USAGE_HARDWARE_FEEDBACK
        ));

        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);
            }
        }
    }

    @Test
    public void shouldIgnoreVibration_notInBatterySaverMode_allowsAnyUsage() {