From 49c171664f6955257dcd5da5fb59601adfcabaeb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Witos=C5=82awski?= Date: Thu, 7 Jan 2021 03:52:21 +0100 Subject: [PATCH] Fix for issue "Suspend causes oxide to crash on RM2 #113" (#114) * Fix for issue "Suspend causes oxide to crash on RM2 #113" Co-authored-by: Piotr Witoslawski --- applications/system-service/screenapi.h | 4 +--- applications/system-service/systemapi.cpp | 9 +++++++++ applications/system-service/wlan.h | 14 ++++++++++++-- shared/devicesettings.h | 1 - 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/applications/system-service/screenapi.h b/applications/system-service/screenapi.h index c693824a1..899da159d 100644 --- a/applications/system-service/screenapi.h +++ b/applications/system-service/screenapi.h @@ -17,15 +17,13 @@ #include "stb_image.h" #include "stb_image_write.h" #include "fb2png.h" +#include "devicesettings.h" #define DISPLAYWIDTH 1404 #define DISPLAYHEIGHT 1872 #define TEMP_USE_REMARKABLE_DRAW 0x0018 #define remarkable_color uint16_t #define DISPLAYSIZE DISPLAYWIDTH * DISPLAYHEIGHT * sizeof(remarkable_color) -#define RDISPLAYWIDTH 1408 -#define RDISPLAYHEIGHT 1920 -#define RDISPLAYSIZE RDISPLAYWIDTH * RDISPLAYHEIGHT * sizeof(remarkable_color) #define screenAPI ScreenAPI::singleton() diff --git a/applications/system-service/systemapi.cpp b/applications/system-service/systemapi.cpp index cb5943a25..0ed119b71 100644 --- a/applications/system-service/systemapi.cpp +++ b/applications/system-service/systemapi.cpp @@ -1,6 +1,7 @@ #include "systemapi.h" #include "appsapi.h" #include "powerapi.h" +#include "devicesettings.h" void SystemAPI::PrepareForSleep(bool suspending){ if(suspending){ @@ -14,10 +15,18 @@ void SystemAPI::PrepareForSleep(bool suspending){ drawSleepImage(); qDebug() << "Suspending..."; buttonHandler->setEnabled(false); + if (DeviceSettings::instance().getDeviceType() == DeviceType::RM2) { + qDebug() << "Removing module"; + qDebug() << "Exit code: " << system("rmmod brcmfmac"); + } releaseSleepInhibitors(); }else{ inhibitSleep(); qDebug() << "Resuming..."; + if (DeviceSettings::instance().getDeviceType() == DeviceType::RM2) { + qDebug() << "Inserting module"; + qDebug() << "Exit code: " << system("modprobe brcmfmac"); + } QCoreApplication::processEvents(QEventLoop::AllEvents, 100); if(resumeApp == nullptr){ resumeApp = appsAPI->getApplication(appsAPI->startupApplication()); diff --git a/applications/system-service/wlan.h b/applications/system-service/wlan.h index 1ad249efb..949c12949 100644 --- a/applications/system-service/wlan.h +++ b/applications/system-service/wlan.h @@ -33,12 +33,22 @@ class Wlan : public QObject, public SysObject { } return ""; } + bool pingIP(std::string ip, const char* port) { + return !system(("echo -n > /dev/tcp/" + ip.substr(0, ip.length() - 1) + "/" + port).c_str()); + } bool isConnected(){ auto ip = exec("ip r | grep " + iface() + " | grep default | awk '{print $3}'"); - return ip != "" && !system(("echo -n > /dev/tcp/" + ip.substr(0, ip.length() - 1) + "/53").c_str()); + return ip != "" && (pingIP(ip, "53") || pingIP(ip, "80")); } int link(){ - return std::stoi(exec("cat /proc/net/wireless | grep " + iface() + " | awk '{print $3}'")); + std::string out = exec("cat /proc/net/wireless | grep " + iface() + " | awk '{print $3}'"); + try { + return std::stoi(out); + } + catch (const std::invalid_argument& e) { + qDebug() << "link failed: " << out.c_str(); + return 0; + } } signals: void BSSAdded(Wlan*, QDBusObjectPath, QVariantMap); diff --git a/shared/devicesettings.h b/shared/devicesettings.h index fcc125e06..0ebbd8b7d 100644 --- a/shared/devicesettings.h +++ b/shared/devicesettings.h @@ -24,5 +24,4 @@ class DeviceSettings{ const char* getTouchDevicePath() const; const char* getTouchEnvSetting() const; DeviceType getDeviceType() const; - };