From 539c74d51362a0b2b5a5093c05a3742fce1c40e5 Mon Sep 17 00:00:00 2001 From: zhanghang Date: Thu, 22 May 2025 14:36:19 +0800 Subject: [PATCH] =?UTF-8?q?=E9=AA=8C=E8=AF=81SA=E6=9E=84=E5=BB=BA=EF=BC=8C?= =?UTF-8?q?=E6=94=AF=E6=92=91IR=E4=B8=8B=E4=B8=AASR=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E7=82=B9=20master?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhanghang --- adapter/ohos/build/BUILD.gn | 1 + adapter/ohos/entrance/ui_session/BUILD.gn | 4 +-- .../ui_session/test/mock_ui_sa_service.cpp | 34 +++++++++++++++++++ .../ui_session/test/mock_ui_sa_service.h | 7 ++++ 4 files changed, 44 insertions(+), 2 deletions(-) diff --git a/adapter/ohos/build/BUILD.gn b/adapter/ohos/build/BUILD.gn index b70e40698a6..e18e210ab5c 100644 --- a/adapter/ohos/build/BUILD.gn +++ b/adapter/ohos/build/BUILD.gn @@ -31,6 +31,7 @@ group("ace_packages") { "$ace_root/interfaces/inner_api/ace:ace_uicontent", "$ace_root/interfaces/napi/kits:napi_group", "$ace_root/interfaces/native:ace_packages_ndk", + "$ace_root/adapter/ohos/entrance/ui_session:mock_sa_target", ] if (is_asan) { diff --git a/adapter/ohos/entrance/ui_session/BUILD.gn b/adapter/ohos/entrance/ui_session/BUILD.gn index 84be6e4cd40..a6f436c6509 100644 --- a/adapter/ohos/entrance/ui_session/BUILD.gn +++ b/adapter/ohos/entrance/ui_session/BUILD.gn @@ -11,6 +11,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -group("services_target") { +group("mock_sa_target") { deps = [ "test:mock_ui_sa" ] -} +} \ No newline at end of file diff --git a/adapter/ohos/entrance/ui_session/test/mock_ui_sa_service.cpp b/adapter/ohos/entrance/ui_session/test/mock_ui_sa_service.cpp index 2aeee0d5869..a50daef5d5d 100644 --- a/adapter/ohos/entrance/ui_session/test/mock_ui_sa_service.cpp +++ b/adapter/ohos/entrance/ui_session/test/mock_ui_sa_service.cpp @@ -25,6 +25,8 @@ namespace OHOS::Ace { const bool REGISTER_RESULT = SystemAbility::MakeAndRegisterAbility(&MockSaService::GetInstance()); +const int32_t MIN_ARGS_SIZE = 2; + MockSaService::MockSaService() : SystemAbility(SA_ID, true) {} MockSaService& MockSaService::GetInstance() @@ -74,7 +76,39 @@ int32_t MockSaService::Dump(int32_t fd, const std::vector& args) if (!args.empty()) { message.pop_back(); } + if (str8Args.size() >= MIN_ARGS_SIZE) { + std::string command = str8Args[0]; + std::string param = str8Args[1]; + std::string idStr = str8Args[2]; + if (command == "SendCommandWithId") { + int32_t validId = std::stoi(idStr); + SendCommandWithId(service, param, validId); + } else if (command == "SendCommandWithIdAsync") { + int32_t validId = std::stoi(idStr); + SendCommandWithIdAsync(service, param, validId); + } else if (command == "SendCommandWithoutId") { + SendCommandWithoutId(service, param); + } else { + dprintf(fd, "Unknown command: %s\n", command.c_str()); + } + } return ERR_NONE; } + void MockSaService::SendCommandWithId(sptr service, const std::string& param, int32_t id) + { + service->SendCommand(id, param); + } + + void MockSaService::SendCommandWithIdAsync( + sptr service, const std::string& param, int32_t id) + { + service->SendCommandAsync(id, param); + } + + void MockSaService::SendCommandWithoutId(sptr service, const std::string& param) + { + service->SendCommand(param); + } + } // namespace OHOS::Ace \ No newline at end of file diff --git a/adapter/ohos/entrance/ui_session/test/mock_ui_sa_service.h b/adapter/ohos/entrance/ui_session/test/mock_ui_sa_service.h index 0bae9ebf669..3a2fab9b1f8 100644 --- a/adapter/ohos/entrance/ui_session/test/mock_ui_sa_service.h +++ b/adapter/ohos/entrance/ui_session/test/mock_ui_sa_service.h @@ -19,6 +19,7 @@ #include "system_ability.h" #include "adapter/ohos/entrance/ui_session/test/mock_ui_sa_stub.h" +#include "ui_content_service_interface.h" namespace OHOS::Ace { @@ -44,6 +45,12 @@ public: int32_t Dump(int32_t fd, const std::vector& args) override; + void SendCommandWithId(sptr service, const std::string& param, int32_t id); + + void SendCommandWithIdAsync(sptr service, const std::string& param, int32_t id); + + void SendCommandWithoutId(sptr service, const std::string& param); + private: DECLEAR_SYSTEM_ABILITY(MockSaService); -- Gitee