aurum: Introduce ActionAndWaitEvent feature 43/268643/6
authorWoochanlee <wc0917.lee@samsung.com>
Tue, 28 Dec 2021 10:52:49 +0000 (19:52 +0900)
committerWoochanlee <wc0917.lee@samsung.com>
Wed, 19 Jan 2022 07:03:10 +0000 (16:03 +0900)
Do user request action and wait A11y event. such as window activate, focus changed.

Change-Id: I84534b11bceaad2e1fbcc7e3805bac18e34cfe75

org.tizen.aurum-bootstrap/inc/AurumServiceImpl.h
org.tizen.aurum-bootstrap/inc/Commands/ActionAndWaitEventCommand.h [new file with mode: 0644]
org.tizen.aurum-bootstrap/inc/Commands/Commands.h
org.tizen.aurum-bootstrap/inc/Runnable/ActionAndWaitEventRunnable.h [new file with mode: 0644]
org.tizen.aurum-bootstrap/meson.build
org.tizen.aurum-bootstrap/src/AurumServiceImpl.cc
org.tizen.aurum-bootstrap/src/Commands/ActionAndWaitEventCommand.cc [new file with mode: 0644]
org.tizen.aurum-bootstrap/src/Runnable/ActionAndWaitEventRunnable.cc [new file with mode: 0644]
protocol/aurum.proto

index f532b6a..7a6c971 100644 (file)
@@ -110,6 +110,9 @@ public:
     ::grpc::Status getScreenSize(::grpc::ServerContext *context,
                             const ::aurum::ReqGetScreenSize *request,
                             ::aurum::RspGetScreenSize *response) override;
+    ::grpc::Status actionAndWaitEvent(::grpc::ServerContext *context,
+                                      const ::aurum::ReqActionAndWaitEvent *request,
+                                      ::aurum::RspActionAndWaitEvent *response) override;
 };
 
 #endif
diff --git a/org.tizen.aurum-bootstrap/inc/Commands/ActionAndWaitEventCommand.h b/org.tizen.aurum-bootstrap/inc/Commands/ActionAndWaitEventCommand.h
new file mode 100644 (file)
index 0000000..b6bf1ec
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *               http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+
+#include <gio/gio.h>
+#include <grpcpp/grpcpp.h>
+#include "Commands/Command.h"
+#include "ObjectMapper.h"
+#include <aurum.grpc.pb.h>
+#include "config.h"
+
+class ActionAndWaitEventCommand : public Command {
+private:
+    const ::aurum::ReqActionAndWaitEvent *mRequest;
+    ::aurum::RspActionAndWaitEvent *mResponse;
+
+public:
+    ActionAndWaitEventCommand(const ::aurum::ReqActionAndWaitEvent *request,
+                     ::aurum::RspActionAndWaitEvent *response);
+    ::grpc::Status execute() override;
+};
index 5c9b25f..754b8eb 100644 (file)
@@ -46,3 +46,4 @@
 #include "Commands/TakeScreenshotCommand.h"
 #include "Commands/DumpObjectTreeCommand.h"
 #include "Commands/GetScreenSizeCommand.h"
