summaryrefslogtreecommitdiff
path: root/libs
diff options
context:
space:
mode:
authorVladislav Kaznacheev <kaznacheev@google.com>2016-09-09 10:03:31 -0700
committerVladislav Kaznacheev <kaznacheev@google.com>2016-09-09 10:03:31 -0700
commit33c5903e7759b0594b1e0a062b066945a2c86989 (patch)
treefb992fafc36f0e3d4c3baeb79e68594ae0b4d9e7 /libs
parentfd97e7bc8cac91d849bf40202870c2220fc04f7a (diff)
downloadandroid-frameworks-base-33c5903e7759b0594b1e0a062b066945a2c86989.tar.gz
android-frameworks-base-33c5903e7759b0594b1e0a062b066945a2c86989.tar.xz
Hold a weak reference to PointerController when handling vsync
Currently PointerController starts listening to display events immediately (in its constructor) and never explicitly removes the callback. The reference dangling from the looper prevents the PointerController instance from being deleted when all the clients have released their references. As a result, when USB or BT mouse is disconnected, the mouse stays frozen on screen and only goes away after a 15 sec inactivity timeout. This change introduces an intermediary LooperCallback which holds only a weak reference to PointerController. The pointer now disappears immediately upon mouse disconnect. Bug: 30824220 Change-Id: I5f7208dbfa381b3e21f248cc0da402f307faa184
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;