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

Commit d6637467 authored by Toshiki Kikuchi's avatar Toshiki Kikuchi
Browse files

Consider input device signal in desktop-first switch

This CL lets the controller use an input device signal to determine the
display windowing mode.
If any mouse like device is connected to the device, the device goes to
desktop-first mode.

Flag: com.android.window.flags.form_factor_based_desktop_first_switch
Bug: 400645703
Test: DesktopDisplayModeControllerTest
Change-Id: Iaf5f080a28647efc54f6084a5d2f11dc6525cd79
parent 31bf2957
Loading
Loading
Loading
Loading
+23 −1
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import android.provider.Settings
import android.provider.Settings.Global.DEVELOPMENT_FORCE_DESKTOP_MODE_ON_EXTERNAL_DISPLAYS
import android.view.Display.DEFAULT_DISPLAY
import android.view.IWindowManager
import android.view.InputDevice
import android.view.WindowManager.TRANSIT_CHANGE
import android.window.DesktopExperienceFlags
import android.window.WindowContainerTransaction
@@ -62,12 +63,28 @@ class DesktopDisplayModeController(
            }
        }

    private val inputDeviceListener =
        object : InputManager.InputDeviceListener {
            override fun onInputDeviceAdded(deviceId: Int) {
                refreshDisplayWindowingMode()
            }

            override fun onInputDeviceChanged(deviceId: Int) {
                refreshDisplayWindowingMode()
            }

            override fun onInputDeviceRemoved(deviceId: Int) {
                refreshDisplayWindowingMode()
            }
        }

    init {
        if (DesktopExperienceFlags.FORM_FACTOR_BASED_DESKTOP_FIRST_SWITCH.isTrue) {
            inputManager.registerOnTabletModeChangedListener(
                onTabletModeChangedListener,
                mainHandler,
            )
            inputManager.registerInputDeviceListener(inputDeviceListener, mainHandler)
        }
    }

@@ -122,7 +139,7 @@ class DesktopDisplayModeController(
                return true
            }
            if (DesktopExperienceFlags.FORM_FACTOR_BASED_DESKTOP_FIRST_SWITCH.isTrue) {
                if (isInClamshellMode()) {
                if (isInClamshellMode() || hasAnyMouseDevice()) {
                    return true
                }
            }
@@ -169,6 +186,11 @@ class DesktopDisplayModeController(
    private fun hasExternalDisplay() =
        rootTaskDisplayAreaOrganizer.getDisplayIds().any { it != DEFAULT_DISPLAY }

    private fun hasAnyMouseDevice() =
        inputManager.inputDeviceIds.any {
            inputManager.getInputDevice(it)?.supportsSource(InputDevice.SOURCE_MOUSE) == true
        }

    private fun isInClamshellMode() = inputManager.isInTabletMode() == InputManager.SWITCH_STATE_OFF

    private fun isDefaultDisplayDesktopEligible(): Boolean {
+255 −24

File changed.

Preview size limit exceeded, changes collapsed.