Aurum: findObject performance improvement 82/261382/4
authorWoochanlee <wc0917.lee@samsung.com>
Fri, 16 Jul 2021 07:50:21 +0000 (16:50 +0900)
committerwoochan lee <wc0917.lee@samsung.com>
Tue, 20 Jul 2021 05:35:55 +0000 (05:35 +0000)
Improved object search logic

as is -
 1. process list up <- performance degradation point
 2. active window list up
to be -
 1. activated window's process list up
 2. active window list up

Use runnable feature to look up window event when app launched.

Change-Id: I607ae2c20b594b256b2e7b23d5a32eaad90eb255

12 files changed:
libaurum/inc/Accessibility/AccessibleWatcher.h
libaurum/inc/Impl/Accessibility/AtspiAccessibleWatcher.h
libaurum/inc/Impl/Accessibility/MockAccessibleWatcher.h
libaurum/inc/UiDevice.h
libaurum/src/Impl/Accessibility/AtspiAccessibleWatcher.cc
libaurum/src/Impl/Accessibility/MockAccessibleWatcher.cc
libaurum/src/UiDevice.cc
org.tizen.aurum-bootstrap/inc/Commands/LaunchAppCommand.h
org.tizen.aurum-bootstrap/inc/Runnable/LaunchAppRunnable.h [new file with mode: 0644]
org.tizen.aurum-bootstrap/meson.build
org.tizen.aurum-bootstrap/src/Commands/LaunchAppCommand.cc
org.tizen.aurum-bootstrap/src/Runnable/LaunchAppRunnable.cc [new file with mode: 0644]

index d9869cdb4c755cb2aadf868c16b5f41ee41067ef..3090741747d9560ec111d1acdc2b2a827bfa15d8 100644 (file)
@@ -7,6 +7,7 @@
 #include "IEventSource.h"
 #include "Runnable.h"
 #include "A11yEvent.h"
+#include <atspi/atspi.h>
 
 #include <memory>
 #include <vector>
@@ -64,6 +65,7 @@ public:
      */
     virtual bool executeAndWaitForEvents(const Runnable *cmd, const A11yEvent type, const int timeout) = 0;
 
+    virtual std::map<AtspiAccessible *, std::shared_ptr<AccessibleApplication>> getActiveAppMap(void) = 0;
 public:
     /**
      * @brief TBD
index d0590b47c5907ddcd057d4506439883596347e04..663835fd1f32514117fc5cc356f7f2219ad58206 100644 (file)
@@ -2,6 +2,7 @@
 
 #include "AccessibleNode.h"
 #include "AccessibleWatcher.h"
+#include "AtspiAccessibleApplication.h"
 
 #include <atspi/atspi.h>
 #include <gio/gio.h>
@@ -104,6 +105,8 @@ public:
      */
     virtual bool executeAndWaitForEvents(const Runnable *cmd, const A11yEvent type, const int timeout) override;
 
+    virtual std::map<AtspiAccessible *, std::shared_ptr<AccessibleApplication>> getActiveAppMap(void) override;
+
 public:
     /**
      * @brief TBD
@@ -221,7 +224,7 @@ private:
     /**
      * @brief TBD
      */
-    std::map<AtspiAccessible *, AtspiAccessible *> mWindowAppMap;
+    std::map<AtspiAccessible *, std::shared_ptr<AccessibleApplication>> mActiveAppMap;
 
     /**
      * @brief TBD
index f51097b08b79b5ebe2119aaa0508603568da27cd..5721722cf1906c592cad56e536345fba7b566275 100644 (file)
@@ -49,6 +49,8 @@ public:
      */
     virtual bool executeAndWaitForEvents(const Runnable *cmd, const A11yEvent type, const int timeout) override;
 
+    std::map<AtspiAccessible *, std::shared_ptr<AccessibleApplication>> getActiveAppMap(void);
+
 public:
     /**
      * @brief TBD
@@ -67,4 +69,6 @@ private:
      * @brief TBD
      */
     std::vector<std::shared_ptr<AccessibleApplication>> mApplicationList;
+
+    std::map<AtspiAccessible *, std::shared_ptr<AccessibleApplication>> mActiveAppMap;
 };
index dbda79c68be4f7f5690e2399eebd6797486d6057..03cce467bcfd2a07f04c6d1c3230666f1db0116f 100644 (file)
@@ -176,7 +176,7 @@ public:
      */
     bool sendKeyAndWaitForEvents(
         const std::string keycode, const A11yEvent type, const int timeout) const;
-private:
+
     bool executeAndWaitForEvents(
         const Runnable *cmd, const A11yEvent type, const int timeout) const;
 public:
