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

Commit 914ac9af authored by Bharat Singh's avatar Bharat Singh
Browse files

Modified revert "[SysUI][Floaty] Send KeyEvent with FLAG_LONG_PRESS on long power press"

This reverts commit 44824f37.

Reason for revert: Cleanup, not needed anymore

Bug: 399263897
Test: NONE revert
Flag: NONE revert
Change-Id: I4139ac33d2c453ac1e159b60d923297c768cd288
parent fd834737
Loading
Loading
Loading
Loading
+0 −13
Original line number Diff line number Diff line
@@ -2554,19 +2554,6 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            // this to all single key gestures after moving Single key gestures to
            // KeyGestureController.
            if (enableLppAssistInvocationEffect()) {
                // TODO(b/358569822): Remove this synthetic key event and directly listen to key
                //  gesture event in SysUI
                if (event.getAction() == ACTION_COMPLETE) {
                    // Long press is detected in a callback, so there's no explicit hardware
                    // KeyEvent available here. Instead, we create a synthetic power key event that
                    // has properties similar to the original one.
                    final KeyEvent keyEvent = new KeyEvent(KeyEvent.ACTION_DOWN, KEYCODE_POWER);
                    keyEvent.setFlags(KeyEvent.FLAG_LONG_PRESS);
                    // setting both downTime and eventTime as same as downTime is sent as eventTime
                    // for long press event in SingleKeyGestureDetector's handler
                    keyEvent.setTime(event.getStartTime(), event.getEventTime());
                    sendSystemKeyToStatusBarAsync(keyEvent);
                }
                if (getResolvedLongPressOnPowerBehavior() == LONG_PRESS_POWER_ASSISTANT) {
                    handleSingleKeyGestureInKeyGestureController(
                            KeyGestureEvent.KEY_GESTURE_TYPE_LAUNCH_ASSISTANT, event);
+0 −1
Original line number Diff line number Diff line
@@ -84,7 +84,6 @@ android_test {
        "androidx.test.rules",
        "androidx.test.runner",
        "com.android.window.flags.window-aconfig-java",
        "cts-input-lib",
        "flag-junit",
        "flickerlib",
        "frameworks-base-testutils",
+0 −86
Original line number Diff line number Diff line
@@ -15,16 +15,9 @@
 */
package com.android.server.policy;

import static android.view.Display.DEFAULT_DISPLAY;
import static android.view.KeyEvent.ACTION_DOWN;
import static android.view.KeyEvent.ACTION_UP;
import static android.view.KeyEvent.FLAG_LONG_PRESS;
import static android.view.KeyEvent.KEYCODE_POWER;
import static android.view.KeyEvent.KEYCODE_VOLUME_UP;

import static com.android.cts.input.inputeventmatchers.InputEventMatchersKt.withKeyAction;
import static com.android.cts.input.inputeventmatchers.InputEventMatchersKt.withKeyCode;
import static com.android.cts.input.inputeventmatchers.InputEventMatchersKt.withKeyFlags;
import static com.android.server.policy.PhoneWindowManager.LONG_PRESS_POWER_ASSISTANT;
import static com.android.server.policy.PhoneWindowManager.LONG_PRESS_POWER_GLOBAL_ACTIONS;
import static com.android.server.policy.PhoneWindowManager.LONG_PRESS_POWER_GO_TO_SLEEP;
@@ -32,30 +25,13 @@ import static com.android.server.policy.PhoneWindowManager.POWER_MULTI_PRESS_TIM
import static com.android.server.policy.PhoneWindowManager.SHORT_PRESS_POWER_DREAM_OR_SLEEP;
import static com.android.server.policy.PhoneWindowManager.SHORT_PRESS_POWER_GO_TO_SLEEP;

import static org.hamcrest.Matchers.allOf;

import android.os.RemoteException;
import android.platform.test.annotations.DisableFlags;
import android.platform.test.annotations.EnableFlags;
import android.platform.test.annotations.Presubmit;
import android.provider.Settings;
import android.view.Display;
import android.view.InputDevice;
import android.view.InputEvent;
import android.view.KeyCharacterMap;
import android.view.KeyEvent;

import androidx.annotation.NonNull;

import com.android.cts.input.BlockingQueueEventVerifier;
import com.android.systemui.shared.Flags;

import org.junit.Before;
import org.junit.Test;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;

/**
 * Test class for power key gesture.
 *
@@ -184,66 +160,4 @@ public class PowerKeyGestureTests extends ShortcutKeyTestBase {
        sendKey(KEYCODE_POWER);
        mPhoneWindowManager.assertNoPowerSleep();
    }

    @EnableFlags(Flags.FLAG_ENABLE_LPP_ASSIST_INVOCATION_EFFECT)
    @Test
    public void testPowerLongPress_flagEnabled_shouldSendSyntheticKeyEvent()
            throws RemoteException {
        final BlockingQueue<InputEvent> eventQueue = new LinkedBlockingQueue<>();
        final BlockingQueueEventVerifier verifier = new BlockingQueueEventVerifier(eventQueue);
        mPhoneWindowManager.overrideLongPressPowerForSyntheticEvent(LONG_PRESS_POWER_ASSISTANT,
                eventQueue);
        sendKeyForTriggeringSyntheticEvent();
        verifier.assertReceivedKey(allOf(withKeyCode(KEYCODE_POWER), withKeyAction(ACTION_DOWN)));
        verifier.assertReceivedKey(allOf(withKeyCode(KEYCODE_POWER), withKeyAction(ACTION_DOWN),
                withKeyFlags(FLAG_LONG_PRESS)));
        verifier.assertReceivedKey(allOf(withKeyCode(KEYCODE_POWER), withKeyAction(ACTION_UP)));
    }

    @DisableFlags(Flags.FLAG_ENABLE_LPP_ASSIST_INVOCATION_EFFECT)
    @Test
    public void testPowerLongPress_flagDisabled_shouldNotSendSyntheticKeyEvent()
            throws RemoteException {
        final BlockingQueue<InputEvent> eventQueue = new LinkedBlockingQueue<>();
        final BlockingQueueEventVerifier verifier = new BlockingQueueEventVerifier(eventQueue);
        mPhoneWindowManager.overrideLongPressPowerForSyntheticEvent(LONG_PRESS_POWER_ASSISTANT,
                eventQueue);
        sendKeyForTriggeringSyntheticEvent();
        verifier.assertReceivedKey(allOf(withKeyCode(KEYCODE_POWER), withKeyAction(ACTION_DOWN)));
        verifier.assertReceivedKey(allOf(withKeyCode(KEYCODE_POWER), withKeyAction(ACTION_UP)));
    }

    private void sendKeyForTriggeringSyntheticEvent() {
        // send power button key down event (without setting long press flag) and move time forward
        // by long press duration timeout, it should send a synthetic power button down event with
        // long press flag set
        final long time = mPhoneWindowManager.getCurrentTime();
        final KeyEvent downEvent = getPowerButtonKeyEvent(ACTION_DOWN, time);
        mPhoneWindowManager.interceptKeyBeforeQueueing(downEvent);
        mPhoneWindowManager.dispatchAllPendingEvents();
        mPhoneWindowManager.moveTimeForward(SingleKeyGestureDetector.sDefaultLongPressTimeout);

        // send power button key up event to emulate power button has been released
        final KeyEvent upEvent = getPowerButtonKeyEvent(ACTION_UP, time);
        mPhoneWindowManager.interceptKeyBeforeQueueing(upEvent);
        mPhoneWindowManager.dispatchAllPendingEvents();
    }

    @NonNull
    private KeyEvent getPowerButtonKeyEvent(final int action, final long time) {
        final KeyEvent downEvent = new KeyEvent(
                /* downTime */ time,
                /* eventTime */ time,
                /* action */ action,
                /* keyCode */ KEYCODE_POWER,
                /* repeat */ 0,
                /* metaState */ 0,
                /* deviceId */ KeyCharacterMap.VIRTUAL_KEYBOARD,
                /* scanCode */ 0,
                /* flags */ 0,
                /* source */ InputDevice.SOURCE_KEYBOARD
        );
        downEvent.setDisplayId(DEFAULT_DISPLAY);
        return downEvent;
    }
}
+0 −14
Original line number Diff line number Diff line
@@ -78,7 +78,6 @@ import android.hardware.input.InputManager;
import android.hardware.input.KeyGestureEvent;
import android.media.AudioManagerInternal;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.IBinder;
import android.os.Looper;
import android.os.PowerManager;
@@ -101,7 +100,6 @@ import android.view.accessibility.AccessibilityManager;
import android.view.autofill.AutofillManagerInternal;

