Skip to content

Commit

Permalink
Fix #340
Browse files Browse the repository at this point in the history
  • Loading branch information
Eeems committed Jan 16, 2024
1 parent 1ecc539 commit 1683bd6
Show file tree
Hide file tree
Showing 15 changed files with 994 additions and 113 deletions.
160 changes: 80 additions & 80 deletions applications/inject_evdev/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ bool process_EV_ABS(const QStringList& args){
abs(ABS_TILT_Y);
abs(ABS_TOOL_WIDTH);
abs(ABS_VOLUME);
//abs(ABS_PROFILE);
// abs(ABS_PROFILE);
abs(ABS_MISC);
//abs(ABS_RESERVED);
abs(ABS_RESERVED);
abs(ABS_MT_SLOT);
abs(ABS_MT_TOUCH_MAJOR);
abs(ABS_MT_TOUCH_MINOR);
Expand Down Expand Up @@ -128,9 +128,9 @@ bool process_EV_REL(const QStringList& args){
rel(REL_DIAL);
rel(REL_WHEEL);
rel(REL_MISC);
//rel(REL_RESERVED);
//rel(REL_WHEEL_HI_RES);
//rel(REL_HWHEEL_HI_RES);
rel(REL_RESERVED);
rel(REL_WHEEL_HI_RES);
rel(REL_HWHEEL_HI_RES);
rel(REL_MAX);
rel(REL_CNT);
qDebug() << "Unknown EV_REL event code:" << code.c_str();
Expand Down Expand Up @@ -350,7 +350,7 @@ bool process_EV_KEY(const QStringList& args){
key(KEY_PAUSECD);
key(KEY_PROG3);
key(KEY_PROG4);
//key(KEY_ALL_APPLICATIONS);
// key(KEY_ALL_APPLICATIONS);
key(KEY_DASHBOARD);
key(KEY_SUSPEND);
key(KEY_CLOSE);
Expand Down Expand Up @@ -418,11 +418,11 @@ bool process_EV_KEY(const QStringList& args){
key(KEY_TITLE);
key(KEY_SUBTITLE);
key(KEY_ANGLE);
//key(KEY_FULL_SCREEN);
key(KEY_FULL_SCREEN);
key(KEY_ZOOM);
key(KEY_MODE);
key(KEY_KEYBOARD);
//key(KEY_ASPECT_RATIO);
key(KEY_ASPECT_RATIO);
key(KEY_SCREEN);
key(KEY_PC);
key(KEY_TV);
Expand Down Expand Up @@ -492,9 +492,9 @@ bool process_EV_KEY(const QStringList& args){
key(KEY_10CHANNELSUP);
key(KEY_10CHANNELSDOWN);
key(KEY_IMAGES);
//key(KEY_NOTIFICATION_CENTER);
//key(KEY_PICKUP_PHONE);
//key(KEY_HANGUP_PHONE);
// key(KEY_NOTIFICATION_CENTER);
// key(KEY_PICKUP_PHONE);
// key(KEY_HANGUP_PHONE);
key(KEY_DEL_EOL);
key(KEY_DEL_EOS);
key(KEY_INS_LINE);
Expand All @@ -520,7 +520,7 @@ bool process_EV_KEY(const QStringList& args){
key(KEY_FN_F);
key(KEY_FN_S);
key(KEY_FN_B);
//key(KEY_FN_RIGHT_SHIFT);
// key(KEY_FN_RIGHT_SHIFT);
key(KEY_BRL_DOT1);
key(KEY_BRL_DOT2);
key(KEY_BRL_DOT3);
Expand Down Expand Up @@ -563,21 +563,21 @@ bool process_EV_KEY(const QStringList& args){
key(KEY_ATTENDANT_TOGGLE);
key(KEY_LIGHTS_TOGGLE);
key(KEY_ALS_TOGGLE);
//key(KEY_ROTATE_LOCK_TOGGLE);
key(KEY_ROTATE_LOCK_TOGGLE);
key(KEY_BUTTONCONFIG);
key(KEY_TASKMANAGER);
key(KEY_JOURNAL);
key(KEY_CONTROLPANEL);
key(KEY_APPSELECT);
key(KEY_SCREENSAVER);
key(KEY_VOICECOMMAND);
//key(KEY_ASSISTANT);
//key(KEY_KBD_LAYOUT_NEXT);
//key(KEY_EMOJI_PICKER);
//key(KEY_DICTATE);
//key(KEY_CAMERA_ACCESS_ENABLE);
//key(KEY_CAMERA_ACCESS_DISABLE);
//key(KEY_CAMERA_ACCESS_TOGGLE);
key(KEY_ASSISTANT);
key(KEY_KBD_LAYOUT_NEXT);
// key(KEY_EMOJI_PICKER);
// key(KEY_DICTATE);
// key(KEY_CAMERA_ACCESS_ENABLE);
// key(KEY_CAMERA_ACCESS_DISABLE);
// key(KEY_CAMERA_ACCESS_TOGGLE);
key(KEY_BRIGHTNESS_MIN);
key(KEY_BRIGHTNESS_MAX);
key(KEY_KBDINPUTASSIST_PREV);
Expand All @@ -604,65 +604,65 @@ bool process_EV_KEY(const QStringList& args){
key(KEY_FASTREVERSE);
key(KEY_SLOWREVERSE);
key(KEY_DATA);
//key(KEY_ONSCREEN_KEYBOARD);
//key(KEY_PRIVACY_SCREEN_TOGGLE);
//key(KEY_SELECTIVE_SCREENSHOT);
//key(KEY_NEXT_ELEMENT);
//key(KEY_PREVIOUS_ELEMENT);
//key(KEY_AUTOPILOT_ENGAGE_TOGGLE);
//key(KEY_MARK_WAYPOINT);
//key(KEY_SOS);
//key(KEY_NAV_CHART);
//key(KEY_FISHING_CHART);
//key(KEY_SINGLE_RANGE_RADAR);
//key(KEY_DUAL_RANGE_RADAR);
//key(KEY_RADAR_OVERLAY);
//key(KEY_TRADITIONAL_SONAR);
//key(KEY_CLEARVU_SONAR);
//key(KEY_SIDEVU_SONAR);
//key(KEY_NAV_INFO);
//key(KEY_BRIGHTNESS_MENU);
//key(KEY_MACRO1);
//key(KEY_MACRO2);
//key(KEY_MACRO3);
//key(KEY_MACRO4);
//key(KEY_MACRO5);
//key(KEY_MACRO6);
//key(KEY_MACRO7);
//key(KEY_MACRO8);
//key(KEY_MACRO9);
//key(KEY_MACRO10);
//key(KEY_MACRO11);
//key(KEY_MACRO12);
//key(KEY_MACRO13);
//key(KEY_MACRO14);
//key(KEY_MACRO15);
//key(KEY_MACRO16);
//key(KEY_MACRO17);
//key(KEY_MACRO18);
//key(KEY_MACRO19);
//key(KEY_MACRO20);
//key(KEY_MACRO21);
//key(KEY_MACRO22);
//key(KEY_MACRO23);
//key(KEY_MACRO24);
//key(KEY_MACRO25);
//key(KEY_MACRO26);
//key(KEY_MACRO27);
//key(KEY_MACRO28);
//key(KEY_MACRO29);
//key(KEY_MACRO30);
//key(KEY_MACRO_RECORD_START);
//key(KEY_MACRO_RECORD_STOP);
//key(KEY_MACRO_PRESET_CYCLE);
//key(KEY_MACRO_PRESET1);
//key(KEY_MACRO_PRESET2);
//key(KEY_MACRO_PRESET3);
//key(KEY_KBD_LCD_MENU1);
//key(KEY_KBD_LCD_MENU2);
//key(KEY_KBD_LCD_MENU3);
//key(KEY_KBD_LCD_MENU4);
//key(KEY_KBD_LCD_MENU5);
key(KEY_ONSCREEN_KEYBOARD);
// key(KEY_PRIVACY_SCREEN_TOGGLE);
// key(KEY_SELECTIVE_SCREENSHOT);
// key(KEY_NEXT_ELEMENT);
// key(KEY_PREVIOUS_ELEMENT);
// key(KEY_AUTOPILOT_ENGAGE_TOGGLE);
// key(KEY_MARK_WAYPOINT);
// key(KEY_SOS);
// key(KEY_NAV_CHART);
// key(KEY_FISHING_CHART);
// key(KEY_SINGLE_RANGE_RADAR);
// key(KEY_DUAL_RANGE_RADAR);
// key(KEY_RADAR_OVERLAY);
// key(KEY_TRADITIONAL_SONAR);
// key(KEY_CLEARVU_SONAR);
// key(KEY_SIDEVU_SONAR);
// key(KEY_NAV_INFO);
// key(KEY_BRIGHTNESS_MENU);
// key(KEY_MACRO1);
// key(KEY_MACRO2);
// key(KEY_MACRO3);
// key(KEY_MACRO4);
// key(KEY_MACRO5);
// key(KEY_MACRO6);
// key(KEY_MACRO7);
// key(KEY_MACRO8);
// key(KEY_MACRO9);
// key(KEY_MACRO10);
// key(KEY_MACRO11);
// key(KEY_MACRO12);
// key(KEY_MACRO13);
// key(KEY_MACRO14);
// key(KEY_MACRO15);
// key(KEY_MACRO16);
// key(KEY_MACRO17);
// key(KEY_MACRO18);
// key(KEY_MACRO19);
// key(KEY_MACRO20);
// key(KEY_MACRO21);
// key(KEY_MACRO22);
// key(KEY_MACRO23);
// key(KEY_MACRO24);
// key(KEY_MACRO25);
// key(KEY_MACRO26);
// key(KEY_MACRO27);
// key(KEY_MACRO28);
// key(KEY_MACRO29);
// key(KEY_MACRO30);
// key(KEY_MACRO_RECORD_START);
// key(KEY_MACRO_RECORD_STOP);
// key(KEY_MACRO_PRESET_CYCLE);
// key(KEY_MACRO_PRESET1);
// key(KEY_MACRO_PRESET2);
// key(KEY_MACRO_PRESET3);
// key(KEY_KBD_LCD_MENU1);
// key(KEY_KBD_LCD_MENU2);
// key(KEY_KBD_LCD_MENU3);
// key(KEY_KBD_LCD_MENU4);
// key(KEY_KBD_LCD_MENU5);
key(KEY_MIN_INTERESTING);
key(KEY_MAX);
key(KEY_CNT);
Expand Down Expand Up @@ -731,7 +731,7 @@ bool process_EV_KEY(const QStringList& args){
key(BTN_TOOL_MOUSE);
key(BTN_TOOL_LENS);
key(BTN_TOOL_QUINTTAP);
//key(BTN_STYLUS3);
key(BTN_STYLUS3);
key(BTN_TOUCH);
key(BTN_STYLUS);
key(BTN_STYLUS2);
Expand Down
6 changes: 3 additions & 3 deletions applications/system-service/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ void Application::uninterruptApplication(){
case Background:
case Backgroundable:
if(stateNoSecurityCheck() == Paused){
touchHandler->clear_buffer();
systemAPI->clearDeviceBuffers();
kill(-m_process->processId(), SIGCONT);
}
qDebug() << "Waiting for SIGUSR1 ack";
Expand All @@ -303,7 +303,7 @@ void Application::uninterruptApplication(){
break;
case Foreground:
default:
touchHandler->clear_buffer();
systemAPI->clearDeviceBuffers();
kill(-m_process->processId(), SIGCONT);
startSpan("foreground", "Application is in the foreground");
}
Expand Down Expand Up @@ -339,7 +339,7 @@ void Application::stopNoSecurityCheck(){
Application* pausedApplication = nullptr;
if(state == Paused){
Oxide::Sentry::sentry_span(t, "resume", "Resume paused application", [this, &pausedApplication](){
touchHandler->clear_buffer();
systemAPI->clearDeviceBuffers();
auto currentApplication = appsAPI->currentApplicationNoSecurityCheck();
if(currentApplication.path() != path()){
pausedApplication = appsAPI->getApplication(currentApplication);
Expand Down
4 changes: 3 additions & 1 deletion applications/system-service/buttonhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,11 @@ void ButtonHandler::clear_buffer(){
#ifdef DEBUG
qDebug() << "Clearing event buffer on" << buttons.device.c_str();
#endif
::write(buttons.fd, flood, 512 * 8 * 4 * sizeof(input_event));
::write(buttons.fd, flood, EVENT_FLOOD_SIZE);
}

input_event* ButtonHandler::event_flood(){ return flood; }

void ButtonHandler::run(){
char name[256];
memset(name, 0, sizeof(name));
Expand Down
2 changes: 2 additions & 0 deletions applications/system-service/buttonhandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ using namespace std;
using namespace Oxide;

#define buttonHandler ButtonHandler::init()
#define EVENT_FLOOD_SIZE 512 * 8 * 4 * sizeof(input_event)

struct PressRecord {
bool pressed = false;
Expand All @@ -51,6 +52,7 @@ class ButtonHandler : public QThread {
ButtonHandler();
void setEnabled(bool enabled);
void clear_buffer();
input_event* event_flood();

public slots:
void pressKey(Qt::Key);
Expand Down
71 changes: 71 additions & 0 deletions applications/system-service/keyboarddevice.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#include "keyboarddevice.h"
#include "buttonhandler.h"
#include "keyboardhandler.h"

KeyboardDevice::KeyboardDevice(QThread* handler, event_device device)
: QObject(handler),
device(device),
sys("/sys/class/input/" + devName() + "/device/")
{
moveToThread(handler);
_name = sys.strProperty("name").c_str();
device.lock();
notifier = new QSocketNotifier(device.fd, QSocketNotifier::Read, this);
connect(notifier, &QSocketNotifier::activated, this, &KeyboardDevice::readEvents);
notifier->setEnabled(true);
}

KeyboardDevice::~KeyboardDevice(){
if(exists() && device.locked){
device.unlock();
}
}

QString KeyboardDevice::devName(){ return QFileInfo(device.device.c_str()).baseName(); }

QString KeyboardDevice::name(){ return _name; }

QString KeyboardDevice::path(){ return device.device.c_str(); }

QString KeyboardDevice::id(){
return QString("%1:%2")
.arg(sys.strProperty("id/vendor").c_str())
.arg(sys.strProperty("id/product").c_str());
}

bool KeyboardDevice::exists(){ return QFile::exists(path()); }

void KeyboardDevice::flood(){
if(device.fd == -1 || !device.locked){
return;
}
::write(device.fd, buttonHandler->event_flood(), EVENT_FLOOD_SIZE);
}

void KeyboardDevice::readEvents(){
notifier->setEnabled(false);
input_event event;
while(::read(device.fd, &event, sizeof(input_event)) > 0){

Check notice on line 48 in applications/system-service/keyboarddevice.cpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

applications/system-service/keyboarddevice.cpp#L48

Check buffer boundaries if used in a loop including recursive loops (CWE-120, CWE-20).
switch(event.type){
case EV_KEY:
pressed[event.code] = event.value;
break;
case EV_SYN:
switch(event.code){
case SYN_DROPPED:
pressed.clear();
break;
case SYN_REPORT:
auto handler = static_cast<KeyboardHandler*>(parent());
for(auto code : pressed.keys()){
handler->writeEvent(EV_KEY, code, pressed[code]);
}
handler->writeEvent(EV_SYN, SYN_REPORT, 0);
pressed.clear();
break;
}
break;
}
}
notifier->setEnabled(true);
}
30 changes: 30 additions & 0 deletions applications/system-service/keyboarddevice.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#pragma once

#include <liboxide/event_device.h>
#include <liboxide/sysobject.h>

using namespace Oxide;

class KeyboardDevice : public QObject{
Q_OBJECT

public:
KeyboardDevice(QThread* handler, event_device device);
~KeyboardDevice();
QString devName();
QString name();
QString path();
QString id();
bool exists();
void flood();

public slots:
void readEvents();

private:
event_device device;
SysObject sys;
QString _name;
QSocketNotifier* notifier;
QMap<int, bool> pressed;
};
Loading

0 comments on commit 1683bd6

Please sign in to comment.