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

Commit 68d60fdf authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "TV would like to launch home after stopping dreaming" into main

parents dcfb635e 10e5239c
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -1851,9 +1851,14 @@ public class PhoneWindowManager implements WindowManagerPolicy {
        final DreamManagerInternal dreamManagerInternal = getDreamManagerInternal();
        if (dreamManagerInternal != null && dreamManagerInternal.isDreaming()) {
            dreamManagerInternal.stopDream(false /*immediate*/, "short press on home" /*reason*/);
            if (mHasFeatureLeanback) {
                if (localLOGV) Log.v(TAG, "TV will launch home after stopping dream");
            } else {
                return;
            }

        }

        // Go home!
        launchHomeFromHotKey(displayId);
    }
+10 −1
Original line number Diff line number Diff line
@@ -157,7 +157,7 @@ public class KeyGestureEventTests extends ShortcutKeyTestBase {

    @Before
    public void setUp() {
        setUpPhoneWindowManager(/*supportSettingsUpdate*/ true);
        setUpPhoneWindowManager(/*supportSettingsUpdate*/ true, /* supportFeature */ "");
        mPhoneWindowManager.overrideLaunchHome();
        mPhoneWindowManager.overrideEnableBugReportTrigger(true);
        mPhoneWindowManager.overrideStatusBarManagerInternal();
@@ -241,6 +241,15 @@ public class KeyGestureEventTests extends ShortcutKeyTestBase {
        mPhoneWindowManager.assertGoToHomescreen();
    }

    @Test
    public void testKeyGestureStopDreaming() {
        mPhoneWindowManager.overrideCanStartDreaming(true);
        mPhoneWindowManager.overrideIsDreaming(true);
        sendKeyGestureEventComplete(KeyGestureEvent.KEY_GESTURE_TYPE_HOME);
        mPhoneWindowManager.assertDreamStopped();
        mPhoneWindowManager.assertNotGoToHomescreen();
    }

    @Test
    public void testKeyGestureLaunchSystemSettings() {
        sendKeyGestureEventComplete(KeyGestureEvent.KEY_GESTURE_TYPE_LAUNCH_SYSTEM_SETTINGS);
+52 −0
Original line number Diff line number Diff line
/*
 * Copyright 2025 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.server.policy;

import static android.content.pm.PackageManager.FEATURE_LEANBACK;

import android.hardware.input.KeyGestureEvent;
import android.platform.test.annotations.Presubmit;

import androidx.test.filters.MediumTest;

import junitparams.JUnitParamsRunner;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

@Presubmit
@MediumTest
@RunWith(JUnitParamsRunner.class)
public class KeyGestureEventTvTests extends ShortcutKeyTestBase {
    @Before
    public void setUp() {
        setUpPhoneWindowManager(
                /*supportSettingsUpdate*/ true, /*supportFeature*/ FEATURE_LEANBACK);
        mPhoneWindowManager.overrideLaunchHome();
        mPhoneWindowManager.overrideUserSetupComplete();
    }

    @Test
    public void testKeyGestureTvStopDreamingAndGoHome() {
        mPhoneWindowManager.overrideCanStartDreaming(true);
        mPhoneWindowManager.overrideIsDreaming(true);
        sendKeyGestureEventComplete(KeyGestureEvent.KEY_GESTURE_TYPE_HOME);
        mPhoneWindowManager.assertDreamStopped();
        mPhoneWindowManager.assertGoToHomescreen();
    }
}
+11 −5
Original line number Diff line number Diff line
@@ -128,10 +128,12 @@ class ShortcutKeyTestBase {
        } catch (PackageManager.NameNotFoundException ignored) { }
    }


    /** Same as {@link setUpPhoneWindowManager(boolean)}, without supporting settings update. */
    /**
     * Same as {@link setUpPhoneWindowManager(boolean, String)}, without supporting settings update
     * and feature.
     */
    protected final void setUpPhoneWindowManager() {
        setUpPhoneWindowManager(/* supportSettingsUpdate= */ false);
        setUpPhoneWindowManager(/* supportSettingsUpdate= */ false, /* supportFeature */ "");
    }

    /**
@@ -146,9 +148,13 @@ class ShortcutKeyTestBase {
     *    notifyChange(), which prevents SettingsObserver from getting notified of events. So
     *    we're effectively always instantiating TestPhoneWindowManager with
     *    supportSettingsUpdate=false.
     * @param supportFeature The feature will be supported by TestPhoneWindowManager. Empty string
     *    if no specific feature to be provided.
     */
    protected final void setUpPhoneWindowManager(boolean supportSettingsUpdate) {
        mPhoneWindowManager = new TestPhoneWindowManager(mContext, supportSettingsUpdate);
    protected final void setUpPhoneWindowManager(
            boolean supportSettingsUpdate, String supportFeature) {
        mPhoneWindowManager =
                new TestPhoneWindowManager(mContext, supportSettingsUpdate, supportFeature);
    }

    protected final void setDispatchedKeyHandler(DispatchedKeyHandler keyHandler) {
+16 −16
Original line number Diff line number Diff line
@@ -66,7 +66,7 @@ public class StemKeyGestureTests extends ShortcutKeyTestBase {
    @Test
    public void stemSingleKey_duringSetup_doNothing() {
        overrideBehavior(STEM_PRIMARY_BUTTON_SHORT_PRESS, SHORT_PRESS_PRIMARY_LAUNCH_ALL_APPS);
        setUpPhoneWindowManager(/* supportSettingsUpdate= */ true);
        setUpPhoneWindowManager(/* supportSettingsUpdate= */ true, /* supportFeature */ "");
        mPhoneWindowManager.overrideShouldEarlyShortPressOnStemPrimary(false);
        mPhoneWindowManager.setKeyguardServiceDelegateIsShowing(false);
        mPhoneWindowManager.overrideIsUserSetupComplete(false);
@@ -82,7 +82,7 @@ public class StemKeyGestureTests extends ShortcutKeyTestBase {
    @Test
    public void stemSingleKey_AfterSetup_openAllApp() {
        overrideBehavior(STEM_PRIMARY_BUTTON_SHORT_PRESS, SHORT_PRESS_PRIMARY_LAUNCH_ALL_APPS);
        setUpPhoneWindowManager(/* supportSettingsUpdate= */ true);
        setUpPhoneWindowManager(/* supportSettingsUpdate= */ true, /* supportFeature */ "");
        mPhoneWindowManager.overrideShouldEarlyShortPressOnStemPrimary(false);
        mPhoneWindowManager.overrideStartActivity();
        mPhoneWindowManager.setKeyguardServiceDelegateIsShowing(false);
@@ -101,7 +101,7 @@ public class StemKeyGestureTests extends ShortcutKeyTestBase {
        overrideBehavior(
                STEM_PRIMARY_BUTTON_SHORT_PRESS,
                SHORT_PRESS_PRIMARY_LAUNCH_TARGET_ACTIVITY);
        setUpPhoneWindowManager(/* supportSettingsUpdate= */ true);
        setUpPhoneWindowManager(/* supportSettingsUpdate= */ true, /* supportFeature */ "");
        mPhoneWindowManager.overrideShouldEarlyShortPressOnStemPrimary(false);
        mPhoneWindowManager.overrideStartActivity();
        mPhoneWindowManager.setKeyguardServiceDelegateIsShowing(false);
@@ -121,7 +121,7 @@ public class StemKeyGestureTests extends ShortcutKeyTestBase {
        overrideBehavior(
                STEM_PRIMARY_BUTTON_SHORT_PRESS,
                SHORT_PRESS_PRIMARY_LAUNCH_TARGET_ACTIVITY);
        setUpPhoneWindowManager(/* supportSettingsUpdate= */ true);
        setUpPhoneWindowManager(/* supportSettingsUpdate= */ true, /* supportFeature */ "");
        mPhoneWindowManager.overrideShouldEarlyShortPressOnStemPrimary(false);
        mPhoneWindowManager.overrideStartActivity();
        mPhoneWindowManager.setKeyguardServiceDelegateIsShowing(false);
@@ -140,7 +140,7 @@ public class StemKeyGestureTests extends ShortcutKeyTestBase {
    @Test
    public void stemSingleKey_appHasOverridePermission_consumedByApp_notOpenAllApp() {
        overrideBehavior(STEM_PRIMARY_BUTTON_SHORT_PRESS, SHORT_PRESS_PRIMARY_LAUNCH_ALL_APPS);
        setUpPhoneWindowManager(/* supportSettingsUpdate= */ true);
        setUpPhoneWindowManager(/* supportSettingsUpdate= */ true, /* supportFeature */ "");
        mPhoneWindowManager.overrideStartActivity();
        mPhoneWindowManager.setKeyguardServiceDelegateIsShowing(false);
        mPhoneWindowManager.overrideIsUserSetupComplete(true);
@@ -156,7 +156,7 @@ public class StemKeyGestureTests extends ShortcutKeyTestBase {
    @Test
    public void stemSingleKey_appHasOverridePermission_notConsumedByApp_openAllApp() {
        overrideBehavior(STEM_PRIMARY_BUTTON_SHORT_PRESS, SHORT_PRESS_PRIMARY_LAUNCH_ALL_APPS);
        setUpPhoneWindowManager(/* supportSettingsUpdate= */ true);
        setUpPhoneWindowManager(/* supportSettingsUpdate= */ true, /* supportFeature */ "");
        mPhoneWindowManager.overrideStartActivity();
        mPhoneWindowManager.setKeyguardServiceDelegateIsShowing(false);
        mPhoneWindowManager.overrideIsUserSetupComplete(true);
@@ -172,7 +172,7 @@ public class StemKeyGestureTests extends ShortcutKeyTestBase {
        overrideBehavior(
                STEM_PRIMARY_BUTTON_LONG_PRESS,
                LONG_PRESS_PRIMARY_LAUNCH_VOICE_ASSISTANT);
        setUpPhoneWindowManager(/* supportSettingsUpdate= */ true);
        setUpPhoneWindowManager(/* supportSettingsUpdate= */ true, /* supportFeature */ "");
        mPhoneWindowManager.overrideShouldEarlyShortPressOnStemPrimary(false);
        mPhoneWindowManager.setupAssistForLaunch();
        mPhoneWindowManager.overrideIsUserSetupComplete(true);
@@ -186,7 +186,7 @@ public class StemKeyGestureTests extends ShortcutKeyTestBase {
        overrideBehavior(
                STEM_PRIMARY_BUTTON_LONG_PRESS,
                LONG_PRESS_PRIMARY_LAUNCH_VOICE_ASSISTANT);
        setUpPhoneWindowManager(/* supportSettingsUpdate= */ true);
        setUpPhoneWindowManager(/* supportSettingsUpdate= */ true, /* supportFeature */ "");
        mPhoneWindowManager.overrideShouldEarlyShortPressOnStemPrimary(false);
        mPhoneWindowManager.setupAssistForLaunch();
        mPhoneWindowManager.overrideSearchManager(null);
@@ -202,7 +202,7 @@ public class StemKeyGestureTests extends ShortcutKeyTestBase {
        overrideBehavior(
                STEM_PRIMARY_BUTTON_LONG_PRESS,
                LONG_PRESS_PRIMARY_LAUNCH_VOICE_ASSISTANT);
        setUpPhoneWindowManager(/* supportSettingsUpdate= */ true);
        setUpPhoneWindowManager(/* supportSettingsUpdate= */ true, /* supportFeature */ "");
        mPhoneWindowManager.overrideShouldEarlyShortPressOnStemPrimary(false);
        mPhoneWindowManager.setupAssistForLaunch();
        mPhoneWindowManager.overrideSearchManager(null);
@@ -222,7 +222,7 @@ public class StemKeyGestureTests extends ShortcutKeyTestBase {
            throws RemoteException {
        overrideBehavior(STEM_PRIMARY_BUTTON_SHORT_PRESS, SHORT_PRESS_PRIMARY_LAUNCH_ALL_APPS);
        overrideBehavior(STEM_PRIMARY_BUTTON_DOUBLE_PRESS, DOUBLE_PRESS_PRIMARY_SWITCH_RECENT_APP);
        setUpPhoneWindowManager(/* supportSettingsUpdate= */ true);
        setUpPhoneWindowManager(/* supportSettingsUpdate= */ true, /* supportFeature */ "");
        mPhoneWindowManager.overrideShouldEarlyShortPressOnStemPrimary(true);
        mPhoneWindowManager.setKeyguardServiceDelegateIsShowing(false);
        mPhoneWindowManager.overrideIsUserSetupComplete(true);
@@ -243,7 +243,7 @@ public class StemKeyGestureTests extends ShortcutKeyTestBase {
    public void stemDoubleKey_behaviorIsLaunchFitness_gestureEventFired() {
        overrideBehavior(
                STEM_PRIMARY_BUTTON_DOUBLE_PRESS, DOUBLE_PRESS_PRIMARY_LAUNCH_DEFAULT_FITNESS_APP);
        setUpPhoneWindowManager(/* supportSettingsUpdate= */ true);
        setUpPhoneWindowManager(/* supportSettingsUpdate= */ true, /* supportFeature */ "");

        sendKey(KEYCODE_STEM_PRIMARY);
        sendKey(KEYCODE_STEM_PRIMARY);
@@ -258,7 +258,7 @@ public class StemKeyGestureTests extends ShortcutKeyTestBase {
        overrideBehavior(STEM_PRIMARY_BUTTON_SHORT_PRESS, SHORT_PRESS_PRIMARY_LAUNCH_ALL_APPS);
        overrideBehavior(
                STEM_PRIMARY_BUTTON_TRIPLE_PRESS, TRIPLE_PRESS_PRIMARY_TOGGLE_ACCESSIBILITY);
        setUpPhoneWindowManager(/* supportSettingsUpdate= */ true);
        setUpPhoneWindowManager(/* supportSettingsUpdate= */ true, /* supportFeature */ "");
        mPhoneWindowManager.overrideShouldEarlyShortPressOnStemPrimary(true);
        mPhoneWindowManager.overrideTalkbackShortcutGestureEnabled(true);
        mPhoneWindowManager.setKeyguardServiceDelegateIsShowing(false);
@@ -287,7 +287,7 @@ public class StemKeyGestureTests extends ShortcutKeyTestBase {
        overrideBehavior(STEM_PRIMARY_BUTTON_DOUBLE_PRESS, SHORT_PRESS_PRIMARY_LAUNCH_ALL_APPS);
        overrideBehavior(
                STEM_PRIMARY_BUTTON_TRIPLE_PRESS, TRIPLE_PRESS_PRIMARY_TOGGLE_ACCESSIBILITY);
        setUpPhoneWindowManager(/* supportSettingsUpdate= */ true);
        setUpPhoneWindowManager(/* supportSettingsUpdate= */ true, /* supportFeature */ "");
        mPhoneWindowManager.overrideShouldEarlyShortPressOnStemPrimary(false);
        mPhoneWindowManager.overrideTalkbackShortcutGestureEnabled(true);
        mPhoneWindowManager.setKeyguardServiceDelegateIsShowing(false);
@@ -316,7 +316,7 @@ public class StemKeyGestureTests extends ShortcutKeyTestBase {
    public void stemDoubleKey_earlyShortPress_firstPressConsumedByApp_switchToMostRecent()
            throws RemoteException {
        overrideBehavior(STEM_PRIMARY_BUTTON_DOUBLE_PRESS, SHORT_PRESS_PRIMARY_LAUNCH_ALL_APPS);
        setUpPhoneWindowManager(/* supportSettingsUpdate= */ true);
        setUpPhoneWindowManager(/* supportSettingsUpdate= */ true, /* supportFeature */ "");
        mPhoneWindowManager.overrideShouldEarlyShortPressOnStemPrimary(true);
        mPhoneWindowManager.setKeyguardServiceDelegateIsShowing(false);
        mPhoneWindowManager.overrideIsUserSetupComplete(true);
@@ -362,7 +362,7 @@ public class StemKeyGestureTests extends ShortcutKeyTestBase {
                SHORT_PRESS_PRIMARY_LAUNCH_ALL_APPS);

        // start the PhoneWindowManager, just like would happen with a reboot
        setUpPhoneWindowManager(/* supportSettingsUpdate= */ true);
        setUpPhoneWindowManager(/* supportSettingsUpdate= */ true, /* supportFeature */ "");
        // Set the stem behavior back to something normal after boot
        overrideBehavior(STEM_PRIMARY_BUTTON_SHORT_PRESS,
                SHORT_PRESS_PRIMARY_LAUNCH_ALL_APPS);
@@ -409,7 +409,7 @@ public class StemKeyGestureTests extends ShortcutKeyTestBase {
                PhoneWindowManager.LONG_PRESS_PRIMARY_NOTHING);

        // start the PhoneWindowManager, just like would happen with a reboot
        setUpPhoneWindowManager(/* supportSettingsUpdate= */ true);
        setUpPhoneWindowManager(/* supportSettingsUpdate= */ true, /* supportFeature */ "");
        // Set the stem behavior back to something normal after boot
        // (Despite this fact, a stem press shouldn't have any behavior because there's no rule.)
        overrideBehavior(STEM_PRIMARY_BUTTON_SHORT_PRESS,
Loading