diff options
| author | 2016-12-06 15:17:16 -0800 | |
|---|---|---|
| committer | 2016-12-06 15:17:16 -0800 | |
| commit | 82834baa358f55acb542e17da828b2d497cf8332 (patch) | |
| tree | 35a57c84d9810438a92cb7036cab3bba96580a5b /libs/input/PointerController.cpp | |
| parent | 800a4e753e991ea23b4c72568b3150b8c232aa6a (diff) | |
| parent | 5b9b0db9f8532aea7c907d3f5ac8b7808b46c1c7 (diff) | |
Merge remote-tracking branch 'goog/stage-aosp-master' into HEAD
Diffstat (limited to 'libs/input/PointerController.cpp')
| -rw-r--r-- | libs/input/PointerController.cpp | 26 |
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."); } |