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

Commit 02b2812c authored by Josh Yang's avatar Josh Yang Committed by Android (Google) Code Review
Browse files

Merge "Support launching fitness app from stem primary button double press." into main

parents 6c566601 3caedfb9
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -1250,6 +1250,7 @@
         a watch, setting this config is no-op.
            0 - Nothing
            1 - Switch to the recent app
            2 - Launch the default fitness app
    -->
    <integer name="config_doublePressOnStemPrimaryBehavior">0</integer>

+1 −1
Original line number Diff line number Diff line
@@ -186,7 +186,7 @@ public class GlobalSettingsValidators {
        VALIDATORS.put(
                Global.STEM_PRIMARY_BUTTON_SHORT_PRESS, new InclusiveIntegerRangeValidator(0, 1));
        VALIDATORS.put(
                Global.STEM_PRIMARY_BUTTON_DOUBLE_PRESS, new InclusiveIntegerRangeValidator(0, 1));
                Global.STEM_PRIMARY_BUTTON_DOUBLE_PRESS, new InclusiveIntegerRangeValidator(0, 2));
        VALIDATORS.put(
                Global.STEM_PRIMARY_BUTTON_TRIPLE_PRESS, new InclusiveIntegerRangeValidator(0, 1));
        VALIDATORS.put(
+9 −0
Original line number 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
    static final int DOUBLE_PRESS_PRIMARY_NOTHING = 0;
    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
    // The config value can be overridden using Settings.Global.STEM_PRIMARY_BUTTON_TRIPLE_PRESS
@@ -1596,6 +1597,12 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                    performStemPrimaryDoublePressSwitchToRecentTask();
                }
                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;
        }
    }

@@ -7244,6 +7251,8 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                return "DOUBLE_PRESS_PRIMARY_NOTHING";
            case 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:
                return Integer.toString(behavior);
        }
+15 −0
Original line number 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 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.LONG_PRESS_PRIMARY_LAUNCH_VOICE_ASSISTANT;
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.ActivityTaskManager.RootTaskInfo;
import android.content.ComponentName;
import android.hardware.input.KeyGestureEvent;
import android.os.RemoteException;
import android.provider.Settings;
import android.view.Display;
@@ -235,6 +237,19 @@ public class StemKeyGestureTests extends ShortcutKeyTestBase {
        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
    public void stemTripleKey_EarlyShortPress_AllAppsThenBackToOriginalThenToggleA11y()
            throws RemoteException {
+5 −0
Original line number Diff line number Diff line
@@ -919,4 +919,9 @@ class TestPhoneWindowManager {
        mTestLooper.dispatchAll();
        Assert.assertEquals(expectEnabled, mIsTalkBackEnabled);
    }

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