summaryrefslogtreecommitdiff
path: root/libs/input/PointerController.cpp
diff options
context:
space:
mode:
authorVladislav Kaznacheev <kaznacheev@google.com>2016-09-09 19:34:21 +0000
committerandroid-build-merger <android-build-merger@google.com>2016-09-09 19:34:21 +0000
commit8728a2fe53cd63b4f78fe28dc8205ece88eba75e (patch)
treec220ab14c3dcb79dde80607f72fd340bca698c0b /libs/input/PointerController.cpp
parentaab953778b2d408da14355a600a0d706a2f9432d (diff)
parent33c5903e7759b0594b1e0a062b066945a2c86989 (diff)
Hold a weak reference to PointerController when handling vsync
am: 33c5903e77 Change-Id: If3e218dfdaa68953d184812884b7ed80ab16acfa
Diffstat (limited to 'libs/input/PointerController.cpp')
-rw-r--r--libs/input/PointerController.cpp26
1 files changed, 25 insertions, 1 deletions
diff --git a/libs/input/PointerController.cpp b/libs/input/PointerController.cpp
index 27193b743379..abef66f9ecd9 100644
--- a/libs/input/PointerController.cpp
+++ b/libs/input/PointerController.cpp
@@ -36,6 +36,29 @@
namespace android {
+// --- WeakLooperCallback ---
+
+class WeakLooperCallback: public LooperCallback {
+protected:
+ virtual ~WeakLooperCallback() { }
+
+public:
+ WeakLooperCallback(const wp<LooperCallback>& callback) :
+ mCallback(callback) {
+ }
+
+ virtual int handleEvent(int fd, int events, void* data) {
+ sp<LooperCallback> callback = mCallback.promote();
+ if (callback != NULL) {
+ return callback->handleEvent(fd, events, data);
+ }
+ return 0; // the client is gone, remove the callback
+ }
+
+private:
+ wp<LooperCallback> mCallback;
+};
+
// --- PointerController ---
// Time to wait before starting the fade when the pointer is inactive.
@@ -57,10 +80,11 @@ PointerController::PointerController(const sp<PointerControllerPolicyInterface>&
const sp<Looper>& looper, const sp<SpriteController>& spriteController) :
mPolicy(policy), mLooper(looper), mSpriteController(spriteController) {
mHandler = new WeakMessageHandler(this);
+ mCallback = new WeakLooperCallback(this);
if (mDisplayEventReceiver.initCheck() == NO_ERROR) {
mLooper->addFd(mDisplayEventReceiver.getFd(), Looper::POLL_CALLBACK,
- Looper::EVENT_INPUT, this, nullptr);
+ Looper::EVENT_INPUT, mCallback, nullptr);
} else {
ALOGE("Failed to initialize DisplayEventReceiver.");
}