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

Commit 3caedfb9 authored by Josh Yang's avatar Josh Yang
Browse files

Support launching fitness app from stem primary button double press.

Flag: com.google.android.clockwork.systemui.flags.key_gesture_handler_enabled
Bug: 342503447
Test: manual test
Change-Id: I16d329b305a080b10e512c5d50ee825c98a9b1d7
parent e94b365d
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -1250,6 +1250,7 @@
         a watch, setting this config is no-op.
         a watch, setting this config is no-op.
            0 - Nothing
            0 - Nothing
            1 - Switch to the recent app
            1 - Switch to the recent app
            2 - Launch the default fitness app
    -->
    -->
    <integer name="config_doublePressOnStemPrimaryBehavior">0</integer>
    <integer name="config_doublePressOnStemPrimaryBehavior">0</integer>


+1 −1
Original line number Original line Diff line number Diff line
@@ -186,7 +186,7 @@ public class GlobalSettingsValidators {
        VALIDATORS.put(
        VALIDATORS.put(
                Global.STEM_PRIMARY_BUTTON_SHORT_PRESS, new InclusiveIntegerRangeValidator(0, 1));
                Global.STEM_PRIMARY_BUTTON_SHORT_PRESS, new InclusiveIntegerRangeValidator(0, 1));
        VALIDATORS.put(
        VALIDATORS.put(
                Global.STEM_PRIMARY_BUTTON_DOUBLE_PRESS, new InclusiveIntegerRangeValidator(0, 1));
                Global.STEM_PRIMARY_BUTTON_DOUBLE_PRESS, new InclusiveIntegerRangeValidator(0, 2));
        VALIDATORS.put(
        VALIDATORS.put(
                Global.STEM_PRIMARY_BUTTON_TRIPLE_PRESS, new InclusiveIntegerRangeValidator(0, 1));
                Global.STEM_PRIMARY_BUTTON_TRIPLE_PRESS, new InclusiveIntegerRangeValidator(0, 1));
        VALIDATORS.put(
        VALIDATORS.put(
+9 −0
Original line number Original line Diff line number Diff line
@@ -373,6 +373,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
    //The config value can be overridden using Settings.Global.STEM_PRIMARY_BUTTON_DOUBLE_PRESS
    //The config value can be overridden using Settings.Global.STEM_PRIMARY_BUTTON_DOUBLE_PRESS
    static final int DOUBLE_PRESS_PRIMARY_NOTHING = 0;
    static final int DOUBLE_PRESS_PRIMARY_NOTHING = 0;
    static final int DOUBLE_PRESS_PRIMARY_SWITCH_RECENT_APP = 1;
    static final int DOUBLE_PRESS_PRIMARY_SWITCH_RECENT_APP = 1;
    static final int DOUBLE_PRESS_PRIMARY_LAUNCH_DEFAULT_FITNESS_APP = 2;


    // Must match: config_triplePressOnStemPrimaryBehavior in config.xml
    // Must match: config_triplePressOnStemPrimaryBehavior in config.xml
    // The config value can be overridden using Settings.Global.STEM_PRIMARY_BUTTON_TRIPLE_PRESS
    // The config value can be overridden using Settings.Global.STEM_PRIMARY_BUTTON_TRIPLE_PRESS
@@ -1596,6 +1597,12 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                    performStemPrimaryDoublePressSwitchToRecentTask();
                    performStemPrimaryDoublePressSwitchToRecentTask();
                }
                }
                break;
                break;
            case DOUBLE_PRESS_PRIMARY_LAUNCH_DEFAULT_FITNESS_APP:
                final int stemPrimaryKeyDeviceId = INVALID_INPUT_DEVICE_ID;
                handleKeyGestureInKeyGestureController(
                        KeyGestureEvent.KEY_GESTURE_TYPE_LAUNCH_DEFAULT_FITNESS,
                        stemPrimaryKeyDeviceId, KEYCODE_STEM_PRIMARY, /* metaState= */ 0);
                break;
        }
        }
    }
    }


