Skip to content

Commit 8b37b1b

Browse files
author
Arpit Singh
committed
Move utility functions related to isFromSource to Input.h
Moving following function to a common file to avoid duplication. 1. isStylusHoverEvent 2. isFromMouse 3. isFromTouchpad 4. isFromDrawingTablet 5. isHoverAction 6. isMouseOrTouchpad Test: atest inputflinger_tests Bug: 245989146 Flag: EXEMPT refactor Change-Id: I9538646f126e792897c525e7e698f6acde4aaa22
1 parent 9381637 commit 8b37b1b

5 files changed

Lines changed: 49 additions & 53 deletions

File tree

include/input/Input.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,19 @@ struct PointerProperties;
316316

317317
bool isStylusEvent(uint32_t source, const std::vector<PointerProperties>& properties);
318318

319+
bool isStylusHoverEvent(uint32_t source, const std::vector<PointerProperties>& properties,
320+
int32_t action);
321+
322+
bool isFromMouse(uint32_t source, ToolType tooltype);
323+
324+
bool isFromTouchpad(uint32_t source, ToolType tooltype);
325+
326+
bool isFromDrawingTablet(uint32_t source, ToolType tooltype);
327+
328+
bool isHoverAction(int32_t action);
329+
330+
bool isMouseOrTouchpad(uint32_t sources);
331+
319332
/*
320333
* Flags that flow alongside events in the input dispatch system to help with certain
321334
* policy decisions such as waking from device sleep.

libs/input/Input.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,36 @@ bool isStylusEvent(uint32_t source, const std::vector<PointerProperties>& proper
284284
return false;
285285
}
286286

287+
bool isStylusHoverEvent(uint32_t source, const std::vector<PointerProperties>& properties,
288+
int32_t action) {
289+
return isStylusEvent(source, properties) && isHoverAction(action);
290+
}
291+
292+
bool isFromMouse(uint32_t source, ToolType toolType) {
293+
return isFromSource(source, AINPUT_SOURCE_MOUSE) && toolType == ToolType::MOUSE;
294+
}
295+
296+
bool isFromTouchpad(uint32_t source, ToolType toolType) {
297+
return isFromSource(source, AINPUT_SOURCE_MOUSE) && toolType == ToolType::FINGER;
298+
}
299+
300+
bool isFromDrawingTablet(uint32_t source, ToolType toolType) {
301+
return isFromSource(source, AINPUT_SOURCE_MOUSE | AINPUT_SOURCE_STYLUS) &&
302+
isStylusToolType(toolType);
303+
}
304+
305+
bool isHoverAction(int32_t action) {
306+
return action == AMOTION_EVENT_ACTION_HOVER_ENTER ||
307+
action == AMOTION_EVENT_ACTION_HOVER_MOVE || action == AMOTION_EVENT_ACTION_HOVER_EXIT;
308+
}
309+
310+
bool isMouseOrTouchpad(uint32_t sources) {
311+
// Check if this is a mouse or touchpad, but not a drawing tablet.
312+
return isFromSource(sources, AINPUT_SOURCE_MOUSE_RELATIVE) ||
313+
(isFromSource(sources, AINPUT_SOURCE_MOUSE) &&
314+
!isFromSource(sources, AINPUT_SOURCE_STYLUS));
315+
}
316+
287317
VerifiedKeyEvent verifiedKeyEventFromKeyEvent(const KeyEvent& event) {
288318
return {{VerifiedInputEvent::Type::KEY, event.getDeviceId(), event.getEventTime(),
289319
event.getSource(), event.getDisplayId()},

services/inputflinger/PointerChoreographer.cpp

Lines changed: 5 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -36,37 +36,6 @@ namespace android {
3636

3737
namespace {
3838

39-
bool isFromMouse(const NotifyMotionArgs& args) {
40-
return isFromSource(args.source, AINPUT_SOURCE_MOUSE) &&
41-
args.pointerProperties[0].toolType == ToolType::MOUSE;
42-
}
43-
44-
bool isFromTouchpad(const NotifyMotionArgs& args) {
45-
return isFromSource(args.source, AINPUT_SOURCE_MOUSE) &&
46-
args.pointerProperties[0].toolType == ToolType::FINGER;
47-
}
48-
49-
bool isFromDrawingTablet(const NotifyMotionArgs& args) {
50-
return isFromSource(args.source, AINPUT_SOURCE_MOUSE | AINPUT_SOURCE_STYLUS) &&
51-
isStylusToolType(args.pointerProperties[0].toolType);
52-
}
53-
54-
bool isHoverAction(int32_t action) {
55-
return action == AMOTION_EVENT_ACTION_HOVER_ENTER ||
56-
action == AMOTION_EVENT_ACTION_HOVER_MOVE || action == AMOTION_EVENT_ACTION_HOVER_EXIT;
57-
}
58-
59-
bool isStylusHoverEvent(const NotifyMotionArgs& args) {
60-
return isStylusEvent(args.source, args.pointerProperties) && isHoverAction(args.action);
61-
}
62-
63-
bool isMouseOrTouchpad(uint32_t sources) {
64-
// Check if this is a mouse or touchpad, but not a drawing tablet.
65-
return isFromSource(sources, AINPUT_SOURCE_MOUSE_RELATIVE) ||
66-
(isFromSource(sources, AINPUT_SOURCE_MOUSE) &&
67-
!isFromSource(sources, AINPUT_SOURCE_STYLUS));
68-
}
69-
7039
inline void notifyPointerDisplayChange(std::optional<std::tuple<ui::LogicalDisplayId, vec2>> change,
7140
PointerChoreographerPolicyInterface& policy) {
7241
if (!change) {
@@ -239,15 +208,16 @@ NotifyMotionArgs PointerChoreographer::processMotion(const NotifyMotionArgs& arg
239208
PointerDisplayChange pointerDisplayChange;
240209
{ // acquire lock
241210
std::scoped_lock _l(getLock());
242-
if (isFromMouse(args)) {
211+
if (isFromMouse(args.source, args.pointerProperties[0].toolType)) {
243212
newArgs = processMouseEventLocked(args);
244213
pointerDisplayChange = calculatePointerDisplayChangeToNotify();
245-
} else if (isFromTouchpad(args)) {
214+
} else if (isFromTouchpad(args.source, args.pointerProperties[0].toolType)) {
246215
newArgs = processTouchpadEventLocked(args);
247216
pointerDisplayChange = calculatePointerDisplayChangeToNotify();
248-
} else if (isFromDrawingTablet(args)) {
217+
} else if (isFromDrawingTablet(args.source, args.pointerProperties[0].toolType)) {
249218
processDrawingTabletEventLocked(args);
250-
} else if (mStylusPointerIconEnabled && isStylusHoverEvent(args)) {
219+
} else if (mStylusPointerIconEnabled &&
220+
isStylusHoverEvent(args.source, args.pointerProperties, args.action)) {
251221
processStylusHoverEventLocked(args);
252222
} else if (isFromSource(args.source, AINPUT_SOURCE_TOUCHSCREEN)) {
253223
processTouchscreenAndStylusEventLocked(args);

services/inputflinger/dispatcher/InputDispatcher.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -920,13 +920,6 @@ std::string dumpWindowForTouchOcclusion(const WindowInfo& info, bool isTouchedWi
920920
binderToString(info.applicationInfo.token).c_str());
921921
}
922922

923-
bool isMouseOrTouchpad(uint32_t sources) {
924-
// Check if this is a mouse or touchpad, but not a drawing tablet.
925-
return isFromSource(sources, AINPUT_SOURCE_MOUSE_RELATIVE) ||
926-
(isFromSource(sources, AINPUT_SOURCE_MOUSE) &&
927-
!isFromSource(sources, AINPUT_SOURCE_STYLUS));
928-
}
929-
930923
} // namespace
931924

932925
// --- InputDispatcher ---

services/inputflinger/dispatcher/InputState.cpp

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616

1717
#include "DebugConfig.h"
18+
#include "input/Input.h"
1819
#include "input/InputDevice.h"
1920
#include "input/InputFlags.h"
2021

@@ -25,17 +26,6 @@
2526

2627
namespace android::inputdispatcher {
2728

28-
namespace {
29-
30-
bool isMouseOrTouchpad(uint32_t sources) {
31-
// Check if this is a mouse or touchpad, but not a drawing tablet.
32-
return isFromSource(sources, AINPUT_SOURCE_MOUSE_RELATIVE) ||
33-
(isFromSource(sources, AINPUT_SOURCE_MOUSE) &&
34-
!isFromSource(sources, AINPUT_SOURCE_STYLUS));
35-
}
36-
37-
} // namespace
38-
3929
InputState::InputState(const IdGenerator& idGenerator) : mIdGenerator(idGenerator) {}
4030

4131
InputState::~InputState() {}

0 commit comments

Comments
 (0)