diff --git a/bundle.json b/bundle.json index f19cc683cce1b250905d013038b63c955cd23c5b..285b5768afb6c9943d24e0ea15885464d26b76b2 100755 --- a/bundle.json +++ b/bundle.json @@ -95,6 +95,7 @@ "//foundation/window/window_manager/interfaces/kits/js/declaration:window", "//foundation/window/window_manager/dm:libdm", "//foundation/window/window_manager/extension/extension_connection:libwindow_extension_client", + "//foundation/window/window_manager/extension/modal_system_ui_extension:libmodal_system_ui_extension_client", "//foundation/window/window_manager/extension/window_extension:libwindow_extension", "//foundation/window/window_manager/extension/window_extension:window_extension_module", "//foundation/window/window_manager/wm:libwm", @@ -170,6 +171,16 @@ "header_base": "//foundation/window/window_manager/interfaces/innerkits/extension" } }, + { + "type": "so", + "name": "//foundation/window/window_manager/extension/modal_system_ui_extension:libmodal_system_ui_extension_client", + "header": { + "header_files": [ + "modal_system_ui_extension.h" + ], + "header_base": "//foundation/window/window_manager/interfaces/innerkits/extension" + } + }, { "type": "so", "name": "//foundation/window/window_manager/window_scene/interfaces/innerkits:libwsutils", diff --git a/extension/modal_system_ui_extension/BUILD.gn b/extension/modal_system_ui_extension/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..2ebb9aa83405c1696ee4620ab9c2de5da0839efb --- /dev/null +++ b/extension/modal_system_ui_extension/BUILD.gn @@ -0,0 +1,61 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# 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. + +import("//build/ohos.gni") + +config("libmodal_system_ui_extension_client_private_config") { + visibility = [ ":*" ] + + include_dirs = [ "include" ] +} + +config("libmodal_system_ui_extension_client_public_config") { + include_dirs = [ "../../interfaces/innerkits/extension" ] +} + +ohos_shared_library("libmodal_system_ui_extension_client") { + branch_protector_ret = "pac_ret" + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + install_enable = true + sources = [ "src/modal_system_ui_extension.cpp" ] + + configs = [ + ":libmodal_system_ui_extension_client_private_config", + "../../resources/config/build:coverage_flags", + ] + + public_configs = [ ":libmodal_system_ui_extension_client_public_config" ] + + deps = [ + "../../window_scene/session:scene_session", + "../../wm:libwm", + ] + + external_deps = [ + "ability_base:session_info", + "ability_base:want", + "ability_runtime:ability_manager", + "c_utils:utils", + "hilog:libhilog", + "input:libmmi-client", + "ipc:ipc_single", + ] + + innerapi_tags = [ "platformsdk_indirect" ] + part_name = "window_manager" + subsystem_name = "window" +} diff --git a/extension/modal_system_ui_extension/src/modal_system_ui_extension.cpp b/extension/modal_system_ui_extension/src/modal_system_ui_extension.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5dff141abe9be69a8478411f89711b0b49bf62ab --- /dev/null +++ b/extension/modal_system_ui_extension/src/modal_system_ui_extension.cpp @@ -0,0 +1,138 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * 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 "modal_system_ui_extension.h" + +#include +#include + +#include +#include +#include + +#include "window_manager_hilog.h" + +using namespace OHOS::AAFwk; + +namespace OHOS { +namespace Rosen { +namespace { +constexpr HiviewDFX::HiLogLabel LABEL = { LOG_CORE, HILOG_DOMAIN_WINDOW, "ModalSystemUiExtension" }; +constexpr int32_t INVALID_USERID = -1; +constexpr int32_t MESSAGE_PARCEL_KEY_SIZE = 3; +constexpr int32_t VALUE_TYPE_STRING = 9; +std::atomic_bool g_isDialogShow = false; +sptr g_remoteObject = nullptr; +} // namespace + +ModalSystemUiExtension::ModalSystemUiExtension() {} + +ModalSystemUiExtension::~ModalSystemUiExtension() +{ + dialogConnectionCallback_ = nullptr; +} + +bool ModalSystemUiExtension::CreateModalUIExtension(const AAFwk::Want& want) +{ + dialogConnectionCallback_ = sptr(new DialogAbilityConnection(want)); + if (g_isDialogShow) { + AppExecFwk::ElementName element; + dialogConnectionCallback_->OnAbilityConnectDone(element, g_remoteObject, INVALID_USERID); + WLOGI("ConnectSystemUi dialog has been show"); + return true; + } + + auto abilityManagerClient = AbilityManagerClient::GetInstance(); + if (abilityManagerClient == nullptr) { + WLOGFE("ConnectSystemUi AbilityManagerClient is nullptr"); + return false; + } + + AAFwk::Want systemUIWant; + systemUIWant.SetElementName("com.ohos.sceneboard", "com.ohos.sceneboard.systemdialog"); + auto result = abilityManagerClient->ConnectAbility(systemUIWant, dialogConnectionCallback_, INVALID_USERID); + if (result != ERR_OK) { + WLOGFE("ConnectSystemUi ConnectAbility dialog failed, result = %{public}d", result); + return false; + } + WLOGI("ConnectSystemUi ConnectAbility dialog success"); + return true; +} + +std::string ModalSystemUiExtension::ToString(const AAFwk::WantParams& wantParams_) +{ + std::string result; + if (wantParams_.Size() != 0) { + result += "{"; + for (auto it: wantParams_.GetParams()) { + int typeId = AAFwk::WantParams::GetDataType(it.second); + result += "\"" + it.first + "\":"; + if (typeId == VALUE_TYPE_STRING && AAFwk::WantParams::GetStringByType(it.second, typeId)[0] != '{') { + result += "\"" + AAFwk::WantParams::GetStringByType(it.second, typeId) + "\""; + } else { + result += AAFwk::WantParams::GetStringByType(it.second, typeId); + } + if (it != *wantParams_.GetParams().rbegin()) { + result += ","; + } + } + result += "}"; + } else { + result += "{}"; + } + return result; +} + +void ModalSystemUiExtension::DialogAbilityConnection::OnAbilityConnectDone( + const AppExecFwk::ElementName& element, const sptr& remoteObject, int resultCode) +{ + WLOGI("OnAbilityConnectDone show dialog begin"); + std::lock_guard lock(mutex_); + if (remoteObject == nullptr) { + WLOGFE("OnAbilityConnectDone remoteObject is nullptr"); + return; + } + if (g_remoteObject == nullptr) { + g_remoteObject = remoteObject; + } + MessageParcel data; + MessageParcel reply; + MessageOption option; + data.WriteInt32(MESSAGE_PARCEL_KEY_SIZE); + data.WriteString16(u"bundleName"); + data.WriteString16(Str8ToStr16(want_.GetElement().GetBundleName())); + data.WriteString16(u"abilityName"); + data.WriteString16(Str8ToStr16(want_.GetElement().GetAbilityName())); + data.WriteString16(u"parameters"); + data.WriteString16(Str8ToStr16(ModalSystemUiExtension::ToString(want_.GetParams()))); + int32_t ret = remoteObject->SendRequest(AAFwk::IAbilityConnection::ON_ABILITY_CONNECT_DONE, data, reply, option); + if (ret != ERR_OK) { + WLOGFE("OnAbilityConnectDone show dialog is failed"); + return; + } + g_isDialogShow = true; + WLOGI("OnAbilityConnectDone show dialog is success"); +} + +void ModalSystemUiExtension::DialogAbilityConnection::OnAbilityDisconnectDone(const AppExecFwk::ElementName& element, + int resultCode) +{ + WLOGI("OnAbilityDisconnectDone"); + std::lock_guard lock(mutex_); + g_isDialogShow = false; + g_remoteObject = nullptr; +} +} // namespace Rosen +} // namespace OHOS \ No newline at end of file diff --git a/interfaces/innerkits/extension/modal_system_ui_extension.h b/interfaces/innerkits/extension/modal_system_ui_extension.h new file mode 100644 index 0000000000000000000000000000000000000000..37bacff4d89a96fc2a66d0950201214004a44bbe --- /dev/null +++ b/interfaces/innerkits/extension/modal_system_ui_extension.h @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * 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. + */ + +#ifndef WINDOW_MANAGER_MODAL_SYSTEM_UI_EXTENSION_H +#define WINDOW_MANAGER_MODAL_SYSTEM_UI_EXTENSION_H + +#include +#include +#include +#include +#include + +namespace OHOS { +namespace Rosen { +class ModalSystemUiExtension { +public: + ModalSystemUiExtension(); + ~ModalSystemUiExtension(); + + bool CreateModalUIExtension(const AAFwk::Want& want); + static std::string ToString(const AAFwk::WantParams& wantParams_); + +private: + class DialogAbilityConnection : public OHOS::AAFwk::AbilityConnectionStub { + public: + DialogAbilityConnection(const AAFwk::Want& want) + { + want_ = want; + } + virtual ~DialogAbilityConnection() = default; + + void OnAbilityConnectDone(const AppExecFwk::ElementName& element, const sptr& remoteObject, + int resultCode) override; + void OnAbilityDisconnectDone(const AppExecFwk::ElementName& element, int resultCode) override; + + private: + std::mutex mutex_; + AAFwk::Want want_; + }; + + sptr dialogConnectionCallback_{ nullptr }; +}; +} // namespace Rosen +} // namespace OHOS + +#endif // WINDOW_MANAGER_MODAL_SYSTEM_UI_EXTENSION_H \ No newline at end of file diff --git a/test/systemtest/extension/BUILD.gn b/test/systemtest/extension/BUILD.gn index 6bf4a0097fd85d573923ab3dc4789e21931d84ea..d0e905e229ac2e7d58ec941df025d599078dba38 100644 --- a/test/systemtest/extension/BUILD.gn +++ b/test/systemtest/extension/BUILD.gn @@ -17,7 +17,10 @@ module_out_path = "window_manager/extension" group("systemtest") { testonly = true - deps = [ ":window_extension_connection_test" ] + deps = [ + ":modal_system_ui_extension_test", + ":window_extension_connection_test", + ] } config("we_systemtest_common_public_config") { @@ -29,6 +32,34 @@ config("we_systemtest_common_public_config") { ] } +ohos_systemtest("modal_system_ui_extension_test") { + module_out_path = module_out_path + + sources = [ "modal_system_ui_extension_test.cpp" ] + + public_configs = [ + ":we_systemtest_common_public_config", + "../../../resources/config/build:coverage_flags", + "../../../resources/config/build:testcase_flags", + ] + + public_deps = [ + "../../../extension/modal_system_ui_extension:libmodal_system_ui_extension_client", + "//third_party/googletest:gmock", + "//third_party/googletest:gtest_main", + ] + + external_deps = [ + "ability_base:session_info", + "ability_base:want", + "ability_runtime:ability_manager", + "c_utils:utils", + "hilog:libhilog", + "input:libmmi-client", + "ipc:ipc_single", + ] +} + ## SystemTest window_extension_connection_test {{{ ohos_systemtest("window_extension_connection_test") { module_out_path = module_out_path diff --git a/test/systemtest/extension/modal_system_ui_extension_test.cpp b/test/systemtest/extension/modal_system_ui_extension_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..16907029997a213f00240b84d590b9bfbd317202 --- /dev/null +++ b/test/systemtest/extension/modal_system_ui_extension_test.cpp @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * 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 "modal_system_ui_extension.h" +#include "wm_common.h" + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { +namespace Rosen { +class ModalSystemUiExtensionTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp() override; + void TearDown() override; +}; + +void ModalSystemUiExtensionTest::SetUpTestCase() +{ +} + +void ModalSystemUiExtensionTest::TearDownTestCase() +{ +} + +void ModalSystemUiExtensionTest::SetUp() +{ +} + +void ModalSystemUiExtensionTest::TearDown() +{ +} + +namespace { +/** + * @tc.name: ModalSystemUiExtensionConnection01 + * @tc.desc: connect modal system ui_extension + * @tc.type: FUNC + */ +HWTEST_F(ModalSystemUiExtensionTest, ModalSystemUiExtensionConnection01, Function | SmallTest | Level2) +{ + auto connection = new(std::nothrow)ModalSystemUiExtension(); + if (connection == nullptr) { + return; + } + OHOS::AAFwk::Want want; + ASSERT_TRUE(connection->CreateModalUIExtension(want) == ERR_OK); + delete connection; +} +} +} // Rosen +} // OHOS \ No newline at end of file