diff options
author | 2025-03-21 11:31:37 -0700 | |
---|---|---|
committer | 2025-03-21 11:31:37 -0700 | |
commit | c0b28c50549e343400b546a707ca9ea2b5ae8c9d (patch) | |
tree | 41fb89f9431599d9d75e80f8ed6fb6dfd02e6571 | |
parent | e751eaac2a1eec8e54185df4adea8ea5ea9ac6bc (diff) | |
parent | eee436fd1f720c1eb061f300f873f1d7ad84e98a (diff) |
Merge "Remove foreground power key code." into main
12 files changed, 20 insertions, 633 deletions
diff --git a/core/api/system-current.txt b/core/api/system-current.txt index 42c60b0ba0da..b92df4cf7884 100644 --- a/core/api/system-current.txt +++ b/core/api/system-current.txt @@ -18977,10 +18977,8 @@ package android.view { public static class WindowManager.LayoutParams extends android.view.ViewGroup.LayoutParams implements android.os.Parcelable { method public final long getUserActivityTimeout(); - method @FlaggedApi("com.android.hardware.input.override_power_key_behavior_in_focused_window") @RequiresPermission(android.Manifest.permission.OVERRIDE_SYSTEM_KEY_BEHAVIOR_IN_FOCUSED_WINDOW) public boolean isReceivePowerKeyDoublePressEnabled(); method public boolean isSystemApplicationOverlay(); method @FlaggedApi("android.companion.virtualdevice.flags.status_bar_and_insets") public void setInsetsParams(@NonNull java.util.List<android.view.WindowManager.InsetsParams>); - method @FlaggedApi("com.android.hardware.input.override_power_key_behavior_in_focused_window") @RequiresPermission(android.Manifest.permission.OVERRIDE_SYSTEM_KEY_BEHAVIOR_IN_FOCUSED_WINDOW) public void setReceivePowerKeyDoublePressEnabled(boolean); method @RequiresPermission(android.Manifest.permission.SYSTEM_APPLICATION_OVERLAY) public void setSystemApplicationOverlay(boolean); method public final void setUserActivityTimeout(long); field @RequiresPermission(android.Manifest.permission.HIDE_NON_SYSTEM_OVERLAY_WINDOWS) public static final int SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS = 524288; // 0x80000 diff --git a/core/java/android/view/WindowManager.java b/core/java/android/view/WindowManager.java index 9d21f1aff0c3..1ba3a74b8b2b 100644 --- a/core/java/android/view/WindowManager.java +++ b/core/java/android/view/WindowManager.java @@ -80,9 +80,6 @@ import static android.view.WindowLayoutParamsProto.WINDOW_ANIMATIONS; import static android.view.WindowLayoutParamsProto.X; import static android.view.WindowLayoutParamsProto.Y; -import static com.android.hardware.input.Flags.FLAG_OVERRIDE_POWER_KEY_BEHAVIOR_IN_FOCUSED_WINDOW; -import static com.android.hardware.input.Flags.overridePowerKeyBehaviorInFocusedWindow; - import android.Manifest.permission; import android.annotation.CallbackExecutor; import android.annotation.FlaggedApi; @@ -4549,29 +4546,6 @@ public interface WindowManager extends ViewManager { public static final int INPUT_FEATURE_SENSITIVE_FOR_PRIVACY = 1 << 3; /** - * Input feature used to indicate that the system should send power key events to this - * window when it's in the foreground. The window can override the double press power key - * gesture behavior. - * - * A double press gesture is defined as two - * {@link KeyEvent.Callback#onKeyDown(int, KeyEvent)} events within a time span defined by - * {@link ViewConfiguration#getMultiPressTimeout()}. - * - * Note: While the window may receive all power key {@link KeyEvent}s, it can only - * override the double press gesture behavior. The system will perform default behavior for - * single, long-press and other multi-press gestures, regardless of if the app handles the - * key or not. - * - * To override the default behavior for double press, the app must return true for the - * second {@link KeyEvent.Callback#onKeyDown(int, KeyEvent)}. If the app returns false, the - * system behavior will be performed for double press. - * @hide - */ - @RequiresPermission(permission.OVERRIDE_SYSTEM_KEY_BEHAVIOR_IN_FOCUSED_WINDOW) - public static final int - INPUT_FEATURE_RECEIVE_POWER_KEY_DOUBLE_PRESS = 1 << 4; - - /** * An internal annotation for flags that can be specified to {@link #inputFeatures}. * * NOTE: These are not the same as {@link android.os.InputConfig} flags. @@ -4583,8 +4557,7 @@ public interface WindowManager extends ViewManager { INPUT_FEATURE_NO_INPUT_CHANNEL, INPUT_FEATURE_DISABLE_USER_ACTIVITY, INPUT_FEATURE_SPY, - INPUT_FEATURE_SENSITIVE_FOR_PRIVACY, - INPUT_FEATURE_RECEIVE_POWER_KEY_DOUBLE_PRESS + INPUT_FEATURE_SENSITIVE_FOR_PRIVACY }) public @interface InputFeatureFlags { } @@ -4874,44 +4847,6 @@ public interface WindowManager extends ViewManager { } /** - * Specifies if the system should send power key events to this window when it's in the - * foreground, with only the double tap gesture behavior being overrideable. - * - * @param enabled if true, the system should send power key events to this window when it's - * in the foreground, with only the power key double tap gesture being - * overrideable. - * @hide - */ - @SystemApi - @RequiresPermission(permission.OVERRIDE_SYSTEM_KEY_BEHAVIOR_IN_FOCUSED_WINDOW) - @FlaggedApi(FLAG_OVERRIDE_POWER_KEY_BEHAVIOR_IN_FOCUSED_WINDOW) - public void setReceivePowerKeyDoublePressEnabled(boolean enabled) { - if (enabled) { - inputFeatures - |= INPUT_FEATURE_RECEIVE_POWER_KEY_DOUBLE_PRESS; - } else { - inputFeatures - &= ~INPUT_FEATURE_RECEIVE_POWER_KEY_DOUBLE_PRESS; - } - } - - /** - * Returns whether or not the system should send power key events to this window when it's - * in the foreground, with only the double tap gesture being overrideable. - * - * @return if the system should send power key events to this window when it's in the - * foreground, with only the double tap gesture being overrideable. - * @hide - */ - @SystemApi - @RequiresPermission(permission.OVERRIDE_SYSTEM_KEY_BEHAVIOR_IN_FOCUSED_WINDOW) - @FlaggedApi(FLAG_OVERRIDE_POWER_KEY_BEHAVIOR_IN_FOCUSED_WINDOW) - public boolean isReceivePowerKeyDoublePressEnabled() { - return (inputFeatures - & INPUT_FEATURE_RECEIVE_POWER_KEY_DOUBLE_PRESS) != 0; - } - - /** * Specifies that the window should be considered a trusted system overlay. Trusted system * overlays are ignored when considering whether windows are obscured during input * dispatch. Requires the {@link android.Manifest.permission#INTERNAL_SYSTEM_WINDOW} @@ -6312,16 +6247,6 @@ public interface WindowManager extends ViewManager { inputFeatures &= ~INPUT_FEATURE_SPY; features.add("INPUT_FEATURE_SPY"); } - if (overridePowerKeyBehaviorInFocusedWindow()) { - if ((inputFeatures - & INPUT_FEATURE_RECEIVE_POWER_KEY_DOUBLE_PRESS) - != 0) { - inputFeatures - &= - ~INPUT_FEATURE_RECEIVE_POWER_KEY_DOUBLE_PRESS; - features.add("INPUT_FEATURE_RECEIVE_POWER_KEY_DOUBLE_PRESS"); - } - } if (inputFeatures != 0) { features.add(Integer.toHexString(inputFeatures)); } diff --git a/core/java/com/android/internal/policy/KeyInterceptionInfo.java b/core/java/com/android/internal/policy/KeyInterceptionInfo.java index fed8fe3b4cc0..b20f6d225b69 100644 --- a/core/java/com/android/internal/policy/KeyInterceptionInfo.java +++ b/core/java/com/android/internal/policy/KeyInterceptionInfo.java @@ -27,13 +27,11 @@ public class KeyInterceptionInfo { // Debug friendly name to help identify the window public final String windowTitle; public final int windowOwnerUid; - public final int inputFeaturesFlags; - public KeyInterceptionInfo(int type, int flags, String title, int uid, int inputFeaturesFlags) { + public KeyInterceptionInfo(int type, int flags, String title, int uid) { layoutParamsType = type; layoutParamsPrivateFlags = flags; windowTitle = title; windowOwnerUid = uid; - this.inputFeaturesFlags = inputFeaturesFlags; } } diff --git a/services/core/java/com/android/server/GestureLauncherService.java b/services/core/java/com/android/server/GestureLauncherService.java index 87222a60d82d..28258ae47a65 100644 --- a/services/core/java/com/android/server/GestureLauncherService.java +++ b/services/core/java/com/android/server/GestureLauncherService.java @@ -19,7 +19,6 @@ package com.android.server; import static android.service.quickaccesswallet.Flags.launchWalletOptionOnPowerDoubleTap; import static android.service.quickaccesswallet.Flags.launchWalletViaSysuiCallbacks; -import static com.android.hardware.input.Flags.overridePowerKeyBehaviorInFocusedWindow; import static com.android.internal.R.integer.config_defaultMinEmergencyGestureTapDurationMillis; import android.app.ActivityManager; @@ -635,46 +634,6 @@ public class GestureLauncherService extends SystemService { } /** - * Processes a power key event in GestureLauncherService without performing an action. This - * method is called on every KEYCODE_POWER ACTION_DOWN event and ensures that, even if - * KEYCODE_POWER events are passed to and handled by the app, the GestureLauncherService still - * keeps track of all running KEYCODE_POWER events for its gesture detection and relevant - * actions. - */ - public void processPowerKeyDown(KeyEvent event) { - if (mEmergencyGestureEnabled && mEmergencyGesturePowerButtonCooldownPeriodMs >= 0 - && event.getEventTime() - mLastEmergencyGestureTriggered - < mEmergencyGesturePowerButtonCooldownPeriodMs) { - return; - } - if (event.isLongPress()) { - return; - } - - final long powerTapInterval; - - synchronized (this) { - powerTapInterval = event.getEventTime() - mLastPowerDown; - mLastPowerDown = event.getEventTime(); - if (powerTapInterval >= POWER_SHORT_TAP_SEQUENCE_MAX_INTERVAL_MS) { - // Tap too slow, reset consecutive tap counts. - mFirstPowerDown = event.getEventTime(); - mPowerButtonConsecutiveTaps = 1; - mPowerButtonSlowConsecutiveTaps = 1; - } else if (powerTapInterval >= POWER_DOUBLE_TAP_MAX_TIME_MS) { - // Tap too slow for shortcuts - mFirstPowerDown = event.getEventTime(); - mPowerButtonConsecutiveTaps = 1; - mPowerButtonSlowConsecutiveTaps++; - } else if (!overridePowerKeyBehaviorInFocusedWindow() || powerTapInterval > 0) { - // Fast consecutive tap - mPowerButtonConsecutiveTaps++; - mPowerButtonSlowConsecutiveTaps++; - } - } - } - - /** * Attempts to intercept power key down event by detecting certain gesture patterns * * @param interactive true if the event's policy contains {@code FLAG_INTERACTIVE} @@ -721,7 +680,7 @@ public class GestureLauncherService extends SystemService { mFirstPowerDown = event.getEventTime(); mPowerButtonConsecutiveTaps = 1; mPowerButtonSlowConsecutiveTaps++; - } else if (powerTapInterval > 0) { + } else { // Fast consecutive tap mPowerButtonConsecutiveTaps++; mPowerButtonSlowConsecutiveTaps++; diff --git a/services/core/java/com/android/server/policy/PhoneWindowManager.java b/services/core/java/com/android/server/policy/PhoneWindowManager.java index 8cf0481b1dc3..e8843ac214ec 100644 --- a/services/core/java/com/android/server/policy/PhoneWindowManager.java +++ b/services/core/java/com/android/server/policy/PhoneWindowManager.java @@ -520,32 +520,6 @@ public class PhoneWindowManager implements WindowManagerPolicy { private WindowWakeUpPolicy mWindowWakeUpPolicy; - /** - * The three variables below are used for custom power key gesture detection in - * PhoneWindowManager. They are used to detect when the power button has been double pressed - * and, when it does happen, makes the behavior overrideable by the app. - * - * We cannot use the {@link PowerKeyRule} for this because multi-press power gesture detection - * and behaviors are handled by {@link com.android.server.GestureLauncherService}, and the - * {@link PowerKeyRule} only handles single and long-presses of the power button. As a result, - * overriding the double tap behavior requires custom gesture detection here that mimics the - * logic in {@link com.android.server.GestureLauncherService}. - * - * Long-term, it would be beneficial to move all power gesture detection to - * {@link PowerKeyRule} so that this custom logic isn't required. - */ - // Time of last power down event. - private long mLastPowerDown; - - // Number of power button events consecutively triggered (within a specific timeout threshold). - private int mPowerButtonConsecutiveTaps = 0; - - // Whether a double tap of the power button has been detected. - volatile boolean mDoubleTapPowerDetected; - - // Runnable that is queued on a delay when the first power keyDown event is sent to the app. - private Runnable mPowerKeyDelayedRunnable = null; - boolean mSafeMode; // Whether to allow dock apps with METADATA_DOCK_HOME to temporarily take over the Home key. @@ -1135,10 +1109,6 @@ public class PhoneWindowManager implements WindowManagerPolicy { || handledByPowerManager || isKeyGestureTriggered || mKeyCombinationManager.isPowerKeyIntercepted(); - if (overridePowerKeyBehaviorInFocusedWindow()) { - mPowerKeyHandled |= mDoubleTapPowerDetected; - } - if (!mPowerKeyHandled) { if (!interactive) { wakeUpFromWakeKey(event); @@ -2785,18 +2755,7 @@ public class PhoneWindowManager implements WindowManagerPolicy { if (mShouldEarlyShortPressOnPower) { return; } - // TODO(b/380433365): Remove deferring single power press action when refactoring. - if (overridePowerKeyBehaviorInFocusedWindow()) { - mDeferredKeyActionExecutor.cancelQueuedAction(KEYCODE_POWER); - mDeferredKeyActionExecutor.queueKeyAction( - KEYCODE_POWER, - downTime, - () -> { - powerPress(downTime, 1 /*count*/, displayId); - }); - } else { - powerPress(downTime, 1 /*count*/, displayId); - } + powerPress(downTime, 1 /*count*/, displayId); } @Override @@ -2827,17 +2786,7 @@ public class PhoneWindowManager implements WindowManagerPolicy { @Override void onMultiPress(long downTime, int count, int displayId) { - if (overridePowerKeyBehaviorInFocusedWindow()) { - mDeferredKeyActionExecutor.cancelQueuedAction(KEYCODE_POWER); - mDeferredKeyActionExecutor.queueKeyAction( - KEYCODE_POWER, - downTime, - () -> { - powerPress(downTime, count, displayId); - }); - } else { - powerPress(downTime, count, displayId); - } + powerPress(downTime, count, displayId); } @Override @@ -3614,12 +3563,6 @@ public class PhoneWindowManager implements WindowManagerPolicy { } } - if (overridePowerKeyBehaviorInFocusedWindow() && event.getKeyCode() == KEYCODE_POWER - && event.getAction() == KeyEvent.ACTION_UP - && mDoubleTapPowerDetected) { - mDoubleTapPowerDetected = false; - } - return needToConsumeKey ? keyConsumed : keyNotConsumed; } @@ -4117,8 +4060,6 @@ public class PhoneWindowManager implements WindowManagerPolicy { sendSystemKeyToStatusBarAsync(event); return true; } - case KeyEvent.KEYCODE_POWER: - return interceptPowerKeyBeforeDispatching(focusedToken, event); case KeyEvent.KEYCODE_SCREENSHOT: if (firstDown) { interceptScreenshotChord(SCREENSHOT_KEY_OTHER, 0 /*pressDelay*/); @@ -4174,8 +4115,6 @@ public class PhoneWindowManager implements WindowManagerPolicy { sendSystemKeyToStatusBarAsync(event); return true; } - case KeyEvent.KEYCODE_POWER: - return interceptPowerKeyBeforeDispatching(focusedToken, event); } if (isValidGlobalKey(keyCode) && mGlobalKeyManager.handleGlobalKey(mContext, keyCode, event)) { @@ -4193,90 +4132,6 @@ public class PhoneWindowManager implements WindowManagerPolicy { return (metaState & KeyEvent.META_META_ON) != 0; } - /** - * Called by interceptKeyBeforeDispatching to handle interception logic for KEYCODE_POWER - * KeyEvents. - * - * @return true if intercepting the key, false if sending to app. - */ - private boolean interceptPowerKeyBeforeDispatching(IBinder focusedToken, KeyEvent event) { - if (!overridePowerKeyBehaviorInFocusedWindow()) { - //Flag disabled: intercept the power key and do not send to app. - return true; - } - if (event.getKeyCode() != KEYCODE_POWER) { - Log.wtf(TAG, "interceptPowerKeyBeforeDispatching received a non-power KeyEvent " - + "with key code: " + event.getKeyCode()); - return false; - } - - // Intercept keys (don't send to app) for 3x, 4x, 5x gestures) - if (mPowerButtonConsecutiveTaps > DOUBLE_POWER_TAP_COUNT_THRESHOLD) { - setDeferredKeyActionsExecutableAsync(KEYCODE_POWER, event.getDownTime()); - return true; - } - - // UP key; just reuse the original decision. - if (event.getAction() == KeyEvent.ACTION_UP) { - final Set<Integer> consumedKeys = mConsumedKeysForDevice.get(event.getDeviceId()); - return consumedKeys != null - && consumedKeys.contains(event.getKeyCode()); - } - - KeyInterceptionInfo info = - mWindowManagerInternal.getKeyInterceptionInfoFromToken(focusedToken); - - if (info == null || !mButtonOverridePermissionChecker.canWindowOverridePowerKey(mContext, - info.windowOwnerUid, info.inputFeaturesFlags)) { - // The focused window does not have the permission to override power key behavior. - if (DEBUG_INPUT) { - String interceptReason = ""; - if (info == null) { - interceptReason = "Window is null"; - } else if (!mButtonOverridePermissionChecker.canAppOverrideSystemKey(mContext, - info.windowOwnerUid)) { - interceptReason = "Application does not have " - + "OVERRIDE_SYSTEM_KEY_BEHAVIOR_IN_FOCUSED_WINDOW permission"; - } else { - interceptReason = "Window does not have inputFeatureFlag set"; - } - - Log.d(TAG, TextUtils.formatSimple("Intercepting KEYCODE_POWER event. action=%d, " - + "eventTime=%d to window=%s. interceptReason=%s. " - + "mDoubleTapPowerDetected=%b", - event.getAction(), event.getEventTime(), (info != null) - ? info.windowTitle : "null", interceptReason, - mDoubleTapPowerDetected)); - } - // Intercept the key (i.e. do not send to app) - setDeferredKeyActionsExecutableAsync(KEYCODE_POWER, event.getDownTime()); - return true; - } - - if (DEBUG_INPUT) { - Log.d(TAG, TextUtils.formatSimple("Sending KEYCODE_POWER to app. action=%d, " - + "eventTime=%d to window=%s. mDoubleTapPowerDetected=%b", - event.getAction(), event.getEventTime(), info.windowTitle, - mDoubleTapPowerDetected)); - } - - if (!mDoubleTapPowerDetected) { - //Single press: post a delayed runnable for the single press power action that will be - // called if it's not cancelled by a double press. - final var downTime = event.getDownTime(); - mPowerKeyDelayedRunnable = () -> - setDeferredKeyActionsExecutableAsync(KEYCODE_POWER, downTime); - mHandler.postDelayed(mPowerKeyDelayedRunnable, POWER_MULTI_PRESS_TIMEOUT_MILLIS); - } else if (mPowerKeyDelayedRunnable != null) { - //Double press detected: cancel the single press runnable. - mHandler.removeCallbacks(mPowerKeyDelayedRunnable); - mPowerKeyDelayedRunnable = null; - } - - // Focused window has permission. Send to app. - return false; - } - @SuppressLint("MissingPermission") private void initKeyGestures() { if (!useKeyGestureEventHandler()) { @@ -4764,11 +4619,6 @@ public class PhoneWindowManager implements WindowManagerPolicy { return true; } - if (overridePowerKeyBehaviorInFocusedWindow() && keyCode == KEYCODE_POWER) { - handleUnhandledSystemKey(event); - return true; - } - if (useKeyGestureEventHandler()) { return false; } @@ -5595,12 +5445,8 @@ public class PhoneWindowManager implements WindowManagerPolicy { KeyEvent.actionToString(event.getAction()), mPowerKeyHandled ? 1 : 0, mSingleKeyGestureDetector.getKeyPressCounter(KeyEvent.KEYCODE_POWER)); - if (overridePowerKeyBehaviorInFocusedWindow()) { - result |= ACTION_PASS_TO_USER; - } else { - // Any activity on the power button stops the accessibility shortcut - result &= ~ACTION_PASS_TO_USER; - } + // Any activity on the power button stops the accessibility shortcut + result &= ~ACTION_PASS_TO_USER; isWakeKey = false; // wake-up will be handled separately if (down) { interceptPowerKeyDown(event, interactiveAndAwake, isKeyGestureTriggered); @@ -5862,35 +5708,6 @@ public class PhoneWindowManager implements WindowManagerPolicy { } if (event.getKeyCode() == KEYCODE_POWER && event.getAction() == KeyEvent.ACTION_DOWN) { - if (overridePowerKeyBehaviorInFocusedWindow()) { - if (event.getRepeatCount() > 0 && !mHasFeatureWatch) { - return; - } - if (mGestureLauncherService != null) { - mGestureLauncherService.processPowerKeyDown(event); - } - - if (detectDoubleTapPower(event)) { - mDoubleTapPowerDetected = true; - - // Copy of the event for handler in case the original event gets recycled. - KeyEvent eventCopy = KeyEvent.obtain(event); - mDeferredKeyActionExecutor.queueKeyAction( - KeyEvent.KEYCODE_POWER, - eventCopy.getEventTime(), - () -> { - if (!handleCameraGesture(eventCopy, interactive)) { - mSingleKeyGestureDetector.interceptKey( - eventCopy, interactive, defaultDisplayOn); - } else { - mSingleKeyGestureDetector.reset(); - } - eventCopy.recycle(); - }); - return; - } - } - mPowerKeyHandled = handleCameraGesture(event, interactive); if (mPowerKeyHandled) { // handled by camera gesture. @@ -5902,26 +5719,6 @@ public class PhoneWindowManager implements WindowManagerPolicy { mSingleKeyGestureDetector.interceptKey(event, interactive, defaultDisplayOn); } - private boolean detectDoubleTapPower(KeyEvent event) { - //Watches use the SingleKeyGestureDetector for detecting multi-press gestures. - if (mHasFeatureWatch || event.getKeyCode() != KEYCODE_POWER - || event.getAction() != KeyEvent.ACTION_DOWN || event.getRepeatCount() != 0) { - return false; - } - - final long powerTapInterval = event.getEventTime() - mLastPowerDown; - mLastPowerDown = event.getEventTime(); - if (powerTapInterval >= POWER_MULTI_PRESS_TIMEOUT_MILLIS) { - // Tap too slow for double press - mPowerButtonConsecutiveTaps = 1; - } else { - mPowerButtonConsecutiveTaps++; - } - - return powerTapInterval < POWER_MULTI_PRESS_TIMEOUT_MILLIS - && mPowerButtonConsecutiveTaps == DOUBLE_POWER_TAP_COUNT_THRESHOLD; - } - // The camera gesture will be detected by GestureLauncherService. private boolean handleCameraGesture(KeyEvent event, boolean interactive) { // camera gesture. @@ -7779,12 +7576,6 @@ public class PhoneWindowManager implements WindowManagerPolicy { null) == PERMISSION_GRANTED; } - - boolean canWindowOverridePowerKey(Context context, int uid, int inputFeaturesFlags) { - return canAppOverrideSystemKey(context, uid) - && (inputFeaturesFlags & WindowManager.LayoutParams - .INPUT_FEATURE_RECEIVE_POWER_KEY_DOUBLE_PRESS) != 0; - } } private int getTargetDisplayIdForKeyEvent(KeyEvent event) { diff --git a/services/core/java/com/android/server/wm/WindowManagerService.java b/services/core/java/com/android/server/wm/WindowManagerService.java index 00a437cc31f9..c23dabcd2a48 100644 --- a/services/core/java/com/android/server/wm/WindowManagerService.java +++ b/services/core/java/com/android/server/wm/WindowManagerService.java @@ -67,7 +67,6 @@ import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER; import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED; import static android.view.WindowManager.LayoutParams.FLAG_SLIPPERY; import static android.view.WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL; -import static android.view.WindowManager.LayoutParams.INPUT_FEATURE_RECEIVE_POWER_KEY_DOUBLE_PRESS; import static android.view.WindowManager.LayoutParams.INPUT_FEATURE_SENSITIVE_FOR_PRIVACY; import static android.view.WindowManager.LayoutParams.INPUT_FEATURE_SPY; import static android.view.WindowManager.LayoutParams.INVALID_WINDOW_TYPE; @@ -99,7 +98,6 @@ import static android.view.displayhash.DisplayHashResultCallback.DISPLAY_HASH_ER import static android.view.flags.Flags.sensitiveContentAppProtection; import static android.window.WindowProviderService.isWindowProviderService; -import static com.android.hardware.input.Flags.overridePowerKeyBehaviorInFocusedWindow; import static com.android.internal.protolog.WmProtoLogGroups.WM_DEBUG_ADD_REMOVE; import static com.android.internal.protolog.WmProtoLogGroups.WM_DEBUG_ANIM; import static com.android.internal.protolog.WmProtoLogGroups.WM_DEBUG_BOOT; @@ -9241,25 +9239,6 @@ public class WindowManagerService extends IWindowManager.Stub + "' because it isn't a trusted overlay"); return inputFeatures & ~INPUT_FEATURE_SENSITIVE_FOR_PRIVACY; } - - // You need OVERRIDE_SYSTEM_KEY_BEHAVIOR_IN_FOCUSED_WINDOW permission to be able - // to set INPUT_FEATURE_RECEIVE_POWER_KEY_DOUBLE_PRESS. - if (overridePowerKeyBehaviorInFocusedWindow() - && (inputFeatures - & INPUT_FEATURE_RECEIVE_POWER_KEY_DOUBLE_PRESS) - != 0) { - final int powerPermissionResult = - mContext.checkPermission( - permission.OVERRIDE_SYSTEM_KEY_BEHAVIOR_IN_FOCUSED_WINDOW, - callingPid, - callingUid); - if (powerPermissionResult != PackageManager.PERMISSION_GRANTED) { - throw new IllegalArgumentException( - "Cannot use INPUT_FEATURE_RECEIVE_POWER_KEY_DOUBLE_PRESS from" + windowName - + " because it doesn't have the" - + " OVERRIDE_SYSTEM_KEY_BEHAVIOR_IN_FOCUSED_WINDOW permission"); - } - } return inputFeatures; } diff --git a/services/core/java/com/android/server/wm/WindowState.java b/services/core/java/com/android/server/wm/WindowState.java index a03b765cae6a..0bd27d10559c 100644 --- a/services/core/java/com/android/server/wm/WindowState.java +++ b/services/core/java/com/android/server/wm/WindowState.java @@ -5507,10 +5507,9 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP || mKeyInterceptionInfo.layoutParamsPrivateFlags != mAttrs.privateFlags || mKeyInterceptionInfo.layoutParamsType != mAttrs.type || mKeyInterceptionInfo.windowTitle != getWindowTag() - || mKeyInterceptionInfo.windowOwnerUid != getOwningUid() - || mKeyInterceptionInfo.inputFeaturesFlags != mAttrs.inputFeatures) { + || mKeyInterceptionInfo.windowOwnerUid != getOwningUid()) { mKeyInterceptionInfo = new KeyInterceptionInfo(mAttrs.type, mAttrs.privateFlags, - getWindowTag().toString(), getOwningUid(), mAttrs.inputFeatures); + getWindowTag().toString(), getOwningUid()); } return mKeyInterceptionInfo; } diff --git a/services/tests/servicestests/src/com/android/server/GestureLauncherServiceTest.java b/services/tests/servicestests/src/com/android/server/GestureLauncherServiceTest.java index cc0d5e4710d2..73e5f8232faf 100644 --- a/services/tests/servicestests/src/com/android/server/GestureLauncherServiceTest.java +++ b/services/tests/servicestests/src/com/android/server/GestureLauncherServiceTest.java @@ -1787,46 +1787,6 @@ public class GestureLauncherServiceTest { } /** - * If processPowerKeyDown is called instead of interceptPowerKeyDown (meaning the double tap - * gesture isn't performed), the emergency gesture is still launched. - */ - @Test - public void testProcessPowerKeyDown_fiveInboundPresses_emergencyGestureLaunches() { - enableCameraGesture(); - enableEmergencyGesture(); - - // First event - long eventTime = INITIAL_EVENT_TIME_MILLIS; - sendPowerKeyDownToGestureLauncherServiceAndAssertValues(eventTime, false, false); - - //Second event; call processPowerKeyDown without calling interceptPowerKeyDown - final long interval = POWER_DOUBLE_TAP_MAX_TIME_MS - 1; - eventTime += interval; - KeyEvent keyEvent = - new KeyEvent( - IGNORED_DOWN_TIME, eventTime, IGNORED_ACTION, IGNORED_CODE, IGNORED_REPEAT); - mGestureLauncherService.processPowerKeyDown(keyEvent); - - verify(mMetricsLogger, never()) - .action(eq(MetricsEvent.ACTION_DOUBLE_TAP_POWER_CAMERA_GESTURE), anyInt()); - verify(mUiEventLogger, never()).log(any()); - - // Presses 3 and 4 should not trigger any gesture - for (int i = 0; i < 2; i++) { - eventTime += interval; - sendPowerKeyDownToGestureLauncherServiceAndAssertValues(eventTime, true, false); - } - - // Fifth button press should still trigger the emergency flow - eventTime += interval; - sendPowerKeyDownToGestureLauncherServiceAndAssertValues(eventTime, true, true); - - verify(mUiEventLogger, times(1)) - .log(GestureLauncherService.GestureLauncherEvent.GESTURE_EMERGENCY_TAP_POWER); - verify(mStatusBarManagerInternal).onEmergencyActionLaunchGestureDetected(); - } - - /** * Helper method to trigger emergency gesture by pressing button for 5 times. * * @return last event time. diff --git a/services/tests/wmtests/src/com/android/server/policy/PowerKeyGestureTests.java b/services/tests/wmtests/src/com/android/server/policy/PowerKeyGestureTests.java index 53e82bad818d..8d717bc19e72 100644 --- a/services/tests/wmtests/src/com/android/server/policy/PowerKeyGestureTests.java +++ b/services/tests/wmtests/src/com/android/server/policy/PowerKeyGestureTests.java @@ -18,16 +18,12 @@ package com.android.server.policy; import static android.view.KeyEvent.KEYCODE_POWER; import static android.view.KeyEvent.KEYCODE_VOLUME_UP; -import static com.android.hardware.input.Flags.FLAG_OVERRIDE_POWER_KEY_BEHAVIOR_IN_FOCUSED_WINDOW; 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.POWER_MULTI_PRESS_TIMEOUT_MILLIS; 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.junit.Assert.assertEquals; - -import android.platform.test.annotations.EnableFlags; import android.platform.test.annotations.Presubmit; import android.provider.Settings; import android.view.Display; @@ -153,143 +149,4 @@ public class PowerKeyGestureTests extends ShortcutKeyTestBase { sendKey(KEYCODE_POWER); mPhoneWindowManager.assertNoPowerSleep(); } - - - /** - * Double press of power when the window handles the power key events. The - * system double power gesture launch should not be performed. - */ - @Test - @EnableFlags(FLAG_OVERRIDE_POWER_KEY_BEHAVIOR_IN_FOCUSED_WINDOW) - public void testPowerDoublePress_windowHasOverridePermissionAndKeysHandled() { - mPhoneWindowManager.overrideCanWindowOverridePowerKey(true); - setDispatchedKeyHandler(keyEvent -> true); - - sendKey(KEYCODE_POWER); - sendKey(KEYCODE_POWER); - - mPhoneWindowManager.assertDidNotLockAfterAppTransitionFinished(); - - mPhoneWindowManager.assertNoDoublePowerLaunch(); - } - - /** - * Double press of power when the window doesn't handle the power key events. - * The system default gesture launch should be performed and the app should receive both events. - */ - @Test - @EnableFlags(FLAG_OVERRIDE_POWER_KEY_BEHAVIOR_IN_FOCUSED_WINDOW) - public void testPowerDoublePress_windowHasOverridePermissionAndKeysUnHandled() { - mPhoneWindowManager.overrideCanWindowOverridePowerKey(true); - setDispatchedKeyHandler(keyEvent -> false); - - sendKey(KEYCODE_POWER); - sendKey(KEYCODE_POWER); - - mPhoneWindowManager.assertDidNotLockAfterAppTransitionFinished(); - mPhoneWindowManager.assertDoublePowerLaunch(); - assertEquals(getDownKeysDispatched(), 2); - assertEquals(getUpKeysDispatched(), 2); - } - - /** - * Triple press of power when the window handles the power key double press gesture. - * The system default gesture launch should not be performed, and the app only receives the - * first two presses. - */ - @Test - @EnableFlags(FLAG_OVERRIDE_POWER_KEY_BEHAVIOR_IN_FOCUSED_WINDOW) - public void testPowerTriplePress_windowHasOverridePermissionAndKeysHandled() { - mPhoneWindowManager.overrideCanWindowOverridePowerKey(true); - setDispatchedKeyHandler(keyEvent -> true); - - sendKey(KEYCODE_POWER); - sendKey(KEYCODE_POWER); - sendKey(KEYCODE_POWER); - - mPhoneWindowManager.assertDidNotLockAfterAppTransitionFinished(); - mPhoneWindowManager.assertNoDoublePowerLaunch(); - assertEquals(getDownKeysDispatched(), 2); - assertEquals(getUpKeysDispatched(), 2); - } - - /** - * Tests a single press, followed by a double press when the window can handle the power key. - * The app should receive all 3 events. - */ - @Test - @EnableFlags(FLAG_OVERRIDE_POWER_KEY_BEHAVIOR_IN_FOCUSED_WINDOW) - public void testPowerTriplePressWithDelay_windowHasOverridePermissionAndKeysHandled() { - mPhoneWindowManager.overrideCanWindowOverridePowerKey(true); - setDispatchedKeyHandler(keyEvent -> true); - - sendKey(KEYCODE_POWER); - mPhoneWindowManager.moveTimeForward(POWER_MULTI_PRESS_TIMEOUT_MILLIS); - sendKey(KEYCODE_POWER); - sendKey(KEYCODE_POWER); - - mPhoneWindowManager.assertNoDoublePowerLaunch(); - assertEquals(getDownKeysDispatched(), 3); - assertEquals(getUpKeysDispatched(), 3); - } - - /** - * Tests single press when window doesn't handle the power key. Phone should go to sleep. - */ - @Test - @EnableFlags(FLAG_OVERRIDE_POWER_KEY_BEHAVIOR_IN_FOCUSED_WINDOW) - public void testPowerSinglePress_windowHasOverridePermissionAndKeyUnhandledByApp() { - mPhoneWindowManager.overrideCanWindowOverridePowerKey(true); - setDispatchedKeyHandler(keyEvent -> false); - mPhoneWindowManager.overrideShortPressOnPower(SHORT_PRESS_POWER_GO_TO_SLEEP); - - sendKey(KEYCODE_POWER); - - mPhoneWindowManager.assertPowerSleep(); - } - - /** - * Tests single press when the window handles the power key. Phone should go to sleep after a - * delay of {POWER_MULTI_PRESS_TIMEOUT_MILLIS} - */ - @Test - @EnableFlags(FLAG_OVERRIDE_POWER_KEY_BEHAVIOR_IN_FOCUSED_WINDOW) - public void testPowerSinglePress_windowHasOverridePermissionAndKeyHandledByApp() { - mPhoneWindowManager.overrideCanWindowOverridePowerKey(true); - setDispatchedKeyHandler(keyEvent -> true); - mPhoneWindowManager.overrideDisplayState(Display.STATE_ON); - mPhoneWindowManager.overrideShortPressOnPower(SHORT_PRESS_POWER_GO_TO_SLEEP); - - sendKey(KEYCODE_POWER); - - mPhoneWindowManager.moveTimeForward(POWER_MULTI_PRESS_TIMEOUT_MILLIS); - - mPhoneWindowManager.assertPowerSleep(); - } - - - /** - * Tests 5x press when the window handles the power key. Emergency gesture should still be - * launched. - */ - @Test - @EnableFlags(FLAG_OVERRIDE_POWER_KEY_BEHAVIOR_IN_FOCUSED_WINDOW) - public void testPowerFiveTimesPress_windowHasOverridePermissionAndKeyHandledByApp() { - mPhoneWindowManager.overrideCanWindowOverridePowerKey(true); - setDispatchedKeyHandler(keyEvent -> true); - mPhoneWindowManager.overrideDisplayState(Display.STATE_ON); - mPhoneWindowManager.overrideShortPressOnPower(SHORT_PRESS_POWER_GO_TO_SLEEP); - - int minEmergencyGestureDurationMillis = mContext.getResources().getInteger( - com.android.internal.R.integer.config_defaultMinEmergencyGestureTapDurationMillis); - int durationMillis = minEmergencyGestureDurationMillis / 4; - for (int i = 0; i < 5; ++i) { - sendKey(KEYCODE_POWER); - mPhoneWindowManager.moveTimeForward(durationMillis); - } - - mPhoneWindowManager.assertEmergencyLaunch(); - assertEquals(getDownKeysDispatched(), 2); - assertEquals(getUpKeysDispatched(), 2); - } } diff --git a/services/tests/wmtests/src/com/android/server/policy/TestPhoneWindowManager.java b/services/tests/wmtests/src/com/android/server/policy/TestPhoneWindowManager.java index 7059c41898f3..2097d15658a6 100644 --- a/services/tests/wmtests/src/com/android/server/policy/TestPhoneWindowManager.java +++ b/services/tests/wmtests/src/com/android/server/policy/TestPhoneWindowManager.java @@ -37,7 +37,6 @@ import static com.android.dx.mockito.inline.extended.ExtendedMockito.spy; import static com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn; import static com.android.dx.mockito.inline.extended.ExtendedMockito.times; import static com.android.dx.mockito.inline.extended.ExtendedMockito.verify; -import static com.android.hardware.input.Flags.overridePowerKeyBehaviorInFocusedWindow; 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_VOICE_ASSIST; @@ -210,8 +209,6 @@ class TestPhoneWindowManager { private int mKeyEventPolicyFlags = FLAG_INTERACTIVE; - private int mProcessPowerKeyDownCount = 0; - private class TestTalkbackShortcutController extends TalkbackShortcutController { TestTalkbackShortcutController(Context context) { super(context); @@ -424,7 +421,7 @@ class TestPhoneWindowManager { doNothing().when(mContext).startActivityAsUser(any(), any()); doNothing().when(mContext).startActivityAsUser(any(), any(), any()); - KeyInterceptionInfo interceptionInfo = new KeyInterceptionInfo(0, 0, null, 0, 0); + KeyInterceptionInfo interceptionInfo = new KeyInterceptionInfo(0, 0, null, 0); doReturn(interceptionInfo) .when(mWindowManagerInternal).getKeyInterceptionInfoFromToken(any()); @@ -442,9 +439,6 @@ class TestPhoneWindowManager { eq(TEST_BROWSER_ROLE_PACKAGE_NAME)); doReturn(mSmsIntent).when(mPackageManager).getLaunchIntentForPackage( eq(TEST_SMS_ROLE_PACKAGE_NAME)); - mProcessPowerKeyDownCount = 0; - captureProcessPowerKeyDownCount(); - Mockito.reset(mContext); } @@ -715,12 +709,6 @@ class TestPhoneWindowManager { .when(mButtonOverridePermissionChecker).canAppOverrideSystemKey(any(), anyInt()); } - void overrideCanWindowOverridePowerKey(boolean granted) { - doReturn(granted) - .when(mButtonOverridePermissionChecker).canWindowOverridePowerKey(any(), anyInt(), - anyInt()); - } - void overrideKeyEventPolicyFlags(int flags) { mKeyEventPolicyFlags = flags; } @@ -800,10 +788,6 @@ class TestPhoneWindowManager { verify(mGestureLauncherService, atMost(4)) .interceptPowerKeyDown(any(), anyBoolean(), valueCaptor.capture()); - if (overridePowerKeyBehaviorInFocusedWindow()) { - assertTrue(mProcessPowerKeyDownCount >= 2 && mProcessPowerKeyDownCount <= 4); - } - List<Boolean> capturedValues = valueCaptor.getAllValues().stream() .map(mutableBoolean -> mutableBoolean.value) .toList(); @@ -832,10 +816,6 @@ class TestPhoneWindowManager { verify(mGestureLauncherService, atLeast(1)) .interceptPowerKeyDown(any(), anyBoolean(), valueCaptor.capture()); - if (overridePowerKeyBehaviorInFocusedWindow()) { - assertEquals(mProcessPowerKeyDownCount, 5); - } - List<Boolean> capturedValues = valueCaptor.getAllValues().stream() .map(mutableBoolean -> mutableBoolean.value) .toList(); @@ -1063,12 +1043,4 @@ class TestPhoneWindowManager { verify(mContext, never()).startActivityAsUser(any(), any(), any()); verify(mContext, never()).startActivityAsUser(any(), any()); } - - private void captureProcessPowerKeyDownCount() { - doAnswer((Answer<Void>) invocation -> { - invocation.callRealMethod(); - mProcessPowerKeyDownCount++; - return null; - }).when(mGestureLauncherService).processPowerKeyDown(any()); - } } diff --git a/services/tests/wmtests/src/com/android/server/wm/WindowManagerServiceTests.java b/services/tests/wmtests/src/com/android/server/wm/WindowManagerServiceTests.java index 5427dc22e700..795273d47230 100644 --- a/services/tests/wmtests/src/com/android/server/wm/WindowManagerServiceTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/WindowManagerServiceTests.java @@ -29,7 +29,6 @@ import static android.view.Display.FLAG_OWN_FOCUS; import static android.view.Display.INVALID_DISPLAY; import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; import static android.view.WindowManager.LayoutParams.FLAG_SECURE; -import static android.view.WindowManager.LayoutParams.INPUT_FEATURE_RECEIVE_POWER_KEY_DOUBLE_PRESS; import static android.view.WindowManager.LayoutParams.INPUT_FEATURE_SENSITIVE_FOR_PRIVACY; import static android.view.WindowManager.LayoutParams.INPUT_FEATURE_SPY; import static android.view.WindowManager.LayoutParams.INVALID_WINDOW_TYPE; @@ -49,7 +48,6 @@ import static com.android.dx.mockito.inline.extended.ExtendedMockito.doNothing; import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn; import static com.android.dx.mockito.inline.extended.ExtendedMockito.never; import static com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn; -import static com.android.hardware.input.Flags.FLAG_OVERRIDE_POWER_KEY_BEHAVIOR_IN_FOCUSED_WINDOW; import static com.android.server.wm.AppCompatConfiguration.LETTERBOX_BACKGROUND_APP_COLOR_BACKGROUND; import static com.android.server.wm.AppCompatConfiguration.LETTERBOX_BACKGROUND_APP_COLOR_BACKGROUND_FLOATING; import static com.android.server.wm.AppCompatConfiguration.LETTERBOX_BACKGROUND_SOLID_COLOR; @@ -1154,53 +1152,6 @@ public class WindowManagerServiceTests extends WindowTestsBase { } @Test - @RequiresFlagsEnabled(FLAG_OVERRIDE_POWER_KEY_BEHAVIOR_IN_FOCUSED_WINDOW) - public void testUpdateInputChannel_sanitizeWithoutPermission_ThrowsError() { - final Session session = mock(Session.class); - final int callingUid = Process.FIRST_APPLICATION_UID; - final int callingPid = 1234; - final SurfaceControl surfaceControl = mock(SurfaceControl.class); - final IBinder window = new Binder(); - final InputTransferToken inputTransferToken = mock(InputTransferToken.class); - - - final InputChannel inputChannel = new InputChannel(); - - assertThrows(IllegalArgumentException.class, () -> - mWm.grantInputChannel(session, callingUid, callingPid, DEFAULT_DISPLAY, - surfaceControl, window, null /* hostInputToken */, FLAG_NOT_FOCUSABLE, - 0 /* privateFlags */, - INPUT_FEATURE_RECEIVE_POWER_KEY_DOUBLE_PRESS, - TYPE_APPLICATION, null /* windowToken */, inputTransferToken, - "TestInputChannel", inputChannel)); - } - - - @Test - @RequiresFlagsEnabled(FLAG_OVERRIDE_POWER_KEY_BEHAVIOR_IN_FOCUSED_WINDOW) - public void testUpdateInputChannel_sanitizeWithPermission_doesNotThrowError() { - final Session session = mock(Session.class); - final int callingUid = Process.FIRST_APPLICATION_UID; - final int callingPid = 1234; - final SurfaceControl surfaceControl = mock(SurfaceControl.class); - final IBinder window = new Binder(); - final InputTransferToken inputTransferToken = mock(InputTransferToken.class); - - doReturn(PackageManager.PERMISSION_GRANTED).when(mWm.mContext).checkPermission( - android.Manifest.permission.OVERRIDE_SYSTEM_KEY_BEHAVIOR_IN_FOCUSED_WINDOW, - callingPid, - callingUid); - - final InputChannel inputChannel = new InputChannel(); - - mWm.grantInputChannel(session, callingUid, callingPid, DEFAULT_DISPLAY, surfaceControl, - window, null /* hostInputToken */, FLAG_NOT_FOCUSABLE, 0 /* privateFlags */, - INPUT_FEATURE_RECEIVE_POWER_KEY_DOUBLE_PRESS, - TYPE_APPLICATION, null /* windowToken */, inputTransferToken, "TestInputChannel", - inputChannel); - } - - @Test public void testUpdateInputChannel_allowSpyWindowForInputMonitorPermission() { final Session session = mock(Session.class); final int callingUid = Process.SYSTEM_UID; diff --git a/tests/Input/src/com/android/server/input/InputManagerServiceTests.kt b/tests/Input/src/com/android/server/input/InputManagerServiceTests.kt index 4737d19acde1..1858b1da916b 100644 --- a/tests/Input/src/com/android/server/input/InputManagerServiceTests.kt +++ b/tests/Input/src/com/android/server/input/InputManagerServiceTests.kt @@ -714,18 +714,16 @@ class InputManagerServiceTests { ) } - val info = - KeyInterceptionInfo( - /* type = */ 0, - if (hasPrivateFlag) { - WindowManager.LayoutParams.PRIVATE_FLAG_ALLOW_ACTION_KEY_EVENTS - } else { - 0 - }, - "title", - /* uid = */ 0, - /* inputFeatureFlags = */ 0, - ) + val info = KeyInterceptionInfo( + /* type = */0, + if (hasPrivateFlag) { + WindowManager.LayoutParams.PRIVATE_FLAG_ALLOW_ACTION_KEY_EVENTS + } else { + 0 + }, + "title", + /* uid = */0 + ) whenever(windowManagerInternal.getKeyInterceptionInfoFromToken(any())).thenReturn(info) } } |