From 5ef648fe02a27f673cb849b1ab566fa1687e1bfe Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Sun, 28 Mar 2021 03:53:03 -0700 Subject: [PATCH] filter out touches while in android activity (#20515) * filter touches while in android activity * only check after launching activity * move to hw abstraction layer * little cleanup * remove print Co-authored-by: Comma Device old-commit-hash: a2084c2a601ba138c41494420f8275295357981f --- selfdrive/hardware/eon/hardware.h | 22 ++++++++++++++++++++++ selfdrive/ui/qt/offroad/settings.cc | 15 +++------------ selfdrive/ui/qt/window.cc | 13 +++++++++++++ 3 files changed, 38 insertions(+), 12 deletions(-) diff --git a/selfdrive/hardware/eon/hardware.h b/selfdrive/hardware/eon/hardware.h index 70e9144c33..bcf99a6284 100644 --- a/selfdrive/hardware/eon/hardware.h +++ b/selfdrive/hardware/eon/hardware.h @@ -40,4 +40,26 @@ public: std::string cmd = util::string_format("setprop persist.neos.ssh %d", enabled ? 1 : 0); std::system(cmd.c_str()); }; + + // android only + inline static bool launched_activity = false; + static void check_activity() { + int ret = std::system("dumpsys SurfaceFlinger --list | grep -Fq 'com.android.settings'"); + launched_activity = ret == 0; + } + static void launch_activity(std::string activity, std::string opts = "") { + if (!launched_activity) { + std::string cmd = "am start -n " + activity + " " + opts + + " --ez extra_prefs_show_button_bar true \ + --es extra_prefs_set_next_text ''"; + std::system(cmd.c_str()); + } + launched_activity = true; + } + static void launch_wifi() { + launch_activity("com.android.settings/.wifi.WifiPickerActivity", "-a android.net.wifi.PICK_WIFI_NETWORK"); + } + static void launch_tethering() { + launch_activity("com.android.settings/.TetherSettings"); + } }; diff --git a/selfdrive/ui/qt/offroad/settings.cc b/selfdrive/ui/qt/offroad/settings.cc index 67b90aed14..94f2ae43a5 100644 --- a/selfdrive/ui/qt/offroad/settings.cc +++ b/selfdrive/ui/qt/offroad/settings.cc @@ -203,22 +203,13 @@ QWidget * network_panel(QWidget * parent) { layout->setMargin(100); layout->setSpacing(30); - // simple wifi + tethering buttons - const char* launch_wifi = "am start -n com.android.settings/.wifi.WifiPickerActivity \ - -a android.net.wifi.PICK_WIFI_NETWORK \ - --ez extra_prefs_show_button_bar true \ - --es extra_prefs_set_next_text ''"; + // wifi + tethering buttons layout->addWidget(new ButtonControl("WiFi Settings", "OPEN", "", - [=]() { std::system(launch_wifi); })); - + [=]() { HardwareEon::launch_wifi(); })); layout->addWidget(horizontal_line()); - const char* launch_tethering = "am start -n com.android.settings/.TetherSettings \ - --ez extra_prefs_show_button_bar true \ - --es extra_prefs_set_next_text ''"; layout->addWidget(new ButtonControl("Tethering Settings", "OPEN", "", - [=]() { std::system(launch_tethering); })); - + [=]() { HardwareEon::launch_tethering(); })); layout->addWidget(horizontal_line()); // SSH key management diff --git a/selfdrive/ui/qt/window.cc b/selfdrive/ui/qt/window.cc index 0a783b57b8..5205acdb99 100644 --- a/selfdrive/ui/qt/window.cc +++ b/selfdrive/ui/qt/window.cc @@ -1,4 +1,5 @@ #include "window.hpp" +#include "selfdrive/hardware/hw.h" MainWindow::MainWindow(QWidget *parent) : QWidget(parent) { main_layout = new QStackedLayout; @@ -54,8 +55,20 @@ void MainWindow::reviewTrainingGuide() { } bool MainWindow::eventFilter(QObject *obj, QEvent *event){ + // wake screen on tap if (event->type() == QEvent::MouseButtonPress) { homeWindow->glWindow->wake(); } + + // filter out touches while in android activity +#ifdef QCOM + const QList filter_events = {QEvent::MouseButtonPress, QEvent::MouseMove, QEvent::TouchBegin, QEvent::TouchUpdate, QEvent::TouchEnd}; + if (HardwareEon::launched_activity && filter_events.contains(event->type())) { + HardwareEon::check_activity(); + if (HardwareEon::launched_activity) { + return true; + } + } +#endif return false; }