index 544c56db7e602baafb14a5d7e9be466cee94e1db..a1778c627097738044f30bddce21580b1b7cef4e 100644 (file)
@@ -149,7 +149,29 @@ void AtspiAccessibleWatcher::onAtspiEvents(AtspiEvent *event, void *user_data)
     if (app)
     {
         pkg = AtspiWrapper::Atspi_accessible_get_name(app, NULL);
-        g_object_unref(app);
+        if (!strncmp(event->type, "window:activate", 15)) {
+            LOGI("window activated in app(%s)", pkg);
+            if (!instance->mActiveAppMap.count(app)) {
+                LOGI("add activated window's app in map");
+                instance->mActiveAppMap.insert(std::pair<AtspiAccessible *, std::shared_ptr<AccessibleApplication>>(app,
+                                     std::make_shared<AtspiAccessibleApplication>(std::make_shared<AtspiAccessibleNode>(app))));
+            }
+            else {
+                LOGI("app(%s) is already in map", pkg);
+            }
+        }
+        else if (!strncmp(event->type, "window:deactivate", 16)) {
+            LOGI("window deactivate in app(%s)", pkg);
+            if (!instance->mActiveAppMap.count(app)) {
+                LOGI("window deactivated delete app(%s) in map", pkg);
+                instance->mActiveAppMap.erase(app);
+            }
+            else {
+                LOGE("deactivated window's app(%s) is not in map", pkg);
+            }
+
+            g_object_unref(app);
+        }
     }
     else
         pkg = strdup("");
@@ -301,6 +323,11 @@ bool AtspiAccessibleWatcher::executeAndWaitForEvents(const Runnable *cmd, const
     return false;
 }
 