import com.android.dx.mockito.inline.extended.StaticMockitoSession;
import com.android.internal.accessibility.AccessibilityShortcutController;
import com.android.internal.logging.MetricsLogger;
import com.android.internal.logging.UiEventLogger;
import com.android.internal.policy.KeyInterceptionInfo;
@@ -132,7 +130,6 @@ import org.mockito.MockitoAnnotations;
import org.mockito.quality.Strictness;

import java.util.List;
import java.util.concurrent.BlockingQueue;
import java.util.function.Supplier;

class TestPhoneWindowManager {
@@ -507,17 +504,6 @@ class TestPhoneWindowManager {
        }
    }

    void overrideLongPressPowerForSyntheticEvent(final int behavior,
            final BlockingQueue<InputEvent> eventQueue) throws RemoteException {
        mPhoneWindowManager.getStatusBarService();
        spyOn(mPhoneWindowManager.mStatusBarService);
        Mockito.doAnswer(invocation -> {
            eventQueue.add(new KeyEvent(invocation.getArgument(0)));
            return null;
        }).when(mPhoneWindowManager.mStatusBarService).handleSystemKey(any());
        overrideLongPressOnPower(behavior);
    }

    void overrideLongPressOnHomeBehavior(int behavior) {
        mPhoneWindowManager.mLongPressOnHomeBehavior = behavior;
    }