From 95ca12a29b0f6a0fb5120d238d5aaf8f1a163fac Mon Sep 17 00:00:00 2001 From: w00887908 Date: Tue, 10 Jun 2025 21:19:49 +0800 Subject: [PATCH 1/6] =?UTF-8?q?Description:=E4=BF=AE=E6=94=B9=E6=97=A0?= =?UTF-8?q?=E5=93=8D=E5=BA=94=E5=BC=B9=E7=AA=97=E5=BD=A2=E5=BC=8F=EF=BC=8C?= =?UTF-8?q?=E7=94=B1=E6=A8=A1=E7=B3=BB=E7=BB=9F=E5=8F=98=E6=9B=B4=E4=B8=BA?= =?UTF-8?q?=E6=A8=A1=E5=BA=94=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: w00887908 --- .../modal_system_app_freeze_uiextension.h | 32 +-- .../modal_system_app_freeze_uiextension.cpp | 195 +++++++----------- test/unittest/BUILD.gn | 1 + .../BUILD.gn | 104 ++++++++++ ...dal_system_app_freeze_uiextension_test.cpp | 94 +++++++++ 5 files changed, 279 insertions(+), 147 deletions(-) create mode 100644 test/unittest/modal_system_app_freeze_uiextension_test/BUILD.gn create mode 100644 test/unittest/modal_system_app_freeze_uiextension_test/modal_system_app_freeze_uiextension_test.cpp diff --git a/services/appmgr/include/modal_system_app_freeze_uiextension.h b/services/appmgr/include/modal_system_app_freeze_uiextension.h index 5bdacfa7ffe..9c4c4528fa7 100644 --- a/services/appmgr/include/modal_system_app_freeze_uiextension.h +++ b/services/appmgr/include/modal_system_app_freeze_uiextension.h @@ -34,7 +34,7 @@ namespace OHOS { namespace AppExecFwk { -constexpr const char* APP_NO_RESPONSE_ABILITY = "AppAbnormalAbility"; +constexpr const char *APP_NO_RESPONSE_ABILITY = "AppAbnormalAbility"; class ModalSystemAppFreezeUIExtension { public: @@ -47,35 +47,15 @@ public: private: bool CreateModalUIExtension(std::string pid, std::string bundleName); - AAFwk::Want CreateSystemDialogWant(std::string pid, std::string bundleName); + bool CreateSystemDialogWant(std::string pid, std::string bundleName, sptr &token, AAFwk::Want &want); private: - class AppFreezeDialogConnection : public AAFwk::AbilityConnectionStub { - public: - AppFreezeDialogConnection() = default; - virtual ~AppFreezeDialogConnection() = default; - - void SetReqeustAppFreezeDialogWant(const AAFwk::Want &want); - void OnAbilityConnectDone(const AppExecFwk::ElementName &element, const sptr &remoteObject, - int resultCode) override; - void OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int resultCode) override; - - private: - bool WriteWantElement(MessageParcel &data); - AAFwk::Want want_; - }; - -private: - sptr GetConnection(); - bool lastFocusStatus = false; uint64_t lastFreezeTime = 0; - sptr dialogConnectionCallback_; std::mutex appFreezeResultMutex_; - std::mutex dialogConnectionMutex_; std::string lastFreezePid; }; -} // namespace AppExecFwk -} // namespace OHOS -#endif // APP_NO_RESPONSE_DIALOG -#endif // OHOS_ABILITY_RUNTIME_MODAL_SYSTEM_APP_FREEZE_UIEXTENSION_H \ No newline at end of file +} // namespace AppExecFwk +} // namespace OHOS +#endif // APP_NO_RESPONSE_DIALOG +#endif // OHOS_ABILITY_RUNTIME_MODAL_SYSTEM_APP_FREEZE_UIEXTENSION_H \ No newline at end of file diff --git a/services/appmgr/src/modal_system_app_freeze_uiextension.cpp b/services/appmgr/src/modal_system_app_freeze_uiextension.cpp index 4e28abf4b80..68f0a16c56f 100644 --- a/services/appmgr/src/modal_system_app_freeze_uiextension.cpp +++ b/services/appmgr/src/modal_system_app_freeze_uiextension.cpp @@ -23,13 +23,24 @@ #include "hitrace_meter.h" #include "in_process_call_wrapper.h" #include "scene_board_judgement.h" +#include "session_manager_lite.h" +#include "ability_record.h" +#include "window_visibility_info.h" + +using namespace OHOS::AAFwk; +using namespace OHOS::Rosen; namespace OHOS { namespace AppExecFwk { const std::string UIEXTENSION_TYPE_KEY = "ability.want.params.uiExtensionType"; const std::string UIEXTENSION_SYS_COMMON_UI = "sysDialog/common"; const std::string APP_FREEZE_PID = "APP_FREEZE_PID"; +const std::string FREEZE_WINDOW_POSX = "FREEZE_WINDOW_POSX"; +const std::string FREEZE_WINDOW_POSY = "FREEZE_WINDOW_POSY"; +const std::string FREEZE_WINDOW_WIDTH = "FREEZE_WINDOW_WIDTH"; +const std::string FREEZE_WINDOW_HEIGHT = "FREEZE_WINDOW_HEIGHT"; const std::string START_BUNDLE_NAME = "startBundleName"; +const std::string APP_FREEZE_TOKEN = "freezeToken"; constexpr int32_t INVALID_USERID = -1; constexpr int32_t MESSAGE_PARCEL_KEY_SIZE = 3; constexpr uint32_t COMMAND_START_DIALOG = 1; @@ -43,21 +54,7 @@ ModalSystemAppFreezeUIExtension &ModalSystemAppFreezeUIExtension::GetInstance() } ModalSystemAppFreezeUIExtension::~ModalSystemAppFreezeUIExtension() -{ - dialogConnectionCallback_ = nullptr; -} - -sptr ModalSystemAppFreezeUIExtension::GetConnection() -{ - if (dialogConnectionCallback_ == nullptr) { - std::lock_guard lock(dialogConnectionMutex_); - if (dialogConnectionCallback_ == nullptr) { - dialogConnectionCallback_ = new (std::nothrow) AppFreezeDialogConnection(); - } - } - - return dialogConnectionCallback_; -} +{} void ModalSystemAppFreezeUIExtension::ProcessAppFreeze(bool focusFlag, const FaultData &faultData, std::string pid, std::string bundleName, std::function callback, bool isDialogExist) @@ -70,13 +67,14 @@ void ModalSystemAppFreezeUIExtension::ProcessAppFreeze(bool focusFlag, const Fau FaultDataType faultType = faultData.faultType; std::string name = faultData.errorObject.name; bool isAppFreezeDialog = name == AppFreezeType::THREAD_BLOCK_6S || name == AppFreezeType::APP_INPUT_BLOCK || - name == AppFreezeType::BUSSINESS_THREAD_BLOCK_6S; - uint64_t now = std::chrono::duration_cast(std::chrono::steady_clock:: - now().time_since_epoch()).count(); + name == AppFreezeType::BUSSINESS_THREAD_BLOCK_6S; + uint64_t now = + std::chrono::duration_cast(std::chrono::steady_clock::now().time_since_epoch()) + .count(); bool timeout = now - lastFreezeTime > TIMEOUT_INTERVAL_MS; TAG_LOGI(AAFwkTag::ABILITYMGR, - "%{public}s is %{public}s.pid:%{public}s lastFreezePid:%{public}s,timeout %{public}lu", bundleName.c_str(), - focusFlag ? "focus" : "not focus", pid.c_str(), lastFreezePid.c_str(), now - lastFreezeTime); + "%{public}s is %{public}s.pid:%{public}s lastFreezePid:%{public}s,timeout %{public}lu", + bundleName.c_str(), focusFlag ? "focus" : "not focus", pid.c_str(), lastFreezePid.c_str(), now - lastFreezeTime); bool isPullUpBox = isAppFreezeDialog && (pid != lastFreezePid || (pid == lastFreezePid && timeout && !isDialogExist)); bool updateTypeName = name == AppFreezeType::THREAD_BLOCK_6S || name == AppFreezeType::BUSSINESS_THREAD_BLOCK_6S; @@ -84,12 +82,7 @@ void ModalSystemAppFreezeUIExtension::ProcessAppFreeze(bool focusFlag, const Fau lastFreezeTime = now; } if (focusFlag && isPullUpBox) { - std::string appNoResponseBundleName = APP_NO_RESPONSE_BUNDLENAME; - if (appNoResponseBundleName == "com.ohos.taskmanager") { - callback(); - } else { - CreateModalUIExtension(pid, bundleName); - } + CreateModalUIExtension(pid, bundleName); } else if (callback && (faultType != FaultDataType::APP_FREEZE || !isAppFreezeDialog)) { callback(); } @@ -101,127 +94,87 @@ void ModalSystemAppFreezeUIExtension::ProcessAppFreeze(bool focusFlag, const Fau bool ModalSystemAppFreezeUIExtension::CreateModalUIExtension(std::string pid, std::string bundleName) { - TAG_LOGD(AAFwkTag::ABILITYMGR, "called"); - AAFwk::Want want = CreateSystemDialogWant(pid, bundleName); + TAG_LOGD(AAFwkTag::ABILITYMGR, "Create Modal UIExtension Called"); + sptr token; + AAFwk::Want want; std::unique_lock lockAssertResult(appFreezeResultMutex_); - auto callback = GetConnection(); - if (callback == nullptr) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "null callback"); + if (!CreateSystemDialogWant(pid, bundleName, token, want)) { return false; } - callback->SetReqeustAppFreezeDialogWant(want); auto abilityManagerClient = AAFwk::AbilityManagerClient::GetInstance(); if (abilityManagerClient == nullptr) { TAG_LOGE(AAFwkTag::ABILITYMGR, "null abilityManagerClient"); return false; } - AAFwk::Want systemUIWant; - if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) { - systemUIWant.SetElementName("com.ohos.sceneboard", "com.ohos.sceneboard.systemdialog"); - } else { - systemUIWant.SetElementName("com.ohos.systemui", "com.ohos.systemui.dialog"); - } - IN_PROCESS_CALL_WITHOUT_RET(abilityManagerClient->DisconnectAbility(callback)); - auto result = IN_PROCESS_CALL(abilityManagerClient->ConnectAbility(systemUIWant, callback, INVALID_USERID)); + auto result = IN_PROCESS_CALL(abilityManagerClient->StartExtensionAbility(want, token)); if (result != ERR_OK) { - TAG_LOGE(AAFwkTag::ABILITYMGR, - "fail, result = %{public}d", result); + TAG_LOGE(AAFwkTag::ABILITYMGR, "StartExtensionAbility failed, result = %{public}d", result); return false; } lastFreezePid = pid; lastFocusStatus = true; - lastFreezeTime = std::chrono::duration_cast( - std::chrono::steady_clock::now().time_since_epoch()).count(); - TAG_LOGI(AAFwkTag::ABILITYMGR, - "success, result = %{public}d", result); + lastFreezeTime = + std::chrono::duration_cast(std::chrono::steady_clock::now().time_since_epoch()) + .count(); + TAG_LOGI(AAFwkTag::ABILITYMGR, "success, result = %{public}d", result); return true; } -AAFwk::Want ModalSystemAppFreezeUIExtension::CreateSystemDialogWant(std::string pid, std::string bundleName) +bool ModalSystemAppFreezeUIExtension::CreateSystemDialogWant( + std::string pid, std::string bundleName, sptr &token, AAFwk::Want &want) { - AAFwk::Want want; want.SetElementName(APP_NO_RESPONSE_BUNDLENAME, APP_NO_RESPONSE_ABILITY); want.SetParam(UIEXTENSION_TYPE_KEY, UIEXTENSION_SYS_COMMON_UI); want.SetParam(APP_FREEZE_PID, pid); want.SetParam(START_BUNDLE_NAME, bundleName); - return want; -} - -void ModalSystemAppFreezeUIExtension::AppFreezeDialogConnection::SetReqeustAppFreezeDialogWant(const AAFwk::Want &want) -{ - want_ = want; -} -bool ModalSystemAppFreezeUIExtension::AppFreezeDialogConnection::WriteWantElement(MessageParcel &data) -{ - if (!data.WriteString16(u"bundleName")) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "write bundleName failed"); - return false; - } - if (!data.WriteString16(Str8ToStr16(want_.GetElement().GetBundleName()))) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "write element bundlename failed"); - return false; - } - if (!data.WriteString16(u"abilityName")) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "write abilityName failed"); - return false; - } - if (!data.WriteString16(Str8ToStr16(want_.GetElement().GetAbilityName()))) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "write element abilityName failed"); + auto sceneSessionManager = Rosen::SessionManagerLite::GetInstance().GetSceneSessionManagerLiteProxy(); + if (!sceneSessionManager) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "sceneSessionManager is null proxy!"); return false; + } else { + auto ret = static_cast(sceneSessionManager->GetFocusSessionToken(token)); + if (ret != ERR_OK) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "Get focus session token err: %{public}d", ret); + return false; + } } - return true; -} + want.SetParam(APP_FREEZE_TOKEN, token); -void ModalSystemAppFreezeUIExtension::AppFreezeDialogConnection::OnAbilityConnectDone( - const AppExecFwk::ElementName &element, const sptr &remote, int resultCode) -{ - TAG_LOGD(AAFwkTag::ABILITYMGR, "called"); - if (remote == nullptr) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "null remote"); - return; + int32_t posX = 0; + int32_t posY = 0; + int32_t width = 10; + int32_t height = 10; + std::vector> infos; + auto ret = sceneSessionManager->GetVisibilityWindowInfo(infos); + if (ret != Rosen::WMError::WM_OK) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "Get visibility window info err: %{public}d", ret); + return false; + } else { + bool infoReady = false; + for (const auto &info : infos) { + if (info->IsFocused()) { + posX = info->rect_.posX_; + posY = info->rect_.posY_; + width = info->rect_.width_; + height = info->rect_.height_; + infoReady = true; + break; + } + } + if (!infoReady) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "No fucused window!"); + return false; + } } + want.SetParam(FREEZE_WINDOW_POSX, std::to_string(posX)); + want.SetParam(FREEZE_WINDOW_POSY, std::to_string(posY)); + want.SetParam(FREEZE_WINDOW_WIDTH, std::to_string(width)); + want.SetParam(FREEZE_WINDOW_HEIGHT, std::to_string(height)); - MessageParcel data; - MessageParcel reply; - MessageOption option; - if (!data.WriteInt32(MESSAGE_PARCEL_KEY_SIZE)) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "write MESSAGE_PARCEL_KEY_SIZE failed"); - return; - } - if (!WriteWantElement(data)) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "write element failed"); - return; - } - if (!data.WriteString16(u"parameters")) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "write parameters failed"); - return; - } - nlohmann::json param; - param[UIEXTENSION_TYPE_KEY.c_str()] = want_.GetStringParam(UIEXTENSION_TYPE_KEY); - param[APP_FREEZE_PID.c_str()] = want_.GetStringParam(APP_FREEZE_PID); - param[START_BUNDLE_NAME.c_str()] = want_.GetStringParam(START_BUNDLE_NAME); - std::string paramStr = param.dump(); - if (!data.WriteString16(Str8ToStr16(paramStr))) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "write paramStr failed"); - return; - } - uint32_t code = !Rosen::SceneBoardJudgement::IsSceneBoardEnabled() ? - COMMAND_START_DIALOG : - AAFwk::IAbilityConnection::ON_ABILITY_CONNECT_DONE; - TAG_LOGI(AAFwkTag::ABILITYMGR, "show dialog"); - auto ret = remote->SendRequest(code, data, reply, option); - if (ret != ERR_OK) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "show dialog fail"); - return; - } + return true; } -void ModalSystemAppFreezeUIExtension::AppFreezeDialogConnection::OnAbilityDisconnectDone( - const AppExecFwk::ElementName &element, int resultCode) -{ - TAG_LOGI(AAFwkTag::ABILITYMGR, "call"); -} -} // namespace AppExecFwk -} // namespace OHOS -#endif // APP_NO_RESPONSE_DIALOG +} // namespace AppExecFwk +} // namespace OHOS +#endif // APP_NO_RESPONSE_DIALOG diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index 5b3948f5fce..5a0ee5a3844 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -386,6 +386,7 @@ group("unittest") { "mission_listener_stub_second_test:unittest", "mission_listener_stub_test:unittest", "mission_listener_test:unittest", + "modal_system_app_freeze_uiextension_test:unittest", "multi_app_utils_test:unittest", "multi_instance_utils_test:unittest", "multi_user_config_mgr_test:unittest", diff --git a/test/unittest/modal_system_app_freeze_uiextension_test/BUILD.gn b/test/unittest/modal_system_app_freeze_uiextension_test/BUILD.gn new file mode 100644 index 00000000000..38b8475d321 --- /dev/null +++ b/test/unittest/modal_system_app_freeze_uiextension_test/BUILD.gn @@ -0,0 +1,104 @@ +# Copyright (c) 2024 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/test.gni") +import("//foundation/ability/ability_runtime/ability_runtime.gni") + +ohos_unittest("modal_system_app_freeze_uiextension_test") { + module_out_path = "ability_runtime/ability_runtime/ability_call_test" + + defines = [ + "APP_NO_RESPONSE_DIALOG=1", + "APP_NO_RESPONSE_BUNDLENAME=\"com.huawei.hmos.abnormal\"", + ] + + include_dirs = [ + "${ability_runtime_test_path}/mock/common/include", + "${ability_runtime_test_path}/mock/mock_appmgr_service/include", + "${ability_runtime_test_path}/mock/mock_sa_call", + "${ability_runtime_test_path}/mock/services_appmgr_test/include", + "${ability_runtime_path}/services/abilitymgr/include", + ] + + sources = [ + "${ability_runtime_services_path}/appmgr/src/modal_system_app_freeze_uiextension.cpp", + "modal_system_app_freeze_uiextension_test.cpp", + ] + + configs = [ "${ability_runtime_services_path}/appmgr:appmgr_config" ] + + deps = [ + "${ability_runtime_innerkits_path}/ability_manager:ability_manager", + "${ability_runtime_innerkits_path}/ability_manager:mission_info", + "${ability_runtime_innerkits_path}/app_manager:app_manager", + "${ability_runtime_native_path}/ability/native:abilitykit_native", + "${ability_runtime_services_path}/abilitymgr:abilityms", + "${ability_runtime_services_path}/common:perm_verification", + "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/aakit:aakit_mock", + "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_appmgr_mock", + "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_bundlemgr_mock", + "${ability_runtime_native_path}/appkit:appkit_native", + "${ability_runtime_path}/utils/server/startup:startup_util", + "${ability_runtime_services_path}/appmgr:libappms", + "${ability_runtime_services_path}/common:app_util", + "${ability_runtime_services_path}/common:res_sched_util", + "${ability_runtime_services_path}/common:task_handler_wrap", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "ability_runtime:ability_manager", + "access_token:libaccesstoken_sdk", + "bundle_framework:appexecfwk_base", + "c_utils:utils", + "common_event_service:cesfwk_innerkits", + "dsoftbus:softbus_client", + "eventhandler:libeventhandler", + "ffrt:libffrt", + "googletest:gmock_main", + "googletest:gtest_main", + "hilog:libhilog", + "hisysevent:libhisysevent", + "hitrace:hitrace_meter", + "init:libbeget_proxy", + "ipc:ipc_core", + "napi:ace_napi", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + "window_manager:libwsutils", + "window_manager:scene_session", + "window_manager:session_manager_lite", + ] + + if (ability_command_for_test) { + defines += [ "ABILITY_COMMAND_FOR_TEST" ] + } + + if (ability_runtime_graphics) { + external_deps += [ + "window_manager:libwm", + "window_manager:libwsutils", + ] + } + if (ability_runtime_upms) { + deps += [ + "${ability_runtime_innerkits_path}/uri_permission:uri_permission_mgr", + ] + } +} + +group("unittest") { + testonly = true + deps = [ ":modal_system_app_freeze_uiextension_test" ] +} diff --git a/test/unittest/modal_system_app_freeze_uiextension_test/modal_system_app_freeze_uiextension_test.cpp b/test/unittest/modal_system_app_freeze_uiextension_test/modal_system_app_freeze_uiextension_test.cpp new file mode 100644 index 00000000000..f1f3f8f1f1d --- /dev/null +++ b/test/unittest/modal_system_app_freeze_uiextension_test/modal_system_app_freeze_uiextension_test.cpp @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2024 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 +#include +#include + +#include "ability_manager_service.h" +#include "ability_record.h" +#include "wm_common.h" +#define private public +#define protected public +#include "modal_system_app_freeze_uiextension.h" +#undef private +#undef protected + +using namespace OHOS::AAFwk; +using namespace OHOS::Rosen; + +namespace OHOS { +namespace AppExecFwk { +using namespace testing::ext; +using namespace OHOS; +using namespace OHOS::AAFwk; + + + +class ModalSystemAppFreezeUiextensionTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); +}; + +void ModalSystemAppFreezeUiextensionTest::SetUpTestCase(void) +{} + +void ModalSystemAppFreezeUiextensionTest::TearDownTestCase(void) +{} + +void ModalSystemAppFreezeUiextensionTest::SetUp(void) +{} + +void ModalSystemAppFreezeUiextensionTest::TearDown(void) +{} + +/** + * @tc.number: CreateModalUIExtension_001 + * @tc.name: DumpFfrt + * @tc.desc: Test whether CreateModalUIExtension is called normally. + * @tc.type: FUNC + * @tc.require: SR000GH1HL + */ +HWTEST_F(ModalSystemAppFreezeUiextensionTest, CreateModalUIExtension_001, TestSize.Level1) +{ + std::string pid = "1"; + std::string bundleName = "Test"; + bool ret = ModalSystemAppFreezeUIExtension::GetInstance().CreateModalUIExtension(pid, bundleName); + EXPECT_NE(ret, true); +} + +/** + * @tc.number: CreateSystemDialogWant_001 + * @tc.name: DumpFfrt + * @tc.desc: Test whether CreateSystemDialogWant is called normally. + * @tc.type: FUNC + * @tc.require: SR000GH1HL + */ +HWTEST_F(ModalSystemAppFreezeUiextensionTest, CreateSystemDialogWant_001, TestSize.Level1) +{ + sptr token; + AAFwk::Want want; + std::string pid = "1"; + std::string bundleName = "Test"; + bool ret = ModalSystemAppFreezeUIExtension::GetInstance().CreateSystemDialogWant(pid, bundleName, token, want); + EXPECT_NE(ret, true); +} + +} +} -- Gitee From f4747bd736e5cfaffa07209190c7fd1eb8f51841 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B4=E6=B5=A9?= Date: Tue, 10 Jun 2025 13:39:49 +0000 Subject: [PATCH 2/6] =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 吴浩 --- .../modal_system_app_freeze_uiextension_test.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/unittest/modal_system_app_freeze_uiextension_test/modal_system_app_freeze_uiextension_test.cpp b/test/unittest/modal_system_app_freeze_uiextension_test/modal_system_app_freeze_uiextension_test.cpp index f1f3f8f1f1d..f6c3a23449e 100644 --- a/test/unittest/modal_system_app_freeze_uiextension_test/modal_system_app_freeze_uiextension_test.cpp +++ b/test/unittest/modal_system_app_freeze_uiextension_test/modal_system_app_freeze_uiextension_test.cpp @@ -36,8 +36,6 @@ using namespace testing::ext; using namespace OHOS; using namespace OHOS::AAFwk; - - class ModalSystemAppFreezeUiextensionTest : public testing::Test { public: static void SetUpTestCase(void); -- Gitee From 3351347035a20197367deaf7900422d83a56b99d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B4=E6=B5=A9?= Date: Wed, 11 Jun 2025 06:21:35 +0000 Subject: [PATCH 3/6] update services/appmgr/src/modal_system_app_freeze_uiextension.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 吴浩 --- services/appmgr/src/modal_system_app_freeze_uiextension.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/appmgr/src/modal_system_app_freeze_uiextension.cpp b/services/appmgr/src/modal_system_app_freeze_uiextension.cpp index 68f0a16c56f..e560875bc66 100644 --- a/services/appmgr/src/modal_system_app_freeze_uiextension.cpp +++ b/services/appmgr/src/modal_system_app_freeze_uiextension.cpp @@ -73,8 +73,8 @@ void ModalSystemAppFreezeUIExtension::ProcessAppFreeze(bool focusFlag, const Fau .count(); bool timeout = now - lastFreezeTime > TIMEOUT_INTERVAL_MS; TAG_LOGI(AAFwkTag::ABILITYMGR, - "%{public}s is %{public}s.pid:%{public}s lastFreezePid:%{public}s,timeout %{public}lu", - bundleName.c_str(), focusFlag ? "focus" : "not focus", pid.c_str(), lastFreezePid.c_str(), now - lastFreezeTime); + "%{public}s is %{public}s.pid:%{public}s lastFreezePid:%{public}s,timeout %{public}llu", bundleName.c_str(), + focusFlag ? "focus" : "not focus", pid.c_str(), lastFreezePid.c_str(), now - lastFreezeTime); bool isPullUpBox = isAppFreezeDialog && (pid != lastFreezePid || (pid == lastFreezePid && timeout && !isDialogExist)); bool updateTypeName = name == AppFreezeType::THREAD_BLOCK_6S || name == AppFreezeType::BUSSINESS_THREAD_BLOCK_6S; -- Gitee From 0fd66b79c75ac45eda2cadd7233e0e95ecd91abb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B4=E6=B5=A9?= Date: Wed, 11 Jun 2025 06:27:46 +0000 Subject: [PATCH 4/6] update services/appmgr/src/modal_system_app_freeze_uiextension.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 吴浩 --- services/appmgr/src/modal_system_app_freeze_uiextension.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/appmgr/src/modal_system_app_freeze_uiextension.cpp b/services/appmgr/src/modal_system_app_freeze_uiextension.cpp index e560875bc66..a98151a8fee 100644 --- a/services/appmgr/src/modal_system_app_freeze_uiextension.cpp +++ b/services/appmgr/src/modal_system_app_freeze_uiextension.cpp @@ -73,7 +73,7 @@ void ModalSystemAppFreezeUIExtension::ProcessAppFreeze(bool focusFlag, const Fau .count(); bool timeout = now - lastFreezeTime > TIMEOUT_INTERVAL_MS; TAG_LOGI(AAFwkTag::ABILITYMGR, - "%{public}s is %{public}s.pid:%{public}s lastFreezePid:%{public}s,timeout %{public}llu", bundleName.c_str(), + "%{public}s is %{public}s.pid:%{public}s lastFreezePid:%{public}s,timeout %{public}lu", bundleName.c_str(), focusFlag ? "focus" : "not focus", pid.c_str(), lastFreezePid.c_str(), now - lastFreezeTime); bool isPullUpBox = isAppFreezeDialog && (pid != lastFreezePid || (pid == lastFreezePid && timeout && !isDialogExist)); -- Gitee From 6fb2af396139726288c92eb40f7900bbe8f528d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B4=E6=B5=A9?= Date: Wed, 11 Jun 2025 07:02:38 +0000 Subject: [PATCH 5/6] update services/appmgr/src/modal_system_app_freeze_uiextension.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 吴浩 --- services/appmgr/src/modal_system_app_freeze_uiextension.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/appmgr/src/modal_system_app_freeze_uiextension.cpp b/services/appmgr/src/modal_system_app_freeze_uiextension.cpp index a98151a8fee..b4310b6eec2 100644 --- a/services/appmgr/src/modal_system_app_freeze_uiextension.cpp +++ b/services/appmgr/src/modal_system_app_freeze_uiextension.cpp @@ -73,8 +73,8 @@ void ModalSystemAppFreezeUIExtension::ProcessAppFreeze(bool focusFlag, const Fau .count(); bool timeout = now - lastFreezeTime > TIMEOUT_INTERVAL_MS; TAG_LOGI(AAFwkTag::ABILITYMGR, - "%{public}s is %{public}s.pid:%{public}s lastFreezePid:%{public}s,timeout %{public}lu", bundleName.c_str(), - focusFlag ? "focus" : "not focus", pid.c_str(), lastFreezePid.c_str(), now - lastFreezeTime); + "%{public}s is %{public}s.pid:%{public}s lastFreezePid:%{public}s", bundleName.c_str(), + focusFlag ? "focus" : "not focus", pid.c_str(), lastFreezePid.c_str()); bool isPullUpBox = isAppFreezeDialog && (pid != lastFreezePid || (pid == lastFreezePid && timeout && !isDialogExist)); bool updateTypeName = name == AppFreezeType::THREAD_BLOCK_6S || name == AppFreezeType::BUSSINESS_THREAD_BLOCK_6S; -- Gitee From 7dceac2420cb13de12ba7e6554cfe3c416036ca3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B4=E6=B5=A9?= Date: Wed, 11 Jun 2025 11:25:18 +0000 Subject: [PATCH 6/6] update services/appmgr/src/modal_system_app_freeze_uiextension.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 吴浩 --- .../modal_system_app_freeze_uiextension.cpp | 51 +++++++++---------- 1 file changed, 24 insertions(+), 27 deletions(-) diff --git a/services/appmgr/src/modal_system_app_freeze_uiextension.cpp b/services/appmgr/src/modal_system_app_freeze_uiextension.cpp index b4310b6eec2..69471d8e6c1 100644 --- a/services/appmgr/src/modal_system_app_freeze_uiextension.cpp +++ b/services/appmgr/src/modal_system_app_freeze_uiextension.cpp @@ -19,12 +19,12 @@ #include #include +#include "ability_record.h" #include "hilog_tag_wrapper.h" #include "hitrace_meter.h" #include "in_process_call_wrapper.h" #include "scene_board_judgement.h" #include "session_manager_lite.h" -#include "ability_record.h" #include "window_visibility_info.h" using namespace OHOS::AAFwk; @@ -113,9 +113,8 @@ bool ModalSystemAppFreezeUIExtension::CreateModalUIExtension(std::string pid, st } lastFreezePid = pid; lastFocusStatus = true; - lastFreezeTime = - std::chrono::duration_cast(std::chrono::steady_clock::now().time_since_epoch()) - .count(); + lastFreezeTime = std::chrono::duration_cast( + std::chrono::steady_clock::now().time_since_epoch()).count(); TAG_LOGI(AAFwkTag::ABILITYMGR, "success, result = %{public}d", result); return true; } @@ -132,12 +131,11 @@ bool ModalSystemAppFreezeUIExtension::CreateSystemDialogWant( if (!sceneSessionManager) { TAG_LOGE(AAFwkTag::ABILITYMGR, "sceneSessionManager is null proxy!"); return false; - } else { - auto ret = static_cast(sceneSessionManager->GetFocusSessionToken(token)); - if (ret != ERR_OK) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "Get focus session token err: %{public}d", ret); - return false; - } + } + auto ret = static_cast(sceneSessionManager->GetFocusSessionToken(token)); + if (ret != ERR_OK) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "Get focus session token err: %{public}d", ret); + return false; } want.SetParam(APP_FREEZE_TOKEN, token); @@ -146,27 +144,26 @@ bool ModalSystemAppFreezeUIExtension::CreateSystemDialogWant( int32_t width = 10; int32_t height = 10; std::vector> infos; - auto ret = sceneSessionManager->GetVisibilityWindowInfo(infos); - if (ret != Rosen::WMError::WM_OK) { + ret = static_cast(sceneSessionManager->GetVisibilityWindowInfo(infos)); + if (ret != ERR_OK) { TAG_LOGE(AAFwkTag::ABILITYMGR, "Get visibility window info err: %{public}d", ret); return false; - } else { - bool infoReady = false; - for (const auto &info : infos) { - if (info->IsFocused()) { - posX = info->rect_.posX_; - posY = info->rect_.posY_; - width = info->rect_.width_; - height = info->rect_.height_; - infoReady = true; - break; - } - } - if (!infoReady) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "No fucused window!"); - return false; + } + bool infoReady = false; + for (const auto &info : infos) { + if (info->IsFocused()) { + posX = info->rect_.posX_; + posY = info->rect_.posY_; + width = info->rect_.width_; + height = info->rect_.height_; + infoReady = true; + break; } } + if (!infoReady) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "No fucused window!"); + return false; + } want.SetParam(FREEZE_WINDOW_POSX, std::to_string(posX)); want.SetParam(FREEZE_WINDOW_POSY, std::to_string(posY)); want.SetParam(FREEZE_WINDOW_WIDTH, std::to_string(width)); -- Gitee