+#include "Commands/ActionAndWaitEventCommand.h"
diff --git a/org.tizen.aurum-bootstrap/inc/Runnable/ActionAndWaitEventRunnable.h b/org.tizen.aurum-bootstrap/inc/Runnable/ActionAndWaitEventRunnable.h
new file mode 100644 (file)
index 0000000..eb31798
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *               http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+
+#include <string>
+
+#include "Runnable.h"
+#include <aurum.grpc.pb.h>
+
+class ActionAndWaitEventRunnable : public Runnable {
+protected:
+    int mType;
+    std::string mElementId;
+    std::string mKeyCode;
+
+public:
+    ActionAndWaitEventRunnable(int type, std::string elementId, std::string keyCode);
+    void run() const override;
+};
index ae2f8dd..3933f64 100644 (file)
@@ -11,6 +11,7 @@ bootstrap_svr_src = [
    files('src/AurumServiceImpl.cc'),
    files('src/ObjectMapper.cc'),
    files('src/Runnable/LaunchAppRunnable.cc'),
+   files('src/Runnable/ActionAndWaitEventRunnable.cc'),
 ]
 
 bootstrap_svr_src += [
@@ -41,6 +42,7 @@ bootstrap_svr_src += [
    files('src/Commands/PostCommand.cc'),
    files('src/Commands/DumpObjectTreeCommand.cc'),
    files('src/Commands/GetScreenSizeCommand.cc'),
+   files('src/Commands/ActionAndWaitEventCommand.cc'),
 ]
 
 bootstrap_svr_dep = [
index 371af97..32cdec4 100644 (file)
@@ -240,3 +240,11 @@ aurumServiceImpl::~aurumServiceImpl()
     std::unique_ptr<GetScreenSizeCommand> cmd = std::make_unique<GetScreenSizeCommand>(request, response);
     return execute(cmd.get(), true);
 }
+
+::grpc::Status aurumServiceImpl::actionAndWaitEvent(::grpc::ServerContext *context,
+                                         const ::aurum::ReqActionAndWaitEvent *request,
+                                         ::aurum::RspActionAndWaitEvent *response)
+{
+    std::unique_ptr<ActionAndWaitEventCommand> cmd = std::make_unique<ActionAndWaitEventCommand>(request, response);
+    return execute(cmd.get(), true);
+}
diff --git a/org.tizen.aurum-bootstrap/src/Commands/ActionAndWaitEventCommand.cc b/org.tizen.aurum-bootstrap/src/Commands/ActionAndWaitEventCommand.cc
new file mode 100644 (file)
index 0000000..b05a05c
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *               http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+
+#include "bootstrap.h"
+#include "ActionAndWaitEventCommand.h"
+#include "ActionAndWaitEventRunnable.h"
+#include "UiDevice.h"
+#include <chrono>
+#include <thread>
+
+ActionAndWaitEventCommand::ActionAndWaitEventCommand(const ::aurum::ReqActionAndWaitEvent *request,
+                                   ::aurum::RspActionAndWaitEvent *response)
+    : mRequest{request}, mResponse{response}
+{
+}
+
+A11yEvent convertEventType(const ::aurum::ReqActionAndWaitEvent_EventType type)
+{
+    if (type == ::aurum::ReqActionAndWaitEvent_EventType::ReqActionAndWaitEvent_EventType_EVENT_WINDOW_ACTIVATE)
+        return A11yEvent::EVENT_WINDOW_ACTIVATE;
+    else if (type == ::aurum::ReqActionAndWaitEvent_EventType::ReqActionAndWaitEvent_EventType_EVENT_WINDOW_DEACTIVATE)
+        return A11yEvent::EVENT_WINDOW_DEACTIVATE;
+    else
+        return A11yEvent::EVENT_STATE_CHANGED_FOCUSED;
+}
+
+::grpc::Status ActionAndWaitEventCommand::execute()
+{
+    LOGI("ActionAndWaitEvent --------------- ");
+    std::unique_ptr<ActionAndWaitEventRunnable> cmd = std::make_unique<ActionAndWaitEventRunnable>(
+                                                      mRequest->type(), mRequest->elementid(), mRequest->xf86keycode());
+    std::shared_ptr<UiDevice> obj = UiDevice::getInstance();
+    obj->executeAndWaitForEvents(cmd.get(), convertEventType(mRequest->eventtype()), mRequest->timeoutms());
+
+    return grpc::Status::OK;
+}
diff --git a/org.tizen.aurum-bootstrap/src/Runnable/ActionAndWaitEventRunnable.cc b/org.tizen.aurum-bootstrap/src/Runnable/ActionAndWaitEventRunnable.cc
new file mode 100644 (file)
index 0000000..a481271
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *               http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+
+#include "Aurum.h"
+#include "bootstrap.h"
+#include "ActionAndWaitEventCommand.h"
+#include "ActionAndWaitEventRunnable.h"
+#include <app_control.h>
+
+ActionAndWaitEventRunnable::ActionAndWaitEventRunnable(int type, std::string elementId, std::string keyCode)
+    : mType{type}, mElementId(elementId), mKeyCode(keyCode)
+{
+}
+
+void ActionAndWaitEventRunnable::run() const
+{
+    if (mType == 0) {
+        ObjectMapper *mObjMap = ObjectMapper::getInstance();
+        std::shared_ptr<UiObject> obj = mObjMap->getElement(mElementId);
+
+        if (obj) {
+            LOGD("Click Object Id(%s)", mElementId.c_str());
+            obj->click();
+        }
+        else
+            LOGE("Object Id(%s) is invalid or not exist on view", mElementId.c_str());
+    }
+    else {
+        LOGD("Send KeyEvent(%s)", mKeyCode.c_str());
+        std::shared_ptr<UiDevice> mDevice = UiDevice::getInstance();
+        mDevice->pressKeyCode(mKeyCode, KeyRequestType::STROKE);
+    }
+}
index bc0444f..1cab347 100644 (file)
@@ -30,6 +30,7 @@ service Bootstrap {
    rpc takeScreenshot(ReqTakeScreenshot) returns (stream RspTakeScreenshot) {}
    rpc dumpObjectTree(ReqDumpObjectTree) returns (RspDumpObjectTree) {}
    rpc getScreenSize(ReqGetScreenSize) returns (RspGetScreenSize) {}
+   rpc actionAndWaitEvent(ReqActionAndWaitEvent) returns (RspActionAndWaitEvent) {}
 }
 
 // ------------------------------------ //
@@ -429,3 +430,26 @@ message RspGetScreenSize {
    RspStatus status = 1;
    Rect size = 2;
 }
+
+message ReqActionAndWaitEvent {
+   enum ActionType{
+      CLICK = 0;
+      KEY = 1;
+   }
+   enum EventType {
+      EVENT_WINDOW_ACTIVATE = 0;
+      EVENT_WINDOW_DEACTIVATE = 1;
+      EVENT_STATE_CHANGED_FOCUSED = 2;
+   }
+   ActionType type = 1;
+   oneof params {
+      string elementId = 2;
+      string XF86keyCode = 3;
+   }
+   EventType eventType = 4;
+   int32 timeoutMs = 5;
+}
+
+message RspActionAndWaitEvent {
+   RspStatus status = 1;
+}
\ No newline at end of file