Search code examples
androidandroid-source

Android Q, Touch screen does not scale after resolution changed


I am trying to change the resolution from 720x1280 to 1080X1920 by this command.

wm size 1080X1920

However, the resolution changed and looked very well, but the touch screen doesn't. The touch region remains in 720x1280, a part of the area in desktop has no event response when I am touching it.

Does anyone know what the rule changes in AOSP from Android O to Android Q? I am trying to find out the problem in WindowManager.java but got no root cause still. Any information would be much appreciated.

Thanks,


Solution

  • The target surface touch range of the input event at isPointInsideSurface which is described in InputReader.cpp. It reports the wrong input event coordinate after resolution scaled.

    Change the rule back to the old version, problem resolved.

    bool TouchInputMapper::isPointInsideSurface(int32_t x, int32_t y) {
    const float scaledX = x * mXScale;
    const float scaledY = y * mYScale;
    return x >= mRawPointerAxes.x.minValue && x <= mRawPointerAxes.x.maxValue
            && scaledX >= mPhysicalLeft && scaledX <= mPhysicalLeft + mPhysicalWidth
            && y >= mRawPointerAxes.y.minValue && y <= mRawPointerAxes.y.maxValue
            && scaledY >= mPhysicalTop && scaledY <= mPhysicalTop + mPhysicalHeight;
    

    change to:

    return x >= mRawPointerAxes.x.minValue && x <= mRawPointerAxes.x.maxValue && y >= mRawPointerAxes.y.minValue && y <= mRawPointerAxes.y.maxValue;