summaryrefslogtreecommitdiff
path: root/libs/input/PointerController.cpp
diff options
context:
space:
mode:
authorPrabir Pradhan <prabirmsp@google.com>2020-01-31 17:42:34 -0800
committerPrabir Pradhan <prabirmsp@google.com>2020-02-07 12:24:32 -0800
commitbe845950a25620eca1d8a3a6cba48c38e5e5e8c4 (patch)
treec6fd33018c5bc13553661731724babf47d6db787 /libs/input/PointerController.cpp
parente0d9b2a9ac4ea679c73edfd8e308540ffd35bc58 (diff)
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
Diffstat (limited to 'libs/input/PointerController.cpp')
-rw-r--r--libs/input/PointerController.cpp33
1 files changed, 24 insertions, 9 deletions
diff --git a/libs/input/PointerController.cpp b/libs/input/PointerController.cpp
index e4348f2a9b21..3b494e9129db 100644
--- a/libs/input/PointerController.cpp
+++ b/libs/input/PointerController.cpp
@@ -251,19 +251,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();
}
}
@@ -285,6 +290,9 @@ void PointerController::setSpots(const PointerCoords* spotCoords,
#endif
AutoMutex _l(mLock);
+ if (!mLocked.viewport.isValid()) {
+ return;
+ }
std::vector<Spot*> newSpots;
std::map<int32_t, std::vector<Spot*>>::const_iterator iter =
@@ -331,6 +339,9 @@ void PointerController::clearSpots() {
#endif
AutoMutex _l(mLock);
+ if (!mLocked.viewport.isValid()) {
+ return;
+ }
fadeOutAndReleaseAllSpotsLocked();
}
@@ -752,6 +763,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);