Skip to content

Commit 774d937

Browse files
author
Arpit Singh
committed
Revert "[9/n Dispatcher refactor] Move computeTouchOcclusionInfo..."
Revert submission 31063667 Reason for revert: b/389024840 Reverted changes: /q/submissionid:31063667 Change-Id: Id951c02a894911a018743f0eef9476b0a5a57bd2
1 parent d20a62a commit 774d937

2 files changed

Lines changed: 141 additions & 142 deletions

File tree

services/inputflinger/dispatcher/InputDispatcher.cpp

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -918,21 +918,6 @@ InputTarget createInputTarget(const std::shared_ptr<Connection>& connection,
918918
return inputTarget;
919919
}
920920

921-
std::string dumpWindowForTouchOcclusion(const WindowInfo& info, bool isTouchedWindow) {
922-
return StringPrintf(INDENT2 "* %spackage=%s/%s, id=%" PRId32 ", mode=%s, alpha=%.2f, "
923-
"frame=[%" PRId32 ",%" PRId32 "][%" PRId32 ",%" PRId32
924-
"], touchableRegion=%s, window={%s}, inputConfig={%s}, "
925-
"hasToken=%s, applicationInfo.name=%s, applicationInfo.token=%s\n",
926-
isTouchedWindow ? "[TOUCHED] " : "", info.packageName.c_str(),
927-
info.ownerUid.toString().c_str(), info.id,
928-
toString(info.touchOcclusionMode).c_str(), info.alpha, info.frame.left,
929-
info.frame.top, info.frame.right, info.frame.bottom,
930-
dumpRegion(info.touchableRegion).c_str(), info.name.c_str(),
931-
info.inputConfig.string().c_str(), toString(info.token != nullptr),
932-
info.applicationInfo.name.c_str(),
933-
binderToString(info.applicationInfo.token).c_str());
934-
}
935-
936921
} // namespace
937922