@@ -7243,6 +7250,8 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                return "DOUBLE_PRESS_PRIMARY_NOTHING";
                return "DOUBLE_PRESS_PRIMARY_NOTHING";
            case DOUBLE_PRESS_PRIMARY_SWITCH_RECENT_APP:
            case DOUBLE_PRESS_PRIMARY_SWITCH_RECENT_APP:
                return "DOUBLE_PRESS_PRIMARY_SWITCH_RECENT_APP";
                return "DOUBLE_PRESS_PRIMARY_SWITCH_RECENT_APP";
            case DOUBLE_PRESS_PRIMARY_LAUNCH_DEFAULT_FITNESS_APP:
                return "DOUBLE_PRESS_PRIMARY_LAUNCH_DEFAULT_FITNESS_APP";
            default:
            default:
                return Integer.toString(behavior);
                return Integer.toString(behavior);
        }
        }
+15 −0
Original line number Original line Diff line number Diff line
@@ -23,6 +23,7 @@ import static android.provider.Settings.Global.STEM_PRIMARY_BUTTON_TRIPLE_PRESS;
import static android.view.KeyEvent.KEYCODE_STEM_PRIMARY;
import static android.view.KeyEvent.KEYCODE_STEM_PRIMARY;


import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn;
import static com.android.server.policy.PhoneWindowManager.DOUBLE_PRESS_PRIMARY_LAUNCH_DEFAULT_FITNESS_APP;
import static com.android.server.policy.PhoneWindowManager.DOUBLE_PRESS_PRIMARY_SWITCH_RECENT_APP;
import static com.android.server.policy.PhoneWindowManager.DOUBLE_PRESS_PRIMARY_SWITCH_RECENT_APP;
import static com.android.server.policy.PhoneWindowManager.LONG_PRESS_PRIMARY_LAUNCH_VOICE_ASSISTANT;
import static com.android.server.policy.PhoneWindowManager.LONG_PRESS_PRIMARY_LAUNCH_VOICE_ASSISTANT;
import static com.android.server.policy.PhoneWindowManager.SHORT_PRESS_PRIMARY_LAUNCH_ALL_APPS;
import static com.android.server.policy.PhoneWindowManager.SHORT_PRESS_PRIMARY_LAUNCH_ALL_APPS;
@@ -32,6 +33,7 @@ import static com.android.server.policy.PhoneWindowManager.TRIPLE_PRESS_PRIMARY_
import android.app.ActivityManager.RecentTaskInfo;
import android.app.ActivityManager.RecentTaskInfo;
import android.app.ActivityTaskManager.RootTaskInfo;
import android.app.ActivityTaskManager.RootTaskInfo;
import android.content.ComponentName;
import android.content.ComponentName;
import android.hardware.input.KeyGestureEvent;
import android.os.RemoteException;
import android.os.RemoteException;
import android.provider.Settings;
import android.provider.Settings;
import android.view.Display;
import android.view.Display;
@@ -235,6 +237,19 @@ public class StemKeyGestureTests extends ShortcutKeyTestBase {
        mPhoneWindowManager.assertSwitchToTask(referenceId);
        mPhoneWindowManager.assertSwitchToTask(referenceId);
    }
    }


    @Test
    public void stemDoubleKey_behaviorIsLaunchFitness_gestureEventFired() {
        overrideBehavior(
                STEM_PRIMARY_BUTTON_DOUBLE_PRESS, DOUBLE_PRESS_PRIMARY_LAUNCH_DEFAULT_FITNESS_APP);
        setUpPhoneWindowManager(/* supportSettingsUpdate= */ true);

        sendKey(KEYCODE_STEM_PRIMARY);
        sendKey(KEYCODE_STEM_PRIMARY);

        mPhoneWindowManager.assertKeyGestureEventSentToKeyGestureController(
                KeyGestureEvent.KEY_GESTURE_TYPE_LAUNCH_DEFAULT_FITNESS);
    }

    @Test
    @Test
    public void stemTripleKey_EarlyShortPress_AllAppsThenBackToOriginalThenToggleA11y()
    public void stemTripleKey_EarlyShortPress_AllAppsThenBackToOriginalThenToggleA11y()
            throws RemoteException {
            throws RemoteException {
+5 −0
Original line number Original line Diff line number Diff line
@@ -919,4 +919,9 @@ class TestPhoneWindowManager {
        mTestLooper.dispatchAll();
        mTestLooper.dispatchAll();
        Assert.assertEquals(expectEnabled, mIsTalkBackEnabled);
        Assert.assertEquals(expectEnabled, mIsTalkBackEnabled);
    }
    }

    void assertKeyGestureEventSentToKeyGestureController(int gestureType) {
        verify(mInputManagerInternal)
                .handleKeyGestureInKeyGestureController(anyInt(), any(), anyInt(), eq(gestureType));
    }
}
}