diff options
| author | 2020-12-10 19:11:48 +0000 | |
|---|---|---|
| committer | 2020-12-10 19:11:48 +0000 | |
| commit | d2007c37534ff81ec0ae8147ec2cff8ea920e847 (patch) | |
| tree | cbea5a0feecb384866f3a2398159f8f5df1195ae | |
| parent | f96294e1cadd46883169805f7efcf6d82d13d4d3 (diff) | |
| parent | 9123a77af7b780c4060b2da92bb01579a7371720 (diff) | |
Merge "Bug fix: GestureLauncherService is disabled incorrectly"
4 files changed, 48 insertions, 12 deletions
diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml index 40e11cb92d3e..03ba83c6bd2e 100644 --- a/core/res/res/values/config.xml +++ b/core/res/res/values/config.xml @@ -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> diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml index e50eee6afa91..aff0695bb14e 100644 --- a/core/res/res/values/symbols.xml +++ b/core/res/res/values/symbols.xml @@ -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" /> diff --git a/services/core/java/com/android/server/GestureLauncherService.java b/services/core/java/com/android/server/GestureLauncherService.java index 8ed23f900d73..c34285e9c062 100644 --- a/services/core/java/com/android/server/GestureLauncherService.java +++ b/services/core/java/com/android/server/GestureLauncherService.java @@ -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); } /** diff --git a/services/tests/servicestests/src/com/android/server/GestureLauncherServiceTest.java b/services/tests/servicestests/src/com/android/server/GestureLauncherServiceTest.java index a02c53336da0..6814c050a845 100644 --- a/services/tests/servicestests/src/com/android/server/GestureLauncherServiceTest.java +++ b/services/tests/servicestests/src/com/android/server/GestureLauncherServiceTest.java @@ -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, |