From cc03650a4f3f93857e08e535b73b73f0fd5f1613 Mon Sep 17 00:00:00 2001 From: Daekwang Ryu Date: Thu, 6 Apr 2023 14:16:21 +0900 Subject: [PATCH] Move getWindowRoot() implementation to DeviceImpl The getTizenWindowInfo function depends on Tizen platform. It has been moved to TizenDeviceImpl. This change helps in running and implementing UTC. Change-Id: Icfe725a21e9178244ae7b9698c1be13fa60efb95 --- libaurum/inc/Impl/MockDeviceImpl.h | 6 + libaurum/inc/Impl/TizenDeviceImpl.h | 16 +++ libaurum/inc/{ => Impl}/TizenWindow.h | 0 libaurum/inc/Interface/IDevice.h | 11 ++ libaurum/inc/UiDevice.h | 13 +-- libaurum/meson.build | 1 - libaurum/src/Impl/MockDeviceImpl.cc | 22 +++- libaurum/src/Impl/TizenDeviceImpl.cc | 149 +++++++++++++++++++++++++ libaurum/src/{ => Impl}/TizenWindow.cc | 0 libaurum/src/Impl/meson.build | 1 + libaurum/src/UiDevice.cc | 147 +----------------------- libaurum/src/meson.build | 1 - 12 files changed, 206 insertions(+), 161 deletions(-) rename libaurum/inc/{ => Impl}/TizenWindow.h (100%) rename libaurum/src/{ => Impl}/TizenWindow.cc (100%) diff --git a/libaurum/inc/Impl/MockDeviceImpl.h b/libaurum/inc/Impl/MockDeviceImpl.h index 4631912..e387a8e 100644 --- a/libaurum/inc/Impl/MockDeviceImpl.h +++ b/libaurum/inc/Impl/MockDeviceImpl.h @@ -19,6 +19,7 @@ #define _MOCK_DEVICE_IMPL_H_ #include "config.h" +#include "AccessibleNode.h" #include "IDevice.h" #include @@ -173,6 +174,11 @@ public: */ const Size2D getScreenSize() override; + /** + * @copydoc IDevice::getWindowRoot() + */ + std::vector> getWindowRoot() const override; + protected: /** * @brief TBD diff --git a/libaurum/inc/Impl/TizenDeviceImpl.h b/libaurum/inc/Impl/TizenDeviceImpl.h index 774841c..e73a564 100644 --- a/libaurum/inc/Impl/TizenDeviceImpl.h +++ b/libaurum/inc/Impl/TizenDeviceImpl.h @@ -20,6 +20,7 @@ #include "config.h" #include "IDevice.h" +#include "TizenWindow.h" #include #include @@ -135,6 +136,11 @@ public: */ const Size2D getScreenSize() override; + /** + * @copydoc IDevice::getWindowRoot() + */ + std::vector> getWindowRoot() const override; + protected: /** * @brief Press and release given key during duration time. @@ -186,6 +192,15 @@ private: */ int stopTimer(void); + /** + * @brief Gets currently window information from window system. + * + * @return TizenWindow ptr vector + * + * @since_tizen 7.0 + */ + std::vector> getTizenWindowInfo() const; + private: efl_util_inputgen_h mFakeTouchHandle; efl_util_inputgen_h mFakeKeyboardHandle; @@ -209,6 +224,7 @@ private: */ Size2D mScreenSize; static std::mutex CaptureMutex; + static std::vector> mTizenWindows; }; } diff --git a/libaurum/inc/TizenWindow.h b/libaurum/inc/Impl/TizenWindow.h similarity index 100% rename from libaurum/inc/TizenWindow.h rename to libaurum/inc/Impl/TizenWindow.h diff --git a/libaurum/inc/Interface/IDevice.h b/libaurum/inc/Interface/IDevice.h index e501b7e..5dc6314 100644 --- a/libaurum/inc/Interface/IDevice.h +++ b/libaurum/inc/Interface/IDevice.h @@ -20,8 +20,10 @@ #include "config.h" #include "Size2D.h" +#include "AccessibleNode.h" #include + namespace Aurum { /** @@ -290,6 +292,15 @@ public: * @since_tizen 6.5 */ virtual const Size2D getScreenSize() = 0; + + /** + * @brief Gets currently enabled applications root window. + * + * @return AccessibleNode ptr vector + * + * @since_tizen 7.5 + */ + virtual std::vector> getWindowRoot() const = 0; }; } diff --git a/libaurum/inc/UiDevice.h b/libaurum/inc/UiDevice.h index 1c6a49b..f1369df 100644 --- a/libaurum/inc/UiDevice.h +++ b/libaurum/inc/UiDevice.h @@ -22,7 +22,6 @@ #include "UiObject.h" #include "UiSelector.h" -#include "TizenWindow.h" #include "IDevice.h" #include "ISearchable.h" @@ -403,16 +402,7 @@ public: * * @since_tizen 6.5 */ - std::vector> getWindowRoot() const; - - /** - * @brief Gets currently window information from window system. - * - * @return TizenWindow ptr vector - * - * @since_tizen 7.0 - */ - std::vector> getTizenWindowInfo() const; + std::vector> getWindowRoot() const override; #ifdef MQTT_ENABLED /** @@ -501,7 +491,6 @@ public: private: IDevice *mDeviceImpl; const Waiter *mWaiter; - static std::vector> mTizenWindows; bool mIsWithSA; #ifdef MQTT_ENABLED static std::shared_ptr mSAWatcher; diff --git a/libaurum/meson.build b/libaurum/meson.build index 58e8e18..7e31175 100644 --- a/libaurum/meson.build +++ b/libaurum/meson.build @@ -4,7 +4,6 @@ libaurum_install_inc = [ './inc/UiDevice.h', './inc/UiObject.h', './inc/UiSelector.h', - './inc/TizenWindow.h', './inc/Sel.h', './inc/Until.h', './inc/Waiter.h', diff --git a/libaurum/src/Impl/MockDeviceImpl.cc b/libaurum/src/Impl/MockDeviceImpl.cc index 3d3ea8f..1f4c8dd 100644 --- a/libaurum/src/Impl/MockDeviceImpl.cc +++ b/libaurum/src/Impl/MockDeviceImpl.cc @@ -16,7 +16,7 @@ */ #include "Aurum.h" - +#include "AccessibleWatcher.h" #include "MockDeviceImpl.h" #include @@ -265,3 +265,23 @@ long long MockDeviceImpl::timeStamp(void) long long rtn = (t.tv_sec + t.tv_nsec/NANO_SEC) * MICRO_SEC; return rtn; } + +std::vector> MockDeviceImpl::getWindowRoot() const +{ + std::vector> ret{}; + + auto apps = AccessibleWatcher::getInstance()->getApplications(); + + for (auto app : apps) + { + auto wins = app->getWindows(); + std::transform(wins.begin(), wins.end(), std::back_inserter(ret), + [&](std::shared_ptr window) { + return window->getAccessibleNode(); + } + ); + } + + return ret; +} + diff --git a/libaurum/src/Impl/TizenDeviceImpl.cc b/libaurum/src/Impl/TizenDeviceImpl.cc index 273bd9c..84ac438 100644 --- a/libaurum/src/Impl/TizenDeviceImpl.cc +++ b/libaurum/src/Impl/TizenDeviceImpl.cc @@ -31,6 +31,7 @@ #include #include #include +#include using namespace Aurum; using namespace AurumInternal; @@ -38,8 +39,14 @@ using namespace AurumInternal; #define NANO_SEC 1000000000.0 #define MICRO_SEC 1000000 +#define WM_BUS_NAME "org.enlightenment.wm" +#define WM_OBJECT_PATH "/org/enlightenment/wm" +#define WM_INTERFACE_NAME "org.enlightenment.wm.proc" +#define WM_METHOD_NAME_INFO "GetVisibleWinInfo_v2" std::mutex TizenDeviceImpl::CaptureMutex = std::mutex{}; +std::vector> TizenDeviceImpl::mTizenWindows; +static GDBusConnection *system_conn; TizenDeviceImpl::TizenDeviceImpl() : mFakeTouchHandle{0}, mFakeKeyboardHandle{0}, mFakeWheelHandle{0}, tStart{}, isTimerStarted{false}, mTouchSeq{} @@ -422,3 +429,145 @@ bool TizenDeviceImpl::releaseTouchSeqNumber(int seq) } return false; } + +std::vector> TizenDeviceImpl::getWindowRoot() const +{ + LOGI("Request window info"); + getTizenWindowInfo(); + + std::vector> ret{}; + std::unordered_map> pidToAppNode{}; + + auto apps = AccessibleWatcher::getInstance()->getApplications(); + for (auto app : apps) + { + app->getAccessibleNode()->updateName(); + app->getAccessibleNode()->updatePid(); + LOGI("App(%s) Pid(%d)", app->getPackageName().c_str(), app->getAccessibleNode()->getPid()); + pidToAppNode[app->getAccessibleNode()->getPid()] = app; + } + + for (auto tWin : mTizenWindows) + { + LOGI("Visible win (%d) (%d %d %d %d) (%s)", tWin->getPid(), tWin->getWindowGeometry().mTopLeft.x, tWin->getWindowGeometry().mTopLeft.y, tWin->getWindowGeometry().width(), + tWin->getWindowGeometry().height(), tWin->getName().c_str()); + + if (pidToAppNode.count(tWin->getPid()) == 0) continue; + + LOGI("Active App : (%s) (%d)", tWin->getName().c_str(), tWin->getPid()); + auto wins = pidToAppNode[tWin->getPid()]->getWindows(); + std::transform(wins.begin(), wins.end(), std::back_inserter(ret), + [&](std::shared_ptr window) { + window->getAccessibleNode()->updateApplication(); + LOGI("Target window add pkg: (%s), name (%s)", window->getAccessibleNode()->getPkg().c_str(), window->getTitle().c_str()); + return window->getAccessibleNode(); + } + ); + + pidToAppNode.erase(tWin->getPid()); + } + + return ret; +} + +std::vector> TizenDeviceImpl::getTizenWindowInfo() const +{ + GError *err = NULL; + GDBusMessage *msg; + GDBusMessage *reply; + GDBusConnection *conn; + GVariant *body; + GVariantIter *iter = NULL; + int idx = 0; + int pid; + int x; + int y; + int w; + int h; + gboolean transformed; + gboolean alpha; + int opaque; + int visibility; + gboolean focused; + gboolean mapped; + int layer; + char *name; + + mTizenWindows.clear(); + + if (system_conn == NULL) { + conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err); + if (conn == NULL) { + LOGE("g_bus_get_sync() is failed. %s", err->message); + g_error_free(err); + return mTizenWindows; + } + system_conn = conn; + } + + msg = g_dbus_message_new_method_call(WM_BUS_NAME, + WM_OBJECT_PATH, + WM_INTERFACE_NAME, + WM_METHOD_NAME_INFO); + if (msg == NULL) { + LOGE("g_dbus_message_new_method_call() is failed."); + return mTizenWindows; + } + + reply = g_dbus_connection_send_message_with_reply_sync(system_conn, msg, + G_DBUS_SEND_MESSAGE_FLAGS_NONE, -1, NULL, NULL, &err); + + if (!reply) { + if (err != NULL) { + LOGE("Failed to get info [%s]", err->message); + g_error_free(err); + } + goto out; + } + + body = g_dbus_message_get_body(reply); + if (!body) { + LOGE("Failed to get body"); + goto out; + } + + g_variant_get(body, "(a(iiiiibbiibbis))", &iter); + if (!iter) { + LOGE("Failed to get iter"); + goto out; + } + + LOGI("%-3s | %-6s | %-4s | %-4s | %-4s | %-4s | %-5s | %-5s | %-6s | %-3s | %-7s | %-6s | %-5s | %-20s", "No" ,"PID", "X", "Y", "W", "H", "Trans", "Alpha", "Opaque", "Vis", "Focused", "Mapped", "Layer", "Name"); + while (g_variant_iter_loop(iter, "(iiiiibbiibbis)", + &pid, + &x, + &y, + &w, + &h, + &transformed, + &alpha, + &opaque, + &visibility, + &focused, + &mapped, + &layer, + &name)) { + LOGI("%-3d | %-6d | %-4d | %-4d | %-4d | %-4d | %-5d | %-5d | %-6d | %-3d | %-7d | %-6d | %-5d | %-20s", idx++, pid, x,y,w,h, transformed, alpha, opaque, visibility, focused, mapped, layer, name); + if (visibility == 0 && pid > 0) + { + Rect geometry = {x, y, w, h}; + std::string winName(name); + mTizenWindows.push_back(std::make_shared(pid, geometry, transformed, alpha, opaque, visibility, focused, mapped, layer, winName)); + } + } + +out: + if (iter) + g_variant_iter_free(iter); + if (msg) + g_object_unref(msg); + if (reply) + g_object_unref(reply); + + return mTizenWindows; +} diff --git a/libaurum/src/TizenWindow.cc b/libaurum/src/Impl/TizenWindow.cc similarity index 100% rename from libaurum/src/TizenWindow.cc rename to libaurum/src/Impl/TizenWindow.cc diff --git a/libaurum/src/Impl/meson.build b/libaurum/src/Impl/meson.build index 04bdacc..6feed58 100644 --- a/libaurum/src/Impl/meson.build +++ b/libaurum/src/Impl/meson.build @@ -1,6 +1,7 @@ if get_option('tizen') == true libaurum_src += [ files('TizenDeviceImpl.cc'), + files('TizenWindow.cc'), ] endif diff --git a/libaurum/src/UiDevice.cc b/libaurum/src/UiDevice.cc index 7438bbf..a8f40e7 100644 --- a/libaurum/src/UiDevice.cc +++ b/libaurum/src/UiDevice.cc @@ -29,21 +29,13 @@ #include #include #include -#include #include #include using namespace Aurum; using namespace AurumInternal; -#define WM_BUS_NAME "org.enlightenment.wm" -#define WM_OBJECT_PATH "/org/enlightenment/wm" -#define WM_INTERFACE_NAME "org.enlightenment.wm.proc" -#define WM_METHOD_NAME_INFO "GetVisibleWinInfo_v2" - -std::vector> UiDevice::mTizenWindows; std::once_flag UiDevice::mOnceFlag; -static GDBusConnection *system_conn; #ifdef MQTT_ENABLED std::shared_ptr UiDevice::mSAWatcher; @@ -86,146 +78,9 @@ std::shared_ptr UiDevice::getInstance(IDevice *deviceImpl) return device; } -std::vector> UiDevice::getTizenWindowInfo() const -{ - GError *err = NULL; - GDBusMessage *msg; - GDBusMessage *reply; - GDBusConnection *conn; - GVariant *body; - GVariantIter *iter = NULL; - int idx = 0; - int pid; - int x; - int y; - int w; - int h; - gboolean transformed; - gboolean alpha; - int opaque; - int visibility; - gboolean focused; - gboolean mapped; - int layer; - char *name; - - mTizenWindows.clear(); - - if (system_conn == NULL) { - conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err); - if (conn == NULL) { - LOGE("g_bus_get_sync() is failed. %s", err->message); - g_error_free(err); - return mTizenWindows; - } - system_conn = conn; - } - - msg = g_dbus_message_new_method_call(WM_BUS_NAME, - WM_OBJECT_PATH, - WM_INTERFACE_NAME, - WM_METHOD_NAME_INFO); - if (msg == NULL) { - LOGE("g_dbus_message_new_method_call() is failed."); - return mTizenWindows; - } - - reply = g_dbus_connection_send_message_with_reply_sync(system_conn, msg, - G_DBUS_SEND_MESSAGE_FLAGS_NONE, -1, NULL, NULL, &err); - - if (!reply) { - if (err != NULL) { - LOGE("Failed to get info [%s]", err->message); - g_error_free(err); - } - goto out; - } - - body = g_dbus_message_get_body(reply); - if (!body) { - LOGE("Failed to get body"); - goto out; - } - - g_variant_get(body, "(a(iiiiibbiibbis))", &iter); - if (!iter) { - LOGE("Failed to get iter"); - goto out; - } - - LOGI("%-3s | %-6s | %-4s | %-4s | %-4s | %-4s | %-5s | %-5s | %-6s | %-3s | %-7s | %-6s | %-5s | %-20s", "No" ,"PID", "X", "Y", "W", "H", "Trans", "Alpha", "Opaque", "Vis", "Focused", "Mapped", "Layer", "Name"); - while (g_variant_iter_loop(iter, "(iiiiibbiibbis)", - &pid, - &x, - &y, - &w, - &h, - &transformed, - &alpha, - &opaque, - &visibility, - &focused, - &mapped, - &layer, - &name)) { - LOGI("%-3d | %-6d | %-4d | %-4d | %-4d | %-4d | %-5d | %-5d | %-6d | %-3d | %-7d | %-6d | %-5d | %-20s", idx++, pid, x,y,w,h, transformed, alpha, opaque, visibility, focused, mapped, layer, name); - if (visibility == 0 && pid > 0) - { - Rect geometry = {x, y, w, h}; - std::string winName(name); - mTizenWindows.push_back(std::make_shared(pid, geometry, transformed, alpha, opaque, visibility, focused, mapped, layer, winName)); - } - } - -out: - if (iter) - g_variant_iter_free(iter); - if (msg) - g_object_unref(msg); - if (reply) - g_object_unref(reply); - - return mTizenWindows; -} - std::vector> UiDevice::getWindowRoot() const { - LOGI("Request window info"); - getTizenWindowInfo(); - - std::vector> ret{}; - std::unordered_map> pidToAppNode{}; - - auto apps = AccessibleWatcher::getInstance()->getApplications(); - for (auto app : apps) - { - app->getAccessibleNode()->updateName(); - app->getAccessibleNode()->updatePid(); - LOGI("App(%s) Pid(%d)", app->getPackageName().c_str(), app->getAccessibleNode()->getPid()); - pidToAppNode[app->getAccessibleNode()->getPid()] = app; - } - - for (auto tWin : mTizenWindows) - { - LOGI("Visible win (%d) (%d %d %d %d) (%s)", tWin->getPid(), tWin->getWindowGeometry().mTopLeft.x, tWin->getWindowGeometry().mTopLeft.y, tWin->getWindowGeometry().width(), - tWin->getWindowGeometry().height(), tWin->getName().c_str()); - - if (pidToAppNode.count(tWin->getPid()) == 0) continue; - - LOGI("Active App : (%s) (%d)", tWin->getName().c_str(), tWin->getPid()); - auto wins = pidToAppNode[tWin->getPid()]->getWindows(); - std::transform(wins.begin(), wins.end(), std::back_inserter(ret), - [&](std::shared_ptr window) { - window->getAccessibleNode()->updateApplication(); - LOGI("Target window add pkg: (%s), name (%s)", window->getAccessibleNode()->getPkg().c_str(), window->getTitle().c_str()); - return window->getAccessibleNode(); - } - ); - - pidToAppNode.erase(tWin->getPid()); - } - - return ret; + return mDeviceImpl->getWindowRoot(); } bool UiDevice::hasObject(const std::shared_ptr selector) const diff --git a/libaurum/src/meson.build b/libaurum/src/meson.build index 7e6a215..caae22d 100644 --- a/libaurum/src/meson.build +++ b/libaurum/src/meson.build @@ -11,7 +11,6 @@ libaurum_src += [ files('A11yEvent.cc'), files('A11yEventHandler.cc'), files('AurumXML.cc'), - files('TizenWindow.cc'), ] if get_option('mqtt_enabled') == true -- 2.34.1