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

Commit 9123a77a authored by Fan Zhang's avatar Fan Zhang
Browse files

Bug fix: GestureLauncherService is disabled incorrectly

The enable condition only includes camera sysprops/res configs however
the class handles both camera gesture and emergency gesture. When camera
flags are all turned off, the entirely class is turned off by mistake.

This change adds a res config so OEMs can turn on/off emergency gesture
feature individually, instead of bundling camera/emergency together.

Fix: 175236091
Test: atest GestureLauncherServiceTest
Change-Id: I774edb646b96c69549ee883143d76500af32b298
parent 7ffb3ba9
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -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>
+1 −0
Original line number Diff line number Diff line
@@ -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" />
+20 −8
Original line number Diff line number Diff line
@@ -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);
    }

    /**
+23 −4
Original line number Diff line number Diff line
@@ -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,