新增CreateModalUIExtension接口

Signed-off-by: zhanggong <zhanggong16@huawei.com>
This commit is contained in:
zhanggong 2023-12-13 09:27:51 +08:00
parent 8e64bd244f
commit 8108e45679
6 changed files with 368 additions and 1 deletions

View File

@ -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",

View File

@ -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"
}

View File

@ -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 <atomic>
#include <memory>
#include <message_parcel.h>
#include <ability_manager_client.h>
#include <iremote_object.h>
#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<IRemoteObject> g_remoteObject = nullptr;
} // namespace
ModalSystemUiExtension::ModalSystemUiExtension() {}
ModalSystemUiExtension::~ModalSystemUiExtension()
{
dialogConnectionCallback_ = nullptr;
}
bool ModalSystemUiExtension::CreateModalUIExtension(const AAFwk::Want& want)
{
dialogConnectionCallback_ = sptr<OHOS::AAFwk::IAbilityConnection>(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<IRemoteObject>& 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

View File

@ -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 <mutex>
#include <string>
#include <element_name.h>
#include <ability_connect_callback_interface.h>
#include <ability_connect_callback_stub.h>
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<IRemoteObject>& remoteObject,
int resultCode) override;
void OnAbilityDisconnectDone(const AppExecFwk::ElementName& element, int resultCode) override;
private:
std::mutex mutex_;
AAFwk::Want want_;
};
sptr<OHOS::AAFwk::IAbilityConnection> dialogConnectionCallback_{ nullptr };
};
} // namespace Rosen
} // namespace OHOS
#endif // WINDOW_MANAGER_MODAL_SYSTEM_UI_EXTENSION_H

View File

@ -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

View File

@ -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 <gtest/gtest.h>
#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