From ca7d72347ec2890ffa4f6efda514b66334b7ac66 Mon Sep 17 00:00:00 2001 From: Prabir Pradhan Date: Fri, 31 Jan 2020 17:42:34 -0800 Subject: PointerController: Add guards to ensure display is valid This change makes it so that PointerController does not ask its Policy to load any resources for any displays until a DisplayViewport is set, and verifies this with unit tests. Bug: 145699789 Bug: 146385350 Test: atest libinputservice_test Change-Id: I2e48e7ac4700e6f9fdf939a7bd0e6639b051ade6 Merged-In: I2e48e7ac4700e6f9fdf939a7bd0e6639b051ade6 --- libs/input/PointerController.cpp | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) (limited to 'libs/input/PointerController.cpp') diff --git a/libs/input/PointerController.cpp b/libs/input/PointerController.cpp index abf083789c23..5c2ef15cbd1e 100644 --- a/libs/input/PointerController.cpp +++ b/libs/input/PointerController.cpp @@ -257,19 +257,24 @@ void PointerController::unfade(Transition transition) { void PointerController::setPresentation(Presentation presentation) { AutoMutex _l(mLock); - if (presentation == PRESENTATION_POINTER && mLocked.additionalMouseResources.empty()) { - mPolicy->loadAdditionalMouseResources(&mLocked.additionalMouseResources, - &mLocked.animationResources, mLocked.viewport.displayId); + if (mLocked.presentation == presentation) { + return; } - if (mLocked.presentation != presentation) { - mLocked.presentation = presentation; - mLocked.presentationChanged = true; + mLocked.presentation = presentation; + mLocked.presentationChanged = true; - if (presentation != PRESENTATION_SPOT) { - fadeOutAndReleaseAllSpotsLocked(); - } + if (!mLocked.viewport.isValid()) { + return; + } + if (presentation == PRESENTATION_POINTER) { + if (mLocked.additionalMouseResources.empty()) { + mPolicy->loadAdditionalMouseResources(&mLocked.additionalMouseResources, + &mLocked.animationResources, + mLocked.viewport.displayId); + } + fadeOutAndReleaseAllSpotsLocked(); updatePointerLocked(); } } @@ -291,6 +296,9 @@ void PointerController::setSpots(const PointerCoords* spotCoords, #endif AutoMutex _l(mLock); + if (!mLocked.viewport.isValid()) { + return; + } std::vector newSpots; std::map>::const_iterator iter = @@ -337,6 +345,9 @@ void PointerController::clearSpots() { #endif AutoMutex _l(mLock); + if (!mLocked.viewport.isValid()) { + return; + } fadeOutAndReleaseAllSpotsLocked(); } @@ -758,6 +769,10 @@ void PointerController::fadeOutAndReleaseAllSpotsLocked() { } void PointerController::loadResourcesLocked() REQUIRES(mLock) { + if (!mLocked.viewport.isValid()) { + return; + } + mPolicy->loadPointerResources(&mResources, mLocked.viewport.displayId); mPolicy->loadPointerIcon(&mLocked.pointerIcon, mLocked.viewport.displayId); -- cgit v1.2.3-59-g8ed1b