Merge "Bug fix: GestureLauncherService is disabled incorrectly"

This commit is contained in:
TreeHugger Robot
2020-12-10 19:11:48 +00:00
committed by Android (Google) Code Review
4 changed files with 48 additions and 12 deletions

View File

@@ -3303,6 +3303,10 @@
is non-interactive. -->
<bool name="config_cameraDoubleTapPowerGestureEnabled">true</bool>
<!-- Allow the gesture to quick tap the power button multiple times to start the emergency sos
experience while the device is non-interactive. -->
<bool name="config_emergencyGestureEnabled">true</bool>
<!-- Allow the gesture power + volume up to change the ringer mode while the device
is interactive. -->
<bool name="config_volumeHushGestureEnabled">true</bool>

View File

@@ -2823,6 +2823,7 @@
<java-symbol type="bool" name="config_cameraDoubleTapPowerGestureEnabled" />
<java-symbol type="integer" name="config_cameraLiftTriggerSensorType" />
<java-symbol type="string" name="config_cameraLiftTriggerSensorStringType" />
<java-symbol type="bool" name="config_emergencyGestureEnabled" />
<java-symbol type="bool" name="config_volumeHushGestureEnabled" />
<java-symbol type="drawable" name="platlogo_m" />

View File

@@ -257,7 +257,7 @@ public class GestureLauncherService extends SystemService {
@VisibleForTesting
void updateEmergencyGestureEnabled() {
boolean enabled = isEmergencyGestureEnabled(mContext, mUserId);
boolean enabled = isEmergencyGestureSettingEnabled(mContext, mUserId);
synchronized (this) {
mEmergencyGestureEnabled = enabled;
}
@@ -390,38 +390,50 @@ public class GestureLauncherService extends SystemService {
/**
* Whether to enable emergency gesture.
*/
public static boolean isEmergencyGestureEnabled(Context context, int userId) {
return Settings.Secure.getIntForUser(context.getContentResolver(),
@VisibleForTesting
static boolean isEmergencyGestureSettingEnabled(Context context, int userId) {
return isEmergencyGestureEnabled(context.getResources())
&& Settings.Secure.getIntForUser(context.getContentResolver(),
Settings.Secure.EMERGENCY_GESTURE_ENABLED, 0, userId) != 0;
}
/**
* Whether to enable the camera launch gesture.
*/
public static boolean isCameraLaunchEnabled(Resources resources) {
private static boolean isCameraLaunchEnabled(Resources resources) {
boolean configSet = resources.getInteger(
com.android.internal.R.integer.config_cameraLaunchGestureSensorType) != -1;
return configSet &&
!SystemProperties.getBoolean("gesture.disable_camera_launch", false);
}
public static boolean isCameraDoubleTapPowerEnabled(Resources resources) {
@VisibleForTesting
static boolean isCameraDoubleTapPowerEnabled(Resources resources) {
return resources.getBoolean(
com.android.internal.R.bool.config_cameraDoubleTapPowerGestureEnabled);
}
public static boolean isCameraLiftTriggerEnabled(Resources resources) {
private static boolean isCameraLiftTriggerEnabled(Resources resources) {
boolean configSet = resources.getInteger(
com.android.internal.R.integer.config_cameraLiftTriggerSensorType) != -1;
return configSet;
}
/**
* Whether or not the emergency gesture feature is enabled by platform
*/
private static boolean isEmergencyGestureEnabled(Resources resources) {
return resources.getBoolean(com.android.internal.R.bool.config_emergencyGestureEnabled);
}
/**
* Whether GestureLauncherService should be enabled according to system properties.
*/
public static boolean isGestureLauncherEnabled(Resources resources) {
return isCameraLaunchEnabled(resources) || isCameraDoubleTapPowerEnabled(resources) ||
isCameraLiftTriggerEnabled(resources);
return isCameraLaunchEnabled(resources)
|| isCameraDoubleTapPowerEnabled(resources)
|| isCameraLiftTriggerEnabled(resources)
|| isEmergencyGestureEnabled(resources);
}
/**

View File

@@ -163,16 +163,26 @@ public class GestureLauncherServiceTest {
}
@Test
public void testIsEmergencyGestureEnabled_settingDisabled() {
public void testIsEmergencyGestureSettingEnabled_settingDisabled() {
withEmergencyGestureEnabledConfigValue(true);
withEmergencyGestureEnabledSettingValue(false);
assertFalse(mGestureLauncherService.isEmergencyGestureEnabled(
assertFalse(mGestureLauncherService.isEmergencyGestureSettingEnabled(
mContext, FAKE_USER_ID));
}
@Test
public void testIsEmergencyGestureEnabled_settingEnabled() {
public void testIsEmergencyGestureSettingEnabled_settingEnabled() {
withEmergencyGestureEnabledConfigValue(true);
withEmergencyGestureEnabledSettingValue(true);
assertTrue(mGestureLauncherService.isEmergencyGestureEnabled(
assertTrue(mGestureLauncherService.isEmergencyGestureSettingEnabled(
mContext, FAKE_USER_ID));
}
@Test
public void testIsEmergencyGestureSettingEnabled_supportDisabled() {
withEmergencyGestureEnabledConfigValue(false);
withEmergencyGestureEnabledSettingValue(true);
assertFalse(mGestureLauncherService.isEmergencyGestureSettingEnabled(
mContext, FAKE_USER_ID));
}
@@ -438,6 +448,7 @@ public class GestureLauncherServiceTest {
testInterceptPowerKeyDown_fiveInboundPresses_cameraAndEmergencyEnabled_bothLaunch() {
withCameraDoubleTapPowerEnableConfigValue(true);
withCameraDoubleTapPowerDisableSettingValue(0);
withEmergencyGestureEnabledConfigValue(true);
withEmergencyGestureEnabledSettingValue(true);
mGestureLauncherService.updateCameraDoubleTapPowerEnabled();
mGestureLauncherService.updateEmergencyGestureEnabled();
@@ -527,6 +538,7 @@ public class GestureLauncherServiceTest {
@Test
public void
testInterceptPowerKeyDown_fiveInboundPresses_emergencyGestureEnabled_launchesFlow() {
withEmergencyGestureEnabledConfigValue(true);
withEmergencyGestureEnabledSettingValue(true);
mGestureLauncherService.updateEmergencyGestureEnabled();
withUserSetupCompleteValue(true);
@@ -580,6 +592,7 @@ public class GestureLauncherServiceTest {
@Test
public void
testInterceptPowerKeyDown_tenInboundPresses_emergencyGestureEnabled_keyIntercepted() {
withEmergencyGestureEnabledConfigValue(true);
withEmergencyGestureEnabledSettingValue(true);
mGestureLauncherService.updateEmergencyGestureEnabled();
withUserSetupCompleteValue(true);
@@ -1146,6 +1159,12 @@ public class GestureLauncherServiceTest {
.thenReturn(enableConfigValue);
}
private void withEmergencyGestureEnabledConfigValue(boolean enableConfigValue) {
when(mResources.getBoolean(
com.android.internal.R.bool.config_emergencyGestureEnabled))
.thenReturn(enableConfigValue);
}
private void withCameraDoubleTapPowerDisableSettingValue(int disableSettingValue) {
Settings.Secure.putIntForUser(
mContentResolver,