Convert tool type to enum class
For better type safety, use enum class when sending tool type.
Bug: 198472780
Test: atest libinput_tests inputflinger_tests
Change-Id: I371f08087b9513b6f75966c124de77bc12f8324e
diff --git a/include/input/Input.h b/include/input/Input.h
index e8af5f7..a033535 100644
--- a/include/input/Input.h
+++ b/include/input/Input.h
@@ -216,7 +216,21 @@
bool isFromSource(uint32_t source, uint32_t test);
-bool isStylusToolType(uint32_t toolType);
+/**
+ * The pointer tool type.
+ */
+enum class ToolType {
+ UNKNOWN = AMOTION_EVENT_TOOL_TYPE_UNKNOWN,
+ FINGER = AMOTION_EVENT_TOOL_TYPE_FINGER,
+ STYLUS = AMOTION_EVENT_TOOL_TYPE_STYLUS,
+ MOUSE = AMOTION_EVENT_TOOL_TYPE_MOUSE,
+ ERASER = AMOTION_EVENT_TOOL_TYPE_ERASER,
+ PALM = AMOTION_EVENT_TOOL_TYPE_PALM,
+ ftl_first = UNKNOWN,
+ ftl_last = PALM,
+};
+
+bool isStylusToolType(ToolType toolType);
/*
* Flags that flow alongside events in the input dispatch system to help with certain
@@ -320,8 +334,6 @@
*/
const char* motionClassificationToString(MotionClassification classification);
-const char* motionToolTypeToString(int32_t toolType);
-
/**
* Portion of FrameMetrics timeline of interest to input code.
*/
@@ -448,11 +460,11 @@
int32_t id;
// The pointer tool type.
- int32_t toolType;
+ ToolType toolType;
inline void clear() {
id = -1;
- toolType = 0;
+ toolType = ToolType::UNKNOWN;
}
bool operator==(const PointerProperties& other) const;
@@ -638,7 +650,7 @@
return mPointerProperties[pointerIndex].id;
}
- inline int32_t getToolType(size_t pointerIndex) const {
+ inline ToolType getToolType(size_t pointerIndex) const {
return mPointerProperties[pointerIndex].toolType;
}