+std::map<AtspiAccessible *, std::shared_ptr<AccessibleApplication>> AtspiAccessibleWatcher::getActiveAppMap(void)
+{
+    return mActiveAppMap;
+}
+
 bool AtspiAccessibleWatcher::removeFromActivatedList(AtspiAccessible *node)
 {
     LOGI("remove from activelist node %p", node);
index 379a25b260da30f6ac690115f71a6db4130a2e49..75f4048c86bf3a9d8a04217926c7eec69d12b114 100644 (file)
@@ -30,6 +30,10 @@ void MockAccessibleWatcher::addApplication(std::shared_ptr<AccessibleApplication
 {
     mApplicationList.push_back(application);
 }
+std::map<AtspiAccessible *, std::shared_ptr<AccessibleApplication>> MockAccessibleWatcher::getActiveAppMap(void)
+{
+    return mActiveAppMap;
+}
 
 std::shared_ptr<MockAccessibleApplication> MockAccessibleWatcher::addApplication(std::string pkgName, Rect<int> geometry, int ifaces, int properties)
 {
index 23b78cee6190f115236233aa4144e97a545d08c2..0d838bac4a5d306356dec14b57fa928ff0291a0b 100644 (file)
@@ -4,7 +4,7 @@
 #include "TizenDeviceImpl.h"
 #endif
 #include "MockDeviceImpl.h"
-
+#include "AtspiAccessibleWatcher.h"
 #include <unistd.h>
 #include <utility>
 #include <vector>
@@ -50,16 +50,19 @@ std::vector<std::shared_ptr<AccessibleNode>> UiDevice::getWindowRoot() const
 {
     std::vector<std::shared_ptr<AccessibleNode>> ret{};
 
-    auto apps = AccessibleWatcher::getInstance()->getActiveApplications();
-    for (auto &app : apps){
-        auto activeWindows = app->getActiveWindows();
+    auto appsMap = AccessibleWatcher::getInstance()->getActiveAppMap();
+    LOGI("activeAppMap.size: %d" , appsMap.size());
+    for (auto itr = appsMap.begin(); itr != appsMap.end(); itr++)
+    {
+        auto activeWindows = itr->second->getActiveWindows();
         std::transform(activeWindows.begin(), activeWindows.end(), std::back_inserter(ret),
             [&](std::shared_ptr<AccessibleWindow> window){
-                LOGI("Active pkg: %s, window: %s", window->getAccessibleNode()->getPkg().c_str(), window->getTitle().c_str());
+                LOGI("active pkg: %s, window: %s", window->getAccessibleNode()->getPkg().c_str(), window->getTitle().c_str());
                 return window->getAccessibleNode();
             }
         );
     }
+
     return ret;
 }
 
index a08d30c4486f8e44a99b2bca183946ba8383ba5f..c994bf210e82d13c266fefc00873fbf58d425fef 100644 (file)
@@ -16,5 +16,4 @@ public:
     LaunchAppCommand(const ::aurum::ReqLaunchApp *request,
                      ::aurum::RspLaunchApp *response);
     ::grpc::Status execute() override;
-    ::grpc::Status executePost() override;
 };
\ No newline at end of file
diff --git a/org.tizen.aurum-bootstrap/inc/Runnable/LaunchAppRunnable.h b/org.tizen.aurum-bootstrap/inc/Runnable/LaunchAppRunnable.h
new file mode 100644 (file)
index 0000000..0fe4ca2
--- /dev/null
@@ -0,0 +1,15 @@
+#pragma once
+
+#include <string>
+
+#include "Runnable.h"
+
+class LaunchAppRunnable : public Runnable {
+protected:
+    std::string mPkg;
+
+public:
+    LaunchAppRunnable(std::string pkg);
+    std::string getPkgName();
+    void run() const override;
+};
index 41d847293d140789c7d2020ad99be6f6080ca421..8bb2b35cf2bf6c922d33c15fea5a8cb0900299cb 100644 (file)
@@ -3,12 +3,14 @@ bootstrap_svr_inc = [
    root_inc,
    include_directories('inc'),
    include_directories('inc/Commands'),
+   include_directories('inc/Runnable'),
 ]
 
 bootstrap_svr_src = [
    files('src/BootstrapServer.cc'),
    files('src/AurumServiceImpl.cc'),
    files('src/ObjectMapper.cc'),
+   files('src/Runnable/LaunchAppRunnable.cc'),
 ]
 
 bootstrap_svr_src += [
index f7c30ed7390391cd17f59a744da2be876de1a33b..f695723f2f84c9319cf085ec8f90dae8fff7921e 100644 (file)
@@ -1,11 +1,11 @@
 #include "bootstrap.h"
 #include "LaunchAppCommand.h"
+#include "LaunchAppRunnable.h"
+#include "UiDevice.h"
 #include <chrono>
 #include <thread>
 
-#ifdef GBSBUILD
-#include <app_control.h>
-#endif
+#define WAIT_APP_LAUNCH 10000
 
 LaunchAppCommand::LaunchAppCommand(const ::aurum::ReqLaunchApp *request,
                                    ::aurum::RspLaunchApp *response)
@@ -16,43 +16,9 @@ LaunchAppCommand::LaunchAppCommand(const ::aurum::ReqLaunchApp *request,
 ::grpc::Status LaunchAppCommand::execute()
 {
     LOGI("LaunchApp --------------- ");
-#ifdef GBSBUILD
-    app_control_h appControl;
-    std::string   packageName = mRequest->packagename();
-    int           ret = -1;
+    std::unique_ptr<LaunchAppRunnable> cmd = std::make_unique<LaunchAppRunnable>(mRequest->packagename());
+    std::shared_ptr<UiDevice> obj = UiDevice::getInstance();
+    obj->executeAndWaitForEvents(cmd.get(), A11yEvent::EVENT_WINDOW_ACTIVATE, WAIT_APP_LAUNCH);
 
-    if (packageName.empty()) return grpc::Status::OK;
-
-    ret = app_control_create(&appControl);
-    if (ret) {
-        LOGE("Launch Failed(1/3) Err Code : %ull", ret);
-        mResponse->set_status(::aurum::RspStatus::ERROR);
-        return grpc::Status::OK;
-    }
-
-    ret = app_control_set_app_id(appControl, packageName.c_str());
-    if (ret) {
-        LOGE("Launch Failed(2/3) Err Code : %ull", ret);
-        mResponse->set_status(::aurum::RspStatus::ERROR);
-        app_control_destroy(appControl);
-        return grpc::Status::OK;
-    }
-
-    ret = app_control_send_launch_request(appControl, NULL, NULL);
-    if (ret) {
-        LOGE("Launch Failed(3/3) Err Code : %ull", ret);
-        mResponse->set_status(::aurum::RspStatus::ERROR);
-        app_control_destroy(appControl);
-        return grpc::Status::OK;
-    }
-
-    app_control_destroy(appControl);
-#endif
     return grpc::Status::OK;
-}
-::grpc::Status LaunchAppCommand::executePost()
-{
-    LOGI("Wait for 2500ms");
-    std::this_thread::sleep_for(std::chrono::milliseconds{2500});
-    return grpc::Status::OK;
-}
+}
\ No newline at end of file
diff --git a/org.tizen.aurum-bootstrap/src/Runnable/LaunchAppRunnable.cc b/org.tizen.aurum-bootstrap/src/Runnable/LaunchAppRunnable.cc
new file mode 100644 (file)
index 0000000..cafa48b
--- /dev/null
@@ -0,0 +1,51 @@
+#include "Aurum.h"
+#include "bootstrap.h"
+#include "LaunchAppCommand.h"
+#include "LaunchAppRunnable.h"
+
+#ifdef GBSBUILD
+#include <app_control.h>
+#endif
+
+LaunchAppRunnable::LaunchAppRunnable(std::string pkg)
+    : mPkg{pkg}
+{
+}
+
+void LaunchAppRunnable::run() const
+{
+#ifdef GBSBUILD
+    app_control_h appControl;
+    std::string   packageName = mPkg;
+    int           ret = -1;
+
+    if (packageName.empty()) return;
+
+    ret = app_control_create(&appControl);
+    if (ret) {
+        LOGE("Launch Failed(app_control_create) Err Code : %ull", ret);
+        return;
+    }
+
+    ret = app_control_set_app_id(appControl, packageName.c_str());
+    if (ret) {
+        LOGE("Launch Failed(app_control_set_app_id) Err Code : %ull", ret);
+        app_control_destroy(appControl);
+        return;
+    }
+
+    ret = app_control_send_launch_request(appControl, NULL, NULL);
+    if (ret) {
+        LOGE("Launch Failed(app_control_send_launch_request) Err Code : %ull", ret);
+        app_control_destroy(appControl);
+        return;
+    }
+
+    app_control_destroy(appControl);
+#endif
+}
+
+std::string LaunchAppRunnable::getPkgName()
+{
+    return mPkg;
+}
\ No newline at end of file