From 96922eee28132b5712dfca940b98cc50074c1664 Mon Sep 17 00:00:00 2001 From: Woochanlee Date: Tue, 28 Dec 2021 19:52:49 +0900 Subject: [PATCH] aurum: Introduce ActionAndWaitEvent feature Do user request action and wait A11y event. such as window activate, focus changed. Change-Id: I84534b11bceaad2e1fbcc7e3805bac18e34cfe75 --- .../inc/AurumServiceImpl.h | 3 ++ .../inc/Commands/ActionAndWaitEventCommand.h | 34 +++++++++++++ .../inc/Commands/Commands.h | 1 + .../inc/Runnable/ActionAndWaitEventRunnable.h | 32 ++++++++++++ org.tizen.aurum-bootstrap/meson.build | 2 + .../src/AurumServiceImpl.cc | 8 +++ .../src/Commands/ActionAndWaitEventCommand.cc | 50 +++++++++++++++++++ .../Runnable/ActionAndWaitEventRunnable.cc | 47 +++++++++++++++++ protocol/aurum.proto | 24 +++++++++ 9 files changed, 201 insertions(+) create mode 100644 org.tizen.aurum-bootstrap/inc/Commands/ActionAndWaitEventCommand.h create mode 100644 org.tizen.aurum-bootstrap/inc/Runnable/ActionAndWaitEventRunnable.h create mode 100644 org.tizen.aurum-bootstrap/src/Commands/ActionAndWaitEventCommand.cc create mode 100644 org.tizen.aurum-bootstrap/src/Runnable/ActionAndWaitEventRunnable.cc diff --git a/org.tizen.aurum-bootstrap/inc/AurumServiceImpl.h b/org.tizen.aurum-bootstrap/inc/AurumServiceImpl.h index f532b6a..7a6c971 100644 --- a/org.tizen.aurum-bootstrap/inc/AurumServiceImpl.h +++ b/org.tizen.aurum-bootstrap/inc/AurumServiceImpl.h @@ -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 index 0000000..b6bf1ec --- /dev/null +++ b/org.tizen.aurum-bootstrap/inc/Commands/ActionAndWaitEventCommand.h @@ -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 +#include +#include "Commands/Command.h" +#include "ObjectMapper.h" +#include +#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; +}; diff --git a/org.tizen.aurum-bootstrap/inc/Commands/Commands.h b/org.tizen.aurum-bootstrap/inc/Commands/Commands.h index 5c9b25f..754b8eb 100644 --- a/org.tizen.aurum-bootstrap/inc/Commands/Commands.h +++ b/org.tizen.aurum-bootstrap/inc/Commands/Commands.h @@ -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 index 0000000..eb31798 --- /dev/null +++ b/org.tizen.aurum-bootstrap/inc/Runnable/ActionAndWaitEventRunnable.h @@ -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 + +#include "Runnable.h" +#include + +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; +}; diff --git a/org.tizen.aurum-bootstrap/meson.build b/org.tizen.aurum-bootstrap/meson.build index ae2f8dd..3933f64 100644 --- a/org.tizen.aurum-bootstrap/meson.build +++ b/org.tizen.aurum-bootstrap/meson.build @@ -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 = [ diff --git a/org.tizen.aurum-bootstrap/src/AurumServiceImpl.cc b/org.tizen.aurum-bootstrap/src/AurumServiceImpl.cc index 371af97..32cdec4 100644 --- a/org.tizen.aurum-bootstrap/src/AurumServiceImpl.cc +++ b/org.tizen.aurum-bootstrap/src/AurumServiceImpl.cc @@ -240,3 +240,11 @@ aurumServiceImpl::~aurumServiceImpl() std::unique_ptr cmd = std::make_unique(request, response); return execute(cmd.get(), true); } + +::grpc::Status aurumServiceImpl::actionAndWaitEvent(::grpc::ServerContext *context, + const ::aurum::ReqActionAndWaitEvent *request, + ::aurum::RspActionAndWaitEvent *response) +{ + std::unique_ptr cmd = std::make_unique(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 index 0000000..b05a05c --- /dev/null +++ b/org.tizen.aurum-bootstrap/src/Commands/ActionAndWaitEventCommand.cc @@ -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 +#include + +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 cmd = std::make_unique( + mRequest->type(), mRequest->elementid(), mRequest->xf86keycode()); + std::shared_ptr 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 index 0000000..a481271 --- /dev/null +++ b/org.tizen.aurum-bootstrap/src/Runnable/ActionAndWaitEventRunnable.cc @@ -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 + +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 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 mDevice = UiDevice::getInstance(); + mDevice->pressKeyCode(mKeyCode, KeyRequestType::STROKE); + } +} diff --git a/protocol/aurum.proto b/protocol/aurum.proto index bc0444f..1cab347 100644 --- a/protocol/aurum.proto +++ b/protocol/aurum.proto @@ -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 -- 2.34.1