From 6200eacdc927776483d775562db11cce284cc7e0 Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Thu, 5 Oct 2017 14:24:41 -0700 Subject: surfaceflinger: make vsync injection more robust There are more issues than I expected :) - no lock to synchronize enable/disable and injection - Every time injection is diabled and enabled, a new EventThread is created - mCallback might be nullptr - ENABLE_VSYNC_INJECTIONS/INJECT_VSYNC should require special permission - MessageQueue::setEventThread must be called from the main thread - MessageQueue::setEventThread does not handle EventThread switch well Bug: 65483324 Test: manual Merged-In: I7d7b98d1f57afc64af0f2065a9bc7c8ad004ca9f Change-Id: I7d7b98d1f57afc64af0f2065a9bc7c8ad004ca9f --- services/surfaceflinger/MessageQueue.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'services/surfaceflinger/MessageQueue.cpp') diff --git a/services/surfaceflinger/MessageQueue.cpp b/services/surfaceflinger/MessageQueue.cpp index bca3430794..0b1199c2d0 100644 --- a/services/surfaceflinger/MessageQueue.cpp +++ b/services/surfaceflinger/MessageQueue.cpp @@ -91,6 +91,14 @@ void MessageQueue::init(const sp& flinger) void MessageQueue::setEventThread(const sp& eventThread) { + if (mEventThread == eventThread) { + return; + } + + if (mEventTube.getFd() >= 0) { + mLooper->removeFd(mEventTube.getFd()); + } + mEventThread = eventThread; mEvents = eventThread->createEventConnection(); mEvents->stealReceiveChannel(&mEventTube); -- cgit v1.2.3-59-g8ed1b