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

Commit 5728aca7 authored by Kevin Chyn's avatar Kevin Chyn
Browse files

Ignore focus change when in RDMV2

In RDMV2, if the device receives a pointer event outside of the
current focused display, the device should not change focus. This
is because the inner display is displaying only a system dialog, and
any interactions with the inner display should not take focus away
from whatever is on the main (outer) display.

In the case of rear camera selfie, changing focus causes the volume
buttons to no longer be sent to the camera app for the shutter action.

Fixes: 398500791
Flag: EXEMPT bugfix
Test: manual test
Test: atest WindowManagerServiceTests
Change-Id: I9eaa1d497d3abb84c1c32079dcb5ad84107a7bc8
parent fedfa791
Loading
Loading
Loading
Loading
+32 −0
Original line number Diff line number Diff line
@@ -199,6 +199,8 @@ import android.graphics.Rect;
import android.graphics.Region;
import android.hardware.configstore.V1_0.OptionalBool;
import android.hardware.configstore.V1_1.ISurfaceFlingerConfigs;
import android.hardware.devicestate.DeviceState;
import android.hardware.devicestate.DeviceStateManager;
import android.hardware.display.DisplayManager;
import android.hardware.display.DisplayManagerInternal;
import android.hardware.input.InputSettings;
@@ -1034,6 +1036,21 @@ public class WindowManagerService extends IWindowManager.Stub
    PowerManager mPowerManager;
    PowerManagerInternal mPowerManagerInternal;

    private DeviceStateManager mDeviceStateManager;
    private DeviceStateCallback mDeviceStateCallback;
    private class DeviceStateCallback implements DeviceStateManager.DeviceStateCallback {
        private DeviceState mCurrentDeviceState;
        @Override
        public void onDeviceStateChanged(@NonNull DeviceState state) {
            mCurrentDeviceState = state;
        }

        boolean isInRearDisplayOuterDefaultState() {
            return mCurrentDeviceState != null && mCurrentDeviceState
                    .hasProperties(DeviceState.PROPERTY_FEATURE_REAR_DISPLAY_OUTER_DEFAULT);
        }
    }

    private float mWindowAnimationScaleSetting = 1.0f;
    private float mTransitionAnimationScaleSetting = 1.0f;
    private float mAnimatorDurationScaleSetting = 1.0f;
@@ -1321,6 +1338,10 @@ public class WindowManagerService extends IWindowManager.Stub
        mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
        mPowerManagerInternal = LocalServices.getService(PowerManagerInternal.class);

        mDeviceStateManager = context.getSystemService(DeviceStateManager.class);
        mDeviceStateCallback = new DeviceStateCallback();
        mDeviceStateManager.registerCallback(new HandlerExecutor(mH), mDeviceStateCallback);

        if (mPowerManagerInternal != null) {
            mPowerManagerInternal.registerLowPowerModeObserver(
                    new PowerManagerInternal.LowPowerModeListener() {
@@ -8975,6 +8996,17 @@ public class WindowManagerService extends IWindowManager.Stub
            }
        }

        if (mDeviceStateCallback.isInRearDisplayOuterDefaultState()) {
            final Display[] rearDisplays = mDisplayManager
                    .getDisplays(DisplayManager.DISPLAY_CATEGORY_REAR);
            if (rearDisplays.length > 0 && rearDisplays[0].getDisplayId() == t.getDisplayId()) {
                // Do not change display focus to the inner display if we're in this mode. Note that
                // in this mode, the inner display is configured as a rear display.
                Slog.w(TAG, "Ignoring focus change because device is in RDM.");
                return;
            }
        }

        clearPointerDownOutsideFocusRunnable();

        final InputTarget focusedInputTarget = mFocusedInputTarget;