summaryrefslogtreecommitdiff
path: root/libs
diff options
context:
space:
mode:
authorTreeHugger Robot <treehugger-gerrit@google.com>2016-09-09 19:28:08 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2016-09-09 19:28:10 +0000
commitc1c0421f678054eace8d588a2ea2d40ce9a64bdd (patch)
tree6e3a540e2b9ab7198307f92a782d71255d195f17 /libs
parent163f8eac70fe732d35f4daad649431208e6e702e (diff)
parent33c5903e7759b0594b1e0a062b066945a2c86989 (diff)
downloadandroid-frameworks-base-c1c0421f678054eace8d588a2ea2d40ce9a64bdd.tar.gz
android-frameworks-base-c1c0421f678054eace8d588a2ea2d40ce9a64bdd.tar.xz
Merge "Hold a weak reference to PointerController when handling vsync" into nyc-mr1-dev
Diffstat (limited to 'libs')
-rw-r--r--libs/input/PointerController.cpp26
-rw-r--r--libs/input/PointerController.h1
2 files changed, 26 insertions, 1 deletions
diff --git a/libs/input/PointerController.cpp b/libs/input/PointerController.cpp
index 27193b7..abef66f 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.");
}
diff --git a/libs/input/PointerController.h b/libs/input/PointerController.h
index 99292d7..4794f3d 100644
--- a/libs/input/PointerController.h
+++ b/libs/input/PointerController.h
@@ -144,6 +144,7 @@ private:
sp<Looper> mLooper;
sp<SpriteController> mSpriteController;
sp<WeakMessageHandler> mHandler;
+ sp<LooperCallback> mCallback;
DisplayEventReceiver mDisplayEventReceiver;