From bd2347fd5733565a4e6101cbd4bf4cd0af667088 Mon Sep 17 00:00:00 2001 From: Robert Tari Date: Wed, 11 Aug 2021 23:46:45 +0200 Subject: Check for ADBD socket before creating UsbManager fixes https://github.com/AyatanaIndicators/ayatana-indicator-display/issues/13 --- src/main.cpp | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 004b21d..f145504 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -28,6 +28,8 @@ #include #include +#include +#include extern "C" { @@ -63,15 +65,31 @@ main(int /*argc*/, char** /*argv*/) exporters.push_back(exporter); } + gboolean bHasSocket = FALSE; + if (ayatana_common_utils_is_lomiri()) { - // We need the ADBD handler running, - // even though it doesn't have an indicator component yet - static constexpr char const * ADB_SOCKET_PATH {"/dev/socket/adbd"}; - static constexpr char const * PUBLIC_KEYS_FILENAME {"/data/misc/adb/adb_keys"}; - auto usb_monitor = std::make_shared(); - auto greeter = std::make_shared(); - UsbManager usb_manager {ADB_SOCKET_PATH, PUBLIC_KEYS_FILENAME, usb_monitor, greeter}; + struct stat cStat; + + if (stat("/dev/socket/adbd", &cStat) == 0) + { + if (S_ISSOCK(cStat.st_mode)) + { + // We need the ADBD handler running, + // even though it doesn't have an indicator component yet + static constexpr char const * ADB_SOCKET_PATH {"/dev/socket/adbd"}; + static constexpr char const * PUBLIC_KEYS_FILENAME {"/data/misc/adb/adb_keys"}; + auto usb_monitor = std::make_shared(); + auto greeter = std::make_shared(); + UsbManager usb_manager {ADB_SOCKET_PATH, PUBLIC_KEYS_FILENAME, usb_monitor, greeter}; + bHasSocket = TRUE; + } + } + } + + if (bHasSocket == FALSE) + { + g_message("No /dev/socket/adbd socket found, skipping UsbManager"); } // let's go! -- cgit v1.2.3