Merge "Allow hardware feedback on low battery mode." into tm-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
6bcc34ca8c
@@ -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.
|
||||||
|
|||||||
@@ -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,35 +203,24 @@ 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) {
|
||||||
assertVibrationNotIgnoredForUsage(usage);
|
if (expectedAllowedVibrations.contains(usage)) {
|
||||||
}
|
assertVibrationNotIgnoredForUsage(usage);
|
||||||
}
|
} else {
|
||||||
|
assertVibrationIgnoredForUsage(usage, Vibration.Status.IGNORED_BACKGROUND);
|
||||||
@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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -243,33 +236,22 @@ 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) {
|
||||||
assertVibrationIgnoredForUsage(usage, Vibration.Status.IGNORED_FOR_POWER);
|
if (expectedAllowedVibrations.contains(usage)) {
|
||||||
|
assertVibrationNotIgnoredForUsage(usage);
|
||||||
|
} else {
|
||||||
|
assertVibrationIgnoredForUsage(usage, Vibration.Status.IGNORED_FOR_POWER);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user