Loading services/inputflinger/InputReader.cpp +11 −2 Original line number Diff line number Diff line Loading @@ -254,7 +254,6 @@ static void synthesizeButtonKeys(InputReaderContext* context, int32_t action, } // --- InputReader --- InputReader::InputReader(const sp<EventHubInterface>& eventHub, Loading Loading @@ -3446,7 +3445,17 @@ std::optional<DisplayViewport> TouchInputMapper::findViewport() { } else { viewportTypeToUse = ViewportType::VIEWPORT_INTERNAL; } return mConfig.getDisplayViewportByType(viewportTypeToUse); std::optional<DisplayViewport> viewport = mConfig.getDisplayViewportByType(viewportTypeToUse); if (!viewport && viewportTypeToUse == ViewportType::VIEWPORT_EXTERNAL) { ALOGW("Input device %s should be associated with external display, " "fallback to internal one for the external viewport is not found.", getDeviceName().c_str()); viewport = mConfig.getDisplayViewportByType(ViewportType::VIEWPORT_INTERNAL); } return viewport; } DisplayViewport newViewport; Loading services/inputflinger/tests/InputReader_test.cpp +30 −0 Original line number Diff line number Diff line Loading @@ -6284,4 +6284,34 @@ TEST_F(MultiTouchInputMapperTest, Configure_AssignsDisplayPort) { ASSERT_EQ(DISPLAY_ID, args.displayId); } /** * Expect fallback to internal viewport if device is external and external viewport is not present. */ TEST_F(MultiTouchInputMapperTest, Viewports_Fallback) { MultiTouchInputMapper* mapper = new MultiTouchInputMapper(mDevice); prepareAxes(POSITION); addConfigurationProperty("touch.deviceType", "touchScreen"); prepareDisplay(DISPLAY_ORIENTATION_0); mDevice->setExternal(true); addMapperAndConfigure(mapper); ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, mapper->getSources()); NotifyMotionArgs motionArgs; // Expect the event to be sent to the internal viewport, // because an external viewport is not present. processPosition(mapper, 100, 100); processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(ADISPLAY_ID_DEFAULT, motionArgs.displayId); // Expect the event to be sent to the external viewport if it is present. prepareSecondaryDisplay(ViewportType::VIEWPORT_EXTERNAL); processPosition(mapper, 100, 100); processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(SECONDARY_DISPLAY_ID, motionArgs.displayId); } } // namespace android Loading
services/inputflinger/InputReader.cpp +11 −2 Original line number Diff line number Diff line Loading @@ -254,7 +254,6 @@ static void synthesizeButtonKeys(InputReaderContext* context, int32_t action, } // --- InputReader --- InputReader::InputReader(const sp<EventHubInterface>& eventHub, Loading Loading @@ -3446,7 +3445,17 @@ std::optional<DisplayViewport> TouchInputMapper::findViewport() { } else { viewportTypeToUse = ViewportType::VIEWPORT_INTERNAL; } return mConfig.getDisplayViewportByType(viewportTypeToUse); std::optional<DisplayViewport> viewport = mConfig.getDisplayViewportByType(viewportTypeToUse); if (!viewport && viewportTypeToUse == ViewportType::VIEWPORT_EXTERNAL) { ALOGW("Input device %s should be associated with external display, " "fallback to internal one for the external viewport is not found.", getDeviceName().c_str()); viewport = mConfig.getDisplayViewportByType(ViewportType::VIEWPORT_INTERNAL); } return viewport; } DisplayViewport newViewport; Loading
services/inputflinger/tests/InputReader_test.cpp +30 −0 Original line number Diff line number Diff line Loading @@ -6284,4 +6284,34 @@ TEST_F(MultiTouchInputMapperTest, Configure_AssignsDisplayPort) { ASSERT_EQ(DISPLAY_ID, args.displayId); } /** * Expect fallback to internal viewport if device is external and external viewport is not present. */ TEST_F(MultiTouchInputMapperTest, Viewports_Fallback) { MultiTouchInputMapper* mapper = new MultiTouchInputMapper(mDevice); prepareAxes(POSITION); addConfigurationProperty("touch.deviceType", "touchScreen"); prepareDisplay(DISPLAY_ORIENTATION_0); mDevice->setExternal(true); addMapperAndConfigure(mapper); ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, mapper->getSources()); NotifyMotionArgs motionArgs; // Expect the event to be sent to the internal viewport, // because an external viewport is not present. processPosition(mapper, 100, 100); processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(ADISPLAY_ID_DEFAULT, motionArgs.displayId); // Expect the event to be sent to the external viewport if it is present. prepareSecondaryDisplay(ViewportType::VIEWPORT_EXTERNAL); processPosition(mapper, 100, 100); processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(SECONDARY_DISPLAY_ID, motionArgs.displayId); } } // namespace android