938923
// --- InputDispatcher ---
@@ -948,13 +933,13 @@ InputDispatcher::InputDispatcher(InputDispatcherPolicyInterface& policy,
948933
mLastDropReason(DropReason::NOT_DROPPED),
949934
mIdGenerator(IdGenerator::Source::INPUT_DISPATCHER),
950935
mMinTimeBetweenUserActivityPokes(DEFAULT_USER_ACTIVITY_POKE_INTERVAL),
951-
mConnectionManager(mLooper),
952936
mNextUnblockedEvent(nullptr),
953937
mMonitorDispatchingTimeout(DEFAULT_INPUT_DISPATCHING_TIMEOUT),
954938
mDispatchEnabled(false),
955939
mDispatchFrozen(false),
956940
mInputFilterEnabled(false),
957941
mMaximumObscuringOpacityForTouch(1.0f),
942+
mConnectionManager(mLooper),
958943
mFocusedDisplayId(ui::LogicalDisplayId::DEFAULT),
959944
mWindowTokenWithPointerCapture(nullptr),
960945
mAwaitedApplicationDisplayId(ui::LogicalDisplayId::INVALID),
@@ -3108,12 +3093,12 @@ static bool canBeObscuredBy(const sp<WindowInfoHandle>& windowHandle,
31083093
*
31093094
* If neither of those is true, then it means the touch can be allowed.
31103095
*/
3111-
InputDispatcher::DispatcherWindowInfo::TouchOcclusionInfo
3112-
InputDispatcher::DispatcherWindowInfo::computeTouchOcclusionInfo(
3096+
InputDispatcher::TouchOcclusionInfo InputDispatcher::computeTouchOcclusionInfoLocked(
31133097
const sp<WindowInfoHandle>& windowHandle, float x, float y) const {
31143098
const WindowInfo* windowInfo = windowHandle->getInfo();
31153099
ui::LogicalDisplayId displayId = windowInfo->displayId;
3116-
const std::vector<sp<WindowInfoHandle>>& windowHandles = getWindowHandlesForDisplay(displayId);
3100+
const std::vector<sp<WindowInfoHandle>>& windowHandles =
3101+
mWindowInfos.getWindowHandlesForDisplay(displayId);
31173102
TouchOcclusionInfo info;
31183103
info.hasBlockingOcclusion = false;
31193104
info.obscuringOpacity = 0;
@@ -3125,11 +3110,12 @@ InputDispatcher::DispatcherWindowInfo::computeTouchOcclusionInfo(
31253110
}
31263111
const WindowInfo* otherInfo = otherHandle->getInfo();
31273112
if (canBeObscuredBy(windowHandle, otherHandle) &&
3128-
windowOccludesTouchAt(*otherInfo, displayId, x, y, getDisplayTransform(displayId)) &&
3113+
windowOccludesTouchAt(*otherInfo, displayId, x, y,
3114+
mWindowInfos.getDisplayTransform(displayId)) &&
31293115
!haveSameApplicationToken(windowInfo, otherInfo)) {
31303116
if (DEBUG_TOUCH_OCCLUSION) {
31313117
info.debugInfo.push_back(
3132-
dumpWindowForTouchOcclusion(*otherInfo, /*isTouchedWindow=*/false));
3118+
dumpWindowForTouchOcclusion(otherInfo, /*isTouchedWindow=*/false));
31333119
}
31343120
// canBeObscuredBy() has returned true above, which means this window is untrusted, so
31353121
// we perform the checks below to see if the touch can be propagated or not based on the
@@ -3157,14 +3143,28 @@ InputDispatcher::DispatcherWindowInfo::computeTouchOcclusionInfo(
31573143
}
31583144
}
31593145
if (DEBUG_TOUCH_OCCLUSION) {
3160-
info.debugInfo.push_back(
3161-
dumpWindowForTouchOcclusion(*windowInfo, /*isTouchedWindow=*/true));
3146+
info.debugInfo.push_back(dumpWindowForTouchOcclusion(windowInfo, /*isTouchedWindow=*/true));
31623147
}
31633148
return info;
31643149
}
31653150

3166-
bool InputDispatcher::isTouchTrustedLocked(
3167-
const DispatcherWindowInfo::TouchOcclusionInfo& occlusionInfo) const {
3151+
std::string InputDispatcher::dumpWindowForTouchOcclusion(const WindowInfo* info,
3152+
bool isTouchedWindow) const {
3153+
return StringPrintf(INDENT2 "* %spackage=%s/%s, id=%" PRId32 ", mode=%s, alpha=%.2f, "
3154+
"frame=[%" PRId32 ",%" PRId32 "][%" PRId32 ",%" PRId32
3155+
"], touchableRegion=%s, window={%s}, inputConfig={%s}, "
3156+
"hasToken=%s, applicationInfo.name=%s, applicationInfo.token=%s\n",
3157+
isTouchedWindow ? "[TOUCHED] " : "", info->packageName.c_str(),
3158+
info->ownerUid.toString().c_str(), info->id,
3159+
toString(info->touchOcclusionMode).c_str(), info->alpha, info->frame.left,
3160+
info->frame.top, info->frame.right, info->frame.bottom,
3161+
dumpRegion(info->touchableRegion).c_str(), info->name.c_str(),
3162+
info->inputConfig.string().c_str(), toString(info->token != nullptr),
3163+
info->applicationInfo.name.c_str(),
3164+
binderToString(info->applicationInfo.token).c_str());
3165+
}
3166+
3167+
bool InputDispatcher::isTouchTrustedLocked(const TouchOcclusionInfo& occlusionInfo) const {
31683168
if (occlusionInfo.hasBlockingOcclusion) {
31693169
ALOGW("Untrusted touch due to occlusion by %s/%s", occlusionInfo.obscuringPackage.c_str(),
31703170
occlusionInfo.obscuringUid.toString().c_str());
@@ -5306,8 +5306,7 @@ bool InputDispatcher::canWindowReceiveMotionLocked(const sp<WindowInfoHandle>& w
53065306

53075307
// Drop events that can't be trusted due to occlusion
53085308
const auto [x, y] = resolveTouchedPosition(motionEntry);
5309-
DispatcherWindowInfo::TouchOcclusionInfo occlusionInfo =
5310-
mWindowInfos.computeTouchOcclusionInfo(window, x, y);
5309+
TouchOcclusionInfo occlusionInfo = computeTouchOcclusionInfoLocked(window, x, y);
53115310
if (!isTouchTrustedLocked(occlusionInfo)) {
53125311
if (DEBUG_TOUCH_OCCLUSION) {
53135312
ALOGD("Stack of obscuring windows during untrusted touch (%.1f, %.1f):", x, y);

services/inputflinger/dispatcher/InputDispatcher.h

Lines changed: 115 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -224,120 +224,6 @@ class InputDispatcher : public android::InputDispatcherInterface {
224224
/** Stores the latest user-activity poke event times per user activity types. */
225225
std::array<nsecs_t, USER_ACTIVITY_EVENT_LAST + 1> mLastUserActivityTimes GUARDED_BY(mLock);
226226

227-
template <typename T>
228-
struct StrongPointerHash {
229-
std::size_t operator()(const sp<T>& b) const { return std::hash<T*>{}(b.get()); }
230-
};
231-
232-
class ConnectionManager {
233-
public:
234-
ConnectionManager(sp<Looper> lopper);
235-
~ConnectionManager();
236-
237-
std::shared_ptr<Connection> getConnection(const sp<IBinder>& inputConnectionToken) const;
238-
std::string getConnectionName(const sp<IBinder>& connectionToken) const;
239-
240-
// Find a monitor pid by the provided token.
241-
std::optional<gui::Pid> findMonitorPidByToken(const sp<IBinder>& token) const;
242-
void forEachGlobalMonitorConnection(
243-
std::function<void(const std::shared_ptr<Connection>&)> f) const;
244-
void forEachGlobalMonitorConnection(
245-
ui::LogicalDisplayId displayId,
246-
std::function<void(const std::shared_ptr<Connection>&)> f) const;
247-
248-
void createGlobalInputMonitor(ui::LogicalDisplayId displayId,
249-
std::unique_ptr<InputChannel>&& inputChannel,
250-
const IdGenerator& idGenerator, gui::Pid pid);
251-
252-
status_t removeInputChannel(const std::shared_ptr<Connection>& connection);
253-
void removeConnection(const std::shared_ptr<Connection>& connection);
254-
255-
void createConnection(std::unique_ptr<InputChannel>&& inputChannel,
256-
const IdGenerator& idGenerator);
257-
258-
std::string dump(nsecs_t currentTime) const;
259-
260-
private:
261-
sp<Looper> mLooper;
262-
263-
// All registered connections mapped by input channel token.
264-
std::unordered_map<sp<IBinder>, std::shared_ptr<Connection>, StrongPointerHash<IBinder>>
265-
mConnectionsByToken;
266-
267-
// Input channels that will receive a copy of all input events sent to the provided display.
268-
std::unordered_map<ui::LogicalDisplayId, std::vector<Monitor>> mGlobalMonitorsByDisplay;
269-
270-
void removeMonitorChannel(const sp<IBinder>& connectionToken);
271-
};
272-
273-
ConnectionManager mConnectionManager GUARDED_BY(mLock);
274-
275-
class DispatcherWindowInfo {
276-
public:
277-
struct TouchOcclusionInfo {
278-
bool hasBlockingOcclusion;
279-
float obscuringOpacity;
280-
std::string obscuringPackage;
281-
gui::Uid obscuringUid = gui::Uid::INVALID;
282-
std::vector<std::string> debugInfo;
283-
};
284-
285-
void setWindowHandlesForDisplay(
286-
ui::LogicalDisplayId displayId,
287-
std::vector<sp<android::gui::WindowInfoHandle>>&& windowHandles);
288-
289-
void setDisplayInfos(const std::vector<android::gui::DisplayInfo>& displayInfos);
290-
291-
void removeDisplay(ui::LogicalDisplayId displayId);
292-
293-
// Get a reference to window handles by display, return an empty vector if not found.
294-
const std::vector<sp<android::gui::WindowInfoHandle>>& getWindowHandlesForDisplay(
295-
ui::LogicalDisplayId displayId) const;
296-
297-
void forEachWindowHandle(
298-
std::function<void(const sp<android::gui::WindowInfoHandle>&)> f) const;
299-
300-
void forEachDisplayId(std::function<void(ui::LogicalDisplayId)> f) const;
301-
302-
// Get the transform for display, returns Identity-transform if display is missing.
303-
ui::Transform getDisplayTransform(ui::LogicalDisplayId displayId) const;
304-
305-
// Get the raw transform to use for motion events going to the given window.
306-
ui::Transform getRawTransform(const android::gui::WindowInfo&) const;
307-
308-
// Lookup for WindowInfoHandle from token and optionally a display-id. In cases where
309-
// display-id is not provided lookup is done for all displays.
310-
sp<android::gui::WindowInfoHandle> findWindowHandle(
311-
const sp<IBinder>& windowHandleToken,
312-
std::optional<ui::LogicalDisplayId> displayId = {}) const;
313-
314-
bool isWindowPresent(const sp<android::gui::WindowInfoHandle>& windowHandle) const;
315-
316-
// Returns the touched window at the given location, excluding the ignoreWindow if provided.
317-
sp<android::gui::WindowInfoHandle> findTouchedWindowAt(
318-
ui::LogicalDisplayId displayId, float x, float y, bool isStylus = false,
319-
const sp<android::gui::WindowInfoHandle> ignoreWindow = nullptr) const;
320-
321-
std::vector<sp<android::gui::WindowInfoHandle>> findTouchedSpyWindowsAt(
322-
ui::LogicalDisplayId displayId, float x, float y, bool isStylus, DeviceId deviceId,
323-
const std::unordered_map<ui::LogicalDisplayId, TouchState>& touchStatesByDisplay)
324-
const;
325-
326-
TouchOcclusionInfo computeTouchOcclusionInfo(
327-
const sp<android::gui::WindowInfoHandle>& windowHandle, float x, float y) const;
328-
329-
std::string dumpDisplayAndWindowInfo() const;
330-
331-
private:
332-
std::unordered_map<ui::LogicalDisplayId /*displayId*/,
333-
std::vector<sp<android::gui::WindowInfoHandle>>>
334-
mWindowHandlesByDisplay;
335-
std::unordered_map<ui::LogicalDisplayId /*displayId*/, android::gui::DisplayInfo>
336-
mDisplayInfos;
337-
};
338-
339-
DispatcherWindowInfo mWindowInfos GUARDED_BY(mLock);
340-
341227
// With each iteration, InputDispatcher nominally processes one queued event,
342228
// a timeout, or a response from an input consumer.
343229
// This method should only be called on the input dispatcher's own thread.
@@ -376,6 +262,11 @@ class InputDispatcher : public android::InputDispatcherInterface {
376262

377263
status_t pilferPointersLocked(const sp<IBinder>& token) REQUIRES(mLock);
378264

265+
template <typename T>
266+
struct StrongPointerHash {
267+
std::size_t operator()(const sp<T>& b) const { return std::hash<T*>{}(b.get()); }
268+
};
269+
379270
const HmacKeyManager mHmacKeyManager;
380271
const std::array<uint8_t, 32> getSignature(const MotionEntry& motionEntry,
381272
const DispatchEntry& dispatchEntry) const;
@@ -453,6 +344,103 @@ class InputDispatcher : public android::InputDispatcherInterface {
453344
};
454345
sp<gui::WindowInfosListener> mWindowInfoListener;
455346

347+
class DispatcherWindowInfo {
348+
public:
349+
void setWindowHandlesForDisplay(
350+
ui::LogicalDisplayId displayId,
351+
std::vector<sp<android::gui::WindowInfoHandle>>&& windowHandles);
352+
353+
void setDisplayInfos(const std::vector<android::gui::DisplayInfo>& displayInfos);
354+
355+
void removeDisplay(ui::LogicalDisplayId displayId);
356+
357+
// Get a reference to window handles by display, return an empty vector if not found.
358+
const std::vector<sp<android::gui::WindowInfoHandle>>& getWindowHandlesForDisplay(
359+
ui::LogicalDisplayId displayId) const;
360+
361+
void forEachWindowHandle(
362+
std::function<void(const sp<android::gui::WindowInfoHandle>&)> f) const;
363+
364+
void forEachDisplayId(std::function<void(ui::LogicalDisplayId)> f) const;
365+
366+
// Get the transform for display, returns Identity-transform if display is missing.
367+
ui::Transform getDisplayTransform(ui::LogicalDisplayId displayId) const;
368+
369+
// Get the raw transform to use for motion events going to the given window.
370+
ui::Transform getRawTransform(const android::gui::WindowInfo&) const;
371+
372+
// Lookup for WindowInfoHandle from token and optionally a display-id. In cases where
373+
// display-id is not provided lookup is done for all displays.
374+
sp<android::gui::WindowInfoHandle> findWindowHandle(
375+
const sp<IBinder>& windowHandleToken,
376+
std::optional<ui::LogicalDisplayId> displayId = {}) const;
377+
378+
bool isWindowPresent(const sp<android::gui::WindowInfoHandle>& windowHandle) const;
379+
380+
// Returns the touched window at the given location, excluding the ignoreWindow if provided.
381+
sp<android::gui::WindowInfoHandle> findTouchedWindowAt(
382+
ui::LogicalDisplayId displayId, float x, float y, bool isStylus = false,
383+
const sp<android::gui::WindowInfoHandle> ignoreWindow = nullptr) const;
384+
385+
std::vector<sp<android::gui::WindowInfoHandle>> findTouchedSpyWindowsAt(
386+
ui::LogicalDisplayId displayId, float x, float y, bool isStylus, DeviceId deviceId,
387+
const std::unordered_map<ui::LogicalDisplayId, TouchState>& touchStatesByDisplay)
388+
const;
389+
390+
std::string dumpDisplayAndWindowInfo() const;
391+
392+
private:
393+
std::unordered_map<ui::LogicalDisplayId /*displayId*/,
394+
std::vector<sp<android::gui::WindowInfoHandle>>>
395+
mWindowHandlesByDisplay;
396+
std::unordered_map<ui::LogicalDisplayId /*displayId*/, android::gui::DisplayInfo>
397+
mDisplayInfos;
398+
};
399+
400+
DispatcherWindowInfo mWindowInfos GUARDED_BY(mLock);
401+
402+
class ConnectionManager {
403+
public:
404+
ConnectionManager(sp<Looper> lopper);
405+
~ConnectionManager();
406+
407+
std::shared_ptr<Connection> getConnection(const sp<IBinder>& inputConnectionToken) const;
408+
409+
// Find a monitor pid by the provided token.
410+
std::optional<gui::Pid> findMonitorPidByToken(const sp<IBinder>& token) const;
411+
void forEachGlobalMonitorConnection(
412+
std::function<void(const std::shared_ptr<Connection>&)> f) const;
413+
void forEachGlobalMonitorConnection(
414+
ui::LogicalDisplayId displayId,
415+
std::function<void(const std::shared_ptr<Connection>&)> f) const;
416+
417+
void createGlobalInputMonitor(ui::LogicalDisplayId displayId,
418+
std::unique_ptr<InputChannel>&& inputChannel,
419+
const IdGenerator& idGenerator, gui::Pid pid);
420+
421+
status_t removeInputChannel(const std::shared_ptr<Connection>& connection);
422+
void removeConnection(const std::shared_ptr<Connection>& connection);
423+
424+
void createConnection(std::unique_ptr<InputChannel>&& inputChannel,
425+
const IdGenerator& idGenerator);
426+
427+
std::string dump(nsecs_t currentTime) const;
428+
429+
private:
430+
sp<Looper> mLooper;
431+
432+
// All registered connections mapped by input channel token.
433+
std::unordered_map<sp<IBinder>, std::shared_ptr<Connection>, StrongPointerHash<IBinder>>
434+
mConnectionsByToken;
435+
436+
// Input channels that will receive a copy of all input events sent to the provided display.
437+
std::unordered_map<ui::LogicalDisplayId, std::vector<Monitor>> mGlobalMonitorsByDisplay;
438+
439+
void removeMonitorChannel(const sp<IBinder>& connectionToken);
440+
};
441+
442+
ConnectionManager mConnectionManager GUARDED_BY(mLock);
443+
456444
void setInputWindowsLocked(
457445
const std::vector<sp<android::gui::WindowInfoHandle>>& inputWindowHandles,
458446
ui::LogicalDisplayId displayId) REQUIRES(mLock);
@@ -638,12 +626,24 @@ class InputDispatcher : public android::InputDispatcherInterface {
638626
void addDragEventLocked(const MotionEntry& entry) REQUIRES(mLock);
639627
void finishDragAndDrop(ui::LogicalDisplayId displayId, float x, float y) REQUIRES(mLock);
640628

641-
bool isTouchTrustedLocked(const DispatcherWindowInfo::TouchOcclusionInfo& occlusionInfo) const
629+
struct TouchOcclusionInfo {
630+
bool hasBlockingOcclusion;
631+
float obscuringOpacity;
632+
std::string obscuringPackage;
633+
gui::Uid obscuringUid = gui::Uid::INVALID;
634+
std::vector<std::string> debugInfo;
635+
};
636+
637+
TouchOcclusionInfo computeTouchOcclusionInfoLocked(
638+
const sp<android::gui::WindowInfoHandle>& windowHandle, float x, float y) const
642639
REQUIRES(mLock);
640+
bool isTouchTrustedLocked(const TouchOcclusionInfo& occlusionInfo) const REQUIRES(mLock);
643641
bool isWindowObscuredAtPointLocked(const sp<android::gui::WindowInfoHandle>& windowHandle,
644642
float x, float y) const REQUIRES(mLock);
645643
bool isWindowObscuredLocked(const sp<android::gui::WindowInfoHandle>& windowHandle) const
646644
REQUIRES(mLock);
645+
std::string dumpWindowForTouchOcclusion(const android::gui::WindowInfo* info,
646+
bool isTouchWindow) const;
647647
std::string getApplicationWindowLabel(const InputApplicationHandle* applicationHandle,
648648
const sp<android::gui::WindowInfoHandle>& windowHandle);
649649

0 commit comments

Comments
 (0)