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

Commit 87700036 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

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

Merge "Allow hardware feedback on low battery mode." into tm-dev am: 6bcc34ca am: 7a9ad316 am: 6064cf85

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/18404449



Change-Id: I681ca784c446b9f793f3c4d1e99882e80627f081
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 0fc74d37 6064cf85
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() {