!105 resolve the warning

Merge pull request !105 from 李尚/master
This commit is contained in:
openharmony_ci
2023-11-29 08:08:56 +00:00
committed by Gitee
2 changed files with 29 additions and 5 deletions
+27 -4
View File
@@ -1469,20 +1469,36 @@ void InputHub::SavePressedKeyState(const InputHub::Device *dev, int32_t keyCode)
dev->identifier.descriptor.c_str());
}
void InputHub::CheckTargetKeyState(const InputHub::Device *dev, const unsigned long *keyState)
bool InputHub::IsLengthExceeds(const unsigned long *keyState, const unsigned long len, int keyIndex)
{
if (len < (keyIndex / LONG_BITS) + 1) {
DHLOGE("Length exceeds for key index: %d", keyIndex);
return true;
}
return false;
}
void InputHub::CheckTargetKeyState(const InputHub::Device *dev, const unsigned long *keyState, const unsigned long len)
{
// If device is a mouse, record the mouse pressed key.
if ((dev->classes & INPUT_DEVICE_CLASS_CURSOR) != 0) {
if (IsLengthExceeds(keyState, len, BTN_LEFT)) {
return;
}
int mouseLeftBtnState = BitIsSet(keyState, BTN_LEFT);
if (mouseLeftBtnState != 0) {
SavePressedKeyState(dev, BTN_LEFT);
}
if (IsLengthExceeds(keyState, len, BTN_RIGHT)) {
return;
}
int mouseRightBtnState = BitIsSet(keyState, BTN_RIGHT);
if (mouseRightBtnState != 0) {
SavePressedKeyState(dev, BTN_RIGHT);
}
if (IsLengthExceeds(keyState, len, BTN_MIDDLE)) {
return;
}
int mouseMidBtnState = BitIsSet(keyState, BTN_MIDDLE);
if (mouseMidBtnState != 0) {
SavePressedKeyState(dev, BTN_MIDDLE);
@@ -1492,6 +1508,9 @@ void InputHub::CheckTargetKeyState(const InputHub::Device *dev, const unsigned l
// If device is a keyboard, record all the pressed keys.
if ((dev->classes & INPUT_DEVICE_CLASS_KEYBOARD) != 0) {
for (int32_t keyIndex = 0; keyIndex < KEY_MAX; keyIndex++) {
if (IsLengthExceeds(keyState, len, keyIndex)) {
return;
}
if (BitIsSet(keyState, keyIndex) != 0) {
SavePressedKeyState(dev, keyIndex);
}
@@ -1500,6 +1519,9 @@ void InputHub::CheckTargetKeyState(const InputHub::Device *dev, const unsigned l
// If device is a touchscreen or touchpad, record the touch event.
if ((dev->classes & INPUT_DEVICE_CLASS_TOUCH) != 0 || (dev->classes & INPUT_DEVICE_CLASS_TOUCH_MT) != 0) {
if (IsLengthExceeds(keyState, len, BTN_TOUCH)) {
return;
}
int btnTouchState = BitIsSet(keyState, BTN_TOUCH);
if (btnTouchState != 0) {
SavePressedKeyState(dev, BTN_TOUCH);
@@ -1507,6 +1529,7 @@ void InputHub::CheckTargetKeyState(const InputHub::Device *dev, const unsigned l
}
}
void InputHub::CheckTargetDevicesState(std::vector<InputHub::Device*> targetDevices)
{
uint32_t count = 0;
@@ -1524,7 +1547,7 @@ void InputHub::CheckTargetDevicesState(std::vector<InputHub::Device*> targetDevi
std::this_thread::sleep_for(std::chrono::milliseconds(READ_SLEEP_TIME_MS));
continue;
}
CheckTargetKeyState(dev, keyState);
CheckTargetKeyState(dev, keyState, NLONGS(KEY_CNT));
break;
}
}
+2 -1
View File
@@ -97,7 +97,8 @@ public:
void RecordDeviceStates();
void CheckTargetDevicesState(std::vector<Device*> targetDevices);
void CheckTargetKeyState(const InputHub::Device *dev, const unsigned long *keyState);
bool IsLengthExceeds(const unsigned long *keyState, const unsigned long len, int keyIndex);
void CheckTargetKeyState(const InputHub::Device *dev, const unsigned long *keyState, const unsigned long len);
void SavePressedKeyState(const Device *dev, int32_t keyCode);
void ClearDeviceStates();
private: