From 7f8788a77ff1757a8991603aefa7b62f539ce9b4 Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Fri, 15 Nov 2024 14:41:59 +0100 Subject: [PATCH] ProjectExplorer: Add IDevice::portsGatheringRecipe() It's going to replace portsGatheringMethod(). Using recipe is more general and it enables many process runs or using different task types, e.g. NetworkQueryTask. Change-Id: Ic330a41cf3b5268e0f763b1b7584dbe1d689671e Reviewed-by: Christian Kandeler --- src/plugins/android/androiddevice.cpp | 30 +++++++++++++++++++ src/plugins/android/androiddevice.h | 2 ++ .../projectexplorer/devicesupport/idevice.cpp | 21 +++++++++++-- .../projectexplorer/devicesupport/idevice.h | 3 ++ 4 files changed, 54 insertions(+), 2 deletions(-) diff --git a/src/plugins/android/androiddevice.cpp b/src/plugins/android/androiddevice.cpp index 363646f0006..0d5fb804c73 100644 --- a/src/plugins/android/androiddevice.cpp +++ b/src/plugins/android/androiddevice.cpp @@ -23,6 +23,8 @@ #include #include +#include + #include #include #include @@ -625,6 +627,34 @@ DeviceProcessSignalOperation::Ptr AndroidDevice::signalOperation() const return DeviceProcessSignalOperation::Ptr(new AndroidSignalOperation()); } +ExecutableItem AndroidDevice::portsGatheringRecipe(const Storage &output) const +{ + const Storage serialNumberStorage; + const Storage input; + + const auto hasSerialNumber = [this, serialNumberStorage] { + if (machineType() == Hardware) + *serialNumberStorage = extraData(Constants::AndroidSerialNumber).toString(); + return machineType() == Hardware; + }; + + const auto onSerialNumberSetup = [this, input, serialNumberStorage] { + const CommandLine cmd{AndroidConfig::adbToolPath(), + {adbSelector(*serialNumberStorage), "shell" , "netstat", "-a", "-n" }}; + *input = {freePorts(), cmd}; + }; + + return Group { + serialNumberStorage, + input, + If (!Sync(hasSerialNumber)) >> Then { + serialNumberRecipe(avdName(), serialNumberStorage), + }, + Sync(onSerialNumberSetup), + portsFromProcessRecipe(input, output) + }; +} + PortsGatheringMethod AndroidDevice::portsGatheringMethod() const { return { diff --git a/src/plugins/android/androiddevice.h b/src/plugins/android/androiddevice.h index 3ae700e6347..eca0fb7d09b 100644 --- a/src/plugins/android/androiddevice.h +++ b/src/plugins/android/androiddevice.h @@ -58,6 +58,8 @@ private: ProjectExplorer::IDeviceWidget *createWidget() override; ProjectExplorer::DeviceProcessSignalOperation::Ptr signalOperation() const override; QUrl toolControlChannel(const ControlChannelHint &) const override; + Tasking::ExecutableItem portsGatheringRecipe( + const Tasking::Storage &output) const override; ProjectExplorer::PortsGatheringMethod portsGatheringMethod() const override; QSettings *avdSettings() const; diff --git a/src/plugins/projectexplorer/devicesupport/idevice.cpp b/src/plugins/projectexplorer/devicesupport/idevice.cpp index 94baa513daf..0ac286d7dbf 100644 --- a/src/plugins/projectexplorer/devicesupport/idevice.cpp +++ b/src/plugins/projectexplorer/devicesupport/idevice.cpp @@ -83,6 +83,7 @@ * Creates an identical copy of a device object. */ +using namespace Tasking; using namespace Utils; namespace ProjectExplorer { @@ -439,6 +440,24 @@ const QList IDevice::deviceActions() const return d->deviceActions; } +ExecutableItem IDevice::portsGatheringRecipe(const Storage &output) const +{ + const Storage input; + + const auto onSetup = [this, input] { + const CommandLine cmd = filePath("/proc/net").isReadableDir() + ? CommandLine{filePath("/bin/sh"), {"-c", "cat /proc/net/tcp*"}} + : CommandLine{filePath("netstat"), {"-a", "-n"}}; + *input = {freePorts(), cmd}; + }; + + return Group { + input, + onGroupSetup(onSetup), + portsFromProcessRecipe(input, output) + }; +} + PortsGatheringMethod IDevice::portsGatheringMethod() const { return {[this](QAbstractSocket::NetworkLayerProtocol protocol) -> CommandLine { @@ -757,8 +776,6 @@ void DeviceProcessSignalOperation::setDebuggerCommand(const FilePath &cmd) DeviceProcessSignalOperation::DeviceProcessSignalOperation() = default; -using namespace Tasking; - void DeviceProcessKiller::start() { m_signalOperation.reset(); diff --git a/src/plugins/projectexplorer/devicesupport/idevice.h b/src/plugins/projectexplorer/devicesupport/idevice.h index fb1fd2b1196..d672b8222d3 100644 --- a/src/plugins/projectexplorer/devicesupport/idevice.h +++ b/src/plugins/projectexplorer/devicesupport/idevice.h @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -140,6 +141,8 @@ public: void addDeviceAction(const DeviceAction &deviceAction); const QList deviceActions() const; + virtual Tasking::ExecutableItem portsGatheringRecipe( + const Tasking::Storage &output) const; virtual PortsGatheringMethod portsGatheringMethod() const; virtual bool canCreateProcessModel() const { return false; } virtual bool hasDeviceTester() const { return false; }